@theoremjs/studio 0.3.4-next.522.g9e684cd → 0.3.4-next.526.g51bc66f

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{Banner-UZW6WFTG.js → Banner-DcgTcVVW.js} +2 -2
  3. package/page/assets/{ConsoleFrame-C6ZxuLse.js → ConsoleFrame-Dep1lvnm.js} +1 -1
  4. package/page/assets/{ContextMenu-ClIUDzvK.js → ContextMenu-NgzKbTao.js} +2 -2
  5. package/page/assets/{ToolResultCharts-COgqvWEu.js → ToolResultCharts-CFvHRt5v.js} +1 -1
  6. package/page/assets/{TraceInspector-D2unePaa.js → TraceInspector-D92rKzc_.js} +1 -1
  7. package/page/assets/{TraceOverview-CCA1iUNg.js → TraceOverview-m12m2XgM.js} +1 -1
  8. package/page/assets/{_virtual_studio-type-sources-DfyVGpe8.js → _virtual_studio-type-sources-DVbxNwnP.js} +26 -4
  9. package/page/assets/browser-engine-DL-WovTC.js +11 -0
  10. package/page/assets/{browser-transport-CgmN-3Ia.js → browser-transport-CmAIXFia.js} +4 -4
  11. package/page/assets/{crypto-BoqeX_71.js → crypto-BAY2nUlu.js} +1 -1
  12. package/page/assets/{encode-files-DFrbgXms.js → encode-files-BSTfq_Gp.js} +1 -1
  13. package/page/assets/{export-agent-U8qRBuhg.js → export-agent-C8_6CZgy.js} +1 -1
  14. package/page/assets/{guardrail-tester-DASanQyo.js → guardrail-tester-Dk5L25mc.js} +1 -1
  15. package/page/assets/{index-CGN6iWF2.js → index-B95kGH1Q.js} +9 -9
  16. package/page/assets/{live-messages-cl-CI8gZ.js → live-messages-DIf_R-NT.js} +1 -1
  17. package/page/assets/{reader-IkImpzZF.js → reader-BkaAkeh0.js} +5 -5
  18. package/page/assets/{shaped-data-CITXsEfw.js → shaped-data-C4jsvipW.js} +12 -13
  19. package/page/assets/{stub-Ccyi1ZiM.js → stub-4m0tKRlG.js} +1 -1
  20. package/page/assets/{studio-code-pane-AoMu0cGy.js → studio-code-pane-CPyzXehM.js} +3 -3
  21. package/page/assets/{studio-console-JNYkyQ0E.js → studio-console-BV4NlQY-.js} +1 -1
  22. package/page/assets/{studio-decision-BRJuvgS3.js → studio-decision-BT6Ee-kK.js} +1 -1
  23. package/page/assets/{studio-embedding-D-r2kuz3.js → studio-embedding-DVduw2Un.js} +1 -1
  24. package/page/assets/{studio-host-console-HoLSpRVk.js → studio-host-console-CngXS38i.js} +2 -2
  25. package/page/assets/{studio-labels-CBcjlfH4.js → studio-labels--uHJcIbG.js} +1 -1
  26. package/page/assets/{studio-live-DtywUIK2.js → studio-live-DTHgPVFH.js} +2 -2
  27. package/page/assets/{studio-map-BIJ-S7br.js → studio-map-CT0jsRMr.js} +1 -1
  28. package/page/assets/{studio-trace-replay-BuOKQwlj.js → studio-trace-replay-DS9o-VrA.js} +1 -1
  29. package/page/assets/{studio-type-checker-C8qG2W9D.js → studio-type-checker-CHFs7A7H.js} +1 -1
  30. package/page/assets/tool-schema-DpbtSZtQ.js +17 -0
  31. package/page/assets/{trace-record-Dqvj9bhx.js → trace-record-D9wgX8kq.js} +1 -1
  32. package/page/assets/{tree-jmLWUWxQ.js → tree-0OoOeHfS.js} +1 -1
  33. package/page/assets/{turn-client-DSatougR.js → turn-client-BWO4ocVM.js} +1 -1
  34. package/page/assets/types-BRZU5tBz.js +1 -0
  35. package/page/assets/{use-one-call-BcTU9gJ9.js → use-one-call-DOzbF9kQ.js} +1 -1
  36. package/page/assets/{workspace-B2bnm5qv.js → workspace-DJBP4Adw.js} +1 -1
  37. package/page/index.html +15 -15
  38. package/page/assets/browser-engine-CRGnAh9x.js +0 -11
  39. package/page/assets/tool-schema-DDkOMTMz.js +0 -17
  40. package/page/assets/types-4jMDDudJ.js +0 -1
