@chatpanel/events 0.432.2 → 0.435.0
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/a2ui-style.js +105 -0
- package/index.js +1 -1
- package/package.json +5 -1
- package/settings-chat.js +4 -0
- package/settings-registry.js +1 -1
- package/tool-hub.js +11 -8
- package/toolset.js +2 -2
package/tool-hub.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import{findToolsResult as
|
|
2
|
-
${
|
|
1
|
+
import{findToolsResult as L,oneLiner as k}from"./tool-discovery.js";import{validateAction as Y}from"./tool-dispatch.js";import{isPermissionTool as K}from"./agent-permission.js";import{CONTEXT_TAGS as B}from"./context-attachments.js";const v="tools",O="find",S="describe",j=6,X=5,Q=2,Z=new Set("mcp server api tool tools app apps the and for with data cloud online local remote connector integration a an of to in on my go is it by or at".split(" "));function ee(e){const i=(String(e?.name||"").match(/^mcp_(.+?)__/)||[])[1]||"",o=(String(e?.description||"").match(/^\[([^\]]+)\]/)||[])[1]||"";return[...new Set(`${i.replace(/_/g," ")} ${o}`.toLowerCase().match(/[a-z][a-z0-9]+/g)||[])].filter(t=>!Z.has(t))}function te(e,i){const o=new Set(String(e||"").toLowerCase().match(/[a-z][a-z0-9]+/g)||[]);return ee(i).some(t=>o.has(t))}const J=e=>{const i=e?.parameters||e?.inputSchema;return Array.isArray(i?.required)?i.required.map(String):[]},R=e=>`${e.name}(${J(e).join(", ")})`,z=e=>k(String(e||"").split(/\n\s*\n/)[0],140);function ne(){return{name:v,description:`Every action Chap gives you — the user's own data, their connected integrations, the browser tab — in one tool. Run one: {"action":"<name>","args":{…}}. Not sure which: {"action":"find","query":"<what you need>"}. Its arguments: {"action":"describe","tool":"<name>"}.`,parameters:{type:"object",properties:{action:{type:"string",description:'The action to run — a name from the catalog, a hint or a find — or "find" / "describe".'},args:{type:"object",additionalProperties:!0,description:"The action's own arguments, verbatim. {} when it takes none."},query:{type:"string",description:'With action "find": what you need to do, in words.'},tool:{type:"string",description:'With action "describe": the action to describe.'}},required:["action"],additionalProperties:!0}}}const N=e=>K(e);function re(e){const i=e.hiddenVia instanceof Map?e.hiddenVia:new Map,o=new Set(i.values()),t=new Map;for(const n of e.reach||[])n?.name&&!N(n.name)&&!t.has(n.name)&&t.set(n.name,n);for(const n of e.specs||[])n?.name&&!N(n.name)&&!o.has(n.name)&&!t.has(n.name)&&t.set(n.name,n);return{leaves:t,hiddenVia:i,groups:o}}function oe(e,i){const o=n=>e.some(g=>n.test(g)),t=[];return o(/^(history_|recall$|memory_recall$|meeting_)/)&&t.push("You HAVE access to the user's own Chap data — past chats, notes, meeting transcripts and summaries — here. For anything they discussed or wrote, search it FIRST (`history_search`) and answer from it; never say you cannot access their meetings, notes or history."),o(/^(weather|web_search)$/)&&t.push("For anything current — weather, prices, news — use `weather` / `web_search` here, not a search tool of your own; the user sees these calls as steps. A [prefetch] block in the message IS that call, already made: answer from it, no call."),i.size&&t.push("The user's connected integrations are here too — when a request matches one, call it rather than saying it is unavailable."),o(/^read_page$/)&&t.push("The browser tab the user is looking at can be read and acted on here — `read_page` first."),t}function ie(e,i,o){const t=new Map;for(const[l,p]of o)i.has(l)&&(t.get(p)||t.set(p,[]).get(p)).push(l);const n=[],g=e.quietTools instanceof Set?e.quietTools:new Set;for(const l of e.specs||[]){if(g.has(l.name))continue;const p=t.get(l.name);if(p?.length){const A=p.slice(0,j).join(", "),w=p.length>j?`, … (+${p.length-j} — find them)`:"";n.push(`- ${z(l.description)} — ${A}${w}`)}else i.has(l.name)&&n.push(`- ${R(l)}: ${z(l.description)}`)}return n}function he(e,{rank:i,providerSystem:o=""}={}){if(!e||typeof e.execute!="function")return null;const{leaves:t,hiddenVia:n}=re(e);if(!t.size)return null;const g=e.residents instanceof Map?e.residents:new Map,l=Array.isArray(e.hinters)?e.hinters.filter(r=>typeof r=="function"):[],p=r=>n.get(r)||r,A=r=>{const s=new Set(r instanceof Set?r:[]);for(const[u,h]of n)s.has(h)&&s.add(u);return s},w=A(e.remoteTools),F=A(e.serialTools),q=[...t.keys()],H=oe(q,new Set(q.filter(r=>w.has(r)))),P=new Set(n.values()),E=[...new Set([...g].filter(([r])=>t.has(r)&&!P.has(r)).map(([,r])=>r.trim()).filter(Boolean))],$=['Everything below is reached through ONE tool, `tools`: {"action":"<name>","args":{…}}. Not sure which action? {"action":"find","query":"<what you need>"} searches all of them. Not sure of its arguments? {"action":"describe","tool":"<name>"}.',...H,`Available:
|
|
2
|
+
${ie(e,t,n).join(`
|
|
3
3
|
`)}`,...E.length?[`Every tool the notes below name is an action of \`tools\`: call it as {"action":"<name>","args":{…}}.
|
|
4
4
|
|
|
5
5
|
${E.join(`
|
|
6
6
|
|
|
7
7
|
`)}`]:[]].join(`
|
|
8
|
-
`)
|
|
8
|
+
`),x=String(e.system||""),V=o&&x.includes(o)?x.replace(o,$):[x,$].filter(Boolean).join(`
|
|
9
9
|
|
|
10
|
-
`),
|
|
10
|
+
`),I=(r,s,u)=>{const h=n.get(r);return h?e.execute(h,{action:r,args:s},u):e.execute(r,s,u)},_=r=>Object.hasOwn(B,r)?JSON.stringify({error:`"${r}" is not an action.`,what:B[r],hint:'{"action":"find","query":"<what you need>"} lists the actions.'}):null;async function G(r){const s=t.get(r);if(!s)return _(r)??JSON.stringify({error:`Unknown action "${r}".`,hint:'{"action":"find","query":"<what you need>"} lists what exists.'});const u=[g.get(p(r))];if(n.has(r))try{const h=JSON.parse(await e.execute(n.get(r),{action:S,args:{tool:r}},{}));h?.guidance&&u.push(h.guidance)}catch{}return JSON.stringify({name:s.name,description:s.description||"",parameters:s.parameters||s.inputSchema||{type:"object",properties:{}},...u.filter(Boolean).length?{guidance:u.filter(Boolean).join(`
|
|
11
11
|
|
|
12
|
-
`)}:{},callAs:{action:s.name,args:"<the properties above>"}})}async function
|
|
13
|
-
`)
|
|
12
|
+
`)}:{},callAs:{action:s.name,args:"<the properties above>"}})}async function M(r,s,u={}){const h=s&&typeof s=="object"?s:{};if(r!==v)return t.has(r)&&!n.has(r)?e.execute(r,h,u):n.has(r)?I(r,h,u):e.execute(r,h,u);const{action:T,args:a,...b}=h,f=String(T||""),d={...b,...a&&typeof a=="object"?a:{}},m=a&&typeof a=="object"?String(a.action||""):"";if(f===O&&m&&m!==O&&m!==S&&t.has(m))return M(v,{action:m,args:a.args&&typeof a.args=="object"?a.args:{}},u);if(f===O)return L([...t.values()],String(d.query??d.tool??""),{rank:i,describeAction:S});if(f===S)return G(String(d.tool||d.name||d.action||""));const y=t.get(f);if(!y&&_(f))return _(f);if(!y){const W=JSON.parse(await L([...t.values()],f.replace(/[_-]+/g," "),{rank:i,describeAction:S,limit:5}));return JSON.stringify({error:`Unknown action "${f}".`,didYouMean:W.matches.map(D=>D.name),hint:'Call one of those, or {"action":"find","query":"<what you need>"}.'})}const c=typeof a=="string"&&a.trim()?J(y):[];c.length===1&&d[c[0]]==null&&[void 0,"string"].includes(y.parameters?.properties?.[c[0]]?.type)&&(d[c[0]]=a.trim(),u?.shims?.fire?.("hub.args-text",{tool:f}));const C=Y(y,d,{envelope:a});return C?JSON.stringify(C):I(f,d,u)}function U(r,{score:s,limit:u=X,minScore:h=Q,small:T=!1}={}){const a=String(r||"").trim();if(!a)return"";const b=l.map(c=>{try{return String(c(a,{small:T})||"")}catch{return""}}).filter(Boolean);if(typeof s!="function")return b.join(`
|
|
13
|
+
`);let f;try{f=s([...t.values()],a)}catch{return b.join(`
|
|
14
|
+
`)}const d=c=>!T||!w.has(c.name)||te(a,c),m=(f||[]).filter(c=>c&&c.n>h&&d(c.s)).slice(0,u).map(c=>c.s);return[m.length?`[Chap] Likely useful for this message, through \`tools\`: ${m.map(c=>`${R(c)} — ${k(c.description,90)}`).join("; ")}.`:"",...b].filter(Boolean).join(`
|
|
15
|
+
`)}return{...e,specs:[ne(),...(e.specs||[]).filter(r=>N(r?.name))],system:V,systemParts:{tools:Math.round($.length/4)},remoteTools:w,serialTools:F,execute:M,hub:{leaves:[...t.keys()],hintFor:U,groupOf:p}}}function fe(e){for(let i=(e||[]).length-1;i>=0;i--){const o=e[i];if(o?.role==="user")return typeof o.content=="string"?o.content:Array.isArray(o.content)?o.content.filter(t=>t?.type==="text").map(t=>t.text||"").join(`
|
|
16
|
+
`):""}return""}function le(e,i){const o=Array.isArray(e)?e:[];if(!i)return o;let t=o.length-1;for(;t>=0&&o[t]?.role!=="user";)t--;if(t<0)return o;const n=o[t],g=typeof n.content=="string"?`${n.content}
|
|
14
17
|
|
|
15
|
-
${i}`:Array.isArray(n.content)?[...n.content,{type:"text",text:i}]:n.content;return[...o.slice(0,
|
|
18
|
+
${i}`:Array.isArray(n.content)?[...n.content,{type:"text",text:i}]:n.content;return[...o.slice(0,t),{...n,content:g},...o.slice(t+1)]}function pe(e,i){const o=Array.isArray(e)?e:[];if(!i)return o;let t=o.length-1;for(;t>=0&&o[t]?.role!=="user";)t--;if(t<0)return o;const n=o[t],g=typeof n.content=="string"?`${i}
|
|
16
19
|
|
|
17
|
-
${n.content}`:Array.isArray(n.content)?[{type:"text",text:i},...n.content]:n.content;return[...o.slice(0,
|
|
20
|
+
${n.content}`:Array.isArray(n.content)?[{type:"text",text:i},...n.content]:n.content;return[...o.slice(0,t),{...n,content:g},...o.slice(t+1)]}export{v as HUB_TOOL_NAME,ne as hubSpec,fe as lastUserText,he as makeToolHub,te as namesIntegration,le as withHint,pe as withLead};
|
package/toolset.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
1
|
+
const T=/^mcp[_-]/i;function N(A,{mcpSystem:f=""}={}){const i=(A||[]).filter(e=>e&&e.specs?.length);if(!i.length)return;const r=[],u=new Map,g=new Set,h=new Map,y=new Set,m=[],o=new Map,M=new Map,S=new Set,l=[];for(const e of i){if(typeof e.hint=="function"&&l.push(e.hint),Array.isArray(e.hinters))for(const t of e.hinters)typeof t=="function"&&l.push(t);const s=e.remote===!0;if(e.traits instanceof Map)for(const[t,n]of e.traits)h.has(t)||h.set(t,n);const a=e.hiddenVia instanceof Map;if(a){const t=new Map((Array.isArray(e.reach)?e.reach:[]).filter(n=>n?.name).map(n=>[n.name,n]));for(const[n,w]of e.hiddenVia)o.has(n)||!e.specs.some(R=>R?.name===w)||(o.set(n,w),t.has(n)&&m.push(t.get(n)))}else if(Array.isArray(e.reach)&&e.specs.length===1)for(const t of e.reach)t?.name&&!o.has(t.name)&&(o.set(t.name,e.specs[0].name),m.push(t));const c=e.remoteTools instanceof Set?e.remoteTools:null,E=e.serialTools instanceof Set?e.serialTools:null;for(const t of e.specs){if(u.has(t.name))continue;r.push(t),u.set(t.name,e.execute);const n=a&&e.residents instanceof Map?e.residents.get(t.name):e.system;n&&M.set(t.name,String(n)),(s||c?.has(t.name)||T.test(String(t.name||"")))&&g.add(t.name),(e.serial===!0||E?.has(t.name))&&y.add(t.name),(e.quiet===!0||e.quietTools instanceof Set&&e.quietTools.has(t.name))&&S.add(t.name)}}if(!r.length)return;const p=r.some(e=>T.test(String(e?.name||"")))?String((typeof f=="function"?f():f)||""):"",q=[p,...i.filter(e=>e.quiet!==!0).map(e=>e.system)].map(e=>String(e||"").trim()).filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`)||void 0,d={};p.trim()&&(d.mcp=Math.round(p.length/4));for(const e of
|
|
3
|
+
`)||void 0,d={};p.trim()&&(d.mcp=Math.round(p.length/4));for(const e of i){if(e.quiet===!0)continue;const s=Math.round(String(e.system||"").trim().length/4);s&&(d[e.id||e.specs[0]?.name||"group"]=s)}return{specs:r,system:q,systemParts:d,remoteTools:g,traits:h,serialTools:y,reach:m,hiddenVia:o,residents:M,quietTools:S,hinters:l,async execute(e,s,a={}){const c=u.get(e);return c?c(e,s,a):JSON.stringify({error:`Unknown tool: ${e}`})}}}export{N as buildToolset};
|