@chatpanel/events 0.361.0 → 0.362.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/events",
3
- "version": "0.361.0",
3
+ "version": "0.362.0",
4
4
  "description": "The canonical ChatPanel event-log and capability contracts — typed durable facts, clock-free deterministic linearization, schema upcasting, and the invariants the replay harness asserts. Pure, dependency-free ESM shared by the ChatPanel extension, gateway and bridge.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -263,6 +263,7 @@
263
263
  "./voice-intents.js": "./voice-intents.js",
264
264
  "./voice-speaker.js": "./voice-speaker.js",
265
265
  "./speaker-cluster.js": "./speaker-cluster.js",
266
+ "./speaker-turns.js": "./speaker-turns.js",
266
267
  "./link-noise.js": "./link-noise.js",
267
268
  "./link-protocol.js": "./link-protocol.js",
268
269
  "./voice-channels.js": "./voice-channels.js",
@@ -597,6 +598,7 @@
597
598
  "voice-intents.js",
598
599
  "voice-speaker.js",
599
600
  "speaker-cluster.js",
601
+ "speaker-turns.js",
600
602
  "link-noise.js",
601
603
  "link-protocol.js",
602
604
  "voice-channels.js",
package/prefetch.js CHANGED
@@ -1,5 +1,5 @@
1
- import{researchAsk as j,runResearch as Z}from"./web-research.js";import{frontPagesAskedAbout as ee}from"./site-pages.js";import{weatherFromSearch as te}from"./weather-tool.js";const O=/(\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,ne=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,se=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),R=8,E="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",oe=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${E}\\b`,"i"),re=new RegExp(`^\\s*(?:(?:can you |could you |please )?(?:summari[sz]e|tl;?\\s?dr|recap|give me the gist|what are the key (?:points|takeaways))(?:\\s+(?:it|this|that|here|(?:the|this)\\s+${E}(?:\\s+and\\s+(?:the\\s+)?${E})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),ae=/\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,ie=/^\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 ce(e){const t=ie.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const he=/\b(?:weather|forecast|temperature|rain|snow)\b/i,le=/\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,ue=/\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,pe=/\b(?:find out more|find (?:out )?more|more (?:info|information|details)|look into (?:it|that|this)|dig (?:deeper|into (?:it|that))|get more details?|find (?:it|that) out|check (?:on )?(?:it|that) (?:again|online)|search (?:for )?more|look (?:it|that) up|find (?:the )?(?:rest|full|whole)(?: of it| forecast)?)\b/i,de=/^\s*(?:yes|yeah|yep|yup|sure|ok(?:ay)?|k|please(?: do)?|go ahead|go for it|do it|yes please|sure thing|absolutely|of course|ok look|look|search|please search|search it)(?:[\s,.!]+(?:please|thanks|thank you|go ahead|do it|look|search|yes))*[\s.!]*$/i,we=/\b(?:search the web|web search|search online|search for|look (?:it|that|this) up|look up|check online|find (?:it|that|out|more))\b/i,fe=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function ge(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(we.test(t)&&/\?/.test(t)){const s=(fe.exec(t)?.[1]||"").replace(/\s+for me$/i,"").trim();if(s)return s}const n=/\b(?:searching(?: the web| online)? for|looking up|checking(?: the web| online)? for)\s+(?:the\s+)?(.{3,160}?)(?:\.\.\.|…|[.!?]|$)/i.exec(t);return n?n[1].trim():""}const A=/^\s*(?:(?:no|nope|actually|but|well|sorry)\b[,.!]?\s*)?(?:i|we) (?:asked|said|meant|wanted)\b/i,N=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function be(e){const t=String(e||"");if(!A.test(t)||N.test(t))return"";const n=t.replace(A,"").replace(/^\s*(?:for|about)\s+/i,"").replace(/[.;]\s+(?:and|also)\s+/gi," and ").replace(/,?\s+not\s+[^.?!]*/i,"").trim();return/^(?:the\s+)?(?:weather|forecast|temperature)\b/i.test(n)?`what is ${/^the\s/i.test(n)?"":"the "}${n}`:""}function ke(e){const t=String(e||"");return A.test(t)&&!N.test(t)?!1:ue.test(t)}const me=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i;function x(e){const t=String(e||"").trim();return!t||t.length>300||ae.test(t)?null:oe.test(t)||re.test(t)?{}:null}function b(e){return String(e||"").replace(ne," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const C=/\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&&!se.has(t)&&!C.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function P(e){const t=String(e||"").trim();return!O.test(t)||$(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 ye=/\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(!O.test(t))return"";const n=t.replace(ye,"").trim();let s=/\b(?:in|at|for|around|near)\s+([^?!.;]+?)(?:\s+(?:right now|now|today|tonight|tomorrow|currently|this \w+))*\s*[?!.]*$/i.exec(n);return s&&y(b(s[1]))||(s=/^(?:what(?:'s| is) the\s+)?([\p{L}][\p{L}\s,.'-]{1,60}?)\s+(?:weather|forecast|temperature)\b/iu.exec(n),s&&y(b(s[1])))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&y(b(s[1])))?b(s[1]):""}const T=/\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|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)(?:[\s,.!—-]+|$))+/i,Se=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,W=/^(?:(?:how|what) about|(?:how|what)(?:'s| is|s) it(?: like)?(?: in| at| for| around| near)?|(?:in|at|for|around|near))\b[\s,]*/i;function F(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace($e,"").trim().replace(Se,"").trim();if(!s||s.split(/\s+/).length>R)return"";const o=W.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=b(s.replace(W,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!y(r)||T.test(r)?"":r}const k="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",_e=[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],Ee=/^(?: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,Ae=/^(?: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,Le=/\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 D(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Ee.test(t)&&!C.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function je(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&Ae.test(t[0]);)t.shift();return t.join(" ")}function q(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(Le,"").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 v(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 _e){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=je(q(r[1]));if(D(l))return l}return""}function B(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>R)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=q(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!D(o)||T.test(o)?"":o}const M=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function U(e){return String(e||"").replace(M,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function Oe(e){return[...String(e||"").matchAll(M)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Re=/\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,Ne=/[.?!;:,()](?=\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,xe=/^(?:it|this|that|these|those|him|her|them|me|you|yourself|us|he|she|they|we|i|my|our|your|his|their|here|there|on|in|at|to|for|with|from|going|coming|speaking|talking|calling|joining|what|how|why|when|where|which|the weather|weather)\b/i,Ce=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,Pe=/^(?:the|a|an)\b/i,Te=6;function I(e){const n=(String(e||"").split(Ne)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>Te||!new RegExp("\\p{L}","u").test(n)||xe.test(n)?"":n}function We(e){const t=Re.exec(U(e));return t?I(t[1]):""}const Fe=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],De=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,qe=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function ve(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 Be(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function H(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=Oe(s),r=U(s);let l=o.at(-1)||"";if(!l&&qe.test(r)&&(l=De.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let u=-1;for(const[a,d]of Fe)if(a.test(r)){u=d(c);break}if(u<0){let a=1/0;c.forEach((d,w)=>{const f=ve(d,l)/Math.max(d.length,l.length);f<a&&(a=f,u=w)}),a>.6&&(u=c.length===1?0:-1)}if(u<0)return null;const i=c[u];return i.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[u]=Be(l,c.find(a=>new RegExp("^\\p{Lu}","u").test(a))||i),{subject:c.join(" "),replaced:i})}const Me=/\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,G=/\b(?:web|online|internet|google)\b/i;function Ue(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=H(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Me.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:G.test(e)}}function J(e,t){const n=We(e);if(n){const o=H(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:G.test(e)}}const s=Ue(e,t);return s?{kind:"lookup",...s}:null}function K(e){return Ce.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!Pe.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const Ie=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,He=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,Ge=/^(?:(?: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,Je=/^(?:(?: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,Y=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function Ke(e){const t=String(e||"").trim();if(!t||ee(t).length)return null;if(Je.test(t))return{subject:""};const n=Ie.exec(t)||Ge.exec(t),s=n?null:He.exec(t),o=n||s;if(!o)return null;const r=I(o[1].replace(/[?.!]+$/,"").replace(Y,"")).replace(Y,"");return s&&r.split(/\s+/).length>4||!r||!K(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function nt(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const z=Object.freeze({page:15e3,web:12e3,lookup:12e3}),Ye=6e3;function st(e){return Object.hasOwn(z,e?.kind)?z[e.kind]:Ye}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 X(e,t){return!t||t.kind!=="weather"?"":ze.test(String(e||""))?String(t.subject||"here"):""}function Xe(e,t){const n=$(e)||X(e,t)||F(e,t);if(n)return{kind:"weather",subject:n};if(P(e))return{kind:"weather",subject:"here"};const s=v(e)||B(e,t);if(s)return{kind:"stock",subject:s};const o=J(String(e||""),t);if(o)return o;const r=j(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function ot(e){const t=(Array.isArray(e)?e:[]).filter(o=>o&&!o.pending&&(o.role==="user"||o.role==="assistant")),n=[];for(let o=0;o<t.length;o++)t[o].role==="user"&&n.push(o);if(n.length<2)return null;let s=null;for(let o=0;o<n.length-1;o++){const r=t[n[o]],l=t[n[o]+1]?.role==="assistant"?t[n[o]+1]:null,c=(r.attachments||[]).find(a=>a?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"";s=Xe(u,s)||(c?{kind:c.prefetch,...c.research?{research:c.research}:{}}:null)||((l?.steps||[]).some(a=>a?.input?.action==="weather"||a?.tool==="weather")?{kind:"weather"}:null)}return s}function rt({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,now:u=Date.now()}={}){const i=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),a=[];if(ke(e))return r?Q(e,t,i):[];const d=de.test(String(e||""))?ge(s):"",w=String(e||"").trim().split(/\s+/).length,f=ce(e)||(d?{query:d}:null)||(pe.test(String(e||""))&&w<=14?{}:null);if(f&&(i.has("find:web_search")||i.has("web_search"))){const h=f.query||String(n||"").trim();if(h){const p=i.has("find:web_search"),m=!f.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,...he.test(h)?{weather:!0}:{},...m?{borrowed:!0}:{}}]}}if(c&&(i.has("page:read_page")||i.has("read_page"))&&x(e)){const h=i.has("page:read_page"),p=me.test(e)&&x(n)?String(n).trim():"";return[{kind:"page",tool:h?"page":"read_page",input:h?{action:"read_page",args:{}}:{},label:"This page",...p?{ask:p}:{}}]}const S=i.has("find:weather"),V=i.has("weather");if(S||V){e=be(e)||e;const h=$(e)?"":X(e,t),p=$(e)||(h?h!=="here"?h:"":F(e,t)),m=p||(P(e)||h?"here":"");if(m&&(a.push({kind:"weather",tool:S?"find":"weather",input:S?{action:"weather",args:{location:m}}:{location:m},label:p?`Weather — ${p}`:"Weather — near you"}),p&&le.test(String(e||""))&&(i.has("find:web_search")||i.has("web_search")))){const _=`${p} 10 day weather forecast`,L=i.has("find:web_search");a.push({kind:"web",tool:L?"find":"web_search",input:L?{action:"web_search",args:{query:_}}:{query:_},label:`Web — ${p} extended forecast`,subject:_,weather:!0})}}const g=i.has("find:web_search");if(!a.length&&(g||i.has("web_search"))){const h=v(e)||B(e,t);if(h){const p=`${h} stock price today`;a.push({kind:"stock",tool:g?"find":"web_search",input:g?{action:"web_search",args:{query:p}}:{query:p},label:`Stock — ${h}`})}}if(!a.length&&(g||i.has("web_search"))){const h=Ke(e);if(h){const p=h.subject?`${h.subject} news today`:"top news today";a.push({kind:"news",tool:g?"find":"web_search",input:g?{action:"web_search",args:{query:p}}:{query:p},label:h.subject?`News — ${h.subject}`:"News — today",subject:h.subject})}}if(l&&!a.length&&(g||i.has("web_search"))){const h=j(e,{previous:t,now:u});if(h){const p=g?"find":"web_search";a.push({kind:"research",tool:p,input:p==="find"?{action:"web_search",args:{query:h.queries[0]}}:{query:h.queries[0]},label:`Research — ${h.subject}`,subject:h.subject,research:h})}}return r&&!a.length&&a.push(...Q(e,t,i)),a}function Q(e,t,n){const s=J(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:d=>({action:a,args:d})}:n.has(a)?{tool:a,input:d=>d}:null,c=[],u=l("history_search"),i=l("web_search");return u&&!s.web&&c.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),i&&(s.web||K(o))&&c.push({kind:"lookup",tool:i.tool,input:i.input({query:o}),label:`Web — ${o}`,subject:o,note:r,fallback:c.length>0}),c}function at(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 it(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 Qe(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function Ve(e,t,{now:n=Date.now(),note:s=""}={}){if(e.kind==="web"&&e.weather&&(t=te(t)||t),e.kind==="research"){const u=String(t||""),{question:i,domain:a,subject:d,slots:w}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||d||"",research:{question:i,domain:a,subject:d,slots:w},title:e.label,text:u,chars:u.length}}const o=e.kind==="page"?"this is the page they mean.":e.kind==="web"?`these are web results for "${String(e.subject||"").slice(0,80)}" — answer from them; search again only with different words.`:e.kind==="stock"?`do not call ${e.tool} or any search tool again for the same company. Say the price and change it gives; if it gives none, say you could not find a current price — never estimate one.`:e.kind==="lookup"?`if it is about someone or something else, or found nothing, search again with DIFFERENT words (another spelling, the other source — library or web) — never the same query.${e.note?` ${e.note}`:""}`:`do not call ${e.tool} or any weather/search tool again for the same place.`,r=e.kind==="lookup"||e.kind==="web"?`SEARCHED for "${e.subject}"`:e.kind==="page"?"READ the page the user has open":"FETCHED",l=e.kind==="page"&&e.ask?`
1
+ import{researchAsk as O,runResearch as Z}from"./web-research.js";import{frontPagesAskedAbout as ee}from"./site-pages.js";import{weatherFromSearch as te}from"./weather-tool.js";const R=/(\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,ne=/\b(right now|now|today|tonight|this (?:morning|afternoon|evening|weekend|week)|tomorrow|currently|at the moment|these days|later)\b/gi,se=new Set(["here","there","home","outside","my location","my area","my city","where i am","it","that"]),N=8,E="(?:page|tab|article|post|thread|discussion|story|site|website|doc|document|comments?|content|piece|blog(?: post)?|paper|video|readme|pdf)",oe=new RegExp(`\\b(?:this|current|the current|the open|open|that)\\s+${E}\\b`,"i"),re=new RegExp(`^\\s*(?:(?:can you |could you |please )?(?:summari[sz]e|tl;?\\s?dr|recap|give me the gist|what are the key (?:points|takeaways))(?:\\s+(?:it|this|that|here|(?:the|this)\\s+${E}(?:\\s+and\\s+(?:the\\s+)?${E})?))?|what(?:'s| is| are)? (?:people|they|folks|commenters) (?:saying|think(?:ing)?)(?: here| about (?:it|this))?)\\s*[?.!]*\\s*$`,"i"),ae=/\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,ie=/^\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 ce(e){const t=ie.exec(String(e||""));if(!t)return null;const n=String(t[1]||"").trim();return n?{query:n}:{}}const he=/\b(?:weather|forecast|temperature|rain|snow)\b/i,le=/\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,ue=/\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,pe=/\b(?:find out more|find (?:out )?more|more (?:info|information|details)|look into (?:it|that|this)|dig (?:deeper|into (?:it|that))|get more details?|find (?:it|that) out|check (?:on )?(?:it|that) (?:again|online)|search (?:for )?more|look (?:it|that) up|find (?:the )?(?:rest|full|whole)(?: of it| forecast)?)\b/i,de=/^\s*(?:yes|yeah|yep|yup|sure|ok(?:ay)?|k|please(?: do)?|go ahead|go for it|do it|yes please|sure thing|absolutely|of course|ok look|look|search|please search|search it)(?:[\s,.!]+(?:please|thanks|thank you|go ahead|do it|look|search|yes))*[\s.!]*$/i,we=/\b(?:search the web|web search|search online|search for|look (?:it|that|this) up|look up|check online|find (?:it|that|out|more))\b/i,fe=/(?:web search for|search the web for|search (?:online )?for|look up|look for)\s+(?:the\s+)?(.{3,160}?)(?:\s*[?.!]|$)/i;function ge(e){const t=String(e||"").split(/\n+/).map(s=>s.trim()).filter(Boolean).slice(-3).join(" ");if(we.test(t)&&/\?/.test(t)){const s=(fe.exec(t)?.[1]||"").replace(/\s+for me$/i,"").trim();if(s)return s}const n=/\b(?:searching(?: the web| online)? for|looking up|checking(?: the web| online)? for)\s+(?:the\s+)?(.{3,160}?)(?:\.\.\.|…|[.!?]|$)/i.exec(t);return n?n[1].trim():""}const A=/^\s*(?:(?:no|nope|actually|but|well|sorry)\b[,.!]?\s*)?(?:i|we) (?:asked|said|meant|wanted)\b/i,x=/\b(?:did|when|how (?:many|often)|earlier|before|yesterday|last (?:time|week|month)|ago|previously|other day)\b/i;function be(e){const t=String(e||"");if(!A.test(t)||x.test(t))return"";const n=t.replace(A,"").replace(/^\s*(?:for|about)\s+/i,"").replace(/[.;]\s+(?:and|also)\s+/gi," and ").replace(/,?\s+not\s+[^.?!]*/i,"").trim();return/^(?:the\s+)?(?:weather|forecast|temperature)\b/i.test(n)?`what is ${/^the\s/i.test(n)?"":"the "}${n}`:""}function ke(e){const t=String(e||"");return A.test(t)&&!x.test(t)?!1:ue.test(t)}const me=/^\s*(?:and|what about|how about|now|no,?|ok,?|same for)\b[^?.!]{0,30}[?.!]*\s*$/i;function C(e){const t=String(e||"").trim();return!t||t.length>300||ae.test(t)?null:oe.test(t)||re.test(t)?{}:null}function w(e){return String(e||"").replace(ne," ").replace(/[?!.,;:]+$/g,"").replace(/^\s*(the|in|at|for|around|near|of)\s+/i,"").replace(/\s+/g," ").trim()}const P=/\b(how|what|what's|whats|is|are|was|will|do|does|can|should|why|when|the|a|an|tell|me|there|here|it|like|about)\b/i;function y(e){const t=e.toLowerCase();return t.length>=2&&t.length<=60&&!se.has(t)&&!P.test(t)&&!/^(weather|forecast|temperature)$/.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=5}function T(e){const t=String(e||"").trim();return!R.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 ye=/\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(!R.test(t))return"";const n=t.replace(ye,"").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(y(o))return o;if(y(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&&y(w(s[1]))&&!L.test(w(s[1]))||(s=/\b(?:weather|forecast|temperature)\s*[:\-]?\s+([\p{L}][\p{L}\s,.'-]{1,60}?)\s*[?!.]*$/iu.exec(n),s&&y(w(s[1])))?w(s[1]):""}const L=/\b(summari[sz]e|explain|try|again|retry|do|make|write|show|tell|open|read|find|search|help|stop|continue|go|list|give|send|run|check|fix|get|fetch|pull|grab|look ?up|display|compare|bring|thanks|thank|yes|no|please|this|that|my|page|note|file|meeting|chat|sounds?|good|great|nice|cool|fine|perfect|awesome|sure|nothing|else|ok|okay|yeah|yep|nope|bye|hello|hi|hey|time|traffic|news|story|joke|stock|price|you|yourself|him|her|them|us)\b/i,$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)(?:[\s,.!—-]+|$))+/i,Se=/^(?:(?:i(?: want| wanted| would like|'d like) to know|i'm wondering|i wonder|(?:can|could) you (?:tell|check) (?:me)?|tell me)\s+)/i,W=/^(?:(?:how|what) about|(?:how|what)(?:'s| is|s) it(?: like)?(?: in| at| for| around| near)?|(?:in|at|for|around|near))\b[\s,]*/i;function F(e,t){if(!t||t.kind!=="weather")return"";const n=String(e||"").trim().replace(/[?!.]+$/,"").trim(),s=n.replace($e,"").trim().replace(Se,"").trim();if(!s||s.split(/\s+/).length>N)return"";const o=W.test(s)||s!==n&&/^(?:and|also)\b/i.test(n),r=w(s.replace(W,"").replace(/^(?:like\s+)?(?:in|at|for|around|near)\s+/i,""));return!r||/\d/.test(r)||!o&&r.split(/\s+/).length>2||!y(r)||L.test(r)?"":r}const k="([\\p{L}$][\\p{L}\\p{N}.&'-]*(?:\\s+[\\p{L}][\\p{L}\\p{N}.&'-]*){0,3})",_e=[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],Ee=/^(?: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,Ae=/^(?: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,Le=/\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 D(e){const t=e.toLowerCase();return t.length>=1&&t.length<=40&&!Ee.test(t)&&!P.test(t)&&/^[\p{L}]/u.test(t)&&t.split(/\s+/).length<=4}function je(e){const t=e.split(/\s+/).filter(Boolean);for(;t.length>1&&Ae.test(t[0]);)t.shift();return t.join(" ")}function q(e){return String(e||"").replace(/[?!.,;:]+$/g,"").replace(Le,"").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 v(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 _e){const o=s instanceof RegExp?s:s.re;if(s.question&&!n)continue;const r=o.exec(t);if(!r)continue;const l=je(q(r[1]));if(D(l))return l}return""}function B(e,t){if(!t||t.kind!=="stock")return"";let n=String(e||"").trim().replace(/[?!.]+$/,"").trim();if(!n||n.split(/\s+/).length>N)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=q(n);return!o||!s&&(o.split(/\s+/).length>2||!/[?]\s*$/.test(String(e))&&o.split(/\s+/).length>1)||!D(o)||L.test(o)?"":o}const M=new RegExp("(?<![\\p{L}\\p{N}'])\\p{L}(?:[ \\t.,\\-–]{1,3}\\p{L}(?![\\p{L}\\p{N}'])){2,}","gu");function U(e){return String(e||"").replace(M,t=>t.replace(/[^\p{L}]/gu,"").toLowerCase())}function Oe(e){return[...String(e||"").matchAll(M)].map(t=>t[0].replace(/[^\p{L}]/gu,"").toLowerCase())}const Re=/\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,Ne=/[.?!;:,()](?=\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,xe=/^(?:it|this|that|these|those|him|her|them|me|you|yourself|us|he|she|they|we|i|my|our|your|his|their|here|there|on|in|at|to|for|with|from|going|coming|speaking|talking|calling|joining|what|how|why|when|where|which|the weather|weather)\b/i,Ce=/^(?:my|our|your|this|that|today'?s|yesterday'?s|last|next|latest|recent)\b/i,Pe=/^(?:the|a|an)\b/i,Te=6;function I(e){const n=(String(e||"").split(Ne)[0]||"").replace(/\s+/g," ").replace(/^["'“‘]+|["'”’]+$/g,"").trim(),s=n.split(" ").filter(Boolean);return!s.length||s.length>Te||!new RegExp("\\p{L}","u").test(n)||xe.test(n)?"":n}function We(e){const t=Re.exec(U(e));return t?I(t[1]):""}const Fe=[[/\b(?:last|sur|family|second) ?name\b|\bsurname\b/i,e=>e.length-1],[/\bfirst name\b|\bgiven name\b/i,()=>0]],De=/\b(?:it(?:'s| is)|spelled|spelt|should be|is actually|actually|but|name is)\s+["'“‘]?([\p{L}][\p{L}'-]{1,40})["'”’]?\s*[.!?]*\s*$/iu,qe=/\b(?:no|nope|not|wrong|incorrect|misspel\w*|spell\w*|typo|name|actually|i meant|i mean)\b/i;function ve(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 Be(e,t){return new RegExp("^\\p{Lu}","u").test(t)?e.charAt(0).toUpperCase()+e.slice(1):e}function H(e,t){const n=String(t||"").trim();if(!n)return null;const s=String(e||""),o=Oe(s),r=U(s);let l=o.at(-1)||"";if(!l&&qe.test(r)&&(l=De.exec(r)?.[1]||""),!l||l.length<2)return null;const c=n.split(/\s+/);let u=-1;for(const[a,d]of Fe)if(a.test(r)){u=d(c);break}if(u<0){let a=1/0;c.forEach((d,f)=>{const g=ve(d,l)/Math.max(d.length,l.length);g<a&&(a=g,u=f)}),a>.6&&(u=c.length===1?0:-1)}if(u<0)return null;const i=c[u];return i.toLowerCase()===l.toLowerCase()?{subject:n,replaced:""}:(c[u]=Be(l,c.find(a=>new RegExp("^\\p{Lu}","u").test(a))||i),{subject:c.join(" "),replaced:i})}const Me=/\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,G=/\b(?:web|online|internet|google)\b/i;function Ue(e,t){if(!t||t.kind!=="lookup"||!t.subject)return null;const n=H(e,t.subject),s=/\b(?:not|wrong|isn'?t|incorrect|nope)\b/i.test(e);return!n&&!s&&!Me.test(e)?null:{subject:n?.subject||t.subject,replaced:n?.replaced||"",corrected:!!n||s,web:G.test(e)}}function J(e,t){const n=We(e);if(n){const o=H(e.slice(e.toLowerCase().indexOf(n.toLowerCase())+n.length),n);return{kind:"lookup",subject:o?.subject||n,replaced:o?.replaced||"",corrected:!!o?.replaced,web:G.test(e)}}const s=Ue(e,t);return s?{kind:"lookup",...s}:null}function K(e){return Ce.test(e)||/@|\d{5,}/.test(e)||!new RegExp("\\p{L}{2,}","u").test(e)?!1:!Pe.test(e)||new RegExp("\\s\\p{Lu}","u").test(e)}const Ie=/\b(?:news|headlines|stories)\s+(?:on|about|from|in|for|regarding|around)\s+(.+)$/i,He=/\bwhat(?:'s| is| are)\s+(?:new|happening|going on|the latest|the news)\s+(?:with|in|on|at|around|from)\s+(.+)$/i,Ge=/^(?:(?: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,Je=/^(?:(?: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,Y=/\s+(?:today|tonight|this (?:morning|week|evening|year)|right now|lately|these days|recently|now)$/i;function Ke(e){const t=String(e||"").trim();if(!t||ee(t).length)return null;if(Je.test(t))return{subject:""};const n=Ie.exec(t)||Ge.exec(t),s=n?null:He.exec(t),o=n||s;if(!o)return null;const r=I(o[1].replace(/[?.!]+$/,"").replace(Y,"")).replace(Y,"");return s&&r.split(/\s+/).length>4||!r||!K(r)||/^(?:the )?(?:weather|stock|stocks|market)$/i.test(r)?null:{subject:r}}function nt(e){return/^\s*No (?:history matches|web results)\b/.test(String(e||""))}const z=Object.freeze({page:15e3,web:12e3,lookup:12e3}),Ye=6e3;function st(e){return Object.hasOwn(z,e?.kind)?z[e.kind]:Ye}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 X(e,t){return!t||t.kind!=="weather"?"":ze.test(String(e||""))?String(t.subject||"here"):""}function Xe(e,t){const n=$(e)||X(e,t)||F(e,t);if(n)return{kind:"weather",subject:n};if(T(e))return{kind:"weather",subject:"here"};const s=v(e)||B(e,t);if(s)return{kind:"stock",subject:s};const o=J(String(e||""),t);if(o)return o;const r=O(e,{previous:t});return r?{kind:"research",subject:r.subject,research:r}:null}function ot(e){const t=(Array.isArray(e)?e:[]).filter(o=>o&&!o.pending&&(o.role==="user"||o.role==="assistant")),n=[];for(let o=0;o<t.length;o++)t[o].role==="user"&&n.push(o);if(n.length<2)return null;let s=null;for(let o=0;o<n.length-1;o++){const r=t[n[o]],l=t[n[o]+1]?.role==="assistant"?t[n[o]+1]:null,c=(r.attachments||[]).find(a=>a?.kind==="prefetch"),u=typeof r.content=="string"?r.content:"";s=Xe(u,s)||(c?{kind:c.prefetch,...c.research?{research:c.research}:{}}:null)||((l?.steps||[]).some(a=>a?.input?.action==="weather"||a?.tool==="weather")?{kind:"weather"}:null)}return s}function rt({text:e="",previous:t=null,previousText:n="",previousAnswer:s="",reach:o=new Set,lookup:r=!1,research:l=!1,page:c=!1,now:u=Date.now()}={}){const i=o instanceof Set?o:new Set(Array.isArray(o)?o:[]),a=[];if(ke(e))return r?Q(e,t,i):[];const d=de.test(String(e||""))?ge(s):"",f=String(e||"").trim().split(/\s+/).length,g=ce(e)||(d?{query:d}:null)||(pe.test(String(e||""))&&f<=14?{}:null);if(g&&(i.has("find:web_search")||i.has("web_search"))){const h=g.query||String(n||"").trim();if(h){const p=i.has("find:web_search"),m=!g.query;return[{kind:"web",tool:p?"find":"web_search",input:p?{action:"web_search",args:{query:h}}:{query:h},label:`Web — ${h.slice(0,60)}`,subject:h,...he.test(h)?{weather:!0}:{},...m?{borrowed:!0}:{}}]}}if(c&&(i.has("page:read_page")||i.has("read_page"))&&C(e)){const h=i.has("page:read_page"),p=me.test(e)&&C(n)?String(n).trim():"";return[{kind:"page",tool:h?"page":"read_page",input:h?{action:"read_page",args:{}}:{},label:"This page",...p?{ask:p}:{}}]}const S=i.has("find:weather"),V=i.has("weather");if(S||V){e=be(e)||e;const h=$(e)?"":X(e,t),p=$(e)||(h?h!=="here"?h:"":F(e,t)),m=p||(T(e)||h?"here":"");if(m&&(a.push({kind:"weather",tool:S?"find":"weather",input:S?{action:"weather",args:{location:m}}:{location:m},label:p?`Weather — ${p}`:"Weather — near you"}),p&&le.test(String(e||""))&&(i.has("find:web_search")||i.has("web_search")))){const _=`${p} 10 day weather forecast`,j=i.has("find:web_search");a.push({kind:"web",tool:j?"find":"web_search",input:j?{action:"web_search",args:{query:_}}:{query:_},label:`Web — ${p} extended forecast`,subject:_,weather:!0})}}const b=i.has("find:web_search");if(!a.length&&(b||i.has("web_search"))){const h=v(e)||B(e,t);if(h){const p=`${h} stock price today`;a.push({kind:"stock",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:`Stock — ${h}`})}}if(!a.length&&(b||i.has("web_search"))){const h=Ke(e);if(h){const p=h.subject?`${h.subject} news today`:"top news today";a.push({kind:"news",tool:b?"find":"web_search",input:b?{action:"web_search",args:{query:p}}:{query:p},label:h.subject?`News — ${h.subject}`:"News — today",subject:h.subject})}}if(l&&!a.length&&(b||i.has("web_search"))){const h=O(e,{previous:t,now:u});if(h){const p=b?"find":"web_search";a.push({kind:"research",tool:p,input:p==="find"?{action:"web_search",args:{query:h.queries[0]}}:{query:h.queries[0]},label:`Research — ${h.subject}`,subject:h.subject,research:h})}}return r&&!a.length&&a.push(...Q(e,t,i)),a}function Q(e,t,n){const s=J(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:d=>({action:a,args:d})}:n.has(a)?{tool:a,input:d=>d}:null,c=[],u=l("history_search"),i=l("web_search");return u&&!s.web&&c.push({kind:"lookup",tool:u.tool,input:u.input({query:o}),label:`Library — ${o}`,subject:o,note:r}),i&&(s.web||K(o))&&c.push({kind:"lookup",tool:i.tool,input:i.input({query:o}),label:`Web — ${o}`,subject:o,note:r,fallback:c.length>0}),c}function at(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 it(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 Qe(e,t=""){const n=String(t||"").replace(/^ChatPanel\s*·\s*/u,"").trim();return n&&n!=="ChatPanel"?`${e?.label||""} · ${n}`:e?.label||""}function Ve(e,t,{now:n=Date.now(),note:s=""}={}){if(e.kind==="web"&&e.weather&&(t=te(t)||t),e.kind==="research"){const u=String(t||""),{question:i,domain:a,subject:d,slots:f}=e.research||{};return{id:`prefetch_research_${n}`,kind:"prefetch",prefetch:"research",subject:e.subject||d||"",research:{question:i,domain:a,subject:d,slots:f},title:e.label,text:u,chars:u.length}}const o=e.kind==="page"?"this is the page they mean.":e.kind==="web"?`these are web results for "${String(e.subject||"").slice(0,80)}" — answer from them; search again only with different words.`:e.kind==="stock"?`do not call ${e.tool} or any search tool again for the same company. Say the price and change it gives; if it gives none, say you could not find a current price — never estimate one.`:e.kind==="lookup"?`if it is about someone or something else, or found nothing, search again with DIFFERENT words (another spelling, the other source — library or web) — never the same query.${e.note?` ${e.note}`:""}`:`do not call ${e.tool} or any weather/search tool again for the same place.`,r=e.kind==="lookup"||e.kind==="web"?`SEARCHED for "${e.subject}"`:e.kind==="page"?"READ the page the user has open":"FETCHED",l=e.kind==="page"&&e.ask?`
2
2
 
3
3
  The question about this page: ${e.ask.slice(0,200)}`:"",c=`(ALREADY ${r} for the question below, with ${e.tool}. Answer from this; ${o})
4
4
 
5
- ${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:Qe(e,s),text:c,chars:c.length}}async function ct(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const c=s(),u=i=>{try{o({type:"tool",name:"research",prefetched:!0,...i})}catch{}};u({phase:"start",input:e.input,summary:e.label});try{const{text:i,result:a}=await Z(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:f=>u({phase:"progress",summary:`${e.label} — ${f.label}`})});if(!i)return u({phase:"done",status:"skipped",summary:e.label,ms:s()-c}),{attachment:null,text:"",result:a,note:"",status:"skipped"};const d=a.stats,w=`${d.searches} search${d.searches===1?"":"es"} · ${d.sites} site${d.sites===1?"":"s"} · ${(d.ms/1e3).toFixed(1)} s`;return u({phase:"done",status:"ok",summary:`${e.label} — ${w}`,ms:s()-c}),{attachment:Ve(e,i,{now:s()}),text:i,result:a,note:w,status:"ok"}}catch(i){const a=`error: ${String(i?.message||i).slice(0,80)}`;return u({phase:"done",status:a,summary:e.label,ms:s()-c}),{attachment:null,text:"",result:null,note:"",status:a}}}export{ke as aboutOwnPast,at as answeredByPrefetch,H as correctedSubject,U as joinSpelled,Ue as lookupFollowup,Qe as lookupLabel,it as lookupResult,We as lookupSubject,Ke as newsAsk,ge as offeredSearch,x as pageAsk,Ve as prefetchAttachment,st as prefetchBudgetMs,nt as prefetchMissed,rt as prefetchPlan,ot as previousAsk,be as restatedWeather,ct as runResearchItem,B as stockFollowupSubject,v as stockSubject,F as weatherFollowupPlace,X as weatherFollowupWhen,P as weatherHere,$ as weatherPlace,ce as webRedoAsk};
5
+ ${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:Qe(e,s),text:c,chars:c.length}}async function ct(e,{execute:t,until:n=null,now:s=()=>Date.now(),onActivity:o=()=>{},read:r=null,rerank:l=null}={}){const c=s(),u=i=>{try{o({type:"tool",name:"research",prefetched:!0,...i})}catch{}};u({phase:"start",input:e.input,summary:e.label});try{const{text:i,result:a}=await Z(e,{execute:t,until:n,now:s,read:r,rerank:l,onProgress:g=>u({phase:"progress",summary:`${e.label} — ${g.label}`})});if(!i)return u({phase:"done",status:"skipped",summary:e.label,ms:s()-c}),{attachment:null,text:"",result:a,note:"",status:"skipped"};const d=a.stats,f=`${d.searches} search${d.searches===1?"":"es"} · ${d.sites} site${d.sites===1?"":"s"} · ${(d.ms/1e3).toFixed(1)} s`;return u({phase:"done",status:"ok",summary:`${e.label} — ${f}`,ms:s()-c}),{attachment:Ve(e,i,{now:s()}),text:i,result:a,note:f,status:"ok"}}catch(i){const a=`error: ${String(i?.message||i).slice(0,80)}`;return u({phase:"done",status:a,summary:e.label,ms:s()-c}),{attachment:null,text:"",result:null,note:"",status:a}}}export{ke as aboutOwnPast,at as answeredByPrefetch,H as correctedSubject,U as joinSpelled,Ue as lookupFollowup,Qe as lookupLabel,it as lookupResult,We as lookupSubject,Ke as newsAsk,ge as offeredSearch,C as pageAsk,Ve as prefetchAttachment,st as prefetchBudgetMs,nt as prefetchMissed,rt as prefetchPlan,ot as previousAsk,be as restatedWeather,ct as runResearchItem,B as stockFollowupSubject,v as stockSubject,F as weatherFollowupPlace,X as weatherFollowupWhen,T as weatherHere,$ as weatherPlace,ce as webRedoAsk};
@@ -0,0 +1 @@
1
+ const i=Object.freeze([[],[1],[2],[3],[1,2],[1,3],[2,3]]);function p(r=[],{minMs:a=300,gapMs:o=250}={}){const s=new Map;for(const t of r)if(!(!t||!(t.end>t.start)))for(const n of i[t.id]||[]){const c=s.get(n)||[],e=c[c.length-1];e&&t.start-e.end<=o/1e3?e.end=Math.max(e.end,t.end):c.push({local:n,start:t.start,end:t.end}),s.set(n,c)}const l=[];for(const t of s.values())for(const n of t)(n.end-n.start)*1e3>=a&&l.push(n);return l.sort((t,n)=>t.start-n.start||t.local-n.local)}function d(r=[]){const a=new Map;for(const o of r)a.set(o.local,(a.get(o.local)||0)+(o.end-o.start));return[...a.entries()].map(([o,s])=>({local:o,seconds:s})).sort((o,s)=>s.seconds-o.seconds||o.local-s.local)}function h(r=[]){return d(r)[0]?.local??null}function x(r,a,o,s=16e3){const l=[];let t=0;for(const e of a){if(e.local!==o)continue;const f=Math.max(0,Math.round(e.start*s)),u=Math.min(r.length,Math.round(e.end*s));u>f&&(l.push(r.subarray(f,u)),t+=u-f)}const n=new Float32Array(t);let c=0;for(const e of l)n.set(e,c),c+=e.length;return n}export{i as POWERSET,x as audioOfLocal,h as mainLocal,d as timeByLocal,p as turnsFromSpans};