@chatpanel/events 0.396.3 → 0.405.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-capabilities.js +1 -0
- package/agent-thread.js +3 -3
- package/client-prefs.js +1 -1
- package/index.js +1 -1
- package/markdown-render.js +0 -0
- package/note-blank.js +1 -0
- package/note-link.js +1 -0
- package/note-recall.js +7 -0
- package/package.json +13 -1
- package/prefetch.js +4 -4
- package/settings-registry.js +1 -1
- package/speech-language.js +1 -1
- package/subject-match.js +1 -0
- package/turn-gather.js +1 -1
- package/weather-tool.js +7 -7
- package/web-address.js +1 -0
package/prefetch.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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(`
|
|
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(`
|
|
2
2
|
|
|
3
|
-
`)}catch{return t}}function
|
|
3
|
+
`)}catch{return t}}function rt(e,t,{now:n=Date.now(),note:s=""}={}){if(e.kind==="web"&&e.weather&&(t=ae(t)||t),e.kind==="page"&&(t=ot(t)),e.kind==="research"){const u=String(t||""),{question:a,domain:i,subject:p,slots:g}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||p||"",research:{question:a,domain:i,subject:p,slots:g},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)}`:"",h=`(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:st(e,s),text:h,chars:h.length}}async function gt(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const h=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 oe(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:b=>u({phase:"progress",summary:`${e.label} — ${b.label}`})});if(!a)return u({phase:"done",status:"skipped",summary:e.label,ms:s()-h}),{attachment:null,text:"",result:i,note:"",status:"skipped"};const p=i.stats,g=`${p.searches} search${p.searches===1?"":"es"} · ${p.sites} site${p.sites===1?"":"s"} · ${(p.ms/1e3).toFixed(1)} s`;return u({phase:"done",status:"ok",summary:`${e.label} — ${g}`,ms:s()-h}),{attachment:rt(e,a,{now:s()}),text:a,result:i,note:g,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()-h}),{attachment:null,text:"",result:null,note:"",status:i}}}export{Se as aboutOwnPast,ft as answeredByPrefetch,nt as borrowedContext,ee as carriedPlace,Y as correctedSubject,J as joinSpelled,Je as lookupFollowup,st as lookupLabel,wt as lookupResult,qe as lookupSubject,Qe as newsAsk,ye as offeredSearch,F as pageAsk,rt as prefetchAttachment,ut as prefetchBudgetMs,lt as prefetchMissed,dt as prefetchPlan,pt as previousAsk,tt as resolvedOf,$e as restatedWeather,gt as runResearchItem,G as stockFollowupSubject,I as stockSubject,B as weatherFollowupPlace,te as weatherFollowupWhen,v as weatherHere,S as weatherPlace,pe as webRedoAsk};
|