@theoremjs/studio 0.3.4-next.727.g8a08b91 → 0.3.4-next.729.g096feb6

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 (32) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{Banner-BLNhepw5.js → Banner-DdKVQVIA.js} +3 -3
  3. package/page/assets/{ConsoleFrame-CPxgSITW.js → ConsoleFrame-CXVxrOXS.js} +1 -1
  4. package/page/assets/{MenuBottomSheet-DkcUfuBE.js → MenuBottomSheet-C3gi7El9.js} +1 -1
  5. package/page/assets/{SchemaFields-DuwdKRO9.js → SchemaFields-bnMsWJjR.js} +1 -1
  6. package/page/assets/{ToolResultCharts-CkvTtwJ1.js → ToolResultCharts-Bn2FEUbS.js} +1 -1
  7. package/page/assets/{TraceInspector-DKh6_uCU.js → TraceInspector-Bj_ZXTQQ.js} +1 -1
  8. package/page/assets/{TraceOverview-1CQk-7B8.js → TraceOverview-DpjrzPHw.js} +1 -1
  9. package/page/assets/{browser-connection-DMLe-0pv.js → browser-connection-IC3QKsFq.js} +1 -1
  10. package/page/assets/{browser-engine-CU1JMUMz.js → browser-engine-Bavv76-3.js} +1 -1
  11. package/page/assets/{browser-transport-BCwSLVJv.js → browser-transport-BRjXq2Qp.js} +3 -3
  12. package/page/assets/{export-agent-C43TTkhk.js → export-agent-DWKNTptV.js} +1 -1
  13. package/page/assets/{guardrail-tester-0xHqNTIG.js → guardrail-tester-5IMes5w-.js} +1 -1
  14. package/page/assets/{index-DxaSpTtM.js → index-CCj0zkrC.js} +7 -7
  15. package/page/assets/{live-messages-eYYz6aFz.js → live-messages-ConwEl7T.js} +1 -1
  16. package/page/assets/{reader-DAdKx3ZF.js → reader-Ql1nrrAA.js} +1 -1
  17. package/page/assets/{stub-4NoUUWes.js → stub-U8WThytR.js} +1 -1
  18. package/page/assets/{studio-code-pane-CnNaDzrN.js → studio-code-pane-CFOmHAPp.js} +1 -1
  19. package/page/assets/{studio-console-BD3mlhyS.js → studio-console-C0F2FDl3.js} +1 -1
  20. package/page/assets/{studio-decision-jCaBdiGS.js → studio-decision-Cityn64u.js} +1 -1
  21. package/page/assets/{studio-embedding-DD4c70Np.js → studio-embedding-S9ZH-InI.js} +1 -1
  22. package/page/assets/{studio-host-console-BdXfPdWD.js → studio-host-console-CcGeithp.js} +2 -2
  23. package/page/assets/{studio-labels-B1CPAbnq.js → studio-labels-DwBTrktF.js} +1 -1
  24. package/page/assets/{studio-live-SbPBqNbn.js → studio-live-BhwFs5I4.js} +1 -1
  25. package/page/assets/{studio-map-Bajn32Xo.js → studio-map-BAXmd4eb.js} +1 -1
  26. package/page/assets/{studio-trace-replay-D78AB4Zj.js → studio-trace-replay-Wc4f_9El.js} +1 -1
  27. package/page/assets/{tool-schema-C7lMQU0w.js → tool-schema-BHHcOFff.js} +1 -1
  28. package/page/assets/{tree-BpAzPK_j.js → tree-DveW6zCH.js} +1 -1
  29. package/page/assets/{turn-client-CMgd-m7p.js → turn-client-D36i6KKG.js} +1 -1
  30. package/page/assets/{use-one-call-DS5qaoqY.js → use-one-call-CJYjKc3D.js} +1 -1
  31. package/page/assets/{workspace-CUvoWPwb.js → workspace-BmMSRE4E.js} +1 -1
  32. package/page/index.html +11 -11
