@chatpanel/events 0.452.0 → 0.453.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/voice-intents.js +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/events",
3
- "version": "0.452.0",
3
+ "version": "0.453.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",
package/voice-intents.js CHANGED
@@ -1,2 +1,2 @@
1
- import{defineSchema as ee,describeSchema as te,responseFormat as ne,coerce as re,createStructuredStream as se}from"./structured.js";import{DANGLING_TAILS as ie}from"./schedule.js";import{editDistance as R}from"./distance.js";class D extends Error{constructor(e,s){super(s),this.name="VoiceIntentError",this.code=e}}const oe=Object.freeze(["chatpanel"]),ae="Chap",le=Object.freeze(["Chapel"]);function U(t){return t<=4?0:t<=6?1:2}const j=3,ce=8;function I(t){return String(t||"").toLowerCase().replace(/[‘’]/g,"'").replace(/[^\p{L}\p{N}':.\s]/gu," ")}function W(t){const e=I(t),s=[],n=/[\p{L}\p{N}'.:]+/gu;let r;for(;r=n.exec(e);){const i=r[0].replace(/^[.:]+|[.:]+$/g,"");i&&s.push({w:i,start:r.index,end:r.index+r[0].length})}return s}function x(t=oe,{exact:e=[]}={}){const s=(Array.isArray(t)?t:String(t??"").split(/[,|;\n]/)).map(o=>String(o??"").trim()).filter(Boolean),n=[],r=[],i=o=>String(o??"").toLowerCase().replace(/[^\p{L}\p{N}]/gu,""),a=new Set((Array.isArray(e)?e:[e]).map(i)),c=[];let l=1;for(const o of s){const d=i(o);d.length<3||n.includes(d)||(n.push(d),r.push(o),c.push(a.has(d)?0:U(d.length)),l=Math.max(l,o.split(/\s+/).filter(Boolean).length+1))}if(!n.length)throw new D("BAD_WAKE","wake word must have at least 3 letters");return Object.freeze({phrases:Object.freeze(n),labels:Object.freeze(r),slacks:Object.freeze(c),maxTokens:Math.min(Math.max(l,j),ce)})}function Ke({words:t="",name:e="",bare:s=!0}={}){const n=(Array.isArray(t)?t:String(t||"").split(/[,|;\n]/)).map(d=>String(d).trim()).filter(Boolean),r=String(e||"").trim(),i=r.replace(/[^\p{L}\p{N}]/gu,"").length,a=i>=3?s?[`hey ${r}`,r]:[`hey ${r}`]:[],c=r.toLowerCase()===ae.toLowerCase()?le.map(d=>`hey ${d}`):[],l=[...a,...c,...n],o=i>=3&&i<=4?a:[];return l.length?x(l,{exact:o}):x()}const ue=2;function de(t,e,s){const n=[],r=s.maxTokens||j;for(let i=0;i<e.length;i++){let a="",c=!1;for(let l=0;l<r&&i+l<e.length&&!c;l++){a+=e[i+l].w.replace(/[^\p{L}\p{N}]/gu,"");for(let o=0;o<s.phrases.length;o++){const d=s.phrases[o],u=s.slacks?.[o]??U(d.length);if(!(Math.abs(a.length-d.length)>u)&&R(a,d,u)<=u){n.push({phrase:d,start:e[i].start,end:e[i+l].end,addressed:ke(t,e,i,l)}),i+=l,c=!0;break}}}}return n}function z(t,e){const s=String(t||"");if(!s)return s;const n=/[.!?…]+["'\u2019\u201d)\]]*(?=\s|$)/g;let r=0,i;for(;r<e&&(i=n.exec(s));)if(r+=1,r===e)return s.slice(0,i.index+i[0].length);return s}function F(t,e=x(),{maxSentences:s=ue}={}){const n=String(t||""),r=W(n);if(!r.length)return[];const i=de(n,r,e),a=[];let c=0;for(let l=0;l<i.length;l++){const o=i[l];if(!o.addressed&&o.start<c)continue;let d=n.length;for(let p=l+1;p<i.length;p++)if(i[p].addressed){d=i[p].start;break}const u=n.slice(o.end,d),h=xe($(z(u,s)).trim());c=Math.max(c,o.end+u.indexOf(h)+h.length),a.push({command:h,wake:o.phrase,heard:n.slice(o.start,o.end),at:o.start,addressed:o.addressed,rest:n.slice(o.end+u.indexOf(h)+h.length,d).trim()})}return a}function he(t,e=x(),s={}){return F(t,e,s)[0]||null}const B=new RegExp("^(?:ok(?:ay)?|all ?right|right|so|well|um+|uh+|hmm+|yeah|yep|hey|and|but|then|now|let(?:'s| us) see|we(?:'ll| will) see|so we(?:'ll| will) see|i think it is doing something|it does anything|does it (?:do )?anything|hold on(?: a second)?|one second|let me see|i think|i guess|here we go|there we go|test(?:ing)?)[\\s,.!?]*$","i"),fe=/(?<=[.!?])\s+/;function me(t){const e=String(t||"").trim().replace(/^[\s,.:;!?-]+/,"");if(!e||B.test(e))return!0;const s=e.split(",").map(n=>n.trim()).filter(Boolean);return s.length>1&&s.every(n=>B.test(n))}function He(t,{maxName:e=48}={}){const s=$(String(t||"")).trim();if(!s)return{request:"",name:""};const r=s.split(fe).map(u=>u.trim()).filter(Boolean).filter(u=>!me(u)),i=r.filter(u=>/\?\s*$/.test(u)),a=i.length>1,c=i.length===1?i[0]:r.length?r.join(" "):s,l=$(c).trim()||s,o=l.replace(/\s+/g," ").trim(),d=o.length>e?`${o.slice(0,e-1).replace(/\s+\S*$/,"")}…`:o;return{request:l,name:d||o,ambiguous:a}}const T=ee({name:"voice_refinement",fields:{request:{type:"string",required:!0,max:400,describe:"the one thing they actually want done, in their own words, one sentence"},name:{type:"string",max:48,describe:"a label of at most 6 words"},kind:{type:"enum",values:["question","action","monitor","note","skill","timer","none"],default:"question",describe:"the SMALLEST kind that does what they asked"},skill:{type:"string",max:80,describe:"the skill name, only when kind is skill"}},nothing:{request:"",name:"",kind:"none",skill:""}});function Ve(t){return["A person spoke to their assistant during a meeting. Below is everything they said after","the wake word, transcribed live — so it contains false starts, thinking aloud, and","sometimes several questions where only one is the request.","",te(T),"","Pick the SMALLEST kind that does what they asked:"," question — answer it once, now. The DEFAULT for anything they want to know.",' action — DO something in the browser or an app ("go to google.com and search for X").',' monitor — only if they asked to be told as the meeting CONTINUES ("let me know if",',' "keep an eye on"). A one-off question is NOT a monitor.',' note — they asked for notes written down ("take notes on", "write that up").',' skill — they named a saved skill ("use the summarize skill"); put its name in `skill`.',' timer — alerted after an AMOUNT OF TIME ("set a one minute"); keep it in `request`.'," none — not asking for anything: thinking aloud, or talking ABOUT the assistant.",'Never invent a request that is not there — return "none". Keep `request` close to their',"words; do not answer it.","","WHAT THEY SAID:",String(t||"")].join(`
2
- `)}function Pe(t="schema"){return ne(T,{mode:t})}function Xe(t){const e=re(t,T);return e?C(e.value):null}function C(t){if(!t)return null;const e=String(t.request||"").trim();if(t.kind==="none"||!e)return{request:"",name:"",kind:"none",skill:""};let s=t.kind==="skill"&&!t.skill?"question":t.kind;const n=String(t.name||"").trim()||e;if(s==="timer"){const r=q(e);return r?{request:e,name:n,kind:"timer",skill:"",ms:r.ms}:{request:e,name:n,kind:"question",skill:""}}return{request:e,name:n,kind:s,skill:t.skill||""}}function Ye(t,e){const s=String(e||"").toLowerCase();if(!s)return!1;let n;try{n=new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return!1}if(!n)return!1;if(s.includes(n))return!0;const r=n.split(".");return r.length!==2?!1:new RegExp(`\\b${r[0].replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`).test(s)}function Je({onChange:t=null}={}){const e=se(T,{onChange:t?(n,r)=>t(C(n),r):null}),s=n=>({...n,value:C(n.value)});return{push:n=>s(e.push(n)),end:()=>s(e.end()),snapshot:()=>s(e.snapshot()),reset:()=>e.reset(),get text(){return e.text}}}const G=/^(?:the|a|an|our|your|their|my|this|that|these|those|about|on|in|of|with|via|using|called|named|to)$/i,pe=/^(?:actually|really|also|always|never|just|only|still|often|usually|basically|literally|probably|certainly|definitely|now|then|even|apparently|obviously)$/i,ge=/^(?:is|isn't|was|wasn't|are|aren't|were|weren't|has|hasn't|have|had|does|doesn't|did|didn't|can|can't|cannot|could|couldn't|will|won't|would|wouldn't|should|shouldn't|shall|may|might|must|seems|helps|lets|gives|allows|works|looks|means|needs|wants|keeps|makes|shows|tells|comes|goes|takes|runs|becomes|provides|supports)$/i,we=/^(?:you|we|i|they|it|there|he|she)$/i,O=t=>String(t?.w||"").replace(/[^\p{L}\p{N}']/gu,"");function ye(t,e,s){const n=e[s+1];if(!n||/[.!?,;:–—-]/.test(t.slice(e[s].end,n.start)))return!1;let r=s+1;return pe.test(O(e[r]))&&e[r+1]&&(r+=1),ge.test(O(e[r]))?!we.test(O(e[r+1])):!1}function ke(t,e,s,n=0){if(n>0&&G.test(String(e[s].w||"").replace(/[^\p{L}\p{N}]/gu,""))||ye(t,e,s+n))return!1;if(s===0)return!0;const r=e[s-1],i=String(r.w||"").replace(/[^\p{L}\p{N}]/gu,"");if(G.test(i))return!1;if(/^(?:ok|okay|hey|hi|yo|hello|so|um|uh)$/i.test(i))return!0;const a=t.slice(r.start,e[s].start);return/[.!?,;:]["'’”)\]]*\s*$/.test(a)?!/[.!?…]/.test(a)||J(t.slice(0,r.end)):!1}function xe(t){return String(t).replace(/(?:[\s,.:;!?-]*\b(?:ok|okay|hey|hi|yo|hello|so|um+|uh+|and|then|now)\b)+[\s,.:;!?-]*$/i,"").trim()}function $(t){return String(t).replace(/^[\s,.:;!?-]+/,"").replace(/^(?:(?:hey|hi|ok|okay|yo)\b[\s,]*)+/i,"").replace(/^(?:(?:can|could|would|will)\s+you\s+(?:please\s+)?|please\s+)/i,"").trim()}const K={zero:0,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12,thirteen:13,fourteen:14,fifteen:15,sixteen:16,seventeen:17,eighteen:18,nineteen:19},H={twenty:20,thirty:30,forty:40,fourty:40,fifty:50,sixty:60,seventy:70,eighty:80,ninety:90},b={half:.5,quarter:.25};function L(t){if(!t.length)return null;let e=null,s=!1;for(let n=0;n<t.length;n++){const r=t[n];if(!(r==="and"||r==="of")){if(r==="a"||r==="an"){e===null&&!(t[n+1]in b)&&(s=!0);continue}if(r in b){e=(e??0)+b[r];continue}if(r in K){e=(e??0)+K[r];continue}if(r in H){e=(e??0)+H[r];continue}if(/^\d+(?:\.\d+)?$/.test(r)){e=(e??0)+Number(r);continue}return null}}return e??(s?1:null)}const V={second:1e3,seconds:1e3,sec:1e3,secs:1e3,s:1e3,minute:6e4,minutes:6e4,min:6e4,mins:6e4,m:6e4,hour:36e5,hours:36e5,hr:36e5,hrs:36e5,h:36e5,day:864e5,days:864e5},be=/^(\d+(?:\.\d+)?)(s|m|h|secs?|mins?|hrs?|seconds?|minutes?|hours?|days?)$/;function q(t){const e=W(t);let s=0,n=-1,r=-1,i=!1,a=[],c=-1;for(let l=0;l<e.length;l++){const o=e[l],d=(f,y,k,m)=>{s+=f*y,n<0&&(n=k),r=m,i=!0},u=be.exec(o.w),h=u?V[u[2]]:V[o.w];if(!h){const f=[...a,o.w];L(f)!==null?(c<0&&(c=o.start),a=f):L([o.w])!==null?(a=[o.w],c=o.start):(a=[],c=-1);continue}if(u)d(Number(u[1]),h,o.start,o.end);else{const f=a.length?L(a):null;f!==null&&d(f,h,c>=0?c:o.start,o.end)}a=[],c=-1;const p=Se(e,l);p>l&&(s+=b[e[p].w]*h,r=e[p].end,l=p)}return!i||s<=0?null:{ms:Math.round(s),start:n,end:r}}function Se(t,e){let s=e+1;return t[s]?.w!=="and"?e:(s++,(t[s]?.w==="a"||t[s]?.w==="an")&&s++,b[t[s]?.w]===void 0?e:s)}const S={sunday:0,sun:0,monday:1,mon:1,tuesday:2,tue:2,tues:2,wednesday:3,wed:3,weds:3,thursday:4,thu:4,thur:4,thurs:4,friday:5,fri:5,saturday:6,sat:6},A=Object.freeze({morning:9,afternoon:14,evening:19,night:20,tonight:19,noon:12,midnight:0});function w(t,{days:e=0,hour:s,minute:n=0}){const r=new Date(t);return r.setDate(r.getDate()+e),r.setHours(s,n,0,0),r.getTime()}function P(t,{now:e=Date.now()}={}){const s=String(t||""),n=I(s);let r=1/0,i=-1;const a=(m,g)=>{m<r&&(r=m),g>i&&(i=g)},c=/\bin\s+(.+)$/i.exec(n);if(c){const m=q(c[1]);if(m){const g=c.index+c[0].length-c[1].length;return{at:e+m.ms,recurrence:null,kind:"relative",...E(n,c.index,g+m.end)}}}const l=/\bevery\s+(day|morning|afternoon|evening|night|week|weekday|[a-z]+day|mon|tue|tues|wed|weds|thu|thur|thurs|fri|sat|sun)\b/i.exec(n)||/\b(daily|nightly|weekly)\b/i.exec(n),o=Ee(n),d=/\b(today|tonight|tomorrow)\b/i.exec(n),u=/\b(next\s+)?(sunday|sun|monday|mon|tuesday|tues|tue|wednesday|weds|wed|thursday|thurs|thur|thu|friday|fri|saturday|sat)\b/i.exec(n),h=/\b(morning|afternoon|evening|tonight|night|noon|midnight)\b/i.exec(n);l&&a(l.index,l.index+l[0].length),o&&a(o.start,o.end),d&&a(d.index,d.index+d[0].length),u&&a(u.index,u.index+u[0].length),h&&a(h.index,h.index+h[0].length);let p=o?o.hour:h?A[h[1]]:null;const f=o?o.minute:0;if(o&&!o.meridiem&&p<12&&h&&A[h[1]]>=12&&(p+=12),l){const m=(l[1]||"").toLowerCase(),g=p??A[m]??A[m.replace(/ly$/,"")]??9,M=m in S?X(e,S[m],g,f):m==="week"||m==="weekly"?w(e,{days:7,hour:g,minute:f}):Ae(e,g,f,m==="weekday"),Z=m in S?{kind:"weekly",weekday:S[m],hour:g,minute:f}:m==="week"||m==="weekly"?{kind:"weekly",weekday:new Date(e).getDay(),hour:g,minute:f}:{kind:"daily",hour:g,minute:f,weekdaysOnly:m==="weekday"};return{at:M,recurrence:Z,kind:"recurring",...E(n,r,i)}}if(p===null&&!d&&!u)return null;if(u){const m=S[u[2]];return{at:X(e,m,p??9,f,!!u[1]),recurrence:null,kind:"weekday",...E(n,r,i)}}const y=p??A[h?.[1]||"morning"];if(d){const m=d[1].toLowerCase();return{at:w(e,{days:m==="tomorrow"?1:0,hour:y,minute:f}),recurrence:null,kind:m,...E(n,r,i)}}let k=w(e,{hour:y,minute:f});return k<=e&&(k=w(e,{days:1,hour:y,minute:f})),{at:k,recurrence:null,kind:"clock",...E(n,r,i)}}function E(t,e,s){if(!(e>=0)||!(s>e))return{start:-1,end:-1};const n=/\b(?:at|on|by|in|this|starting|from)\s+$/i.exec(t.slice(0,e));return{start:n?e-n[0].length:e,end:s}}function Ae(t,e,s,n=!1){let r=w(t,{hour:e,minute:s});if(r<=t&&(r=w(t,{days:1,hour:e,minute:s})),n)for(let i=0;i<7;i++){const a=new Date(r).getDay();if(a!==0&&a!==6)break;r=w(r,{days:1,hour:e,minute:s})}return r}function X(t,e,s,n,r=!1){const i=new Date(t);let a=(e-i.getDay()+7)%7;return a===0&&(r||w(t,{hour:s,minute:n})<=t)&&(a=7),w(t,{days:a,hour:s,minute:n})}function Ee(t){const e=I(t),s=/(\d{1,2})(?:[:.](\d{2}))?\s*(a\.?m\.?|p\.?m\.?|o'?clock)?/gi;let n;for(;n=s.exec(e);){const i=/\bat\s+$/.test(e.slice(0,n.index));if(!n[2]&&!n[3]&&!i)continue;let a=Number(n[1]);const c=n[2]?Number(n[2]):0;if(a>23||c>59)continue;const l=(n[3]||"").replace(/[.\s]/g,"").toLowerCase();return l==="pm"&&a<12&&(a+=12),l==="am"&&a===12&&(a=0),{hour:a,minute:c,meridiem:l==="am"||l==="pm",start:n.index,end:n.index+n[0].length}}const r=/\bat\s+([a-z]+)(?:\s+(a\.?m\.?|p\.?m\.?))?/i.exec(e);if(r){const i=L([r[1]]);if(i!==null&&Number.isInteger(i)&&i>=0&&i<=23){let a=i;const c=(r[2]||"").replace(/[.\s]/g,"").toLowerCase();return c==="pm"&&a<12&&(a+=12),c==="am"&&a===12&&(a=0),{hour:a,minute:0,meridiem:c==="am"||c==="pm",start:r.index,end:r.index+r[0].length}}}return null}function N({id:t,label:e,description:s="",examples:n=[],classUsed:r="R",effects:i="idempotent",requiresApproval:a=!1,match:c}){if(!t)throw new D("BAD_INTENT","intent.id required");if(typeof c!="function")throw new D("BAD_INTENT",`intent '${t}': match required`);return Object.freeze({id:t,label:e||t,description:s,examples:Object.freeze([...n]),classUsed:r,effects:i,requiresApproval:a,match:c})}function Ne(t=[]){const e=[...t];return{add(s){return e.push(s),()=>{const n=e.indexOf(s);n>=0&&e.splice(n,1)}},list:()=>[...e],get:s=>e.find(n=>n.id===s)||null,parse(s,n={}){const r=String(s||"").trim();if(!r)return null;for(const i of e){let a=null;try{a=i.match(r,n)}catch{a=null}if(a)return{intent:i.id,label:i.label,classUsed:i.classUsed,effects:i.effects,requiresApproval:i.requiresApproval,args:a,command:r,needsModel:!1}}return{intent:null,args:null,command:r,needsModel:!0}}}}const _e=N({id:"voice:timer",label:"Set a timer",description:"Starts a countdown and alerts when it finishes.",examples:["set a timer for 10 minutes","start a 90 second timer","timer for an hour and a half"],match:(t,{now:e=Date.now()}={})=>{const s=q(t);if(!s||!/\btimers?\b/i.test(t)&&(!/^(?:set|start|make|create|put)\b/i.test(t.trim())||(t.slice(0,s.start)+" "+t.slice(s.end)).replace(/\b(set|start|make|create|put|a|an|the|for|please|to|of|and|half|quarter|this|that|time|up|on|me)\b/gi," ").replace(/[^\p{L}\p{N}]+/gu,"")))return null;const n=(t.slice(0,s.start)+" "+t.slice(s.end)).replace(/\b(set|start|make|create|a|an|the|for|please|timer|timers|to|of|and|half|quarter)\b/gi," ");return{ms:s.ms,at:e+s.ms,label:_(n)}}}),Te=N({id:"voice:reminder",label:"Set a reminder",description:"Remembers something and raises it at the time you said.",examples:["remind me to send the deck at 4pm","remember to take the kids to school at 9am on Wednesday","remind me every weekday morning to check the queue"],match:(t,{now:e=Date.now()}={})=>{const s=/\b(?:remind\s+(?:me|us)|reminder|remember)\b/i.exec(t);if(!s)return null;const n=P(t,{now:e});let r=n&&n.end>n.start?t.slice(0,n.start)+" "+t.slice(n.end):t;return r=r.slice(r.toLowerCase().indexOf(s[0].toLowerCase())+s[0].length),r=_(r.replace(/^(?:\s*(?:to|that|about|i\s+need\s+to|we\s+need\s+to))\b/i,"")),r?{text:r,at:n?.at??null,recurrence:n?.recurrence??null,when:n?.kind??null}:null}}),Le=N({id:"voice:note",label:"Take a note",description:"Appends a line to the meeting notes.",examples:["note that we agreed to ship on Friday","take a note: budget is approved"],match:t=>{const e=/^(?:(?:take|make|write|jot|add)\s+(?:down\s+)?(?:a\s+|the\s+|some\s+)?notes?|(?:write|jot)\s+down|notes?)\b[\s:,-]*(?:down\s+)?(?:that\s+|of\s+|on\s+|about\s+|from\s+)?(.+)$/i.exec(t.trim()),s=e&&_(e[1]);return s?{text:s}:null}}),ve=N({id:"voice:monitor",label:"Watch for something",description:"Starts a live monitor that answers as the meeting continues.",examples:["watch for whether we agree a date","keep an eye on the pricing question","track who owns the migration"],classUsed:"C",match:t=>{const e=/^(?:(?:start|set\s+up|create|begin|add|open|run)\s+(?:a\s+|the\s+|an\s+)?(?:live\s+|new\s+)?(?:monitor|monitoring|watch|tracker)|watch\s+(?:out\s+)?for|watch|keep\s+an\s+eye\s+on|track|monitor|monitoring)\b[\s:,-]*(?:whether\s+|if\s+|for\s+|on\s+|about\s+|that\s+)?(.+)$/i.exec(t.trim()),s=e&&_(e[1]);return s&&s.length>2?{prompt:s}:null}}),De=N({id:"voice:schedule",label:"Schedule something",description:"Runs one of your skills (or a plain instruction) on a schedule.",examples:["every weekday at 8am run my daily brief","run the standup summary every morning","tomorrow at 9 do the release checklist"],classUsed:"C",match:(t,{now:e=Date.now()}={})=>{if(!/\b(run|do|start|kick\s+off|execute)\b/i.exec(t))return null;const n=P(t,{now:e});if(!n)return null;let r=n.end>n.start?t.slice(0,n.start)+" "+t.slice(n.end):t;const i=/\b(run|do|start|kick\s+off|execute)\b/i.exec(r);return r=_((i?r.slice(i.index+i[0].length):r).replace(/^\s*(?:my|the|our)\b/i,"").replace(/\b(skill|job|task)\b\s*$/i,"")),r?{target:r,at:n.at,recurrence:n.recurrence,when:n.kind}:null}}),Ie=Object.freeze([_e,Te,De,Le,ve]);function _(t){return String(t||"").replace(/\s+/g," ").replace(/^[\s,.:;-]+|[\s,.:;-]+$/g,"").trim()}function Y(){return Ne(Ie)}function Qe(t,{wake:e=x(),intents:s=Y(),now:n=Date.now()}={}){const r=he(t,e);if(!r)return null;const i=s.parse(r.command,{now:n});return i?{...i,wake:r.wake,heard:r.heard,at:r.at,addressed:r.addressed!==!1}:null}const Ce=new Set(["maybe","perhaps","probably","basically","roughly","kinda","sorta"]);function J(t){const e=String(t||"").trim().replace(/[\s.,;:!?…'"’”)\]-]+$/u,"");if(!e)return!1;const s=e.toLowerCase().match(/[\p{L}\p{N}']+/gu)||[],n=s[s.length-1];return n?!ie.has(n)&&!Ce.has(n):!1}const Oe=t=>/[.!?…]["'’”)\]]*\s*$/.test(String(t||"").trim());function $e(t,e,s){const n=z(t,1).trim();if(n&&n!==t){const r=e.parse(n,{now:s});if(r?.intent)return r}return e.parse(t,{now:s})}const Q=t=>String(t||"").toLowerCase().replace(/[^a-z0-9]+/g," ").trim().slice(0,160),v=6,qe=t=>Q(t).split(" ").slice(0,v).join(" "),Me=3;function Ze(t,{wake:e=x(),intents:s=Y(),isSelf:n=null,sinceTs:r=0,now:i=Date.now(),meetingId:a="",max:c=Me,gate:l=null}={}){const o=[];for(const u of t||[])if(!(!u||!u.text)&&!(u.t&&u.t<=r))for(const h of F(u.text,e)){if(!h.command)continue;const p=$e(h.command,s,i),f=p&&{...p,wake:h.wake,heard:h.heard,at:h.at,addressed:h.addressed,rest:h.rest};if(!f||!f.intent&&!f.addressed)continue;const y=J(h.command);if(!f.intent&&!l&&!(y&&Oe(u.text)))continue;const k=n?!!n(u.speaker):!1;o.push({...f,allowed:k,finished:y,speaker:u.speaker||"",t:u.t||i,meetingId:a,key:`voice:${a}:${f.intent||"ask"}:${f.ms??f.when??""}:${qe(h.command)}`})}const d=o.length>c?o.slice(-c):o;return l?l.offer(d,i).due(i):d}const Re=5e3,Ue=12e3,je=3*6e4,We=24;function ze(t,e){if(!t||!e)return!1;if(t===e||t.startsWith(e)||e.startsWith(t))return!0;const s=t.split(" ").slice(0,v),n=e.split(" ").slice(0,v);return s.length>=v&&s.join(" ")===n.join(" ")}function et({settleMs:t=Re,danglingMs:e=Ue,forgetMs:s=je,max:n=We}={}){let r=[];const i=c=>c.command.finished===!1?e:t,a=(c,l)=>r.find(o=>o.meetingId===(c.meetingId||"")&&ze(o.gist,l));return{offer(c,l=Date.now()){for(const o of c||[]){const d=Q(o.command);if(!d)continue;const u=a(o,d);if(!u){r.push({meetingId:o.meetingId||"",gist:d,command:o,changedAt:l,seenAt:l,done:!1});continue}u.seenAt=l,!u.done&&d!==u.gist&&(u.gist=d,u.command=o,u.changedAt=l)}return r=r.filter(o=>l-o.seenAt<=s),r.length>n&&(r=r.slice(-n)),this},due(c=Date.now()){const l=[];for(const o of r)o.done||c-o.changedAt<i(o)||(o.done=!0,l.push(o.command));return l},nextDueIn(c=Date.now()){let l=null;for(const o of r){if(o.done)continue;const d=Math.max(0,i(o)-(c-o.changedAt));(l===null||d<l)&&(l=d)}return l},get waiting(){return r.filter(c=>!c.done).length}}}export{ae as ASSISTANT_NAME,Ie as BUILTIN_VOICE_INTENTS,A as DAYPART_HOUR,oe as DEFAULT_WAKE,Me as MAX_COMMANDS_PER_DELTA,ue as MAX_COMMAND_SENTENCES,v as OPENING_WORDS,T as REFINEMENT_SCHEMA,Ue as UTTERANCE_DANGLING_MS,Re as UTTERANCE_SETTLE_MS,D as VoiceIntentError,J as commandLooksFinished,Ze as commandsFromSegments,x as compileWake,et as createUtteranceGate,Ne as createVoiceIntentRegistry,Y as defaultVoiceIntents,N as defineVoiceIntent,R as editDistance,he as findWakeCommand,F as findWakeCommands,qe as gistOpening,Q as gistText,me as isFillerSentence,ve as monitorIntent,I as normalizeSpeech,Le as noteIntent,Ee as parseClock,Qe as parseCommand,q as parseDuration,L as parseNumberWords,Xe as parseRefinement,P as parseWhen,He as refineSpokenCommand,Pe as refinementFormat,Ve as refinementPrompt,Je as refinementStream,Te as reminderIntent,ze as sameUtterance,De as scheduleIntent,C as settleRefinement,Ye as spokenNamesHost,_e as timerIntent,W as tokenize,Ke as wakeFor};
1
+ import{defineSchema as ee,describeSchema as te,responseFormat as ne,coerce as re,createStructuredStream as se}from"./structured.js";import{DANGLING_TAILS as ie}from"./schedule.js";import{editDistance as R}from"./distance.js";class D extends Error{constructor(e,s){super(s),this.name="VoiceIntentError",this.code=e}}const oe=Object.freeze(["chatpanel"]),ae="Chap",le=Object.freeze(["Chapel"]),ce=Object.freeze(["Chad","Chop"]);function U(t){return t<=4?0:t<=6?1:2}const j=3,ue=8;function I(t){return String(t||"").toLowerCase().replace(/[‘’]/g,"'").replace(/[^\p{L}\p{N}':.\s]/gu," ")}function z(t){const e=I(t),s=[],n=/[\p{L}\p{N}'.:]+/gu;let r;for(;r=n.exec(e);){const i=r[0].replace(/^[.:]+|[.:]+$/g,"");i&&s.push({w:i,start:r.index,end:r.index+r[0].length})}return s}function x(t=oe,{exact:e=[]}={}){const s=(Array.isArray(t)?t:String(t??"").split(/[,|;\n]/)).map(o=>String(o??"").trim()).filter(Boolean),n=[],r=[],i=o=>String(o??"").toLowerCase().replace(/[^\p{L}\p{N}]/gu,""),a=new Set((Array.isArray(e)?e:[e]).map(i)),c=[];let l=1;for(const o of s){const d=i(o);d.length<3||n.includes(d)||(n.push(d),r.push(o),c.push(a.has(d)?0:U(d.length)),l=Math.max(l,o.split(/\s+/).filter(Boolean).length+1))}if(!n.length)throw new D("BAD_WAKE","wake word must have at least 3 letters");return Object.freeze({phrases:Object.freeze(n),labels:Object.freeze(r),slacks:Object.freeze(c),maxTokens:Math.min(Math.max(l,j),ue)})}function He({words:t="",name:e="",bare:s=!0}={}){const n=(Array.isArray(t)?t:String(t||"").split(/[,|;\n]/)).map(h=>String(h).trim()).filter(Boolean),r=String(e||"").trim(),i=r.replace(/[^\p{L}\p{N}]/gu,"").length,a=i>=3?s?[`hey ${r}`,r]:[`hey ${r}`]:[],c=r.toLowerCase()===ae.toLowerCase(),l=c?le.map(h=>`hey ${h}`):[],o=c&&s?ce.map(h=>`hey ${h}`):[],d=[...a,...o,...l,...n],u=i>=3&&i<=4?[...a,...o]:[];return d.length?x(d,{exact:u}):x()}const de=2;function he(t,e,s){const n=[],r=s.maxTokens||j;for(let i=0;i<e.length;i++){let a="",c=!1;for(let l=0;l<r&&i+l<e.length&&!c;l++){a+=e[i+l].w.replace(/[^\p{L}\p{N}]/gu,"");for(let o=0;o<s.phrases.length;o++){const d=s.phrases[o],u=s.slacks?.[o]??U(d.length);if(!(Math.abs(a.length-d.length)>u)&&R(a,d,u)<=u){n.push({phrase:d,start:e[i].start,end:e[i+l].end,addressed:xe(t,e,i,l)}),i+=l,c=!0;break}}}}return n}function W(t,e){const s=String(t||"");if(!s)return s;const n=/[.!?…]+["'\u2019\u201d)\]]*(?=\s|$)/g;let r=0,i;for(;r<e&&(i=n.exec(s));)if(r+=1,r===e)return s.slice(0,i.index+i[0].length);return s}function F(t,e=x(),{maxSentences:s=de}={}){const n=String(t||""),r=z(n);if(!r.length)return[];const i=he(n,r,e),a=[];let c=0;for(let l=0;l<i.length;l++){const o=i[l];if(!o.addressed&&o.start<c)continue;let d=n.length;for(let p=l+1;p<i.length;p++)if(i[p].addressed){d=i[p].start;break}const u=n.slice(o.end,d),h=be($(W(u,s)).trim());c=Math.max(c,o.end+u.indexOf(h)+h.length),a.push({command:h,wake:o.phrase,heard:n.slice(o.start,o.end),at:o.start,addressed:o.addressed,rest:n.slice(o.end+u.indexOf(h)+h.length,d).trim()})}return a}function fe(t,e=x(),s={}){return F(t,e,s)[0]||null}const B=new RegExp("^(?:ok(?:ay)?|all ?right|right|so|well|um+|uh+|hmm+|yeah|yep|hey|and|but|then|now|let(?:'s| us) see|we(?:'ll| will) see|so we(?:'ll| will) see|i think it is doing something|it does anything|does it (?:do )?anything|hold on(?: a second)?|one second|let me see|i think|i guess|here we go|there we go|test(?:ing)?)[\\s,.!?]*$","i"),me=/(?<=[.!?])\s+/;function pe(t){const e=String(t||"").trim().replace(/^[\s,.:;!?-]+/,"");if(!e||B.test(e))return!0;const s=e.split(",").map(n=>n.trim()).filter(Boolean);return s.length>1&&s.every(n=>B.test(n))}function Ve(t,{maxName:e=48}={}){const s=$(String(t||"")).trim();if(!s)return{request:"",name:""};const r=s.split(me).map(u=>u.trim()).filter(Boolean).filter(u=>!pe(u)),i=r.filter(u=>/\?\s*$/.test(u)),a=i.length>1,c=i.length===1?i[0]:r.length?r.join(" "):s,l=$(c).trim()||s,o=l.replace(/\s+/g," ").trim(),d=o.length>e?`${o.slice(0,e-1).replace(/\s+\S*$/,"")}…`:o;return{request:l,name:d||o,ambiguous:a}}const T=ee({name:"voice_refinement",fields:{request:{type:"string",required:!0,max:400,describe:"the one thing they actually want done, in their own words, one sentence"},name:{type:"string",max:48,describe:"a label of at most 6 words"},kind:{type:"enum",values:["question","action","monitor","note","skill","timer","none"],default:"question",describe:"the SMALLEST kind that does what they asked"},skill:{type:"string",max:80,describe:"the skill name, only when kind is skill"}},nothing:{request:"",name:"",kind:"none",skill:""}});function Pe(t){return["A person spoke to their assistant during a meeting. Below is everything they said after","the wake word, transcribed live — so it contains false starts, thinking aloud, and","sometimes several questions where only one is the request.","",te(T),"","Pick the SMALLEST kind that does what they asked:"," question — answer it once, now. The DEFAULT for anything they want to know.",' action — DO something in the browser or an app ("go to google.com and search for X").',' monitor — only if they asked to be told as the meeting CONTINUES ("let me know if",',' "keep an eye on"). A one-off question is NOT a monitor.',' note — they asked for notes written down ("take notes on", "write that up").',' skill — they named a saved skill ("use the summarize skill"); put its name in `skill`.',' timer — alerted after an AMOUNT OF TIME ("set a one minute"); keep it in `request`.'," none — not asking for anything: thinking aloud, or talking ABOUT the assistant.",'Never invent a request that is not there — return "none". Keep `request` close to their',"words; do not answer it.","","WHAT THEY SAID:",String(t||"")].join(`
2
+ `)}function Xe(t="schema"){return ne(T,{mode:t})}function Ye(t){const e=re(t,T);return e?C(e.value):null}function C(t){if(!t)return null;const e=String(t.request||"").trim();if(t.kind==="none"||!e)return{request:"",name:"",kind:"none",skill:""};let s=t.kind==="skill"&&!t.skill?"question":t.kind;const n=String(t.name||"").trim()||e;if(s==="timer"){const r=q(e);return r?{request:e,name:n,kind:"timer",skill:"",ms:r.ms}:{request:e,name:n,kind:"question",skill:""}}return{request:e,name:n,kind:s,skill:t.skill||""}}function Je(t,e){const s=String(e||"").toLowerCase();if(!s)return!1;let n;try{n=new URL(t).hostname.toLowerCase().replace(/^www\./,"")}catch{return!1}if(!n)return!1;if(s.includes(n))return!0;const r=n.split(".");return r.length!==2?!1:new RegExp(`\\b${r[0].replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`).test(s)}function Qe({onChange:t=null}={}){const e=se(T,{onChange:t?(n,r)=>t(C(n),r):null}),s=n=>({...n,value:C(n.value)});return{push:n=>s(e.push(n)),end:()=>s(e.end()),snapshot:()=>s(e.snapshot()),reset:()=>e.reset(),get text(){return e.text}}}const G=/^(?:the|a|an|our|your|their|my|this|that|these|those|about|on|in|of|with|via|using|called|named|to)$/i,ge=/^(?:actually|really|also|always|never|just|only|still|often|usually|basically|literally|probably|certainly|definitely|now|then|even|apparently|obviously)$/i,we=/^(?:is|isn't|was|wasn't|are|aren't|were|weren't|has|hasn't|have|had|does|doesn't|did|didn't|can|can't|cannot|could|couldn't|will|won't|would|wouldn't|should|shouldn't|shall|may|might|must|seems|helps|lets|gives|allows|works|looks|means|needs|wants|keeps|makes|shows|tells|comes|goes|takes|runs|becomes|provides|supports)$/i,ye=/^(?:you|we|i|they|it|there|he|she)$/i,O=t=>String(t?.w||"").replace(/[^\p{L}\p{N}']/gu,"");function ke(t,e,s){const n=e[s+1];if(!n||/[.!?,;:–—-]/.test(t.slice(e[s].end,n.start)))return!1;let r=s+1;return ge.test(O(e[r]))&&e[r+1]&&(r+=1),we.test(O(e[r]))?!ye.test(O(e[r+1])):!1}function xe(t,e,s,n=0){if(n>0&&G.test(String(e[s].w||"").replace(/[^\p{L}\p{N}]/gu,""))||ke(t,e,s+n))return!1;if(s===0)return!0;const r=e[s-1],i=String(r.w||"").replace(/[^\p{L}\p{N}]/gu,"");if(G.test(i))return!1;if(/^(?:ok|okay|hey|hi|yo|hello|so|um|uh)$/i.test(i))return!0;const a=t.slice(r.start,e[s].start);return/[.!?,;:]["'’”)\]]*\s*$/.test(a)?!/[.!?…]/.test(a)||J(t.slice(0,r.end)):!1}function be(t){return String(t).replace(/(?:[\s,.:;!?-]*\b(?:ok|okay|hey|hi|yo|hello|so|um+|uh+|and|then|now)\b)+[\s,.:;!?-]*$/i,"").trim()}function $(t){return String(t).replace(/^[\s,.:;!?-]+/,"").replace(/^(?:(?:hey|hi|ok|okay|yo)\b[\s,]*)+/i,"").replace(/^(?:(?:can|could|would|will)\s+you\s+(?:please\s+)?|please\s+)/i,"").trim()}const K={zero:0,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10,eleven:11,twelve:12,thirteen:13,fourteen:14,fifteen:15,sixteen:16,seventeen:17,eighteen:18,nineteen:19},H={twenty:20,thirty:30,forty:40,fourty:40,fifty:50,sixty:60,seventy:70,eighty:80,ninety:90},b={half:.5,quarter:.25};function L(t){if(!t.length)return null;let e=null,s=!1;for(let n=0;n<t.length;n++){const r=t[n];if(!(r==="and"||r==="of")){if(r==="a"||r==="an"){e===null&&!(t[n+1]in b)&&(s=!0);continue}if(r in b){e=(e??0)+b[r];continue}if(r in K){e=(e??0)+K[r];continue}if(r in H){e=(e??0)+H[r];continue}if(/^\d+(?:\.\d+)?$/.test(r)){e=(e??0)+Number(r);continue}return null}}return e??(s?1:null)}const V={second:1e3,seconds:1e3,sec:1e3,secs:1e3,s:1e3,minute:6e4,minutes:6e4,min:6e4,mins:6e4,m:6e4,hour:36e5,hours:36e5,hr:36e5,hrs:36e5,h:36e5,day:864e5,days:864e5},Se=/^(\d+(?:\.\d+)?)(s|m|h|secs?|mins?|hrs?|seconds?|minutes?|hours?|days?)$/;function q(t){const e=z(t);let s=0,n=-1,r=-1,i=!1,a=[],c=-1;for(let l=0;l<e.length;l++){const o=e[l],d=(f,y,k,m)=>{s+=f*y,n<0&&(n=k),r=m,i=!0},u=Se.exec(o.w),h=u?V[u[2]]:V[o.w];if(!h){const f=[...a,o.w];L(f)!==null?(c<0&&(c=o.start),a=f):L([o.w])!==null?(a=[o.w],c=o.start):(a=[],c=-1);continue}if(u)d(Number(u[1]),h,o.start,o.end);else{const f=a.length?L(a):null;f!==null&&d(f,h,c>=0?c:o.start,o.end)}a=[],c=-1;const p=Ae(e,l);p>l&&(s+=b[e[p].w]*h,r=e[p].end,l=p)}return!i||s<=0?null:{ms:Math.round(s),start:n,end:r}}function Ae(t,e){let s=e+1;return t[s]?.w!=="and"?e:(s++,(t[s]?.w==="a"||t[s]?.w==="an")&&s++,b[t[s]?.w]===void 0?e:s)}const S={sunday:0,sun:0,monday:1,mon:1,tuesday:2,tue:2,tues:2,wednesday:3,wed:3,weds:3,thursday:4,thu:4,thur:4,thurs:4,friday:5,fri:5,saturday:6,sat:6},A=Object.freeze({morning:9,afternoon:14,evening:19,night:20,tonight:19,noon:12,midnight:0});function w(t,{days:e=0,hour:s,minute:n=0}){const r=new Date(t);return r.setDate(r.getDate()+e),r.setHours(s,n,0,0),r.getTime()}function P(t,{now:e=Date.now()}={}){const s=String(t||""),n=I(s);let r=1/0,i=-1;const a=(m,g)=>{m<r&&(r=m),g>i&&(i=g)},c=/\bin\s+(.+)$/i.exec(n);if(c){const m=q(c[1]);if(m){const g=c.index+c[0].length-c[1].length;return{at:e+m.ms,recurrence:null,kind:"relative",...E(n,c.index,g+m.end)}}}const l=/\bevery\s+(day|morning|afternoon|evening|night|week|weekday|[a-z]+day|mon|tue|tues|wed|weds|thu|thur|thurs|fri|sat|sun)\b/i.exec(n)||/\b(daily|nightly|weekly)\b/i.exec(n),o=Ne(n),d=/\b(today|tonight|tomorrow)\b/i.exec(n),u=/\b(next\s+)?(sunday|sun|monday|mon|tuesday|tues|tue|wednesday|weds|wed|thursday|thurs|thur|thu|friday|fri|saturday|sat)\b/i.exec(n),h=/\b(morning|afternoon|evening|tonight|night|noon|midnight)\b/i.exec(n);l&&a(l.index,l.index+l[0].length),o&&a(o.start,o.end),d&&a(d.index,d.index+d[0].length),u&&a(u.index,u.index+u[0].length),h&&a(h.index,h.index+h[0].length);let p=o?o.hour:h?A[h[1]]:null;const f=o?o.minute:0;if(o&&!o.meridiem&&p<12&&h&&A[h[1]]>=12&&(p+=12),l){const m=(l[1]||"").toLowerCase(),g=p??A[m]??A[m.replace(/ly$/,"")]??9,M=m in S?X(e,S[m],g,f):m==="week"||m==="weekly"?w(e,{days:7,hour:g,minute:f}):Ee(e,g,f,m==="weekday"),Z=m in S?{kind:"weekly",weekday:S[m],hour:g,minute:f}:m==="week"||m==="weekly"?{kind:"weekly",weekday:new Date(e).getDay(),hour:g,minute:f}:{kind:"daily",hour:g,minute:f,weekdaysOnly:m==="weekday"};return{at:M,recurrence:Z,kind:"recurring",...E(n,r,i)}}if(p===null&&!d&&!u)return null;if(u){const m=S[u[2]];return{at:X(e,m,p??9,f,!!u[1]),recurrence:null,kind:"weekday",...E(n,r,i)}}const y=p??A[h?.[1]||"morning"];if(d){const m=d[1].toLowerCase();return{at:w(e,{days:m==="tomorrow"?1:0,hour:y,minute:f}),recurrence:null,kind:m,...E(n,r,i)}}let k=w(e,{hour:y,minute:f});return k<=e&&(k=w(e,{days:1,hour:y,minute:f})),{at:k,recurrence:null,kind:"clock",...E(n,r,i)}}function E(t,e,s){if(!(e>=0)||!(s>e))return{start:-1,end:-1};const n=/\b(?:at|on|by|in|this|starting|from)\s+$/i.exec(t.slice(0,e));return{start:n?e-n[0].length:e,end:s}}function Ee(t,e,s,n=!1){let r=w(t,{hour:e,minute:s});if(r<=t&&(r=w(t,{days:1,hour:e,minute:s})),n)for(let i=0;i<7;i++){const a=new Date(r).getDay();if(a!==0&&a!==6)break;r=w(r,{days:1,hour:e,minute:s})}return r}function X(t,e,s,n,r=!1){const i=new Date(t);let a=(e-i.getDay()+7)%7;return a===0&&(r||w(t,{hour:s,minute:n})<=t)&&(a=7),w(t,{days:a,hour:s,minute:n})}function Ne(t){const e=I(t),s=/(\d{1,2})(?:[:.](\d{2}))?\s*(a\.?m\.?|p\.?m\.?|o'?clock)?/gi;let n;for(;n=s.exec(e);){const i=/\bat\s+$/.test(e.slice(0,n.index));if(!n[2]&&!n[3]&&!i)continue;let a=Number(n[1]);const c=n[2]?Number(n[2]):0;if(a>23||c>59)continue;const l=(n[3]||"").replace(/[.\s]/g,"").toLowerCase();return l==="pm"&&a<12&&(a+=12),l==="am"&&a===12&&(a=0),{hour:a,minute:c,meridiem:l==="am"||l==="pm",start:n.index,end:n.index+n[0].length}}const r=/\bat\s+([a-z]+)(?:\s+(a\.?m\.?|p\.?m\.?))?/i.exec(e);if(r){const i=L([r[1]]);if(i!==null&&Number.isInteger(i)&&i>=0&&i<=23){let a=i;const c=(r[2]||"").replace(/[.\s]/g,"").toLowerCase();return c==="pm"&&a<12&&(a+=12),c==="am"&&a===12&&(a=0),{hour:a,minute:0,meridiem:c==="am"||c==="pm",start:r.index,end:r.index+r[0].length}}}return null}function N({id:t,label:e,description:s="",examples:n=[],classUsed:r="R",effects:i="idempotent",requiresApproval:a=!1,match:c}){if(!t)throw new D("BAD_INTENT","intent.id required");if(typeof c!="function")throw new D("BAD_INTENT",`intent '${t}': match required`);return Object.freeze({id:t,label:e||t,description:s,examples:Object.freeze([...n]),classUsed:r,effects:i,requiresApproval:a,match:c})}function _e(t=[]){const e=[...t];return{add(s){return e.push(s),()=>{const n=e.indexOf(s);n>=0&&e.splice(n,1)}},list:()=>[...e],get:s=>e.find(n=>n.id===s)||null,parse(s,n={}){const r=String(s||"").trim();if(!r)return null;for(const i of e){let a=null;try{a=i.match(r,n)}catch{a=null}if(a)return{intent:i.id,label:i.label,classUsed:i.classUsed,effects:i.effects,requiresApproval:i.requiresApproval,args:a,command:r,needsModel:!1}}return{intent:null,args:null,command:r,needsModel:!0}}}}const Te=N({id:"voice:timer",label:"Set a timer",description:"Starts a countdown and alerts when it finishes.",examples:["set a timer for 10 minutes","start a 90 second timer","timer for an hour and a half"],match:(t,{now:e=Date.now()}={})=>{const s=q(t);if(!s||!/\btimers?\b/i.test(t)&&(!/^(?:set|start|make|create|put)\b/i.test(t.trim())||(t.slice(0,s.start)+" "+t.slice(s.end)).replace(/\b(set|start|make|create|put|a|an|the|for|please|to|of|and|half|quarter|this|that|time|up|on|me)\b/gi," ").replace(/[^\p{L}\p{N}]+/gu,"")))return null;const n=(t.slice(0,s.start)+" "+t.slice(s.end)).replace(/\b(set|start|make|create|a|an|the|for|please|timer|timers|to|of|and|half|quarter)\b/gi," ");return{ms:s.ms,at:e+s.ms,label:_(n)}}}),Le=N({id:"voice:reminder",label:"Set a reminder",description:"Remembers something and raises it at the time you said.",examples:["remind me to send the deck at 4pm","remember to take the kids to school at 9am on Wednesday","remind me every weekday morning to check the queue"],match:(t,{now:e=Date.now()}={})=>{const s=/\b(?:remind\s+(?:me|us)|reminder|remember)\b/i.exec(t);if(!s)return null;const n=P(t,{now:e});let r=n&&n.end>n.start?t.slice(0,n.start)+" "+t.slice(n.end):t;return r=r.slice(r.toLowerCase().indexOf(s[0].toLowerCase())+s[0].length),r=_(r.replace(/^(?:\s*(?:to|that|about|i\s+need\s+to|we\s+need\s+to))\b/i,"")),r?{text:r,at:n?.at??null,recurrence:n?.recurrence??null,when:n?.kind??null}:null}}),ve=N({id:"voice:note",label:"Take a note",description:"Appends a line to the meeting notes.",examples:["note that we agreed to ship on Friday","take a note: budget is approved"],match:t=>{const e=/^(?:(?:take|make|write|jot|add)\s+(?:down\s+)?(?:a\s+|the\s+|some\s+)?notes?|(?:write|jot)\s+down|notes?)\b[\s:,-]*(?:down\s+)?(?:that\s+|of\s+|on\s+|about\s+|from\s+)?(.+)$/i.exec(t.trim()),s=e&&_(e[1]);return s?{text:s}:null}}),De=N({id:"voice:monitor",label:"Watch for something",description:"Starts a live monitor that answers as the meeting continues.",examples:["watch for whether we agree a date","keep an eye on the pricing question","track who owns the migration"],classUsed:"C",match:t=>{const e=/^(?:(?:start|set\s+up|create|begin|add|open|run)\s+(?:a\s+|the\s+|an\s+)?(?:live\s+|new\s+)?(?:monitor|monitoring|watch|tracker)|watch\s+(?:out\s+)?for|watch|keep\s+an\s+eye\s+on|track|monitor|monitoring)\b[\s:,-]*(?:whether\s+|if\s+|for\s+|on\s+|about\s+|that\s+)?(.+)$/i.exec(t.trim()),s=e&&_(e[1]);return s&&s.length>2?{prompt:s}:null}}),Ie=N({id:"voice:schedule",label:"Schedule something",description:"Runs one of your skills (or a plain instruction) on a schedule.",examples:["every weekday at 8am run my daily brief","run the standup summary every morning","tomorrow at 9 do the release checklist"],classUsed:"C",match:(t,{now:e=Date.now()}={})=>{if(!/\b(run|do|start|kick\s+off|execute)\b/i.exec(t))return null;const n=P(t,{now:e});if(!n)return null;let r=n.end>n.start?t.slice(0,n.start)+" "+t.slice(n.end):t;const i=/\b(run|do|start|kick\s+off|execute)\b/i.exec(r);return r=_((i?r.slice(i.index+i[0].length):r).replace(/^\s*(?:my|the|our)\b/i,"").replace(/\b(skill|job|task)\b\s*$/i,"")),r?{target:r,at:n.at,recurrence:n.recurrence,when:n.kind}:null}}),Ce=Object.freeze([Te,Le,Ie,ve,De]);function _(t){return String(t||"").replace(/\s+/g," ").replace(/^[\s,.:;-]+|[\s,.:;-]+$/g,"").trim()}function Y(){return _e(Ce)}function Ze(t,{wake:e=x(),intents:s=Y(),now:n=Date.now()}={}){const r=fe(t,e);if(!r)return null;const i=s.parse(r.command,{now:n});return i?{...i,wake:r.wake,heard:r.heard,at:r.at,addressed:r.addressed!==!1}:null}const Oe=new Set(["maybe","perhaps","probably","basically","roughly","kinda","sorta"]);function J(t){const e=String(t||"").trim().replace(/[\s.,;:!?…'"’”)\]-]+$/u,"");if(!e)return!1;const s=e.toLowerCase().match(/[\p{L}\p{N}']+/gu)||[],n=s[s.length-1];return n?!ie.has(n)&&!Oe.has(n):!1}const $e=t=>/[.!?…]["'’”)\]]*\s*$/.test(String(t||"").trim());function qe(t,e,s){const n=W(t,1).trim();if(n&&n!==t){const r=e.parse(n,{now:s});if(r?.intent)return r}return e.parse(t,{now:s})}const Q=t=>String(t||"").toLowerCase().replace(/[^a-z0-9]+/g," ").trim().slice(0,160),v=6,Me=t=>Q(t).split(" ").slice(0,v).join(" "),Re=3;function et(t,{wake:e=x(),intents:s=Y(),isSelf:n=null,sinceTs:r=0,now:i=Date.now(),meetingId:a="",max:c=Re,gate:l=null}={}){const o=[];for(const u of t||[])if(!(!u||!u.text)&&!(u.t&&u.t<=r))for(const h of F(u.text,e)){if(!h.command)continue;const p=qe(h.command,s,i),f=p&&{...p,wake:h.wake,heard:h.heard,at:h.at,addressed:h.addressed,rest:h.rest};if(!f||!f.intent&&!f.addressed)continue;const y=J(h.command);if(!f.intent&&!l&&!(y&&$e(u.text)))continue;const k=n?!!n(u.speaker):!1;o.push({...f,allowed:k,finished:y,speaker:u.speaker||"",t:u.t||i,meetingId:a,key:`voice:${a}:${f.intent||"ask"}:${f.ms??f.when??""}:${Me(h.command)}`})}const d=o.length>c?o.slice(-c):o;return l?l.offer(d,i).due(i):d}const Ue=5e3,je=12e3,ze=3*6e4,We=24;function Fe(t,e){if(!t||!e)return!1;if(t===e||t.startsWith(e)||e.startsWith(t))return!0;const s=t.split(" ").slice(0,v),n=e.split(" ").slice(0,v);return s.length>=v&&s.join(" ")===n.join(" ")}function tt({settleMs:t=Ue,danglingMs:e=je,forgetMs:s=ze,max:n=We}={}){let r=[];const i=c=>c.command.finished===!1?e:t,a=(c,l)=>r.find(o=>o.meetingId===(c.meetingId||"")&&Fe(o.gist,l));return{offer(c,l=Date.now()){for(const o of c||[]){const d=Q(o.command);if(!d)continue;const u=a(o,d);if(!u){r.push({meetingId:o.meetingId||"",gist:d,command:o,changedAt:l,seenAt:l,done:!1});continue}u.seenAt=l,!u.done&&d!==u.gist&&(u.gist=d,u.command=o,u.changedAt=l)}return r=r.filter(o=>l-o.seenAt<=s),r.length>n&&(r=r.slice(-n)),this},due(c=Date.now()){const l=[];for(const o of r)o.done||c-o.changedAt<i(o)||(o.done=!0,l.push(o.command));return l},nextDueIn(c=Date.now()){let l=null;for(const o of r){if(o.done)continue;const d=Math.max(0,i(o)-(c-o.changedAt));(l===null||d<l)&&(l=d)}return l},get waiting(){return r.filter(c=>!c.done).length}}}export{ae as ASSISTANT_NAME,ce as ASSISTANT_SOUND_ALIKES,Ce as BUILTIN_VOICE_INTENTS,A as DAYPART_HOUR,oe as DEFAULT_WAKE,Re as MAX_COMMANDS_PER_DELTA,de as MAX_COMMAND_SENTENCES,v as OPENING_WORDS,T as REFINEMENT_SCHEMA,je as UTTERANCE_DANGLING_MS,Ue as UTTERANCE_SETTLE_MS,D as VoiceIntentError,J as commandLooksFinished,et as commandsFromSegments,x as compileWake,tt as createUtteranceGate,_e as createVoiceIntentRegistry,Y as defaultVoiceIntents,N as defineVoiceIntent,R as editDistance,fe as findWakeCommand,F as findWakeCommands,Me as gistOpening,Q as gistText,pe as isFillerSentence,De as monitorIntent,I as normalizeSpeech,ve as noteIntent,Ne as parseClock,Ze as parseCommand,q as parseDuration,L as parseNumberWords,Ye as parseRefinement,P as parseWhen,Ve as refineSpokenCommand,Xe as refinementFormat,Pe as refinementPrompt,Qe as refinementStream,Le as reminderIntent,Fe as sameUtterance,Ie as scheduleIntent,C as settleRefinement,Je as spokenNamesHost,Te as timerIntent,z as tokenize,He as wakeFor};