@chatpanel/events 0.447.0 → 0.447.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/settings-chat.js +4 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/events",
|
|
3
|
-
"version": "0.447.
|
|
3
|
+
"version": "0.447.1",
|
|
4
4
|
"description": "The canonical ChatPanel event-log and capability contracts — typed durable facts, clock-free deterministic linearization, schema upcasting, and the invariants the replay harness asserts. Pure, dependency-free ESM shared by the ChatPanel extension, gateway and bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/settings-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{listRows as Se,findRow as X,rowsFor as
|
|
2
|
-
`)}function Fe({items:e=[],why:t=""}){const a=e.slice(0,
|
|
3
|
-
`)}const Pe=new Set("the a an and or but to of in on at by for with from into onto my me i you your we our it its this that these those is are was were be been am do does did can could would should will shall may might must please hey chap just also so then than there here what which who whom how why when where all any some each every not no yes ok okay get got make made let use using want need like".split(" ")),qe=e=>e.length>4&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,
|
|
4
|
-
`),
|
|
1
|
+
import{listRows as Se,findRow as X,rowsFor as se,breadcrumb as E,linkToRow as ke,setValue as $e,effectiveValue as ve,describeValue as Ne,gateOf as Y}from"./settings-registry.js";import{makeDispatchProvider as Oe}from"./tool-dispatch.js";import{exprLit as $}from"./a2ui-tool-cards.js";const ae="settings",H="settings_find",K="settings_change",ce="settings_run",Q=Object.freeze({allow:"chap.settings.allow",deny:"chap.settings.deny",open:"chap.settings.open"}),V=6,xe=new Set(["bridge-url","bridge-token","gw-url","gw-token","ch-token"]),Te=new Set(["internal-restore","license-deactivate","backup-import","btn-subscribe-pro","btn-check-purchase","btn-restore","gw-pro-activate","link-pair","link-partner-pair","ch-pair","ch-connect","drive-connect"]),Ce=Object.freeze({"memory-clear":"forget","activity-clear":"clear","obs-clear":"clear","usage-clear":"clear","reset-skills":"reset","drive-disconnect":"disconnect","ch-disconnect":"disconnect","drive-backup-restore":"restore","drive-backup-restore-all":"restore"}),_e=new Set(["local-recheck","bridge-test","priv-ner-check","gw-check","gw-ner-check","gw-logs-refresh","rt-recheck","obs-refresh","check-updates","plugins-refresh","skill-sources-refresh"]),le=new Set(["toggle","select","text","number","textarea","picker"]),Ee=500,Ae=8e3;function Re(e,{bound:t={},actions:a={},choices:r=null}={}){const o=e?.row;return!o||o.composer?"none":o.type==="secret"||xe.has(o.id)||o.consent?"open":e.page?.id==="plan"||e.group?.id==="privacy"&&!(o.stricter&&le.has(o.type))?o.type==="status"?"read":"open":o.type==="status"?"read":o.type==="link"?"open":o.type==="action"?Te.has(o.id)?"open":typeof a[o.id]?.run=="function"?"run":"open":typeof a[o.id]?.run=="function"?"run":le.has(o.type)?o.store==="local"||o.store==="gateway"||!o.key?typeof t[o.id]?.write=="function"?"change":"open":o.type==="picker"&&typeof r!="function"?"open":"change":"open"}const A=e=>String(e??"").trim().toLowerCase(),Je=new Set(["true","on","yes","1","enable","enabled"]),je=new Set(["false","off","no","0","disable","disabled"]);function he(e,t){return e.type==="secret"?t?"set":"not set":Ne(e,t)||(t==null||t===""?"not set":String(t))}function Le(e,t,{options:a=e.options}={}){switch(e.type){case"toggle":{if(typeof t=="boolean")return{ok:!0,value:t};const r=A(t);return Je.has(r)?{ok:!0,value:!0}:je.has(r)?{ok:!0,value:!1}:{ok:!1,why:`"${e.label}" is on or off`}}case"select":case"picker":{const r=Array.isArray(a)?a:[];if(!r.length)return{ok:!1,why:`there are no choices for "${e.label}" here`};const o=r.find(h=>String(h[0])===String(t))||r.find(h=>A(h[0])===A(t)||A(h[1])===A(t));return o?{ok:!0,value:o[0]}:{ok:!1,why:`"${t}" is not one of the choices for "${e.label}": ${r.slice(0,12).map(h=>h[1]||h[0]).join(", ")}`}}case"number":{const r=typeof t=="number"?t:Number(String(t??"").trim());return!Number.isFinite(r)||String(t??"").trim()===""?{ok:!1,why:`"${e.label}" takes a number`}:r<0?{ok:!1,why:`"${e.label}" cannot be negative`}:Number.isFinite(e.min)&&r<e.min?{ok:!1,why:`"${e.label}" is at least ${e.min}`}:Number.isFinite(e.max)&&r>e.max?{ok:!1,why:`"${e.label}" is at most ${e.max}`}:{ok:!0,value:r}}case"text":case"textarea":{if(typeof t!="string"&&typeof t!="number")return{ok:!1,why:`"${e.label}" takes text`};const r=String(t),o=e.type==="text"?Ee:Ae;return r.length>o?{ok:!1,why:`"${e.label}" takes at most ${o} characters`}:/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/.test(r)||e.type==="text"&&/[\r\n]/.test(r)?{ok:!1,why:`"${e.label}" takes plain text on one line`}:{ok:!0,value:e.type==="text"?r.trim():r}}default:return{ok:!1,why:`"${e.label}" is not set by value`}}}function Ie(e,t,a){const r=e?.stricter;if(!r)return!1;if(r===!0){const b=t==null?e.default===!0:t===!0;return a===!0||a===b}const o=Array.isArray(r.order)?r.order.map(String):[],h=o.indexOf(String(t==null||t===""?r.unset:t)),d=o.indexOf(String(a));return h!==-1&&d!==-1&&d>=h}const f=(e,t=160)=>{const a=String(e??"");return a.length>t?`${a.slice(0,t-1)}…`:a};function ue({title:e,items:t=[],reason:a="",ticket:r="",allowLabel:o="Apply",note:h="",mustType:d=""}){const b=t.map(S=>({l:f(S.label,60),w:f(S.where,80),f:f(S.from,60),t:f(S.to,80)}));return[`$/c = ${$({title:f(e,80),reason:a?`Chap says: ${f(a,200)}`:"",note:f(h,200),warn:d?"This cannot be undone":"",typeLabel:d?`Type “${d}” to confirm`:""})}`,...d?['$/typed = ""']:[],`$/items = ${$(b)}`,'head = Row([Icon("settings"), Text($/c/title, "h3")])','items = List(_template($/items, Column([Text($l), Text($w, "caption"), Row([Badge($f), Text("→"), Badge($t, "info")])])))',...a?['why = Text($/c/reason, "caption")']:[],...h?['note = Text($/c/note, "caption")']:[],...d?['warn = Badge($/c/warn, "bad")',"typed = TextField($/c/typeLabel, $/typed, "+$(d)+', "shortText")']:[],`allow = Button(Text(${$(o)}), "primary", Event(${$(Q.allow)}, {ticket: ${$(r)}${d?", typed: $/typed":""}}))`,`deny = Button(Text("Not now"), _, Event(${$(Q.deny)}, {ticket: ${$(r)}}))`,`root = Card(Column([head, items, ${a?"why, ":""}${h?"note, ":""}${d?"warn, typed, ":""}Row([allow, deny])]))`].join(`
|
|
2
|
+
`)}function Fe({items:e=[],why:t=""}){const a=e.slice(0,V).map(o=>({l:f(o.label,60),w:f(o.where,80),id:o.id}));return[`$/c = ${$({why:f(t||"You change these in Settings yourself.",200)})}`,`$/items = ${$(a)}`,'head = Row([Icon("settings"), Text("In Settings", "h3")])',`items = List(_template($/items, Row([Column([Text($l), Text($w, "caption")]), Button(Text("Open"), "borderless", Event(${$(Q.open)}, {row: $id}))])))`,'root = Card(Column([head, Text($/c/why, "caption"), items]))'].join(`
|
|
3
|
+
`)}const Pe=new Set("the a an and or but to of in on at by for with from into onto my me i you your we our it its this that these those is are was were be been am do does did can could would should will shall may might must please hey chap just also so then than there here what which who whom how why when where all any some each every not no yes ok okay get got make made let use using want need like".split(" ")),qe=e=>e.length>4&&e.endsWith("s")&&!e.endsWith("ss")?e.slice(0,-1):e,P=e=>String(e||"").toLowerCase().normalize("NFKD").replace(/[̀-ͯ]/g,"").split(/[^a-z0-9]+/).filter(t=>t.length>=3&&!Pe.has(t)).map(qe);let Z=null;function De(e){const{row:t}=e;return{name:new Set([t.label,...t.synonyms||[]].flatMap(P)),names:[t.label,...t.synonyms||[]].map(P).filter(a=>a.length),opts:new Set((t.options||[]).flatMap(a=>P(a[1]))),place:new Set([e.page.label,e.section.label].flatMap(P))}}function Ge(){return Z||(Z=new Map(Se().map(e=>[e.row.id,De(e)]))),Z}function Ue(e,t){let a=e.indexOf(t[0]);for(;a!==-1;){let r=a,o=!0;for(const h of t.slice(1))if(e[r+1]===h)r+=1;else if(e[r+2]===h)r+=2;else{o=!1;break}if(o)return!0;a=e.indexOf(t[0],a+1)}return!1}function ee(e,{rows:t=null,min:a=10,limit:r=3,lookup:o=!1}={}){const h=P(e),d=[...new Set(h)],b=o?new Set(String(e||"").toLowerCase().match(/[a-z0-9]+(?:-[a-z0-9]+)+/g)||[]):null;if(!d.length&&!b?.size)return[];const R=t?new Set(t):null,S=[];for(const[y,N]of Ge()){if(R&&!R.has(y))continue;if(b?.has(y)){S.push({id:y,score:100});continue}let C=0,O=0;for(const k of d){const q=N.name.has(k)?3:N.opts.has(k)?2:N.place.has(k)?1:0;q&&(C+=q,O+=1)}const J=N.names.filter(k=>Ue(h,k));J.length&&(C+=4);const j=J.some(k=>k.length>1);C>=a&&(o||O>=2||j)&&S.push({id:y,score:C})}return S.sort((y,N)=>N.score-y.score).slice(0,r)}const ze={name:H,description:"Look up Chap's own settings — models and which model does what, voices, search engines, backups, updates, privacy, everything on the Settings pages — and their current values.",parameters:{type:"object",properties:{query:{type:"string",description:'What the setting is about, in a few words ("title model", "dark mode", "backup").'}},required:["query"]},annotations:{readOnlyHint:!0}},Me={name:K,description:"Propose a change to one or more of Chap's settings. The person sees a card and decides; nothing changes until they apply it.",parameters:{type:"object",properties:{changes:{type:"array",description:`Up to ${V}, applied together on one card.`,items:{type:"object",properties:{id:{type:"string",description:"The setting id from settings_find."},value:{description:"The new value: true/false, a choice's value, a number or text."}},required:["id","value"]}},reason:{type:"string",description:"One short sentence the person reads on the card: why this change."}},required:["changes"]}},Ve={name:ce,description:"Run one of Chap's settings actions (back up now, check for updates, download a model…). One that changes something shows the person a card first.",parameters:{type:"object",properties:{id:{type:"string",description:"The action id from settings_find."},args:{type:"object",description:"The action's own arguments, when settings_find lists any."},reason:{type:"string",description:"One short sentence the person reads on the card."}},required:["id"]}},Be='Chap\'s own settings: `settings_find` looks them up with their values and what you may do with each (`can`): "change" → propose with `settings_change` (the person decides on a card); "run" → `settings_run`; "open" → the person changes it in Settings — say so, Chap shows them the way. Never claim a setting changed unless the result says it did.';let We=0;const de=e=>(typeof e=="string"?e:e?.decision)==="allow"?"allow":"deny";function Ke({client:e="browser",read:t=()=>({}),write:a=null,bound:r={},choices:o=null,actions:h={},runtime:d=()=>({}),confirm:b=null,record:R=null,newTicket:S=()=>`s${Date.now().toString(36)}${We+=1}`}={}){const y=new Set(se(e)),N={bound:r,actions:h,choices:o},C=n=>{const c=X(String(n||""));return c&&y.has(c.row.id)?c:null},O=n=>Re(n,N),J=(n,c)=>r[n.row.id]?.read?r[n.row.id].read():ve(c,n.row),j=(n,c)=>{const p=()=>{try{return typeof o=="function"?o(n.row.id,c):null}catch{return null}};return n.row.type==="picker"?p():n.row.options?.length?n.row.options:p()},k=n=>{try{R?.(n)}catch{}};function q(n,c){const p=O(n),i=p==="change"?j(n,c):null,g=Y(n.row,d()||{});return{id:n.row.id,label:n.row.label,where:E(n),...n.row.key||r[n.row.id]?.read?{value:he(n.row,J(n,c))}:{},can:p,type:n.row.type,...i?.length?{choices:i.slice(0,12).map(v=>v[0])}:{},...h[n.row.id]?.args?{args:h[n.row.id].args}:{},...g.ok?{}:{blocked:g.reason},...n.row.pro?{pro:!0}:{},...n.row.help?{help:f(n.row.help,140)}:{}}}function pe({query:n=""}={}){const c=t()||{},p=ee(n,{rows:[...y],min:1,limit:y.size,lookup:!0}),i=p.filter(g=>g.score*3>=p[0].score).map(g=>q(X(g.id),c)).filter(g=>g.can!=="none").slice(0,8);return i.length?JSON.stringify({matches:i}):JSON.stringify({matches:[],hint:"Nothing matched — try other words for the setting (what it does, or where it lives in Settings)."})}const te=(n,c)=>({text:JSON.stringify({changed:!1,open:n.map(p=>p.id),say:`${c} Chap shows the person a card that opens it in Settings; do not say it changed.`}),card:{lang:"a2ui",source:Fe({items:n,why:c})}});async function fe({changes:n,reason:c="",id:p,value:i}={}){const g=Array.isArray(n)?n:p?[{id:p,value:i}]:[];if(!g.length)return JSON.stringify({error:'No change given. Pass {"changes":[{"id":"<from settings_find>","value":…}]}.'});if(g.length>V)return JSON.stringify({error:`At most ${V} changes on one card.`});const v=t()||{},L=d()||{},w=[],u=[],m=[];for(const l of g){const s=C(l?.id);if(!s){u.push({id:l?.id,why:"no such setting here — look it up with settings_find"});continue}const B=O(s);if(B==="open"){m.push({id:s.row.id,label:s.row.label,where:E(s)});continue}if(B!=="change"){u.push({id:s.row.id,why:B==="run"?"this is an action — use settings_run":"this one is shown, not set"});continue}const U=Y(s.row,L);if(!U.ok){u.push({id:s.row.id,why:`${U.reason}${U.fix?` (${U.fix})`:""}`});continue}const _=Le(s.row,l.value,{options:j(s,v)});if(!_.ok){u.push({id:s.row.id,why:_.why});continue}const z=J(s,v),W=(z==null||z==="")&&s.row.stricter?.unset!==void 0?s.row.stricter.unset:z;if(JSON.stringify(W)===JSON.stringify(_.value))continue;if(s.group?.id==="privacy"&&!Ie(s.row,W,_.value)){m.push({id:s.row.id,label:s.row.label,where:E(s)}),u.push({id:s.row.id,why:"that loosens privacy — the person changes it in Settings"});continue}const re=j(s,v);if(re?.find(M=>String(M[0])===String(_.value))?.[2]?.leaves===!0){m.push({id:s.row.id,label:s.row.label,where:E(s)}),u.push({id:s.row.id,why:"that choice sends your words off this device"});continue}const oe=M=>{const ie=re?.find(be=>String(be[0])===String(M));return ie?ie[1]:he(s.row,M)};w.push({e:s,value:_.value,item:{id:s.row.id,label:s.row.label,where:E(s),from:oe(W),to:oe(_.value)}})}if(m.length&&!w.length)return te(m,u.length?`Not changed from the chat: ${u.map(l=>l.why).join("; ")}.`:"These are changed by the person in Settings, not from the chat.");if(!w.length)return u.length?JSON.stringify({changed:!1,refused:u}):JSON.stringify({changed:!1,unchanged:!0,say:"Already set that way — nothing to change."});if(typeof b!="function"||typeof a!="function"&&w.some(l=>!r[l.e.row.id]?.write))return JSON.stringify({changed:!1,error:"Settings cannot be changed from this chat here — the person can change them in Settings."});const I=S(),F=w.map(l=>l.item.id),x=w.length===1?`Change ${w[0].item.label}?`:`Change ${w.length} settings?`,T=w.map(l=>`${l.item.label}: ${l.item.from} → ${l.item.to}`).join(`
|
|
4
|
+
`),D=m.length?`Not on this card — change in Settings: ${m.map(l=>l.label).join(", ")}.`:"";let G="deny";try{G=de(await b({kind:"change",title:x,detail:T,reason:f(c,200),card:ue({title:x,items:w.map(l=>l.item),reason:c,ticket:I,note:D}),ticket:I,ids:F}))}catch{G="deny"}if(k({kind:"change",ids:F,decision:G==="allow"?"allow":"deny"}),G!=="allow")return JSON.stringify({changed:!1,declined:F,say:"The person kept their settings as they were. Do not propose this again unless they ask."});try{const l=w.filter(s=>!r[s.e.row.id]?.write);l.length&&await a(l.map(s=>({id:s.e.row.id,key:s.e.row.key,value:s.value})));for(const s of w)r[s.e.row.id]?.write&&await r[s.e.row.id].write(s.value)}catch(l){return JSON.stringify({changed:!1,error:`Could not save: ${f(l?.message||l,160)}`})}return JSON.stringify({changed:!0,now:w.map(l=>({id:l.item.id,label:l.item.label,value:l.item.to})),...u.length?{refused:u}:{},...m.length?{open:m.map(l=>l.id)}:{}})}async function ge({id:n,args:c={},reason:p=""}={}){const i=C(n);if(!i)return JSON.stringify({error:"No such action here — look it up with settings_find."});const g=O(i);if(g==="open")return te([{id:i.row.id,label:i.row.label,where:E(i)}],`"${i.row.label}" is done by the person in Settings, not from the chat.`);if(g!=="run")return JSON.stringify({error:g==="change"?"This is a setting — propose it with settings_change.":"This one is shown, not run."});const v=Y(i.row,d()||{});if(!v.ok)return JSON.stringify({ran:!1,why:`${v.reason}${v.fix?` (${v.fix})`:""}`});const L=h[i.row.id],w=c&&typeof c=="object"?c:{};if(_e.has(i.row.id))k({kind:"run",ids:[i.row.id],decision:"look"});else{if(typeof b!="function")return JSON.stringify({ran:!1,error:"Actions cannot be run from this chat here — the person can run it in Settings."});let u="";try{u=L.preview?String(L.preview(w)||""):""}catch{u=""}const m=S(),I=`${i.row.label}?`,F={id:i.row.id,label:i.row.label,where:E(i),from:"now",to:f(u||i.row.help||i.row.label,80)},x=Ce[i.row.id]||"";let T="deny";try{const D=await b({kind:"run",title:I,detail:u||i.row.help||"",reason:f(p,200),card:ue({title:I,items:[F],reason:p,ticket:m,allowLabel:i.row.label,mustType:x}),ticket:m,ids:[i.row.id],...x?{mustType:x}:{}});T=de(D),x&&T==="allow"&&A(D?.typed)!==x&&(T="deny")}catch{T="deny"}if(k({kind:"run",ids:[i.row.id],decision:T==="allow"?"allow":"deny"}),T!=="allow")return JSON.stringify({ran:!1,declined:i.row.id,say:"The person chose not to. Do not ask again unless they do."})}try{const u=await L.run(w);return JSON.stringify({ran:!0,id:i.row.id,result:f(typeof u=="string"?u:JSON.stringify(u??""),1500)})}catch(u){return JSON.stringify({ran:!1,id:i.row.id,error:f(u?.message||u,200)})}}const ne=Object.keys(h).some(n=>typeof h[n]?.run=="function"&&y.has(n)),we=[ze,Me,...ne?[Ve]:[]],ye=Oe({name:ae,description:"Chap's own settings — look up, propose a change (the person approves), run an action.",resident:Be,inner:{specs:we,async execute(n,c={}){return n===H?pe(c):n===K?fe(c):n===ce&&ne?ge(c):JSON.stringify({error:`Unknown settings action: ${n}`})}}});function me(n){const c=ee(n,{rows:[...y],min:10,limit:3}).map(i=>X(i.id)).filter(i=>i&&O(i)!=="none");return c.length?`[Chap] This may be about Chap's own settings: ${c.map(i=>`${i.row.label} (\`${i.row.id}\`, ${O(i)})`).join("; ")}. Through \`tools\`: {"action":"${H}","args":{"query":"…"}} for values and choices, then {"action":"${K}","args":{"changes":[{"id":"…","value":…}]}} — the person approves on a card.`:""}return{...ye,id:ae,quiet:!0,hint:me}}function Qe(e,{client:t="browser"}={}){return ee(e,{rows:se(t),min:10,limit:1}).length>0}const Ze=e=>ke(e);function et(e,t=[]){return(t||[]).filter(a=>a?.key).reduce((a,r)=>$e(a,r.key,r.value),e||{})}export{_e as LOOK_ONLY_ACTIONS,V as MAX_CHANGES,K as SETTINGS_CHANGE,Q as SETTINGS_EVENTS,H as SETTINGS_FIND,ae as SETTINGS_GROUP,ce as SETTINGS_RUN,Ce as TYPE_TO_RUN,et as applyChanges,Qe as asksAboutSettings,ue as changeCard,Re as chatReachOf,Le as coerceValue,Ie as isStricter,Fe as openCard,ee as rankForMessage,Ke as settingsChatProvider,Ze as settingsLinkFor,he as shownValue};
|