@theoremjs/studio 0.3.4-next.596.g481e1de → 0.3.4-next.598.gb003e90

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 (34) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{Banner-CHeVMGoC.js → Banner-B_2gi5vH.js} +3 -3
  3. package/page/assets/{ConsoleFrame-Dda6SBPG.js → ConsoleFrame-CEavxV8f.js} +1 -1
  4. package/page/assets/{ContextMenu-C495-aZp.js → ContextMenu-BPGWn4aq.js} +2 -2
  5. package/page/assets/{MenuBottomSheet-aMEz6yoB.js → MenuBottomSheet-B8bZZgjf.js} +1 -1
  6. package/page/assets/{SchemaFields-DcDcvpsG.js → SchemaFields-BVWsFTc6.js} +1 -1
  7. package/page/assets/{ToolResultCharts-aA2wFbId.js → ToolResultCharts-DVVuoOH8.js} +1 -1
  8. package/page/assets/{TraceInspector-5ry_XWrM.js → TraceInspector-DgOd5uwx.js} +1 -1
  9. package/page/assets/{TraceOverview-Bm9BhnMp.js → TraceOverview-Daolem_3.js} +1 -1
  10. package/page/assets/{browser-connection-BIUInCkF.js → browser-connection-CfhefDFM.js} +1 -1
  11. package/page/assets/{browser-engine-DwNilPPx.js → browser-engine-DOETo2NM.js} +1 -1
  12. package/page/assets/{browser-transport-D1j81h5x.js → browser-transport-DwKQIgk5.js} +3 -3
  13. package/page/assets/{export-agent-DAaryvB-.js → export-agent-DwnIwJFq.js} +1 -1
  14. package/page/assets/{guardrail-tester-DlyBh4uQ.js → guardrail-tester-Bu0YJX9s.js} +1 -1
  15. package/page/assets/{index-CTD7Bm4u.js → index-BK6Cf7vm.js} +7 -7
  16. package/page/assets/{live-messages-DNJY4_6_.js → live-messages-CVmXXeLQ.js} +1 -1
  17. package/page/assets/{reader-DhxMA39i.js → reader-CJEp4m2A.js} +1 -1
  18. package/page/assets/{stub-CWWsL_k2.js → stub-Z-Vm8Sv8.js} +1 -1
  19. package/page/assets/{studio-code-pane-DVvvv8F_.js → studio-code-pane-BDV47nwZ.js} +1 -1
  20. package/page/assets/{studio-console-Bgo9j6-O.js → studio-console-C3uZUuqy.js} +1 -1
  21. package/page/assets/{studio-decision-DMAwsopk.js → studio-decision-BOnqIS6C.js} +1 -1
  22. package/page/assets/{studio-embedding-DDPNL0_7.js → studio-embedding-B89jIyAy.js} +1 -1
  23. package/page/assets/{studio-host-console-CSY1Fe84.js → studio-host-console-CPYsftTx.js} +2 -2
  24. package/page/assets/{studio-labels-TTCu8mYo.js → studio-labels-D1QhaZ40.js} +1 -1
  25. package/page/assets/{studio-live-fMKQMfJP.js → studio-live-DFLAIpSa.js} +1 -1
  26. package/page/assets/{studio-map-abMXWAJe.js → studio-map-DFIoea5d.js} +1 -1
  27. package/page/assets/{studio-trace-replay-CF0qyy1C.js → studio-trace-replay-BFtV9j-3.js} +1 -1
  28. package/page/assets/{tool-schema-CSmvha7v.js → tool-schema-CWSpXHJV.js} +6 -6
  29. package/page/assets/{tree-OCi2Y2Hk.js → tree-BTHpYpj5.js} +1 -1
  30. package/page/assets/{turn-client-d6laDQzK.js → turn-client-DzIqP2qE.js} +1 -1
  31. package/page/assets/{use-one-call-9B17zBP3.js → use-one-call-BJxTAI48.js} +1 -1
  32. package/page/assets/{use-second-ticker-Csf4IJNZ.js → use-second-ticker-B9Dklglz.js} +1 -1
  33. package/page/assets/{workspace-BLQkQuMh.js → workspace-DT7jMw84.js} +1 -1
  34. package/page/index.html +13 -13