@@ -1 +1 @@
1
- import{E as e,g as t,l as n,o as r,p as i,v as a,w as o,x as s,y as c}from"./schemas-BQ9Jydzb.js";import{An as l,Bn as u,Cr as d,Ln as f}from"./tool-schema-DDkOMTMz.js";import{A as p,C as m,j as h}from"./reader-IkImpzZF.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{C as _}from"./turn-client-DSatougR.js";var v=c({type:t(`open`),history:n(u).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:d,awayMs:a().nonnegative()}).optional(),host:s(o(),e()).optional()}),y=i(`type`,[c({type:t(`audio`),data:o()}),c({type:t(`video`),data:o(),mimeType:o()}),c({type:t(`text`),text:o()}),c({type:t(`context`),context:e()}),c({type:t(`executeTool`),callId:o().min(1),operationId:o().min(1).max(256),decision:r(_).optional(),input:e().optional(),secret:o().optional(),output:e().optional(),grantId:o().min(1).optional(),unanswered:t(!0).optional()})]),b={ready:c({type:t(`ready`),profile:o().optional(),sessionId:o().optional()}),events:c({type:t(`events`),events:n(e())}),trace:c({type:t(`trace`),record:g}),error:c({type:t(`error`)}).and(m),executeToolResult:i(`status`,[c({type:t(`executeToolResult`),callId:o().min(1),operationId:o().min(1).max(256),status:t(`dispatched`),grantId:o().min(1),arguments:s(o(),e())}),c({type:t(`executeToolResult`),callId:o(),status:t(`settled`),operationId:o().min(1).max(256)}),c({type:t(`executeToolResult`),callId:o(),status:t(`gated`),operationId:o().min(1).max(256),gate:f}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=p(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>h(l,e))}:t}export{v as n,x as r,y as t};
1
+ import{E as e,g as t,l as n,o as r,p as i,v as a,w as o,x as s,y as c}from"./schemas-BQ9Jydzb.js";import{An as l,Bn as u,Cr as d,Ln as f}from"./tool-schema-DpbtSZtQ.js";import{A as p,C as m,j as h}from"./reader-BkaAkeh0.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{C as _}from"./turn-client-BWO4ocVM.js";var v=c({type:t(`open`),history:n(u).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:d,awayMs:a().nonnegative()}).optional(),host:s(o(),e()).optional()}),y=i(`type`,[c({type:t(`audio`),data:o()}),c({type:t(`video`),data:o(),mimeType:o()}),c({type:t(`text`),text:o()}),c({type:t(`context`),context:e()}),c({type:t(`executeTool`),callId:o().min(1),operationId:o().min(1).max(256),decision:r(_).optional(),input:e().optional(),secret:o().optional(),output:e().optional(),grantId:o().min(1).optional(),unanswered:t(!0).optional()})]),b={ready:c({type:t(`ready`),profile:o().optional(),sessionId:o().optional()}),events:c({type:t(`events`),events:n(e())}),trace:c({type:t(`trace`),record:g}),error:c({type:t(`error`)}).and(m),executeToolResult:i(`status`,[c({type:t(`executeToolResult`),callId:o().min(1),operationId:o().min(1).max(256),status:t(`dispatched`),grantId:o().min(1),arguments:s(o(),e())}),c({type:t(`executeToolResult`),callId:o(),status:t(`settled`),operationId:o().min(1).max(256)}),c({type:t(`executeToolResult`),callId:o(),status:t(`gated`),operationId:o().min(1).max(256),gate:f}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=p(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>h(l,e))}:t}export{v as n,x as r,y as t};
@@ -1,7 +1,7 @@
1
- import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,E as n,O as r,T as i,b as a,d as o,f as s,g as c,l,m as u,o as d,p as f,s as p,u as m,v as h,w as g,x as _,y as v}from"./schemas-BQ9Jydzb.js";import{$n as y,$t as b,An as x,Bn as S,Bt as ee,Dr as te,Fn as C,G as w,Gn as T,Hn as E,In as D,Jt as O,Kn as k,Mn as ne,Mr as re,Or as ie,Pn as ae,Qn as oe,Qt as se,Rt as ce,Ut as le,Wn as ue,Xn as de,Zn as fe,ar as pe,br as me,dn as A,fn as he,gn as ge,hn as _e,ir as ve,jn as ye,kr as be,lr as xe,mn as Se,nr as Ce,or as we,pn as j,pr as Te,qn as Ee,qt as De,rr as Oe,s as ke,tn as Ae,tr as je,un as Me,vr as Ne,vt as Pe,wr as Fe,yr as Ie,zn as Le}from"./tool-schema-DDkOMTMz.js";import{c as M}from"./host-patterns-cSf1U25G.js";import{$t as Re,A as ze,An as Be,B as Ve,Bn as He,Bt as Ue,En as We,Et as Ge,F as Ke,Fn as qe,Gt as Je,Hn as N,Ht as Ye,I as Xe,In as Ze,It as Qe,Jt as $e,Kt as et,L as tt,Ln as nt,Lt as rt,M as it,Mt as at,N as ot,Nn as st,On as ct,P as lt,Pt as ut,Q as dt,Rn as ft,Rt as pt,Sn as mt,St as ht,Un as gt,Ut as _t,Vt as vt,W as yt,Wt as bt,X as xt,bt as St,et as Ct,ft as wt,gn as Tt,hn as Et,in as Dt,it as Ot,jn as kt,jt as At,k as jt,mn as Mt,mt as P,nt as Nt,pn as Pt,rn as Ft,rt as It,tt as Lt,ut as Rt,wn as zt,wt as Bt,xn as Vt,zt as Ht}from"./shaped-data-CITXsEfw.js";import{a as Ut,n as Wt}from"./live-ingress-qi-y5uvH.js";import{n as Gt,t as Kt}from"./trace-schema-9CdEyG6Q.js";import{n as qt}from"./stub-Ccyi1ZiM.js";function Jt(e){return{type:`guardrail`,guardrail:e}}function Yt(e,t,n,r=`redact`,i){if(n.length!==0)return Jt({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Xt(e,t){return e.type===`guardrail`?{...e,guardrail:Tt(e.guardrail,t)}:e}var Zt=65536;function F(e){let t=e.classStarts.length,n=new Uint16Array(Zt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Zt);let r=e.charsets.map(e=>{let n=new Uint8Array(t);for(let t of e)n[t]=1;return n}),i=e.nodes.length,a=new Int32Array(i),o=new Uint8Array(i),s=[];return e.nodes.forEach((e,t)=>{a[t]=e[0],o[t]=e[1],s.push(Int32Array.from(e.slice(2)))}),{classOf:n,has:r,pattern:a,final:o,edges:s,initials:e.initials,leads:e.leads,size:i}}var Qt,I,$t;async function en(){if(Qt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);Qt={forward:t,reversed:n}}function tn(){if(!Qt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return Qt}var L;function nn(e){let t=String.fromCharCode(e).toUpperCase();if(t.length!==1)return e;let n=t.charCodeAt(0);return e>=128&&n<128?e:n}function rn(e){if(!L){L=new Map;for(let e=0;e<Zt;e++){let t=nn(e),n=L.get(t);n?n.push(e):L.set(t,[e])}}return L.get(nn(e))??[e]}function an(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Zt&&t.push(n+1);return t}var on=new Map;function sn(e){let t=on.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>rn(e.charCodeAt(n))),r=an([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=F({classStarts:r,charsets:n.map(e=>e.map(i)),initials:[0],leads:[-1],nodes:[...n.map((e,t)=>[0,0,t+1,t]),[0,1]]});return on.set(e,a),a}function cn(e){let t=JSON.stringify(e),n=on.get(t);if(n)return n;let r=[...new Set(e.flatMap(e=>Array.from(e,e=>e.charCodeAt(0))))];r.sort((e,t)=>e-t);let i=an(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=F({classStarts:i,charsets:a,initials:e.map((e,t)=>{let n=o.length;for(let n=0;n<e.length;n++)o.push([t,0,o.length+1,r.indexOf(e.charCodeAt(n))]);return o.push([t,1]),n}),leads:e.map(()=>-1),nodes:o});return on.set(t,s),s}function ln(e,t){let n=e.has[0]?.length??0,r=Array.from({length:n},()=>[]);for(let i of t){let t=e.edges[e.initials[i]];for(let i=0;i<t.length;i+=2){let a=e.has[t[i+1]];for(let e=0;e<n;e++)a[e]&&r[e]?.push(t[i])}}return r.map(e=>Int32Array.from(e))}function un(e,t){e.text+=t,e.fresh+=t}function dn(e){return e.text.length-e.fresh.length}function R(e,t){let n=dn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function fn(e,t,n=e.text.length){let r=dn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function pn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function mn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,un(n,t(fn(e,n.text.length)))}};return n}var hn=/\w/,gn=Math.max(...pt.map(e=>e.length));function _n(e){return e.length<=gn+1&&/^[A-Za-z]*$/.test(e)}function vn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{un(o,e);for(let r=0;r<e.length;r++)i.push(t+Math.min(r,n-1))},o={text:``,fresh:``,rawAt:r=>e.rawAt(r<i.length?i[r]:t-(n?.length??0)),update(){o.fresh=``;for(let i=e.text.length;t<i;t++){let i=String.fromCharCode(R(e,t)),o=hn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Ye(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!_n(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function yn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function z(e,t,n){un(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var bn=55296,xn=56319,Sn=/[A-Za-z]/,Cn=56320,wn=57343;function Tn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=yn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(Sn.test(e)||z(c,`\\`,s),s=-1),e===`\\`?s=t:z(c,e,t)}function u(e,t){if(_t(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!Sn.test(e))for(let e=0;e<i.length;e++)l(i[e],a[e]);i=``,a=[]}for(let n=0;n<e.length;n++)l(e[n],t);o=Sn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=bn&&t<=xn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=Cn&&a<=wn?2:1;u(n.slice(e,e+o),r[e]),e+=o}n=n.slice(e),r=r.slice(e)}return c.update=()=>{c.fresh=``;let i=e.text.length;for(;t<i;){let a=R(e,t),o=a>=bn&&a<=xn;if(o&&t+1>=i)break;let s=R(e,t+1),c=o&&s>=Cn&&s<=wn?2:1,l=bt(fn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var En=/[0-9A-Fa-f]/;function Dn(e){let t=0,n=-1,r=yn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(R(e,t));if(n<0){a===`%`?n=t:(z(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:En.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)z(r,String.fromCharCode(R(e,n)),n)}}};function i(t){t>n&&z(r,Ht(fn(e,n,t)),n),n=-1}return r}var On=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),kn=new Map(rt.map(({pattern:e,hit:t})=>[e,t])),An=new Map(Lt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function B(e){return{rule:Vt(e),severity:`high`,detector:e}}var jn=B(`injection`),Mn=B(`marker_leak`),Nn=B(`tool_leak`);function Pn({kind:e,group:t}){if(On.has(e))return jn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:B(t);case`boundary`:return Mn;case`image`:return B(`ungiven_images`);default:return B(`ungiven_links`)}}function Fn(e,t,n){if(e===`card`)return{hit:Nt};if(e===`image`||e===`link`){let r=(e===`image`?It:Ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=kn.get(t)??An.get(t);return r?{hit:r}:{}}function In(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Rt(i(n?.ungiven_images)),link:wt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return dt.forEach((t,n)=>{let r=Pn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:et(t.pattern),...Fn(t.kind,t.pattern,a)})}),o}function Ln(){let e=[];return dt.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=kn.get(n);e.push({...jn,id:r,regex:et(n),...i?{hit:i}:{}})}),e}function Rn(){return Je.map((e,t)=>({...jn,id:t,regex:new RegExp(e.source,e.flags)}))}function zn(e,t,n){let r=ln(t,n.map(e=>e.id)),i=new Int32Array(t.initials.length).fill(-1);n.forEach((e,t)=>{i[e.id]=t});let a=new Int32Array(t.size),o=new Int32Array(t.size),s=new Int32Array(t.size),c=new Int32Array(t.size),l=0,u=new Int32Array(t.size),d=new Int32Array(t.size),f=0,p=0,m=new Uint8Array(n.length),h=new Uint8Array(n.length),g=new Int32Array(n.length),_=new Int32Array(n.length),v=new Uint8Array(n.length),y=Uint8Array.from(n,e=>+!!e.find),b=new Int32Array(n.length).fill(-1),x=new Int32Array(n.length).fill(-1),S=Int32Array.from(n,e=>t.leads[e.id]??-1),ee=[...new Set(S)].filter(e=>e>=0),te=n.flatMap((e,t)=>S[t]<0?[]:[t]),C=new Int32Array(t.has.length).fill(-1);function w(){let{text:n,fresh:h}=e,g=dn(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function k(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function ne(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):k(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=ne();e;e=ne())t.push(e);return e.rawAt(n)}}}var Bn=new WeakMap;function Vn(e){let t=Bn.get(e);return t||(t=F(e),Bn.set(e,t)),t}function Hn(e={}){let t={text:``,fresh:``},n=pn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),zn(e,t,n)),a=[],o=e.detect??[],s=In(o,e);if(s.length>0&&(I??=F(tn().forward),a.push(i(n,I,s))),o.includes(`injection`)){I??=F(tn().forward),$t??=F(tn().reversed);let e=Tn(t),r=Ln();a.push(i(n,$t,Rn()),i(vn(n),I,r),i(e,I,r),i(vn(e),I,r),i(mn(n,vt),I,r),i(mn(n,e=>Ue(e)??e),I,r),i(Dn(t),I,r))}if(o.includes(`marker_leak`)&&e.note){let t=Ct(e.note);a.push(i(n,sn(e.note),[{...Mn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=yt(e.tools),r=t.map(({regex:e},t)=>({...Nn,id:t,regex:e}));t.length>0&&a.push(i(n,cn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...B(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Vn(r.automaton),e))}let c=0;return{push(e){t.text+=e,t.fresh=e;for(let e of r)e.update();let n=[],i=t.text.length;for(let e of a)i=Math.min(i,e.run(n));return c=i,n},holdFrom:()=>c}}function Un(e,t,n={},r=[]){let i=Ke(e,t).filter(e=>!(tt(e)||r.includes(e))),a=Xe(e,t);if(i.length===0&&a.length===0)return;let o=[...i,...a.map(({id:e})=>e)],s=t.sources??{},c=[...i.map(e=>({detector:e,...s[e]})),...a.map(({id:e,matchers:t,compiled:n})=>({detector:e,matchers:t,compiled:n}))],l=c.some(({matchers:e,compiled:t})=>e?.length&&!t),u=Hn({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=lt(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Wn(e){let{context:t}=e,n=e.detect,r=n?Un(n.boundary,n.matrix,n.scope):void 0,i=e=>n?n.matrix[e][n.boundary]:`block`,a=i(`canary_leak`),o=i(`prompt_leak`),s=t.canaryGiven||a===`ignore`?void 0:t.canary,c=o===`ignore`?void 0:t.privateSystem,l=s!==void 0||c!==void 0,u=l?e.carry??``:``,d=[],f=new Set,p=``,m=0,h=``,g=u.slice(-P),_=u,v=0,y=u,b=0,x=0,S=s?ht(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,Et]),c){let r=_.length;_+=e;let i=Qe(_,r);_=_.slice(i),v+=i;let[a]=xt(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?T(s):h.length,n=c&&o!==`flag`?E(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function T(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-P),i=r+St(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+St(y,e)),x=Math.min(i,u.length+p.length-P);let a=Math.max(b,Math.max(t,x)-P);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function E(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+ut(i,e,t)-u.length-m)}function D(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:O(o)});let s=r.take(m,m+o,i);return s.action===`block`||s.action===`redact`&&!n.rewrite?{blocked:!0,hits:s.hits,boundary:n.boundary}:(O(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function O(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-P)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),D(e)):{blocked:!1,emit:``}},flush:()=>D(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?Ge(u+p,s,c):``}}function V(e,t,n){return ot(t,e.detect,n)}async function Gn(e,t,n,r){return V(e,[n],t)?(await en(),Kn(e,t,n,r)):null}function Kn(e,t,n,r){return V(e,[n],t)?Wn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Ve(e,t)},...r?{carry:r}:{}}):null}async function qn(e,t,n,r){return V(e,[n],r??t)?(await en(),Wn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Ve(e,t)}})):null}var Jn=class{open;gate;constructor(e){this.open=e}async read(e){if(this.gate===void 0&&(this.gate=await this.open()),this.gate===`stopped`)return``;if(!this.gate)return e;let t=this.gate.process(e);return t.blocked?(this.gate=`stopped`,``):t.emit}end(){if(!this.gate||this.gate===`stopped`)return``;let e=this.gate.flush();return e.blocked?``:e.emit}},Yn=2,Xn=4,Zn=3,Qn=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,$n=/^[A-Za-z0-9+/]*={0,2}$/,er=new Set([`text/csv`,`text/plain`,`text/markdown`]);function tr(e){let{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}=e;if(t&&n&&r)return{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}}function nr(e,t){if(t.limitsByMime){let n=_e(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function rr(e){return`uri`in e}function ir(e){if(e.type===`speech`)throw new M(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new M(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new M(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=tr(e.inputs??{});if(!t)throw new M(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function ar(e){let t=0;return e.endsWith(`==`)?t=Yn:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Zn/Xn)-t}function or(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function sr(e){return e.replace(Qn,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function cr(e,t,n){let r=or(t);return e===`text/csv`&&(r=sr(r)),new TextEncoder().encode(n.read(r))}function lr(e,t){return t?{...e,fileName:t}:e}function ur(e,t,n){return t.filter(t=>!A(e,t.mimeType)).map(e=>lr({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function dr(e,t){let n=[];e.length>t.maxFiles&&n.push({code:`too_many_files`,params:{maxFiles:t.maxFiles}});let r=0;for(let i of e){if(i.sizeBytes===void 0)continue;let e=nr(i.mimeType,t);i.sizeBytes>e&&n.push(lr({code:`file_too_large`,params:{maxBytes:e}},i.name)),r+=i.sizeBytes}return r>t.maxTurnBytes&&n.push({code:`turn_too_large`,params:{maxTurnBytes:t.maxTurnBytes}}),n}function fr(e,t,n){let r=[];return t.length>0&&!e.attachments&&r.push({code:`attachments_not_accepted`,params:{channel:`attachment`}}),n.length>0&&!e.voice&&r.push({code:`voice_not_accepted`,params:{channel:`voice`}}),r.length>0||t.length===0&&n.length===0?r:(e.attachments&&r.push(...ur(e.attachments,t,`attachment`)),e.voice&&r.push(...ur(e.voice,n,`voice`)),e.limits?[...r,...dr([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var pr={mime_not_allowed:`attachments.mime_not_allowed`,too_many_files:`attachments.too_many_files`,too_many_of_kind:`attachments.too_many_of_kind`,file_too_large:`attachments.file_too_large`,turn_too_large:`attachments.turn_too_large`,attachments_not_accepted:`attachments.not_accepted`,voice_not_accepted:`attachments.not_accepted`,limits_unconfigured:`attachments.limits_unconfigured`};function mr(e){let t={};for(let[n,r]of Object.entries(e.params??{}))r!==void 0&&(t[n]=r);return e.fileName!==void 0&&(t.fileName=e.fileName),{key:pr[e.code],params:t}}function hr(e,t){let n=mr(e);return N(n.key,n.params,t)}function gr(e){return new M(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(mr)})}function _r(e){if(!$n.test(e))throw new M(`request`,`attachment data must be base64`);return ar(e)}function vr(e){let t={mimeType:e.mimeType,name:e.name};return rr(e)||(t.sizeBytes=_r(e.data)),t}function yr(e,t,n){if(!xr(t,n))return;let r=ir(e),i=fr({attachments:he(e,`attachments`),voice:he(e,`voice`),limits:r},(t??[]).map(vr),(n??[]).map(vr));if(i.length>0)throw gr(i)}function br(e,t){if(rr(e))return e;let{mimeType:n,data:r}=e;if(!er.has(_e(n)))return e;let i=cr(n,Pt(r),t);return{...e,data:Mt(i)}}function xr(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Sr(e,t,n,r){return yr(e,t,n),{attachments:t?.length?t.map(e=>br(e,r.attachment)):t,voice:n?.length?n.map(e=>br(e,r.voice)):n}}var Cr=`
1
+ import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,E as n,O as r,T as i,b as a,d as o,f as s,g as c,l,m as u,o as d,p as f,s as p,u as m,v as h,w as g,x as _,y as v}from"./schemas-BQ9Jydzb.js";import{$n as y,$t as b,An as x,Bn as S,Bt as ee,Dr as te,Fn as C,G as w,Gn as T,Hn as E,In as D,Jt as O,Kn as k,Mn as ne,Mr as re,Or as ie,Pn as ae,Qn as oe,Qt as se,Rt as ce,Ut as le,Wn as ue,Xn as de,Zn as fe,ar as pe,br as me,dn as A,fn as he,gn as ge,hn as _e,ir as ve,jn as ye,kr as be,lr as xe,mn as Se,nr as Ce,or as we,pn as j,pr as Te,qn as Ee,qt as De,rr as Oe,s as ke,tn as Ae,tr as je,un as Me,vr as Ne,vt as Pe,wr as Fe,yr as Ie,zn as Le}from"./tool-schema-DpbtSZtQ.js";import{c as M}from"./host-patterns-cSf1U25G.js";import{$t as Re,A as ze,An as Be,B as Ve,Bt as He,En as Ue,Et as We,F as Ge,Gt as Ke,Ht as qe,I as Je,In as Ye,It as Xe,Jt as Ze,Kt as Qe,L as $e,Ln as et,Lt as tt,M as nt,Mn as rt,Mt as it,N as at,On as ot,P as st,Pt as ct,Q as lt,Rn as ut,Rt as dt,Sn as ft,St as pt,Un as N,Ut as mt,Vn as ht,Vt as gt,W as _t,Wn as vt,Wt as yt,X as bt,bt as xt,et as St,ft as Ct,gn as wt,hn as Tt,in as Et,it as Dt,jn as Ot,jt as kt,k as At,mn as jt,mt as P,nt as Mt,pn as Nt,rn as Pt,rt as Ft,tt as It,ut as Lt,wn as Rt,wt as zt,xn as Bt,zn as Vt,zt as Ht}from"./shaped-data-C4jsvipW.js";import{a as Ut,n as Wt}from"./live-ingress-qi-y5uvH.js";import{n as Gt,t as Kt}from"./trace-schema-9CdEyG6Q.js";import{n as qt}from"./stub-4m0tKRlG.js";function Jt(e){return{type:`guardrail`,guardrail:e}}function Yt(e,t,n,r=`redact`,i){if(n.length!==0)return Jt({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Xt(e,t){return e.type===`guardrail`?{...e,guardrail:wt(e.guardrail,t)}:e}var Zt=65536;function F(e){let t=e.classStarts.length,n=new Uint16Array(Zt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Zt);let r=e.charsets.map(e=>{let n=new Uint8Array(t);for(let t of e)n[t]=1;return n}),i=e.nodes.length,a=new Int32Array(i),o=new Uint8Array(i),s=[];return e.nodes.forEach((e,t)=>{a[t]=e[0],o[t]=e[1],s.push(Int32Array.from(e.slice(2)))}),{classOf:n,has:r,pattern:a,final:o,edges:s,initials:e.initials,leads:e.leads,size:i}}var Qt,I,$t;async function en(){if(Qt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);Qt={forward:t,reversed:n}}function tn(){if(!Qt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return Qt}var L;function nn(e){let t=String.fromCharCode(e).toUpperCase();if(t.length!==1)return e;let n=t.charCodeAt(0);return e>=128&&n<128?e:n}function rn(e){if(!L){L=new Map;for(let e=0;e<Zt;e++){let t=nn(e),n=L.get(t);n?n.push(e):L.set(t,[e])}}return L.get(nn(e))??[e]}function an(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Zt&&t.push(n+1);return t}var on=new Map;function sn(e){let t=on.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>rn(e.charCodeAt(n))),r=an([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=F({classStarts:r,charsets:n.map(e=>e.map(i)),initials:[0],leads:[-1],nodes:[...n.map((e,t)=>[0,0,t+1,t]),[0,1]]});return on.set(e,a),a}function cn(e){let t=JSON.stringify(e),n=on.get(t);if(n)return n;let r=[...new Set(e.flatMap(e=>Array.from(e,e=>e.charCodeAt(0))))];r.sort((e,t)=>e-t);let i=an(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=F({classStarts:i,charsets:a,initials:e.map((e,t)=>{let n=o.length;for(let n=0;n<e.length;n++)o.push([t,0,o.length+1,r.indexOf(e.charCodeAt(n))]);return o.push([t,1]),n}),leads:e.map(()=>-1),nodes:o});return on.set(t,s),s}function ln(e,t){let n=e.has[0]?.length??0,r=Array.from({length:n},()=>[]);for(let i of t){let t=e.edges[e.initials[i]];for(let i=0;i<t.length;i+=2){let a=e.has[t[i+1]];for(let e=0;e<n;e++)a[e]&&r[e]?.push(t[i])}}return r.map(e=>Int32Array.from(e))}function un(e,t){e.text+=t,e.fresh+=t}function dn(e){return e.text.length-e.fresh.length}function R(e,t){let n=dn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function fn(e,t,n=e.text.length){let r=dn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function pn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function mn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,un(n,t(fn(e,n.text.length)))}};return n}var hn=/\w/,gn=Math.max(...dt.map(e=>e.length));function _n(e){return e.length<=gn+1&&/^[A-Za-z]*$/.test(e)}function vn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{un(o,e);for(let r=0;r<e.length;r++)i.push(t+Math.min(r,n-1))},o={text:``,fresh:``,rawAt:r=>e.rawAt(r<i.length?i[r]:t-(n?.length??0)),update(){o.fresh=``;for(let i=e.text.length;t<i;t++){let i=String.fromCharCode(R(e,t)),o=hn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(qe(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!_n(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function yn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function z(e,t,n){un(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var bn=55296,xn=56319,Sn=/[A-Za-z]/,Cn=56320,wn=57343;function Tn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=yn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(Sn.test(e)||z(c,`\\`,s),s=-1),e===`\\`?s=t:z(c,e,t)}function u(e,t){if(mt(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!Sn.test(e))for(let e=0;e<i.length;e++)l(i[e],a[e]);i=``,a=[]}for(let n=0;n<e.length;n++)l(e[n],t);o=Sn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=bn&&t<=xn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=Cn&&a<=wn?2:1;u(n.slice(e,e+o),r[e]),e+=o}n=n.slice(e),r=r.slice(e)}return c.update=()=>{c.fresh=``;let i=e.text.length;for(;t<i;){let a=R(e,t),o=a>=bn&&a<=xn;if(o&&t+1>=i)break;let s=R(e,t+1),c=o&&s>=Cn&&s<=wn?2:1,l=yt(fn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var En=/[0-9A-Fa-f]/;function Dn(e){let t=0,n=-1,r=yn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(R(e,t));if(n<0){a===`%`?n=t:(z(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:En.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)z(r,String.fromCharCode(R(e,n)),n)}}};function i(t){t>n&&z(r,Ht(fn(e,n,t)),n),n=-1}return r}var On=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),kn=new Map(tt.map(({pattern:e,hit:t})=>[e,t])),An=new Map(It.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function B(e){return{rule:Bt(e),severity:`high`,detector:e}}var jn=B(`injection`),Mn=B(`marker_leak`),Nn=B(`tool_leak`);function Pn({kind:e,group:t}){if(On.has(e))return jn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:B(t);case`boundary`:return Mn;case`image`:return B(`ungiven_images`);default:return B(`ungiven_links`)}}function Fn(e,t,n){if(e===`card`)return{hit:Mt};if(e===`image`||e===`link`){let r=(e===`image`?Ft:Dt).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=kn.get(t)??An.get(t);return r?{hit:r}:{}}function In(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Lt(i(n?.ungiven_images)),link:Ct(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return lt.forEach((t,n)=>{let r=Pn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Qe(t.pattern),...Fn(t.kind,t.pattern,a)})}),o}function Ln(){let e=[];return lt.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=kn.get(n);e.push({...jn,id:r,regex:Qe(n),...i?{hit:i}:{}})}),e}function Rn(){return Ke.map((e,t)=>({...jn,id:t,regex:new RegExp(e.source,e.flags)}))}function zn(e,t,n){let r=ln(t,n.map(e=>e.id)),i=new Int32Array(t.initials.length).fill(-1);n.forEach((e,t)=>{i[e.id]=t});let a=new Int32Array(t.size),o=new Int32Array(t.size),s=new Int32Array(t.size),c=new Int32Array(t.size),l=0,u=new Int32Array(t.size),d=new Int32Array(t.size),f=0,p=0,m=new Uint8Array(n.length),h=new Uint8Array(n.length),g=new Int32Array(n.length),_=new Int32Array(n.length),v=new Uint8Array(n.length),y=Uint8Array.from(n,e=>+!!e.find),b=new Int32Array(n.length).fill(-1),x=new Int32Array(n.length).fill(-1),S=Int32Array.from(n,e=>t.leads[e.id]??-1),ee=[...new Set(S)].filter(e=>e>=0),te=n.flatMap((e,t)=>S[t]<0?[]:[t]),C=new Int32Array(t.has.length).fill(-1);function w(){let{text:n,fresh:h}=e,g=dn(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function k(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function ne(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):k(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=ne();e;e=ne())t.push(e);return e.rawAt(n)}}}var Bn=new WeakMap;function Vn(e){let t=Bn.get(e);return t||(t=F(e),Bn.set(e,t)),t}function Hn(e={}){let t={text:``,fresh:``},n=pn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),zn(e,t,n)),a=[],o=e.detect??[],s=In(o,e);if(s.length>0&&(I??=F(tn().forward),a.push(i(n,I,s))),o.includes(`injection`)){I??=F(tn().forward),$t??=F(tn().reversed);let e=Tn(t),r=Ln();a.push(i(n,$t,Rn()),i(vn(n),I,r),i(e,I,r),i(vn(e),I,r),i(mn(n,gt),I,r),i(mn(n,e=>He(e)??e),I,r),i(Dn(t),I,r))}if(o.includes(`marker_leak`)&&e.note){let t=St(e.note);a.push(i(n,sn(e.note),[{...Mn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=_t(e.tools),r=t.map(({regex:e},t)=>({...Nn,id:t,regex:e}));t.length>0&&a.push(i(n,cn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...B(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Vn(r.automaton),e))}let c=0;return{push(e){t.text+=e,t.fresh=e;for(let e of r)e.update();let n=[],i=t.text.length;for(let e of a)i=Math.min(i,e.run(n));return c=i,n},holdFrom:()=>c}}function Un(e,t,n={},r=[]){let i=Ge(e,t).filter(e=>!($e(e)||r.includes(e))),a=Je(e,t);if(i.length===0&&a.length===0)return;let o=[...i,...a.map(({id:e})=>e)],s=t.sources??{},c=[...i.map(e=>({detector:e,...s[e]})),...a.map(({id:e,matchers:t,compiled:n})=>({detector:e,matchers:t,compiled:n}))],l=c.some(({matchers:e,compiled:t})=>e?.length&&!t),u=Hn({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=st(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Wn(e){let{context:t}=e,n=e.detect,r=n?Un(n.boundary,n.matrix,n.scope):void 0,i=e=>n?n.matrix[e][n.boundary]:`block`,a=i(`canary_leak`),o=i(`prompt_leak`),s=t.canaryGiven||a===`ignore`?void 0:t.canary,c=o===`ignore`?void 0:t.privateSystem,l=s!==void 0||c!==void 0,u=l?e.carry??``:``,d=[],f=new Set,p=``,m=0,h=``,g=u.slice(-P),_=u,v=0,y=u,b=0,x=0,S=s?pt(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,Tt]),c){let r=_.length;_+=e;let i=Xe(_,r);_=_.slice(i),v+=i;let[a]=bt(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?T(s):h.length,n=c&&o!==`flag`?E(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function T(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-P),i=r+xt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+xt(y,e)),x=Math.min(i,u.length+p.length-P);let a=Math.max(b,Math.max(t,x)-P);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function E(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+ct(i,e,t)-u.length-m)}function D(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:O(o)});let s=r.take(m,m+o,i);return s.action===`block`||s.action===`redact`&&!n.rewrite?{blocked:!0,hits:s.hits,boundary:n.boundary}:(O(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function O(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-P)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),D(e)):{blocked:!1,emit:``}},flush:()=>D(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?We(u+p,s,c):``}}function V(e,t,n){return at(t,e.detect,n)}async function Gn(e,t,n,r){return V(e,[n],t)?(await en(),Kn(e,t,n,r)):null}function Kn(e,t,n,r){return V(e,[n],t)?Wn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Ve(e,t)},...r?{carry:r}:{}}):null}async function qn(e,t,n,r){return V(e,[n],r??t)?(await en(),Wn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Ve(e,t)}})):null}var Jn=class{open;gate;constructor(e){this.open=e}async read(e){if(this.gate===void 0&&(this.gate=await this.open()),this.gate===`stopped`)return``;if(!this.gate)return e;let t=this.gate.process(e);return t.blocked?(this.gate=`stopped`,``):t.emit}end(){if(!this.gate||this.gate===`stopped`)return``;let e=this.gate.flush();return e.blocked?``:e.emit}},Yn=2,Xn=4,Zn=3,Qn=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,$n=/^[A-Za-z0-9+/]*={0,2}$/,er=new Set([`text/csv`,`text/plain`,`text/markdown`]);function tr(e){let{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}=e;if(t&&n&&r)return{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}}function nr(e,t){if(t.limitsByMime){let n=_e(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function rr(e){return`uri`in e}function ir(e){if(e.type===`speech`)throw new M(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new M(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new M(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=tr(e.inputs??{});if(!t)throw new M(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function ar(e){let t=0;return e.endsWith(`==`)?t=Yn:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Zn/Xn)-t}function or(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function sr(e){return e.replace(Qn,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function cr(e,t,n){let r=or(t);return e===`text/csv`&&(r=sr(r)),new TextEncoder().encode(n.read(r))}function lr(e,t){return t?{...e,fileName:t}:e}function ur(e,t,n){return t.filter(t=>!A(e,t.mimeType)).map(e=>lr({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function dr(e,t){let n=[];e.length>t.maxFiles&&n.push({code:`too_many_files`,params:{maxFiles:t.maxFiles}});let r=0;for(let i of e){if(i.sizeBytes===void 0)continue;let e=nr(i.mimeType,t);i.sizeBytes>e&&n.push(lr({code:`file_too_large`,params:{maxBytes:e}},i.name)),r+=i.sizeBytes}return r>t.maxTurnBytes&&n.push({code:`turn_too_large`,params:{maxTurnBytes:t.maxTurnBytes}}),n}function fr(e,t,n){let r=[];return t.length>0&&!e.attachments&&r.push({code:`attachments_not_accepted`,params:{channel:`attachment`}}),n.length>0&&!e.voice&&r.push({code:`voice_not_accepted`,params:{channel:`voice`}}),r.length>0||t.length===0&&n.length===0?r:(e.attachments&&r.push(...ur(e.attachments,t,`attachment`)),e.voice&&r.push(...ur(e.voice,n,`voice`)),e.limits?[...r,...dr([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var pr={mime_not_allowed:`attachments.mime_not_allowed`,too_many_files:`attachments.too_many_files`,too_many_of_kind:`attachments.too_many_of_kind`,file_too_large:`attachments.file_too_large`,turn_too_large:`attachments.turn_too_large`,attachments_not_accepted:`attachments.not_accepted`,voice_not_accepted:`attachments.not_accepted`,limits_unconfigured:`attachments.limits_unconfigured`};function mr(e){let t={};for(let[n,r]of Object.entries(e.params??{}))r!==void 0&&(t[n]=r);return e.fileName!==void 0&&(t.fileName=e.fileName),{key:pr[e.code],params:t}}function hr(e,t){let n=mr(e);return N(n.key,n.params,t)}function gr(e){return new M(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(mr)})}function _r(e){if(!$n.test(e))throw new M(`request`,`attachment data must be base64`);return ar(e)}function vr(e){let t={mimeType:e.mimeType,name:e.name};return rr(e)||(t.sizeBytes=_r(e.data)),t}function yr(e,t,n){if(!xr(t,n))return;let r=ir(e),i=fr({attachments:he(e,`attachments`),voice:he(e,`voice`),limits:r},(t??[]).map(vr),(n??[]).map(vr));if(i.length>0)throw gr(i)}function br(e,t){if(rr(e))return e;let{mimeType:n,data:r}=e;if(!er.has(_e(n)))return e;let i=cr(n,Nt(r),t);return{...e,data:jt(i)}}function xr(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Sr(e,t,n,r){return yr(e,t,n),{attachments:t?.length?t.map(e=>br(e,r.attachment)):t,voice:n?.length?n.map(e=>br(e,r.voice)):n}}var Cr=`
2
2
 
3
- `;function wr(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function Tr(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=wr(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function Er(e,t){let n=Tr(e,t);if(n)throw new M(`config`,n)}function Dr(e,t,n){return Er(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Or(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function kr(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Cr,private:!0}),t.push(...n));return t}function Ar(e){return e.map(e=>e.text).join(``)}function jr(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:Ar(e),private:t}}function Mr(e,t){return jr(kr([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var Nr=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Pr(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Fr={client:`untrusted`,server:`assembled`};function Ir(e){return typeof e==`string`?e:JSON.stringify(e)}function Lr(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of k){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Ir(o));let c=s.found(),l=it(`context`,c);l&&n.push({...l,trust:Fr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Rr=/^[A-Za-z0-9._-]+$/;function zr(e){let t=e?.trim();return t&&Rr.test(t)?t:void 0}function Br(e,t){if(!e)return e;let n=e.guidance?t.read(e.guidance):void 0;return{previousOutput:t.read(e.previousOutput),rejection:t.read(e.rejection),...n?{guidance:n}:{}}}function Vr(e,t){return e.map(e=>{let n=e.content===void 0?void 0:t.read(e.content),r=e.parts?.map(e=>e.type===`text`?{...e,text:t.read(e.text)}:e);return{role:e.role,...n===void 0?{}:{content:n},...r?{parts:r}:{},...e.tool_calls?{tool_calls:e.tool_calls}:{},...e.tool_call_id?{tool_call_id:e.tool_call_id}:{},...e.name?{name:e.name}:{},...e.metadata?{metadata:e.metadata}:{},...e.reasoning?{reasoning:e.reasoning}:{}}})}function Hr(e,t){let n=t?`: ${t}`:``;return new M(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function Ur(e,t){let{detect:n}=ge(t.guardrails),r=We(Nr,e=>ze(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Dr(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=Pr(i.slots,r.slots),c=Lr(i.context,()=>ze(`context`,n)),l=Br(i.repair,r.repair),u=i.history?Vr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?Sr(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Nr){let t=r[e].found(),n=it(e,t);n&&p.push(Jt(n)),t.action===`block`&&(m??=Hr(e,t.errorInternal))}return p.push(...c.events.map(Jt)),c.blocked&&(m??=Hr(`context`)),{request:{...e,system:o,projectId:zr(e.projectId),input:{...i,text:a,slots:s,...c.context?{context:c.context}:{},repair:l,history:u,attachments:d,voice:f}},events:p,...m?{refusal:m}:{}}}function Wr(e,t){let{request:n,refusal:r}=Ur(e,t);if(r)throw r;return n}function Gr(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function Kr(e,t){return[...new Set([...t.filter(t=>A(e,t)),...e.filter(e=>A(t,e))])]}function qr(e,t){let n=e.attachments?t?Kr(e.attachments.accept,t.media.flatMap(e=>e.accept)):[...e.attachments.accept]:[],r=(t?.media??[]).flatMap(e=>e.maxPerInput===void 0?[]:[{accept:[...e.accept],max:e.maxPerInput}]);return{text:e.text!==!1,...n.length>0?{attachments:{accept:n}}:{},...e.maxFiles===void 0?{}:{maxFiles:e.maxFiles},...e.maxBytes===void 0?{}:{maxBytes:e.maxBytes},...e.maxTurnBytes===void 0?{}:{maxTurnBytes:e.maxTurnBytes},...e.limitsByMime===void 0?{}:{limitsByMime:{...e.limitsByMime}},...t?.maxInputs===void 0?{}:{maxInputs:t.maxInputs},...r.length>0?{perInput:r}:{}}}function Jr(e){let t=_e(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Yr(e,t){let n=tr(e),r=fr({attachments:e.attachments?.accept,...n?{limits:{...n,maxFiles:2**53-1}}:{}},t.flat(),[]);if(n)for(let i of t){i.length>n.maxFiles&&r.push({code:`too_many_files`,params:{maxFiles:n.maxFiles}});for(let t of e.perInput??[])i.filter(e=>A(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:Jr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var Xr=`final_answer`;function Zr(e){return e.structured!==null&&e.tools.wire.length>0}function Qr(e,t,n){let{structured:r}=t;if(!r||!Zr(t))return e;let i={type:`function`,name:Xr,description:N(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function $r(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function ei(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ti(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function H(e){return`tools`in e?e.tools.allow:[]}function ni(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function ri(e){return`tools`in e?e.tools.parallel:void 0}function ii(e,t,n){return H(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||ei(i.paths,n.path)})}function ai(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&ei(r.paths,n.path)}):[]}function oi(e,t){let n=e.get(t);if(n&&n.type!==`builtin`)return{type:`function`,name:n.name,description:n.description,parameters:n.inputSchema}}function si(e,t){let n=[];for(let r of t){let t=oi(e,r);t&&n.push(t)}return n}function ci(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=oi(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function li(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function ui(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function di(e,t,n){return ti(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function fi(e,t,n,r){let i=ii(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ai(e,t,n,r),o=[...i,...a],s=di(e,t,o),c=ui(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>$r(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:si(e,c)}}async function pi(e,t,n,r){let i=fi(e,t,n,r);return await hi(e,i,t,n),i}function mi(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)}))}}async function hi(e,t,n,r){let i=ni(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new M(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new M(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);for(let n of a){if(!t.gated.includes(n))continue;let r=e.get(n);r?.loadTier===`T2`&&(r.type===`builtin`?li(e,t,n):ci(e,t,n))}t.executable=t.visible.filter(t=>$r(e,t))}var gi=new Set([`__proto__`,`constructor`,`prototype`]);function _i(e){if(!jt(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function vi(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||gi.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=bi(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;ei(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)ci(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>$r(e,t)),{promoted:a}}function yi(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function bi(e,t,n){if(!H(n).includes(t))return yi(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?yi(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:yi(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):yi(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function xi(e,t){return e.get(t)||{name:t,missing:!0}}function Si(e){let t=new Set;if(e.type===`host`||e.type===`decision`||e.type===`embedding`)return[];for(let n of Object.values(e.models))for(let e of n.builtInTools??[])t.add(e);return[...t]}function Ci(e,t){return[...H(t),...Si(t)].map(t=>xi(e,t))}function wi(e,t){if(Array.isArray(e)){for(let n of e)wi(n,t);return}if(typeof e!=`object`||!e)return;let{properties:n,...r}=e;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n))t.add(e),wi(r,t);for(let e of Object.values(r))wi(e,t)}function Ti(e,t){let n=Ci(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&wi(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function Ei(e){return!e||e.length===0?[]:e.slice(-4)}function Di(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${N(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
4
- `)}\n\n`}function Oi(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||N(`repair.default_guidance`,{},t.labels),a=Di(Ei(r),t.labels),o=`${N(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${N(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${N(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${N(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${N(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${N(`repair.section_instructions`,{},t.labels)}\n`,o+=N(`repair.prompt_instructions`,{},t.labels),o}function ki(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function Ai(e,t){let n=ki(e,t);if(!(n.length<=1))throw new M(`config`,`Profile ${e.id} declares multiple output wire formats (${n.join(`, `)}). Only one of a structured JSON schema (outputs.structured), image, or speech may be active.`)}function ji(e,t){if(e.type!==`speech`){if(t.speech)throw new M(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new M(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function Mi(e,t){return e.type===`speech`?{...e.speech,...Ni(t.speech)}:void 0}function Ni(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function Pi(e){if(e.type!==`image`)return null;let t=e.image;return{type:`image`,mimeType:t.mimeType,aspectRatio:t.aspectRatio,resolution:t.resolution,quality:t.quality,background:t.background,n:t.n,seed:t.seed,outputCompression:t.outputCompression,includeText:t.includeText===!0}}function Fi(e){let t=Me(e);if(!t)throw new M(`input`,`MIME '${e}' is not a supported media input type`);return t}function Ii(e){return e.map(e=>{let t=Fi(e.mimeType),n=_e(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return rr(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Li(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new M(`request`,`Profile ${e.id} (speech) requires text input`);if(j(e)?.text===!1&&n)throw new M(`request`,`Profile ${e.id} does not accept text input`);let a=r?Oi({profile:e,repair:r,history:i}):zi(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Ri(t),...a?[at(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
3
+ `;function wr(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function Tr(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=wr(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function Er(e,t){let n=Tr(e,t);if(n)throw new M(`config`,n)}function Dr(e,t,n){return Er(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Or(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function kr(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Cr,private:!0}),t.push(...n));return t}function Ar(e){return e.map(e=>e.text).join(``)}function jr(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:Ar(e),private:t}}function Mr(e,t){return jr(kr([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var Nr=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Pr(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Fr={client:`untrusted`,server:`assembled`};function Ir(e){return typeof e==`string`?e:JSON.stringify(e)}function Lr(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of k){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Ir(o));let c=s.found(),l=nt(`context`,c);l&&n.push({...l,trust:Fr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Rr=/^[A-Za-z0-9._-]+$/;function zr(e){let t=e?.trim();return t&&Rr.test(t)?t:void 0}function Br(e,t){if(!e)return e;let n=e.guidance?t.read(e.guidance):void 0;return{previousOutput:t.read(e.previousOutput),rejection:t.read(e.rejection),...n?{guidance:n}:{}}}function Vr(e,t){return e.map(e=>{let n=e.content===void 0?void 0:t.read(e.content),r=e.parts?.map(e=>e.type===`text`?{...e,text:t.read(e.text)}:e);return{role:e.role,...n===void 0?{}:{content:n},...r?{parts:r}:{},...e.tool_calls?{tool_calls:e.tool_calls}:{},...e.tool_call_id?{tool_call_id:e.tool_call_id}:{},...e.name?{name:e.name}:{},...e.metadata?{metadata:e.metadata}:{},...e.reasoning?{reasoning:e.reasoning}:{}}})}function Hr(e,t){let n=t?`: ${t}`:``;return new M(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function Ur(e,t){let{detect:n}=ge(t.guardrails),r=Ue(Nr,e=>ze(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Dr(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=Pr(i.slots,r.slots),c=Lr(i.context,()=>ze(`context`,n)),l=Br(i.repair,r.repair),u=i.history?Vr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?Sr(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Nr){let t=r[e].found(),n=nt(e,t);n&&p.push(Jt(n)),t.action===`block`&&(m??=Hr(e,t.errorInternal))}return p.push(...c.events.map(Jt)),c.blocked&&(m??=Hr(`context`)),{request:{...e,system:o,projectId:zr(e.projectId),input:{...i,text:a,slots:s,...c.context?{context:c.context}:{},repair:l,history:u,attachments:d,voice:f}},events:p,...m?{refusal:m}:{}}}function Wr(e,t){let{request:n,refusal:r}=Ur(e,t);if(r)throw r;return n}function Gr(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function Kr(e,t){return[...new Set([...t.filter(t=>A(e,t)),...e.filter(e=>A(t,e))])]}function qr(e,t){let n=e.attachments?t?Kr(e.attachments.accept,t.media.flatMap(e=>e.accept)):[...e.attachments.accept]:[],r=(t?.media??[]).flatMap(e=>e.maxPerInput===void 0?[]:[{accept:[...e.accept],max:e.maxPerInput}]);return{text:e.text!==!1,...n.length>0?{attachments:{accept:n}}:{},...e.maxFiles===void 0?{}:{maxFiles:e.maxFiles},...e.maxBytes===void 0?{}:{maxBytes:e.maxBytes},...e.maxTurnBytes===void 0?{}:{maxTurnBytes:e.maxTurnBytes},...e.limitsByMime===void 0?{}:{limitsByMime:{...e.limitsByMime}},...t?.maxInputs===void 0?{}:{maxInputs:t.maxInputs},...r.length>0?{perInput:r}:{}}}function Jr(e){let t=_e(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Yr(e,t){let n=tr(e),r=fr({attachments:e.attachments?.accept,...n?{limits:{...n,maxFiles:2**53-1}}:{}},t.flat(),[]);if(n)for(let i of t){i.length>n.maxFiles&&r.push({code:`too_many_files`,params:{maxFiles:n.maxFiles}});for(let t of e.perInput??[])i.filter(e=>A(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:Jr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var Xr=`final_answer`;function Zr(e){return e.structured!==null&&e.tools.wire.length>0}function Qr(e,t,n){let{structured:r}=t;if(!r||!Zr(t))return e;let i={type:`function`,name:Xr,description:N(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function $r(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function ei(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ti(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function H(e){return`tools`in e?e.tools.allow:[]}function ni(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function ri(e){return`tools`in e?e.tools.parallel:void 0}function ii(e,t,n){return H(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||ei(i.paths,n.path)})}function ai(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&ei(r.paths,n.path)}):[]}function oi(e,t){let n=e.get(t);if(n&&n.type!==`builtin`)return{type:`function`,name:n.name,description:n.description,parameters:n.inputSchema}}function si(e,t){let n=[];for(let r of t){let t=oi(e,r);t&&n.push(t)}return n}function ci(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=oi(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function li(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function ui(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function di(e,t,n){return ti(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function fi(e,t,n,r){let i=ii(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ai(e,t,n,r),o=[...i,...a],s=di(e,t,o),c=ui(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>$r(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:si(e,c)}}async function pi(e,t,n,r){let i=fi(e,t,n,r);return await hi(e,i,t,n),i}function mi(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)}))}}async function hi(e,t,n,r){let i=ni(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new M(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new M(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);for(let n of a){if(!t.gated.includes(n))continue;let r=e.get(n);r?.loadTier===`T2`&&(r.type===`builtin`?li(e,t,n):ci(e,t,n))}t.executable=t.visible.filter(t=>$r(e,t))}var gi=new Set([`__proto__`,`constructor`,`prototype`]);function _i(e){if(!At(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function vi(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||gi.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=bi(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;ei(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)ci(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>$r(e,t)),{promoted:a}}function yi(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function bi(e,t,n){if(!H(n).includes(t))return yi(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?yi(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:yi(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):yi(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function xi(e,t){return e.get(t)||{name:t,missing:!0}}function Si(e){let t=new Set;if(e.type===`host`||e.type===`decision`||e.type===`embedding`)return[];for(let n of Object.values(e.models))for(let e of n.builtInTools??[])t.add(e);return[...t]}function Ci(e,t){return[...H(t),...Si(t)].map(t=>xi(e,t))}function wi(e,t){if(Array.isArray(e)){for(let n of e)wi(n,t);return}if(typeof e!=`object`||!e)return;let{properties:n,...r}=e;if(typeof n==`object`&&n)for(let[e,r]of Object.entries(n))t.add(e),wi(r,t);for(let e of Object.values(r))wi(e,t)}function Ti(e,t){let n=Ci(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&wi(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function Ei(e){return!e||e.length===0?[]:e.slice(-4)}function Di(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${N(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
4
+ `)}\n\n`}function Oi(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||N(`repair.default_guidance`,{},t.labels),a=Di(Ei(r),t.labels),o=`${N(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${N(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${N(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${N(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${N(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${N(`repair.section_instructions`,{},t.labels)}\n`,o+=N(`repair.prompt_instructions`,{},t.labels),o}function ki(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function Ai(e,t){let n=ki(e,t);if(!(n.length<=1))throw new M(`config`,`Profile ${e.id} declares multiple output wire formats (${n.join(`, `)}). Only one of a structured JSON schema (outputs.structured), image, or speech may be active.`)}function ji(e,t){if(e.type!==`speech`){if(t.speech)throw new M(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new M(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function Mi(e,t){return e.type===`speech`?{...e.speech,...Ni(t.speech)}:void 0}function Ni(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function Pi(e){if(e.type!==`image`)return null;let t=e.image;return{type:`image`,mimeType:t.mimeType,aspectRatio:t.aspectRatio,resolution:t.resolution,quality:t.quality,background:t.background,n:t.n,seed:t.seed,outputCompression:t.outputCompression,includeText:t.includeText===!0}}function Fi(e){let t=Me(e);if(!t)throw new M(`input`,`MIME '${e}' is not a supported media input type`);return t}function Ii(e){return e.map(e=>{let t=Fi(e.mimeType),n=_e(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return rr(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Li(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new M(`request`,`Profile ${e.id} (speech) requires text input`);if(j(e)?.text===!1&&n)throw new M(`request`,`Profile ${e.id} does not accept text input`);let a=r?Oi({profile:e,repair:r,history:i}):zi(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Ri(t),...a?[it(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
5
5
 
6
- `)}:null}function Ri(e){let t=e.input?.context??{};return[...k].reverse().filter(e=>t[e]!==void 0).map(e=>At(e,Ir(t[e])))}function zi(e,t){if(t.continueFrom&&ee.includes(e.type)){if(t.input?.text)throw new M(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return N(`continue.instruction`,{},e.labels)}}function Bi(e){return e.type===`image`&&e.image.references?Ii(e.image.references):[]}function Vi(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Bi(e),...Ii(n),...Ii(r)]}function Hi(e,t){let n=[],r=Li(e,t);return r&&n.push(r),n.push(...Vi(e,t)),n}function Ui(e,t){let n=t.input?.slots;if(!n)return;let r=j(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new M(`request`,`Profile ${e.id} has no slot '${t}'`);if(!n.includes(i))throw new M(`request`,`Profile ${e.id}: slot '${t}' takes ${n.join(`, `)}, not '${i}'`)}}function Wi(e,t){let n=t.input?.context;if(!n)return;let r=j(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!k.includes(t)||!r?.from.some(e=>e===t))throw new M(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Ir(i).length>r.maxChars)throw new M(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Gi=/\{([A-Za-z_][\w-]*)\}/g;function Ki(e,t,n,r){let i=j(e)?.slots;return i?t.replace(Gi,(t,a)=>{if(!Object.hasOwn(i,a))return t;let o=n&&Object.hasOwn(n,a)?n[a]:void 0;if(o===void 0)throw new M(`request`,`Profile ${e.id}: ${r} uses slot '${a}', and the request chose no value for it`);return o}):t}function qi(e,t){let{handle:n}=e.identity,r=e.type===`speech`?void 0:e.identity.systemByRole;return t&&r&&Object.hasOwn(r,t)?t:n}function Ji(e,t,n){if(e.type===`speech`)return[];let{systemByRole:r,system:i}=e.identity,a=r?.[t]||i||``;return a?Or(Dr(a,`Profile ${e.id} identity.system`,t=>Ki(e,t,n,`identity.system`))):[]}function Yi(e,t){return kr([Ji(e,qi(e,t.input?.role),t.input?.slots),t.system===void 0?[]:Or(t.system)])}function Xi(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function Zi(e,t){if(Xi(e))return e;throw e.type===`host`?new M(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new M(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new M(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function Qi(e,t){if(t){if(!e.allowModelSelect)throw new M(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new M(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function $i(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new M(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new M(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new M(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function ea(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function ta(e,t){if(e.type===`live`)return null;let n=e.outputs?.structured;if(!n)return null;if(typeof n==`string`)return n;let r=t?.[n.by];if(r){let e=n.map[r];if(e)return e}return n.fallback}function na(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function ra(e,t){return e.type===`live`?`live`:`turn`}function ia(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new M(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=O(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new M(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new M(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new M(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function aa(e,t){return V(ge(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function oa(e){let{detect:t}=ge(e.guardrails);return e.type!==`speech`&&Dt(t,`canary_leak`)?Bt():``}function sa(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new M(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function ca(e,t,n){let r=Zi(e.profiles.get(t.profile),`resolveTurn`);Ui(r,t),Wi(r,t);let i=Wr(t,r),a=i.input??{};ia(r,i);let o=n??Qi(r,i.model),s=Se(r,o),c=fi(e.tools,r,i,o),l=c.builtins,u=ta(r,a.slots);if(Ai(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new M(`config`,`Profile ${r.id}: a structured turn answers through '${Xr}', so no tool of its own may take that name`);ji(r,i);let d=sa(r,o,s,i.builtInArgs),f=ra(r,s);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,stream:na(r),thinking:$i(r,s,o,i.effort),summaries:ea(s),maxOutputTokens:s.maxOutputTokens,temperature:s.temperature,builtins:l,builtInArgs:d,sessionId:i.sessionId,tools:c,sessionPermissions:i.sessionPermissions,execution:i.execution,pageExecution:i.pageExecution,history:a.history,maxSteps:r.maxSteps??20,structured:u?{id:u,jsonSchema:e.schemas.get(u).jsonSchema}:null,image:Pi(r),speech:Mi(r,i),live:r.type===`live`?aa(r.live,r.guardrails):void 0,input:Hi(r,i),canary:oa(r),resolvedSystem:Yi(r,i),host:i.host}}}function la(e){return e.type===`image`?e.image:null}function ua(e,t){let n=Zi(t,`projectProfile`),{identity:r}=n,i=j(n)??null,a=n.type===`live`?null:n.outputs??null;return{id:n.id,type:n.type,handle:r.handle,models:n.models,defaultModel:n.defaultModel,allowModelSelect:n.allowModelSelect,maxSteps:n.maxSteps,tools:Ci(e,n),inputs:i,outputs:a,image:la(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function da(e,t){return ua(e.tools,e.profiles.get(t))}function fa(e){return e==null}function U(e){return fa(e)||typeof e!=`object`||Array.isArray(e)?null:e}function pa(e){let t=U(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function ma(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function ha(e){let t=e.properties;return U(t)??{}}function ga(e,t){return e?`${e}.${t}`:t}function _a(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function va(e,t,n,r,i){if(!n)return;let a=await n(t,r);a.isValid||i.push({path:e,error:a.error||a.finding||`Validation failed for '${e}'`})}async function ya(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(fa(r)){i&&_a(t,s);return}await va(t,r,a?.[t],o,s);let c=pa(n),l=c?U(r):null;c&&l&&await ba(c,l,t,a,o,s)}async function ba(e,t,n,r,i,a){let o=ha(e),s=new Set(ma(e)),c=new Set([...Object.keys(o),...s]),l=U(t);for(let e of c)await ya({path:ga(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function xa(e,t,n,r){let i=pa(e);if(!i)throw new M(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!U(t)){for(let e of ma(i))_a(e,a);return a}return await ba(i,t,``,n,r,a),a}function Sa(e,t){let n=e;for(let e of t.split(`.`)){let t=pa(n);if(!t)return!1;let r=ha(t);if(!Object.hasOwn(r,e)&&!ma(t).includes(e))return!1;n=r[e]}return!0}function Ca(e){return e.map(e=>e.error).join(`; `)}function wa(e,t){let n=e;for(let e of t.split(`.`))n=U(n)?.[e];return n}function Ta(e,t,n){let[r,...i]=t.split(`.`),a=U(e)??{};return r===void 0?e:{...a,[r]:i.length?Ta(a[r],i.join(`.`),n):n}}async function Ea(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=wa(e,i);if(Array.isArray(t))for(let[e,o]of t.entries()){let t=await a.check(o,n);t.isValid||r.push({path:i,index:e,item:o,reason:t.error||t.finding||`Validation failed for '${i}'`,onFail:a.onFail})}}return r}function Da(e,t){let n=e;for(let e of t.split(`.`)){let t=pa(n);if(!t)return;n=ha(t)[e]}let r=U(n);if(r?.type===`array`)return U(r.items)??void 0}var Oa=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},ka=new Set([`text`,`image`,`speech`]),Aa=g().regex(/\S/),ja=t({mimeType:g(),data:m(),name:g().optional()}),Ma=t({mimeType:g(),uri:g(),name:g().optional()}),Na=t({voice:g().optional(),style:g().optional(),speed:h().positive().optional()});function Pa(e){return t(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,d(t).optional()])))}var Fa=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function Ia(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function La(e,n){let{inputs:r}=e,a={text:Aa};r?.attachments&&(a.attachments=l(i([ja,Ma])).optional()),r?.voice&&(a.voice=l(ja).optional()),r?.slots&&(a.slots=Pa(r.slots).optional()),e.type===`speech`&&(a.speech=Na.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new M(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new M(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(Fa.has(e))throw new M(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return t(a)}var Ra=v({text:g().optional(),structured:n().optional(),removed:l(v({path:g(),reason:g(),item:n()})).optional(),parts:l(ne).optional(),sources:l(D).optional()});function za(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function Ba(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Va(e,t){if(!ka.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!za(e))return`it does not take text`;for(let n of H(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(Ba(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Ha(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new M(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new M(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=Va(a,n);if(o)throw new M(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ua(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return H(e).length===0&&!t?`local`:`delegated`}function Wa(e){let t=ae(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ce(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ga(e,t,n){return{...e,type:`agent`,input:t,output:Ra,sources:e=>e.sources??[],...n}}var Ka=/^[\x21-\x7E]{1,256}$/;function qa(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function Ja(e){return e!==null&&Ka.test(e)}async function Ya(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Xa(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function Za(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&Qa(i,`${n}.properties.${t}`,r)}function Qa(e,t,n){if(!Xa(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Za(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&Qa(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&Qa(e,`${t}.${r}[${i}]`,n)})}}function $a(e,t){let n=[];if(Qa(e,`$`,n),n.length>0)throw new M(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function eo(e,t=`output`){let n=r(e,{target:`draft-7`,io:t});return delete n.$schema,n.type||=`object`,n}function to(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(to);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=to(e[n]));return t}function no(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new M(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}var ro=class{value;constructor(e){this.value=e}};function io(e){return new ro(e)}function ao(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return io(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(N(`tool.page_timed_out`,{},i)):Error(N(`tool.page_no_answer`,{tool:e},i))}}function oo(e){let t=eo(e.input,`input`);$a(t,`input`);let n=eo(e.output,`output`);$a(n,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?Pe(n,r[t]):void 0;if(i)throw new M(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:t,outputSchema:n}}function so(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new M(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function co(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new M(`config`,`Tool "${e}" auth.queryParam ${r}`)}function lo(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new M(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function uo(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new M(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function W(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new M(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function fo(e){W(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(W(e.name,`imageLimits.count`,t.count),W(e.name,`imageLimits.bytes`,t.bytes),W(e.name,`imageLimits.totalBytes`,t.totalBytes),uo(e.name,t.timeoutMs))}function po(e){return no(e.endpoint),so(e.name,e.auth),co(e.name,e.auth,e.mapping?.queryParams),lo(e.name,e.limit),uo(e.name,e.timeoutMs),fo(e),{...e,type:`http`,...oo(e)}}function mo(e){return so(e.name,e.auth),co(e.name,e.auth),fo(e),W(e.name,`session.idleMs`,e.session?.idleMs),W(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...oo(e)}}function ho(e){so(e.name,e.auth),co(e.name,e.auth);let t=e.answeredBy===`page`?ao(e.name):e.handler;if(typeof t!=`function`)throw new M(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...oo(e)}}function go(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=Ha(e,t,n),i=j(r),a=La({type:r.type,...i?{inputs:i}:{}},e);return Ga(e,a,oo({...e,input:a,output:Ra}))}return e.type===`http`?po(e):e.type===`mcp`?mo(e):ho(e)}function _o(e=()=>void 0){let t=new Map,n=qa(),r=e=>t.get(e),i=n=>{let i=go(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new M(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}function vo(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new M(`config`,N(`provider.binding_identity`))}function yo(e){Oo(e.id,e.models),Xo(e.id,e.observability),vs(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))Ao(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:ko(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function bo(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new M(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function xo(e,t,n){if(bo(e,t,n,b),vo(e,t,n,`decision`),`retry`in n)throw new M(`config`,`Profile ${e} model '${t}': a decision binding takes no retry; a decision retries only a transient failure, by the kernel's rule`);if(n.timeoutMs!==void 0&&(!Number.isFinite(n.timeoutMs)||n.timeoutMs<=0))throw new M(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function So(e){let t=e.models?Gr(e.models):void 0;if(!t)throw new M(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);xo(e.id,t,e.models[t])}function Co(e){if(e.inputs.state!==`json`)throw new M(`config`,`Profile ${e.id}: decision inputs.state must be 'json'`);let t=e.inputs.maxStateBytes;if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw new M(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new M(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function wo(e){return So(e),Co(e),Xo(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function To(e){return e===void 0?{}:{parallel:e}}function Eo(e){return Do(e.id,e.tools),Xo(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...To(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Do(e,t){if(!Array.isArray(t.allow))throw new M(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function Oo(e,t){if(Object.keys(t).length===0)throw new M(`config`,`Profile ${e} must declare at least one model`)}function ko(e,t){let n=t.defaultModel??Gr(t.models);if(!n)throw new M(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new M(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function Ao(e,t,n){jo(e,t,n),bo(e,t,n,Ae),jo(e,t,n)}function jo(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new M(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!we.includes(i))throw new M(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${we.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new M(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new M(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new M(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function Mo(e){return{providerContinuation:e.providerContinuation?Fe.parse(e.providerContinuation):{},models:e.models,defaultModel:ko(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function No(e,t,n){if(n?.length){for(let r of n)if(!le(r))throw new M(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function Po(e,t){t&&(No(e,`allowContinue`,t.allowContinue),No(e,`autoContinue`,t.autoContinue))}function Fo(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Io(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>Fo(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var Lo=Object.entries(je).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Ro(e){if(!Fo(e))throw new M(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new M(`config`,`Profile definition must set id`);if(!Ce.find(t=>t===e.type))throw new M(`config`,`Profile ${t}: type must be one of ${Ce.join(`, `)}`)}function zo(e){let t=e.identity?.handle,n=[[`id`,e.id,64],[`identity.handle`,typeof t==`string`?t:``,32]];for(let[t,r,i]of n)if(!(Array.from(r).length<=i))throw new M(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function Bo(e){let{id:t,type:n}=e,r=e;for(let[e,i]of Lo){if(i&&!i.includes(n))continue;let a=Ie(e),o=Io(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!Fo(e))return!1;let t=e[s];return t==null||t===``}))throw new M(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Vo(e){let{id:t,type:n}=e;if(n!==`live`&&me(`inputs`).includes(n)&&e.inputs==null)throw new M(`config`,`Profile ${t}: type '${n}' must set inputs`)}function Ho(e){let[t]=Ne(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new M(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Uo(e,t){let n=t.turnBehaviour;Po(e,n?.resumption)}function Wo(e,t){let n=t=>new M(`config`,`Profile ${e}: ${t}`),r=t?.maxRetries;if(r!==void 0&&(!Number.isInteger(r)||r<0))throw n(`outputs.validation.maxRetries must be a non-negative integer`)}function Go(e,t){let n=t=>new M(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Ko.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Ko.join(`, `)}`);Jo(t?.blockedReply,n)}var Ko=[`quota`,`detect`,`blockedReply`,`network`,`taint`],qo=[`onBlock`,`maxRetries`];function Jo(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!qo.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!re.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${re.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function Yo(e){let t=e.guardrails?.detect,n=e.type===`host`?Ft(`guardrails.detect`,t,zt):Ft(`guardrails.detect`,t);if(n!==void 0)throw new M(`config`,`Profile ${e.id}: ${n}`)}function Xo(e,t){try{let n=Ut(t);if(!Number.isFinite(n.retainForDays))throw new M(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new M(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof M&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new M(Be(t),`Profile ${e}: ${n}`,{cause:t})}}function Zo(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`embedding`)return;let{system:t,systemByRole:n}=e.identity;t!==void 0&&Er(t,`Profile ${e.id} identity.system`);for(let[t,r]of Object.entries(n??{}))Er(r,`Profile ${e.id} identity.systemByRole.${t}`)}function Qo(e){Ro(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new M(`config`,N(`provider.profile_configuration`,{profile:e.id,field:t}));if(Ho(e),Vo(e),Bo(e),zo(e),e.labels&&gt(e.labels,`Profile ${e.id}`),Zo(e),Yo(e),e.type===`host`)return Eo(e);if(e.type===`decision`)return wo(e);if(e.type===`embedding`)return yo(e);Oo(e.id,e.models),Uo(e.id,e),Go(e.id,e.guardrails),e.type===`text`&&Wo(e.id,e.outputs?.validation),Xo(e.id,e.observability);for(let[t,n]of Object.entries(e.models))Ao(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,system:e.identity.system,systemByRole:e.identity.systemByRole},n=e.guardrails,r=e.observability,i=e.labels,a=Mo(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},is(o.id,o.inputs.attachments?.accept),rs(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs,tools:{allow:e.tools.allow,...To(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Wt(o),os(o.id,o.live.contextCompression),as(o);break;default:throw new M(`config`,`Unknown profile type '${String(e)}'`)}return ts(o),$o(o),es(o),o}function $o(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new M(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function es(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new M(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function ts(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=j(e)?.slots?.[t.by];if(!n)throw new M(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=Object.keys(t.map).filter(e=>!n.includes(e));if(r.length)throw new M(`config`,`Profile ${e.id}: outputs.structured.map maps ${r.join(`, `)}, not a choice of slot '${t.by}'`)}var ns={n:{ok:e=>Number.isInteger(e)&&e>=1,rule:`a whole number of 1 or more`},seed:{ok:Number.isInteger,rule:`a whole number`},outputCompression:{ok:e=>Number.isInteger(e)&&e>=0&&e<=100,rule:`a whole number from 0 to 100`}};function rs(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(ns)){let a=t[n];if(a!==void 0&&!r(a))throw new M(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(Me(t.mimeType)!==`image`)throw new M(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(rr(t)?t.uri:t.data))throw new M(`config`,`${r} needs its bytes or its uri`)})}function is(e,t){let n=t?.filter(e=>!A(de,e));if(n?.length)throw new M(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function as(e){let{greeting:t,resumed:n,sessionResumption:r}=e.live,i=`Profile ${e.id} live`;if(t!==void 0&&(typeof t!=`string`||!t.trim()))throw new M(`config`,`${i}.greeting must be a prompt; leave it out to wait`);if(!n)return;if(typeof n.prompt!=`string`||!n.prompt.trim())throw new M(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new M(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new M(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function os(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(ss(`${n}.triggerTokens`,r),ss(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new M(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function ss(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new M(`config`,`${e} must be a whole number above 0`)}function cs(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(ls(i,r),us(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new M(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new M(`config`,`${i}: a profile that compacts itself must be a text profile that takes text`);return}let a=e.get(r.profile);if(!a)throw new M(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new M(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function ls(e,t){if(t.maxTokens<=0)throw new M(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new M(`config`,`${e}: compactAt must be in (0, 1)`)}function us(e,t){if(t.previousExchanges<0)throw new M(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new M(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new M(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function ds(e,t){for(let n of H(t))if(e.get(n)?.type===`builtin`)throw new M(`config`,t.type===`host`?`Profile ${t.id} lists builtin '${n}' in tools.allow — type 'host' never runs a model`:`Profile ${t.id} lists builtin '${n}' in tools.allow — declare it on models.*.builtInTools instead`)}function fs(e,t){let n=ni(t)?.t2Loader;if(n){if(!H(t).includes(n))throw new M(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new M(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*ps(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function ms(e,t){for(let{modelId:n,id:r}of ps(t))if(e.get(r)?.type!==`builtin`)throw new M(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function hs(e){let t=e.type===`text`?e.outputs?.structured:void 0;return t?typeof t==`string`?[t]:[...new Set([...Object.values(t.map),t.fallback])]:[]}function gs(e,t){let n=hs(t).map(n=>{let r=e.find(n);if(!r)throw new M(`config`,`Profile ${t.id}: outputs.structured names '${n}', which is not a registered schema; register it before the profile`);return r}),r=t.type===`text`?t.outputs?.validation:void 0,i=Object.keys(r?.fields??{}),a=Object.keys(r?.items??{});if(!i.length&&!a.length)return;if(!n.length)throw new M(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Da(t.jsonSchema,e)));if(o.length)throw new M(`config`,`Profile ${t.id}: outputs.validation.items has ${o.join(`, `)}, which no structured schema reaches as a list with an items schema`);let s=i.filter(e=>!n.some(t=>Sa(t.jsonSchema,e)));if(s.length)throw new M(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function _s(e){let t=j(e)?.context;if(!t)return;let n=k;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new M(`config`,`Profile ${e.id}: inputs.context.from must list ${k.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new M(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function vs(e,t){if(!t)return;let{attachments:n,voice:r,maxFiles:i,maxBytes:a,maxTurnBytes:o,limitsByMime:s}=t,c={maxFiles:i,maxBytes:a,maxTurnBytes:o};if((n||r)&&Object.values(c).some(e=>e===void 0))throw new M(`config`,`Profile ${e} must set maxFiles, maxBytes, and maxTurnBytes`);for(let[e,t]of Object.entries(s??{}))c[`limitsByMime['${e}']`]=t;for(let[t,n]of Object.entries(c))if(n!==void 0&&!(Number.isInteger(n)&&n>0))throw new M(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function ys(e,t,n){let r=new Map,i=i=>{let a=Qo(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,se(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(ds(e,o),fs(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){ms(e,o),vs(o.id,j(o)),_s(o),gs(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&cs(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new M(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}var bs=`https://generativelanguage.googleapis.com/v1beta/models`;function xs(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Ss(e){let t;try{t=new URL(e.baseUrl)}catch{throw new M(`config`,`Enter a valid localhost URL.`)}if(![`http:`,`https:`].includes(t.protocol)||![`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)||t.username||t.password||t.search||t.hash)throw new M(`config`,`Use a localhost URL without credentials, query parameters or a fragment.`);return{baseUrl:t.href.replace(/\/$/,``),fetch:(e,n)=>new URL(e instanceof Request?e.url:String(e)).origin===t.origin?fetch(e,{...n,redirect:`error`,credentials:`omit`}):Promise.reject(new M(`blocked`,`Local requests must stay on the configured origin.`))}}var Cs=v({data:l(v({id:g().min(1)}))});async function ws(e,t){let n=Ss(e);if(!n?.fetch)throw new M(`config`,`Enter a local endpoint.`);let r=await n.fetch(`${n.baseUrl}/v1/models`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)throw new M(`network`,`Local model list returned HTTP ${r.status}.`);let i=Cs.safeParse(await r.json());if(!i.success)throw new M(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var Ts=`https://openrouter.ai/api/v1/models`,Es=`https://openrouter.ai/api/v1/embeddings/models`,Ds=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],Os=[{id:`liquid/lfm-2.5-embedding-350m:free`,label:`Liquid LFM 2.5 Embedding 350M (free)`},{id:`nvidia/nemotron-3-embed-1b:free`,label:`NVIDIA Nemotron 3 Embed 1B (free)`},{id:`nvidia/llama-nemotron-embed-vl-1b-v2:free`,label:`NVIDIA Llama Nemotron Embed VL 1B v2 (free)`}],ks={text:`text`,image:`image`,speech:`speech`,live:void 0,embedding:void 0},As=v({data:l(v({id:g().min(1),name:g().optional(),architecture:v({output_modalities:l(g()).optional()}).optional()}))}),js=v({data:l(v({id:g().min(1),name:g().optional()}))}),Ms=v({models:l(v({name:g().min(1),displayName:g().optional(),supportedGenerationMethods:l(g()).optional()})).optional(),nextPageToken:g().optional()}),Ns=5;async function Ps(e,t,n){let r=await fetch(t,{...n,redirect:`error`,credentials:`omit`});if(r.status===400||r.status===401||r.status===403)throw new M(`auth`,`${e} refused the key.`);if(!r.ok)throw new M(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Fs(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?Os:Ds];if(e===`openrouter`)return await Is(t,i,r);if(!i)throw new M(`auth`,`Choose a key to list Gemini models.`);return await Rs(t,i,r)}async function Is(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=js.safeParse(await Ps(`OpenRouter`,Es,r));if(!e.success)throw new M(`bad_response`,`OpenRouter returned an invalid embedding model list.`);return e.data.data.map(e=>({id:e.id,label:e.name??e.id}))}let i=ks[e];if(!i)return[];let a=As.safeParse(await Ps(`OpenRouter`,`${Ts}?output_modalities=${i}`,r));if(!a.success)throw new M(`bad_response`,`OpenRouter returned an invalid model list.`);return a.data.data.filter(e=>e.architecture?.output_modalities?.includes(i)??!0).map(e=>({id:e.id,label:e.name??e.id}))}var Ls={live:`bidiGenerateContent`,embedding:`embedContent`};async function Rs(e,t,n){let r=Ls[e]??`generateContent`,i=[],a;for(let e=0;e<Ns;e++){let e=new URL(bs);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=Ms.safeParse(await Ps(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new M(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function zs(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Bs(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}var Vs=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function Hs(e){return e.join(`,`)}function Us(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:Hs(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:e?.slots,context:e?.context}}function Ws(e){return{text:e.text,attachments:e.attachments?{accept:e.attachments.accept}:void 0,voice:e.voice?{accept:e.voice.accept}:void 0,maxFiles:e.maxFiles,maxBytes:e.maxBytes,maxTurnBytes:e.maxTurnBytes,limitsByMime:e.limitsByMime,slots:e.slots,context:e.context}}function Gs(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=fr({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:tr(Ws(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Ks(e){let t=globalThis.MediaRecorder;if(t===void 0)return;let n=e=>t.isTypeSupported(e),r=e=>e.find(n);return e?.length?r(Vs.filter(t=>A(e,t)))??e.find(n):r(Vs)}var qs=v({protocol:g(),provider:g(),apiId:g(),options:_(g(),u()).optional(),keySlot:g().optional(),fallbackKeySlot:g().optional(),efforts:_(g(),d(we)).optional(),defaultEffort:g().optional(),allowEffortSelect:o().optional(),summaries:o().optional(),maxOutputTokens:h().optional(),temperature:h().optional(),builtInTools:l(g()).optional(),compaction:v({maxTokens:h(),compactAt:h(),previousExchanges:h(),profile:g().optional(),timing:d(T),meter:d(ue).optional()}).optional(),limits:v({operationTimeoutMs:h().optional(),connectTimeoutMs:h().optional(),liveStepTimeoutMs:h().optional(),maxWireRecordBytes:h().optional(),maxWireResponseBytes:h().optional(),maxEventBytes:h().optional(),maxStepBytes:h().optional(),maxStepEvents:h().optional(),maxPendingToolCalls:h().optional()}).optional()}),Js=v({structured:i([g(),v({by:g(),map:_(g(),g()),fallback:g()}),p()]).optional(),streaming:v({mode:d(pe).optional(),streamThoughts:o().optional()}).optional()}),Ys=v(We(mt,()=>d(Re))),Xs=v(We($e,()=>Ys)),Zs=v({id:g(),label:g(),actions:Ys,names:l(g()),find:o()}),Qs=v({hosts:l(g()),fromTools:o()}),$s=v({quota:v({perDay:h()}).optional(),detect:Xs,patterns:a(d($e),v({theorem:o(),names:l(g())})).optional(),host:l(Zs).optional(),allow:v({ungiven_images:Qs,ungiven_links:Qs}),blockedReply:v({onBlock:d(re),maxRetries:h()})}),ec=i([o(),v({theorem:o(),host:o()})]),tc=v({record:o(),writeTo:i([c(!1),g()]).optional(),sampleRate:h(),include:v({upstreamLog:o(),outboundWire:o(),evidenceRaw:o(),usage:o(),guardrailDecisions:o(),guardrailMatchPreview:o()}),scrub:v({sensitive:ec,injection:ec,canary:ec}),resource:Kt,retainForDays:h(),rotateAfterMiB:h(),hasOnWriteError:o()}),nc=v({text:o(),attachments:v({accept:l(g()),acceptAttr:g()}).nullable(),voice:v({accept:l(g())}).nullable(),maxFiles:h().optional(),maxBytes:h().optional(),maxTurnBytes:h().optional(),limitsByMime:_(g(),h()).optional(),slots:_(g(),l(g())).optional(),context:v({from:l(d(k)),maxChars:h()}).optional()}),rc=v({allowContinue:l(d(Ee)).optional(),autoContinue:l(d(Ee)).optional(),maxContinues:h().optional()}),ic=v({resumption:rc.optional()}),ac=v({allow:l(g()),page:l(g()),t2Loader:g().optional(),parallel:o().optional()}),oc={providerContinuation:v({history:d([`host`,`stateless`,`provider`]).optional()}).optional(),id:g(),models:_(g(),qs),defaultModel:g(),allowModelSelect:o().optional(),maxSteps:h().optional(),labels:a(d(ft),g()),guardrails:$s.optional(),observability:tc.optional()},sc=i([g(),l(i([g(),t({private:g().min(1)})])).min(1).readonly()]),cc=v({handle:g(),system:sc.optional(),systemByRole:_(g(),sc).optional()}),G=f(`type`,[v({...oc,type:c(`text`),identity:cc,outputs:Js.optional(),inputs:nc,tools:ac,turnBehaviour:v({resumption:rc.optional(),allowSteering:o().optional(),atStepLimit:d(ve).optional()}).optional(),canStop:c(!0),allowSteering:o()}),v({...oc,type:c(`image`),identity:cc,outputs:Js.optional(),image:v({aspectRatio:g().optional(),resolution:g().optional(),mimeType:g().optional(),quality:g().optional(),background:g().optional(),n:h().int().min(1).optional(),seed:h().int().optional(),outputCompression:h().int().min(0).max(100).optional(),references:l(i([v({mimeType:g(),data:g(),name:g().optional()}),v({mimeType:g(),uri:g(),name:g().optional()})])).optional(),includeText:o().optional()}),inputs:nc,tools:ac,turnBehaviour:ic.optional(),canStop:c(!0)}),v({...oc,type:c(`speech`),identity:v({handle:g()}),outputs:Js.optional(),speech:v({voice:g().optional(),style:g().optional(),speed:h().optional(),format:d(Oe).optional()}),inputs:nc,turnBehaviour:ic.optional(),canStop:c(!0)}),v({...oc,type:c(`live`),identity:cc,inputs:nc.pick({slots:!0,context:!0}).optional(),live:v({ingress:v({audio:o().optional(),video:o().optional(),text:o().optional()}).optional(),voice:g().optional(),vad:v({activityHandling:d(fe).optional(),startSensitivity:d(y).optional(),endSensitivity:d(oe).optional(),prefixPaddingMs:h().optional(),silenceDurationMs:h().optional()}).optional(),sessionResumption:o().optional(),contextCompression:v({triggerTokens:h().optional(),slidingWindow:v({targetTokens:h().optional()})}).optional(),transcription:v({input:o().optional(),output:o().optional()}).optional()}),tools:ac.pick({allow:!0,page:!0}),turnBehaviour:v({allowSteering:o().optional()}).optional()})]);function lc(e){let t=ge(e),{sources:n,host:r,...i}=t.detect;return{quota:t.quota,detect:i,...n?{patterns:Object.fromEntries(Object.entries(n).map(([e,{theorem:t,matchers:n}])=>[e,{theorem:t,names:n.map(({name:e})=>e)}]))}:{},...r?{host:r.map(({id:e,label:t,actions:n,matchers:r,find:i})=>({id:e,label:t,actions:n,names:r.map(({name:e})=>e),find:!!i}))}:{},allow:{ungiven_images:uc(t.allow.ungiven_images),ungiven_links:uc(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function uc(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function dc(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function fc(e){if(!e)return;let t=Ut(e);return{record:t.record,writeTo:dc(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function pc(e){let{greeting:t,resumed:n,...r}=e??{};return r}function mc(e,t){let n=e.tools.filter(e=>`type`in e&&e.type===`function`&&e.answeredBy===`page`).map(e=>e.name);if(t){let e=ni(t),r=ri(t);return{allow:[...H(t)],page:n,...e?.t2Loader?{t2Loader:e.t2Loader}:{},...r===void 0?{}:{parallel:r}}}return{allow:e.tools.filter(e=>!(`type`in e&&e.type===`builtin`)).map(e=>e.name),page:n}}function hc({allow:e,page:t}){return{allow:e,page:t}}function gc(e,t){let n=Us(e.inputs),r=t?.identity??{handle:e.handle},i=t?lc(t.guardrails):void 0,a=t?fc(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:He(t?.labels)};switch(e.type){case`text`:return G.parse({...s,type:`text`,inputs:n,tools:mc(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||De(t)});case`image`:return G.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:mc(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return G.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`live`:return G.parse({...s,type:`live`,live:pc(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:hc(mc(e,t))});default:return e.type}}function _c(e,t){let n=Zi(e,`interfaceFromProfile`);return gc(ua(t,n),n)}function vc(e){return s(t=>Le.safeParse(e(t)).success)}var yc=[`running`,`gate`,`complete`,`error`,`cancel`],bc=s(e=>{let t=Le.safeParse({type:`tool`,tool:e});if(!t.success||t.data.type!==`tool`||!(`phase`in t.data.tool))return!1;let{phase:n}=t.data.tool;return yc.some(e=>e===n)}),xc=_(g(),n()),Sc=v({operationId:g().optional(),name:g(),callId:g(),arguments:xc,draft:g().optional(),reasoning:l(C).optional(),stepId:g().optional(),edited:v({from:xc,to:xc}).optional(),activity:g().optional(),activityPast:g().optional(),outputDraft:g().optional(),state:bc.optional(),startedAt:h().optional(),endedAt:h().optional(),artifacts:l(n())}),Cc=v({kind:d(Te),native:g().optional()}),K={id:g()},q=f(`kind`,[v({...K,kind:c(`user-text`),text:g()}),v({...K,kind:d([`user-attachment`,`user-voice`]),name:g(),mimeType:g(),sizeBytes:h(),data:g().optional()}),v({...K,kind:c(`thought`),text:g()}),v({...K,kind:c(`text`),text:g()}),v({...K,kind:c(`tool`),tool:Sc}),v({...K,kind:c(`structured`),value:n(),draft:g().optional()}),v({...K,kind:c(`media`),mimeType:g(),data:g().optional(),url:g().optional(),previewUrl:g().optional()}),v({...K,kind:c(`grounding`),grounding:vc(e=>({type:`grounding`,grounding:e}))}),v({...K,kind:c(`citation`),sources:vc(e=>({type:`citation`,sources:e})),callId:g().optional()}),v({...K,kind:c(`evidence`),evidence:vc(e=>({type:`evidence`,evidence:e}))}),v({...K,kind:c(`guardrail`),guardrail:be}),v({...K,kind:c(`error`),message:g()}),v({...K,kind:c(`turn-done`),stop:Cc.optional(),tokens:vc(e=>({type:`tokens`,tokens:e})).optional(),interactionId:g().optional(),compaction:o().optional(),workedMs:h().optional(),endedAt:h().optional()})]),wc=v({type:g()});function Tc(e,t){return Object.hasOwn(e,t)}function Ec(e,t){return e.map(e=>{let n=[...t,...e.path],r=`${n.map(String).join(`.`)||`(root)`} ${e.code}`;return e.code!==`invalid_union`||e.errors.length===0?r:`${r} [${e.errors.map(e=>Ec(e,n)).join(` | `)}]`}).join(`; `)}function Dc(e){return Ec(e.issues,[])}function Oc(e,t){return new M(`bad_response`,`${e} failed its wire check: ${Dc(t)}`)}function J(e,t,n){let r=e.safeParse(t);if(!r.success)throw Oc(n,r.error);return r.data}function kc(e){return{type:`malformed`,error:new M(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Ac(e,t){let n=wc.safeParse(t);if(!n.success)return kc(`a line without a kind failed its wire check: ${Dc(n.error)}`);let{type:r}=n.data;if(!Tc(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:kc(`a '${r}' line failed its wire check: ${Dc(i.error)}`)}function jc(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Mc(e,t){let n=jc(t);return n?Ac(e,n.value):kc(`a line is not JSON`)}function Nc(e){let t=jc(e);if(!t)throw new M(`bad_response`,`a line is not JSON`);return t.value}var Pc=v({name:g(),mimeType:g(),data:g()}),Fc=v({slots:_(g(),g()).optional(),context:n().optional(),text:g().optional(),attachments:l(Pc).optional(),voice:l(Pc).optional()}),Ic=v({gateKind:d(xe).optional(),sessionPermissions:l(g()).optional(),name:g().optional(),input:n().optional(),snapshot:E.optional(),promoted:l(g()).optional(),model:g().optional(),effort:g().optional()}),Y=g().trim().min(1);v({input:Fc,conversation:g().min(1).optional(),model:g().optional(),effort:g().optional(),turnId:Y.optional(),abandon:l(ye).min(1).optional(),replay:Ic.pick({sessionPermissions:!0}).optional(),transcript:l(q).optional()});var Lc=[`approve`,`deny`],Rc=i([t({unanswered:c(!0)}),t({output:n()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);v({gateId:g().min(1),operationId:g().min(1).max(256),decision:d(Lc),input:n().optional(),secret:g().optional(),page:Rc.optional(),conversation:g().min(1).optional(),turnId:Y.optional(),replay:Ic.optional()}),v({turnId:Y,id:Y,inject:l(S).min(1)}),v({turnId:Y});var zc=v({type:c(`conversation`),ref:g().min(1),posted:c(!0).optional()}),Bc={...x,conversation:zc},Vc=v({transcript:l(q),paused:v({events:l(Le),blocks:l(q)}).optional()});v({conversation:g().min(1)}),v({conversation:g().min(1),at:h().int().min(-1)}),v({blocks:l(q)});var Hc=v({conversation:g().min(1),view:Vc}),Uc=class extends Error{kind;publicMessage;internalMessage;copy;constructor(e,t,n,r){super(n??t??e),this.name=`TheoremStreamError`,this.kind=e,t&&(this.publicMessage=t),n&&(this.internalMessage=n),r&&(this.copy=r)}};function Wc(e){return e instanceof Uc}function Gc(e){return e?.trim()||void 0}var Kc=v({error:g().optional(),errorKind:ie.optional(),errorCopy:te.optional(),errorInternal:g().optional()}),qc=Kc;function X(e,t){let n=Gc(e.error),r=Gc(e.errorInternal);return new Uc(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function Jc(e){return!Wc(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function Yc(e,t){let n=Mc(e,t);if(n.type===`error`)throw X(Kc.parse(n),`internal`);return n}function Xc(e,t,n){let r=e.split(`
7
- `),i=r.pop()??``;for(let e of r)e.trim()&&n(Yc(t,e));return i}async function Zc(e,t,n,r){if(!e.body)throw new M(`bad_response`,`stream reply has no body`);let i=e.body.getReader(),a=new TextDecoder,o=``,s=()=>{i.cancel()};r?.addEventListener(`abort`,s,{once:!0});try{for(;;){qe(r);let{done:e,value:s}=await i.read();if(e)break;o=Xc(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(Yc(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function Qc(e){let t=typeof e.headers==`function`?await e.headers():e.headers,n=new Headers(t);return n.set(`content-type`,`application/json`),n}async function $c(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return X({errorInternal:`HTTP ${String(e.status)}`},st(e.status))}let i=Kc.safeParse(r);return i.success?X({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},st(e.status)):new M(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function el(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await Qc(n),credentials:n.credentials??`same-origin`})}catch(e){throw kt(e)?e:new M(`network`,ct(e),{cause:e})}}async function tl(e,t,n,r,i={}){await Zc(await nl(e,t,i),n,r,i.signal)}async function nl(e,t,n){let r=await el(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await $c(r);return r}async function Z(e,t,n={}){await nl(e,t,n)}async function Q(e,t,n={}){let r=await el(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await $c(r,t.failed);return Nc(await r.text())}async function rl(e,t,n={}){let{signal:r,...i}=n;return J(Vc,await Q(e,{body:t,signal:r},i),`the conversation`)}async function il(e,t,n,r){let{signal:i,...a}=n;return J(Hc,await Q(e,{body:t,signal:i},a),r)}function al(e,t,n={}){return il(e,t,n,`the rewound conversation`)}function ol(e,t,n={}){return il(e,t,n,`the started conversation`)}function sl(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var cl=v({interface:G});function ll(e={}){let t=sl(e.endpoint??`/api/theorem`);return{async describe(n){let r=await el(t,{method:`GET`,signal:n},e);if(!r.ok)throw await $c(r);return J(cl,Nc(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>tl(`${t}/turn`,r,Bc,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>tl(`${t}/invoke`,r,Bc,i,{...e,signal:a}),conversation:(n,r)=>rl(`${t}/conversation`,n,{...e,signal:r}),rewind:(n,r)=>al(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>Z(`${t}/page-result`,n,{...e,signal:r}),steer:n=>Z(`${t}/steer`,n,e),stop:n=>Z(`${t}/stop`,n,e)}}function ul(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?ul(n[0],t):t}function dl(e,t,n){return{type:`decision`,identity:{handle:e.identity.handle},contract:e.decision.contract,...e.inputs.maxStateBytes===void 0?{}:{maxStateBytes:e.inputs.maxStateBytes},questions:Object.entries(t).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>ul(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}})),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:Ut(e.observability).record}}:{}}}function fl(e,t){let n=Object.keys(t??{}).find(t=>e&&Object.hasOwn(e,t));if(n!==void 0)throw new M(`request`,`the image ${n} is the host's, so the page's needs another name`);let r={...e,...t};return Object.keys(r).length>0?r:void 0}var $=h().min(0).max(1),pl=_(g(),$),ml=f(`type`,[v({type:c(`choice`),choice:g(),confidence:$,probabilities:pl}),v({type:c(`noul`),noul:$}),v({type:c(`box`),box:v({top:$,bottom:$,left:$,right:$}),confidence:$}),v({type:c(`score`),score:h().nonnegative(),confidence:$,legend:_(g(),g().min(1)),probabilities:pl})]),hl=v({result:v({model:g().min(1),answers:_(g(),ml),usage:v({inputTokens:h().int().nonnegative(),outputTokens:h().int().nonnegative(),costUsd:h().nonnegative().optional()}).optional()}),traces:l(Gt).optional()}),gl=new WeakMap;function _l(e,t){return t.length>0&&typeof e==`object`&&e&&gl.set(e,t),e}function vl(e){return typeof e==`object`&&!!e&&gl.get(e)||[]}var yl=v({traces:l(Gt)});async function bl(e,t,n,r,i){let a=[],o=e=>{let t=yl.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Q(e,{body:t,signal:n,failed:o},r))}catch(e){throw _l(e,a)}}function xl(e,t,n,r={}){return bl(e,t,n,r,Sl)}function Sl(e){return J(hl,e,`the decision`)}var Cl=v({interface:v({type:c(`decision`),identity:v({handle:g()}),contract:g(),maxStateBytes:h().optional(),questions:l(v({id:g(),type:d([`choice`,`noul`,`score`,`box`]),labels:l(g()),image:g().optional()})),images:_(g(),v({mimeType:d([`image/png`,`image/jpeg`]),data:g()})).optional(),observability:v({record:o()}).optional()})});function wl(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return J(Cl,await Q(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i)=>xl(`${t}/decide`,{state:n,...i?{assets:i}:{}},r,e)}}function Tl(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:ke(t.inputSchema),output:ke(t.outputSchema)};if(t.type===`http`){e.register({...i,type:`http`,endpoint:t.endpoint,method:t.method,headers:t.headers,mapping:t.mapping,auth:t.auth,maxResponseBytes:t.maxResponseBytes});return}if(t.type===`mcp`){e.register({...i,type:`mcp`,serverUrl:t.serverUrl,mcpToolName:t.mcpToolName,headers:t.headers,auth:t.auth,maxResponseBytes:t.maxResponseBytes,session:t.session});return}if(t.answeredBy===`page`){e.register({...i,type:`function`,answeredBy:`page`});return}let a=t.stubResponse||!Object.hasOwn(n,t.name)?void 0:n[t.name],o=t.stubResponse??qt(t.outputSchema);e.register({...i,type:`function`,handler:a?e=>{try{return Promise.resolve(a(e))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}}:()=>Promise.resolve(o)})}function El(e,t,n){e.registerMany(w);for(let r of t)Tl(e,r,n)}function Dl(e,t,n,r,i){return El(e.tools,n,i),r&&t.type!==`live`&&e.schemas.register(r.id,r.spec),e.profiles.register(t),t}function Ol(e){if(e.type===`error`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,error:t}}if(e.type===`session`&&e.session.kind===`ended`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,session:{...e.session,message:t}}}if(e.type===`tool`&&e.tool.phase===`error`&&e.tool.failure.error!==void 0){let{failure:t}=e.tool;return{...e,tool:{...e.tool,failure:{...t,error:t.message}}}}return e}function kl(e){if(e.type!==`error`&&e.type!==`session`&&e.type!==`tool`||e.errorInternal===void 0)return e;let{errorInternal:t,...n}=e;return n}function Al(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function jl(e){if(e.type!==`guardrail`||!e.guardrail?.errorInternal)return e;let{errorInternal:t,...n}=e.guardrail;return{...e,guardrail:n}}function Ml(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function Nl(e,t){let n=t?.reader===`builder`?Ol(e):Al(jl(kl(e)));return t?.includeEvidenceRaw||(n=Ml(n)),n=Xt(n,!1),n}function Pl(e,t){return e.map(e=>Nl(e,t))}function Fl(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=Nl(nt(Ze(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var Il={reader:`builder`};function Ll(e){return e.mode===`demo`?{reader:`visitor`}:Il}export{Va as $,Mc as A,qr as At,zs as B,gr as Bt,qc as C,ri as Ct,tl as D,Zr as Dt,Z as E,Xr as Et,Gs as F,Wr as Ft,ro as G,Kn as Gt,ys as H,Jn as Ht,xs as I,Ur as It,to as J,Hn as Jt,no as K,V as Kt,ws as L,Mr as Lt,q as M,Hr as Mt,_c as N,Lr as Nt,J as O,Qr as Ot,Ks as P,Vr as Pt,Oa as Q,Xt as Qt,Fs as R,Tr as Rt,X as S,H as St,Jc as T,vi as Tt,Qo as U,qn as Ut,Bs as V,_r as Vt,_o as W,Gn as Wt,Ja as X,Yt as Xt,qa as Y,en as Yt,Ya as Z,Jt as Zt,ll as _,Ti as _t,Pl as a,Ea as at,al as b,_i as bt,wl as c,Da as ct,vl as d,Qi as dt,La as et,xl as f,da as ft,Uc as g,Hi as gt,Bc as h,Wi as ht,Nl as i,Ia as it,Ac as j,Gr as jt,Dc as k,Yr as kt,fl as l,wa as lt,_l as m,Ki as mt,Ll as n,Ra as nt,Dl as o,xa as ot,bl as p,ca as pt,eo as q,Un as qt,Fl as r,Wa as rt,El as s,Ca as st,Il as t,Ua as tt,dl as u,Ta as ut,rl as v,mi as vt,Wc as w,ni as wt,ol as x,pi as xt,Q as y,hi as yt,Ss as z,hr as zt};
6
+ `)}:null}function Ri(e){let t=e.input?.context??{};return[...k].reverse().filter(e=>t[e]!==void 0).map(e=>kt(e,Ir(t[e])))}function zi(e,t){if(t.continueFrom&&ee.includes(e.type)){if(t.input?.text)throw new M(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return N(`continue.instruction`,{},e.labels)}}function Bi(e){return e.type===`image`&&e.image.references?Ii(e.image.references):[]}function Vi(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Bi(e),...Ii(n),...Ii(r)]}function Hi(e,t){let n=[],r=Li(e,t);return r&&n.push(r),n.push(...Vi(e,t)),n}function Ui(e,t){let n=t.input?.slots;if(!n)return;let r=j(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new M(`request`,`Profile ${e.id} has no slot '${t}'`);if(!n.includes(i))throw new M(`request`,`Profile ${e.id}: slot '${t}' takes ${n.join(`, `)}, not '${i}'`)}}function Wi(e,t){let n=t.input?.context;if(!n)return;let r=j(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!k.includes(t)||!r?.from.some(e=>e===t))throw new M(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Ir(i).length>r.maxChars)throw new M(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Gi=/\{([A-Za-z_][\w-]*)\}/g;function Ki(e,t,n,r){let i=j(e)?.slots;return i?t.replace(Gi,(t,a)=>{if(!Object.hasOwn(i,a))return t;let o=n&&Object.hasOwn(n,a)?n[a]:void 0;if(o===void 0)throw new M(`request`,`Profile ${e.id}: ${r} uses slot '${a}', and the request chose no value for it`);return o}):t}function qi(e,t){let{handle:n}=e.identity,r=e.type===`speech`?void 0:e.identity.systemByRole;return t&&r&&Object.hasOwn(r,t)?t:n}function Ji(e,t,n){if(e.type===`speech`)return[];let{systemByRole:r,system:i}=e.identity,a=r?.[t]||i||``;return a?Or(Dr(a,`Profile ${e.id} identity.system`,t=>Ki(e,t,n,`identity.system`))):[]}function Yi(e,t){return kr([Ji(e,qi(e,t.input?.role),t.input?.slots),t.system===void 0?[]:Or(t.system)])}function Xi(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function Zi(e,t){if(Xi(e))return e;throw e.type===`host`?new M(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new M(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new M(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function Qi(e,t){if(t){if(!e.allowModelSelect)throw new M(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new M(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function $i(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new M(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new M(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new M(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function ea(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function ta(e,t){if(e.type===`live`)return null;let n=e.outputs?.structured;if(!n)return null;if(typeof n==`string`)return n;let r=t?.[n.by];if(r){let e=n.map[r];if(e)return e}return n.fallback}function na(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function ra(e,t){return e.type===`live`?`live`:`turn`}function ia(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new M(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=O(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new M(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new M(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new M(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function aa(e,t){return V(ge(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function oa(e){let{detect:t}=ge(e.guardrails);return e.type!==`speech`&&Et(t,`canary_leak`)?zt():``}function sa(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new M(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function ca(e,t,n){let r=Zi(e.profiles.get(t.profile),`resolveTurn`);Ui(r,t),Wi(r,t);let i=Wr(t,r),a=i.input??{};ia(r,i);let o=n??Qi(r,i.model),s=Se(r,o),c=fi(e.tools,r,i,o),l=c.builtins,u=ta(r,a.slots);if(Ai(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new M(`config`,`Profile ${r.id}: a structured turn answers through '${Xr}', so no tool of its own may take that name`);ji(r,i);let d=sa(r,o,s,i.builtInArgs),f=ra(r,s);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,stream:na(r),thinking:$i(r,s,o,i.effort),summaries:ea(s),maxOutputTokens:s.maxOutputTokens,temperature:s.temperature,builtins:l,builtInArgs:d,sessionId:i.sessionId,tools:c,sessionPermissions:i.sessionPermissions,execution:i.execution,pageExecution:i.pageExecution,history:a.history,maxSteps:r.maxSteps??20,structured:u?{id:u,jsonSchema:e.schemas.get(u).jsonSchema}:null,image:Pi(r),speech:Mi(r,i),live:r.type===`live`?aa(r.live,r.guardrails):void 0,input:Hi(r,i),canary:oa(r),resolvedSystem:Yi(r,i),host:i.host}}}function la(e){return e.type===`image`?e.image:null}function ua(e,t){let n=Zi(t,`projectProfile`),{identity:r}=n,i=j(n)??null,a=n.type===`live`?null:n.outputs??null;return{id:n.id,type:n.type,handle:r.handle,models:n.models,defaultModel:n.defaultModel,allowModelSelect:n.allowModelSelect,maxSteps:n.maxSteps,tools:Ci(e,n),inputs:i,outputs:a,image:la(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function da(e,t){return ua(e.tools,e.profiles.get(t))}function fa(e){return e==null}function U(e){return fa(e)||typeof e!=`object`||Array.isArray(e)?null:e}function pa(e){let t=U(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function ma(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function ha(e){let t=e.properties;return U(t)??{}}function ga(e,t){return e?`${e}.${t}`:t}function _a(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function va(e,t,n,r,i){if(!n)return;let a=await n(t,r);a.isValid||i.push({path:e,error:a.error||a.finding||`Validation failed for '${e}'`})}async function ya(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(fa(r)){i&&_a(t,s);return}await va(t,r,a?.[t],o,s);let c=pa(n),l=c?U(r):null;c&&l&&await ba(c,l,t,a,o,s)}async function ba(e,t,n,r,i,a){let o=ha(e),s=new Set(ma(e)),c=new Set([...Object.keys(o),...s]),l=U(t);for(let e of c)await ya({path:ga(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function xa(e,t,n,r){let i=pa(e);if(!i)throw new M(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!U(t)){for(let e of ma(i))_a(e,a);return a}return await ba(i,t,``,n,r,a),a}function Sa(e,t){let n=e;for(let e of t.split(`.`)){let t=pa(n);if(!t)return!1;let r=ha(t);if(!Object.hasOwn(r,e)&&!ma(t).includes(e))return!1;n=r[e]}return!0}function Ca(e){return e.map(e=>e.error).join(`; `)}function wa(e,t){let n=e;for(let e of t.split(`.`))n=U(n)?.[e];return n}function Ta(e,t,n){let[r,...i]=t.split(`.`),a=U(e)??{};return r===void 0?e:{...a,[r]:i.length?Ta(a[r],i.join(`.`),n):n}}async function Ea(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=wa(e,i);if(Array.isArray(t))for(let[e,o]of t.entries()){let t=await a.check(o,n);t.isValid||r.push({path:i,index:e,item:o,reason:t.error||t.finding||`Validation failed for '${i}'`,onFail:a.onFail})}}return r}function Da(e,t){let n=e;for(let e of t.split(`.`)){let t=pa(n);if(!t)return;n=ha(t)[e]}let r=U(n);if(r?.type===`array`)return U(r.items)??void 0}var Oa=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},ka=new Set([`text`,`image`,`speech`]),Aa=g().regex(/\S/),ja=t({mimeType:g(),data:m(),name:g().optional()}),Ma=t({mimeType:g(),uri:g(),name:g().optional()}),Na=t({voice:g().optional(),style:g().optional(),speed:h().positive().optional()});function Pa(e){return t(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,d(t).optional()])))}var Fa=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function Ia(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function La(e,n){let{inputs:r}=e,a={text:Aa};r?.attachments&&(a.attachments=l(i([ja,Ma])).optional()),r?.voice&&(a.voice=l(ja).optional()),r?.slots&&(a.slots=Pa(r.slots).optional()),e.type===`speech`&&(a.speech=Na.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new M(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new M(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(Fa.has(e))throw new M(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return t(a)}var Ra=v({text:g().optional(),structured:n().optional(),removed:l(v({path:g(),reason:g(),item:n()})).optional(),parts:l(ne).optional(),sources:l(D).optional()});function za(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function Ba(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Va(e,t){if(!ka.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!za(e))return`it does not take text`;for(let n of H(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(Ba(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Ha(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new M(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new M(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=Va(a,n);if(o)throw new M(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ua(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return H(e).length===0&&!t?`local`:`delegated`}function Wa(e){let t=ae(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ce(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ga(e,t,n){return{...e,type:`agent`,input:t,output:Ra,sources:e=>e.sources??[],...n}}var Ka=/^[\x21-\x7E]{1,256}$/;function qa(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function Ja(e){return e!==null&&Ka.test(e)}async function Ya(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function Xa(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function Za(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&Qa(i,`${n}.properties.${t}`,r)}function Qa(e,t,n){if(!Xa(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Za(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&Qa(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&Qa(e,`${t}.${r}[${i}]`,n)})}}function $a(e,t){let n=[];if(Qa(e,`$`,n),n.length>0)throw new M(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function eo(e,t=`output`){let n=r(e,{target:`draft-7`,io:t});return delete n.$schema,n.type||=`object`,n}function to(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(to);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=to(e[n]));return t}function no(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new M(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}var ro=class{value;constructor(e){this.value=e}};function io(e){return new ro(e)}function ao(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return io(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(N(`tool.page_timed_out`,{},i)):Error(N(`tool.page_no_answer`,{tool:e},i))}}function oo(e){let t=eo(e.input,`input`);$a(t,`input`);let n=eo(e.output,`output`);$a(n,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?Pe(n,r[t]):void 0;if(i)throw new M(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:t,outputSchema:n}}function so(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new M(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function co(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new M(`config`,`Tool "${e}" auth.queryParam ${r}`)}function lo(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new M(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function uo(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new M(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function W(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new M(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function fo(e){W(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(W(e.name,`imageLimits.count`,t.count),W(e.name,`imageLimits.bytes`,t.bytes),W(e.name,`imageLimits.totalBytes`,t.totalBytes),uo(e.name,t.timeoutMs))}function po(e){return no(e.endpoint),so(e.name,e.auth),co(e.name,e.auth,e.mapping?.queryParams),lo(e.name,e.limit),uo(e.name,e.timeoutMs),fo(e),{...e,type:`http`,...oo(e)}}function mo(e){return so(e.name,e.auth),co(e.name,e.auth),fo(e),W(e.name,`session.idleMs`,e.session?.idleMs),W(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...oo(e)}}function ho(e){so(e.name,e.auth),co(e.name,e.auth);let t=e.answeredBy===`page`?ao(e.name):e.handler;if(typeof t!=`function`)throw new M(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...oo(e)}}function go(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=Ha(e,t,n),i=j(r),a=La({type:r.type,...i?{inputs:i}:{}},e);return Ga(e,a,oo({...e,input:a,output:Ra}))}return e.type===`http`?po(e):e.type===`mcp`?mo(e):ho(e)}function _o(e=()=>void 0){let t=new Map,n=qa(),r=e=>t.get(e),i=n=>{let i=go(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new M(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}function vo(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new M(`config`,N(`provider.binding_identity`))}function yo(e){Oo(e.id,e.models),Xo(e.id,e.observability),vs(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))Ao(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:ko(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function bo(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new M(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function xo(e,t,n){if(bo(e,t,n,b),vo(e,t,n,`decision`),`retry`in n)throw new M(`config`,`Profile ${e} model '${t}': a decision binding takes no retry; a decision retries only a transient failure, by the kernel's rule`);if(n.timeoutMs!==void 0&&(!Number.isFinite(n.timeoutMs)||n.timeoutMs<=0))throw new M(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function So(e){let t=e.models?Gr(e.models):void 0;if(!t)throw new M(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);xo(e.id,t,e.models[t])}function Co(e){if(e.inputs.state!==`json`)throw new M(`config`,`Profile ${e.id}: decision inputs.state must be 'json'`);let t=e.inputs.maxStateBytes;if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw new M(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new M(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function wo(e){return So(e),Co(e),Xo(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function To(e){return e===void 0?{}:{parallel:e}}function Eo(e){return Do(e.id,e.tools),Xo(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...To(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Do(e,t){if(!Array.isArray(t.allow))throw new M(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function Oo(e,t){if(Object.keys(t).length===0)throw new M(`config`,`Profile ${e} must declare at least one model`)}function ko(e,t){let n=t.defaultModel??Gr(t.models);if(!n)throw new M(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new M(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function Ao(e,t,n){jo(e,t,n),bo(e,t,n,Ae),jo(e,t,n)}function jo(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new M(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!we.includes(i))throw new M(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${we.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new M(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new M(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new M(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function Mo(e){return{providerContinuation:e.providerContinuation?Fe.parse(e.providerContinuation):{},models:e.models,defaultModel:ko(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function No(e,t,n){if(n?.length){for(let r of n)if(!le(r))throw new M(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function Po(e,t){t&&(No(e,`allowContinue`,t.allowContinue),No(e,`autoContinue`,t.autoContinue))}function Fo(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Io(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>Fo(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var Lo=Object.entries(je).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Ro(e){if(!Fo(e))throw new M(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new M(`config`,`Profile definition must set id`);if(!Ce.find(t=>t===e.type))throw new M(`config`,`Profile ${t}: type must be one of ${Ce.join(`, `)}`)}function zo(e){let t=e.identity?.handle,n=[[`id`,e.id,64],[`identity.handle`,typeof t==`string`?t:``,32]];for(let[t,r,i]of n)if(!(Array.from(r).length<=i))throw new M(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function Bo(e){let{id:t,type:n}=e,r=e;for(let[e,i]of Lo){if(i&&!i.includes(n))continue;let a=Ie(e),o=Io(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!Fo(e))return!1;let t=e[s];return t==null||t===``}))throw new M(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Vo(e){let{id:t,type:n}=e;if(n!==`live`&&me(`inputs`).includes(n)&&e.inputs==null)throw new M(`config`,`Profile ${t}: type '${n}' must set inputs`)}function Ho(e){let[t]=Ne(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new M(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Uo(e,t){let n=t.turnBehaviour;Po(e,n?.resumption)}function Wo(e,t){let n=t=>new M(`config`,`Profile ${e}: ${t}`),r=t?.maxRetries;if(r!==void 0&&(!Number.isInteger(r)||r<0))throw n(`outputs.validation.maxRetries must be a non-negative integer`)}function Go(e,t){let n=t=>new M(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Ko.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Ko.join(`, `)}`);Jo(t?.blockedReply,n)}var Ko=[`quota`,`detect`,`blockedReply`,`network`,`taint`],qo=[`onBlock`,`maxRetries`];function Jo(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!qo.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!re.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${re.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function Yo(e){let t=e.guardrails?.detect,n=e.type===`host`?Pt(`guardrails.detect`,t,Rt):Pt(`guardrails.detect`,t);if(n!==void 0)throw new M(`config`,`Profile ${e.id}: ${n}`)}function Xo(e,t){try{let n=Ut(t);if(!Number.isFinite(n.retainForDays))throw new M(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new M(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof M&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new M(Be(t),`Profile ${e}: ${n}`,{cause:t})}}function Zo(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`embedding`)return;let{system:t,systemByRole:n}=e.identity;t!==void 0&&Er(t,`Profile ${e.id} identity.system`);for(let[t,r]of Object.entries(n??{}))Er(r,`Profile ${e.id} identity.systemByRole.${t}`)}function Qo(e){Ro(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new M(`config`,N(`provider.profile_configuration`,{profile:e.id,field:t}));if(Ho(e),Vo(e),Bo(e),zo(e),e.labels&&vt(e.labels,`Profile ${e.id}`),Zo(e),Yo(e),e.type===`host`)return Eo(e);if(e.type===`decision`)return wo(e);if(e.type===`embedding`)return yo(e);Oo(e.id,e.models),Uo(e.id,e),Go(e.id,e.guardrails),e.type===`text`&&Wo(e.id,e.outputs?.validation),Xo(e.id,e.observability);for(let[t,n]of Object.entries(e.models))Ao(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,system:e.identity.system,systemByRole:e.identity.systemByRole},n=e.guardrails,r=e.observability,i=e.labels,a=Mo(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},is(o.id,o.inputs.attachments?.accept),rs(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs,tools:{allow:e.tools.allow,...To(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Wt(o),os(o.id,o.live.contextCompression),as(o);break;default:throw new M(`config`,`Unknown profile type '${String(e)}'`)}return ts(o),$o(o),es(o),o}function $o(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new M(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function es(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new M(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function ts(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=j(e)?.slots?.[t.by];if(!n)throw new M(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=Object.keys(t.map).filter(e=>!n.includes(e));if(r.length)throw new M(`config`,`Profile ${e.id}: outputs.structured.map maps ${r.join(`, `)}, not a choice of slot '${t.by}'`)}var ns={n:{ok:e=>Number.isInteger(e)&&e>=1,rule:`a whole number of 1 or more`},seed:{ok:Number.isInteger,rule:`a whole number`},outputCompression:{ok:e=>Number.isInteger(e)&&e>=0&&e<=100,rule:`a whole number from 0 to 100`}};function rs(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(ns)){let a=t[n];if(a!==void 0&&!r(a))throw new M(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(Me(t.mimeType)!==`image`)throw new M(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(rr(t)?t.uri:t.data))throw new M(`config`,`${r} needs its bytes or its uri`)})}function is(e,t){let n=t?.filter(e=>!A(de,e));if(n?.length)throw new M(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function as(e){let{greeting:t,resumed:n,sessionResumption:r}=e.live,i=`Profile ${e.id} live`;if(t!==void 0&&(typeof t!=`string`||!t.trim()))throw new M(`config`,`${i}.greeting must be a prompt; leave it out to wait`);if(!n)return;if(typeof n.prompt!=`string`||!n.prompt.trim())throw new M(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new M(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new M(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function os(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(ss(`${n}.triggerTokens`,r),ss(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new M(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function ss(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new M(`config`,`${e} must be a whole number above 0`)}function cs(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(ls(i,r),us(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new M(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new M(`config`,`${i}: a profile that compacts itself must be a text profile that takes text`);return}let a=e.get(r.profile);if(!a)throw new M(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new M(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function ls(e,t){if(t.maxTokens<=0)throw new M(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new M(`config`,`${e}: compactAt must be in (0, 1)`)}function us(e,t){if(t.previousExchanges<0)throw new M(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new M(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new M(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function ds(e,t){for(let n of H(t))if(e.get(n)?.type===`builtin`)throw new M(`config`,t.type===`host`?`Profile ${t.id} lists builtin '${n}' in tools.allow — type 'host' never runs a model`:`Profile ${t.id} lists builtin '${n}' in tools.allow — declare it on models.*.builtInTools instead`)}function fs(e,t){let n=ni(t)?.t2Loader;if(n){if(!H(t).includes(n))throw new M(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new M(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*ps(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function ms(e,t){for(let{modelId:n,id:r}of ps(t))if(e.get(r)?.type!==`builtin`)throw new M(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function hs(e){let t=e.type===`text`?e.outputs?.structured:void 0;return t?typeof t==`string`?[t]:[...new Set([...Object.values(t.map),t.fallback])]:[]}function gs(e,t){let n=hs(t).map(n=>{let r=e.find(n);if(!r)throw new M(`config`,`Profile ${t.id}: outputs.structured names '${n}', which is not a registered schema; register it before the profile`);return r}),r=t.type===`text`?t.outputs?.validation:void 0,i=Object.keys(r?.fields??{}),a=Object.keys(r?.items??{});if(!i.length&&!a.length)return;if(!n.length)throw new M(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Da(t.jsonSchema,e)));if(o.length)throw new M(`config`,`Profile ${t.id}: outputs.validation.items has ${o.join(`, `)}, which no structured schema reaches as a list with an items schema`);let s=i.filter(e=>!n.some(t=>Sa(t.jsonSchema,e)));if(s.length)throw new M(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function _s(e){let t=j(e)?.context;if(!t)return;let n=k;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new M(`config`,`Profile ${e.id}: inputs.context.from must list ${k.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new M(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function vs(e,t){if(!t)return;let{attachments:n,voice:r,maxFiles:i,maxBytes:a,maxTurnBytes:o,limitsByMime:s}=t,c={maxFiles:i,maxBytes:a,maxTurnBytes:o};if((n||r)&&Object.values(c).some(e=>e===void 0))throw new M(`config`,`Profile ${e} must set maxFiles, maxBytes, and maxTurnBytes`);for(let[e,t]of Object.entries(s??{}))c[`limitsByMime['${e}']`]=t;for(let[t,n]of Object.entries(c))if(n!==void 0&&!(Number.isInteger(n)&&n>0))throw new M(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function ys(e,t,n){let r=new Map,i=i=>{let a=Qo(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,se(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(ds(e,o),fs(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){ms(e,o),vs(o.id,j(o)),_s(o),gs(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&cs(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new M(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}var bs=`https://generativelanguage.googleapis.com/v1beta/models`;function xs(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Ss(e){let t;try{t=new URL(e.baseUrl)}catch{throw new M(`config`,`Enter a valid localhost URL.`)}if(![`http:`,`https:`].includes(t.protocol)||![`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)||t.username||t.password||t.search||t.hash)throw new M(`config`,`Use a localhost URL without credentials, query parameters or a fragment.`);return{baseUrl:t.href.replace(/\/$/,``),fetch:(e,n)=>new URL(e instanceof Request?e.url:String(e)).origin===t.origin?fetch(e,{...n,redirect:`error`,credentials:`omit`}):Promise.reject(new M(`blocked`,`Local requests must stay on the configured origin.`))}}var Cs=v({data:l(v({id:g().min(1)}))});async function ws(e,t){let n=Ss(e);if(!n?.fetch)throw new M(`config`,`Enter a local endpoint.`);let r=await n.fetch(`${n.baseUrl}/v1/models`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)throw new M(`network`,`Local model list returned HTTP ${r.status}.`);let i=Cs.safeParse(await r.json());if(!i.success)throw new M(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var Ts=`https://openrouter.ai/api/v1/models`,Es=`https://openrouter.ai/api/v1/embeddings/models`,Ds=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],Os=[{id:`liquid/lfm-2.5-embedding-350m:free`,label:`Liquid LFM 2.5 Embedding 350M (free)`},{id:`nvidia/nemotron-3-embed-1b:free`,label:`NVIDIA Nemotron 3 Embed 1B (free)`},{id:`nvidia/llama-nemotron-embed-vl-1b-v2:free`,label:`NVIDIA Llama Nemotron Embed VL 1B v2 (free)`}],ks={text:`text`,image:`image`,speech:`speech`,live:void 0,embedding:void 0},As=v({data:l(v({id:g().min(1),name:g().optional(),architecture:v({output_modalities:l(g()).optional()}).optional()}))}),js=v({data:l(v({id:g().min(1),name:g().optional()}))}),Ms=v({models:l(v({name:g().min(1),displayName:g().optional(),supportedGenerationMethods:l(g()).optional()})).optional(),nextPageToken:g().optional()}),Ns=5;async function Ps(e,t,n){let r=await fetch(t,{...n,redirect:`error`,credentials:`omit`});if(r.status===400||r.status===401||r.status===403)throw new M(`auth`,`${e} refused the key.`);if(!r.ok)throw new M(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Fs(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?Os:Ds];if(e===`openrouter`)return await Is(t,i,r);if(!i)throw new M(`auth`,`Choose a key to list Gemini models.`);return await Rs(t,i,r)}async function Is(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=js.safeParse(await Ps(`OpenRouter`,Es,r));if(!e.success)throw new M(`bad_response`,`OpenRouter returned an invalid embedding model list.`);return e.data.data.map(e=>({id:e.id,label:e.name??e.id}))}let i=ks[e];if(!i)return[];let a=As.safeParse(await Ps(`OpenRouter`,`${Ts}?output_modalities=${i}`,r));if(!a.success)throw new M(`bad_response`,`OpenRouter returned an invalid model list.`);return a.data.data.filter(e=>e.architecture?.output_modalities?.includes(i)??!0).map(e=>({id:e.id,label:e.name??e.id}))}var Ls={live:`bidiGenerateContent`,embedding:`embedContent`};async function Rs(e,t,n){let r=Ls[e]??`generateContent`,i=[],a;for(let e=0;e<Ns;e++){let e=new URL(bs);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=Ms.safeParse(await Ps(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new M(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function zs(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Bs(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}var Vs=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function Hs(e){return e.join(`,`)}function Us(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:Hs(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:e?.slots,context:e?.context}}function Ws(e){return{text:e.text,attachments:e.attachments?{accept:e.attachments.accept}:void 0,voice:e.voice?{accept:e.voice.accept}:void 0,maxFiles:e.maxFiles,maxBytes:e.maxBytes,maxTurnBytes:e.maxTurnBytes,limitsByMime:e.limitsByMime,slots:e.slots,context:e.context}}function Gs(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=fr({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:tr(Ws(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Ks(e){let t=globalThis.MediaRecorder;if(t===void 0)return;let n=e=>t.isTypeSupported(e),r=e=>e.find(n);return e?.length?r(Vs.filter(t=>A(e,t)))??e.find(n):r(Vs)}var qs=v({protocol:g(),provider:g(),apiId:g(),options:_(g(),u()).optional(),keySlot:g().optional(),fallbackKeySlot:g().optional(),efforts:_(g(),d(we)).optional(),defaultEffort:g().optional(),allowEffortSelect:o().optional(),summaries:o().optional(),maxOutputTokens:h().optional(),temperature:h().optional(),builtInTools:l(g()).optional(),compaction:v({maxTokens:h(),compactAt:h(),previousExchanges:h(),profile:g().optional(),timing:d(T),meter:d(ue).optional()}).optional(),limits:v({operationTimeoutMs:h().optional(),connectTimeoutMs:h().optional(),liveStepTimeoutMs:h().optional(),maxWireRecordBytes:h().optional(),maxWireResponseBytes:h().optional(),maxEventBytes:h().optional(),maxStepBytes:h().optional(),maxStepEvents:h().optional(),maxPendingToolCalls:h().optional()}).optional()}),Js=v({structured:i([g(),v({by:g(),map:_(g(),g()),fallback:g()}),p()]).optional(),streaming:v({mode:d(pe).optional(),streamThoughts:o().optional()}).optional()}),Ys=v(Ue(ft,()=>d(Re))),Xs=v(Ue(Ze,()=>Ys)),Zs=v({id:g(),label:g(),actions:Ys,names:l(g()),find:o()}),Qs=v({hosts:l(g()),fromTools:o()}),$s=v({quota:v({perDay:h()}).optional(),detect:Xs,patterns:a(d(Ze),v({theorem:o(),names:l(g())})).optional(),host:l(Zs).optional(),allow:v({ungiven_images:Qs,ungiven_links:Qs}),blockedReply:v({onBlock:d(re),maxRetries:h()})}),ec=i([o(),v({theorem:o(),host:o()})]),tc=v({record:o(),writeTo:i([c(!1),g()]).optional(),sampleRate:h(),include:v({upstreamLog:o(),outboundWire:o(),evidenceRaw:o(),usage:o(),guardrailDecisions:o(),guardrailMatchPreview:o()}),scrub:v({sensitive:ec,injection:ec,canary:ec}),resource:Kt,retainForDays:h(),rotateAfterMiB:h(),hasOnWriteError:o()}),nc=v({text:o(),attachments:v({accept:l(g()),acceptAttr:g()}).nullable(),voice:v({accept:l(g())}).nullable(),maxFiles:h().optional(),maxBytes:h().optional(),maxTurnBytes:h().optional(),limitsByMime:_(g(),h()).optional(),slots:_(g(),l(g())).optional(),context:v({from:l(d(k)),maxChars:h()}).optional()}),rc=v({allowContinue:l(d(Ee)).optional(),autoContinue:l(d(Ee)).optional(),maxContinues:h().optional()}),ic=v({resumption:rc.optional()}),ac=v({allow:l(g()),page:l(g()),t2Loader:g().optional(),parallel:o().optional()}),oc={providerContinuation:v({history:d([`host`,`stateless`,`provider`]).optional()}).optional(),id:g(),models:_(g(),qs),defaultModel:g(),allowModelSelect:o().optional(),maxSteps:h().optional(),labels:a(d(Vt),g()),guardrails:$s.optional(),observability:tc.optional()},sc=i([g(),l(i([g(),t({private:g().min(1)})])).min(1).readonly()]),cc=v({handle:g(),system:sc.optional(),systemByRole:_(g(),sc).optional()}),G=f(`type`,[v({...oc,type:c(`text`),identity:cc,outputs:Js.optional(),inputs:nc,tools:ac,turnBehaviour:v({resumption:rc.optional(),allowSteering:o().optional(),atStepLimit:d(ve).optional()}).optional(),canStop:c(!0),allowSteering:o()}),v({...oc,type:c(`image`),identity:cc,outputs:Js.optional(),image:v({aspectRatio:g().optional(),resolution:g().optional(),mimeType:g().optional(),quality:g().optional(),background:g().optional(),n:h().int().min(1).optional(),seed:h().int().optional(),outputCompression:h().int().min(0).max(100).optional(),references:l(i([v({mimeType:g(),data:g(),name:g().optional()}),v({mimeType:g(),uri:g(),name:g().optional()})])).optional(),includeText:o().optional()}),inputs:nc,tools:ac,turnBehaviour:ic.optional(),canStop:c(!0)}),v({...oc,type:c(`speech`),identity:v({handle:g()}),outputs:Js.optional(),speech:v({voice:g().optional(),style:g().optional(),speed:h().optional(),format:d(Oe).optional()}),inputs:nc,turnBehaviour:ic.optional(),canStop:c(!0)}),v({...oc,type:c(`live`),identity:cc,inputs:nc.pick({slots:!0,context:!0}).optional(),live:v({ingress:v({audio:o().optional(),video:o().optional(),text:o().optional()}).optional(),voice:g().optional(),vad:v({activityHandling:d(fe).optional(),startSensitivity:d(y).optional(),endSensitivity:d(oe).optional(),prefixPaddingMs:h().optional(),silenceDurationMs:h().optional()}).optional(),sessionResumption:o().optional(),contextCompression:v({triggerTokens:h().optional(),slidingWindow:v({targetTokens:h().optional()})}).optional(),transcription:v({input:o().optional(),output:o().optional()}).optional()}),tools:ac.pick({allow:!0,page:!0}),turnBehaviour:v({allowSteering:o().optional()}).optional()})]);function lc(e){let t=ge(e),{sources:n,host:r,...i}=t.detect;return{quota:t.quota,detect:i,...n?{patterns:Object.fromEntries(Object.entries(n).map(([e,{theorem:t,matchers:n}])=>[e,{theorem:t,names:n.map(({name:e})=>e)}]))}:{},...r?{host:r.map(({id:e,label:t,actions:n,matchers:r,find:i})=>({id:e,label:t,actions:n,names:r.map(({name:e})=>e),find:!!i}))}:{},allow:{ungiven_images:uc(t.allow.ungiven_images),ungiven_links:uc(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function uc(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function dc(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function fc(e){if(!e)return;let t=Ut(e);return{record:t.record,writeTo:dc(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function pc(e){let{greeting:t,resumed:n,...r}=e??{};return r}function mc(e,t){let n=e.tools.filter(e=>`type`in e&&e.type===`function`&&e.answeredBy===`page`).map(e=>e.name);if(t){let e=ni(t),r=ri(t);return{allow:[...H(t)],page:n,...e?.t2Loader?{t2Loader:e.t2Loader}:{},...r===void 0?{}:{parallel:r}}}return{allow:e.tools.filter(e=>!(`type`in e&&e.type===`builtin`)).map(e=>e.name),page:n}}function hc({allow:e,page:t}){return{allow:e,page:t}}function gc(e,t){let n=Us(e.inputs),r=t?.identity??{handle:e.handle},i=t?lc(t.guardrails):void 0,a=t?fc(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:ht(t?.labels)};switch(e.type){case`text`:return G.parse({...s,type:`text`,inputs:n,tools:mc(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||De(t)});case`image`:return G.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:mc(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return G.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`live`:return G.parse({...s,type:`live`,live:pc(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:hc(mc(e,t))});default:return e.type}}function _c(e,t){let n=Zi(e,`interfaceFromProfile`);return gc(ua(t,n),n)}function vc(e){return s(t=>Le.safeParse(e(t)).success)}var yc=[`running`,`gate`,`complete`,`error`,`cancel`],bc=s(e=>{let t=Le.safeParse({type:`tool`,tool:e});if(!t.success||t.data.type!==`tool`||!(`phase`in t.data.tool))return!1;let{phase:n}=t.data.tool;return yc.some(e=>e===n)}),xc=_(g(),n()),Sc=v({operationId:g().optional(),name:g(),callId:g(),arguments:xc,draft:g().optional(),reasoning:l(C).optional(),stepId:g().optional(),edited:v({from:xc,to:xc}).optional(),activity:g().optional(),activityPast:g().optional(),outputDraft:g().optional(),state:bc.optional(),startedAt:h().optional(),endedAt:h().optional(),artifacts:l(n())}),Cc=v({kind:d(Te),native:g().optional()}),K={id:g()},q=f(`kind`,[v({...K,kind:c(`user-text`),text:g()}),v({...K,kind:d([`user-attachment`,`user-voice`]),name:g(),mimeType:g(),sizeBytes:h(),data:g().optional()}),v({...K,kind:c(`thought`),text:g()}),v({...K,kind:c(`text`),text:g()}),v({...K,kind:c(`tool`),tool:Sc}),v({...K,kind:c(`structured`),value:n(),draft:g().optional()}),v({...K,kind:c(`media`),mimeType:g(),data:g().optional(),url:g().optional(),previewUrl:g().optional()}),v({...K,kind:c(`grounding`),grounding:vc(e=>({type:`grounding`,grounding:e}))}),v({...K,kind:c(`citation`),sources:vc(e=>({type:`citation`,sources:e})),callId:g().optional()}),v({...K,kind:c(`evidence`),evidence:vc(e=>({type:`evidence`,evidence:e}))}),v({...K,kind:c(`guardrail`),guardrail:be}),v({...K,kind:c(`error`),message:g()}),v({...K,kind:c(`turn-done`),stop:Cc.optional(),tokens:vc(e=>({type:`tokens`,tokens:e})).optional(),interactionId:g().optional(),compaction:o().optional(),workedMs:h().optional(),endedAt:h().optional()})]),wc=v({type:g()});function Tc(e,t){return Object.hasOwn(e,t)}function Ec(e,t){return e.map(e=>{let n=[...t,...e.path],r=`${n.map(String).join(`.`)||`(root)`} ${e.code}`;return e.code!==`invalid_union`||e.errors.length===0?r:`${r} [${e.errors.map(e=>Ec(e,n)).join(` | `)}]`}).join(`; `)}function Dc(e){return Ec(e.issues,[])}function Oc(e,t){return new M(`bad_response`,`${e} failed its wire check: ${Dc(t)}`)}function J(e,t,n){let r=e.safeParse(t);if(!r.success)throw Oc(n,r.error);return r.data}function kc(e){return{type:`malformed`,error:new M(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Ac(e,t){let n=wc.safeParse(t);if(!n.success)return kc(`a line without a kind failed its wire check: ${Dc(n.error)}`);let{type:r}=n.data;if(!Tc(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:kc(`a '${r}' line failed its wire check: ${Dc(i.error)}`)}function jc(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Mc(e,t){let n=jc(t);return n?Ac(e,n.value):kc(`a line is not JSON`)}function Nc(e){let t=jc(e);if(!t)throw new M(`bad_response`,`a line is not JSON`);return t.value}var Pc=v({name:g(),mimeType:g(),data:g()}),Fc=v({slots:_(g(),g()).optional(),context:n().optional(),text:g().optional(),attachments:l(Pc).optional(),voice:l(Pc).optional()}),Ic=v({gateKind:d(xe).optional(),sessionPermissions:l(g()).optional(),name:g().optional(),input:n().optional(),snapshot:E.optional(),promoted:l(g()).optional(),model:g().optional(),effort:g().optional()}),Y=g().trim().min(1);v({input:Fc,conversation:g().min(1).optional(),model:g().optional(),effort:g().optional(),turnId:Y.optional(),abandon:l(ye).min(1).optional(),replay:Ic.pick({sessionPermissions:!0}).optional(),transcript:l(q).optional()});var Lc=[`approve`,`deny`],Rc=i([t({unanswered:c(!0)}),t({output:n()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);v({gateId:g().min(1),operationId:g().min(1).max(256),decision:d(Lc),input:n().optional(),secret:g().optional(),page:Rc.optional(),conversation:g().min(1).optional(),turnId:Y.optional(),replay:Ic.optional()}),v({turnId:Y,id:Y,inject:l(S).min(1)}),v({turnId:Y});var zc=v({type:c(`conversation`),ref:g().min(1),posted:c(!0).optional()}),Bc={...x,conversation:zc},Vc=v({transcript:l(q),paused:v({events:l(Le),blocks:l(q)}).optional()});v({conversation:g().min(1)}),v({conversation:g().min(1),at:h().int().min(-1)}),v({blocks:l(q)});var Hc=v({conversation:g().min(1),view:Vc}),Uc=class extends Error{kind;publicMessage;internalMessage;copy;constructor(e,t,n,r){super(n??t??e),this.name=`TheoremStreamError`,this.kind=e,t&&(this.publicMessage=t),n&&(this.internalMessage=n),r&&(this.copy=r)}};function Wc(e){return e instanceof Uc}function Gc(e){return e?.trim()||void 0}var Kc=v({error:g().optional(),errorKind:ie.optional(),errorCopy:te.optional(),errorInternal:g().optional()}),qc=Kc;function X(e,t){let n=Gc(e.error),r=Gc(e.errorInternal);return new Uc(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function Jc(e){return!Wc(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function Yc(e,t){let n=Mc(e,t);if(n.type===`error`)throw X(Kc.parse(n),`internal`);return n}function Xc(e,t,n){let r=e.split(`
7
+ `),i=r.pop()??``;for(let e of r)e.trim()&&n(Yc(t,e));return i}async function Zc(e,t,n,r){if(!e.body)throw new M(`bad_response`,`stream reply has no body`);let i=e.body.getReader(),a=new TextDecoder,o=``,s=()=>{i.cancel()};r?.addEventListener(`abort`,s,{once:!0});try{for(;;){Ye(r);let{done:e,value:s}=await i.read();if(e)break;o=Xc(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(Yc(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function Qc(e){let t=typeof e.headers==`function`?await e.headers():e.headers,n=new Headers(t);return n.set(`content-type`,`application/json`),n}async function $c(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return X({errorInternal:`HTTP ${String(e.status)}`},rt(e.status))}let i=Kc.safeParse(r);return i.success?X({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},rt(e.status)):new M(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function el(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await Qc(n),credentials:n.credentials??`same-origin`})}catch(e){throw Ot(e)?e:new M(`network`,ot(e),{cause:e})}}async function tl(e,t,n,r,i={}){await Zc(await nl(e,t,i),n,r,i.signal)}async function nl(e,t,n){let r=await el(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await $c(r);return r}async function Z(e,t,n={}){await nl(e,t,n)}async function Q(e,t,n={}){let r=await el(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await $c(r,t.failed);return Nc(await r.text())}async function rl(e,t,n={}){let{signal:r,...i}=n;return J(Vc,await Q(e,{body:t,signal:r},i),`the conversation`)}async function il(e,t,n,r){let{signal:i,...a}=n;return J(Hc,await Q(e,{body:t,signal:i},a),r)}function al(e,t,n={}){return il(e,t,n,`the rewound conversation`)}function ol(e,t,n={}){return il(e,t,n,`the started conversation`)}function sl(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var cl=v({interface:G});function ll(e={}){let t=sl(e.endpoint??`/api/theorem`);return{async describe(n){let r=await el(t,{method:`GET`,signal:n},e);if(!r.ok)throw await $c(r);return J(cl,Nc(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>tl(`${t}/turn`,r,Bc,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>tl(`${t}/invoke`,r,Bc,i,{...e,signal:a}),conversation:(n,r)=>rl(`${t}/conversation`,n,{...e,signal:r}),rewind:(n,r)=>al(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>Z(`${t}/page-result`,n,{...e,signal:r}),steer:n=>Z(`${t}/steer`,n,e),stop:n=>Z(`${t}/stop`,n,e)}}function ul(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?ul(n[0],t):t}function dl(e,t,n){return{type:`decision`,identity:{handle:e.identity.handle},contract:e.decision.contract,...e.inputs.maxStateBytes===void 0?{}:{maxStateBytes:e.inputs.maxStateBytes},questions:Object.entries(t).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>ul(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}})),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:Ut(e.observability).record}}:{}}}function fl(e,t){let n=Object.keys(t??{}).find(t=>e&&Object.hasOwn(e,t));if(n!==void 0)throw new M(`request`,`the image ${n} is the host's, so the page's needs another name`);let r={...e,...t};return Object.keys(r).length>0?r:void 0}var $=h().min(0).max(1),pl=_(g(),$),ml=f(`type`,[v({type:c(`choice`),choice:g(),confidence:$,probabilities:pl}),v({type:c(`noul`),noul:$}),v({type:c(`box`),box:v({top:$,bottom:$,left:$,right:$}),confidence:$}),v({type:c(`score`),score:h().nonnegative(),confidence:$,legend:_(g(),g().min(1)),probabilities:pl})]),hl=v({result:v({model:g().min(1),answers:_(g(),ml),usage:v({inputTokens:h().int().nonnegative(),outputTokens:h().int().nonnegative(),costUsd:h().nonnegative().optional()}).optional()}),traces:l(Gt).optional()}),gl=new WeakMap;function _l(e,t){return t.length>0&&typeof e==`object`&&e&&gl.set(e,t),e}function vl(e){return typeof e==`object`&&!!e&&gl.get(e)||[]}var yl=v({traces:l(Gt)});async function bl(e,t,n,r,i){let a=[],o=e=>{let t=yl.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Q(e,{body:t,signal:n,failed:o},r))}catch(e){throw _l(e,a)}}function xl(e,t,n,r={}){return bl(e,t,n,r,Sl)}function Sl(e){return J(hl,e,`the decision`)}var Cl=v({interface:v({type:c(`decision`),identity:v({handle:g()}),contract:g(),maxStateBytes:h().optional(),questions:l(v({id:g(),type:d([`choice`,`noul`,`score`,`box`]),labels:l(g()),image:g().optional()})),images:_(g(),v({mimeType:d([`image/png`,`image/jpeg`]),data:g()})).optional(),observability:v({record:o()}).optional()})});function wl(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return J(Cl,await Q(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i)=>xl(`${t}/decide`,{state:n,...i?{assets:i}:{}},r,e)}}function Tl(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:ke(t.inputSchema),output:ke(t.outputSchema)};if(t.type===`http`){e.register({...i,type:`http`,endpoint:t.endpoint,method:t.method,headers:t.headers,mapping:t.mapping,auth:t.auth,maxResponseBytes:t.maxResponseBytes});return}if(t.type===`mcp`){e.register({...i,type:`mcp`,serverUrl:t.serverUrl,mcpToolName:t.mcpToolName,headers:t.headers,auth:t.auth,maxResponseBytes:t.maxResponseBytes,session:t.session});return}if(t.answeredBy===`page`){e.register({...i,type:`function`,answeredBy:`page`});return}let a=t.stubResponse||!Object.hasOwn(n,t.name)?void 0:n[t.name],o=t.stubResponse??qt(t.outputSchema);e.register({...i,type:`function`,handler:a?e=>{try{return Promise.resolve(a(e))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}}:()=>Promise.resolve(o)})}function El(e,t,n){e.registerMany(w);for(let r of t)Tl(e,r,n)}function Dl(e,t,n,r,i){return El(e.tools,n,i),r&&t.type!==`live`&&e.schemas.register(r.id,r.spec),e.profiles.register(t),t}function Ol(e){if(e.type===`error`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,error:t}}if(e.type===`session`&&e.session.kind===`ended`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,session:{...e.session,message:t}}}if(e.type===`tool`&&e.tool.phase===`error`&&e.tool.failure.error!==void 0){let{failure:t}=e.tool;return{...e,tool:{...e.tool,failure:{...t,error:t.message}}}}return e}function kl(e){if(e.type!==`error`&&e.type!==`session`&&e.type!==`tool`||e.errorInternal===void 0)return e;let{errorInternal:t,...n}=e;return n}function Al(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function jl(e){if(e.type!==`guardrail`||!(e.guardrail?.errorInternal||e.guardrail?.errorSummary))return e;let{errorInternal:t,errorSummary:n,...r}=e.guardrail;return{...e,guardrail:r}}function Ml(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function Nl(e,t){let n=t?.reader===`builder`?Ol(e):Al(jl(kl(e)));return t?.includeEvidenceRaw||(n=Ml(n)),n=Xt(n,!1),n}function Pl(e,t){return e.map(e=>Nl(e,t))}function Fl(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=Nl(ut(et(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var Il={reader:`builder`};function Ll(e){return e.mode===`demo`?{reader:`visitor`}:Il}export{Va as $,Mc as A,qr as At,zs as B,gr as Bt,qc as C,ri as Ct,tl as D,Zr as Dt,Z as E,Xr as Et,Gs as F,Wr as Ft,ro as G,Kn as Gt,ys as H,Jn as Ht,xs as I,Ur as It,to as J,Hn as Jt,no as K,V as Kt,ws as L,Mr as Lt,q as M,Hr as Mt,_c as N,Lr as Nt,J as O,Qr as Ot,Ks as P,Vr as Pt,Oa as Q,Xt as Qt,Fs as R,Tr as Rt,X as S,H as St,Jc as T,vi as Tt,Qo as U,qn as Ut,Bs as V,_r as Vt,_o as W,Gn as Wt,Ja as X,Yt as Xt,qa as Y,en as Yt,Ya as Z,Jt as Zt,ll as _,Ti as _t,Pl as a,Ea as at,al as b,_i as bt,wl as c,Da as ct,vl as d,Qi as dt,La as et,xl as f,da as ft,Uc as g,Hi as gt,Bc as h,Wi as ht,Nl as i,Ia as it,Ac as j,Gr as jt,Dc as k,Yr as kt,fl as l,wa as lt,_l as m,Ki as mt,Ll as n,Ra as nt,Dl as o,xa as ot,bl as p,ca as pt,eo as q,Un as qt,Fl as r,Wa as rt,El as s,Ca as st,Il as t,Ua as tt,dl as u,Ta as ut,rl as v,mi as vt,Wc as w,ni as wt,ol as x,pi as xt,Q as y,hi as yt,Ss as z,hr as zt};