@chatpanel/events 0.464.0 → 0.466.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/contexts.js ADDED
@@ -0,0 +1 @@
1
+ import{makeRecordId as I,parseRecordId as _}from"./library.js";const X=80,M=600,L=16,k=5e3,A=Object.freeze(["blue","orange","green","purple","pink","teal","gray"]),R=Object.freeze(["chat","note","meeting","brief"]),i=t=>Number.isFinite(Number(t))?Number(t):0,h=t=>t&&!i(t.deletedAt),B=t=>R.includes(_(t)?.kind);function b(t,e){const o=String(t??"").replace(/[\u0000-\u001f\u007f]+/g," ").replace(/\s+/g," ").trim();return o.length>e?o.slice(0,e).trimEnd():o}const S=t=>b(t,X);function C(t){const e=[];for(const o of Array.isArray(t)?t:String(t||"").split(",")){const r=b(o,40).toLowerCase();if(r&&!e.includes(r)&&e.push(r),e.length>=L)break}return e}function K({name:t,color:e=null,about:o="",keywords:r=[],newId:s,now:c=0}={}){if(typeof s!="function")throw new Error("makeContext needs newId()");const n=S(t);if(!n)throw new Error("a context needs a name");return{id:I("context",s()),kind:"context",title:n,createdAt:i(c),updatedAt:i(c),body:{color:A.includes(e)?e:A[0],about:b(o,M),keywords:C(r),members:{}}}}function D(t,{name:e,color:o,about:r,keywords:s}={},{now:c=0}={}){const n={...t?.body||{}};let d=t?.title||"";if(e!==void 0){const f=S(e);f&&(d=f)}return o!==void 0&&A.includes(o)&&(n.color=o),r!==void 0&&(n.about=b(r,M)),s!==void 0&&(n.keywords=C(s)),{...t,title:d,body:n,updatedAt:Math.max(i(c),i(t?.updatedAt))}}function O(t,e,o,r){const s={...t?.body?.members||{}};for(const n of Array.isArray(e)?e:[e]){if(!B(n))continue;const d=s[n];d&&i(d.at)>i(r)||(s[n]={on:!!o,at:i(r)})}const c=Object.keys(s);if(c.length>k){const n=c.filter(d=>!s[d].on).sort((d,f)=>s[d].at-s[f].at);for(const d of n.slice(0,c.length-k))delete s[d]}return{...t,body:{...t?.body||{},members:s},updatedAt:Math.max(i(r),i(t?.updatedAt))}}const F=(t,e,{now:o=0}={})=>O(t,e,!0,o),H=(t,e,{now:o=0}={})=>O(t,e,!1,o);function T(t){const e=t?.body?.members||{};return Object.keys(e).filter(o=>e[o]?.on).sort((o,r)=>i(e[r].at)-i(e[o].at))}function W(t,e){if(!t)return e;if(!e)return t;const o=i(e.updatedAt)>i(t.updatedAt)?e:t,r={...t.body?.members||{}};for(const[c,n]of Object.entries(e.body?.members||{}))(!r[c]||i(n?.at)>i(r[c].at))&&(r[c]={on:!!n?.on,at:i(n?.at)});const s=Math.max(i(t.deletedAt),i(e.deletedAt))||void 0;return{...o,body:{...o.body||{},members:r},updatedAt:Math.max(i(t.updatedAt),i(e.updatedAt)),...s?{deletedAt:s}:{}}}function q(t,e=[]){return e.filter(o=>h(o)&&o.body?.members?.[t]?.on)}function E(t=[],e=[]){const o=new Map(e.filter(h).map(r=>[r.id,r]));return t.filter(h).map(r=>{const s=T(r).map(n=>o.get(n)).filter(Boolean).sort((n,d)=>i(d.updatedAt)-i(n.updatedAt)),c={chat:0,note:0,meeting:0,brief:0};for(const n of s)c[n.kind]=(c[n.kind]||0)+1;return{context:r,counts:c,items:s,last:s.length?i(s[0].updatedAt):i(r.updatedAt)}}).sort((r,s)=>s.last-r.last)}function P(t=[],e=[]){const o=t.filter(h),r=new Set(o.map(d=>d.id)),s=[],c=new Set;for(const{context:d,items:f}of E(e,o)){const a=f.filter(l=>r.has(l.id));if(a.length){for(const l of a)c.add(l.id);s.push({context:d,items:a})}}const n=o.filter(d=>!c.has(d.id));return n.length&&s.push({context:null,items:n}),s}const v=new Set(["the","and","for","with","that","this","from","about","what","when","how","are","was","you","your","our","into","have","has","not","but","can","will","just","new","chat","note","notes","meeting"]),g=t=>String(t||"").toLowerCase().match(/[\p{L}\p{N}][\p{L}\p{N}'-]{2,}/gu)?.filter(e=>!v.has(e))||[];function U({title:t="",text:e="",contexts:o=[],records:r=[],limit:s=3,min:c=.2}={}){const n=new Set(g(`${t} ${String(e).slice(0,4e3)}`));if(!n.size)return[];const d=new Map(r.filter(h).map(a=>[a.id,a])),f=[];for(const a of o.filter(h)){const l=g(a.title),N=(a.body?.keywords||[]).flatMap(u=>g(u)),$=T(a).slice(0,60).map(u=>d.get(u)?.title||"").flatMap(u=>g(u));let p=0;const m=[],y=l.filter(u=>n.has(u));y.length&&(p+=.6*(y.length/l.length),m.push(`names "${y.join(" ")}"`));const w=[...new Set(N.filter(u=>n.has(u)))];w.length&&(p+=Math.min(.5,.2*w.length),m.push(`keywords ${w.slice(0,3).join(", ")}`));const j=new Set($),x=[...n].filter(u=>j.has(u));x.length&&(p+=Math.min(.4,.08*x.length),m.push(`like what it holds (${x.slice(0,3).join(", ")})`)),p>=c&&f.push({id:a.id,title:a.title,score:Math.round(Math.min(1,p)*100)/100,why:m.join("; ")})}return f.sort((a,l)=>l.score-a.score).slice(0,Math.max(1,s))}function Y(t,e=[]){if(!h(t))return{ids:[],line:""};const[o]=E([t],e),r=o?.counts||{},s=[["chat","chats"],["note","notes"],["meeting","meetings"]].filter(([n])=>r[n]).map(([n,d])=>`${r[n]} ${r[n]===1?n:d}`),c=t.body?.about?` — ${t.body.about}`:"";return{ids:(o?.items||[]).map(n=>n.id),line:`The person is working in their context "${t.title}"${c}.${s.length?` It holds ${s.join(", ")}; search them first for anything this question refers to.`:""}`}}export{A as CONTEXT_COLORS,R as CONTEXT_ITEM_KINDS,M as MAX_CONTEXT_ABOUT,X as MAX_CONTEXT_NAME,L as MAX_KEYWORDS,k as MAX_MEMBERS,F as addToContext,S as cleanContextName,E as contextIndex,T as contextMembers,Y as contextScope,q as contextsOf,D as editContext,P as groupByContext,K as makeContext,W as mergeContexts,H as removeFromContext,U as suggestContexts};
package/library.js CHANGED
@@ -1,4 +1,4 @@
1
- class l extends Error{constructor(t){super(t),this.name="LibraryError"}}const y=Object.freeze(["chat","note","meeting","brief"]),g=Object.freeze(["folder"]),p=new Set([...y,...g]);function m(e){const t=String(e||""),n=t.indexOf(":");if(n<=0)return null;const r=t.slice(0,n),o=t.slice(n+1);return!p.has(r)||!o?null:{kind:r,localId:o}}function B(e,t){if(!p.has(e))throw new l(`unknown record kind: ${e}`);const n=String(t||"");if(!n)throw new l("a record id needs a local id");if(n.includes(":"))throw new l(`local id may not contain ":" — got ${n}`);return`${e}:${n}`}function F(e){return m(e)!==null}const h=/`((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)`/g,A=/\[((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)\](?!\()/g,x=/(?<![\w/:.\[`-])((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)(?![\w-])/g,u=/(```[\s\S]*?```)/g;function Z(e){const t=new Set;for(const n of String(e||"").split(u))if(!n.startsWith("```"))for(const r of[h,A,x])for(const o of n.matchAll(r))t.add(o[1]);return[...t]}const R=/`\s*(\[[^\]\n`]+\]\((?:chatpanel-record:|https?:\/\/)[^)\s`]+\))\s*`/g,$=/`\s*(chatpanel-record:(?:chat|note|meeting|brief):[A-Za-z0-9_-]+)\s*`/g,E=Object.freeze({rightarrow:"→",to:"→",leftarrow:"←",gets:"←",leftrightarrow:"↔",Rightarrow:"⇒",Leftarrow:"⇐",Leftrightarrow:"⇔",implies:"⇒",iff:"⇔",uparrow:"↑",downarrow:"↓",mapsto:"↦",longrightarrow:"⟶",times:"×",cdot:"·",div:"÷",pm:"±",mp:"∓",le:"≤",leq:"≤",ge:"≥",geq:"≥",ne:"≠",neq:"≠",approx:"≈",sim:"∼",equiv:"≡",infty:"∞",checkmark:"✓",ldots:"…",dots:"…",cdots:"⋯",degree:"°",circ:"°",bullet:"•",star:"★",alpha:"α",beta:"β",gamma:"γ",delta:"δ",Delta:"Δ",lambda:"λ",mu:"μ",pi:"π",sigma:"σ",Sigma:"Σ",theta:"θ",omega:"ω",in:"∈",notin:"∉",subset:"⊂",cup:"∪",cap:"∩",forall:"∀",exists:"∃",neg:"¬",land:"∧",lor:"∨"}),S=/\$\s*\\([A-Za-z]+)\s*\$/g,_=/\\([A-Za-z]+)(?![A-Za-z])/g;function T(e){const t=String(e??"");return!t.includes("`")&&!t.includes("\\")?t:t.split(u).map(n=>n.startsWith("```")?n:n.replace(R,"$1").replace($,(o,i)=>`[${i.slice(17)}](${i})`).split(/(`[^`\n]*`)/g).map((o,i)=>i%2===1?o:o.replace(S,(c,a)=>E[a]??c).replace(_,(c,a)=>E[a]??c)).join("")).join("")}function K(e,{href:t=r=>`chatpanel-record:${r}`,label:n=r=>r}={}){const r=i=>String(i).replace(/[\[\]]/g,c=>`\\${c}`),o=(i,c)=>{const a=n(c);return a==null?i:`[${r(a)}](${t(c)})`};return T(e).split(u).map(i=>i.startsWith("```")?i:i.replace(h,o).replace(A,o).replace(x,o)).join("")}const w=48;function k(e,t="Untitled"){const n=String(e||"").split(`
1
+ class l extends Error{constructor(t){super(t),this.name="LibraryError"}}const y=Object.freeze(["chat","note","meeting","brief"]),g=Object.freeze(["folder","context"]),p=new Set([...y,...g]);function m(e){const t=String(e||""),n=t.indexOf(":");if(n<=0)return null;const r=t.slice(0,n),o=t.slice(n+1);return!p.has(r)||!o?null:{kind:r,localId:o}}function B(e,t){if(!p.has(e))throw new l(`unknown record kind: ${e}`);const n=String(t||"");if(!n)throw new l("a record id needs a local id");if(n.includes(":"))throw new l(`local id may not contain ":" — got ${n}`);return`${e}:${n}`}function F(e){return m(e)!==null}const h=/`((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)`/g,A=/\[((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)\](?!\()/g,x=/(?<![\w/:.\[`-])((?:chat|note|meeting|brief):[A-Za-z0-9_-]+)(?![\w-])/g,u=/(```[\s\S]*?```)/g;function Z(e){const t=new Set;for(const n of String(e||"").split(u))if(!n.startsWith("```"))for(const r of[h,A,x])for(const o of n.matchAll(r))t.add(o[1]);return[...t]}const R=/`\s*(\[[^\]\n`]+\]\((?:chatpanel-record:|https?:\/\/)[^)\s`]+\))\s*`/g,$=/`\s*(chatpanel-record:(?:chat|note|meeting|brief):[A-Za-z0-9_-]+)\s*`/g,E=Object.freeze({rightarrow:"→",to:"→",leftarrow:"←",gets:"←",leftrightarrow:"↔",Rightarrow:"⇒",Leftarrow:"⇐",Leftrightarrow:"⇔",implies:"⇒",iff:"⇔",uparrow:"↑",downarrow:"↓",mapsto:"↦",longrightarrow:"⟶",times:"×",cdot:"·",div:"÷",pm:"±",mp:"∓",le:"≤",leq:"≤",ge:"≥",geq:"≥",ne:"≠",neq:"≠",approx:"≈",sim:"∼",equiv:"≡",infty:"∞",checkmark:"✓",ldots:"…",dots:"…",cdots:"⋯",degree:"°",circ:"°",bullet:"•",star:"★",alpha:"α",beta:"β",gamma:"γ",delta:"δ",Delta:"Δ",lambda:"λ",mu:"μ",pi:"π",sigma:"σ",Sigma:"Σ",theta:"θ",omega:"ω",in:"∈",notin:"∉",subset:"⊂",cup:"∪",cap:"∩",forall:"∀",exists:"∃",neg:"¬",land:"∧",lor:"∨"}),S=/\$\s*\\([A-Za-z]+)\s*\$/g,_=/\\([A-Za-z]+)(?![A-Za-z])/g;function T(e){const t=String(e??"");return!t.includes("`")&&!t.includes("\\")?t:t.split(u).map(n=>n.startsWith("```")?n:n.replace(R,"$1").replace($,(o,i)=>`[${i.slice(17)}](${i})`).split(/(`[^`\n]*`)/g).map((o,i)=>i%2===1?o:o.replace(S,(c,a)=>E[a]??c).replace(_,(c,a)=>E[a]??c)).join("")).join("")}function K(e,{href:t=r=>`chatpanel-record:${r}`,label:n=r=>r}={}){const r=i=>String(i).replace(/[\[\]]/g,c=>`\\${c}`),o=(i,c)=>{const a=n(c);return a==null?i:`[${r(a)}](${t(c)})`};return T(e).split(u).map(i=>i.startsWith("```")?i:i.replace(h,o).replace(A,o).replace(x,o)).join("")}const w=48;function k(e,t="Untitled"){const n=String(e||"").split(`
2
2
  `).map(r=>r.replace(/^\s*#{1,6}\s*/,"").replace(/[*_`>~]+/g,"").trim()).find(r=>r.length>0);return n?n.length>w?`${n.slice(0,w-1).trimEnd()}…`:n:t}const d=(e,t=0)=>Number.isFinite(Number(e))?Number(e):t,s=e=>typeof e=="string"?e:e==null?"":String(e);function f(e={},{now:t=0}={}){const n=m(e.id);if(!n)throw new l(`not a record id: ${JSON.stringify(e.id)}`);const r=d(e.createdAt,d(e.date,t));return{id:e.id,kind:n.kind,localId:n.localId,title:s(e.title).trim()||L(n.kind,e),tags:j(e.tags),createdAt:r,updatedAt:d(e.updatedAt,r),deletedAt:d(e.deletedAt,0)||0,body:e.body??null,meta:e.meta&&typeof e.meta=="object"?e.meta:{}}}function L(e,t){return e==="note"?k(t?.body?.markdown??t?.body,"Untitled note"):e==="meeting"?"Untitled meeting":e==="brief"?"Untitled brief":e==="folder"?"Untitled folder":"New chat"}function j(e){if(!Array.isArray(e))return[];const t=[];for(const n of e){const r=s(n).trim();r&&!t.includes(r)&&t.push(r)}return t}function M(e){try{return f(e),!0}catch{return!1}}const I={assistant:"Assistant",system:"System",user:"You"};function q(e){const t=f(e);return t.deletedAt||g.includes(t.kind)?null:{id:t.id,type:t.kind,title:t.title,date:t.updatedAt||t.createdAt,text:N(t)}}function N(e){const t=e.kind?e:f(e),n=`${O(t.kind)}: ${t.title}`,r=t.tags.length?`
3
3
  Tags: ${t.tags.join(", ")}`:"";return`${n}${r}
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/events",
3
- "version": "0.464.0",
3
+ "version": "0.466.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",
@@ -156,6 +156,7 @@
156
156
  "./stitch.js": "./stitch.js",
157
157
  "./note-merge.js": "./note-merge.js",
158
158
  "./folders.js": "./folders.js",
159
+ "./contexts.js": "./contexts.js",
159
160
  "./html-markdown.js": "./html-markdown.js",
160
161
  "./notes-import.js": "./notes-import.js",
161
162
  "./onenote-source.js": "./onenote-source.js",
@@ -522,6 +523,7 @@
522
523
  "stitch.js",
523
524
  "note-merge.js",
524
525
  "folders.js",
526
+ "contexts.js",
525
527
  "html-markdown.js",
526
528
  "notes-import.js",
527
529
  "onenote-source.js",
package/voice-room.js CHANGED
@@ -1,5 +1,5 @@
1
- const m=Object.freeze(["me","room","anyone"]),y="me",d="You",g=6,f=1200;function k(s={}){const e=s?.ui?.voice||{};return m.includes(e.listenTo)?e.listenTo:e.onlyMe===!1?"anyone":y}const A=s=>s==="me"||s==="room",x=/^(?:(?:so|and|but|ok(?:ay)?|hey|um+|uh+|well|chap|chad)[,\s]+)*(?:what|what's|whats|who|who's|whose|whom|where|where's|when|why|how|how's|which|is|isn't|are|aren't|am|was|were|can|can't|could|would|will|won't|do|does|doesn't|did|didn't|should|shall|may|might|have|has|tell|explain|give|show|find|help|remind|translate|define|say)\b/i,T=/\b(?:hey\s+)?(?:chap|chad)\b/i,_=/\b(?:i (?:was |am |'m )?wonder(?:ing)?|i(?:'d| would) (?:like|love) to (?:know|find out|hear)|i want(?:ed)? to (?:know|find out)|(?:do|does) (?:you|anyone|anybody) know|any idea|i(?:'m| am) curious|can (?:you|someone|anyone) (?:tell|help|find|check|explain|look)|tell (?:me|us))\b/i;function N(s){const e=String(s||"").trim();return e?/\?\s*$/.test(e)||x.test(e)||_.test(e)||T.test(e):!1}const b='Several people are in the room with you. Answer what was asked, directly. Do not repeat or quote any line of the conversation, and do not begin with a name or a label such as "You:" or "Chap:".',S="This question is from a guest in the room, not the person whose Chap you are. Answer it helpfully, but do not use or reveal that person's personal information — their memories, notes, messages, calendar, contacts, history, location or anything said to you privately. If the answer needs it, say that only they can ask for that.";function E({text:s="",from:e=null,room:a=[]}={}){const t=String(s||"").trim(),l=String(e?.label||d),r=e?.guest===!0;let o=(Array.isArray(a)?a:[]).slice(-g).map(h=>[h?.label||"Someone",String(h?.text||"").trim()]).filter(([,h])=>h).map(([h,w])=>`${h}: ${w}`).join(`
2
- `);o.length>f&&(o=o.slice(-f).replace(/^[^\n]*\n/,""));const c=o?'The message is what was said in the room, one line per person ("Name: words"). ':"",i=r?`${c}Reply to the last line, said by ${l}, a guest in the room.`:`${c}Reply to the last line, said by the person whose Chap you are ("${d}").`;return{text:[o,`${l}: ${t}`].filter(Boolean).join(`
3
- `),speaker:{label:l,guest:r},guest:r,hint:[b,i,...r?[S]:[]].join(`
4
- `)}}function v(s={}){const e=s?.ui||{};return{...s,mcpServers:[],recipes:[],skills:[],ui:{...e,guestTurn:!0,memory:{...e.memory||{},enabled:!1,recall:!1},historyContextMode:"off",historyTools:!1,mcpToolsMode:"off",search:{...e.search||{},personalFirst:!1}}}}const u=/^\s*(?:\*\*|__)?(?:you|chap|assistant|ai|answer|response|speaker \d+|another voice)(?:\*\*|__)?\s*:\s*/i,p=s=>[...String(s||"").matchAll(/[\p{L}\p{N}']+/gu)].map(e=>({w:e[0].toLowerCase().replace(/'/g,""),end:e.index+e[0].length}));function C(s,{question:e="",done:a=!1}={}){let t=String(s||"");for(let n=u.exec(t);n;n=u.exec(t))t=t.slice(n[0].length);if(!a&&/^\s*(?:\*\*|__)?[A-Za-z]{0,9}(?: \d{0,2})?(?:\*\*|__)?\s*$/.test(t)&&t.trim().length<12)return{text:"",hold:!0};const l=String(e||"").split(`
5
- `).map(n=>p(n.replace(u,"")).map(o=>o.w)).filter(n=>n.length>=3);let r=!1;for(const n of l){const o=O(t,n,a);if(o.hold)return{text:"",hold:!0};if(o.cut!=null){t=t.slice(o.cut).replace(/^[\s?.!,:;—–-]+/,""),r=!0;break}}if(r)for(let n=u.exec(t);n;n=u.exec(t))t=t.slice(n[0].length);return{text:t,hold:!1}}function O(s,e,a){const t=p(s);if(!t.length)return a?{}:{hold:!0};let l=!1;for(let r=0;r<e.length;r++){const n=e.length-r;if(r>0&&n<4)break;let o=0;for(;o<t.length&&o<n&&t[o].w===e[r+o];)o++;if(o===n)return{cut:t[o-1].end};if(r===0&&t.length>=e.length){let c=0;for(let i=0;i<e.length;i++)t[i].w===e[i]&&c++;if(c/e.length>=.8)return{cut:t[e.length-1].end}}!a&&o===t.length&&(r===0||o>=2)&&(l=!0)}return l?{hold:!0}:{}}export{y as DEFAULT_LISTEN_TO,S as GUEST_HINT,m as LISTEN_TO,g as ROOM_CONTEXT,b as ROOM_HINT,d as ROOM_OWNER,N as asksChap,C as cleanReplyStart,v as guestPrefs,A as judgesOwner,k as listenToOf,E as roomMessage};
1
+ const w=Object.freeze(["me","room","anyone"]),y="me",d="You",g=6,f=1200;function k(o={}){const e=o?.ui?.voice||{};return w.includes(e.listenTo)?e.listenTo:e.onlyMe===!1?"anyone":y}const A=o=>o==="me"||o==="room",x=/^(?:(?:so|and|but|ok(?:ay)?|hey|um+|uh+|well|chap|chad)[,\s]+)*(?:what|what's|whats|who|who's|whose|whom|where|where's|when|why|how|how's|which|is|isn't|are|aren't|am|was|were|can|can't|could|would|will|won't|do|does|doesn't|did|didn't|should|shall|may|might|have|has|tell|explain|give|show|find|help|remind|translate|define|say)\b/i,T=/\b(?:hey\s+)?(?:chap|chad)\b/i,b=/\b(?:i (?:was |am |'m )?wonder(?:ing)?|i(?:'d| would) (?:like|love) to (?:know|find out|hear)|i want(?:ed)? to (?:know|find out)|(?:do|does) (?:you|anyone|anybody) know|any idea|i(?:'m| am) curious|can (?:you|someone|anyone) (?:tell|help|find|check|explain|look)|tell (?:me|us))\b/i;function N(o){const e=String(o||"").trim();return e?/\?\s*$/.test(e)||x.test(e)||b.test(e)||T.test(e):!1}const S='Several people are in the room with you. Answer what was asked, directly. Do not repeat or quote any line of the conversation, and do not begin with a name or a label such as "You:" or "Chap:".',_="This question is from a guest in the room, not the person whose Chap you are. Answer it helpfully, but do not use or reveal that person's personal information — their memories, notes, messages, calendar, contacts, history, location or anything said to you privately. If the answer needs it, say that only they can ask for that.";function v({text:o="",from:e=null,room:l=[]}={}){const t=String(o||"").trim(),a=String(e?.label||d),r=e?.guest===!0;let n=(Array.isArray(l)?l:[]).slice(-g).map(h=>[h?.label||"Someone",String(h?.text||"").trim()]).filter(([,h])=>h).map(([h,m])=>`${h}: ${m}`).join(`
2
+ `);n.length>f&&(n=n.slice(-f).replace(/^[^\n]*\n/,""));const c=n?'The message is what was said in the room, one line per person ("Name: words"). ':"",i=r?`${c}Reply to the last line, said by ${a}, a guest in the room.`:`${c}Reply to the last line, said by the person whose Chap you are ("${d}").`;return{text:[n,`${a}: ${t}`].filter(Boolean).join(`
3
+ `),speaker:{label:a,guest:r},guest:r,hint:[S,i,...r?[_]:[]].join(`
4
+ `)}}function C(o={}){if(o&&typeof o=="object"&&!o.ui)return{...o,mcpServers:[],recipes:[],skills:[],guestTurn:!0,tools:{...o.tools||{},historyTools:!1,historyContextMode:"off",mcpToolsMode:"off"},memory:{...o.memory||{},enabled:!1,recall:!1},search:{...o.search||{},personalFirst:!1}};const e=o?.ui||{};return{...o,mcpServers:[],recipes:[],skills:[],ui:{...e,guestTurn:!0,memory:{...e.memory||{},enabled:!1,recall:!1},historyContextMode:"off",historyTools:!1,mcpToolsMode:"off",search:{...e.search||{},personalFirst:!1}}}}const u=/^\s*(?:\*\*|__)?(?:you|chap|assistant|ai|answer|response|speaker \d+|another voice)(?:\*\*|__)?\s*:\s*/i,p=o=>[...String(o||"").matchAll(/[\p{L}\p{N}']+/gu)].map(e=>({w:e[0].toLowerCase().replace(/'/g,""),end:e.index+e[0].length}));function E(o,{question:e="",done:l=!1}={}){let t=String(o||"");for(let s=u.exec(t);s;s=u.exec(t))t=t.slice(s[0].length);if(!l&&/^\s*(?:\*\*|__)?[A-Za-z]{0,9}(?: \d{0,2})?(?:\*\*|__)?\s*$/.test(t)&&t.trim().length<12)return{text:"",hold:!0};const a=String(e||"").split(`
5
+ `).map(s=>p(s.replace(u,"")).map(n=>n.w)).filter(s=>s.length>=3);let r=!1;for(const s of a){const n=O(t,s,l);if(n.hold)return{text:"",hold:!0};if(n.cut!=null){t=t.slice(n.cut).replace(/^[\s?.!,:;—–-]+/,""),r=!0;break}}if(r)for(let s=u.exec(t);s;s=u.exec(t))t=t.slice(s[0].length);return{text:t,hold:!1}}function O(o,e,l){const t=p(o);if(!t.length)return l?{}:{hold:!0};let a=!1;for(let r=0;r<e.length;r++){const s=e.length-r;if(r>0&&s<4)break;let n=0;for(;n<t.length&&n<s&&t[n].w===e[r+n];)n++;if(n===s)return{cut:t[n-1].end};if(r===0&&t.length>=e.length){let c=0;for(let i=0;i<e.length;i++)t[i].w===e[i]&&c++;if(c/e.length>=.8)return{cut:t[e.length-1].end}}!l&&n===t.length&&(r===0||n>=2)&&(a=!0)}return a?{hold:!0}:{}}export{y as DEFAULT_LISTEN_TO,_ as GUEST_HINT,w as LISTEN_TO,g as ROOM_CONTEXT,S as ROOM_HINT,d as ROOM_OWNER,N as asksChap,E as cleanReplyStart,C as guestPrefs,A as judgesOwner,k as listenToOf,v as roomMessage};