friend-assistant 0.1.10 → 0.1.12

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/dist/BUILD.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.10",
4
- "builtAt": "2026-10-09T16:43:32.038Z"
3
+ "version": "0.1.12",
4
+ "builtAt": "2026-10-10T02:03:49.747Z"
5
5
  }
package/dist/friend.mjs CHANGED
@@ -503,6 +503,12 @@ var VOICE_CHOICES = [
503
503
  { id: "en_GB-alan-medium", name: "Alan", gender: "male", accent: "British" },
504
504
  { id: "en_GB-northern_english_male-medium", name: "Tom", gender: "male", accent: "Northern English" }
505
505
  ];
506
+ var HINDI_VOICES = [
507
+ { id: "hi_IN-priyamvada-medium", name: "Priyamvada", gender: "female", accent: "Hindi", note: "for personal use (non-commercial licence)" },
508
+ { id: "hi_IN-pratham-medium", name: "Pratham", gender: "male", accent: "Hindi", note: "for personal use (non-commercial licence)" },
509
+ { id: "hi_IN-rohan-medium", name: "Rohan", gender: "male", accent: "Hindi" }
510
+ ];
511
+ var MARATHI_VOICES = [{ id: "mr_IN-google-medium", name: "Marathi", gender: "female", accent: "Marathi" }];
506
512
  var DEFAULT_HINDI_VOICE = "hi_IN-priyamvada-medium";
507
513
  var DEFAULT_MARATHI_VOICE = "mr_IN-google-medium";
