@chatpanel/events 0.329.0 → 0.353.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/answer-grounding.js +5 -0
- package/capability-endpoints.js +1 -1
- package/capability-uses.js +1 -1
- package/client-prefs.js +1 -1
- package/context-attachments.js +4 -4
- package/context-breakdown.js +5 -0
- package/context-window.js +1 -1
- package/engine-pacer.js +1 -0
- package/housekeeping.js +1 -1
- package/index.js +1 -1
- package/local-engine.js +1 -0
- package/mcp-client.js +4 -4
- package/mcp-signin.js +1 -1
- package/memory.js +2 -2
- package/model-candidates.js +1 -1
- package/notes-grounding.js +5 -5
- package/package.json +27 -1
- package/plan-executor.js +1 -1
- package/plan.js +1 -1
- package/prefetch.js +3 -3
- package/question-plan.js +11 -0
- package/retrieval-plan.js +2 -1
- package/search-api.js +1 -0
- package/search-engines.js +1 -1
- package/search-modes.js +7 -7
- package/search-outcome.js +1 -0
- package/settings-registry.js +1 -1
- package/stitch.js +8 -8
- package/team-trail.js +2 -2
- package/titles.js +4 -4
- package/tool-hub.js +11 -9
- package/tool-need.js +2 -2
- package/tool-round.js +1 -1
- package/turn-events.js +1 -0
- package/turn-flow.js +2 -0
- package/turn-gather.js +1 -0
- package/turn-intent.js +3 -0
- package/turn-loop.js +4 -4
- package/turn-pipeline.js +4 -0
- package/turn-replay.js +1 -0
- package/web-search-tool.js +8 -8
- package/web-search.js +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import{isSmallWindow as w}from"./context-window.js";const y={thousand:3,k:3,million:6,mn:6,m:6,billion:9,bn:9,b:9,trillion:12,tn:12,t:12},$=/([$€£¥₹]\s?)?(?<![\w.])(\d{1,3}(?:,\d{3})+|\d+)(\.\d+)?(?:\s?(%|percent\b|per cent\b)|\s?(thousand|million|billion|trillion|mn|bn|tn)\b|(k|m|b|t)\b)?/gi;function k(t,{evidence:n=!1}={}){return(n?String(t||""):String(t||"").replace(/\n\s*\*{0,2}Sources:?\*{0,2}[\s\S]*$/i,"")).replace(/\]\([^)]*\)/g,"]").replace(/https?:\/\/\S+/g," ").replace(/\[\d+(?:\s*[,–-]\s*\d+)*\]/g," ").replace(/^\s*\d+[.)]\s+/gm,"")}function h(t,{evidence:n=!1}={}){const o=[];for(const i of k(t,{evidence:n}).matchAll($)){const[c,s,a,e="",l,r,u]=i,p=y[String(r||u||"").toLowerCase()]||0,g=10**p,d=+`${a.replace(/,/g,"")}${e}e${p}`;if(!Number.isFinite(d))continue;const m=e?e.length-1:0,b=+`5e${p-m-1}`,f=!e&&!s&&!l&&g===1,S=!(f&&/^(?:19|20)\d\d$/.test(a))&&(!f||d>=1e3);o.push({raw:c.trim(),value:d,tol:b,checked:S})}return o}function x(t,n,{asked:o=""}={}){const i=[String(n||""),String(o||"")].join(`
|
|
2
|
+
`);if(!String(n||"").trim())return[];const c=h(i,{evidence:!0}).map(e=>e.value),s=[],a=new Set;for(const e of h(t))!e.checked||a.has(e.raw)||(a.add(e.raw),!c.some(l=>Math.abs(l-e.value)<=e.tol+Math.abs(e.value)*1e-9)&&s.push(e.raw));return s}function A(t,{max:n=4}={}){const o=(Array.isArray(t)?t:[]).filter(Boolean);return o.length?`⚠ Not in what was looked up: ${o.slice(0,n).join(", ")+(o.length>n?`, and ${o.length-n} more`:"")}. Check ${o.length===1?"it":"these"} before relying on ${o.length===1?"it":"them"}.`:""}function N(t,n,o={}){return A(x(t,n,o))}const v=new Set(["web","lookup","research","stock","page"]),j=t=>typeof t?.content=="string"?t.content:Array.isArray(t?.content)?t.content.map(n=>typeof n?.text=="string"?n.text:"").join(`
|
|
3
|
+
`):"";function F({answer:t="",messages:n=[],window:o=0}={}){if(!w(o)||!String(t||"").trim())return"";const i=Array.isArray(n)?n:[],c=i.findLastIndex(r=>r?.role==="user"),s=i.slice(0,c+1);if(!(s[c]?.attachments||[]).some(r=>r?.kind==="prefetch"&&v.has(r.prefetch)&&String(r.text||"").trim()))return"";const e=s.flatMap(r=>(r?.attachments||[]).map(u=>String(u?.text||""))).join(`
|
|
4
|
+
`),l=s.map(j).join(`
|
|
5
|
+
`);return N(t,e,{asked:l})}export{h as figuresIn,N as groundingNote,F as turnGroundingNote,x as unsupportedFigures,A as unsupportedNote};
|
package/capability-endpoints.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventError as q}from"./event.js";const x=Object.freeze(["detect","decide","rerank","embed","stt","tts","search","read","extract","chat","s2s"]),p=Object.freeze(["embedded","container","remote","harness","router","none"]),f=Object.freeze(["none","loopback","lan","internet","configurable"]),b=Object.freeze({detect:"/v1/detect",decide:"/v1/decide",rerank:"/v1/rerank",embed:"/v1/embeddings",stt:"/v1/audio/transcriptions",tts:"/v1/audio/speech",search:"/v1/search",read:"/v1/read",extract:"/v1/extract",chat:"/v1/chat/completions",s2s:"/v1/audio/conversations"}),g=Object.freeze(new Set(["search","read","extract"])),v=Object.freeze(["day","week","month","year"]),h=Object.freeze(["login","paywall","rate_limited","robots","tdm"]),c=Object.freeze(["markdown","text"]),I="/v1/capabilities",A="over_budget",a=e=>!!e&&typeof e=="object"&&!Array.isArray(e),n=e=>typeof e=="string"&&e.length>0,d=e=>typeof e=="number"&&Number.isFinite(e),t=(e,s)=>{if(!e)throw new q("SHAPE",s)};function k(e,s){if(!a(e)||!(e.calls>0))return null;const r=d(e.p50Ms)?e.p50Ms:0,i=d(e.charsPerSec)&&e.charsPerSec>0&&d(s)?s/e.charsPerSec*1e3:0;return Math.round(Math.max(r,i))}function _(e,s,r){if(!d(r)||r<=0)return null;const i=k(e,s);return i===null||i<=r?null:{error:{type:A,message:`predicted ${i} ms is over the ${r} ms budget`,predictedMs:i,budgetMs:r}}}function O(e){t(a(e),"detect: body must be an object"),t(typeof e.text=="string","detect: text (string) required");const s={text:e.text};return e.model!=null&&(t(n(e.model),"detect: model must be a non-empty string"),s.model=e.model),e.labels!=null&&(t(Array.isArray(e.labels)&&e.labels.every(n),"detect: labels must be string[]"),s.labels=e.labels),e.budgetMs!=null&&(t(d(e.budgetMs)&&e.budgetMs>=0,"detect: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function w(e,s=null){t(a(e),"detect: response must be an object"),t(Array.isArray(e.entities),"detect: entities[] required"),t(n(e.model),"detect: model required"),t(d(e.ms)&&e.ms>=0,"detect: ms required");for(const r of e.entities)t(a(r)&&n(r.value)&&n(r.type),"detect: entity needs value and type"),t(Number.isInteger(r.start)&&Number.isInteger(r.end)&&r.start>=0&&r.end>r.start,`detect: entity ${JSON.stringify(r.value)} needs start < end`),t(d(r.score)&&r.score>=0&&r.score<=1,`detect: entity ${JSON.stringify(r.value)} needs a score in [0,1]`),typeof s=="string"&&t(s.slice(r.start,r.end)===r.value,`detect: entity ${JSON.stringify(r.value)} is not at ${r.start}–${r.end} of the text`);return e}const m=e=>{if(!n(e))return!1;try{const s=new URL(e);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}};function E(e){t(a(e),"search: body must be an object"),t(n(e.q)&&e.q.trim().length>0,"search: q (non-empty string) required");const s={q:e.q.trim()};return e.limit!=null&&(t(Number.isInteger(e.limit)&&e.limit>=1&&e.limit<=50,"search: limit must be an integer 1–50"),s.limit=e.limit),e.lang!=null&&(t(n(e.lang)&&/^[a-z]{2}(-[A-Za-z]{2})?$/.test(e.lang),"search: lang must be a BCP-47 tag like en or en-US"),s.lang=e.lang),e.site!=null&&(t(n(e.site)&&!/[\s/]/.test(e.site),"search: site must be a hostname"),s.site=e.site.toLowerCase()),e.freshness!=null&&(t(v.includes(e.freshness),`search: freshness must be one of ${v.join(", ")}`),s.freshness=e.freshness),e.read!=null&&(t(Number.isInteger(e.read)&&e.read>=0&&e.read<=10,"search: read must be an integer 0–10"),s.read=e.read),e.provider!=null&&(t(n(e.provider),"search: provider must be a non-empty string"),s.provider=e.provider),e.budgetMs!=null&&(t(d(e.budgetMs)&&e.budgetMs>=0,"search: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function N(e){return t(a(e),"search: response must be an object"),t(Array.isArray(e.results),"search: results[] required"),t(n(e.provider),"search: provider required"),t(d(e.ms)&&e.ms>=0,"search: ms required"),e.results.forEach((s,r)=>{t(a(s)&&s.rank===r+1,`search: result ${r} must carry rank ${r+1}`),t(m(s.url),`search: result ${r+1} needs an absolute http(s) url`),t(n(s.title),`search: result ${r+1} needs a title`),t(typeof s.snippet=="string",`search: result ${r+1} needs a snippet (may be empty)`),s.read!=null&&S(s.read)}),e}function C(e){t(a(e),"read: body must be an object"),t(m(e.url),"read: url (absolute http(s)) required");const s={url:e.url,format:"markdown"};return e.format!=null&&(t(c.includes(e.format),`read: format must be one of ${c.join(", ")}`),s.format=e.format),e.maxChars!=null&&(t(Number.isInteger(e.maxChars)&&e.maxChars>=200,"read: maxChars must be an integer ≥ 200"),s.maxChars=e.maxChars),e.snippet!=null&&(t(typeof e.snippet=="string","read: snippet must be a string"),s.snippet=e.snippet),e.provider!=null&&(t(n(e.provider),"read: provider must be a non-empty string"),s.provider=e.provider),e.budgetMs!=null&&(t(d(e.budgetMs)&&e.budgetMs>=0,"read: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function S(e){t(a(e),"read: response must be an object"),t(m(e.url),"read: url (absolute, where the page landed) required"),t(typeof e.title=="string","read: title (string, may be empty) required"),t(c.includes(e.format),"read: format required");const s=e[e.format];t(typeof s=="string",`read: ${e.format} (string) required`),t(Number.isInteger(e.chars)&&e.chars===s.length,"read: chars must equal the content length"),t(typeof e.truncated=="boolean","read: truncated (boolean) required"),t(n(e.provider),"read: provider required"),t(d(e.ms)&&e.ms>=0,"read: ms required"),t(Array.isArray(e.sections),"read: sections[] required");for(const r of e.sections)t(a(r)&&n(r.id)&&n(r.heading),"read: section needs id and heading"),t(Number.isInteger(r.level)&&r.level>=1&&r.level<=6,`read: section ${r.id} needs level 1–6`),t(Number.isInteger(r.offset)&&r.offset>=0&&r.offset<=s.length,`read: section ${r.id} offset must index the content`);return e.restricted!=null&&t(a(e.restricted)&&h.includes(e.restricted.reason),`read: restricted.reason must be one of ${h.join(", ")}`),e}const $=Object.freeze(["choice","score","noul"]),M=/^[A-Za-z_][A-Za-z0-9_]*$/;function D(e){t(a(e),"decide: body must be an object"),t(n(e.state),"decide: state (non-empty string) required"),t(a(e.questions)&&Object.keys(e.questions).length>0,"decide: questions {} required");const s={};for(const[i,u]of Object.entries(e.questions)){t(M.test(i),`decide: question key ${JSON.stringify(i)} must be an identifier`),t(a(u)&&$.includes(u.type),`decide: question ${i}.type must be one of ${$.join(", ")}`),t(n(u.instructions),`decide: question ${i} needs instructions`);const l={type:u.type,instructions:u.instructions};u.type==="noul"?t(u.options==null,`decide: question ${i}: a noul has no options`):(t(Array.isArray(u.options)&&u.options.length>=2&&u.options.length<=255,`decide: question ${i}.options needs 2–255 entries`),l.options=u.options.map(o=>n(o)?{value:o}:(t(a(o)&&n(o.value),`decide: question ${i}: an option is a string or { value, describe? }`),o.describe!=null?{value:o.value,describe:String(o.describe)}:{value:o.value})),t(new Set(l.options.map(o=>o.value)).size===l.options.length,`decide: question ${i}.options must be distinct`)),s[i]=l}const r={state:e.state,questions:s};return e.model!=null&&(t(n(e.model),"decide: model must be a non-empty string"),r.model=e.model),e.budgetMs!=null&&(t(d(e.budgetMs)&&e.budgetMs>=0,"decide: budgetMs must be a number ≥ 0"),r.budgetMs=e.budgetMs),r}function z(e,s=null){t(a(e),"decide: response must be an object"),t(a(e.answers),"decide: answers {} required"),t(n(e.model),"decide: model required"),t(d(e.ms)&&e.ms>=0,"decide: ms required"),e.calibrated!=null&&t(typeof e.calibrated=="boolean","decide: calibrated must be a boolean");const r=i=>d(i)&&i>=0&&i<=1;for(const i of Object.keys(s?s.questions:e.answers)){const u=e.answers[i];t(a(u),`decide: answer ${i} missing`),t(r(u.p),`decide: answer ${i}.p must be in [0,1]`),t(Array.isArray(u.options)&&u.options.every(o=>a(o)&&o.value!==void 0&&r(o.p)),`decide: answer ${i}.options must be [{ value, p }]`),u.confidence!=null&&t(r(u.confidence),`decide: answer ${i}.confidence must be in [0,1]`);const l=s?.questions?.[i];l?.type==="choice"&&t(l.options.some(o=>o.value===u.value),`decide: answer ${i}.value must be one of the options`),l?.type==="noul"&&t(typeof u.value=="boolean",`decide: answer ${i}.value must be a boolean`),l?.type==="score"&&t(d(u.value),`decide: answer ${i}.value must be a number`)}return e}function P(e){t(a(e),"rerank: body must be an object"),t(n(e.query),"rerank: query (non-empty string) required"),t(Array.isArray(e.documents)&&e.documents.length>=1&&e.documents.length<=1e3&&e.documents.every(r=>typeof r=="string"),"rerank: documents must be 1–1000 strings");const s={query:e.query,documents:e.documents.slice()};return e.top_n!=null&&(t(Number.isInteger(e.top_n)&&e.top_n>=1,"rerank: top_n must be an integer ≥ 1"),s.top_n=e.top_n),e.model!=null&&(t(n(e.model),"rerank: model must be a non-empty string"),s.model=e.model),e.budgetMs!=null&&(t(d(e.budgetMs)&&e.budgetMs>=0,"rerank: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function T(e,s=null){t(a(e),"rerank: response must be an object"),t(Array.isArray(e.results),"rerank: results[] required"),t(n(e.model),"rerank: model required"),t(d(e.ms)&&e.ms>=0,"rerank: ms required");const r=s?s.documents.length:1/0,i=new Set;let u=1/0;return e.results.forEach((l,o)=>{t(a(l)&&Number.isInteger(l.index)&&l.index>=0&&l.index<r,`rerank: result ${o} needs an index into the documents`),t(!i.has(l.index),`rerank: index ${l.index} listed twice`),i.add(l.index),t(d(l.relevance_score),`rerank: result ${o} needs relevance_score`),t(l.relevance_score<=u,"rerank: results must be ordered best first"),u=l.relevance_score}),s?.top_n!=null&&t(e.results.length<=s.top_n,`rerank: more than top_n (${s.top_n}) results`),e}function y(e){t(a(e),"capabilities: response must be an object"),t(Array.isArray(e.capabilities),"capabilities: capabilities[] required"),t(a(e.server)&&n(e.server.name)&&n(e.server.version),"capabilities: server {name, version} required");const s=new Set;for(const r of e.capabilities)t(a(r)&&x.includes(r.id),`capabilities: unknown capability id ${JSON.stringify(r?.id)}`),t(!s.has(r.id),`capabilities: ${r.id} listed twice`),s.add(r.id),t(r.route===b[r.id],`capabilities: ${r.id} must be served at ${b[r.id]}`),g.has(r.id)?(t(Array.isArray(r.providers)&&r.providers.length>0&&r.providers.every(n),`capabilities: ${r.id}.providers must be a non-empty string[]`),r.default!=null&&t(r.providers.includes(r.default),`capabilities: ${r.id}.default must be one of its providers`)):(t(Array.isArray(r.models)&&r.models.every(n),`capabilities: ${r.id}.models must be string[]`),r.default!=null&&t(r.models.includes(r.default),`capabilities: ${r.id}.default must be one of its models`)),r.labels!=null&&t(Array.isArray(r.labels)&&r.labels.every(n),`capabilities: ${r.id}.labels must be string[]`),r.stats!=null&&t(a(r.stats)&&(g.has(r.id)||d(r.stats.calls)),`capabilities: ${r.id}.stats needs calls`),r.runtime!=null&&t(a(r.runtime)&&n(r.runtime.state),`capabilities: ${r.id}.runtime needs state`),r.provider!=null&&j(r.provider,r.id);return e}function j(e,s="capability"){return t(a(e)&&p.includes(e.kind),`capabilities: ${s}.provider.kind must be one of ${p.join(", ")}`),e.egress!=null&&t(f.includes(e.egress),`capabilities: ${s}.provider.egress must be one of ${f.join(", ")}`),e.url!=null&&t(n(e.url)&&/^https?:\/\//.test(e.url),`capabilities: ${s}.provider.url must be http(s)`),e.adapter!=null&&t(n(e.adapter),`capabilities: ${s}.provider.adapter must be a string`),e.model!=null&&t(n(e.model),`capabilities: ${s}.provider.model must be a string`),e.label!=null&&t(n(e.label),`capabilities: ${s}.provider.label must be a string`),e}function B(e){return(e?.capabilities||[]).map(s=>({id:s.id,route:s.route,models:s.models||[],providers:s.providers||[],ready:!s.runtime||["ready","external","idle"].includes(s.runtime.state),stats:s.stats||null,labels:s.labels||null}))}export{x as CAPABILITIES,b as CAPABILITY_ROUTES,$ as DECIDE_QUESTION_TYPES,I as DISCOVERY_ROUTE,f as EGRESS_KINDS,A as OVER_BUDGET,g as PROVIDER_CAPABILITIES,p as PROVIDER_KINDS,c as READ_FORMATS,h as READ_RESTRICTIONS,v as SEARCH_FRESHNESS,B as offeredCapabilities,_ as overBudget,k as predictMs,y as validateCapabilitiesResponse,D as validateDecideRequest,z as validateDecideResponse,O as validateDetectRequest,w as validateDetectResponse,j as validateProvider,C as validateReadRequest,S as validateReadResponse,P as validateRerankRequest,T as validateRerankResponse,E as validateSearchRequest,N as validateSearchResponse};
|
|
1
|
+
import{EventError as A}from"./event.js";const k=Object.freeze(["detect","decide","rerank","embed","stt","tts","search","read","extract","chat","s2s"]),p=Object.freeze(["embedded","container","remote","harness","router","none"]),f=Object.freeze(["none","loopback","lan","internet","configurable"]),g=Object.freeze({detect:"/v1/detect",decide:"/v1/decide",rerank:"/v1/rerank",embed:"/v1/embeddings",stt:"/v1/audio/transcriptions",tts:"/v1/audio/speech",search:"/v1/search",read:"/v1/read",extract:"/v1/extract",chat:"/v1/chat/completions",s2s:"/v1/audio/conversations"}),b=Object.freeze(new Set(["search","read","extract"])),v=Object.freeze(["day","week","month","year"]),h=Object.freeze(["login","paywall","rate_limited","robots","tdm"]),c=Object.freeze(["markdown","text"]),w="/v1/capabilities",S="over_budget",a=e=>!!e&&typeof e=="object"&&!Array.isArray(e),n=e=>typeof e=="string"&&e.length>0,o=e=>typeof e=="number"&&Number.isFinite(e),t=(e,s)=>{if(!e)throw new A("SHAPE",s)};function j(e,s){if(!a(e)||!(e.calls>0))return null;const r=o(e.p50Ms)?e.p50Ms:0,i=o(e.charsPerSec)&&e.charsPerSec>0&&o(s)?s/e.charsPerSec*1e3:0;return Math.round(Math.max(r,i))}function E(e,s,r){if(!o(r)||r<=0)return null;const i=j(e,s);return i===null||i<=r?null:{error:{type:S,message:`predicted ${i} ms is over the ${r} ms budget`,predictedMs:i,budgetMs:r}}}function O(e){t(a(e),"detect: body must be an object"),t(typeof e.text=="string","detect: text (string) required");const s={text:e.text};return e.model!=null&&(t(n(e.model),"detect: model must be a non-empty string"),s.model=e.model),e.labels!=null&&(t(Array.isArray(e.labels)&&e.labels.every(n),"detect: labels must be string[]"),s.labels=e.labels),e.budgetMs!=null&&(t(o(e.budgetMs)&&e.budgetMs>=0,"detect: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),e.strict!=null&&(t(typeof e.strict=="boolean","detect: strict must be a boolean"),e.strict&&(s.strict=!0)),s}function N(e,s=null){t(a(e),"detect: response must be an object"),t(Array.isArray(e.entities),"detect: entities[] required"),t(n(e.model),"detect: model required"),t(o(e.ms)&&e.ms>=0,"detect: ms required");for(const r of e.entities)t(a(r)&&n(r.value)&&n(r.type),"detect: entity needs value and type"),t(Number.isInteger(r.start)&&Number.isInteger(r.end)&&r.start>=0&&r.end>r.start,`detect: entity ${JSON.stringify(r.value)} needs start < end`),t(o(r.score)&&r.score>=0&&r.score<=1,`detect: entity ${JSON.stringify(r.value)} needs a score in [0,1]`),typeof s=="string"&&t(s.slice(r.start,r.end)===r.value,`detect: entity ${JSON.stringify(r.value)} is not at ${r.start}–${r.end} of the text`);return e}const m=e=>{if(!n(e))return!1;try{const s=new URL(e);return s.protocol==="http:"||s.protocol==="https:"}catch{return!1}};function C(e){t(a(e),"search: body must be an object"),t(n(e.q)&&e.q.trim().length>0,"search: q (non-empty string) required");const s={q:e.q.trim()};return e.limit!=null&&(t(Number.isInteger(e.limit)&&e.limit>=1&&e.limit<=50,"search: limit must be an integer 1–50"),s.limit=e.limit),e.lang!=null&&(t(n(e.lang)&&/^[a-z]{2}(-[A-Za-z]{2})?$/.test(e.lang),"search: lang must be a BCP-47 tag like en or en-US"),s.lang=e.lang),e.site!=null&&(t(n(e.site)&&!/[\s/]/.test(e.site),"search: site must be a hostname"),s.site=e.site.toLowerCase()),e.freshness!=null&&(t(v.includes(e.freshness),`search: freshness must be one of ${v.join(", ")}`),s.freshness=e.freshness),e.read!=null&&(t(Number.isInteger(e.read)&&e.read>=0&&e.read<=10,"search: read must be an integer 0–10"),s.read=e.read),e.provider!=null&&(t(n(e.provider),"search: provider must be a non-empty string"),s.provider=e.provider),e.budgetMs!=null&&(t(o(e.budgetMs)&&e.budgetMs>=0,"search: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function y(e){return t(a(e),"search: response must be an object"),t(Array.isArray(e.results),"search: results[] required"),t(n(e.provider),"search: provider required"),t(o(e.ms)&&e.ms>=0,"search: ms required"),e.results.forEach((s,r)=>{t(a(s)&&s.rank===r+1,`search: result ${r} must carry rank ${r+1}`),t(m(s.url),`search: result ${r+1} needs an absolute http(s) url`),t(n(s.title),`search: result ${r+1} needs a title`),t(typeof s.snippet=="string",`search: result ${r+1} needs a snippet (may be empty)`),s.read!=null&&R(s.read),s.engine!=null&&t(typeof s.engine=="string",`search: result ${r+1} engine must be a string`),s.via!=null&&t($.includes(s.via),`search: result ${r+1} via must be one of ${$.join(", ")}`)}),e.trail!=null&&(t(a(e.trail)&&x.includes(e.trail.status),`search: trail.status must be one of ${x.join(", ")}`),t(Array.isArray(e.trail.asked)&&e.trail.asked.every(s=>a(s)&&n(s.id)&&["answered","empty","refused"].includes(s.outcome)),"search: trail.asked[] needs { id, outcome }"),t(Array.isArray(e.trail.resting)&&e.trail.resting.every(s=>a(s)&&n(s.id)&&o(s.until)),"search: trail.resting[] needs { id, until }")),e}const $=Object.freeze(["gateway","searxng","api","page","browser"]),x=Object.freeze(["answered","nothing","blocked","resting","offline","no-engines"]);function z(e){t(a(e),"read: body must be an object"),t(m(e.url),"read: url (absolute http(s)) required");const s={url:e.url,format:"markdown"};return e.format!=null&&(t(c.includes(e.format),`read: format must be one of ${c.join(", ")}`),s.format=e.format),e.maxChars!=null&&(t(Number.isInteger(e.maxChars)&&e.maxChars>=200,"read: maxChars must be an integer ≥ 200"),s.maxChars=e.maxChars),e.snippet!=null&&(t(typeof e.snippet=="string","read: snippet must be a string"),s.snippet=e.snippet),e.provider!=null&&(t(n(e.provider),"read: provider must be a non-empty string"),s.provider=e.provider),e.budgetMs!=null&&(t(o(e.budgetMs)&&e.budgetMs>=0,"read: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function R(e){t(a(e),"read: response must be an object"),t(m(e.url),"read: url (absolute, where the page landed) required"),t(typeof e.title=="string","read: title (string, may be empty) required"),t(c.includes(e.format),"read: format required");const s=e[e.format];t(typeof s=="string",`read: ${e.format} (string) required`),t(Number.isInteger(e.chars)&&e.chars===s.length,"read: chars must equal the content length"),t(typeof e.truncated=="boolean","read: truncated (boolean) required"),t(n(e.provider),"read: provider required"),t(o(e.ms)&&e.ms>=0,"read: ms required"),t(Array.isArray(e.sections),"read: sections[] required");for(const r of e.sections)t(a(r)&&n(r.id)&&n(r.heading),"read: section needs id and heading"),t(Number.isInteger(r.level)&&r.level>=1&&r.level<=6,`read: section ${r.id} needs level 1–6`),t(Number.isInteger(r.offset)&&r.offset>=0&&r.offset<=s.length,`read: section ${r.id} offset must index the content`);return e.restricted!=null&&t(a(e.restricted)&&h.includes(e.restricted.reason),`read: restricted.reason must be one of ${h.join(", ")}`),e}const q=Object.freeze(["choice","score","noul"]),M=/^[A-Za-z_][A-Za-z0-9_]*$/;function D(e){t(a(e),"decide: body must be an object"),t(n(e.state),"decide: state (non-empty string) required"),t(a(e.questions)&&Object.keys(e.questions).length>0,"decide: questions {} required");const s={};for(const[i,l]of Object.entries(e.questions)){t(M.test(i),`decide: question key ${JSON.stringify(i)} must be an identifier`),t(a(l)&&q.includes(l.type),`decide: question ${i}.type must be one of ${q.join(", ")}`),t(n(l.instructions),`decide: question ${i} needs instructions`);const u={type:l.type,instructions:l.instructions};l.type==="noul"?t(l.options==null,`decide: question ${i}: a noul has no options`):(t(Array.isArray(l.options)&&l.options.length>=2&&l.options.length<=255,`decide: question ${i}.options needs 2–255 entries`),u.options=l.options.map(d=>n(d)?{value:d}:(t(a(d)&&n(d.value),`decide: question ${i}: an option is a string or { value, describe? }`),d.describe!=null?{value:d.value,describe:String(d.describe)}:{value:d.value})),t(new Set(u.options.map(d=>d.value)).size===u.options.length,`decide: question ${i}.options must be distinct`)),s[i]=u}const r={state:e.state,questions:s};return e.model!=null&&(t(n(e.model),"decide: model must be a non-empty string"),r.model=e.model),e.budgetMs!=null&&(t(o(e.budgetMs)&&e.budgetMs>=0,"decide: budgetMs must be a number ≥ 0"),r.budgetMs=e.budgetMs),r}function T(e,s=null){t(a(e),"decide: response must be an object"),t(a(e.answers),"decide: answers {} required"),t(n(e.model),"decide: model required"),t(o(e.ms)&&e.ms>=0,"decide: ms required"),e.calibrated!=null&&t(typeof e.calibrated=="boolean","decide: calibrated must be a boolean");const r=i=>o(i)&&i>=0&&i<=1;for(const i of Object.keys(s?s.questions:e.answers)){const l=e.answers[i];t(a(l),`decide: answer ${i} missing`),t(r(l.p),`decide: answer ${i}.p must be in [0,1]`),t(Array.isArray(l.options)&&l.options.every(d=>a(d)&&d.value!==void 0&&r(d.p)),`decide: answer ${i}.options must be [{ value, p }]`),l.confidence!=null&&t(r(l.confidence),`decide: answer ${i}.confidence must be in [0,1]`);const u=s?.questions?.[i];u?.type==="choice"&&t(u.options.some(d=>d.value===l.value),`decide: answer ${i}.value must be one of the options`),u?.type==="noul"&&t(typeof l.value=="boolean",`decide: answer ${i}.value must be a boolean`),u?.type==="score"&&t(o(l.value),`decide: answer ${i}.value must be a number`)}return e}function P(e){t(a(e),"rerank: body must be an object"),t(n(e.query),"rerank: query (non-empty string) required"),t(Array.isArray(e.documents)&&e.documents.length>=1&&e.documents.length<=1e3&&e.documents.every(r=>typeof r=="string"),"rerank: documents must be 1–1000 strings");const s={query:e.query,documents:e.documents.slice()};return e.top_n!=null&&(t(Number.isInteger(e.top_n)&&e.top_n>=1,"rerank: top_n must be an integer ≥ 1"),s.top_n=e.top_n),e.model!=null&&(t(n(e.model),"rerank: model must be a non-empty string"),s.model=e.model),e.budgetMs!=null&&(t(o(e.budgetMs)&&e.budgetMs>=0,"rerank: budgetMs must be a number ≥ 0"),s.budgetMs=e.budgetMs),s}function U(e,s=null){t(a(e),"rerank: response must be an object"),t(Array.isArray(e.results),"rerank: results[] required"),t(n(e.model),"rerank: model required"),t(o(e.ms)&&e.ms>=0,"rerank: ms required");const r=s?s.documents.length:1/0,i=new Set;let l=1/0;return e.results.forEach((u,d)=>{t(a(u)&&Number.isInteger(u.index)&&u.index>=0&&u.index<r,`rerank: result ${d} needs an index into the documents`),t(!i.has(u.index),`rerank: index ${u.index} listed twice`),i.add(u.index),t(o(u.relevance_score),`rerank: result ${d} needs relevance_score`),t(u.relevance_score<=l,"rerank: results must be ordered best first"),l=u.relevance_score}),s?.top_n!=null&&t(e.results.length<=s.top_n,`rerank: more than top_n (${s.top_n}) results`),e}function B(e){t(a(e),"capabilities: response must be an object"),t(Array.isArray(e.capabilities),"capabilities: capabilities[] required"),t(a(e.server)&&n(e.server.name)&&n(e.server.version),"capabilities: server {name, version} required");const s=new Set;for(const r of e.capabilities)t(a(r)&&k.includes(r.id),`capabilities: unknown capability id ${JSON.stringify(r?.id)}`),t(!s.has(r.id),`capabilities: ${r.id} listed twice`),s.add(r.id),t(r.route===g[r.id],`capabilities: ${r.id} must be served at ${g[r.id]}`),b.has(r.id)?(t(Array.isArray(r.providers)&&r.providers.length>0&&r.providers.every(n),`capabilities: ${r.id}.providers must be a non-empty string[]`),r.default!=null&&t(r.providers.includes(r.default),`capabilities: ${r.id}.default must be one of its providers`)):(t(Array.isArray(r.models)&&r.models.every(n),`capabilities: ${r.id}.models must be string[]`),r.default!=null&&t(r.models.includes(r.default),`capabilities: ${r.id}.default must be one of its models`)),r.labels!=null&&t(Array.isArray(r.labels)&&r.labels.every(n),`capabilities: ${r.id}.labels must be string[]`),r.stats!=null&&t(a(r.stats)&&(b.has(r.id)||o(r.stats.calls)),`capabilities: ${r.id}.stats needs calls`),r.runtime!=null&&t(a(r.runtime)&&n(r.runtime.state),`capabilities: ${r.id}.runtime needs state`),r.provider!=null&&I(r.provider,r.id);return e}function I(e,s="capability"){return t(a(e)&&p.includes(e.kind),`capabilities: ${s}.provider.kind must be one of ${p.join(", ")}`),e.egress!=null&&t(f.includes(e.egress),`capabilities: ${s}.provider.egress must be one of ${f.join(", ")}`),e.url!=null&&t(n(e.url)&&/^https?:\/\//.test(e.url),`capabilities: ${s}.provider.url must be http(s)`),e.adapter!=null&&t(n(e.adapter),`capabilities: ${s}.provider.adapter must be a string`),e.model!=null&&t(n(e.model),`capabilities: ${s}.provider.model must be a string`),e.label!=null&&t(n(e.label),`capabilities: ${s}.provider.label must be a string`),e}function H(e){return(e?.capabilities||[]).map(s=>({id:s.id,route:s.route,models:s.models||[],providers:s.providers||[],ready:!s.runtime||["ready","external","idle"].includes(s.runtime.state),stats:s.stats||null,labels:s.labels||null}))}export{k as CAPABILITIES,g as CAPABILITY_ROUTES,q as DECIDE_QUESTION_TYPES,w as DISCOVERY_ROUTE,f as EGRESS_KINDS,S as OVER_BUDGET,b as PROVIDER_CAPABILITIES,p as PROVIDER_KINDS,c as READ_FORMATS,h as READ_RESTRICTIONS,v as SEARCH_FRESHNESS,x as SEARCH_TRAIL_STATUSES,$ as SEARCH_VIAS,H as offeredCapabilities,E as overBudget,j as predictMs,B as validateCapabilitiesResponse,D as validateDecideRequest,T as validateDecideResponse,O as validateDetectRequest,N as validateDetectResponse,I as validateProvider,z as validateReadRequest,R as validateReadResponse,P as validateRerankRequest,U as validateRerankResponse,C as validateSearchRequest,y as validateSearchResponse};
|
package/capability-uses.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CAPABILITIES as
|
|
1
|
+
import{CAPABILITIES as i}from"./capability-endpoints.js";const n=Object.freeze({chat:[{id:"chat",label:"Chat",what:"answers and drafts in the thread"},{id:"notes",label:"Notes",what:"the co-writer and the note actions"},{id:"meetings",label:"Meetings",what:"the running summary, insights and monitors"},{id:"jobs",label:"Jobs & teams",what:"scheduled and triggered work, team runs"}],stt:[{id:"dictation",label:"Dictation",what:"speaking into a composer"},{id:"voice",label:"Voice conversation",what:"talking with the assistant"},{id:"meetings",label:"Meetings",what:"the audio scribe — what is playing and the room"}],tts:[{id:"read-aloud",label:"Read aloud",what:"a reply spoken on request"},{id:"voice",label:"Voice conversation",what:"the assistant’s replies spoken"}],detect:[{id:"redaction",label:"Redaction",what:"names, places and secrets replaced before a model sees them"},{id:"fast-path",label:"Fast path",what:"an extraction asked in chat answered without a language model"}],decide:[{id:"routing",label:"Model routing",what:"which model a message goes to, when the decision model is set to route Auto (Routing › Decision model routes Auto)"},{id:"fast-path",label:"Fast path",what:"a classification asked in chat answered without a language model"},{id:"lookups",label:"What to look up",what:"whether a message needs the web, the weather or your own data — and what to search — before a small model answers"},{id:"tools",label:"Tools for the model",what:"a turn’s decide tool, when the model asks for a typed judgement"},{id:"mcp",label:"MCP tool choice",what:"which server’s tools a message needs"},{id:"speaker-names",label:"Speaker naming",what:"“speaker 2 must be Priya” read from a chat message"},{id:"teams",label:"Teams",what:"the assignments a team run makes"}],rerank:[{id:"search",label:"Search",what:"history and web results ordered by relevance"},{id:"tools",label:"Tools for the model",what:"a turn’s rerank tool"},{id:"mcp",label:"MCP tool choice",what:"the tools a lookup (find) returns from your MCP servers, ordered by meaning as well as words"},{id:"notes",label:"Notes research",what:"sources ordered for a plan note"}],embed:[{id:"search",label:"Semantic search",what:"meaning-based retrieval over notes, chats and meetings"}],search:[{id:"chat",label:"Chat",what:"web search in a turn"},{id:"notes",label:"Notes research",what:"sources for a plan note"}],read:[{id:"chat",label:"Chat",what:"a page read for a turn"},{id:"notes",label:"Notes research",what:"sources read for a note"}],extract:[{id:"attachments",label:"Attachments",what:"documents attached by reference, read by page"}],s2s:[{id:"voice",label:"Voice conversation",what:"speech in, speech out, no text in between"}]});for(const e of i)if(!n[e])throw new Error(`capability-uses: ${e} has no uses listed`);function l(e,a,t){return e?.ui?.capabilityUses?.[a]?.[t]!==!1}function h(e,a){return(n[a]||[]).map(t=>({...t,on:l(e,a,t.id)}))}function c(e,a,t,r){const s={...e?.ui?.capabilityUses||{}},o={...s[a]||{}};return r?delete o[t]:o[t]=!1,Object.keys(o).length?s[a]=o:delete s[a],{ui:{capabilityUses:s}}}export{n as CAPABILITY_USES,c as setUse,l as useAllowed,h as usesOf};
|
package/client-prefs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const c=Object.freeze([{id:"mcpServers",label:"MCP tool servers",path:["mcpServers"],kind:"array"},{id:"skills",label:"Skills",path:["skills"],kind:"array"},{id:"skillDirs",label:"Skill folders",path:["ui","skillDirs"],kind:"array"},{id:"recipes",label:"Recipes",path:["recipes"],kind:"array"},{id:"teams",label:"Teams",path:["teams"],kind:"array"},{id:"agents",label:"Agents",path:["agentPool"],kind:"array"},{id:"connections",label:"Connections",path:["connections"],kind:"array"},{id:"projects",label:"Projects",path:["projects"],kind:"array"},{id:"webSearch",label:"Web search",path:["ui","webSearch"],kind:"object"},{id:"tools",label:"Tools",path:null,kind:"object",keys:["mcpToolsMode","maxToolsPerTurn","maxToolRoundsPerTurn","historyTools","historyContextMode","dataDispatch","toolResultMaxChars"]},{id:"endpoints",label:"Models",path:["endpoints"],kind:"array"},{id:"agentTools",label:"Coding Agents",path:null,kind:"object",rootKeys:["agents","removedBuiltinAgents"]},{id:"freeSlots",label:"Free plan picks",path:null,kind:"object",rootKeys:["freeEndpointId","freeAgentId"]},{id:"routing",label:"Model routing",path:["ui","routing"],kind:"object"},{id:"capabilityUses",label:"Where models may be used",path:["ui","capabilityUses"],kind:"object"},{id:"general",label:"General",path:null,kind:"object",keys:["theme","language","sendOnEnter","streamResponses","autoAttachActiveTab","autocomplete","settingsOpen"]},{id:"identity",label:"Identity",path:null,kind:"object",rootKeys:["selfName"]},{id:"suggestions",label:"Smart suggestions",path:["ui","suggestions"],kind:"object"},{id:"topics",label:"Topic extraction",path:["ui","topicExtraction"],kind:"object"},{id:"memory",label:"Memory",path:["ui","memory"],kind:"object"},{id:"notes",label:"Notes",path:["ui","notes"],kind:"object"},{id:"speech",label:"Speech",path:null,kind:"object",keys:["dictation","capture","scribeLive"]},{id:"warmSearch",label:"Gateway search index",path:["ui","warmSearch"],kind:"object"},{id:"recall",label:"Search & indexing",path:["ui","recall"],kind:"object"},{id:"voice",label:"Voice",path:["ui","voice"],kind:"object"},{id:"watch",label:"Watch",path:["ui","watch"],kind:"object"},{id:"meetings",label:"Meetings",path:null,kind:"object",keys:["meetingWindowMin","liveNotesIntervalMin","alertSound","meetingSummaryStyle","meetingAutoOpen"]},{id:"monitors",label:"Live monitors",path:["ui","monitors"],kind:"object"},{id:"redaction",label:"Redaction (client-side)",path:["ui","piiRedaction"],kind:"object"},{id:"internalSites",label:"Internal sites",path:["privacy"],kind:"object"},{id:"pageActions",label:"Act on page",path:null,kind:"object",browserOnly:!0,keys:["pageActions","pageActionsCdp","pageActionsDevJs","pageActionConfirm","pageSites"]},{id:"webllm",label:"In-browser model",path:null,kind:"object",browserOnly:!0,keys:["webllmBackground"],rootKeys:["webllmCustomModels"]}]),f=Object.freeze(c.map(t=>t.id)),m=Object.freeze(c.filter(t=>!t.browserOnly).map(t=>t.id));function g(t){return c.find(o=>o.id===t)}const s=t=>t===void 0?void 0:JSON.parse(JSON.stringify(t));function h(t,o){let e=t;for(const i of o){if(!e||typeof e!="object")return;e=e[i]}return e}function k(t,o,e){let i=t;for(let a=0;a<o.length-1;a+=1){const r=o[a];(!i[r]||typeof i[r]!="object")&&(i[r]={}),i=i[r]}i[o[o.length-1]]=e}function y(t,o){const e=c.find(n=>n.id===o);if(!e||!t)return;if(e.path)return s(h(t,e.path));const i=t.ui||{},a={};let r=!1;for(const n of e.keys||[])i[n]!==void 0&&(a[n]=s(i[n]),r=!0);for(const n of e.rootKeys||[])t[n]!==void 0&&(a[n]=s(t[n]),r=!0);return r?a:void 0}function j(t){const o={};for(const e of c){const i=y(t,e.id);i!==void 0&&(o[e.id]=i)}return o}function S(t,o){const e=s(t||{})||{};for(const[i,a]of Object.entries(o||{})){const r=c.find(n=>n.id===i);if(!(!r||a===void 0)){if(r.path){k(e,r.path,s(a));continue}(!e.ui||typeof e.ui!="object")&&(e.ui={});for(const n of r.keys||[])a&&a[n]!==void 0&&(e.ui[n]=s(a[n]));for(const n of r.rootKeys||[])a&&a[n]!==void 0&&(e[n]=s(a[n]))}}return e}function b(t){const o=e=>Array.isArray(e)?e.map(o):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(i=>[i,o(e[i])])):e;try{return JSON.stringify(o(t))}catch{return String(t)}}function O(t={},o={}){const e={},i=[],a=[],r=new Set([...Object.keys(t||{}),...Object.keys(o||{})]);for(const n of r){const l=t?.[n],d=o?.[n],u=Number(l?.updatedAt)||0,p=Number(d?.updatedAt)||0;if(d&&(!l||p>u)){e[n]={value:s(d.value),updatedAt:p},(!l||b(l.value)!==b(d.value))&&i.push(n);continue}l&&(e[n]={value:s(l.value),updatedAt:u},(!d||u>p)&&a.push(n))}return{merged:e,fromRemote:i,fromLocal:a}}function A(t,o={},{now:e=Date.now()}={}){const i={};for(const[a,r]of Object.entries(t||{})){if(!f.includes(a))continue;const n=o?.[a];n&&n.hash===b(r)||(i[a]={value:s(r),updatedAt:e})}return i}export{m as DESKTOP_SECTION_IDS,c as PREF_SECTIONS,f as PREF_SECTION_IDS,S as applySections,A as changedSections,O as mergeStamped,j as pickSections,b as sectionHash,g as sectionSpec,y as sectionValue};
|
|
1
|
+
const c=Object.freeze([{id:"mcpServers",label:"MCP tool servers",path:["mcpServers"],kind:"array"},{id:"skills",label:"Skills",path:["skills"],kind:"array"},{id:"skillDirs",label:"Skill folders",path:["ui","skillDirs"],kind:"array"},{id:"recipes",label:"Recipes",path:["recipes"],kind:"array"},{id:"teams",label:"Teams",path:["teams"],kind:"array"},{id:"agents",label:"Agents",path:["agentPool"],kind:"array"},{id:"connections",label:"Connections",path:["connections"],kind:"array"},{id:"projects",label:"Projects",path:["projects"],kind:"array"},{id:"webSearch",label:"Web search",path:["ui","webSearch"],kind:"object"},{id:"tools",label:"Tools",path:null,kind:"object",keys:["mcpToolsMode","maxToolsPerTurn","maxToolRoundsPerTurn","historyTools","historyContextMode","dataDispatch","toolResultMaxChars","turn"]},{id:"endpoints",label:"Models",path:["endpoints"],kind:"array"},{id:"agentTools",label:"Coding Agents",path:null,kind:"object",rootKeys:["agents","removedBuiltinAgents"]},{id:"freeSlots",label:"Free plan picks",path:null,kind:"object",rootKeys:["freeEndpointId","freeAgentId"]},{id:"routing",label:"Model routing",path:["ui","routing"],kind:"object"},{id:"capabilityUses",label:"Where models may be used",path:["ui","capabilityUses"],kind:"object"},{id:"general",label:"General",path:null,kind:"object",keys:["theme","language","sendOnEnter","streamResponses","autoAttachActiveTab","autocomplete","settingsOpen"]},{id:"identity",label:"Identity",path:null,kind:"object",rootKeys:["selfName"]},{id:"suggestions",label:"Smart suggestions",path:["ui","suggestions"],kind:"object"},{id:"topics",label:"Topic extraction",path:["ui","topicExtraction"],kind:"object"},{id:"memory",label:"Memory",path:["ui","memory"],kind:"object"},{id:"notes",label:"Notes",path:["ui","notes"],kind:"object"},{id:"speech",label:"Speech",path:null,kind:"object",keys:["dictation","capture","scribeLive"]},{id:"warmSearch",label:"Gateway search index",path:["ui","warmSearch"],kind:"object"},{id:"recall",label:"Search & indexing",path:["ui","recall"],kind:"object"},{id:"voice",label:"Voice",path:["ui","voice"],kind:"object"},{id:"watch",label:"Watch",path:["ui","watch"],kind:"object"},{id:"meetings",label:"Meetings",path:null,kind:"object",keys:["meetingWindowMin","liveNotesIntervalMin","alertSound","meetingSummaryStyle","meetingAutoOpen"]},{id:"monitors",label:"Live monitors",path:["ui","monitors"],kind:"object"},{id:"redaction",label:"Redaction (client-side)",path:["ui","piiRedaction"],kind:"object"},{id:"internalSites",label:"Internal sites",path:["privacy"],kind:"object"},{id:"pageActions",label:"Act on page",path:null,kind:"object",browserOnly:!0,keys:["pageActions","pageActionsCdp","pageActionsDevJs","pageActionConfirm","pageSites"]},{id:"webllm",label:"In-browser model",path:null,kind:"object",browserOnly:!0,keys:["webllmBackground"],rootKeys:["webllmCustomModels"]}]),f=Object.freeze(c.map(t=>t.id)),m=Object.freeze(c.filter(t=>!t.browserOnly).map(t=>t.id));function g(t){return c.find(o=>o.id===t)}const s=t=>t===void 0?void 0:JSON.parse(JSON.stringify(t));function h(t,o){let e=t;for(const i of o){if(!e||typeof e!="object")return;e=e[i]}return e}function k(t,o,e){let i=t;for(let a=0;a<o.length-1;a+=1){const r=o[a];(!i[r]||typeof i[r]!="object")&&(i[r]={}),i=i[r]}i[o[o.length-1]]=e}function y(t,o){const e=c.find(n=>n.id===o);if(!e||!t)return;if(e.path)return s(h(t,e.path));const i=t.ui||{},a={};let r=!1;for(const n of e.keys||[])i[n]!==void 0&&(a[n]=s(i[n]),r=!0);for(const n of e.rootKeys||[])t[n]!==void 0&&(a[n]=s(t[n]),r=!0);return r?a:void 0}function j(t){const o={};for(const e of c){const i=y(t,e.id);i!==void 0&&(o[e.id]=i)}return o}function S(t,o){const e=s(t||{})||{};for(const[i,a]of Object.entries(o||{})){const r=c.find(n=>n.id===i);if(!(!r||a===void 0)){if(r.path){k(e,r.path,s(a));continue}(!e.ui||typeof e.ui!="object")&&(e.ui={});for(const n of r.keys||[])a&&a[n]!==void 0&&(e.ui[n]=s(a[n]));for(const n of r.rootKeys||[])a&&a[n]!==void 0&&(e[n]=s(a[n]))}}return e}function b(t){const o=e=>Array.isArray(e)?e.map(o):e&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(i=>[i,o(e[i])])):e;try{return JSON.stringify(o(t))}catch{return String(t)}}function O(t={},o={}){const e={},i=[],a=[],r=new Set([...Object.keys(t||{}),...Object.keys(o||{})]);for(const n of r){const l=t?.[n],d=o?.[n],u=Number(l?.updatedAt)||0,p=Number(d?.updatedAt)||0;if(d&&(!l||p>u)){e[n]={value:s(d.value),updatedAt:p},(!l||b(l.value)!==b(d.value))&&i.push(n);continue}l&&(e[n]={value:s(l.value),updatedAt:u},(!d||u>p)&&a.push(n))}return{merged:e,fromRemote:i,fromLocal:a}}function A(t,o={},{now:e=Date.now()}={}){const i={};for(const[a,r]of Object.entries(t||{})){if(!f.includes(a))continue;const n=o?.[a];n&&n.hash===b(r)||(i[a]={value:s(r),updatedAt:e})}return i}export{m as DESKTOP_SECTION_IDS,c as PREF_SECTIONS,f as PREF_SECTION_IDS,S as applySections,A as changedSections,O as mergeStamped,j as pickSections,b as sectionHash,g as sectionSpec,y as sectionValue};
|
package/context-attachments.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{makeSourceStore as
|
|
1
|
+
import{makeSourceStore as p,manifestText as m,readSource as x,approxTokens as h}from"./sources-retrieval.js";function y(r){const t=String(r||"").trim();return t?`<presence>
|
|
2
2
|
${t}
|
|
3
|
-
</presence>`:""}function d(r){let t=r.content||"";const s=(r.attachments||[]).filter(e=>e.kind!=="image"),n=e=>e.kind==="prefetch"||e.inline,i=s.filter(n),a=s.filter(e=>!n(e)),c=e=>{const u=`[${e.kind||"context"}] ${e.title||e.url||""}`.trim();return`<context source="${(e.url||e.title||"").replace(/"/g,"")}">
|
|
3
|
+
</presence>`:""}function d(r){let t=r.content||"";const s=(r.attachments||[]).filter(e=>e.kind!=="image"),n=e=>e.kind==="prefetch"||e.inline||e.before,i=s.filter(n),a=s.filter(e=>!n(e)),c=e=>{const u=`[${e.kind||"context"}] ${e.title||e.url||""}`.trim();return`<context source="${(e.url||e.title||"").replace(/"/g,"")}">
|
|
4
4
|
# ${u}
|
|
5
5
|
${e.text||""}
|
|
6
6
|
</context>`};if(i.length&&(t=`${i.map(c).join(`
|
|
@@ -13,8 +13,8 @@ ${t}`.trim()),a.length){const e=a.map(c).join(`
|
|
|
13
13
|
|
|
14
14
|
${e}`:e}const o=y(r.presence);return o&&(t=t?`${t}
|
|
15
15
|
|
|
16
|
-
${o}`:o),t}function T(r){return r.filter(t=>t.role==="user"||t.role==="assistant").map(t=>({role:t.role,content:d(t)}))}function k(r){return(r.attachments||[]).filter(t=>t.kind==="image"&&t.dataUrl)}function
|
|
16
|
+
${o}`:o),t}function T(r){return r.filter(t=>t.role==="user"||t.role==="assistant").map(t=>({role:t.role,content:d(t)}))}function k(r){return(r.attachments||[]).filter(t=>t.kind==="image"&&t.dataUrl)}function b(r,t){return r.filter(s=>s.role==="user"||s.role==="assistant").map(s=>{const n=d(s),i=s.role==="user"?k(s):[];if(i.length===0)return{role:s.role,content:n};if(t==="anthropic"){const c=[];for(const o of i){const e=/^data:([^;]+);base64,(.+)$/s.exec(o.dataUrl);e&&c.push({type:"image",source:{type:"base64",media_type:e[1],data:e[2]}})}return n&&c.push({type:"text",text:n}),{role:"user",content:c.length?c:n}}const a=[];n&&a.push({type:"text",text:n});for(const c of i)a.push({type:"image_url",image_url:{url:c.dataUrl}});return{role:"user",content:a.length?a:n}})}function O(r,t,{minTokens:s=700}={}){if(!t?.specs?.length)return null;const n=[];for(const o of r||[])for(const e of o?.attachments||[])e?.kind==="image"||!e?.text||e.kind!=="prefetch"&&e.kind!=="path"&&(e.inline||n.push(e));if(!n.length)return null;const i=p(n.map(o=>({kind:o.kind||"context",title:o.title,url:o.url,text:o.text})));if(i.tokens<s)return null;const a=new Map(n.map((o,e)=>[o,i.entries[e]?.id]));return{messages:(r||[]).map(o=>o?.attachments?.some(e=>a.get(e))?{...o,attachments:o.attachments.map(e=>{const u=a.get(e);return u?{...e,text:`(not included — read with \`source\`: id ${u}, ~${h(e.text)} tokens)`}:e})}:o),store:i}}const $={name:"source",description:"Read an attached source (a page, tab, selection or file the user attached) or something this conversation already fetched (an id like f3 from the presence block). Their content is NOT in the conversation — read what you need from here.",parameters:{type:"object",properties:{id:{type:"string",description:"The source id from the manifest, e.g. page-1."},query:{type:"string",description:"What you are looking for. A large source returns the matching sections rather than its first page."}},required:["id"]}};function w(r,t,{fetched:s=[]}={}){const n=t?.entries?.length?t:null,i=Array.isArray(s)&&s.length?p(s):null;if(!n&&!i)return r;const a={...$},c=n?`${m(n)}
|
|
17
17
|
|
|
18
18
|
Their content is NOT in this conversation. Call \`source\` with an id — and a query when the source is large — to read what you need.`:"",o=[r?.system,c].filter(Boolean).join(`
|
|
19
19
|
|
|
20
|
-
`),e=u=>{const l=typeof u=="string"?JSON.parse(u||"{}"):u||{},
|
|
20
|
+
`),e=u=>{const l=typeof u=="string"?JSON.parse(u||"{}"):u||{},f=String(l?.id||"").trim(),g=n?.get?.(f)?n:i?.get?.(f)?i:n||i;return x(g,l)};return{...r,specs:[...r?.specs||[],a],system:o,systemParts:{...r?.systemParts||{},source:h(c)},execute:async(u,l,f)=>u==="source"?JSON.stringify(e(l)):r.execute(u,l,f)}}export{$ as SOURCE_TOOL_SPEC,O as deferAttachedSources,k as imageAttachmentsOf,y as presenceBlock,d as renderContent,T as toChatMessages,b as toMultimodalMessages,w as withSourceTool};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const u=t=>t==null?0:Math.round((typeof t=="string"?t:JSON.stringify(t)).length/4),k=t=>typeof t=="string"?t:Array.isArray(t)?t.map(o=>o?.type==="text"&&o.text||"").join(`
|
|
2
|
+
`):"",L=t=>Array.isArray(t)?t.filter(o=>o&&o.type!=="text").length:0,K=/<context source="[^"]*">\n# \[([\w-]+)\][^\n]*\n[\s\S]*?\n<\/context>/g,W=/<presence>\n[\s\S]*?\n<\/presence>/g,j=/\n*\[Chap\] Likely useful for this message[^\n]*/g;function M(t){const o=String(t||""),c=[];let r=o.replace(K,(l,a)=>(c.push({kind:a==="prefetch"?"fetched":"attached",of:a,tokens:u(l)}),""));r=r.replace(W,l=>(c.push({kind:"presence",tokens:u(l)}),""));let d=0;return r=r.replace(j,l=>(d+=u(l),"")),{words:u(r.trim()),blocks:c,hint:d}}function B(t){const o=String(t||"");return o.trim()?o.split(/\n(?=## )/).map(r=>{const d=(r.match(/^## ([^\n]+)/)||[])[1];return{label:d?d.trim().slice(0,60):"Instructions",tokens:u(r)}}).filter(r=>r.tokens>0):[]}const v=Object.freeze({instructions:"The system prompt: who the assistant is, how to answer, what it may use. Sent on every turn so the model behaves the same way each time.",toolText:"The tools' rules and catalog: which actions exist and when to use them. Sent every turn; the provider caches it.",toolSchemas:"The tool definitions the model can call — kept to one tool (`tools`) so a turn carries one schema, not one per action.",history:'The earlier messages of this conversation, so a follow-up ("how many in south?") is read against what came before.',historyCarried:"Context that rode on earlier messages — fetched results, attachments, presence — kept with them so the model can refer back.",toolExchange:"Tool calls and their results from earlier rounds.",fetched:"Looked up before the model ran (the weather, a search, the page), so it answers instead of calling a tool.",attached:"What the person attached to this message, or the client added as context.",presence:"What exists around the turn (the open page, notes, what was fetched before) — names, not contents.",hint:"The actions likely useful for this message — appended to the message, not the system prompt, so the prompt cache holds.",words:"The person's own words.",agentOwn:"The agent's own context: its system prompt, its built-in tools, its skills and MCP servers, its session. Not sent by us; it reads it every turn.",cached:"Read from the provider's prompt cache — already there, billed at a fraction, and fast."});function H({messages:t=[],tools:o=null,usage:c=null,agent:r=!1,agentContext:d=null}={}){const l=Array.isArray(t)?t:[],a=[],i=(e,n,s,h={})=>{(s>0||h.always)&&a.push({id:e,label:n,tokens:s,why:v[e]||"",...h})},y=l.filter(e=>e?.role==="system").map(e=>k(e.content)).join(`
|
|
3
|
+
|
|
4
|
+
`),b=String(o?.system||""),E=b&&y.includes(b)?y.replace(b,""):y,S=B(E);i("instructions","Instructions (system prompt)",S.reduce((e,n)=>e+n.tokens,0),S.length>1?{items:S}:{}),i("toolText","Tool rules & catalog",u(b));const C=Array.isArray(o?.specs)?o.specs:[];i("toolSchemas",`Tool definitions (${C.length})`,u(C),{count:C.length});const g=l.filter(e=>e&&e.role!=="system");let p=-1;for(let e=g.length-1;e>=0;e--)if(g[e].role==="user"){p=e;break}const q=p>=0?g.slice(0,p):g,I=p>=0?g.slice(p+1):[];let N=0,O=0,A=0,x=0;const T=new Map;for(const e of q){if((e.role==="tool"||e.tool_calls)&&(A+=u(k(e.content))+u(e.tool_calls),e.role==="tool")||e.role!=="user"&&e.role!=="assistant")continue;e.role==="user"&&(x+=1);const n=M(k(e.content));N+=n.words+n.hint;for(const s of n.blocks)O+=s.tokens,T.set(s.of||s.kind,(T.get(s.of||s.kind)||0)+s.tokens)}i("history",`Conversation history (${x} earlier ${x===1?"question":"questions"})`,N,{count:x}),i("historyCarried","Context carried in the history",O,T.size?{items:[...T].map(([e,n])=>({label:e,tokens:n}))}:{});for(const e of I)A+=u(k(e.content))+u(e.tool_calls);if(i("toolExchange","Tool calls & results",A),p>=0){const e=g[p],n=M(k(e.content)),s=m=>n.blocks.filter(f=>f.kind===m),h=m=>m.reduce((f,$)=>f+$.tokens,0);i("fetched","Fetched for this message",h(s("fetched")),{count:s("fetched").length}),i("attached","Attached to this message",h(s("attached")),{count:s("attached").length,...s("attached").length?{items:s("attached").map(m=>({label:m.of,tokens:m.tokens}))}:{}}),i("presence","Presence (what is around the turn)",h(s("presence"))),i("hint","Hint (likely actions)",n.hint),i("words","Your message",n.words,{always:!0,...L(e.content)?{images:L(e.content)}:{}})}const _=a.reduce((e,n)=>e+n.tokens,0),w={rows:a,ours:_};if(c){const e=h=>Math.max(0,Number(h)||0),n=e(c.cacheReadTokens),s=e(c.inputTokens)+n+e(c.cacheWriteTokens);if(s>0&&(w.reported=s,w.cached=n,w.requests=e(c.requests)||e(c.calls)||1,r)){const h=Math.max(0,s-_*w.requests),m=Array.isArray(d)?d.filter(f=>f&&Number(f.tokens)>0).map(f=>({label:String(f.label),tokens:Math.round(Number(f.tokens))})):null;w.agentOwn=h,a.push({id:"agentOwn",label:"The agent's own context",tokens:h,why:v.agentOwn,...m?.length?{items:m}:{}})}}return w}function P(t){const o=[],c=String(t||""),r=c.match(/\*\*Tokens:\*\*\s*([\d.]+)(k|m)?\s*\//i)||[];for(const l of c.split(`
|
|
5
|
+
`)){const a=l.match(/^\|\s*([^|]+?)\s*\|\s*([\d.,]+)\s*(k|m)?\s*\|\s*[\d.]+%\s*\|$/i);if(!a)continue;const i=a[1].trim();if(/deferred|free space|autocompact|^category$/i.test(i))continue;const y=Number(a[2].replace(/,/g,""))*(a[3]?.toLowerCase()==="k"?1e3:a[3]?.toLowerCase()==="m"?1e6:1);y>0&&o.push({label:i,tokens:Math.round(y)})}if(!o.length)return null;const d=r[1]?Math.round(Number(r[1])*(r[2]?.toLowerCase()==="k"?1e3:r[2]?.toLowerCase()==="m"?1e6:1)):o.reduce((l,a)=>l+a.tokens,0);return{items:o,total:d}}export{H as contextBreakdown,P as parseAgentContext,M as splitMessage,B as systemSections};
|
package/context-window.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const d=[[/gpt-4\.1/,1e6],[/gpt-5|o3|o4|o1/,2e5],[/gpt-4o|gpt-4-turbo/,128e3],[/claude-(3|4|5|opus|sonnet|haiku|fable)/,2e5],[/gemini-(1\.5|2|2\.5|3)/,1e6],[/gemini/,1e6],[/deepseek/,128e3],[/mistral-large|mixtral|codestral/,128e3],[/grok/,128e3],[/llama-3\.[1-3]|llama-4/,128e3]];function x(
|
|
1
|
+
const d=[[/^apple-on-device$|apple[-_ ]?foundation/,4096],[/gemini-?nano/,4096]],l=[[/gpt-4\.1/,1e6],[/gpt-5|o3|o4|o1/,2e5],[/gpt-4o|gpt-4-turbo/,128e3],[/claude-(3|4|5|opus|sonnet|haiku|fable)/,2e5],[/gemini-(1\.5|2|2\.5|3)/,1e6],[/gemini/,1e6],[/deepseek/,128e3],[/mistral-large|mixtral|codestral/,128e3],[/grok/,128e3],[/llama-3\.[1-3]|llama-4/,128e3]];function x(n={},t=null){const e=String(n.id||""),r=String(n.model||n.id||"").toLowerCase(),c=t&&(t[a(n)]||t[r]||t[String(n.model||"")]||(n.gateway?0:t[e]));if(Number(c)>0)return Number(c);const i=Number(n.window||n.contextLength||n.contextWindow||0);if(i>0)return i;for(const[o,u]of d)if(o.test(r))return u;if(n.reach==="device"||n.kind==="webllm")return 0;for(const[o,u]of l)if(o.test(r))return u;return 0}function a(n={}){const t=String(n.id||""),e=String(n.model||"");return e?`${t}:${e}`:t}const s=.85,f=8192,p=n=>Number(n)>0&&Number(n)<=f,w=2;function _({promptTokens:n=0,floorTokens:t=0,window:e=0,reserve:r=1024,headroom:c=s}={}){const i=Number(e)||0;if(!i)return{status:"unknown",budget:0,over:0,window:0};const o=Math.max(0,Math.floor(i*c)-Math.max(0,Number(r)||0)),u=Math.max(0,Number(n)||0),m=Math.max(0,Number(t)||0);return u<=o?{status:"ok",budget:o,over:0,window:i}:m<=o?{status:"compact",budget:o,over:u-o,window:i}:{status:"too-big",budget:o,over:m-o,window:i}}function b(n=0){const t=Number(n)||0;return t?t<=8e3?2:t<=32768?4:t<=128e3?8:12:4}function h({floorTokens:n=0,reserve:t=1024,headroom:e=s}={}){const r=Math.max(0,Number(n)||0);return r?Math.ceil((r+Math.max(0,Number(t)||0))/e):0}function N(n){return/context.{0,8}(length|window|size)|context_length_exceeded|prompt is too long|too many tokens|maximum context|exceed.{0,20}context|reduce the (length|number|size)|input is too long|token limit|n_ctx|kv cache|longer than .{0,80}\bwindow\b|exceed.{0,30}\bwindow\b/i.test(String(n?.message||n||""))}export{s as FIT_HEADROOM,f as SMALL_WINDOW,w as SMALL_WINDOW_ROUNDS,_ as fitFor,N as isContextLimitError,p as isSmallWindow,b as keepRecentFor,h as minWindowFor,a as observedKey,x as windowOf};
|
package/engine-pacer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{engineOrder as A,mergeEngineResults as M,offTopic as x,isSearchPage as U}from"./web-search.js";import{tagResults as E,searchStatus as R}from"./search-outcome.js";const S=Object.freeze({gapMs:2e4,firstRestMs:2*6e4,maxRestMs:60*6e4,emptyStrikes:3});function O({status:i=0,timedOut:d=!1,network:o=!1,results:f=[]}={}){return Array.isArray(f)&&f.length?"answered":d||o||i===429||i===403||i>=500||i===-1?"refused":"empty"}function N({now:i=()=>Date.now(),random:d=Math.random,...o}={}){const f={...S,...o},c=new Map,p=n=>c.get(n)||{askedAt:0,empties:0,refusals:0,restUntil:0};function y(n,r){n.refusals+=1,n.restUntil=i()+Math.min(f.maxRestMs,r||f.firstRestMs*2**(n.refusals-1))}return{order(n){const r=i(),u=A(n),a=u.filter(t=>t.kind==="gateway"&&t.enabled!==!1),k=t=>t.kind==="api"&&t.needsKey,s=[u.filter(t=>k(t)&&t.enabled!==!1),u.filter(t=>t.kind!=="gateway"&&!k(t)&&t.enabled!==!1),u.filter(t=>!a.includes(t)&&t.enabled===!1)],m=t=>t.filter(e=>e.kind==="gateway"||p(e.id).restUntil<=r).map(e=>{const l=p(e.id),g=1/(1+l.empties)*(r-l.askedAt<f.gapMs?.1:1);return{e,key:Math.pow(d()||Number.MIN_VALUE,1/g)}}).sort((e,l)=>l.key-e.key).map(({e})=>e);return[...a,...s.flatMap(m)]},record(n,r,{retryAfterMs:u=0}={}){const a={...p(n),askedAt:i()};r==="answered"?(a.empties=0,a.refusals=0,a.restUntil=0):r==="refused"?y(a,u):++a.empties>=f.emptyStrikes&&(a.empties=0,y(a)),c.set(n,a)},resting(){const n=i();return[...c].filter(([,r])=>r.restUntil>n).map(([r,u])=>({id:r,until:u.restUntil}))}}}async function P(i,d,{pacer:o,limit:f=8,signal:c,lastResort:p=null,query:y=""}={}){const n=[],r=[],u=o.order(i),a=async(s,m)=>{let t;try{t=await m(s)}catch{t={network:!0}}const e=Array.isArray(t)?{results:t}:t||{};let l=(Array.isArray(e.results)?e.results:[]).filter(h=>!U(h?.url));const g=s.kind!=="gateway"&&!(s.kind==="api"&&s.needsKey);if(y&&g&&x(l,y)&&(l=[]),c?.aborted)return null;const b=O({...e,results:l});s.kind!=="gateway"&&s.kind!=="tab"&&o.record(s.id,b,{retryAfterMs:e.retryAfterMs});const w={id:s.id,found:l.length,outcome:b};return e.status&&(w.status=e.status),e.timedOut&&(w.timedOut=!0),(e.network||!e.status&&!e.timedOut&&b==="refused")&&(w.network=!0),n.push(w),l.length?E(l,s):null};for(const s of u){if(c?.aborted)break;const m=await a(s,d);if(m){r.push(m);break}}if(!r.length&&typeof p=="function"&&!c?.aborted){const s=await a({id:"browser",kind:"tab"},()=>p(u));s&&r.push(s)}const k={results:M(r,f),asked:n,resting:o.resting()};return{...k,status:R(k)}}function j(i,d=Date.now()){const o=String(i??"").trim();if(!o)return 0;if(/^\d+$/.test(o))return Number(o)*1e3;const f=Date.parse(o);return Number.isFinite(f)?Math.max(0,f-d):0}export{S as PACER_DEFAULTS,O as classifyAnswer,N as createEnginePacer,j as retryAfterMs,P as searchPolitely};
|
package/housekeeping.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{reachOf as
|
|
1
|
+
import{reachOf as f}from"./model-candidates.js";import{isPleasantry as d}from"./tool-need.js";function h(e){return(Array.isArray(e)?e:[e]).some(n=>String(n||"").trim()&&!d(n))}function l(e){if(!e||e.enabled===!1||!e.model||e.kind==="bridge"||e.kind==="webllm")return!1;try{return f(e)==="device"}catch{return!1}}const u=/^apple-on-device$|apple[-_ ]?foundation/i;function s(e){return l(e)&&(e.systemHeld===!0||u.test(String(e.model||"")))}function c(e){const t=(e||[]).filter(l);return t.find(s)||t[0]||null}function y({job:e,conversation:t=null,candidates:n=[],chosen:i=null,userTexts:a=[]}={}){if(!h(a))return{target:null,why:"nothing said yet worth a model",wait:!0};if(i)return{target:i,why:"the model chosen for this in Settings",wait:!1};const o=(n||[]).find(s);if(o)return{target:o,why:"the system's own model on this device — free, nothing leaves, nothing stays loaded",wait:!1};if(t&&t.kind!=="bridge")return{target:t,why:"the conversation's own model",wait:!1};const r=c(n);return r?{target:r,why:"a model on this device — a coding agent pays its whole context on every call",wait:!1}:e==="title"&&t?{target:t,why:"no model on this device — the conversation's own agent, once",wait:!1}:{target:null,why:"no model on this device, and nowhere new to send it",wait:!1}}export{h as hasSubstance,y as housekeepingTarget,l as isLocalHelper,s as isSystemModel,c as lightestLocalHelper};
|