@theoremjs/studio 0.3.2 → 0.3.3

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 (33) hide show
  1. package/package.json +3 -3
  2. package/page/assets/{Banner-BISz3nXA.js → Banner-Buiul23B.js} +2 -2
  3. package/page/assets/{ContextMenu-CBu9H-9H.js → ContextMenu-Dw9_F5b0.js} +2 -2
  4. package/page/assets/{ToolResultCharts-CgshSv9Q.js → ToolResultCharts-CVlI3NkJ.js} +1 -1
  5. package/page/assets/{TraceInspector-_yZiz05W.js → TraceInspector-TusXx3zZ.js} +1 -1
  6. package/page/assets/{TraceOverview-BPO-HIYK.js → TraceOverview-DrHQgMQO.js} +1 -1
  7. package/page/assets/{_virtual_studio-type-sources-ByxqQaOG.js → _virtual_studio-type-sources-BwZOives.js} +39 -11
  8. package/page/assets/browser-engine-BTOR18GA.js +11 -0
  9. package/page/assets/{browser-transport-D-2jDYe7.js → browser-transport-BEFsWdzI.js} +3 -3
  10. package/page/assets/{export-agent-C3yyzXH8.js → export-agent-BnlMWFTv.js} +1 -1
  11. package/page/assets/{guardrail-tester-Gut5xK4a.js → guardrail-tester-DRsOgbwK.js} +1 -1
  12. package/page/assets/{index-CvvmFKgS.js → index-D2T8e_8Q.js} +6 -6
  13. package/page/assets/{live-messages-CnkL4GWi.js → live-messages-BYi31jQk.js} +1 -1
  14. package/page/assets/{reader-BOCCYaRp.js → reader-B0gVhfoZ.js} +1 -1
  15. package/page/assets/{stub-DhdcU_Ew.js → stub-DEZDrr-l.js} +1 -1
  16. package/page/assets/{studio-code-pane-C_SAbcOa.js → studio-code-pane-PndbSO1v.js} +3 -3
  17. package/page/assets/{studio-console-DZwlEsvr.js → studio-console-e6kqu38F.js} +1 -1
  18. package/page/assets/{studio-decision-B0FnCAXA.js → studio-decision-DFM0psog.js} +1 -1
  19. package/page/assets/{studio-embedding-CmA51HVo.js → studio-embedding-4qgdJ4gh.js} +1 -1
  20. package/page/assets/{studio-host-console-By7hqu2l.js → studio-host-console-DajI604W.js} +2 -2
  21. package/page/assets/{studio-live-BrcVQcyV.js → studio-live-B1a0aWbl.js} +1 -1
  22. package/page/assets/{studio-map-B_xSia-z.js → studio-map-CdrEm07d.js} +1 -1
  23. package/page/assets/{studio-type-checker-BOvxudki.js → studio-type-checker-DosSRFbd.js} +1 -1
  24. package/page/assets/tool-schema-BrqSc6vO.js +18 -0
  25. package/page/assets/{tree-DqyAMsbI.js → tree-DeO1319a.js} +1 -1
  26. package/page/assets/{turn-client-Du3Um3Mg.js → turn-client-DwVPS3TX.js} +1 -1
  27. package/page/assets/types-EVrOoUBG.js +1 -0
  28. package/page/assets/{use-one-call-Hcs8YBp1.js → use-one-call-9e3o5vH-.js} +1 -1
  29. package/page/assets/{workspace-DZALqEDX.js → workspace-Ck0o-_fd.js} +1 -1
  30. package/page/index.html +11 -11
  31. package/page/assets/browser-engine-CYq9DQAM.js +0 -9
  32. package/page/assets/tool-schema-idaOe2nI.js +0 -18
  33. package/page/assets/types-BhfXQCLx.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{Dn as l,Ln as u,Pn as d,br as f}from"./tool-schema-idaOe2nI.js";import{A as p,S as m,k as h}from"./reader-BOCCYaRp.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{S as _}from"./turn-client-Du3Um3Mg.js";var v=c({type:t(`open`),history:n(u).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:f,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:d}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=h(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>p(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{Dn as l,Ln as u,Pn as d,br as f}from"./tool-schema-BrqSc6vO.js";import{A as p,S as m,k as h}from"./reader-B0gVhfoZ.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{S as _}from"./turn-client-DwVPS3TX.js";var v=c({type:t(`open`),history:n(u).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:f,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:d}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=h(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>p(l,e))}:t}export{v as n,x as r,y as t};
