@chatpanel/events 0.448.0 → 0.450.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.
@@ -0,0 +1,26 @@
1
+ import{defineSchema as $,describeSchema as x,parseStructured as E}from"./structured.js";const y=Object.freeze(["none","add_section","replace_section"]),f=$({name:"meeting_followup",purpose:"the answer to a question about a meeting, and the change to its notes when one was asked for",fields:{reply:{type:"string",required:!0,max:2e3,multiline:!0,describe:"what to say back to the person: the answer, or one line saying what was changed in the notes"},edit:{type:"enum",values:y,required:!0,describe:"add_section or replace_section ONLY when the person asked to add to, change, update or fix the notes; none for a question"},heading:{type:"string",max:80,describe:"the section heading to add or replace, short; empty when edit is none"},body:{type:"string",max:4e3,multiline:!0,describe:"the section content in markdown (bullets welcome), without the heading; empty when edit is none"}}}),O=4,_=2e4,k=8e3;function N({transcript:o="",notes:e="",history:t=[],question:a=""}={}){const i=(Array.isArray(t)?t:[]).slice(-O).map(r=>`Q: ${r.question}
2
+ A: ${r.reply}`).join(`
3
+
4
+ `),n=["You help with one meeting: you answer questions about it and keep its notes up to date.","Answer from the transcript and the notes. When they do not say, say so rather than guess.","When the person asks to add something to the notes, change, update or fix them, put it in a section: add_section with a new heading, or replace_section with the heading of the section to rewrite. The section body holds the content, in markdown.","When the person only asks a question, edit is none.",x(f)].join(`
5
+ `),d=[`TRANSCRIPT:
6
+ ${String(o).slice(-_)}`,`NOTES:
7
+ ${String(e||"(none yet)").slice(0,k)}`,i?`EARLIER QUESTIONS:
8
+ ${i}`:"",`THE PERSON NOW SAYS: ${a}`].filter(Boolean).join(`
9
+
10
+ `);return{system:n,user:d,maxTokens:1200}}function R(o){const e=E(o,f);if(!e||typeof e.reply!="string")return{reply:String(o||"").trim(),edit:"none",heading:"",body:""};const t=y.includes(e.edit)?e.edit:"none",a=String(e.heading||"").replace(/^#+\s*/,"").trim(),i=String(e.body||"").trim();return t!=="none"&&(!a||!i)?{reply:e.reply.trim(),edit:"none",heading:"",body:""}:{reply:e.reply.trim(),edit:t,heading:a,body:i}}const w=/^(#{1,6})\s+(.+?)\s*#*\s*$/,S=o=>String(o||"").toLowerCase().replace(/[^\p{L}\p{N}]+/gu," ").trim();function A(o="",{edit:e="none",heading:t="",body:a=""}={}){const i=String(o||"");if(e==="none"||!t||!a)return i;const n=i.split(`
11
+ `),d=S(t);let r=-1,p=2;for(let s=0;s<n.length;s++){const c=w.exec(n[s]);if(c&&S(c[2])===d){r=s,p=c[1].length;break}}const h=String(a).trim();if(r<0)return`${i.trimEnd()}${i.trim()?`
12
+
13
+ `:""}## ${t}
14
+
15
+ ${h}
16
+ `;let l=n.length;for(let s=r+1;s<n.length;s++){const c=w.exec(n[s]);if(c&&c[1].length<=p){l=s;break}}const u=e==="add_section"?n.slice(r+1,l).join(`
17
+ `).trim():"",b=`${n[r]}
18
+
19
+ ${u?`${u}
20
+
21
+ `:""}${h}
22
+ `,m=n.slice(0,r).join(`
23
+ `),g=n.slice(l).join(`
24
+ `);return`${m}${m?`
25
+ `:""}${b}${g?`
26
+ ${g}`:""}`}function L({question:o="",result:e={},at:t=0}={}){return{at:Number(t)||0,question:String(o).trim(),reply:String(e.reply||"").trim(),...e.edit&&e.edit!=="none"?{edit:e.edit,heading:e.heading}:{}}}export{y as FOLLOWUP_EDITS,O as FOLLOWUP_HISTORY,f as MEETING_FOLLOWUP_SCHEMA,A as applyNotesEdit,L as followupEntry,N as followupPrompt,R as followupResult};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/events",
3
- "version": "0.448.0",
3
+ "version": "0.450.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",
@@ -128,6 +128,7 @@
128
128
  "./media-transcript.js": "./media-transcript.js",
129
129
  "./meeting-analyzers.js": "./meeting-analyzers.js",
130
130
  "./meeting-insights.js": "./meeting-insights.js",
131
+ "./meeting-followup.js": "./meeting-followup.js",
131
132
  "./meeting-insight-prompts.js": "./meeting-insight-prompts.js",
132
133
  "./meeting-shape.js": "./meeting-shape.js",
133
134
  "./meeting-speakers.js": "./meeting-speakers.js",
@@ -489,6 +490,7 @@
489
490
  "media-transcript.js",
490
491
  "meeting-analyzers.js",
491
492
  "meeting-insights.js",
493
+ "meeting-followup.js",
492
494
  "meeting-insight-prompts.js",
493
495
  "meeting-shape.js",
494
496
  "meeting-speakers.js",
package/structured.js CHANGED
@@ -1,4 +1,8 @@
1
1
  class m extends Error{constructor(t,r){super(r),this.name="StructuredError",this.code=t}}const P=Object.freeze(["string","number","integer","boolean","enum","string[]","number[]","object[]"]),E=/^(?:none|n\/a|na|nothing|no|null|nil|empty|no results?|nothing found|no request|-{1,3}|\.)\s*[.!]?$/i,K=/^(?:(?:sure|certainly|of course|okay|ok|got it|here(?:'s| is)(?: the)?(?: \w+)?|the (?:json|answer|result|output)(?: is)?|json|output|answer|result)\s*[:.!,-]*\s*)+/i,b=e=>!!e&&typeof e=="object"&&!Array.isArray(e),ne=(e,t)=>e.length>t?`${e.slice(0,t)}`:e;function re(e={}){const t=String(e.name||"").trim();if(!t)throw new m("no-name","a schema needs a name");if(!b(e.fields)||!Object.keys(e.fields).length)throw new m("no-fields",`schema ${t} declares no fields`);const r={};for(const[n,i]of Object.entries(e.fields))r[n]=L(t,n,i);if(e.nothingIf!=null&&!(e.nothingIf instanceof RegExp))throw new m("bad-nothing",`schema ${t}: nothingIf must be a RegExp`);if(e.fallback!=null&&e.fallback!=="lines"&&typeof e.fallback!="function")throw new m("bad-fallback",`schema ${t}: fallback must be 'lines' or a function`);return Object.freeze({name:t,purpose:String(e.purpose||"").trim(),fields:Object.freeze(r),order:Object.freeze(Object.keys(r)),nothing:e.nothing??null,nothingIf:e.nothingIf??null,fallback:e.fallback??null,strictRequired:e.strictRequired!==!1})}function L(e,t,r){const n=typeof r=="string"?{type:r}:{...r||{}},i=String(n.type||"string");if(!P.includes(i))throw new m("bad-type",`schema ${e}.${t}: unknown type ${JSON.stringify(i)}`);if(i==="enum"){const l=(n.values||[]).map(o=>String(o));if(!l.length)throw new m("bad-enum",`schema ${e}.${t}: enum with no values`);if(n.default!=null&&!l.includes(String(n.default)))throw new m("bad-default",`schema ${e}.${t}: default ${JSON.stringify(n.default)} is not one of its values`);n.values=Object.freeze(l);const s=new Map;for(const o of l)s.set(o.toLowerCase(),o);for(const[o,u]of Object.entries(n.aliases||{})){if(!l.includes(String(u)))throw new m("bad-alias",`schema ${e}.${t}: alias → ${u}, which is not a value`);s.set(String(o).toLowerCase(),String(u))}n.aliasMap=s}if(i==="object[]"){if(!b(n.fields))throw new m("bad-items",`schema ${e}.${t}: object[] needs \`fields\``);const l={};for(const[s,o]of Object.entries(n.fields))l[s]=L(`${e}.${t}[]`,s,o);n.fields=Object.freeze(l),n.order=Object.freeze(Object.keys(l))}if(n.emptyIf!=null&&!(n.emptyIf instanceof RegExp))throw new m("bad-emptyif",`schema ${e}.${t}: emptyIf must be a RegExp`);return n.type=i,n.describe=String(n.describe||"").trim(),Object.freeze(n)}const I=e=>e==="string[]"||e==="number[]"||e==="object[]";function q(e){const t=e.order.filter(r=>I(e.fields[r].type));return t.length===1?t[0]:null}function ie(e,{fences:t=!1}={}){const r=e.order.map(i=>`${JSON.stringify(i)}: ${A(e.fields[i])}`).join(", "),n=[];for(const i of e.order){const l=e.fields[i],s=[];l.describe&&s.push(l.describe),l.required&&s.push("required"),l.default!=null&&!l.required&&s.push(`defaults to ${JSON.stringify(l.default)}`),l.type==="string"&&l.max&&s.push(`at most ${l.max} characters`),I(l.type)&&l.maxItems&&s.push(`at most ${l.maxItems} items`),s.length&&n.push(`- ${i} — ${s.join("; ")}.`)}return[e.purpose?`${e.purpose}`:"",(e.purpose,""),t?"Return a single JSON object in a ```json code fence and nothing else:":"Return ONLY a JSON object — no prose, no code fences, no explanation:",`{${r}}`,(n.length,""),...n].filter(i=>i!=="").join(`
2
2
  `)}function A(e){switch(e.type){case"enum":return e.values.map(t=>JSON.stringify(t)).join("|");case"string[]":return"[string, …]";case"number[]":return"[number, …]";case"object[]":return`[{${e.order.map(t=>`${JSON.stringify(t)}: ${A(e.fields[t])}`).join(", ")}}, …]`;case"integer":return"integer";case"number":return"number";case"boolean":return"true|false";default:return"string"}}function U(e,{strict:t=!0}={}){const r={};for(const i of e.order)r[i]=_(e.fields[i]);const n=t?e.order.slice():e.order.filter(i=>e.fields[i].required);return{type:"object",properties:r,required:n,additionalProperties:!1}}function _(e){const t=e.describe?{description:e.describe}:{};switch(e.type){case"enum":return{...t,type:"string",enum:e.values.slice()};case"integer":return{...t,type:"integer"};case"number":return{...t,type:"number"};case"boolean":return{...t,type:"boolean"};case"string[]":return{...t,type:"array",items:{type:"string"}};case"number[]":return{...t,type:"array",items:{type:"number"}};case"object[]":return{...t,type:"array",items:{type:"object",properties:Object.fromEntries(e.order.map(r=>[r,_(e.fields[r])])),required:e.order.slice(),additionalProperties:!1}};default:return{...t,type:"string"}}}function se(e,{mode:t="schema",strict:r=!0}={}){return t==="none"?null:t==="object"?{response_format:{type:"json_object"}}:{response_format:{type:"json_schema",json_schema:{name:e.name.replace(/[^a-zA-Z0-9_-]/g,"_").slice(0,64)||"answer",strict:r,schema:U(e,{strict:r})}}}}const le=Object.freeze(["schema","object","none"]);function v(e){let t=String(e??"").trim();const r=t.match(/```(?:json|jsonc|json5)?\s*\n?([\s\S]*?)(?:```|$)/i);r&&r[1].trim()&&(t=r[1].trim());const n=t.replace(K,"");return n!==t&&/^[[{"]/.test(n)&&(t=n),t.trim()}function F(e){const t=String(e??"");let r=null;for(let n=0;n<t.length;n++){const i=t[n];if(i!=="{"&&i!=="[")continue;const l=W(t,n);if(l.complete)return{text:t.slice(n,l.end),start:n,end:l.end,complete:!0};r||(r={text:t.slice(n),start:n,end:t.length,complete:!1})}return r}function W(e,t){const r=[];let n=!1,i='"';for(let l=t;l<e.length;l++){const s=e[l];if(n){if(s==="\\"){l++;continue}s===i&&(n=!1);continue}if(j.has(s)){n=!0,i=j.get(s);continue}if(s==="{"||s==="["){r.push(s);continue}if((s==="}"||s==="]")&&(r.pop(),!r.length))return{end:l+1,complete:!0,depth:0,inStr:!1}}return{end:e.length,complete:!1,depth:r.length,inStr:n}}const B=new Map([["true","true"],["false","false"],["null","null"],["True","true"],["False","false"],["None","null"],["TRUE","true"],["FALSE","false"],["NULL","null"],["yes","true"],["no","false"],["Yes","true"],["No","false"],["undefined","null"],["NaN","null"],["Infinity","null"]]),j=new Map([['"','"'],["'","'"],["“","”"],["”","”"],["‘","’"],["’","’"]]),D=e=>j.has(e);function z(e,{partial:t=!1}={}){const r=String(e??"");let n="";const i=[],l=new Set;let s=!1,o=null,u=-1,d=-1,f=!1;const g=()=>i[i.length-1]||null,x=()=>{s&&(d=n.length,n+=",",s=!1)},$=()=>{const c=g();c&&c.kind==="{"?(i.length===1&&o&&l.add(o),c.expect="comma"):c&&(c.expect="comma")};for(let c=0;c<r.length;c++){const p=r[c];if(/\s/.test(p)){n&&!/\s$/.test(n)&&(n+=" ");continue}if(p==="/"&&(r[c+1]==="/"||r[c+1]==="*")){if(r[c+1]==="/")for(;c<r.length&&r[c]!==`
3
3
  `;)c++;else{const a=r.indexOf("*/",c+2);c=a<0?r.length:a+1}continue}if(p==="{"||p==="["){x(),i.push({kind:p,expect:p==="{"?"key":"value"}),n+=p;continue}if(p==="}"||p==="]"){s=!1;const a=g();if(!a)continue;a.kind==="{"&&(a.expect==="colon"||a.expect==="value"&&n.endsWith(":"))&&O(),i.pop(),n+=a.kind==="{"?"}":"]",$();continue}if(p===":"){n+=":";const a=g();a&&(a.expect="value");continue}if(p===","){s=!0;const a=g();a&&(a.expect=a.kind==="{"?"key":"value");continue}if(D(p)){x();const a=g(),k=!!a&&a.kind==="{"&&a.expect!=="value";k&&(u=n.length);const y=G(r,c,p);if(c=y.end,!y.closed){if(f=!0,!t)return{json:null,complete:!1,settled:l,truncated:!0};if(k){O();break}n+=`${JSON.stringify(y.value)}`,i.length;break}n+=JSON.stringify(y.value),k?(i.length===1&&(o=y.value),a&&(a.expect="colon")):$();continue}const h=H(r,c);if(!h.value)continue;c=h.end,x();const S=g();if(!!S&&S.kind==="{"&&S.expect!=="value"){u=n.length,n+=JSON.stringify(h.value),i.length===1&&(o=h.value),S.expect="colon";continue}const J=B.get(h.value);J?n+=J:/^-?\d+(?:\.\d+)?(?:[eE][-+]?\d+)?$/.test(h.value)?n+=h.value:n+=JSON.stringify(h.value),t&&h.end>=r.length-1?f=!0:$()}function O(){u<0||(n=n.slice(0,d>=0&&d>=u-1?d:u),n.endsWith(",")&&(n=n.slice(0,-1)),u=-1,i.length===1&&(o=null))}if(i.length){if(f=!0,!t)return{json:null,complete:!1,settled:l,truncated:!0};const c=g();for(c&&c.kind==="{"&&c.expect==="colon"&&O(),n.trimEnd().endsWith(":")&&(n+="null"),n.trimEnd().endsWith(",")&&(n=n.trimEnd().slice(0,-1));i.length;)n+=i.pop().kind==="{"?"}":"]"}return{json:n.trim(),complete:!f,settled:l,truncated:f}}function G(e,t,r){const n=j.get(r)||'"';let i="";for(let l=t+1;l<e.length;l++){const s=e[l];if(s==="\\"){const o=e[l+1];if(o===void 0)return{value:i,end:e.length,closed:!1};o==="n"?i+=`
4
- `:o==="t"?i+=" ":o==="r"?i+="\r":o==="u"&&/^[0-9a-fA-F]{4}$/.test(e.slice(l+2,l+6))?(i+=String.fromCharCode(parseInt(e.slice(l+2,l+6),16)),l+=4):i+=o,l++;continue}if(s===n)return{value:i,end:l,closed:!0};i+=s}return{value:i,end:e.length,closed:!1}}function H(e,t){let r=t;for(;r<e.length&&!/[\s,:{}[\]"']/.test(e[r]);)r++;return{value:e.slice(t,r),end:r-1}}function oe(e,{partial:t=!1}={}){const r=F(v(e));return r?z(r.text,{partial:t}).json:null}function C(e,t,{partial:r=!1}={}){const n=String(e??"").trim();if(!n)return null;const i=v(n);if(E.test(i)||t.nothingIf?.test(i))return N(t);const l=F(i);let s=null,o=!1,u=new Set;if(l){const f=z(l.text,{partial:r});if(o=f.complete&&l.complete,u=f.settled,f.json)try{s=JSON.parse(f.json)}catch{s=null}}if(s==null){const f=V(i,t);if(f){const g=R(f,t,{partial:r});if(g===w)return N(t);if(g)return{value:g,complete:!0,settled:t.order.slice(),source:"fallback"}}return null}if(Array.isArray(s)){const f=q(t);if(!f)return null;s={[f]:s}}if(!b(s))return null;const d=R(s,t,{partial:r});return d===w?N(t):d==null?null:{value:d,complete:o,settled:[...u].filter(f=>t.order.includes(f)),source:"json"}}const w=Symbol("nothing");function N(e){return e.nothing==null?null:{value:e.nothing,complete:!0,settled:e.order.slice(),source:"nothing"}}function ue(e,t,r){return C(e,t,r)?.value??null}function V(e,t){if(typeof t.fallback=="function")try{const s=t.fallback(e);return b(s)?s:null}catch{return null}if(t.fallback!=="lines")return null;const r=q(t);if(!r)return null;const n=e.split(/\r?\n/).map(s=>s.trim()).filter(Boolean),i=n.filter(s=>/^(?:[-*+•]|\d+[.)])\s+/.test(s));if(!i.length&&n.length<2)return null;const l=(i.length?i:n).map(s=>s.replace(/^(?:[-*+•]|\d+[.)])\s*/,"").replace(/^["'`]|["'`]$/g,"").trim()).filter(Boolean);return l.length?{[r]:l}:null}function R(e,t,{partial:r}){const n={};let i=!1,l=!1,s=!1;for(const o of t.order){const u=t.fields[o],d=Q(e,o),f=M(d,u);if(f===void 0){u.required&&(i=!0),u.default!==void 0?n[o]=u.default:r||(n[o]=Z(u));continue}s=!0,n[o]=f,u.required&&Y(f)&&(l=!0)}return s?r?n:l?w:i&&t.strictRequired?null:n:null}const Y=e=>e===""||e===null||Array.isArray(e)&&e.length===0;function Q(e,t){if(t in e)return e[t];const r=t.toLowerCase().replace(/[^a-z0-9]/g,"");for(const n of Object.keys(e))if(n.toLowerCase().replace(/[^a-z0-9]/g,"")===r)return e[n]}function Z(e){return I(e.type)?[]:e.type==="boolean"?!1:e.type==="number"||e.type==="integer"?null:e.type==="enum"?e.default??e.values[0]:""}function M(e,t){if(e!=null)switch(t.type){case"string":{const r=T(e,t);return r===void 0?void 0:r}case"enum":{const r=String(typeof e=="string"?e:e?.value??e).trim().toLowerCase().replace(/[.!]+$/,""),n=t.aliasMap.get(r)??t.aliasMap.get(r.replace(/^(?:a|an|the)\s+/,""));return n||(t.default!==void 0?t.default:void 0)}case"number":case"integer":{const r=typeof e=="number"?e:Number(String(e).replace(/[^0-9.eE+-]/g,""));if(!Number.isFinite(r))return;const n=t.type==="integer"?Math.round(r):r;return t.min!=null&&n<t.min?t.min:t.max!=null&&n>t.max?t.max:n}case"boolean":{if(typeof e=="boolean")return e;const r=String(e).trim().toLowerCase();return/^(?:true|yes|y|1)$/.test(r)?!0:/^(?:false|no|n|0)$/.test(r)?!1:void 0}case"string[]":case"number[]":case"object[]":{const r=Array.isArray(e)?e:e===""?[]:[e],n=t.type==="string[]"?s=>T(s,{max:t.itemMax,emptyIf:t.itemEmptyIf}):t.type==="number[]"?s=>M(s,{type:"number",min:t.min,max:t.max}):s=>b(s)?R(s,{order:t.order,fields:t.fields,strictRequired:!0},{partial:!1}):void 0,i=[],l=new Set;for(const s of r){const o=n(s);if(!(o==null||o===""||o===w)){if(t.dedupe!==!1){const u=typeof o=="object"?JSON.stringify(o):String(o).toLowerCase();if(l.has(u))continue;l.add(u)}if(i.push(o),t.maxItems&&i.length>=t.maxItems)break}}return i}default:return}}function T(e,t={}){if(e==null)return;let n=(typeof e=="string"?e:b(e)?String(e.value??e.text??e.name??""):String(e)).replace(/\s+/g," ").trim();if(t.emptyIf&&t.emptyIf.test(n)||E.test(n))return"";if(n=n.replace(/^["'`]+|["'`]+$/g,"").trim(),t.max&&n.length>t.max){const i=n.slice(0,t.max);n=/\s/.test(i)?i.replace(/\s+\S*$/,""):i}return n}function ce(e){return E.test(String(e??"").trim())}const X=/[{}[\]",:]/,ee=12;function fe(e,{onChange:t=null}={}){let r="",n=0,i=null,l="";const s=o=>{const u=C(r,e,{partial:o});if(u){i=u;const d=JSON.stringify(u.value);d!==l&&(l=d,t?.(u.value,u.settled))}return n=0,i};return{push(o){const u=String(o??"");return u&&(r+=u,n+=u.length),u&&(X.test(u)||n>=ee)&&s(!0),this.snapshot()},end(){return s(!1),i||s(!0),this.snapshot()},snapshot(){return{value:i?.value??null,settled:i?.settled??[],complete:!!i?.complete,source:i?.source??null,text:r}},reset(){r="",n=0,i=null,l=""},get text(){return r}}}export{P as FIELD_TYPES,le as RESPONSE_MODES,m as StructuredError,C as coerce,fe as createStructuredStream,re as defineSchema,ie as describeSchema,F as findJson,ce as isNothing,ue as parseStructured,oe as repairJson,se as responseFormat,z as rewriteJson,U as toJsonSchema,v as unfence};
4
+ `:o==="t"?i+=" ":o==="r"?i+="\r":o==="u"&&/^[0-9a-fA-F]{4}$/.test(e.slice(l+2,l+6))?(i+=String.fromCharCode(parseInt(e.slice(l+2,l+6),16)),l+=4):i+=o,l++;continue}if(s===n)return{value:i,end:l,closed:!0};i+=s}return{value:i,end:e.length,closed:!1}}function H(e,t){let r=t;for(;r<e.length&&!/[\s,:{}[\]"']/.test(e[r]);)r++;return{value:e.slice(t,r),end:r-1}}function oe(e,{partial:t=!1}={}){const r=F(v(e));return r?z(r.text,{partial:t}).json:null}function C(e,t,{partial:r=!1}={}){const n=String(e??"").trim();if(!n)return null;const i=v(n);if(E.test(i)||t.nothingIf?.test(i))return N(t);const l=F(i);let s=null,o=!1,u=new Set;if(l){const f=z(l.text,{partial:r});if(o=f.complete&&l.complete,u=f.settled,f.json)try{s=JSON.parse(f.json)}catch{s=null}}if(s==null){const f=V(i,t);if(f){const g=R(f,t,{partial:r});if(g===w)return N(t);if(g)return{value:g,complete:!0,settled:t.order.slice(),source:"fallback"}}return null}if(Array.isArray(s)){const f=q(t);if(!f)return null;s={[f]:s}}if(!b(s))return null;const d=R(s,t,{partial:r});return d===w?N(t):d==null?null:{value:d,complete:o,settled:[...u].filter(f=>t.order.includes(f)),source:"json"}}const w=Symbol("nothing");function N(e){return e.nothing==null?null:{value:e.nothing,complete:!0,settled:e.order.slice(),source:"nothing"}}function ue(e,t,r){return C(e,t,r)?.value??null}function V(e,t){if(typeof t.fallback=="function")try{const s=t.fallback(e);return b(s)?s:null}catch{return null}if(t.fallback!=="lines")return null;const r=q(t);if(!r)return null;const n=e.split(/\r?\n/).map(s=>s.trim()).filter(Boolean),i=n.filter(s=>/^(?:[-*+•]|\d+[.)])\s+/.test(s));if(!i.length&&n.length<2)return null;const l=(i.length?i:n).map(s=>s.replace(/^(?:[-*+•]|\d+[.)])\s*/,"").replace(/^["'`]|["'`]$/g,"").trim()).filter(Boolean);return l.length?{[r]:l}:null}function R(e,t,{partial:r}){const n={};let i=!1,l=!1,s=!1;for(const o of t.order){const u=t.fields[o],d=Q(e,o),f=M(d,u);if(f===void 0){u.required&&(i=!0),u.default!==void 0?n[o]=u.default:r||(n[o]=Z(u));continue}s=!0,n[o]=f,u.required&&Y(f)&&(l=!0)}return s?r?n:l?w:i&&t.strictRequired?null:n:null}const Y=e=>e===""||e===null||Array.isArray(e)&&e.length===0;function Q(e,t){if(t in e)return e[t];const r=t.toLowerCase().replace(/[^a-z0-9]/g,"");for(const n of Object.keys(e))if(n.toLowerCase().replace(/[^a-z0-9]/g,"")===r)return e[n]}function Z(e){return I(e.type)?[]:e.type==="boolean"?!1:e.type==="number"||e.type==="integer"?null:e.type==="enum"?e.default??e.values[0]:""}function M(e,t){if(e!=null)switch(t.type){case"string":{const r=T(e,t);return r===void 0?void 0:r}case"enum":{const r=String(typeof e=="string"?e:e?.value??e).trim().toLowerCase().replace(/[.!]+$/,""),n=t.aliasMap.get(r)??t.aliasMap.get(r.replace(/^(?:a|an|the)\s+/,""));return n||(t.default!==void 0?t.default:void 0)}case"number":case"integer":{const r=typeof e=="number"?e:Number(String(e).replace(/[^0-9.eE+-]/g,""));if(!Number.isFinite(r))return;const n=t.type==="integer"?Math.round(r):r;return t.min!=null&&n<t.min?t.min:t.max!=null&&n>t.max?t.max:n}case"boolean":{if(typeof e=="boolean")return e;const r=String(e).trim().toLowerCase();return/^(?:true|yes|y|1)$/.test(r)?!0:/^(?:false|no|n|0)$/.test(r)?!1:void 0}case"string[]":case"number[]":case"object[]":{const r=Array.isArray(e)?e:e===""?[]:[e],n=t.type==="string[]"?s=>T(s,{max:t.itemMax,emptyIf:t.itemEmptyIf}):t.type==="number[]"?s=>M(s,{type:"number",min:t.min,max:t.max}):s=>b(s)?R(s,{order:t.order,fields:t.fields,strictRequired:!0},{partial:!1}):void 0,i=[],l=new Set;for(const s of r){const o=n(s);if(!(o==null||o===""||o===w)){if(t.dedupe!==!1){const u=typeof o=="object"?JSON.stringify(o):String(o).toLowerCase();if(l.has(u))continue;l.add(u)}if(i.push(o),t.maxItems&&i.length>=t.maxItems)break}}return i}default:return}}function T(e,t={}){if(e==null)return;const r=typeof e=="string"?e:b(e)?String(e.value??e.text??e.name??""):String(e);let n=t.multiline?r.replace(/\r\n?/g,`
5
+ `).replace(/[ \t]+/g," ").replace(/ *\n */g,`
6
+ `).replace(/\n{3,}/g,`
7
+
8
+ `).trim():r.replace(/\s+/g," ").trim();if(t.emptyIf&&t.emptyIf.test(n)||E.test(n))return"";if(n=n.replace(/^["'`]+|["'`]+$/g,"").trim(),t.max&&n.length>t.max){const i=n.slice(0,t.max);n=/\s/.test(i)?i.replace(/\s+\S*$/,""):i}return n}function ce(e){return E.test(String(e??"").trim())}const X=/[{}[\]",:]/,ee=12;function fe(e,{onChange:t=null}={}){let r="",n=0,i=null,l="";const s=o=>{const u=C(r,e,{partial:o});if(u){i=u;const d=JSON.stringify(u.value);d!==l&&(l=d,t?.(u.value,u.settled))}return n=0,i};return{push(o){const u=String(o??"");return u&&(r+=u,n+=u.length),u&&(X.test(u)||n>=ee)&&s(!0),this.snapshot()},end(){return s(!1),i||s(!0),this.snapshot()},snapshot(){return{value:i?.value??null,settled:i?.settled??[],complete:!!i?.complete,source:i?.source??null,text:r}},reset(){r="",n=0,i=null,l=""},get text(){return r}}}export{P as FIELD_TYPES,le as RESPONSE_MODES,m as StructuredError,C as coerce,fe as createStructuredStream,re as defineSchema,ie as describeSchema,F as findJson,ce as isNothing,ue as parseStructured,oe as repairJson,se as responseFormat,z as rewriteJson,U as toJsonSchema,v as unfence};