@chatpanel/events 0.392.0 → 0.400.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/agent-session-open.js +1 -1
- package/client-prefs.js +1 -1
- package/index.js +1 -1
- package/mcp-oauth.js +1 -1
- package/meeting-insight-prompts.js +11 -0
- package/note-blank.js +1 -0
- package/note-link.js +1 -0
- package/note-recall.js +7 -0
- package/note-tool.js +2 -2
- package/offers.js +4 -3
- package/package.json +11 -1
- package/prefetch.js +3 -3
- package/sandbox-policy.js +1 -1
- package/settings-registry.js +1 -1
- package/sources-retrieval.js +5 -3
- package/speech-language.js +1 -1
- package/thread-material.js +2 -0
- package/tool-dispatch.js +4 -4
- package/tool-need.js +3 -3
- package/turn-intent.js +3 -3
- package/turn-pipeline.js +3 -3
- package/web-research.js +5 -5
- package/web-search-tool.js +8 -8
package/note-tool.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
const
|
|
1
|
+
const $=[{name:"note",description:"WRITE to the user's Chap notes: create a new note, append to one, or revise one. Use this when the user asks you to save, note down, write up or record something — do NOT try to drive the Notes page with browser tools, and do not hand back text for them to copy. To FIND or READ notes use `find`; this tool only writes. Every write asks the user to confirm, so say what you are saving in your reply.",parameters:{type:"object",properties:{action:{type:"string",enum:["create","append","update"],description:"create a new note, append to the end of one, or revise one."},id:{type:"string",description:"The note to change. Required for append and update; get it from `find`."},title:{type:"string",description:"Title. Used by create, and by update when renaming."},body:{type:"string",description:"Markdown body. The whole note for create/update; use `text` to append."},text:{type:"string",description:"Markdown to add to the end of an existing note (append)."},tags:{type:"array",items:{type:"string"},description:"Optional tags."}},required:["action"]}}],i=(s,h={})=>JSON.stringify({ok:!1,error:s,...h});function v({store:s,confirm:h,onWrote:u=()=>{},agentLabel:c="AI",needsConfirm:m=!0,now:y=Date.now}={}){return async function(w,o={}){if(w!=="note")return i(`Unknown tool "${w}".`);const t=String(o.action||"").trim();if(!["create","append","update"].includes(t))return i(`Unknown action "${t}".`,{actions:["create","append","update"]});const p=String(o.title||"").trim(),a=String(o.body??o.content??o.markdown??(t==="append"?"":o.text)??""),d=String(o.text??(t==="append"?o.content??o.body??"":"")??""),k=new Set(["action","id","title","body","text","content","markdown"]),b=Object.keys(o||{}).filter(e=>!k.has(e)&&typeof o[e]=="string"&&o[e].length>40);if(b.length&&!(t==="append"?d:a).trim())return i(`"${t}" got its text as \`${b[0]}\`, which this tool does not read — send it as \`${t==="append"?"text":"body"}\`. Nothing was written.`);let n=null;if(t!=="create"){const e=String(o.id||"").trim();if(!e)return i(`"${t}" needs the note's id. Use \`find\` to look it up.`);if(n=await s.getNote(e),!n)return i(`No note with id "${e}".`);if(t==="append"&&!d.trim())return i('"append" needs `text`.');if(t==="update"&&!a.trim()&&!p)return i('"update" needs a `body` or a `title`.')}else if(!a.trim()&&!p)return i('"create" needs a `title` or a `body`.');const g=(e,l=60)=>{const r=String(e||"").replace(/\s+/g," ").trim();return r.length>l?`${r.slice(0,l)}…`:r},x=t==="create"?`Create a note “${g(p||a)}”`:t==="append"?`Add ${d.length} characters to your note “${g(n.title||"Untitled")}”`:`Rewrite your note “${g(n.title||"Untitled")}” (the current version is kept)`;if(m&&await h(x)==="deny")return i("The user DECLINED this note write. Do not retry it — stop and ask the user how to proceed.");try{if(t==="create"){const r=await s.createNote({title:p,body:a,attribution:[{by:c,at:y(),from:0,to:a.length}]});return u(r.id,t),JSON.stringify({ok:!0,id:r.id,title:r.title,chars:(r.body||"").length})}if(t==="append"){const r=String(n.body||""),f=r?`${r.replace(/\s+$/,"")}
|
|
2
2
|
|
|
3
|
-
${
|
|
3
|
+
${d}`:d,N=await s.saveNote({...n,body:f,attribution:[...n.attribution||[],{by:c,at:y(),from:r.length,to:f.length}]});return u(n.id,t),JSON.stringify({ok:!0,id:n.id,title:N?.title,chars:f.length,added:d.length})}const e=String(n.body||""),l=await s.saveNote({...n,title:p||n.title,body:a||e,versions:[...n.versions||[],{body:e,attribution:n.attribution||[],at:y(),by:c,label:`before ${c} revised it`}],attribution:[{by:c,at:y(),from:0,to:(a||e).length}]});return u(n.id,t),JSON.stringify({ok:!0,id:n.id,title:l?.title,chars:(a||e).length,previousVersionKept:!0})}catch(e){return i(String(e?.message||e))}}}export{$ as NOTE_TOOL_SPECS,v as makeNoteToolExecutor};
|
package/offers.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
const A=[["US$","USD"],["CA$","CAD"],["C$","CAD"],["AU$","AUD"],["A$","AUD"],["NZ$","NZD"],["HK$","HKD"],["S$","SGD"],["R$","BRL"],["$","USD"],["€","EUR"],["£","GBP"],["¥","JPY"],["₹","INR"],["₩","KRW"]],
|
|
2
|
-
`,e-1)+1;
|
|
3
|
-
`,
|
|
1
|
+
const A=[["US$","USD"],["CA$","CAD"],["C$","CAD"],["AU$","AUD"],["A$","AUD"],["NZ$","NZD"],["HK$","HKD"],["S$","SGD"],["R$","BRL"],["$","USD"],["€","EUR"],["£","GBP"],["¥","JPY"],["₹","INR"],["₩","KRW"]],D=["USD","EUR","GBP","INR","CAD","AUD","JPY","NZD","CHF","SGD","HKD","SEK","NOK","DKK","MXN","BRL","ZAR"],k=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),M=A.map(([t])=>k(t)).join("|"),E=D.join("|"),O=String.raw`\d{1,3}(?:[,. ]\d{3})+(?:[.,]\d{1,2})?|\d+(?:[.,]\d{1,2})?`,N=new RegExp(String.raw`(?<![\p{L}\d])(?:(${M})\s?|(${E})\s)(${O})(?![\d])|(?<![\p{L}\d.,])(${O})\s?(€|£|${E})(?![\p{L}])`,"gu");function I(t){let e=String(t||"").replace(/[ ]/g,"");const a=e.lastIndexOf(","),r=e.lastIndexOf("."),i=a>r&&/,\d{1,2}$/.test(e);i?e=e.replace(/\./g,"").replace(",","."):e=e.replace(/,/g,""),!i&&/^\d{1,3}(\.\d{3})+$/.test(e)&&(e=e.replace(/\./g,""));const s=Number(e);return Number.isFinite(s)?s:NaN}function R(t){const e=String(t||""),a=[];for(const r of e.matchAll(N)){const[i,s,f,p,m,u]=r,h=s?A.find(([l])=>l===s)[1]:f||(u==="€"?"EUR":u==="£"?"GBP":u),o=I(p||m);!(o>0)||o>=1e7||a.push({amount:o,currency:h,raw:i.trim(),index:r.index,end:r.index+i.length})}return a}const L=[["6months",/^\s*(?:\/|per|for|every|a)?\s*(?:6|six)[- ]?(?:months?|mos?\.?)\b/i],["month",/^\s*(?:\/\s*(?:mo|mth|month)\b|per\s+month\b|a\s+month\b|monthly\b|p\/?m\b|\/?\s*mo\.?\b)/i],["year",/^\s*(?:\/\s*(?:yr|year|annum)\b|per\s+(?:year|annum)\b|a\s+year\b|annually\b|yearly\b|p\.?a\.?\b|\/?\s*yr\.?\b)/i],["week",/^\s*(?:\/\s*(?:wk|week)\b|per\s+week\b|a\s+week\b|weekly\b)/i],["night",/^\s*(?:\/\s*night\b|per\s+night\b|a\s+night\b|nightly\b|\/\s*nt\b)/i],["day",/^\s*(?:\/\s*day\b|per\s+day\b|a\s+day\b|daily\b)/i],["hour",/^\s*(?:\/\s*(?:hr|hour)\b|per\s+hour\b|an\s+hour\b|hourly\b)/i],["trip",/^[^.\n]{0,24}?\b(?:round[- ]?trip|return|one[- ]way|roundtrip)\b/i],["person",/^\s*(?:\/\s*(?:person|pp|adult)\b|per\s+(?:person|passenger|traveller|traveler|adult)\b|pp\b)/i]],U=[["6months",/\b(?:6|six)[- ]month(?:s|ly)?\s+(?:premium|rate|cost|price|policy)?[^.\n]{0,20}$/i],["month",/\b(?:monthly|per month|a month)\b[^.\n]{0,24}$/i],["year",/\b(?:annual|annually|yearly|per year|a year)\b[^.\n]{0,24}$/i],["night",/\b(?:nightly|per night)\b[^.\n]{0,24}$/i],["trip",/\b(?:round[- ]?trip|return|one[- ]way)\b[^.\n]{0,24}$/i]],q=[["saving",/\b(?:save|saving|savings(?: of)?|discount(?: of)?|rebate|cash ?back|credit of|reward of)\s*(?:up to\s*)?$/i],["was",/\b(?:was|reg\.?|regular(?:ly)?|list price|msrp|rrp|originally|compare at)\s*:?\s*$/i],["threshold",/\b(?:over|above|orders? (?:of|over)|minimum(?: of)?|min\.?|spend|when you spend|up to|max(?:imum)?(?: of)?|under|below|less than)\s*$/i],["average",/\b(?:averages?|averaging|avg\.?|median|typical(?:ly)?|national average|mean)\b[^.\n$€£]{0,56}$/i],["fee",/\b(?:fee|fees|deposit|surcharge|taxes|tax|shipping|delivery|excess|deductible)\s*(?:of|is|:)?\s*$/i],["from",/\b(?:from|starting (?:at|from)|starts at|as low as|low as|rates from|prices from|fares from)\s*:?\s*$/i]],B=[["saving",/^\s*(?:off|discount|cash ?back|savings?|less|back\b|below\b|cheaper|lower|more than|over\b)/i],["fee",/^\s*(?:fee|deposit|surcharge|deductible|excess|shipping|delivery)\b/i],["average",/^[^.\n]{0,20}\b(?:on average|average)\b/i],["average",/^\s*\)?\s*(?:vs\.?|versus)\s/i]];function C(t,{index:e,end:a}){const r=String(t).slice(a,a+40);for(const[s,f]of L)if(f.test(r))return s;const i=String(t).slice(Math.max(0,e-48),e);for(const[s,f]of U)if(f.test(i))return s;return""}function _(t,{index:e,end:a}){const r=String(t).slice(Math.max(0,e-64),e);for(const[p,m]of q)if(m.test(r))return p;const i=String(t).slice(a,a+30);for(const[p,m]of B)if(m.test(i))return p;const s=String(t),f=Math.max(s.lastIndexOf(`
|
|
2
|
+
`,e-1),s.slice(0,e).search(/[.!?]\s[^.!?]*$/))+1;return F.test(s.slice(Math.max(f,e-200),e))?"saving":/\b(?:vs\.?|versus)\s*$/i.test(r)?"average":/\b(?:on|for|say|e\.g\.,?|imagine|if you (?:pay|spend))\s+an?\s*$/i.test(r)?"example":""}const F=/\b(?:saves?|saving|savings|save up to|cheaper by|knock(?:s|ed)? off|cut(?:s)? (?:the )?(?:price|fare|cost) by)\b/i;function K(t,{index:e,end:a},r=220,i=24){const s=String(t),f=s.lastIndexOf(`
|
|
3
|
+
`,e-1)+1;let p=s.indexOf(`
|
|
4
|
+
`,a);p<0&&(p=s.length);const m=[...s.slice(f,p).matchAll(new RegExp("(?<!\\b\\p{Lu})[.!?](?=\\s)","gu"))].map(b=>f+b.index+1),u=m.filter(b=>b<=e);let h=u.length?u[u.length-1]:f;const o=m.find(b=>b>=a)??p;o-h<i&&u.length&&(h=u.length>1?u[u.length-2]:f);let l=s.slice(h,o);if(l.length>r){const b=e-h,d=Math.max(0,b-Math.floor(r/2));l=l.slice(d,d+r)}return l.replace(/\s+/g," ").replace(/^[\s|*#>•·.-]+/,"").trim()}function P(t){try{return new URL(t).hostname.replace(/^www\./,"").toLowerCase()}catch{return""}}const G=/[\p{L}\p{N}][\p{L}\p{N}'+-]*/gu,x=t=>(String(t||"").toLowerCase().match(G)||[]).filter(e=>e.length>2);function J(t,{url:e="",title:a="",terms:r=[],max:i=8}={}){const s=String(t||""),f=P(e),p=new Set(r.flatMap(x)),m=!p.size||x(`${a} ${s.slice(0,4e3)}`).some(o=>p.has(o)),u=new Set,h=[];for(const o of R(s)){const l=K(s,o),b=_(s,o),d=p.size?x(l).filter(S=>p.has(S)).length:1;if(!d&&!m)continue;const w=`${o.currency}|${o.amount}|${l.slice(0,60)}`;u.has(w)||(u.add(w),h.push({amount:o.amount,currency:o.currency,raw:o.raw,basis:C(s,o),qualifier:b,quote:l,url:e,host:f,title:a,relevance:d}))}return h.map((o,l)=>({o,i:l})).sort((o,l)=>(l.o.relevance>0)-(o.o.relevance>0)||o.i-l.i).slice(0,i).map(({o})=>o)}const Y={month:1,year:1/12,"6months":1/6,week:52/12},H={month:"per month",year:"per year","6months":"per 6 months",week:"per week",night:"per night",day:"per day",hour:"per hour",trip:"per trip",person:"per person","":"one-off price"},T=t=>H[t]??t;function $(t){const e=Y[t.basis];return e?{value:t.amount*e,basis:"month",converted:t.basis!=="month"}:{value:t.amount,basis:t.basis,converted:!1}}const z=["month","trip","night","person","","day","hour"],v=t=>Math.round(t*100);function Q(t=[]){const e=t.filter(n=>n.qualifier===""||n.qualifier==="from"),a=t.filter(n=>n.qualifier==="average"),r=n=>e.reduce((c,g)=>c.set(n(g),(c.get(n(g))||0)+1),new Map),i=r(n=>$(n).basis),s=r(n=>n.currency),f=(n,c=[])=>[...n.entries()].sort((g,y)=>y[1]-g[1]||c.indexOf(g[0])-c.indexOf(y[0]))[0]?.[0],p=f(i,z)??"",m=f(s)??"",u=new Map;for(const n of e){const c=$(n),g=`${n.currency}|${c.basis}|${v(c.value)}`;u.has(g)||u.set(g,new Set),u.get(g).add(n.host)}const h=n=>n.currency===m&&$(n).basis===p,o=n=>{const c=new Set;return n.filter(g=>{const y=`${g.host}|${g.currency}|${v($(g).value)}`;return c.has(y)?!1:(c.add(y),!0)})},l=n=>{const c=$(n);return{...n,value:c.value,converted:c.converted,seenOn:u.get(`${n.currency}|${c.basis}|${v(c.value)}`)?.size||1}},b=(n,c)=>n.value-c.value||c.seenOn-n.seenOn||c.relevance-n.relevance,d=o(e.filter(n=>h(n)&&n.qualifier==="")).map(l).sort(b),w=o(e.filter(n=>h(n)&&n.qualifier==="from")).map(l).sort(b),S=o(e.filter(n=>!h(n))).map(l).sort(b);return{basis:p,currency:m,ranked:d,floors:w,other:S,averages:a}}function W(t,e,a){const r={USD:"$",EUR:"€",GBP:"£",JPY:"¥",INR:"₹",KRW:"₩"}[e],i=t>=100?Math.round(t).toLocaleString("en-US"):t.toFixed(2).replace(/\.00$/,"");return`${r?`${r}${i}`:`${i} ${e}`}${a==="month"?"/mo":a?` ${T(a)}`:""}`}function j(t,e=[]){const a=new Set;for(const r of e)for(const i of R(r)){a.add(`${i.currency}|${v(i.amount)}`);for(const s of[1/12,1/6])a.add(`${i.currency}|~${Math.round(i.amount*s)}`)}return R(t).filter(r=>!a.has(`${r.currency}|${v(r.amount)}`)&&!a.has(`${r.currency}|~${Math.round(r.amount)}`)).map(r=>r.raw)}const Z=/\b(get (?:a |your |my |an? instant |free )*quotes?|start (?:a |your )?quote|compare (?:\d+ )?quotes|get (?:my |your )?rates?|see (?:my |your )?rates?|check (?:your )?(?:rates?|prices?|availability)|enter (?:your )?(?:zip|postcode|postal code)(?: code)?|search flights|find flights|search hotels|book now|find (?:my|your) (?:rate|price|plan))\b/i;function V(t){const e=Z.exec(String(t||""));return e?e[1].replace(/\s+/g," "):""}export{C as basisAt,T as basisLabel,$ as comparable,W as formatValue,P as hostOf,R as moneyIn,J as offersIn,I as parseAmount,_ as qualifierAt,K as quoteAround,V as quoteFormIn,Q as rankOffers,j as unverifiedAmounts};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.400.0",
|
|
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",
|
|
@@ -109,6 +109,7 @@
|
|
|
109
109
|
"./media-transcript.js": "./media-transcript.js",
|
|
110
110
|
"./meeting-analyzers.js": "./meeting-analyzers.js",
|
|
111
111
|
"./meeting-insights.js": "./meeting-insights.js",
|
|
112
|
+
"./meeting-insight-prompts.js": "./meeting-insight-prompts.js",
|
|
112
113
|
"./meeting-shape.js": "./meeting-shape.js",
|
|
113
114
|
"./meeting-speakers.js": "./meeting-speakers.js",
|
|
114
115
|
"./meeting-speakers-typed.js": "./meeting-speakers-typed.js",
|
|
@@ -151,8 +152,11 @@
|
|
|
151
152
|
"./monitor-profile.js": "./monitor-profile.js",
|
|
152
153
|
"./monitor-turn.js": "./monitor-turn.js",
|
|
153
154
|
"./note-actions.js": "./note-actions.js",
|
|
155
|
+
"./note-blank.js": "./note-blank.js",
|
|
156
|
+
"./note-recall.js": "./note-recall.js",
|
|
154
157
|
"./note-tool.js": "./note-tool.js",
|
|
155
158
|
"./note-graph.js": "./note-graph.js",
|
|
159
|
+
"./note-link.js": "./note-link.js",
|
|
156
160
|
"./note-links.js": "./note-links.js",
|
|
157
161
|
"./note-mentions.js": "./note-mentions.js",
|
|
158
162
|
"./note-plan.js": "./note-plan.js",
|
|
@@ -256,6 +260,7 @@
|
|
|
256
260
|
"./tool-group-data.js": "./tool-group-data.js",
|
|
257
261
|
"./tool-hints.js": "./tool-hints.js",
|
|
258
262
|
"./tool-need.js": "./tool-need.js",
|
|
263
|
+
"./thread-material.js": "./thread-material.js",
|
|
259
264
|
"./housekeeping.js": "./housekeeping.js",
|
|
260
265
|
"./tool-result.js": "./tool-result.js",
|
|
261
266
|
"./agent-permission.js": "./agent-permission.js",
|
|
@@ -441,6 +446,7 @@
|
|
|
441
446
|
"media-transcript.js",
|
|
442
447
|
"meeting-analyzers.js",
|
|
443
448
|
"meeting-insights.js",
|
|
449
|
+
"meeting-insight-prompts.js",
|
|
444
450
|
"meeting-shape.js",
|
|
445
451
|
"meeting-speakers.js",
|
|
446
452
|
"meeting-speakers-typed.js",
|
|
@@ -483,8 +489,11 @@
|
|
|
483
489
|
"monitor-profile.js",
|
|
484
490
|
"monitor-turn.js",
|
|
485
491
|
"note-actions.js",
|
|
492
|
+
"note-blank.js",
|
|
493
|
+
"note-recall.js",
|
|
486
494
|
"note-tool.js",
|
|
487
495
|
"note-graph.js",
|
|
496
|
+
"note-link.js",
|
|
488
497
|
"note-links.js",
|
|
489
498
|
"note-mentions.js",
|
|
490
499
|
"note-plan.js",
|
|
@@ -552,6 +561,7 @@
|
|
|
552
561
|
"kb-index.js",
|
|
553
562
|
"kb-research.js",
|
|
554
563
|
"document-context.js",
|
|
564
|
+
"thread-material.js",
|
|
555
565
|
"page-context.js",
|
|
556
566
|
"kb-tool.js",
|
|
557
567
|
"kb-capability.js",
|
package/prefetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{researchAsk as O,runResearch as ee}from"./web-research.js";import{frontPagesAskedAbout as te}from"./site-pages.js";import{weatherFromSearch as ne}from"./weather-tool.js";import{PAGE_READ_ARGS as R}from"./page-context.js";const N=/(\bhow(?:'s| is| was|s) (?:the )?(?:weather|forecast|temperature)\b|\bwhat(?:'s| is|s) (?:the )?(?:weather|forecast|temperature)\b|\b(?:weather|forecast|temperature) (?:in|for|at|around|near)\b|\bis it (?:raining|snowing|hot|cold|warm|sunny|cloudy|windy)\b|\b(?:will|does) it (?:rain|snow)\b|\bhow (?:hot|cold|warm|humid|windy) is it\b|^\s*(?:weather|forecast)\b|\b(?:weather|forecast)\s*\??\s*$)/i,se=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,oe=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),x=8,E="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",re=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${E}\\b`,"i"),ae=new RegExp(`^\\s*(?:(?:can you |could you |please )?(?:summari[sz]e|tl;?\\s?dr|recap|give me the gist|what are the key (?:points|takeaways))(?:\\s+(?:it|this|that|here|(?:the|this)\\s+${E}(?:\\s+and\\s+(?:the\\s+)?${E})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),ie=/\b(?:my|our|your|the|this|that|last|today'?s|yesterday'?s)\s+(?:meeting|chat|conversation|call|standup|notes?|email|inbox|calendar|day|week|transcript|thread with)\b|https?:\/\//i,ce=/^\s*(?:(?:please|pls|can you|could you|just|ok,?|no,?|then|so|now)\s+)*(?:use (?:the )?(?:web|internet)(?: search)?|use web ?search|(?:do|run|perform|make|start|try)(?: an?| the)? (?:(?:web|internet|online|google) ?)?search|search for (?:it|that|this)|search (?:the )?(?:web|internet|online)|web ?search(?: it)?|google(?: it| that)?|look (?:it |that )?up(?: online| on the web)?|check (?:the web|online)|try (?:the )?(?:web|internet|a web search|web search)|search (?:it|that|again|online))\b(?:\s+(?:for|about)\s+(.+?))?(?:,?\s+(?:please|pls|thanks|instead|now|then))*\s*[?.!]*\s*$/i;function he(e){const t=ce.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const le=/\b(?:weather|forecast|temperature|rain|snow)\b/i,ue=/\b(?:rest of (?:the|this) (?:week|weekend|month)|(?:this|next|coming) (?:week|weekend)|(?:the|this) weekend|week ahead|the week|next (?:few|several|couple of) days|coming days|(?:5|7|10|14)[- ]?days?|extended|long[- ]range|two[- ]weeks?)\b/i,pe=/\b(?:i|we) (?:asked|said|wrote|told|searched|talked|discussed|mentioned|looked up|checked)\b|\b(?:did|have|had) (?:i|we)\b|\bhow (?:many|often) (?:times )?(?:i|we|did|have)\b|\bhow many times\b|\bmy (?:chats?|notes?|history|meetings?|conversations?|questions?|searches)\b|\blast time (?:i|we)\b/i,fe=/\b(?:find out more|find (?:out )?more|more (?:info|information|details)|look into (?:it|that|this)|dig (?:deeper|into (?:it|that))|get more details?|find (?:it|that) out|check (?:on )?(?:it|that) (?:again|online)|search (?:for )?more|look (?:it|that) up|find (?:the )?(?:rest|full|whole)(?: of it| forecast)?)\b/i,de=/^\s*(?:yes|yeah|yep|yup|sure|ok(?:ay)?|k|please(?: do)?|go ahead|go for it|do it|yes please|sure thing|absolutely|of course|ok look|look|search|please search|search it)(?:[\s,.!]+(?:please|thanks|thank you|go ahead|do it|look|search|yes))*[\s.!]*$/i,we=/\b(?:search the web|web search|search online|search for|look (?:it|that|this) up|look up|check online|find (?:it|that|out|more))\b/i,ge=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function be(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(we.test(t)&&/\?/.test(t)){const s=(ge.exec(t)?.[1]||"").replace(/\s+for me$/i,"").trim();if(s)return s}const n=/\b(?:searching(?: the web| online)? for|looking up|checking(?: the web| online)? for)\s+(?:the\s+)?(.{3,160}?)(?:\.\.\.|…|[.!?]|$)/i.exec(t);return n?n[1].trim():""}const A=/^\s*(?:(?:no|nope|actually|but|well|sorry)\b[,.!]?\s*)?(?:i|we) (?:asked|said|meant|wanted)\b/i,T=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function ke(e){const t=String(e||"");if(!A.test(t)||T.test(t))return"";const n=t.replace(A,"").replace(/^\s*(?:for|about)\s+/i,"").replace(/[.;]\s+(?:and|also)\s+/gi," and ").replace(/,?\s+not\s+[^.?!]*/i,"").trim();return/^(?:the\s+)?(?:weather|forecast|temperature)\b/i.test(n)?`what is ${/^the\s/i.test(n)?"":"the "}${n}`:""}function me(e){const t=String(e||"");return A.test(t)&&!T.test(t)?!1:pe.test(t)}const ye=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i;function C(e){const t=String(e||"").trim();return!t||t.length>300||ie.test(t)?null:re.test(t)||ae.test(t)?{}:null}function d(e){return String(e||"").replace(se," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const P=/\b(how|what|what's|whats|is|are|was|will|do|does|can|should|why|when|the|a|an|tell|me|there|here|it|like|about)\b/i;function y(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!oe.has(t)&&!P.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function W(e){const t=String(e||"").trim();return!N.test(t)||$(t)||/\b(?:love|like|hate|enjoy|miss|prefer)\s+(?:this|the|that|such|today's)?\s*(?:weather|forecast)\b/i.test(t)||/\b(?:api|app|apps|service|widget|feature|code|bug|model|tool|component|test|tests|data|endpoint|sdk|library|module|page|screen)\b/i.test(t)?!1:t.split(/\s+/).length<=12}const $e=/\s+(?:for|over|during|through|in|this|next|and)?\s*(?:the\s+)?(?:rest of (?:the|this) (?:week|weekend|day|month)|next (?:few|several|couple of|\d+) days|(?:this|next|coming) (?:week|weekend|month|few days)|the (?:weekend|week(?: ahead)?|coming days)|week ahead|\d+[- ]days?(?: forecast)?)\b/gi;function $(e){const t=String(e||"").trim();if(!N.test(t))return"";const n=t.replace($e,"").trim();let s=/\b(?:in|at|for|around|near)\s+([^?!.;]+?)(?:\s+(?:right now|now|today|tonight|tomorrow|currently|this \w+))*\s*[?!.]*$/i.exec(n);if(s){const o=d(s[1].split(/\s+(?:and|&|vs\.?|versus|compared (?:to|with)|then|,)\s+/i)[0]);if(y(o))return o;if(y(d(s[1])))return d(s[1])}return s=/^(?:what(?:'s| is) the\s+)?([\p{L}][\p{L}\s,.'-]{1,60}?)\s+(?:weather|forecast|temperature)\b/iu.exec(n),s&&y(d(s[1]))&&!L.test(d(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&y(d(s[1])))?d(s[1]):""}const L=/\b(summari[sz]e|explain|try|again|retry|do|make|write|show|tell|open|read|find|search|help|stop|continue|go|list|give|send|run|check|fix|get|fetch|pull|grab|look ?up|display|compare|bring|thanks|thank|yes|no|please|this|that|my|page|note|file|meeting|chat|sounds?|good|great|nice|cool|fine|perfect|awesome|sure|nothing|else|ok|okay|yeah|yep|nope|bye|hello|hi|hey|time|traffic|news|story|joke|stock|price|you|yourself|him|her|them|us)\b/i,Se=/^(?:(?:okay|ok|alright|all right|great|cool|thanks|thank you|fine|good|and|also|then|so|now|actually|well|um+|uh+|hmm+|oh|no|wait)(?:[\s,.!—-]+|$))+/i,_e=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,D=/^(?:(?:how|what) about|(?:how|what)(?:'s| is|s) it(?: like)?(?: in| at| for| around| near)?|(?:in|at|for|around|near))\b[\s,]*/i;function F(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace(Se,"").trim().replace(_e,"").trim();if(!s||s.split(/\s+/).length>x)return"";const o=D.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=d(s.replace(D,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!y(r)||L.test(r)?"":r}const k="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",Ee=[new RegExp(`\\b(?:share price|stock price|stock quote|ticker)\\s+(?:of|for)\\s+${k}`,"iu"),{question:!0,re:new RegExp(`\\b(?:stock|stocks|shares?)\\s+(?:of|for|in)\\s+${k}`,"iu")},new RegExp(`\\b${k}(?:'s)?\\s+(?:stock|shares)\\s+(?:price|doing|trading|today|now|performance|performing|up|down|quote)\\b`,"iu"),new RegExp(`\\b${k}(?:'s)?\\s+(?:share price|stock price|stock quote)\\b`,"iu"),new RegExp(`^\\s*${k}(?:'s)?\\s+(?:stock|shares)\\s*\\??\\s*$`,"iu"),new RegExp(`\\b(?:how|where)(?:'s| is| are)\\s+${k}\\s+(?:stock\\s+|shares\\s+)?trading\\b`,"iu"),new RegExp(`\\bwhat(?:'s| is| are)\\s+${k}\\s+trading at\\b`,"iu"),/\$([A-Z]{1,5})\b/u],Ae=/^(?:the|a|an|my|our|your|this|that|it|its|their|market|stock market|markets|price|prices|today|now|company|companies|how|what|is|are|doing|of|for|in|weather|forecast|news|time|date|temperature|rain|you|me|us|them|those|these)$/i,Le=/^(?:how|what|what's|whats|where|is|are|was|the|a|an|can|could|you|tell|me|about|of|for|in|and|also|so|now|then|please|check|show|give|get)$/i,je=/\s+(?:stock|stocks|shares?|price|prices|doing|trading|today|now|right now|currently|at the moment|this (?:morning|afternoon|week)|lately|so far)\b.*$/i;function q(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Ae.test(t)&&!P.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function Oe(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&Le.test(t[0]);)t.shift();return t.join(" ")}function v(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(je,"").replace(/(?:\s+(?:at|on|up|down|for me|please))+$/i,"").replace(/^\s*(?:the|shares? of|stock of)\s+/i,"").replace(/'s$/i,"").replace(/\s+(?:corp(?:oration)?|inc|co|company|ltd)\.?$/i,t=>t).replace(/\s+/g," ").trim()}function B(e){const t=String(e||"").trim(),n=/\?\s*$/.test(t)||/^\s*(?:(?:hey|hi|ok|okay|so|and|now)[\s,]+)*(?:how|what|where|is|are|can|could|would|will|tell|check|show|give|get|find|look up|please)\b/i.test(t);for(const s of Ee){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=Oe(v(r[1]));if(q(l))return l}return""}function M(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>x)return"";n=n.replace(/^(?:(?:okay|ok|fine|good|great|thanks|thank you|cool|alright|all right|that'?s (?:fine|good|great|ok|okay))[\s,.!—-]*)+/i,"").trim();const s=/^(?:(?:and|also|then|so|now)[\s,]+)*(?:how about|what about)\b/i.test(n)||/^(?:and|also)[\s,]+/i.test(n);n=n.replace(/^(?:(?:and|also|then|so|now)[\s,]+)*(?:(?:how|what) about\b)?[\s,]*/i,"").trim();const o=v(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!q(o)||L.test(o)?"":o}const U=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function I(e){return String(e||"").replace(U,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function Re(e){return[...String(e||"").matchAll(U)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Ne=/\b(?:tell me (?:more |everything |all |something )?about|what do you know about|do you know (?:anything )?about|who(?:'s| is| was| are)|look up|lookup|search (?:the web |online |the internet |google )?for|search up|google|find (?:out )?(?:info(?:rmation)?|details|more|anything|something|everything) (?:on|about)|(?:info|information|background|details) (?:on|about)|research)\s+(.+)$/i,xe=/[.?!;:,()](?=\s|$)|\s(?:uh|um|umm|er|erm|hmm|like|actually|i mean|sorry|the (?:first |last |sur|family )?name|his|her|their|its|it's|it is|spelled|spelt|and (?:tell|give|find|show|let|search|look)|then|please|for me|on the web|online|on google|from the web|if you can|thanks|thank you)\b/i,Te=/^(?:it|this|that|these|those|him|her|them|me|you|yourself|us|he|she|they|we|i|my|our|your|his|their|here|there|on|in|at|to|for|with|from|going|coming|speaking|talking|calling|joining|what|how|why|when|where|which|the weather|weather)\b/i,Ce=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,Pe=/^(?:the|a|an)\b/i,We=6;function G(e){const n=(String(e||"").split(xe)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>We||!new RegExp("\\p{L}","u").test(n)||Te.test(n)?"":n}function De(e){const t=Ne.exec(I(e));return t?G(t[1]):""}const Fe=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],qe=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,ve=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function Be(e,t){const n=e.toLowerCase(),s=t.toLowerCase(),o=Array.from({length:s.length+1},(r,l)=>l);for(let r=1;r<=n.length;r++){let l=o[0];o[0]=r;for(let c=1;c<=s.length;c++){const u=o[c];o[c]=Math.min(o[c]+1,o[c-1]+1,l+(n[r-1]===s[c-1]?0:1)),l=u}}return o[s.length]}function Me(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function H(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=Re(s),r=I(s);let l=o.at(-1)||"";if(!l&&ve.test(r)&&(l=qe.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let u=-1;for(const[a,f]of Fe)if(a.test(r)){u=f(c);break}if(u<0){let a=1/0;c.forEach((f,w)=>{const g=Be(f,l)/Math.max(f.length,l.length);g<a&&(a=g,u=w)}),a>.6&&(u=c.length===1?0:-1)}if(u<0)return null;const i=c[u];return i.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[u]=Me(l,c.find(a=>new RegExp("^\\p{Lu}","u").test(a))||i),{subject:c.join(" "),replaced:i})}const Ue=/\b(?:search|look|google|check|find|try)\b[^.?!]{0,30}\b(?:web|online|internet|google|up|again|it|him|her|them)\b|\blook(?:ing)? (?:it|that|him|her|them)? ?up\b/i,J=/\b(?:web|online|internet|google)\b/i;function Ie(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=H(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Ue.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:J.test(e)}}function K(e,t){const n=De(e);if(n){const o=H(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:J.test(e)}}const s=Ie(e,t);return s?{kind:"lookup",...s}:null}function Y(e){return Ce.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!Pe.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const Ge=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,He=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,Je=/^(?:(?:can|could) you (?:tell|give) me |tell me |give me |show me )?(?:the |any |some )?(?:latest |recent |top |today'?s |breaking )?(.{2,60}?)\s+news(?:\s+(?:today|this (?:morning|week|evening)|right now|lately|these days))?\s*[?.!]*$/i,Ke=/^(?:(?:can|could) you (?:tell|give) me |tell me |give me |show me |what(?:'s| is| are) )?(?:the |any )?(?:latest |top |today'?s |breaking )?(?:news|headlines)(?:\s+(?:today|this (?:morning|week|evening)|right now))?\s*[?.!]*$/i,z=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function Ye(e){const t=String(e||"").trim();if(!t||te(t).length)return null;if(Ke.test(t))return{subject:""};const n=Ge.exec(t)||Je.exec(t),s=n?null:He.exec(t),o=n||s;if(!o)return null;const r=G(o[1].replace(/[?.!]+$/,"").replace(z,"")).replace(z,"");return s&&r.split(/\s+/).length>4||!r||!Y(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function rt(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const X=Object.freeze({page:15e3,web:12e3,lookup:12e3}),ze=6e3;function at(e){return Object.hasOwn(X,e?.kind)?X[e.kind]:ze}const Xe=/^\s*(?:(?:and|also|ok(?:ay)?|so|then)[,\s]+)?(?:(?:what|how) about|how(?:'s|’s| is| will| does)?(?: it| the weather| things)?(?: be| look(?:ing)?)?|is it|and|for)?\s*(?:(?:right )?now|currently|today|tonight|tomorrow(?: morning| afternoon| evening| night)?|(?:a |the )?day after tomorrow|later(?: today| tonight)?|(?:this|next|the) (?:morning|afternoon|evening|night|weekend|week)|(?:the )?rest of (?:the|this) week|(?:on |this |next )?(?:mon|tues|wednes|thurs|fri|satur|sun)day|outside|out there)\s*[?!.]*\s*$/i;function Q(e,t){return!t||t.kind!=="weather"?"":Xe.test(String(e||""))?String(t.subject||"here"):""}function Qe(e,t){const n=$(e)||Q(e,t)||F(e,t);if(n)return{kind:"weather",subject:n};if(W(e))return{kind:"weather",subject:"here"};const s=B(e)||M(e,t);if(s)return{kind:"stock",subject:s};const o=K(String(e||""),t);if(o)return o;const r=O(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function it(e){const t=(Array.isArray(e)?e:[]).filter(o=>o&&!o.pending&&(o.role==="user"||o.role==="assistant")),n=[];for(let o=0;o<t.length;o++)t[o].role==="user"&&n.push(o);if(n.length<2)return null;let s=null;for(let o=0;o<n.length-1;o++){const r=t[n[o]],l=t[n[o]+1]?.role==="assistant"?t[n[o]+1]:null,c=(r.attachments||[]).find(a=>a?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"";s=Qe(u,s)||(c?{kind:c.prefetch,...c.research?{research:c.research}:{}}:null)||((l?.steps||[]).some(a=>a?.input?.action==="weather"||a?.tool==="weather")?{kind:"weather"}:null)}return s}function ct({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,now:u=Date.now()}={}){const i=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),a=[];if(me(e))return r?V(e,t,i):[];const f=de.test(String(e||""))?be(s):"",w=String(e||"").trim().split(/\s+/).length,g=he(e)||(f?{query:f}:null)||(fe.test(String(e||""))&&w<=14?{}:null);if(g&&(i.has("find:web_search")||i.has("web_search"))){const h=g.query||String(n||"").trim();if(h){const p=i.has("find:web_search"),m=!g.query;return[{kind:"web",tool:p?"find":"web_search",input:p?{action:"web_search",args:{query:h}}:{query:h},label:`Web — ${h.slice(0,60)}`,subject:h,...le.test(h)?{weather:!0}:{},...m?{borrowed:!0}:{}}]}}if(c&&(i.has("page:read_page")||i.has("read_page"))&&C(e)){const h=i.has("page:read_page"),p=ye.test(e)&&C(n)?String(n).trim():"";return[{kind:"page",tool:h?"page":"read_page",input:h?{action:"read_page",args:{...R}}:{...R},label:"This page",...p?{ask:p}:{}}]}const S=i.has("find:weather"),Z=i.has("weather");if(S||Z){e=ke(e)||e;const h=$(e)?"":Q(e,t),p=$(e)||(h?h!=="here"?h:"":F(e,t)),m=p||(W(e)||h?"here":"");if(m&&(a.push({kind:"weather",tool:S?"find":"weather",input:S?{action:"weather",args:{location:m}}:{location:m},label:p?`Weather — ${p}`:"Weather — near you"}),p&&ue.test(String(e||""))&&(i.has("find:web_search")||i.has("web_search")))){const _=`${p} 10 day weather forecast`,j=i.has("find:web_search");a.push({kind:"web",tool:j?"find":"web_search",input:j?{action:"web_search",args:{query:_}}:{query:_},label:`Web — ${p} extended forecast`,subject:_,weather:!0})}}const b=i.has("find:web_search");if(!a.length&&(b||i.has("web_search"))){const h=B(e)||M(e,t);if(h){const p=`${h} stock price today`;a.push({kind:"stock",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:`Stock — ${h}`})}}if(!a.length&&(b||i.has("web_search"))){const h=Ye(e);if(h){const p=h.subject?`${h.subject} news today`:"top news today";a.push({kind:"news",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:h.subject?`News — ${h.subject}`:"News — today",subject:h.subject})}}if(l&&!a.length&&(b||i.has("web_search"))){const h=O(e,{previous:t,now:u});if(h){const p=b?"find":"web_search";a.push({kind:"research",tool:p,input:p==="find"?{action:"web_search",args:{query:h.queries[0]}}:{query:h.queries[0]},label:`Research — ${h.subject}`,subject:h.subject,research:h})}}return r&&!a.length&&a.push(...V(e,t,i)),a}function V(e,t,n){const s=K(String(e||""),t);if(!s)return[];const{subject:o}=s,r=s.corrected?`The user corrected the name: it is "${o}"${s.replaced?`, not "${s.replaced}"`:""} — use this spelling; earlier answers in this chat were about the wrong name.`:"",l=a=>n.has(`find:${a}`)?{tool:"find",input:f=>({action:a,args:f})}:n.has(a)?{tool:a,input:f=>f}:null,c=[],u=l("history_search"),i=l("web_search");return u&&!s.web&&c.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),i&&(s.web||Y(o))&&c.push({kind:"lookup",tool:i.tool,input:i.input({query:o}),label:`Web — ${o}`,subject:o,note:r,fallback:c.length>0}),c}function ht(e=[]){const t=Array.isArray(e)?e:[];for(let n=t.length-1;n>=0;n--)if(t[n]?.role==="user")return(t[n].attachments||[]).some(s=>s?.kind==="prefetch"&&String(s.text||"").trim());return!1}function lt(e){const t=typeof e=="string"?e:e&&typeof e.text=="string"?e.text:JSON.stringify(e??""),n=e&&typeof e=="object"&&typeof e.note=="string"?e.note:"";return{text:t,note:n}}function Ve(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function Ze(e){const t=String(e||"");if(!t.startsWith("{"))return t;try{const n=JSON.parse(t);return typeof n?.text!="string"?t:[typeof n.note=="string"?n.note:"",n.text,n.truncated?"(The page continues past what was read.)":""].filter(Boolean).join(`
|
|
1
|
+
import{researchAsk as R,runResearch as ne}from"./web-research.js";import{frontPagesAskedAbout as se}from"./site-pages.js";import{weatherFromSearch as oe}from"./weather-tool.js";import{PAGE_READ_ARGS as N}from"./page-context.js";const C=/(\bhow(?:'s| is| was|s) (?:the )?(?:weather|forecast|temperature)\b|\bwhat(?:'s| is|s) (?:the )?(?:weather|forecast|temperature)\b|\b(?:weather|forecast|temperature) (?:in|for|at|around|near)\b|\bis it (?:raining|snowing|hot|cold|warm|sunny|cloudy|windy)\b|\b(?:will|does) it (?:rain|snow)\b|\bhow (?:hot|cold|warm|humid|windy) is it\b|^\s*(?:weather|forecast)\b|\b(?:weather|forecast)\s*\??\s*$)/i,re=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,E=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),x=8,A="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",ae=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${A}\\b`,"i"),ie=new RegExp(`^\\s*(?:(?:can you |could you |please )?(?:summari[sz]e|tl;?\\s?dr|recap|give me the gist|what are the key (?:points|takeaways))(?:\\s+(?:it|this|that|here|(?:the|this)\\s+${A}(?:\\s+and\\s+(?:the\\s+)?${A})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),ce=/\b(?:my|our|your|the|this|that|last|today'?s|yesterday'?s)\s+(?:meeting|chat|conversation|call|standup|notes?|email|inbox|calendar|day|week|transcript|thread with)\b|https?:\/\//i,he=/^\s*(?:(?:please|pls|can you|could you|just|ok,?|no,?|then|so|now)\s+)*(?:use (?:the )?(?:web|internet)(?: search)?|use web ?search|(?:do|run|perform|make|start|try)(?: an?| the)? (?:(?:web|internet|online|google) ?)?search|search for (?:it|that|this)|search (?:the )?(?:web|internet|online)|web ?search(?: it)?|google(?: it| that)?|look (?:it |that )?up(?: online| on the web)?|check (?:the web|online)|try (?:the )?(?:web|internet|a web search|web search)|search (?:it|that|again|online))\b(?:\s+(?:for|about)\s+(.+?))?(?:,?\s+(?:please|pls|thanks|instead|now|then))*\s*[?.!]*\s*$/i;function le(e){const t=he.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const ue=/\b(?:weather|forecast|temperature|rain|snow)\b/i,pe=/\b(?:rest of (?:the|this) (?:week|weekend|month)|(?:this|next|coming) (?:week|weekend)|(?:the|this) weekend|week ahead|the week|next (?:few|several|couple of) days|coming days|(?:5|7|10|14)[- ]?days?|extended|long[- ]range|two[- ]weeks?)\b/i,fe=/\b(?:i|we) (?:asked|said|wrote|told|searched|talked|discussed|mentioned|looked up|checked)\b|\b(?:did|have|had) (?:i|we)\b|\bhow (?:many|often) (?:times )?(?:i|we|did|have)\b|\bhow many times\b|\bmy (?:chats?|notes?|history|meetings?|conversations?|questions?|searches)\b|\blast time (?:i|we)\b/i,de=/\b(?:find out more|find (?:out )?more|more (?:info|information|details)|look into (?:it|that|this)|dig (?:deeper|into (?:it|that))|get more details?|find (?:it|that) out|check (?:on )?(?:it|that) (?:again|online)|search (?:for )?more|look (?:it|that) up|find (?:the )?(?:rest|full|whole)(?: of it| forecast)?)\b/i,we=/^\s*(?:yes|yeah|yep|yup|sure|ok(?:ay)?|k|please(?: do)?|go ahead|go for it|do it|yes please|sure thing|absolutely|of course|ok look|look|search|please search|search it)(?:[\s,.!]+(?:please|thanks|thank you|go ahead|do it|look|search|yes))*[\s.!]*$/i,ge=/\b(?:search the web|web search|search online|search for|look (?:it|that|this) up|look up|check online|find (?:it|that|out|more))\b/i,be=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function ke(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(ge.test(t)&&/\?/.test(t)){const s=(be.exec(t)?.[1]||"").replace(/\s+for me$/i,"").trim();if(s)return s}const n=/\b(?:searching(?: the web| online)? for|looking up|checking(?: the web| online)? for)\s+(?:the\s+)?(.{3,160}?)(?:\.\.\.|…|[.!?]|$)/i.exec(t);return n?n[1].trim():""}const L=/^\s*(?:(?:no|nope|actually|but|well|sorry)\b[,.!]?\s*)?(?:i|we) (?:asked|said|meant|wanted)\b/i,P=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function me(e){const t=String(e||"");if(!L.test(t)||P.test(t))return"";const n=t.replace(L,"").replace(/^\s*(?:for|about)\s+/i,"").replace(/[.;]\s+(?:and|also)\s+/gi," and ").replace(/,?\s+not\s+[^.?!]*/i,"").trim();return/^(?:the\s+)?(?:weather|forecast|temperature)\b/i.test(n)?`what is ${/^the\s/i.test(n)?"":"the "}${n}`:""}function ye(e){const t=String(e||"");return L.test(t)&&!P.test(t)?!1:fe.test(t)}const $e=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i;function T(e){const t=String(e||"").trim();return!t||t.length>300||ce.test(t)?null:ae.test(t)||ie.test(t)?{}:null}function d(e){return String(e||"").replace(re," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const W=/\b(how|what|what's|whats|is|are|was|will|do|does|can|should|why|when|the|a|an|tell|me|there|here|it|like|about)\b/i;function y(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!E.has(t)&&!W.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function D(e){const t=String(e||"").trim();return!C.test(t)||$(t)||/\b(?:love|like|hate|enjoy|miss|prefer)\s+(?:this|the|that|such|today's)?\s*(?:weather|forecast)\b/i.test(t)||/\b(?:api|app|apps|service|widget|feature|code|bug|model|tool|component|test|tests|data|endpoint|sdk|library|module|page|screen)\b/i.test(t)?!1:t.split(/\s+/).length<=12}const Se=/\s+(?:for|over|during|through|in|this|next|and)?\s*(?:the\s+)?(?:rest of (?:the|this) (?:week|weekend|day|month)|next (?:few|several|couple of|\d+) days|(?:this|next|coming) (?:week|weekend|month|few days)|the (?:weekend|week(?: ahead)?|coming days)|week ahead|\d+[- ]days?(?: forecast)?)\b/gi;function $(e){const t=String(e||"").trim();if(!C.test(t))return"";const n=t.replace(Se,"").trim();let s=/\b(?:in|at|for|around|near)\s+([^?!.;]+?)(?:\s+(?:right now|now|today|tonight|tomorrow|currently|this \w+))*\s*[?!.]*$/i.exec(n);if(s){const o=d(s[1].split(/\s+(?:and|&|vs\.?|versus|compared (?:to|with)|then|,)\s+/i)[0]);if(y(o))return o;if(y(d(s[1])))return d(s[1])}return s=/^(?:what(?:'s| is) the\s+)?([\p{L}][\p{L}\s,.'-]{1,60}?)\s+(?:weather|forecast|temperature)\b/iu.exec(n),s&&y(d(s[1]))&&!j.test(d(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&y(d(s[1])))?d(s[1]):""}const j=/\b(summari[sz]e|explain|try|again|retry|do|make|write|show|tell|open|read|find|search|help|stop|continue|go|list|give|send|run|check|fix|get|fetch|pull|grab|look ?up|display|compare|bring|thanks|thank|yes|no|please|this|that|my|page|note|file|meeting|chat|sounds?|good|great|nice|cool|fine|perfect|awesome|sure|nothing|else|ok|okay|yeah|yep|nope|bye|hello|hi|hey|time|traffic|news|story|joke|stock|price|you|yourself|him|her|them|us)\b/i,_e=/^(?:(?:okay|ok|alright|all right|great|cool|thanks|thank you|fine|good|and|also|then|so|now|actually|well|um+|uh+|hmm+|oh|no|wait|sorry|oops)(?:[\s,.!—-]+|$))+/i,Ee=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,F=/^(?:(?:how|what) about|(?:how|what)(?:'s| is|s) it(?: like)?(?: in| at| for| around| near)?|i (?:meant|mean)(?: in)?|it(?:'s|’s| is|s)(?: in)?|(?:in|at|for|around|near))\b[\s,]*/i;function q(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace(_e,"").trim().replace(Ee,"").trim();if(!s||s.split(/\s+/).length>x)return"";const o=F.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=d(s.replace(F,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!y(r)||j.test(r)?"":r}const m="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",Ae=[new RegExp(`\\b(?:share price|stock price|stock quote|ticker)\\s+(?:of|for)\\s+${m}`,"iu"),{question:!0,re:new RegExp(`\\b(?:stock|stocks|shares?)\\s+(?:of|for|in)\\s+${m}`,"iu")},new RegExp(`\\b${m}(?:'s)?\\s+(?:stock|shares)\\s+(?:price|doing|trading|today|now|performance|performing|up|down|quote)\\b`,"iu"),new RegExp(`\\b${m}(?:'s)?\\s+(?:share price|stock price|stock quote)\\b`,"iu"),new RegExp(`^\\s*${m}(?:'s)?\\s+(?:stock|shares)\\s*\\??\\s*$`,"iu"),new RegExp(`\\b(?:how|where)(?:'s| is| are)\\s+${m}\\s+(?:stock\\s+|shares\\s+)?trading\\b`,"iu"),new RegExp(`\\bwhat(?:'s| is| are)\\s+${m}\\s+trading at\\b`,"iu"),/\$([A-Z]{1,5})\b/u],Le=/^(?:the|a|an|my|our|your|this|that|it|its|their|market|stock market|markets|price|prices|today|now|company|companies|how|what|is|are|doing|of|for|in|weather|forecast|news|time|date|temperature|rain|you|me|us|them|those|these)$/i,je=/^(?:how|what|what's|whats|where|is|are|was|the|a|an|can|could|you|tell|me|about|of|for|in|and|also|so|now|then|please|check|show|give|get)$/i,Oe=/\s+(?:stock|stocks|shares?|price|prices|doing|trading|today|now|right now|currently|at the moment|this (?:morning|afternoon|week)|lately|so far)\b.*$/i;function v(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Le.test(t)&&!W.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function Re(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&je.test(t[0]);)t.shift();return t.join(" ")}function B(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(Oe,"").replace(/(?:\s+(?:at|on|up|down|for me|please))+$/i,"").replace(/^\s*(?:the|shares? of|stock of)\s+/i,"").replace(/'s$/i,"").replace(/\s+(?:corp(?:oration)?|inc|co|company|ltd)\.?$/i,t=>t).replace(/\s+/g," ").trim()}function M(e){const t=String(e||"").trim(),n=/\?\s*$/.test(t)||/^\s*(?:(?:hey|hi|ok|okay|so|and|now)[\s,]+)*(?:how|what|where|is|are|can|could|would|will|tell|check|show|give|get|find|look up|please)\b/i.test(t);for(const s of Ae){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=Re(B(r[1]));if(v(l))return l}return""}function U(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>x)return"";n=n.replace(/^(?:(?:okay|ok|fine|good|great|thanks|thank you|cool|alright|all right|that'?s (?:fine|good|great|ok|okay))[\s,.!—-]*)+/i,"").trim();const s=/^(?:(?:and|also|then|so|now)[\s,]+)*(?:how about|what about)\b/i.test(n)||/^(?:and|also)[\s,]+/i.test(n);n=n.replace(/^(?:(?:and|also|then|so|now)[\s,]+)*(?:(?:how|what) about\b)?[\s,]*/i,"").trim();const o=B(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!v(o)||j.test(o)?"":o}const I=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function G(e){return String(e||"").replace(I,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function Ne(e){return[...String(e||"").matchAll(I)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Ce=/\b(?:tell me (?:more |everything |all |something )?about|what do you know about|do you know (?:anything )?about|who(?:'s| is| was| are)|look up|lookup|search (?:the web |online |the internet |google )?for|search up|google|find (?:out )?(?:info(?:rmation)?|details|more|anything|something|everything) (?:on|about)|(?:info|information|background|details) (?:on|about)|research)\s+(.+)$/i,xe=/[.?!;:,()](?=\s|$)|\s(?:uh|um|umm|er|erm|hmm|like|actually|i mean|sorry|the (?:first |last |sur|family )?name|his|her|their|its|it's|it is|spelled|spelt|and (?:tell|give|find|show|let|search|look)|then|please|for me|on the web|online|on google|from the web|if you can|thanks|thank you)\b/i,Pe=/^(?:it|this|that|these|those|him|her|them|me|you|yourself|us|he|she|they|we|i|my|our|your|his|their|here|there|on|in|at|to|for|with|from|going|coming|speaking|talking|calling|joining|what|how|why|when|where|which|the weather|weather)\b/i,Te=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,We=/^(?:the|a|an)\b/i,De=6;function H(e){const n=(String(e||"").split(xe)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>De||!new RegExp("\\p{L}","u").test(n)||Pe.test(n)?"":n}function Fe(e){const t=Ce.exec(G(e));return t?H(t[1]):""}const qe=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],ve=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,Be=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function Me(e,t){const n=e.toLowerCase(),s=t.toLowerCase(),o=Array.from({length:s.length+1},(r,l)=>l);for(let r=1;r<=n.length;r++){let l=o[0];o[0]=r;for(let c=1;c<=s.length;c++){const u=o[c];o[c]=Math.min(o[c]+1,o[c-1]+1,l+(n[r-1]===s[c-1]?0:1)),l=u}}return o[s.length]}function Ue(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function J(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=Ne(s),r=G(s);let l=o.at(-1)||"";if(!l&&Be.test(r)&&(l=ve.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let u=-1;for(const[i,f]of qe)if(i.test(r)){u=f(c);break}if(u<0){let i=1/0;c.forEach((f,w)=>{const g=Me(f,l)/Math.max(f.length,l.length);g<i&&(i=g,u=w)}),i>.6&&(u=c.length===1?0:-1)}if(u<0)return null;const a=c[u];return a.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[u]=Ue(l,c.find(i=>new RegExp("^\\p{Lu}","u").test(i))||a),{subject:c.join(" "),replaced:a})}const Ie=/\b(?:search|look|google|check|find|try)\b[^.?!]{0,30}\b(?:web|online|internet|google|up|again|it|him|her|them)\b|\blook(?:ing)? (?:it|that|him|her|them)? ?up\b/i,K=/\b(?:web|online|internet|google)\b/i;function Ge(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=J(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Ie.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:K.test(e)}}function Y(e,t){const n=Fe(e);if(n){const o=J(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:K.test(e)}}const s=Ge(e,t);return s?{kind:"lookup",...s}:null}function z(e){return Te.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!We.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const He=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,Je=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,Ke=/^(?:(?:can|could) you (?:tell|give) me |tell me |give me |show me )?(?:the |any |some )?(?:latest |recent |top |today'?s |breaking )?(.{2,60}?)\s+news(?:\s+(?:today|this (?:morning|week|evening)|right now|lately|these days))?\s*[?.!]*$/i,Ye=/^(?:(?:can|could) you (?:tell|give) me |tell me |give me |show me |what(?:'s| is| are) )?(?:the |any )?(?:latest |top |today'?s |breaking )?(?:news|headlines)(?:\s+(?:today|this (?:morning|week|evening)|right now))?\s*[?.!]*$/i,X=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function ze(e){const t=String(e||"").trim();if(!t||se(t).length)return null;if(Ye.test(t))return{subject:""};const n=He.exec(t)||Ke.exec(t),s=n?null:Je.exec(t),o=n||s;if(!o)return null;const r=H(o[1].replace(/[?.!]+$/,"").replace(X,"")).replace(X,"");return s&&r.split(/\s+/).length>4||!r||!z(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function at(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const Q=Object.freeze({page:15e3,web:12e3,lookup:12e3}),Xe=6e3;function it(e){return Object.hasOwn(Q,e?.kind)?Q[e.kind]:Xe}const Qe=/^\s*(?:(?:and|also|ok(?:ay)?|so|then)[,\s]+)?(?:(?:what|how) about|how(?:'s|’s| is| will| does)?(?: it| the weather| things)?(?: be| look(?:ing)?)?|is it|and|for)?\s*(?:(?:right )?now|currently|today|tonight|tomorrow(?: morning| afternoon| evening| night)?|(?:a |the )?day after tomorrow|later(?: today| tonight)?|(?:this|next|the) (?:morning|afternoon|evening|night|weekend|week)|(?:the )?rest of (?:the|this) week|(?:on |this |next )?(?:mon|tues|wednes|thurs|fri|satur|sun)day|outside|out there)\s*[?!.]*\s*$/i;function V(e,t){if(!t||t.kind!=="weather")return"";const n=String(t.subject||"");if(!n||E.has(n.toLowerCase()))return"";const s=String(e||"").toLowerCase();return[...E].some(o=>o!=="it"&&o!=="that"&&new RegExp(`\\b${o}\\b`).test(s))?"":n}function Z(e,t){return!t||t.kind!=="weather"?"":Qe.test(String(e||""))?String(t.subject||"here"):""}function Ve(e,t){const n=$(e)||Z(e,t)||q(e,t);if(n)return{kind:"weather",subject:n};if(D(e))return{kind:"weather",subject:V(e,t)||"here"};const s=M(e)||U(e,t);if(s)return{kind:"stock",subject:s};const o=Y(String(e||""),t);if(o)return o;const r=R(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function ct(e){const t=(Array.isArray(e)?e:[]).filter(o=>o&&!o.pending&&(o.role==="user"||o.role==="assistant")),n=[];for(let o=0;o<t.length;o++)t[o].role==="user"&&n.push(o);if(n.length<2)return null;let s=null;for(let o=0;o<n.length-1;o++){const r=t[n[o]],l=t[n[o]+1]?.role==="assistant"?t[n[o]+1]:null,c=(r.attachments||[]).find(i=>i?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"";s=Ve(u,s)||(c?{kind:c.prefetch,...c.research?{research:c.research}:{}}:null)||((l?.steps||[]).some(i=>i?.input?.action==="weather"||i?.tool==="weather")?{kind:"weather"}:null)}return s}function ht({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,now:u=Date.now()}={}){const a=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),i=[];if(ye(e))return r?ee(e,t,a):[];const f=we.test(String(e||""))?ke(s):"",w=String(e||"").trim().split(/\s+/).length,g=le(e)||(f?{query:f}:null)||(de.test(String(e||""))&&w<=14?{}:null);if(g&&(a.has("find:web_search")||a.has("web_search"))){const h=g.query||String(n||"").trim();if(h){const p=a.has("find:web_search"),k=!g.query;return[{kind:"web",tool:p?"find":"web_search",input:p?{action:"web_search",args:{query:h}}:{query:h},label:`Web — ${h.slice(0,60)}`,subject:h,...ue.test(h)?{weather:!0}:{},...k?{borrowed:!0}:{}}]}}if(c&&(a.has("page:read_page")||a.has("read_page"))&&T(e)){const h=a.has("page:read_page"),p=$e.test(e)&&T(n)?String(n).trim():"";return[{kind:"page",tool:h?"page":"read_page",input:h?{action:"read_page",args:{...N}}:{...N},label:"This page",...p?{ask:p}:{}}]}const S=a.has("find:weather"),te=a.has("weather");if(S||te){e=me(e)||e;const h=$(e)?"":Z(e,t),p=$(e)||(h?h!=="here"?h:"":q(e,t)),k=p||(D(e)?V(e,t)||"here":h?"here":"");if(k&&(i.push({kind:"weather",tool:S?"find":"weather",input:S?{action:"weather",args:{location:k}}:{location:k},label:p?`Weather — ${p}`:"Weather — near you"}),p&&pe.test(String(e||""))&&(a.has("find:web_search")||a.has("web_search")))){const _=`${p} 10 day weather forecast`,O=a.has("find:web_search");i.push({kind:"web",tool:O?"find":"web_search",input:O?{action:"web_search",args:{query:_}}:{query:_},label:`Web — ${p} extended forecast`,subject:_,weather:!0})}}const b=a.has("find:web_search");if(!i.length&&(b||a.has("web_search"))){const h=M(e)||U(e,t);if(h){const p=`${h} stock price today`;i.push({kind:"stock",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:`Stock — ${h}`})}}if(!i.length&&(b||a.has("web_search"))){const h=ze(e);if(h){const p=h.subject?`${h.subject} news today`:"top news today";i.push({kind:"news",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:h.subject?`News — ${h.subject}`:"News — today",subject:h.subject})}}if(l&&!i.length&&(b||a.has("web_search"))){const h=R(e,{previous:t,now:u});if(h){const p=b?"find":"web_search";i.push({kind:"research",tool:p,input:p==="find"?{action:"web_search",args:{query:h.queries[0]}}:{query:h.queries[0]},label:`Research — ${h.subject}`,subject:h.subject,research:[...a].some(k=>/^(?:page:)?(?:open_tab|navigate)$/.test(k))?{...h,browse:!0}:h})}}return r&&!i.length&&i.push(...ee(e,t,a)),i}function ee(e,t,n){const s=Y(String(e||""),t);if(!s)return[];const{subject:o}=s,r=s.corrected?`The user corrected the name: it is "${o}"${s.replaced?`, not "${s.replaced}"`:""} — use this spelling; earlier answers in this chat were about the wrong name.`:"",l=i=>n.has(`find:${i}`)?{tool:"find",input:f=>({action:i,args:f})}:n.has(i)?{tool:i,input:f=>f}:null,c=[],u=l("history_search"),a=l("web_search");return u&&!s.web&&c.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),a&&(s.web||z(o))&&c.push({kind:"lookup",tool:a.tool,input:a.input({query:o}),label:`Web — ${o}`,subject:o,note:r,fallback:c.length>0}),c}function lt(e=[]){const t=Array.isArray(e)?e:[];for(let n=t.length-1;n>=0;n--)if(t[n]?.role==="user")return(t[n].attachments||[]).some(s=>s?.kind==="prefetch"&&String(s.text||"").trim());return!1}function ut(e){const t=typeof e=="string"?e:e&&typeof e.text=="string"?e.text:JSON.stringify(e??""),n=e&&typeof e=="object"&&typeof e.note=="string"?e.note:"";return{text:t,note:n}}function Ze(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function et(e){const t=String(e||"");if(!t.startsWith("{"))return t;try{const n=JSON.parse(t);return typeof n?.text!="string"?t:[typeof n.note=="string"?n.note:"",n.text,n.truncated?"(The page continues past what was read.)":""].filter(Boolean).join(`
|
|
2
2
|
|
|
3
|
-
`)}catch{return t}}function
|
|
3
|
+
`)}catch{return t}}function tt(e,t,{now:n=Date.now(),note:s=""}={}){if(e.kind==="web"&&e.weather&&(t=oe(t)||t),e.kind==="page"&&(t=et(t)),e.kind==="research"){const u=String(t||""),{question:a,domain:i,subject:f,slots:w}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||f||"",research:{question:a,domain:i,subject:f,slots:w},title:e.label,text:u,chars:u.length}}const o=e.kind==="page"?"this is the page they mean.":e.kind==="web"?`these are web results for "${String(e.subject||"").slice(0,80)}" — answer from them; search again only with different words.`:e.kind==="stock"?`do not call ${e.tool} or any search tool again for the same company. Say the price and change it gives; if it gives none, say you could not find a current price — never estimate one.`:e.kind==="lookup"?`if it is about someone or something else, or found nothing, search again with DIFFERENT words (another spelling, the other source — library or web) — never the same query.${e.note?` ${e.note}`:""}`:`do not call ${e.tool} or any weather/search tool again for the same place.`,r=e.kind==="lookup"||e.kind==="web"?`SEARCHED for "${e.subject}"`:e.kind==="page"?"READ the page the user has open":"FETCHED",l=e.kind==="page"&&e.ask?`
|
|
4
4
|
|
|
5
5
|
The question about this page: ${e.ask.slice(0,200)}`:"",c=`(ALREADY ${r} for the question below, with ${e.tool}. Answer from this; ${o})
|
|
6
6
|
|
|
7
|
-
${String(t||"")}${l}`;return{id:`prefetch_${e.kind}${e.kind==="lookup"?`_${e.input?.action||e.tool}`:""}_${n}`,kind:"prefetch",prefetch:e.kind,...e.subject?{subject:e.subject}:{},title:
|
|
7
|
+
${String(t||"")}${l}`;return{id:`prefetch_${e.kind}${e.kind==="lookup"?`_${e.input?.action||e.tool}`:""}_${n}`,kind:"prefetch",prefetch:e.kind,...e.subject?{subject:e.subject}:{},title:Ze(e,s),text:c,chars:c.length}}async function pt(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const c=s(),u=a=>{try{o({type:"tool",name:"research",prefetched:!0,...a})}catch{}};u({phase:"start",input:e.input,summary:e.label});try{const{text:a,result:i}=await ne(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:g=>u({phase:"progress",summary:`${e.label} — ${g.label}`})});if(!a)return u({phase:"done",status:"skipped",summary:e.label,ms:s()-c}),{attachment:null,text:"",result:i,note:"",status:"skipped"};const f=i.stats,w=`${f.searches} search${f.searches===1?"":"es"} · ${f.sites} site${f.sites===1?"":"s"} · ${(f.ms/1e3).toFixed(1)} s`;return u({phase:"done",status:"ok",summary:`${e.label} — ${w}`,ms:s()-c}),{attachment:tt(e,a,{now:s()}),text:a,result:i,note:w,status:"ok"}}catch(a){const i=`error: ${String(a?.message||a).slice(0,80)}`;return u({phase:"done",status:i,summary:e.label,ms:s()-c}),{attachment:null,text:"",result:null,note:"",status:i}}}export{ye as aboutOwnPast,lt as answeredByPrefetch,V as carriedPlace,J as correctedSubject,G as joinSpelled,Ge as lookupFollowup,Ze as lookupLabel,ut as lookupResult,Fe as lookupSubject,ze as newsAsk,ke as offeredSearch,T as pageAsk,tt as prefetchAttachment,it as prefetchBudgetMs,at as prefetchMissed,ht as prefetchPlan,ct as previousAsk,me as restatedWeather,pt as runResearchItem,U as stockFollowupSubject,M as stockSubject,q as weatherFollowupPlace,Z as weatherFollowupWhen,D as weatherHere,$ as weatherPlace,le as webRedoAsk};
|
package/sandbox-policy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{EventError as L}from"./event.js";import{normalizeGrant as y,SIGN_IN_NAMES as P,SIGN_IN_LABELS as x}from"./sandbox-grant.js";import{SECRET_DIR_NAMES as T,SECRET_DIR_PAIRS as H}from"./secret-names.js";const k=Object.freeze(["none","process","container","kubernetes","external"]),N=Object.freeze(["open","allowlist","none","gateway"]),S=Object.freeze(["~/.chatpanel","~/.ssh","~/.gnupg","~/.aws","~/.azure","~/.config/gcloud","~/.kube","~/.netrc","~/.docker/config.json","~/.npmrc","~/.pypirc"]),g=e=>{let t=String(e||"").trim();for(;t.length>1&&(t.endsWith("/")||t.endsWith("\\"));)t=t.slice(0,-1);return t},O=(e,t)=>t&&(e==="~"||e.startsWith("~/")||e.startsWith("~\\"))?t+e.slice(1):e,m=e=>String(e||"").replace(/\\/g,"/"),A=(e,t)=>{const n=m(g(e)),r=m(g(t));return!!n&&!!r&&(n===r||n.startsWith(`${r}/`))},G=S.map(e=>m(g(e)).replace(/^~\//,"").split("/").filter(Boolean));function W(e,t=""){const n=m(g(O(g(e),t)));if(!n)return!1;for(const o of S)if(A(n,o)||t&&A(n,O(o,t)))return!0;const r=n.split("/").filter(Boolean).map(o=>o.toLowerCase());return G.some(o=>{for(let s=0;s+o.length<=r.length;s+=1)if(o.every((l,c)=>l.toLowerCase()===r[s+c]))return!0;return!1})}const j=Object.freeze([...[...T].map(e=>`~/**/${e}`),...H.map(([e,t])=>`~/**/${e}/${t}`),...[".env",".netrc","_netrc",".git-credentials",".pgpass",".my.cnf",".npmrc",".pypirc",".htpasswd",".terraformrc",".vault-token","credentials","credentials.toml","id_rsa","id_dsa","id_ecdsa","id_ed25519","*.pem","*.p12","*.pfx","*.jks","*.keystore","*.kdbx","*.ppk"].map(e=>`~/**/${e}`)]);function ae(e,{home:t="",globs:n=[...S,...j]}={}){const r=m(g(O(g(e),t)));if(!r)return null;const o=r.split("/").filter(Boolean),s=m(g(t));for(const l of n){const c=m(g(l));if(c){if(c.startsWith("~/**/")){if(s&&!A(r,s))continue;const a=c.slice(5).split("/").filter(Boolean).map(K);for(let i=0;i+a.length<=o.length;i+=1)if(a.every((d,u)=>d.test(o[i+u])))return l;continue}if(A(r,O(c,t)))return l}}return null}function K(e){return new RegExp(`^${e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"[^/]*")}$`,"i")}const C=".cache/chatpanel/ca-bundle.crt",ce=".cache/chatpanel/ca-bundle.pem";function le(e=""){const t=m(g(e));return t?`${t}/${C}`:`~/${C}`}const B=Object.freeze(["~/.npm","~/.cache","~/.local","~/Library/Caches","~/.nvm","~/.volta","~/.asdf","~/.nodenv","~/.bun","~/.deno","~/.pyenv","~/.rye","~/.pdm","~/.cargo","~/.rustup","~/go","~/.goenv","~/.m2","~/.gradle","~/.sdkman","~/.jenv","~/.gem","~/.rbenv","~/.bundle","~/.composer","~/.nuget","~/.dotnet","~/.stack","~/.ghcup","~/.opam","~/.pub-cache","~/.gitconfig","~/.config/git"]),z=Object.freeze(["/tmp","/private/tmp","~/.cache","~/.npm","~/.local/share/uv","~/.local/state"]),v=Object.freeze({codex:Object.freeze({hosts:["api.openai.com","chatgpt.com","auth.openai.com","*.openai.com"],write:["~/.codex"]}),claude:Object.freeze({hosts:["api.anthropic.com","*.anthropic.com","claude.ai","statsig.anthropic.com"],write:["~/.claude","~/.claude.json"],keychain:!0,sockets:["/tmp/cc-socks","/private/tmp/cc-socks"]}),antigravity:Object.freeze({hosts:["*.googleapis.com","*.google.com","oauth2.googleapis.com"],write:["~/.gemini","~/.antigravity","~/.config/antigravity"]}),custom:Object.freeze({hosts:[],write:[]}),mcp:Object.freeze({hosts:[],write:[]}),extract:Object.freeze({hosts:[],write:[]}),"model-server":Object.freeze({hosts:["huggingface.co","*.huggingface.co","*.hf.co","cdn-lfs.huggingface.co","cas-bridge.xethub.hf.co","dl.chatpanel.net"],write:[]})}),M="~/Library/Keychains",U=/(^|\/)Keychains\/?$/,I=Object.freeze({aws:Object.freeze({label:x.aws,where:"~/.aws",read:["~/.aws","~/.aws/credentials","~/.aws/sso"],hosts:["*.amazonaws.com","*.api.aws"],failure:/could not load (aws )?credentials|unable to locate credentials|CredentialsProviderError|NoCredentialProviders|failed to refresh cached credentials|aws credentials? (not found|could not be)/i}),oci:Object.freeze({label:x.oci,where:"~/.oci",read:["~/.oci","~/.oci/**/*.pem"],hosts:["*.oraclecloud.com"],failure:/could not find config file at .*\.oci|ConfigFileNotFound|oci config(uration)? (file )?(was )?not found|\.oci[\\/]config.*(not found|no such file|not permitted|permission denied)/i}),gcloud:Object.freeze({label:x.gcloud,where:"~/.config/gcloud",read:["~/.config/gcloud"],hosts:["*.googleapis.com","accounts.google.com"],failure:/could not load the default credentials|DefaultCredentialsError|could not (automatically )?(find|determine) (default )?credentials|application default credentials (were|are) not (found|available)/i}),azure:Object.freeze({label:x.azure,where:"~/.azure",read:["~/.azure"],hosts:["*.azure.com","login.microsoftonline.com"],failure:/DefaultAzureCredential failed|CredentialUnavailableError|please run 'az login'|AzureCliCredential authentication (unavailable|failed)/i})});function D(e){return f((y(e).signIn||[]).flatMap(t=>I[t].read))}function Y(e){return f((y(e).signIn||[]).flatMap(t=>I[t].hosts))}function de(e,{grant:t=null,sandboxed:n=!0,agentLabel:r="This agent",agent:o=""}={}){if(!n)return null;let s=[];try{s=y(t).signIn||[]}catch{}const l=String(e||"");for(const c of P){const a=I[c];if(!(s.includes(c)||!a.failure.test(l)))return{store:c,line:`${r} could not sign in to ${a.label}: the ChatPanel sandbox keeps your ${a.label} sign-in (${a.where}) from every agent until you allow it. To allow it for this agent only, turn on ${a.label} under "May sign in with" in its Coding Agents settings${o?`, or run: chatpanel-gateway sandbox allow ${o} ${c}`:""}. Nothing else it is denied changes.`}}return null}const F=Object.freeze(["github.com","*.github.com","*.githubusercontent.com","gitlab.com","bitbucket.org","registry.npmjs.org","pypi.org","files.pythonhosted.org","crates.io","static.crates.io","proxy.golang.org","sum.golang.org","huggingface.co","*.huggingface.co"]),E=e=>!!e&&typeof e=="object"&&!Array.isArray(e),_=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.length>0),p=(e,t)=>{if(!e)throw new L("SHAPE",t)},f=e=>[...new Set(e)];function $(e){p(E(e),"kit: must be an object"),p(typeof e.id=="string"&&e.id.length>0,"kit: id required"),p(E(e.network)&&N.includes(e.network.mode),`kit ${e.id}: network.mode must be one of ${N.join(", ")}`),p(_(e.network.allowedDomains||[]),`kit ${e.id}: network.allowedDomains must be string[]`),p(_(e.network.deniedDomains||[]),`kit ${e.id}: network.deniedDomains must be string[]`),p(E(e.filesystem),`kit ${e.id}: filesystem required`);for(const t of["allowWrite","denyWrite","allowRead","denyRead"])p(_(e.filesystem[t]||[]),`kit ${e.id}: filesystem.${t} must be string[]`);return p(_(e.filesystem.allowWrite)&&e.filesystem.allowWrite.length>0,`kit ${e.id}: filesystem.allowWrite must name at least the working directory`),p(_(e.network.unixSockets||[])&&(e.network.unixSockets||[]).every(t=>t.startsWith("/")&&t.replace(/\/+$/,"")!==""),`kit ${e.id}: network.unixSockets must be absolute folders, never /`),e.image!=null&&p(typeof e.image=="string",`kit ${e.id}: image must be a string`),e.credentials!=null&&p(Array.isArray(e.credentials)&&e.credentials.every(t=>E(t)&&typeof t.name=="string"&&typeof t.forHost=="string"),`kit ${e.id}: credentials must be [{ name, forHost }]`),{id:e.id,kind:e.kind||"process",image:e.image||null,network:{mode:e.network.mode,allowedDomains:f(e.network.allowedDomains||[]),deniedDomains:f(e.network.deniedDomains||[]),...(e.network.unixSockets||[]).length?{unixSockets:f(e.network.unixSockets)}:{}},filesystem:{allowWrite:f(e.filesystem.allowWrite),denyWrite:f(e.filesystem.denyWrite||[]),allowRead:f(e.filesystem.allowRead||[]),denyRead:f(e.filesystem.denyRead||[])},credentials:e.credentials||[],limits:E(e.limits)?{...e.limits}:{}}}import{normalizeGrant as xe,mergeGrants as Se,mergePersonGrants as Oe,parseHostList as Ae,SIGN_IN_NAMES as Re,SIGN_IN_LABELS as Ie}from"./sandbox-grant.js";import{SANDBOX_READ_MODES as ke,SANDBOX_RUNTIMES as Ne,parseWrapperTemplate as We,expandWrapper as je}from"./sandbox-choice.js";const X=e=>String(e).replace(/([\\/])\*$/,"$1**");function q({engine:e="custom",cwd:t,mode:n="open",extraHosts:r=[],extraWrite:o=[],extraDenyRead:s=[],grant:l=null,home:c="",reads:a="enumerated",readOnly:i=!1,peers:d=!0}={}){const u=v[e]||v.custom;p(typeof t=="string"&&t.length>0,"kit: cwd required");const h=y(l);return $({id:`${e}:${n}`,kind:"process",network:{mode:n,allowedDomains:n==="open"?["*"]:n==="none"?[]:f([...u.hosts,...F,...r,...h.hosts,...Y(h)]),deniedDomains:[],unixSockets:d?[...u.sockets||[]]:[]},filesystem:{allowWrite:f(i?[...z,...u.write]:[t,...z,...u.write,...[...o,...h.write].filter(R=>!W(R,c)).map(X)]),denyWrite:[],allowRead:f(a==="inverted"?[t,...B,...u.write,...u.keychain?[M]:[],...Z({grant:h,extraWrite:o,cwd:t,home:c}),...D(h)]:[t,...D(h)]),denyRead:f([...a==="inverted"?["~",...c?[c]:[]]:[],...[...S,...j].filter(R=>!(u.keychain&&U.test(R))),...s])}})}const V=Object.freeze({noWrite:Object.freeze(["runtime/sandbox-runtime","runtime/ort","bin","node_modules","package.json","package-lock.json","git-hooks","policy.json","bridge-token","agent-threads.json","update-check.json","launch.vbs","workspace","worktrees","channels","desktop","cli","actions-runner","release.env"]),noRead:Object.freeze(["channels","desktop","cli","actions-runner","release.env","workspace","worktrees"])});function ue({stateDir:e,codeDirs:t=[],home:n="",mode:r="open",hosts:o=[],scratch:s=[],fence:l=V}={}){p(typeof e=="string"&&e.length>1,"gateway kit: stateDir required");const c=q({engine:"custom",cwd:e,mode:r,extraHosts:o,home:n,reads:"inverted",peers:!1}),a=u=>typeof u=="string"&&u.startsWith("/")&&u.replace(/\/+$/,"")!==""&&u!==n,i=t.filter(a),d=u=>`${e.replace(/\/+$/,"")}/${u}`;return $({...c,id:`gateway:${r}`,filesystem:{...c.filesystem,allowWrite:f([e,"/tmp","/private/tmp",...s.filter(a)]),denyWrite:f([...i,...l.noWrite.map(d)]),allowRead:f([...c.filesystem.allowRead,...i]),denyRead:f([...c.filesystem.denyRead,...l.noRead.map(d)])}})}function Q(e){if(!/[*?[{]/.test(e))return e;const t=e.split(/[\\/]/),n=t.findIndex(s=>/[*?[{]/.test(s)),r=e.includes("\\")&&!e.includes("/")?"\\":"/",o=t.slice(0,n).join(r);return o&&o!=="~"?o:""}function Z({grant:e=null,extraWrite:t=[],cwd:n="",home:r=""}={}){const o=i=>r&&(i==="~"||i.startsWith("~/")||i.startsWith("~\\"))?r+i.slice(1):i,s=i=>{let d=String(i||"").trim();for(;d.length>1&&(d.endsWith("/")||d.endsWith("\\"));)d=d.slice(0,-1);return d},l=(i,d)=>i===d||i.startsWith(`${d}/`)||i.startsWith(`${d}\\`),c=s(o(n)),a=[];for(const i of[...y(e).write,...Array.isArray(t)?t:[]]){const d=Q(s(o(s(i))));if(d&&!W(d,r)&&!(c&&l(d,c))&&!a.some(u=>l(d,u))){for(let u=a.length-1;u>=0;u--)l(a[u],d)&&a.splice(u,1);a.push(d)}}return a}function fe(e,{loopback:t=[],home:n="",platform:r="darwin"}={}){const o=$(e),s=c=>n&&c.startsWith("~")?n+c.slice(1):c,l=o.network.mode==="none"?[]:t.map(c=>`127.0.0.1:${c}`);return{network:{allowedDomains:f([...o.network.allowedDomains,...l]),deniedDomains:o.network.deniedDomains,allowLocalBinding:r==="darwin"&&l.length>0,...r==="darwin"&&o.network.unixSockets?.length?{allowUnixSockets:o.network.unixSockets}:{}},filesystem:{denyRead:o.filesystem.denyRead.map(s),allowRead:o.filesystem.allowRead.map(s),allowWrite:o.filesystem.allowWrite.map(s),denyWrite:o.filesystem.denyWrite.map(s)}}}function pe({layer:e="none",runtime:t=null,kitId:n=null,mode:r=null,reason:o=null,hosts:s=null}={}){return p(k.includes(e),`sandbox record: layer must be one of ${k.join(", ")}`),{layer:e,runtime:t,kit:n,mode:r,...e==="none"&&o?{reason:o}:{},...Array.isArray(s)&&s.length?{hosts:f(s)}:{}}}function J(e,{platform:t="darwin"}={}){const n=String(e);if(t==="win32"){p(!/[\r\n]/.test(n),"win32 command line: an argument holds a newline, which cmd.exe cannot carry");let r=n;if(n===""||/[ \t\v"]/.test(n)){r='"';for(let o=0;o<n.length;o++){let s=0;for(;o<n.length&&n[o]==="\\";)s++,o++;if(o===n.length){r+="\\".repeat(s*2);break}n[o]==='"'?r+="\\".repeat(s*2+1)+'"':r+="\\".repeat(s)+n[o]}r+='"'}return r.replace(/[()%!^"<>&|]/g,"^$&")}return n===""?"''":/^[A-Za-z0-9_\-./=:@%+,]+$/.test(n)?n:`'${n.replace(/'/g,"'\\''")}'`}const ee=Object.freeze(["SSL_CERT_FILE","REQUESTS_CA_BUNDLE","CURL_CA_BUNDLE","GIT_SSL_CAINFO"]);function ge(e={},{platform:t="darwin",caBundle:n=""}={}){const r={NODE_USE_ENV_PROXY:"1"};if(n)for(const o of ee)e[o]||(r[o]=n);if(t==="linux")for(const o of["no_proxy","NO_PROXY"])typeof e[o]=="string"&&(r[o]=e[o].split(",").map(s=>s.trim()).filter(s=>s&&!/^(localhost|127\.0\.0\.1|::1|\[::1\])$/i.test(s)).join(","));return r}function me(e,t=[],{platform:n="darwin"}={}){return[e,...t].map(r=>J(r,{platform:n})).join(" ")}const we=/[\\/]+/,w=e=>String(e||"").replace(/\//g,"\\").replace(/\\+$/,"").toLowerCase(),te=e=>/^[a-z]:$/i.test(w(e))||w(e)==="";function b(e,t){const n=w(e),r=w(t);return!!r&&n!==r&&n.startsWith(r+"\\")}function ne(e){const t=String(e||"").replace(/\//g,"\\").split("\\");if(t.length<2)return"";const n=t.findIndex(r=>r.toLowerCase()==="node_modules");return(n>0?t.slice(0,n):t.slice(0,-1)).join("\\")}function he({kit:e,files:t=[],home:n}){p(typeof n=="string"&&n.length>0,"windows grants: home required");const r=a=>(a.startsWith("~")?n+a.slice(1):a).replace(/\//g,"\\"),o=[];for(const a of e?.filesystem?.allowWrite||[]){const i=r(a);!/^[a-z]:\\/i.test(i)&&!i.startsWith("\\\\")||(p(!te(i)&&w(i)!==w(n),`windows grants: a write on ${i} would hand the sandbox account the whole profile`),b(i,n)&&o.push(i))}const s=(a,i)=>i.some(d=>w(a)===w(d)||b(a,d)),l=[];for(const a of t){const i=ne(a);i&&b(i,n)&&l.push(i)}for(const a of e?.filesystem?.allowRead||[]){if(/[*?[]/.test(a))continue;const i=r(a);b(i,n)&&l.push(i)}const c=f(l).filter(a=>!s(a,o));return{read:c.filter(a=>!c.some(i=>i!==a&&b(a,i))),write:f(o)}}const oe=Object.freeze(["ANTHROPIC_API_KEY","ANTHROPIC_AUTH_TOKEN","ANTHROPIC_BASE_URL","CLAUDE_CONFIG_DIR","OPENAI_API_KEY","OPENAI_BASE_URL","OPENAI_API_BASE","CODEX_HOME","GEMINI_API_KEY","GOOGLE_API_KEY","DEEPSEEK_API_KEY","DSH_HOME","OPENROUTER_API_KEY","GROQ_API_KEY","XAI_API_KEY","MISTRAL_API_KEY"]);function ye({engine:e="custom",home:t,env:n={},base:r={},carry:o=oe}={}){p(typeof t=="string"&&t.length>0,"windows env: home required");const s=t.replace(/\//g,"\\"),l=/^[a-z]:/i.test(s)?s.slice(0,2):"",c={USERPROFILE:s,...l?{HOMEDRIVE:l,HOMEPATH:s.slice(2)}:{}};for(const[a,i]of Object.entries(n))typeof i=="string"&&(r[a]!==i||o.includes(a))&&(c[a]=i);return e==="codex"&&!c.CODEX_HOME&&(c.CODEX_HOME=s+"\\.codex"),c}function Ee(e,t){p(Array.isArray(e),"srt-win argv: must be an array");const n=e.indexOf("exec"),r=n>=0?e.indexOf("--",n+1):-1;p(n>=0&&r>n,"srt-win argv: expected `exec … -- <shell> <command>`");const o=new Set;for(let l=n+1;l<r;l++)e[l]==="--env"&&typeof e[l+1]=="string"&&o.add(e[l+1].split("=")[0].toUpperCase());const s=[];for(const[l,c]of Object.entries(t||{}))p(/^[A-Za-z_][A-Za-z0-9_]*$/.test(l),`srt-win env: bad key ${l}`),p(!/[\r\n]/.test(c),`srt-win env: ${l} holds a newline`),o.has(l.toUpperCase())||s.push("--env",`${l}=${c}`);return[...e.slice(0,r),...s,...e.slice(r)]}export{C as CA_BUNDLE_RELPATH,ce as CA_BUNDLE_RELPATH_LEGACY,z as COMMON_WRITE,F as DEVELOPER_HOSTS,v as ENGINE_KITS,V as GATEWAY_FENCE,N as NETWORK_MODES,k as SANDBOX_LAYERS,ke as SANDBOX_READ_MODES,Ne as SANDBOX_RUNTIMES,S as SECRET_PATHS,j as SECRET_READ_GLOBS,Ie as SIGN_IN_LABELS,Re as SIGN_IN_NAMES,I as SIGN_IN_STORES,B as TOOLCHAIN_READ,oe as WINDOWS_CARRY_KEYS,le as caBundlePath,je as expandWrapper,ue as gatewayKit,W as isSecretWritePath,q as kitFor,Se as mergeGrants,Oe as mergePersonGrants,xe as normalizeGrant,Ae as parseHostList,We as parseWrapperTemplate,ae as readDenialFor,ge as sandboxEnvOverlay,pe as sandboxRecord,me as shellJoin,J as shellQuote,de as signInDenial,Y as signInHosts,D as signInRead,fe as toSrtSettings,b as underWindowsHome,$ as validateKit,he as windowsGrantsFor,ne as windowsInstallRoot,ye as windowsSandboxEnv,Ee as withSrtWinEnv,Z as writableRoots};
|
|
1
|
+
import{EventError as L}from"./event.js";import{normalizeGrant as y,SIGN_IN_NAMES as P,SIGN_IN_LABELS as x}from"./sandbox-grant.js";import{SECRET_DIR_NAMES as T,SECRET_DIR_PAIRS as H}from"./secret-names.js";const k=Object.freeze(["none","process","container","kubernetes","external"]),N=Object.freeze(["open","allowlist","none","gateway"]),O=Object.freeze(["~/.chatpanel","~/.ssh","~/.gnupg","~/.aws","~/.azure","~/.config/gcloud","~/.kube","~/.netrc","~/.docker/config.json","~/.npmrc","~/.pypirc"]),g=e=>{let t=String(e||"").trim();for(;t.length>1&&(t.endsWith("/")||t.endsWith("\\"));)t=t.slice(0,-1);return t},S=(e,t)=>t&&(e==="~"||e.startsWith("~/")||e.startsWith("~\\"))?t+e.slice(1):e,m=e=>String(e||"").replace(/\\/g,"/"),A=(e,t)=>{const n=m(g(e)),r=m(g(t));return!!n&&!!r&&(n===r||n.startsWith(`${r}/`))},G=O.map(e=>m(g(e)).replace(/^~\//,"").split("/").filter(Boolean));function j(e,t=""){const n=m(g(S(g(e),t)));if(!n)return!1;for(const o of O)if(A(n,o)||t&&A(n,S(o,t)))return!0;const r=n.split("/").filter(Boolean).map(o=>o.toLowerCase());return G.some(o=>{for(let s=0;s+o.length<=r.length;s+=1)if(o.every((l,c)=>l.toLowerCase()===r[s+c]))return!0;return!1})}const W=Object.freeze([...[...T].map(e=>`~/**/${e}`),...H.map(([e,t])=>`~/**/${e}/${t}`),...[".env",".netrc","_netrc",".git-credentials",".pgpass",".my.cnf",".npmrc",".pypirc",".htpasswd",".terraformrc",".vault-token","credentials","credentials.toml","id_rsa","id_dsa","id_ecdsa","id_ed25519","*.pem","*.p12","*.pfx","*.jks","*.keystore","*.kdbx","*.ppk"].map(e=>`~/**/${e}`)]);function ae(e,{home:t="",globs:n=[...O,...W]}={}){const r=m(g(S(g(e),t)));if(!r)return null;const o=r.split("/").filter(Boolean),s=m(g(t));for(const l of n){const c=m(g(l));if(c){if(c.startsWith("~/**/")){if(s&&!A(r,s))continue;const a=c.slice(5).split("/").filter(Boolean).map(K);for(let i=0;i+a.length<=o.length;i+=1)if(a.every((d,u)=>d.test(o[i+u])))return l;continue}if(A(r,S(c,t)))return l}}return null}function K(e){return new RegExp(`^${e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,"[^/]*")}$`,"i")}const C=".cache/chatpanel/ca-bundle.crt",ce=".cache/chatpanel/ca-bundle.pem";function le(e=""){const t=m(g(e));return t?`${t}/${C}`:`~/${C}`}const B=Object.freeze(["~/.npm","~/.cache","~/.local","~/Library/Caches","~/.nvm","~/.volta","~/.asdf","~/.nodenv","~/.bun","~/.deno","~/.pyenv","~/.rye","~/.pdm","~/.cargo","~/.rustup","~/go","~/.goenv","~/.m2","~/.gradle","~/.sdkman","~/.jenv","~/.gem","~/.rbenv","~/.bundle","~/.composer","~/.nuget","~/.dotnet","~/.stack","~/.ghcup","~/.opam","~/.pub-cache","~/.gitconfig","~/.config/git"]),z=Object.freeze(["/tmp","/private/tmp","~/.cache","~/.npm","~/.local/share/uv","~/.local/state"]),v=Object.freeze({codex:Object.freeze({hosts:["api.openai.com","chatgpt.com","auth.openai.com","*.openai.com"],write:["~/.codex"]}),claude:Object.freeze({hosts:["api.anthropic.com","*.anthropic.com","claude.ai","statsig.anthropic.com"],write:["~/.claude","~/.claude.json"],keychain:!0,sockets:["/tmp/cc-socks","/private/tmp/cc-socks"]}),antigravity:Object.freeze({hosts:["*.googleapis.com","*.google.com","oauth2.googleapis.com"],write:["~/.gemini","~/.antigravity","~/.config/antigravity"]}),opencode:Object.freeze({hosts:[],write:["~/.local/share/opencode","~/.config/opencode"]}),copilot:Object.freeze({hosts:["api.githubcopilot.com","*.githubcopilot.com","api.github.com","github.com"],write:["~/.copilot"]}),custom:Object.freeze({hosts:[],write:[]}),mcp:Object.freeze({hosts:[],write:[]}),extract:Object.freeze({hosts:[],write:[]}),"model-server":Object.freeze({hosts:["huggingface.co","*.huggingface.co","*.hf.co","cdn-lfs.huggingface.co","cas-bridge.xethub.hf.co","dl.chatpanel.net"],write:[]})}),M="~/Library/Keychains",U=/(^|\/)Keychains\/?$/,I=Object.freeze({aws:Object.freeze({label:x.aws,where:"~/.aws",read:["~/.aws","~/.aws/credentials","~/.aws/sso"],hosts:["*.amazonaws.com","*.api.aws"],failure:/could not load (aws )?credentials|unable to locate credentials|CredentialsProviderError|NoCredentialProviders|failed to refresh cached credentials|aws credentials? (not found|could not be)/i}),oci:Object.freeze({label:x.oci,where:"~/.oci",read:["~/.oci","~/.oci/**/*.pem"],hosts:["*.oraclecloud.com"],failure:/could not find config file at .*\.oci|ConfigFileNotFound|oci config(uration)? (file )?(was )?not found|\.oci[\\/]config.*(not found|no such file|not permitted|permission denied)/i}),gcloud:Object.freeze({label:x.gcloud,where:"~/.config/gcloud",read:["~/.config/gcloud"],hosts:["*.googleapis.com","accounts.google.com"],failure:/could not load the default credentials|DefaultCredentialsError|could not (automatically )?(find|determine) (default )?credentials|application default credentials (were|are) not (found|available)/i}),azure:Object.freeze({label:x.azure,where:"~/.azure",read:["~/.azure"],hosts:["*.azure.com","login.microsoftonline.com"],failure:/DefaultAzureCredential failed|CredentialUnavailableError|please run 'az login'|AzureCliCredential authentication (unavailable|failed)/i})});function D(e){return f((y(e).signIn||[]).flatMap(t=>I[t].read))}function Y(e){return f((y(e).signIn||[]).flatMap(t=>I[t].hosts))}function de(e,{grant:t=null,sandboxed:n=!0,agentLabel:r="This agent",agent:o=""}={}){if(!n)return null;let s=[];try{s=y(t).signIn||[]}catch{}const l=String(e||"");for(const c of P){const a=I[c];if(!(s.includes(c)||!a.failure.test(l)))return{store:c,line:`${r} could not sign in to ${a.label}: the ChatPanel sandbox keeps your ${a.label} sign-in (${a.where}) from every agent until you allow it. To allow it for this agent only, turn on ${a.label} under "May sign in with" in its Coding Agents settings${o?`, or run: chatpanel-gateway sandbox allow ${o} ${c}`:""}. Nothing else it is denied changes.`}}return null}const F=Object.freeze(["github.com","*.github.com","*.githubusercontent.com","gitlab.com","bitbucket.org","registry.npmjs.org","pypi.org","files.pythonhosted.org","crates.io","static.crates.io","proxy.golang.org","sum.golang.org","huggingface.co","*.huggingface.co"]),E=e=>!!e&&typeof e=="object"&&!Array.isArray(e),b=e=>Array.isArray(e)&&e.every(t=>typeof t=="string"&&t.length>0),p=(e,t)=>{if(!e)throw new L("SHAPE",t)},f=e=>[...new Set(e)];function $(e){p(E(e),"kit: must be an object"),p(typeof e.id=="string"&&e.id.length>0,"kit: id required"),p(E(e.network)&&N.includes(e.network.mode),`kit ${e.id}: network.mode must be one of ${N.join(", ")}`),p(b(e.network.allowedDomains||[]),`kit ${e.id}: network.allowedDomains must be string[]`),p(b(e.network.deniedDomains||[]),`kit ${e.id}: network.deniedDomains must be string[]`),p(E(e.filesystem),`kit ${e.id}: filesystem required`);for(const t of["allowWrite","denyWrite","allowRead","denyRead"])p(b(e.filesystem[t]||[]),`kit ${e.id}: filesystem.${t} must be string[]`);return p(b(e.filesystem.allowWrite)&&e.filesystem.allowWrite.length>0,`kit ${e.id}: filesystem.allowWrite must name at least the working directory`),p(b(e.network.unixSockets||[])&&(e.network.unixSockets||[]).every(t=>t.startsWith("/")&&t.replace(/\/+$/,"")!==""),`kit ${e.id}: network.unixSockets must be absolute folders, never /`),e.image!=null&&p(typeof e.image=="string",`kit ${e.id}: image must be a string`),e.credentials!=null&&p(Array.isArray(e.credentials)&&e.credentials.every(t=>E(t)&&typeof t.name=="string"&&typeof t.forHost=="string"),`kit ${e.id}: credentials must be [{ name, forHost }]`),{id:e.id,kind:e.kind||"process",image:e.image||null,network:{mode:e.network.mode,allowedDomains:f(e.network.allowedDomains||[]),deniedDomains:f(e.network.deniedDomains||[]),...(e.network.unixSockets||[]).length?{unixSockets:f(e.network.unixSockets)}:{}},filesystem:{allowWrite:f(e.filesystem.allowWrite),denyWrite:f(e.filesystem.denyWrite||[]),allowRead:f(e.filesystem.allowRead||[]),denyRead:f(e.filesystem.denyRead||[])},credentials:e.credentials||[],limits:E(e.limits)?{...e.limits}:{}}}import{normalizeGrant as xe,mergeGrants as Oe,mergePersonGrants as Se,parseHostList as Ae,SIGN_IN_NAMES as Re,SIGN_IN_LABELS as Ie}from"./sandbox-grant.js";import{SANDBOX_READ_MODES as ke,SANDBOX_RUNTIMES as Ne,parseWrapperTemplate as je,expandWrapper as We}from"./sandbox-choice.js";const X=e=>String(e).replace(/([\\/])\*$/,"$1**");function q({engine:e="custom",cwd:t,mode:n="open",extraHosts:r=[],extraWrite:o=[],extraDenyRead:s=[],grant:l=null,home:c="",reads:a="enumerated",readOnly:i=!1,peers:d=!0}={}){const u=v[e]||v.custom;p(typeof t=="string"&&t.length>0,"kit: cwd required");const h=y(l);return $({id:`${e}:${n}`,kind:"process",network:{mode:n,allowedDomains:n==="open"?["*"]:n==="none"?[]:f([...u.hosts,...F,...r,...h.hosts,...Y(h)]),deniedDomains:[],unixSockets:d?[...u.sockets||[]]:[]},filesystem:{allowWrite:f(i?[...z,...u.write]:[t,...z,...u.write,...[...o,...h.write].filter(R=>!j(R,c)).map(X)]),denyWrite:[],allowRead:f(a==="inverted"?[t,...B,...u.write,...u.keychain?[M]:[],...Z({grant:h,extraWrite:o,cwd:t,home:c}),...D(h)]:[t,...D(h)]),denyRead:f([...a==="inverted"?["~",...c?[c]:[]]:[],...[...O,...W].filter(R=>!(u.keychain&&U.test(R))),...s])}})}const V=Object.freeze({noWrite:Object.freeze(["runtime/sandbox-runtime","runtime/ort","bin","node_modules","package.json","package-lock.json","git-hooks","policy.json","bridge-token","agent-threads.json","update-check.json","launch.vbs","workspace","worktrees","channels","desktop","cli","actions-runner","release.env"]),noRead:Object.freeze(["channels","desktop","cli","actions-runner","release.env","workspace","worktrees"])});function ue({stateDir:e,codeDirs:t=[],home:n="",mode:r="open",hosts:o=[],scratch:s=[],fence:l=V}={}){p(typeof e=="string"&&e.length>1,"gateway kit: stateDir required");const c=q({engine:"custom",cwd:e,mode:r,extraHosts:o,home:n,reads:"inverted",peers:!1}),a=u=>typeof u=="string"&&u.startsWith("/")&&u.replace(/\/+$/,"")!==""&&u!==n,i=t.filter(a),d=u=>`${e.replace(/\/+$/,"")}/${u}`;return $({...c,id:`gateway:${r}`,filesystem:{...c.filesystem,allowWrite:f([e,"/tmp","/private/tmp",...s.filter(a)]),denyWrite:f([...i,...l.noWrite.map(d)]),allowRead:f([...c.filesystem.allowRead,...i]),denyRead:f([...c.filesystem.denyRead,...l.noRead.map(d)])}})}function Q(e){if(!/[*?[{]/.test(e))return e;const t=e.split(/[\\/]/),n=t.findIndex(s=>/[*?[{]/.test(s)),r=e.includes("\\")&&!e.includes("/")?"\\":"/",o=t.slice(0,n).join(r);return o&&o!=="~"?o:""}function Z({grant:e=null,extraWrite:t=[],cwd:n="",home:r=""}={}){const o=i=>r&&(i==="~"||i.startsWith("~/")||i.startsWith("~\\"))?r+i.slice(1):i,s=i=>{let d=String(i||"").trim();for(;d.length>1&&(d.endsWith("/")||d.endsWith("\\"));)d=d.slice(0,-1);return d},l=(i,d)=>i===d||i.startsWith(`${d}/`)||i.startsWith(`${d}\\`),c=s(o(n)),a=[];for(const i of[...y(e).write,...Array.isArray(t)?t:[]]){const d=Q(s(o(s(i))));if(d&&!j(d,r)&&!(c&&l(d,c))&&!a.some(u=>l(d,u))){for(let u=a.length-1;u>=0;u--)l(a[u],d)&&a.splice(u,1);a.push(d)}}return a}function fe(e,{loopback:t=[],home:n="",platform:r="darwin"}={}){const o=$(e),s=c=>n&&c.startsWith("~")?n+c.slice(1):c,l=o.network.mode==="none"?[]:t.map(c=>`127.0.0.1:${c}`);return{network:{allowedDomains:f([...o.network.allowedDomains,...l]),deniedDomains:o.network.deniedDomains,allowLocalBinding:r==="darwin"&&l.length>0,...r==="darwin"&&o.network.unixSockets?.length?{allowUnixSockets:o.network.unixSockets}:{}},filesystem:{denyRead:o.filesystem.denyRead.map(s),allowRead:o.filesystem.allowRead.map(s),allowWrite:o.filesystem.allowWrite.map(s),denyWrite:o.filesystem.denyWrite.map(s)}}}function pe({layer:e="none",runtime:t=null,kitId:n=null,mode:r=null,reason:o=null,hosts:s=null}={}){return p(k.includes(e),`sandbox record: layer must be one of ${k.join(", ")}`),{layer:e,runtime:t,kit:n,mode:r,...e==="none"&&o?{reason:o}:{},...Array.isArray(s)&&s.length?{hosts:f(s)}:{}}}function J(e,{platform:t="darwin"}={}){const n=String(e);if(t==="win32"){p(!/[\r\n]/.test(n),"win32 command line: an argument holds a newline, which cmd.exe cannot carry");let r=n;if(n===""||/[ \t\v"]/.test(n)){r='"';for(let o=0;o<n.length;o++){let s=0;for(;o<n.length&&n[o]==="\\";)s++,o++;if(o===n.length){r+="\\".repeat(s*2);break}n[o]==='"'?r+="\\".repeat(s*2+1)+'"':r+="\\".repeat(s)+n[o]}r+='"'}return r.replace(/[()%!^"<>&|]/g,"^$&")}return n===""?"''":/^[A-Za-z0-9_\-./=:@%+,]+$/.test(n)?n:`'${n.replace(/'/g,"'\\''")}'`}const ee=Object.freeze(["SSL_CERT_FILE","REQUESTS_CA_BUNDLE","CURL_CA_BUNDLE","GIT_SSL_CAINFO"]);function ge(e={},{platform:t="darwin",caBundle:n=""}={}){const r={NODE_USE_ENV_PROXY:"1"};if(n)for(const o of ee)e[o]||(r[o]=n);if(t==="linux")for(const o of["no_proxy","NO_PROXY"])typeof e[o]=="string"&&(r[o]=e[o].split(",").map(s=>s.trim()).filter(s=>s&&!/^(localhost|127\.0\.0\.1|::1|\[::1\])$/i.test(s)).join(","));return r}function me(e,t=[],{platform:n="darwin"}={}){return[e,...t].map(r=>J(r,{platform:n})).join(" ")}const we=/[\\/]+/,w=e=>String(e||"").replace(/\//g,"\\").replace(/\\+$/,"").toLowerCase(),te=e=>/^[a-z]:$/i.test(w(e))||w(e)==="";function _(e,t){const n=w(e),r=w(t);return!!r&&n!==r&&n.startsWith(r+"\\")}function ne(e){const t=String(e||"").replace(/\//g,"\\").split("\\");if(t.length<2)return"";const n=t.findIndex(r=>r.toLowerCase()==="node_modules");return(n>0?t.slice(0,n):t.slice(0,-1)).join("\\")}function he({kit:e,files:t=[],home:n}){p(typeof n=="string"&&n.length>0,"windows grants: home required");const r=a=>(a.startsWith("~")?n+a.slice(1):a).replace(/\//g,"\\"),o=[];for(const a of e?.filesystem?.allowWrite||[]){const i=r(a);!/^[a-z]:\\/i.test(i)&&!i.startsWith("\\\\")||(p(!te(i)&&w(i)!==w(n),`windows grants: a write on ${i} would hand the sandbox account the whole profile`),_(i,n)&&o.push(i))}const s=(a,i)=>i.some(d=>w(a)===w(d)||_(a,d)),l=[];for(const a of t){const i=ne(a);i&&_(i,n)&&l.push(i)}for(const a of e?.filesystem?.allowRead||[]){if(/[*?[]/.test(a))continue;const i=r(a);_(i,n)&&l.push(i)}const c=f(l).filter(a=>!s(a,o));return{read:c.filter(a=>!c.some(i=>i!==a&&_(a,i))),write:f(o)}}const oe=Object.freeze(["ANTHROPIC_API_KEY","ANTHROPIC_AUTH_TOKEN","ANTHROPIC_BASE_URL","CLAUDE_CONFIG_DIR","OPENAI_API_KEY","OPENAI_BASE_URL","OPENAI_API_BASE","CODEX_HOME","GEMINI_API_KEY","GOOGLE_API_KEY","DEEPSEEK_API_KEY","DSH_HOME","OPENROUTER_API_KEY","GROQ_API_KEY","XAI_API_KEY","MISTRAL_API_KEY"]);function ye({engine:e="custom",home:t,env:n={},base:r={},carry:o=oe}={}){p(typeof t=="string"&&t.length>0,"windows env: home required");const s=t.replace(/\//g,"\\"),l=/^[a-z]:/i.test(s)?s.slice(0,2):"",c={USERPROFILE:s,...l?{HOMEDRIVE:l,HOMEPATH:s.slice(2)}:{}};for(const[a,i]of Object.entries(n))typeof i=="string"&&(r[a]!==i||o.includes(a))&&(c[a]=i);return e==="codex"&&!c.CODEX_HOME&&(c.CODEX_HOME=s+"\\.codex"),c}function Ee(e,t){p(Array.isArray(e),"srt-win argv: must be an array");const n=e.indexOf("exec"),r=n>=0?e.indexOf("--",n+1):-1;p(n>=0&&r>n,"srt-win argv: expected `exec … -- <shell> <command>`");const o=new Set;for(let l=n+1;l<r;l++)e[l]==="--env"&&typeof e[l+1]=="string"&&o.add(e[l+1].split("=")[0].toUpperCase());const s=[];for(const[l,c]of Object.entries(t||{}))p(/^[A-Za-z_][A-Za-z0-9_]*$/.test(l),`srt-win env: bad key ${l}`),p(!/[\r\n]/.test(c),`srt-win env: ${l} holds a newline`),o.has(l.toUpperCase())||s.push("--env",`${l}=${c}`);return[...e.slice(0,r),...s,...e.slice(r)]}export{C as CA_BUNDLE_RELPATH,ce as CA_BUNDLE_RELPATH_LEGACY,z as COMMON_WRITE,F as DEVELOPER_HOSTS,v as ENGINE_KITS,V as GATEWAY_FENCE,N as NETWORK_MODES,k as SANDBOX_LAYERS,ke as SANDBOX_READ_MODES,Ne as SANDBOX_RUNTIMES,O as SECRET_PATHS,W as SECRET_READ_GLOBS,Ie as SIGN_IN_LABELS,Re as SIGN_IN_NAMES,I as SIGN_IN_STORES,B as TOOLCHAIN_READ,oe as WINDOWS_CARRY_KEYS,le as caBundlePath,We as expandWrapper,ue as gatewayKit,j as isSecretWritePath,q as kitFor,Oe as mergeGrants,Se as mergePersonGrants,xe as normalizeGrant,Ae as parseHostList,je as parseWrapperTemplate,ae as readDenialFor,ge as sandboxEnvOverlay,pe as sandboxRecord,me as shellJoin,J as shellQuote,de as signInDenial,Y as signInHosts,D as signInRead,fe as toSrtSettings,_ as underWindowsHome,$ as validateKit,he as windowsGrantsFor,ne as windowsInstallRoot,ye as windowsSandboxEnv,Ee as withSrtWinEnv,Z as writableRoots};
|