@chatpanel/events 0.429.0 → 0.432.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/a2ui-catalog.js +2 -0
- package/a2ui-chart.js +1 -0
- package/a2ui-express.js +5 -0
- package/a2ui-html.js +1 -0
- package/a2ui-reply.js +11 -0
- package/a2ui-surface.js +1 -0
- package/a2ui-text.js +2 -0
- package/a2ui-tool-cards.js +12 -0
- package/endpoint-jobs.js +1 -1
- package/index.js +1 -1
- package/markdown-render.js +0 -0
- package/model-catalog.js +1 -1
- package/package.json +17 -1
- package/prefetch.js +6 -4
- package/settings-registry.js +1 -1
- package/turn-gather.js +1 -1
- package/turn-pipeline.js +1 -1
- package/weather-tool.js +6 -6
package/prefetch.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
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(`
|
|
1
|
+
import{researchAsk as P,runResearch as ce}from"./web-research.js";import{frontPagesAskedAbout as he}from"./site-pages.js";import{weatherFromSearch as le}from"./weather-tool.js";import{cardOf as T,CARD_SHOWN_NOTE as ue}from"./a2ui-tool-cards.js";import{PAGE_READ_ARGS as W}from"./page-context.js";const D=/(\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,pe=/\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"]),F=8,L="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",de=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${L}\\b`,"i"),fe=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"),we=/\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,ge=/^\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 be(e){const t=ge.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const me=/\b(?:weather|forecast|temperature|rain|snow)\b/i,ke=/\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,ye=/\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,$e=/\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,Se=/^\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,_e=/\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,Ee=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function Ae(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(_e.test(t)&&/\?/.test(t)){const s=(Ee.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,q=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function je(e){const t=String(e||"");if(!O.test(t)||q.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 Le(e){const t=String(e||"");return O.test(t)&&!q.test(t)?!1:ye.test(t)}const Oe=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i,Re=/(?: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 xe(e,t){if(!t||!(t.title||t.url))return!1;const n=Re.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 v(e){const t=String(e||"").trim();return!t||t.length>300||we.test(t)?null:de.test(t)||fe.test(t)?{}:null}function b(e){return String(e||"").replace(pe," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const B=/\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 S(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!j.has(t)&&!B.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function U(e){const t=String(e||"").trim();return!D.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 Ce=/\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(!D.test(t))return"";const n=t.replace(Ce,"").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=b(s[1].split(/\s+(?:and|&|vs\.?|versus|compared (?:to|with)|then|,)\s+/i)[0]);if(S(o))return o;if(S(b(s[1])))return b(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&&S(b(s[1]))&&!x.test(b(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&S(b(s[1])))?b(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,Ne=/^(?:(?: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,Pe=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,M=/^(?:(?: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 I(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace(Ne,"").trim().replace(Pe,"").trim();if(!s||s.split(/\s+/).length>F)return"";const o=M.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=b(s.replace(M,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!S(r)||x.test(r)?"":r}const k="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",Te=[new RegExp(`\\b(?:share price|stock price|stock quote|ticker)\\s+(?:of|for)\\s+${k}`,"iu"),{question:!0,re:new RegExp(`\\b(?:stock|stocks|shares?)\\s+(?:of|for|in)\\s+${k}`,"iu")},new RegExp(`\\b${k}(?:'s)?\\s+(?:stock|shares)\\s+(?:price|doing|trading|today|now|performance|performing|up|down|quote)\\b`,"iu"),new RegExp(`\\b${k}(?:'s)?\\s+(?:share price|stock price|stock quote)\\b`,"iu"),new RegExp(`^\\s*${k}(?:'s)?\\s+(?:stock|shares)\\s*\\??\\s*$`,"iu"),new RegExp(`\\b(?:how|where)(?:'s| is| are)\\s+${k}\\s+(?:stock\\s+|shares\\s+)?trading\\b`,"iu"),new RegExp(`\\bwhat(?:'s| is| are)\\s+${k}\\s+trading at\\b`,"iu"),/\$([A-Z]{1,5})\b/u],We=/^(?: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,De=/^(?: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,Fe=/\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 G(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!We.test(t)&&!B.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function qe(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&De.test(t[0]);)t.shift();return t.join(" ")}function H(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(Fe,"").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 J(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 Te){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=qe(H(r[1]));if(G(l))return l}return""}function z(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>F)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=H(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!G(o)||x.test(o)?"":o}const K=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function Y(e){return String(e||"").replace(K,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function ve(e){return[...String(e||"").matchAll(K)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Be=/\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,Ue=/[.?!;:,()](?=\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,Me=/^(?: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,Ie=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,Ge=/^(?:the|a|an)\b/i,He=6;function X(e){const n=(String(e||"").split(Ue)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>He||!new RegExp("\\p{L}","u").test(n)||Me.test(n)?"":n}function Je(e){const t=Be.exec(Y(e));return t?X(t[1]):""}const ze=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],Ke=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,Ye=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function Xe(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 p=o[c];o[c]=Math.min(o[c]+1,o[c-1]+1,l+(n[r-1]===s[c-1]?0:1)),l=p}}return o[s.length]}function Qe(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function Q(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=ve(s),r=Y(s);let l=o.at(-1)||"";if(!l&&Ye.test(r)&&(l=Ke.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let p=-1;for(const[a,h]of ze)if(a.test(r)){p=h(c);break}if(p<0){let a=1/0;c.forEach((h,f)=>{const w=Xe(h,l)/Math.max(h.length,l.length);w<a&&(a=w,p=f)}),a>.6&&(p=c.length===1?0:-1)}if(p<0)return null;const u=c[p];return u.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[p]=Qe(l,c.find(a=>new RegExp("^\\p{Lu}","u").test(a))||u),{subject:c.join(" "),replaced:u})}const Ve=/\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,V=/\b(?:web|online|internet|google)\b/i;function Ze(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=Q(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Ve.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:V.test(e)}}function Z(e,t){const n=Je(e);if(n){const o=Q(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:V.test(e)}}const s=Ze(e,t);return s?{kind:"lookup",...s}:null}function ee(e){return Ie.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!Ge.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const et=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,tt=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,nt=/^(?:(?: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,st=/^(?:(?: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,te=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function ot(e){const t=String(e||"").trim();if(!t||he(t).length)return null;if(st.test(t))return{subject:""};const n=et.exec(t)||nt.exec(t),s=n?null:tt.exec(t),o=n||s;if(!o)return null;const r=X(o[1].replace(/[?.!]+$/,"").replace(te,"")).replace(te,"");return s&&r.split(/\s+/).length>4||!r||!ee(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function bt(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const ne=Object.freeze({page:15e3,web:12e3,lookup:12e3}),rt=6e3;function mt(e){return Object.hasOwn(ne,e?.kind)?ne[e.kind]:rt}const at=/^\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 se(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 oe(e,t){return!t||t.kind!=="weather"?"":at.test(String(e||""))?String(t.subject||"here"):""}function it(e,t){const n=_(e)||oe(e,t)||I(e,t);if(n)return{kind:"weather",subject:n};if(U(e))return{kind:"weather",subject:se(e,t)||"here"};const s=J(e)||z(e,t);if(s)return{kind:"stock",subject:s};const o=Z(String(e||""),t);if(o)return o;const r=P(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function kt(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"),p=typeof r.content=="string"?r.content:"",u=it(p,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=ct(c?.text);s=u&&{...u,...a?{resolved:a}:s?.resolved&&s.kind===u.kind?{resolved:s.resolved}:{}}}return s}function ct(e){const t=/(?:^|\n)\w+ for ([^\n(]+?)\s*\(asked:/.exec(String(e||""));return t?t[1].trim():""}function ht(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 yt({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,tab:p=null,now:u=Date.now()}={}){const a=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),h=[];if(Le(e))return r?re(e,t,a):[];const f=Se.test(String(e||""))?Ae(s):"",w=String(e||"").trim().split(/\s+/).length,$=be(e)||(f?{query:f}:null)||($e.test(String(e||""))&&w<=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"),g=!$.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,...me.test(i)?{weather:!0}:{},...g?{borrowed:!0}:{}}]}}if(c&&(a.has("page:read_page")||a.has("read_page"))&&v(e)&&!xe(e,p)){const i=a.has("page:read_page"),d=Oe.test(e)&&v(n)?String(n).trim():"";return[{kind:"page",tool:i?"page":"read_page",input:i?{action:"read_page",args:{...W}}:{...W},label:"This page",...d?{ask:d}:{}}]}const E=a.has("find:weather"),ie=a.has("weather");if(E||ie){e=je(e)||e;const i=_(e)?"":oe(e,t),d=_(e)||(i?i!=="here"?i:"":I(e,t)),g=d||(U(e)?se(e,t)||"here":i?"here":"");if(g){const A=g!=="here"?ht(t,"weather",g):"",C=y=>E?{action:"weather",args:{location:y}}:{location:y};if(h.push({kind:"weather",tool:E?"find":"weather",input:C(g),label:d?`Weather — ${d}`:"Weather — near you",...d?{about:d}:{},...A?{retry:{input:C(`${g}, ${A}`),context:A.split(",")[0].trim()}}:{}}),d&&ke.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 m=a.has("find:web_search");if(!h.length&&(m||a.has("web_search"))){const i=J(e)||z(e,t);if(i){const d=`${i} stock price today`;h.push({kind:"stock",tool:m?"find":"web_search",input:m?{action:"web_search",args:{query:d}}:{query:d},label:`Stock — ${i}`,about:i})}}if(!h.length&&(m||a.has("web_search"))){const i=ot(e);if(i){const d=i.subject?`${i.subject} news today`:"top news today";h.push({kind:"news",tool:m?"find":"web_search",input:m?{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&&(m||a.has("web_search"))){const i=P(e,{previous:t,now:u});if(i){const d=m?"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(g=>/^(?:page:)?(?:open_tab|navigate)$/.test(g))?{...i,browse:!0}:i})}}return r&&!h.length&&h.push(...re(e,t,a)),h}function re(e,t,n){const s=Z(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=[],p=l("history_search"),u=l("web_search");return p&&!s.web&&c.push({kind:"lookup",tool:p.tool,input:p.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),u&&(s.web||ee(o))&&c.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Web — ${o}`,subject:o,about:o,note:r,fallback:c.length>0}),c}function $t(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 St(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:"",s=T(e);return s?{text:t,note:n,card:s}:{text:t,note:n}}function lt(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function ut(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 ae(e,t,{now:n=Date.now(),note:s="",card:o=null}={}){const r=T({card:o});if(r)return{...ae(e,`${String(t||"")}
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
${ue}`,{now:n,note:s}),card:r};if(e.kind==="web"&&e.weather&&(t=le(t)||t),e.kind==="page"&&(t=ut(t)),e.kind==="research"){const a=String(t||""),{question:h,domain:f,subject:w,slots:$}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||w||"",research:{question:h,domain:f,subject:w,slots:$},title:e.label,text:a,chars:a.length}}const l=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.`,c=e.kind==="lookup"||e.kind==="web"?`SEARCHED for "${e.subject}"`:e.kind==="page"?"READ the page the user has open":"FETCHED",p=e.kind==="page"&&e.ask?`
|
|
6
6
|
|
|
7
|
-
${
|
|
7
|
+
The question about this page: ${e.ask.slice(0,200)}`:"",u=`(ALREADY ${c} for the question below, with ${e.tool}. Answer from this; ${l})
|
|
8
|
+
|
|
9
|
+
${String(t||"")}${p}`;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:lt(e,s),text:u,chars:u.length}}async function _t(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const c=s(),p=u=>{try{o({type:"tool",name:"research",prefetched:!0,...u})}catch{}};p({phase:"start",input:e.input,summary:e.label});try{const{text:u,result:a}=await ce(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:w=>p({phase:"progress",summary:`${e.label} — ${w.label}`})});if(!u)return p({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 p({phase:"done",status:"ok",summary:`${e.label} — ${f}`,ms:s()-c}),{attachment:ae(e,u,{now:s()}),text:u,result:a,note:f,status:"ok"}}catch(u){const a=`error: ${String(u?.message||u).slice(0,80)}`;return p({phase:"done",status:a,summary:e.label,ms:s()-c}),{attachment:null,text:"",result:null,note:"",status:a}}}export{Le as aboutOwnPast,$t as answeredByPrefetch,ht as borrowedContext,se as carriedPlace,Q as correctedSubject,Y as joinSpelled,Ze as lookupFollowup,lt as lookupLabel,St as lookupResult,Je as lookupSubject,ot as newsAsk,Ae as offeredSearch,v as pageAsk,xe as placedElsewhere,ae as prefetchAttachment,mt as prefetchBudgetMs,bt as prefetchMissed,yt as prefetchPlan,kt as previousAsk,ct as resolvedOf,je as restatedWeather,_t as runResearchItem,z as stockFollowupSubject,J as stockSubject,I as weatherFollowupPlace,oe as weatherFollowupWhen,U as weatherHere,_ as weatherPlace,be as webRedoAsk};
|