@@ -1 +1 @@
1
- import{E as e,g as t,l as n,o as r,p as i,v as a,w as o,x as s,y as c}from"./schemas-BQ9Jydzb.js";import{Bn as l,Nn as u,Tr as d,Un as f}from"./tool-schema-CSmvha7v.js";import{A as p,C as m,j as h}from"./reader-DhxMA39i.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{C as _}from"./turn-client-d6laDQzK.js";var v=c({type:t(`open`),history:n(f).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:d,awayMs:a().nonnegative()}).optional(),host:s(o(),e()).optional()}),y=i(`type`,[c({type:t(`audio`),data:o()}),c({type:t(`video`),data:o(),mimeType:o()}),c({type:t(`text`),text:o()}),c({type:t(`context`),context:e()}),c({type:t(`executeTool`),callId:o().min(1),operationId:o().min(1).max(256),decision:r(_).optional(),input:e().optional(),secret:o().optional(),output:e().optional(),grantId:o().min(1).optional(),unanswered:t(!0).optional()})]),b={ready:c({type:t(`ready`),profile:o().optional(),sessionId:o().optional()}),events:c({type:t(`events`),events:n(e())}),trace:c({type:t(`trace`),record:g}),error:c({type:t(`error`)}).and(m),executeToolResult:i(`status`,[c({type:t(`executeToolResult`),callId:o().min(1),operationId:o().min(1).max(256),status:t(`dispatched`),grantId:o().min(1),arguments:s(o(),e())}),c({type:t(`executeToolResult`),callId:o(),status:t(`settled`),operationId:o().min(1).max(256)}),c({type:t(`executeToolResult`),callId:o(),status:t(`gated`),operationId:o().min(1).max(256),gate:l}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=p(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>h(u,e))}:t}export{v as n,x as r,y as t};
1
+ import{E as e,g as t,l as n,o as r,p as i,v as a,w as o,x as s,y as c}from"./schemas-BQ9Jydzb.js";import{Bn as l,Nn as u,Tr as d,Un as f}from"./tool-schema-CWSpXHJV.js";import{A as p,C as m,j as h}from"./reader-CJEp4m2A.js";import{n as g}from"./trace-schema-9CdEyG6Q.js";import{C as _}from"./turn-client-DzIqP2qE.js";var v=c({type:t(`open`),history:n(f).optional(),slots:s(o(),o()).optional(),context:e().optional(),resume:c({providerState:d,awayMs:a().nonnegative()}).optional(),host:s(o(),e()).optional()}),y=i(`type`,[c({type:t(`audio`),data:o()}),c({type:t(`video`),data:o(),mimeType:o()}),c({type:t(`text`),text:o()}),c({type:t(`context`),context:e()}),c({type:t(`executeTool`),callId:o().min(1),operationId:o().min(1).max(256),decision:r(_).optional(),input:e().optional(),secret:o().optional(),output:e().optional(),grantId:o().min(1).optional(),unanswered:t(!0).optional()})]),b={ready:c({type:t(`ready`),profile:o().optional(),sessionId:o().optional()}),events:c({type:t(`events`),events:n(e())}),trace:c({type:t(`trace`),record:g}),error:c({type:t(`error`)}).and(m),executeToolResult:i(`status`,[c({type:t(`executeToolResult`),callId:o().min(1),operationId:o().min(1).max(256),status:t(`dispatched`),grantId:o().min(1),arguments:s(o(),e())}),c({type:t(`executeToolResult`),callId:o(),status:t(`settled`),operationId:o().min(1).max(256)}),c({type:t(`executeToolResult`),callId:o(),status:t(`gated`),operationId:o().min(1).max(256),gate:l}),c({type:t(`executeToolResult`),callId:o(),status:t(`refused`),operationId:o().min(1).max(256),body:m})])};function x(e){let t=p(b,e);return t.type===`events`?{type:`events`,events:t.events.map(e=>h(u,e))}:t}export{v as n,x as r,y as t};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,E as n,T as r,b as i,d as a,f as o,g as s,l as c,m as l,o as u,p as d,s as f,v as p,w as m,x as h,y as g}from"./schemas-BQ9Jydzb.js";import{Ar as _,Gn as v,Hn as y,Jn as b,Jt as x,Nn as S,Pn as ee,Pr as te,Rn as C,U as w,Un as T,Vt as E,X as D,Xn as O,Yn as k,Yt as ne,_n as re,cr as ie,er as ae,fr as oe,gn as A,gr as se,jr as ce,kr as le,lr as ue,mn as j,nr as de,or as fe,pn as pe,qn as me,s as he,sr as ge,tr as _e,vn as ve,yn as ye,yt as be}from"./tool-schema-CSmvha7v.js";import{c as M}from"./host-patterns-F-KZIzkF.js";import{A as xe,B as Se,Bt as Ce,En as we,Et as Te,F as Ee,Ft as De,Gt as Oe,Ht as ke,I as Ae,In as je,It as Me,L as Ne,Ln as Pe,Lt as Fe,M as Ie,Mn as Le,Mt as Re,N as ze,Nt as Be,On as Ve,P as He,Q as Ue,Qt as We,Rn as Ge,Rt as Ke,Sn as qe,St as Je,Un as N,Ut as Ye,Vn as Xe,Vt as Ze,W as Qe,Wt as $e,X as et,bt as tt,et as nt,ft as rt,gn as it,hn as at,it as ot,jn as st,jt as ct,mt as P,nt as lt,qt as ut,rn as dt,rt as ft,tt as pt,ut as mt,wt as ht,xn as gt,zn as _t,zt as vt}from"./shaped-data-BO6EAfYh.js";import{F as yt,H as bt,I as xt,K as St,O as Ct,P as wt,R as Tt,U as Et,V as Dt,X as Ot,Y as kt,Z as At,_ as jt,b as Mt,f as Nt,h as Pt,k as Ft,l as It,u as Lt,y as Rt}from"./browser-connection-BIUInCkF.js";import{a as zt}from"./live-ingress-OuSlQ6q7.js";import{n as Bt,t as Vt}from"./trace-schema-9CdEyG6Q.js";import{n as Ht}from"./stub-CWWsL_k2.js";function Ut(e){return{type:`guardrail`,guardrail:e}}function Wt(e,t,n,r=`redact`,i){if(n.length!==0)return Ut({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Gt(e,t){return e.type===`guardrail`?{...e,guardrail:it(e.guardrail,t)}:e}var Kt=65536;function F(e){let t=e.classStarts.length,n=new Uint16Array(Kt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Kt);let r=e.charsets.map(e=>{let n=new Uint8Array(t);for(let t of e)n[t]=1;return n}),i=e.nodes.length,a=new Int32Array(i),o=new Uint8Array(i),s=[];return e.nodes.forEach((e,t)=>{a[t]=e[0],o[t]=e[1],s.push(Int32Array.from(e.slice(2)))}),{classOf:n,has:r,pattern:a,final:o,edges:s,initials:e.initials,leads:e.leads,size:i}}var qt,I,Jt;async function Yt(){if(qt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);qt={forward:t,reversed:n}}function Xt(){if(!qt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return qt}var L;function Zt(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 Qt(e){if(!L){L=new Map;for(let e=0;e<Kt;e++){let t=Zt(e),n=L.get(t);n?n.push(e):L.set(t,[e])}}return L.get(Zt(e))??[e]}function $t(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Kt&&t.push(n+1);return t}var R=new Map;function en(e){let t=R.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>Qt(e.charCodeAt(n))),r=$t([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=F({classStarts:r,charsets:n.map(e=>e.map(i)),initials:[0],leads:[-1],nodes:[...n.map((e,t)=>[0,0,t+1,t]),[0,1]]});return R.set(e,a),a}function tn(e){let t=JSON.stringify(e),n=R.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=$t(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=F({classStarts:i,charsets:a,initials:e.map((e,t)=>{let n=o.length;for(let n=0;n<e.length;n++)o.push([t,0,o.length+1,r.indexOf(e.charCodeAt(n))]);return o.push([t,1]),n}),leads:e.map(()=>-1),nodes:o});return R.set(t,s),s}function nn(e,t){let n=e.has[0]?.length??0,r=Array.from({length:n},()=>[]);for(let i of t){let t=e.edges[e.initials[i]];for(let i=0;i<t.length;i+=2){let a=e.has[t[i+1]];for(let e=0;e<n;e++)a[e]&&r[e]?.push(t[i])}}return r.map(e=>Int32Array.from(e))}function rn(e,t){e.text+=t,e.fresh+=t}function an(e){return e.text.length-e.fresh.length}function z(e,t){let n=an(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function on(e,t,n=e.text.length){let r=an(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function sn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function cn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,rn(n,t(on(e,n.text.length)))}};return n}var ln=/\w/,un=Math.max(...Fe.map(e=>e.length));function dn(e){return e.length<=un+1&&/^[A-Za-z]*$/.test(e)}function fn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{rn(o,e);for(let r=0;r<e.length;r++)i.push(t+Math.min(r,n-1))},o={text:``,fresh:``,rawAt:r=>e.rawAt(r<i.length?i[r]:t-(n?.length??0)),update(){o.fresh=``;for(let i=e.text.length;t<i;t++){let i=String.fromCharCode(z(e,t)),o=ln.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Ze(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!dn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function pn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function B(e,t,n){rn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var mn=55296,hn=56319,gn=/[A-Za-z]/,_n=56320,vn=57343;function yn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=pn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(gn.test(e)||B(c,`\\`,s),s=-1),e===`\\`?s=t:B(c,e,t)}function u(e,t){if(ke(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!gn.test(e))for(let e=0;e<i.length;e++)l(i[e],a[e]);i=``,a=[]}for(let n=0;n<e.length;n++)l(e[n],t);o=gn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=mn&&t<=hn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=_n&&a<=vn?2:1;u(n.slice(e,e+o),r[e]),e+=o}n=n.slice(e),r=r.slice(e)}return c.update=()=>{c.fresh=``;let i=e.text.length;for(;t<i;){let a=z(e,t),o=a>=mn&&a<=hn;if(o&&t+1>=i)break;let s=z(e,t+1),c=o&&s>=_n&&s<=vn?2:1,l=Ye(on(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var bn=/[0-9A-Fa-f]/;function xn(e){let t=0,n=-1,r=pn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(z(e,t));if(n<0){a===`%`?n=t:(B(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:bn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)B(r,String.fromCharCode(z(e,n)),n)}}};function i(t){t>n&&B(r,Ke(on(e,n,t)),n),n=-1}return r}var Sn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Cn=new Map(Me.map(({pattern:e,hit:t})=>[e,t])),wn=new Map(pt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function V(e){return{rule:gt(e),severity:`high`,detector:e}}var Tn=V(`injection`),En=V(`marker_leak`),Dn=V(`tool_leak`);function On({kind:e,group:t}){if(Sn.has(e))return Tn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:V(t);case`boundary`:return En;case`image`:return V(`ungiven_images`);default:return V(`ungiven_links`)}}function kn(e,t,n){if(e===`card`)return{hit:lt};if(e===`image`||e===`link`){let r=(e===`image`?ft:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Cn.get(t)??wn.get(t);return r?{hit:r}:{}}function An(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:mt(i(n?.ungiven_images)),link:rt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return Ue.forEach((t,n)=>{let r=On(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Oe(t.pattern),...kn(t.kind,t.pattern,a)})}),o}function jn(){let e=[];return Ue.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Cn.get(n);e.push({...Tn,id:r,regex:Oe(n),...i?{hit:i}:{}})}),e}function Mn(){return $e.map((e,t)=>({...Tn,id:t,regex:new RegExp(e.source,e.flags)}))}function Nn(e,t,n){let r=nn(t,n.map(e=>e.id)),i=new Int32Array(t.initials.length).fill(-1);n.forEach((e,t)=>{i[e.id]=t});let a=new Int32Array(t.size),o=new Int32Array(t.size),s=new Int32Array(t.size),c=new Int32Array(t.size),l=0,u=new Int32Array(t.size),d=new Int32Array(t.size),f=0,p=0,m=new Uint8Array(n.length),h=new Uint8Array(n.length),g=new Int32Array(n.length),_=new Int32Array(n.length),v=new Uint8Array(n.length),y=Uint8Array.from(n,e=>+!!e.find),b=new Int32Array(n.length).fill(-1),x=new Int32Array(n.length).fill(-1),S=Int32Array.from(n,e=>t.leads[e.id]??-1),ee=[...new Set(S)].filter(e=>e>=0),te=n.flatMap((e,t)=>S[t]<0?[]:[t]),C=new Int32Array(t.has.length).fill(-1);function w(){let{text:n,fresh:h}=e,g=an(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function k(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function ne(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):k(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=ne();e;e=ne())t.push(e);return e.rawAt(n)}}}var Pn=new WeakMap;function Fn(e){let t=Pn.get(e);return t||(t=F(e),Pn.set(e,t)),t}function In(e={}){let t={text:``,fresh:``},n=sn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Nn(e,t,n)),a=[],o=e.detect??[],s=An(o,e);if(s.length>0&&(I??=F(Xt().forward),a.push(i(n,I,s))),o.includes(`injection`)){I??=F(Xt().forward),Jt??=F(Xt().reversed);let e=yn(t),r=jn();a.push(i(n,Jt,Mn()),i(fn(n),I,r),i(e,I,r),i(fn(e),I,r),i(cn(n,Ce),I,r),i(cn(n,e=>vt(e)??e),I,r),i(xn(t),I,r))}if(o.includes(`marker_leak`)&&e.note){let t=nt(e.note);a.push(i(n,en(e.note),[{...En,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=Qe(e.tools),r=t.map(({regex:e},t)=>({...Dn,id:t,regex:e}));t.length>0&&a.push(i(n,tn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...V(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Fn(r.automaton),e))}let c=0;return{push(e){t.text+=e,t.fresh=e;for(let e of r)e.update();let n=[],i=t.text.length;for(let e of a)i=Math.min(i,e.run(n));return c=i,n},holdFrom:()=>c}}function Ln(e,t,n={},r=[]){let i=Ee(e,t).filter(e=>!(Ne(e)||r.includes(e))),a=Ae(e,t);if(i.length===0&&a.length===0)return;let o=[...i,...a.map(({id:e})=>e)],s=t.sources??{},c=[...i.map(e=>({detector:e,...s[e]})),...a.map(({id:e,matchers:t,compiled:n})=>({detector:e,matchers:t,compiled:n}))],l=c.some(({matchers:e,compiled:t})=>e?.length&&!t),u=In({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=He(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Rn(e){let{context:t}=e,n=e.detect,r=n?Ln(n.boundary,n.matrix,n.scope):void 0,i=e=>n?n.matrix[e][n.boundary]:`block`,a=i(`canary_leak`),o=i(`prompt_leak`),s=t.canaryGiven||a===`ignore`?void 0:t.canary,c=o===`ignore`?void 0:t.privateSystem,l=s!==void 0||c!==void 0,u=l?e.carry??``:``,d=[],f=new Set,p=``,m=0,h=``,g=u.slice(-P),_=u,v=0,y=u,b=0,x=0,S=s?Je(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,at]),c){let r=_.length;_+=e;let i=De(_,r);_=_.slice(i),v+=i;let[a]=et(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?T(s):h.length,n=c&&o!==`flag`?E(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function T(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-P),i=r+tt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+tt(y,e)),x=Math.min(i,u.length+p.length-P);let a=Math.max(b,Math.max(t,x)-P);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function E(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+Be(i,e,t)-u.length-m)}function D(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:O(o)});let s=r.take(m,m+o,i);return s.action===`block`||s.action===`redact`&&!n.rewrite?{blocked:!0,hits:s.hits,boundary:n.boundary}:(O(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function O(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-P)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),D(e)):{blocked:!1,emit:``}},flush:()=>D(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?Te(u+p,s,c):``}}function H(e,t,n){return ze(t,e.detect,n)}async function zn(e,t,n,r){return H(e,[n],t)?(await Yt(),Bn(e,t,n,r)):null}function Bn(e,t,n,r){return H(e,[n],t)?Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Se(e,t)},...r?{carry:r}:{}}):null}async function Vn(e,t,n,r){return H(e,[n],r??t)?(await Yt(),Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Se(e,t)}})):null}var Hn=class{open;gate;constructor(e){this.open=e}async read(e){if(this.gate===void 0&&(this.gate=await this.open()),this.gate===`stopped`)return``;if(!this.gate)return e;let t=this.gate.process(e);return t.blocked?(this.gate=`stopped`,``):t.emit}end(){if(!this.gate||this.gate===`stopped`)return``;let e=this.gate.flush();return e.blocked?``:e.emit}},Un=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Wn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Gn={client:`untrusted`,server:`assembled`};function Kn(e){return typeof e==`string`?e:JSON.stringify(e)}function qn(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of k){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Kn(o));let c=s.found(),l=Ie(`context`,c);l&&n.push({...l,trust:Gn[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Jn=/^[A-Za-z0-9._-]+$/;function Yn(e){let t=e?.trim();return t&&Jn.test(t)?t:void 0}function Xn(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 Zn(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 Qn(e,t){let n=t?`: ${t}`:``;return new M(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function $n(e,t){let{detect:n}=ye(t.guardrails),r=we(Un,e=>xe(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=Wn(i.slots,r.slots),c=qn(i.context,()=>xe(`context`,n)),l=Xn(i.repair,r.repair),u=i.history?Zn(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?At(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Un){let t=r[e].found(),n=Ie(e,t);n&&p.push(Ut(n)),t.action===`block`&&(m??=Qn(e,t.errorInternal))}return p.push(...c.events.map(Ut)),c.blocked&&(m??=Qn(`context`)),{request:{...e,system:o,projectId:Yn(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 er(e,t){let{request:n,refusal:r}=$n(e,t);if(r)throw r;return n}function tr(e,t){return[...new Set([...t.filter(t=>j(e,t)),...e.filter(e=>j(t,e))])]}function nr(e,t){let n=e.attachments?t?tr(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 rr(e){let t=ve(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function ir(e,t){let n=Ot(e),r=St({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=>j(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:rr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var ar=`final_answer`;function or(e){return e.structured!==null&&e.tools.wire.length>0}function sr(e,t,n){let{structured:r}=t;if(!r||!or(t))return e;let i={type:`function`,name:ar,description:N(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function cr(e,t){return e.get(t)||{name:t,missing:!0}}function lr(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 ur(e,t){return[...wt(t),...lr(t)].map(t=>cr(e,t))}function dr(e,t){if(Array.isArray(e)){for(let n of e)dr(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),dr(r,t);for(let e of Object.values(r))dr(e,t)}function fr(e,t){let n=ur(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&dr(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function pr(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`${N(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
1
+ import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,E as n,T as r,b as i,d as a,f as o,g as s,l as c,m as l,o as u,p as d,s as f,v as p,w as m,x as h,y as g}from"./schemas-BQ9Jydzb.js";import{Ar as _,Gn as v,Hn as y,Jn as b,Jt as x,Nn as S,Pn as ee,Pr as te,Rn as C,U as w,Un as T,Vt as E,X as D,Xn as O,Yn as k,Yt as ne,_n as re,cr as ie,er as ae,fr as oe,gn as A,gr as se,jr as ce,kr as le,lr as ue,mn as j,nr as de,or as fe,pn as pe,qn as me,s as he,sr as ge,tr as _e,vn as ve,yn as ye,yt as be}from"./tool-schema-CWSpXHJV.js";import{c as M}from"./host-patterns-F-KZIzkF.js";import{A as xe,B as Se,Bt as Ce,En as we,Et as Te,F as Ee,Ft as De,Gt as Oe,Ht as ke,I as Ae,In as je,It as Me,L as Ne,Ln as Pe,Lt as Fe,M as Ie,Mn as Le,Mt as Re,N as ze,Nt as Be,On as Ve,P as He,Q as Ue,Qt as We,Rn as Ge,Rt as Ke,Sn as qe,St as Je,Un as N,Ut as Ye,Vn as Xe,Vt as Ze,W as Qe,Wt as $e,X as et,bt as tt,et as nt,ft as rt,gn as it,hn as at,it as ot,jn as st,jt as ct,mt as P,nt as lt,qt as ut,rn as dt,rt as ft,tt as pt,ut as mt,wt as ht,xn as gt,zn as _t,zt as vt}from"./shaped-data-BO6EAfYh.js";import{F as yt,H as bt,I as xt,K as St,O as Ct,P as wt,R as Tt,U as Et,V as Dt,X as Ot,Y as kt,Z as At,_ as jt,b as Mt,f as Nt,h as Pt,k as Ft,l as It,u as Lt,y as Rt}from"./browser-connection-CfhefDFM.js";import{a as zt}from"./live-ingress-OuSlQ6q7.js";import{n as Bt,t as Vt}from"./trace-schema-9CdEyG6Q.js";import{n as Ht}from"./stub-Z-Vm8Sv8.js";function Ut(e){return{type:`guardrail`,guardrail:e}}function Wt(e,t,n,r=`redact`,i){if(n.length!==0)return Ut({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function Gt(e,t){return e.type===`guardrail`?{...e,guardrail:it(e.guardrail,t)}:e}var Kt=65536;function F(e){let t=e.classStarts.length,n=new Uint16Array(Kt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Kt);let r=e.charsets.map(e=>{let n=new Uint8Array(t);for(let t of e)n[t]=1;return n}),i=e.nodes.length,a=new Int32Array(i),o=new Uint8Array(i),s=[];return e.nodes.forEach((e,t)=>{a[t]=e[0],o[t]=e[1],s.push(Int32Array.from(e.slice(2)))}),{classOf:n,has:r,pattern:a,final:o,edges:s,initials:e.initials,leads:e.leads,size:i}}var qt,I,Jt;async function Yt(){if(qt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);qt={forward:t,reversed:n}}function Xt(){if(!qt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return qt}var L;function Zt(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 Qt(e){if(!L){L=new Map;for(let e=0;e<Kt;e++){let t=Zt(e),n=L.get(t);n?n.push(e):L.set(t,[e])}}return L.get(Zt(e))??[e]}function $t(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Kt&&t.push(n+1);return t}var R=new Map;function en(e){let t=R.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>Qt(e.charCodeAt(n))),r=$t([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=F({classStarts:r,charsets:n.map(e=>e.map(i)),initials:[0],leads:[-1],nodes:[...n.map((e,t)=>[0,0,t+1,t]),[0,1]]});return R.set(e,a),a}function tn(e){let t=JSON.stringify(e),n=R.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=$t(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=F({classStarts:i,charsets:a,initials:e.map((e,t)=>{let n=o.length;for(let n=0;n<e.length;n++)o.push([t,0,o.length+1,r.indexOf(e.charCodeAt(n))]);return o.push([t,1]),n}),leads:e.map(()=>-1),nodes:o});return R.set(t,s),s}function nn(e,t){let n=e.has[0]?.length??0,r=Array.from({length:n},()=>[]);for(let i of t){let t=e.edges[e.initials[i]];for(let i=0;i<t.length;i+=2){let a=e.has[t[i+1]];for(let e=0;e<n;e++)a[e]&&r[e]?.push(t[i])}}return r.map(e=>Int32Array.from(e))}function rn(e,t){e.text+=t,e.fresh+=t}function an(e){return e.text.length-e.fresh.length}function z(e,t){let n=an(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function on(e,t,n=e.text.length){let r=an(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function sn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function cn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,rn(n,t(on(e,n.text.length)))}};return n}var ln=/\w/,un=Math.max(...Fe.map(e=>e.length));function dn(e){return e.length<=un+1&&/^[A-Za-z]*$/.test(e)}function fn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{rn(o,e);for(let r=0;r<e.length;r++)i.push(t+Math.min(r,n-1))},o={text:``,fresh:``,rawAt:r=>e.rawAt(r<i.length?i[r]:t-(n?.length??0)),update(){o.fresh=``;for(let i=e.text.length;t<i;t++){let i=String.fromCharCode(z(e,t)),o=ln.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(Ze(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!dn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function pn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function B(e,t,n){rn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var mn=55296,hn=56319,gn=/[A-Za-z]/,_n=56320,vn=57343;function yn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=pn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(gn.test(e)||B(c,`\\`,s),s=-1),e===`\\`?s=t:B(c,e,t)}function u(e,t){if(ke(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!gn.test(e))for(let e=0;e<i.length;e++)l(i[e],a[e]);i=``,a=[]}for(let n=0;n<e.length;n++)l(e[n],t);o=gn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=mn&&t<=hn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=_n&&a<=vn?2:1;u(n.slice(e,e+o),r[e]),e+=o}n=n.slice(e),r=r.slice(e)}return c.update=()=>{c.fresh=``;let i=e.text.length;for(;t<i;){let a=z(e,t),o=a>=mn&&a<=hn;if(o&&t+1>=i)break;let s=z(e,t+1),c=o&&s>=_n&&s<=vn?2:1,l=Ye(on(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var bn=/[0-9A-Fa-f]/;function xn(e){let t=0,n=-1,r=pn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(z(e,t));if(n<0){a===`%`?n=t:(B(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:bn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)B(r,String.fromCharCode(z(e,n)),n)}}};function i(t){t>n&&B(r,Ke(on(e,n,t)),n),n=-1}return r}var Sn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Cn=new Map(Me.map(({pattern:e,hit:t})=>[e,t])),wn=new Map(pt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function V(e){return{rule:gt(e),severity:`high`,detector:e}}var Tn=V(`injection`),En=V(`marker_leak`),Dn=V(`tool_leak`);function On({kind:e,group:t}){if(Sn.has(e))return Tn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:V(t);case`boundary`:return En;case`image`:return V(`ungiven_images`);default:return V(`ungiven_links`)}}function kn(e,t,n){if(e===`card`)return{hit:lt};if(e===`image`||e===`link`){let r=(e===`image`?ft:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Cn.get(t)??wn.get(t);return r?{hit:r}:{}}function An(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:mt(i(n?.ungiven_images)),link:rt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return Ue.forEach((t,n)=>{let r=On(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Oe(t.pattern),...kn(t.kind,t.pattern,a)})}),o}function jn(){let e=[];return Ue.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Cn.get(n);e.push({...Tn,id:r,regex:Oe(n),...i?{hit:i}:{}})}),e}function Mn(){return $e.map((e,t)=>({...Tn,id:t,regex:new RegExp(e.source,e.flags)}))}function Nn(e,t,n){let r=nn(t,n.map(e=>e.id)),i=new Int32Array(t.initials.length).fill(-1);n.forEach((e,t)=>{i[e.id]=t});let a=new Int32Array(t.size),o=new Int32Array(t.size),s=new Int32Array(t.size),c=new Int32Array(t.size),l=0,u=new Int32Array(t.size),d=new Int32Array(t.size),f=0,p=0,m=new Uint8Array(n.length),h=new Uint8Array(n.length),g=new Int32Array(n.length),_=new Int32Array(n.length),v=new Uint8Array(n.length),y=Uint8Array.from(n,e=>+!!e.find),b=new Int32Array(n.length).fill(-1),x=new Int32Array(n.length).fill(-1),S=Int32Array.from(n,e=>t.leads[e.id]??-1),ee=[...new Set(S)].filter(e=>e>=0),te=n.flatMap((e,t)=>S[t]<0?[]:[t]),C=new Int32Array(t.has.length).fill(-1);function w(){let{text:n,fresh:h}=e,g=an(e),{classOf:_,has:v,edges:te,final:w,pattern:T}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,E=(e,n)=>{if(d[e]===f){let t=u[e];n<c[t]&&(c[t]=n)}else d[e]=f,u[e]=t,s[t]=e,c[t]=n,t++,w[e]&&(m[i[T[e]]]=1)};for(let t=0;t<l;t++){let n=te[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&E(n[t],r)}let D=r[e];for(let e=0;e<D.length;e++){let t=D[e],n=i[T[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;E(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of ee)v[t][e]?C[t]<0&&(C[t]=p):C[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function T(){let n=e.text.length;_.fill(n),v.fill(0);let r=n;for(let e=0;e<l;e++){let n=a[e],s=i[t.pattern[n]],c=o[e];c<_[s]&&(_[s]=c),t.final[n]&&(v[s]=1),c<r&&(r=c)}for(let e of te){let t=C[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function E(t,r){let i=b[t],a=g[t];if(i<0||i>=r){g[t]=r;return}let{find:o,rule:s,severity:c,detector:l}=n[t],u=o?.(e.text,a,r);if(u===void 0)g[t]=r,b[t]=x[t]>=r?r:-1;else return g[t]=Math.max(a,u)+1,{rule:s,severity:c,start:e.rawAt(u),detector:l}}let D={text:``,lower:``},O=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function k(t,r){if(!m[t]&&!h[t]){g[t]=r;return}m[t]=0;let i=e.text,{regex:a,hit:o,rule:s,severity:c,detector:l}=n[t];for(a.lastIndex=g[t];;){let n=a.exec(i);if(!n||n.index>=r){g[t]=r,h[t]=n||v[t]?1:0;return}let[u]=n;if(u&&(!o||o(u,i,n.index,O)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function ne(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?E(e,t):k(e,t);if(r)return r}}return{run(t){w();let n=T();for(let e=ne();e;e=ne())t.push(e);return e.rawAt(n)}}}var Pn=new WeakMap;function Fn(e){let t=Pn.get(e);return t||(t=F(e),Pn.set(e,t)),t}function In(e={}){let t={text:``,fresh:``},n=sn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Nn(e,t,n)),a=[],o=e.detect??[],s=An(o,e);if(s.length>0&&(I??=F(Xt().forward),a.push(i(n,I,s))),o.includes(`injection`)){I??=F(Xt().forward),Jt??=F(Xt().reversed);let e=yn(t),r=jn();a.push(i(n,Jt,Mn()),i(fn(n),I,r),i(e,I,r),i(fn(e),I,r),i(cn(n,Ce),I,r),i(cn(n,e=>vt(e)??e),I,r),i(xn(t),I,r))}if(o.includes(`marker_leak`)&&e.note){let t=nt(e.note);a.push(i(n,en(e.note),[{...En,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=Qe(e.tools),r=t.map(({regex:e},t)=>({...Dn,id:t,regex:e}));t.length>0&&a.push(i(n,tn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...V(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Fn(r.automaton),e))}let c=0;return{push(e){t.text+=e,t.fresh=e;for(let e of r)e.update();let n=[],i=t.text.length;for(let e of a)i=Math.min(i,e.run(n));return c=i,n},holdFrom:()=>c}}function Ln(e,t,n={},r=[]){let i=Ee(e,t).filter(e=>!(Ne(e)||r.includes(e))),a=Ae(e,t);if(i.length===0&&a.length===0)return;let o=[...i,...a.map(({id:e})=>e)],s=t.sources??{},c=[...i.map(e=>({detector:e,...s[e]})),...a.map(({id:e,matchers:t,compiled:n})=>({detector:e,matchers:t,compiled:n}))],l=c.some(({matchers:e,compiled:t})=>e?.length&&!t),u=In({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=He(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Rn(e){let{context:t}=e,n=e.detect,r=n?Ln(n.boundary,n.matrix,n.scope):void 0,i=e=>n?n.matrix[e][n.boundary]:`block`,a=i(`canary_leak`),o=i(`prompt_leak`),s=t.canaryGiven||a===`ignore`?void 0:t.canary,c=o===`ignore`?void 0:t.privateSystem,l=s!==void 0||c!==void 0,u=l?e.carry??``:``,d=[],f=new Set,p=``,m=0,h=``,g=u.slice(-P),_=u,v=0,y=u,b=0,x=0,S=s?Je(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,at]),c){let r=_.length;_+=e;let i=De(_,r);_=_.slice(i),v+=i;let[a]=et(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?T(s):h.length,n=c&&o!==`flag`?E(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function T(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-P),i=r+tt(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+tt(y,e)),x=Math.min(i,u.length+p.length-P);let a=Math.max(b,Math.max(t,x)-P);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function E(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+Be(i,e,t)-u.length-m)}function D(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:O(o)});let s=r.take(m,m+o,i);return s.action===`block`||s.action===`redact`&&!n.rewrite?{blocked:!0,hits:s.hits,boundary:n.boundary}:(O(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function O(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-P)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),D(e)):{blocked:!1,emit:``}},flush:()=>D(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?Te(u+p,s,c):``}}function H(e,t,n){return ze(t,e.detect,n)}async function zn(e,t,n,r){return H(e,[n],t)?(await Yt(),Bn(e,t,n,r)):null}function Bn(e,t,n,r){return H(e,[n],t)?Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Se(e,t)},...r?{carry:r}:{}}):null}async function Vn(e,t,n,r){return H(e,[n],r??t)?(await Yt(),Rn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Se(e,t)}})):null}var Hn=class{open;gate;constructor(e){this.open=e}async read(e){if(this.gate===void 0&&(this.gate=await this.open()),this.gate===`stopped`)return``;if(!this.gate)return e;let t=this.gate.process(e);return t.blocked?(this.gate=`stopped`,``):t.emit}end(){if(!this.gate||this.gate===`stopped`)return``;let e=this.gate.flush();return e.blocked?``:e.emit}},Un=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Wn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Gn={client:`untrusted`,server:`assembled`};function Kn(e){return typeof e==`string`?e:JSON.stringify(e)}function qn(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of k){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Kn(o));let c=s.found(),l=Ie(`context`,c);l&&n.push({...l,trust:Gn[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Jn=/^[A-Za-z0-9._-]+$/;function Yn(e){let t=e?.trim();return t&&Jn.test(t)?t:void 0}function Xn(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 Zn(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 Qn(e,t){let n=t?`: ${t}`:``;return new M(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function $n(e,t){let{detect:n}=ye(t.guardrails),r=we(Un,e=>xe(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=Wn(i.slots,r.slots),c=qn(i.context,()=>xe(`context`,n)),l=Xn(i.repair,r.repair),u=i.history?Zn(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?At(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Un){let t=r[e].found(),n=Ie(e,t);n&&p.push(Ut(n)),t.action===`block`&&(m??=Qn(e,t.errorInternal))}return p.push(...c.events.map(Ut)),c.blocked&&(m??=Qn(`context`)),{request:{...e,system:o,projectId:Yn(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 er(e,t){let{request:n,refusal:r}=$n(e,t);if(r)throw r;return n}function tr(e,t){return[...new Set([...t.filter(t=>j(e,t)),...e.filter(e=>j(t,e))])]}function nr(e,t){let n=e.attachments?t?tr(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 rr(e){let t=ve(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function ir(e,t){let n=Ot(e),r=St({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=>j(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:rr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var ar=`final_answer`;function or(e){return e.structured!==null&&e.tools.wire.length>0}function sr(e,t,n){let{structured:r}=t;if(!r||!or(t))return e;let i={type:`function`,name:ar,description:N(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function cr(e,t){return e.get(t)||{name:t,missing:!0}}function lr(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 ur(e,t){return[...wt(t),...lr(t)].map(t=>cr(e,t))}function dr(e,t){if(Array.isArray(e)){for(let n of e)dr(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),dr(r,t);for(let e of Object.values(r))dr(e,t)}function fr(e,t){let n=ur(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&dr(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function pr(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`${N(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
2
2
  `)}\n\n`}function hr(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||N(`repair.default_guidance`,{},t.labels),a=mr(pr(r),t.labels),o=`${N(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${N(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${N(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${N(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${N(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${N(`repair.section_instructions`,{},t.labels)}\n`,o+=N(`repair.prompt_instructions`,{},t.labels),o}function gr(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function _r(e,t){let n=gr(e,t);if(!(n.length<=1))throw new M(`config`,`Profile ${e.id} declares multiple output wire formats (${n.join(`, `)}). Only one of a structured JSON schema (outputs.structured), image, or speech may be active.`)}function vr(e,t){if(e.type!==`speech`){if(t.speech)throw new M(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new M(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function yr(e,t){return e.type===`speech`?{...e.speech,...br(t.speech)}:void 0}function br(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function xr(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 Sr(e){let t=pe(e);if(!t)throw new M(`input`,`MIME '${e}' is not a supported media input type`);return t}function Cr(e){return e.map(e=>{let t=Sr(e.mimeType),n=ve(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return kt(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function wr(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new M(`request`,`Profile ${e.id} (speech) requires text input`);if(A(e)?.text===!1&&n)throw new M(`request`,`Profile ${e.id} does not accept text input`);let a=r?hr({profile:e,repair:r,history:i}):Er(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Tr(t),...a?[Re(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
3
3
 
4
4
  `)}:null}function Tr(e){let t=e.input?.context??{};return[...k].reverse().filter(e=>t[e]!==void 0).map(e=>ct(e,Kn(t[e])))}function Er(e,t){if(t.continueFrom&&E.includes(e.type)){if(t.input?.text)throw new M(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return N(`continue.instruction`,{},e.labels)}}function Dr(e){return e.type===`image`&&e.image.references?Cr(e.image.references):[]}function Or(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Dr(e),...Cr(n),...Cr(r)]}function kr(e,t){let n=[],r=wr(e,t);return r&&n.push(r),n.push(...Or(e,t)),n}function Ar(e,t){let n=t.input?.slots;if(!n)return;let r=A(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new M(`request`,`Profile ${e.id} has no slot '${t}'`);let a=Ft(n);if(!a.includes(i))throw new M(`request`,`Profile ${e.id}: slot '${t}' takes ${a.join(`, `)}, not '${i}'`)}}function jr(e,t){let n=t.input?.context;if(!n)return;let r=A(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!k.includes(t)||!r?.from.some(e=>e===t))throw new M(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Kn(i).length>r.maxChars)throw new M(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Mr=/\{([A-Za-z_][\w-]*)\}/g;function Nr(e,t,n,r){let i=A(e)?.slots;return i?t.replace(Mr,(t,a)=>{if(!Object.hasOwn(i,a))return t;let o=n&&Object.hasOwn(n,a)?n[a]:void 0;if(o===void 0)throw new M(`request`,`Profile ${e.id}: ${r} uses slot '${a}', and the request chose no value for it`);return o}):t}function Pr(e,t){let{handle:n}=e.identity,r=e.type===`speech`?void 0:e.identity.systemByRole;return t&&r&&Object.hasOwn(r,t)?t:n}function Fr(e,t,n){if(e.type===`speech`)return[];let{systemByRole:r,system:i}=e.identity,a=r?.[t]||i||``;return a?Et(bt(a,`Profile ${e.id} identity.system`,t=>Nr(e,t,n,`identity.system`))):[]}function Ir(e,t){let n=Pr(e,t.input?.role);return Dt([Fr(e,n,t.input?.slots),t.system===void 0?[]:Et(t.system)])}function Lr(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function Rr(e,t){if(Lr(e))return e;throw e.type===`host`?new M(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new M(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new M(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function zr(e,t){if(t){if(!e.allowModelSelect)throw new M(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new M(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function Br(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new M(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new M(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new M(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function Vr(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function Hr(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 Ur(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function Wr(e,t){return e.type===`live`?`live`:`turn`}function Gr(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new M(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=ne(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new M(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new M(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new M(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function Kr(e,t){return H(ye(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function qr(e){let{detect:t}=ye(e.guardrails);return e.type!==`speech`&&dt(t,`canary_leak`)?ht():``}function Jr(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new M(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function Yr(e,t,n){let r=Rr(e.profiles.get(t.profile),`resolveTurn`);Ar(r,t),jr(r,t);let i=er(t,r),a=i.input??{};Gr(r,i);let o=n??zr(r,i.model),s=re(r,o),c=Tt(e.tools,r,i,o),l=c.builtins,u=Hr(r,a.slots);if(_r(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new M(`config`,`Profile ${r.id}: a structured turn answers through '${ar}', so no tool of its own may take that name`);vr(r,i);let d=Jr(r,o,s,i.builtInArgs),f=Wr(r,s);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,stream:Ur(r),thinking:Br(r,s,o,i.effort),summaries:Vr(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:xr(r),speech:yr(r,i),live:r.type===`live`?Kr(r.live,r.guardrails):void 0,input:kr(r,i),canary:qr(r),resolvedSystem:Ir(r,i),host:i.host}}}function Xr(e){return e.type===`image`?e.image:null}function Zr(e,t){let n=Rr(t,`projectProfile`),{identity:r}=n,i=A(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:ur(e,n),inputs:i,outputs:a,image:Xr(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function Qr(e,t){return Zr(e.tools,e.profiles.get(t))}var $r=/^[\x21-\x7E]{1,256}$/;function ei(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 ti(e){return e!==null&&$r.test(e)}async function ni(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=class{value;constructor(e){this.value=e}};function ii(e){return new ri(e)}function ai(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return ii(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(N(`tool.page_timed_out`,{},i)):Error(N(`tool.page_no_answer`,{tool:e},i))}}function oi(e){let t=Lt(e.input,`input`);Nt(t,`input`);let n=Lt(e.output,`output`);Nt(n,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?be(n,r[t]):void 0;if(i)throw new M(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:t,outputSchema:n}}function si(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new M(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function ci(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new M(`config`,`Tool "${e}" auth.queryParam ${r}`)}function li(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new M(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function ui(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new M(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function U(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new M(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function di(e){U(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(U(e.name,`imageLimits.count`,t.count),U(e.name,`imageLimits.bytes`,t.bytes),U(e.name,`imageLimits.totalBytes`,t.totalBytes),ui(e.name,t.timeoutMs))}function fi(e){return It(e.endpoint),si(e.name,e.auth),ci(e.name,e.auth,e.mapping?.queryParams),li(e.name,e.limit),ui(e.name,e.timeoutMs),di(e),{...e,type:`http`,...oi(e)}}function pi(e){return si(e.name,e.auth),ci(e.name,e.auth),di(e),U(e.name,`session.idleMs`,e.session?.idleMs),U(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...oi(e)}}function mi(e){si(e.name,e.auth),ci(e.name,e.auth);let t=e.answeredBy===`page`?ai(e.name):e.handler;if(typeof t!=`function`)throw new M(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...oi(e)}}function hi(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=Rt(e,t,n),i=A(r),a=Pt({type:r.type,...i?{inputs:i}:{}},e),o=oi({...e,input:a,output:jt});return Mt(e,a,o)}return e.type===`http`?fi(e):e.type===`mcp`?pi(e):mi(e)}function gi(e=()=>void 0){let t=new Map,n=ei(),r=e=>t.get(e),i=n=>{let i=hi(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new M(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}var _i=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function vi(e){return e.join(`,`)}function yi(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:vi(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:Ct(e?.slots),context:e?.context}}function bi(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 xi(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=St({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Ot(bi(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Si(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(_i.filter(t=>j(e,t)))??e.find(n):r(_i)}var Ci=g({protocol:m(),provider:m(),apiId:m(),options:h(m(),l()).optional(),keySlot:m().optional(),fallbackKeySlot:m().optional(),efforts:h(m(),u(ue)).optional(),defaultEffort:m().optional(),allowEffortSelect:a().optional(),summaries:a().optional(),maxOutputTokens:p().optional(),temperature:p().optional(),builtInTools:c(m()).optional(),compaction:g({maxTokens:p(),compactAt:p(),previousExchanges:p(),profile:m().optional(),timing:u(b),meter:u(me).optional()}).optional(),limits:g({operationTimeoutMs:p().optional(),connectTimeoutMs:p().optional(),liveStepTimeoutMs:p().optional(),maxWireRecordBytes:p().optional(),maxWireResponseBytes:p().optional(),maxEventBytes:p().optional(),maxStepBytes:p().optional(),maxStepEvents:p().optional(),maxPendingToolCalls:p().optional()}).optional()}),wi=g({structured:r([m(),g({by:m(),map:h(m(),m()),fallback:m()}),f()]).optional(),streaming:g({mode:u(ie).optional(),streamThoughts:a().optional()}).optional()}),Ti=g(we(qe,()=>u(We))),Ei=g(we(ut,()=>Ti)),Di=g({id:m(),label:m(),actions:Ti,names:c(m()),find:a()}),Oi=g({hosts:c(m()),fromTools:a()}),ki=g({quota:g({perDay:p()}).optional(),detect:Ei,patterns:i(u(ut),g({theorem:a(),names:c(m())})).optional(),host:c(Di).optional(),allow:g({ungiven_images:Oi,ungiven_links:Oi}),blockedReply:g({onBlock:u(te),maxRetries:p()})}),Ai=r([a(),g({theorem:a(),host:a()})]),ji=g({record:a(),writeTo:r([s(!1),m()]).optional(),sampleRate:p(),include:g({upstreamLog:a(),outboundWire:a(),evidenceRaw:a(),usage:a(),guardrailDecisions:a(),guardrailMatchPreview:a()}),scrub:g({sensitive:Ai,injection:Ai,canary:Ai}),resource:Vt,retainForDays:p(),rotateAfterMiB:p(),hasOnWriteError:a()}),Mi=g({text:a(),attachments:g({accept:c(m()),acceptAttr:m()}).nullable(),voice:g({accept:c(m())}).nullable(),maxFiles:p().optional(),maxBytes:p().optional(),maxTurnBytes:p().optional(),limitsByMime:h(m(),p()).optional(),slots:h(m(),g({label:m().optional(),choices:c(g({value:m(),description:m().optional()}))})).optional(),context:g({from:c(u(k)),maxChars:p()}).optional()}),Ni=g({allowContinue:c(u(O)).optional(),autoContinue:c(u(O)).optional(),maxContinues:p().optional()}),Pi=g({resumption:Ni.optional()}),Fi=g({allow:c(m()),page:c(m()),t2Loader:m().optional(),parallel:a().optional()}),Ii={providerContinuation:g({history:u([`host`,`stateless`,`provider`]).optional()}).optional(),id:m(),models:h(m(),Ci),defaultModel:m(),allowModelSelect:a().optional(),maxSteps:p().optional(),labels:i(u(_t),m()),guardrails:ki.optional(),observability:ji.optional()},Li=r([m(),c(r([m(),t({private:m().min(1)})])).min(1).readonly()]),Ri=g({handle:m(),system:Li.optional(),systemByRole:h(m(),Li).optional()}),W=d(`type`,[g({...Ii,type:s(`text`),identity:Ri,outputs:wi.optional(),inputs:Mi,tools:Fi,turnBehaviour:g({resumption:Ni.optional(),allowSteering:a().optional(),atStepLimit:u(ge).optional()}).optional(),canStop:s(!0),allowSteering:a()}),g({...Ii,type:s(`image`),identity:Ri,outputs:wi.optional(),image:g({aspectRatio:m().optional(),resolution:m().optional(),mimeType:m().optional(),quality:m().optional(),background:m().optional(),n:p().int().min(1).optional(),seed:p().int().optional(),outputCompression:p().int().min(0).max(100).optional(),references:c(r([g({mimeType:m(),data:m(),name:m().optional()}),g({mimeType:m(),uri:m(),name:m().optional()})])).optional(),includeText:a().optional()}),inputs:Mi,tools:Fi,turnBehaviour:Pi.optional(),canStop:s(!0)}),g({...Ii,type:s(`speech`),identity:g({handle:m()}),outputs:wi.optional(),speech:g({voice:m().optional(),style:m().optional(),speed:p().optional(),format:u(fe).optional()}),inputs:Mi,turnBehaviour:Pi.optional(),canStop:s(!0)}),g({...Ii,type:s(`live`),identity:Ri,inputs:Mi.pick({slots:!0,context:!0}).optional(),live:g({ingress:g({audio:a().optional(),video:a().optional(),text:a().optional()}).optional(),voice:m().optional(),vad:g({activityHandling:u(ae).optional(),startSensitivity:u(de).optional(),endSensitivity:u(_e).optional(),prefixPaddingMs:p().optional(),silenceDurationMs:p().optional()}).optional(),sessionResumption:a().optional(),contextCompression:g({triggerTokens:p().optional(),slidingWindow:g({targetTokens:p().optional()})}).optional(),transcription:g({input:a().optional(),output:a().optional()}).optional()}),tools:Fi.pick({allow:!0,page:!0}),turnBehaviour:g({allowSteering:a().optional()}).optional()})]);function zi(e){let t=ye(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:Bi(t.allow.ungiven_images),ungiven_links:Bi(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function Bi(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function Vi(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function Hi(e){if(!e)return;let t=zt(e);return{record:t.record,writeTo:Vi(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function Ui(e){let{greeting:t,resumed:n,...r}=e??{};return r}function Wi(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=xt(t),r=yt(t);return{allow:[...wt(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 Gi({allow:e,page:t}){return{allow:e,page:t}}function Ki(e,t){let n=yi(e.inputs),r=t?.identity??{handle:e.handle},i=t?zi(t.guardrails):void 0,a=t?Hi(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:Xe(t?.labels)};switch(e.type){case`text`:return W.parse({...s,type:`text`,inputs:n,tools:Wi(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||x(t)});case`image`:return W.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:Wi(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`live`:return W.parse({...s,type:`live`,live:Ui(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:Gi(Wi(e,t))});default:return e.type}}function qi(e,t){let n=Rr(e,`interfaceFromProfile`);return Ki(Zr(t,n),n)}function Ji(e){return o(t=>y.safeParse(e(t)).success)}var Yi=[`running`,`gate`,`complete`,`error`,`cancel`],Xi=o(e=>{let t=y.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 Yi.some(e=>e===n)}),Zi=h(m(),n()),Qi=g({operationId:m().optional(),name:m(),callId:m(),arguments:Zi,draft:m().optional(),reasoning:c(C).optional(),stepId:m().optional(),edited:g({from:Zi,to:Zi}).optional(),activity:m().optional(),activityPast:m().optional(),outputDraft:m().optional(),state:Xi.optional(),startedAt:p().optional(),endedAt:p().optional(),artifacts:c(n())}),$i=g({kind:u(se),native:m().optional()}),G={id:m()},K=d(`kind`,[g({...G,kind:s(`user-text`),text:m()}),g({...G,kind:u([`user-attachment`,`user-voice`]),name:m(),mimeType:m(),sizeBytes:p(),data:m().optional()}),g({...G,kind:s(`thought`),text:m()}),g({...G,kind:s(`text`),text:m()}),g({...G,kind:s(`tool`),tool:Qi}),g({...G,kind:s(`structured`),value:n(),draft:m().optional()}),g({...G,kind:s(`media`),mimeType:m(),data:m().optional(),url:m().optional(),previewUrl:m().optional()}),g({...G,kind:s(`grounding`),grounding:Ji(e=>({type:`grounding`,grounding:e}))}),g({...G,kind:s(`citation`),sources:Ji(e=>({type:`citation`,sources:e})),callId:m().optional()}),g({...G,kind:s(`evidence`),evidence:Ji(e=>({type:`evidence`,evidence:e}))}),g({...G,kind:s(`guardrail`),guardrail:ce}),g({...G,kind:s(`error`),message:m()}),g({...G,kind:s(`turn-done`),stop:$i.optional(),tokens:Ji(e=>({type:`tokens`,tokens:e})).optional(),interactionId:m().optional(),compaction:a().optional(),workedMs:p().optional(),endedAt:p().optional()})]),ea=g({type:m()});function ta(e,t){return Object.hasOwn(e,t)}function na(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=>na(e,n)).join(` | `)}]`}).join(`; `)}function ra(e){return na(e.issues,[])}function ia(e,t){return new M(`bad_response`,`${e} failed its wire check: ${ra(t)}`)}function q(e,t,n){let r=e.safeParse(t);if(!r.success)throw ia(n,r.error);return r.data}function aa(e){return{type:`malformed`,error:new M(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function oa(e,t){let n=ea.safeParse(t);if(!n.success)return aa(`a line without a kind failed its wire check: ${ra(n.error)}`);let{type:r}=n.data;if(!ta(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:aa(`a '${r}' line failed its wire check: ${ra(i.error)}`)}function sa(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function ca(e,t){let n=sa(t);return n?oa(e,n.value):aa(`a line is not JSON`)}function la(e){let t=sa(e);if(!t)throw new M(`bad_response`,`a line is not JSON`);return t.value}var ua=g({name:m(),mimeType:m(),data:m()}),da=g({slots:h(m(),m()).optional(),context:n().optional(),text:m().optional(),attachments:c(ua).optional(),voice:c(ua).optional()}),fa=g({gateKind:u(oe).optional(),sessionPermissions:c(m()).optional(),name:m().optional(),input:n().optional(),snapshot:v.optional(),promoted:c(m()).optional(),model:m().optional(),effort:m().optional()}),J=m().trim().min(1);g({input:da,conversation:m().min(1).optional(),model:m().optional(),effort:m().optional(),turnId:J.optional(),abandon:c(ee).min(1).optional(),replay:fa.pick({sessionPermissions:!0}).optional(),transcript:c(K).optional()});var pa=[`approve`,`deny`],ma=r([t({unanswered:s(!0)}),t({output:n()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);g({gateId:m().min(1),operationId:m().min(1).max(256),decision:u(pa),input:n().optional(),secret:m().optional(),page:ma.optional(),conversation:m().min(1).optional(),turnId:J.optional(),replay:fa.optional()}),g({turnId:J,id:J,inject:c(T).min(1)}),g({turnId:J});var ha=g({type:s(`conversation`),ref:m().min(1),posted:s(!0).optional()}),ga={...S,conversation:ha},_a=g({transcript:c(K),paused:g({events:c(y),blocks:c(K)}).optional()});g({conversation:m().min(1)}),g({conversation:m().min(1),at:p().int().min(-1)}),g({blocks:c(K)});var va=g({conversation:m().min(1),view:_a}),ya=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 ba(e){return e instanceof ya}function xa(e){return e?.trim()||void 0}var Sa=g({error:m().optional(),errorKind:_.optional(),errorCopy:le.optional(),errorInternal:m().optional()}),Ca=Sa;function wa(e,t){let n=xa(e.error),r=xa(e.errorInternal);return new ya(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function Ta(e){return!ba(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function Ea(e,t){let n=ca(e,t);if(n.type===`error`)throw wa(Sa.parse(n),`internal`);return n}function Da(e,t,n){let r=e.split(`
@@ -1,4 +1,4 @@
1
- import{Kn as e,_r as t,i as n,o as r}from"./tool-schema-CSmvha7v.js";var i=e.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=t.filter(e=>e===`audio/*`),o=`{
1
+ import{Kn as e,_r as t,i as n,o as r}from"./tool-schema-CWSpXHJV.js";var i=e.filter(e=>e===`image/*`||e===`application/pdf`||e.startsWith(`text/`)),a=t.filter(e=>e===`audio/*`),o=`{
2
2
  "User-Agent": "TheoremStudio/1.0 (travel demo; +https://github.com/masudl-hub/theoremai)"
3
3
  }`,s=`{
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-BPZzvJmB.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,Ht as a,T as o,Ut as s,Yn as c,k as l,vr as u}from"./tool-schema-CSmvha7v.js";import{En as d,Sn as f,qt as p,sn as m}from"./shaped-data-BO6EAfYh.js";import{J as h,b as g,g as _,h as v,m as y,w as b,x,y as S}from"./tree-OCi2Y2Hk.js";import{r as C}from"./live-ingress-OuSlQ6q7.js";import{n as w,r as T}from"./use-second-ticker-Csf4IJNZ.js";import{n as E}from"./stub-CWWsL_k2.js";import{I as D,M as ee,k as te,r as ne}from"./workspace-BLQkQuMh.js";import{Y as re,g as ie}from"./index-CTD7Bm4u.js";var O=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},ae=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,Ht as a,T as o,Ut as s,Yn as c,k as l,vr as u}from"./tool-schema-CWSpXHJV.js";import{En as d,Sn as f,qt as p,sn as m}from"./shaped-data-BO6EAfYh.js";import{J as h,b as g,g as _,h as v,m as y,w as b,x,y as S}from"./tree-BTHpYpj5.js";import{r as C}from"./live-ingress-OuSlQ6q7.js";import{n as w,r as T}from"./use-second-ticker-B9Dklglz.js";import{n as E}from"./stub-Z-Vm8Sv8.js";import{I as D,M as ee,k as te,r as ne}from"./workspace-DT7jMw84.js";import{Y as re,g as ie}from"./index-BK6Cf7vm.js";var O=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},ae=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{u as t}from"./themeProps-3IqahpCr.js";import{o as n}from"./index-CTD7Bm4u.js";var r=e(t(),1);function i({payload:e,runtime:t=null,traces:i,onActivity:a},o,s){return(0,r.useMemo)(()=>{let r=t?s(e,t,{traces:i}):o(e,{traces:i});return a?n(r,a):r},[e,t,i,a,o,s])}export{i as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{o as n}from"./index-BK6Cf7vm.js";var r=e(t(),1);function i({payload:e,runtime:t=null,traces:i,onActivity:a},o,s){return(0,r.useMemo)(()=>{let r=t?s(e,t,{traces:i}):o(e,{traces:i});return a?n(r,a):r},[e,t,i,a,o,s])}export{i 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{h as r,n as i,s as a}from"./browser-transport-D1j81h5x.js";import{n as o,t as s}from"./labels-provider-C_KY4x6D.js";import{a as c,t as l}from"./Banner-CHeVMGoC.js";import{l as u,u as d}from"./tool-schema-CSmvha7v.js";import{c as f}from"./reader-DhxMA39i.js";import{p,u as m}from"./tree-OCi2Y2Hk.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-Dda6SBPG.js";import{i as D,t as O}from"./use-one-call-9B17zBP3.js";import{t as k}from"./SchemaFields-DcDcvpsG.js";import{Q as A,_ as j,et as M,g as ee,l as te,m as N,tt as P}from"./index-CTD7Bm4u.js";import{t as F}from"./studio-console-Bgo9j6-O.js";var I=(e,t,n,r,i)=>e.decide(n,t,r,i);function L(e){let{iface:t,describeFailure:n}=N(e),{call:r,...i}=O(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)(k,{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)(j,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,z.jsx)(D,{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)(j,{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)(ee,{title:n.describeFailure.error}):n.iface?(0,z.jsx)(J,{...e,iface:n.iface,decision:n}):(0,z.jsx)(j,{label:t(`@theorem.chat.loading`)})}function X({endpoint:e,http:t,transport:n,theme:r,mode:i,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)(a,{theme:r,mode:i,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??=P(),{defaultState:A,defaultImages:{...(0,R.use)(Z)}};if(e.agentId===`research.pagereader`)return{defaultState:M};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=F(e,r,i);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)(te),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{h as r,n as i,s as a}from"./browser-transport-DwKQIgk5.js";import{n as o,t as s}from"./labels-provider-C_KY4x6D.js";import{a as c,t as l}from"./Banner-B_2gi5vH.js";import{l as u,u as d}from"./tool-schema-CWSpXHJV.js";import{c as f}from"./reader-CJEp4m2A.js";import{p,u as m}from"./tree-BTHpYpj5.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-CEavxV8f.js";import{i as D,t as O}from"./use-one-call-BJxTAI48.js";import{t as k}from"./SchemaFields-BVWsFTc6.js";import{Q as A,_ as j,et as M,g as ee,l as te,m as N,tt as P}from"./index-BK6Cf7vm.js";import{t as F}from"./studio-console-C3uZUuqy.js";var I=(e,t,n,r,i)=>e.decide(n,t,r,i);function L(e){let{iface:t,describeFailure:n}=N(e),{call:r,...i}=O(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)(k,{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)(j,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,z.jsx)(D,{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)(j,{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)(ee,{title:n.describeFailure.error}):n.iface?(0,z.jsx)(J,{...e,iface:n.iface,decision:n}):(0,z.jsx)(j,{label:t(`@theorem.chat.loading`)})}function X({endpoint:e,http:t,transport:n,theme:r,mode:i,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)(a,{theme:r,mode:i,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??=P(),{defaultState:A,defaultImages:{...(0,R.use)(Z)}};if(e.agentId===`research.pagereader`)return{defaultState:M};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=F(e,r,i);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)(te),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};