@@ -1 +1 @@
1
- import{C as e,E as t,O as n,b as r,c as i,d as a,h as o,v as s,x as c}from"./schemas-D7cgkv3L.js";import{$n as l,Kn as u,Yn as d,zn as f}from"./tool-schema-C7lMQU0w.js";import{C as p,M as m,O as h,j as g}from"./reader-DAdKx3ZF.js";import{n as _}from"./trace-schema--4IGmLeE.js";import{w as v}from"./turn-client-CMgd-m7p.js";var y=c({type:s(`open`),history:a(d).optional(),slots:e(t(),t()).optional(),context:n().optional(),stated:h.optional(),model:t().optional(),effort:t().optional(),resume:c({providerState:l,awayMs:r().nonnegative()}).optional(),host:e(t(),n()).optional()}),b=o(`type`,[c({type:s(`audio`),data:t()}),c({type:s(`video`),data:t(),mimeType:t()}),c({type:s(`text`),text:t()}),c({type:s(`context`),context:n()}),c({type:s(`executeTool`),callId:t().min(1),operationId:t().min(1).max(256),decision:i(v).optional(),input:n().optional(),secret:t().optional(),output:n().optional(),grantId:t().min(1).optional(),unanswered:s(!0).optional()})]),x={ready:c({type:s(`ready`),profile:t().optional(),sessionId:t().optional()}),events:c({type:s(`events`),events:a(n())}),trace:c({type:s(`trace`),record:_}),error:c({type:s(`error`)}).and(p),executeToolResult:o(`status`,[c({type:s(`executeToolResult`),callId:t().min(1),operationId:t().min(1).max(256),status:s(`dispatched`),grantId:t().min(1),arguments:e(t(),n())}),c({type:s(`executeToolResult`),callId:t(),status:s(`settled`),operationId:t().min(1).max(256)}),c({type:s(`executeToolResult`),callId:t(),status:s(`gated`),operationId:t().min(1).max(256),gate:u}),c({type:s(`executeToolResult`),callId:t(),status:s(`refused`),operationId:t().min(1).max(256),body:p})])};function S(e){let t=g(x,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>m(f,e))}:t}export{y as n,S as r,b as t};
1
+ import{C as e,E as t,O as n,b as r,c as i,d as a,h as o,v as s,x as c}from"./schemas-D7cgkv3L.js";import{$n as l,Kn as u,Yn as d,zn as f}from"./tool-schema-BHHcOFff.js";import{C as p,M as m,O as h,j as g}from"./reader-Ql1nrrAA.js";import{n as _}from"./trace-schema--4IGmLeE.js";import{w as v}from"./turn-client-D36i6KKG.js";var y=c({type:s(`open`),history:a(d).optional(),slots:e(t(),t()).optional(),context:n().optional(),stated:h.optional(),model:t().optional(),effort:t().optional(),resume:c({providerState:l,awayMs:r().nonnegative()}).optional(),host:e(t(),n()).optional()}),b=o(`type`,[c({type:s(`audio`),data:t()}),c({type:s(`video`),data:t(),mimeType:t()}),c({type:s(`text`),text:t()}),c({type:s(`context`),context:n()}),c({type:s(`executeTool`),callId:t().min(1),operationId:t().min(1).max(256),decision:i(v).optional(),input:n().optional(),secret:t().optional(),output:n().optional(),grantId:t().min(1).optional(),unanswered:s(!0).optional()})]),x={ready:c({type:s(`ready`),profile:t().optional(),sessionId:t().optional()}),events:c({type:s(`events`),events:a(n())}),trace:c({type:s(`trace`),record:_}),error:c({type:s(`error`)}).and(p),executeToolResult:o(`status`,[c({type:s(`executeToolResult`),callId:t().min(1),operationId:t().min(1).max(256),status:s(`dispatched`),grantId:t().min(1),arguments:e(t(),n())}),c({type:s(`executeToolResult`),callId:t(),status:s(`settled`),operationId:t().min(1).max(256)}),c({type:s(`executeToolResult`),callId:t(),status:s(`gated`),operationId:t().min(1).max(256),gate:u}),c({type:s(`executeToolResult`),callId:t(),status:s(`refused`),operationId:t().min(1).max(256),body:p})])};function S(e){let t=g(x,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>m(f,e))}:t}export{y as n,S as r,b as t};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,D as n,E as r,O as i,S as a,T as o,b as s,c,d as l,g as u,h as d,l as f,m as p,o as m,p as h,pt as g,s as _,t as v,u as y,v as b,x}from"./schemas-D7cgkv3L.js";import{$t as S,Bn as ee,Cn as te,Jn as C,Kt as w,Sn as T,St as E,Tn as D,U as O,Vn as ne,Wn as re,X as ie,Yn as ae,Zn as oe,_t as se,ar as ce,bn as le,en as ue,fn as de,ir as fe,mt as pe,nr as k,or as me,rr as he,s as ge,sr as _e,tr as ve,wn as ye,yn as be,zn as xe}from"./tool-schema-C7lMQU0w.js";import{c as A}from"./host-patterns-F-KZIzkF.js";import{$ as Se,Ar as Ce,Bt as we,Ct as Te,Dt as Ee,En as De,Er as Oe,F as ke,Fr as Ae,G as je,Gt as Me,Ht as Ne,I as Pe,It as Fe,Kt as Ie,L as Le,Lr as j,Lt as Re,Mr as ze,Mt as Be,N as Ve,Nt as He,P as Ue,Pn as We,Pr as Ge,Pt as Ke,Qt as qe,R as Je,Rt as Ye,Sr as Xe,Tr as Ze,Tt as Qe,Ut as $e,V as et,Vt as tt,Wn as nt,Wt as rt,Z as it,_n as at,at as ot,br as st,cn as ct,cr as lt,dt as ut,en as dt,gn as ft,gr as pt,ht as M,it as mt,j as ht,jr as gt,ln as _t,lr as vt,mn as yt,nn as bt,nr as xt,nt as St,pt as Ct,rr as wt,rt as Tt,sn as Et,tn as Dt,tt as Ot,vn as kt,xn as At,xt as jt,zn as Mt,zt as Nt}from"./shaped-data-BRffby3g.js";import{$ as Pt,B as Ft,F as It,G as Lt,H as Rt,I as zt,K as Bt,O as Vt,P as Ht,Q as Ut,Y as Wt,_ as Gt,b as Kt,et as qt,f as Jt,h as Yt,k as Xt,l as Zt,q as Qt,u as $t,y as en,z as tn}from"./browser-connection-DMLe-0pv.js";import{a as nn}from"./live-ingress-OuSlQ6q7.js";import{n as rn,t as an}from"./trace-schema--4IGmLeE.js";import{n as on}from"./stub-4NoUUWes.js";function sn(e){return{type:`guardrail`,guardrail:e}}function cn(e,t,n,r=`redact`,i){if(n.length!==0)return sn({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function ln(e,t){return e.type===`guardrail`?{...e,guardrail:wt(e.guardrail,t)}:e}var un=65536;function N(e){let t=e.classStarts.length,n=new Uint16Array(un);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??un);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 dn,P,fn;async function pn(){if(dn)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);dn={forward:t,reversed:n}}function mn(){if(!dn)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return dn}var F;function hn(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 gn(e){if(!F){F=new Map;for(let e=0;e<un;e++){let t=hn(e),n=F.get(t);n?n.push(e):F.set(t,[e])}}return F.get(hn(e))??[e]}function _n(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<un&&t.push(n+1);return t}var vn=new Map;function yn(e){let t=vn.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>gn(e.charCodeAt(n))),r=_n([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=N({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 vn.set(e,a),a}function bn(e){let t=JSON.stringify(e),n=vn.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=_n(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=N({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 vn.set(t,s),s}function xn(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 Sn(e,t){e.text+=t,e.fresh+=t}function Cn(e){return e.text.length-e.fresh.length}function I(e,t){let n=Cn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function wn(e,t,n=e.text.length){let r=Cn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function Tn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function En(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,Sn(n,t(wn(e,n.text.length)))}};return n}var Dn=/\w/,On=Math.max(...Ye.map(e=>e.length));function kn(e){return e.length<=On+1&&/^[A-Za-z]*$/.test(e)}function An(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{Sn(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(I(e,t)),o=Dn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Ne(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!kn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function jn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function L(e,t,n){Sn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var Mn=55296,Nn=56319,Pn=/[A-Za-z]/,Fn=56320,In=57343;function Ln(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=jn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(Pn.test(e)||L(c,`\\`,s),s=-1),e===`\\`?s=t:L(c,e,t)}function u(e,t){if($e(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!Pn.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=Pn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=Mn&&t<=Nn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=Fn&&a<=In?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=I(e,t),o=a>=Mn&&a<=Nn;if(o&&t+1>=i)break;let s=I(e,t+1),c=o&&s>=Fn&&s<=In?2:1,l=rt(wn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var Rn=/[0-9A-Fa-f]/;function zn(e){let t=0,n=-1,r=jn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(I(e,t));if(n<0){a===`%`?n=t:(L(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:Rn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)L(r,String.fromCharCode(I(e,n)),n)}}};function i(t){t>n&&L(r,Nt(wn(e,n,t)),n),n=-1}return r}var Bn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Vn=new Map(Re.map(({pattern:e,hit:t})=>[e,t])),Hn=new Map(St.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function R(e){return{rule:lt(e),severity:`high`,detector:e}}var Un=R(`injection`),Wn=R(`marker_leak`),Gn=R(`tool_leak`);function Kn({kind:e,group:t}){if(Bn.has(e))return Un;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:R(t);case`boundary`:return Wn;case`image`:return R(`ungiven_images`);default:return R(`ungiven_links`)}}function qn(e,t,n){if(e===`card`)return{hit:Tt};if(e===`image`||e===`link`){let r=(e===`image`?mt:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Vn.get(t)??Hn.get(t);return r?{hit:r}:{}}function Jn(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:ut(i(n?.ungiven_images)),link:Ct(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return Se.forEach((t,n)=>{let r=Kn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Ie(t.pattern),...qn(t.kind,t.pattern,a)})}),o}function Yn(){let e=[];return Se.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Vn.get(n);e.push({...Un,id:r,regex:Ie(n),...i?{hit:i}:{}})}),e}function Xn(){return Me.map((e,t)=>({...Un,id:t,regex:new RegExp(e.source,e.flags)}))}function Zn(e,t,n){let r=xn(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=Cn(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function ne(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function re(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):ne(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=re();e;e=re())t.push(e);return e.rawAt(n)}}}var Qn=new WeakMap;function $n(e){let t=Qn.get(e);return t||(t=N(e),Qn.set(e,t)),t}function er(e={}){let t={text:``,fresh:``},n=Tn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Zn(e,t,n)),a=[],o=e.detect??[],s=Jn(o,e);if(s.length>0&&(P??=N(mn().forward),a.push(i(n,P,s))),o.includes(`injection`)){P??=N(mn().forward),fn??=N(mn().reversed);let e=Ln(t),r=Yn();a.push(i(n,fn,Xn()),i(An(n),P,r),i(e,P,r),i(An(e),P,r),i(En(n,tt),P,r),i(En(n,e=>we(e)??e),P,r),i(zn(t),P,r))}if(o.includes(`marker_leak`)&&e.note){let t=Ot(e.note);a.push(i(n,yn(e.note),[{...Wn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=je(e.tools),r=t.map(({regex:e},t)=>({...Gn,id:t,regex:e}));t.length>0&&a.push(i(n,bn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...R(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,$n(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 tr(e,t,n={},r=[]){let i=Pe(e,t).filter(e=>!(Je(e)||r.includes(e))),a=Le(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=er({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=ke(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function nr(e){let{context:t}=e,n=e.detect,r=n?tr(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(-M),_=u,v=0,y=u,b=0,x=0,S=s?Te(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,xt]),c){let r=_.length;_+=e;let i=Fe(_,r);_=_.slice(i),v+=i;let[a]=it(_,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-M),i=r+jt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+jt(y,e)),x=Math.min(i,u.length+p.length-M);let a=Math.max(b,Math.max(t,x)-M);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+Ke(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(-M)),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?Ee(u+p,s,c):``}}function z(e,t,n){return Ue(t,e.detect,n)}async function rr(e,t,n,r){return z(e,[n],t)?(await pn(),ir(e,t,n,r)):null}function ir(e,t,n,r){return z(e,[n],t)?nr({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:et(e,t)},...r?{carry:r}:{}}):null}async function ar(e,t,n,r){return z(e,[n],r??t)?(await pn(),nr({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??et(e,t)}})):null}var or=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}},sr=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function cr(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var lr={client:`untrusted`,server:`assembled`};function ur(e){return typeof e==`string`?e:JSON.stringify(e)}function dr(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of Dt){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(ur(o));let c=s.found(),l=Ve(`context`,c);l&&n.push({...l,trust:lr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var fr=/^[A-Za-z0-9._-]+$/;function pr(e){let t=e?.trim();return t&&fr.test(t)?t:void 0}function mr(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 hr(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 gr(e,t){let n=t?`: ${t}`:``;return new A(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function _r(e,t){let{detect:n}=D(t.guardrails),r=st(sr,e=>ht(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Bt(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=cr(i.slots,r.slots),c=dr(i.context,()=>ht(`context`,n)),l=mr(i.repair,r.repair),u=i.history?hr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?qt(t,i.attachments,i.voice,r):i,p=[],m;for(let e of sr){let t=r[e].found(),n=Ve(e,t);n&&p.push(sn(n)),t.action===`block`&&(m??=gr(e,t.errorInternal))}return p.push(...c.events.map(sn)),c.blocked&&(m??=gr(`context`)),{request:{...e,system:o,projectId:pr(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 vr(e,t){let{request:n,refusal:r}=_r(e,t);if(r)throw r;return n}function yr(e,t){return[...new Set([...t.filter(t=>le(e,t)),...e.filter(e=>le(t,e))])]}function br(e,t){let n=e.attachments?t?yr(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 xr(e){let t=ye(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Sr(e,t){let n=Pt(e),r=Wt({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=>le(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:xr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var Cr=`final_answer`;function wr(e){return e.structured!==null&&e.tools.wire.length>0}function Tr(e,t,n){let{structured:r}=t;if(!r||!wr(t))return e;let i={type:`function`,name:Cr,description:j(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function Er(e,t){return e.get(t)||{name:t,missing:!0}}function Dr(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 Or(e,t){return[...Ht(t),...Dr(t)].map(t=>Er(e,t))}function kr(e,t){if(Array.isArray(e)){for(let n of e)kr(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),kr(r,t);for(let e of Object.values(r))kr(e,t)}function Ar(e,t){let n=Or(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&kr(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function jr(e){return!e||e.length===0?[]:e.slice(-4)}function Mr(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${j(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
1
+ import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,D as n,E as r,O as i,S as a,T as o,b as s,c,d as l,g as u,h as d,l as f,m as p,o as m,p as h,pt as g,s as _,t as v,u as y,v as b,x}from"./schemas-D7cgkv3L.js";import{$t as S,Bn as ee,Cn as te,Jn as C,Kt as w,Sn as T,St as E,Tn as D,U as O,Vn as ne,Wn as re,X as ie,Yn as ae,Zn as oe,_t as se,ar as ce,bn as le,en as ue,fn as de,ir as fe,mt as pe,nr as k,or as me,rr as he,s as ge,sr as _e,tr as ve,wn as ye,yn as be,zn as xe}from"./tool-schema-BHHcOFff.js";import{c as A}from"./host-patterns-F-KZIzkF.js";import{$ as Se,Ar as Ce,Bt as we,Ct as Te,Dt as Ee,En as De,Er as Oe,F as ke,Fr as Ae,G as je,Gt as Me,Ht as Ne,I as Pe,It as Fe,Kt as Ie,L as Le,Lr as j,Lt as Re,Mr as ze,Mt as Be,N as Ve,Nt as He,P as Ue,Pn as We,Pr as Ge,Pt as Ke,Qt as qe,R as Je,Rt as Ye,Sr as Xe,Tr as Ze,Tt as Qe,Ut as $e,V as et,Vt as tt,Wn as nt,Wt as rt,Z as it,_n as at,at as ot,br as st,cn as ct,cr as lt,dt as ut,en as dt,gn as ft,gr as pt,ht as M,it as mt,j as ht,jr as gt,ln as _t,lr as vt,mn as yt,nn as bt,nr as xt,nt as St,pt as Ct,rr as wt,rt as Tt,sn as Et,tn as Dt,tt as Ot,vn as kt,xn as At,xt as jt,zn as Mt,zt as Nt}from"./shaped-data-BRffby3g.js";import{$ as Pt,B as Ft,F as It,G as Lt,H as Rt,I as zt,K as Bt,O as Vt,P as Ht,Q as Ut,Y as Wt,_ as Gt,b as Kt,et as qt,f as Jt,h as Yt,k as Xt,l as Zt,q as Qt,u as $t,y as en,z as tn}from"./browser-connection-IC3QKsFq.js";import{a as nn}from"./live-ingress-OuSlQ6q7.js";import{n as rn,t as an}from"./trace-schema--4IGmLeE.js";import{n as on}from"./stub-U8WThytR.js";function sn(e){return{type:`guardrail`,guardrail:e}}function cn(e,t,n,r=`redact`,i){if(n.length!==0)return sn({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function ln(e,t){return e.type===`guardrail`?{...e,guardrail:wt(e.guardrail,t)}:e}var un=65536;function N(e){let t=e.classStarts.length,n=new Uint16Array(un);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??un);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 dn,P,fn;async function pn(){if(dn)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);dn={forward:t,reversed:n}}function mn(){if(!dn)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return dn}var F;function hn(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 gn(e){if(!F){F=new Map;for(let e=0;e<un;e++){let t=hn(e),n=F.get(t);n?n.push(e):F.set(t,[e])}}return F.get(hn(e))??[e]}function _n(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<un&&t.push(n+1);return t}var vn=new Map;function yn(e){let t=vn.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>gn(e.charCodeAt(n))),r=_n([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=N({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 vn.set(e,a),a}function bn(e){let t=JSON.stringify(e),n=vn.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=_n(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=N({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 vn.set(t,s),s}function xn(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 Sn(e,t){e.text+=t,e.fresh+=t}function Cn(e){return e.text.length-e.fresh.length}function I(e,t){let n=Cn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function wn(e,t,n=e.text.length){let r=Cn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function Tn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function En(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,Sn(n,t(wn(e,n.text.length)))}};return n}var Dn=/\w/,On=Math.max(...Ye.map(e=>e.length));function kn(e){return e.length<=On+1&&/^[A-Za-z]*$/.test(e)}function An(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{Sn(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(I(e,t)),o=Dn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Ne(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!kn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function jn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function L(e,t,n){Sn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var Mn=55296,Nn=56319,Pn=/[A-Za-z]/,Fn=56320,In=57343;function Ln(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=jn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(Pn.test(e)||L(c,`\\`,s),s=-1),e===`\\`?s=t:L(c,e,t)}function u(e,t){if($e(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!Pn.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=Pn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=Mn&&t<=Nn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=Fn&&a<=In?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=I(e,t),o=a>=Mn&&a<=Nn;if(o&&t+1>=i)break;let s=I(e,t+1),c=o&&s>=Fn&&s<=In?2:1,l=rt(wn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var Rn=/[0-9A-Fa-f]/;function zn(e){let t=0,n=-1,r=jn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(I(e,t));if(n<0){a===`%`?n=t:(L(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:Rn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)L(r,String.fromCharCode(I(e,n)),n)}}};function i(t){t>n&&L(r,Nt(wn(e,n,t)),n),n=-1}return r}var Bn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Vn=new Map(Re.map(({pattern:e,hit:t})=>[e,t])),Hn=new Map(St.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function R(e){return{rule:lt(e),severity:`high`,detector:e}}var Un=R(`injection`),Wn=R(`marker_leak`),Gn=R(`tool_leak`);function Kn({kind:e,group:t}){if(Bn.has(e))return Un;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:R(t);case`boundary`:return Wn;case`image`:return R(`ungiven_images`);default:return R(`ungiven_links`)}}function qn(e,t,n){if(e===`card`)return{hit:Tt};if(e===`image`||e===`link`){let r=(e===`image`?mt:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Vn.get(t)??Hn.get(t);return r?{hit:r}:{}}function Jn(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:ut(i(n?.ungiven_images)),link:Ct(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return Se.forEach((t,n)=>{let r=Kn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Ie(t.pattern),...qn(t.kind,t.pattern,a)})}),o}function Yn(){let e=[];return Se.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Vn.get(n);e.push({...Un,id:r,regex:Ie(n),...i?{hit:i}:{}})}),e}function Xn(){return Me.map((e,t)=>({...Un,id:t,regex:new RegExp(e.source,e.flags)}))}function Zn(e,t,n){let r=xn(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=Cn(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function ne(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function re(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):ne(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=re();e;e=re())t.push(e);return e.rawAt(n)}}}var Qn=new WeakMap;function $n(e){let t=Qn.get(e);return t||(t=N(e),Qn.set(e,t)),t}function er(e={}){let t={text:``,fresh:``},n=Tn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Zn(e,t,n)),a=[],o=e.detect??[],s=Jn(o,e);if(s.length>0&&(P??=N(mn().forward),a.push(i(n,P,s))),o.includes(`injection`)){P??=N(mn().forward),fn??=N(mn().reversed);let e=Ln(t),r=Yn();a.push(i(n,fn,Xn()),i(An(n),P,r),i(e,P,r),i(An(e),P,r),i(En(n,tt),P,r),i(En(n,e=>we(e)??e),P,r),i(zn(t),P,r))}if(o.includes(`marker_leak`)&&e.note){let t=Ot(e.note);a.push(i(n,yn(e.note),[{...Wn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=je(e.tools),r=t.map(({regex:e},t)=>({...Gn,id:t,regex:e}));t.length>0&&a.push(i(n,bn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...R(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,$n(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 tr(e,t,n={},r=[]){let i=Pe(e,t).filter(e=>!(Je(e)||r.includes(e))),a=Le(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=er({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=ke(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function nr(e){let{context:t}=e,n=e.detect,r=n?tr(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(-M),_=u,v=0,y=u,b=0,x=0,S=s?Te(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,xt]),c){let r=_.length;_+=e;let i=Fe(_,r);_=_.slice(i),v+=i;let[a]=it(_,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-M),i=r+jt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+jt(y,e)),x=Math.min(i,u.length+p.length-M);let a=Math.max(b,Math.max(t,x)-M);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+Ke(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(-M)),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?Ee(u+p,s,c):``}}function z(e,t,n){return Ue(t,e.detect,n)}async function rr(e,t,n,r){return z(e,[n],t)?(await pn(),ir(e,t,n,r)):null}function ir(e,t,n,r){return z(e,[n],t)?nr({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:et(e,t)},...r?{carry:r}:{}}):null}async function ar(e,t,n,r){return z(e,[n],r??t)?(await pn(),nr({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??et(e,t)}})):null}var or=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}},sr=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function cr(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var lr={client:`untrusted`,server:`assembled`};function ur(e){return typeof e==`string`?e:JSON.stringify(e)}function dr(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of Dt){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(ur(o));let c=s.found(),l=Ve(`context`,c);l&&n.push({...l,trust:lr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var fr=/^[A-Za-z0-9._-]+$/;function pr(e){let t=e?.trim();return t&&fr.test(t)?t:void 0}function mr(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 hr(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 gr(e,t){let n=t?`: ${t}`:``;return new A(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function _r(e,t){let{detect:n}=D(t.guardrails),r=st(sr,e=>ht(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Bt(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=cr(i.slots,r.slots),c=dr(i.context,()=>ht(`context`,n)),l=mr(i.repair,r.repair),u=i.history?hr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?qt(t,i.attachments,i.voice,r):i,p=[],m;for(let e of sr){let t=r[e].found(),n=Ve(e,t);n&&p.push(sn(n)),t.action===`block`&&(m??=gr(e,t.errorInternal))}return p.push(...c.events.map(sn)),c.blocked&&(m??=gr(`context`)),{request:{...e,system:o,projectId:pr(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 vr(e,t){let{request:n,refusal:r}=_r(e,t);if(r)throw r;return n}function yr(e,t){return[...new Set([...t.filter(t=>le(e,t)),...e.filter(e=>le(t,e))])]}function br(e,t){let n=e.attachments?t?yr(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 xr(e){let t=ye(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Sr(e,t){let n=Pt(e),r=Wt({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=>le(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:xr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var Cr=`final_answer`;function wr(e){return e.structured!==null&&e.tools.wire.length>0}function Tr(e,t,n){let{structured:r}=t;if(!r||!wr(t))return e;let i={type:`function`,name:Cr,description:j(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function Er(e,t){return e.get(t)||{name:t,missing:!0}}function Dr(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 Or(e,t){return[...Ht(t),...Dr(t)].map(t=>Er(e,t))}function kr(e,t){if(Array.isArray(e)){for(let n of e)kr(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),kr(r,t);for(let e of Object.values(r))kr(e,t)}function Ar(e,t){let n=Or(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&kr(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function jr(e){return!e||e.length===0?[]:e.slice(-4)}function Mr(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${j(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
2
2
  `)}\n\n`}function Nr(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||j(`repair.default_guidance`,{},t.labels),a=Mr(jr(r),t.labels),o=`${j(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${j(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${j(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${j(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${j(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${j(`repair.section_instructions`,{},t.labels)}\n`,o+=j(`repair.prompt_instructions`,{},t.labels),o}function Pr(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function Fr(e,t){let n=Pr(e,t);if(!(n.length<=1))throw new A(`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 Ir(e,t){if(e.type!==`speech`){if(t.speech)throw new A(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new A(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function Lr(e,t){if(e.type===`transcription`){if(t.system)throw new A(`config`,`Profile ${e.id} (transcription) takes no system prompt — the input is the clip`);if(!t.input?.voice?.length)throw new A(`request`,`Profile ${e.id} (transcription) requires a voice clip`)}}function Rr(e,t){return e.type===`speech`?{...e.speech,...zr(t.speech)}:void 0}function zr(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function Br(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 Vr(e){let t=be(e);if(!t)throw new A(`input`,`MIME '${e}' is not a supported media input type`);return t}function Hr(e){return e.map(e=>{let t=Vr(e.mimeType),n=ye(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return Ut(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Ur(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new A(`request`,`Profile ${e.id} (speech) requires text input`);if(T(e)?.text===!1&&n)throw new A(`request`,`Profile ${e.id} does not accept text input`);let a=r?Nr({profile:e,repair:r,history:i}):Gr(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Wr(t),...a?[He(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
3
3
 
4
4
  `)}:null}function Wr(e){let t=e.input?.context??{};return[...Dt].reverse().filter(e=>t[e]!==void 0).map(e=>Be(e,ur(t[e])))}function Gr(e,t){if(t.continueFrom&&w.includes(e.type)){if(t.input?.text)throw new A(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return j(`continue.instruction`,{},e.labels)}}function Kr(e){return e.type===`image`&&e.image.references?Hr(e.image.references):[]}function qr(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Kr(e),...Hr(n),...Hr(r)]}function Jr(e,t){let n=[],r=Ur(e,t);return r&&n.push(r),n.push(...qr(e,t)),n}function Yr(e,t){let n=t.input?.slots;if(!n)return;let r=T(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new A(`request`,`Profile ${e.id} has no slot '${t}'`);let a=Xt(n);if(!a.includes(i))throw new A(`request`,`Profile ${e.id}: slot '${t}' takes ${a.join(`, `)}, not '${i}'`)}}function Xr(e,t){let n=t.input?.context;if(!n)return;let r=T(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!Dt.includes(t)||!r?.from.some(e=>e===t))throw new A(`request`,`Profile ${e.id} takes no context from '${t}'`);if(ur(i).length>r.maxChars)throw new A(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Zr=/\{([A-Za-z_][\w-]*)\}/g;function Qr(e,t,n,r){let i=T(e)?.slots;return i?t.replace(Zr,(t,a)=>{if(!Object.hasOwn(i,a))return t;let o=n&&Object.hasOwn(n,a)?n[a]:void 0;if(o===void 0)throw new A(`request`,`Profile ${e.id}: ${r} uses slot '${a}', and the request chose no value for it`);return o}):t}function $r(e,t,n){if(e.type===`speech`||e.type===`transcription`)return[];let r=e.identity.system;if(!r)return[];let i=Rt(e.id,e.identity.conditions,n,t);return Ft(r,i,n=>Qr(e,n,t,`identity.system`))}function ei(e,t){let n=$r(e,t.input?.slots,t);return{pieces:Lt([...n.map(({pieces:e})=>e),t.system===void 0?[]:Qt(t.system)]),lines:n.map(({line:e})=>e)}}function ti(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function ni(e,t){if(ti(e))return e;throw e.type===`host`?new A(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new A(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new A(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function ri(e,t){if(t){if(!e.allowModelSelect)throw new A(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new A(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function ii(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new A(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new A(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new A(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function ai(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function oi(e,t){if(e.type===`live`)return null;let n=e.outputs?.structured;if(!n)return null;if(typeof n==`string`)return n;let r=t?.[n.by];if(r){let e=n.map[r];if(e)return e}return n.fallback}function si(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function ci(e,t){return e.type===`live`?`live`:`turn`}function li(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new A(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=ue(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new A(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new A(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new A(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function ui(e,t){return z(D(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function di(e){let{detect:t}=D(e.guardrails);return e.type!==`speech`&&e.type!==`transcription`&&nt(t,`canary_leak`)?Qe():``}function fi(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new A(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function pi(e,t,n){let r=ni(e.profiles.get(t.profile),`resolveTurn`);Yr(r,t),Xr(r,t);let i=vr(t,r),a=i.input??{};li(r,i);let o=n??ri(r,i.model),s=te(r,o),c=tn(e.tools,r,i,o),l=c.builtins,u=oi(r,a.slots);if(Fr(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new A(`config`,`Profile ${r.id}: a structured turn answers through '${Cr}', so no tool of its own may take that name`);Ir(r,i),Lr(r,i);let d=fi(r,o,s,i.builtInArgs),f=ci(r,s),p=e.providers.get(s.provider),m=p&&de(p,s,r.type),h=ei(r,i);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,...m?{operationName:m}:{},stream:si(r),thinking:ii(r,s,o,i.effort),summaries:ai(s),maxOutputTokens:s.maxOutputTokens,temperature:s.temperature,builtins:l,builtInArgs:d,sessionId:i.sessionId,tools:c,sessionPermissions:i.sessionPermissions,execution:i.execution,pageExecution:i.pageExecution,history:a.history,maxSteps:r.maxSteps??20,structured:u?{id:u,jsonSchema:e.schemas.get(u).jsonSchema}:null,image:Br(r),speech:Rr(r,i),live:r.type===`live`?ui(r.live,r.guardrails):void 0,input:Jr(r,i),canary:di(r),resolvedSystem:h.pieces,systemLines:h.lines,host:i.host}}}function mi(e){return e.type===`image`?e.image:null}function hi(e,t){let n=ni(t,`projectProfile`),{identity:r}=n,i=T(n)??null,a=n.type===`live`?null:n.outputs??null;return{id:n.id,type:n.type,handle:r.handle,models:n.models,defaultModel:n.defaultModel,allowModelSelect:n.allowModelSelect,maxSteps:n.maxSteps,tools:Or(e,n),inputs:i,outputs:a,image:mi(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function gi(e,t){return hi(e.tools,e.profiles.get(t))}var _i=o({accepted:ve,preparedInput:k});function B(e){return new A(`internal`,e)}function vi(e,t,n){return new A(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function yi(e){return vi(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function bi(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,n])=>[e,t(n)])):e,n=k.parse(t(Ei(e))),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(n)));return Array.from(new Uint8Array(r),e=>e.toString(16).padStart(2,`0`)).join(``)}var xi=xe.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),g)),Si=o({finding:r(),data:k.optional(),parts:l(ne).optional(),modelText:r().optional(),provenance:_e.optional(),suspicious:l(me).optional()}),Ci=xe.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),g)),wi=o({event:Ci,replay:o({modelResult:Si})}),Ti=o({event:xi,effects:c([`not_started`,`completed`,`unknown`]),replay:o({modelResult:Si.optional(),outputRaw:k.optional(),failure:o({code:r(),kind:fe,message:r(),error:r().optional(),details:k.optional()}).optional(),awaiting:h().optional(),denied:b(!0).optional(),callNotStarted:h().optional(),aborted:n([h(),o({reason:r().optional()})]).optional(),pendingInject:l(o({id:r().optional(),messages:l(ae),released:s().int().nonnegative().optional()})).optional()})});function Ei(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw B(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw B(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw B(`Tool operation value has an own __proto__ key`);t.add(e);try{if(Array.isArray(e))return e.map(n);let t=Object.entries(Object.getOwnPropertyDescriptors(e)),r=t.find(([,e])=>e.get||e.set);if(r)throw B(`Tool operation value has a getter or setter at '${r[0]}'`);return Object.fromEntries(t.filter(([,e])=>e.enumerable&&e.value!==void 0).map(([e,t])=>[e,n(t.value)]))}finally{t.delete(e)}};return k.parse(n(e))}var Di=`background`;function Oi(){return h().optional().describe(j(`tool.background_field`))}function ki(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[Di]:n,...r}=t;return{input:r,asked:n===!0}}function Ai(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?ki(e,t).asked?`claim`:void 0:n}function ji(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||!n)return;let a=Ai(t,e.input);if(a!==void 0)return{at:a,support:n,trace:n.openTrace(r.callId),reply:()=>{let e={finding:j(`tool.background_started`,{tool:t.name},i)},n=se(e),a=pe(r,{phase:`background`,readBack:n});return wi.parse(Ei({event:a,replay:{modelResult:e}}))}}}function Mi(e,t){if(e&&!t?.detach)throw new A(`config`,`A request with a background service needs a coordinator with detach`)}function Ni(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new A(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(typeof n==`object`&&!(Number.isFinite(n.afterMs)&&n.afterMs>=0))throw new A(`config`,`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`)}}var Pi=/^[\x21-\x7E]{1,256}$/;function Fi(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function Ii(e){return e!==null&&Pi.test(e)}async function Li(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var Ri=`after`;function zi(){return l(r()).optional().describe(j(`tool.after_field`))}function Bi(e,t,r,i){let a=t=>{if(t instanceof m){if(r in t.shape)throw new A(`config`,`Tool '${e}' sets ${r}, and its input already has a field of that name`);return t.safeExtend({[r]:i()})}if(t instanceof v){let e=t.options.map(a);return d(t.def.discriminator,e)}if(t instanceof _)return n(t.options.map(a));throw new A(`config`,`Tool '${e}' sets ${r}, which needs an object input or a union of objects`)};return a(t)}function Vi(e,t){return Bi(e,t,Ri,zi)}function Hi(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[Ri]:n,...r}=t;return{input:r,names:n??[]}}function Ui(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var Wi=class{value;constructor(e){this.value=e}};function Gi(e){return new Wi(e)}function Ki(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return Gi(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(j(`tool.page_timed_out`,{},i)):Error(j(`tool.page_no_answer`,{tool:e},i))}}var qi=new WeakMap;function Ji(e,t){let n=qi.get(e);n||(n=new WeakMap,qi.set(e,n));let r=n.get(t);if(!r){let i=$t(e,`input`);Jt(i,`input`);let a=$t(t,`output`);Jt(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Yi(e){let{inputSchema:t,outputSchema:n}=Ji(e.input,e.output),r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?E(n,r[t]):void 0;if(i)throw new A(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Xi(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new A(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function Zi(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new A(`config`,`Tool "${e}" auth.queryParam ${r}`)}function Qi(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new A(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function $i(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new A(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function V(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new A(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function ea(e){V(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(V(e.name,`imageLimits.count`,t.count),V(e.name,`imageLimits.bytes`,t.bytes),V(e.name,`imageLimits.totalBytes`,t.totalBytes),$i(e.name,t.timeoutMs))}function ta(e){return Zt(e.endpoint),Xi(e.name,e.auth),Zi(e.name,e.auth,e.mapping?.queryParams),Qi(e.name,e.limit),$i(e.name,e.timeoutMs),ea(e),{...e,type:`http`,...Yi(e)}}function na(e){return Xi(e.name,e.auth),Zi(e.name,e.auth),ea(e),V(e.name,`session.idleMs`,e.session?.idleMs),V(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...Yi(e)}}function ra(e){Xi(e.name,e.auth),Zi(e.name,e.auth);let t=e.answeredBy===`page`?Ki(e.name):e.handler;if(typeof t!=`function`)throw new A(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...Yi(e)}}function ia(e){if(e.type===`builtin`||(Ni({name:e.name,...e.background===void 0?{}:{background:e.background},...e.type===`function`&&e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.background!==`ask`))return e;let t=e.input,n=Bi(e.name,t,`background`,Oi);return{...e,askInputSchema:Ji(n,e.output).inputSchema}}function aa(e,t,n){return ia(oa(e,t,n))}function oa(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=en(e,t,n),i=T(r),a=Yt({type:r.type,...i?{inputs:i}:{}},e),o=e.after?Vi(e.name,a):a,s=Yi({...e,input:o,output:Gt});return Kt(e,o,s)}let r=e.after?{...e,input:Vi(e.name,e.input)}:e;return r.type===`http`?ta(r):r.type===`mcp`?na(r):ra(r)}function sa(e=()=>void 0){let t=new Map,n=Fi(),r=e=>t.get(e),i=n=>{let i=aa(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new A(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}var ca=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function la(e){return e.join(`,`)}function ua(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:la(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:Vt(e?.slots),context:e?.context}}function da(e){return{text:e.text,attachments:e.attachments?{accept:e.attachments.accept}:void 0,voice:e.voice?{accept:e.voice.accept}:void 0,maxFiles:e.maxFiles,maxBytes:e.maxBytes,maxTurnBytes:e.maxTurnBytes,limitsByMime:e.limitsByMime,slots:e.slots,context:e.context}}function fa(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=Wt({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Pt(da(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function pa(e){let t=globalThis.MediaRecorder;if(t===void 0)return;let n=e=>t.isTypeSupported(e),r=e=>e.find(n);return e?.length?r(ca.filter(t=>le(e,t)))??e.find(n):r(ca)}var ma=x({protocol:r(),provider:r(),apiId:r(),options:t(r(),u()).optional(),keySlot:r().optional(),fallbackKeySlot:r().optional(),efforts:t(r(),c(kt)).optional(),defaultEffort:r().optional(),allowEffortSelect:h().optional(),summaries:h().optional(),maxOutputTokens:s().optional(),temperature:s().optional(),builtInTools:l(r()).optional(),compaction:x({maxTokens:s(),compactAt:s(),previousExchanges:s(),profile:r().optional(),timing:c(dt),meter:c(qe).optional()}).optional(),limits:x({operationTimeoutMs:s().optional(),connectTimeoutMs:s().optional(),liveStepTimeoutMs:s().optional(),maxWireRecordBytes:s().optional(),maxWireResponseBytes:s().optional(),maxEventBytes:s().optional(),maxStepBytes:s().optional(),maxStepEvents:s().optional(),maxPendingToolCalls:s().optional()}).optional()}),ha=x({structured:n([r(),x({by:r(),map:t(r(),r()),fallback:r()}),f()]).optional(),streaming:x({mode:c(at).optional(),streamThoughts:h().optional()}).optional()}),ga=x(st(pt,()=>c(Mt))),_a=x(st(We,()=>ga)),va=x({id:r(),label:r(),actions:ga,names:l(r()),find:h()}),ya=x({hosts:l(r()),fromTools:h()}),ba=x({quota:x({perDay:s()}).optional(),detect:_a,patterns:a(c(We),x({theorem:h(),names:l(r())})).optional(),host:l(va).optional(),allow:x({ungiven_images:ya,ungiven_links:ya}),blockedReply:x({onBlock:c(vt),maxRetries:s()})}),xa=n([h(),x({theorem:h(),host:h()})]),Sa=x({record:h(),writeTo:n([b(!1),r()]).optional(),sampleRate:s(),include:x({upstreamLog:h(),outboundWire:h(),evidenceRaw:h(),usage:h(),guardrailDecisions:h(),guardrailMatchPreview:h()}),scrub:x({sensitive:xa,injection:xa,canary:xa}),resource:an,retainForDays:s(),rotateAfterMiB:s(),hasOnWriteError:h()}),H=x({text:h(),attachments:x({accept:l(r()),acceptAttr:r()}).nullable(),voice:x({accept:l(r())}).nullable(),maxFiles:s().optional(),maxBytes:s().optional(),maxTurnBytes:s().optional(),limitsByMime:t(r(),s()).optional(),slots:t(r(),x({label:r().optional(),choices:l(x({value:r(),description:r().optional()}))})).optional(),context:x({from:l(c(Dt)),maxChars:s()}).optional()}),Ca=x({allowContinue:l(c(bt)).optional(),autoContinue:l(c(bt)).optional(),maxContinues:s().optional()}),wa=x({resumption:Ca.optional()}),Ta=x({allow:l(r()),page:l(r()),t2Loader:r().optional(),parallel:h().optional()}),U={providerContinuation:x({history:c([`host`,`stateless`,`provider`]).optional()}).optional(),id:r(),models:t(r(),ma),defaultModel:r(),allowModelSelect:h().optional(),maxSteps:s().optional(),labels:a(c(Ge),r()),guardrails:ba.optional(),observability:Sa.optional()},Ea=n([r(),o({private:r().min(1)})]),Da=n([r(),l(n([r(),l(Ea).readonly()])).min(1).readonly()]),Oa=x({handle:r(),conditions:t(r(),l(r()).readonly()).readonly().optional(),system:Da.optional()}),W=d(`type`,[x({...U,type:b(`text`),identity:Oa,outputs:ha.optional(),inputs:H,tools:Ta,turnBehaviour:x({resumption:Ca.optional(),allowSteering:h().optional(),atStepLimit:c(ft).optional()}).optional(),canStop:b(!0),allowSteering:h()}),x({...U,type:b(`image`),identity:Oa,outputs:ha.optional(),image:x({aspectRatio:r().optional(),resolution:r().optional(),mimeType:r().optional(),quality:r().optional(),background:r().optional(),n:s().int().min(1).optional(),seed:s().int().optional(),outputCompression:s().int().min(0).max(100).optional(),references:l(n([x({mimeType:r(),data:r(),name:r().optional()}),x({mimeType:r(),uri:r(),name:r().optional()})])).optional(),includeText:h().optional()}),inputs:H,tools:Ta,turnBehaviour:wa.optional(),canStop:b(!0)}),x({...U,type:b(`transcription`),identity:x({handle:r()}),maxSteps:y().optional(),outputs:ha.optional(),inputs:H,canStop:b(!0)}),x({...U,type:b(`speech`),identity:x({handle:r()}),outputs:ha.optional(),speech:x({voice:r().optional(),style:r().optional(),speed:s().optional(),format:c(yt).optional()}),inputs:H,turnBehaviour:wa.optional(),canStop:b(!0)}),x({...U,type:b(`live`),identity:Oa,inputs:H.pick({slots:!0,context:!0}).optional(),live:x({ingress:x({audio:h().optional(),video:h().optional(),text:h().optional()}).optional(),voice:r().optional(),vad:x({activityHandling:c(Et).optional(),startSensitivity:c(_t).optional(),endSensitivity:c(ct).optional(),prefixPaddingMs:s().optional(),silenceDurationMs:s().optional()}).optional(),sessionResumption:h().optional(),contextCompression:x({triggerTokens:s().optional(),slidingWindow:x({targetTokens:s().optional()})}).optional(),transcription:x({input:h().optional(),output:h().optional()}).optional()}),tools:Ta.pick({allow:!0,page:!0}),turnBehaviour:x({allowSteering:h().optional()}).optional()})]);function ka(e){let t=D(e),{sources:n,host:r,...i}=t.detect;return{quota:t.quota,detect:i,...n?{patterns:Object.fromEntries(Object.entries(n).map(([e,{theorem:t,matchers:n}])=>[e,{theorem:t,names:n.map(({name:e})=>e)}]))}:{},...r?{host:r.map(({id:e,label:t,actions:n,matchers:r,find:i})=>({id:e,label:t,actions:n,names:r.map(({name:e})=>e),find:!!i}))}:{},allow:{ungiven_images:Aa(t.allow.ungiven_images),ungiven_links:Aa(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function Aa(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function ja(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function Ma(e){if(!e)return;let t=nn(e);return{record:t.record,writeTo:ja(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function Na(e){let{greeting:t,resumed:n,...r}=e??{};return r}function Pa(e,t){let n=e.tools.filter(e=>`type`in e&&e.type===`function`&&e.answeredBy===`page`).map(e=>e.name);if(t){let e=zt(t),r=It(t);return{allow:[...Ht(t)],page:n,...e?.t2Loader?{t2Loader:e.t2Loader}:{},...r===void 0?{}:{parallel:r}}}return{allow:e.tools.filter(e=>!(`type`in e&&e.type===`builtin`)).map(e=>e.name),page:n}}function Fa({allow:e,page:t}){return{allow:e,page:t}}function Ia(e,t){let n=ua(e.inputs),r=t?.identity??{handle:e.handle},i=t?ka(t.guardrails):void 0,a=t?Ma(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:Ae(t?.labels)};switch(e.type){case`text`:return W.parse({...s,type:`text`,inputs:n,tools:Pa(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||S(t)});case`image`:return W.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:Pa(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return W.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`transcription`:return W.parse({...s,type:`transcription`,inputs:n,canStop:!0});case`live`:return W.parse({...s,type:`live`,live:Na(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:Fa(Pa(e,t))});default:return e.type}}function La(e,t){let n=ni(e,`interfaceFromProfile`);return Ia(hi(t,n),n)}function Ra(e){return p(t=>C.safeParse(e(t)).success)}var za=[`running`,`gate`,`background`,`complete`,`error`,`cancel`],Ba=p(e=>{let t=C.safeParse({type:`tool`,tool:e});if(!t.success||t.data.type!==`tool`||!(`phase`in t.data.tool))return!1;let{phase:n}=t.data.tool;return za.some(e=>e===n)}),Va=t(r(),i()),Ha=x({operationId:r().optional(),name:r(),callId:r(),arguments:Va,draft:r().optional(),reasoning:l(re).optional(),stepId:r().optional(),edited:x({from:Va,to:Va}).optional(),activity:r().optional(),activityPast:r().optional(),outputDraft:r().optional(),state:Ba.optional(),startedAt:s().optional(),endedAt:s().optional(),artifacts:l(i()),get steps(){return l(Ha).optional()}}),Ua=x({kind:c(De),native:r().optional()}),G={id:r()},K=d(`kind`,[x({...G,kind:b(`user-text`),text:r()}),x({...G,kind:c([`user-attachment`,`user-voice`]),name:r(),mimeType:r(),sizeBytes:s(),data:r().optional()}),x({...G,kind:b(`thought`),text:r()}),x({...G,kind:b(`text`),text:r()}),x({...G,kind:b(`tool`),tool:Ha}),x({...G,kind:b(`structured`),value:i(),draft:r().optional()}),x({...G,kind:b(`media`),mimeType:r(),data:r().optional(),url:r().optional(),previewUrl:r().optional()}),x({...G,kind:b(`grounding`),grounding:Ra(e=>({type:`grounding`,grounding:e}))}),x({...G,kind:b(`citation`),sources:Ra(e=>({type:`citation`,sources:e})),callId:r().optional()}),x({...G,kind:b(`evidence`),evidence:Ra(e=>({type:`evidence`,evidence:e}))}),x({...G,kind:b(`guardrail`),guardrail:ce}),x({...G,kind:b(`error`),message:r()}),x({...G,kind:b(`turn-done`),stop:Ua.optional(),tokens:Ra(e=>({type:`tokens`,tokens:e})).optional(),interactionId:r().optional(),compaction:h().optional(),workedMs:s().optional(),endedAt:s().optional()})]),Wa=x({type:r()});function Ga(e,t){return Object.hasOwn(e,t)}function Ka(e,t){return e.map(e=>{let n=[...t,...e.path],r=`${n.map(String).join(`.`)||`(root)`} ${e.code}`;return e.code!==`invalid_union`||e.errors.length===0?r:`${r} [${e.errors.map(e=>Ka(e,n)).join(` | `)}]`}).join(`; `)}function qa(e){return Ka(e.issues,[])}function Ja(e,t){return new A(`bad_response`,`${e} failed its wire check: ${qa(t)}`)}function q(e,t,n){let r=e.safeParse(t);if(!r.success)throw Ja(n,r.error);return r.data}function Ya(e){return{type:`malformed`,error:new A(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Xa(e,t){let n=Wa.safeParse(t);if(!n.success)return Ya(`a line without a kind failed its wire check: ${qa(n.error)}`);let{type:r}=n.data;if(!Ga(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:Ya(`a '${r}' line failed its wire check: ${qa(i.error)}`)}function Za(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Qa(e,t){let n=Za(t);return n?Xa(e,n.value):Ya(`a line is not JSON`)}function $a(e){let t=Za(e);if(!t)throw new A(`bad_response`,`a line is not JSON`);return t.value}var eo=x({name:r(),mimeType:r(),data:r()}),to=x({slots:t(r(),r()).optional(),context:i().optional(),text:r().optional(),attachments:l(eo).optional(),voice:l(eo).optional()}),no=x({gateKind:c(At).optional(),sessionPermissions:l(r()).optional(),name:r().optional(),input:i().optional(),snapshot:oe.optional(),promoted:l(r()).optional(),model:r().optional(),effort:r().optional()}),J=r().trim().min(1),ro=x({path:r().optional(),conditions:t(r(),r()).optional()}),io=ro;x({input:to,conversation:r().min(1).optional(),model:r().optional(),effort:r().optional(),stated:ro.optional(),turnId:J.optional(),abandon:l(ee).min(1).optional(),replay:no.pick({sessionPermissions:!0}).optional(),transcript:l(K).optional()});var ao=[`approve`,`deny`],oo=n([o({unanswered:b(!0)}),o({output:i()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);x({gateId:r().min(1),operationId:r().min(1).max(256),decision:c(ao),input:i().optional(),secret:r().optional(),page:oo.optional(),conversation:r().min(1).optional(),turnId:J.optional(),replay:no.optional()}),x({turnId:J,id:J,inject:l(ae).min(1)}),x({turnId:J});var so=x({type:b(`conversation`),ref:r().min(1),posted:b(!0).optional()}),co={...xe,conversation:so},lo=x({transcript:l(K),paused:x({events:l(C),blocks:l(K)}).optional()});x({conversation:r().min(1)}),x({conversation:r().min(1),at:s().int().min(-1)}),x({blocks:l(K)});var uo=x({conversation:r().min(1),view:lo}),fo=class extends Error{kind;publicMessage;internalMessage;copy;constructor(e,t,n,r){super(n??t??e),this.name=`TheoremStreamError`,this.kind=e,t&&(this.publicMessage=t),n&&(this.internalMessage=n),r&&(this.copy=r)}};function po(e){return e instanceof fo}function mo(e){return e?.trim()||void 0}var ho=x({error:r().optional(),errorKind:fe.optional(),errorCopy:he.optional(),errorInternal:r().optional()}),go=ho;function _o(e,t){let n=mo(e.error),r=mo(e.errorInternal);return new fo(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function vo(e){return!po(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function yo(e,t){let n=Qa(e,t);if(n.type===`error`)throw _o(ho.parse(n),`internal`);return n}function bo(e,t,n){let r=e.split(`
@@ -1,4 +1,4 @@
1
- import{i as e,o as t}from"./tool-schema-C7lMQU0w.js";import{Dn as n,Jt as r}from"./shaped-data-BRffby3g.js";var i=r.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=n.filter(e=>e===`audio/*`),o=`{
1
+ import{i as e,o as t}from"./tool-schema-BHHcOFff.js";import{Dn as n,Jt as r}from"./shaped-data-BRffby3g.js";var i=r.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=n.filter(e=>e===`audio/*`),o=`{
2
2
  "User-Agent": "TheoremStudio/1.0 (travel demo; +https://github.com/masudl-hub/theoremai)"
3
3
  }`,s=`{
4
4
  "Accept": "application/vnd.github.raw",
@@ -1,5 +1,5 @@
1
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-BO-lN_65.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{D as i,Jt as a,T as o,k as s,qt as c}from"./tool-schema-C7lMQU0w.js";import{Jn as l,On as u,Pn as d,br as f,gr as p,tn as m}from"./shaped-data-BRffby3g.js";import{X as h,b as g,g as _,h as v,m as y,w as b,x,y as S}from"./tree-BpAzPK_j.js";import{r as C}from"./live-ingress-OuSlQ6q7.js";import{a as w,i as T,n as E,r as ee}from"./use-second-ticker-sszFj3Ez.js";import{n as te}from"./stub-4NoUUWes.js";import{I as D,M as ne,k as re,r as ie}from"./workspace-CUvoWPwb.js";import{ct as ae,y as oe}from"./index-DxaSpTtM.js";var O=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},se=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 O(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===`
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{D as i,Jt as a,T as o,k as s,qt as c}from"./tool-schema-BHHcOFff.js";import{Jn as l,On as u,Pn as d,br as f,gr as p,tn as m}from"./shaped-data-BRffby3g.js";import{X as h,b as g,g as _,h as v,m as y,w as b,x,y as S}from"./tree-DveW6zCH.js";import{r as C}from"./live-ingress-OuSlQ6q7.js";import{a as w,i as T,n as E,r as ee}from"./use-second-ticker-sszFj3Ez.js";import{n as te}from"./stub-U8WThytR.js";import{I as D,M as ne,k as re,r as ie}from"./workspace-BmMSRE4E.js";import{ct as ae,y as oe}from"./index-CCj0zkrC.js";var O=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},se=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 O(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 k(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function A(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:`
@@ -1 +1 @@
1
- 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"./VStack-CkVMcNiK.js";import{d as i}from"./useTooltip-c097gL_-.js";import{o as a}from"./index-DxaSpTtM.js";var o=e(n(),1),s=i();function c(e,t,n){return Math.max(1,Math.floor((e+n)/(t+n)))}function l(e,t,n){let r=Array.from({length:t},()=>0);return{places:e.map(e=>{let t=r.indexOf(Math.min(...r)),i=r[t]??0;return e!==0&&(r[t]=i+(e??0)+n),{column:t,top:i}}),height:Math.max(0,Math.max(...r)-n)}}var u=t();function d(e,t){return e.width===t.width&&e.gap===t.gap&&e.heights.length===t.heights.length&&e.heights.every((e,n)=>e===t.heights[n])}function f({minWidth:e,children:t}){let n=o.Children.toArray(t),i=(e,t)=>(0,o.isValidElement)(e)&&e.key!==null?e.key:String(t),a=(0,o.useRef)(null),f=(0,o.useRef)([]),p=(0,o.useRef)(null),m=(0,o.useRef)([]),h=e=>(m.current[e]??=t=>(f.current[e]=t,t&&p.current?.observe(t),()=>{t&&p.current?.unobserve(t)}),m.current[e]),[g,_]=(0,o.useState)({width:0,gap:0,heights:[]}),v=c(g.width,e,g.gap),y=(g.width-g.gap*(v-1))/v,{places:b,height:x}=l(n.map((e,t)=>g.heights[t]),v,g.gap),S=g.width>0;return f.current.length=n.length,(0,o.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new WeakMap,n=0,r=new ResizeObserver(r=>{for(let i of r){let r=i.borderBoxSize[0];i.target===e?n=i.contentBoxSize[0]?.inlineSize??n:r&&t.set(i.target,r.blockSize)}let i={width:n,gap:Number.parseFloat(getComputedStyle(e).rowGap)||0,heights:f.current.map(e=>e?t.get(e):void 0)};(0,s.flushSync)(()=>_(e=>d(e,i)?e:i))});r.observe(e);for(let e of f.current)e&&r.observe(e);return p.current=r,()=>{r.disconnect(),p.current=null}},[]),(0,u.jsx)(r,{ref:a,gap:3,style:S?{position:`relative`,height:x}:void 0,children:n.map((e,t)=>{let n=b[t];return(0,u.jsx)(`div`,{ref:h(t),style:S&&n?{position:`absolute`,top:n.top,left:n.column*(y+g.gap),width:y}:void 0,children:e},i(e,t))})})}function p({payload:e,runtime:t=null,traces:n,onActivity:r},i,s){return(0,o.useMemo)(()=>{let o=t?s(e,t,{traces:n}):i(e,{traces:n});return r?a(o,r):o},[e,t,n,r,i,s])}export{f as n,p as t};
1
+ 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"./VStack-CkVMcNiK.js";import{d as i}from"./useTooltip-c097gL_-.js";import{o as a}from"./index-CCj0zkrC.js";var o=e(n(),1),s=i();function c(e,t,n){return Math.max(1,Math.floor((e+n)/(t+n)))}function l(e,t,n){let r=Array.from({length:t},()=>0);return{places:e.map(e=>{let t=r.indexOf(Math.min(...r)),i=r[t]??0;return e!==0&&(r[t]=i+(e??0)+n),{column:t,top:i}}),height:Math.max(0,Math.max(...r)-n)}}var u=t();function d(e,t){return e.width===t.width&&e.gap===t.gap&&e.heights.length===t.heights.length&&e.heights.every((e,n)=>e===t.heights[n])}function f({minWidth:e,children:t}){let n=o.Children.toArray(t),i=(e,t)=>(0,o.isValidElement)(e)&&e.key!==null?e.key:String(t),a=(0,o.useRef)(null),f=(0,o.useRef)([]),p=(0,o.useRef)(null),m=(0,o.useRef)([]),h=e=>(m.current[e]??=t=>(f.current[e]=t,t&&p.current?.observe(t),()=>{t&&p.current?.unobserve(t)}),m.current[e]),[g,_]=(0,o.useState)({width:0,gap:0,heights:[]}),v=c(g.width,e,g.gap),y=(g.width-g.gap*(v-1))/v,{places:b,height:x}=l(n.map((e,t)=>g.heights[t]),v,g.gap),S=g.width>0;return f.current.length=n.length,(0,o.useLayoutEffect)(()=>{let e=a.current;if(!e)return;let t=new WeakMap,n=0,r=new ResizeObserver(r=>{for(let i of r){let r=i.borderBoxSize[0];i.target===e?n=i.contentBoxSize[0]?.inlineSize??n:r&&t.set(i.target,r.blockSize)}let i={width:n,gap:Number.parseFloat(getComputedStyle(e).rowGap)||0,heights:f.current.map(e=>e?t.get(e):void 0)};(0,s.flushSync)(()=>_(e=>d(e,i)?e:i))});r.observe(e);for(let e of f.current)e&&r.observe(e);return p.current=r,()=>{r.disconnect(),p.current=null}},[]),(0,u.jsx)(r,{ref:a,gap:3,style:S?{position:`relative`,height:x}:void 0,children:n.map((e,t)=>{let n=b[t];return(0,u.jsx)(`div`,{ref:h(t),style:S&&n?{position:`absolute`,top:n.top,left:n.column*(y+g.gap),width:y}:void 0,children:e},i(e,t))})})}function p({payload:e,runtime:t=null,traces:n,onActivity:r},i,s){return(0,o.useMemo)(()=>{let o=t?s(e,t,{traces:n}):i(e,{traces:n});return r?a(o,r):o},[e,t,n,r,i,s])}export{f as n,p as t};
@@ -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,s as i,u as a}from"./browser-transport-BCwSLVJv.js";import{n as o,t as s}from"./labels-provider-uONlWExD.js";import{a as c,t as l}from"./Banner-BLNhepw5.js";import{l as u,u as d}from"./tool-schema-C7lMQU0w.js";import{c as f}from"./reader-DAdKx3ZF.js";import{p,u as m}from"./tree-BpAzPK_j.js";import{S as h,a as g,f as _,h as v,i as y,o as b,p as x,r as S,s as C,t as w,v as T,x as E}from"./ConsoleFrame-CPxgSITW.js";import{t as D}from"./studio-console-BD3mlhyS.js";import{i as O,t as k}from"./use-one-call-DS5qaoqY.js";import{t as A}from"./SchemaFields-DuwdKRO9.js";import{_ as j,b as M,d as ee,dt as te,mt as N,pt as P,y as F}from"./index-DxaSpTtM.js";var I=(e,t,n,r,i)=>e.decide(n,t,r,i);function L(e){let{iface:t,describeFailure:n}=j(e),{call:r,...i}=k(e,`deciding`,I);return{iface:t,describeFailure:n,...i,decide:r}}var R=e(n(),1),z=t();function B(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 V(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 H(e){return e.failure||e.result?`settled`:e.status===`deciding`?`waiting`:`idle`}function U(e,t){let[n,r]=(0,R.useState)(e),i=B(n,t),[a,o]=(0,R.useState)(()=>i.state===void 0?`json`:`fields`);return{text:n,setText:r,check:i,shown:i.state===void 0?`json`:a,setView:o}}function W(e){let[t,n]=(0,R.useState)(()=>e?d(e):{});return{schema:e,input:t,setInput:n,missing:e?u(e,t):[]}}function G({form:e,built:t,iface:n,images:r,onImages:i,note:a,isReady:s,isRunning:c,onRun:l,onStop:u}){let d=o(),{text:f,setText:p,check:m,shown:g,setView:C}=e,w=n.questions.some(e=>e.type===`box`)||Object.keys(r).length>0,E=g===`fields`?m.state:void 0,D=h(E);return(0,z.jsxs)(y,{title:d(`@theorem.decision.state`),view:g,hasFields:m.state!==void 0,onView:C,onRun:l,children:[t.schema?(0,z.jsx)(A,{schema:t.schema,value:t.input,onChange:t.setInput}):null,E===void 0?(0,z.jsx)(S,{label:d(`@theorem.decision.state`),text:f,isInvalid:!m.ok,onChange:p}):(0,z.jsx)(x,{value:{images:r,onImages:i},children:(0,z.jsx)(_,{label:d(`@theorem.decision.state`),value:E,onChange:e=>{p(JSON.stringify(e,null,2))}})}),w&&D?(0,z.jsx)(v,{onImages:e=>{let t=T(e,{images:r,host:n.images,state:D});i(t.images),p(JSON.stringify(t.state,null,2))}}):null,(0,z.jsx)(b,{note:a,isReady:s,isRunning:c,runLabel:d(`@theorem.decision.decide`),runningLabel:d(`@theorem.decision.deciding`),stopLabel:d(`@theorem.decision.stop`),onRun:l,onStop:u})]})}function K({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=o(),s=t.status===`deciding`;return(0,z.jsxs)(z.Fragment,{children:[t.failure?(0,z.jsx)(l,{status:`error`,role:`alert`,title:t.failure.error}):null,s&&!t.result?(0,z.jsx)(M,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,z.jsx)(O,{iface:t.result.questions?{...e,questions:t.result.questions}:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:s}):null]})}function q(e,t,n,r,i){if(t===`idle`)return null;if(!e)return i;let a=t===`waiting`;return(0,z.jsx)(g,{label:n.answers,fill:a,children:a?(0,z.jsx)(M,{label:n.deciding,since:r}):i})}function J({transport:e,iface:t,decision:n,defaultState:r=`{}`,defaultImages:i,onQuestion:a,questionText:s,maxWidth:l=`960px`,trace:u,flush:d,columns:f=!1,className:p,style:m}){let h=o(),g=C(),_=U(r,t.maxStateBytes),v=W(t.build?.input),{check:y}=_,[b,x]=(0,R.useState)(i??{}),[S,T]=(0,R.useState)(),D=c(t,e.traces,u);return(0,z.jsxs)(w,{inspector:D,maxWidth:l,flush:d,columns:f,requestLabel:h(`@theorem.decision.state`),className:p,style:m,children:[(0,z.jsx)(G,{form:_,built:v,iface:t,images:b,onImages:x,note:v.missing.length>0?h(`@theorem.host.missing`,{fields:v.missing.join(`, `)}):V(h,y,t.maxStateBytes,g),isReady:y.ok&&v.missing.length===0,isRunning:n.status===`deciding`,onRun:()=>{if(!y.ok||v.missing.length>0)return;let e=E(b,y.state);T({images:{...t.images,...e},state:y.state}),n.decide(y.state,Object.keys(e).length>0?e:void 0,v.schema?v.input:void 0)},onStop:n.cancel}),q(f,H(n),{answers:h(`@theorem.decision.answers`),deciding:h(`@theorem.decision.deciding`)},n.startedAt,(0,z.jsx)(K,{iface:t,decision:n,asked:S,onQuestion:a,questionText:s}))]})}function Y(e){let t=o(),n=L(e.transport);return n.describeFailure?(0,z.jsx)(F,{title:n.describeFailure.error}):n.iface?(0,z.jsx)(J,{...e,iface:n.iface,decision:n}):(0,z.jsx)(M,{label:t(`@theorem.chat.loading`)})}function X({endpoint:e,http:t,transport:n,theme:r,mode:a,labels:o,...c}){let l=(0,R.useRef)(t);l.current=t;let u=(0,R.useMemo)(()=>n??f({...l.current,endpoint:e}),[n,e]);return(0,z.jsx)(i,{theme:r,mode:a,children:(0,z.jsx)(s,{labels:o,children:(0,z.jsx)(Y,{...c,transport:u})})})}var Z;function ne(e){if(e.agentId===`pantry.jev`)return Z??=N(),{defaultState:te,defaultImages:{...(0,R.use)(Z)}};if(e.agentId===`research.pagereader`)return{defaultState:P};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?p:m}}function Q(e){return typeof e==`string`?e:Array.isArray(e)?e.map(Q).join(` `):Object.entries(e).map(([e,t])=>`${e}: ${Q(t)}`).join(` `)}function re(e){let t=D(e,a,r);return(0,z.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let{open:o}=(0,R.useContext)(ee),s=ne(e),{questions:c}=e,l=(0,R.useMemo)(()=>c&&Object.fromEntries(Object.entries(c).map(([e,t])=>[e,Q(t.instructions)])),[c]);return(0,z.jsx)(X,{transport:t,...s,trace:n,flush:r,columns:i,className:a,onQuestion:o,questionText:l})}export{$ as DecisionView,re 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,s as i,u as a}from"./browser-transport-BRjXq2Qp.js";import{n as o,t as s}from"./labels-provider-uONlWExD.js";import{a as c,t as l}from"./Banner-DdKVQVIA.js";import{l as u,u as d}from"./tool-schema-BHHcOFff.js";import{c as f}from"./reader-Ql1nrrAA.js";import{p,u as m}from"./tree-DveW6zCH.js";import{S as h,a as g,f as _,h as v,i as y,o as b,p as x,r as S,s as C,t as w,v as T,x as E}from"./ConsoleFrame-CXVxrOXS.js";import{t as D}from"./studio-console-C0F2FDl3.js";import{i as O,t as k}from"./use-one-call-CJYjKc3D.js";import{t as A}from"./SchemaFields-bnMsWJjR.js";import{_ as j,b as M,d as ee,dt as te,mt as N,pt as P,y as F}from"./index-CCj0zkrC.js";var I=(e,t,n,r,i)=>e.decide(n,t,r,i);function L(e){let{iface:t,describeFailure:n}=j(e),{call:r,...i}=k(e,`deciding`,I);return{iface:t,describeFailure:n,...i,decide:r}}var R=e(n(),1),z=t();function B(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 V(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 H(e){return e.failure||e.result?`settled`:e.status===`deciding`?`waiting`:`idle`}function U(e,t){let[n,r]=(0,R.useState)(e),i=B(n,t),[a,o]=(0,R.useState)(()=>i.state===void 0?`json`:`fields`);return{text:n,setText:r,check:i,shown:i.state===void 0?`json`:a,setView:o}}function W(e){let[t,n]=(0,R.useState)(()=>e?d(e):{});return{schema:e,input:t,setInput:n,missing:e?u(e,t):[]}}function G({form:e,built:t,iface:n,images:r,onImages:i,note:a,isReady:s,isRunning:c,onRun:l,onStop:u}){let d=o(),{text:f,setText:p,check:m,shown:g,setView:C}=e,w=n.questions.some(e=>e.type===`box`)||Object.keys(r).length>0,E=g===`fields`?m.state:void 0,D=h(E);return(0,z.jsxs)(y,{title:d(`@theorem.decision.state`),view:g,hasFields:m.state!==void 0,onView:C,onRun:l,children:[t.schema?(0,z.jsx)(A,{schema:t.schema,value:t.input,onChange:t.setInput}):null,E===void 0?(0,z.jsx)(S,{label:d(`@theorem.decision.state`),text:f,isInvalid:!m.ok,onChange:p}):(0,z.jsx)(x,{value:{images:r,onImages:i},children:(0,z.jsx)(_,{label:d(`@theorem.decision.state`),value:E,onChange:e=>{p(JSON.stringify(e,null,2))}})}),w&&D?(0,z.jsx)(v,{onImages:e=>{let t=T(e,{images:r,host:n.images,state:D});i(t.images),p(JSON.stringify(t.state,null,2))}}):null,(0,z.jsx)(b,{note:a,isReady:s,isRunning:c,runLabel:d(`@theorem.decision.decide`),runningLabel:d(`@theorem.decision.deciding`),stopLabel:d(`@theorem.decision.stop`),onRun:l,onStop:u})]})}function K({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=o(),s=t.status===`deciding`;return(0,z.jsxs)(z.Fragment,{children:[t.failure?(0,z.jsx)(l,{status:`error`,role:`alert`,title:t.failure.error}):null,s&&!t.result?(0,z.jsx)(M,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,z.jsx)(O,{iface:t.result.questions?{...e,questions:t.result.questions}:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:s}):null]})}function q(e,t,n,r,i){if(t===`idle`)return null;if(!e)return i;let a=t===`waiting`;return(0,z.jsx)(g,{label:n.answers,fill:a,children:a?(0,z.jsx)(M,{label:n.deciding,since:r}):i})}function J({transport:e,iface:t,decision:n,defaultState:r=`{}`,defaultImages:i,onQuestion:a,questionText:s,maxWidth:l=`960px`,trace:u,flush:d,columns:f=!1,className:p,style:m}){let h=o(),g=C(),_=U(r,t.maxStateBytes),v=W(t.build?.input),{check:y}=_,[b,x]=(0,R.useState)(i??{}),[S,T]=(0,R.useState)(),D=c(t,e.traces,u);return(0,z.jsxs)(w,{inspector:D,maxWidth:l,flush:d,columns:f,requestLabel:h(`@theorem.decision.state`),className:p,style:m,children:[(0,z.jsx)(G,{form:_,built:v,iface:t,images:b,onImages:x,note:v.missing.length>0?h(`@theorem.host.missing`,{fields:v.missing.join(`, `)}):V(h,y,t.maxStateBytes,g),isReady:y.ok&&v.missing.length===0,isRunning:n.status===`deciding`,onRun:()=>{if(!y.ok||v.missing.length>0)return;let e=E(b,y.state);T({images:{...t.images,...e},state:y.state}),n.decide(y.state,Object.keys(e).length>0?e:void 0,v.schema?v.input:void 0)},onStop:n.cancel}),q(f,H(n),{answers:h(`@theorem.decision.answers`),deciding:h(`@theorem.decision.deciding`)},n.startedAt,(0,z.jsx)(K,{iface:t,decision:n,asked:S,onQuestion:a,questionText:s}))]})}function Y(e){let t=o(),n=L(e.transport);return n.describeFailure?(0,z.jsx)(F,{title:n.describeFailure.error}):n.iface?(0,z.jsx)(J,{...e,iface:n.iface,decision:n}):(0,z.jsx)(M,{label:t(`@theorem.chat.loading`)})}function X({endpoint:e,http:t,transport:n,theme:r,mode:a,labels:o,...c}){let l=(0,R.useRef)(t);l.current=t;let u=(0,R.useMemo)(()=>n??f({...l.current,endpoint:e}),[n,e]);return(0,z.jsx)(i,{theme:r,mode:a,children:(0,z.jsx)(s,{labels:o,children:(0,z.jsx)(Y,{...c,transport:u})})})}var Z;function ne(e){if(e.agentId===`pantry.jev`)return Z??=N(),{defaultState:te,defaultImages:{...(0,R.use)(Z)}};if(e.agentId===`research.pagereader`)return{defaultState:P};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?p:m}}function Q(e){return typeof e==`string`?e:Array.isArray(e)?e.map(Q).join(` `):Object.entries(e).map(([e,t])=>`${e}: ${Q(t)}`).join(` `)}function re(e){let t=D(e,a,r);return(0,z.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let{open:o}=(0,R.useContext)(ee),s=ne(e),{questions:c}=e,l=(0,R.useMemo)(()=>c&&Object.fromEntries(Object.entries(c).map(([e,t])=>[e,Q(t.instructions)])),[c]);return(0,z.jsx)(X,{transport:t,...s,trace:n,flush:r,columns:i,className:a,onQuestion:o,questionText:l})}export{$ as DecisionView,re as StudioDecision};