@@ -1,4 +1,4 @@
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,Br as x,Dn as S,Er as ee,G as te,Gt as C,Hn as w,Ht as T,In as E,Ir as D,Jn as O,Kt as ne,Ln as re,Lt as ie,Mn as ae,Nn as oe,On as se,Pr as ce,Qn as le,Rr as ue,Tr as de,Un as k,Vn as fe,Wn as pe,Xn as me,Xt as he,Yn as ge,Zt as _e,_r as ve,cn as A,dn as ye,er as be,fn as j,gr as xe,hr as Se,jn as Ce,jr as we,kn as Te,kr as Ee,ln as De,nr as Oe,or as ke,pn as Ae,qn as je,rr as Me,s as Ne,sn as Pe,tr as Fe,un as M,ur as Ie,vt as Le,wr as Re,xr as ze,zn as Be,zr as Ve,zt as He}from"./tool-schema-idaOe2nI.js";import{c as N}from"./host-patterns-C9RMP16Q.js";import{An as Ue,B as We,Bt as Ge,En as Ke,Et as qe,F as Je,Gt as Ye,Ht as Xe,I as Ze,It as Qe,Lt as $e,M as et,Mn as P,Mt as tt,N as nt,Nn as rt,O as it,On as at,P as ot,Pt as st,Q as ct,Qt as lt,Rt as ut,Sn as dt,St as ft,Ut as pt,Vt as mt,W as ht,Wt as gt,X as _t,bt as vt,et as yt,fn as bt,ft as xt,gn as St,it as Ct,j as wt,jt as Tt,k as Et,mn as Dt,mt as F,nn as Ot,nt as kt,pn as At,qt as jt,rn as Mt,rt as Nt,tt as Pt,ut as Ft,wn as It,wt as Lt,xn as Rt,zt}from"./shaped-data-BcarWqd5.js";import{a as Bt,n as Vt}from"./live-ingress-lDUGPwth.js";import{n as Ht,t as Ut}from"./trace-schema-9CdEyG6Q.js";import{n as Wt}from"./stub-DhdcU_Ew.js";function I(e){return{type:`guardrail`,guardrail:e}}function Gt(e,t,n,r=`redact`,i){if(n.length!==0)return I({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Kt(e,t){return e.type===`guardrail`?{...e,guardrail:St(e.guardrail,t)}:e}var L=65536;function R(e){let t=e.classStarts.length,n=new Uint16Array(L);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??L);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 z,B,qt;async function Jt(){if(z)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-B5ZGE1mT.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);z={forward:t,reversed:n}}function Yt(){if(!z)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return z}var V;function Xt(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 Zt(e){if(!V){V=new Map;for(let e=0;e<L;e++){let t=Xt(e),n=V.get(t);n?n.push(e):V.set(t,[e])}}return V.get(Xt(e))??[e]}function Qt(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<L&&t.push(n+1);return t}var $t=new Map;function en(e){let t=$t.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>Zt(e.charCodeAt(n))),r=Qt([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=R({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 $t.set(e,a),a}function tn(e){let t=JSON.stringify(e),n=$t.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=Qt(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=R({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 $t.set(t,s),s}function nn(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 rn(e,t){e.text+=t,e.fresh+=t}function an(e){return e.text.length-e.fresh.length}function H(e,t){let n=an(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function on(e,t,n=e.text.length){let r=an(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function sn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function cn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,rn(n,t(on(e,n.text.length)))}};return n}var ln=/\w/,un=Math.max(...ut.map(e=>e.length));function dn(e){return e.length<=un+1&&/^[A-Za-z]*$/.test(e)}function fn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{rn(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(H(e,t)),o=ln.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Xe(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!dn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function pn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function U(e,t,n){rn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var mn=55296,hn=56319,gn=/[A-Za-z]/,_n=56320,vn=57343;function yn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=pn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(gn.test(e)||U(c,`\\`,s),s=-1),e===`\\`?s=t:U(c,e,t)}function u(e,t){if(pt(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!gn.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=gn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=mn&&t<=hn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=_n&&a<=vn?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=H(e,t),o=a>=mn&&a<=hn;if(o&&t+1>=i)break;let s=H(e,t+1),c=o&&s>=_n&&s<=vn?2:1,l=gt(on(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var bn=/[0-9A-Fa-f]/;function xn(e){let t=0,n=-1,r=pn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(H(e,t));if(n<0){a===`%`?n=t:(U(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:bn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)U(r,String.fromCharCode(H(e,n)),n)}}};function i(t){t>n&&U(r,zt(on(e,n,t)),n),n=-1}return r}var Sn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Cn=new Map($e.map(({pattern:e,hit:t})=>[e,t])),wn=new Map(Pt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function W(e){return{rule:Rt(e),severity:`high`,detector:e}}var Tn=W(`injection`),En=W(`marker_leak`),Dn=W(`tool_leak`);function On({kind:e,group:t}){if(Sn.has(e))return Tn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:W(t);case`boundary`:return En;case`image`:return W(`ungiven_images`);default:return W(`ungiven_links`)}}function kn(e,t,n){if(e===`card`)return{hit:kt};if(e===`image`||e===`link`){let r=(e===`image`?Nt:Ct).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Cn.get(t)??wn.get(t);return r?{hit:r}:{}}function An(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Ft(i(n?.ungiven_images)),link:xt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return ct.forEach((t,n)=>{let r=On(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:new RegExp(t.pattern.source,t.pattern.flags),...kn(t.kind,t.pattern,a)})}),o}function jn(){let e=[];return ct.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Cn.get(n);e.push({...Tn,id:r,regex:new RegExp(n.source,n.flags),...i?{hit:i}:{}})}),e}function Mn(){return Ye.map((e,t)=>({...Tn,id:t,regex:new RegExp(e.source,e.flags)}))}function Nn(e,t,n){let r=nn(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=an(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}}function D(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)))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 O(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):D(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=O();e;e=O())t.push(e);return e.rawAt(n)}}}var Pn=new WeakMap;function Fn(e){let t=Pn.get(e);return t||(t=R(e),Pn.set(e,t)),t}function In(e={}){let t={text:``,fresh:``},n=sn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Nn(e,t,n)),a=[],o=e.detect??[],s=An(o,e);if(s.length>0&&(B??=R(Yt().forward),a.push(i(n,B,s))),o.includes(`injection`)){B??=R(Yt().forward),qt??=R(Yt().reversed);let e=yn(t),r=jn();a.push(i(n,qt,Mn()),i(fn(n),B,r),i(e,B,r),i(fn(e),B,r),i(cn(n,mt),B,r),i(cn(n,e=>Ge(e)??e),B,r),i(xn(t),B,r))}if(o.includes(`marker_leak`)&&e.note){let t=yt(e.note);a.push(i(n,en(e.note),[{...En,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=ht(e.tools),r=t.map(({regex:e},t)=>({...Dn,id:t,regex:e}));t.length>0&&a.push(i(n,tn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...W(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Fn(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 Ln(e,t,n={},r=[]){let i=ot(e,t).filter(e=>!(Ze(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=In({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=nt(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Rn(e){let{context:t}=e,n=e.detect,r=n?Ln(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(-F),_=u,v=0,y=u,b=0,x=0,S=s?ft(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,Dt]),c){let r=_.length;_+=e;let i=Qe(_,r);_=_.slice(i),v+=i;let[a]=_t(_,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-F),i=r+vt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+vt(y,e)),x=Math.min(i,u.length+p.length-F);let a=Math.max(b,Math.max(t,x)-F);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+st(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(-F)),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?qe(u+p,s,c):``}}function G(e,t,n){return et(t,e.detect,n)}async function zn(e,t,n,r){return G(e,[n],t)?(await Jt(),Bn(e,t,n,r)):null}function Bn(e,t,n,r){return G(e,[n],t)?Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:We(e,t)},...r?{carry:r}:{}}):null}async function Vn(e,t,n,r){return G(e,[n],r??t)?(await Jt(),Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??We(e,t)}})):null}var Hn=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}},Un=2,Wn=4,Gn=3,Kn=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,qn=/^[A-Za-z0-9+/]*={0,2}$/,Jn=new Set([`text/csv`,`text/plain`,`text/markdown`]);function Yn(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 Xn(e,t){if(t.limitsByMime){let n=j(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 Zn(e){return`uri`in e}function Qn(e){if(e.type===`speech`)throw new N(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new N(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new N(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=Yn(e.inputs??{});if(!t)throw new N(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function $n(e){let t=0;return e.endsWith(`==`)?t=Un:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Gn/Wn)-t}function er(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function tr(e){return e.replace(Kn,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function nr(e,t,n){let r=er(t);return e===`text/csv`&&(r=tr(r)),new TextEncoder().encode(n.read(r))}function rr(e,t){return t?{...e,fileName:t}:e}function ir(e,t,n){return t.filter(t=>!A(e,t.mimeType)).map(e=>rr({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function ar(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=Xn(i.mimeType,t);i.sizeBytes>e&&n.push(rr({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 or(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(...ir(e.attachments,t,`attachment`)),e.voice&&r.push(...ir(e.voice,n,`voice`)),e.limits?[...r,...ar([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var sr={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 cr(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:sr[e.code],params:t}}function lr(e,t){let n=cr(e);return P(n.key,n.params,t)}function ur(e){return new N(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(cr)})}function dr(e){if(!qn.test(e))throw new N(`request`,`attachment data must be base64`);return $n(e)}function fr(e){let t={mimeType:e.mimeType,name:e.name};return Zn(e)||(t.sizeBytes=dr(e.data)),t}function pr(e,t,n){if(!hr(t,n))return;let r=Qn(e),i=or({attachments:De(e,`attachments`),voice:De(e,`voice`),limits:r},(t??[]).map(fr),(n??[]).map(fr));if(i.length>0)throw ur(i)}function mr(e,t){if(Zn(e))return e;let{mimeType:n,data:r}=e;if(!Jn.has(j(n)))return e;let i=nr(n,bt(r),t);return{...e,data:At(i)}}function hr(e,t){return(e?.length??0)>0||(t?.length??0)>0}function gr(e,t,n,r){return pr(e,t,n),{attachments:t?.length?t.map(e=>mr(e,r.attachment)):t,voice:n?.length?n.map(e=>mr(e,r.voice)):n}}var _r=`
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,Br as x,Dn as S,Er as ee,G as te,Gt as C,Hn as w,Ht as T,In as E,Ir as D,Jn as O,Kt as ne,Ln as re,Lt as ie,Mn as ae,Nn as oe,On as se,Pr as ce,Qn as le,Rr as ue,Tr as de,Un as k,Vn as fe,Wn as pe,Xn as me,Xt as he,Yn as ge,Zt as _e,_r as ve,cn as A,dn as ye,er as be,fn as j,gr as xe,hr as Se,jn as Ce,jr as we,kn as Te,kr as Ee,ln as De,nr as Oe,or as ke,pn as Ae,qn as je,rr as Me,s as Ne,sn as Pe,tr as Fe,un as M,ur as Ie,vt as Le,wr as Re,xr as ze,zn as Be,zr as Ve,zt as He}from"./tool-schema-BrqSc6vO.js";import{c as N}from"./host-patterns-C9RMP16Q.js";import{An as Ue,B as We,Bt as Ge,En as Ke,Et as qe,F as Je,Gt as Ye,Ht as Xe,I as Ze,It as Qe,Lt as $e,M as et,Mn as P,Mt as tt,N as nt,Nn as rt,O as it,On as at,P as ot,Pt as st,Q as ct,Qt as lt,Rt as ut,Sn as dt,St as ft,Ut as pt,Vt as mt,W as ht,Wt as gt,X as _t,bt as vt,et as yt,fn as bt,ft as xt,gn as St,it as Ct,j as wt,jt as Tt,k as Et,mn as Dt,mt as F,nn as Ot,nt as kt,pn as At,qt as jt,rn as Mt,rt as Nt,tt as Pt,ut as Ft,wn as It,wt as Lt,xn as Rt,zt}from"./shaped-data-BcarWqd5.js";import{a as Bt,n as Vt}from"./live-ingress-lDUGPwth.js";import{n as Ht,t as Ut}from"./trace-schema-9CdEyG6Q.js";import{n as Wt}from"./stub-DEZDrr-l.js";function I(e){return{type:`guardrail`,guardrail:e}}function Gt(e,t,n,r=`redact`,i){if(n.length!==0)return I({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Kt(e,t){return e.type===`guardrail`?{...e,guardrail:St(e.guardrail,t)}:e}var L=65536;function R(e){let t=e.classStarts.length,n=new Uint16Array(L);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??L);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 z,B,qt;async function Jt(){if(z)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-B5ZGE1mT.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);z={forward:t,reversed:n}}function Yt(){if(!z)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return z}var V;function Xt(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 Zt(e){if(!V){V=new Map;for(let e=0;e<L;e++){let t=Xt(e),n=V.get(t);n?n.push(e):V.set(t,[e])}}return V.get(Xt(e))??[e]}function Qt(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<L&&t.push(n+1);return t}var $t=new Map;function en(e){let t=$t.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>Zt(e.charCodeAt(n))),r=Qt([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=R({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 $t.set(e,a),a}function tn(e){let t=JSON.stringify(e),n=$t.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=Qt(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=R({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 $t.set(t,s),s}function nn(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 rn(e,t){e.text+=t,e.fresh+=t}function an(e){return e.text.length-e.fresh.length}function H(e,t){let n=an(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function on(e,t,n=e.text.length){let r=an(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function sn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function cn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,rn(n,t(on(e,n.text.length)))}};return n}var ln=/\w/,un=Math.max(...ut.map(e=>e.length));function dn(e){return e.length<=un+1&&/^[A-Za-z]*$/.test(e)}function fn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{rn(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(H(e,t)),o=ln.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Xe(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!dn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function pn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function U(e,t,n){rn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var mn=55296,hn=56319,gn=/[A-Za-z]/,_n=56320,vn=57343;function yn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=pn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(gn.test(e)||U(c,`\\`,s),s=-1),e===`\\`?s=t:U(c,e,t)}function u(e,t){if(pt(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!gn.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=gn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=mn&&t<=hn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=_n&&a<=vn?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=H(e,t),o=a>=mn&&a<=hn;if(o&&t+1>=i)break;let s=H(e,t+1),c=o&&s>=_n&&s<=vn?2:1,l=gt(on(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var bn=/[0-9A-Fa-f]/;function xn(e){let t=0,n=-1,r=pn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(H(e,t));if(n<0){a===`%`?n=t:(U(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:bn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)U(r,String.fromCharCode(H(e,n)),n)}}};function i(t){t>n&&U(r,zt(on(e,n,t)),n),n=-1}return r}var Sn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Cn=new Map($e.map(({pattern:e,hit:t})=>[e,t])),wn=new Map(Pt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function W(e){return{rule:Rt(e),severity:`high`,detector:e}}var Tn=W(`injection`),En=W(`marker_leak`),Dn=W(`tool_leak`);function On({kind:e,group:t}){if(Sn.has(e))return Tn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:W(t);case`boundary`:return En;case`image`:return W(`ungiven_images`);default:return W(`ungiven_links`)}}function kn(e,t,n){if(e===`card`)return{hit:kt};if(e===`image`||e===`link`){let r=(e===`image`?Nt:Ct).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Cn.get(t)??wn.get(t);return r?{hit:r}:{}}function An(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Ft(i(n?.ungiven_images)),link:xt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return ct.forEach((t,n)=>{let r=On(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:new RegExp(t.pattern.source,t.pattern.flags),...kn(t.kind,t.pattern,a)})}),o}function jn(){let e=[];return ct.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Cn.get(n);e.push({...Tn,id:r,regex:new RegExp(n.source,n.flags),...i?{hit:i}:{}})}),e}function Mn(){return Ye.map((e,t)=>({...Tn,id:t,regex:new RegExp(e.source,e.flags)}))}function Nn(e,t,n){let r=nn(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=an(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}}function D(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)))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 O(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):D(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=O();e;e=O())t.push(e);return e.rawAt(n)}}}var Pn=new WeakMap;function Fn(e){let t=Pn.get(e);return t||(t=R(e),Pn.set(e,t)),t}function In(e={}){let t={text:``,fresh:``},n=sn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Nn(e,t,n)),a=[],o=e.detect??[],s=An(o,e);if(s.length>0&&(B??=R(Yt().forward),a.push(i(n,B,s))),o.includes(`injection`)){B??=R(Yt().forward),qt??=R(Yt().reversed);let e=yn(t),r=jn();a.push(i(n,qt,Mn()),i(fn(n),B,r),i(e,B,r),i(fn(e),B,r),i(cn(n,mt),B,r),i(cn(n,e=>Ge(e)??e),B,r),i(xn(t),B,r))}if(o.includes(`marker_leak`)&&e.note){let t=yt(e.note);a.push(i(n,en(e.note),[{...En,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=ht(e.tools),r=t.map(({regex:e},t)=>({...Dn,id:t,regex:e}));t.length>0&&a.push(i(n,tn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...W(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Fn(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 Ln(e,t,n={},r=[]){let i=ot(e,t).filter(e=>!(Ze(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=In({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=nt(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Rn(e){let{context:t}=e,n=e.detect,r=n?Ln(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(-F),_=u,v=0,y=u,b=0,x=0,S=s?ft(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,Dt]),c){let r=_.length;_+=e;let i=Qe(_,r);_=_.slice(i),v+=i;let[a]=_t(_,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-F),i=r+vt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+vt(y,e)),x=Math.min(i,u.length+p.length-F);let a=Math.max(b,Math.max(t,x)-F);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+st(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(-F)),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?qe(u+p,s,c):``}}function G(e,t,n){return et(t,e.detect,n)}async function zn(e,t,n,r){return G(e,[n],t)?(await Jt(),Bn(e,t,n,r)):null}function Bn(e,t,n,r){return G(e,[n],t)?Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:We(e,t)},...r?{carry:r}:{}}):null}async function Vn(e,t,n,r){return G(e,[n],r??t)?(await Jt(),Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??We(e,t)}})):null}var Hn=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}},Un=2,Wn=4,Gn=3,Kn=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,qn=/^[A-Za-z0-9+/]*={0,2}$/,Jn=new Set([`text/csv`,`text/plain`,`text/markdown`]);function Yn(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 Xn(e,t){if(t.limitsByMime){let n=j(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 Zn(e){return`uri`in e}function Qn(e){if(e.type===`speech`)throw new N(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new N(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new N(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=Yn(e.inputs??{});if(!t)throw new N(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function $n(e){let t=0;return e.endsWith(`==`)?t=Un:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Gn/Wn)-t}function er(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function tr(e){return e.replace(Kn,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function nr(e,t,n){let r=er(t);return e===`text/csv`&&(r=tr(r)),new TextEncoder().encode(n.read(r))}function rr(e,t){return t?{...e,fileName:t}:e}function ir(e,t,n){return t.filter(t=>!A(e,t.mimeType)).map(e=>rr({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function ar(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=Xn(i.mimeType,t);i.sizeBytes>e&&n.push(rr({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 or(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(...ir(e.attachments,t,`attachment`)),e.voice&&r.push(...ir(e.voice,n,`voice`)),e.limits?[...r,...ar([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var sr={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 cr(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:sr[e.code],params:t}}function lr(e,t){let n=cr(e);return P(n.key,n.params,t)}function ur(e){return new N(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(cr)})}function dr(e){if(!qn.test(e))throw new N(`request`,`attachment data must be base64`);return $n(e)}function fr(e){let t={mimeType:e.mimeType,name:e.name};return Zn(e)||(t.sizeBytes=dr(e.data)),t}function pr(e,t,n){if(!hr(t,n))return;let r=Qn(e),i=or({attachments:De(e,`attachments`),voice:De(e,`voice`),limits:r},(t??[]).map(fr),(n??[]).map(fr));if(i.length>0)throw ur(i)}function mr(e,t){if(Zn(e))return e;let{mimeType:n,data:r}=e;if(!Jn.has(j(n)))return e;let i=nr(n,bt(r),t);return{...e,data:At(i)}}function hr(e,t){return(e?.length??0)>0||(t?.length??0)>0}function gr(e,t,n,r){return pr(e,t,n),{attachments:t?.length?t.map(e=>mr(e,r.attachment)):t,voice:n?.length?n.map(e=>mr(e,r.voice)):n}}var _r=`
2
2
 
3
3
  `;function vr(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 yr(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=vr(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function br(e,t){let n=yr(e,t);if(n)throw new N(`config`,n)}function xr(e,t,n){return br(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Sr(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 Cr(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:_r,private:!0}),t.push(...n));return t}function wr(e){return e.map(e=>e.text).join(``)}function Tr(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:wr(e),private:t}}function Er(e,t){return Tr(Cr([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var Dr=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Or(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var kr={client:`untrusted`,server:`assembled`};function Ar(e){return typeof e==`string`?e:JSON.stringify(e)}function jr(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(Ar(o));let c=s.found(),l=wt(`context`,c);l&&n.push({...l,trust:kr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Mr=/^[A-Za-z0-9._-]+$/;function Nr(e){let t=e?.trim();return t&&Mr.test(t)?t:void 0}function Pr(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 Fr(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 Ir(e){return new N(`input`,`guardrails.detect blocked the request at ${e}`,{copy:{key:`detect.blocked`}})}function Lr(e,t){let{detect:n}=Ae(t.guardrails),r=Ke(Dr,e=>Et(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:xr(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=Or(i.slots,r.slots),c=jr(i.context,()=>Et(`context`,n)),l=Pr(i.repair,r.repair),u=i.history?Fr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?gr(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Dr){let t=r[e].found(),n=wt(e,t);n&&p.push(I(n)),t.action===`block`&&(m??=Ir(e))}return p.push(...c.events.map(I)),c.blocked&&(m??=Ir(`context`)),{request:{...e,system:o,projectId:Nr(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 Rr(e,t){let{request:n,refusal:r}=Lr(e,t);if(r)throw r;return n}function zr(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function Br(e,t){return[...new Set([...t.filter(t=>A(e,t)),...e.filter(e=>A(t,e))])]}function Vr(e,t){let n=e.attachments?t?Br(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 Hr(e){let t=j(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Ur(e,t){let n=Yn(e),r=or({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:Hr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}function Wr(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function Gr(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function Kr(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function K(e){return`tools`in e?e.tools.allow:[]}function qr(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function Jr(e){return`tools`in e?e.tools.parallel:void 0}function Yr(e,t,n){return K(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||Gr(i.paths,n.path)})}function Xr(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&Gr(r.paths,n.path)}):[]}function Zr(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 Qr(e,t){let n=[];for(let r of t){let t=Zr(e,r);t&&n.push(t)}return n}function $r(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=Zr(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function ei(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 ti(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function ni(e,t,n){return Kr(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function ri(e,t,n,r){let i=Yr(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:Xr(e,t,n,r),o=[...i,...a],s=ni(e,t,o),c=ti(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>Wr(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:Qr(e,c)}}async function ii(e,t,n,r){let i=ri(e,t,n,r);return await oi(e,i,t,n),i}function ai(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 oi(e,t,n,r){let i=qr(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 N(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new N(`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`?ei(e,t,n):$r(e,t,n))}t.executable=t.visible.filter(t=>Wr(e,t))}var si=new Set([`__proto__`,`constructor`,`prototype`]);function ci(e){if(!it(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function li(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||si.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=di(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;Gr(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)$r(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>Wr(e,t)),{promoted:a}}function ui(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function di(e,t,n){if(!K(n).includes(t))return ui(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?ui(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:ui(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):ui(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function fi(e,t){return e.get(t)||{name:t,missing:!0}}function pi(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 mi(e,t){return[...K(t),...pi(t)].map(t=>fi(e,t))}function q(e,t){if(Array.isArray(e)){for(let n of e)q(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),q(r,t);for(let e of Object.values(r))q(e,t)}function hi(e,t){let n=mi(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&q(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function gi(e){return!e||e.length===0?[]:e.slice(-4)}function _i(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${P(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
4
4
  `)}\n\n`}function vi(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||P(`repair.default_guidance`,{},t.labels),a=_i(gi(r),t.labels),o=`${P(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${P(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${P(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${P(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${P(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${P(`repair.section_instructions`,{},t.labels)}\n`,o+=P(`repair.prompt_instructions`,{},t.labels),o}function yi(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function bi(e,t){let n=yi(e,t);if(!(n.length<=1))throw new N(`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 xi(e,t){if(e.type!==`speech`){if(t.speech)throw new N(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new N(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function Si(e,t){return e.type===`speech`?{...e.speech,...Ci(t.speech)}:void 0}function Ci(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function wi(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 Ti(e){let t=Pe(e);if(!t)throw new N(`input`,`MIME '${e}' is not a supported media input type`);return t}function Ei(e){return e.map(e=>{let t=Ti(e.mimeType),n=j(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return Zn(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Di(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new N(`request`,`Profile ${e.id} (speech) requires text input`);if(M(e)?.text===!1&&n)throw new N(`request`,`Profile ${e.id} does not accept text input`);let a=r?vi({profile:e,repair:r,history:i}):ki(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Oi(t),...a?[tt(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
@@ -1,4 +1,4 @@
1
- import{Bn as e,dr as t,i as n,o as r}from"./tool-schema-idaOe2nI.js";var i=e.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=t.filter(e=>e===`audio/*`),o=`{
1
+ import{Bn as e,dr as t,i as n,o as r}from"./tool-schema-BrqSc6vO.js";var i=e.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=t.filter(e=>e===`audio/*`),o=`{
2
2
  "User-Agent": "TheoremStudio/1.0 (travel demo; +https://github.com/masudl-hub/theoremai)"
3
3
  }`,s=[`get_cat_fact`,`tell_joke`,`get_advice`,`random_dog_image`],c={geocode_city:{name:`Paris`},search_places:{q:`Paris`,limit:1},reverse_geocode:{lat:48.85,lon:2.35},get_weather:{latitude:48.85,longitude:2.35},get_sun_times:{lat:48.85,lng:2.35},convert_currency:{from:`USD`,to:`EUR`,amount:100},wikipedia_summary:{title:`Paris`},archive_text_search:{q:`mediatype:texts AND travel`,rows:1},lookup_postal_code:{country:`us`,postal:`90210`},get_pokemon:{name:`pikachu`},read_repo_file:{owner:`denoland`,repo:`std`,path:`README.md`},lookup_package:{name:`zod`},get_cat_fact:{},tell_joke:{},get_advice:{},random_dog_image:{}};function l(e){return c[e]}var u=`nominatim.openstreetmap.org, geocoding-api.open-meteo.com, api.open-meteo.com, api.frankfurter.dev, api.sunrise-sunset.org, api.zippopotam.us, en.wikipedia.org, archive.org, pokeapi.co, dog.ceo, api.adviceslip.com, catfact.ninja, official-joke-api.appspot.com, mcp.deepwiki.com, mcp.context7.com, learn.microsoft.com, docs.mcp.cloudflare.com, knowledge-mcp.global.api.aws, huggingface.co, mcp.docs.astro.build, mcp.exa.ai, raw.githubusercontent.com, registry.npmjs.org`,d=`Role: Elite, charismatic travel concierge.
4
4
 
@@ -1,8 +1,8 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/studio-monaco-xfyfezQS.js","assets/editor.api-Cd3ViPQa.js","assets/preload-helper-DpV6A1kQ.js","assets/editor-DjpsE8to.css","assets/studio-monaco-CbKf90i6.css","assets/register-CDgivxvX.js","assets/studio-type-checker-BOvxudki.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./preload-helper-DpV6A1kQ.js";import{Bt as i,D as a,T as o,Un as s,Vt as c,fr as l,k as u}from"./tool-schema-idaOe2nI.js";import{En as d,Sn as f,qt as p}from"./shaped-data-BcarWqd5.js";import{S as m,U as h,_ as g,h as _,m as v,v as y,y as b}from"./tree-DqyAMsbI.js";import{r as x}from"./live-ingress-lDUGPwth.js";import{n as S,t as C}from"./types-BhfXQCLx.js";import{n as w}from"./stub-DhdcU_Ew.js";import{F as T,M as E,k as ee,r as te}from"./workspace-DZALqEDX.js";import{t as ne}from"./PaneState-BvA2tLQg.js";import{K as re}from"./index-CvvmFKgS.js";var D=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},ie=class{text;of;i=0;line=1;column=1;constructor(e,t=`profile`){this.text=e,this.of=t}get done(){return this.i>=this.text.length}pos(){return{line:this.line,column:this.column}}fail(e){throw new D(e,this.line,this.column)}peek(e=0){return this.text[this.i+e]??``}bump(){let e=this.text[this.i]??``;return this.i+=1,e===`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/studio-monaco-xfyfezQS.js","assets/editor.api-Cd3ViPQa.js","assets/preload-helper-DpV6A1kQ.js","assets/editor-DjpsE8to.css","assets/studio-monaco-CbKf90i6.css","assets/register-CDgivxvX.js","assets/studio-type-checker-DosSRFbd.js"])))=>i.map(i=>d[i]);
2
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./preload-helper-DpV6A1kQ.js";import{Bt as i,D as a,T as o,Un as s,Vt as c,fr as l,k as u}from"./tool-schema-BrqSc6vO.js";import{En as d,Sn as f,qt as p}from"./shaped-data-BcarWqd5.js";import{S as m,U as h,_ as g,h as _,m as v,v as y,y as b}from"./tree-DeO1319a.js";import{r as x}from"./live-ingress-lDUGPwth.js";import{n as S,t as C}from"./types-EVrOoUBG.js";import{n as w}from"./stub-DEZDrr-l.js";import{F as T,M as E,k as ee,r as te}from"./workspace-Ck0o-_fd.js";import{t as ne}from"./PaneState-BvA2tLQg.js";import{K as re}from"./index-D2T8e_8Q.js";var D=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},ie=class{text;of;i=0;line=1;column=1;constructor(e,t=`profile`){this.text=e,this.of=t}get done(){return this.i>=this.text.length}pos(){return{line:this.line,column:this.column}}fail(e){throw new D(e,this.line,this.column)}peek(e=0){return this.text[this.i+e]??``}bump(){let e=this.text[this.i]??``;return this.i+=1,e===`
3
3
  `?(this.line+=1,this.column=1):this.column+=1,e}skip(){for(;;){let e=this.peek();if(e===` `||e===` `||e===`
4
4
  `||e===`\r`||e===``)this.bump();else if(e===`/`&&this.peek(1)===`/`)for(;!this.done&&this.peek()!==`
5
5
  `;)this.bump();else if(e===`/`&&this.peek(1)===`*`){for(this.bump(),this.bump();!this.done&&(this.peek()!==`*`||this.peek(1)!==`/`);)this.bump();this.done&&this.fail(`This comment never closes.`),this.bump(),this.bump()}else return}}starts(e){return this.skip(),this.text.startsWith(e,this.i)}eat(e){if(!this.starts(e))return!1;for(let t=0;t<e.length;t+=1)this.bump();return!0}expect(e){this.eat(e)||this.fail(`Expected '${e}'.`)}ident(){this.skip();let e=this.peek();if(!/^[A-Za-z_$]/.test(e))return;let t=``;for(;/^[A-Za-z0-9_$]/.test(this.peek());)t+=this.bump();return t}expectIdent(){let e=this.ident();return e===void 0&&this.fail(`Expected a name.`),e}peekIdent(){return this.skip(),/^[A-Za-z_$][A-Za-z0-9_$]*/.exec(this.text.slice(this.i))?.[0]}rest(){return this.skip(),this.text.slice(this.i)}};function O(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function k(e){e.skip();let t=e.peek();t!==`'`&&t!==`"`&&e.fail(`Expected a string.`),e.bump();let n=``;for(;!e.done&&e.peek()!==t;){let t=e.bump();if(t!==`\\`){n+=t;continue}let r=e.bump(),i={n:`
6
6
  `,r:`\r`,t:` `,"\\":`\\`,"'":`'`,'"':`"`};if(r in i)n+=i[r];else if(r===`u`){let t=``;for(let n=0;n<4;n+=1)t+=e.bump();n+=String.fromCharCode(Number.parseInt(t,16))}else n+=r}return e.peek()!==t&&e.fail(`This string never closes.`),e.bump(),n}function ae(e){e.skip();let t=e.pos(),n=``;for(e.peek()===`-`&&(n+=e.bump());/^[0-9.eE+-]/.test(e.peek())&&n.length<64;)n+=e.bump();let r=Number(n);if(!Number.isFinite(r))throw new D(`'${n}' is not a number.`,t.line,t.column);return r}function oe(e,t,n,r){let i=0;for(;!e.done;){if(r()&&i===0)return;let a=e.peek();a===`'`||a===`"`?k(e):(a!==``&&t.includes(a)?i+=1:a!==``&&n.includes(a)&&--i,e.bump())}}function se(e){oe(e,`<([{`,`>)]}`,()=>(e.skip(),e.peek()===`;`||e.peek()===`
7
7
  `))}function ce(e){oe(e,`{([`,`})]`,()=>e.peek()===`;`),e.peek()===`;`&&e.bump()}function le(e,t,n){e.expect(`{`);let r={};for(;!e.eat(`}`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`);let i=e.pos(),a;if(a=e.peek()===`'`||e.peek()===`"`?k(e):e.expectIdent(),a===`__proto__`)throw new D(`'__proto__' sets what an object inherits, not a setting.`,i.line,i.column);if(Object.hasOwn(r,a))throw new D(`'${a}' is set twice.`,i.line,i.column);let o=t?`${t}.${a}`:a;n.push({path:o,line:i.line,column:i.column}),e.expect(`:`),r[a]=F(e,o,n),e.eat(`,`),e.done&&e.fail(`This object never closes.`)}return r}function ue(e,t,n){e.expect(`[`);let r=[],i=0;for(;!e.eat(`]`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`),e.skip();let a=e.pos(),o=t?`${t}.${String(i)}`:String(i);n.push({path:o,line:a.line,column:a.column}),r.push(F(e,o,n)),i+=1,e.eat(`,`),e.done&&e.fail(`This array never closes.`)}return r}function de(e,t,n){let[r]=t;return e!==`z.fromJSONSchema`&&n.fail(`The studio reads a schema as JSON Schema: z.fromJSONSchema({ ... }), not '${e}'.`),O(r)||n.fail(`z.fromJSONSchema() needs a schema.`),r}function A(e){return O(e)&&e.kind===`member`}function fe(e,t){return{kind:`member`,object:e,name:t}}function pe(e){if(typeof e.object==`string`)return`${e.object}.${e.name}`;if(A(e.object)){let t=pe(e.object);return t?`${t}.${e.name}`:void 0}}function j(e,t,n){let r=e[0];return O(r)||t.fail(n),r}function me(e,t,n){let r=j(e,t,`registerTool() needs the tool object.`),i=r.type,a=typeof i==`string`&&C.includes(i);if(i!==void 0&&!a){let e=n.findLast(e=>e.path===`type`)??t.pos();throw new D(S,e.line,e.column)}return{kind:`registerTool`,tool:r}}function he(e,t,n,r){if(n.of===`provider`){if(e!==`registerProvider`)return n.fail(`'${e}' isn't part of a provider's code.`);let[r,i={}]=t;return typeof r!=`string`&&n.fail(`registerProvider() needs the definition it registers from.`),(!O(i)||t.length>2)&&n.fail(`registerProvider() takes the definition and its settings.`),{kind:`provider`,definition:r,spec:i}}return e===`compileDetect`?j(t,n,`compileDetect() needs the detect object.`):e===`defineProfile`?j(t,n,`defineProfile() needs the profile object.`):e===`registerTool`?me(t,n,r):e===`registerStructured`?{kind:`registerStructured`,args:t}:e===`registerProfile`||e===`registerProvider`?{kind:e}:n.fail(`'${e}' isn't part of this file.`)}function ge(e,t,n){return(typeof t!=`string`||e.some(e=>typeof e!=`string`))&&n.fail(`.join() here joins lines of one string.`),e.join(t)}function _e(e,t,n){if(e.name===`join`&&Array.isArray(e.object))return ge(e.object,t[0],n);if(e.name===`resolve`&&e.object===`Promise`)return t[0];let r=pe(e);return r?.startsWith(`z.`)?de(r,t,n):n.fail(`This call isn't part of this file.`)}function ve(e,t,n,r){return typeof e==`string`?he(e,t,n,r):(A(e)||n.fail(`This call isn't part of this file.`),_e(e,t,n))}function ye(e){return/^(async\s*)?\(\s*\)\s*=>/.test(e.rest())}function be(e,t,n){return e.peekIdent()===`async`&&e.expectIdent(),e.expect(`(`),e.eat(`)`)||e.fail(`A handler here takes no arguments. It returns a fixed value.`),e.expect(`=>`),F(e,t,n)}var M=class{name;constructor(e){this.name=e}};function N(e){return e instanceof M?e.name:e}function P(e,t,n){return ye(e)?be(e,t,n):Se(xe(e,t,n),e,t,n)}function xe(e,t,n){e.skip();let r=e.peek();if(r===`'`||r===`"`)return k(e);if(r==="`"&&e.fail(`This file doesn't use template strings.`),r===`-`||/^[0-9]/.test(r))return ae(e);if(r===`{`)return le(e,t,n);if(r===`[`)return ue(e,t,n);if(r===`(`){e.bump();let r=P(e,t,n);return e.expect(`)`),r}let i=e.ident();return i===`true`?!0:i===`false`?!1:i===`null`?null:(i===void 0&&e.fail(`Expected a value.`),new M(i))}function F(e,t,n){e.skip();let r=e.pos(),i=P(e,t,n);if(!(i instanceof M))return i;if(i.name!==`undefined`)throw new D(`'${i.name}' is set somewhere else. Write its value here.`,r.line,r.column)}function Se(e,t,n,r){let i=e;for(;;)if(t.eat(`.`)){let e=t.expectIdent();i=fe(N(i),e)}else if(t.eat(`(`)){let e=r.length,a=[];for(;!t.eat(`)`);)a.push(N(P(t,n,r))),t.eat(`,`),t.done&&t.fail(`This call never closes.`);i=ve(N(i),a,t,r.slice(e))}else return A(i)&&t.fail(`This file doesn't stop on a property.`),i}function Ce(e,t){e.expectIdent();let n=e.expectIdent();e.expect(`=`);let r=P(e,``,t.spans);(e.eat(`satisfies`)||e.eat(`as`))&&se(e),e.eat(`;`),e.of===`provider`?e.fail(`A provider's code is its registerProvider() call and nothing else.`):n===`profile`?(O(r)||e.fail(`profile has to be the defineProfile() object.`),t.profile&&e.fail(`This file defines two profiles.`),t.profile=r):n===`questions`?(O(r)||e.fail(`questions has to be an object.`),t.questions=r):n===`images`&&(O(r)||e.fail(`images has to be an object.`),t.images=r)}function we(e,t){let n=P(e,``,t.spans);if(e.eat(`;`),O(n)){if(n.kind===`provider`&&typeof n.definition==`string`&&O(n.spec))t.provider&&e.fail(`This code registers two providers.`),t.provider={definition:n.definition,spec:n.spec};else if(n.kind===`registerTool`){let r=n.tool;O(r)||e.fail(`registerTool() needs the tool object.`),t.tools.push(r)}else if(n.kind===`registerStructured`){let[r,i]=Array.isArray(n.args)?n.args:[];(typeof r!=`string`||!O(i))&&e.fail(`registerStructured() needs an id and a spec.`),t.structured={id:r,spec:i}}}}function I(e,t=`profile`){let n=new ie(e,t),r={tools:[],spans:[]};for(n.skip();!n.done;n.skip())n.peekIdent()===`import`?(n.expectIdent(),ce(n)):(n.peekIdent()===`export`&&n.expectIdent(),n.peekIdent()===`const`?Ce(n,r):we(n,r));return t===`provider`?r.provider||n.fail(`This code needs registerProvider().`):r.profile||n.fail(`This file needs defineProfile().`),r}function L(e,t=``){return typeof e==`string`?e:t}function R(e){return typeof e==`number`?e:null}function Te(e,t){if(e===void 0)return``;if(typeof e==`string`)return e;if(!Array.isArray(e))throw new D(t,1,1);return e.map(e=>{if(typeof e==`string`)return e;if(O(e)&&typeof e.private==`string`)return`{private: ${e.private}}`;throw new D(t,1,1)}).join(``)}function z(e){return e===void 0?``:JSON.stringify(e,null,2)}function Ee(e,t){return T(e)===T(t)}function B(e){return O(e)?JSON.stringify(e,null,2):JSON.stringify(e)}function V(e){return Array.isArray(e)?e.map(e=>{if(!O(e)||typeof e.name!=`string`)throw new D(`A pattern needs a name.`,1,1);return Array.isArray(e.words)?{name:e.name,kind:`words`,pattern:``,flags:``,words:e.words.filter(e=>typeof e==`string`)}:{name:e.name,kind:`pattern`,pattern:L(e.pattern),flags:L(e.flags),words:[]}}):[]}function H(e){return O(e)?e:void 0}function U(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function W(e){return Array.isArray(e)?U(e):void 0}function G(e){return L(e)||void 0}function K(e){return Array.isArray(e)?U(e).join(`
8
- `)||void 0:G(e)}function q(e,t,n){return O(e)?t(e):n}function De(e,t,n){if(!O(n))return;if(Array.isArray(n.names)){e.innocentNames=U(n.names);return}if(!(t in e.allow))return;let r=e.allow[t];r.hosts=U(n.hosts),r.fromTools=n.fromTools!==!1}function Oe(e,t,n){let r=H(n.at)??{};e.detect[t]={...e.detect[t],...r};let i=e.sources[t];i&&(n.theorem===!1&&(i.theorem=!1),i.patterns=V(n.patterns),i.hint=L(n.hint)),De(e,t,n.allow)}function ke(e,t){let n=d(f,()=>`ignore`);return O(t.at)&&Object.assign(n,t.at),{key:e,label:L(t.label),at:n,patterns:V(t.patterns),hint:L(t.hint)}}function Ae(e){let t=g().guardrails;if(!O(e))return t;let n={detect:structuredClone(t.detect),sources:structuredClone(t.sources),allow:structuredClone(t.allow),innocentNames:[...t.innocentNames]},r=[],i=new Set(p);for(let[t,a]of Object.entries(H(e.detect)??{}))O(a)&&(i.has(t)?Oe(n,t,a):r.push(ke(t,a)));let a=H(e.quota),o=H(e.blockedReply),s=H(e.network),c=H(e.taint);return{...t,...n,own:r,quotaEnabled:a!==void 0,quotaPerDay:R(a?.perDay),blockedReplyOnBlock:L(o?.onBlock),blockedReplyMaxRetries:R(o?.maxRetries),allowPrivateNetworks:s?.allowPrivateNetworks===!0,allowedHosts:U(s?.allowedHosts),allowedSchemes:U(s?.allowedSchemes),taintAfterRemoteRead:L(c?.afterRemoteRead),taintRemoteDestination:L(c?.remoteDestination)}}var je={"continue.instruction":(e,t)=>{e.turnBehaviour.continueInstruction=t},"canary.bind_note":(e,t)=>{e.guardrails.canaryBindNote=t},"quota.exhausted":(e,t)=>{e.guardrails.quotaMessage=t},"repair.default_guidance":(e,t)=>{e.outputs.repairGuidance=t},"egress.default_repair_guidance":(e,t)=>{e.guardrails.egressRepairGuidance=t},"egress.refusal":(e,t)=>{e.guardrails.egressRefusal=t}};function Me(e,t){if(!O(t))return;let n={};for(let[r,i]of Object.entries(t)){if(typeof i!=`string`)continue;let t=je[r];t?t(e,i):v[r]||(n[r]=i)}e.labels=n}function Ne(e,t,n,r,i){let a=n??y({modelId:e});if(!O(t))return{...a,modelId:e};let o=O(t.efforts)?Object.entries(t.efforts).map(([e,t])=>({alias:e,level:t})):[],s=O(t.compaction)?t.compaction:void 0,c=L(s?.profile),l=R(t.timeoutMs);return{...a,modelId:e,protocol:L(t.protocol,a.protocol),provider:L(t.provider,a.provider),apiId:L(t.apiId),options:H(t.options)??{},timeoutMs:l,efforts:o,defaultEffort:L(t.defaultEffort),allowEffortSelect:t.allowEffortSelect===!0,summaries:typeof t.summaries==`boolean`?t.summaries:null,maxOutputTokens:R(t.maxOutputTokens),temperature:typeof t.temperature==`number`?t.temperature:null,builtInTools:Array.isArray(t.builtInTools)?t.builtInTools.filter(e=>typeof e==`string`):[],keySlot:L(t.keySlot),fallbackKeySlot:L(t.fallbackKeySlot),compactTiming:L(s?.timing),compactMaxTokens:R(s?.maxTokens),compactAt:typeof s?.compactAt==`number`?s.compactAt:void 0,compactKeep:R(s?.previousExchanges),compactMeter:L(s?.meter),compactWith:c?Pe(c,r,`models.${e}.compaction.profile`,i):``}}function Pe(e,t,n,r){return t?t(e)??X(r,n,`'${e}' is not an agent here, so it can't write this model's summaries.`):``}function Fe(e,t){let n=t.output;if(e===`function`&&O(t.handler)&&O(n)&&!Ee(t.handler,w(n)))return z(t.handler)}function Ie(e){let t=H(e.mapping)??{};return{endpoint:G(e.endpoint),method:G(e.method),headersJson:O(e.headers)?z(e.headers):void 0,pathParams:W(t.pathParams),queryParams:W(t.queryParams),bodyParam:G(t.bodyParam),serverUrl:G(e.serverUrl),mcpToolName:G(e.mcpToolName)}}function Le(e){let t=H(e.auth)??{};return{authType:L(t.type),authSlot:G(t.slot),authService:G(t.service),authHeaderName:G(t.headerName),authHeaderPrefix:typeof t.headerPrefix==`string`?t.headerPrefix:void 0,authQueryParam:G(t.queryParam),authUnauthenticated:L(t.onUnauthenticated),authScopes:W(t.scopes),authClientId:G(t.clientId),authRedirectUri:G(t.redirectUri)}}function Re(e,t,n){let r=t??b(),i=L(e.type,r.toolType),a=H(e.labels)??{},o=L(e.profile),s=e.answeredBy===`page`;return{...r,key:t?.key??m(`tool`),toolName:L(e.name,r.toolName),toolType:i,description:L(e.description),category:L(e.category,`studio`),access:L(e.access,r.access),permission:L(e.permission,r.permission),loadTier:L(e.loadTier,r.loadTier),paths:W(e.paths)??[`*`],inputJson:e.input===void 0?r.inputJson:B(e.input),outputJson:e.output===void 0?r.outputJson:B(e.output),activity:K(a.activity),activityPast:K(a.activityPast),activityFailed:K(a.activityFailed),request:K(a.request),stubOutputJson:s?t?.stubOutputJson:Fe(i,e),answeredBy:s?`page`:void 0,...Ie(e),agentKey:o?n?.(o):void 0,maxCallsPerTurn:R(e.maxCallsPerTurn),...Le(e)}}function ze(e,t){let n=new Map(t.map(e=>[e.id,e]));return Object.entries(e).map(([e,t])=>{let r=n.get(e),i=O(t)?t:{},a=L(i.type,`choice`),o=i.criteria,s=Array.isArray(o)?o.map((e,t)=>({key:r?.criteria[t]?.key??m(`criterion`),label:``,text:L(e)})):O(o)?Object.entries(o).map(([e,t],n)=>({key:r?.criteria[n]?.key??m(`criterion`),label:e,text:L(t)})):[];return{key:r?.key??m(`question`),id:e,type:a,instructions:L(i.instructions),criteria:s,...a===`box`&&L(i.image)?{image:L(i.image)}:{}}})}function Be(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)if(O(n)){if(typeof n.uri==`string`){let e=L(n.name);t.push({key:m(`reference`),uri:n.uri,...e?{name:e}:{}})}else typeof n.data==`string`&&t.push({key:m(`reference`),name:L(n.name),mimeType:L(n.mimeType),data:n.data})}return t}function Ve(e,t){return e?h.filter(n=>!n.optional||n.role===`branch`||!n.profileTypes.includes(e)?!1:n.profilePath in t).map(e=>e.id):g().included}function He(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Re(o,t.get(L(o.name)),n);if(e.toolName&&a.has(e.toolName)){let t=r.filter(e=>e.path===`name`)[i.length]??{line:1,column:1};throw new D(`'${e.toolName}' is registered twice.`,t.line,t.column)}e.toolName&&a.add(e.toolName),i.push(e)}return i}function Ue(e,t,n){if(t===void 0)return[];let r=n.findLast(e=>e.path===`tools.allow`)??{line:1,column:1};if(!Array.isArray(t))throw new D(`tools.allow has to be a list of tool names.`,r.line,r.column);let i=new Map(e.map(e=>[e.toolName,e])),a=[],o=new Set;for(let[e,s]of t.entries()){let t=n.find(t=>t.path===`tools.allow.${String(e)}`)??r;if(typeof s!=`string`||s.trim()===``)throw new D(`tools.allow names tools.`,t.line,t.column);if(o.has(s))throw new D(`'${s}' is listed twice in tools.allow.`,t.line,t.column);o.add(s);let c=i.get(s);if(!c)throw new D(`'${s}' is in tools.allow, and this file has no registerTool for it.`,t.line,t.column);a.push(c)}return a}function We(e,t,n){let r=H(t.identity)??{},i=r.systemByRole;return{...e,agentId:L(t.id),profileType:n,handle:L(r.handle),system:Te(r.system,`The system prompt has to be text.`),systemByRoleJson:O(i)||Array.isArray(i)?z(i):``}}function Ge(e){return{...O(e.providerContinuation)&&(e.providerContinuation.history===`provider`||e.providerContinuation.history===`stateless`)?{providerHistory:e.providerContinuation.history}:{},defaultModel:L(e.defaultModel),allowModelSelect:e.allowModelSelect===!0,maxSteps:R(e.maxSteps),key:L(e.key),fallbackKey:L(e.fallbackKey)}}function Ke(e){return s.includes(e)}function qe(e){let t=H(e.context);return{text:e.text!==!1,attachmentsAccept:U(H(e.attachments)?.accept),voiceAccept:U(H(e.voice)?.accept),maxFiles:R(e.maxFiles),maxBytes:R(e.maxBytes),maxTurnBytes:R(e.maxTurnBytes),limitsByMimeJson:z(e.limitsByMime),slotsJson:z(e.slots),contextFrom:U(t?.from).filter(Ke),contextMaxChars:R(t?.maxChars)}}function Je(e){return Object.fromEntries(Object.entries(e??{}).map(([e,t])=>[e,H(t)?.onFail===`fix`?`fix`:`drop`]))}function Ye(e,t){let n=t?.id??L(e?.structured),r=H(e?.streaming),i=H(e?.validation);return{mode:n?`structured`:`text`,schemaId:n,schemaJson:z(t?.spec.jsonSchema),streamMode:L(r?.mode),streamThoughts:r?.streamThoughts!==!1,validationEnabled:i!==void 0,maxRetries:R(i?.maxRetries),itemRules:Je(H(i?.items)),repairGuidance:``}}function Xe(e){let t=H(e.resumption),n=Array.isArray(t?.allowContinue)?t.allowContinue:[...i],r=Array.isArray(t?.autoContinue)?t.autoContinue:[...c];return{resumeEnabled:n.length>0||r.length>0,allowContinue:n,autoContinue:r,maxContinues:R(t?.maxContinues),continueInstruction:``,allowSteering:e.allowSteering!==!1,atStepLimit:e.atStepLimit===`answer`?`answer`:`stop`}}function Ze(e){let t=g().observability,n=typeof e.writeTo==`string`&&e.writeTo?e.writeTo:t.destination;return{...t,writeTo:e.writeTo!==!1&&n,destination:n,sampleRate:typeof e.sampleRate==`number`?e.sampleRate:t.sampleRate,include:{...t.include,...H(e.include)},scrub:{...t.scrub,...H(e.scrub)},retainForDays:R(e.retainForDays),rotateAfterMiB:R(e.rotateAfterMiB),resourceJson:z(e.resource)}}function Qe(e){return{aspectRatio:L(e.aspectRatio),resolution:L(e.resolution),mimeType:L(e.mimeType),quality:L(e.quality),background:L(e.background),n:R(e.n),seed:R(e.seed),outputCompression:R(e.outputCompression),includeText:e.includeText===!0,references:Be(e.references)}}function $e(e){return{voice:L(e.voice),style:L(e.style),speed:R(e.speed),format:L(e.format)}}function J(e,t){let n=e[t];return typeof n==`boolean`?n:x(t)}function et(e){let t=H(e.ingress)??{},n=H(e.vad)??{},r=H(e.contextCompression),i=H(r?.slidingWindow),a=H(e.transcription);return{ingressAudio:J(t,`audio`),ingressVideo:J(t,`video`),ingressText:J(t,`text`),voice:L(e.voice),sessionResumption:e.sessionResumption===!0,greeting:L(e.greeting),resumedPrompt:L(H(e.resumed)?.prompt),resumedAfterMs:R(H(e.resumed)?.afterMs),contextCompression:r!==void 0,compressionTriggerTokens:R(r?.triggerTokens),compressionTargetTokens:R(i?.targetTokens),transcriptionInput:a?.input===!0,transcriptionOutput:a?.output===!0,vadActivityHandling:L(n.activityHandling),vadStartSensitivity:L(n.startSensitivity),vadEndSensitivity:L(n.endSensitivity),vadPrefixPaddingMs:R(n.prefixPaddingMs),vadSilenceDurationMs:R(n.silenceDurationMs)}}function tt(e,t,n){let r=R(H(t.profile?.inputs)?.maxStateBytes);return{contract:L(e.contract),maxStateBytes:r,questions:t.questions?ze(t.questions,n.questions):[],images:t.images?nt(t.images,n.images):[]}}function nt(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(e).map(([e,t])=>{let r=e.replace(/^<|>$/g,``),i=O(t)?t:{};return{key:n.get(r)?.key??m(`image`),name:r,mimeType:L(i.mimeType),data:L(i.data)}})}function rt(e){let t=L(e.type);if(t&&!_.includes(t))throw new D(`'${t}' is not a profile type.`,1,1);return t}var it=[`turnBehaviour.atStepLimit`,`outputs.validation.items.*.onFail`];function at(e,t){for(let n of it){let r=l(n)?.options??[];for(let[i,a]of Y(e,n.split(`.`),[]))a!==void 0&&!r.includes(a)&&X(t,i,`${JSON.stringify(a)} is not one of ${r.map(e=>`'${e}'`).join(`, `)}.`)}}function Y(e,t,n){let[r,...i]=t;return r===void 0?[[n.join(`.`),e]]:O(e)?(r===`*`?Object.keys(e):[r]).flatMap(t=>Y(e[t],i,[...n,t])):[]}function ot(e,t,n){let r=e.profile??{},i=rt(r);at(r,e.spans);let a=new Map(t.modelBindings.map(e=>[e.modelId,e])),o=new Map(t.toolSpecs.map(e=>[e.toolName,e])),s=H(r.tools)??{},c=H(r.inputs),l=H(r.outputs),u={...t,identity:We(t.identity,r,i),included:Ve(i,r),models:Ge(r),modelBindings:Object.entries(H(r.models)??{}).map(([t,r])=>Ne(t,r,a.get(t),n,e.spans)),tools:{t2Loader:L(s.t2Loader),parallel:s.parallel===!0},toolSpecs:[],inputs:c&&i!==`decision`?qe(c):t.inputs,outputs:l||e.structured?Ye(l,e.structured):t.outputs,turnBehaviour:q(r.turnBehaviour,Xe,t.turnBehaviour),guardrails:q(r.guardrails,Ae,t.guardrails),observability:q(r.observability,Ze,t.observability),image:q(r.image,Qe,t.image),speech:q(r.speech,$e,t.speech),live:q(r.live,et,t.live),decision:q(r.decision,n=>tt(n,e,t.decision),t.decision),labels:{}},d=He(e.tools,o,n,e.spans),f=Ue(d,s.allow,e.spans);u.toolSpecs=f;let p=new Set(f.map(e=>e.toolName));return u.tools.t2Loader&&!p.has(u.tools.t2Loader)&&(u.tools={...u.tools,t2Loader:``}),Me(u,r.labels),{draft:u,registered:d}}function st(e,t,n){try{let r=I(e),{draft:i,registered:a}=ot(r,t,n);return{ok:!0,draft:i,spans:r.spans,registered:a}}catch(e){if(e instanceof D)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}function X(e,t,n){let r=e.findLast(e=>e.path===t)??{line:1,column:1};throw new D(n,r.line,r.column)}var ct=new Set([`id`,`connection`,`keySlot`,`fallbackKeySlot`]);function lt(e,t,n){let{spec:r}=e;for(let e of Object.keys(r))ct.has(e)||X(n,e,`'${e}' isn't a provider setting the studio holds.`);r.id!==t.id&&X(n,`id`,`The id stays '${t.id}': models and code name the provider by it.`);let i=a(e.definition);if(!i){let t=u().flatMap(e=>o(e)??[]).join(`, `);X(n,``,`'${e.definition}' isn't one of the kernel's providers: ${t}.`)}let s=r.connection===void 0?{}:ut(r.connection,n),c=Object.keys(s).length===0&&t.connection===void 0,l={id:t.id,definition:i,...c?{}:{connection:s}};for(let e of[`keySlot`,`fallbackKeySlot`]){let t=r[e];t!==void 0&&(typeof t!=`string`&&X(n,e,`${e} names a key slot.`),l[e]=t)}return l}function ut(e,t){let n=`connection holds text settings here.`,r={};O(e)||X(t,`connection`,n);for(let[i,a]of Object.entries(e))typeof a!=`string`&&X(t,`connection`,n),r[i]=a;return r}function dt(e,t){try{let n=I(e,`provider`);if(!n.provider)throw new D(`This code needs registerProvider().`,1,1);return{ok:!0,provider:lt(n.provider,t,n.spans),spans:n.spans}}catch(e){if(e instanceof D)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}var Z=e(n(),1),Q=t(),ft=300,pt=2e3;function mt({editor:e,monaco:t,spans:n,errors:r},i){let a=e?.getModel();t&&a&&t.editor.setModelMarkers(a,`studio`,[...r.map(e=>$(t,e.line,e.column,e.message)),...gt(t,n,i)])}function ht({text:e,hold:t,isReadOnly:n=!1,issues:i,onApply:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(a),c=(0,Z.useRef)(e),l=(0,Z.useRef)(n);l.current=n;let u=(0,Z.useRef)(i),d=(0,Z.useRef)({spans:[],errors:[],setting:!1,dirty:!1});return s.current=a,c.current=e,u.current=i,(0,Z.useEffect)(()=>{let e=o.current;if(!e)return;let t={disposed:!1},n,i,a=0,f,p=!1,m=!1,h=()=>{a+=1,i&&clearTimeout(i),i=void 0,f?.stop(),f=void 0,p=!1,m=!1},g=t=>e.contains(t)?!0:t instanceof Element&&!!t.closest(`.suggest-widget, .parameter-hints-widget, .monaco-hover, .monaco-menu-container, .context-view`),_=()=>!!document.querySelector(`.suggest-widget.visible, .parameter-hints-widget.visible`),v,y=()=>{mt(d.current,u.current)};return(async()=>{let o=await r(()=>import(`./studio-monaco-xfyfezQS.js`),__vite__mapDeps([0,1,2,3,4]));await r(()=>import(`./register-CDgivxvX.js`),__vite__mapDeps([5,2,1,3]));let u=(await r(async()=>{let{default:e}=await import(`./editor.worker-6GY8RhDc.js`);return{default:e}},[])).default;if(self.MonacoEnvironment={getWorker(){return new u}},t.disposed||!e.isConnected)return;let b=document.documentElement.dataset.theme===`dark`||globalThis.matchMedia(`(prefers-color-scheme: dark)`).matches,x=o.Uri.parse(`file:///agent.ts`);o.editor.getModel(x)?.dispose();let S=o.editor.createModel(c.current,`typescript`,x),C=o.editor.create(e,{model:S,readOnly:l.current,language:`typescript`,theme:b?`vs-dark`:`vs`,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,wrappingIndent:`indent`,scrollBeyondLastLine:!1,automaticLayout:!0,fixedOverflowWidgets:!0,tabSize:2,padding:{top:12},quickSuggestions:{other:!0,comments:!1,strings:!0},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,tabCompletion:`on`,wordBasedSuggestions:`currentDocument`,parameterHints:{enabled:!0},suggest:{preview:!0,showIcons:!0}});d.current.editor=C,d.current.monaco=o;let w=()=>{i&&clearTimeout(i),i=setTimeout(()=>{t.disposed||(_()?w():h())},pt)},T=()=>{if(f){m&&w();return}if(p)return;let e=a,n=()=>t.disposed||e!==a;p=!0,r(async()=>{let{openTypeChecker:e}=await import(`./studio-type-checker-BOvxudki.js`);return{openTypeChecker:e}},__vite__mapDeps([6,2])).then(({openTypeChecker:r})=>{if(n())return;let i=r(o,C,()=>{t.disposed||e!==a||(m=!0,w())});n()?i.stop():f=i}).catch(()=>{}).finally(()=>{e===a&&(p=!1)})};C.onKeyDown(e=>{let t=e.browserEvent;t.metaKey||t.ctrlKey||t.altKey||m&&w()});let E=e=>{let t=e.target;t instanceof Node&&!g(t)&&h()};document.addEventListener(`pointerdown`,E,!0),v=()=>{document.removeEventListener(`pointerdown`,E,!0)},C.onDidBlurEditorText(()=>{queueMicrotask(()=>{if(t.disposed||C.hasTextFocus())return;let e=document.activeElement;e&&g(e)||h()})}),C.onDidChangeModelContent(()=>{if(d.current.setting)return;T();let e=C.getValue();d.current.dirty=e!==c.current,n&&clearTimeout(n),n=setTimeout(()=>{let t=s.current(e);d.current.spans=t.spans,d.current.errors=t.errors,y()},ft)}),y()})(),()=>{t.disposed=!0,v?.(),h(),n&&clearTimeout(n);let e=d.current.editor?.getModel();d.current.editor?.dispose(),e?.dispose(),d.current.editor=void 0}},[]),(0,Z.useEffect)(()=>{let{editor:n}=d.current;n&&!t&&(d.current.dirty&&n.getValue()!==e||(n.getValue()===e||(d.current.setting=!0,n.setValue(e),d.current.setting=!1),d.current.dirty=!1))},[e,t]),(0,Z.useEffect)(()=>{d.current.editor?.updateOptions({readOnly:n})},[n]),(0,Z.useEffect)(()=>{mt(d.current,i)},[i]),(0,Q.jsx)(`div`,{ref:o,className:`studio-fill`})}function $(e,t,n,r){return{startLineNumber:t,startColumn:n,endLineNumber:t,endColumn:n+1,message:r,severity:e.MarkerSeverity.Error}}function gt(e,t,n){return n.flatMap(n=>{let r=n.field?`${n.nodeId}.${n.field}`:n.nodeId,i=t.find(e=>e.path===r)??(n.field?t.find(e=>e.path===n.field):void 0);return i?[$(e,i.line,i.column,n.message)]:[]})}function _t({source:e,blocked:t,issues:n,state:r}){let i=(0,Z.useRef)(e);e&&(i.current=e);let a=(0,Z.useCallback)(e=>{let t=te(r.workspace,r.focus);if(!t)return{errors:[{message:`No agent is open.`,line:1,column:1}],spans:[]};let n=st(e,{...t,toolSpecs:r.workspace.toolSpecs},e=>r.workspace.agents.find(t=>t.identity.agentId.trim()===e)?.key);return n.ok?(r.update(e=>ee(e,r.focus,n.draft,n.registered)),{errors:[],spans:n.spans}):{errors:n.errors,spans:[]}},[r]);return i.current?(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(ht,{text:e??i.current,hold:e==null,issues:n,onApply:a})}):(0,Q.jsx)(ne,{title:`No code yet`,description:`${t??``} to generate the TypeScript.`})}function vt({provider:e,issues:t,state:n,isEditable:r}){let i=(0,Z.useCallback)(t=>{let r=n.workspace.providers.find(t=>t.id===e.id);if(!r)return{errors:[{message:`No provider is open.`,line:1,column:1}],spans:[]};let i=dt(t,r);return i.ok?(n.update(e=>E(e,i.provider)),{errors:[],spans:i.spans}):{errors:i.errors,spans:[]}},[n,e.id]);return(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(ht,{text:re(e),hold:!1,isReadOnly:!r||o(e.definition)===void 0,issues:t,onApply:i},e.id)})}export{_t as CodeBody,vt as ProviderCode};
8
+ `)||void 0:G(e)}function q(e,t,n){return O(e)?t(e):n}function De(e,t,n){if(!O(n))return;if(Array.isArray(n.names)){e.innocentNames=U(n.names);return}if(!(t in e.allow))return;let r=e.allow[t];r.hosts=U(n.hosts),r.fromTools=n.fromTools!==!1}function Oe(e,t,n){let r=H(n.at)??{};e.detect[t]={...e.detect[t],...r};let i=e.sources[t];i&&(n.theorem===!1&&(i.theorem=!1),i.patterns=V(n.patterns),i.hint=L(n.hint)),De(e,t,n.allow)}function ke(e,t){let n=d(f,()=>`ignore`);return O(t.at)&&Object.assign(n,t.at),{key:e,label:L(t.label),at:n,patterns:V(t.patterns),hint:L(t.hint)}}function Ae(e){let t=g().guardrails;if(!O(e))return t;let n={detect:structuredClone(t.detect),sources:structuredClone(t.sources),allow:structuredClone(t.allow),innocentNames:[...t.innocentNames]},r=[],i=new Set(p);for(let[t,a]of Object.entries(H(e.detect)??{}))O(a)&&(i.has(t)?Oe(n,t,a):r.push(ke(t,a)));let a=H(e.quota),o=H(e.blockedReply),s=H(e.network),c=H(e.taint);return{...t,...n,own:r,quotaEnabled:a!==void 0,quotaPerDay:R(a?.perDay),blockedReplyOnBlock:L(o?.onBlock),blockedReplyMaxRetries:R(o?.maxRetries),allowPrivateNetworks:s?.allowPrivateNetworks===!0,allowedHosts:U(s?.allowedHosts),allowedSchemes:U(s?.allowedSchemes),taintAfterRemoteRead:L(c?.afterRemoteRead),taintRemoteDestination:L(c?.remoteDestination)}}var je={"continue.instruction":(e,t)=>{e.turnBehaviour.continueInstruction=t},"canary.bind_note":(e,t)=>{e.guardrails.canaryBindNote=t},"quota.exhausted":(e,t)=>{e.guardrails.quotaMessage=t},"repair.default_guidance":(e,t)=>{e.outputs.repairGuidance=t},"egress.default_repair_guidance":(e,t)=>{e.guardrails.egressRepairGuidance=t},"egress.refusal":(e,t)=>{e.guardrails.egressRefusal=t}};function Me(e,t){if(!O(t))return;let n={};for(let[r,i]of Object.entries(t)){if(typeof i!=`string`)continue;let t=je[r];t?t(e,i):v[r]||(n[r]=i)}e.labels=n}function Ne(e,t,n,r,i){let a=n??y({modelId:e});if(!O(t))return{...a,modelId:e};let o=O(t.efforts)?Object.entries(t.efforts).map(([e,t])=>({alias:e,level:t})):[],s=O(t.compaction)?t.compaction:void 0,c=L(s?.profile),l=R(t.timeoutMs);return{...a,modelId:e,protocol:L(t.protocol,a.protocol),provider:L(t.provider,a.provider),apiId:L(t.apiId),options:H(t.options)??{},timeoutMs:l,efforts:o,defaultEffort:L(t.defaultEffort),allowEffortSelect:t.allowEffortSelect===!0,summaries:typeof t.summaries==`boolean`?t.summaries:null,maxOutputTokens:R(t.maxOutputTokens),temperature:typeof t.temperature==`number`?t.temperature:null,builtInTools:Array.isArray(t.builtInTools)?t.builtInTools.filter(e=>typeof e==`string`):[],keySlot:L(t.keySlot),fallbackKeySlot:L(t.fallbackKeySlot),compactTiming:L(s?.timing),compactMaxTokens:R(s?.maxTokens),compactAt:typeof s?.compactAt==`number`?s.compactAt:void 0,compactKeep:R(s?.previousExchanges),compactMeter:L(s?.meter),compactWith:c?Pe(c,r,`models.${e}.compaction.profile`,i):``}}function Pe(e,t,n,r){return t?t(e)??X(r,n,`'${e}' is not an agent here, so it can't write this model's summaries.`):``}function Fe(e,t){let n=t.output;if(e===`function`&&O(t.handler)&&O(n)&&!Ee(t.handler,w(n)))return z(t.handler)}function Ie(e){let t=H(e.mapping)??{};return{endpoint:G(e.endpoint),method:G(e.method),headersJson:O(e.headers)?z(e.headers):void 0,pathParams:W(t.pathParams),queryParams:W(t.queryParams),bodyParam:G(t.bodyParam),serverUrl:G(e.serverUrl),mcpToolName:G(e.mcpToolName)}}function Le(e){let t=H(e.auth)??{};return{authType:L(t.type),authSlot:G(t.slot),authService:G(t.service),authHeaderName:G(t.headerName),authHeaderPrefix:typeof t.headerPrefix==`string`?t.headerPrefix:void 0,authQueryParam:G(t.queryParam),authUnauthenticated:L(t.onUnauthenticated),authScopes:W(t.scopes),authClientId:G(t.clientId),authRedirectUri:G(t.redirectUri)}}function Re(e,t,n){let r=t??b(),i=L(e.type,r.toolType),a=H(e.labels)??{},o=L(e.profile),s=e.answeredBy===`page`;return{...r,key:t?.key??m(`tool`),toolName:L(e.name,r.toolName),toolType:i,description:L(e.description),category:L(e.category,`studio`),access:L(e.access,r.access),permission:L(e.permission,r.permission),loadTier:L(e.loadTier,r.loadTier),paths:W(e.paths)??[`*`],inputJson:e.input===void 0?r.inputJson:B(e.input),outputJson:e.output===void 0?r.outputJson:B(e.output),activity:K(a.activity),activityPast:K(a.activityPast),activityFailed:K(a.activityFailed),request:K(a.request),stubOutputJson:s?t?.stubOutputJson:Fe(i,e),answeredBy:s?`page`:void 0,...Ie(e),agentKey:o?n?.(o):void 0,maxCallsPerTurn:R(e.maxCallsPerTurn),...Le(e)}}function ze(e,t){let n=new Map(t.map(e=>[e.id,e]));return Object.entries(e).map(([e,t])=>{let r=n.get(e),i=O(t)?t:{},a=L(i.type,`choice`),o=i.criteria,s=Array.isArray(o)?o.map((e,t)=>({key:r?.criteria[t]?.key??m(`criterion`),label:``,text:L(e)})):O(o)?Object.entries(o).map(([e,t],n)=>({key:r?.criteria[n]?.key??m(`criterion`),label:e,text:L(t)})):[];return{key:r?.key??m(`question`),id:e,type:a,instructions:L(i.instructions),criteria:s,...a===`box`&&L(i.image)?{image:L(i.image)}:{}}})}function Be(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)if(O(n)){if(typeof n.uri==`string`){let e=L(n.name);t.push({key:m(`reference`),uri:n.uri,...e?{name:e}:{}})}else typeof n.data==`string`&&t.push({key:m(`reference`),name:L(n.name),mimeType:L(n.mimeType),data:n.data})}return t}function Ve(e,t){return e?h.filter(n=>!n.optional||n.role===`branch`||!n.profileTypes.includes(e)?!1:n.profilePath in t).map(e=>e.id):g().included}function He(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Re(o,t.get(L(o.name)),n);if(e.toolName&&a.has(e.toolName)){let t=r.filter(e=>e.path===`name`)[i.length]??{line:1,column:1};throw new D(`'${e.toolName}' is registered twice.`,t.line,t.column)}e.toolName&&a.add(e.toolName),i.push(e)}return i}function Ue(e,t,n){if(t===void 0)return[];let r=n.findLast(e=>e.path===`tools.allow`)??{line:1,column:1};if(!Array.isArray(t))throw new D(`tools.allow has to be a list of tool names.`,r.line,r.column);let i=new Map(e.map(e=>[e.toolName,e])),a=[],o=new Set;for(let[e,s]of t.entries()){let t=n.find(t=>t.path===`tools.allow.${String(e)}`)??r;if(typeof s!=`string`||s.trim()===``)throw new D(`tools.allow names tools.`,t.line,t.column);if(o.has(s))throw new D(`'${s}' is listed twice in tools.allow.`,t.line,t.column);o.add(s);let c=i.get(s);if(!c)throw new D(`'${s}' is in tools.allow, and this file has no registerTool for it.`,t.line,t.column);a.push(c)}return a}function We(e,t,n){let r=H(t.identity)??{},i=r.systemByRole;return{...e,agentId:L(t.id),profileType:n,handle:L(r.handle),system:Te(r.system,`The system prompt has to be text.`),systemByRoleJson:O(i)||Array.isArray(i)?z(i):``}}function Ge(e){return{...O(e.providerContinuation)&&(e.providerContinuation.history===`provider`||e.providerContinuation.history===`stateless`)?{providerHistory:e.providerContinuation.history}:{},defaultModel:L(e.defaultModel),allowModelSelect:e.allowModelSelect===!0,maxSteps:R(e.maxSteps),key:L(e.key),fallbackKey:L(e.fallbackKey)}}function Ke(e){return s.includes(e)}function qe(e){let t=H(e.context);return{text:e.text!==!1,attachmentsAccept:U(H(e.attachments)?.accept),voiceAccept:U(H(e.voice)?.accept),maxFiles:R(e.maxFiles),maxBytes:R(e.maxBytes),maxTurnBytes:R(e.maxTurnBytes),limitsByMimeJson:z(e.limitsByMime),slotsJson:z(e.slots),contextFrom:U(t?.from).filter(Ke),contextMaxChars:R(t?.maxChars)}}function Je(e){return Object.fromEntries(Object.entries(e??{}).map(([e,t])=>[e,H(t)?.onFail===`fix`?`fix`:`drop`]))}function Ye(e,t){let n=t?.id??L(e?.structured),r=H(e?.streaming),i=H(e?.validation);return{mode:n?`structured`:`text`,schemaId:n,schemaJson:z(t?.spec.jsonSchema),streamMode:L(r?.mode),streamThoughts:r?.streamThoughts!==!1,validationEnabled:i!==void 0,maxRetries:R(i?.maxRetries),itemRules:Je(H(i?.items)),repairGuidance:``}}function Xe(e){let t=H(e.resumption),n=Array.isArray(t?.allowContinue)?t.allowContinue:[...i],r=Array.isArray(t?.autoContinue)?t.autoContinue:[...c];return{resumeEnabled:n.length>0||r.length>0,allowContinue:n,autoContinue:r,maxContinues:R(t?.maxContinues),continueInstruction:``,allowSteering:e.allowSteering!==!1,atStepLimit:e.atStepLimit===`answer`?`answer`:`stop`}}function Ze(e){let t=g().observability,n=typeof e.writeTo==`string`&&e.writeTo?e.writeTo:t.destination;return{...t,writeTo:e.writeTo!==!1&&n,destination:n,sampleRate:typeof e.sampleRate==`number`?e.sampleRate:t.sampleRate,include:{...t.include,...H(e.include)},scrub:{...t.scrub,...H(e.scrub)},retainForDays:R(e.retainForDays),rotateAfterMiB:R(e.rotateAfterMiB),resourceJson:z(e.resource)}}function Qe(e){return{aspectRatio:L(e.aspectRatio),resolution:L(e.resolution),mimeType:L(e.mimeType),quality:L(e.quality),background:L(e.background),n:R(e.n),seed:R(e.seed),outputCompression:R(e.outputCompression),includeText:e.includeText===!0,references:Be(e.references)}}function $e(e){return{voice:L(e.voice),style:L(e.style),speed:R(e.speed),format:L(e.format)}}function J(e,t){let n=e[t];return typeof n==`boolean`?n:x(t)}function et(e){let t=H(e.ingress)??{},n=H(e.vad)??{},r=H(e.contextCompression),i=H(r?.slidingWindow),a=H(e.transcription);return{ingressAudio:J(t,`audio`),ingressVideo:J(t,`video`),ingressText:J(t,`text`),voice:L(e.voice),sessionResumption:e.sessionResumption===!0,greeting:L(e.greeting),resumedPrompt:L(H(e.resumed)?.prompt),resumedAfterMs:R(H(e.resumed)?.afterMs),contextCompression:r!==void 0,compressionTriggerTokens:R(r?.triggerTokens),compressionTargetTokens:R(i?.targetTokens),transcriptionInput:a?.input===!0,transcriptionOutput:a?.output===!0,vadActivityHandling:L(n.activityHandling),vadStartSensitivity:L(n.startSensitivity),vadEndSensitivity:L(n.endSensitivity),vadPrefixPaddingMs:R(n.prefixPaddingMs),vadSilenceDurationMs:R(n.silenceDurationMs)}}function tt(e,t,n){let r=R(H(t.profile?.inputs)?.maxStateBytes);return{contract:L(e.contract),maxStateBytes:r,questions:t.questions?ze(t.questions,n.questions):[],images:t.images?nt(t.images,n.images):[]}}function nt(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(e).map(([e,t])=>{let r=e.replace(/^<|>$/g,``),i=O(t)?t:{};return{key:n.get(r)?.key??m(`image`),name:r,mimeType:L(i.mimeType),data:L(i.data)}})}function rt(e){let t=L(e.type);if(t&&!_.includes(t))throw new D(`'${t}' is not a profile type.`,1,1);return t}var it=[`turnBehaviour.atStepLimit`,`outputs.validation.items.*.onFail`];function at(e,t){for(let n of it){let r=l(n)?.options??[];for(let[i,a]of Y(e,n.split(`.`),[]))a!==void 0&&!r.includes(a)&&X(t,i,`${JSON.stringify(a)} is not one of ${r.map(e=>`'${e}'`).join(`, `)}.`)}}function Y(e,t,n){let[r,...i]=t;return r===void 0?[[n.join(`.`),e]]:O(e)?(r===`*`?Object.keys(e):[r]).flatMap(t=>Y(e[t],i,[...n,t])):[]}function ot(e,t,n){let r=e.profile??{},i=rt(r);at(r,e.spans);let a=new Map(t.modelBindings.map(e=>[e.modelId,e])),o=new Map(t.toolSpecs.map(e=>[e.toolName,e])),s=H(r.tools)??{},c=H(r.inputs),l=H(r.outputs),u={...t,identity:We(t.identity,r,i),included:Ve(i,r),models:Ge(r),modelBindings:Object.entries(H(r.models)??{}).map(([t,r])=>Ne(t,r,a.get(t),n,e.spans)),tools:{t2Loader:L(s.t2Loader),parallel:s.parallel===!0},toolSpecs:[],inputs:c&&i!==`decision`?qe(c):t.inputs,outputs:l||e.structured?Ye(l,e.structured):t.outputs,turnBehaviour:q(r.turnBehaviour,Xe,t.turnBehaviour),guardrails:q(r.guardrails,Ae,t.guardrails),observability:q(r.observability,Ze,t.observability),image:q(r.image,Qe,t.image),speech:q(r.speech,$e,t.speech),live:q(r.live,et,t.live),decision:q(r.decision,n=>tt(n,e,t.decision),t.decision),labels:{}},d=He(e.tools,o,n,e.spans),f=Ue(d,s.allow,e.spans);u.toolSpecs=f;let p=new Set(f.map(e=>e.toolName));return u.tools.t2Loader&&!p.has(u.tools.t2Loader)&&(u.tools={...u.tools,t2Loader:``}),Me(u,r.labels),{draft:u,registered:d}}function st(e,t,n){try{let r=I(e),{draft:i,registered:a}=ot(r,t,n);return{ok:!0,draft:i,spans:r.spans,registered:a}}catch(e){if(e instanceof D)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}function X(e,t,n){let r=e.findLast(e=>e.path===t)??{line:1,column:1};throw new D(n,r.line,r.column)}var ct=new Set([`id`,`connection`,`keySlot`,`fallbackKeySlot`]);function lt(e,t,n){let{spec:r}=e;for(let e of Object.keys(r))ct.has(e)||X(n,e,`'${e}' isn't a provider setting the studio holds.`);r.id!==t.id&&X(n,`id`,`The id stays '${t.id}': models and code name the provider by it.`);let i=a(e.definition);if(!i){let t=u().flatMap(e=>o(e)??[]).join(`, `);X(n,``,`'${e.definition}' isn't one of the kernel's providers: ${t}.`)}let s=r.connection===void 0?{}:ut(r.connection,n),c=Object.keys(s).length===0&&t.connection===void 0,l={id:t.id,definition:i,...c?{}:{connection:s}};for(let e of[`keySlot`,`fallbackKeySlot`]){let t=r[e];t!==void 0&&(typeof t!=`string`&&X(n,e,`${e} names a key slot.`),l[e]=t)}return l}function ut(e,t){let n=`connection holds text settings here.`,r={};O(e)||X(t,`connection`,n);for(let[i,a]of Object.entries(e))typeof a!=`string`&&X(t,`connection`,n),r[i]=a;return r}function dt(e,t){try{let n=I(e,`provider`);if(!n.provider)throw new D(`This code needs registerProvider().`,1,1);return{ok:!0,provider:lt(n.provider,t,n.spans),spans:n.spans}}catch(e){if(e instanceof D)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}var Z=e(n(),1),Q=t(),ft=300,pt=2e3;function mt({editor:e,monaco:t,spans:n,errors:r},i){let a=e?.getModel();t&&a&&t.editor.setModelMarkers(a,`studio`,[...r.map(e=>$(t,e.line,e.column,e.message)),...gt(t,n,i)])}function ht({text:e,hold:t,isReadOnly:n=!1,issues:i,onApply:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(a),c=(0,Z.useRef)(e),l=(0,Z.useRef)(n);l.current=n;let u=(0,Z.useRef)(i),d=(0,Z.useRef)({spans:[],errors:[],setting:!1,dirty:!1});return s.current=a,c.current=e,u.current=i,(0,Z.useEffect)(()=>{let e=o.current;if(!e)return;let t={disposed:!1},n,i,a=0,f,p=!1,m=!1,h=()=>{a+=1,i&&clearTimeout(i),i=void 0,f?.stop(),f=void 0,p=!1,m=!1},g=t=>e.contains(t)?!0:t instanceof Element&&!!t.closest(`.suggest-widget, .parameter-hints-widget, .monaco-hover, .monaco-menu-container, .context-view`),_=()=>!!document.querySelector(`.suggest-widget.visible, .parameter-hints-widget.visible`),v,y=()=>{mt(d.current,u.current)};return(async()=>{let o=await r(()=>import(`./studio-monaco-xfyfezQS.js`),__vite__mapDeps([0,1,2,3,4]));await r(()=>import(`./register-CDgivxvX.js`),__vite__mapDeps([5,2,1,3]));let u=(await r(async()=>{let{default:e}=await import(`./editor.worker-6GY8RhDc.js`);return{default:e}},[])).default;if(self.MonacoEnvironment={getWorker(){return new u}},t.disposed||!e.isConnected)return;let b=document.documentElement.dataset.theme===`dark`||globalThis.matchMedia(`(prefers-color-scheme: dark)`).matches,x=o.Uri.parse(`file:///agent.ts`);o.editor.getModel(x)?.dispose();let S=o.editor.createModel(c.current,`typescript`,x),C=o.editor.create(e,{model:S,readOnly:l.current,language:`typescript`,theme:b?`vs-dark`:`vs`,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,wrappingIndent:`indent`,scrollBeyondLastLine:!1,automaticLayout:!0,fixedOverflowWidgets:!0,tabSize:2,padding:{top:12},quickSuggestions:{other:!0,comments:!1,strings:!0},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,tabCompletion:`on`,wordBasedSuggestions:`currentDocument`,parameterHints:{enabled:!0},suggest:{preview:!0,showIcons:!0}});d.current.editor=C,d.current.monaco=o;let w=()=>{i&&clearTimeout(i),i=setTimeout(()=>{t.disposed||(_()?w():h())},pt)},T=()=>{if(f){m&&w();return}if(p)return;let e=a,n=()=>t.disposed||e!==a;p=!0,r(async()=>{let{openTypeChecker:e}=await import(`./studio-type-checker-DosSRFbd.js`);return{openTypeChecker:e}},__vite__mapDeps([6,2])).then(({openTypeChecker:r})=>{if(n())return;let i=r(o,C,()=>{t.disposed||e!==a||(m=!0,w())});n()?i.stop():f=i}).catch(()=>{}).finally(()=>{e===a&&(p=!1)})};C.onKeyDown(e=>{let t=e.browserEvent;t.metaKey||t.ctrlKey||t.altKey||m&&w()});let E=e=>{let t=e.target;t instanceof Node&&!g(t)&&h()};document.addEventListener(`pointerdown`,E,!0),v=()=>{document.removeEventListener(`pointerdown`,E,!0)},C.onDidBlurEditorText(()=>{queueMicrotask(()=>{if(t.disposed||C.hasTextFocus())return;let e=document.activeElement;e&&g(e)||h()})}),C.onDidChangeModelContent(()=>{if(d.current.setting)return;T();let e=C.getValue();d.current.dirty=e!==c.current,n&&clearTimeout(n),n=setTimeout(()=>{let t=s.current(e);d.current.spans=t.spans,d.current.errors=t.errors,y()},ft)}),y()})(),()=>{t.disposed=!0,v?.(),h(),n&&clearTimeout(n);let e=d.current.editor?.getModel();d.current.editor?.dispose(),e?.dispose(),d.current.editor=void 0}},[]),(0,Z.useEffect)(()=>{let{editor:n}=d.current;n&&!t&&(d.current.dirty&&n.getValue()!==e||(n.getValue()===e||(d.current.setting=!0,n.setValue(e),d.current.setting=!1),d.current.dirty=!1))},[e,t]),(0,Z.useEffect)(()=>{d.current.editor?.updateOptions({readOnly:n})},[n]),(0,Z.useEffect)(()=>{mt(d.current,i)},[i]),(0,Q.jsx)(`div`,{ref:o,className:`studio-fill`})}function $(e,t,n,r){return{startLineNumber:t,startColumn:n,endLineNumber:t,endColumn:n+1,message:r,severity:e.MarkerSeverity.Error}}function gt(e,t,n){return n.flatMap(n=>{let r=n.field?`${n.nodeId}.${n.field}`:n.nodeId,i=t.find(e=>e.path===r)??(n.field?t.find(e=>e.path===n.field):void 0);return i?[$(e,i.line,i.column,n.message)]:[]})}function _t({source:e,blocked:t,issues:n,state:r}){let i=(0,Z.useRef)(e);e&&(i.current=e);let a=(0,Z.useCallback)(e=>{let t=te(r.workspace,r.focus);if(!t)return{errors:[{message:`No agent is open.`,line:1,column:1}],spans:[]};let n=st(e,{...t,toolSpecs:r.workspace.toolSpecs},e=>r.workspace.agents.find(t=>t.identity.agentId.trim()===e)?.key);return n.ok?(r.update(e=>ee(e,r.focus,n.draft,n.registered)),{errors:[],spans:n.spans}):{errors:n.errors,spans:[]}},[r]);return i.current?(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(ht,{text:e??i.current,hold:e==null,issues:n,onApply:a})}):(0,Q.jsx)(ne,{title:`No code yet`,description:`${t??``} to generate the TypeScript.`})}function vt({provider:e,issues:t,state:n,isEditable:r}){let i=(0,Z.useCallback)(t=>{let r=n.workspace.providers.find(t=>t.id===e.id);if(!r)return{errors:[{message:`No provider is open.`,line:1,column:1}],spans:[]};let i=dt(t,r);return i.ok?(n.update(e=>E(e,i.provider)),{errors:[],spans:i.spans}):{errors:i.errors,spans:[]}},[n,e.id]);return(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(ht,{text:re(e),hold:!1,isReadOnly:!r||o(e.definition)===void 0,issues:t,onApply:i},e.id)})}export{_t as CodeBody,vt as ProviderCode};
@@ -1,3 +1,3 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{l as r,n as i,t as a,u as o}from"./SegmentedControlItem-h-aaXzyS.js";import{t as s}from"./VStack-CkVMcNiK.js";import{n as c,t as l}from"./StackItem-CQviqAfM.js";import{c as u,u as d}from"./browser-transport-D-2jDYe7.js";import{p as f,v as p}from"./groupStyles-C7Ter7zC.js";import{r as m,t as ee}from"./IconButton-DlOGzJIX.js";import{a as h,g as te,i as ne,l as g,s as re,u as ie}from"./SidePanel-BL32abk8.js";import{t as _}from"./Text-bum6zWWx.js";import{n as v}from"./labels-provider-4TIWDvsE.js";import{n as ae,t as y}from"./Card-Lp-0P5eL.js";import{n as b}from"./ScrollableArea-Ckugdj1N.js";import{i as x}from"./Banner-BISz3nXA.js";import{a as oe}from"./arrive-DvbqpeRS.js";import{t as se}from"./Center-nHS1JSux.js";import{a as S,o as ce}from"./shaped-data-BcarWqd5.js";import{n as C}from"./trace-patterns-DnYJa0nI.js";import{Ot as le,S as ue,_ as w,g as T,h as de,o as fe,w as pe}from"./index-CvvmFKgS.js";var E=e(n(),1),me=new Set([`image/png`,`image/jpeg`]),D=`image/png,image/jpeg`;function he(e,t){let n=e.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)||`image`,r=`<${n}>`;for(let e=2;t.includes(r);e+=1)r=`<${n}_${String(e)}>`;return r}async function O(e){if(!me.has(e.type))return null;let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return{mimeType:e.type,data:btoa(n)}}function k(e){return`data:${e.mimeType};base64,${e.data}`}function A(e,t){return typeof e==`string`?e===t:Array.isArray(e)?e.some(e=>A(e,t)):typeof e==`object`&&e?Object.values(e).some(e=>A(e,t)):!1}function j(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>A(t,e)))}function M(e,t,n){let r=he(e,[...Object.keys(t),...n.map(e=>`<${e}>`)]);return{key:r.slice(1,-1),reference:r}}function N(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function P(e,t){let{images:n,state:r}=t;for(let[i,a]of e){let{key:e,reference:o}=M(i.name,{...t.host,...n},Object.keys(r));n={...n,[o]:a},r={...r,[e]:o}}return{images:n,state:r}}function F(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=Array.isArray(n)?n[Number(e)]:n[e]}return n}function I(e,t,n){let r=Object.keys(e),i=n===void 0||n in e?n:F(t,n);return e[(typeof i==`string`&&i in e?i:void 0)??r.find(e=>A(t,e))??r[0]??``]}function L(e,t,n){return{x:e.left*t,y:e.top*n,width:(e.right-e.left)*t,height:(e.bottom-e.top)*n,line:Math.max(2,Math.round(Math.min(t,n)/200))}}var R=.45;async function ge(e,t,n){let r=new Image;r.src=e,await r.decode();let i=document.createElement(`canvas`);i.width=r.naturalWidth,i.height=r.naturalHeight;let a=i.getContext(`2d`);if(!a)return e;let o=L(t,i.width,i.height);return a.drawImage(r,0,0),a.fillStyle=n.shade,a.globalAlpha=R,a.beginPath(),a.rect(0,0,i.width,i.height),a.rect(o.x,o.y,o.width,o.height),a.fill(`evenodd`),a.globalAlpha=1,a.strokeStyle=n.outline,a.lineWidth=o.line,a.strokeRect(o.x,o.y,o.width,o.height),i.toDataURL(`image/png`)}function _e(e){let t=e.right-e.left,n=e.bottom-e.top;return{width:100/t,height:100/n,left:-e.left/t*100,top:-e.top/n*100}}function ve(e){return e.every(e=>typeof e==`string`)}function z(e){return e==null||typeof e==`string`?``:typeof e==`number`?0:typeof e==`boolean`?!1:Array.isArray(e)?[]:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,z(t)]))}function ye(e){let t=e[0];if(typeof t!=`object`||!t||Array.isArray(t))return null;let n=Object.keys(t);return n.length===0||n.length>4||!e.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).join()===n.join()&&Object.values(e).every(e=>typeof e!=`object`||!e))?null:n.map(t=>{let n=e.map(e=>String(e[t]??``).length),r=Math.max(t.length,...n);return{key:t,weight:Math.min(4,Math.max(1,Math.round(r/10)))}})}var B=t();function be(e){return e===null?[]:Array.isArray(e)?e:[e]}function V(){let e=v(),[t,n]=(0,E.useState)(null);return{read:async e=>{n(null);let t=[];for(let r of be(e)){let e=await O(r);e?t.push([r,e]):n(r.name)}return t},status:t===null?void 0:{type:`error`,message:e(`@theorem.decision.image_bad`,{file:t})}}}function xe({onImages:e}){let t=v(),{read:n,status:r}=V();return(0,B.jsx)(T,{label:t(`@theorem.decision.add_image`),isLabelHidden:!0,mode:`dropzone`,isMultiple:!0,accept:D,value:null,placeholder:t(`@theorem.decision.add_image_hint`),status:r,statusVariant:`detached`,onChange:t=>{n(t).then(t=>{t.length>0&&e(t)})}})}var Se={search:()=>[],bootstrap:()=>[]},Ce=48;function H(e,t,n){return Math.min(Math.max(e.split(`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{l as r,n as i,t as a,u as o}from"./SegmentedControlItem-h-aaXzyS.js";import{t as s}from"./VStack-CkVMcNiK.js";import{n as c,t as l}from"./StackItem-CQviqAfM.js";import{c as u,u as d}from"./browser-transport-BEFsWdzI.js";import{p as f,v as p}from"./groupStyles-C7Ter7zC.js";import{r as m,t as ee}from"./IconButton-DlOGzJIX.js";import{a as h,g as te,i as ne,l as g,s as re,u as ie}from"./SidePanel-BL32abk8.js";import{t as _}from"./Text-bum6zWWx.js";import{n as v}from"./labels-provider-4TIWDvsE.js";import{n as ae,t as y}from"./Card-Lp-0P5eL.js";import{n as b}from"./ScrollableArea-Ckugdj1N.js";import{i as x}from"./Banner-Buiul23B.js";import{a as oe}from"./arrive-DvbqpeRS.js";import{t as se}from"./Center-nHS1JSux.js";import{a as S,o as ce}from"./shaped-data-BcarWqd5.js";import{n as C}from"./trace-patterns-DnYJa0nI.js";import{Ot as le,S as ue,_ as w,g as T,h as de,o as fe,w as pe}from"./index-D2T8e_8Q.js";var E=e(n(),1),me=new Set([`image/png`,`image/jpeg`]),D=`image/png,image/jpeg`;function he(e,t){let n=e.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)||`image`,r=`<${n}>`;for(let e=2;t.includes(r);e+=1)r=`<${n}_${String(e)}>`;return r}async function O(e){if(!me.has(e.type))return null;let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));return{mimeType:e.type,data:btoa(n)}}function k(e){return`data:${e.mimeType};base64,${e.data}`}function A(e,t){return typeof e==`string`?e===t:Array.isArray(e)?e.some(e=>A(e,t)):typeof e==`object`&&e?Object.values(e).some(e=>A(e,t)):!1}function j(e,t){return Object.fromEntries(Object.entries(e).filter(([e])=>A(t,e)))}function M(e,t,n){let r=he(e,[...Object.keys(t),...n.map(e=>`<${e}>`)]);return{key:r.slice(1,-1),reference:r}}function N(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:void 0}function P(e,t){let{images:n,state:r}=t;for(let[i,a]of e){let{key:e,reference:o}=M(i.name,{...t.host,...n},Object.keys(r));n={...n,[o]:a},r={...r,[e]:o}}return{images:n,state:r}}function F(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=Array.isArray(n)?n[Number(e)]:n[e]}return n}function I(e,t,n){let r=Object.keys(e),i=n===void 0||n in e?n:F(t,n);return e[(typeof i==`string`&&i in e?i:void 0)??r.find(e=>A(t,e))??r[0]??``]}function L(e,t,n){return{x:e.left*t,y:e.top*n,width:(e.right-e.left)*t,height:(e.bottom-e.top)*n,line:Math.max(2,Math.round(Math.min(t,n)/200))}}var R=.45;async function ge(e,t,n){let r=new Image;r.src=e,await r.decode();let i=document.createElement(`canvas`);i.width=r.naturalWidth,i.height=r.naturalHeight;let a=i.getContext(`2d`);if(!a)return e;let o=L(t,i.width,i.height);return a.drawImage(r,0,0),a.fillStyle=n.shade,a.globalAlpha=R,a.beginPath(),a.rect(0,0,i.width,i.height),a.rect(o.x,o.y,o.width,o.height),a.fill(`evenodd`),a.globalAlpha=1,a.strokeStyle=n.outline,a.lineWidth=o.line,a.strokeRect(o.x,o.y,o.width,o.height),i.toDataURL(`image/png`)}function _e(e){let t=e.right-e.left,n=e.bottom-e.top;return{width:100/t,height:100/n,left:-e.left/t*100,top:-e.top/n*100}}function ve(e){return e.every(e=>typeof e==`string`)}function z(e){return e==null||typeof e==`string`?``:typeof e==`number`?0:typeof e==`boolean`?!1:Array.isArray(e)?[]:Object.fromEntries(Object.entries(e).map(([e,t])=>[e,z(t)]))}function ye(e){let t=e[0];if(typeof t!=`object`||!t||Array.isArray(t))return null;let n=Object.keys(t);return n.length===0||n.length>4||!e.every(e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).join()===n.join()&&Object.values(e).every(e=>typeof e!=`object`||!e))?null:n.map(t=>{let n=e.map(e=>String(e[t]??``).length),r=Math.max(t.length,...n);return{key:t,weight:Math.min(4,Math.max(1,Math.round(r/10)))}})}var B=t();function be(e){return e===null?[]:Array.isArray(e)?e:[e]}function V(){let e=v(),[t,n]=(0,E.useState)(null);return{read:async e=>{n(null);let t=[];for(let r of be(e)){let e=await O(r);e?t.push([r,e]):n(r.name)}return t},status:t===null?void 0:{type:`error`,message:e(`@theorem.decision.image_bad`,{file:t})}}}function xe({onImages:e}){let t=v(),{read:n,status:r}=V();return(0,B.jsx)(T,{label:t(`@theorem.decision.add_image`),isLabelHidden:!0,mode:`dropzone`,isMultiple:!0,accept:D,value:null,placeholder:t(`@theorem.decision.add_image_hint`),status:r,statusVariant:`detached`,onChange:t=>{n(t).then(t=>{t.length>0&&e(t)})}})}var Se={search:()=>[],bootstrap:()=>[]},Ce=48;function H(e,t,n){return Math.min(Math.max(e.split(`
2
2
  `).length,t),n)}var U=(0,E.createContext)({images:{},onImages:()=>{}});function we({value:e,label:t,isLabelHidden:n}){let r=v(),{images:i,onImages:a}=(0,E.useContext)(U),{read:o,status:s}=V(),[f,p]=(0,E.useState)(!1),m=Object.hasOwn(i,e)?k(i[e]):void 0;return(0,B.jsxs)(c,{gap:2,vAlign:`center`,children:[(0,B.jsx)(d,{src:m,alt:t,label:e,onClick:m?()=>p(!0):void 0}),m?(0,B.jsx)(u,{isOpen:f,onOpenChange:p,media:{src:m,alt:t,caption:e},hasZoom:!0}):null,(0,B.jsx)(l,{size:`fill`,children:(0,B.jsx)(T,{label:t,isLabelHidden:n,accept:D,value:null,placeholder:r(`@theorem.decision.replace_image`),status:s,statusVariant:`detached`,onChange:t=>{o(t).then(([t])=>{t&&a({...i,[e]:t[1]})})}})})]})}function W({value:e,onChange:t,label:n,isLabelHidden:r}){let{images:i}=(0,E.useContext)(U),[a]=(0,E.useState)(()=>typeof e==`string`&&(e.length>Ce||e.includes(`
3
3
  `))),[o]=(0,E.useState)(()=>typeof e==`string`&&Object.hasOwn(i,e));if(o&&typeof e==`string`)return(0,B.jsx)(we,{value:e,label:n,isLabelHidden:r});if(typeof e==`boolean`)return(0,B.jsx)(de,{label:n,value:e,onChange:t});if(typeof e==`number`)return(0,B.jsx)(pe,{label:n,isLabelHidden:r,size:`sm`,value:e,isWheelEnabled:!1,onChange:t});if(e===null)return(0,B.jsx)(b,{label:n,isLabelHidden:r,size:`sm`,value:``,placeholder:`null`,isDisabled:!0,onChange:()=>{}});let s=String(e);return a?(0,B.jsx)(w,{label:n,isLabelHidden:r,size:`sm`,rows:H(s,2,12),value:s,onChange:t}):(0,B.jsx)(b,{label:n,isLabelHidden:r,size:`sm`,value:s,onChange:t})}function G({label:e,isRequired:t,description:n,children:r}){let i=(0,E.useId)();return(0,B.jsxs)(s,{gap:2,role:`group`,"aria-labelledby":i,children:[(0,B.jsx)(f,{label:e,inputID:``,labelID:i,isGroupLabel:!0,isRequired:t,description:n}),r]})}function K({children:e,...t}){return(0,B.jsx)(G,{...t,children:(0,B.jsx)(`div`,{style:{paddingInlineStart:12,borderInlineStart:`1px solid var(--color-border)`},children:e})})}function q({field:e,onAdd:t}){let n=v();return(0,B.jsx)(c,{children:(0,B.jsx)(m,{label:n(`@theorem.decision.add_item`,{field:e}),size:`sm`,variant:`ghost`,icon:(0,B.jsx)(le,{size:14}),onClick:t})})}function J({index:e,onRemove:t}){let n=v();return(0,B.jsx)(ee,{label:n(`@theorem.decision.remove_item`,{item:n(`@theorem.data.item`,{index:String(e+1)})}),size:`sm`,variant:`ghost`,icon:(0,B.jsx)(p,{size:14}),onClick:t})}function Y({value:e,onChange:t}){return(0,B.jsx)(s,{gap:3,children:Object.entries(e).map(([n,r])=>(0,B.jsx)(X,{label:S(n),value:r,onChange:r=>t({...e,[n]:r})},n))})}function Te({value:e,onChange:t,label:n}){let r=v(),i=oe(e);if(ve(e))return(0,B.jsx)(ue,{label:n,size:`sm`,value:e.map((e,t)=>({id:`${String(t)}:${e}`,label:e})),searchSource:Se,hasCreate:!0,debounceMs:0,placeholder:r(`@theorem.decision.add_value`),onChange:e=>t(e.map(e=>e.label))});let a=ye(e),o=(0,B.jsx)(q,{field:n,onAdd:()=>t([...e,z(e.at(-1))])}),u=n=>(0,B.jsx)(J,{index:n,onRemove:()=>{i.drop(n),t(e.filter((e,t)=>t!==n))}});if(a){let r={display:`grid`,gap:8,alignItems:`start`,gridTemplateColumns:`${a.map(e=>`minmax(0, ${String(e.weight)}fr)`).join(` `)} auto`},s=e;return(0,B.jsxs)(G,{label:n,children:[(0,B.jsxs)(`div`,{style:r,"aria-hidden":!0,children:[a.map(e=>(0,B.jsx)(_,{type:`supporting`,color:`secondary`,maxLines:1,children:S(e.key)},e.key)),(0,B.jsx)(`span`,{style:{width:28}})]}),i.rows.map(({index:e,key:n})=>{let i=s[e];return(0,B.jsxs)(`div`,{style:r,children:[a.map(n=>(0,B.jsx)(W,{label:`${S(n.key)} ${String(e+1)}`,isLabelHidden:!0,value:i[n.key]??null,onChange:r=>t(s.map((t,i)=>i===e?{...t,[n.key]:r}:t))},n.key)),u(e)]},n)}),o]})}return(0,B.jsx)(K,{label:n,children:(0,B.jsxs)(s,{gap:3,children:[i.rows.map(({item:n,index:i,key:a})=>{let o=r(`@theorem.data.item`,{index:String(i+1)}),s=n=>t(e.map((e,t)=>t===i?n:e));return(0,B.jsxs)(c,{gap:2,vAlign:`start`,children:[(0,B.jsx)(l,{size:`fill`,children:ce(n)?(0,B.jsx)(W,{label:o,isLabelHidden:!0,value:n,onChange:s}):(0,B.jsx)(X,{label:o,value:n,onChange:s})}),u(i)]},a)}),o]})})}function X({value:e,onChange:t,label:n}){return Array.isArray(e)?(0,B.jsx)(Te,{label:n,value:e,onChange:t}):typeof e==`object`&&e?(0,B.jsx)(K,{label:n,children:(0,B.jsx)(Y,{value:e,onChange:t})}):(0,B.jsx)(W,{label:n,value:e,onChange:t})}function Ee({value:e,onChange:t,label:n}){return typeof e==`object`&&e&&!Array.isArray(e)?(0,B.jsx)(Y,{value:e,onChange:t}):(0,B.jsx)(X,{label:n,value:e,onChange:t})}var De={"--theorem-console-card":`var(--color-background-muted)`},Z=`(width < 768px)`,Q=(0,E.createContext)(!0);function $(){return(0,E.useSyncExternalStore)(e=>{let t=globalThis.matchMedia(Z);return t.addEventListener(`change`,e),()=>{t.removeEventListener(`change`,e)}},()=>globalThis.matchMedia(Z).matches,()=>!1)}function Oe({flush:e,wide:t,maxWidth:n,children:r}){return(0,B.jsx)(s,{height:`100%`,paddingInline:3,style:e?De:void 0,children:(0,B.jsx)(y,{variant:`transparent`,height:`100%`,padding:0,style:e?{overflowY:`auto`}:{...re,overflowY:`auto`},children:(0,B.jsx)(se,{axis:`horizontal`,width:`100%`,minHeight:`100%`,children:(0,B.jsx)(s,{width:`100%`,maxWidth:t?void 0:n,gap:3,padding:4,children:r})})})})}function ke({inspector:e,maxWidth:t,flush:n=!1,columns:i=!1,requestLabel:a,className:s,style:c,children:l}){let u=(0,E.useRef)(null);return(0,B.jsx)(x,{inspector:e,children:(0,B.jsx)(o,{ref:u,height:`fill`,className:s,style:c,header:e.toggle?(0,B.jsx)(ie,{children:e.toggle}):void 0,content:(0,B.jsx)(r,{padding:0,isScrollable:!1,children:(0,B.jsx)(Ae,{layoutRef:u,flush:n,columns:i,maxWidth:t,requestLabel:a,children:l})})})})}function Ae({layoutRef:e,flush:t,columns:n,maxWidth:r,requestLabel:i,children:a}){let o=$(),s=E.Children.toArray(a).length,c=n&&s>1;return c&&!o?(0,B.jsx)(je,{requestLabel:i,basisWidth:e.current?.clientWidth??0,children:a}):(0,B.jsx)(Oe,{flush:t,wide:c,maxWidth:r,children:a})}function je({requestLabel:e=`Request`,basisWidth:t,children:n}){let i=v(),a=(0,E.useRef)(null),s=te({defaultSize:t>0?Math.round(t*.4):`40%`,minSize:280,maxSize:`70%`,containerRef:a}),[c,l]=E.Children.toArray(n),u={name:e,show:e,hide:e,resize:i(`@theorem.panel.resize`,{name:e})};return(0,B.jsx)(Q,{value:!1,children:(0,B.jsx)(o,{ref:a,height:`fill`,start:(0,B.jsx)(g,{side:`start`,className:`theorem-console-request`,labels:u,resizable:s,open:!0,children:(0,B.jsx)(h,{label:e,children:c})}),content:(0,B.jsx)(r,{padding:0,isScrollable:!1,children:(0,B.jsx)(ne,{inset:`beside`,className:`theorem-console-response`,children:l})})})})}function Me({children:e}){return(0,B.jsx)(y,{variant:`muted`,padding:0,className:`theorem-console-card`,style:C,children:(0,B.jsx)(Q,{value:!1,children:e})})}function Ne({label:e,fill:t=!1,children:n}){return(0,E.use)(Q)?(0,B.jsx)(y,{variant:`muted`,padding:t?0:4,className:`theorem-console-card`,style:C,children:t?n:(0,B.jsx)(s,{height:`100%`,gap:3,children:n})}):t?n:(0,B.jsx)(h,{label:e,padding:4,children:n})}function Pe(e){return t=>{t.key===`Enter`&&(t.metaKey||t.ctrlKey)&&(t.preventDefault(),e())}}function Fe({title:e,view:t,hasFields:n,onView:r,onRun:o,children:l}){let u=v(),d=(0,E.use)(Q),f=(0,B.jsxs)(s,{gap:3,padding:d?void 0:4,onKeyDown:Pe(o),children:[(0,B.jsxs)(c,{gap:2,hAlign:`between`,vAlign:`center`,children:[(0,B.jsx)(_,{type:`supporting`,color:`secondary`,as:`h3`,children:e}),(0,B.jsxs)(i,{label:u(`@theorem.decision.view`),size:`sm`,value:t,onChange:e=>{r(e===`json`?`json`:`fields`)},children:[(0,B.jsx)(a,{value:`fields`,label:u(`@theorem.decision.fields`),isDisabled:!n}),(0,B.jsx)(a,{value:`json`,label:u(`@theorem.data.json`)})]})]}),l]});return d?(0,B.jsx)(y,{variant:`muted`,padding:4,className:`theorem-console-card`,style:C,children:f}):f}var Ie={"--font-family-body":`var(--font-family-code)`};function Le({label:e,text:t,isInvalid:n,onChange:r}){return(0,B.jsx)(w,{label:e,isLabelHidden:!0,value:t,onChange:r,rows:H(t,8,24),hasSpellCheck:!1,status:n?{type:`error`}:void 0,controlStyle:Ie})}function Re({note:e,isReady:t,isRunning:n,runLabel:r,runningLabel:i,stopLabel:a,onRun:o,onStop:s}){return(0,B.jsxs)(c,{gap:3,hAlign:`between`,vAlign:`center`,children:[(0,B.jsx)(_,{type:`supporting`,color:`secondary`,style:t?void 0:{color:`var(--color-error)`},hasTabularNumbers:!0,children:e}),(0,B.jsxs)(c,{gap:2,vAlign:`center`,children:[n?(0,B.jsx)(m,{label:a,variant:`ghost`,onClick:s}):null,(0,B.jsx)(m,{label:n?i:r,variant:`primary`,isLoading:n,isDisabled:!t,onClick:o})]})]})}function ze(){let e=ae();return(0,E.useMemo)(()=>{let t=new Intl.NumberFormat(e,{style:`unit`,unit:`byte`,unitDisplay:`narrow`}),n=new Intl.NumberFormat(e,{style:`unit`,unit:`kilobyte`,unitDisplay:`narrow`,maximumFractionDigits:1});return e=>e<1024?t.format(e):n.format(e/1024)},[e])}function Be({payload:e,runtime:t=null,traces:n,onActivity:r},i,a){return(0,E.useMemo)(()=>{let o=t?a(e,t,{traces:n}):i(e,{traces:n});return r?fe(o,r):o},[e,t,n,r,i,a])}export{N as C,j as S,I as _,Fe as a,k as b,ze as c,G as d,J as f,xe as g,H as h,Le as i,q as l,U as m,ke as n,Ne as o,Ee as p,Me as r,Re as s,Be as t,K as u,_e as v,ge as x,P as y};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{n as r,o as i,p as a,s as o}from"./browser-transport-D-2jDYe7.js";import{n as s,t as c}from"./labels-provider-4TIWDvsE.js";import{a as l,t as u}from"./Banner-BISz3nXA.js";import{c as d}from"./reader-BOCCYaRp.js";import{p as f,u as p}from"./tree-DqyAMsbI.js";import{n as m,t as h}from"./PaneState-BvA2tLQg.js";import{C as g,S as _,a as v,c as y,g as b,i as x,m as S,n as C,o as w,p as T,s as E,t as D,y as O}from"./studio-console-DZwlEsvr.js";import{i as k,t as A}from"./use-one-call-Hcs8YBp1.js";import{$ as j,et as M,l as N}from"./index-CvvmFKgS.js";var P=(e,t,n,r)=>e.decide(n,t,r);function F(e){let{iface:t,describeFailure:n}=o(e),{call:r,...i}=A(e,`deciding`,P);return{iface:t,describeFailure:n,...i,decide:r}}var I=e(n(),1),L=t();function R(e,t){let n;try{n=JSON.parse(e)}catch{return{ok:!1,reason:`invalid_json`}}if(n===null)return{ok:!1,reason:`null_state`,state:n};let r=new TextEncoder().encode(JSON.stringify(n)).byteLength;return t!==void 0&&r>t?{ok:!1,reason:`too_large`,bytes:r,state:n}:{ok:!0,state:n,bytes:r}}function z(e,t,n,r){return t.ok?n===void 0?null:e(`@theorem.decision.state_size`,{size:r(t.bytes),limit:r(n)}):t.reason===`too_large`?e(`@theorem.decision.too_large`,{limit:r(n??0)}):e(t.reason===`invalid_json`?`@theorem.decision.invalid_json`:`@theorem.decision.null_state`)}function B(e){return e.failure||e.result?`settled`:e.status===`deciding`?`waiting`:`idle`}function V(e,t){let[n,r]=(0,I.useState)(e),i=R(n,t),[a,o]=(0,I.useState)(()=>i.state===void 0?`json`:`fields`);return{text:n,setText:r,check:i,shown:i.state===void 0?`json`:a,setView:o}}function H({form:e,iface:t,images:n,onImages:r,note:i,isRunning:a,onRun:o,onStop:c}){let l=s(),{text:u,setText:d,check:f,shown:p,setView:m}=e,h=t.questions.some(e=>e.type===`box`)||Object.keys(n).length>0,_=p===`fields`?f.state:void 0,y=g(_);return(0,L.jsxs)(v,{title:l(`@theorem.decision.state`),view:p,hasFields:f.state!==void 0,onView:m,onRun:o,children:[_===void 0?(0,L.jsx)(x,{label:l(`@theorem.decision.state`),text:u,isInvalid:!f.ok,onChange:d}):(0,L.jsx)(S,{value:{images:n,onImages:r},children:(0,L.jsx)(T,{label:l(`@theorem.decision.state`),value:_,onChange:e=>{d(JSON.stringify(e,null,2))}})}),h&&y?(0,L.jsx)(b,{onImages:e=>{let i=O(e,{images:n,host:t.images,state:y});r(i.images),d(JSON.stringify(i.state,null,2))}}):null,(0,L.jsx)(E,{note:i,isReady:f.ok,isRunning:a,runLabel:l(`@theorem.decision.decide`),runningLabel:l(`@theorem.decision.deciding`),stopLabel:l(`@theorem.decision.stop`),onRun:o,onStop:c})]})}function U({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=s(),o=t.status===`deciding`;return(0,L.jsxs)(L.Fragment,{children:[t.failure?(0,L.jsx)(u,{status:`error`,role:`alert`,title:t.failure.error}):null,o&&!t.result?(0,L.jsx)(m,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,L.jsx)(k,{iface:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:o}):null]})}function W(e,t,n,r,i){if(t===`idle`)return null;if(!e)return i;let a=t===`waiting`;return(0,L.jsx)(w,{label:n.answers,fill:a,children:a?(0,L.jsx)(m,{label:n.deciding,since:r}):i})}function G({transport:e,iface:t,decision:n,defaultState:r=`{}`,defaultImages:i,onQuestion:a,questionText:o,maxWidth:c=`960px`,trace:u,flush:d,columns:f=!1,className:p,style:m}){let h=s(),g=y(),v=V(r,t.maxStateBytes),{check:b}=v,[x,S]=(0,I.useState)(i??{}),[w,T]=(0,I.useState)(),E=l(t,e.traces,u);return(0,L.jsxs)(C,{inspector:E,maxWidth:c,flush:d,columns:f,requestLabel:h(`@theorem.decision.state`),className:p,style:m,children:[(0,L.jsx)(H,{form:v,iface:t,images:x,onImages:S,note:z(h,b,t.maxStateBytes,g),isRunning:n.status===`deciding`,onRun:()=>{if(!b.ok)return;let e=_(x,b.state);T({images:{...t.images,...e},state:b.state}),n.decide(b.state,Object.keys(e).length>0?e:void 0)},onStop:n.cancel}),W(f,B(n),{answers:h(`@theorem.decision.answers`),deciding:h(`@theorem.decision.deciding`)},n.startedAt,(0,L.jsx)(U,{iface:t,decision:n,asked:w,onQuestion:a,questionText:o}))]})}function K(e){let t=s(),n=F(e.transport);return n.describeFailure?(0,L.jsx)(h,{title:n.describeFailure.error}):n.iface?(0,L.jsx)(G,{...e,iface:n.iface,decision:n}):(0,L.jsx)(m,{label:t(`@theorem.chat.loading`)})}function q({endpoint:e,http:t,transport:n,theme:r,mode:a,labels:o,...s}){let l=(0,I.useRef)(t);l.current=t;let u=(0,I.useMemo)(()=>n??d({...l.current,endpoint:e}),[n,e]);return(0,L.jsx)(i,{theme:r,mode:a,children:(0,L.jsx)(c,{labels:o,children:(0,L.jsx)(K,{...s,transport:u})})})}var J;function Y(e){if(e.agentId===`pantry.jev`)return J??=M(),{defaultState:j,defaultImages:{...(0,I.use)(J)}};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?f:p}}function X(e){return typeof e==`string`?e:Array.isArray(e)?e.map(X).join(` `):Object.entries(e).map(([e,t])=>`${e}: ${X(t)}`).join(` `)}function Z(e){let t=D(e,a,r);return(0,L.jsx)(Q,{...e,transport:t})}function Q({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let{open:o}=(0,I.useContext)(N),s=Y(e),{questions:c}=e,l=(0,I.useMemo)(()=>c&&Object.fromEntries(Object.entries(c).map(([e,t])=>[e,X(t.instructions)])),[c]);return(0,L.jsx)(q,{transport:t,...s,trace:n,flush:r,columns:i,className:a,onQuestion:o,questionText:l})}export{Q as DecisionView,Z as StudioDecision};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{n as r,o as i,p as a,s as o}from"./browser-transport-BEFsWdzI.js";import{n as s,t as c}from"./labels-provider-4TIWDvsE.js";import{a as l,t as u}from"./Banner-Buiul23B.js";import{c as d}from"./reader-B0gVhfoZ.js";import{p as f,u as p}from"./tree-DeO1319a.js";import{n as m,t as h}from"./PaneState-BvA2tLQg.js";import{C as g,S as _,a as v,c as y,g as b,i as x,m as S,n as C,o as w,p as T,s as E,t as D,y as O}from"./studio-console-e6kqu38F.js";import{i as k,t as A}from"./use-one-call-9e3o5vH-.js";import{$ as j,et as M,l as N}from"./index-D2T8e_8Q.js";var P=(e,t,n,r)=>e.decide(n,t,r);function F(e){let{iface:t,describeFailure:n}=o(e),{call:r,...i}=A(e,`deciding`,P);return{iface:t,describeFailure:n,...i,decide:r}}var I=e(n(),1),L=t();function R(e,t){let n;try{n=JSON.parse(e)}catch{return{ok:!1,reason:`invalid_json`}}if(n===null)return{ok:!1,reason:`null_state`,state:n};let r=new TextEncoder().encode(JSON.stringify(n)).byteLength;return t!==void 0&&r>t?{ok:!1,reason:`too_large`,bytes:r,state:n}:{ok:!0,state:n,bytes:r}}function z(e,t,n,r){return t.ok?n===void 0?null:e(`@theorem.decision.state_size`,{size:r(t.bytes),limit:r(n)}):t.reason===`too_large`?e(`@theorem.decision.too_large`,{limit:r(n??0)}):e(t.reason===`invalid_json`?`@theorem.decision.invalid_json`:`@theorem.decision.null_state`)}function B(e){return e.failure||e.result?`settled`:e.status===`deciding`?`waiting`:`idle`}function V(e,t){let[n,r]=(0,I.useState)(e),i=R(n,t),[a,o]=(0,I.useState)(()=>i.state===void 0?`json`:`fields`);return{text:n,setText:r,check:i,shown:i.state===void 0?`json`:a,setView:o}}function H({form:e,iface:t,images:n,onImages:r,note:i,isRunning:a,onRun:o,onStop:c}){let l=s(),{text:u,setText:d,check:f,shown:p,setView:m}=e,h=t.questions.some(e=>e.type===`box`)||Object.keys(n).length>0,_=p===`fields`?f.state:void 0,y=g(_);return(0,L.jsxs)(v,{title:l(`@theorem.decision.state`),view:p,hasFields:f.state!==void 0,onView:m,onRun:o,children:[_===void 0?(0,L.jsx)(x,{label:l(`@theorem.decision.state`),text:u,isInvalid:!f.ok,onChange:d}):(0,L.jsx)(S,{value:{images:n,onImages:r},children:(0,L.jsx)(T,{label:l(`@theorem.decision.state`),value:_,onChange:e=>{d(JSON.stringify(e,null,2))}})}),h&&y?(0,L.jsx)(b,{onImages:e=>{let i=O(e,{images:n,host:t.images,state:y});r(i.images),d(JSON.stringify(i.state,null,2))}}):null,(0,L.jsx)(E,{note:i,isReady:f.ok,isRunning:a,runLabel:l(`@theorem.decision.decide`),runningLabel:l(`@theorem.decision.deciding`),stopLabel:l(`@theorem.decision.stop`),onRun:o,onStop:c})]})}function U({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=s(),o=t.status===`deciding`;return(0,L.jsxs)(L.Fragment,{children:[t.failure?(0,L.jsx)(u,{status:`error`,role:`alert`,title:t.failure.error}):null,o&&!t.result?(0,L.jsx)(m,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,L.jsx)(k,{iface:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:o}):null]})}function W(e,t,n,r,i){if(t===`idle`)return null;if(!e)return i;let a=t===`waiting`;return(0,L.jsx)(w,{label:n.answers,fill:a,children:a?(0,L.jsx)(m,{label:n.deciding,since:r}):i})}function G({transport:e,iface:t,decision:n,defaultState:r=`{}`,defaultImages:i,onQuestion:a,questionText:o,maxWidth:c=`960px`,trace:u,flush:d,columns:f=!1,className:p,style:m}){let h=s(),g=y(),v=V(r,t.maxStateBytes),{check:b}=v,[x,S]=(0,I.useState)(i??{}),[w,T]=(0,I.useState)(),E=l(t,e.traces,u);return(0,L.jsxs)(C,{inspector:E,maxWidth:c,flush:d,columns:f,requestLabel:h(`@theorem.decision.state`),className:p,style:m,children:[(0,L.jsx)(H,{form:v,iface:t,images:x,onImages:S,note:z(h,b,t.maxStateBytes,g),isRunning:n.status===`deciding`,onRun:()=>{if(!b.ok)return;let e=_(x,b.state);T({images:{...t.images,...e},state:b.state}),n.decide(b.state,Object.keys(e).length>0?e:void 0)},onStop:n.cancel}),W(f,B(n),{answers:h(`@theorem.decision.answers`),deciding:h(`@theorem.decision.deciding`)},n.startedAt,(0,L.jsx)(U,{iface:t,decision:n,asked:w,onQuestion:a,questionText:o}))]})}function K(e){let t=s(),n=F(e.transport);return n.describeFailure?(0,L.jsx)(h,{title:n.describeFailure.error}):n.iface?(0,L.jsx)(G,{...e,iface:n.iface,decision:n}):(0,L.jsx)(m,{label:t(`@theorem.chat.loading`)})}function q({endpoint:e,http:t,transport:n,theme:r,mode:a,labels:o,...s}){let l=(0,I.useRef)(t);l.current=t;let u=(0,I.useMemo)(()=>n??d({...l.current,endpoint:e}),[n,e]);return(0,L.jsx)(i,{theme:r,mode:a,children:(0,L.jsx)(c,{labels:o,children:(0,L.jsx)(K,{...s,transport:u})})})}var J;function Y(e){if(e.agentId===`pantry.jev`)return J??=M(),{defaultState:j,defaultImages:{...(0,I.use)(J)}};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?f:p}}function X(e){return typeof e==`string`?e:Array.isArray(e)?e.map(X).join(` `):Object.entries(e).map(([e,t])=>`${e}: ${X(t)}`).join(` `)}function Z(e){let t=D(e,a,r);return(0,L.jsx)(Q,{...e,transport:t})}function Q({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let{open:o}=(0,I.useContext)(N),s=Y(e),{questions:c}=e,l=(0,I.useMemo)(()=>c&&Object.fromEntries(Object.entries(c).map(([e,t])=>[e,X(t.instructions)])),[c]);return(0,L.jsx)(q,{transport:t,...s,trace:n,flush:r,columns:i,className:a,onQuestion:o,questionText:l})}export{Q as DecisionView,Z as StudioDecision};