char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
521a64cd0
char/aliceai-t5-moe
1/** 2* permissionsStore - Allowed tool permissions 3* 4* Owns the set of tools the user has permanently allowed, persisted to 5* localStorage. The agentic loop's permission gates consult it to run a 6* tool without prompting. 7*/ 8 9import { browser } from '$app/environment' ; 10import { ALWAYS_ALLOWED_TOOLS_LOCALSTORAGE_KEY } from '$lib/constants' ; 11import { SvelteSet } from 'svelte/reactivity' ; 12 13class PermissionsStore { 14private _tools = $state ( new SvelteSet < string >()); 15 16get tools () :ReadonlySet < string > { 17return this . _tools ; 18} 19 20allowTool ( key :string ) :void { 21this . _tools . add ( key ); 22this . persist (); 23} 24 25allowTools ( keys :string []) :void { 26for ( const key of keys ) this . _tools . add ( key ); 27this . persist (); 28} 29 30hasTool ( key :string ) :boolean { 31return this . _tools . has ( key ); 32} 33 34/** 35* Load persisted permissions. Called by initStores() after migrations 36* have run. 37*/ 38initialize () :void { 39// browser-only init: skip on SSR to avoid localStorage side effects 40if ( ! browser ) return ; 41 42try { 43const stored = localStorage . getItem ( ALWAYS_ALLOWED_TOOLS_LOCALSTORAGE_KEY ); 44 45if ( stored ) { 46for ( const name of JSON . parse ( stored ) as string []) { 47if ( typeof name === 'string' ) this . _tools . add ( name ); 48} 49} 50} catch ( err ) { 51console . error ( 52`Failed to load permissions from localStorage (" ${ ALWAYS_ALLOWED_TOOLS_LOCALSTORAGE_KEY } "):` , 53err 54); 55} 56} 57 58revokeTool ( key :string ) :void { 59this . _tools . delete ( key ); 60this . persist (); 61} 62 63private persist () :void { 64try { 65localStorage . setItem ( ALWAYS_ALLOWED_TOOLS_LOCALSTORAGE_KEY , JSON . stringify ([ ...this . _tools ])); 66} catch ( err ) { 67console . error ( 68`Failed to persist to localStorage (" ${ ALWAYS_ALLOWED_TOOLS_LOCALSTORAGE_KEY } "):` , 69err 70); 71} 72} 73} 74 75export const permissionsStore = new PermissionsStore ();