508
514
  var ORIGINAL_VOICE = {
@@ -6851,7 +6857,10 @@ async function createApp(opts) {
6851
6857
  connectors: connectorsApi,
6852
6858
  voicePreview: async (id2) => {
6853
6859
  if (!voice2 || !voiceAvailable()) throw new HttpError(503, "Voice is not available. Run: friend voice setup");
6854
- if (!isCatalogVoice(id2) && id2 !== config.voice.ttsVoice) throw new HttpError(400, "That voice is not in the list.");
6860
+ const indian = [...HINDI_VOICES, ...MARATHI_VOICES].some((v) => v.id === id2) || id2 === config.voice.hindiVoice || id2 === config.voice.marathiVoice;
6861
+ if (!isCatalogVoice(id2) && !indian && id2 !== config.voice.ttsVoice) throw new HttpError(400, "That voice is not in the list.");
6862
+ if (id2.startsWith("hi_")) return voice2.synthesize("\u0928\u092E\u0938\u094D\u0924\u0947, \u092E\u0948\u0902 \u0906\u092A\u0915\u0940 \u0938\u0939\u093E\u092F\u0915 \u0939\u0942\u0901\u0964 \u092E\u0947\u0930\u0940 \u0906\u0935\u093E\u091C\u093C \u0910\u0938\u0940 \u0939\u0948\u0964", id2);
6863
+ if (id2.startsWith("mr_")) return voice2.synthesize("\u0928\u092E\u0938\u094D\u0915\u093E\u0930, \u092E\u0940 \u0924\u0941\u092E\u091A\u0940 \u092E\u0926\u0924\u0928\u0940\u0938 \u0906\u0939\u0947. \u092E\u093E\u091D\u093E \u0906\u0935\u093E\u091C \u0905\u0938\u093E \u0906\u0939\u0947.", id2);
6855
6864
  return voice2.synthesize(`Hello, I am ${auth.assistantName()}. This is how I sound.`, id2);
6856
6865
  },
6857
6866
  config,
@@ -9585,7 +9594,7 @@ async function daemonCommand(args, io2, deps = realDeps) {
9585
9594
  import crossSpawn5 from "cross-spawn";
9586
9595
  var PACKAGE = "friend-assistant";
9587
9596
  var real = {
9588
- current: () => true ? "0.1.10" : "development",
9597
+ current: () => true ? "0.1.12" : "development",
9589
9598
  latest: () => new Promise((resolve10) => {
9590
9599
  const child = crossSpawn5("npm", ["view", PACKAGE, "version", "--prefer-online"], { stdio: ["ignore", "pipe", "ignore"] });
9591
9600
  let out = "";
@@ -9838,7 +9847,7 @@ async function run(argv, io2) {
9838
9847
  case "version":
9839
9848
  case "--version":
9840
9849
  case "-v":
9841
- io2.out(true ? "0.1.10" : "development");
9850
+ io2.out(true ? "0.1.12" : "development");
9842
9851
  return 0;
9843
9852
  case "lan":
9844
9853
  return await lanCommand(rest, io2);
@@ -4382,7 +4382,7 @@ void main() {
4382
4382
 
4383
4383
  `)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=Lu,c=!Nd.jitless,l=c&&Ru.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?um([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function pm(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!rd(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>cd(e,r,Pd())))}),t)}var mm=Z(`$ZodUnion`,(e,t)=>{up.init(e,t),Cd(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),Cd(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),Cd(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),Cd(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>wu(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>pm(t,r,e,i)):pm(o,r,e,i)}});function hm(e){let t=new Map;for(let n of e.options){let r=n._zod.propValues?.[e.discriminator];if(!r||r.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(n)}"`);for(let e of r)if(t.has(e)){if(e!==void 0)throw Error(`Duplicate discriminator value "${String(e)}"`);t.set(e,null)}else t.set(e,n)}return t}var gm=Z(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,mm.init(e,t);let n=e._zod.parse;Cd(e,`propValues`,e=>{let t={},n=0;for(let r of e.def.options){let i=r._zod.propValues;if(!i||Object.keys(i).length===0)throw Error(`Invalid discriminated union option at index "${e.def.options.indexOf(r)}"`);i[e.def.discriminator]?.has(void 0)&&n++;for(let[e,n]of Object.entries(i)){Object.prototype.hasOwnProperty.call(t,e)||Eu(t,e,new Set);for(let r of n)t[e].add(r)}}return!e.def.unionFallback&&n>1&&t[e.def.discriminator]?.delete(void 0),t}),t.options.forEach((e,n)=>{let r=Du(e._zod.def);if(r&&!Object.prototype.hasOwnProperty.call(r,t.discriminator))throw Error(`Invalid discriminated union option at index "${n}"`)});let r=Su(()=>hm(t));e._zod.parse=(i,a)=>{let o=i.value;if(!Lu(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=o?.[t.discriminator],c=r.value.get(s);return c&&(s!==void 0||a.direction!==`backward`)?c._zod.run(i,a):t.unionFallback||a.direction===`backward`?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,options:Array.from(r.value.keys()).filter(e=>r.value.get(e)!==null),input:o,path:[t.discriminator],inst:e}),i)}}),_m=Z(`$ZodIntersection`,(e,t)=>{up.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>ym(e,t,n)):ym(e,i,a)}});function vm(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(zu(e)&&zu(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=vm(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=vm(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function ym(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=vm(t.value,n.value);if(!c.valid){if(rd(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var bm=Z(`$ZodRecord`,(e,t)=>{up.init(e,t);let n=Nd.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!zu(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>cd(e,i,Pd())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...ad(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...ad(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&Bf.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>cd(e,i,Pd())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...ad(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...ad(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),xm=Z(`$ZodEnum`,(e,t)=>{up.init(e,t);let n=vu(t.entries),r=new Set(n);e._zod.values=r,Cd(e,`pattern`,e=>{let t=vu(e.def.entries).filter(e=>Vu.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Hu(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Sm=Z(`$ZodLiteral`,(e,t)=>{up.init(e,t);let n=new Set(t.values);e._zod.values=n,Cd(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?Hu(e):e?Hu(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Cm=Z(`$ZodTransform`,(e,t)=>{up.init(e,t),e._zod.optin=`optional`,Nd.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Md(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new jd;return n.value=i,n}});function wm(e,t){return e.value=t.issues.length?void 0:t.value,e}var Tm=Z(`$ZodOptional`,(e,t)=>{up.init(e,t),Cd(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,Cd(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),Cd(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${wu(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>wm(e,t)):wm(e,r)}return t.innerType._zod.run(e,n)}}),Em=Z(`$ZodExactOptional`,(e,t)=>{Tm.init(e,t),Cd(e,`values`,e=>e.def.innerType._zod.values),Cd(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),Dm=Z(`$ZodNullable`,(e,t)=>{up.init(e,t),Cd(e,`optin`,e=>e.def.innerType._zod.optin),Cd(e,`optout`,e=>e.def.innerType._zod.optout),Cd(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${wu(t.source)}|null)$`):void 0}),Cd(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),Om=Z(`$ZodDefault`,(e,t)=>{up.init(e,t),e._zod.optin=`defaulted`,Cd(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>km(e,t)):km(r,t)}});function km(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var Am=Z(`$ZodPrefault`,(e,t)=>{up.init(e,t),e._zod.optin=`defaulted`,Cd(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),jm=Z(`$ZodNonOptional`,(e,t)=>{up.init(e,t),Cd(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Mm(t,e)):Mm(i,e)}});function Mm(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function Nm(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>cd(e,r,Pd()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var Pm=Z(`$ZodCatch`,(e,t)=>{up.init(e,t),Cd(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),Cd(e,`optout`,e=>e.def.innerType._zod.optout),Cd(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>Nm(e,r,t,n)):Nm(e,r,t,n)}}),Fm=Z(`$ZodPipe`,(e,t)=>{up.init(e,t),Cd(e,`values`,e=>e.def.in._zod.values),Cd(e,`optin`,e=>e.def.in._zod.optin),Cd(e,`optout`,e=>e.def.out._zod.optout),Cd(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Im(e,t.in,n)):Im(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Im(e,t.out,n)):Im(r,t.out,n)}});function Im(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var Lm=Z(`$ZodReadonly`,(e,t)=>{up.init(e,t),Cd(e,`propValues`,e=>e.def.innerType._zod.propValues),Cd(e,`values`,e=>e.def.innerType._zod.values),Cd(e,`optin`,e=>e.def.innerType?._zod?.optin),Cd(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Rm):Rm(r)}});function Rm(e){return e.memo||(e.value=Object.freeze(e.value)),e}var zm=Z(`$ZodCustom`,(e,t)=>{Wf.init(e,t),up.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Bm(t,n,r,e));Bm(i,n,r,e)}});function Bm(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(pd(e))}}var Vm=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},Hm=`~memo`,Um=[];function Wm(e){return typeof e==`object`&&!!e}function Gm(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var Km=new WeakMap,qm=0,Jm=1,Ym=2;function Xm(e,t,n){let r=Km.get(e);if(r!==void 0)return r?Ym:qm;if(t.has(e))return Ym;t.add(e);let i=qm,a=e=>{if(i!==Ym&&e?._zod){let r=Xm(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=qm;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?Jm:o.value?._zod?Xm(o.value,t,n):qm;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=Du(c);s(e?o(e,!0):Jm),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Xm(r,t,!1):Jm);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Zm(e,i)}function Zm(e,t){return t!==Jm&&Km.set(e,t===Ym),t}function Qm(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var $m,eh=[],th={alloc(e,t,n){let r=$m;if(!r)return n;$m=void 0;let i={value:n,issues:null};return r.set(t.value,i),eh.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&rh(n,e.value))throw new Vm;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Xm(e,new Set,!1);if(i===qm)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===Ym||r?n=!0:r=!0}let l=s.value;if(!Wm(l))return t(s,c);let u=c[Hm];u||(u={buckets:new WeakMap,backEdges:void 0},c[Hm]=u);let d;i===c?d=a:(d=Qm(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...Gm(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;$m=d;let p=eh.length,m=t(s,c);$m=void 0;let h=eh.length>p?eh.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?Gm(e.issues):Um),e)):(h&&(h.issues=m.issues.length?Gm(m.issues):Um),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function nh(){return th}function rh(e,t){let n=e[Hm]?.backEdges;return n!==void 0&&Wm(t)&&n.has(t)}var ih=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(fd(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Wu(e.values[0])}`:`Invalid option: expected one of ${yu(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${yu(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function ah(){return{localeError:ih()}}var oh,sh=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function ch(){return new sh}(oh=globalThis).__zod_globalRegistry??(oh.__zod_globalRegistry=ch());var lh=globalThis.__zod_globalRegistry;function uh(e){return e.checks&&=[...e.checks],e}function dh(e,t){return new e(uh({type:`string`,...X(t)}))}function fh(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...X(t)})}function ph(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...X(t)})}function mh(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...X(t)})}function hh(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...X(t)})}function gh(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...X(t)})}function _h(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...X(t)})}function vh(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...X(t)})}function yh(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...X(t)})}function bh(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...X(t)})}function xh(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...X(t)})}function Sh(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...X(t)})}function Ch(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...X(t)})}function wh(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...X(t)})}function Th(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...X(t)})}function Eh(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...X(t)})}function Dh(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...X(t)})}function Oh(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...X(t)})}function kh(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...X(t)})}function Ah(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...X(t)})}function jh(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...X(t)})}function Mh(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...X(t)})}function Nh(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...X(t)})}function Ph(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...X(t)})}function Fh(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...X(t)})}function Ih(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...X(t)})}function Lh(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...X(t)})}function Rh(e,t){return new e(uh({type:`number`,checks:[],...X(t)}))}function zh(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...X(t)})}function Bh(e,t){return new e({type:`boolean`,...X(t)})}function Vh(e){return new e({type:`unknown`})}function Hh(e,t){return new e({type:`never`,...X(t)})}function Uh(e,t){return new qf({check:`less_than`,...X(t),value:e,inclusive:!1})}function Wh(e,t){return new qf({check:`less_than`,...X(t),value:e,inclusive:!0})}function Gh(e,t){return new Jf({check:`greater_than`,...X(t),value:e,inclusive:!1})}function Kh(e,t){return new Jf({check:`greater_than`,...X(t),value:e,inclusive:!0})}function qh(e,t){return new Yf({check:`multiple_of`,...X(t),value:e})}function Jh(e,t){return new Zf({check:`max_length`,...X(t),maximum:e})}function Yh(e,t){return new Qf({check:`min_length`,...X(t),minimum:e})}function Xh(e,t){return new $f({check:`length_equals`,...X(t),length:e})}function Zh(e,t){return new tp({check:`string_format`,format:`regex`,...X(t),pattern:e})}function Qh(e){return new np({check:`string_format`,format:`lowercase`,...X(e)})}function $h(e){return new rp({check:`string_format`,format:`uppercase`,...X(e)})}function eg(e,t){return new ip({check:`string_format`,format:`includes`,...X(t),includes:e})}function tg(e,t){return new ap({check:`string_format`,format:`starts_with`,...X(t),prefix:e})}function ng(e,t){return new op({check:`string_format`,format:`ends_with`,...X(t),suffix:e})}function rg(e){return new sp({check:`overwrite`,tx:e})}function ig(e){return rg(t=>t.normalize(e))}function ag(){return rg(e=>e.trim())}function og(){return rg(e=>e.toLowerCase())}function sg(){return rg(e=>e.toUpperCase())}function cg(){return rg(e=>Fu(e))}function lg(e,t,n){return new e({type:`array`,element:t,...X(n)})}function ug(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...X(n)})}function dg(e,t){let n=fg(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(pd(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(pd(r))}},e(t.value,t)),t);return n}function fg(e,t){let n=new Wf({check:`custom`,...X(t)});return n._zod.check=e,n}function pg(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&Eu(e,t,n[t]);return e}function mg(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??lh,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function hg(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function gg(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,gg(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&pg(o.schema,c),t.io===`input`&&Eg(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function _g(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function vg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${_g(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+_g(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
4384
4384
 
4385
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function yg(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;yg(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var bg=new Set([`type`,`properties`,`required`,`additionalProperties`]),xg=[`oneOf`,`anyOf`];function Sg(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Cg(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!bg.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Sg(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Eu(n,r,e.length===1?e[0]:Cg(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Sg(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function wg(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of bg)if(t in e)return;let n=t.filter(e=>xg.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Cg(t);else{let e=n[0],i=xg.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Cg([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,pg(e,r))}function Tg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):pg(i,s),pg(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())yg(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])wg(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}pg(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Eu(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Og(t,`input`,e.processors),output:Og(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Eg(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Eg(r.element,n);if(r.type===`set`)return Eg(r.valueType,n);if(r.type===`lazy`)return Eg(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Eg(r.innerType,n);if(r.type===`intersection`)return Eg(r.left,n)||Eg(r.right,n);if(r.type===`record`||r.type===`map`)return Eg(r.keyType,n)||Eg(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Eg(r.in,n)||Eg(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Eg(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Eg(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Eg(e,n))return!0;return!!(r.rest&&Eg(r.rest,n))}return!1}var Dg=(e,t={})=>n=>{let r=mg({...n,processors:t});return gg(e,r),vg(r,e),Tg(r,e)},Og=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=mg({...i??{},target:a,io:t,processors:n});return gg(e,o),vg(o,e),Tg(o,e)},kg=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Ag=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},jg=(e,t)=>{kg(e,`minimum`,t),Ag(e,`maximum`,t)},Mg=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Ng=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Pg=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Fg=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ig=(e,t)=>kg(e,`minimum`,t.minimum),Lg=(e,t)=>Ag(e,`maximum`,t.maximum),Rg=e=>(t,n)=>{Fg(t,n.format);let[r,i]=e[n.format];kg(t,`minimum`,r),Ag(t,`maximum`,i)},zg={greater_than:(e,t)=>kg(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Ag(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Mg(e,t.value),number_format:Rg(Ku),bigint_format:Rg(qu),min_length:Ig,max_length:Lg,length_equals:(e,t)=>jg(e,t.length),min_size:Ig,max_size:Lg,size_equals:(e,t)=>jg(e,t.size),string_format:(e,t)=>{Fg(e,t.format),t.pattern&&Ng(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Pg(e,t.mime)};function Bg(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)zg[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&kg(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&kg(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Ag(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Ag(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Mg(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Pg(t,i.mime);for(let e of i.patterns??[])Ng(t,e);return t}var Vg={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Hg=new Map([[Kp,Of],[Jp,kf]]),Ug=e=>Hg.get(e)??e,Wg=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Bg(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Vg[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Ug);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Gg=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Bg(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):hg(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Kg=(e,t,n,r)=>{n.type=`boolean`},qg=(e,t,n,r)=>{n.not={}},Jg=(e,t,n,r)=>{let i=e._zod.def,a=vu(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Yg=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(hg(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(hg(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Xg=(e,t,n,r)=>{hg(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Zg=(e,t,n,r)=>{hg(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Qg=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Bg(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=gg(a.element,t,{...r,path:[...r.path,`items`]})};function $g(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?$g(t.out):t.type===`catch`?$g(t.innerType):e._zod.optin}var e_=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&hg(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Eu(i.properties,e,gg(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?$g(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=gg(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},t_=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>gg(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},n_=(e,t,n,r)=>{let i=e._zod.def,a=gg(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=gg(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function r_(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=r_(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>r_(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?Bf:zf).source),p):p}var i_=new WeakMap;function a_(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of i_.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=r_(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}var o_=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=Bg(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=gg(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Eu(i.patternProperties,Ug(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=gg(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=i_.get(t);n||(n=[],i_.set(t,n),t.deferred.push(()=>a_(t))),n.push(e)}i.additionalProperties=gg(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&$g(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},s_=(e,t,n,r)=>{let i=e._zod.def,a=gg(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},c_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},l_=Symbol();function u_(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(hg(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),l_):JSON.parse(o)}var d_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=u_(i.defaultValue,e,t,n,r);o!==l_&&(n.default=o)},f_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=u_(i.defaultValue,e,t,n,r);o!==l_&&(n._prefault=o)},p_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{hg(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},m_=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;gg(o,t,r);let s=t.seen.get(e);s.ref=o},h_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},g_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},__=new WeakSet([Object.prototype,Error.prototype]);function v_(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var y_=Z(`ZodError`,(e,t)=>{Vd.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);__.has(n)||(__.add(n),v_(n,`format`,e=>t=>Wd(e,t)),v_(n,`flatten`,e=>t=>Ud(e,t)),v_(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,bu,2)}),v_(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,bu,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),b_=Kd(y_),x_=qd(y_),S_=Jd(y_),C_=Xd(y_),w_=nf(y_),T_=rf(y_),E_=af(y_),D_=of(y_),O_=sf(y_),k_=cf(y_),A_=lf(y_),j_=uf(y_);function M_(){Nd.localeError||Pd(ah())}function N_(){Nd.memoizer||Pd({memoizer:nh()})}var P_=Z(`ZodType`,(e,t)=>(M_(),up.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Nu(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Uu(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check($v(e,t))},superRefine(e,t){return this.check(ey(e,t))},overwrite(e){return this.check(rg(e))},optional(){return Fv(this)},exactOptional(){return Lv(this)},nullable(){return zv(this)},nullish(){return Fv(zv(this))},nonoptional(e){return Gv(this,e)},array(){return vv(this)},or(e){return xv([this,e])},and(e){return Tv(this,e)},transform(e){return Yv(this,Nv(e))},default(e){return Vv(this,e)},prefault(e){return Uv(this,e)},catch(e){return qv(this,e)},pipe(e){return Yv(this,e)},readonly(){return Zv(this)},describe(e){let t=this.clone();return lh.add(t,{description:e}),t},meta(...e){if(e.length===0)return lh.get(this);let t=this.clone();return lh.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return gd(this,`~standard`,{...pp(this),jsonSchema:{input:Og(this,`input`),output:Og(this,`output`)}})},set"~standard"(e){hd(this,`~standard`,e)},parse:function e(t,n){return b_(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await x_(this,t,n,{callee:e})},safeParse(e,t){return S_(this,e,t)},async safeParseAsync(e,t){return C_(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){hd(this,`spa`,e)},validate(e,t){return $d(this,e,t)},validateAsync(e,t){return tf(this,e,t)},encode:function e(t,n){return w_(this,t,n,{callee:e})},decode:function e(t,n){return T_(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await E_(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await D_(this,t,n,{callee:e})},safeEncode(e,t){return O_(this,e,t)},safeDecode(e,t){return k_(this,e,t)},async safeEncodeAsync(e,t){return A_(this,e,t)},async safeDecodeAsync(e,t){return j_(this,e,t)},toJSONSchema(e){return Dg(this,{})(e)},get description(){return lh.get(this)?.description},get _def(){return this._zod.def}}),F_=Z(`_ZodString`,(e,t)=>{mp.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wg(e,t,n,r)},_d({format:e=>Bg(e).format??null,minLength:e=>Bg(e).minimum??null,maxLength:e=>Bg(e).maximum??null},{regex(...e){return this.check(Zh(...e))},includes(...e){return this.check(eg(...e))},startsWith(...e){return this.check(tg(...e))},endsWith(...e){return this.check(ng(...e))},min(...e){return this.check(Yh(...e))},max(...e){return this.check(Jh(...e))},length(...e){return this.check(Xh(...e))},nonempty(...e){return this.check(Yh(1,...e))},lowercase(e){return this.check(Qh(e))},uppercase(e){return this.check($h(e))},trim(){return this.check(ag())},normalize(...e){return this.check(ig(...e))},toLowerCase(){return this.check(og())},toUpperCase(){return this.check(sg())},slugify(){return this.check(cg())}})),I_=Z(`ZodString`,(e,t)=>{mp.init(e,t),F_.init(e,t)},{email(e){return this.check(fh(H_,e))},url(e){return this.check(vh(G_,e))},jwt(e){return this.check(Nh(ov,e))},emoji(e){return this.check(yh(K_,e))},guid(e){return this.check(ph(U_,e))},uuid(e){return this.check(mh(W_,e))},uuidv4(e){return this.check(hh(W_,e))},uuidv6(e){return this.check(gh(W_,e))},uuidv7(e){return this.check(_h(W_,e))},nanoid(e){return this.check(bh(q_,e))},cuid(e){return this.check(xh(J_,e))},cuid2(e){return this.check(Sh(Y_,e))},ulid(e){return this.check(Ch(X_,e))},base64(e){return this.check(Ah(rv,e))},base64url(e){return this.check(jh(iv,e))},xid(e){return this.check(wh(Z_,e))},ksuid(e){return this.check(Th(Q_,e))},ipv4(e){return this.check(Eh($_,e))},ipv6(e){return this.check(Dh(ev,e))},cidrv4(e){return this.check(Oh(tv,e))},cidrv6(e){return this.check(kh(nv,e))},e164(e){return this.check(Mh(av,e))},datetime(e){return this.check(Ph(R_,e))},date(e){return this.check(Fh(z_,e))},time(e){return this.check(Ih(B_,e))},duration(e){return this.check(Lh(V_,e))}});function Q(e){return dh(I_,e)}var L_=Z(`ZodStringFormat`,(e,t)=>{hp.init(e,t),F_.init(e,t)}),R_=Z(`ZodISODateTime`,(e,t)=>{Pp.init(e,t),L_.init(e,t)}),z_=Z(`ZodISODate`,(e,t)=>{Fp.init(e,t),L_.init(e,t)}),B_=Z(`ZodISOTime`,(e,t)=>{Ip.init(e,t),L_.init(e,t)}),V_=Z(`ZodISODuration`,(e,t)=>{Lp.init(e,t),L_.init(e,t)}),H_=Z(`ZodEmail`,(e,t)=>{vp.init(e,t),L_.init(e,t)}),U_=Z(`ZodGUID`,(e,t)=>{gp.init(e,t),L_.init(e,t)}),W_=Z(`ZodUUID`,(e,t)=>{_p.init(e,t),L_.init(e,t)}),G_=Z(`ZodURL`,(e,t)=>{Ep.init(e,t),L_.init(e,t)}),K_=Z(`ZodEmoji`,(e,t)=>{Dp.init(e,t),L_.init(e,t)}),q_=Z(`ZodNanoID`,(e,t)=>{Op.init(e,t),L_.init(e,t)}),J_=Z(`ZodCUID`,(e,t)=>{kp.init(e,t),L_.init(e,t)}),Y_=Z(`ZodCUID2`,(e,t)=>{Ap.init(e,t),L_.init(e,t)}),X_=Z(`ZodULID`,(e,t)=>{jp.init(e,t),L_.init(e,t)}),Z_=Z(`ZodXID`,(e,t)=>{Mp.init(e,t),L_.init(e,t)}),Q_=Z(`ZodKSUID`,(e,t)=>{Np.init(e,t),L_.init(e,t)}),$_=Z(`ZodIPv4`,(e,t)=>{Rp.init(e,t),L_.init(e,t)}),ev=Z(`ZodIPv6`,(e,t)=>{Vp.init(e,t),L_.init(e,t)}),tv=Z(`ZodCIDRv4`,(e,t)=>{Hp.init(e,t),L_.init(e,t)}),nv=Z(`ZodCIDRv6`,(e,t)=>{Wp.init(e,t),L_.init(e,t)}),rv=Z(`ZodBase64`,(e,t)=>{qp.init(e,t),L_.init(e,t)}),iv=Z(`ZodBase64URL`,(e,t)=>{Xp.init(e,t),L_.init(e,t)}),av=Z(`ZodE164`,(e,t)=>{Zp.init(e,t),L_.init(e,t)}),ov=Z(`ZodJWT`,(e,t)=>{$p.init(e,t),L_.init(e,t)}),sv=Z(`ZodNumber`,(e,t)=>{em.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gg(e,t,n,r),e.isFinite=!0},_d({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Bg(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Bg(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Bg(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Bg(e).format??null},{gt(e,t){return this.check(Gh(e,t))},gte(e,t){return this.check(Kh(e,t))},min(e,t){return this.check(Kh(e,t))},lt(e,t){return this.check(Uh(e,t))},lte(e,t){return this.check(Wh(e,t))},max(e,t){return this.check(Wh(e,t))},int(e){return this.check(uv(e))},safe(e){return this.check(uv(e))},positive(e){return this.check(Gh(0,e))},nonnegative(e){return this.check(Kh(0,e))},negative(e){return this.check(Uh(0,e))},nonpositive(e){return this.check(Wh(0,e))},multipleOf(e,t){return this.check(qh(e,t))},step(e,t){return this.check(qh(e,t))},finite(){return this}}));function cv(e){return Rh(sv,e)}var lv=Z(`ZodNumberFormat`,(e,t)=>{tm.init(e,t),sv.init(e,t)});function uv(e){return zh(lv,e)}var dv=Z(`ZodBoolean`,(e,t)=>{nm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kg(e,t,n,r)});function fv(e){return Bh(dv,e)}var pv=Z(`ZodUnknown`,(e,t)=>{rm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function mv(){return Vh(pv)}var hv=Z(`ZodNever`,(e,t)=>{im.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qg(e,t,n,r)});function gv(e){return Hh(hv,e)}var _v=Z(`ZodArray`,(e,t)=>{N_(),om.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.element=t.element},{min(e,t){return this.check(Yh(e,t))},nonempty(e){return this.check(Yh(1,e))},max(e,t){return this.check(Jh(e,t))},length(e,t){return this.check(Xh(e,t))},unwrap(){return this.element}});function vv(e,t){return lg(_v,e,t)}var yv=Z(`ZodObject`,(e,t)=>{N_(),fm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>e_(e,t,n,r),wd(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return kv(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Nu(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Nu(this._zod.def,{catchall:mv()}))},loose(){return this.clone(Nu(this._zod.def,{catchall:mv()}))},strict(){return this.clone(Nu(this._zod.def,{catchall:gv()}))},strip(){return this.clone(Nu(this._zod.def,{catchall:void 0}))},extend(e){return Zu(this,e)},safeExtend(e){return $u(this,e)},merge(e){return ed(this,e)},pick(e){return Ju(this,e)},omit(e){return Xu(this,e)},partial(...e){return td(Pv,this,e[0])},exactPartial(...e){return td(Iv,this,e[0],`exactPartial`)},required(...e){return nd(Wv,this,e[0])}});function $(e,t){return new yv({type:`object`,shape:e??{},...X(t)})}var bv=Z(`ZodUnion`,(e,t)=>{mm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>t_(e,t,n,r),e.options=t.options});function xv(e,t){return new bv({type:`union`,options:e,...X(t)})}var Sv=Z(`ZodDiscriminatedUnion`,(e,t)=>{bv.init(e,t),gm.init(e,t)});function Cv(e,t,n){return new Sv({type:`union`,options:t,discriminator:e,...X(n)})}var wv=Z(`ZodIntersection`,(e,t)=>{_m.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>n_(e,t,n,r)});function Tv(e,t){return new wv({type:`intersection`,left:e,right:t})}var Ev=Z(`ZodRecord`,(e,t)=>{N_(),bm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>o_(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Dv(e,t,n){return!t||!t._zod?new Ev({type:`record`,keyType:Q(),valueType:e,...X(t)}):new Ev({type:`record`,keyType:e,valueType:t,...X(n)})}var Ov=Z(`ZodEnum`,(e,t)=>{xm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jg(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ov({...t,checks:[],...X(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ov({...t,checks:[],...X(r),entries:i})}});function kv(e,t){return new Ov({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...X(t)})}var Av=Z(`ZodLiteral`,(e,t)=>{Sm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yg(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function jv(e,t){return new Av({type:`literal`,values:Array.isArray(e)?e:[e],...X(t)})}var Mv=Z(`ZodTransform`,(e,t)=>{N_(),Cm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zg(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Md(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(pd(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(pd(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Nv(e){return new Mv({type:`transform`,transform:e})}var Pv=Z(`ZodOptional`,(e,t)=>{Tm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>g_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fv(e){return new Pv({type:`optional`,innerType:e})}var Iv=Z(`ZodExactOptional`,(e,t)=>{Em.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>g_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Lv(e){return new Iv({type:`optional`,innerType:e})}var Rv=Z(`ZodNullable`,(e,t)=>{Dm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>s_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function zv(e){return new Rv({type:`nullable`,innerType:e})}var Bv=Z(`ZodDefault`,(e,t)=>{Om.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>d_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Vv(e,t){return new Bv({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bu(t)}})}var Hv=Z(`ZodPrefault`,(e,t)=>{Am.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>f_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uv(e,t){return new Hv({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bu(t)}})}var Wv=Z(`ZodNonOptional`,(e,t)=>{jm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>c_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Gv(e,t){return new Wv({type:`nonoptional`,innerType:e,...X(t)})}var Kv=Z(`ZodCatch`,(e,t)=>{Pm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>p_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function qv(e,t){return new Kv({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ed(t)})}var Jv=Z(`ZodPipe`,(e,t)=>{Fm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>m_(e,t,n,r),e.in=t.in,e.out=t.out});function Yv(e,t){return new Jv({type:`pipe`,in:e,out:t})}var Xv=Z(`ZodReadonly`,(e,t)=>{Lm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>h_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Zv(e){return new Xv({type:`readonly`,innerType:e})}var Qv=Z(`ZodCustom`,(e,t)=>{zm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xg(e,t,n,r)});function $v(e,t={}){return ug(Qv,e,t)}function ey(e,t){return dg(e,t)}var ty=kv([`T0`,`T1`,`T2`,`T3`]);kv([`owner`,`guest`,`member`]);var ny=cv().min(0).max(1),ry=xv([kv([`auto`,`center`,`left`,`right`,`top`,`bottom`]),$({x:ny,y:ny,w:ny,h:ny})]),iy=kv([`ambient`,`conversation`,`focus`,`multi`]),ay=kv([`idle`,`listening`,`thinking`,`speaking`]),oy=kv([`sphere`,`orb`,`ring`]),sy=$({id:Q().min(1).max(64),type:kv([`card`,`stat`,`list`,`table`,`code`,`chart`,`gauge`,`timeline`,`graph`,`sandbox`]),props:Dv(Q(),mv()),placement:ry,ttl:cv().positive().max(3600).optional(),style:kv([`glass`,`alert`]).optional(),pinned:fv().optional()}),cy=Cv(`cmd`,[$({cmd:jv(`scene`),mode:iy}),$({cmd:jv(`show`),object:sy}),$({cmd:jv(`update`),id:Q(),props:Dv(Q(),mv())}),$({cmd:jv(`hide`),id:Q()}),$({cmd:jv(`clear`)}),$({cmd:jv(`pin`),id:Q()}),$({cmd:jv(`unpin`),id:Q()}),$({cmd:jv(`place`),id:Q(),placement:ry}),$({cmd:jv(`presence`),state:ay.optional(),style:oy.optional()}),$({cmd:jv(`mood`),accent:Q().max(16).optional(),intensity:ny.optional()})]),ly=$({scene:iy,objects:vv(sy),presence:$({state:ay,style:oy}),mood:$({accent:Q(),intensity:ny})}),uy={center:[20,18,60,58],left:[3,12,30,70],right:[67,12,30,70],top:[20,4,60,30],bottom:[20,62,60,30]};Object.keys(uy);var dy=[{id:`en_US-amy-medium`,name:`Amy`,gender:`female`,accent:`American`},{id:`en_US-kristin-medium`,name:`Kristin`,gender:`female`,accent:`American`},{id:`en_US-hfc_female-medium`,name:`Hannah`,gender:`female`,accent:`American`,note:`clear and steady`},{id:`en_GB-jenny_dioco-medium`,name:`Jenny`,gender:`female`,accent:`British`},{id:`en_GB-alba-medium`,name:`Alba`,gender:`female`,accent:`Scottish`},{id:`en_US-kathleen-low`,name:`Kathleen`,gender:`female`,accent:`American`,note:`smaller and faster`},{id:`en_US-ryan-medium`,name:`Ryan`,gender:`male`,accent:`American`},{id:`en_US-joe-medium`,name:`Joe`,gender:`male`,accent:`American`},{id:`en_US-norman-medium`,name:`Norman`,gender:`male`,accent:`American`},{id:`en_US-hfc_male-medium`,name:`Henry`,gender:`male`,accent:`American`,note:`clear and steady`},{id:`en_GB-alan-medium`,name:`Alan`,gender:`male`,accent:`British`},{id:`en_GB-northern_english_male-medium`,name:`Tom`,gender:`male`,accent:`Northern English`}],fy=[{id:`hi_IN-priyamvada-medium`,name:`Priyamvada`,gender:`female`,accent:`Hindi`,note:`for personal use (non-commercial licence)`},{id:`hi_IN-pratham-medium`,name:`Pratham`,gender:`male`,accent:`Hindi`,note:`for personal use (non-commercial licence)`},{id:`hi_IN-rohan-medium`,name:`Rohan`,gender:`male`,accent:`Hindi`}],py=[{id:`mr_IN-google-medium`,name:`Marathi`,gender:`female`,accent:`Marathi`}],my={id:`en_US-lessac-medium`,name:`Lessac`,accent:`American`,note:`the original voice`},hy=e=>e===my.id||dy.some(t=>t.id===e),gy=[{id:`aurora`,name:`Aurora`,style:`sphere`,accent:`#3fd8ff`,intensity:.6},{id:`ocean`,name:`Ocean`,style:`sphere`,accent:`#2b7bff`,intensity:.6},{id:`ember`,name:`Ember`,style:`orb`,accent:`#ff9b3d`,intensity:.7},{id:`violet`,name:`Violet storm`,style:`orb`,accent:`#a066ff`,intensity:.8},{id:`matrix`,name:`Matrix`,style:`ring`,accent:`#3dff8c`,intensity:.6},{id:`rose`,name:`Rose`,style:`ring`,accent:`#ff6fae`,intensity:.7},{id:`ghost`,name:`Ghost`,style:`sphere`,accent:`#e8f4ff`,intensity:.4}],_y=kv([`minimal`,`companion`,`workspace`]),vy=$({size:cv().min(.5).max(1.5),reactivity:cv().min(0).max(1),ambient:fv(),captions:fv(),captionSize:kv([`small`,`medium`,`large`])}),yy={width:cv().int().min(100).max(1e4),height:cv().int().min(100).max(1e4),kind:kv([`phone`,`tablet`,`desktop`]),orientation:kv([`portrait`,`landscape`]),touch:fv()};$(yy);var by=$({id:Q(),tool:Q(),summary:Q(),tier:ty,needsPin:fv()}),xy=Cv(`type`,[$({type:jv(`stage`),command:cy}),$({type:jv(`caption.delta`),text:Q()}),$({type:jv(`caption.end`)}),$({type:jv(`approval.request`)}).merge(by),$({type:jv(`approval.resolved`),id:Q()}),$({type:jv(`alert`),level:kv([`info`,`warn`,`error`]),text:Q()}),$({type:jv(`chat.user`),text:Q()}),$({type:jv(`ui`),view:_y,look:vy.optional(),ownerName:Q().max(40).optional()}),$({type:jv(`activity`),text:Q().max(80).nullable()}),$({type:jv(`status`),busy:fv(),deviceOnline:fv(),voiceAvailable:fv().optional(),voiceEnrolled:fv().optional(),message:Q().optional()}),$({type:jv(`voice.heard`),text:Q(),trust:kv([`owner`,`guest`,`unverified`,`member`]).optional(),speaker:Q().max(60).optional()}),$({type:jv(`voice.challenge`),id:Q(),text:Q()}),$({type:jv(`voice.challenge.end`),id:Q()}),$({type:jv(`audio.chunk`),id:Q(),seq:cv().int().min(0),last:fv(),mime:Q(),data:Q()}),$({type:jv(`audio.stop`)}),$({type:jv(`camera.request`),id:Q()}),$({type:jv(`camera.cancel`),id:Q()}),$({type:jv(`snapshot`),stage:ly,pendingApproval:by.nullable().optional()}),$({type:jv(`error`),message:Q()})]),Sy=$({type:jv(`approval.respond`),id:Q(),decision:kv([`approve`,`deny`,`approve_always`]),pin:Q().max(32).optional()});Cv(`type`,[$({type:jv(`chat.send`),text:Q().min(1).max(8e3)}),$({type:jv(`stage.event`),objectId:Q(),event:Q().max(64)}),Sy,$({type:jv(`voice.interrupt`)}),$({type:jv(`voice.confirm`),id:Q(),pin:Q().max(32)}),$({type:jv(`voice.cancel`),id:Q()}),$({type:jv(`camera.denied`),id:Q(),reason:kv([`off`,`no-camera`,`permission`,`busy`])}),$({type:jv(`ui.panels`),open:vv(kv([`chat`,`tasks`])).max(2)}),$({type:jv(`ui.screen`),...yy}),$({type:jv(`stage.move`),objectId:Q().max(64),rect:$({x:cv().min(0).max(1),y:cv().min(0).max(1),w:cv().min(0).max(1),h:cv().min(0).max(1)})}),$({type:jv(`stage.pin`),objectId:Q().max(64),pinned:fv()}),$({type:jv(`ping`)})]),$({type:jv(`tool.exec`),id:Q(),tool:Q(),args:mv(),approvedOutside:fv().optional()}),Cv(`type`,[$({type:jv(`tool.result`),id:Q(),result:$({output:Q(),truncated:fv()})}),$({type:jv(`tool.error`),id:Q(),error:Q()})]),$({path:Q()}),$({path:Q()}),$({path:Q(),content:Q()}),$({}),$({}),$({command:Q().min(1),cwd:Q().optional()}),$({city:Q().min(1).max(80)}),$({plugin:Q().min(1).max(40),name:Q().min(1).max(40)}),$({language:kv([`python`,`node`,`shell`]),code:Q().min(1).max(5e4),timeoutSec:cv().int().min(1).max(60).optional()}),$({text:Q().min(1).max(4e3)}),$({query:Q().min(1).max(200)}),$({id:cv().int().positive()}),$({title:Q().min(1).max(1e3),inMinutes:cv().int().min(1).max(525600).optional(),dueAt:Q().max(40).optional(),repeat:kv([`hourly`,`daily`,`weekly`]).optional()}),$({}),$({id:cv().int().positive()}),$({id:cv().int().positive()}),$({}),$({}),$({settings:Dv(Q(),mv())}),$({style:oy.optional(),accent:Q().regex(/^#[0-9a-fA-F]{6}$/).optional(),intensity:cv().min(0).max(1).optional(),size:cv().min(.5).max(1.5).optional(),reactivity:cv().min(0).max(1).optional(),ambient:fv().optional(),captions:fv().optional(),captionSize:kv([`small`,`medium`,`large`]).optional()}),$({view:_y}),$({}),$({id:Q().min(1).max(16),name:Q().min(1).max(60),kind:kv([`stdio`,`http`]),command:Q().max(260).optional(),args:vv(Q().max(500)).max(20).optional(),url:Q().max(2e3).optional()}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({}),$({id:Q().min(1).max(40),name:Q().min(1).max(80),description:Q().max(500).optional(),skills:vv($({name:Q().min(1).max(40),description:Q().min(1).max(300),text:Q().min(1).max(2e4)})).max(10).optional(),tools:vv($({name:Q().min(1).max(40),description:Q().min(1).max(500),language:kv([`python`,`node`,`shell`]),code:Q().min(1).max(5e4),parameters:Dv(Q(),$({type:kv([`string`,`number`,`integer`,`boolean`]),description:Q().max(300).optional(),enum:vv(Q().max(100)).max(50).optional()})).optional(),required:vv(Q()).optional()})).max(10).optional()}),$({}),$({id:Q().min(1).max(40)}),$({id:Q().min(1).max(40)}),$({id:Q().min(1).max(40)}),$({mode:iy}),$({object:sy}),$({id:Q(),props:Dv(Q(),mv())}),$({id:Q()}),$({}),$({id:Q()}),$({id:Q()}),$({state:ay.optional(),style:oy.optional()}),$({accent:Q().max(16).optional(),intensity:cv().min(0).max(1).optional()});var Cy=[`#3fd8ff`,`#2b7bff`,`#a066ff`,`#ff6fae`,`#ff5a5a`,`#ff9b3d`,`#ffd23d`,`#3dff8c`,`#e8f4ff`],wy=[{id:`sphere`,name:`Sphere`,note:`A cloud of particles`},{id:`orb`,name:`Orb`,note:`A glowing plasma ball`},{id:`ring`,name:`Ring`,note:`Radial bars, like a voice meter`}],Ty=(e,t)=>e.style===t.style&&e.accent.toLowerCase()===t.accent&&Math.abs(e.intensity-t.intensity)<.005,Ey=[{id:`model`,label:`Model`,note:`Where Friend thinks`},{id:`voice`,label:`Voice`,note:`Speaking and listening`},{id:`look`,label:`Voice presence`,note:`How it looks`}],Dy=[{id:`claude-code`,label:`Claude subscription (Claude Code)`,note:`Uses the Claude Code app you are signed in to. No API key.`},{id:`claude`,label:`Claude API key`,note:`Pay per use with an Anthropic API key.`},{id:`ollama`,label:`Local model (Ollama)`,note:`Runs on this PC. Free and private, but slower.`},{id:`openai`,label:`OpenAI-compatible server (OmniRoute, LM Studio…)`,note:`Any server that speaks the OpenAI chat API. OmniRoute is one address that routes to many models, many of them free.`}],Oy={"voice.enabled":`Speech on/off`,"voice.ttsVoice":`Voice`,"voice.sttModel":`Listening model`};function ky({label:e,children:t,hint:n}){return(0,p.jsxs)(`label`,{className:`settings-field`,children:[(0,p.jsx)(`span`,{children:e}),t,n&&(0,p.jsx)(`small`,{className:`auth-note`,children:n})]})}function Ay({api:e=Ie,onClose:t,initialTab:n=`model`,preview:r=Le}){let[i,a]=(0,l.useState)(null),[o,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(n),[f,m]=(0,l.useState)(``),[h,g]=(0,l.useState)(``),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(``),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(null),[E,D]=(0,l.useState)(null),[O,k]=(0,l.useState)(!1),[A,j]=(0,l.useState)(null),ee=(0,l.useRef)(!0);(0,l.useEffect)(()=>(ee.current=!0,e.get().then(e=>{ee.current&&(a(e),s(structuredClone(e)))}).catch(e=>ee.current&&T(e.message)),()=>{ee.current=!1}),[e]);let M=(e,t=!1)=>(0,p.jsxs)(`div`,{className:`approval settings glass${t?` settings-wide`:``}`,role:`dialog`,"aria-label":`Settings`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:`Settings`})}),e]});if(!o||!i)return M((0,p.jsxs)(p.Fragment,{children:[w?(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}):(0,p.jsx)(`p`,{className:`auth-note`,children:`Loading…`}),(0,p.jsx)(`div`,{className:`approval-actions`,children:(0,p.jsx)(`button`,{type:`button`,style:d,onClick:t,children:`Close`})})]}));let N=Re(i,o,f,h),P=Object.keys(N).length>0,F=(e,t,n)=>s({...o,[e]:{...o[e],[t]:n}}),I=o.look,te=async t=>{T(null),C(!0);try{let n=await e.save(N,t);if(!ee.current)return;a(n.settings),s(structuredClone(n.settings)),m(``),g(``),v(!1);let r=N.voice&&N.voice.ttsVoice!==void 0;D(n.restart.length?`Saved. Restart Friend for: ${n.restart.map(e=>Oy[e]??e).join(`, `)}.`:r?`Saved. The new voice is loading; you will get a message when it is ready (the first time it downloads about 60 MB).`:Pe(N)?`Saved. It is in use now.`:`Saved. Every open screen has changed.`)}catch(e){ee.current&&T(e.message)}finally{ee.current&&(C(!1),b(``))}};if(_)return M((0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to save these changes.`}),(0,p.jsx)(x,{pin:y,onChange:b,onSubmit:()=>!S&&void te(y)}),w&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:S||y.length<6,onClick:()=>void te(y),children:`Save`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{v(!1),b(``),T(null)},children:`Back`})]})]}));let ne=Dy.find(e=>e.id===o.provider),L=e=>{let t=Ey.findIndex(e=>e.id===c),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%Ey.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t+Ey.length-1)%Ey.length:e.key===`Home`?0:e.key===`End`?Ey.length-1:-1;n<0||(e.preventDefault(),u(Ey[n].id),document.getElementById(`settings-tab-${Ey[n].id}`)?.focus())},re=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Where Friend thinks`}),(0,p.jsx)(ky,{label:`Model provider`,hint:ne.note,children:(0,p.jsx)(`select`,{value:o.provider,onChange:e=>s({...o,provider:e.target.value}),children:Dy.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),o.provider===`claude-code`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(ky,{label:`Claude model`,hint:`sonnet, haiku, opus, or a full model name`,children:[(0,p.jsx)(`input`,{list:`cc-models`,value:o.claudeCode.model,onChange:e=>F(`claudeCode`,`model`,e.target.value)}),(0,p.jsxs)(`datalist`,{id:`cc-models`,children:[(0,p.jsx)(`option`,{value:`sonnet`}),(0,p.jsx)(`option`,{value:`haiku`}),(0,p.jsx)(`option`,{value:`opus`})]})]}),(0,p.jsx)(ky,{label:`If Claude is unavailable`,hint:`For example when the plan's usage limit is reached.`,children:(0,p.jsxs)(`select`,{value:o.claudeCode.fallback,onChange:e=>F(`claudeCode`,`fallback`,e.target.value),children:[(0,p.jsx)(`option`,{value:`ollama`,children:`Answer with the local model (Ollama)`}),(0,p.jsx)(`option`,{value:`none`,children:`Show an error`})]})}),(0,p.jsx)(ky,{label:`Claude Code command`,hint:`Leave as it is unless the program is somewhere else.`,children:(0,p.jsx)(`input`,{value:o.claudeCode.command,onChange:e=>F(`claudeCode`,`command`,e.target.value)})})]}),o.provider===`claude`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ky,{label:`Claude model`,children:(0,p.jsx)(`input`,{value:o.model,onChange:e=>s({...o,model:e.target.value})})}),(0,p.jsx)(ky,{label:`API key`,hint:i.apiKeySet?`A key is saved. Type a new one only to replace it.`:`No key saved yet.`,children:(0,p.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:i.apiKeySet?`saved`:`sk-ant-…`,value:f,onChange:e=>m(e.target.value)})})]}),o.provider===`openai`&&o.openai&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ky,{label:`Server address`,hint:`Ends in /v1. OmniRoute: http://localhost:20128/v1 (install it with npm install -g omniroute, then run omniroute).`,children:(0,p.jsx)(`input`,{value:o.openai.url,onChange:e=>s({...o,openai:{...o.openai,url:e.target.value}})})}),(0,p.jsx)(ky,{label:`Model`,hint:`The name that server knows. OmniRoute answers to auto.`,children:(0,p.jsx)(`input`,{value:o.openai.model,onChange:e=>s({...o,openai:{...o.openai,model:e.target.value}})})}),(0,p.jsx)(ky,{label:`API key`,hint:i.openai?.apiKeySet?`A key is saved. Type a new one only to replace it.`:`Leave empty if the server asks for none.`,children:(0,p.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:i.openai?.apiKeySet?`saved`:``,value:h,onChange:e=>g(e.target.value)})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.openai.vision,onChange:e=>s({...o,openai:{...o.openai,vision:e.target.checked}})}),` This model can look at pictures`]})]}),(o.provider===`ollama`||o.provider===`claude-code`&&o.claudeCode.fallback===`ollama`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Local model (Ollama)`}),(0,p.jsx)(ky,{label:`Address`,children:(0,p.jsx)(`input`,{value:o.ollama.url,onChange:e=>F(`ollama`,`url`,e.target.value)})}),(0,p.jsx)(ky,{label:`Model`,children:(0,p.jsx)(`input`,{value:o.ollama.model,onChange:e=>F(`ollama`,`model`,e.target.value)})}),(0,p.jsx)(ky,{label:`Memory window (tokens)`,children:(0,p.jsx)(`input`,{type:`number`,min:1024,max:131072,step:1024,value:o.ollama.contextTokens,onChange:e=>F(`ollama`,`contextTokens`,Number(e.target.value))})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.ollama.vision,onChange:e=>F(`ollama`,`vision`,e.target.checked)}),` This model can look at pictures`]})]})]}),ie=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Speaking and listening`}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.voice.speakTyped,onChange:e=>F(`voice`,`speakTyped`,e.target.checked)}),` Also speak the replies to typed messages`]}),(0,p.jsx)(ky,{label:`Spoken language`,hint:`Leave empty to detect it by itself: best when you mix English, Hindi and Marathi. Or force one: en, hi, mr.`,children:(0,p.jsx)(`input`,{value:o.voice.language??``,maxLength:10,onChange:e=>F(`voice`,`language`,e.target.value.trim()===``?null:e.target.value.trim())})}),(0,p.jsx)(ky,{label:`Speaking voice`,hint:`Female or male. The first time a voice is used it downloads about 60 MB, then it works without internet.`,children:(0,p.jsxs)(`select`,{value:o.voice.ttsVoice,onChange:e=>F(`voice`,`ttsVoice`,e.target.value),children:[(0,p.jsx)(`optgroup`,{label:`Female`,children:dy.filter(e=>e.gender===`female`).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,p.jsx)(`optgroup`,{label:`Male`,children:dy.filter(e=>e.gender===`male`).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,p.jsx)(`optgroup`,{label:`Original`,children:(0,p.jsxs)(`option`,{value:my.id,children:[my.name,` · `,my.accent,` · `,my.note]})}),!hy(o.voice.ttsVoice)&&(0,p.jsx)(`optgroup`,{label:`Other`,children:(0,p.jsx)(`option`,{value:o.voice.ttsVoice,children:o.voice.ttsVoice})})]})}),(0,p.jsx)(ky,{label:`Hindi voice`,hint:`Reads Hindi (Devanagari) text; English words in the same sentence still use the voice above. The first time it downloads about 64 MB.`,children:(0,p.jsxs)(`select`,{value:o.voice.hindiVoice??``,onChange:e=>F(`voice`,`hindiVoice`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:`Same as the voice above`}),fy.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.gender,e.note?` · ${e.note}`:``]},e.id))]})}),(0,p.jsx)(ky,{label:`Marathi voice`,hint:`Reads Marathi text. Friend tells Marathi from Hindi by the words used.`,children:(0,p.jsxs)(`select`,{value:o.voice.marathiVoice??``,onChange:e=>F(`voice`,`marathiVoice`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:`Same as the voice above`}),py.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,p.jsxs)(`div`,{className:`voice-hear`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,disabled:O,onClick:()=>{k(!0),j(null),r(o.voice.ttsVoice).then(()=>ee.current&&j(`Playing…`)).catch(e=>ee.current&&j(e.message)).finally(()=>ee.current&&k(!1))},children:O?`Loading the voice…`:`Hear it`}),A&&(0,p.jsx)(`small`,{className:`auth-note`,role:`status`,children:A})]}),(0,p.jsx)(ky,{label:`Listening model`,hint:`tiny, base, small … Bigger is more accurate but slower. For Hindi and Marathi use small or larger (base mishears them). Needs a restart.`,children:(0,p.jsx)(`input`,{value:o.voice.sttModel,onChange:e=>F(`voice`,`sttModel`,e.target.value)})}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Who is speaking`}),(0,p.jsx)(ky,{label:`"It is me" match level: ${o.voice.accept.toFixed(2)}`,hint:`Higher is stricter. Only matters after you enrolled your voice.`,children:(0,p.jsx)(`input`,{type:`range`,min:.3,max:.95,step:.01,value:o.voice.accept,onChange:e=>F(`voice`,`accept`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`"Ask for my PIN" level: ${o.voice.challenge.toFixed(2)}`,hint:`Voices between this and the level above must be confirmed with the PIN.`,children:(0,p.jsx)(`input`,{type:`range`,min:.2,max:.9,step:.01,value:o.voice.challenge,onChange:e=>F(`voice`,`challenge`,Number(e.target.value))})})]}),ae=(0,p.jsxs)(`div`,{className:`look-tab`,children:[(0,p.jsxs)(`div`,{className:`look-side`,children:[(0,p.jsx)(_u,{look:I}),(0,p.jsx)(`p`,{className:`auth-note`,children:`This is a live preview. Nothing changes on the screen until you save.`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>s({...o,look:{...Me}}),children:`Back to the default look`})]}),(0,p.jsxs)(`div`,{className:`look-controls`,children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Themes`}),(0,p.jsx)(`div`,{className:`theme-grid`,role:`group`,"aria-label":`Themes`,children:gy.map(e=>(0,p.jsxs)(`button`,{type:`button`,className:`theme-card${Ty(I,e)?` on`:``}`,"aria-pressed":Ty(I,e),style:{"--swatch":e.accent},onClick:()=>s({...o,look:{...I,style:e.style,accent:e.accent,intensity:e.intensity}}),children:[(0,p.jsx)(`i`,{"aria-hidden":`true`}),(0,p.jsx)(`b`,{children:e.name}),(0,p.jsx)(`small`,{children:e.style})]},e.id))}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Shape`}),(0,p.jsx)(`div`,{className:`style-row`,role:`radiogroup`,"aria-label":`Style`,children:wy.map(e=>(0,p.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":I.style===e.id,className:`style-choice${I.style===e.id?` on`:``}`,onClick:()=>F(`look`,`style`,e.id),children:[(0,p.jsx)(`b`,{children:e.name}),(0,p.jsx)(`small`,{children:e.note})]},e.id))}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Colour and light`}),(0,p.jsxs)(`div`,{className:`swatch-row`,role:`group`,"aria-label":`Colour`,children:[Cy.map(e=>(0,p.jsx)(`button`,{type:`button`,"aria-label":`Colour ${e}`,"aria-pressed":I.accent.toLowerCase()===e,className:`swatch${I.accent.toLowerCase()===e?` on`:``}`,style:{background:e},onClick:()=>F(`look`,`accent`,e)},e)),(0,p.jsxs)(`label`,{className:`swatch-custom`,children:[(0,p.jsx)(`span`,{children:`Other`}),(0,p.jsx)(`input`,{type:`color`,"aria-label":`Pick another colour`,value:I.accent,onChange:e=>F(`look`,`accent`,e.target.value.toLowerCase())})]})]}),(0,p.jsx)(ky,{label:`Brightness: ${Math.round(I.intensity*100)}%`,children:(0,p.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:I.intensity,onChange:e=>F(`look`,`intensity`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`Size: ${Math.round(I.size*100)}%`,hint:`How big it is in the middle of the screen.`,children:(0,p.jsx)(`input`,{type:`range`,min:.5,max:1.5,step:.05,value:I.size,onChange:e=>F(`look`,`size`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`Reaction to my voice: ${Math.round(I.reactivity*100)}%`,hint:`Low is calm, high moves a lot when anyone speaks.`,children:(0,p.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:I.reactivity,onChange:e=>F(`look`,`reactivity`,Number(e.target.value))})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.ambient,onChange:e=>F(`look`,`ambient`,e.target.checked)}),` Soft glow behind everything`]}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Words on the screen`}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.captions,onChange:e=>F(`look`,`captions`,e.target.checked)}),` Show the live words while Friend speaks`]}),(0,p.jsx)(ky,{label:`Caption size`,children:(0,p.jsxs)(`select`,{value:I.captionSize,disabled:!I.captions,onChange:e=>F(`look`,`captionSize`,e.target.value),children:[(0,p.jsx)(`option`,{value:`small`,children:`Small`}),(0,p.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,p.jsx)(`option`,{value:`large`,children:`Large`})]})}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`What is on the screen`}),(0,p.jsx)(ky,{label:`Your name`,hint:`Shown on the badge in the corner, next to the shield, while you are signed in. Empty shows Owner.`,children:(0,p.jsx)(`input`,{value:o.ownerName??``,maxLength:40,placeholder:`Owner`,onChange:e=>s({...o,ownerName:e.target.value})})}),(0,p.jsx)(ky,{label:`View`,hint:`Minimal: only the voice presence. Companion: plus a status line and a clock. Workspace: also the chat and the schedule. Drag any panel to move it.`,children:(0,p.jsxs)(`select`,{value:o.view,onChange:e=>s({...o,view:e.target.value}),children:[(0,p.jsx)(`option`,{value:`minimal`,children:`Minimal`}),(0,p.jsx)(`option`,{value:`companion`,children:`Companion`}),(0,p.jsx)(`option`,{value:`workspace`,children:`Workspace`})]})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.aiMayChange,onChange:e=>F(`look`,`aiMayChange`,e.target.checked)}),` Let the AI change the shape, colour and brightness to suit a topic`]}),(0,p.jsx)(`small`,{className:`auth-note`,children:`Off keeps exactly the look you chose. You can still ask it to change the look yourself.`})]})]});return M((0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`settings-layout`,children:[(0,p.jsx)(`div`,{className:`settings-tabs`,role:`tablist`,"aria-label":`Settings sections`,"aria-orientation":`vertical`,onKeyDown:L,children:Ey.map(e=>(0,p.jsxs)(`button`,{id:`settings-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":c===e.id,"aria-controls":`settings-panel-${e.id}`,tabIndex:c===e.id?0:-1,className:`settings-tab${c===e.id?` on`:``}`,onClick:()=>u(e.id),children:[(0,p.jsx)(`b`,{children:e.label}),(0,p.jsx)(`small`,{children:e.note})]},e.id))}),(0,p.jsxs)(`div`,{className:`settings-body`,role:`tabpanel`,id:`settings-panel-${c}`,"aria-labelledby":`settings-tab-${c}`,children:[c===`model`&&re,c===`voice`&&ie,c===`look`&&ae]})]}),E&&!P&&(0,p.jsx)(`p`,{className:`auth-note`,children:E}),w&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:!P||S,onClick:()=>{D(null),T(null),Pe(N)?v(!0):te()},children:P&&!Pe(N)?`Save`:`Save…`}),P&&(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{s(structuredClone(i)),m(``),g(``)},children:`Undo changes`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:t,children:`Close`})]}),(0,p.jsx)(`p`,{className:`auth-note`,children:`Network, folders and safety rules are not here on purpose. Change those in the terminal: friend config set.`})]}),!0)}var jy=e=>e instanceof HTMLElement&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable);function My({onSend:e,requestOpen:t,slash:n,onOpenChange:r}){let[i,a]=(0,l.useState)(!1),o=(0,l.useRef)(r);o.current=r,(0,l.useEffect)(()=>o.current?.(i),[i]);let[s,c]=(0,l.useState)(``),[u,d]=(0,l.useState)(0),f=(0,l.useRef)(null);if((0,l.useEffect)(()=>{t>0&&a(!0)},[t]),(0,l.useEffect)(()=>{let e=e=>{i||jy(e.target)||e.ctrlKey||e.metaKey||e.altKey||e.key.length===1&&(e.preventDefault(),c(e.key),d(0),a(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,l.useEffect)(()=>{i&&f.current?.focus()},[i]),!i)return null;let m=n?ee(n.commands,s):[],h=m[Math.min(u,Math.max(m.length-1,0))],g=()=>{c(``),d(0),a(!1)},_=()=>{let t=s.trim();if(n&&j(t)){let e=/^\/\S*\s/.test(t);n.run(!e&&h?`/${h.name}`:t)}else t&&e(N(t));g()};return(0,p.jsxs)(`form`,{className:`command-bar`,onSubmit:e=>{e.preventDefault(),_()},children:[m.length>0&&(0,p.jsx)(`ul`,{className:`slash-list`,role:`listbox`,"aria-label":`Commands`,children:m.map((e,t)=>(0,p.jsxs)(`li`,{role:`option`,"aria-selected":e===h,className:e===h?`on`:void 0,onMouseDown:n=>{n.preventDefault(),c(`/${e.name} `),f.current?.focus(),d(t)},children:[(0,p.jsxs)(`b`,{children:[`/`,e.name]}),e.usage&&(0,p.jsx)(`i`,{children:e.usage}),(0,p.jsx)(`span`,{children:e.description})]},e.name))}),(0,p.jsx)(`input`,{ref:f,"aria-label":`Message`,value:s,placeholder:`Talk to me… or type / for commands`,autoComplete:`off`,onChange:e=>{c(e.target.value),d(0)},onKeyDown:e=>{e.key===`Escape`?(e.stopPropagation(),g()):m.length>0&&(e.key===`ArrowDown`||e.key===`ArrowUp`)?(e.preventDefault(),d(t=>(t+(e.key===`ArrowDown`?1:m.length-1))%m.length)):e.key===`Tab`&&h&&(e.preventDefault(),c(`/${h.name} `))}}),(0,p.jsx)(`button`,{type:`submit`,"aria-label":`Send`,children:`↵`})]})}var Ny={width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0},Py=(e,t)=>e===`listening`?t?`Listening… tap to send`:`Listening… let go to send`:e===`transcribing`?`Understanding…`:e===`speaking`?`Tap to talk over me`:`Hold to talk, or tap once`;function Fy({voice:e,mode:t,onType:n,onMenu:r}){let i=(0,l.useRef)(null),a=(0,l.useRef)(!1),[o,s]=(0,l.useState)(!1),c=e=>{a.current=e,s(e)},u=(0,l.useRef)(t);u.current=t,(0,l.useEffect)(()=>{t!==`listening`&&!i.current&&c(!1)},[t]);let d=t=>{if((t.pointerType!==`mouse`||t.button===0)&&!i.current){if(a.current&&u.current===`listening`){c(!1),e.pressEnd();return}c(!1),i.current={at:Date.now(),id:t.pointerId};try{t.currentTarget.setPointerCapture?.(t.pointerId)}catch{}e.pressStart()}},f=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,Date.now()-n.at>=450?e.pressEnd():c(!0))},m=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,c(!1),e.blur?.())},h=t===`listening`;return(0,p.jsxs)(`div`,{className:`touch-controls`,"data-testid":`touch-controls`,children:[(0,p.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Open the menu`,onClick:r,children:(0,p.jsx)(`svg`,{...Ny,children:(0,p.jsx)(`path`,{d:`M4 7h16M4 12h16M4 17h16`})})}),(0,p.jsxs)(`div`,{className:`touch-talk`,children:[(0,p.jsx)(`button`,{type:`button`,className:`touch-mic${h?` on`:``}`,"aria-label":`Talk to Friend`,"aria-pressed":h,onPointerDown:d,onPointerUp:f,onPointerCancel:m,onContextMenu:e=>e.preventDefault(),children:(0,p.jsxs)(`svg`,{...Ny,width:30,height:30,children:[(0,p.jsx)(`rect`,{x:`9`,y:`3`,width:`6`,height:`11`,rx:`3`}),(0,p.jsx)(`path`,{d:`M5 11a7 7 0 0 0 14 0M12 18v3`})]})}),(0,p.jsx)(`span`,{className:`touch-hint`,"aria-live":`polite`,children:Py(t,o)})]}),(0,p.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Type a message`,onClick:n,children:(0,p.jsxs)(`svg`,{...Ny,children:[(0,p.jsx)(`rect`,{x:`3`,y:`6`,width:`18`,height:`12`,rx:`2`}),(0,p.jsx)(`path`,{d:`M7 10h.01M11 10h.01M15 10h.01M7 14h10`})]})})]})}function Iy(e,t){this.v=e,this.k=t}function Ly(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Ry(e){if(Array.isArray(e))return e}function zy(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function By(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4385
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function yg(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;yg(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var bg=new Set([`type`,`properties`,`required`,`additionalProperties`]),xg=[`oneOf`,`anyOf`];function Sg(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function Cg(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!bg.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??Sg(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}Eu(n,r,e.length===1?e[0]:Cg(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=Sg(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function wg(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of bg)if(t in e)return;let n=t.filter(e=>xg.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=Cg(t);else{let e=n[0],i=xg.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>Cg([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,pg(e,r))}function Tg(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):pg(i,s),pg(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())yg(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])wg(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}pg(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,Eu(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Og(t,`input`,e.processors),output:Og(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function Eg(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return Eg(r.element,n);if(r.type===`set`)return Eg(r.valueType,n);if(r.type===`lazy`)return Eg(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return Eg(r.innerType,n);if(r.type===`intersection`)return Eg(r.left,n)||Eg(r.right,n);if(r.type===`record`||r.type===`map`)return Eg(r.keyType,n)||Eg(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:Eg(r.in,n)||Eg(r.out,n);if(r.type===`object`){for(let e in r.shape)if(Eg(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(Eg(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(Eg(e,n))return!0;return!!(r.rest&&Eg(r.rest,n))}return!1}var Dg=(e,t={})=>n=>{let r=mg({...n,processors:t});return gg(e,r),vg(r,e),Tg(r,e)},Og=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=mg({...i??{},target:a,io:t,processors:n});return gg(e,o),vg(o,e),Tg(o,e)},kg=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Ag=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},jg=(e,t)=>{kg(e,`minimum`,t),Ag(e,`maximum`,t)},Mg=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Ng=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Pg=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Fg=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ig=(e,t)=>kg(e,`minimum`,t.minimum),Lg=(e,t)=>Ag(e,`maximum`,t.maximum),Rg=e=>(t,n)=>{Fg(t,n.format);let[r,i]=e[n.format];kg(t,`minimum`,r),Ag(t,`maximum`,i)},zg={greater_than:(e,t)=>kg(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Ag(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>Mg(e,t.value),number_format:Rg(Ku),bigint_format:Rg(qu),min_length:Ig,max_length:Lg,length_equals:(e,t)=>jg(e,t.length),min_size:Ig,max_size:Lg,size_equals:(e,t)=>jg(e,t.size),string_format:(e,t)=>{Fg(e,t.format),t.pattern&&Ng(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Pg(e,t.mime)};function Bg(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)zg[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&kg(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&kg(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Ag(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Ag(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&Mg(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Pg(t,i.mime);for(let e of i.patterns??[])Ng(t,e);return t}var Vg={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Hg=new Map([[Kp,Of],[Jp,kf]]),Ug=e=>Hg.get(e)??e,Wg=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Bg(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Vg[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Ug);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Gg=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Bg(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):hg(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Kg=(e,t,n,r)=>{n.type=`boolean`},qg=(e,t,n,r)=>{n.not={}},Jg=(e,t,n,r)=>{let i=e._zod.def,a=vu(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Yg=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(hg(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(hg(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Xg=(e,t,n,r)=>{hg(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Zg=(e,t,n,r)=>{hg(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Qg=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Bg(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=gg(a.element,t,{...r,path:[...r.path,`items`]})};function $g(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?$g(t.out):t.type===`catch`?$g(t.innerType):e._zod.optin}var e_=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&hg(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)Eu(i.properties,e,gg(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?$g(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=gg(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},t_=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>gg(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},n_=(e,t,n,r)=>{let i=e._zod.def,a=gg(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=gg(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function r_(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=r_(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>r_(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?Bf:zf).source),p):p}var i_=new WeakMap;function a_(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of i_.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=r_(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}var o_=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=Bg(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=gg(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)Eu(i.patternProperties,Ug(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=gg(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=i_.get(t);n||(n=[],i_.set(t,n),t.deferred.push(()=>a_(t))),n.push(e)}i.additionalProperties=gg(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&$g(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},s_=(e,t,n,r)=>{let i=e._zod.def,a=gg(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},c_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},l_=Symbol();function u_(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(hg(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),l_):JSON.parse(o)}var d_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=u_(i.defaultValue,e,t,n,r);o!==l_&&(n.default=o)},f_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=u_(i.defaultValue,e,t,n,r);o!==l_&&(n._prefault=o)},p_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{hg(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},m_=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;gg(o,t,r);let s=t.seen.get(e);s.ref=o},h_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},g_=(e,t,n,r)=>{let i=e._zod.def;gg(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},__=new WeakSet([Object.prototype,Error.prototype]);function v_(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var y_=Z(`ZodError`,(e,t)=>{Vd.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);__.has(n)||(__.add(n),v_(n,`format`,e=>t=>Wd(e,t)),v_(n,`flatten`,e=>t=>Ud(e,t)),v_(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,bu,2)}),v_(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,bu,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),b_=Kd(y_),x_=qd(y_),S_=Jd(y_),C_=Xd(y_),w_=nf(y_),T_=rf(y_),E_=af(y_),D_=of(y_),O_=sf(y_),k_=cf(y_),A_=lf(y_),j_=uf(y_);function M_(){Nd.localeError||Pd(ah())}function N_(){Nd.memoizer||Pd({memoizer:nh()})}var P_=Z(`ZodType`,(e,t)=>(M_(),up.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(Nu(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Uu(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check($v(e,t))},superRefine(e,t){return this.check(ey(e,t))},overwrite(e){return this.check(rg(e))},optional(){return Fv(this)},exactOptional(){return Lv(this)},nullable(){return zv(this)},nullish(){return Fv(zv(this))},nonoptional(e){return Gv(this,e)},array(){return vv(this)},or(e){return xv([this,e])},and(e){return Tv(this,e)},transform(e){return Yv(this,Nv(e))},default(e){return Vv(this,e)},prefault(e){return Uv(this,e)},catch(e){return qv(this,e)},pipe(e){return Yv(this,e)},readonly(){return Zv(this)},describe(e){let t=this.clone();return lh.add(t,{description:e}),t},meta(...e){if(e.length===0)return lh.get(this);let t=this.clone();return lh.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return gd(this,`~standard`,{...pp(this),jsonSchema:{input:Og(this,`input`),output:Og(this,`output`)}})},set"~standard"(e){hd(this,`~standard`,e)},parse:function e(t,n){return b_(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await x_(this,t,n,{callee:e})},safeParse(e,t){return S_(this,e,t)},async safeParseAsync(e,t){return C_(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){hd(this,`spa`,e)},validate(e,t){return $d(this,e,t)},validateAsync(e,t){return tf(this,e,t)},encode:function e(t,n){return w_(this,t,n,{callee:e})},decode:function e(t,n){return T_(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await E_(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await D_(this,t,n,{callee:e})},safeEncode(e,t){return O_(this,e,t)},safeDecode(e,t){return k_(this,e,t)},async safeEncodeAsync(e,t){return A_(this,e,t)},async safeDecodeAsync(e,t){return j_(this,e,t)},toJSONSchema(e){return Dg(this,{})(e)},get description(){return lh.get(this)?.description},get _def(){return this._zod.def}}),F_=Z(`_ZodString`,(e,t)=>{mp.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wg(e,t,n,r)},_d({format:e=>Bg(e).format??null,minLength:e=>Bg(e).minimum??null,maxLength:e=>Bg(e).maximum??null},{regex(...e){return this.check(Zh(...e))},includes(...e){return this.check(eg(...e))},startsWith(...e){return this.check(tg(...e))},endsWith(...e){return this.check(ng(...e))},min(...e){return this.check(Yh(...e))},max(...e){return this.check(Jh(...e))},length(...e){return this.check(Xh(...e))},nonempty(...e){return this.check(Yh(1,...e))},lowercase(e){return this.check(Qh(e))},uppercase(e){return this.check($h(e))},trim(){return this.check(ag())},normalize(...e){return this.check(ig(...e))},toLowerCase(){return this.check(og())},toUpperCase(){return this.check(sg())},slugify(){return this.check(cg())}})),I_=Z(`ZodString`,(e,t)=>{mp.init(e,t),F_.init(e,t)},{email(e){return this.check(fh(H_,e))},url(e){return this.check(vh(G_,e))},jwt(e){return this.check(Nh(ov,e))},emoji(e){return this.check(yh(K_,e))},guid(e){return this.check(ph(U_,e))},uuid(e){return this.check(mh(W_,e))},uuidv4(e){return this.check(hh(W_,e))},uuidv6(e){return this.check(gh(W_,e))},uuidv7(e){return this.check(_h(W_,e))},nanoid(e){return this.check(bh(q_,e))},cuid(e){return this.check(xh(J_,e))},cuid2(e){return this.check(Sh(Y_,e))},ulid(e){return this.check(Ch(X_,e))},base64(e){return this.check(Ah(rv,e))},base64url(e){return this.check(jh(iv,e))},xid(e){return this.check(wh(Z_,e))},ksuid(e){return this.check(Th(Q_,e))},ipv4(e){return this.check(Eh($_,e))},ipv6(e){return this.check(Dh(ev,e))},cidrv4(e){return this.check(Oh(tv,e))},cidrv6(e){return this.check(kh(nv,e))},e164(e){return this.check(Mh(av,e))},datetime(e){return this.check(Ph(R_,e))},date(e){return this.check(Fh(z_,e))},time(e){return this.check(Ih(B_,e))},duration(e){return this.check(Lh(V_,e))}});function Q(e){return dh(I_,e)}var L_=Z(`ZodStringFormat`,(e,t)=>{hp.init(e,t),F_.init(e,t)}),R_=Z(`ZodISODateTime`,(e,t)=>{Pp.init(e,t),L_.init(e,t)}),z_=Z(`ZodISODate`,(e,t)=>{Fp.init(e,t),L_.init(e,t)}),B_=Z(`ZodISOTime`,(e,t)=>{Ip.init(e,t),L_.init(e,t)}),V_=Z(`ZodISODuration`,(e,t)=>{Lp.init(e,t),L_.init(e,t)}),H_=Z(`ZodEmail`,(e,t)=>{vp.init(e,t),L_.init(e,t)}),U_=Z(`ZodGUID`,(e,t)=>{gp.init(e,t),L_.init(e,t)}),W_=Z(`ZodUUID`,(e,t)=>{_p.init(e,t),L_.init(e,t)}),G_=Z(`ZodURL`,(e,t)=>{Ep.init(e,t),L_.init(e,t)}),K_=Z(`ZodEmoji`,(e,t)=>{Dp.init(e,t),L_.init(e,t)}),q_=Z(`ZodNanoID`,(e,t)=>{Op.init(e,t),L_.init(e,t)}),J_=Z(`ZodCUID`,(e,t)=>{kp.init(e,t),L_.init(e,t)}),Y_=Z(`ZodCUID2`,(e,t)=>{Ap.init(e,t),L_.init(e,t)}),X_=Z(`ZodULID`,(e,t)=>{jp.init(e,t),L_.init(e,t)}),Z_=Z(`ZodXID`,(e,t)=>{Mp.init(e,t),L_.init(e,t)}),Q_=Z(`ZodKSUID`,(e,t)=>{Np.init(e,t),L_.init(e,t)}),$_=Z(`ZodIPv4`,(e,t)=>{Rp.init(e,t),L_.init(e,t)}),ev=Z(`ZodIPv6`,(e,t)=>{Vp.init(e,t),L_.init(e,t)}),tv=Z(`ZodCIDRv4`,(e,t)=>{Hp.init(e,t),L_.init(e,t)}),nv=Z(`ZodCIDRv6`,(e,t)=>{Wp.init(e,t),L_.init(e,t)}),rv=Z(`ZodBase64`,(e,t)=>{qp.init(e,t),L_.init(e,t)}),iv=Z(`ZodBase64URL`,(e,t)=>{Xp.init(e,t),L_.init(e,t)}),av=Z(`ZodE164`,(e,t)=>{Zp.init(e,t),L_.init(e,t)}),ov=Z(`ZodJWT`,(e,t)=>{$p.init(e,t),L_.init(e,t)}),sv=Z(`ZodNumber`,(e,t)=>{em.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gg(e,t,n,r),e.isFinite=!0},_d({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Bg(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Bg(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Bg(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Bg(e).format??null},{gt(e,t){return this.check(Gh(e,t))},gte(e,t){return this.check(Kh(e,t))},min(e,t){return this.check(Kh(e,t))},lt(e,t){return this.check(Uh(e,t))},lte(e,t){return this.check(Wh(e,t))},max(e,t){return this.check(Wh(e,t))},int(e){return this.check(uv(e))},safe(e){return this.check(uv(e))},positive(e){return this.check(Gh(0,e))},nonnegative(e){return this.check(Kh(0,e))},negative(e){return this.check(Uh(0,e))},nonpositive(e){return this.check(Wh(0,e))},multipleOf(e,t){return this.check(qh(e,t))},step(e,t){return this.check(qh(e,t))},finite(){return this}}));function cv(e){return Rh(sv,e)}var lv=Z(`ZodNumberFormat`,(e,t)=>{tm.init(e,t),sv.init(e,t)});function uv(e){return zh(lv,e)}var dv=Z(`ZodBoolean`,(e,t)=>{nm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Kg(e,t,n,r)});function fv(e){return Bh(dv,e)}var pv=Z(`ZodUnknown`,(e,t)=>{rm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function mv(){return Vh(pv)}var hv=Z(`ZodNever`,(e,t)=>{im.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qg(e,t,n,r)});function gv(e){return Hh(hv,e)}var _v=Z(`ZodArray`,(e,t)=>{N_(),om.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qg(e,t,n,r),e.element=t.element},{min(e,t){return this.check(Yh(e,t))},nonempty(e){return this.check(Yh(1,e))},max(e,t){return this.check(Jh(e,t))},length(e,t){return this.check(Xh(e,t))},unwrap(){return this.element}});function vv(e,t){return lg(_v,e,t)}var yv=Z(`ZodObject`,(e,t)=>{N_(),fm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>e_(e,t,n,r),wd(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return kv(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(Nu(this._zod.def,{catchall:e}))},passthrough(){return this.clone(Nu(this._zod.def,{catchall:mv()}))},loose(){return this.clone(Nu(this._zod.def,{catchall:mv()}))},strict(){return this.clone(Nu(this._zod.def,{catchall:gv()}))},strip(){return this.clone(Nu(this._zod.def,{catchall:void 0}))},extend(e){return Zu(this,e)},safeExtend(e){return $u(this,e)},merge(e){return ed(this,e)},pick(e){return Ju(this,e)},omit(e){return Xu(this,e)},partial(...e){return td(Pv,this,e[0])},exactPartial(...e){return td(Iv,this,e[0],`exactPartial`)},required(...e){return nd(Wv,this,e[0])}});function $(e,t){return new yv({type:`object`,shape:e??{},...X(t)})}var bv=Z(`ZodUnion`,(e,t)=>{mm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>t_(e,t,n,r),e.options=t.options});function xv(e,t){return new bv({type:`union`,options:e,...X(t)})}var Sv=Z(`ZodDiscriminatedUnion`,(e,t)=>{bv.init(e,t),gm.init(e,t)});function Cv(e,t,n){return new Sv({type:`union`,options:t,discriminator:e,...X(n)})}var wv=Z(`ZodIntersection`,(e,t)=>{_m.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>n_(e,t,n,r)});function Tv(e,t){return new wv({type:`intersection`,left:e,right:t})}var Ev=Z(`ZodRecord`,(e,t)=>{N_(),bm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>o_(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function Dv(e,t,n){return!t||!t._zod?new Ev({type:`record`,keyType:Q(),valueType:e,...X(t)}):new Ev({type:`record`,keyType:e,valueType:t,...X(n)})}var Ov=Z(`ZodEnum`,(e,t)=>{xm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jg(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Ov({...t,checks:[],...X(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Ov({...t,checks:[],...X(r),entries:i})}});function kv(e,t){return new Ov({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...X(t)})}var Av=Z(`ZodLiteral`,(e,t)=>{Sm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yg(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function jv(e,t){return new Av({type:`literal`,values:Array.isArray(e)?e:[e],...X(t)})}var Mv=Z(`ZodTransform`,(e,t)=>{N_(),Cm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zg(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Md(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(pd(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(pd(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Nv(e){return new Mv({type:`transform`,transform:e})}var Pv=Z(`ZodOptional`,(e,t)=>{Tm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>g_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Fv(e){return new Pv({type:`optional`,innerType:e})}var Iv=Z(`ZodExactOptional`,(e,t)=>{Em.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>g_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Lv(e){return new Iv({type:`optional`,innerType:e})}var Rv=Z(`ZodNullable`,(e,t)=>{Dm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>s_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function zv(e){return new Rv({type:`nullable`,innerType:e})}var Bv=Z(`ZodDefault`,(e,t)=>{Om.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>d_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Vv(e,t){return new Bv({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bu(t)}})}var Hv=Z(`ZodPrefault`,(e,t)=>{Am.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>f_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Uv(e,t){return new Hv({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():Bu(t)}})}var Wv=Z(`ZodNonOptional`,(e,t)=>{jm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>c_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Gv(e,t){return new Wv({type:`nonoptional`,innerType:e,...X(t)})}var Kv=Z(`ZodCatch`,(e,t)=>{Pm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>p_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function qv(e,t){return new Kv({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:Ed(t)})}var Jv=Z(`ZodPipe`,(e,t)=>{Fm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>m_(e,t,n,r),e.in=t.in,e.out=t.out});function Yv(e,t){return new Jv({type:`pipe`,in:e,out:t})}var Xv=Z(`ZodReadonly`,(e,t)=>{Lm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>h_(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Zv(e){return new Xv({type:`readonly`,innerType:e})}var Qv=Z(`ZodCustom`,(e,t)=>{zm.init(e,t),P_.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xg(e,t,n,r)});function $v(e,t={}){return ug(Qv,e,t)}function ey(e,t){return dg(e,t)}var ty=kv([`T0`,`T1`,`T2`,`T3`]);kv([`owner`,`guest`,`member`]);var ny=cv().min(0).max(1),ry=xv([kv([`auto`,`center`,`left`,`right`,`top`,`bottom`]),$({x:ny,y:ny,w:ny,h:ny})]),iy=kv([`ambient`,`conversation`,`focus`,`multi`]),ay=kv([`idle`,`listening`,`thinking`,`speaking`]),oy=kv([`sphere`,`orb`,`ring`]),sy=$({id:Q().min(1).max(64),type:kv([`card`,`stat`,`list`,`table`,`code`,`chart`,`gauge`,`timeline`,`graph`,`sandbox`]),props:Dv(Q(),mv()),placement:ry,ttl:cv().positive().max(3600).optional(),style:kv([`glass`,`alert`]).optional(),pinned:fv().optional()}),cy=Cv(`cmd`,[$({cmd:jv(`scene`),mode:iy}),$({cmd:jv(`show`),object:sy}),$({cmd:jv(`update`),id:Q(),props:Dv(Q(),mv())}),$({cmd:jv(`hide`),id:Q()}),$({cmd:jv(`clear`)}),$({cmd:jv(`pin`),id:Q()}),$({cmd:jv(`unpin`),id:Q()}),$({cmd:jv(`place`),id:Q(),placement:ry}),$({cmd:jv(`presence`),state:ay.optional(),style:oy.optional()}),$({cmd:jv(`mood`),accent:Q().max(16).optional(),intensity:ny.optional()})]),ly=$({scene:iy,objects:vv(sy),presence:$({state:ay,style:oy}),mood:$({accent:Q(),intensity:ny})}),uy={center:[20,18,60,58],left:[3,12,30,70],right:[67,12,30,70],top:[20,4,60,30],bottom:[20,62,60,30]};Object.keys(uy);var dy=[{id:`en_US-amy-medium`,name:`Amy`,gender:`female`,accent:`American`},{id:`en_US-kristin-medium`,name:`Kristin`,gender:`female`,accent:`American`},{id:`en_US-hfc_female-medium`,name:`Hannah`,gender:`female`,accent:`American`,note:`clear and steady`},{id:`en_GB-jenny_dioco-medium`,name:`Jenny`,gender:`female`,accent:`British`},{id:`en_GB-alba-medium`,name:`Alba`,gender:`female`,accent:`Scottish`},{id:`en_US-kathleen-low`,name:`Kathleen`,gender:`female`,accent:`American`,note:`smaller and faster`},{id:`en_US-ryan-medium`,name:`Ryan`,gender:`male`,accent:`American`},{id:`en_US-joe-medium`,name:`Joe`,gender:`male`,accent:`American`},{id:`en_US-norman-medium`,name:`Norman`,gender:`male`,accent:`American`},{id:`en_US-hfc_male-medium`,name:`Henry`,gender:`male`,accent:`American`,note:`clear and steady`},{id:`en_GB-alan-medium`,name:`Alan`,gender:`male`,accent:`British`},{id:`en_GB-northern_english_male-medium`,name:`Tom`,gender:`male`,accent:`Northern English`}],fy=[{id:`hi_IN-priyamvada-medium`,name:`Priyamvada`,gender:`female`,accent:`Hindi`,note:`for personal use (non-commercial licence)`},{id:`hi_IN-pratham-medium`,name:`Pratham`,gender:`male`,accent:`Hindi`,note:`for personal use (non-commercial licence)`},{id:`hi_IN-rohan-medium`,name:`Rohan`,gender:`male`,accent:`Hindi`}],py=[{id:`mr_IN-google-medium`,name:`Marathi`,gender:`female`,accent:`Marathi`}],my={id:`en_US-lessac-medium`,name:`Lessac`,accent:`American`,note:`the original voice`},hy=e=>e===my.id||dy.some(t=>t.id===e),gy=[{id:`aurora`,name:`Aurora`,style:`sphere`,accent:`#3fd8ff`,intensity:.6},{id:`ocean`,name:`Ocean`,style:`sphere`,accent:`#2b7bff`,intensity:.6},{id:`ember`,name:`Ember`,style:`orb`,accent:`#ff9b3d`,intensity:.7},{id:`violet`,name:`Violet storm`,style:`orb`,accent:`#a066ff`,intensity:.8},{id:`matrix`,name:`Matrix`,style:`ring`,accent:`#3dff8c`,intensity:.6},{id:`rose`,name:`Rose`,style:`ring`,accent:`#ff6fae`,intensity:.7},{id:`ghost`,name:`Ghost`,style:`sphere`,accent:`#e8f4ff`,intensity:.4}],_y=kv([`minimal`,`companion`,`workspace`]),vy=$({size:cv().min(.5).max(1.5),reactivity:cv().min(0).max(1),ambient:fv(),captions:fv(),captionSize:kv([`small`,`medium`,`large`])}),yy={width:cv().int().min(100).max(1e4),height:cv().int().min(100).max(1e4),kind:kv([`phone`,`tablet`,`desktop`]),orientation:kv([`portrait`,`landscape`]),touch:fv()};$(yy);var by=$({id:Q(),tool:Q(),summary:Q(),tier:ty,needsPin:fv()}),xy=Cv(`type`,[$({type:jv(`stage`),command:cy}),$({type:jv(`caption.delta`),text:Q()}),$({type:jv(`caption.end`)}),$({type:jv(`approval.request`)}).merge(by),$({type:jv(`approval.resolved`),id:Q()}),$({type:jv(`alert`),level:kv([`info`,`warn`,`error`]),text:Q()}),$({type:jv(`chat.user`),text:Q()}),$({type:jv(`ui`),view:_y,look:vy.optional(),ownerName:Q().max(40).optional()}),$({type:jv(`activity`),text:Q().max(80).nullable()}),$({type:jv(`status`),busy:fv(),deviceOnline:fv(),voiceAvailable:fv().optional(),voiceEnrolled:fv().optional(),message:Q().optional()}),$({type:jv(`voice.heard`),text:Q(),trust:kv([`owner`,`guest`,`unverified`,`member`]).optional(),speaker:Q().max(60).optional()}),$({type:jv(`voice.challenge`),id:Q(),text:Q()}),$({type:jv(`voice.challenge.end`),id:Q()}),$({type:jv(`audio.chunk`),id:Q(),seq:cv().int().min(0),last:fv(),mime:Q(),data:Q()}),$({type:jv(`audio.stop`)}),$({type:jv(`camera.request`),id:Q()}),$({type:jv(`camera.cancel`),id:Q()}),$({type:jv(`snapshot`),stage:ly,pendingApproval:by.nullable().optional()}),$({type:jv(`error`),message:Q()})]),Sy=$({type:jv(`approval.respond`),id:Q(),decision:kv([`approve`,`deny`,`approve_always`]),pin:Q().max(32).optional()});Cv(`type`,[$({type:jv(`chat.send`),text:Q().min(1).max(8e3)}),$({type:jv(`stage.event`),objectId:Q(),event:Q().max(64)}),Sy,$({type:jv(`voice.interrupt`)}),$({type:jv(`voice.confirm`),id:Q(),pin:Q().max(32)}),$({type:jv(`voice.cancel`),id:Q()}),$({type:jv(`camera.denied`),id:Q(),reason:kv([`off`,`no-camera`,`permission`,`busy`])}),$({type:jv(`ui.panels`),open:vv(kv([`chat`,`tasks`])).max(2)}),$({type:jv(`ui.screen`),...yy}),$({type:jv(`stage.move`),objectId:Q().max(64),rect:$({x:cv().min(0).max(1),y:cv().min(0).max(1),w:cv().min(0).max(1),h:cv().min(0).max(1)})}),$({type:jv(`stage.pin`),objectId:Q().max(64),pinned:fv()}),$({type:jv(`ping`)})]),$({type:jv(`tool.exec`),id:Q(),tool:Q(),args:mv(),approvedOutside:fv().optional()}),Cv(`type`,[$({type:jv(`tool.result`),id:Q(),result:$({output:Q(),truncated:fv()})}),$({type:jv(`tool.error`),id:Q(),error:Q()})]),$({path:Q()}),$({path:Q()}),$({path:Q(),content:Q()}),$({}),$({}),$({command:Q().min(1),cwd:Q().optional()}),$({city:Q().min(1).max(80)}),$({plugin:Q().min(1).max(40),name:Q().min(1).max(40)}),$({language:kv([`python`,`node`,`shell`]),code:Q().min(1).max(5e4),timeoutSec:cv().int().min(1).max(60).optional()}),$({text:Q().min(1).max(4e3)}),$({query:Q().min(1).max(200)}),$({id:cv().int().positive()}),$({title:Q().min(1).max(1e3),inMinutes:cv().int().min(1).max(525600).optional(),dueAt:Q().max(40).optional(),repeat:kv([`hourly`,`daily`,`weekly`]).optional()}),$({}),$({id:cv().int().positive()}),$({id:cv().int().positive()}),$({}),$({}),$({settings:Dv(Q(),mv())}),$({style:oy.optional(),accent:Q().regex(/^#[0-9a-fA-F]{6}$/).optional(),intensity:cv().min(0).max(1).optional(),size:cv().min(.5).max(1.5).optional(),reactivity:cv().min(0).max(1).optional(),ambient:fv().optional(),captions:fv().optional(),captionSize:kv([`small`,`medium`,`large`]).optional()}),$({view:_y}),$({}),$({id:Q().min(1).max(16),name:Q().min(1).max(60),kind:kv([`stdio`,`http`]),command:Q().max(260).optional(),args:vv(Q().max(500)).max(20).optional(),url:Q().max(2e3).optional()}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({id:Q().min(1).max(16)}),$({}),$({id:Q().min(1).max(40),name:Q().min(1).max(80),description:Q().max(500).optional(),skills:vv($({name:Q().min(1).max(40),description:Q().min(1).max(300),text:Q().min(1).max(2e4)})).max(10).optional(),tools:vv($({name:Q().min(1).max(40),description:Q().min(1).max(500),language:kv([`python`,`node`,`shell`]),code:Q().min(1).max(5e4),parameters:Dv(Q(),$({type:kv([`string`,`number`,`integer`,`boolean`]),description:Q().max(300).optional(),enum:vv(Q().max(100)).max(50).optional()})).optional(),required:vv(Q()).optional()})).max(10).optional()}),$({}),$({id:Q().min(1).max(40)}),$({id:Q().min(1).max(40)}),$({id:Q().min(1).max(40)}),$({mode:iy}),$({object:sy}),$({id:Q(),props:Dv(Q(),mv())}),$({id:Q()}),$({}),$({id:Q()}),$({id:Q()}),$({state:ay.optional(),style:oy.optional()}),$({accent:Q().max(16).optional(),intensity:cv().min(0).max(1).optional()});var Cy=[`#3fd8ff`,`#2b7bff`,`#a066ff`,`#ff6fae`,`#ff5a5a`,`#ff9b3d`,`#ffd23d`,`#3dff8c`,`#e8f4ff`],wy=[{id:`sphere`,name:`Sphere`,note:`A cloud of particles`},{id:`orb`,name:`Orb`,note:`A glowing plasma ball`},{id:`ring`,name:`Ring`,note:`Radial bars, like a voice meter`}],Ty=(e,t)=>e.style===t.style&&e.accent.toLowerCase()===t.accent&&Math.abs(e.intensity-t.intensity)<.005,Ey=[{id:`model`,label:`Model`,note:`Where Friend thinks`},{id:`voice`,label:`Voice`,note:`Speaking and listening`},{id:`look`,label:`Voice presence`,note:`How it looks`}],Dy=[{id:`claude-code`,label:`Claude subscription (Claude Code)`,note:`Uses the Claude Code app you are signed in to. No API key.`},{id:`claude`,label:`Claude API key`,note:`Pay per use with an Anthropic API key.`},{id:`ollama`,label:`Local model (Ollama)`,note:`Runs on this PC. Free and private, but slower.`},{id:`openai`,label:`OpenAI-compatible server (OmniRoute, LM Studio…)`,note:`Any server that speaks the OpenAI chat API. OmniRoute is one address that routes to many models, many of them free.`}],Oy={"voice.enabled":`Speech on/off`,"voice.ttsVoice":`Voice`,"voice.sttModel":`Listening model`};function ky({label:e,children:t,hint:n}){return(0,p.jsxs)(`label`,{className:`settings-field`,children:[(0,p.jsx)(`span`,{children:e}),t,n&&(0,p.jsx)(`small`,{className:`auth-note`,children:n})]})}function Ay({api:e=Ie,onClose:t,initialTab:n=`model`,preview:r=Le}){let[i,a]=(0,l.useState)(null),[o,s]=(0,l.useState)(null),[c,u]=(0,l.useState)(n),[f,m]=(0,l.useState)(``),[h,g]=(0,l.useState)(``),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(``),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)(null),[E,D]=(0,l.useState)(null),[O,k]=(0,l.useState)(null),[A,j]=(0,l.useState)(null),ee=(0,l.useRef)(!0);(0,l.useEffect)(()=>(ee.current=!0,e.get().then(e=>{ee.current&&(a(e),s(structuredClone(e)))}).catch(e=>ee.current&&T(e.message)),()=>{ee.current=!1}),[e]);let M=(e,t=!1)=>(0,p.jsxs)(`div`,{className:`approval settings glass${t?` settings-wide`:``}`,role:`dialog`,"aria-label":`Settings`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:`Settings`})}),e]});if(!o||!i)return M((0,p.jsxs)(p.Fragment,{children:[w?(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}):(0,p.jsx)(`p`,{className:`auth-note`,children:`Loading…`}),(0,p.jsx)(`div`,{className:`approval-actions`,children:(0,p.jsx)(`button`,{type:`button`,style:d,onClick:t,children:`Close`})})]}));let N=Re(i,o,f,h),P=Object.keys(N).length>0,F=(e,t,n)=>s({...o,[e]:{...o[e],[t]:n}}),I=o.look,te=(e,t)=>{t&&(k(e),j(e===`main`?null:`The first time, the voice downloads (about 64 MB). Please wait…`),r(t).then(()=>ee.current&&j(`Playing…`)).catch(e=>ee.current&&j(e.message)).finally(()=>ee.current&&k(null)))},ne=async t=>{T(null),C(!0);try{let n=await e.save(N,t);if(!ee.current)return;a(n.settings),s(structuredClone(n.settings)),m(``),g(``),v(!1);let r=N.voice&&N.voice.ttsVoice!==void 0;D(n.restart.length?`Saved. Restart Friend for: ${n.restart.map(e=>Oy[e]??e).join(`, `)}.`:r?`Saved. The new voice is loading; you will get a message when it is ready (the first time it downloads about 60 MB).`:Pe(N)?`Saved. It is in use now.`:`Saved. Every open screen has changed.`)}catch(e){ee.current&&T(e.message)}finally{ee.current&&(C(!1),b(``))}};if(_)return M((0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:`Enter your PIN to save these changes.`}),(0,p.jsx)(x,{pin:y,onChange:b,onSubmit:()=>!S&&void ne(y)}),w&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:S||y.length<6,onClick:()=>void ne(y),children:`Save`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{v(!1),b(``),T(null)},children:`Back`})]})]}));let L=Dy.find(e=>e.id===o.provider),re=e=>{let t=Ey.findIndex(e=>e.id===c),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%Ey.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t+Ey.length-1)%Ey.length:e.key===`Home`?0:e.key===`End`?Ey.length-1:-1;n<0||(e.preventDefault(),u(Ey[n].id),document.getElementById(`settings-tab-${Ey[n].id}`)?.focus())},ie=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Where Friend thinks`}),(0,p.jsx)(ky,{label:`Model provider`,hint:L.note,children:(0,p.jsx)(`select`,{value:o.provider,onChange:e=>s({...o,provider:e.target.value}),children:Dy.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.label},e.id))})}),o.provider===`claude-code`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(ky,{label:`Claude model`,hint:`sonnet, haiku, opus, or a full model name`,children:[(0,p.jsx)(`input`,{list:`cc-models`,value:o.claudeCode.model,onChange:e=>F(`claudeCode`,`model`,e.target.value)}),(0,p.jsxs)(`datalist`,{id:`cc-models`,children:[(0,p.jsx)(`option`,{value:`sonnet`}),(0,p.jsx)(`option`,{value:`haiku`}),(0,p.jsx)(`option`,{value:`opus`})]})]}),(0,p.jsx)(ky,{label:`If Claude is unavailable`,hint:`For example when the plan's usage limit is reached.`,children:(0,p.jsxs)(`select`,{value:o.claudeCode.fallback,onChange:e=>F(`claudeCode`,`fallback`,e.target.value),children:[(0,p.jsx)(`option`,{value:`ollama`,children:`Answer with the local model (Ollama)`}),(0,p.jsx)(`option`,{value:`none`,children:`Show an error`})]})}),(0,p.jsx)(ky,{label:`Claude Code command`,hint:`Leave as it is unless the program is somewhere else.`,children:(0,p.jsx)(`input`,{value:o.claudeCode.command,onChange:e=>F(`claudeCode`,`command`,e.target.value)})})]}),o.provider===`claude`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ky,{label:`Claude model`,children:(0,p.jsx)(`input`,{value:o.model,onChange:e=>s({...o,model:e.target.value})})}),(0,p.jsx)(ky,{label:`API key`,hint:i.apiKeySet?`A key is saved. Type a new one only to replace it.`:`No key saved yet.`,children:(0,p.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:i.apiKeySet?`saved`:`sk-ant-…`,value:f,onChange:e=>m(e.target.value)})})]}),o.provider===`openai`&&o.openai&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ky,{label:`Server address`,hint:`Ends in /v1. OmniRoute: http://localhost:20128/v1 (install it with npm install -g omniroute, then run omniroute).`,children:(0,p.jsx)(`input`,{value:o.openai.url,onChange:e=>s({...o,openai:{...o.openai,url:e.target.value}})})}),(0,p.jsx)(ky,{label:`Model`,hint:`The name that server knows. OmniRoute answers to auto.`,children:(0,p.jsx)(`input`,{value:o.openai.model,onChange:e=>s({...o,openai:{...o.openai,model:e.target.value}})})}),(0,p.jsx)(ky,{label:`API key`,hint:i.openai?.apiKeySet?`A key is saved. Type a new one only to replace it.`:`Leave empty if the server asks for none.`,children:(0,p.jsx)(`input`,{type:`password`,autoComplete:`off`,placeholder:i.openai?.apiKeySet?`saved`:``,value:h,onChange:e=>g(e.target.value)})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.openai.vision,onChange:e=>s({...o,openai:{...o.openai,vision:e.target.checked}})}),` This model can look at pictures`]})]}),(o.provider===`ollama`||o.provider===`claude-code`&&o.claudeCode.fallback===`ollama`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Local model (Ollama)`}),(0,p.jsx)(ky,{label:`Address`,children:(0,p.jsx)(`input`,{value:o.ollama.url,onChange:e=>F(`ollama`,`url`,e.target.value)})}),(0,p.jsx)(ky,{label:`Model`,children:(0,p.jsx)(`input`,{value:o.ollama.model,onChange:e=>F(`ollama`,`model`,e.target.value)})}),(0,p.jsx)(ky,{label:`Memory window (tokens)`,children:(0,p.jsx)(`input`,{type:`number`,min:1024,max:131072,step:1024,value:o.ollama.contextTokens,onChange:e=>F(`ollama`,`contextTokens`,Number(e.target.value))})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.ollama.vision,onChange:e=>F(`ollama`,`vision`,e.target.checked)}),` This model can look at pictures`]})]})]}),ae=(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Speaking and listening`}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:o.voice.speakTyped,onChange:e=>F(`voice`,`speakTyped`,e.target.checked)}),` Also speak the replies to typed messages`]}),(0,p.jsx)(ky,{label:`Spoken language`,hint:`Leave empty to detect it by itself: best when you mix English, Hindi and Marathi. Or force one: en, hi, mr.`,children:(0,p.jsx)(`input`,{value:o.voice.language??``,maxLength:10,onChange:e=>F(`voice`,`language`,e.target.value.trim()===``?null:e.target.value.trim())})}),(0,p.jsx)(ky,{label:`Speaking voice`,hint:`Female or male. The first time a voice is used it downloads about 60 MB, then it works without internet.`,children:(0,p.jsxs)(`select`,{value:o.voice.ttsVoice,onChange:e=>F(`voice`,`ttsVoice`,e.target.value),children:[(0,p.jsx)(`optgroup`,{label:`Female`,children:dy.filter(e=>e.gender===`female`).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,p.jsx)(`optgroup`,{label:`Male`,children:dy.filter(e=>e.gender===`male`).map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.accent,e.note?` · ${e.note}`:``]},e.id))}),(0,p.jsx)(`optgroup`,{label:`Original`,children:(0,p.jsxs)(`option`,{value:my.id,children:[my.name,` · `,my.accent,` · `,my.note]})}),!hy(o.voice.ttsVoice)&&(0,p.jsx)(`optgroup`,{label:`Other`,children:(0,p.jsx)(`option`,{value:o.voice.ttsVoice,children:o.voice.ttsVoice})})]})}),(0,p.jsx)(ky,{label:`Hindi voice`,hint:`Reads Hindi (Devanagari) text; English words in the same sentence still use the voice above. The first time it downloads about 64 MB.`,children:(0,p.jsxs)(`select`,{value:o.voice.hindiVoice??``,onChange:e=>F(`voice`,`hindiVoice`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:`Same as the voice above`}),fy.map(e=>(0,p.jsxs)(`option`,{value:e.id,children:[e.name,` · `,e.gender,e.note?` · ${e.note}`:``]},e.id))]})}),(0,p.jsx)(ky,{label:`Marathi voice`,hint:`Reads Marathi text. Friend tells Marathi from Hindi by the words used.`,children:(0,p.jsxs)(`select`,{value:o.voice.marathiVoice??``,onChange:e=>F(`voice`,`marathiVoice`,e.target.value),children:[(0,p.jsx)(`option`,{value:``,children:`Same as the voice above`}),py.map(e=>(0,p.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,p.jsxs)(`div`,{className:`voice-hear`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,disabled:O!==null,onClick:()=>te(`main`,o.voice.ttsVoice),children:O===`main`?`Loading the voice…`:`Hear it`}),(0,p.jsx)(`button`,{type:`button`,style:d,disabled:O!==null||!o.voice.hindiVoice,onClick:()=>te(`hindi`,o.voice.hindiVoice??``),children:O===`hindi`?`Loading the voice…`:`Hear the Hindi voice`}),(0,p.jsx)(`button`,{type:`button`,style:d,disabled:O!==null||!o.voice.marathiVoice,onClick:()=>te(`marathi`,o.voice.marathiVoice??``),children:O===`marathi`?`Loading the voice…`:`Hear the Marathi voice`}),A&&(0,p.jsx)(`small`,{className:`auth-note`,role:`status`,children:A})]}),(0,p.jsx)(ky,{label:`Listening model`,hint:`tiny, base, small … Bigger is more accurate but slower. For Hindi and Marathi use small or larger (base mishears them). Needs a restart.`,children:(0,p.jsx)(`input`,{value:o.voice.sttModel,onChange:e=>F(`voice`,`sttModel`,e.target.value)})}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Who is speaking`}),(0,p.jsx)(ky,{label:`"It is me" match level: ${o.voice.accept.toFixed(2)}`,hint:`Higher is stricter. Only matters after you enrolled your voice.`,children:(0,p.jsx)(`input`,{type:`range`,min:.3,max:.95,step:.01,value:o.voice.accept,onChange:e=>F(`voice`,`accept`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`"Ask for my PIN" level: ${o.voice.challenge.toFixed(2)}`,hint:`Voices between this and the level above must be confirmed with the PIN.`,children:(0,p.jsx)(`input`,{type:`range`,min:.2,max:.9,step:.01,value:o.voice.challenge,onChange:e=>F(`voice`,`challenge`,Number(e.target.value))})})]}),oe=(0,p.jsxs)(`div`,{className:`look-tab`,children:[(0,p.jsxs)(`div`,{className:`look-side`,children:[(0,p.jsx)(_u,{look:I}),(0,p.jsx)(`p`,{className:`auth-note`,children:`This is a live preview. Nothing changes on the screen until you save.`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>s({...o,look:{...Me}}),children:`Back to the default look`})]}),(0,p.jsxs)(`div`,{className:`look-controls`,children:[(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Themes`}),(0,p.jsx)(`div`,{className:`theme-grid`,role:`group`,"aria-label":`Themes`,children:gy.map(e=>(0,p.jsxs)(`button`,{type:`button`,className:`theme-card${Ty(I,e)?` on`:``}`,"aria-pressed":Ty(I,e),style:{"--swatch":e.accent},onClick:()=>s({...o,look:{...I,style:e.style,accent:e.accent,intensity:e.intensity}}),children:[(0,p.jsx)(`i`,{"aria-hidden":`true`}),(0,p.jsx)(`b`,{children:e.name}),(0,p.jsx)(`small`,{children:e.style})]},e.id))}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Shape`}),(0,p.jsx)(`div`,{className:`style-row`,role:`radiogroup`,"aria-label":`Style`,children:wy.map(e=>(0,p.jsxs)(`button`,{type:`button`,role:`radio`,"aria-checked":I.style===e.id,className:`style-choice${I.style===e.id?` on`:``}`,onClick:()=>F(`look`,`style`,e.id),children:[(0,p.jsx)(`b`,{children:e.name}),(0,p.jsx)(`small`,{children:e.note})]},e.id))}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Colour and light`}),(0,p.jsxs)(`div`,{className:`swatch-row`,role:`group`,"aria-label":`Colour`,children:[Cy.map(e=>(0,p.jsx)(`button`,{type:`button`,"aria-label":`Colour ${e}`,"aria-pressed":I.accent.toLowerCase()===e,className:`swatch${I.accent.toLowerCase()===e?` on`:``}`,style:{background:e},onClick:()=>F(`look`,`accent`,e)},e)),(0,p.jsxs)(`label`,{className:`swatch-custom`,children:[(0,p.jsx)(`span`,{children:`Other`}),(0,p.jsx)(`input`,{type:`color`,"aria-label":`Pick another colour`,value:I.accent,onChange:e=>F(`look`,`accent`,e.target.value.toLowerCase())})]})]}),(0,p.jsx)(ky,{label:`Brightness: ${Math.round(I.intensity*100)}%`,children:(0,p.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:I.intensity,onChange:e=>F(`look`,`intensity`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`Size: ${Math.round(I.size*100)}%`,hint:`How big it is in the middle of the screen.`,children:(0,p.jsx)(`input`,{type:`range`,min:.5,max:1.5,step:.05,value:I.size,onChange:e=>F(`look`,`size`,Number(e.target.value))})}),(0,p.jsx)(ky,{label:`Reaction to my voice: ${Math.round(I.reactivity*100)}%`,hint:`Low is calm, high moves a lot when anyone speaks.`,children:(0,p.jsx)(`input`,{type:`range`,min:0,max:1,step:.05,value:I.reactivity,onChange:e=>F(`look`,`reactivity`,Number(e.target.value))})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.ambient,onChange:e=>F(`look`,`ambient`,e.target.checked)}),` Soft glow behind everything`]}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`Words on the screen`}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.captions,onChange:e=>F(`look`,`captions`,e.target.checked)}),` Show the live words while Friend speaks`]}),(0,p.jsx)(ky,{label:`Caption size`,children:(0,p.jsxs)(`select`,{value:I.captionSize,disabled:!I.captions,onChange:e=>F(`look`,`captionSize`,e.target.value),children:[(0,p.jsx)(`option`,{value:`small`,children:`Small`}),(0,p.jsx)(`option`,{value:`medium`,children:`Medium`}),(0,p.jsx)(`option`,{value:`large`,children:`Large`})]})}),(0,p.jsx)(`h4`,{className:`plugins-heading`,children:`What is on the screen`}),(0,p.jsx)(ky,{label:`Your name`,hint:`Shown on the badge in the corner, next to the shield, while you are signed in. Empty shows Owner.`,children:(0,p.jsx)(`input`,{value:o.ownerName??``,maxLength:40,placeholder:`Owner`,onChange:e=>s({...o,ownerName:e.target.value})})}),(0,p.jsx)(ky,{label:`View`,hint:`Minimal: only the voice presence. Companion: plus a status line and a clock. Workspace: also the chat and the schedule. Drag any panel to move it.`,children:(0,p.jsxs)(`select`,{value:o.view,onChange:e=>s({...o,view:e.target.value}),children:[(0,p.jsx)(`option`,{value:`minimal`,children:`Minimal`}),(0,p.jsx)(`option`,{value:`companion`,children:`Companion`}),(0,p.jsx)(`option`,{value:`workspace`,children:`Workspace`})]})}),(0,p.jsxs)(`label`,{className:`settings-check`,children:[(0,p.jsx)(`input`,{type:`checkbox`,checked:I.aiMayChange,onChange:e=>F(`look`,`aiMayChange`,e.target.checked)}),` Let the AI change the shape, colour and brightness to suit a topic`]}),(0,p.jsx)(`small`,{className:`auth-note`,children:`Off keeps exactly the look you chose. You can still ask it to change the look yourself.`})]})]});return M((0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`settings-layout`,children:[(0,p.jsx)(`div`,{className:`settings-tabs`,role:`tablist`,"aria-label":`Settings sections`,"aria-orientation":`vertical`,onKeyDown:re,children:Ey.map(e=>(0,p.jsxs)(`button`,{id:`settings-tab-${e.id}`,type:`button`,role:`tab`,"aria-selected":c===e.id,"aria-controls":`settings-panel-${e.id}`,tabIndex:c===e.id?0:-1,className:`settings-tab${c===e.id?` on`:``}`,onClick:()=>u(e.id),children:[(0,p.jsx)(`b`,{children:e.label}),(0,p.jsx)(`small`,{children:e.note})]},e.id))}),(0,p.jsxs)(`div`,{className:`settings-body`,role:`tabpanel`,id:`settings-panel-${c}`,"aria-labelledby":`settings-tab-${c}`,children:[c===`model`&&ie,c===`voice`&&ae,c===`look`&&oe]})]}),E&&!P&&(0,p.jsx)(`p`,{className:`auth-note`,children:E}),w&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:w}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:!P||S,onClick:()=>{D(null),T(null),Pe(N)?v(!0):ne()},children:P&&!Pe(N)?`Save`:`Save…`}),P&&(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{s(structuredClone(i)),m(``),g(``)},children:`Undo changes`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:t,children:`Close`})]}),(0,p.jsx)(`p`,{className:`auth-note`,children:`Network, folders and safety rules are not here on purpose. Change those in the terminal: friend config set.`})]}),!0)}var jy=e=>e instanceof HTMLElement&&(e.tagName===`INPUT`||e.tagName===`TEXTAREA`||e.isContentEditable);function My({onSend:e,requestOpen:t,slash:n,onOpenChange:r}){let[i,a]=(0,l.useState)(!1),o=(0,l.useRef)(r);o.current=r,(0,l.useEffect)(()=>o.current?.(i),[i]);let[s,c]=(0,l.useState)(``),[u,d]=(0,l.useState)(0),f=(0,l.useRef)(null);if((0,l.useEffect)(()=>{t>0&&a(!0)},[t]),(0,l.useEffect)(()=>{let e=e=>{i||jy(e.target)||e.ctrlKey||e.metaKey||e.altKey||e.key.length===1&&(e.preventDefault(),c(e.key),d(0),a(!0))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[i]),(0,l.useEffect)(()=>{i&&f.current?.focus()},[i]),!i)return null;let m=n?ee(n.commands,s):[],h=m[Math.min(u,Math.max(m.length-1,0))],g=()=>{c(``),d(0),a(!1)},_=()=>{let t=s.trim();if(n&&j(t)){let e=/^\/\S*\s/.test(t);n.run(!e&&h?`/${h.name}`:t)}else t&&e(N(t));g()};return(0,p.jsxs)(`form`,{className:`command-bar`,onSubmit:e=>{e.preventDefault(),_()},children:[m.length>0&&(0,p.jsx)(`ul`,{className:`slash-list`,role:`listbox`,"aria-label":`Commands`,children:m.map((e,t)=>(0,p.jsxs)(`li`,{role:`option`,"aria-selected":e===h,className:e===h?`on`:void 0,onMouseDown:n=>{n.preventDefault(),c(`/${e.name} `),f.current?.focus(),d(t)},children:[(0,p.jsxs)(`b`,{children:[`/`,e.name]}),e.usage&&(0,p.jsx)(`i`,{children:e.usage}),(0,p.jsx)(`span`,{children:e.description})]},e.name))}),(0,p.jsx)(`input`,{ref:f,"aria-label":`Message`,value:s,placeholder:`Talk to me… or type / for commands`,autoComplete:`off`,onChange:e=>{c(e.target.value),d(0)},onKeyDown:e=>{e.key===`Escape`?(e.stopPropagation(),g()):m.length>0&&(e.key===`ArrowDown`||e.key===`ArrowUp`)?(e.preventDefault(),d(t=>(t+(e.key===`ArrowDown`?1:m.length-1))%m.length)):e.key===`Tab`&&h&&(e.preventDefault(),c(`/${h.name} `))}}),(0,p.jsx)(`button`,{type:`submit`,"aria-label":`Send`,children:`↵`})]})}var Ny={width:24,height:24,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:1.8,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0},Py=(e,t)=>e===`listening`?t?`Listening… tap to send`:`Listening… let go to send`:e===`transcribing`?`Understanding…`:e===`speaking`?`Tap to talk over me`:`Hold to talk, or tap once`;function Fy({voice:e,mode:t,onType:n,onMenu:r}){let i=(0,l.useRef)(null),a=(0,l.useRef)(!1),[o,s]=(0,l.useState)(!1),c=e=>{a.current=e,s(e)},u=(0,l.useRef)(t);u.current=t,(0,l.useEffect)(()=>{t!==`listening`&&!i.current&&c(!1)},[t]);let d=t=>{if((t.pointerType!==`mouse`||t.button===0)&&!i.current){if(a.current&&u.current===`listening`){c(!1),e.pressEnd();return}c(!1),i.current={at:Date.now(),id:t.pointerId};try{t.currentTarget.setPointerCapture?.(t.pointerId)}catch{}e.pressStart()}},f=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,Date.now()-n.at>=450?e.pressEnd():c(!0))},m=t=>{let n=i.current;n&&n.id===t.pointerId&&(i.current=null,c(!1),e.blur?.())},h=t===`listening`;return(0,p.jsxs)(`div`,{className:`touch-controls`,"data-testid":`touch-controls`,children:[(0,p.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Open the menu`,onClick:r,children:(0,p.jsx)(`svg`,{...Ny,children:(0,p.jsx)(`path`,{d:`M4 7h16M4 12h16M4 17h16`})})}),(0,p.jsxs)(`div`,{className:`touch-talk`,children:[(0,p.jsx)(`button`,{type:`button`,className:`touch-mic${h?` on`:``}`,"aria-label":`Talk to Friend`,"aria-pressed":h,onPointerDown:d,onPointerUp:f,onPointerCancel:m,onContextMenu:e=>e.preventDefault(),children:(0,p.jsxs)(`svg`,{...Ny,width:30,height:30,children:[(0,p.jsx)(`rect`,{x:`9`,y:`3`,width:`6`,height:`11`,rx:`3`}),(0,p.jsx)(`path`,{d:`M5 11a7 7 0 0 0 14 0M12 18v3`})]})}),(0,p.jsx)(`span`,{className:`touch-hint`,"aria-live":`polite`,children:Py(t,o)})]}),(0,p.jsx)(`button`,{type:`button`,className:`touch-side`,"aria-label":`Type a message`,onClick:n,children:(0,p.jsxs)(`svg`,{...Ny,children:[(0,p.jsx)(`rect`,{x:`3`,y:`6`,width:`18`,height:`12`,rx:`2`}),(0,p.jsx)(`path`,{d:`M7 10h.01M11 10h.01M15 10h.01M7 14h10`})]})})]})}function Iy(e,t){this.v=e,this.k=t}function Ly(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Ry(e){if(Array.isArray(e))return e}function zy(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function By(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4386
4386
  In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function Vy(e,t){return Ry(e)||zy(e,t)||Hy(e,t)||By()}function Hy(e,t){if(e){if(typeof e==`string`)return Ly(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Ly(e,t):void 0}}function Uy(e){var t,n;function r(t,n){try{var a=e[t](n),o=a.value,s=o instanceof Iy;Promise.resolve(s?o.v:o).then(function(n){if(s){var c=t===`return`&&o.k?t:`next`;if(!o.k||n.done)return r(c,n);n=e[c](n).value}i(!!a.done,n)},function(e){r(`throw`,e)})}catch(e){i(2,e)}}function i(e,i){e===2?t.reject(i):t.resolve({value:i,done:e}),(t=t.next)?r(t.key,t.arg):n=null}this._invoke=function(e,i){return new Promise(function(a,o){var s={key:e,arg:i,resolve:a,reject:o,next:null};n?n=n.next=s:(t=n=s,r(e,i))})},typeof e.return!=`function`&&(this.return=void 0)}Uy.prototype[typeof Symbol==`function`&&Symbol.asyncIterator||`@@asyncIterator`]=function(){return this},Uy.prototype.next=function(e){return this._invoke(`next`,e)},Uy.prototype.throw=function(e){return this._invoke(`throw`,e)},Uy.prototype.return=function(e){return this._invoke(`return`,e)};var Wy=Object.entries,Gy=Object.setPrototypeOf,Ky=Object.isFrozen,qy=Object.getPrototypeOf,Jy=Object.getOwnPropertyDescriptor,Yy=Object.freeze,Xy=Object.seal,Zy=Object.create,Qy=typeof Reflect<`u`&&Reflect,$y=Qy.apply,eb=Qy.construct;Yy||=function(e){return e},Xy||=function(e){return e},$y||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},eb||=function(e){return new e(...[...arguments].slice(1))};var tb=xb(Array.prototype.forEach);Array.prototype.indexOf;var nb=xb(Array.prototype.lastIndexOf),rb=xb(Array.prototype.pop),ib=xb(Array.prototype.push);Array.prototype.slice;var ab=xb(Array.prototype.splice),ob=Array.isArray,sb=xb(String.prototype.toLowerCase),cb=xb(String.prototype.toString),lb=xb(String.prototype.match),ub=xb(String.prototype.replace),db=xb(String.prototype.indexOf),fb=xb(String.prototype.trim),pb=xb(Number.prototype.toString),mb=xb(Boolean.prototype.toString),hb=typeof BigInt>`u`?null:xb(BigInt.prototype.toString),gb=typeof Symbol>`u`?null:xb(Symbol.prototype.toString),_b=xb(Object.prototype.hasOwnProperty),vb=xb(Object.prototype.toString),yb=xb(RegExp.prototype.test),bb=Sb(TypeError);function xb(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return $y(e,t,n)}}function Sb(e){return function(){return eb(e,[...arguments])}}function Cb(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:sb;if(Gy&&Gy(e,null),!ob(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(Ky(t)||(t[r]=e),i=e)}e[i]=!0}return e}function wb(e){for(let t=0;t<e.length;t++)_b(e,t)||(e[t]=null);return e}function Tb(e){let t=Zy(null);for(let r of Wy(e)){var n=Vy(r,2);let i=n[0],a=n[1];_b(e,i)&&(t[i]=ob(a)?wb(a):a&&typeof a==`object`&&a.constructor===Object?Tb(a):a)}return t}function Eb(e){switch(typeof e){case`string`:return e;case`number`:return pb(e);case`boolean`:return mb(e);case`bigint`:return hb?hb(e):`0`;case`symbol`:return gb?gb(e):`Symbol()`;case`undefined`:return vb(e);case`function`:case`object`:{if(e===null)return vb(e);let t=e,n=Db(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:vb(e)}return vb(e)}default:return vb(e)}}function Db(e,t){for(;e!==null;){let n=Jy(e,t);if(n){if(n.get)return xb(n.get);if(typeof n.value==`function`)return xb(n.value)}e=qy(e)}function n(){return null}return n}function Ob(e){try{return yb(e,``),!0}catch{return!1}}var kb=Yy(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),Ab=Yy(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),jb=Yy([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),Mb=Yy([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),Nb=Yy(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),Pb=Yy([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),Fb=Yy([`#text`]),Ib=Yy(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),Lb=Yy(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dominant-baseline.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.pointer-events.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-orientation.text-rendering.textlength.type.u1.u2.unicode.values.vector-effect.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),Rb=Yy(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),zb=Yy([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Bb=Xy(/{{[\w\W]*|^[\w\W]*}}/g),Vb=Xy(/<%[\w\W]*|^[\w\W]*%>/g),Hb=Xy(/\${[\w\W]*/g),Ub=Xy(/^data-[\-\w.\u00B7-\uFFFF]+$/),Wb=Xy(/^aria-[\-\w]+$/),Gb=Xy(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Kb=Xy(/^(?:\w+script|data):/i),qb=Xy(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Jb=Xy(/^html$/i),Yb=Xy(/^[a-z][.\w]*(-[.\w]+)+$/i),Xb=Xy(/<[/\w!]/g),Zb=Xy(/<[/\w]/g),Qb=Xy(/<\/no(script|embed|frames)/i),$b=Xy(/\/>/i),ex={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},tx=[`style`,`script`,`xmp`,`iframe`,`noembed`,`noframes`,`plaintext`,`noscript`],nx=Yy(Cb({},tx)),rx=function(){let e={};return tb(tx,t=>{e[t]=Xy(RegExp(`</`+t+`(?=[\\t\\n\\f\\r />])`,`i`))}),Yy(e)}(),ix=function(){return typeof window>`u`?null:window},ax=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},ox=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},sx=function(e,t,n,r){return _b(e,t)&&ob(e[t])?Cb(r.base?Tb(r.base):{},e[t],r.transform):n},cx=function(e,t,n){let r=_b(e,t)?e[t]:void 0;return r&&typeof r==`object`?Tb(r):n()};function lx(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:ix(),t=e=>lx(e);if(t.version=`3.4.16`,t.removed=[],!e||!e.document||e.document.nodeType!==ex.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=Db(d,`cloneNode`),p=Db(d,`remove`),m=Db(d,`removeAttributeNode`),h=Db(d,`nextSibling`),g=Db(d,`childNodes`),_=Db(d,`parentNode`),v=Db(d,`shadowRoot`),y=Db(d,`attributes`),b=o&&o.prototype?Db(o.prototype,`nodeType`):null,x=o&&o.prototype?Db(o.prototype,`nodeName`):null,S=o&&o.prototype?Db(o.prototype,`ownerDocument`):null,C=function(e){return b?b(e):e.nodeType},w=function(e){return x?x(e):e.nodeName};if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let T,E=``,D,O=!1,k=0,A=function(){if(k>0)throw bb(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},j=function(e){A(),k++;try{return T.createHTML(e)}finally{k--}},ee=function(e){A(),k++;try{return T.createScriptURL(e)}finally{k--}},M=function(){return O||=(D=ax(u,i),!0),D},N=n,P=N.implementation,F=N.createNodeIterator,I=N.createDocumentFragment,te=N.getElementsByTagName,ne=r.importNode,L=ox();t.isSupported=typeof Wy==`function`&&typeof _==`function`&&P&&P.createHTMLDocument!==void 0;let re=Bb,ie=Vb,ae=Hb,oe=Ub,se=Wb,ce=Kb,le=qb,ue=Yb,de=Gb,R=null,z=Cb({},[...kb,...Ab,...jb,...Nb,...Fb]),B=null,fe=Cb({},[...Ib,...Lb,...Rb,...zb]),pe=Object.seal(Zy(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),me=null,he=null,ge=Object.seal(Zy(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),V=!0,_e=!0,ve=!1,ye=!0,H=!1,be=!0,U=!1,W=!1,xe=null,Se=null,Ce=!1,we=!1,Te=!1,Ee=!1,De=!0,Oe=!1,ke=`user-content-`,Ae=!0,je=!1,Me={},Ne=null,Pe=Cb({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Fe=null,Ie=Cb({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Le=null,Re=Cb({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),ze=`http://www.w3.org/1998/Math/MathML`,Be=`http://www.w3.org/2000/svg`,Ve=`http://www.w3.org/1999/xhtml`,He=Ve,Ue=!1,We=null,Ge=Cb({},[ze,Be,Ve],cb),Ke=Yy([`mi`,`mo`,`mn`,`ms`,`mtext`]),qe=Cb({},Ke),Je=Yy([`annotation-xml`]),Ye=Cb({},Je),Xe=Cb({},[`title`,`style`,`font`,`a`,`script`]),Ze=null,Qe=[`application/xhtml+xml`,`text/html`],$e=null,et=null,tt=n.createElement(`form`),nt=function(e){return e instanceof RegExp||e instanceof Function},rt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(et&&et===e)return;(!e||typeof e!=`object`)&&(e={}),e=Tb(e),Ze=Qe.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,$e=Ze===`application/xhtml+xml`?cb:sb,R=sx(e,`ALLOWED_TAGS`,z,{transform:$e}),B=sx(e,`ALLOWED_ATTR`,fe,{transform:$e}),We=sx(e,`ALLOWED_NAMESPACES`,Ge,{transform:cb}),Le=sx(e,`ADD_URI_SAFE_ATTR`,Re,{transform:$e,base:Re}),Fe=sx(e,`ADD_DATA_URI_TAGS`,Ie,{transform:$e,base:Ie}),Ne=sx(e,`FORBID_CONTENTS`,Pe,{transform:$e}),me=sx(e,`FORBID_TAGS`,Tb({}),{transform:$e}),he=sx(e,`FORBID_ATTR`,Tb({}),{transform:$e}),Me=_b(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?Tb(e.USE_PROFILES):e.USE_PROFILES:!1,V=e.ALLOW_ARIA_ATTR!==!1,_e=e.ALLOW_DATA_ATTR!==!1,ve=e.ALLOW_UNKNOWN_PROTOCOLS||!1,ye=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,H=e.SAFE_FOR_TEMPLATES||!1,be=e.SAFE_FOR_XML!==!1,U=e.WHOLE_DOCUMENT||!1,we=e.RETURN_DOM||!1,Te=e.RETURN_DOM_FRAGMENT||!1,Ee=e.RETURN_TRUSTED_TYPE||!1,Ce=e.FORCE_BODY||!1,De=e.SANITIZE_DOM!==!1,Oe=e.SANITIZE_NAMED_PROPS||!1,Ae=e.KEEP_CONTENT!==!1,je=e.IN_PLACE||!1,de=Ob(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Gb,He=typeof e.NAMESPACE==`string`?e.NAMESPACE:Ve,qe=cx(e,`MATHML_TEXT_INTEGRATION_POINTS`,()=>Cb({},Ke)),Ye=cx(e,`HTML_INTEGRATION_POINTS`,()=>Cb({},Je));let t=cx(e,`CUSTOM_ELEMENT_HANDLING`,()=>Zy(null));if(pe=Zy(null),_b(t,`tagNameCheck`)&&nt(t.tagNameCheck)&&(pe.tagNameCheck=t.tagNameCheck),_b(t,`attributeNameCheck`)&&nt(t.attributeNameCheck)&&(pe.attributeNameCheck=t.attributeNameCheck),_b(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(pe.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),Xy(pe),H&&(_e=!1),Te&&(we=!0),Me&&(R=Cb({},Fb),B=Zy(null),Me.html===!0&&(Cb(R,kb),Cb(B,Ib)),Me.svg===!0&&(Cb(R,Ab),Cb(B,Lb),Cb(B,zb)),Me.svgFilters===!0&&(Cb(R,jb),Cb(B,Lb),Cb(B,zb)),Me.mathMl===!0&&(Cb(R,Nb),Cb(B,Rb),Cb(B,zb))),ge.tagCheck=null,ge.attributeCheck=null,_b(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?ge.tagCheck=e.ADD_TAGS:ob(e.ADD_TAGS)&&(R===z&&(R=Tb(R)),Cb(R,e.ADD_TAGS,$e))),_b(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?ge.attributeCheck=e.ADD_ATTR:ob(e.ADD_ATTR)&&(B===fe&&(B=Tb(B)),Cb(B,e.ADD_ATTR,$e))),_b(e,`ADD_FORBID_CONTENTS`)&&ob(e.ADD_FORBID_CONTENTS)&&(Ne===Pe&&(Ne=Tb(Ne)),Cb(Ne,e.ADD_FORBID_CONTENTS,$e)),Ae&&(R[`#text`]=!0),U&&Cb(R,[`html`,`head`,`body`]),R.table&&(Cb(R,[`tbody`]),delete me.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw bb(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw bb(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=T;T=e.TRUSTED_TYPES_POLICY;try{E=j(``)}catch(e){throw T=t,e}}else e.TRUSTED_TYPES_POLICY===null?(T=void 0,E=``):(T===void 0&&(T=M()),T&&typeof E==`string`&&(E=j(``)));Yy&&Yy(e),et=e},it=Cb({},[...Ab,...jb,...Mb]),at=Cb({},[...Nb,...Pb]),ot=function(e,t,n){return t.namespaceURI===Ve?e===`svg`:t.namespaceURI===ze?e===`svg`&&(n===`annotation-xml`||qe[n]):!!it[e]},st=function(e,t,n){return t.namespaceURI===Ve?e===`math`:t.namespaceURI===Be?e===`math`&&Ye[n]:!!at[e]},ct=function(e,t,n){return t.namespaceURI===Be&&!Ye[n]||t.namespaceURI===ze&&!qe[n]?!1:!at[e]&&(Xe[e]||!it[e])},lt=function(e){let t=_(e);(!t||!t.tagName)&&(t={namespaceURI:He,tagName:`template`});let n=sb(e.tagName),r=sb(t.tagName);return We[e.namespaceURI]?e.namespaceURI===Be?ot(n,t,r):e.namespaceURI===ze?st(n,t,r):e.namespaceURI===Ve?ct(n,t,r):!!(Ze===`application/xhtml+xml`&&We[e.namespaceURI]):!1},ut=function(e){ib(t.removed,{element:e});try{_(e).removeChild(e)}catch{if(p(e),!_(e))throw bb(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},dt=function(e,t,n){try{m(e,t)}catch{try{e.removeAttribute(n)}catch{}}},ft=function(e){ht(e);let t=g(e);if(t){let e=[];tb(t,t=>{ib(e,t)}),tb(e,e=>{try{p(e)}catch{}})}let n=y(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;typeof i==`string`&&dt(e,r,i)}},pt=function(e,n,r){if(!r)try{r=n.getAttributeNode(e)}catch{r=null}ib(t.removed,{attribute:r||null,from:n});try{r?m(n,r):n.removeAttribute(e)}catch{try{n.removeAttribute(e)}catch{}}if(e===`is`){if(we||Te)try{ut(n)}catch{}else try{n.setAttribute(e,``)}catch{}}},mt=function(e){let t=y(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;typeof i!=`string`||B[$e(i)]||dt(e,r,i)}},ht=function(e){let t=[e];for(;t.length>0;){let e=t.pop();C(e)===ex.element&&mt(e);let n=g(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},gt=function(e,t){return be?e===`patchsrc`||e===`for`&&t!==`label`&&t!==`output`:!1},_t=function(e){if(!be)return;let t=[e];for(;t.length>0;){let e=t.pop(),n=C(e);if(n===ex.processingInstruction||n===ex.comment&&yb(Zb,e.data)){try{p(e)}catch{}continue}if(n===ex.element){let t=e,n=$e(w(e));try{t.hasAttribute&&t.hasAttribute(`patchsrc`)&&t.removeAttribute(`patchsrc`),t.hasAttribute&&t.hasAttribute(`for`)&&gt(`for`,n)&&t.removeAttribute(`for`)}catch{}}let r=g(e);if(r)for(let e=r.length-1;e>=0;--e)t.push(r[e])}},vt=function(e){let t=null,r=null;if(Ce)e=`<remove></remove>`+e;else{let t=lb(e,/^[\r\n\t ]+/);r=t&&t[0]}Ze===`application/xhtml+xml`&&He===Ve&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=T?j(e):e;if(He===Ve)try{t=new l().parseFromString(i,Ze)}catch{}if(!t||!t.documentElement){t=P.createDocument(He,`template`,null);try{t.documentElement.innerHTML=Ue?E:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),He===Ve?te.call(t,U?`html`:`body`)[0]:U?t.documentElement:a},yt=function(e){let t=S?S(e):e.ownerDocument;return F.call(t||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},bt=function(e){return e=ub(e,re,` `),e=ub(e,ie,` `),e=ub(e,ae,` `),e},xt=function(e){e.normalize();let t=S?S(e):e.ownerDocument,n=F.call(t||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),r=n.nextNode();for(;r;)r.data=bt(r.data),r=n.nextNode();let i=e.querySelectorAll?.call(e,`template`);i&&tb(i,e=>{Ct(e.content)&&xt(e.content)})},St=function(e){let t=x?x(e):null;return typeof t!=`string`||$e(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==y(e)||typeof e.removeAttribute!=`function`||typeof e.removeAttributeNode!=`function`||typeof e.getAttributeNode!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==b(e)||e.childNodes!==g(e)},Ct=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return b(e)===ex.documentFragment}catch{return!1}},wt=function(e){if(!b||typeof e!=`object`||!e)return!1;try{return typeof b(e)==`number`}catch{return!1}};function Tt(e,n,r){e.length!==0&&tb(e,e=>{e.call(t,n,r,et)})}let Et=function(e,t){return!!(be&&e.hasChildNodes()&&!wt(e.firstElementChild)&&yb(Xb,e.textContent)&&yb(Xb,e.innerHTML)||be&&e.namespaceURI===Ve&&nx[t]&&(wt(e.firstElementChild)||typeof e.textContent==`string`&&yb(rx[t],e.textContent))||e.nodeType===ex.processingInstruction||be&&e.nodeType===ex.comment&&yb(Zb,e.data))},Dt=function(e,t){return e instanceof RegExp?yb(e,t):e instanceof Function&&!!e(t,...[...arguments].slice(2))},Ot=function(e,t,n){if(!me[t]&&Pt(t)&&Dt(pe.tagNameCheck,t))return!1;if(Ae&&!Ne[t]){let t=_(e),r=g(e);if(r&&t){let i=r.length;for(let a=i-1;a>=0;--a){let i=e===n?f(r[a],!0):r[a];t.insertBefore(i,h(e))}}}return ut(e),!0},kt=function(e,t,n,r){return e.length===0?t:t===n||t===r?Tb(t):t},At=function(e,t){return e===t||_(e)!==null?!1:(je&&ht(e),!0)},jt=function(e,n){if(Tt(L.beforeSanitizeElements,e,null),At(e,n))return!0;if(St(e))return ut(e),!0;let r=$e(w(e));if(R=kt(L.uponSanitizeElement,R,z,xe),Tt(L.uponSanitizeElement,e,{tagName:r,allowedTags:R}),At(e,n))return!0;if(Et(e,r))return ut(e),!0;if(me[r]||!(ge.tagCheck instanceof Function&&ge.tagCheck(r))&&!R[r]){let t=Ot(e,r,n);return t===!1&&(Tt(L.afterSanitizeElements,e,null),At(e,n))?!0:t}if(C(e)===ex.element&&!lt(e)||(r===`noscript`||r===`noembed`||r===`noframes`)&&yb(Qb,e.innerHTML))return ut(e),!0;if(H&&e.nodeType===ex.text){let n=bt(e.textContent);e.textContent!==n&&(ib(t.removed,{element:e.cloneNode()}),e.textContent=n)}return Tt(L.afterSanitizeElements,e,null),At(e,n)},Mt=function(e,t,r){if(he[t]||gt(t,e)||De&&(t===`id`||t===`name`)&&(r in n||r in tt))return!1;let i=B[t]||ge.attributeCheck instanceof Function&&ge.attributeCheck(t,e);return _e&&yb(oe,t)||V&&yb(se,t)?!0:i?Le[t]||yb(de,ub(r,le,``))||(t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&db(r,`data:`)===0&&Fe[e]||ve&&!yb(ce,ub(r,le,``))?!0:!r:Pt(e)&&Dt(pe.tagNameCheck,e)&&Dt(pe.attributeNameCheck,t,e)||t===`is`&&pe.allowCustomizedBuiltInElements&&Dt(pe.tagNameCheck,r)},Nt=Cb({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Pt=function(e){return!Nt[sb(e)]&&yb(ue,e)},Ft=function(e,t,n,r){if(T&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return j(r);case`TrustedScriptURL`:return ee(r)}return r},It=function(e,t,n,r){try{return n?e.setAttributeNS(n,t,r):e.setAttribute(t,r),!St(e)||(ut(e),!1)}catch{return pt(t,e),!1}},Lt=function(e,n){if(Tt(L.beforeSanitizeAttributes,e,null),At(e,n))return;let r=e.attributes;if(!r||St(e))return;B=kt(L.uponSanitizeAttribute,B,fe,Se);let i={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:B,forceKeepAttr:void 0},a=r.length,o=$e(e.nodeName);for(;a--;){let n=r[a],s=n.name,c=n.namespaceURI,l=n.value,u=$e(s),d=l,f=s===`value`?d:fb(d),p=!1;if(i.attrName=u,i.attrValue=f,i.keepAttr=!0,i.forceKeepAttr=void 0,Tt(L.uponSanitizeAttribute,e,i),f=i.attrValue,Oe&&(u===`id`||u===`name`)&&db(f,ke)!==0&&(pt(s,e,n),f=ke+f,p=!0),be&&yb(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,f)){pt(s,e,n);continue}if(u===`attributename`&&lb(f,`href`)){pt(s,e,n);continue}if(!i.forceKeepAttr){if(!i.keepAttr){pt(s,e,n);continue}if(!ye&&yb($b,f)){pt(s,e,n);continue}if(H&&(f=bt(f)),!Mt(o,u,f)){pt(s,e,n);continue}f=Ft(o,u,c,f),f!==d&&It(e,s,c,f)&&p&&rb(t.removed)}}Tt(L.afterSanitizeAttributes,e,null),At(e,n)},Rt=function(e){let t=null,n=yt(e);for(Tt(L.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(Tt(L.uponSanitizeShadowNode,t,null),jt(t,e),Lt(t,e),Ct(t.content)&&Rt(t.content),C(t)===ex.element){let e=v(t);Ct(e)&&(zt(e),Rt(e))}Tt(L.afterSanitizeShadowDOM,e,null)},zt=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){Rt(e.shadow);continue}let n=e.node,r=C(n)===ex.element,i=g(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=x?x(n):null;if(typeof e==`string`&&$e(e)===`template`){let e=n.content;Ct(e)&&t.push({node:e,shadow:null})}}if(r){let e=v(n);Ct(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Ue=!e,Ue&&(e=`<!-->`),typeof e!=`string`&&!wt(e)&&(e=Eb(e),typeof e!=`string`))throw bb(`dirty is not a string, aborting`);if(!t.isSupported)return e;W?(R=xe,B=Se):rt(n),(L.uponSanitizeElement.length>0||L.uponSanitizeAttribute.length>0)&&(R=Tb(R)),L.uponSanitizeAttribute.length>0&&(B=Tb(B)),t.removed=[];let c=je&&typeof e!=`string`&&wt(e);if(c){_t(e);let t=w(e);if(typeof t==`string`){let n=$e(t);if(!R[n]||me[n])throw ft(e),bb(`root node is forbidden and cannot be sanitized in-place`)}if(St(e))throw ft(e),bb(`root node is clobbered and cannot be sanitized in-place`);try{zt(e)}catch(t){throw ft(e),t}}else if(wt(e))i=vt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===ex.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),zt(i);else{if(!we&&!H&&!U&&e.indexOf(`<`)===-1)return T&&Ee?j(e):e;if(i=vt(e),!i)return we?null:Ee?E:``}i&&Ce&&ut(i.firstChild);let l=c?e:i;try{let e=yt(l);for(;o=e.nextNode();)jt(o,l),Lt(o,l),Ct(o.content)&&Rt(o.content)}catch(n){throw c&&(ft(e),tb(t.removed,e=>{e.element&&ht(e.element)})),n}if(c){let n=!1;if(tb(t.removed,t=>{t.element&&(t.element===e&&(n=!0),ht(t.element))}),n)throw bb(`a node selected for removal could not be safely returned; refusing to sanitize in place`);return H&&xt(e),e}if(we){if(H&&xt(i),Te)for(s=I.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(B.shadowroot||B.shadowrootmode)&&(s=ne.call(r,s,!0)),s}let u=U?i.outerHTML:i.innerHTML;return U&&R[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&yb(Jb,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
4387
4387
  `+u),H&&(u=bt(u)),T&&Ee?j(u):u},t.setConfig=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};rt(e),W=!0,xe=R,Se=B},t.clearConfig=function(){et=null,W=!1,xe=null,Se=null,T=D,E=``},t.isValidAttribute=function(e,t,n){et||rt({});let r=$e(e),i=$e(t);return Mt(r,i,n)},t.addHook=function(e,t){typeof t==`function`&&_b(L,e)&&ib(L[e],t)},t.removeHook=function(e,t){if(_b(L,e)){if(t!==void 0){let n=nb(L[e],t);return n===-1?void 0:ab(L[e],n,1)[0]}return rb(L[e])}},t.removeHooks=function(e){_b(L,e)&&(L[e]=[])},t.removeAllHooks=function(){L=ox()},t}var ux=lx();function dx(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var fx=dx();function px(e){fx=e}var mx={exec:()=>null};function hx(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function gx(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(vx.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var _x=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),vx={codeRemoveIndent:/^(?: {0,3}\t| {1,4})/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,endingSpaceTabChar:/[ \t]$/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,leadingSpaceTab:/^[ \t]+/,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,numericCharacterReference:/&#(?:(\d{1,7})|[Xx]([A-Fa-f0-9]{1,6}));/g,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:hx(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:hx(e=>RegExp(`^ {0,${e}}((?:-[ ]*){3,}|(?:_[ ]*){3,}|(?:\\*[ ]*){3,})(?:\\n+|$)`)),fencesBeginRegex:hx(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:hx(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:hx(e=>RegExp(`^ {0,${e}}(?:</?(?:${Nx})(?: +|$|/?>)|<(?:script|pre|style|textarea|!--))`,`i`)),blockquoteBeginRegex:hx(e=>RegExp(`^ {0,${e}}>`))},yx=/^(?:[ \t]*(?:\n|$))+/,bx=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,xx=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Sx=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Cx=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,wx=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Tx=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |fences|blockquote|heading|hr|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Ex=gx(Tx).replace(/bull/g,wx).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),Dx=gx(Tx).replace(/bull/g,wx).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}(?:\s|$)/).replace(/hr/g,/ {0,3}(?:(?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Ox=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table|[ \t]+\n)[^\n]+)*)/,kx=/^[^\n]+/,Ax=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,jx=gx(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,Ax).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Mx=gx(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,wx).getRegex(),Nx=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,Px=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Fx=gx(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n*|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>[^\\n]*\\n*|$)|<![A-Z][\\s\\S]*?(?:>[^\\n]*\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>[^\\n]*\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][a-z0-9-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][a-z0-9-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,Px).replace(`tag`,Nx).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Ix=e=>gx(Ox).replace(`hr`,Sx).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,e).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Nx).getRegex(),Lx=Ix(/ {0,3}(?:[*+-]|1[.)])[ \t]+[^ \t\n]/),Rx=Ix(/ {0,3}(?:[*+-]|\d{1,9}[.)])(?:[ \t]|\n|$)/),zx={blockquote:gx(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,Rx).getRegex(),code:bx,def:jx,fences:xx,heading:Cx,hr:Sx,html:Fx,lheading:Ex,list:Mx,newline:yx,paragraph:Lx,table:mx,text:kx},Bx=gx(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,Sx).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Nx).getRegex(),Vx={...zx,lheading:Dx,table:Bx,paragraph:gx(Ox).replace(`hr`,Sx).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,Bx).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*(?:\\n|$))|~~~)[^\\n]*(?:\\n|$)").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,Nx).getRegex()},Hx={...zx,html:gx(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,Px).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:mx,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:gx(Ox).replace(`hr`,Sx).replace(`heading`,` *#{1,6} *[^
4388
4388
  ]`).replace(`lheading`,Ex).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},Ux=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Wx=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Gx=/^( {2,}|\\)\n(?!\s*$)[ \t]*/,Kx=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,qx=/[\p{P}\p{S}]/u,Jx=/[\s\p{P}\p{S}]/u,Yx=/[^\s\p{P}\p{S}]/u,Xx=gx(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Jx).getRegex(),Zx=/[\p{Pi}\p{Ps}"']/u,Qx=/(?!~)[\p{P}\p{S}]/u,$x=/(?!~)[\s\p{P}\p{S}]/u,eS=/(?:[^\s\p{P}\p{S}]|~)/u,tS=gx(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,_x?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),nS=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,rS=gx(nS,`u`).replace(/punct/g,qx).getRegex(),iS=gx(nS,`u`).replace(/punct/g,Qx).getRegex(),aS=gx(/^(?:\*+(?:((?!\*)(?!openQuote)punct)|([^\s*]))?)|^_+(?:((?!_)(?!openQuote)punct)|([^\s_]))?/,`u`).replace(/openQuote/g,Zx).replace(/punct/g,qx).getRegex(),oS=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,sS=gx(oS,`gu`).replace(/notPunctSpace/g,Yx).replace(/punctSpace/g,Jx).replace(/punct/g,qx).getRegex(),cS=gx(oS,`gu`).replace(/notPunctSpace/g,eS).replace(/punctSpace/g,$x).replace(/punct/g,Qx).getRegex(),lS=gx(`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)[\\s](\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Yx).replace(/punctSpace/g,Jx).replace(/punct/g,qx).getRegex(),uS=gx(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,Yx).replace(/punctSpace/g,Jx).replace(/punct/g,qx).getRegex(),dS=gx(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)[\\s](_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)|(?:(?!_)punct|notPunctSpace)(_+)(?!_)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Yx).replace(/punctSpace/g,Jx).replace(/punct/g,qx).getRegex(),fS=gx(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,qx).getRegex(),pS=gx(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,Yx).replace(/punctSpace/g,Jx).replace(/punct/g,qx).getRegex(),mS=gx(/\\(punct)/,`gu`).replace(/punct/g,qx).getRegex(),hS=gx(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),gS=gx(Px).replace(`(?:-->|$)`,`-->`).getRegex(),_S=gx(`^comment|^</[a-zA-Z][a-zA-Z0-9-]*\\s*>|^<[a-zA-Z][a-zA-Z0-9-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,gS).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),vS=/\[(?:\\[\s\S]|[^\[\]\\])*\]/,yS=gx(/(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/).replace(`brackets`,vS).getRegex(),bS=gx(/^!?\[(label)\]\([ \t\n]*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?[ \t\n]*\)/).replace(`label`,yS).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]+|(?=\))/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),xS=gx(/^!?\[(label)\]\[(ref)\]/).replace(`label`,yS).replace(`ref`,Ax).getRegex(),SS=gx(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,Ax).getRegex(),CS=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\]){1,999}/,wS=gx(/(?:[^\[\]\\`]*(?:\[(?:brackets|\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\]))){0,999}?[^\[\]\\`]*?/).replace(`brackets`,vS).getRegex(),TS=gx(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,gx(/^!?\[(label)\]\[(ref)\]/).replace(`label`,wS).replace(`ref`,CS).getRegex()).replace(`nolink`,gx(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,CS).getRegex()).getRegex(),ES=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,DS=gx(/(?:mailto:email|xmpp:email(?:\/[A-Za-z0-9@.]+)?)/).replace(/email/g,/[A-Za-z0-9._+-]+@[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),OS={_backpedal:mx,anyPunctuation:mS,autolink:hS,blockSkip:tS,br:Gx,code:Wx,del:mx,delLDelim:mx,delRDelim:mx,emStrongLDelim:rS,emStrongRDelimAst:sS,emStrongRDelimUnd:uS,escape:Ux,link:bS,nolink:SS,punctuation:Xx,reflink:xS,reflinkSearch:TS,tag:_S,text:Kx,url:mx},kS={...OS,emStrongLDelim:aS,emStrongRDelimAst:lS,emStrongRDelimUnd:dS,link:gx(/^!?\[(label)\]\((.*?)\)/).replace(`label`,yS).getRegex(),reflink:gx(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,yS).getRegex()},AS={...OS,emStrongRDelimAst:cS,emStrongLDelim:iS,delLDelim:fS,delRDelim:pS,url:gx(/^emailProtocol|^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`emailProtocol`,DS).replace(`protocol`,ES).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![\w-])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:gx(/^(?:[^a-zA-Z0-9](?=emailProtocol)|(`+|~+|[^`~])(?:(?=[`~])|(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9](?=emailProtocol)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@))))/).replace(`protocol`,ES).replace(/emailProtocol/g,/(?:mailto|xmpp):/).getRegex()},jS={...AS,br:gx(Gx).replace(`{2,}`,`*`).getRegex(),text:gx(AS.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},MS={normal:zx,gfm:Vx,pedantic:Hx},NS={normal:OS,gfm:AS,breaks:jS,pedantic:kS},PS={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},FS=e=>PS[e];function IS(e,t){if(t){if(vx.escapeTest.test(e))return e.replace(vx.escapeReplace,FS)}else if(vx.escapeTestNoEncode.test(e))return e.replace(vx.escapeReplaceNoEncode,FS);return e}function LS(e){return e.replace(vx.numericCharacterReference,(e,t,n)=>{let r=t===void 0?Number.parseInt(n,16):Number.parseInt(t,10);return r===0||r>1114111||r>=55296&&r<=57343?`�`:String.fromCodePoint(r)})}function RS(e){try{e=encodeURI(e).replace(vx.percentDecode,`%`)}catch{return null}return e}function zS(e,t){let n=e.replace(vx.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(vx.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t){if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``)}for(;r<n.length;r++)n[r]=n[r].trim().replace(vx.slashPipe,`|`);return n}function BS(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function VS(e){let t=e.split(`
@@ -4450,4 +4450,4 @@ ${this.parser.parse(e)}</blockquote>
4450
4450
  ${e}</tr>
4451
4451
  `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
4452
4452
  `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${IS(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,text:n,tokens:r,autolink:i}){let a=i?IS(n,!0):this.parser.parseInline(r),o=RS(e);if(o===null)return a;e=IS(o,i);let s=`<a href="`+e+`"`;return t&&(s+=` title="`+IS(t)+`"`),s+=`>`+a+`</a>`,s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=RS(e);if(i===null)return IS(n);e=i;let a=`<img src="${IS(e)}" alt="${IS(n)}"`;return t&&(a+=` title="${IS(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:IS(e.text)}},ZS=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},QS=class e{options;renderer;textRenderer;constructor(e){this.options=e||fx,this.options.renderer=this.options.renderer||new XS,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ZS}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`checkbox`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`checkbox`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},$S=class{options;block;constructor(e){this.options=e||fx}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?YS.lex:YS.lexInline}provideParser(e=this.block){return e?QS.parse:QS.parseInline}},eC=new class{defaults=dx();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=QS;Renderer=XS;TextRenderer=ZS;Lexer=YS;Tokenizer=JS;Hooks=$S;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new XS(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new JS(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new $S;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];t[r]=$S.passThroughHooks.has(n)?e=>{if(this.defaults.async&&$S.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return YS.lex(e,t??this.defaults)}parser(e,t){return QS.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?YS.lex:YS.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?QS.parse:QS.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?YS.lex:YS.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?QS.parse:QS.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
4453
- Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+IS(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function tC(e,t){return eC.parse(e,t)}tC.options=tC.setOptions=function(e){return eC.setOptions(e),tC.defaults=eC.defaults,px(tC.defaults),tC},tC.getDefaults=dx,tC.defaults=fx;function nC(...e){return eC.use(...e),tC.defaults=eC.defaults,px(tC.defaults),tC}tC.use=nC,tC.walkTokens=function(e,t){return eC.walkTokens(e,t)},tC.parseInline=eC.parseInline,tC.Parser=QS,tC.parser=QS.parse,tC.Renderer=XS,tC.TextRenderer=ZS,tC.Lexer=YS,tC.lexer=YS.lex,tC.Tokenizer=JS,tC.Hooks=$S,tC.parse=tC,tC.options,tC.setOptions,tC.walkTokens,tC.parseInline,QS.parse,YS.lex;var rC=!1;function iC(){rC||(rC=!0,ux.addHook(`afterSanitizeAttributes`,e=>{e instanceof Element&&e.tagName===`A`&&(e.setAttribute(`rel`,`noopener noreferrer`),e.setAttribute(`target`,`_blank`))}))}function aC(e){iC();let t=tC.parse(e,{async:!1,breaks:!0});return ux.sanitize(t,{ALLOWED_TAGS:[`p`,`br`,`strong`,`em`,`code`,`pre`,`ul`,`ol`,`li`,`a`,`h1`,`h2`,`h3`,`h4`,`blockquote`,`hr`,`del`],ALLOWED_ATTR:[`href`,`rel`,`target`],ALLOWED_URI_REGEXP:/^(?:https?:|mailto:)/i})}var oC=e=>Number.isFinite(e);function sC(e){let t=Math.floor(Math.log10(e)),n=e/10**t;return(n<=1?1:n<=2?2:n<=2.5?2.5:n<=5?5:10)*10**t}function cC(e,t,n=5){let r=oC(e)?e:0,i=oC(t)?t:r+1;r>i&&([r,i]=[i,r]),r===i&&(i=r+(Math.abs(r)||1));let a=sC((i-r)/Math.max(1,n-1)),o=Math.floor(r/a)*a,s=Math.ceil(i/a)*a,c=[];for(let e=o;e<=s+a/2;e+=a)c.push(Math.round(e*1e9)/1e9);return{min:o,max:s,ticks:c}}function lC(e,t){let[n,r]=e,[i,a]=t;return r===n?()=>i:e=>i+(e-n)/(r-n)*(a-i)}function uC(e){return e.map(([e,t],n)=>`${n===0?`M`:`L`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function dC(e,t,n,r,i){let a=r=>{let i=r*Math.PI/180;return`${(e+n*Math.cos(i)).toFixed(2)} ${(t+n*Math.sin(i)).toFixed(2)}`},o=+(Math.abs(i-r)>180);return`M ${a(r)} A ${n} ${n} 0 ${o} 1 ${a(i)}`}function fC(e,t,n){return!oC(e)||!oC(t)||!oC(n)||n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))*240}function pC(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=Math.hypot(i,a);if(o===0||o<=n+r)return{from:{...e},to:{...t}};let s=i/o,c=a/o;return{from:{x:e.x+s*n,y:e.y+c*n},to:{x:t.x-s*r,y:t.y-c*r}}}function mC(e,t,n){if(e<=0)return[];if(e===1)return[{x:t/2,y:n/2}];let r=Math.min(t,n)*.36;return Array.from({length:e},(i,a)=>{let o=-Math.PI/2+a*2*Math.PI/e;return{x:t/2+r*Math.cos(o),y:n/2+r*Math.sin(o)}})}var hC=e=>typeof e==`object`&&!!e&&!Array.isArray(e),gC=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,_C=e=>Array.isArray(e)?e:[],vC=e=>typeof e==`number`?Number.isFinite(e)?e:null:typeof e==`string`&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):null,yC=(e,t)=>e.length>t?e.slice(0,t)+`…`:e,bC=[`var(--accent)`,`#ffb454`,`#7b8cff`,`#5ef0b0`,`#ff6b7a`,`#c792ea`],xC=({text:e})=>e?(0,p.jsx)(`h3`,{className:`obj-title`,children:e}):null,SC=({text:e=`No data`})=>(0,p.jsx)(`p`,{className:`obj-empty`,children:e}),CC=400,wC=220,TC={l:44,r:12,t:10,b:28};function EC({props:e}){let t=e.kind===`bar`||e.kind===`area`?e.kind:`line`,n=_C(e.labels).slice(0,120).map(gC),r=_C(e.series).slice(0,6).map((e,t)=>{let n=hC(e)?e:{},r=_C(n.values).slice(0,120).map((e,t)=>({idx:t,v:vC(e)})).filter(e=>e.v!==null);return{name:gC(n.name)||`series ${t+1}`,points:r}}).filter(e=>e.points.length>0);if(r.length===0)return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{})]});let i=r.flatMap(e=>e.points.map(e=>e.v)),a=Math.min(...i),o=Math.max(...i),s=cC(t===`line`?a:Math.min(0,a),t===`line`?o:Math.max(0,o),5),c=Math.max(n.length,...r.map(e=>e.points[e.points.length-1].idx+1),2),l=lC([s.min,s.max],[wC-TC.b,TC.t]),u=lC([0,c-1],[TC.l,CC-TC.r]),d=(CC-TC.l-TC.r)/c,f=Math.max(1,d*.7/r.length),m=(e,t)=>TC.l+e*d+d*.15+t*f,h=Math.max(1,Math.ceil(c/6)),g=gC(e.unit);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsxs)(`svg`,{className:`obj-chart`,viewBox:`0 0 ${CC} ${wC}`,role:`img`,"aria-label":gC(e.title)||`chart`,children:[s.ticks.map(e=>(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`line`,{className:`grid`,x1:TC.l,x2:CC-TC.r,y1:l(e),y2:l(e)}),(0,p.jsxs)(`text`,{className:`tick`,x:TC.l-6,y:l(e)+3,textAnchor:`end`,children:[e,g&&e===s.max?g:``]})]},e)),Array.from({length:c},(e,t)=>t).filter(e=>e%h===0&&n[e]).map(e=>(0,p.jsx)(`text`,{className:`tick`,x:t===`bar`?m(e,0)+f*r.length/2:u(e),y:212,textAnchor:`middle`,children:yC(n[e],8)},e)),r.map((e,n)=>{let r=bC[n%bC.length];if(t===`bar`)return(0,p.jsx)(`g`,{children:e.points.map(e=>(0,p.jsx)(`rect`,{className:`bar`,x:m(e.idx,n),y:Math.min(l(e.v),l(0)),width:f,height:Math.abs(l(e.v)-l(0)),fill:r},e.idx))},n);let i=e.points.map(e=>[u(e.idx),l(e.v)]),a=uC(i),o=`${a} L${i[i.length-1][0].toFixed(2)} ${l(s.min).toFixed(2)} L${i[0][0].toFixed(2)} ${l(s.min).toFixed(2)} Z`;return(0,p.jsxs)(`g`,{children:[t===`area`&&(0,p.jsx)(`path`,{className:`series-area`,d:o,fill:r,opacity:.18}),(0,p.jsx)(`path`,{className:`series-line`,d:a,fill:`none`,stroke:r,strokeWidth:2,strokeLinejoin:`round`})]},n)})]}),r.length>1&&(0,p.jsx)(`ul`,{className:`legend`,children:r.map((e,t)=>(0,p.jsxs)(`li`,{children:[(0,p.jsx)(`i`,{style:{background:bC[t%bC.length]}}),(0,p.jsx)(`span`,{children:e.name})]},t))})]})}function DC({props:e}){let t=vC(e.min)??0,n=vC(e.max)??100,r=vC(e.value)??t,i=fC(r,t,n),a=i/240;return(0,p.jsxs)(`div`,{className:`obj-gauge ${a>.95?`gauge-crit`:a>.8?`gauge-warn`:``}`,children:[(0,p.jsxs)(`svg`,{viewBox:`0 0 200 150`,role:`img`,"aria-label":`${gC(e.label)} ${r}`,children:[(0,p.jsx)(`path`,{className:`track`,d:dC(100,100,70,150,390),fill:`none`,strokeWidth:12,strokeLinecap:`round`}),i>0&&(0,p.jsx)(`path`,{className:`value`,d:dC(100,100,70,150,150+i),fill:`none`,strokeWidth:12,strokeLinecap:`round`})]}),(0,p.jsxs)(`div`,{className:`gauge-read`,children:[(0,p.jsx)(`span`,{className:`gauge-value`,children:String(Math.round(r*100)/100)}),gC(e.unit)&&(0,p.jsx)(`small`,{className:`gauge-unit`,children:gC(e.unit)})]}),(0,p.jsx)(`span`,{className:`obj-label`,children:gC(e.label)})]})}function OC({props:e}){let t=_C(e.items).slice(0,30).map(e=>hC(e)?e:{}).map(e=>({time:gC(e.time),title:gC(e.title),detail:gC(e.detail)})).filter(e=>e.title||e.time);return t.length===0?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{text:`Nothing to show`})]}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(`ol`,{className:`obj-timeline`,children:t.map((e,t)=>(0,p.jsxs)(`li`,{children:[(0,p.jsx)(`time`,{children:e.time}),(0,p.jsx)(`strong`,{children:e.title}),e.detail&&(0,p.jsx)(`span`,{children:e.detail})]},t))})]})}var kC=400,AC=300,jC=12;function MC({props:e}){let t=(0,l.useId)(),n=new Set,r=[];for(let t of _C(e.nodes)){let e=hC(t)?t:{},i=gC(e.id);if(i&&!n.has(i)&&(n.add(i),r.push({id:i,label:gC(e.label)||i}),r.length>=40))break}if(r.length===0)return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{text:`Nothing to show`})]});let i=new Map(r.map((e,t)=>[e.id,mC(r.length,kC,AC)[t]])),a=[];for(let t of _C(e.edges)){let e=hC(t)?t:{},n=gC(e.from),r=gC(e.to);if(i.has(n)&&i.has(r)&&n!==r&&(a.push({from:n,to:r,label:gC(e.label)}),a.length>=80))break}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsxs)(`svg`,{className:`obj-graph`,viewBox:`0 0 ${kC} ${AC}`,role:`img`,"aria-label":gC(e.title)||`graph`,children:[(0,p.jsx)(`defs`,{children:(0,p.jsx)(`marker`,{id:t,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,p.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,className:`arrow`})})}),a.map((e,n)=>{let{from:r,to:a}=pC(i.get(e.from),i.get(e.to),14,17),o=(r.x+a.x)/2+(kC/2-(r.x+a.x)/2)*.25,s=(r.y+a.y)/2+(AC/2-(r.y+a.y)/2)*.25;return(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`path`,{className:`edge`,d:`M ${r.x.toFixed(1)} ${r.y.toFixed(1)} Q ${o.toFixed(1)} ${s.toFixed(1)} ${a.x.toFixed(1)} ${a.y.toFixed(1)}`,fill:`none`,markerEnd:`url(#${t})`}),e.label&&(0,p.jsx)(`text`,{className:`edge-label`,x:o,y:s,textAnchor:`middle`,children:yC(e.label,12)})]},n)}),r.map(e=>{let t=i.get(e.id);return(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`circle`,{className:`node`,cx:t.x,cy:t.y,r:jC}),(0,p.jsx)(`text`,{className:`node-label`,x:t.x,y:t.y+26,textAnchor:`middle`,children:yC(e.label,18)})]},e.id)})]})]})}var NC=[`default-src 'none'`,`script-src 'unsafe-inline'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `),PC=`html,body{margin:0;min-height:100%;background:#050b10;color:#d8f6ff;font:15px/1.5 system-ui,sans-serif}`;function FC(e){return`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${NC}"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${PC}</style></head><body>${e}</body></html>`}function IC({props:e}){let t=typeof e.html==`string`?e.html:``,n=typeof e.title==`string`?e.title:``,r=(0,l.useMemo)(()=>FC(t),[t]);return(0,p.jsxs)(`div`,{className:`obj-sandbox`,children:[n&&(0,p.jsx)(`h3`,{className:`obj-title`,children:n}),(0,p.jsx)(`iframe`,{title:n||`Page made by Friend`,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,allow:``,srcDoc:r})]})}var LC=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,RC=e=>Array.isArray(e)?e:[];function zC({props:e}){let t=(0,l.useMemo)(()=>aC(LC(e.text)),[e.text]);return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`div`,{className:`obj-md`,dangerouslySetInnerHTML:{__html:t}})]})}function BC({props:e}){return(0,p.jsxs)(`div`,{className:`obj-stat`,children:[(0,p.jsx)(`span`,{className:`obj-label`,children:LC(e.label)}),(0,p.jsxs)(`span`,{className:`obj-value`,children:[(0,p.jsx)(`span`,{children:LC(e.value)}),LC(e.unit)&&(0,p.jsx)(`small`,{children:LC(e.unit)})]}),LC(e.delta)&&(0,p.jsx)(`span`,{className:`obj-delta`,children:LC(e.delta)})]})}function VC({props:e}){return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`ul`,{className:`obj-list`,children:RC(e.items).map((e,t)=>{let n=typeof e==`object`&&e?e:{text:e};return(0,p.jsx)(`li`,{className:n.done?`done`:void 0,children:LC(n.text)},t)})})]})}function HC({props:e}){let t=RC(e.columns),n=RC(e.rows);return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`div`,{className:`obj-table-wrap`,children:(0,p.jsxs)(`table`,{className:`obj-table`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsx)(`tr`,{children:t.map((e,t)=>(0,p.jsx)(`th`,{children:LC(e)},t))})}),(0,p.jsx)(`tbody`,{children:n.map((e,t)=>(0,p.jsx)(`tr`,{children:RC(e).map((e,t)=>(0,p.jsx)(`td`,{children:LC(e)},t))},t))})]})})]})}function UC({props:e}){return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`pre`,{className:`obj-code`,"data-lang":LC(e.language),children:(0,p.jsx)(`code`,{children:LC(e.code)})})]})}var WC={card:zC,stat:BC,list:VC,table:HC,code:UC,chart:EC,gauge:DC,timeline:OC,graph:MC,sandbox:IC};function GC(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=new Set;for(let t of e){if(i.has(t.object.id))continue;i.add(t.object.id);let e=n.get(t.object.id);r.push(e?{object:e,leaving:!1}:{object:t.object,leaving:!0})}for(let e of t)i.has(e.id)||(i.add(e.id),r.push({object:e,leaving:!1}));return r}function KC(e,t){let[n,r]=(0,l.useState)(()=>e.map(e=>({object:e,leaving:!1}))),i=(0,l.useRef)(new Map);return(0,l.useEffect)(()=>{r(n=>{let a=GC(n,e),o=new Set(n.filter(e=>e.leaving).map(e=>e.object.id));for(let e of a){let n=i.current.get(e.object.id);if(!e.leaving)n&&clearTimeout(n),i.current.delete(e.object.id);else if(!o.has(e.object.id)&&!n){let n=e.object.id;i.current.set(n,setTimeout(()=>{i.current.delete(n),r(e=>e.filter(e=>!(e.object.id===n&&e.leaving)))},Math.max(t,0)))}}return t<=0?a.filter(e=>!e.leaving):a})},[e,t]),(0,l.useEffect)(()=>()=>{for(let e of i.current.values())clearTimeout(e);i.current.clear()},[]),n}var qC=.12,JC=.1,YC=.02,XC=(e,t,n)=>Math.min(Math.max(e,t),n);function ZC(e){let t=XC(e.w,qC,1),n=XC(e.h,JC,1);return{x:XC(e.x,0,1-t),y:XC(e.y,0,1-n),w:t,h:n}}function QC(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return n.width<=0||n.height<=0?null:ZC({x:(r.left-n.left)/n.width,y:(r.top-n.top)/n.height,w:r.width/n.width,h:r.height/n.height})}function $C(e,t,n){let r=(0,l.useRef)(null),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)((n,r)=>{let i=ZC(r);t({type:`object.place`,id:n,placement:{x:i.x,y:i.y,w:i.w,h:i.h}}),e({type:`stage.move`,objectId:n,rect:i})},[e,t]),s=(0,l.useCallback)((e,t,i)=>{if(e.pointerType===`mouse`&&e.button!==0)return;let o=n(),s=e.currentTarget.closest(`[data-object]`);if(!o||!s||r.current)return;let c=QC(s,o);if(!c)return;let l=o.getBoundingClientRect();r.current={id:t.id,mode:i,pointer:e.pointerId,startX:e.clientX,startY:e.clientY,from:c,stageW:l.width,stageH:l.height};try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}e.stopPropagation(),e.preventDefault(),a({id:t.id,box:c})},[n]),c=(e,t)=>{let n=(t.clientX-e.startX)/e.stageW,r=(t.clientY-e.startY)/e.stageH;return e.mode===`move`?ZC({...e.from,x:e.from.x+n,y:e.from.y+r}):ZC({...e.from,w:e.from.w+n,h:e.from.h+r})};return{preview:i,begin:s,move:(0,l.useCallback)(e=>{let t=r.current;t&&t.pointer===e.pointerId&&a({id:t.id,box:c(t,e)})},[]),end:(0,l.useCallback)((e,t)=>{let n=r.current;n&&n.pointer===e.pointerId&&(r.current=null,a(null),t||o(n.id,c(n,e)))},[o]),key:(0,l.useCallback)((e,t)=>{let r={ArrowLeft:[-.02,0],ArrowRight:[YC,0],ArrowUp:[0,-.02],ArrowDown:[0,YC]}[e.key],i=n(),a=e.currentTarget.closest(`[data-object]`);if(!r||!i||!a)return;let s=QC(a,i);s&&(e.preventDefault(),o(t.id,e.shiftKey?{...s,w:s.w+r[0],h:s.h+r[1]}:{...s,x:s.x+r[0],y:s.y+r[1]}))},[o,n])}}function ew(e,t){if(e===`auto`)return{position:`relative`};if(t.w<600)return{position:`relative`,width:`100%`};let[n,r,i,a]=typeof e==`string`?uy[e]:[e.x*100,e.y*100,e.w*100,e.h*100],o={position:`absolute`,left:`${n}%`,top:`${r}%`,width:`${i}%`};return e===`top`||e===`bottom`?{...o,maxHeight:`${a}%`}:{...o,height:`${a}%`}}var tw=350,nw=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,rw=class extends l.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function iw(){let e=()=>({w:window.innerWidth,h:window.innerHeight}),[t,n]=(0,l.useState)(e);return(0,l.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[]),t}var aw=350;function ow({state:e,send:t,dispatch:n,voice:r,slash:i,onMenu:a}){let o=iw(),[s,c]=(0,l.useState)(0),[u,d]=(0,l.useState)(!1),f=ne(),m=o.w<600,h=e.scene===`focus`||e.scene===`multi`,g={"--accent":e.mood.accent,"--intensity":e.mood.intensity},_=e.voice.mode,v=_===`listening`?`listening`:_===`speaking`?`speaking`:_===`transcribing`?`thinking`:e.presence.state,y=gu(e.look.reactivity),b=Math.min(1,(_===`listening`||_===`speaking`?e.voice.level:e.presence.amplitude)*y),x=(0,l.useRef)({timer:null,down:!1,talking:!1,id:null}),S=e=>{if(!(e.target===e.currentTarget||e.target.closest(`[data-presence]`))||e.pointerType===`mouse`&&e.button!==0)return;let t=x.current;if(!(t.down&&t.id!==null&&e.pointerId!==t.id)){t.timer&&clearTimeout(t.timer),t.down=!0,t.talking=!1,t.id=typeof e.pointerId==`number`?e.pointerId:null;try{t.id!==null&&e.currentTarget.setPointerCapture?.(t.id)}catch{}t.timer=r?setTimeout(()=>{t.down&&(t.talking=!0,r.pressStart())},aw):null}},C=(e,t)=>{let n=x.current;n.down&&(n.id===null||typeof e.pointerId!=`number`||e.pointerId===n.id)&&(n.down=!1,n.id=null,n.timer&&clearTimeout(n.timer),n.timer=null,n.talking?(n.talking=!1,t?r?.blur?.():r?.pressEnd()):t||c(e=>e+1))},w=(0,l.useRef)(null),T=$C(t,n,()=>w.current),E=KC(e.objects,nw()?0:tw),D=E.filter(e=>e.object.placement===`auto`),O=E.filter(e=>e.object.placement!==`auto`),k=({object:e,leaving:r})=>{let i=WC[e.type];if(!i)return null;let a=!m&&!r,s=T.preview?.id===e.id?T.preview.box:null,c=s?{x:s.x,y:s.y,w:s.w,h:s.h}:e.placement;return(0,p.jsxs)(`section`,{"data-object":e.id,className:`obj glass${e.style===`alert`?` alert`:``}${e.pinned?` pinned`:``}${s?` dragging`:``}${r?` leaving`:``}`,style:ew(c,o),children:[a&&(0,p.jsx)(`div`,{className:`obj-grip`,role:`button`,tabIndex:0,"aria-label":`Move ${e.id}. Drag, or use the arrow keys; hold Shift to resize.`,onPointerDown:t=>T.begin(t,e,`move`),onPointerMove:T.move,onPointerUp:e=>T.end(e,!1),onPointerCancel:e=>T.end(e,!0),onKeyDown:t=>T.key(t,e)}),(0,p.jsx)(`button`,{className:`obj-pin${e.pinned?` on`:``}`,"aria-label":e.pinned?`Unpin ${e.id}`:`Pin ${e.id} to the screen`,"aria-pressed":!!e.pinned,title:e.pinned?`Pinned: stays on the screen. Click to unpin.`:`Pin: keep this on the screen.`,disabled:r,onClick:()=>t({type:`stage.pin`,objectId:e.id,pinned:!e.pinned}),children:(0,p.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:e.pinned?`currentColor`:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{d:`M12 17v5M9 3h6l-1 7 3 3H7l3-3-1-7z`})})}),(0,p.jsx)(`button`,{className:`obj-close`,"aria-label":`Dismiss ${e.id}`,title:e.pinned?`Remove this widget`:`Dismiss`,disabled:r,onClick:()=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})},children:`×`}),a&&(0,p.jsx)(`div`,{className:`obj-resize`,"aria-hidden":`true`,onPointerDown:t=>T.begin(t,e,`resize`),onPointerMove:T.move,onPointerUp:e=>T.end(e,!1),onPointerCancel:e=>T.end(e,!0)}),(0,p.jsx)(rw,{children:(0,p.jsx)(i,{props:e.props})})]},e.id)};return(0,p.jsxs)(`div`,{ref:w,"data-testid":`stage`,className:`stage`,style:g,onPointerDown:S,onPointerUp:e=>C(e,!1),onPointerCancel:e=>C(e,!0),onContextMenu:e=>r&&e.preventDefault(),children:[e.look.ambient&&(0,p.jsx)(`div`,{className:`ambient`,"aria-hidden":`true`,style:{opacity:.35+.65*e.mood.intensity}}),(0,p.jsx)(hu,{state:v,amplitude:b,pulse:e.presence.pulse,mode:h?`corner`:`full`,accent:e.mood.accent,style:e.presence.style,intensity:e.mood.intensity,scale:e.look.size}),(0,p.jsxs)(`div`,{className:m?`objects objects-stack`:`objects`,style:{zIndex:10},children:[D.length>0&&(0,p.jsx)(`div`,{className:`auto-grid`,children:D.map(k)}),O.map(k)]}),e.look.captions&&e.captions&&(0,p.jsx)(`p`,{className:`captions captions-${e.look.captionSize}${e.captionDone?` done`:``}`,"aria-live":`polite`,children:e.captions}),f&&r&&!u&&(0,p.jsx)(Fy,{voice:r,mode:_,onType:()=>c(e=>e+1),onMenu:()=>a?.()}),(0,p.jsx)(My,{requestOpen:s,slash:i,onOpenChange:d,onSend:e=>t({type:`chat.send`,text:e})})]})}function sw(){let e=()=>Math.random().toString(36).slice(2,12)+Date.now().toString(36);try{let t=sessionStorage.getItem(`friend.tab`);return t||(t=e(),sessionStorage.setItem(`friend.tab`,t)),t}catch{return e()}}function cw(){return`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}function lw(e=cw()){let t=null,n=`connecting`,r=!1,i=0,a=!1,o=sw(),s=null,c=new Set,l=new Set,u=e=>{n=e,l.forEach(t=>t(e))};function d(){if(r)return;u(`connecting`);let n=new WebSocket(`${e}${e.includes(`?`)?`&`:`?`}tab=${o}${a?`&takeover=1`:``}`);t=n,n.onopen=()=>{i=0,a=!1,u(`open`)},n.onmessage=e=>{try{let t=JSON.parse(String(e.data));c.forEach(e=>e(t))}catch{}},n.onclose=e=>{if(!r){if(e.code===4401)return u(`unauthorized`);if(e.code===4409||e.code===4410)return u(`elsewhere`);u(`closed`),s=setTimeout(d,Math.min(500*2**i++,8e3))}},n.onerror=()=>{}}return d(),{send(e){t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},onMessage(e){return c.add(e),()=>c.delete(e)},onState(e){return l.add(e),()=>l.delete(e)},state:()=>n,takeOver(){r||n!==`elsewhere`||(a=!0,i=0,d())},close(){r=!0,s&&clearTimeout(s),t?.close()}}}var uw={scene:`conversation`,objects:[],captions:``,captionDone:!0,presence:{state:`idle`,style:`sphere`,amplitude:0,pulse:0},mood:{accent:`#3fd8ff`,intensity:.6},approval:null,alerts:[],connection:`connecting`,chat:[],chatLive:!1,view:`companion`,look:{size:1,reactivity:.7,ambient:!0,captions:!0,captionSize:`medium`},viewKnown:!1,busy:!1,activity:null,deviceOnline:!1,voice:{mode:`idle`,level:0,available:!1,enrolled:!1},challenge:null,camera:{enabled:!1,stream:null},speaker:null,ownerName:``},dw=200,fw=e=>e.length>dw?e.slice(-200):e,pw=0,mw=e=>Math.min(1,Math.max(0,e));function hw(e,t){switch(t.cmd){case`scene`:return{...e,scene:t.mode};case`show`:{let n=e.objects.findIndex(e=>e.id===t.object.id),r=n===-1?[...e.objects,t.object]:e.objects.map((e,r)=>r===n?t.object:e);return{...e,objects:r}}case`update`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,props:{...e.props,...t.props}}:e)};case`hide`:return{...e,objects:e.objects.filter(e=>e.id!==t.id)};case`clear`:return{...e,objects:e.objects.filter(e=>e.pinned),scene:`conversation`};case`pin`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,pinned:!0}:e)};case`unpin`:return{...e,objects:e.objects.map(e=>e.id===t.id?(({pinned:e,...t})=>t)(e):e)};case`place`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,placement:t.placement}:e)};case`presence`:return{...e,presence:{...e.presence,state:t.state??e.presence.state,style:t.style??e.presence.style}};case`mood`:return{...e,mood:{accent:t.accent??e.mood.accent,intensity:t.intensity??e.mood.intensity}}}}function gw(e,t){let n=t;if(n&&typeof n==`object`){if(n.type===`conn`)return{...e,connection:n.value};if(n.type===`chat.seed`){let t=Array.isArray(n.lines)?n.lines:[];return e.chat.length===0?{...e,chat:fw(t)}:{...e,chat:fw([...t,...e.chat])}}if(n.type===`alert.add`)return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:n.level,text:n.text}]};if(n.type===`camera.enable`)return{...e,camera:{enabled:n.value,stream:n.value?e.camera.stream:null}};if(n.type===`camera.open`)return{...e,camera:{...e.camera,stream:n.stream}};if(n.type===`camera.closed`)return{...e,camera:{...e.camera,stream:null}};if(n.type===`challenge.dismiss`)return e.challenge?.id===n.id?{...e,challenge:null}:e;if(n.type===`voice.mode`)return{...e,voice:{...e.voice,mode:n.mode,level:n.mode===`idle`?0:e.voice.level}};if(n.type===`voice.level`){let t=Number.isFinite(n.level)?Math.min(1,Math.max(0,n.level)):0;return{...e,voice:{...e.voice,level:t}}}if(n.type===`object.dismiss`)return{...e,objects:e.objects.filter(e=>e.id!==n.id)};if(n.type===`object.place`)return{...e,objects:e.objects.map(e=>e.id===n.id?{...e,placement:n.placement}:e)};if(n.type===`alert.dismiss`)return{...e,alerts:e.alerts.filter(e=>e.id!==n.id)}}let r=xy.safeParse(t);if(!r.success)return e;let i=r.data;switch(i.type){case`snapshot`:return{...e,scene:i.stage.scene,objects:i.stage.objects,presence:{...e.presence,state:i.stage.presence.state,style:i.stage.presence.style},mood:i.stage.mood,approval:i.pendingApproval??null};case`stage`:return hw(e,i.command);case`chat.user`:return{...e,chat:fw([...e.chat,{role:`user`,text:i.text}]),chatLive:!1};case`ui`:return{...e,view:i.view,look:i.look??e.look,ownerName:i.ownerName??e.ownerName,viewKnown:!0};case`caption.delta`:{let t=e.captionDone,n=e.chat.at(-1),r=e.chatLive&&n?.role===`assistant`?[...e.chat.slice(0,-1),{role:`assistant`,text:n.text+i.text}]:fw([...e.chat,{role:`assistant`,text:i.text}]);return{...e,chat:r,chatLive:!0,captions:(t?``:e.captions)+i.text,captionDone:!1,presence:{...e.presence,amplitude:mw(.3+i.text.length*.04),pulse:e.presence.pulse+1}}}case`caption.end`:return{...e,chatLive:!1,captionDone:!0,presence:{...e.presence,amplitude:0}};case`approval.request`:{let{type:t,...n}=i;return{...e,approval:n}}case`approval.resolved`:return e.approval?.id===i.id?{...e,approval:null}:e;case`alert`:return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:i.level,text:i.text}]};case`activity`:return{...e,activity:i.text};case`status`:return{...e,busy:i.busy,activity:i.busy?e.activity:null,deviceOnline:i.deviceOnline,voice:{...e.voice,available:i.voiceAvailable??e.voice.available,enrolled:i.voiceEnrolled??e.voice.enrolled}};case`error`:return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:`error`,text:i.message}]};case`voice.heard`:return{...e,captions:i.trust===`guest`?`Guest: ${i.text}`:i.trust===`member`&&i.speaker?`${i.speaker}: ${i.text}`:i.text,captionDone:!0,speaker:{name:i.trust===`member`?i.speaker??null:null,trust:i.trust??`unverified`,seq:(e.speaker?.seq??0)+1}};case`voice.challenge`:return{...e,challenge:{id:i.id,text:i.text}};case`voice.challenge.end`:return e.challenge?.id===i.id?{...e,challenge:null}:e;case`audio.chunk`:case`audio.stop`:return e;case`camera.request`:case`camera.cancel`:return e}}var _w=1024,vw=.8,yw=300;function bw(e,t){let n=Math.min(1,_w/Math.max(e,t));return{width:Math.round(e*n),height:Math.round(t*n)}}function xw(e){let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`permission`:t===`NotFoundError`||t===`OverconstrainedError`?`no-camera`:`busy`}async function Sw(){if(!navigator.mediaDevices?.getUserMedia)throw Object.assign(Error(`This browser cannot use the camera here (use localhost or HTTPS).`),{name:`NotFoundError`});return navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280}},audio:!1})}async function Cw(e,t=yw){let n=document.createElement(`video`);n.muted=!0,n.playsInline=!0,n.srcObject=e,await n.play(),await new Promise(e=>setTimeout(e,t));let{width:r,height:i}=bw(n.videoWidth||640,n.videoHeight||480),a=document.createElement(`canvas`);return a.width=r,a.height=i,a.getContext(`2d`).drawImage(n,0,0,r,i),n.srcObject=null,new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,vw))}var ww=class{opts;active=null;constructor(e){this.opts=e}async handle(e){if(e.type===`camera.cancel`){let t=this.active;t&&t.id===e.id&&(t.cancelled=!0,this.release(t));return}if(!this.opts.enabled())return this.opts.send({type:`camera.denied`,id:e.id,reason:`off`});if(this.active)return this.opts.send({type:`camera.denied`,id:e.id,reason:`busy`});let t={id:e.id,cancelled:!1,stream:null,opened:!1,released:!1};this.active=t;try{let n=await(this.opts.open??Sw)();if(t.stream=n,t.cancelled){n.getTracks().forEach(e=>e.stop());return}t.opened=!0,this.opts.dispatch({type:`camera.open`,stream:n});let r=await(this.opts.frame??(e=>Cw(e)))(n);if(t.cancelled)return;this.release(t);try{await this.opts.upload(e.id,r)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the camera picture to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`camera.denied`,id:e.id,reason:xw(n)})}finally{this.release(t),this.active===t&&(this.active=null)}}dispose(){let e=this.active;e&&(e.cancelled=!0,this.release(e))}release(e){e.released||(e.released=!0,e.stream?.getTracks().forEach(e=>e.stop()),e.opened&&this.opts.dispatch({type:`camera.closed`}))}},Tw={401:`Please sign in again.`,413:`That recording was too long.`,409:`Friend is busy with the last request. Try again in a moment.`,429:`You're talking too fast. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function Ew(e,t){let n;try{n=await fetch(`/api/voice/utterance`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e,signal:t})}catch(e){throw e.name===`AbortError`?e:Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||Tw[n.status]||`The voice request failed (${n.status}).`)}let r=await n.json();return{text:typeof r.text==`string`?r.text:``}}var Dw=4096,Ow=8,kw=20,Aw=6e6;function jw(e){try{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}catch{return null}}var Mw=class{ctx=null;analyser=null;pending=new Map;queue=[];current=null;busy=!1;gen=0;isPlaying=!1;listeners=new Set;unlock(){try{let e=navigator.audioSession;e&&(e.type=`playback`)}catch{}let e=this.ensureContext();e.state!==`running`&&e.resume().catch(()=>{})}locked(){return!this.ctx||this.ctx.state!==`running`}enqueue(e){if(!Number.isInteger(e.seq)||e.seq<0||e.seq>Dw)return;let t=jw(e.data);if(!t)return;let n=this.pending.get(e.id);if(n||(this.pending.size>=Ow&&this.pending.delete(this.pending.keys().next().value),n={parts:new Map,lastSeq:null,bytes:0},this.pending.set(e.id,n)),n.bytes+=t.length,n.bytes>Aw){this.pending.delete(e.id);return}if(n.parts.set(e.seq,t),e.last&&(n.lastSeq=e.seq),n.lastSeq===null||n.parts.size!==n.lastSeq+1)return;this.pending.delete(e.id);let r=new Uint8Array([...n.parts.values()].reduce((e,t)=>e+t.length,0)),i=0;for(let e=0;e<=n.lastSeq;e++){let t=n.parts.get(e);if(!t)return;r.set(t,i),i+=t.length}for(this.queue.push(r.buffer);this.queue.length>kw;)this.queue.shift();this.pump()}stop(){this.gen++,this.queue=[],this.pending.clear(),this.busy=!1;let e=this.current;if(this.current=null,e){e.onended=null;try{e.stop()}catch{}}this.setPlaying(!1)}dispose(){this.stop(),this.ctx?.close().catch(()=>{}),this.ctx=null,this.analyser=null}playing(){return this.isPlaying}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}level(){if(!this.analyser||!this.isPlaying)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}ensureContext(){if(!this.ctx){let e=window.AudioContext??window.webkitAudioContext;this.ctx=new e,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.analyser.connect(this.ctx.destination)}return this.ctx}setPlaying(e){this.isPlaying!==e&&(this.isPlaying=e,this.listeners.forEach(t=>t(e)))}async pump(){if(this.busy)return;let e=this.queue.shift();if(!e){this.setPlaying(!1);return}this.busy=!0;let t=this.gen;try{let n=this.ensureContext();if(n.state!==`running`){try{await n.resume()}catch{}if(t!==this.gen)return;if(n.state!==`running`){this.queue.unshift(e),this.busy=!1;return}}let r=await n.decodeAudioData(e);if(t!==this.gen)return;let i=n.createBufferSource();i.buffer=r,i.connect(this.analyser),i.onended=()=>{this.current===i&&(this.current=null,this.busy=!1,this.pump())},this.current=i,this.setPlaying(!0),i.start()}catch{if(t!==this.gen)return;this.busy=!1,this.pump()}}},Nw=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],Pw=3e3;function Fw(e){let t=e;return t?.name===`NotAllowedError`||t?.name===`SecurityError`?Error(`Microphone permission was denied. Allow it in the browser to talk.`):t?.name===`NotFoundError`||t?.name===`OverconstrainedError`?Error(`No microphone was found.`):Error(t?.message||`Could not open the microphone.`)}var Iw=class e{opts;stream=null;rec=null;chunks=[];ctx=null;analyser=null;timer=null;starting=!1;constructor(e={}){this.opts=e}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get active(){return this.rec!==null}async start(){if(!(this.rec||this.starting)){if(!e.supported())throw Error(`This browser cannot record audio here (use localhost or HTTPS).`);this.starting=!0;try{try{this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}})}catch(e){throw Fw(e)}try{let e=Nw.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.failed();for(let e of this.stream.getTracks())e.onended=()=>this.failed();this.openMeter(this.stream),t.start(250),this.rec=t,this.opts.maxMs&&(this.timer=setTimeout(()=>{this.timer=null,this.opts.onLimit?.()},this.opts.maxMs))}catch(e){throw this.release(),Fw(e)}}finally{this.starting=!1}}}stop(){let e=this.rec;return e?new Promise(t=>{let n=!1,r=null,i=()=>{if(n)return;n=!0,r&&clearTimeout(r);let i=new Blob(this.chunks,{type:e.mimeType||`audio/webm`});this.release(),t(i)};if(r=setTimeout(i,Pw),e.onstop=i,e.state===`inactive`)return i();try{e.stop()}catch{i()}}):Promise.reject(Error(`Not recording.`))}cancel(){let e=this.rec;if(e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.release()}level(){if(!this.analyser||!this.rec)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}failed(){this.rec&&(this.cancel(),this.opts.onError?.())}openMeter(e){try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(e).connect(this.analyser)}catch{this.analyser=null}}release(){this.timer&&clearTimeout(this.timer),this.timer=null,this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.rec=null,this.ctx=null,this.analyser=null,this.chunks=[]}},Lw=2e3,Rw=()=>typeof window<`u`&&window.isSecureContext===!1,zw=50,Bw=class{deps;recorder;player;mode=`idle`;pressed=!1;disposed=!1;uploads=0;toldAboutSound=!1;abort=null;poll=null;unsubscribe;constructor(e){this.deps=e;let t=()=>this.recorderFailed();this.recorder=e.recorder??e.makeRecorder?.(t)??new Iw({maxMs:6e4,onLimit:()=>void this.pressEnd(),onError:t}),this.player=e.player??new Mw,this.unsubscribe=this.player.onChange(e=>{this.mode!==`listening`&&this.mode!==`transcribing`&&this.setMode(e?`speaking`:`idle`)})}async pressStart(){if(!(this.pressed||this.disposed)){if(!this.deps.available()){this.alert(`warn`,`Voice is not available. Run: friend voice setup`);return}if(!(this.deps.supported?.()??Iw.supported())){this.alert(`warn`,Rw()?`This page is not secure, so the browser blocks the microphone. On the PC run: friend lan https on, restart Friend, and open the https:// address.`:`This browser cannot record audio here (use localhost or HTTPS).`);return}this.pressed=!0,this.player.unlock(),this.player.playing()&&(this.deps.send({type:`voice.interrupt`}),this.player.stop());try{await this.recorder.start()}catch(e){this.pressed=!1,this.alert(`error`,e.message),this.setMode(`idle`);return}if(!this.pressed){this.recorder.cancel(),this.setMode(`idle`);return}this.setMode(`listening`)}}async pressEnd(){if(!this.pressed||(this.pressed=!1,!this.recorder.active))return;let e=await this.recorder.stop();if(e.size<Lw){this.alert(`info`,`Hold the key a little longer while you speak.`),this.setMode(`idle`);return}this.setMode(`transcribing`);let t=new AbortController;this.abort=t,this.uploads++;try{let{text:n}=await this.deps.post(e,t.signal);n.trim()||this.alert(`info`,`I didn't catch that.`)}catch(e){e.name!==`AbortError`&&this.alert(`error`,e.message)}finally{this.uploads--,this.abort===t&&(this.abort=null),this.settle()}}blur(){this.pressed&&(this.pressed=!1,this.recorder.cancel(),this.setMode(`idle`))}handleServer(e){if(e.type!==`audio.chunk`)return this.player.stop();this.player.enqueue(e),!this.toldAboutSound&&this.player.locked?.()&&(this.toldAboutSound=!0,this.deps.dispatch({type:`alert.add`,level:`info`,text:`Sound is blocked by the browser. Click or press a key once anywhere on the page to hear me.`}))}unlock(){this.player.unlock()}dispose(){this.disposed=!0,this.pressed=!1,this.stopPolling(),this.abort?.abort(),this.recorder.cancel(),this.player.stop(),this.player.dispose?.(),this.unsubscribe()}recorderFailed(){this.pressed=!1,this.recorder.cancel(),this.alert(`error`,`The microphone stopped working.`),this.setMode(`idle`)}settle(){this.uploads>0||this.mode!==`transcribing`||this.setMode(this.player.playing()?`speaking`:`idle`)}setMode(e){this.disposed||(this.mode=e,this.deps.dispatch({type:`voice.mode`,mode:e}),e===`listening`||e===`speaking`?this.startPolling():this.stopPolling())}startPolling(){this.stopPolling(),this.poll=setInterval(()=>{let e=this.mode===`listening`?this.recorder.level():this.player.level();this.deps.dispatch({type:`voice.level`,level:e})},zw)}stopPolling(){this.poll&&clearInterval(this.poll),this.poll=null}alert(e,t){this.disposed||this.deps.dispatch({type:`alert.add`,level:e,text:t})}};function Vw(e){let[t,n]=(0,l.useReducer)(gw,uw),r=(0,l.useRef)(null),i=(0,l.useRef)(null),a=(0,l.useRef)(null),o=(0,l.useRef)(e);o.current=e;let s=(0,l.useRef)(t);return s.current=t,(0,l.useEffect)(()=>{let e=lw();r.current=e;let t=new Bw({send:t=>e.send(t),dispatch:e=>n(e),post:Ew,available:()=>s.current.voice.available});i.current=t;let c=new ww({send:t=>e.send(t),dispatch:e=>n(e),enabled:()=>s.current.camera.enabled,upload:async(e,t)=>{let n=await fetch(`/api/camera/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)}});a.current=c;let l=e.onMessage(e=>{n(e);let r=e?.type,i=e?.id;(r===`camera.request`||r===`camera.cancel`)&&typeof i==`string`&&c.handle({type:r,id:i}),(r===`audio.chunk`||r===`audio.stop`)&&t.handleServer(e)}),u=e.onState(e=>{n({type:`conn`,value:e}),e===`unauthorized`&&o.current(),e===`elsewhere`&&(t.blur(),c.dispose())});return()=>{l(),u(),t.dispose(),c.dispose(),e.close(),i.current=null,a.current=null,r.current=null}},[]),(0,l.useEffect)(()=>{t.camera.enabled||a.current?.dispose()},[t.camera.enabled]),{state:t,send:(0,l.useCallback)(e=>r.current?.send(e),[]),dispatch:(0,l.useCallback)(e=>n(e),[]),voice:(0,l.useMemo)(()=>({pressStart:()=>void i.current?.pressStart(),pressEnd:()=>void i.current?.pressEnd(),blur:()=>i.current?.blur(),unlock:()=>i.current?.unlock()}),[]),useHere:(0,l.useCallback)(()=>r.current?.takeOver(),[])}}var Hw={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function Uw(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||Hw[n.status]||`The request failed (${n.status}).`)}return await n.json()}var Ww=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),Gw={state:()=>Uw(`/api/voice/enroll`,{}),sample:e=>Uw(`/api/voice/enroll/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>Uw(`/api/voice/enroll/finish`,Ww(`POST`,{pin:e})),cancel:async()=>{await Uw(`/api/voice/enroll/cancel`,Ww(`POST`,{}))},remove:async e=>{await Uw(`/api/voice/enroll`,Ww(`DELETE`,{pin:e}))}},Kw=[`Friend, good evening. It is a pleasant day to get things done.`,`Open my projects and show me what changed today.`,`My voice is my key, so please remember it well.`,`Check the weather and read me the latest headlines.`,`Always protect the boss, and never trust a stranger.`],qw=15e3;function Jw({api:e=Gw,createRecorder:t=e=>new Iw(e),onClose:n,who:r}){let[i,a]=(0,l.useState)(null),[o,s]=(0,l.useState)(0),[c,u]=(0,l.useState)(null),[f,m]=(0,l.useState)(`record`),[h,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[S,C]=(0,l.useState)(``),w=(0,l.useRef)(!0),T=(0,l.useRef)(null);(0,l.useEffect)(()=>(w.current=!0,e.state().then(e=>{w.current&&(a(e),s(e.samples))}).catch(e=>w.current&&b(e.message)),()=>{w.current=!1,T.current?.cancel(),T.current=null}),[e]);let E=(0,l.useCallback)(async()=>{let t=T.current;if(t){T.current=null,g(!1),v(!0);try{let n=await t.stop(),r=await e.sample(n);if(!w.current)return;s(r.count),u(r.note)}catch(e){w.current&&b(e.message)}finally{w.current&&v(!1)}}},[e]),D=async()=>{b(null),u(null);let e=t({maxMs:qw,onLimit:()=>void E(),onError:()=>{T.current=null,w.current&&(g(!1),b(`The microphone stopped working. Try again.`))}});try{await e.start()}catch(e){w.current&&b(e.message);return}if(!w.current)return e.cancel();T.current=e,g(!0)},O=async e=>{b(null),v(!0);try{await e()}catch(e){w.current&&b(e.message)}finally{w.current&&(v(!1),C(``))}},k=async()=>{T.current?.cancel(),T.current=null,await e.cancel().catch(()=>{}),n()},A=i?.min??3,j=o%Kw.length,ee=o<Kw.length?`Phrase ${o+1} of ${Kw.length}`:`Extra recording (${o} so far)`;return(0,p.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Voice enrollment`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:r?`Teach Friend ${r}'s voice`:`Teach Friend your voice`})}),f===`record`&&(0,p.jsxs)(p.Fragment,{children:[!r&&i?.enrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`Your voice is already saved. Saving a new one replaces it.`}),r&&(0,p.jsxs)(`p`,{className:`auth-note`,children:[`Hand the device to `,r,`. `,r,` reads each sentence aloud, close to the microphone, in a quiet room.`]}),(0,p.jsxs)(`p`,{className:`auth-note`,children:[ee,`. Press Record, read this aloud in a quiet room, then press Stop.`]}),(0,p.jsx)(`pre`,{className:`approval-summary`,"data-testid":`enroll-phrase`,style:{whiteSpace:`pre-wrap`},children:Kw[j]}),(0,p.jsxs)(`div`,{role:`status`,className:`auth-note`,children:[o,` recorded`,o>=A?` — enough to save`:` — at least ${A} needed`,`.`,c?` ${c}`:``]}),y&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:y}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[h?(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,onClick:()=>void E(),children:`Stop`}):(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:_||!i||o>=(i?.max??8),onClick:()=>void D(),children:_?`Uploading…`:`Record`}),(0,p.jsx)(`button`,{type:`button`,style:d,disabled:h||_||o<A,onClick:()=>m(`pin-save`),children:r?`Save ${r}'s voice`:`Save my voice`}),!r&&i?.enrolled&&(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:h||_,onClick:()=>m(`pin-delete`),children:`Delete my voice`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>void k(),children:`Cancel`})]})]}),(f===`pin-save`||f===`pin-delete`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:f===`pin-save`?r?`Enter your PIN to save ${r}'s voice.`:`Enter your PIN to save your voice.`:`Enter your PIN to delete your saved voice.`}),(0,p.jsx)(x,{pin:S,onChange:C,onSubmit:f===`pin-save`?()=>!_&&void O(async()=>{await e.finish(S),w.current&&m(`saved`)}):void 0}),y&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:y}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[f===`pin-save`?(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:_||S.length<6,onClick:()=>void O(async()=>{await e.finish(S),w.current&&m(`saved`)}),children:`Save`}):(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:_||S.length<6,onClick:()=>void O(async()=>{await e.remove(S),w.current&&m(`deleted`)}),children:`Delete`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{C(``),b(null),m(`record`)},children:`Back`})]})]}),(f===`saved`||f===`deleted`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:f===`saved`?r?`${r}'s voice is saved. From now on I will know when ${r} is talking.`:`Your voice is saved. From now on I will tell you apart from other speakers.`:`Your voice was deleted. Every voice is treated as yours until you enroll again.`}),(0,p.jsx)(`div`,{className:`approval-actions`,children:(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,onClick:n,children:`Done`})})]})]})}var Yw=new Set([`INPUT`,`TEXTAREA`,`SELECT`,`BUTTON`,`A`,`SUMMARY`]),Xw=new Set([`button`,`checkbox`,`switch`,`tab`,`menuitem`,`link`,`radio`,`option`,`textbox`,`combobox`,`slider`]),Zw=e=>e instanceof HTMLElement&&(Yw.has(e.tagName)||e.isContentEditable||Xw.has(e.getAttribute(`role`)??``)),Qw=e=>e.code===`Space`||e.key===` `;function $w(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>{let e=!1,n=n=>{!Qw(n)||n.ctrlKey||n.metaKey||n.altKey||Zw(n.target)||Zw(document.activeElement)||(n.preventDefault(),!(n.repeat||e)&&(e=!0,t.current.pressStart()))},r=n=>{Qw(n)&&e&&(e=!1,n.preventDefault(),t.current.pressEnd())},i=()=>{e=!1,t.current.blur()},a=()=>{document.hidden&&i()};return window.addEventListener(`keydown`,n),window.addEventListener(`keyup`,r),window.addEventListener(`blur`,i),document.addEventListener(`visibilitychange`,a),()=>{window.removeEventListener(`keydown`,n),window.removeEventListener(`keyup`,r),window.removeEventListener(`blur`,i),document.removeEventListener(`visibilitychange`,a)}},[])}function eT(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>{let e=()=>t.current.unlock(),n=[`pointerdown`,`keydown`,`touchend`];for(let t of n)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of n)window.removeEventListener(t,e)}},[])}function tT({onUseHere:e}){return(0,p.jsx)(`div`,{className:`elsewhere`,role:`alertdialog`,"aria-labelledby":`elsewhere-title`,"data-testid":`elsewhere`,children:(0,p.jsxs)(`div`,{className:`elsewhere-card`,children:[(0,p.jsx)(`h2`,{id:`elsewhere-title`,children:`Friend is open in another window`}),(0,p.jsx)(`p`,{children:`Friend works in one window at a time. Click “Use here” to use it in this window instead; the other one will stop.`}),(0,p.jsx)(`button`,{type:`button`,className:`elsewhere-btn`,onClick:e,autoFocus:!0,children:`Use here`})]})})}function nT(e,t,n){let r=Math.max(100,Math.round(e)),i=Math.max(100,Math.round(t));return{width:r,height:i,kind:r<=599?`phone`:n||r<1024?`tablet`:`desktop`,orientation:i>r?`portrait`:`landscape`,touch:n}}var rT=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches;function iT(){return nT(window.innerWidth,window.innerHeight,rT())}var aT=(e,t)=>!!e&&e.width===t.width&&e.height===t.height&&e.kind===t.kind&&e.orientation===t.orientation&&e.touch===t.touch;function oT(e,t){let n=(0,l.useRef)(null),r=(0,l.useRef)(e);r.current=e,(0,l.useEffect)(()=>{if(t!==`open`){n.current=null;return}let e=()=>{let e=iT();aT(n.current,e)||(n.current=e,r.current({type:`ui.screen`,...e}))};e();let i=null,a=()=>{i&&clearTimeout(i),i=setTimeout(e,400)};return window.addEventListener(`resize`,a),window.addEventListener(`orientationchange`,a),()=>{i&&clearTimeout(i),window.removeEventListener(`resize`,a),window.removeEventListener(`orientationchange`,a)}},[t])}var sT={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function cT(e,t={}){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||sT[n.status]||`The request failed (${n.status}).`)}return await n.json()}var lT=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),uT={overview:()=>cT(`/api/voice/people`),begin:e=>cT(`/api/voice/people/begin`,lT(`POST`,{name:e})),recording:{state:async()=>(await cT(`/api/voice/people`)).enrolling??{enrolled:!1,samples:0,min:3,max:8},sample:e=>cT(`/api/voice/people/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>cT(`/api/voice/people/finish`,lT(`POST`,{pin:e})),cancel:async()=>{await cT(`/api/voice/people/cancel`,lT(`POST`,{}))},remove:async()=>{}},removePerson:async(e,t)=>{await cT(`/api/voice/people/${e}`,lT(`DELETE`,{pin:t}))}};function dT({api:e=uT,createRecorder:t,onClose:n}){let[r,i]=(0,l.useState)(null),[a,o]=(0,l.useState)({kind:`list`}),[s,c]=(0,l.useState)(``),[u,f]=(0,l.useState)(``),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(null),v=(0,l.useRef)(!0),y=(0,l.useCallback)(()=>{e.overview().then(e=>v.current&&i(e)).catch(e=>v.current&&_(e.message))},[e]);(0,l.useEffect)(()=>(v.current=!0,y(),()=>{v.current=!1}),[y]);let b=async()=>{_(null),h(!0);try{let t=await e.begin(s.trim());v.current&&o({kind:`record`,name:t.name})}catch(e){v.current&&_(e.message)}finally{v.current&&h(!1)}},S=async t=>{_(null),h(!0);try{if(await e.removePerson(t.id,u),!v.current)return;o({kind:`list`}),y()}catch(e){v.current&&_(e.message)}finally{v.current&&(h(!1),f(``))}};return a.kind===`record`?(0,p.jsx)(Jw,{api:e.recording,who:a.name,...t?{createRecorder:t}:{},onClose:()=>{c(``),o({kind:`list`}),y()}}):(0,p.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Family voices`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:`Family voices`})}),a.kind===`list`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:`Friend knows your voice. Add the people at home, so it knows who is talking and answers them by name. They can chat and ask for the weather, but cannot use your PC or see your private things.`}),r&&!r.ownerEnrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`First teach Friend your own voice (Esc, then Enroll my voice).`}),r&&r.people.length===0&&r.ownerEnrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`Nobody added yet.`}),r&&r.people.length>0&&(0,p.jsx)(`ul`,{className:`household-list`,"aria-label":`People Friend knows`,children:r.people.map(e=>(0,p.jsxs)(`li`,{className:`household-row`,children:[(0,p.jsx)(`span`,{children:e.name}),(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,onClick:()=>o({kind:`remove`,person:e}),"aria-label":`Remove ${e.name}`,children:`Remove`})]},e.id))}),r&&r.ownerEnrolled&&r.people.length<r.max&&(0,p.jsxs)(`label`,{className:`settings-field`,children:[(0,p.jsx)(`span`,{children:`Add a person`}),(0,p.jsx)(`input`,{value:s,maxLength:40,placeholder:`Name, for example Priya`,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s.trim()&&!m&&void b()})]}),g&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[r&&r.ownerEnrolled&&r.people.length<r.max&&(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:m||!s.trim(),onClick:()=>void b(),children:`Record their voice`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:n,children:`Close`})]})]}),a.kind===`remove`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`p`,{className:`auth-note`,children:[`Enter your PIN to remove `,a.person.name,`’s voice. Friend will treat their voice as a stranger’s.`]}),(0,p.jsx)(x,{pin:u,onChange:f}),g&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:m||u.length<6,onClick:()=>void S(a.person),children:`Remove`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{f(``),_(null),o({kind:`list`})},children:`Back`})]})]})]})}function fT({onSignedOut:e}){let{state:t,send:n,dispatch:r,voice:i,useHere:a}=Vw(e);$w(i),eT(i),oT(n,t.connection);let[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(null),[v,y]=(0,l.useState)(!1),[b,x]=(0,l.useState)(0),[S,C]=(0,l.useState)(null),w=de(t.view),T=(0,l.useMemo)(()=>o?{...t,objects:[],captions:``}:t,[o,t]),E=(0,l.useRef)(!1);(0,l.useEffect)(()=>{E.current||!t.voice.available||t.voice.enrolled||(E.current=!0,r({type:`alert.add`,level:`info`,text:`Voice recognition is not set up. Press Esc, then Enroll my voice.`}))},[t.voice.available,t.voice.enrolled,r]);let D=ne(),O=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(!D||O.current||t.connection!==`open`)return;O.current=!0;let e=!1;try{e=localStorage.getItem(`friend.touchHint`)===`1`,localStorage.setItem(`friend.touchHint`,`1`)}catch{}e||r({type:`alert.add`,level:`info`,text:`Hold the round mic button to talk, or tap it once to start and again to send. The keyboard button types; the menu button opens settings.`})},[D,t.connection,r]);let k=(0,l.useRef)(!1);(0,l.useEffect)(()=>{k.current||t.connection!==`open`||(k.current=!0,fetch(`/api/history`).then(e=>e.ok?e.json():[]).then(e=>r({type:`chat.seed`,lines:e})).catch(()=>{}))},[t.connection,r]),(0,l.useEffect)(()=>{t.connection===`open`&&n({type:`ui.panels`,open:[...w.show.chat?[`chat`]:[],...w.show.tasks?[`tasks`]:[]]})},[t.connection,w.show.chat,w.show.tasks,n]);let j=(0,l.useRef)(!1);(0,l.useEffect)(()=>{t.viewKnown&&t.view===`minimal`&&!j.current&&(j.current=!0,r({type:`alert.add`,level:`info`,text:`The view is Minimal, so the status line and clock are hidden. Press Esc, then View, to bring them back.`}))},[t.viewKnown,t.view,r]);let ee=e=>{Ie.save({view:e}).catch(e=>r({type:`alert.add`,level:`warn`,text:e.message}))},M=(0,l.useMemo)(()=>F({notify:e=>r({type:`alert.add`,level:`info`,text:e}),openSettings:()=>_(`model`),openLook:()=>_(`look`),openConnectors:()=>y(!0),openPlugins:()=>h(!0),openVoice:t.voice.available?()=>u(!0):null,muted:o,setMuted:s,cameraOn:t.camera.enabled,setCamera:e=>r({type:`camera.enable`,value:e}),clearScreen:()=>{for(let e of t.objects)n({type:`stage.event`,objectId:e.id,event:`dismiss`})},statusLine:()=>Ce({connection:t.connection,deviceOnline:t.deviceOnline,approval:t.approval,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity}).text,endSession:t=>{fetch(t===`lock`?`/api/lock`:`/api/logout`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).catch(()=>{}).finally(e)},panelOn:e=>w.show[e],setPanel:(e,t)=>w.toggle(e,t),view:t.view,setView:ee,openHelp:C,resetLayout:()=>{ue(),window.location.reload()}}),[r,n,o,e,w.show,w.toggle,t.view,t.voice.available,t.voice.mode,t.camera.enabled,t.objects,t.connection,t.deviceOnline,t.approval,t.busy,t.activity]);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ow,{state:T,send:n,dispatch:r,voice:i,slash:M,onMenu:()=>x(e=>e+1)}),(0,p.jsxs)(Ee,{approval:t.approval,challenge:t.challenge,cameraStream:t.camera.stream,alerts:t.alerts,connection:t.connection,deviceOnline:t.deviceOnline,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity,showStatus:t.viewKnown&&w.show.status,showClock:t.viewKnown&&w.show.clock,profile:t.viewKnown&&w.show.profile?{ownerName:t.ownerName,speaker:t.speaker}:null,send:n,dispatch:r,children:[t.viewKnown&&w.show.chat&&(0,p.jsx)(fe,{lines:t.chat,live:t.chatLive,onSend:e=>n({type:`chat.send`,text:e}),onClose:()=>w.toggle(`chat`,!1)}),t.viewKnown&&w.show.tasks&&(0,p.jsx)(he,{busy:t.busy,onClose:()=>w.toggle(`tasks`,!1)}),c&&(0,p.jsx)(Jw,{onClose:()=>u(!1)}),d&&(0,p.jsx)(dT,{onClose:()=>f(!1)}),m&&(0,p.jsx)(je,{onClose:()=>h(!1)}),g&&(0,p.jsx)(Ay,{initialTab:g,onClose:()=>_(null)}),v&&(0,p.jsx)(A,{onClose:()=>y(!1)}),S&&(0,p.jsx)(I,{commands:S,onClose:()=>C(null)})]}),(0,p.jsx)(V,{muted:o,onToggleMute:()=>s(e=>!e),onSignedOut:e,voiceAvailable:t.voice.available,voiceEnrolled:t.voice.enrolled,onEnroll:()=>u(!0),onHousehold:()=>f(!0),onPlugins:()=>h(!0),onSettings:()=>_(`model`),onConnectors:()=>y(!0),cameraOn:t.camera.enabled,onToggleCamera:()=>r({type:`camera.enable`,value:!t.camera.enabled}),chatOn:w.show.chat,onToggleChat:()=>w.toggle(`chat`),tasksOn:w.show.tasks,onToggleTasks:()=>w.toggle(`tasks`),view:t.view,onView:ee,openRequest:b}),t.connection===`elsewhere`&&(0,p.jsx)(tT,{onUseHere:a})]})}function pT(){let[e,t]=(0,l.useState)(`loading`);return(0,l.useEffect)(()=>{let e=!0,n=n=>e&&t(n);return(async()=>{try{if(!(await(await fetch(`/api/state`)).json()).hasOwner)return n(`setup`);let e=await(await fetch(`/api/session`,{cache:`no-store`})).json();n(e.signedIn===!0?`stage`:`login`)}catch{n(`login`)}})(),()=>{e=!1}},[]),e===`loading`?(0,p.jsx)(`div`,{className:`boot`,"aria-busy":`true`}):e===`setup`?(0,p.jsx)(g,{onDone:()=>t(`login`)}):e===`login`?(0,p.jsx)(h,{onLoggedIn:()=>t(`stage`)}):(0,p.jsx)(fT,{onSignedOut:()=>t(`login`)})}(0,u.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(l.StrictMode,{children:(0,p.jsx)(pT,{})}));
4453
+ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+IS(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function tC(e,t){return eC.parse(e,t)}tC.options=tC.setOptions=function(e){return eC.setOptions(e),tC.defaults=eC.defaults,px(tC.defaults),tC},tC.getDefaults=dx,tC.defaults=fx;function nC(...e){return eC.use(...e),tC.defaults=eC.defaults,px(tC.defaults),tC}tC.use=nC,tC.walkTokens=function(e,t){return eC.walkTokens(e,t)},tC.parseInline=eC.parseInline,tC.Parser=QS,tC.parser=QS.parse,tC.Renderer=XS,tC.TextRenderer=ZS,tC.Lexer=YS,tC.lexer=YS.lex,tC.Tokenizer=JS,tC.Hooks=$S,tC.parse=tC,tC.options,tC.setOptions,tC.walkTokens,tC.parseInline,QS.parse,YS.lex;var rC=!1;function iC(){rC||(rC=!0,ux.addHook(`afterSanitizeAttributes`,e=>{e instanceof Element&&e.tagName===`A`&&(e.setAttribute(`rel`,`noopener noreferrer`),e.setAttribute(`target`,`_blank`))}))}function aC(e){iC();let t=tC.parse(e,{async:!1,breaks:!0});return ux.sanitize(t,{ALLOWED_TAGS:[`p`,`br`,`strong`,`em`,`code`,`pre`,`ul`,`ol`,`li`,`a`,`h1`,`h2`,`h3`,`h4`,`blockquote`,`hr`,`del`],ALLOWED_ATTR:[`href`,`rel`,`target`],ALLOWED_URI_REGEXP:/^(?:https?:|mailto:)/i})}var oC=e=>Number.isFinite(e);function sC(e){let t=Math.floor(Math.log10(e)),n=e/10**t;return(n<=1?1:n<=2?2:n<=2.5?2.5:n<=5?5:10)*10**t}function cC(e,t,n=5){let r=oC(e)?e:0,i=oC(t)?t:r+1;r>i&&([r,i]=[i,r]),r===i&&(i=r+(Math.abs(r)||1));let a=sC((i-r)/Math.max(1,n-1)),o=Math.floor(r/a)*a,s=Math.ceil(i/a)*a,c=[];for(let e=o;e<=s+a/2;e+=a)c.push(Math.round(e*1e9)/1e9);return{min:o,max:s,ticks:c}}function lC(e,t){let[n,r]=e,[i,a]=t;return r===n?()=>i:e=>i+(e-n)/(r-n)*(a-i)}function uC(e){return e.map(([e,t],n)=>`${n===0?`M`:`L`}${e.toFixed(2)} ${t.toFixed(2)}`).join(` `)}function dC(e,t,n,r,i){let a=r=>{let i=r*Math.PI/180;return`${(e+n*Math.cos(i)).toFixed(2)} ${(t+n*Math.sin(i)).toFixed(2)}`},o=+(Math.abs(i-r)>180);return`M ${a(r)} A ${n} ${n} 0 ${o} 1 ${a(i)}`}function fC(e,t,n){return!oC(e)||!oC(t)||!oC(n)||n<=t?0:Math.min(1,Math.max(0,(e-t)/(n-t)))*240}function pC(e,t,n,r){let i=t.x-e.x,a=t.y-e.y,o=Math.hypot(i,a);if(o===0||o<=n+r)return{from:{...e},to:{...t}};let s=i/o,c=a/o;return{from:{x:e.x+s*n,y:e.y+c*n},to:{x:t.x-s*r,y:t.y-c*r}}}function mC(e,t,n){if(e<=0)return[];if(e===1)return[{x:t/2,y:n/2}];let r=Math.min(t,n)*.36;return Array.from({length:e},(i,a)=>{let o=-Math.PI/2+a*2*Math.PI/e;return{x:t/2+r*Math.cos(o),y:n/2+r*Math.sin(o)}})}var hC=e=>typeof e==`object`&&!!e&&!Array.isArray(e),gC=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,_C=e=>Array.isArray(e)?e:[],vC=e=>typeof e==`number`?Number.isFinite(e)?e:null:typeof e==`string`&&e.trim()!==``&&Number.isFinite(Number(e))?Number(e):null,yC=(e,t)=>e.length>t?e.slice(0,t)+`…`:e,bC=[`var(--accent)`,`#ffb454`,`#7b8cff`,`#5ef0b0`,`#ff6b7a`,`#c792ea`],xC=({text:e})=>e?(0,p.jsx)(`h3`,{className:`obj-title`,children:e}):null,SC=({text:e=`No data`})=>(0,p.jsx)(`p`,{className:`obj-empty`,children:e}),CC=400,wC=220,TC={l:44,r:12,t:10,b:28};function EC({props:e}){let t=e.kind===`bar`||e.kind===`area`?e.kind:`line`,n=_C(e.labels).slice(0,120).map(gC),r=_C(e.series).slice(0,6).map((e,t)=>{let n=hC(e)?e:{},r=_C(n.values).slice(0,120).map((e,t)=>({idx:t,v:vC(e)})).filter(e=>e.v!==null);return{name:gC(n.name)||`series ${t+1}`,points:r}}).filter(e=>e.points.length>0);if(r.length===0)return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{})]});let i=r.flatMap(e=>e.points.map(e=>e.v)),a=Math.min(...i),o=Math.max(...i),s=cC(t===`line`?a:Math.min(0,a),t===`line`?o:Math.max(0,o),5),c=Math.max(n.length,...r.map(e=>e.points[e.points.length-1].idx+1),2),l=lC([s.min,s.max],[wC-TC.b,TC.t]),u=lC([0,c-1],[TC.l,CC-TC.r]),d=(CC-TC.l-TC.r)/c,f=Math.max(1,d*.7/r.length),m=(e,t)=>TC.l+e*d+d*.15+t*f,h=Math.max(1,Math.ceil(c/6)),g=gC(e.unit);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsxs)(`svg`,{className:`obj-chart`,viewBox:`0 0 ${CC} ${wC}`,role:`img`,"aria-label":gC(e.title)||`chart`,children:[s.ticks.map(e=>(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`line`,{className:`grid`,x1:TC.l,x2:CC-TC.r,y1:l(e),y2:l(e)}),(0,p.jsxs)(`text`,{className:`tick`,x:TC.l-6,y:l(e)+3,textAnchor:`end`,children:[e,g&&e===s.max?g:``]})]},e)),Array.from({length:c},(e,t)=>t).filter(e=>e%h===0&&n[e]).map(e=>(0,p.jsx)(`text`,{className:`tick`,x:t===`bar`?m(e,0)+f*r.length/2:u(e),y:212,textAnchor:`middle`,children:yC(n[e],8)},e)),r.map((e,n)=>{let r=bC[n%bC.length];if(t===`bar`)return(0,p.jsx)(`g`,{children:e.points.map(e=>(0,p.jsx)(`rect`,{className:`bar`,x:m(e.idx,n),y:Math.min(l(e.v),l(0)),width:f,height:Math.abs(l(e.v)-l(0)),fill:r},e.idx))},n);let i=e.points.map(e=>[u(e.idx),l(e.v)]),a=uC(i),o=`${a} L${i[i.length-1][0].toFixed(2)} ${l(s.min).toFixed(2)} L${i[0][0].toFixed(2)} ${l(s.min).toFixed(2)} Z`;return(0,p.jsxs)(`g`,{children:[t===`area`&&(0,p.jsx)(`path`,{className:`series-area`,d:o,fill:r,opacity:.18}),(0,p.jsx)(`path`,{className:`series-line`,d:a,fill:`none`,stroke:r,strokeWidth:2,strokeLinejoin:`round`})]},n)})]}),r.length>1&&(0,p.jsx)(`ul`,{className:`legend`,children:r.map((e,t)=>(0,p.jsxs)(`li`,{children:[(0,p.jsx)(`i`,{style:{background:bC[t%bC.length]}}),(0,p.jsx)(`span`,{children:e.name})]},t))})]})}function DC({props:e}){let t=vC(e.min)??0,n=vC(e.max)??100,r=vC(e.value)??t,i=fC(r,t,n),a=i/240;return(0,p.jsxs)(`div`,{className:`obj-gauge ${a>.95?`gauge-crit`:a>.8?`gauge-warn`:``}`,children:[(0,p.jsxs)(`svg`,{viewBox:`0 0 200 150`,role:`img`,"aria-label":`${gC(e.label)} ${r}`,children:[(0,p.jsx)(`path`,{className:`track`,d:dC(100,100,70,150,390),fill:`none`,strokeWidth:12,strokeLinecap:`round`}),i>0&&(0,p.jsx)(`path`,{className:`value`,d:dC(100,100,70,150,150+i),fill:`none`,strokeWidth:12,strokeLinecap:`round`})]}),(0,p.jsxs)(`div`,{className:`gauge-read`,children:[(0,p.jsx)(`span`,{className:`gauge-value`,children:String(Math.round(r*100)/100)}),gC(e.unit)&&(0,p.jsx)(`small`,{className:`gauge-unit`,children:gC(e.unit)})]}),(0,p.jsx)(`span`,{className:`obj-label`,children:gC(e.label)})]})}function OC({props:e}){let t=_C(e.items).slice(0,30).map(e=>hC(e)?e:{}).map(e=>({time:gC(e.time),title:gC(e.title),detail:gC(e.detail)})).filter(e=>e.title||e.time);return t.length===0?(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{text:`Nothing to show`})]}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(`ol`,{className:`obj-timeline`,children:t.map((e,t)=>(0,p.jsxs)(`li`,{children:[(0,p.jsx)(`time`,{children:e.time}),(0,p.jsx)(`strong`,{children:e.title}),e.detail&&(0,p.jsx)(`span`,{children:e.detail})]},t))})]})}var kC=400,AC=300,jC=12;function MC({props:e}){let t=(0,l.useId)(),n=new Set,r=[];for(let t of _C(e.nodes)){let e=hC(t)?t:{},i=gC(e.id);if(i&&!n.has(i)&&(n.add(i),r.push({id:i,label:gC(e.label)||i}),r.length>=40))break}if(r.length===0)return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsx)(SC,{text:`Nothing to show`})]});let i=new Map(r.map((e,t)=>[e.id,mC(r.length,kC,AC)[t]])),a=[];for(let t of _C(e.edges)){let e=hC(t)?t:{},n=gC(e.from),r=gC(e.to);if(i.has(n)&&i.has(r)&&n!==r&&(a.push({from:n,to:r,label:gC(e.label)}),a.length>=80))break}return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(xC,{text:gC(e.title)}),(0,p.jsxs)(`svg`,{className:`obj-graph`,viewBox:`0 0 ${kC} ${AC}`,role:`img`,"aria-label":gC(e.title)||`graph`,children:[(0,p.jsx)(`defs`,{children:(0,p.jsx)(`marker`,{id:t,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`6`,markerHeight:`6`,orient:`auto-start-reverse`,children:(0,p.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,className:`arrow`})})}),a.map((e,n)=>{let{from:r,to:a}=pC(i.get(e.from),i.get(e.to),14,17),o=(r.x+a.x)/2+(kC/2-(r.x+a.x)/2)*.25,s=(r.y+a.y)/2+(AC/2-(r.y+a.y)/2)*.25;return(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`path`,{className:`edge`,d:`M ${r.x.toFixed(1)} ${r.y.toFixed(1)} Q ${o.toFixed(1)} ${s.toFixed(1)} ${a.x.toFixed(1)} ${a.y.toFixed(1)}`,fill:`none`,markerEnd:`url(#${t})`}),e.label&&(0,p.jsx)(`text`,{className:`edge-label`,x:o,y:s,textAnchor:`middle`,children:yC(e.label,12)})]},n)}),r.map(e=>{let t=i.get(e.id);return(0,p.jsxs)(`g`,{children:[(0,p.jsx)(`circle`,{className:`node`,cx:t.x,cy:t.y,r:jC}),(0,p.jsx)(`text`,{className:`node-label`,x:t.x,y:t.y+26,textAnchor:`middle`,children:yC(e.label,18)})]},e.id)})]})]})}var NC=[`default-src 'none'`,`script-src 'unsafe-inline'`,`style-src 'unsafe-inline'`,`img-src data: blob:`,`form-action 'none'`,`base-uri 'none'`].join(`; `),PC=`html,body{margin:0;min-height:100%;background:#050b10;color:#d8f6ff;font:15px/1.5 system-ui,sans-serif}`;function FC(e){return`<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="${NC}"><meta name="viewport" content="width=device-width,initial-scale=1"><style>${PC}</style></head><body>${e}</body></html>`}function IC({props:e}){let t=typeof e.html==`string`?e.html:``,n=typeof e.title==`string`?e.title:``,r=(0,l.useMemo)(()=>FC(t),[t]);return(0,p.jsxs)(`div`,{className:`obj-sandbox`,children:[n&&(0,p.jsx)(`h3`,{className:`obj-title`,children:n}),(0,p.jsx)(`iframe`,{title:n||`Page made by Friend`,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,allow:``,srcDoc:r})]})}var LC=e=>typeof e==`string`?e:typeof e==`number`?String(e):``,RC=e=>Array.isArray(e)?e:[];function zC({props:e}){let t=(0,l.useMemo)(()=>aC(LC(e.text)),[e.text]);return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`div`,{className:`obj-md`,dangerouslySetInnerHTML:{__html:t}})]})}function BC({props:e}){return(0,p.jsxs)(`div`,{className:`obj-stat`,children:[(0,p.jsx)(`span`,{className:`obj-label`,children:LC(e.label)}),(0,p.jsxs)(`span`,{className:`obj-value`,children:[(0,p.jsx)(`span`,{children:LC(e.value)}),LC(e.unit)&&(0,p.jsx)(`small`,{children:LC(e.unit)})]}),LC(e.delta)&&(0,p.jsx)(`span`,{className:`obj-delta`,children:LC(e.delta)})]})}function VC({props:e}){return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`ul`,{className:`obj-list`,children:RC(e.items).map((e,t)=>{let n=typeof e==`object`&&e?e:{text:e};return(0,p.jsx)(`li`,{className:n.done?`done`:void 0,children:LC(n.text)},t)})})]})}function HC({props:e}){let t=RC(e.columns),n=RC(e.rows);return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`div`,{className:`obj-table-wrap`,children:(0,p.jsxs)(`table`,{className:`obj-table`,children:[(0,p.jsx)(`thead`,{children:(0,p.jsx)(`tr`,{children:t.map((e,t)=>(0,p.jsx)(`th`,{children:LC(e)},t))})}),(0,p.jsx)(`tbody`,{children:n.map((e,t)=>(0,p.jsx)(`tr`,{children:RC(e).map((e,t)=>(0,p.jsx)(`td`,{children:LC(e)},t))},t))})]})})]})}function UC({props:e}){return(0,p.jsxs)(p.Fragment,{children:[LC(e.title)&&(0,p.jsx)(`h3`,{className:`obj-title`,children:LC(e.title)}),(0,p.jsx)(`pre`,{className:`obj-code`,"data-lang":LC(e.language),children:(0,p.jsx)(`code`,{children:LC(e.code)})})]})}var WC={card:zC,stat:BC,list:VC,table:HC,code:UC,chart:EC,gauge:DC,timeline:OC,graph:MC,sandbox:IC};function GC(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[],i=new Set;for(let t of e){if(i.has(t.object.id))continue;i.add(t.object.id);let e=n.get(t.object.id);r.push(e?{object:e,leaving:!1}:{object:t.object,leaving:!0})}for(let e of t)i.has(e.id)||(i.add(e.id),r.push({object:e,leaving:!1}));return r}function KC(e,t){let[n,r]=(0,l.useState)(()=>e.map(e=>({object:e,leaving:!1}))),i=(0,l.useRef)(new Map);return(0,l.useEffect)(()=>{r(n=>{let a=GC(n,e),o=new Set(n.filter(e=>e.leaving).map(e=>e.object.id));for(let e of a){let n=i.current.get(e.object.id);if(!e.leaving)n&&clearTimeout(n),i.current.delete(e.object.id);else if(!o.has(e.object.id)&&!n){let n=e.object.id;i.current.set(n,setTimeout(()=>{i.current.delete(n),r(e=>e.filter(e=>!(e.object.id===n&&e.leaving)))},Math.max(t,0)))}}return t<=0?a.filter(e=>!e.leaving):a})},[e,t]),(0,l.useEffect)(()=>()=>{for(let e of i.current.values())clearTimeout(e);i.current.clear()},[]),n}var qC=.12,JC=.1,YC=.02,XC=(e,t,n)=>Math.min(Math.max(e,t),n);function ZC(e){let t=XC(e.w,qC,1),n=XC(e.h,JC,1);return{x:XC(e.x,0,1-t),y:XC(e.y,0,1-n),w:t,h:n}}function QC(e,t){let n=t.getBoundingClientRect(),r=e.getBoundingClientRect();return n.width<=0||n.height<=0?null:ZC({x:(r.left-n.left)/n.width,y:(r.top-n.top)/n.height,w:r.width/n.width,h:r.height/n.height})}function $C(e,t,n){let r=(0,l.useRef)(null),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)((n,r)=>{let i=ZC(r);t({type:`object.place`,id:n,placement:{x:i.x,y:i.y,w:i.w,h:i.h}}),e({type:`stage.move`,objectId:n,rect:i})},[e,t]),s=(0,l.useCallback)((e,t,i)=>{if(e.pointerType===`mouse`&&e.button!==0)return;let o=n(),s=e.currentTarget.closest(`[data-object]`);if(!o||!s||r.current)return;let c=QC(s,o);if(!c)return;let l=o.getBoundingClientRect();r.current={id:t.id,mode:i,pointer:e.pointerId,startX:e.clientX,startY:e.clientY,from:c,stageW:l.width,stageH:l.height};try{e.currentTarget.setPointerCapture(e.pointerId)}catch{}e.stopPropagation(),e.preventDefault(),a({id:t.id,box:c})},[n]),c=(e,t)=>{let n=(t.clientX-e.startX)/e.stageW,r=(t.clientY-e.startY)/e.stageH;return e.mode===`move`?ZC({...e.from,x:e.from.x+n,y:e.from.y+r}):ZC({...e.from,w:e.from.w+n,h:e.from.h+r})};return{preview:i,begin:s,move:(0,l.useCallback)(e=>{let t=r.current;t&&t.pointer===e.pointerId&&a({id:t.id,box:c(t,e)})},[]),end:(0,l.useCallback)((e,t)=>{let n=r.current;n&&n.pointer===e.pointerId&&(r.current=null,a(null),t||o(n.id,c(n,e)))},[o]),key:(0,l.useCallback)((e,t)=>{let r={ArrowLeft:[-.02,0],ArrowRight:[YC,0],ArrowUp:[0,-.02],ArrowDown:[0,YC]}[e.key],i=n(),a=e.currentTarget.closest(`[data-object]`);if(!r||!i||!a)return;let s=QC(a,i);s&&(e.preventDefault(),o(t.id,e.shiftKey?{...s,w:s.w+r[0],h:s.h+r[1]}:{...s,x:s.x+r[0],y:s.y+r[1]}))},[o,n])}}function ew(e,t){if(e===`auto`)return{position:`relative`};if(t.w<600)return{position:`relative`,width:`100%`};let[n,r,i,a]=typeof e==`string`?uy[e]:[e.x*100,e.y*100,e.w*100,e.h*100],o={position:`absolute`,left:`${n}%`,top:`${r}%`,width:`${i}%`};return e===`top`||e===`bottom`?{...o,maxHeight:`${a}%`}:{...o,height:`${a}%`}}var tw=350,nw=()=>typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,rw=class extends l.Component{state={failed:!1};static getDerivedStateFromError(){return{failed:!0}}render(){return this.state.failed?null:this.props.children}};function iw(){let e=()=>({w:window.innerWidth,h:window.innerHeight}),[t,n]=(0,l.useState)(e);return(0,l.useEffect)(()=>{let t=()=>n(e());return window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[]),t}var aw=350;function ow({state:e,send:t,dispatch:n,voice:r,slash:i,onMenu:a}){let o=iw(),[s,c]=(0,l.useState)(0),[u,d]=(0,l.useState)(!1),f=ne(),m=o.w<600,h=e.scene===`focus`||e.scene===`multi`,g={"--accent":e.mood.accent,"--intensity":e.mood.intensity},_=e.voice.mode,v=_===`listening`?`listening`:_===`speaking`?`speaking`:_===`transcribing`?`thinking`:e.presence.state,y=gu(e.look.reactivity),b=Math.min(1,(_===`listening`||_===`speaking`?e.voice.level:e.presence.amplitude)*y),x=(0,l.useRef)({timer:null,down:!1,talking:!1,id:null}),S=e=>{if(!(e.target===e.currentTarget||e.target.closest(`[data-presence]`))||e.pointerType===`mouse`&&e.button!==0)return;let t=x.current;if(!(t.down&&t.id!==null&&e.pointerId!==t.id)){t.timer&&clearTimeout(t.timer),t.down=!0,t.talking=!1,t.id=typeof e.pointerId==`number`?e.pointerId:null;try{t.id!==null&&e.currentTarget.setPointerCapture?.(t.id)}catch{}t.timer=r?setTimeout(()=>{t.down&&(t.talking=!0,r.pressStart())},aw):null}},C=(e,t)=>{let n=x.current;n.down&&(n.id===null||typeof e.pointerId!=`number`||e.pointerId===n.id)&&(n.down=!1,n.id=null,n.timer&&clearTimeout(n.timer),n.timer=null,n.talking?(n.talking=!1,t?r?.blur?.():r?.pressEnd()):t||c(e=>e+1))},w=(0,l.useRef)(null),T=$C(t,n,()=>w.current),E=KC(e.objects,nw()?0:tw),D=E.filter(e=>e.object.placement===`auto`),O=E.filter(e=>e.object.placement!==`auto`),k=({object:e,leaving:r})=>{let i=WC[e.type];if(!i)return null;let a=!m&&!r,s=T.preview?.id===e.id?T.preview.box:null,c=s?{x:s.x,y:s.y,w:s.w,h:s.h}:e.placement;return(0,p.jsxs)(`section`,{"data-object":e.id,className:`obj glass${e.style===`alert`?` alert`:``}${e.pinned?` pinned`:``}${s?` dragging`:``}${r?` leaving`:``}`,style:ew(c,o),children:[a&&(0,p.jsx)(`div`,{className:`obj-grip`,role:`button`,tabIndex:0,"aria-label":`Move ${e.id}. Drag, or use the arrow keys; hold Shift to resize.`,onPointerDown:t=>T.begin(t,e,`move`),onPointerMove:T.move,onPointerUp:e=>T.end(e,!1),onPointerCancel:e=>T.end(e,!0),onKeyDown:t=>T.key(t,e)}),(0,p.jsx)(`button`,{className:`obj-pin${e.pinned?` on`:``}`,"aria-label":e.pinned?`Unpin ${e.id}`:`Pin ${e.id} to the screen`,"aria-pressed":!!e.pinned,title:e.pinned?`Pinned: stays on the screen. Click to unpin.`:`Pin: keep this on the screen.`,disabled:r,onClick:()=>t({type:`stage.pin`,objectId:e.id,pinned:!e.pinned}),children:(0,p.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:e.pinned?`currentColor`:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:(0,p.jsx)(`path`,{d:`M12 17v5M9 3h6l-1 7 3 3H7l3-3-1-7z`})})}),(0,p.jsx)(`button`,{className:`obj-close`,"aria-label":`Dismiss ${e.id}`,title:e.pinned?`Remove this widget`:`Dismiss`,disabled:r,onClick:()=>{t({type:`stage.event`,objectId:e.id,event:`dismiss`}),n({type:`object.dismiss`,id:e.id})},children:`×`}),a&&(0,p.jsx)(`div`,{className:`obj-resize`,"aria-hidden":`true`,onPointerDown:t=>T.begin(t,e,`resize`),onPointerMove:T.move,onPointerUp:e=>T.end(e,!1),onPointerCancel:e=>T.end(e,!0)}),(0,p.jsx)(rw,{children:(0,p.jsx)(i,{props:e.props})})]},e.id)};return(0,p.jsxs)(`div`,{ref:w,"data-testid":`stage`,className:`stage`,style:g,onPointerDown:S,onPointerUp:e=>C(e,!1),onPointerCancel:e=>C(e,!0),onContextMenu:e=>r&&e.preventDefault(),children:[e.look.ambient&&(0,p.jsx)(`div`,{className:`ambient`,"aria-hidden":`true`,style:{opacity:.35+.65*e.mood.intensity}}),(0,p.jsx)(hu,{state:v,amplitude:b,pulse:e.presence.pulse,mode:h?`corner`:`full`,accent:e.mood.accent,style:e.presence.style,intensity:e.mood.intensity,scale:e.look.size}),(0,p.jsxs)(`div`,{className:m?`objects objects-stack`:`objects`,style:{zIndex:10},children:[D.length>0&&(0,p.jsx)(`div`,{className:`auto-grid`,children:D.map(k)}),O.map(k)]}),e.look.captions&&e.captions&&(0,p.jsx)(`p`,{className:`captions captions-${e.look.captionSize}${e.captionDone?` done`:``}`,"aria-live":`polite`,children:e.captions}),f&&r&&!u&&(0,p.jsx)(Fy,{voice:r,mode:_,onType:()=>c(e=>e+1),onMenu:()=>a?.()}),(0,p.jsx)(My,{requestOpen:s,slash:i,onOpenChange:d,onSend:e=>t({type:`chat.send`,text:e})})]})}function sw(){let e=()=>Math.random().toString(36).slice(2,12)+Date.now().toString(36);try{let t=sessionStorage.getItem(`friend.tab`);return t||(t=e(),sessionStorage.setItem(`friend.tab`,t)),t}catch{return e()}}function cw(){return`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}function lw(e=cw()){let t=null,n=`connecting`,r=!1,i=0,a=!1,o=sw(),s=null,c=new Set,l=new Set,u=e=>{n=e,l.forEach(t=>t(e))};function d(){if(r)return;u(`connecting`);let n=new WebSocket(`${e}${e.includes(`?`)?`&`:`?`}tab=${o}${a?`&takeover=1`:``}`);t=n,n.onopen=()=>{i=0,a=!1,u(`open`)},n.onmessage=e=>{try{let t=JSON.parse(String(e.data));c.forEach(e=>e(t))}catch{}},n.onclose=e=>{if(!r){if(e.code===4401)return u(`unauthorized`);if(e.code===4409||e.code===4410)return u(`elsewhere`);u(`closed`),s=setTimeout(d,Math.min(500*2**i++,8e3))}},n.onerror=()=>{}}return d(),{send(e){t?.readyState===WebSocket.OPEN&&t.send(JSON.stringify(e))},onMessage(e){return c.add(e),()=>c.delete(e)},onState(e){return l.add(e),()=>l.delete(e)},state:()=>n,takeOver(){r||n!==`elsewhere`||(a=!0,i=0,d())},close(){r=!0,s&&clearTimeout(s),t?.close()}}}var uw={scene:`conversation`,objects:[],captions:``,captionDone:!0,presence:{state:`idle`,style:`sphere`,amplitude:0,pulse:0},mood:{accent:`#3fd8ff`,intensity:.6},approval:null,alerts:[],connection:`connecting`,chat:[],chatLive:!1,view:`companion`,look:{size:1,reactivity:.7,ambient:!0,captions:!0,captionSize:`medium`},viewKnown:!1,busy:!1,activity:null,deviceOnline:!1,voice:{mode:`idle`,level:0,available:!1,enrolled:!1},challenge:null,camera:{enabled:!1,stream:null},speaker:null,ownerName:``},dw=200,fw=e=>e.length>dw?e.slice(-200):e,pw=0,mw=e=>Math.min(1,Math.max(0,e));function hw(e,t){switch(t.cmd){case`scene`:return{...e,scene:t.mode};case`show`:{let n=e.objects.findIndex(e=>e.id===t.object.id),r=n===-1?[...e.objects,t.object]:e.objects.map((e,r)=>r===n?t.object:e);return{...e,objects:r}}case`update`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,props:{...e.props,...t.props}}:e)};case`hide`:return{...e,objects:e.objects.filter(e=>e.id!==t.id)};case`clear`:return{...e,objects:e.objects.filter(e=>e.pinned),scene:`conversation`};case`pin`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,pinned:!0}:e)};case`unpin`:return{...e,objects:e.objects.map(e=>e.id===t.id?(({pinned:e,...t})=>t)(e):e)};case`place`:return{...e,objects:e.objects.map(e=>e.id===t.id?{...e,placement:t.placement}:e)};case`presence`:return{...e,presence:{...e.presence,state:t.state??e.presence.state,style:t.style??e.presence.style}};case`mood`:return{...e,mood:{accent:t.accent??e.mood.accent,intensity:t.intensity??e.mood.intensity}}}}function gw(e,t){let n=t;if(n&&typeof n==`object`){if(n.type===`conn`)return{...e,connection:n.value};if(n.type===`chat.seed`){let t=Array.isArray(n.lines)?n.lines:[];return e.chat.length===0?{...e,chat:fw(t)}:{...e,chat:fw([...t,...e.chat])}}if(n.type===`alert.add`)return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:n.level,text:n.text}]};if(n.type===`camera.enable`)return{...e,camera:{enabled:n.value,stream:n.value?e.camera.stream:null}};if(n.type===`camera.open`)return{...e,camera:{...e.camera,stream:n.stream}};if(n.type===`camera.closed`)return{...e,camera:{...e.camera,stream:null}};if(n.type===`challenge.dismiss`)return e.challenge?.id===n.id?{...e,challenge:null}:e;if(n.type===`voice.mode`)return{...e,voice:{...e.voice,mode:n.mode,level:n.mode===`idle`?0:e.voice.level}};if(n.type===`voice.level`){let t=Number.isFinite(n.level)?Math.min(1,Math.max(0,n.level)):0;return{...e,voice:{...e.voice,level:t}}}if(n.type===`object.dismiss`)return{...e,objects:e.objects.filter(e=>e.id!==n.id)};if(n.type===`object.place`)return{...e,objects:e.objects.map(e=>e.id===n.id?{...e,placement:n.placement}:e)};if(n.type===`alert.dismiss`)return{...e,alerts:e.alerts.filter(e=>e.id!==n.id)}}let r=xy.safeParse(t);if(!r.success)return e;let i=r.data;switch(i.type){case`snapshot`:return{...e,scene:i.stage.scene,objects:i.stage.objects,presence:{...e.presence,state:i.stage.presence.state,style:i.stage.presence.style},mood:i.stage.mood,approval:i.pendingApproval??null};case`stage`:return hw(e,i.command);case`chat.user`:return{...e,chat:fw([...e.chat,{role:`user`,text:i.text}]),chatLive:!1};case`ui`:return{...e,view:i.view,look:i.look??e.look,ownerName:i.ownerName??e.ownerName,viewKnown:!0};case`caption.delta`:{let t=e.captionDone,n=e.chat.at(-1),r=e.chatLive&&n?.role===`assistant`?[...e.chat.slice(0,-1),{role:`assistant`,text:n.text+i.text}]:fw([...e.chat,{role:`assistant`,text:i.text}]);return{...e,chat:r,chatLive:!0,captions:(t?``:e.captions)+i.text,captionDone:!1,presence:{...e.presence,amplitude:mw(.3+i.text.length*.04),pulse:e.presence.pulse+1}}}case`caption.end`:return{...e,chatLive:!1,captionDone:!0,presence:{...e.presence,amplitude:0}};case`approval.request`:{let{type:t,...n}=i;return{...e,approval:n}}case`approval.resolved`:return e.approval?.id===i.id?{...e,approval:null}:e;case`alert`:return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:i.level,text:i.text}]};case`activity`:return{...e,activity:i.text};case`status`:return{...e,busy:i.busy,activity:i.busy?e.activity:null,deviceOnline:i.deviceOnline,voice:{...e.voice,available:i.voiceAvailable??e.voice.available,enrolled:i.voiceEnrolled??e.voice.enrolled}};case`error`:return{...e,alerts:[...e.alerts.slice(-3),{id:++pw,level:`error`,text:i.message}]};case`voice.heard`:return{...e,captions:i.trust===`guest`?`Guest: ${i.text}`:i.trust===`member`&&i.speaker?`${i.speaker}: ${i.text}`:i.text,captionDone:!0,speaker:{name:i.trust===`member`?i.speaker??null:null,trust:i.trust??`unverified`,seq:(e.speaker?.seq??0)+1}};case`voice.challenge`:return{...e,challenge:{id:i.id,text:i.text}};case`voice.challenge.end`:return e.challenge?.id===i.id?{...e,challenge:null}:e;case`audio.chunk`:case`audio.stop`:return e;case`camera.request`:case`camera.cancel`:return e}}var _w=1024,vw=.8,yw=300;function bw(e,t){let n=Math.min(1,_w/Math.max(e,t));return{width:Math.round(e*n),height:Math.round(t*n)}}function xw(e){let t=e?.name;return t===`NotAllowedError`||t===`SecurityError`?`permission`:t===`NotFoundError`||t===`OverconstrainedError`?`no-camera`:`busy`}async function Sw(){if(!navigator.mediaDevices?.getUserMedia)throw Object.assign(Error(`This browser cannot use the camera here (use localhost or HTTPS).`),{name:`NotFoundError`});return navigator.mediaDevices.getUserMedia({video:{width:{ideal:1280}},audio:!1})}async function Cw(e,t=yw){let n=document.createElement(`video`);n.muted=!0,n.playsInline=!0,n.srcObject=e,await n.play(),await new Promise(e=>setTimeout(e,t));let{width:r,height:i}=bw(n.videoWidth||640,n.videoHeight||480),a=document.createElement(`canvas`);return a.width=r,a.height=i,a.getContext(`2d`).drawImage(n,0,0,r,i),n.srcObject=null,new Promise((e,t)=>a.toBlob(n=>n?e(n):t(Error(`Could not encode the picture.`)),`image/jpeg`,vw))}var ww=class{opts;active=null;constructor(e){this.opts=e}async handle(e){if(e.type===`camera.cancel`){let t=this.active;t&&t.id===e.id&&(t.cancelled=!0,this.release(t));return}if(!this.opts.enabled())return this.opts.send({type:`camera.denied`,id:e.id,reason:`off`});if(this.active)return this.opts.send({type:`camera.denied`,id:e.id,reason:`busy`});let t={id:e.id,cancelled:!1,stream:null,opened:!1,released:!1};this.active=t;try{let n=await(this.opts.open??Sw)();if(t.stream=n,t.cancelled){n.getTracks().forEach(e=>e.stop());return}t.opened=!0,this.opts.dispatch({type:`camera.open`,stream:n});let r=await(this.opts.frame??(e=>Cw(e)))(n);if(t.cancelled)return;this.release(t);try{await this.opts.upload(e.id,r)}catch{this.opts.dispatch({type:`alert.add`,level:`warn`,text:`Could not send the camera picture to Friend.`})}}catch(n){t.cancelled||this.opts.send({type:`camera.denied`,id:e.id,reason:xw(n)})}finally{this.release(t),this.active===t&&(this.active=null)}}dispose(){let e=this.active;e&&(e.cancelled=!0,this.release(e))}release(e){e.released||(e.released=!0,e.stream?.getTracks().forEach(e=>e.stop()),e.opened&&this.opts.dispatch({type:`camera.closed`}))}},Tw={401:`Please sign in again.`,413:`That recording was too long.`,409:`Friend is busy with the last request. Try again in a moment.`,429:`You're talking too fast. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function Ew(e,t){let n;try{n=await fetch(`/api/voice/utterance`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e,signal:t})}catch(e){throw e.name===`AbortError`?e:Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||Tw[n.status]||`The voice request failed (${n.status}).`)}let r=await n.json();return{text:typeof r.text==`string`?r.text:``}}var Dw=0;function Ow(e){try{let t=navigator.audioSession;t&&t.type!==e&&(t.type=e)}catch{}}function kw(){Dw===0&&Ow(`playback`)}function Aw(){Dw++,Ow(`play-and-record`);let e=!1;return()=>{e||(e=!0,Dw=Math.max(0,Dw-1),Dw===0&&Ow(`playback`))}}var jw=4096,Mw=8,Nw=20,Pw=6e6;function Fw(e){try{let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}catch{return null}}var Iw=class{ctx=null;analyser=null;pending=new Map;queue=[];current=null;busy=!1;gen=0;isPlaying=!1;listeners=new Set;unlock(){kw();let e=this.ensureContext();e.state!==`running`&&e.resume().catch(()=>{})}locked(){return!this.ctx||this.ctx.state!==`running`}enqueue(e){if(!Number.isInteger(e.seq)||e.seq<0||e.seq>jw)return;let t=Fw(e.data);if(!t)return;let n=this.pending.get(e.id);if(n||(this.pending.size>=Mw&&this.pending.delete(this.pending.keys().next().value),n={parts:new Map,lastSeq:null,bytes:0},this.pending.set(e.id,n)),n.bytes+=t.length,n.bytes>Pw){this.pending.delete(e.id);return}if(n.parts.set(e.seq,t),e.last&&(n.lastSeq=e.seq),n.lastSeq===null||n.parts.size!==n.lastSeq+1)return;this.pending.delete(e.id);let r=new Uint8Array([...n.parts.values()].reduce((e,t)=>e+t.length,0)),i=0;for(let e=0;e<=n.lastSeq;e++){let t=n.parts.get(e);if(!t)return;r.set(t,i),i+=t.length}for(this.queue.push(r.buffer);this.queue.length>Nw;)this.queue.shift();this.pump()}stop(){this.gen++,this.queue=[],this.pending.clear(),this.busy=!1;let e=this.current;if(this.current=null,e){e.onended=null;try{e.stop()}catch{}}this.setPlaying(!1)}dispose(){this.stop(),this.ctx?.close().catch(()=>{}),this.ctx=null,this.analyser=null}playing(){return this.isPlaying}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}level(){if(!this.analyser||!this.isPlaying)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}ensureContext(){if(!this.ctx){let e=window.AudioContext??window.webkitAudioContext;this.ctx=new e,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.analyser.connect(this.ctx.destination)}return this.ctx}setPlaying(e){this.isPlaying!==e&&(this.isPlaying=e,this.listeners.forEach(t=>t(e)))}async pump(){if(this.busy)return;let e=this.queue.shift();if(!e){this.setPlaying(!1);return}this.busy=!0;let t=this.gen;try{let n=this.ensureContext();if(n.state!==`running`){try{await n.resume()}catch{}if(t!==this.gen)return;if(n.state!==`running`){this.queue.unshift(e),this.busy=!1;return}}let r=await n.decodeAudioData(e);if(t!==this.gen)return;let i=n.createBufferSource();i.buffer=r,i.connect(this.analyser),i.onended=()=>{this.current===i&&(this.current=null,this.busy=!1,this.pump())},this.current=i,this.setPlaying(!0),i.start()}catch{if(t!==this.gen)return;this.busy=!1,this.pump()}}},Lw=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`],Rw=3e3;function zw(e){let t=e;return t?.name===`NotAllowedError`||t?.name===`SecurityError`?Error(`Microphone permission was denied. Allow it in the browser to talk.`):t?.name===`NotFoundError`||t?.name===`OverconstrainedError`?Error(`No microphone was found.`):Error(t?.message||`Could not open the microphone.`)}var Bw=class e{opts;stream=null;rec=null;chunks=[];ctx=null;analyser=null;timer=null;starting=!1;leaveSession=null;constructor(e={}){this.opts=e}static supported(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof MediaRecorder<`u`}get active(){return this.rec!==null}async start(){if(!(this.rec||this.starting)){if(!e.supported())throw Error(`This browser cannot record audio here (use localhost or HTTPS).`);this.starting=!0;try{this.leaveSession=Aw();try{this.stream=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0}})}catch(e){throw this.leaveSession?.(),this.leaveSession=null,zw(e)}try{let e=Lw.find(e=>MediaRecorder.isTypeSupported(e));this.chunks=[];let t=new MediaRecorder(this.stream,e?{mimeType:e}:void 0);t.ondataavailable=e=>{e.data&&e.data.size>0&&this.chunks.push(e.data)},t.onerror=()=>this.failed();for(let e of this.stream.getTracks())e.onended=()=>this.failed();this.openMeter(this.stream),t.start(250),this.rec=t,this.opts.maxMs&&(this.timer=setTimeout(()=>{this.timer=null,this.opts.onLimit?.()},this.opts.maxMs))}catch(e){throw this.release(),zw(e)}}finally{this.starting=!1}}}stop(){let e=this.rec;return e?new Promise(t=>{let n=!1,r=null,i=()=>{if(n)return;n=!0,r&&clearTimeout(r);let i=new Blob(this.chunks,{type:e.mimeType||`audio/webm`});this.release(),t(i)};if(r=setTimeout(i,Rw),e.onstop=i,e.state===`inactive`)return i();try{e.stop()}catch{i()}}):Promise.reject(Error(`Not recording.`))}cancel(){let e=this.rec;if(e){e.ondataavailable=null,e.onstop=null,e.onerror=null;try{e.state!==`inactive`&&e.stop()}catch{}}this.release()}level(){if(!this.analyser||!this.rec)return 0;let e=new Uint8Array(this.analyser.fftSize);this.analyser.getByteTimeDomainData(e);let t=0;for(let n of e)t+=((n-128)/128)**2;return Math.min(1,Math.sqrt(t/e.length)*4)}failed(){this.rec&&(this.cancel(),this.opts.onError?.())}openMeter(e){try{this.ctx=new AudioContext,this.analyser=this.ctx.createAnalyser(),this.analyser.fftSize=1024,this.ctx.createMediaStreamSource(e).connect(this.analyser)}catch{this.analyser=null}}release(){this.timer&&clearTimeout(this.timer),this.timer=null,this.stream?.getTracks().forEach(e=>{e.onended=null,e.stop()}),this.ctx?.close().catch(()=>{}),this.stream=null,this.rec=null,this.ctx=null,this.analyser=null,this.chunks=[],this.leaveSession?.(),this.leaveSession=null}},Vw=2e3,Hw=()=>typeof window<`u`&&window.isSecureContext===!1,Uw=50,Ww=class{deps;recorder;player;mode=`idle`;pressed=!1;disposed=!1;uploads=0;toldAboutSound=!1;abort=null;poll=null;unsubscribe;constructor(e){this.deps=e;let t=()=>this.recorderFailed();this.recorder=e.recorder??e.makeRecorder?.(t)??new Bw({maxMs:6e4,onLimit:()=>void this.pressEnd(),onError:t}),this.player=e.player??new Iw,this.unsubscribe=this.player.onChange(e=>{this.mode!==`listening`&&this.mode!==`transcribing`&&this.setMode(e?`speaking`:`idle`)})}async pressStart(){if(!(this.pressed||this.disposed)){if(!this.deps.available()){this.alert(`warn`,`Voice is not available. Run: friend voice setup`);return}if(!(this.deps.supported?.()??Bw.supported())){this.alert(`warn`,Hw()?`This page is not secure, so the browser blocks the microphone. On the PC run: friend lan https on, restart Friend, and open the https:// address.`:`This browser cannot record audio here (use localhost or HTTPS).`);return}this.pressed=!0,this.player.unlock(),this.player.playing()&&(this.deps.send({type:`voice.interrupt`}),this.player.stop());try{await this.recorder.start()}catch(e){this.pressed=!1,this.alert(`error`,e.message),this.setMode(`idle`);return}if(!this.pressed){this.recorder.cancel(),this.setMode(`idle`);return}this.setMode(`listening`)}}async pressEnd(){if(!this.pressed||(this.pressed=!1,!this.recorder.active))return;let e=await this.recorder.stop();if(e.size<Vw){this.alert(`info`,`Hold the key a little longer while you speak.`),this.setMode(`idle`);return}this.setMode(`transcribing`);let t=new AbortController;this.abort=t,this.uploads++;try{let{text:n}=await this.deps.post(e,t.signal);n.trim()||this.alert(`info`,`I didn't catch that.`)}catch(e){e.name!==`AbortError`&&this.alert(`error`,e.message)}finally{this.uploads--,this.abort===t&&(this.abort=null),this.settle()}}blur(){this.pressed&&(this.pressed=!1,this.recorder.cancel(),this.setMode(`idle`))}handleServer(e){if(e.type!==`audio.chunk`)return this.player.stop();this.player.enqueue(e),!this.toldAboutSound&&this.player.locked?.()&&(this.toldAboutSound=!0,this.deps.dispatch({type:`alert.add`,level:`info`,text:`Sound is blocked by the browser. Click or press a key once anywhere on the page to hear me.`}))}unlock(){this.player.unlock()}dispose(){this.disposed=!0,this.pressed=!1,this.stopPolling(),this.abort?.abort(),this.recorder.cancel(),this.player.stop(),this.player.dispose?.(),this.unsubscribe()}recorderFailed(){this.pressed=!1,this.recorder.cancel(),this.alert(`error`,`The microphone stopped working.`),this.setMode(`idle`)}settle(){this.uploads>0||this.mode!==`transcribing`||this.setMode(this.player.playing()?`speaking`:`idle`)}setMode(e){this.disposed||(this.mode=e,this.deps.dispatch({type:`voice.mode`,mode:e}),e===`listening`||e===`speaking`?this.startPolling():this.stopPolling())}startPolling(){this.stopPolling(),this.poll=setInterval(()=>{let e=this.mode===`listening`?this.recorder.level():this.player.level();this.deps.dispatch({type:`voice.level`,level:e})},Uw)}stopPolling(){this.poll&&clearInterval(this.poll),this.poll=null}alert(e,t){this.disposed||this.deps.dispatch({type:`alert.add`,level:e,text:t})}};function Gw(e){let[t,n]=(0,l.useReducer)(gw,uw),r=(0,l.useRef)(null),i=(0,l.useRef)(null),a=(0,l.useRef)(null),o=(0,l.useRef)(e);o.current=e;let s=(0,l.useRef)(t);return s.current=t,(0,l.useEffect)(()=>{let e=lw();r.current=e;let t=new Ww({send:t=>e.send(t),dispatch:e=>n(e),post:Ew,available:()=>s.current.voice.available});i.current=t;let c=new ww({send:t=>e.send(t),dispatch:e=>n(e),enabled:()=>s.current.camera.enabled,upload:async(e,t)=>{let n=await fetch(`/api/camera/frame/${encodeURIComponent(e)}`,{method:`POST`,headers:{"content-type":`image/jpeg`},body:t});if(!n.ok)throw Error(`upload failed (${n.status})`)}});a.current=c;let l=e.onMessage(e=>{n(e);let r=e?.type,i=e?.id;(r===`camera.request`||r===`camera.cancel`)&&typeof i==`string`&&c.handle({type:r,id:i}),(r===`audio.chunk`||r===`audio.stop`)&&t.handleServer(e)}),u=e.onState(e=>{n({type:`conn`,value:e}),e===`unauthorized`&&o.current(),e===`elsewhere`&&(t.blur(),c.dispose())});return()=>{l(),u(),t.dispose(),c.dispose(),e.close(),i.current=null,a.current=null,r.current=null}},[]),(0,l.useEffect)(()=>{t.camera.enabled||a.current?.dispose()},[t.camera.enabled]),{state:t,send:(0,l.useCallback)(e=>r.current?.send(e),[]),dispatch:(0,l.useCallback)(e=>n(e),[]),voice:(0,l.useMemo)(()=>({pressStart:()=>void i.current?.pressStart(),pressEnd:()=>void i.current?.pressEnd(),blur:()=>i.current?.blur(),unlock:()=>i.current?.unlock()}),[]),useHere:(0,l.useCallback)(()=>r.current?.takeOver(),[])}}var Kw={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function qw(e,t){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||Kw[n.status]||`The request failed (${n.status}).`)}return await n.json()}var Jw=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),Yw={state:()=>qw(`/api/voice/enroll`,{}),sample:e=>qw(`/api/voice/enroll/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>qw(`/api/voice/enroll/finish`,Jw(`POST`,{pin:e})),cancel:async()=>{await qw(`/api/voice/enroll/cancel`,Jw(`POST`,{}))},remove:async e=>{await qw(`/api/voice/enroll`,Jw(`DELETE`,{pin:e}))}},Xw=[`Friend, good evening. It is a pleasant day to get things done.`,`Open my projects and show me what changed today.`,`My voice is my key, so please remember it well.`,`Check the weather and read me the latest headlines.`,`Always protect the boss, and never trust a stranger.`],Zw=15e3;function Qw({api:e=Yw,createRecorder:t=e=>new Bw(e),onClose:n,who:r}){let[i,a]=(0,l.useState)(null),[o,s]=(0,l.useState)(0),[c,u]=(0,l.useState)(null),[f,m]=(0,l.useState)(`record`),[h,g]=(0,l.useState)(!1),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[S,C]=(0,l.useState)(``),w=(0,l.useRef)(!0),T=(0,l.useRef)(null);(0,l.useEffect)(()=>(w.current=!0,e.state().then(e=>{w.current&&(a(e),s(e.samples))}).catch(e=>w.current&&b(e.message)),()=>{w.current=!1,T.current?.cancel(),T.current=null}),[e]);let E=(0,l.useCallback)(async()=>{let t=T.current;if(t){T.current=null,g(!1),v(!0);try{let n=await t.stop(),r=await e.sample(n);if(!w.current)return;s(r.count),u(r.note)}catch(e){w.current&&b(e.message)}finally{w.current&&v(!1)}}},[e]),D=async()=>{b(null),u(null);let e=t({maxMs:Zw,onLimit:()=>void E(),onError:()=>{T.current=null,w.current&&(g(!1),b(`The microphone stopped working. Try again.`))}});try{await e.start()}catch(e){w.current&&b(e.message);return}if(!w.current)return e.cancel();T.current=e,g(!0)},O=async e=>{b(null),v(!0);try{await e()}catch(e){w.current&&b(e.message)}finally{w.current&&(v(!1),C(``))}},k=async()=>{T.current?.cancel(),T.current=null,await e.cancel().catch(()=>{}),n()},A=i?.min??3,j=o%Xw.length,ee=o<Xw.length?`Phrase ${o+1} of ${Xw.length}`:`Extra recording (${o} so far)`;return(0,p.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Voice enrollment`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:r?`Teach Friend ${r}'s voice`:`Teach Friend your voice`})}),f===`record`&&(0,p.jsxs)(p.Fragment,{children:[!r&&i?.enrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`Your voice is already saved. Saving a new one replaces it.`}),r&&(0,p.jsxs)(`p`,{className:`auth-note`,children:[`Hand the device to `,r,`. `,r,` reads each sentence aloud, close to the microphone, in a quiet room.`]}),(0,p.jsxs)(`p`,{className:`auth-note`,children:[ee,`. Press Record, read this aloud in a quiet room, then press Stop.`]}),(0,p.jsx)(`pre`,{className:`approval-summary`,"data-testid":`enroll-phrase`,style:{whiteSpace:`pre-wrap`},children:Xw[j]}),(0,p.jsxs)(`div`,{role:`status`,className:`auth-note`,children:[o,` recorded`,o>=A?` — enough to save`:` — at least ${A} needed`,`.`,c?` ${c}`:``]}),y&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:y}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[h?(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,onClick:()=>void E(),children:`Stop`}):(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:_||!i||o>=(i?.max??8),onClick:()=>void D(),children:_?`Uploading…`:`Record`}),(0,p.jsx)(`button`,{type:`button`,style:d,disabled:h||_||o<A,onClick:()=>m(`pin-save`),children:r?`Save ${r}'s voice`:`Save my voice`}),!r&&i?.enrolled&&(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:h||_,onClick:()=>m(`pin-delete`),children:`Delete my voice`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>void k(),children:`Cancel`})]})]}),(f===`pin-save`||f===`pin-delete`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:f===`pin-save`?r?`Enter your PIN to save ${r}'s voice.`:`Enter your PIN to save your voice.`:`Enter your PIN to delete your saved voice.`}),(0,p.jsx)(x,{pin:S,onChange:C,onSubmit:f===`pin-save`?()=>!_&&void O(async()=>{await e.finish(S),w.current&&m(`saved`)}):void 0}),y&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:y}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[f===`pin-save`?(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:_||S.length<6,onClick:()=>void O(async()=>{await e.finish(S),w.current&&m(`saved`)}),children:`Save`}):(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:_||S.length<6,onClick:()=>void O(async()=>{await e.remove(S),w.current&&m(`deleted`)}),children:`Delete`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{C(``),b(null),m(`record`)},children:`Back`})]})]}),(f===`saved`||f===`deleted`)&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:f===`saved`?r?`${r}'s voice is saved. From now on I will know when ${r} is talking.`:`Your voice is saved. From now on I will tell you apart from other speakers.`:`Your voice was deleted. Every voice is treated as yours until you enroll again.`}),(0,p.jsx)(`div`,{className:`approval-actions`,children:(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,onClick:n,children:`Done`})})]})]})}var $w=new Set([`INPUT`,`TEXTAREA`,`SELECT`,`BUTTON`,`A`,`SUMMARY`]),eT=new Set([`button`,`checkbox`,`switch`,`tab`,`menuitem`,`link`,`radio`,`option`,`textbox`,`combobox`,`slider`]),tT=e=>e instanceof HTMLElement&&($w.has(e.tagName)||e.isContentEditable||eT.has(e.getAttribute(`role`)??``)),nT=e=>e.code===`Space`||e.key===` `;function rT(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>{let e=!1,n=n=>{!nT(n)||n.ctrlKey||n.metaKey||n.altKey||tT(n.target)||tT(document.activeElement)||(n.preventDefault(),!(n.repeat||e)&&(e=!0,t.current.pressStart()))},r=n=>{nT(n)&&e&&(e=!1,n.preventDefault(),t.current.pressEnd())},i=()=>{e=!1,t.current.blur()},a=()=>{document.hidden&&i()};return window.addEventListener(`keydown`,n),window.addEventListener(`keyup`,r),window.addEventListener(`blur`,i),document.addEventListener(`visibilitychange`,a),()=>{window.removeEventListener(`keydown`,n),window.removeEventListener(`keyup`,r),window.removeEventListener(`blur`,i),document.removeEventListener(`visibilitychange`,a)}},[])}function iT(e){let t=(0,l.useRef)(e);t.current=e,(0,l.useEffect)(()=>{let e=()=>t.current.unlock(),n=[`pointerdown`,`keydown`,`touchend`];for(let t of n)window.addEventListener(t,e,{passive:!0});return()=>{for(let t of n)window.removeEventListener(t,e)}},[])}function aT({onUseHere:e}){return(0,p.jsx)(`div`,{className:`elsewhere`,role:`alertdialog`,"aria-labelledby":`elsewhere-title`,"data-testid":`elsewhere`,children:(0,p.jsxs)(`div`,{className:`elsewhere-card`,children:[(0,p.jsx)(`h2`,{id:`elsewhere-title`,children:`Friend is open in another window`}),(0,p.jsx)(`p`,{children:`Friend works in one window at a time. Click “Use here” to use it in this window instead; the other one will stop.`}),(0,p.jsx)(`button`,{type:`button`,className:`elsewhere-btn`,onClick:e,autoFocus:!0,children:`Use here`})]})})}function oT(e,t,n){let r=Math.max(100,Math.round(e)),i=Math.max(100,Math.round(t));return{width:r,height:i,kind:r<=599?`phone`:n||r<1024?`tablet`:`desktop`,orientation:i>r?`portrait`:`landscape`,touch:n}}var sT=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches;function cT(){return oT(window.innerWidth,window.innerHeight,sT())}var lT=(e,t)=>!!e&&e.width===t.width&&e.height===t.height&&e.kind===t.kind&&e.orientation===t.orientation&&e.touch===t.touch;function uT(e,t){let n=(0,l.useRef)(null),r=(0,l.useRef)(e);r.current=e,(0,l.useEffect)(()=>{if(t!==`open`){n.current=null;return}let e=()=>{let e=cT();lT(n.current,e)||(n.current=e,r.current({type:`ui.screen`,...e}))};e();let i=null,a=()=>{i&&clearTimeout(i),i=setTimeout(e,400)};return window.addEventListener(`resize`,a),window.addEventListener(`orientationchange`,a),()=>{i&&clearTimeout(i),window.removeEventListener(`resize`,a),window.removeEventListener(`orientationchange`,a)}},[t])}var dT={401:`Please sign in again.`,403:`Incorrect PIN.`,413:`That recording was too long.`,429:`Too many attempts. Wait a moment.`,503:`Voice is not available. Run: friend voice setup`};async function fT(e,t={}){let n;try{n=await fetch(e,t)}catch{throw Error(`Could not reach Friend. Check the connection.`)}if(!n.ok){let e=``;try{e=(await n.json()).error??``}catch{}throw Error(e||dT[n.status]||`The request failed (${n.status}).`)}return await n.json()}var pT=(e,t)=>({method:e,headers:{"content-type":`application/json`},body:JSON.stringify(t)}),mT={overview:()=>fT(`/api/voice/people`),begin:e=>fT(`/api/voice/people/begin`,pT(`POST`,{name:e})),recording:{state:async()=>(await fT(`/api/voice/people`)).enrolling??{enrolled:!1,samples:0,min:3,max:8},sample:e=>fT(`/api/voice/people/sample`,{method:`POST`,headers:{"content-type":e.type||`audio/webm`},body:e}),finish:e=>fT(`/api/voice/people/finish`,pT(`POST`,{pin:e})),cancel:async()=>{await fT(`/api/voice/people/cancel`,pT(`POST`,{}))},remove:async()=>{}},removePerson:async(e,t)=>{await fT(`/api/voice/people/${e}`,pT(`DELETE`,{pin:t}))}};function hT({api:e=mT,createRecorder:t,onClose:n}){let[r,i]=(0,l.useState)(null),[a,o]=(0,l.useState)({kind:`list`}),[s,c]=(0,l.useState)(``),[u,f]=(0,l.useState)(``),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(null),v=(0,l.useRef)(!0),y=(0,l.useCallback)(()=>{e.overview().then(e=>v.current&&i(e)).catch(e=>v.current&&_(e.message))},[e]);(0,l.useEffect)(()=>(v.current=!0,y(),()=>{v.current=!1}),[y]);let b=async()=>{_(null),h(!0);try{let t=await e.begin(s.trim());v.current&&o({kind:`record`,name:t.name})}catch(e){v.current&&_(e.message)}finally{v.current&&h(!1)}},S=async t=>{_(null),h(!0);try{if(await e.removePerson(t.id,u),!v.current)return;o({kind:`list`}),y()}catch(e){v.current&&_(e.message)}finally{v.current&&(h(!1),f(``))}};return a.kind===`record`?(0,p.jsx)(Qw,{api:e.recording,who:a.name,...t?{createRecorder:t}:{},onClose:()=>{c(``),o({kind:`list`}),y()}}):(0,p.jsxs)(`div`,{className:`approval enroll glass`,role:`dialog`,"aria-label":`Family voices`,style:{pointerEvents:`auto`},children:[(0,p.jsx)(`div`,{className:`approval-head`,children:(0,p.jsx)(`span`,{className:`approval-title`,children:`Family voices`})}),a.kind===`list`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`p`,{className:`auth-note`,children:`Friend knows your voice. Add the people at home, so it knows who is talking and answers them by name. They can chat and ask for the weather, but cannot use your PC or see your private things.`}),r&&!r.ownerEnrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`First teach Friend your own voice (Esc, then Enroll my voice).`}),r&&r.people.length===0&&r.ownerEnrolled&&(0,p.jsx)(`p`,{className:`auth-note`,children:`Nobody added yet.`}),r&&r.people.length>0&&(0,p.jsx)(`ul`,{className:`household-list`,"aria-label":`People Friend knows`,children:r.people.map(e=>(0,p.jsxs)(`li`,{className:`household-row`,children:[(0,p.jsx)(`span`,{children:e.name}),(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,onClick:()=>o({kind:`remove`,person:e}),"aria-label":`Remove ${e.name}`,children:`Remove`})]},e.id))}),r&&r.ownerEnrolled&&r.people.length<r.max&&(0,p.jsxs)(`label`,{className:`settings-field`,children:[(0,p.jsx)(`span`,{children:`Add a person`}),(0,p.jsx)(`input`,{value:s,maxLength:40,placeholder:`Name, for example Priya`,onChange:e=>c(e.target.value),onKeyDown:e=>e.key===`Enter`&&s.trim()&&!m&&void b()})]}),g&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[r&&r.ownerEnrolled&&r.people.length<r.max&&(0,p.jsx)(`button`,{type:`button`,style:d,className:`primary`,disabled:m||!s.trim(),onClick:()=>void b(),children:`Record their voice`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:n,children:`Close`})]})]}),a.kind===`remove`&&(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`p`,{className:`auth-note`,children:[`Enter your PIN to remove `,a.person.name,`’s voice. Friend will treat their voice as a stranger’s.`]}),(0,p.jsx)(x,{pin:u,onChange:f}),g&&(0,p.jsx)(`p`,{role:`alert`,className:`auth-error`,children:g}),(0,p.jsxs)(`div`,{className:`approval-actions`,children:[(0,p.jsx)(`button`,{type:`button`,style:d,className:`danger`,disabled:m||u.length<6,onClick:()=>void S(a.person),children:`Remove`}),(0,p.jsx)(`button`,{type:`button`,style:d,onClick:()=>{f(``),_(null),o({kind:`list`})},children:`Back`})]})]})]})}function gT({onSignedOut:e}){let{state:t,send:n,dispatch:r,voice:i,useHere:a}=Gw(e);rT(i),iT(i),uT(n,t.connection);let[o,s]=(0,l.useState)(!1),[c,u]=(0,l.useState)(!1),[d,f]=(0,l.useState)(!1),[m,h]=(0,l.useState)(!1),[g,_]=(0,l.useState)(null),[v,y]=(0,l.useState)(!1),[b,x]=(0,l.useState)(0),[S,C]=(0,l.useState)(null),w=de(t.view),T=(0,l.useMemo)(()=>o?{...t,objects:[],captions:``}:t,[o,t]),E=(0,l.useRef)(!1);(0,l.useEffect)(()=>{E.current||!t.voice.available||t.voice.enrolled||(E.current=!0,r({type:`alert.add`,level:`info`,text:`Voice recognition is not set up. Press Esc, then Enroll my voice.`}))},[t.voice.available,t.voice.enrolled,r]);let D=ne(),O=(0,l.useRef)(!1);(0,l.useEffect)(()=>{if(!D||O.current||t.connection!==`open`)return;O.current=!0;let e=!1;try{e=localStorage.getItem(`friend.touchHint`)===`1`,localStorage.setItem(`friend.touchHint`,`1`)}catch{}e||r({type:`alert.add`,level:`info`,text:`Hold the round mic button to talk, or tap it once to start and again to send. The keyboard button types; the menu button opens settings.`})},[D,t.connection,r]);let k=(0,l.useRef)(!1);(0,l.useEffect)(()=>{k.current||t.connection!==`open`||(k.current=!0,fetch(`/api/history`).then(e=>e.ok?e.json():[]).then(e=>r({type:`chat.seed`,lines:e})).catch(()=>{}))},[t.connection,r]),(0,l.useEffect)(()=>{t.connection===`open`&&n({type:`ui.panels`,open:[...w.show.chat?[`chat`]:[],...w.show.tasks?[`tasks`]:[]]})},[t.connection,w.show.chat,w.show.tasks,n]);let j=(0,l.useRef)(!1);(0,l.useEffect)(()=>{t.viewKnown&&t.view===`minimal`&&!j.current&&(j.current=!0,r({type:`alert.add`,level:`info`,text:`The view is Minimal, so the status line and clock are hidden. Press Esc, then View, to bring them back.`}))},[t.viewKnown,t.view,r]);let ee=e=>{Ie.save({view:e}).catch(e=>r({type:`alert.add`,level:`warn`,text:e.message}))},M=(0,l.useMemo)(()=>F({notify:e=>r({type:`alert.add`,level:`info`,text:e}),openSettings:()=>_(`model`),openLook:()=>_(`look`),openConnectors:()=>y(!0),openPlugins:()=>h(!0),openVoice:t.voice.available?()=>u(!0):null,muted:o,setMuted:s,cameraOn:t.camera.enabled,setCamera:e=>r({type:`camera.enable`,value:e}),clearScreen:()=>{for(let e of t.objects)n({type:`stage.event`,objectId:e.id,event:`dismiss`})},statusLine:()=>Ce({connection:t.connection,deviceOnline:t.deviceOnline,approval:t.approval,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity}).text,endSession:t=>{fetch(t===`lock`?`/api/lock`:`/api/logout`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).catch(()=>{}).finally(e)},panelOn:e=>w.show[e],setPanel:(e,t)=>w.toggle(e,t),view:t.view,setView:ee,openHelp:C,resetLayout:()=>{ue(),window.location.reload()}}),[r,n,o,e,w.show,w.toggle,t.view,t.voice.available,t.voice.mode,t.camera.enabled,t.objects,t.connection,t.deviceOnline,t.approval,t.busy,t.activity]);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(ow,{state:T,send:n,dispatch:r,voice:i,slash:M,onMenu:()=>x(e=>e+1)}),(0,p.jsxs)(Ee,{approval:t.approval,challenge:t.challenge,cameraStream:t.camera.stream,alerts:t.alerts,connection:t.connection,deviceOnline:t.deviceOnline,voiceMode:t.voice.mode,busy:t.busy,activity:t.activity,showStatus:t.viewKnown&&w.show.status,showClock:t.viewKnown&&w.show.clock,profile:t.viewKnown&&w.show.profile?{ownerName:t.ownerName,speaker:t.speaker}:null,send:n,dispatch:r,children:[t.viewKnown&&w.show.chat&&(0,p.jsx)(fe,{lines:t.chat,live:t.chatLive,onSend:e=>n({type:`chat.send`,text:e}),onClose:()=>w.toggle(`chat`,!1)}),t.viewKnown&&w.show.tasks&&(0,p.jsx)(he,{busy:t.busy,onClose:()=>w.toggle(`tasks`,!1)}),c&&(0,p.jsx)(Qw,{onClose:()=>u(!1)}),d&&(0,p.jsx)(hT,{onClose:()=>f(!1)}),m&&(0,p.jsx)(je,{onClose:()=>h(!1)}),g&&(0,p.jsx)(Ay,{initialTab:g,onClose:()=>_(null)}),v&&(0,p.jsx)(A,{onClose:()=>y(!1)}),S&&(0,p.jsx)(I,{commands:S,onClose:()=>C(null)})]}),(0,p.jsx)(V,{muted:o,onToggleMute:()=>s(e=>!e),onSignedOut:e,voiceAvailable:t.voice.available,voiceEnrolled:t.voice.enrolled,onEnroll:()=>u(!0),onHousehold:()=>f(!0),onPlugins:()=>h(!0),onSettings:()=>_(`model`),onConnectors:()=>y(!0),cameraOn:t.camera.enabled,onToggleCamera:()=>r({type:`camera.enable`,value:!t.camera.enabled}),chatOn:w.show.chat,onToggleChat:()=>w.toggle(`chat`),tasksOn:w.show.tasks,onToggleTasks:()=>w.toggle(`tasks`),view:t.view,onView:ee,openRequest:b}),t.connection===`elsewhere`&&(0,p.jsx)(aT,{onUseHere:a})]})}function _T(){let[e,t]=(0,l.useState)(`loading`);return(0,l.useEffect)(()=>{let e=!0,n=n=>e&&t(n);return(async()=>{try{if(!(await(await fetch(`/api/state`)).json()).hasOwner)return n(`setup`);let e=await(await fetch(`/api/session`,{cache:`no-store`})).json();n(e.signedIn===!0?`stage`:`login`)}catch{n(`login`)}})(),()=>{e=!1}},[]),e===`loading`?(0,p.jsx)(`div`,{className:`boot`,"aria-busy":`true`}):e===`setup`?(0,p.jsx)(g,{onDone:()=>t(`login`)}):e===`login`?(0,p.jsx)(h,{onLoggedIn:()=>t(`stage`)}):(0,p.jsx)(gT,{onSignedOut:()=>t(`login`)})}(0,u.createRoot)(document.getElementById(`root`)).render((0,p.jsx)(l.StrictMode,{children:(0,p.jsx)(_T,{})}));
@@ -8,7 +8,7 @@
8
8
  <meta name="apple-mobile-web-app-capable" content="yes" />
9
9
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
10
10
  <title>Friend</title>
11
- <script type="module" crossorigin src="/assets/index-T-Oeqprz.js"></script>
11
+ <script type="module" crossorigin src="/assets/index-D-IsArMn.js"></script>
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-Dvv5DXnC.css">
13
13
  </head>
14
14
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "friend-assistant",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "A self-hosted personal AI assistant for your own PC: a full-screen stage, voice, tools with your approval, and your Claude subscription or a local model.",
5
5
  "keywords": ["ai", "assistant", "jarvis", "voice", "claude", "ollama", "mcp", "self-hosted"],
6
6
  "license": "UNLICENSED",