@chatpanel/events 0.405.0 → 0.425.2
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/capability-adapters.js +1 -1
- package/capability-config.js +1 -0
- package/capability-endpoints.js +1 -1
- package/capability-tools.js +4 -3
- package/compaction.js +7 -5
- package/context-window.js +1 -1
- package/decide-ask.js +1 -0
- package/fast-path.js +6 -6
- package/gateway-dests.js +1 -1
- package/history-search.js +7 -6
- package/index.js +1 -1
- package/lookup-decider.js +1 -0
- package/model-catalog.js +1 -0
- package/model-registry.js +1 -1
- package/model-view.js +3 -0
- package/package.json +15 -1
- package/prefetch.js +4 -4
- package/relayed-echo.js +1 -0
- package/retrieval-plan.js +2 -2
- package/route-decider.js +2 -2
- package/runtime-in-process.js +1 -1
- package/runtime-layout.js +1 -0
- package/settings-registry.js +1 -1
- package/shim.js +2 -2
- package/tool-loop-guard.js +8 -4
- package/tool-need.js +3 -3
- package/turn-intent.js +3 -3
- package/turn-loop.js +4 -4
- package/turn-pipeline.js +3 -3
package/prefetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{researchAsk as N,runResearch as oe}from"./web-research.js";import{frontPagesAskedAbout as re}from"./site-pages.js";import{weatherFromSearch as ae}from"./weather-tool.js";import{PAGE_READ_ARGS as C}from"./page-context.js";const P=/(\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,ie=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,A=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),T=8,j="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",ce=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${j}\\b`,"i"),he=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+${j}(?:\\s+and\\s+(?:the\\s+)?${j})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),le=/\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,ue=/^\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 pe(e){const t=ue.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const de=/\b(?:weather|forecast|temperature|rain|snow)\b/i,fe=/\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,we=/\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,ge=/\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,be=/^\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,ke=/\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,me=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function ye(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(ke.test(t)&&/\?/.test(t)){const s=(me.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,W=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function $e(e){const t=String(e||"");if(!L.test(t)||W.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 Se(e){const t=String(e||"");return L.test(t)&&!W.test(t)?!1:we.test(t)}const _e=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i;function F(e){const t=String(e||"").trim();return!t||t.length>300||le.test(t)?null:ce.test(t)||he.test(t)?{}:null}function w(e){return String(e||"").replace(ie," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const D=/\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 $(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!A.has(t)&&!D.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function v(e){const t=String(e||"").trim();return!P.test(t)||S(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 Ee=/\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 S(e){const t=String(e||"").trim();if(!P.test(t))return"";const n=t.replace(Ee,"").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=w(s[1].split(/\s+(?:and|&|vs\.?|versus|compared (?:to|with)|then|,)\s+/i)[0]);if($(o))return o;if($(w(s[1])))return w(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&&$(w(s[1]))&&!O.test(w(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&$(w(s[1])))?w(s[1]):""}const O=/\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,Ae=/^(?:(?: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,je=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,q=/^(?:(?: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 B(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace(Ae,"").trim().replace(je,"").trim();if(!s||s.split(/\s+/).length>T)return"";const o=q.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=w(s.replace(q,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!$(r)||O.test(r)?"":r}const m="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",Le=[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],Oe=/^(?: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,Re=/^(?: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,xe=/\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 M(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Oe.test(t)&&!D.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function Ne(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&Re.test(t[0]);)t.shift();return t.join(" ")}function U(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(xe,"").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 I(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 Le){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=Ne(U(r[1]));if(M(l))return l}return""}function G(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>T)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=U(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!M(o)||O.test(o)?"":o}const H=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function J(e){return String(e||"").replace(H,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function Ce(e){return[...String(e||"").matchAll(H)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Pe=/\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,Te=/[.?!;:,()](?=\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,We=/^(?: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,Fe=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,De=/^(?:the|a|an)\b/i,ve=6;function K(e){const n=(String(e||"").split(Te)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>ve||!new RegExp("\\p{L}","u").test(n)||We.test(n)?"":n}function qe(e){const t=Pe.exec(J(e));return t?K(t[1]):""}const Be=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],Me=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,Ue=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function Ie(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 h=1;h<=s.length;h++){const u=o[h];o[h]=Math.min(o[h]+1,o[h-1]+1,l+(n[r-1]===s[h-1]?0:1)),l=u}}return o[s.length]}function Ge(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function Y(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=Ce(s),r=J(s);let l=o.at(-1)||"";if(!l&&Ue.test(r)&&(l=Me.exec(r)?.[1]||""),!l||l.length<2)return null;const h=n.split(/\s+/);let u=-1;for(const[i,p]of Be)if(i.test(r)){u=p(h);break}if(u<0){let i=1/0;h.forEach((p,g)=>{const b=Ie(p,l)/Math.max(p.length,l.length);b<i&&(i=b,u=g)}),i>.6&&(u=h.length===1?0:-1)}if(u<0)return null;const a=h[u];return a.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(h[u]=Ge(l,h.find(i=>new RegExp("^\\p{Lu}","u").test(i))||a),{subject:h.join(" "),replaced:a})}const He=/\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,z=/\b(?:web|online|internet|google)\b/i;function Je(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=Y(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!He.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:z.test(e)}}function X(e,t){const n=qe(e);if(n){const o=Y(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:z.test(e)}}const s=Je(e,t);return s?{kind:"lookup",...s}:null}function Q(e){return Fe.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!De.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const Ke=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,Ye=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,ze=/^(?:(?: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,Xe=/^(?:(?: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,V=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function Qe(e){const t=String(e||"").trim();if(!t||re(t).length)return null;if(Xe.test(t))return{subject:""};const n=Ke.exec(t)||ze.exec(t),s=n?null:Ye.exec(t),o=n||s;if(!o)return null;const r=K(o[1].replace(/[?.!]+$/,"").replace(V,"")).replace(V,"");return s&&r.split(/\s+/).length>4||!r||!Q(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function lt(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const Z=Object.freeze({page:15e3,web:12e3,lookup:12e3}),Ve=6e3;function ut(e){return Object.hasOwn(Z,e?.kind)?Z[e.kind]:Ve}const Ze=/^\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 ee(e,t){if(!t||t.kind!=="weather")return"";const n=String(t.subject||"");if(!n||A.has(n.toLowerCase()))return"";const s=String(e||"").toLowerCase();return[...A].some(o=>o!=="it"&&o!=="that"&&new RegExp(`\\b${o}\\b`).test(s))?"":n}function te(e,t){return!t||t.kind!=="weather"?"":Ze.test(String(e||""))?String(t.subject||"here"):""}function et(e,t){const n=S(e)||te(e,t)||B(e,t);if(n)return{kind:"weather",subject:n};if(v(e))return{kind:"weather",subject:ee(e,t)||"here"};const s=I(e)||G(e,t);if(s)return{kind:"stock",subject:s};const o=X(String(e||""),t);if(o)return o;const r=N(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function pt(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,h=(r.attachments||[]).find(p=>p?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"",a=et(u,s)||(h?{kind:h.prefetch,...h.research?{research:h.research}:{}}:null)||((l?.steps||[]).some(p=>p?.input?.action==="weather"||p?.tool==="weather")?{kind:"weather"}:null),i=tt(h?.text);s=a&&{...a,...i?{resolved:i}:s?.resolved&&s.kind===a.kind?{resolved:s.resolved}:{}}}return s}function tt(e){const t=/(?:^|\n)\w+ for ([^\n(]+?)\s*\(asked:/.exec(String(e||""));return t?t[1].trim():""}function nt(e,t,n){if(!e?.resolved||e.kind!==t||/,/.test(String(n||"")))return"";const s=String(e.resolved).split(",").map(o=>o.trim()).filter(Boolean);return s.length>1?s.slice(1).join(", "):""}function dt({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:h=!1,now:u=Date.now()}={}){const a=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),i=[];if(Se(e))return r?ne(e,t,a):[];const p=be.test(String(e||""))?ye(s):"",g=String(e||"").trim().split(/\s+/).length,b=pe(e)||(p?{query:p}:null)||(ge.test(String(e||""))&&g<=14?{}:null);if(b&&(a.has("find:web_search")||a.has("web_search"))){const c=b.query||String(n||"").trim();if(c){const d=a.has("find:web_search"),f=!b.query;return[{kind:"web",tool:d?"find":"web_search",input:d?{action:"web_search",args:{query:c}}:{query:c},label:`Web — ${c.slice(0,60)}`,subject:c,...de.test(c)?{weather:!0}:{},...f?{borrowed:!0}:{}}]}}if(h&&(a.has("page:read_page")||a.has("read_page"))&&F(e)){const c=a.has("page:read_page"),d=_e.test(e)&&F(n)?String(n).trim():"";return[{kind:"page",tool:c?"page":"read_page",input:c?{action:"read_page",args:{...C}}:{...C},label:"This page",...d?{ask:d}:{}}]}const _=a.has("find:weather"),se=a.has("weather");if(_||se){e=$e(e)||e;const c=S(e)?"":te(e,t),d=S(e)||(c?c!=="here"?c:"":B(e,t)),f=d||(v(e)?ee(e,t)||"here":c?"here":"");if(f){const E=f!=="here"?nt(t,"weather",f):"",R=y=>_?{action:"weather",args:{location:y}}:{location:y};if(i.push({kind:"weather",tool:_?"find":"weather",input:R(f),label:d?`Weather — ${d}`:"Weather — near you",...d?{about:d}:{},...E?{retry:{input:R(`${f}, ${E}`),context:E.split(",")[0].trim()}}:{}}),d&&fe.test(String(e||""))&&(a.has("find:web_search")||a.has("web_search"))){const y=`${d} 10 day weather forecast`,x=a.has("find:web_search");i.push({kind:"web",tool:x?"find":"web_search",input:x?{action:"web_search",args:{query:y}}:{query:y},label:`Web — ${d} extended forecast`,subject:y,weather:!0})}}}const k=a.has("find:web_search");if(!i.length&&(k||a.has("web_search"))){const c=I(e)||G(e,t);if(c){const d=`${c} stock price today`;i.push({kind:"stock",tool:k?"find":"web_search",input:k?{action:"web_search",args:{query:d}}:{query:d},label:`Stock — ${c}`,about:c})}}if(!i.length&&(k||a.has("web_search"))){const c=Qe(e);if(c){const d=c.subject?`${c.subject} news today`:"top news today";i.push({kind:"news",tool:k?"find":"web_search",input:k?{action:"web_search",args:{query:d}}:{query:d},label:c.subject?`News — ${c.subject}`:"News — today",subject:c.subject,...c.subject?{about:c.subject}:{}})}}if(l&&!i.length&&(k||a.has("web_search"))){const c=N(e,{previous:t,now:u});if(c){const d=k?"find":"web_search";i.push({kind:"research",tool:d,input:d==="find"?{action:"web_search",args:{query:c.queries[0]}}:{query:c.queries[0]},label:`Research — ${c.subject}`,subject:c.subject,research:[...a].some(f=>/^(?:page:)?(?:open_tab|navigate)$/.test(f))?{...c,browse:!0}:c})}}return r&&!i.length&&i.push(...ne(e,t,a)),i}function ne(e,t,n){const s=X(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:p=>({action:i,args:p})}:n.has(i)?{tool:i,input:p=>p}:null,h=[],u=l("history_search"),a=l("web_search");return u&&!s.web&&h.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),a&&(s.web||Q(o))&&h.push({kind:"lookup",tool:a.tool,input:a.input({query:o}),label:`Web — ${o}`,subject:o,about:o,note:r,fallback:h.length>0}),h}function ft(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 wt(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 st(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function ot(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 P,runResearch as ae}from"./web-research.js";import{frontPagesAskedAbout as ie}from"./site-pages.js";import{weatherFromSearch as ce}from"./weather-tool.js";import{PAGE_READ_ARGS as T}from"./page-context.js";const W=/(\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,he=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,j=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),D=8,L="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",le=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${L}\\b`,"i"),ue=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+${L}(?:\\s+and\\s+(?:the\\s+)?${L})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),pe=/\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,de=/^\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 fe(e){const t=de.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const we=/\b(?:weather|forecast|temperature|rain|snow)\b/i,ge=/\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,be=/\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,me=/\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,ke=/^\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,ye=/\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,$e=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function Se(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(ye.test(t)&&/\?/.test(t)){const s=($e.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 O=/^\s*(?:(?:no|nope|actually|but|well|sorry)\b[,.!]?\s*)?(?:i|we) (?:asked|said|meant|wanted)\b/i,F=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function _e(e){const t=String(e||"");if(!O.test(t)||F.test(t))return"";const n=t.replace(O,"").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 Ee(e){const t=String(e||"");return O.test(t)&&!F.test(t)?!1:be.test(t)}const Ae=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i,je=/(?:published|posted|shared|discussed|trending|featured|submitted)\s+(?:on|in|to|at)\s+(?:the\s+)?([a-z0-9][\w.-]*(?:\s+[a-z0-9][\w.-]*)?)/i,R=e=>String(e||"").toLowerCase().replace(/[^a-z0-9]+/g,"");function Le(e,t){if(!t||!(t.title||t.url))return!1;const n=je.exec(String(e||""));if(!n)return!1;let s="";try{s=new URL(String(t.url||"")).hostname}catch{}const o=R(`${t.title||""} ${s}`),r=n[1].split(/\s+/);return![r.join(""),r[0]].some(l=>R(l).length>=2&&o.includes(R(l)))}function q(e){const t=String(e||"").trim();return!t||t.length>300||pe.test(t)?null:le.test(t)||ue.test(t)?{}:null}function g(e){return String(e||"").replace(he," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const v=/\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 $(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!j.has(t)&&!v.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function B(e){const t=String(e||"").trim();return!W.test(t)||S(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 Oe=/\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 S(e){const t=String(e||"").trim();if(!W.test(t))return"";const n=t.replace(Oe,"").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=g(s[1].split(/\s+(?:and|&|vs\.?|versus|compared (?:to|with)|then|,)\s+/i)[0]);if($(o))return o;if($(g(s[1])))return g(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&&$(g(s[1]))&&!x.test(g(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&$(g(s[1])))?g(s[1]):""}const x=/\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,Re=/^(?:(?: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,xe=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,U=/^(?:(?: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 M(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace(Re,"").trim().replace(xe,"").trim();if(!s||s.split(/\s+/).length>D)return"";const o=U.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=g(s.replace(U,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!$(r)||x.test(r)?"":r}const m="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",Ce=[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],Ne=/^(?: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,Pe=/^(?: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,Te=/\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 I(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Ne.test(t)&&!v.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function We(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&Pe.test(t[0]);)t.shift();return t.join(" ")}function G(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(Te,"").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 H(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 Ce){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=We(G(r[1]));if(I(l))return l}return""}function J(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>D)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=G(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!I(o)||x.test(o)?"":o}const z=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function K(e){return String(e||"").replace(z,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function De(e){return[...String(e||"").matchAll(z)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Fe=/\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,qe=/[.?!;:,()](?=\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,ve=/^(?: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,Be=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,Ue=/^(?:the|a|an)\b/i,Me=6;function Y(e){const n=(String(e||"").split(qe)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>Me||!new RegExp("\\p{L}","u").test(n)||ve.test(n)?"":n}function Ie(e){const t=Fe.exec(K(e));return t?Y(t[1]):""}const Ge=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],He=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,Je=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function ze(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 Ke(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function X(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=De(s),r=K(s);let l=o.at(-1)||"";if(!l&&Je.test(r)&&(l=He.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let u=-1;for(const[a,h]of Ge)if(a.test(r)){u=h(c);break}if(u<0){let a=1/0;c.forEach((h,f)=>{const k=ze(h,l)/Math.max(h.length,l.length);k<a&&(a=k,u=f)}),a>.6&&(u=c.length===1?0:-1)}if(u<0)return null;const p=c[u];return p.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[u]=Ke(l,c.find(a=>new RegExp("^\\p{Lu}","u").test(a))||p),{subject:c.join(" "),replaced:p})}const Ye=/\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,Q=/\b(?:web|online|internet|google)\b/i;function Xe(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=X(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Ye.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:Q.test(e)}}function V(e,t){const n=Ie(e);if(n){const o=X(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:Q.test(e)}}const s=Xe(e,t);return s?{kind:"lookup",...s}:null}function Z(e){return Be.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!Ue.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const Qe=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,Ve=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,Ze=/^(?:(?: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,et=/^(?:(?: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,ee=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function tt(e){const t=String(e||"").trim();if(!t||ie(t).length)return null;if(et.test(t))return{subject:""};const n=Qe.exec(t)||Ze.exec(t),s=n?null:Ve.exec(t),o=n||s;if(!o)return null;const r=Y(o[1].replace(/[?.!]+$/,"").replace(ee,"")).replace(ee,"");return s&&r.split(/\s+/).length>4||!r||!Z(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function ft(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const te=Object.freeze({page:15e3,web:12e3,lookup:12e3}),nt=6e3;function wt(e){return Object.hasOwn(te,e?.kind)?te[e.kind]:nt}const st=/^\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 ne(e,t){if(!t||t.kind!=="weather")return"";const n=String(t.subject||"");if(!n||j.has(n.toLowerCase()))return"";const s=String(e||"").toLowerCase();return[...j].some(o=>o!=="it"&&o!=="that"&&new RegExp(`\\b${o}\\b`).test(s))?"":n}function se(e,t){return!t||t.kind!=="weather"?"":st.test(String(e||""))?String(t.subject||"here"):""}function ot(e,t){const n=S(e)||se(e,t)||M(e,t);if(n)return{kind:"weather",subject:n};if(B(e))return{kind:"weather",subject:ne(e,t)||"here"};const s=H(e)||J(e,t);if(s)return{kind:"stock",subject:s};const o=V(String(e||""),t);if(o)return o;const r=P(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function gt(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(h=>h?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"",p=ot(u,s)||(c?{kind:c.prefetch,...c.research?{research:c.research}:{}}:null)||((l?.steps||[]).some(h=>h?.input?.action==="weather"||h?.tool==="weather")?{kind:"weather"}:null),a=rt(c?.text);s=p&&{...p,...a?{resolved:a}:s?.resolved&&s.kind===p.kind?{resolved:s.resolved}:{}}}return s}function rt(e){const t=/(?:^|\n)\w+ for ([^\n(]+?)\s*\(asked:/.exec(String(e||""));return t?t[1].trim():""}function at(e,t,n){if(!e?.resolved||e.kind!==t||/,/.test(String(n||"")))return"";const s=String(e.resolved).split(",").map(o=>o.trim()).filter(Boolean);return s.length>1?s.slice(1).join(", "):""}function bt({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,tab:u=null,now:p=Date.now()}={}){const a=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),h=[];if(Ee(e))return r?oe(e,t,a):[];const f=ke.test(String(e||""))?Se(s):"",k=String(e||"").trim().split(/\s+/).length,_=fe(e)||(f?{query:f}:null)||(me.test(String(e||""))&&k<=14?{}:null);if(_&&(a.has("find:web_search")||a.has("web_search"))){const i=_.query||String(n||"").trim();if(i){const d=a.has("find:web_search"),w=!_.query;return[{kind:"web",tool:d?"find":"web_search",input:d?{action:"web_search",args:{query:i}}:{query:i},label:`Web — ${i.slice(0,60)}`,subject:i,...we.test(i)?{weather:!0}:{},...w?{borrowed:!0}:{}}]}}if(c&&(a.has("page:read_page")||a.has("read_page"))&&q(e)&&!Le(e,u)){const i=a.has("page:read_page"),d=Ae.test(e)&&q(n)?String(n).trim():"";return[{kind:"page",tool:i?"page":"read_page",input:i?{action:"read_page",args:{...T}}:{...T},label:"This page",...d?{ask:d}:{}}]}const E=a.has("find:weather"),re=a.has("weather");if(E||re){e=_e(e)||e;const i=S(e)?"":se(e,t),d=S(e)||(i?i!=="here"?i:"":M(e,t)),w=d||(B(e)?ne(e,t)||"here":i?"here":"");if(w){const A=w!=="here"?at(t,"weather",w):"",C=y=>E?{action:"weather",args:{location:y}}:{location:y};if(h.push({kind:"weather",tool:E?"find":"weather",input:C(w),label:d?`Weather — ${d}`:"Weather — near you",...d?{about:d}:{},...A?{retry:{input:C(`${w}, ${A}`),context:A.split(",")[0].trim()}}:{}}),d&&ge.test(String(e||""))&&(a.has("find:web_search")||a.has("web_search"))){const y=`${d} 10 day weather forecast`,N=a.has("find:web_search");h.push({kind:"web",tool:N?"find":"web_search",input:N?{action:"web_search",args:{query:y}}:{query:y},label:`Web — ${d} extended forecast`,subject:y,weather:!0})}}}const b=a.has("find:web_search");if(!h.length&&(b||a.has("web_search"))){const i=H(e)||J(e,t);if(i){const d=`${i} stock price today`;h.push({kind:"stock",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:d}}:{query:d},label:`Stock — ${i}`,about:i})}}if(!h.length&&(b||a.has("web_search"))){const i=tt(e);if(i){const d=i.subject?`${i.subject} news today`:"top news today";h.push({kind:"news",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:d}}:{query:d},label:i.subject?`News — ${i.subject}`:"News — today",subject:i.subject,...i.subject?{about:i.subject}:{}})}}if(l&&!h.length&&(b||a.has("web_search"))){const i=P(e,{previous:t,now:p});if(i){const d=b?"find":"web_search";h.push({kind:"research",tool:d,input:d==="find"?{action:"web_search",args:{query:i.queries[0]}}:{query:i.queries[0]},label:`Research — ${i.subject}`,subject:i.subject,research:[...a].some(w=>/^(?:page:)?(?:open_tab|navigate)$/.test(w))?{...i,browse:!0}:i})}}return r&&!h.length&&h.push(...oe(e,t,a)),h}function oe(e,t,n){const s=V(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:h=>({action:a,args:h})}:n.has(a)?{tool:a,input:h=>h}:null,c=[],u=l("history_search"),p=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}),p&&(s.web||Z(o))&&c.push({kind:"lookup",tool:p.tool,input:p.input({query:o}),label:`Web — ${o}`,subject:o,about:o,note:r,fallback:c.length>0}),c}function mt(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 kt(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 it(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function ct(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 ht(e,t,{now:n=Date.now(),note:s=""}={}){if(e.kind==="web"&&e.weather&&(t=ce(t)||t),e.kind==="page"&&(t=ct(t)),e.kind==="research"){const u=String(t||""),{question:p,domain:a,subject:h,slots:f}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||h||"",research:{question:p,domain:a,subject:h,slots:f},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
|
-
The question about this page: ${e.ask.slice(0,200)}`:"",
|
|
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:it(e,s),text:c,chars:c.length}}async function yt(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const c=s(),u=p=>{try{o({type:"tool",name:"research",prefetched:!0,...p})}catch{}};u({phase:"start",input:e.input,summary:e.label});try{const{text:p,result:a}=await ae(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:k=>u({phase:"progress",summary:`${e.label} — ${k.label}`})});if(!p)return u({phase:"done",status:"skipped",summary:e.label,ms:s()-c}),{attachment:null,text:"",result:a,note:"",status:"skipped"};const h=a.stats,f=`${h.searches} search${h.searches===1?"":"es"} · ${h.sites} site${h.sites===1?"":"s"} · ${(h.ms/1e3).toFixed(1)} s`;return u({phase:"done",status:"ok",summary:`${e.label} — ${f}`,ms:s()-c}),{attachment:ht(e,p,{now:s()}),text:p,result:a,note:f,status:"ok"}}catch(p){const a=`error: ${String(p?.message||p).slice(0,80)}`;return u({phase:"done",status:a,summary:e.label,ms:s()-c}),{attachment:null,text:"",result:null,note:"",status:a}}}export{Ee as aboutOwnPast,mt as answeredByPrefetch,at as borrowedContext,ne as carriedPlace,X as correctedSubject,K as joinSpelled,Xe as lookupFollowup,it as lookupLabel,kt as lookupResult,Ie as lookupSubject,tt as newsAsk,Se as offeredSearch,q as pageAsk,Le as placedElsewhere,ht as prefetchAttachment,wt as prefetchBudgetMs,ft as prefetchMissed,bt as prefetchPlan,gt as previousAsk,rt as resolvedOf,_e as restatedWeather,yt as runResearchItem,J as stockFollowupSubject,H as stockSubject,M as weatherFollowupPlace,se as weatherFollowupWhen,B as weatherHere,S as weatherPlace,fe as webRedoAsk};
|
package/relayed-echo.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function c(t){const e=String(t||""),n=/^mcp__[A-Za-z0-9-]+(?:_[A-Za-z0-9-]+)*?__(.+)$/.exec(e);if(n)return n[1];const r=/^mcp:[^/]+\/(.+)$/.exec(e);return r?r[1]:null}function a(t,e){if(t?.type!=="tool")return!1;const n=c(t.name);return n?(e instanceof Set?e:new Set(Array.isArray(e)?e:[])).has(n):!1}export{a as isRelayedEcho,c as mcpToolOf};
|
package/retrieval-plan.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{needsWhole as E,noteShape as C}from"./digest.js";import{lookupSubject as P,prefetchPlan as
|
|
2
|
-
${String(o.text||"")}`})):n}function ae(r=[],
|
|
1
|
+
import{needsWhole as E,noteShape as C}from"./digest.js";import{lookupSubject as P,prefetchPlan as _,answeredByPrefetch as D}from"./prefetch.js";import{partChars as W,STITCH_LIMITS as q}from"./stitch.js";import{isSmallWindow as k,FIT_HEADROOM as F,SMALL_WINDOW_ROUNDS as b}from"./context-window.js";import{isPleasantry as L}from"./tool-need.js";const j=4,H={device:3,api:2,agent:8};function ee({question:r="",sources:e=[],fixedTokens:n=0,target:o={}}={}){const a=o.kind||"api",s=Number(o.window)||0,i=k(s),c=E(r),S=Math.max(1,Number(o.concurrency)||(a==="device"?1:4)),M=Number(o.secondsPerCall)||H[a]||2,u=(Array.isArray(e)?e:[]).filter(Boolean).map(t=>({...t,chars:Math.max(0,Number(t.chars)||0)})),d=s?Math.floor(s*F)-(Number(o.reserve)||1024)-(Number(n)||0):1/0,m=Number.isFinite(d)?Math.max(0,d)*j:1/0,g=new Map,h=new Set;let f=m;for(let t=!0;t;){t=!1;const l=u.filter(w=>!h.has(w.id)),y=l.length?f/l.length:0;for(const w of l)w.chars<=y&&(h.add(w.id),f-=w.chars,t=!0)}const p=u.filter(t=>!h.has(t.id)).reduce((t,l)=>t+l.chars,0);for(const t of u)g.set(t.id,h.has(t.id)?t.chars:Math.floor(f*t.chars/(p||1)));const A=W({windowTokens:s,reserveTokens:C(r).tokens})||0,$=u.map(t=>{const l={id:t.id,kind:t.kind,title:t.title||"",chars:t.chars,share:g.get(t.id)};if(a==="agent")return{...l,how:"agent",calls:0,why:"an agent reads it itself — handed the material, not a digest"};if(h.has(t.id)||!Number.isFinite(m))return{...l,how:"whole",calls:0,why:"it fits"};if(!i)return{...l,how:"merge",calls:Math.ceil(t.chars/Math.max(1,l.share)),why:"a large window: what does not fit is merged by the model"};if(c&&A>0){const y=Math.min(q.parts,Math.ceil(t.chars/A)),w=Math.ceil(t.chars/A),R=Math.max(1,Math.ceil(y/4));return{...l,how:"digest",parts:y,calls:y+R,unread:Math.max(0,w-y),why:"the question needs all of it, and it does not fit: read in parts, the notes combined"}}return{...l,how:"cut",calls:0,why:c?"no room to read it in parts: the parts that bear on the question":"a focused question: the parts that bear on it, by relevance"}}),I=u.some(t=>t.prefetched),O=a==="agent"?{offer:!0,rounds:null,why:"an agent keeps its own tools"}:i&&I&&!x.test(String(r||""))?{offer:!1,rounds:1,why:"a small window, and a prefetch already answered"}:i?{offer:!0,rounds:b,why:"a small window: one tool round, then the answer"}:{offer:!0,rounds:null,why:""},N=$.reduce((t,l)=>t+(l.calls||0),0),v=Math.round((Math.ceil(N/S)+1)*M);return{sources:$,tools:O,estimate:{calls:N+1,seconds:v},say:B($,v)}}function B(r,e){const n=r.filter(i=>i.how==="digest");if(!n.length)return"";const o=n.length===1?`"${n[0].title||"what is attached"}"`:`${n.length} attachments`,a=n.reduce((i,c)=>i+c.parts,0),s=n.reduce((i,c)=>i+(c.unread||0),0);return`Reading all of ${o} in ${a} part${a===1?"":"s"} first, so the answer covers the whole of it${s?` (the last ${s} part${s===1?"":"s"} will not fit)`:""} — about ${e} s.`}const x=/\b(?:schedule|reschedule|remind(?:er)?|calendar|invite|e-?mail|inbox|send|reply|draft|create|add|save|write (?:a |an )?note|open|click|fill|book|order|cancel|delete|rename|move|upload|download|run|execute|deploy|commit|share|post)\b/i,U=/\b(?:find out|find more|more (?:info|information|details)|look into|latest|current(?:ly)?|today|tonight|tomorrow|right now|this (?:week|weekend|month|year)|price|prices|cost|stock|shares?|score|news|headlines?|weather|forecast|hours|near me|nearby|directions|traffic|flight|look (?:it |that )?up|search|google|website|link|url|https?:\/\/|who(?:'s| is| was| are)|where(?:'s| is| are)|when(?:'s| is| does| do))\b/i,K=/\b(?:my|mine|our|ours|we|us|did i|have i|i (?:said|asked|wrote|told|had|was)|remember|last time|earlier today|meetings?|notes?|transcripts?|conversations?|chats?)\b/i;function Y(r){const e=String(r||"").trim();return e?x.test(e)||U.test(e)||K.test(e)||!!P(e):!1}const T=new Set(["weather","stock","news","page","web","research"]);function te(r=[]){return(Array.isArray(r)?r:[]).some(e=>e?.kind==="prefetch"&&T.has(e.prefetch)&&String(e.text||"").trim())}function re(r=[]){return(Array.isArray(r)?r:[]).some(e=>e&&T.has(e.kind))}function z({window:r=0,question:e="",answered:n=!1,decided:o="",reference:a=!1}={}){return k(r)?a?{offer:!0,rounds:b,why:"a small window, and a document attached by reference that was not read ahead — the files tool stays"}:n&&!x.test(String(e||""))?{offer:!1,rounds:1,why:"a small window, and a prefetch already answered"}:n?{offer:!0,rounds:b,why:"a small window: a prefetch answered the look-up, and something is still to be done"}:o==="none"?x.test(String(e||""))?{offer:!0,rounds:b,why:"a small window: nothing to look up, and something to do"}:{offer:!1,rounds:1,why:"a small window, and the decider found nothing to look up"}:o?{offer:!0,rounds:b,why:`a small window, the decider asked for ${o}, and the fetch found nothing`}:Y(e)?{offer:!0,rounds:b,why:"a small window: one tool round, then the answer"}:{offer:!1,rounds:1,why:"a small window, and a question that needs no tools"}:{offer:!0,rounds:null,why:""}}function ne({window:r=0,question:e="",answered:n=!1}={}){if(!k(r))return{history:"all",memories:"all",before:!1,why:""};const o=L(e);return{history:n?"none":"all",memories:o?"none":n?"pinned":"matched",before:!0,why:[n?"a small window a fetch answered: the evidence, the question and pinned memories":"",o?"a greeting: no memories":n?"":"a small window: only the memories that bear on it"].filter(Boolean).join("; ")}}const G="From the user's own history. It may have nothing to do with the question: use it only if it answers it, otherwise answer from your own knowledge.";function oe(r=[],e={}){const n=(Array.isArray(r)?r:[]).filter(o=>o&&typeof o=="object");return e?.before?n.map(o=>({...o,before:!0,text:`${G}
|
|
2
|
+
${String(o.text||"")}`})):n}function ae(r=[],e=""){const n=String(e||"").trim();if(!n)return r;const o=/^(?:here|near me|nearby|my (?:location|area|city))$/i;return(Array.isArray(r)?r:[]).map(a=>{const s=a?.input?.args||a?.input;if(!s)return a;if(a.kind==="weather"&&o.test(String(s.location||"").trim())){const i={...s,location:n};return{...a,input:a.input.args?{...a.input,args:i}:i,label:`Weather — ${n}`}}if(typeof s.query=="string"&&/\bnear (?:me|here)\b|\bnearby\b|\baround here\b/i.test(s.query)){const i=s.query.replace(/\bnear (?:me|here)\b|\bnearby\b|\baround here\b/i,`near ${n}`);return{...a,input:a.input.args?{...a.input,args:{...s,query:i}}:{...s,query:i},subject:i,label:String(a.label||"").replace(/\bnear (?:me|here)\b|\bnearby\b|\baround here\b/i,`near ${n}`)}}return a})}function se({question:r="",previousText:e="",previousAnswer:n="",previous:o=null,reach:a=new Set,window:s=0,personal:i=!1,lookup:c=null,tab:S=null,now:M=Date.now()}={}){const u=k(s),d=_({text:r,previous:o,previousText:e,previousAnswer:n,reach:a,research:!0,page:!0,tab:S,lookup:c??u,now:M}),m=d.some(p=>["weather","stock","news","page","web","research"].includes(p.kind)),g=!!i&&!m,h=[];d.length&&h.push(`fetch first: ${d.map(p=>p.label||p.kind).join(", ")}`),i&&m&&h.push("a world fact — the person's history is not searched for it");const f=z({window:s,question:r,answered:d.length>0});return f.why&&h.push(f.why),{prefetch:d,world:m,research:g,tools:f,why:h}}export{G as HISTORY_NOTE,D as answeredByPrefetch,ne as contextPlan,oe as historyContext,ae as placeItems,ee as planRetrieval,se as planTurn,z as toolPlan,Y as toolsWanted,te as worldAnswered,re as worldPlanned};
|
package/route-decider.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import{defineRouteStrategy as q}from"./router.js";function x(e){const l=Number.isFinite(e.quality)?`quality ${e.quality.toFixed(2)}`:"quality unknown",a=e.costPer1k===0?"free":`cost ${e.costPer1k}`,i=Number.isFinite(e.latencyMs)?`~${e.latencyMs} ms to first token`:"",s=e.window?`window ${Math.round(e.window/1e3)}k`:"",n=e.reach==="device"?"on this device":e.reach==="trusted"?"on a trusted host":"a third party",$=e.classUsed==="A"?"a coding agent with its own loop":e.classUsed==="L"?"a local model":"an API model",f=(e.capabilities||[]).length?`can: ${e.capabilities.join(", ")}`:"no declared abilities",r=[e.rateLimited?"rate limited now":"",e.available===!1?"unavailable":""].filter(Boolean).join(", ");return[e.label||e.id,$,n,f,l,a,i,s,r].filter(Boolean).join(" · ")}function v(e={},{text:l=!1}={}){const a=e.signals||{},i=[];i.push(`Task: ${a.smalltalk?"small talk":a.code?"coding":"a question"}; complexity ${a.complexity||"unknown"}; modality ${a.modality||"text"}; about ${a.approxTokens||0} tokens${a.nonLatin?"; non-Latin script":""}.`),a.reference&&i.push(`Material attached by reference: ${a.reference.count} item(s), ${a.reference.pages||0} pages.`),(e.capabilities||[]).length&&i.push(`Needs: ${e.capabilities.join(", ")}.`),e.minQuality&&i.push(`Quality floor ${e.minQuality}.`),e.reach&&e.reach!=="any"&&i.push(`May reach: ${e.reach} only.`),e.prefer&&i.push(`Prefer: ${e.prefer}.`);const s=l&&e.requestText?String(e.requestText).trim().slice(-600):"";return s&&i.push(`The request ends: "${s}"`),i.join(`
|
|
2
|
-
`)}function F({decide:e,rerank:l=null,shortlist:a=6,text:i=!1,timeoutMs:s=4e3}={}){if(typeof e!="function")throw new Error("deciderStrategy: decide is required");return q({id:"decider",label:"Decision model",classUsed:"M",timeoutMs:s,decide:async(n,$)=>{if(!Array.isArray(n)||n.length<2)return null;const f=v($,{text:i}),r=n.map(t=>({id:t.id,card:x(t)})),p=[];let h=r;if(typeof l=="function")try{const t=await l({query:f,documents:r.map(d=>d.card),top_n:r.length}),c=(t?.results||[]).map(d=>r[d.index]).filter(Boolean);c.length&&(h=[...c,...r.filter(d=>!c.includes(d))],p.push(`reranker (${t.model||"rerank"}) ordered: ${h.slice(0,a).map(d=>d.id).join(" > ")}`))}catch(t){p.push(`reranker did not answer (${t?.message||t}); the score's order stands`)}const y=h.slice(0,Math.max(2,a)),g={state:`${f}
|
|
2
|
+
`)}function F({decide:e,rerank:l=null,shortlist:a=6,text:i=!1,timeoutMs:s=4e3}={}){if(typeof e!="function")throw new Error("deciderStrategy: decide is required");return q({id:"decider",label:"Decision model",classUsed:"M",timeoutMs:s,decide:async(n,$)=>{if(!Array.isArray(n)||n.length<2)return null;const f=v($,{text:i}),r=n.map(t=>({id:t.id,card:x(t)})),p=[];let h=r;if(typeof l=="function")try{const t=await l({query:f,documents:r.map(d=>d.card),top_n:r.length,wake:!1}),c=(t?.results||[]).map(d=>r[d.index]).filter(Boolean);c.length&&(h=[...c,...r.filter(d=>!c.includes(d))],p.push(`reranker (${t.model||"rerank"}) ordered: ${h.slice(0,a).map(d=>d.id).join(" > ")}`))}catch(t){p.push(`reranker did not answer (${t?.message||t}); the score's order stands`)}const y=h.slice(0,Math.max(2,a)),g={state:`${f}
|
|
3
3
|
|
|
4
4
|
Candidates:
|
|
5
5
|
${y.map(t=>`- ${t.id}: ${t.card}`).join(`
|
|
6
|
-
`)}`,questions:{model:{type:"choice",instructions:"Which candidate should answer this task? Weigh what the task needs against each card: quality for hard work, speed and cost for easy work, and never a candidate that lacks an ability the task needs.",options:y.map(t=>({value:t.id,describe:t.card}))}},budgetMs:s},k=await e(g),o=k?.answers?.model;if(!o||typeof o.value!="string")return null;const u=y.find(t=>t.id===o.value);if(!u)return null;const b=[...o.options||[]].sort((t,c)=>(c.p||0)-(t.p||0)),w=b.find(t=>t.value!==o.value);p.push(`decision model (${k.model||"decide"}) picked ${u.id}${Number.isFinite(o.p)?` at ${(o.p*100).toFixed(0)}%`:""}${w?`, then ${w.value} at ${((w.p||0)*100).toFixed(0)}%`:""}${k.calibrated===!1?" (not a calibrated probability)":""}`),n[0]&&n[0].id!==u.id&&p.push(`the score would have picked ${n[0].id}`);const m=b.map(t=>t.value).filter(t=>t!==u.id&&y.some(c=>c.id===t));return{ranked:[u.id,...m,...h.map(t=>t.id).filter(t=>t!==u.id&&!m.includes(t))],why:p}}})}export{x as candidateCard,F as deciderStrategy,v as taskBrief};
|
|
6
|
+
`)}`,questions:{model:{type:"choice",instructions:"Which candidate should answer this task? Weigh what the task needs against each card: quality for hard work, speed and cost for easy work, and never a candidate that lacks an ability the task needs.",options:y.map(t=>({value:t.id,describe:t.card}))}},budgetMs:s,wake:!1},k=await e(g),o=k?.answers?.model;if(!o||typeof o.value!="string")return null;const u=y.find(t=>t.id===o.value);if(!u)return null;const b=[...o.options||[]].sort((t,c)=>(c.p||0)-(t.p||0)),w=b.find(t=>t.value!==o.value);p.push(`decision model (${k.model||"decide"}) picked ${u.id}${Number.isFinite(o.p)?` at ${(o.p*100).toFixed(0)}%`:""}${w?`, then ${w.value} at ${((w.p||0)*100).toFixed(0)}%`:""}${k.calibrated===!1?" (not a calibrated probability)":""}`),n[0]&&n[0].id!==u.id&&p.push(`the score would have picked ${n[0].id}`);const m=b.map(t=>t.value).filter(t=>t!==u.id&&y.some(c=>c.id===t));return{ranked:[u.id,...m,...h.map(t=>t.id).filter(t=>t!==u.id&&!m.includes(t))],why:p}}})}export{x as candidateCard,F as deciderStrategy,v as taskBrief};
|
package/runtime-in-process.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const u=Object.freeze(["rerank","decide"]),
|
|
1
|
+
const u=Object.freeze(["rerank","decide","embed"]),h={rerank:"Rerank",decide:"Decide",embed:"Embeddings"},g={rerank:"Orders sources by relevance — research in plan notes, search results, the tool finder.",decide:"Typed decisions — sentiment, routing, triage, naming a speaker — in one pass, no language model.",embed:"Text to vectors — what the knowledge base and history search look things up with."},x={rerank:["reranker","Reranker"],decide:["opendecision","OpenDecision"],embed:["vllm","vLLM"]},m=/^[A-Za-z0-9][A-Za-z0-9._-]{0,95}\/[A-Za-z0-9][A-Za-z0-9._-]{0,95}$/;function p(t){const e=Number(t);return!Number.isFinite(e)||e<=0?"":e>=1024?`${(e/1024).toFixed(1).replace(/\.0$/,"")} GB`:`${Math.round(e)} MB`}function w(t){return[t?.label||t?.id||"",p(t?.mb),t?.languages||""].filter(Boolean).join(" · ")}function k(t){switch(t?.state){case"ready":return{text:"ready",cls:"ok"};case"loading":return{text:"loading",cls:""};case"downloading":{const e=Number(t.progress?.pct);return{text:`downloading${Number.isFinite(e)&&e>0?` ${Math.min(100,Math.round(e))}%`:""}`,cls:""}}case"down":return{text:`could not load${t.error?` — ${String(t.error).slice(0,160)}`:""}`,cls:"bad"};default:return{text:"loads on first use",cls:""}}}function v(t,e,o={}){const n=(Array.isArray(e?.models)?e.models:[]).filter(r=>r&&typeof r.id=="string"),d=n[0]?.id||null,l=["embedded","container","remote","none"].includes(e?.provider)?e.provider:"none",[f,b]=x[t]||[],a=o&&typeof o=="object"?o[f]:null,i=l==="embedded"?e.model||d:null,c=n.find(r=>r.id===i)||null;let s;if(l==="embedded"){const r=k(e);s={text:[`In ChatPanel${i&&i===d?" (default)":""}`,c?.label||i||"",p(c?.mb),r.text].filter(Boolean).join(" · "),cls:r.cls}}else l==="container"?s={text:`Container — ${a?.label||b||t}${a?.model?` · ${a.model}`:""}`,cls:"ok"}:l==="remote"?s={text:"A server set in the gateway’s config",cls:"ok"}:s={text:"Off — nothing answers it; a caller that asks carries on without it",cls:"warn"};return{id:t,title:h[t]||t,what:g[t]||"",provider:l,on:l!=="none",status:s,selected:i||"",placeholder:i?"":l==="none"?"Off — pick a model to turn it on":s.text,elsewhere:l==="container"||l==="remote",settling:l==="embedded"&&["downloading","loading"].includes(e?.state),models:n.map(r=>({id:r.id,text:`${w(r)}${r.id===d?" — default":""}`,note:r.note||""})),note:c?.note||"",threads:Number.isFinite(Number(e?.threads))&&Number(e.threads)>0?Number(e.threads):null,service:f||null}}function $(t){const e=t?.inProcess;if(!e||typeof e!="object")return null;const o=u.filter(n=>e[n]&&typeof e[n]=="object").map(n=>v(n,e[n],t.services));return o.length?o:null}function N(t,e={}){return u.includes(t)?typeof e.model=="string"?m.test(e.model)?{capabilities:{[t]:{provider:"embedded",model:e.model}}}:null:e.on===!1?{capabilities:{[t]:{provider:"none"}}}:e.on===!0?{capabilities:{[t]:null}}:null:null}function I(t,e={}){const o=t?.title||"It";if(typeof e.model=="string"){const n=(t?.models||[]).find(d=>d.id===e.model);return`✓ ${o} now runs ${n?n.text.split(" · ")[0]:e.model} in ChatPanel — downloaded on first use, unloaded when idle.`}return e.on===!1?`✓ ${o} is off — whoever asks carries on without it.`:`✓ ${o} is back on the default.`}function O(t){if(!t||typeof t!="object")return null;const e={};for(const o of u){if(!(o in t))continue;const n=t[o];n===null?e[o]=null:n?.provider==="none"?e[o]={provider:"none"}:n?.provider==="embedded"&&(n.model==null?e[o]={provider:"embedded"}:typeof n.model=="string"&&m.test(n.model)&&(e[o]={provider:"embedded",model:n.model}))}return Object.keys(e).length?e:null}export{u as IN_PROCESS_IDS,v as capabilityView,I as choiceNote,N as choicePatch,O as inProcessPatch,$ as inProcessView,w as modelOptionText,p as sizeText,k as stateText};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const d=Object.freeze({host:{label:"This machine",what:"a process on this computer, on its GPU — the fastest for a language model"},container:{label:"Container",what:"in Podman or Docker, isolated from the computer — for engines that ship as images"},gateway:{label:"In the gateway",what:"inside the ChatPanel gateway itself — nothing else to install or run"}}),h=Object.freeze([{id:"chat",label:"Chat models",what:"Language models on this computer. Each one running is in the chat’s model menu by name."},{id:"embed",label:"Embeddings",what:"Text to vectors — what the knowledge base and history search look things up with."},{id:"rerank",label:"Reranking",what:"Orders search results and documents by how well they answer the question."},{id:"decide",label:"Decisions",what:"Classifiers that answer typed questions: model routing, speaker names, which MCP server a message needs. What a turn looks up is decided by the model picked under “Deciding what to look up”."},{id:"stt",label:"Speech to text",what:"Dictation and meeting transcription.",page:"voice"},{id:"tts",label:"Read aloud",what:"Answers spoken back.",page:"voice"},{id:"detect",label:"Entity detection",what:"Finds names, places and organisations to redact before anything leaves this device.",page:"redaction"},{id:"search",label:"Web search",what:"A metasearch engine for look-ups, on this computer.",page:"websearch"}]),m=e=>e?.kind==="native"||e?.engine==="host"?"host":"container",g=Object.freeze({searxng:["search"],reranker:["rerank"],opendecision:["decide"],llama:["chat"],mlx:["chat"],"vllm-metal":["chat"],apple:["chat"],vllm:["chat","embed","stt"]}),f=e=>Array.isArray(e?.provides)?e.provides:g[e?.id]||[],p=(e,n)=>f(e).includes(n)&&(e.id!=="vllm"||(e.task||"chat")===n||!e.configured),u=e=>e?.state==="running"&&!!e.configured;function b(e){const n=e?.engines||{},t=n.preferred?n[n.preferred]:null,i=e?.machine||{};return[{id:"host",...d.host,state:"ok",detail:[i.chip||i.cpu||null,i.ramGB?`${i.ramGB} GB`:null].filter(Boolean).join(" · ")||null},{id:"container",...d.container,state:n.preferred?t?.running?"ok":"off":"missing",detail:n.preferred?`${n.preferred}${t?.version?` ${t.version}`:""}${t?.running?"":" — not running"}`:"no container engine — install Podman to use one"},{id:"gateway",...d.gateway,state:"ok",detail:null}]}function y(e,{health:n=null}={}){const t=Object.entries(e?.services||{}).filter(([,a])=>a&&typeof a=="object").map(([a,r])=>({id:a,...r})),i=e?.inProcess||{},l=h.map(a=>{const r=[];if(i[a.id]){const o=i[a.id];r.push({kind:"in-process",id:a.id,label:o.model||"built in",place:"gateway",state:o.provider==="embedded"?o.state||"ready":"off",inUse:o.provider==="embedded",model:o.model||null})}if(a.page&&a.id!=="search"){const o=n?.[a.id];r.push({kind:"page",id:a.id,label:o?.model||"built in",place:"gateway",state:o?o.enabled===!1?"off":o.state||"ready":"ready",inUse:o?o.enabled!==!1:!0,model:o?.model||null,page:a.page})}for(const o of t)p(o,a.id)&&r.push({kind:"service",id:o.id,label:o.label||o.id,place:m(o),state:o.state||"absent",inUse:u(o),model:o.model||null,busy:!!(o.job&&!o.job.done)});return{...a,options:r}}).filter(a=>a.options.length);return{places:b(e),jobs:l}}function v(e){return Object.entries(e?.services||{}).map(([n,t])=>({id:n,...t})).filter(n=>p(n,"chat")&&u(n))}const s=Object.freeze({llama:"llama.cpp",mlx:"MLX","vllm-metal":"vLLM-Metal",apple:"Apple on-device",vllm:"vLLM"});function k(e){return Object.entries(e?.services||{}).filter(([n,t])=>t&&typeof t=="object"&&Object.hasOwn(s,n)&&p({id:n,...t},"chat")).map(([n,t])=>{const i=t.job&&!t.job.done?t.job:null,l=i?.kind==="pull-model"&&i.detail||t.model||(n==="apple"?"apple-on-device":null),a=i?i.kind==="pull-model"?"downloading":i.kind==="starting"?"starting":"preparing":t.state==="running"?t.answering?"in-use":"loading":t.job?.error&&!t.job.cancelled?"failed":null;return!a||!l?null:{engine:n,engineLabel:s[n],place:n==="vllm"?"container":"host",model:l,state:a,progress:a==="downloading"&&i.progress||null,since:i?.since||null,error:a==="failed"?String(t.job.error):null}}).filter(Boolean)}const c=e=>e>=2**30?`${(e/2**30).toFixed(1)} GB`:`${Math.max(0,Math.round(e/2**20))} MB`,w=e=>e>=3600?`${Math.floor(e/3600)} h ${Math.round(e%3600/60)} min`:e>=90?`${Math.round(e/60)} min`:`${Math.max(1,Math.round(e))} s`;function $(e,{now:n=Date.now()}={}){const t=e?.progress||null,i=t?.total?Math.min(100,t.bytes/t.total*100):null,l=Number.isFinite(e?.since)?Math.max(0,Math.round((n-e.since)/6e4)):0,a=[t?.total?`${c(t.bytes)} of ${c(t.total)} (${Math.floor(i)}%)`:t?.bytes?c(t.bytes):"",t?.rate?`${c(t.rate)}/s`:t?.bytes&&t.rate===0?"stalled":"",t?.etaS?`about ${w(t.etaS)} left`:"",l?`running ${l} min`:""].filter(Boolean).join(" · ");return{pct:i,text:a,file:t?.file?String(t.file).split("/").pop():null}}function M(e,n){const t=s[n]||n||"",i=String(e||""),l=n==="apple"?"Apple on-device":/\.gguf$/i.test(i)?i.split(/[\\/]/).pop().replace(/\.gguf$/i,""):i.split(":")[0].split("/").pop()||i;return{name:l,engine:t,label:n==="apple"?l:`${l} · ${t}`}}function O(e){const n=String(e||"");return Object.hasOwn(s,n)?{id:n,label:s[n],place:n==="vllm"?"container":"host"}:null}export{h as JOBS,d as PLACES,s as RUNTIME_CHAT_ENGINES,m as placeOf,$ as progressFacts,O as runtimeChatEngineOf,k as runtimeChatModels,y as runtimeLayout,M as runtimeModelName,v as servingChatEngines};
|