@theoremjs/studio 0.3.5-next.949.gac4d2f6 → 0.3.5-next.951.gc40a24e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/page/assets/{BottomSheet-B8zVqDfP.js → BottomSheet-C23uYni9.js} +1 -1
- package/page/assets/{ConsoleFrame-BOhRGqLO.js → ConsoleFrame-DojYn-Ua.js} +1 -1
- package/page/assets/{ContextMenu-9nNeDBhA.js → ContextMenu-scP4QtAy.js} +2 -2
- package/page/assets/{DateInput-DmbOEX0N.js → DateInput-DPnVtBuk.js} +1 -1
- package/page/assets/{DropdownMenu-BFVXngaF.js → DropdownMenu--j6BmlDw.js} +2 -2
- package/page/assets/{Link-Dn_ij1fs.js → Link-BnF6JNw_.js} +1 -1
- package/page/assets/{MenuBottomSheet-BqrOBEgn.js → MenuBottomSheet-DwZ1A0ZP.js} +1 -1
- package/page/assets/{PowerSearchBottomSheet-L00RNH-m.js → PowerSearchBottomSheet-CtXQOyfT.js} +1 -1
- package/page/assets/{RankedBars-bFJCANly.js → RankedBars-DOBs3j5V.js} +1 -1
- package/page/assets/SchemaFields-GsJdP3wy.js +1 -0
- package/page/assets/{ShapedData-CpV8JtvB.js → ShapedData-DAjQUJgj.js} +1 -1
- package/page/assets/{TokenizerBottomSheet-D3ZEiqhi.js → TokenizerBottomSheet-M_4Fynh0.js} +1 -1
- package/page/assets/{ToolResultCharts-DxqWQi-I.js → ToolResultCharts-DcX0_JRq.js} +1 -1
- package/page/assets/{Toolbar-DpJ2JFRA.js → Toolbar-S-NvSzN4.js} +1 -1
- package/page/assets/{TraceInspector-C7FJQ99S.js → TraceInspector-DnQoUd5L.js} +2 -2
- package/page/assets/{TraceOverview-BboUtz91.js → TraceOverview-nRk6pOxZ.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-CBUZdPY-.js → _virtual_studio-type-sources-BZlYhM7H.js} +11 -4
- package/page/assets/{browser-connection-NCW-dfTz.js → browser-connection-Lruy-qTV.js} +1 -1
- package/page/assets/{browser-engine-CKemqI0o.js → browser-engine-B5LWYMgo.js} +12 -12
- package/page/assets/{browser-transport-QpipKsUw.js → browser-transport-BScpLZDa.js} +2 -2
- package/page/assets/{compile-DYy47zUn.js → compile-Ci6XGHY4.js} +3 -3
- package/page/assets/{export-agent-BRbGY7w2.js → export-agent-BQFIIF1w.js} +1 -1
- package/page/assets/{getRadiusAndStrokeWidthFromDot-DP6c67e5.js → getRadiusAndStrokeWidthFromDot-D8AmY_nJ.js} +1 -1
- package/page/assets/{guardrail-health-DBqYJV8g.js → guardrail-health-BzI8GZot.js} +1 -1
- package/page/assets/{guardrail-tester-CXewtG3Y.js → guardrail-tester-DeAAj-Ww.js} +1 -1
- package/page/assets/{index-C2tuqJ9q.js → index-fyDzED1x.js} +17 -17
- package/page/assets/{json-code-CR8n32p8.js → json-code-UNgQyCLH.js} +1 -1
- package/page/assets/{labels-provider-Bd1FiylS.js → labels-provider-CxUJe6Bn.js} +1 -1
- package/page/assets/{live-messages-DEKiiXOQ.js → live-messages-dgQBMP8j.js} +1 -1
- package/page/assets/{prompt-row-B_VZoc3M.js → prompt-row-Bace3EuD.js} +1 -1
- package/page/assets/{reader-Cnfxvoay.js → reader-DoaMWQWB.js} +2 -2
- package/page/assets/{registry-BcbtHM1-.js → registry-BuJuTraO.js} +1 -1
- package/page/assets/schema-2nKQb1q-.js +3 -0
- package/page/assets/{stub-DiDXlAmt.js → stub-CXS-AHtL.js} +1 -1
- package/page/assets/{studio-code-pane-D-EpbItF.js → studio-code-pane-BWTLV4RT.js} +3 -3
- package/page/assets/{studio-console-DqSSJKpN.js → studio-console-CjqEdyB3.js} +1 -1
- package/page/assets/{studio-decision-DlQBuLYW.js → studio-decision-DmQs0n67.js} +1 -1
- package/page/assets/{studio-embedding-B-KID-dk.js → studio-embedding-_Kx6Nz3-.js} +1 -1
- package/page/assets/{studio-host-console-RDOfJzxy.js → studio-host-console-DG4ViMWJ.js} +2 -2
- package/page/assets/{studio-live-C8AeA6hG.js → studio-live-B7O4qpG_.js} +1 -1
- package/page/assets/{studio-map-DWDoH8yn.js → studio-map-Br_kabfa.js} +1 -1
- package/page/assets/{studio-media-yW3bpLfy.js → studio-media-orN5UNpz.js} +1 -1
- package/page/assets/{studio-trace-replay-UhteO7sa.js → studio-trace-replay-DV2HMKFc.js} +1 -1
- package/page/assets/{studio-type-checker-CoJzuBAo.js → studio-type-checker-vtYkUAwV.js} +1 -1
- package/page/assets/tool-schema-DllL3wqs.js +13 -0
- package/page/assets/tree-I-6ZPGON.js +3 -0
- package/page/assets/{turn-client-CLlwLe77.js → turn-client-RIvnewgM.js} +1 -1
- package/page/assets/{use-one-call-DSqGjDOF.js → use-one-call-DZ3NX8RC.js} +1 -1
- package/page/assets/{useDismissSearchOnTouchDrag-BVRD4D01.js → useDismissSearchOnTouchDrag-CCqPhJ4f.js} +1 -1
- package/page/assets/{workspace-BluAvYVx.js → workspace-BI6bC1mm.js} +1 -1
- package/page/index.html +18 -18
- package/page/assets/SchemaFields-CUYMx5Az.js +0 -1
- package/page/assets/schema-tNBJA-hy.js +0 -3
- package/page/assets/tool-schema-h27oVndM.js +0 -13
- package/page/assets/tree-CUvi9p2d.js +0 -3
|
@@ -1,5 +1,5 @@
|
|
|
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,p as m,u as h,v as g,x as _}from"./schemas-D7cgkv3L.js";import{U as v,X as y,s as b}from"./tool-schema-h27oVndM.js";import{$r as x,Aa as S,Ai as ee,Ba as te,Br as C,Ci as w,Cn as T,En as E,Fa as D,Ft as ne,Gn as O,Gr as re,Ha as ie,Hi as ae,Ia as oe,Ii as se,Ir as ce,Ja as le,Jn as ue,Ka as de,Kn as fe,Kr as pe,La as me,Li as he,Ni as ge,Or as k,Pa as _e,Pr as ve,Qa as ye,Qr as be,Ri as xe,Rr as Se,Si as Ce,Ti as we,Tn as Te,Un as Ee,Ut as De,Vn as Oe,Wn as ke,Wt as Ae,Xn as je,Xr as Me,Yr as Ne,Za as Pe,Zr as Fe,_i as Ie,ai as Le,ar as Re,bi as ze,bn as Be,ca as Ve,ci as He,dr as Ue,ei as We,er as Ge,fi as Ke,fr as qe,ft as Je,ht as Ye,ii as Xe,io as Ze,ji as Qe,ka as $e,ki as et,lo as A,lr as tt,ni as nt,no as rt,oo as it,pa as at,pr as ot,qi as st,qn as ct,qr as lt,ra as ut,ri as dt,rn as ft,ro as pt,si as mt,so as ht,sr as gt,ti as _t,ur as vt,vi as yt,wi as bt,wn as xt,xn as St,xr as Ct,yr as wt,zi as Tt}from"./shaped-data-KV3CIOIt.js";import{c as j}from"./host-patterns-F-KZIzkF.js";import{E as Et,F as Dt,G as Ot,I as kt,L as At,N as jt,O as Mt,U as Nt,W as Pt,b as Ft,k as It,w as Lt,x as Rt,y as zt,z as Bt}from"./schema-tNBJA-hy.js";import{a as Vt}from"./live-ingress-OuSlQ6q7.js";import{n as Ht,t as Ut}from"./trace-schema--4IGmLeE.js";import{n as Wt}from"./stub-DiDXlAmt.js";function Gt(e){return{type:`guardrail`,guardrail:e}}function Kt(e,t,n,r=`redact`,i){if(n.length!==0)return Gt({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function qt(e,t){return e.type===`guardrail`?{...e,guardrail:S(e.guardrail,t)}:e}var Jt=65536;function M(e){let t=e.classStarts.length,n=new Uint16Array(Jt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Jt);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 Yt,N,Xt;async function Zt(){if(Yt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-CFjB39wS.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);Yt={forward:t,reversed:n}}function Qt(){if(!Yt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return Yt}var P;function $t(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 en(e){if(!P){P=new Map;for(let e=0;e<Jt;e++){let t=$t(e),n=P.get(t);n?n.push(e):P.set(t,[e])}}return P.get($t(e))??[e]}function tn(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Jt&&t.push(n+1);return t}var nn=new Map;function rn(e){let t=nn.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>en(e.charCodeAt(n))),r=tn([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=M({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 nn.set(e,a),a}function an(e){let t=JSON.stringify(e),n=nn.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=tn(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=M({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 nn.set(t,s),s}function on(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 F(e,t){let n=cn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function ln(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 un(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function dn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,sn(n,t(ln(e,n.text.length)))}};return n}var fn=/\w/,pn=Math.max(...Fe.map(e=>e.length));function mn(e){return e.length<=pn+1&&/^[A-Za-z]*$/.test(e)}function hn(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(F(e,t)),o=fn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(_t(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!mn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function gn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function I(e,t,n){sn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var _n=55296,vn=56319,yn=/[A-Za-z]/,bn=56320,xn=57343;function Sn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=gn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(yn.test(e)||I(c,`\\`,s),s=-1),e===`\\`?s=t:I(c,e,t)}function u(e,t){if(nt(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!yn.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=yn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=_n&&t<=vn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=bn&&a<=xn?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=F(e,t),o=a>=_n&&a<=vn;if(o&&t+1>=i)break;let s=F(e,t+1),c=o&&s>=bn&&s<=xn?2:1,l=dt(ln(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var Cn=/[0-9A-Fa-f]/;function wn(e){let t=0,n=-1,r=gn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(F(e,t));if(n<0){a===`%`?n=t:(I(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:Cn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)I(r,String.fromCharCode(F(e,n)),n)}}};function i(t){t>n&&I(r,be(ln(e,n,t)),n),n=-1}return r}var Tn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),En=new Map(Me.map(({pattern:e,hit:t})=>[e,t])),Dn=new Map(vt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function L(e){return{rule:_e(e),severity:`high`,detector:e}}var On=L(`injection`),kn=L(`marker_leak`),An=L(`tool_leak`);function jn({kind:e,group:t}){if(Tn.has(e))return On;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:L(t);case`boundary`:return kn;case`image`:return L(`ungiven_images`);default:return L(`ungiven_links`)}}function Mn(e,t,n){if(e===`card`)return{hit:Ue};if(e===`image`||e===`link`){let r=(e===`image`?qe:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=En.get(t)??Dn.get(t);return r?{hit:r}:{}}function Nn(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:wt(i(n?.ungiven_images)),link:Ct(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return gt.forEach((t,n)=>{let r=jn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Le(t.pattern),...Mn(t.kind,t.pattern,a)})}),o}function Pn(){let e=[];return gt.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=En.get(n);e.push({...On,id:r,regex:Le(n),...i?{hit:i}:{}})}),e}function Fn(){return Xe.map((e,t)=>({...On,id:t,regex:new RegExp(e.source,e.flags)}))}function In(e,t,n){let r=on(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:``},ne=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function O(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,ne)))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):O(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 Ln=new WeakMap;function Rn(e){let t=Ln.get(e);return t||(t=M(e),Ln.set(e,t)),t}function zn(e={}){let t={text:``,fresh:``},n=un(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),In(e,t,n)),a=[],o=e.detect??[],s=Nn(o,e);if(s.length>0&&(N??=M(Qt().forward),a.push(i(n,N,s))),o.includes(`injection`)){N??=M(Qt().forward),Xt??=M(Qt().reversed);let e=Sn(t),r=Pn();a.push(i(n,Xt,Fn()),i(hn(n),N,r),i(e,N,r),i(hn(e),N,r),i(dn(n,We),N,r),i(dn(n,e=>x(e)??e),N,r),i(wn(t),N,r))}if(o.includes(`marker_leak`)&&e.note){let t=tt(e.note);a.push(i(n,rn(e.note),[{...kn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=Ge(e.tools),r=t.map(({regex:e},t)=>({...An,id:t,regex:e}));t.length>0&&a.push(i(n,an(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...L(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Rn(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 Bn(e,t,n={},r=[]){let i=fe(e,t).filter(e=>!(ue(e)||r.includes(e))),a=ct(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=zn({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=O(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Vn(e){let{context:t}=e,n=e.detect,r=n?Bn(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(-k),_=u,v=0,y=u,b=0,x=0,S=s?ce(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,$e]),c){let r=_.length;_+=e;let i=Ne(_,r);_=_.slice(i),v+=i;let[a]=Re(_,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 w(){let e=s&&a!==`flag`?E(s):h.length,n=c&&o!==`flag`?D(c,t.canary):h.length;return m+Math.min(e,n)}function T(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 E(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-k),i=r+ve(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+ve(y,e)),x=Math.min(i,u.length+p.length-k);let a=Math.max(b,Math.max(t,x)-k);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function D(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+lt(i,e,t)-u.length-m)}function ne(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(w(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return T({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),T({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(-k)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),ne(e)):{blocked:!1,emit:``}},flush:()=>ne(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?C(u+p,s,c):``}}function R(e,t,n){return ke(t,e.detect,n)}async function Hn(e,t,n,r){return R(e,[n],t)?(await Zt(),Un(e,t,n,r)):null}function Un(e,t,n,r){return R(e,[n],t)?Vn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:je(e,t)},...r?{carry:r}:{}}):null}async function Wn(e,t,n,r){return R(e,[n],r??t)?(await Zt(),Vn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??je(e,t)}})):null}var Gn=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}},Kn=[`user`,`options`,`repair`,`attachment`,`voice`,`history`,`system`];function qn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Jn={client:`untrusted`,server:`assembled`};function Yn(e){return typeof e==`string`?e:JSON.stringify(e)}function Xn(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of bt){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Yn(o));let c=s.found(),l=Ee(`context`,c);l&&n.push({...l,trust:Jn[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Zn=/^[A-Za-z0-9._-]+$/,Qn=/^[A-Za-z0-9._:-]{1,32}$/;function $n(e){if(e===void 0||Qn.test(e))return e;throw new j(`request`,`input.messageId must be 1 to 32 letters, digits, ".", "_", ":" or "-"`)}function er(e){let t=e?.trim();return t&&Zn.test(t)?t:void 0}function tr(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 nr(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 rr(e,t){let n=t?`: ${t}`:``;return new j(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function ir(e,t){let{detect:n}=E(t.guardrails),r=de(Kn,e=>Oe(e,n)),i=e.input??{},a=$n(i.messageId),o=i.text===void 0?void 0:r.user.read(i.text),s=e.system===void 0?void 0:kt(e.system,`TurnRequest.system`,e=>r.system.read(e)),c=qn(i.options,r.options),l=Xn(i.context,()=>Oe(`context`,n)),u=tr(i.repair,r.repair),d=i.history?nr(i.history,r.history):void 0,{attachments:f,voice:p}=i.attachments?.length||i.voice?.length?Ot(t,i.attachments,i.voice,r):i,m=[],h;for(let e of Kn){let t=r[e].found(),n=Ee(e,t);n&&m.push(Gt(n)),t.action===`block`&&(h??=rr(e,t.errorInternal))}return m.push(...l.events.map(Gt)),l.blocked&&(h??=rr(`context`)),{request:{...e,system:s,projectId:er(e.projectId),input:{...i,text:o,...a===void 0?{}:{messageId:a},options:c,...l.context?{context:l.context}:{},repair:u,history:d,attachments:f,voice:p}},events:m,...h?{refusal:h}:{}}}function ar(e,t){let{request:n,refusal:r}=ir(e,t);if(r)throw r;return n}function or(e,t){return[...new Set([...t.filter(t=>St(e,t)),...e.filter(e=>St(t,e))])]}function sr(e,t){let n=e.attachments?t?or(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 cr(e){let t=Te(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function lr(e,t){let n=Pt(e),r=Bt({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=>St(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:cr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var ur=`final_answer`;function dr(e){return e.structured!==null&&e.tools.wire.length>0}function fr(e,t,n){let{structured:r}=t;if(!r||!dr(t))return e;let i={type:`function`,name:ur,description:A(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function pr(e,t){return e.get(t)||{name:t,missing:!0}}function mr(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 hr(e,t){return[...zt(t),...mr(t)].map(t=>pr(e,t))}function z(e,t){if(Array.isArray(e)){for(let n of e)z(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),z(r,t);for(let e of Object.values(r))z(e,t)}function gr(e,t){let n=hr(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&z(Je(e.inputSchema),r);return{names:n.map(({name:e})=>e),params:[...r]}}function _r(e){return!e||e.length===0?[]:e.slice(-4)}function vr(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${A(`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,p as m,u as h,v as g,x as _}from"./schemas-D7cgkv3L.js";import{Y as v,nt as y,s as b}from"./tool-schema-DllL3wqs.js";import{$r as x,Aa as S,Ai as ee,Ba as te,Br as C,Ci as w,Cn as T,En as E,Fa as D,Ft as ne,Gn as O,Gr as re,Ha as ie,Hi as ae,Ia as oe,Ii as se,Ir as ce,Ja as le,Jn as ue,Ka as de,Kn as fe,Kr as pe,La as me,Li as he,Ni as ge,Or as k,Pa as _e,Pr as ve,Qa as ye,Qr as be,Ri as xe,Rr as Se,Si as Ce,Ti as we,Tn as Te,Un as Ee,Ut as De,Vn as Oe,Wn as ke,Wt as Ae,Xn as je,Xr as Me,Yr as Ne,Za as Pe,Zr as Fe,_i as Ie,ai as Le,ar as Re,bi as ze,bn as Be,ca as Ve,ci as He,dr as Ue,ei as We,er as Ge,fi as Ke,fr as qe,ft as Je,ht as Ye,ii as Xe,io as Ze,ji as Qe,ka as $e,ki as et,lo as A,lr as tt,ni as nt,no as rt,oo as it,pa as at,pr as ot,qi as st,qn as ct,qr as lt,ra as ut,ri as dt,rn as ft,ro as pt,si as mt,so as ht,sr as gt,ti as _t,ur as vt,vi as yt,wi as bt,wn as xt,xn as St,xr as Ct,yr as wt,zi as Tt}from"./shaped-data-KV3CIOIt.js";import{c as j}from"./host-patterns-F-KZIzkF.js";import{E as Et,F as Dt,G as Ot,I as kt,L as At,N as jt,O as Mt,U as Nt,b as Pt,k as Ft,q as It,w as Lt,x as Rt,y as zt,z as Bt}from"./schema-2nKQb1q-.js";import{a as Vt}from"./live-ingress-OuSlQ6q7.js";import{n as Ht,t as Ut}from"./trace-schema--4IGmLeE.js";import{n as Wt}from"./stub-CXS-AHtL.js";function Gt(e){return{type:`guardrail`,guardrail:e}}function Kt(e,t,n,r=`redact`,i){if(n.length!==0)return Gt({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function qt(e,t){return e.type===`guardrail`?{...e,guardrail:S(e.guardrail,t)}:e}var Jt=65536;function M(e){let t=e.classStarts.length,n=new Uint16Array(Jt);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??Jt);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 Yt,N,Xt;async function Zt(){if(Yt)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-CFjB39wS.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);Yt={forward:t,reversed:n}}function Qt(){if(!Yt)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return Yt}var P;function $t(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 en(e){if(!P){P=new Map;for(let e=0;e<Jt;e++){let t=$t(e),n=P.get(t);n?n.push(e):P.set(t,[e])}}return P.get($t(e))??[e]}function tn(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<Jt&&t.push(n+1);return t}var nn=new Map;function rn(e){let t=nn.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>en(e.charCodeAt(n))),r=tn([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=M({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 nn.set(e,a),a}function an(e){let t=JSON.stringify(e),n=nn.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=tn(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=M({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 nn.set(t,s),s}function on(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 F(e,t){let n=cn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function ln(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 un(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function dn(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,sn(n,t(ln(e,n.text.length)))}};return n}var fn=/\w/,pn=Math.max(...Fe.map(e=>e.length));function mn(e){return e.length<=pn+1&&/^[A-Za-z]*$/.test(e)}function hn(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(F(e,t)),o=fn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(_t(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!mn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function gn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function I(e,t,n){sn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var _n=55296,vn=56319,yn=/[A-Za-z]/,bn=56320,xn=57343;function Sn(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=gn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(yn.test(e)||I(c,`\\`,s),s=-1),e===`\\`?s=t:I(c,e,t)}function u(e,t){if(nt(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!yn.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=yn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=_n&&t<=vn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=bn&&a<=xn?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=F(e,t),o=a>=_n&&a<=vn;if(o&&t+1>=i)break;let s=F(e,t+1),c=o&&s>=bn&&s<=xn?2:1,l=dt(ln(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var Cn=/[0-9A-Fa-f]/;function wn(e){let t=0,n=-1,r=gn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(F(e,t));if(n<0){a===`%`?n=t:(I(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:Cn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)I(r,String.fromCharCode(F(e,n)),n)}}};function i(t){t>n&&I(r,be(ln(e,n,t)),n),n=-1}return r}var Tn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),En=new Map(Me.map(({pattern:e,hit:t})=>[e,t])),Dn=new Map(vt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function L(e){return{rule:_e(e),severity:`high`,detector:e}}var On=L(`injection`),kn=L(`marker_leak`),An=L(`tool_leak`);function jn({kind:e,group:t}){if(Tn.has(e))return On;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:L(t);case`boundary`:return kn;case`image`:return L(`ungiven_images`);default:return L(`ungiven_links`)}}function Mn(e,t,n){if(e===`card`)return{hit:Ue};if(e===`image`||e===`link`){let r=(e===`image`?qe:ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=En.get(t)??Dn.get(t);return r?{hit:r}:{}}function Nn(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:wt(i(n?.ungiven_images)),link:Ct(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return gt.forEach((t,n)=>{let r=jn(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Le(t.pattern),...Mn(t.kind,t.pattern,a)})}),o}function Pn(){let e=[];return gt.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=En.get(n);e.push({...On,id:r,regex:Le(n),...i?{hit:i}:{}})}),e}function Fn(){return Xe.map((e,t)=>({...On,id:t,regex:new RegExp(e.source,e.flags)}))}function In(e,t,n){let r=on(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:``},ne=()=>(D.text!==e.text&&(D={text:e.text,lower:e.text.toLowerCase()}),D.lower);function O(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,ne)))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):O(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 Ln=new WeakMap;function Rn(e){let t=Ln.get(e);return t||(t=M(e),Ln.set(e,t)),t}function zn(e={}){let t={text:``,fresh:``},n=un(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),In(e,t,n)),a=[],o=e.detect??[],s=Nn(o,e);if(s.length>0&&(N??=M(Qt().forward),a.push(i(n,N,s))),o.includes(`injection`)){N??=M(Qt().forward),Xt??=M(Qt().reversed);let e=Sn(t),r=Pn();a.push(i(n,Xt,Fn()),i(hn(n),N,r),i(e,N,r),i(hn(e),N,r),i(dn(n,We),N,r),i(dn(n,e=>x(e)??e),N,r),i(wn(t),N,r))}if(o.includes(`marker_leak`)&&e.note){let t=tt(e.note);a.push(i(n,rn(e.note),[{...kn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=Ge(e.tools),r=t.map(({regex:e},t)=>({...An,id:t,regex:e}));t.length>0&&a.push(i(n,an(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...L(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Rn(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 Bn(e,t,n={},r=[]){let i=fe(e,t).filter(e=>!(ue(e)||r.includes(e))),a=ct(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=zn({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=O(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function Vn(e){let{context:t}=e,n=e.detect,r=n?Bn(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(-k),_=u,v=0,y=u,b=0,x=0,S=s?ce(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,$e]),c){let r=_.length;_+=e;let i=Ne(_,r);_=_.slice(i),v+=i;let[a]=Re(_,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 w(){let e=s&&a!==`flag`?E(s):h.length,n=c&&o!==`flag`?D(c,t.canary):h.length;return m+Math.min(e,n)}function T(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 E(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-k),i=r+ve(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+ve(y,e)),x=Math.min(i,u.length+p.length-k);let a=Math.max(b,Math.max(t,x)-k);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function D(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+lt(i,e,t)-u.length-m)}function ne(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(w(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return T({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),T({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(-k)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),ne(e)):{blocked:!1,emit:``}},flush:()=>ne(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>O(h.length),carryOut:()=>l?C(u+p,s,c):``}}function R(e,t,n){return ke(t,e.detect,n)}async function Hn(e,t,n,r){return R(e,[n],t)?(await Zt(),Un(e,t,n,r)):null}function Un(e,t,n,r){return R(e,[n],t)?Vn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:je(e,t)},...r?{carry:r}:{}}):null}async function Wn(e,t,n,r){return R(e,[n],r??t)?(await Zt(),Vn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??je(e,t)}})):null}var Gn=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}},Kn=[`user`,`options`,`repair`,`attachment`,`voice`,`history`,`system`];function qn(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Jn={client:`untrusted`,server:`assembled`};function Yn(e){return typeof e==`string`?e:JSON.stringify(e)}function Xn(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of bt){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(Yn(o));let c=s.found(),l=Ee(`context`,c);l&&n.push({...l,trust:Jn[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Zn=/^[A-Za-z0-9._-]+$/,Qn=/^[A-Za-z0-9._:-]{1,32}$/;function $n(e){if(e===void 0||Qn.test(e))return e;throw new j(`request`,`input.messageId must be 1 to 32 letters, digits, ".", "_", ":" or "-"`)}function er(e){let t=e?.trim();return t&&Zn.test(t)?t:void 0}function tr(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 nr(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 rr(e,t){let n=t?`: ${t}`:``;return new j(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function ir(e,t){let{detect:n}=E(t.guardrails),r=de(Kn,e=>Oe(e,n)),i=e.input??{},a=$n(i.messageId),o=i.text===void 0?void 0:r.user.read(i.text),s=e.system===void 0?void 0:kt(e.system,`TurnRequest.system`,e=>r.system.read(e)),c=qn(i.options,r.options),l=Xn(i.context,()=>Oe(`context`,n)),u=tr(i.repair,r.repair),d=i.history?nr(i.history,r.history):void 0,{attachments:f,voice:p}=i.attachments?.length||i.voice?.length?It(t,i.attachments,i.voice,r):i,m=[],h;for(let e of Kn){let t=r[e].found(),n=Ee(e,t);n&&m.push(Gt(n)),t.action===`block`&&(h??=rr(e,t.errorInternal))}return m.push(...l.events.map(Gt)),l.blocked&&(h??=rr(`context`)),{request:{...e,system:s,projectId:er(e.projectId),input:{...i,text:o,...a===void 0?{}:{messageId:a},options:c,...l.context?{context:l.context}:{},repair:u,history:d,attachments:f,voice:p}},events:m,...h?{refusal:h}:{}}}function ar(e,t){let{request:n,refusal:r}=ir(e,t);if(r)throw r;return n}function or(e,t){return[...new Set([...t.filter(t=>St(e,t)),...e.filter(e=>St(t,e))])]}function sr(e,t){let n=e.attachments?t?or(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 cr(e){let t=Te(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function lr(e,t){let n=Ot(e),r=Bt({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=>St(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:cr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var ur=`final_answer`;function dr(e){return e.structured!==null&&e.tools.wire.length>0}function fr(e,t,n){let{structured:r}=t;if(!r||!dr(t))return e;let i={type:`function`,name:ur,description:A(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function pr(e,t){return e.get(t)||{name:t,missing:!0}}function mr(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 hr(e,t){return[...zt(t),...mr(t)].map(t=>pr(e,t))}function z(e,t){if(Array.isArray(e)){for(let n of e)z(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),z(r,t);for(let e of Object.values(r))z(e,t)}function gr(e,t){let n=hr(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&z(Je(e.inputSchema),r);return{names:n.map(({name:e})=>e),params:[...r]}}function _r(e){return!e||e.length===0?[]:e.slice(-4)}function vr(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${A(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
|
|
2
2
|
`)}\n\n`}function yr(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||A(`repair.default_guidance`,{},t.labels),a=vr(_r(r),t.labels),o=`${A(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${A(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${A(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${A(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${A(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${A(`repair.section_instructions`,{},t.labels)}\n`,o+=A(`repair.prompt_instructions`,{},t.labels),o}function br(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function xr(e,t){let n=br(e,t);if(!(n.length<=1))throw new j(`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 Sr(e,t){if(e.type!==`speech`){if(t.speech)throw new j(`request`,`Profile ${e.id} (${e.type}) takes no speech settings — only a speech profile speaks`)}else if(t.system)throw new j(`config`,`Profile ${e.id} (speech) takes no system prompt — the input text is the transcript`)}function Cr(e,t){if(e.type===`transcription`){if(t.system)throw new j(`config`,`Profile ${e.id} (transcription) takes no system prompt — the input is the clip`);if(!t.input?.voice?.length)throw new j(`request`,`Profile ${e.id} (transcription) requires a voice clip`)}}function wr(e,t){return e.type===`speech`?{...e.speech,...Tr(t.speech)}:void 0}function Tr(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function Er(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 Dr(e){let t=Be(e);if(!t)throw new j(`input`,`MIME '${e}' is not a supported media input type`);return t}function Or(e){return e.map(e=>{let t=Dr(e.mimeType),n=Te(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return Nt(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function kr(e,t){let{text:n,repair:r,history:i}=t.input??{};if(e.type===`speech`&&!n?.trim())throw new j(`request`,`Profile ${e.id} (speech) requires text input`);if(T(e)?.text===!1&&n)throw new j(`request`,`Profile ${e.id} does not accept text input`);let a=r?yr({profile:e,repair:r,history:i}):jr(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Ar(t),...a?[pe(a,t.input?.messageId)]:[]];return o.length>0?{type:`text`,text:o.join(`
|
|
3
3
|
|
|
4
|
-
`)}:null}function Ar(e){let t=e.input?.context??{};return[...bt].reverse().filter(e=>t[e]!==void 0).map(e=>re(e,Yn(t[e])))}function jr(e,t){if(t.continueFrom&&ne.includes(e.type)){if(t.input?.text)throw new j(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return A(`continue.instruction`,{},e.labels)}}function Mr(e){return e.type===`image`&&e.image.references?Or(e.image.references):[]}function Nr(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Mr(e),...Or(n),...Or(r)]}function Pr(e,t){let n=[],r=kr(e,t);return r&&n.push(r),n.push(...Nr(e,t)),n}function Fr(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(!bt.includes(t)||!r?.from.some(e=>e===t))throw new j(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Yn(i).length>r.maxChars)throw new j(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}function Ir(e,t){if(e.type===`speech`||e.type===`transcription`)return[];let n=e.identity.system;if(!n)return[];let r=jt(e,t);return Et(n,r,t=>It(e,t,r))}function Lr(e,t){let n=Ir(e,t);return{pieces:Dt([...n.map(({pieces:e})=>e),t.system===void 0?[]:At(t.system)]),lines:n.map(({line:e})=>e)}}function Rr(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function zr(e,t){if(Rr(e))return e;throw e.type===`host`?new j(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new j(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new j(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function Br(e,t){if(t){if(!e.allowModelSelect)throw new j(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new j(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function Vr(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new j(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new j(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new j(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function Hr(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function Ur(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 Wr(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function Gr(e,t){return e.type===`live`?`live`:`turn`}function Kr(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new j(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=Ae(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new j(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new j(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new j(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function qr(e,t){return R(E(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function Jr(e){let{detect:t}=E(e.guardrails);return e.type!==`speech`&&e.type!==`transcription`&&at(t,`canary_leak`)?Se():``}function Yr(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new j(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function Xr(e,t,n){let r=zr(e.profiles.get(t.profile),`resolveTurn`);Mt(r,t),Fr(r,t);let i=ar(t,r),a=i.input??{};Kr(r,i);let o=n??Br(r,i.model),s=xt(r,o),c=Lt(e.tools,r,i,o),l=c.builtins,u=Ur(r,jt(r,i));if(xr(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new j(`config`,`Profile ${r.id}: a structured turn answers through '${ur}', so no tool of its own may take that name`);Sr(r,i),Cr(r,i);let d=Yr(r,o,s,i.builtInArgs),f=Gr(r,s),p=e.providers.get(s.provider),m=p&&ft(p,s,r.type),h=Lr(r,i);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,...m?{operationName:m}:{},stream:Wr(r),thinking:Vr(r,s,o,i.effort),summaries:Hr(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:Ye(e.schemas.get(u).jsonSchema)}:null,image:Er(r),speech:wr(r,i),live:r.type===`live`?qr(r.live,r.guardrails):void 0,input:Pr(r,i),canary:Jr(r),resolvedSystem:h.pieces,systemLines:h.lines,host:i.host}}}function Zr(e){return e.type===`image`?e.image:null}function Qr(e,t){let n=zr(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:hr(e,n),inputs:i,outputs:a,image:Zr(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function $r(e,t){return Qr(e.tools,e.profiles.get(t))}var ei=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function ti(e){return e.join(`,`)}function ni(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:ti(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,options:e?.options,context:e?.context}}function ri(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,options:e.options,context:e.context}}function ii(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=Bt({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Pt(ri(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function ai(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(ei.filter(t=>St(e,t)))??e.find(n):r(ei)}var oi=_({protocol:r(),provider:r(),apiId:r(),options:t(r(),u()).optional(),keySlot:r().optional(),fallbackKeySlot:r().optional(),efforts:t(r(),c(Tt)).optional(),defaultEffort:r().optional(),allowEffortSelect:m().optional(),summaries:m().optional(),maxOutputTokens:s().optional(),temperature:s().optional(),builtInTools:l(r()).optional(),compaction:_({maxTokens:s(),compactAt:s(),previousExchanges:s(),profile:r().optional(),timing:c(w),meter:c(Ce).optional()}).optional(),limits:_({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()}),B=_({structured:n([r(),_({by:r(),map:t(r(),r()),fallback:r()}),f()]).optional(),streaming:_({mode:c(xe).optional(),streamThoughts:m().optional()}).optional()}),si=_(de(ie,()=>c(Ve))),ci=_(de(ut,()=>si)),li=_({id:r(),label:r(),actions:si,names:l(r()),find:m()}),ui=_({hosts:l(r()),fromTools:m()}),di=_({quota:_({perDay:s()}).optional(),detect:ci,patterns:a(c(ut),_({theorem:m(),names:l(r())})).optional(),host:l(li).optional(),allow:_({ungiven_images:ui,ungiven_links:ui}),blockedReply:_({onBlock:c(te),maxRetries:s()})}),fi=n([m(),_({theorem:m(),host:m()})]),pi=_({record:m(),writeTo:n([g(!1),r()]).optional(),sampleRate:s(),include:_({upstreamLog:m(),outboundWire:m(),evidenceRaw:m(),usage:m(),guardrailDecisions:m(),guardrailMatchPreview:m()}),scrub:_({sensitive:fi,injection:fi,canary:fi}),resource:Ut,retainForDays:s(),rotateAfterMiB:s(),hasOnWriteError:m()}),mi=t(r(),_({label:r().optional(),choices:l(_({value:r(),description:r().optional()}))})),V=_({text:m(),attachments:_({accept:l(r()),acceptAttr:r()}).nullable(),voice:_({accept:l(r())}).nullable(),maxFiles:s().optional(),maxBytes:s().optional(),maxTurnBytes:s().optional(),limitsByMime:t(r(),s()).optional(),options:mi.optional(),context:_({from:l(c(bt)),maxChars:s()}).optional()}),hi=_({allowContinue:l(c(we)).optional(),autoContinue:l(c(we)).optional(),maxContinues:s().optional()}),gi=_({resumption:hi.optional()}),_i=_({allow:l(r()),page:l(r()),t2Loader:r().optional(),parallel:m().optional()}),H={providerContinuation:_({history:c([`host`,`stateless`,`provider`]).optional()}).optional(),id:r(),models:t(r(),oi),defaultModel:r(),allowModelSelect:m().optional(),maxSteps:s().optional(),labels:a(c(it),r()),guardrails:di.optional(),observability:pi.optional()},vi=n([r(),o({private:r().min(1)})]),yi=n([r(),l(n([r(),l(vi).readonly()])).min(1).readonly()]),bi=_({handle:r(),options:mi.optional(),system:yi.optional()}),U=d(`type`,[_({...H,type:g(`text`),identity:bi,outputs:B.optional(),inputs:V,tools:_i,turnBehaviour:_({resumption:hi.optional(),allowSteering:m().optional(),atStepLimit:c(he).optional()}).optional(),canStop:g(!0),allowSteering:m()}),_({...H,type:g(`image`),identity:bi,outputs:B.optional(),image:_({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([_({mimeType:r(),data:r(),name:r().optional()}),_({mimeType:r(),uri:r(),name:r().optional()})])).optional(),includeText:m().optional()}),inputs:V,tools:_i,turnBehaviour:gi.optional(),canStop:g(!0)}),_({...H,type:g(`transcription`),identity:_({handle:r()}),maxSteps:h().optional(),outputs:B.optional(),inputs:V,canStop:g(!0)}),_({...H,type:g(`speech`),identity:_({handle:r()}),outputs:B.optional(),speech:_({voice:r().optional(),style:r().optional(),speed:s().optional(),format:c(se).optional()}),inputs:V,turnBehaviour:gi.optional(),canStop:g(!0)}),_({...H,type:g(`live`),identity:bi,inputs:V.pick({options:!0,context:!0}).optional(),live:_({ingress:_({audio:m().optional(),video:m().optional(),text:m().optional()}).optional(),voice:r().optional(),vad:_({activityHandling:c(et).optional(),startSensitivity:c(Qe).optional(),endSensitivity:c(ee).optional(),prefixPaddingMs:s().optional(),silenceDurationMs:s().optional()}).optional(),sessionResumption:m().optional(),contextCompression:_({triggerTokens:s().optional(),slidingWindow:_({targetTokens:s().optional()})}).optional(),transcription:_({input:m().optional(),output:m().optional()}).optional()}),tools:_i.pick({allow:!0,page:!0}),turnBehaviour:_({allowSteering:m().optional()}).optional()})]);function xi(e){let t=E(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:Si(t.allow.ungiven_images),ungiven_links:Si(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function Si(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function Ci(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function wi(e){if(!e)return;let t=Vt(e);return{record:t.record,writeTo:Ci(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function Ti(e){let{greeting:t,resumed:n,...r}=e??{};return r}function Ei(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=Rt(t),r=Ft(t);return{allow:[...zt(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 Di({allow:e,page:t}){return{allow:e,page:t}}function Oi(e,t){let n=ni(e.inputs),r=t?.identity??{handle:e.handle},i=t?xi(t.guardrails):void 0,a=t?wi(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:ht(t?.labels)};switch(e.type){case`text`:return U.parse({...s,type:`text`,inputs:n,tools:Ei(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||De(t)});case`image`:return U.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:Ei(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return U.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`transcription`:return U.parse({...s,type:`transcription`,inputs:n,canStop:!0});case`live`:return U.parse({...s,type:`live`,live:Ti(e.live),...e.inputs?{inputs:{options:n.options,context:n.context}}:{},tools:Di(Ei(e,t))});default:return e.type}}function ki(e,t){let n=zr(e,`interfaceFromProfile`);return Oi(Qr(t,n),n)}function Ai(e){return p(t=>Ie.safeParse(e(t)).success)}var ji=[`running`,`gate`,`background`,`complete`,`error`,`cancel`],Mi=p(e=>{let t=Ie.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 ji.some(e=>e===n)}),Ni=t(r(),i()),Pi=_({operationId:r().optional(),name:r(),callId:r(),arguments:Ni,draft:r().optional(),reasoning:l(Ke).optional(),stepId:r().optional(),edited:_({from:Ni,to:Ni}).optional(),activity:r().optional(),activityPast:r().optional(),outputDraft:r().optional(),state:Mi.optional(),startedAt:s().optional(),endedAt:s().optional(),get steps(){return l(Pi).optional()}}),Fi=_({kind:c(st),native:r().optional()}),W={id:r()},G=d(`kind`,[_({...W,kind:g(`user-text`),text:r()}),_({...W,kind:c([`user-attachment`,`user-voice`]),name:r(),mimeType:r(),sizeBytes:s(),data:r().optional()}),_({...W,kind:g(`thought`),text:r()}),_({...W,kind:g(`text`),text:r()}),_({...W,kind:g(`tool`),tool:Pi}),_({...W,kind:g(`structured`),value:i(),draft:r().optional()}),_({...W,kind:g(`media`),mimeType:r(),data:r().optional(),uri:r().optional(),type:c(ge).optional(),fromTool:g(!0).optional(),sent:g(!0).optional(),metadata:t(r(),i()).optional()}),_({...W,kind:g(`grounding`),grounding:Ai(e=>({type:`grounding`,grounding:e}))}),_({...W,kind:g(`citation`),sources:Ai(e=>({type:`citation`,sources:e})),callId:r().optional()}),_({...W,kind:g(`evidence`),evidence:Ai(e=>({type:`evidence`,evidence:e}))}),_({...W,kind:g(`guardrail`),guardrail:me}),_({...W,kind:g(`late-results`),text:r(),operationIds:l(r()),inReply:m()}),_({...W,kind:g(`error`),message:r()}),_({...W,kind:g(`turn-done`),stop:Fi.optional(),tokens:Ai(e=>({type:`tokens`,tokens:e})).optional(),interactionId:r().optional(),compaction:m().optional(),workedMs:s().optional(),endedAt:s().optional()})]),Ii=_({type:r()});function Li(e,t){return Object.hasOwn(e,t)}function Ri(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=>Ri(e,n)).join(` | `)}]`}).join(`; `)}function zi(e){return Ri(e.issues,[])}function Bi(e,t){return new j(`bad_response`,`${e} failed its wire check: ${zi(t)}`)}function K(e,t,n){let r=e.safeParse(t);if(!r.success)throw Bi(n,r.error);return r.data}function Vi(e){return{type:`malformed`,error:new j(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Hi(e,t){let n=Ii.safeParse(t);if(!n.success)return Vi(`a line without a kind failed its wire check: ${zi(n.error)}`);let{type:r}=n.data;if(!Li(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:Vi(`a '${r}' line failed its wire check: ${zi(i.error)}`)}function Ui(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Wi(e,t){let n=Ui(t);return n?Hi(e,n.value):Vi(`a line is not JSON`)}function Gi(e){let t=Ui(e);if(!t)throw new j(`bad_response`,`a line is not JSON`);return t.value}var Ki=_({name:r(),mimeType:r(),data:r()}),qi=_({options:t(r(),r()).optional(),context:i().optional(),text:r().optional(),attachments:l(Ki).optional(),voice:l(Ki).optional()}),Ji=_({gateKind:c(ae).optional(),sessionPermissions:l(r()).optional(),name:r().optional(),input:i().optional(),snapshot:ze.optional(),promoted:l(r()).optional(),model:r().optional(),effort:r().optional()}),q=r().trim().min(1),Yi=_({path:r().optional(),options:t(r(),r()).optional()}),Xi=Yi;_({input:qi,conversation:r().min(1).optional(),model:r().optional(),effort:r().optional(),stated:Yi.optional(),turnId:q.optional(),abandon:l(He).min(1).optional(),replay:Ji.pick({sessionPermissions:!0}).optional(),transcript:l(G).optional()});var Zi=[`approve`,`deny`],Qi=n([o({unanswered:g(!0)}),o({output:i()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);_({gateId:r().min(1),operationId:r().min(1).max(256),decision:c(Zi),input:i().optional(),secret:r().optional(),page:Qi.optional(),conversation:r().min(1).optional(),turnId:q.optional(),replay:Ji.optional()}),_({turnId:q,id:q,inject:l(yt).min(1)}),_({turnId:q});var $i=_({type:g(`conversation`),ref:r().min(1),posted:g(!0).optional()}),ea={...mt,conversation:$i},ta=_({transcript:l(G),paused:_({events:l(Ie),blocks:l(G)}).optional(),notify:_({retryMs:s().optional()}).optional(),wake:g(!0).optional()});_({conversation:r().min(1)}),_({conversation:r().min(1),input:qi.pick({options:!0,context:!0}).optional(),model:r().optional(),effort:r().optional(),turnId:q.optional()}),o({});var na={changed:_({type:g(`changed`)})};_({conversation:r().min(1),at:s().int().min(-1)}),_({blocks:l(G)});var ra=_({conversation:r().min(1),view:ta}),ia=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 aa(e){return e instanceof ia}function oa(e){return e?.trim()||void 0}var sa=_({error:r().optional(),errorKind:oe.optional(),errorCopy:D.optional(),errorInternal:r().optional()}),ca=sa;function la(e,t){let n=oa(e.error),r=oa(e.errorInternal);return new ia(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function ua(e){return!aa(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function da(e,t){let n=Wi(e,t);if(n.type===`error`)throw la(sa.parse(n),`internal`);return n}function fa(e,t,n){let r=e.split(`
|
|
4
|
+
`)}:null}function Ar(e){let t=e.input?.context??{};return[...bt].reverse().filter(e=>t[e]!==void 0).map(e=>re(e,Yn(t[e])))}function jr(e,t){if(t.continueFrom&&ne.includes(e.type)){if(t.input?.text)throw new j(`request`,`Profile ${e.id}: a continueFrom turn takes no input.text — its user message is the continue instruction`);return A(`continue.instruction`,{},e.labels)}}function Mr(e){return e.type===`image`&&e.image.references?Or(e.image.references):[]}function Nr(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Mr(e),...Or(n),...Or(r)]}function Pr(e,t){let n=[],r=kr(e,t);return r&&n.push(r),n.push(...Nr(e,t)),n}function Fr(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(!bt.includes(t)||!r?.from.some(e=>e===t))throw new j(`request`,`Profile ${e.id} takes no context from '${t}'`);if(Yn(i).length>r.maxChars)throw new j(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}function Ir(e,t){if(e.type===`speech`||e.type===`transcription`)return[];let n=e.identity.system;if(!n)return[];let r=jt(e,t);return Et(n,r,t=>Ft(e,t,r))}function Lr(e,t){let n=Ir(e,t);return{pieces:Dt([...n.map(({pieces:e})=>e),t.system===void 0?[]:At(t.system)]),lines:n.map(({line:e})=>e)}}function Rr(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function zr(e,t){if(Rr(e))return e;throw e.type===`host`?new j(`request`,`Profile ${e.id}: type 'host' never runs a model — ${t} is not supported; execute tools with invokeTool`):e.type===`embedding`?new j(`request`,`Profile ${e.id}: type 'embedding' runs through runEmbedding — ${t} is not supported`):new j(`request`,`Profile ${e.id}: type 'decision' runs through runDecision — ${t} is not supported`)}function Br(e,t){if(t){if(!e.allowModelSelect)throw new j(`request`,`Profile ${e.id} does not allow model selection`);if(!e.models[t])throw new j(`request`,`Unknown model '${t}' for ${e.id}`);return t}return e.defaultModel}function Vr(e,t,n,r){let i=t.efforts;if(!i||Object.keys(i).length===0){if(r)throw new j(`request`,`Profile ${e.id} model '${n}' has no selectable efforts`);return}let a=Object.keys(i);if(r){if(!t.allowEffortSelect)throw new j(`request`,`Profile ${e.id} model '${n}' does not allow effort selection`);let a=i[r];if(!a)throw new j(`request`,`Unknown effort '${r}' for ${e.id} model '${n}'`);return a}return i[t.defaultEffort??a[0]]}function Hr(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function Ur(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 Wr(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function Gr(e,t){return e.type===`live`?`live`:`turn`}function Kr(e,t){if(!t.continueFrom)return;if(e.type===`live`)throw new j(`request`,`Profile ${e.id}: type 'live' uses live.sessionResumption, not turnBehaviour.resumption/continueFrom`);let n=Ae(e)?.maxContinues;if(n===void 0)return;let r=t.continuation;if(r===void 0)throw new j(`request`,`Profile ${e.id}: continueFrom requires TurnRequest.continuation when turnBehaviour.resumption.maxContinues is set`);if(r<1)throw new j(`request`,`Profile ${e.id}: continuation must be >= 1`);if(r>n)throw new j(`request`,`Profile ${e.id}: continuation ${r} exceeds turnBehaviour.resumption.maxContinues (${n})`)}function qr(e,t){return R(E(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function Jr(e){let{detect:t}=E(e.guardrails);return e.type!==`speech`&&e.type!==`transcription`&&at(t,`canary_leak`)?Se():``}function Yr(e,t,n,r){if(!r)return;let i={};for(let[a,o]of Object.entries(r)){if(!n.builtInTools?.includes(a))throw new j(`request`,`Profile ${e.id}: builtInArgs names '${a}', which model '${t}' does not list in builtInTools`);i[a]=o}return i}function Xr(e,t,n){let r=zr(e.profiles.get(t.profile),`resolveTurn`);Mt(r,t),Fr(r,t);let i=ar(t,r),a=i.input??{};Kr(r,i);let o=n??Br(r,i.model),s=xt(r,o),c=Lt(e.tools,r,i,o),l=c.builtins,u=Ur(r,jt(r,i));if(xr(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new j(`config`,`Profile ${r.id}: a structured turn answers through '${ur}', so no tool of its own may take that name`);Sr(r,i),Cr(r,i);let d=Yr(r,o,s,i.builtInArgs),f=Gr(r,s),p=e.providers.get(s.provider),m=p&&ft(p,s,r.type),h=Lr(r,i);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,...m?{operationName:m}:{},stream:Wr(r),thinking:Vr(r,s,o,i.effort),summaries:Hr(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:Ye(e.schemas.get(u).jsonSchema)}:null,image:Er(r),speech:wr(r,i),live:r.type===`live`?qr(r.live,r.guardrails):void 0,input:Pr(r,i),canary:Jr(r),resolvedSystem:h.pieces,systemLines:h.lines,host:i.host}}}function Zr(e){return e.type===`image`?e.image:null}function Qr(e,t){let n=zr(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:hr(e,n),inputs:i,outputs:a,image:Zr(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function $r(e,t){return Qr(e.tools,e.profiles.get(t))}var ei=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function ti(e){return e.join(`,`)}function ni(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:ti(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,options:e?.options,context:e?.context}}function ri(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,options:e.options,context:e.context}}function ii(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=Bt({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Ot(ri(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function ai(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(ei.filter(t=>St(e,t)))??e.find(n):r(ei)}var oi=_({protocol:r(),provider:r(),apiId:r(),options:t(r(),u()).optional(),keySlot:r().optional(),fallbackKeySlot:r().optional(),efforts:t(r(),c(Tt)).optional(),defaultEffort:r().optional(),allowEffortSelect:m().optional(),summaries:m().optional(),maxOutputTokens:s().optional(),temperature:s().optional(),builtInTools:l(r()).optional(),compaction:_({maxTokens:s(),compactAt:s(),previousExchanges:s(),profile:r().optional(),timing:c(w),meter:c(Ce).optional()}).optional(),limits:_({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()}),B=_({structured:n([r(),_({by:r(),map:t(r(),r()),fallback:r()}),f()]).optional(),streaming:_({mode:c(xe).optional(),streamThoughts:m().optional()}).optional()}),si=_(de(ie,()=>c(Ve))),ci=_(de(ut,()=>si)),li=_({id:r(),label:r(),actions:si,names:l(r()),find:m()}),ui=_({hosts:l(r()),fromTools:m()}),di=_({quota:_({perDay:s()}).optional(),detect:ci,patterns:a(c(ut),_({theorem:m(),names:l(r())})).optional(),host:l(li).optional(),allow:_({ungiven_images:ui,ungiven_links:ui}),blockedReply:_({onBlock:c(te),maxRetries:s()})}),fi=n([m(),_({theorem:m(),host:m()})]),pi=_({record:m(),writeTo:n([g(!1),r()]).optional(),sampleRate:s(),include:_({upstreamLog:m(),outboundWire:m(),evidenceRaw:m(),usage:m(),guardrailDecisions:m(),guardrailMatchPreview:m()}),scrub:_({sensitive:fi,injection:fi,canary:fi}),resource:Ut,retainForDays:s(),rotateAfterMiB:s(),hasOnWriteError:m()}),mi=t(r(),_({label:r().optional(),choices:l(_({value:r(),description:r().optional()}))})),V=_({text:m(),attachments:_({accept:l(r()),acceptAttr:r()}).nullable(),voice:_({accept:l(r())}).nullable(),maxFiles:s().optional(),maxBytes:s().optional(),maxTurnBytes:s().optional(),limitsByMime:t(r(),s()).optional(),options:mi.optional(),context:_({from:l(c(bt)),maxChars:s()}).optional()}),hi=_({allowContinue:l(c(we)).optional(),autoContinue:l(c(we)).optional(),maxContinues:s().optional()}),gi=_({resumption:hi.optional()}),_i=_({allow:l(r()),page:l(r()),t2Loader:r().optional(),parallel:m().optional()}),H={providerContinuation:_({history:c([`host`,`stateless`,`provider`]).optional()}).optional(),id:r(),models:t(r(),oi),defaultModel:r(),allowModelSelect:m().optional(),maxSteps:s().optional(),labels:a(c(it),r()),guardrails:di.optional(),observability:pi.optional()},vi=n([r(),o({private:r().min(1)})]),yi=n([r(),l(n([r(),l(vi).readonly()])).min(1).readonly()]),bi=_({handle:r(),options:mi.optional(),system:yi.optional()}),U=d(`type`,[_({...H,type:g(`text`),identity:bi,outputs:B.optional(),inputs:V,tools:_i,turnBehaviour:_({resumption:hi.optional(),allowSteering:m().optional(),atStepLimit:c(he).optional()}).optional(),canStop:g(!0),allowSteering:m()}),_({...H,type:g(`image`),identity:bi,outputs:B.optional(),image:_({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([_({mimeType:r(),data:r(),name:r().optional()}),_({mimeType:r(),uri:r(),name:r().optional()})])).optional(),includeText:m().optional()}),inputs:V,tools:_i,turnBehaviour:gi.optional(),canStop:g(!0)}),_({...H,type:g(`transcription`),identity:_({handle:r()}),maxSteps:h().optional(),outputs:B.optional(),inputs:V,canStop:g(!0)}),_({...H,type:g(`speech`),identity:_({handle:r()}),outputs:B.optional(),speech:_({voice:r().optional(),style:r().optional(),speed:s().optional(),format:c(se).optional()}),inputs:V,turnBehaviour:gi.optional(),canStop:g(!0)}),_({...H,type:g(`live`),identity:bi,inputs:V.pick({options:!0,context:!0}).optional(),live:_({ingress:_({audio:m().optional(),video:m().optional(),text:m().optional()}).optional(),voice:r().optional(),vad:_({activityHandling:c(et).optional(),startSensitivity:c(Qe).optional(),endSensitivity:c(ee).optional(),prefixPaddingMs:s().optional(),silenceDurationMs:s().optional()}).optional(),sessionResumption:m().optional(),contextCompression:_({triggerTokens:s().optional(),slidingWindow:_({targetTokens:s().optional()})}).optional(),transcription:_({input:m().optional(),output:m().optional()}).optional()}),tools:_i.pick({allow:!0,page:!0}),turnBehaviour:_({allowSteering:m().optional()}).optional()})]);function xi(e){let t=E(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:Si(t.allow.ungiven_images),ungiven_links:Si(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function Si(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function Ci(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function wi(e){if(!e)return;let t=Vt(e);return{record:t.record,writeTo:Ci(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function Ti(e){let{greeting:t,resumed:n,...r}=e??{};return r}function Ei(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=Rt(t),r=Pt(t);return{allow:[...zt(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 Di({allow:e,page:t}){return{allow:e,page:t}}function Oi(e,t){let n=ni(e.inputs),r=t?.identity??{handle:e.handle},i=t?xi(t.guardrails):void 0,a=t?wi(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:ht(t?.labels)};switch(e.type){case`text`:return U.parse({...s,type:`text`,inputs:n,tools:Ei(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||De(t)});case`image`:return U.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:Ei(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return U.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`transcription`:return U.parse({...s,type:`transcription`,inputs:n,canStop:!0});case`live`:return U.parse({...s,type:`live`,live:Ti(e.live),...e.inputs?{inputs:{options:n.options,context:n.context}}:{},tools:Di(Ei(e,t))});default:return e.type}}function ki(e,t){let n=zr(e,`interfaceFromProfile`);return Oi(Qr(t,n),n)}function Ai(e){return p(t=>Ie.safeParse(e(t)).success)}var ji=[`running`,`gate`,`background`,`complete`,`error`,`cancel`],Mi=p(e=>{let t=Ie.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 ji.some(e=>e===n)}),Ni=t(r(),i()),Pi=_({operationId:r().optional(),name:r(),callId:r(),arguments:Ni,draft:r().optional(),reasoning:l(Ke).optional(),stepId:r().optional(),edited:_({from:Ni,to:Ni}).optional(),activity:r().optional(),activityPast:r().optional(),outputDraft:r().optional(),state:Mi.optional(),startedAt:s().optional(),endedAt:s().optional(),get steps(){return l(Pi).optional()}}),Fi=_({kind:c(st),native:r().optional()}),W={id:r()},G=d(`kind`,[_({...W,kind:g(`user-text`),text:r()}),_({...W,kind:c([`user-attachment`,`user-voice`]),name:r(),mimeType:r(),sizeBytes:s(),data:r().optional()}),_({...W,kind:g(`thought`),text:r()}),_({...W,kind:g(`text`),text:r()}),_({...W,kind:g(`tool`),tool:Pi}),_({...W,kind:g(`structured`),value:i(),draft:r().optional()}),_({...W,kind:g(`media`),mimeType:r(),data:r().optional(),uri:r().optional(),type:c(ge).optional(),fromTool:g(!0).optional(),sent:g(!0).optional(),metadata:t(r(),i()).optional()}),_({...W,kind:g(`grounding`),grounding:Ai(e=>({type:`grounding`,grounding:e}))}),_({...W,kind:g(`citation`),sources:Ai(e=>({type:`citation`,sources:e})),callId:r().optional()}),_({...W,kind:g(`evidence`),evidence:Ai(e=>({type:`evidence`,evidence:e}))}),_({...W,kind:g(`guardrail`),guardrail:me}),_({...W,kind:g(`late-results`),text:r(),operationIds:l(r()),inReply:m()}),_({...W,kind:g(`error`),message:r()}),_({...W,kind:g(`turn-done`),stop:Fi.optional(),tokens:Ai(e=>({type:`tokens`,tokens:e})).optional(),interactionId:r().optional(),compaction:m().optional(),workedMs:s().optional(),endedAt:s().optional()})]),Ii=_({type:r()});function Li(e,t){return Object.hasOwn(e,t)}function Ri(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=>Ri(e,n)).join(` | `)}]`}).join(`; `)}function zi(e){return Ri(e.issues,[])}function Bi(e,t){return new j(`bad_response`,`${e} failed its wire check: ${zi(t)}`)}function K(e,t,n){let r=e.safeParse(t);if(!r.success)throw Bi(n,r.error);return r.data}function Vi(e){return{type:`malformed`,error:new j(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Hi(e,t){let n=Ii.safeParse(t);if(!n.success)return Vi(`a line without a kind failed its wire check: ${zi(n.error)}`);let{type:r}=n.data;if(!Li(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:Vi(`a '${r}' line failed its wire check: ${zi(i.error)}`)}function Ui(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Wi(e,t){let n=Ui(t);return n?Hi(e,n.value):Vi(`a line is not JSON`)}function Gi(e){let t=Ui(e);if(!t)throw new j(`bad_response`,`a line is not JSON`);return t.value}var Ki=_({name:r(),mimeType:r(),data:r()}),qi=_({options:t(r(),r()).optional(),context:i().optional(),text:r().optional(),attachments:l(Ki).optional(),voice:l(Ki).optional()}),Ji=_({gateKind:c(ae).optional(),sessionPermissions:l(r()).optional(),name:r().optional(),input:i().optional(),snapshot:ze.optional(),promoted:l(r()).optional(),model:r().optional(),effort:r().optional()}),q=r().trim().min(1),Yi=_({path:r().optional(),options:t(r(),r()).optional()}),Xi=Yi;_({input:qi,conversation:r().min(1).optional(),model:r().optional(),effort:r().optional(),stated:Yi.optional(),turnId:q.optional(),abandon:l(He).min(1).optional(),replay:Ji.pick({sessionPermissions:!0}).optional(),transcript:l(G).optional()});var Zi=[`approve`,`deny`],Qi=n([o({unanswered:g(!0)}),o({output:i()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);_({gateId:r().min(1),operationId:r().min(1).max(256),decision:c(Zi),input:i().optional(),secret:r().optional(),page:Qi.optional(),conversation:r().min(1).optional(),turnId:q.optional(),replay:Ji.optional()}),_({turnId:q,id:q,inject:l(yt).min(1)}),_({turnId:q});var $i=_({type:g(`conversation`),ref:r().min(1),posted:g(!0).optional()}),ea={...mt,conversation:$i},ta=_({transcript:l(G),paused:_({events:l(Ie),blocks:l(G)}).optional(),notify:_({retryMs:s().optional()}).optional(),wake:g(!0).optional()});_({conversation:r().min(1)}),_({conversation:r().min(1),input:qi.pick({options:!0,context:!0}).optional(),model:r().optional(),effort:r().optional(),turnId:q.optional()}),o({});var na={changed:_({type:g(`changed`)})};_({conversation:r().min(1),at:s().int().min(-1)}),_({blocks:l(G)});var ra=_({conversation:r().min(1),view:ta}),ia=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 aa(e){return e instanceof ia}function oa(e){return e?.trim()||void 0}var sa=_({error:r().optional(),errorKind:oe.optional(),errorCopy:D.optional(),errorInternal:r().optional()}),ca=sa;function la(e,t){let n=oa(e.error),r=oa(e.errorInternal);return new ia(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function ua(e){return!aa(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function da(e,t){let n=Wi(e,t);if(n.type===`error`)throw la(sa.parse(n),`internal`);return n}function fa(e,t,n){let r=e.split(`
|
|
5
5
|
`),i=r.pop()??``;for(let e of r)e.trim()&&n(da(t,e));return i}async function pa(e,t,n,r){if(!e.body)throw new j(`bad_response`,`stream reply has no body`);let i=e.body.getReader(),a=new TextDecoder,o=``,s=()=>{i.cancel()};r?.addEventListener(`abort`,s,{once:!0});try{for(;;){rt(r);let{done:e,value:s}=await i.read();if(e)break;o=fa(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(da(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function ma(e){let t=typeof e.headers==`function`?await e.headers():e.headers,n=new Headers(t);return n.set(`content-type`,`application/json`),n}async function ha(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return la({errorInternal:`HTTP ${String(e.status)}`},ye(e.status))}let i=sa.safeParse(r);return i.success?la({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},ye(e.status)):new j(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function ga(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await ma(n),credentials:n.credentials??`same-origin`})}catch(e){throw Pe(e)?e:new j(`network`,le(e),{cause:e})}}async function J(e,t,n,r,i={}){await pa(await _a(e,t,i),n,r,i.signal)}async function _a(e,t,n){let r=await ga(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await ha(r);return r}async function va(e,t,n={}){await _a(e,t,n)}async function Y(e,t,n={}){let r=await ga(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await ha(r,t.failed);return Gi(await r.text())}async function ya(e,t,n={}){let{signal:r,...i}=n;return K(ta,await Y(e,{body:t,signal:r},i),`the conversation`)}async function ba(e,t,n,r){let{signal:i,...a}=n;return K(ra,await Y(e,{body:t,signal:i},a),r)}function xa(e,t,n={}){return ba(e,t,n,`the rewound conversation`)}function Sa(e,t,n={}){return ba(e,t,n,`the started conversation`)}function Ca(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var wa=_({interface:U});function Ta(e={}){let t=Ca(e.endpoint??`/api/theorem`);return{async describe(n){let r=await ga(t,{method:`GET`,signal:n},e);if(!r.ok)throw await ha(r);return K(wa,Gi(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>J(`${t}/turn`,r,ea,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>J(`${t}/invoke`,r,ea,i,{...e,signal:a}),conversation:(n,r)=>ya(`${t}/conversation`,n,{...e,signal:r}),wake:(n,r,i)=>J(`${t}/wake`,n,ea,r,{...e,signal:i}),notify:(n,r)=>J(`${t}/notify`,{},na,e=>{e.type===`changed`&&n()},{...e,signal:r}),rewind:(n,r)=>xa(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>va(`${t}/page-result`,n,{...e,signal:r}),steer:n=>va(`${t}/steer`,n,e),stop:n=>va(`${t}/stop`,n,e)}}function Ea(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?Ea(n[0],t):t}function Da(e){return Object.entries(e).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>Ea(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}}))}function Oa(e,t,n){return{type:`decision`,identity:{handle:e.identity.handle},contract:e.decision.contract,...e.inputs.maxStateBytes===void 0?{}:{maxStateBytes:e.inputs.maxStateBytes},questions:Da(t),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:Vt(e.observability).record}}:{}}}function ka(e,t){let n=Object.keys(t??{}).find(t=>e&&Object.hasOwn(e,t));if(n!==void 0)throw new j(`request`,`the image ${n} is the host's, so the page's needs another name`);let r={...e,...t};return Object.keys(r).length>0?r:void 0}var X=s().min(0).max(1),Aa=t(r(),X),ja=d(`type`,[_({type:g(`choice`),choice:r(),confidence:X,probabilities:Aa}),_({type:g(`noul`),noul:X}),_({type:g(`box`),box:_({top:X,bottom:X,left:X,right:X}),confidence:X}),_({type:g(`score`),score:s().nonnegative(),confidence:X,legend:t(r(),r().min(1)),probabilities:Aa})]),Ma=_({id:r(),type:c([`choice`,`noul`,`score`,`box`]),labels:l(r()),image:r().optional()}),Na=_({result:_({model:r().min(1),questions:l(Ma).optional(),answers:t(r(),ja),usage:_({inputTokens:s().int().nonnegative(),outputTokens:s().int().nonnegative(),costUsd:s().nonnegative().optional()}).optional()}),traces:l(Ht).optional()}),Pa=new WeakMap;function Fa(e,t){return t.length>0&&typeof e==`object`&&e&&Pa.set(e,t),e}function Ia(e){return typeof e==`object`&&!!e&&Pa.get(e)||[]}var La=_({traces:l(Ht)});async function Ra(e,t,n,r,i){let a=[],o=e=>{let t=La.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Y(e,{body:t,signal:n,failed:o},r))}catch(e){throw Fa(e,a)}}function za(e,t,n,r={}){return Ra(e,t,n,r,Ba)}function Ba(e){return K(Na,e,`the decision`)}var Va=_({interface:_({type:g(`decision`),identity:_({handle:r()}),contract:r(),maxStateBytes:s().optional(),questions:l(Ma),build:_({input:t(r(),i()).optional()}).optional(),images:t(r(),_({mimeType:c([`image/png`,`image/jpeg`]),data:r()})).optional(),observability:_({record:m()}).optional()})});function Ha(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return K(Va,await Y(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i,a)=>za(`${t}/decide`,{state:n,...i?{assets:i}:{},...a===void 0?{}:{input:a}},r,e)}}function Ua(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Wa(e,t){let n=e;for(let e of t){if(!Ua(n))return;n=n[e]}return typeof n==`string`&&n?n:void 0}function Ga(...e){return t=>{let n=Wa(t,e);return n?[{url:n,sent:!0}]:[]}}var Ka={random_dog_image:Ga(`message`),wikipedia_summary:Ga(`originalimage`,`source`),get_pokemon:Ga(`sprites`,`other`,`official-artwork`,`front_default`)};function qa(e){return Ka[e]}function Ja(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e,t){let n=e[t];return typeof n==`string`&&n.trim()?n.trim():void 0}function Q(e,t){if(!URL.canParse(t))return;let n=new URL(t);if(n.protocol===`http:`||n.protocol===`https:`)return{title:e.trim()||n.hostname.replace(/^www\./,``),uri:n.href,type:`web`}}function Ya(e){let t=new Set;return e.filter(e=>!t.has(e.uri)&&(t.add(e.uri),!0))}function Xa(e){let t=[...e.matchAll(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g)].flatMap(e=>Q(e[1]??``,e[2]??``)??[]),n=[...e.matchAll(/https?:\/\/[^\s"'<>\]]+/g)].flatMap(e=>{let t=(e[0]??``).replace(/[),.;:]+$/,``);return Q(t,t)??[]});return Ya([...t,...n])}function Za(e){if(Array.isArray(e))return e;if(!Ja(e))return[];for(let t of[`items`,`results`,`search_results`,`models`,`datasets`]){let n=e[t];if(Array.isArray(n))return n}return[]}function Qa(e,t){return Ya(e.flatMap(e=>Ja(e)?t(e)??[]:[]))}function $a(e,t){let n=t===`dataset`?`https://huggingface.co/datasets/`:`https://huggingface.co/`;return Qa(Za(e),e=>{let t=Z(e,`id`)??Z(e,`modelId`);return t?Q(t,`${n}${t}`):void 0})}function eo(e){return Qa(Za(e),e=>{let t=Z(e,`html_url`),n=Z(e,`full_name`)??Z(e,`name`);return t?Q(n??t,t):void 0})}function to(e){let t=e,n;do n=t,t=t.replace(/<[^>]+>/g,``);while(t!==n);return t.replace(/\s+/g,` `).trim()}function no(e){if(typeof e!=`string`)return Xa(JSON.stringify(e));let t=[...e.matchAll(/<entry\b[\s\S]*?<\/entry>/g)];return t.length===0?Xa(e):Ya(t.flatMap(e=>{let t=/<id>(https?:\/\/[^<]+)<\/id>/.exec(e[0]??``)?.[1],n=/<title>([\s\S]*?)<\/title>/.exec(e[0]??``)?.[1];return t?Q(to(n??t),t)??[]:[]}))}function $(e){if(typeof e==`string`)return Xa(e);if(Array.isArray(e)||Ja(e)){let t=Qa(Za(e),e=>{let t=Z(e,`html_url`)??Z(e,`url`)??Z(e,`source_url`)??Z(e,`contentUrl`),n=Z(e,`title`)??Z(e,`name`)??t;return t?Q(n??t,t):void 0});return t.length>0?t:Xa(JSON.stringify(e))}return[]}var ro={search_models:e=>$a(e,`model`),search_datasets:e=>$a(e,`dataset`),search_github:eo,list_arxiv:no,search_web:$,read_pages:$,read_model_card:$,read_dataset_card:$,read_readme:$,find_library:$,read_library_docs:$,ask_repo_docs:$};function io(e){return ro[e]}function ao(e,t){let n=io(e);return n?{...t,sources:n}:t}function oo(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{},...t.after?{after:!0}:{},...t.background?{background:t.background}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:b(t.inputSchema),output:b(t.outputSchema)};if(t.type===`http`){let n=qa(t.name);e.register(ao(t.name,{...n?{media:n}:{},...i,type:`http`,endpoint:t.endpoint,method:t.method,headers:t.headers,mapping:t.mapping,auth:t.auth,maxResponseBytes:t.maxResponseBytes}));return}if(t.type===`mcp`){e.register(ao(t.name,{...i,type:`mcp`,serverUrl:t.serverUrl,mcpToolName:t.mcpToolName,headers:t.headers,auth:t.auth,maxResponseBytes:t.maxResponseBytes,session:t.session}));return}if(t.answeredBy===`page`){e.register({...i,type:`function`,answeredBy:`page`});return}let a=t.stubResponse||!Object.hasOwn(n,t.name)?void 0:n[t.name],o=t.stubResponse??Wt(t.outputSchema);e.register({...i,type:`function`,handler:a?e=>{try{return Promise.resolve(a(e))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}}:()=>Promise.resolve(o)})}function so(e,t,n){e.registerMany([...v,...y]);for(let r of t)oo(e,r,n)}function co(e,t,n,r,i){if(so(e.tools,n,i),r&&t.type!==`live`)for(let{id:t,spec:n}of[r,...r.also??[]])e.schemas.register(t,n);return e.profiles.register(t),t}function lo(e){if(e.type===`error`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,error:t}}if(e.type===`session`&&e.session.kind===`ended`&&e.errorInternal!==void 0){let{errorInternal:t,...n}=e;return{...n,session:{...e.session,message:t}}}if(e.type===`tool`&&e.tool.phase===`error`&&e.tool.failure.error!==void 0){let{failure:t}=e.tool;return{...e,tool:{...e.tool,failure:{...t,error:t.message}}}}return e}function uo(e){if(e.type!==`error`&&e.type!==`session`&&e.type!==`tool`&&e.type!==`hook_failed`||e.errorInternal===void 0)return e;let{errorInternal:t,...n}=e;return n}function fo(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function po(e){if(e.type!==`guardrail`||!(e.guardrail?.errorInternal||e.guardrail?.errorSummary))return e;let{errorInternal:t,errorSummary:n,...r}=e.guardrail;return{...e,guardrail:r}}function mo(e){if(e.type!==`done`||e.mediaRefused===void 0)return e;let{mediaRefused:t,...n}=e;return n}function ho(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function go(e,t){if(e.type!==`tool`||e.tool.phase!==`progress`)return e;let{data:n}=e.tool;if(typeof n!=`object`||!n||!(`agent`in n)||!(`event`in n))return e;let r=_o(n.event,t);return{...e,tool:{...e.tool,data:{...n,event:r}}}}function _o(e,t){let n=go(e,t),r=t?.reader===`builder`?lo(n):mo(fo(po(uo(n))));return t?.includeEvidenceRaw||(r=ho(r)),r=qt(r,!1),r}function vo(e,t){return e.map(e=>_o(e,t))}function yo(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=_o(Ze(pt(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var bo={reader:`builder`};function xo(e){return e.mode===`demo`?{reader:`visitor`}:bo}export{Gn as $,zi as A,Fr as B,ca as C,J as D,va as E,ai as F,fr as G,gr as H,ii as I,rr as J,lr as K,Br as L,Hi as M,G as N,Xi as O,ki as P,ir as Q,$r as R,la as S,ua as T,ur as U,Pr as V,dr as W,nr as X,Xn as Y,ar as Z,Ta as _,vo as a,zn as at,xa as b,Ha as c,Gt as ct,Ia as d,Wn as et,za as f,ia as g,ea as h,_o as i,Bn as it,Wi as j,K as k,ka as l,qt as lt,Fa as m,xo as n,Un as nt,co as o,Zt as ot,Ra as p,sr as q,yo as r,R as rt,so as s,Kt as st,bo as t,Hn as tt,Oa as u,ya as v,aa as w,Sa as x,Y as y,Xr as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as u,t as d,v as f}from"./schemas-D7cgkv3L.js";import{Cn as ee,Ia as p,Q as te,Qi as ne,Ra as re,Sa as m,hi as ie,it as ae,li as oe,lo as h,q as se,si as g,ut as _,vi as v,xa as y,za as b}from"./shaped-data-KV3CIOIt.js";import{c as x}from"./host-patterns-F-KZIzkF.js";import{c as ce,d as le,i as S,n as C,o as ue,t as w,u as de}from"./schema-tNBJA-hy.js";var fe=n({accepted:y,preparedInput:m});function T(e){return new x(`internal`,e)}function E(e,t,n){return new x(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function D(e){return E(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function O(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=m.parse(t(P(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 k=g.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),A=n({finding:t(),data:m.optional(),parts:a(oe).optional(),media:a(ie).optional(),hidden:f(!0).optional(),modelText:t().optional(),provenance:b.optional(),suspicious:a(re).optional()}),j=g.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),M=n({event:j,replay:n({modelResult:A})}),N=n({event:k,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:A.optional(),outputRaw:m.optional(),failure:n({code:t(),kind:p,message:t(),error:t().optional(),details:m.optional()}).optional(),awaiting:c().optional(),denied:f(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(v),released:r().int().nonnegative().optional(),promote:a(t().min(1)).optional()})).optional(),ended:f(!0).optional()})});function P(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw T(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw T(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw T(`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 T(`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 m.parse(n(e))}var F=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),I=`background`;function L(){return c().optional().describe(h(`tool.background_field`))}function R(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[I]:n,...r}=t;return{input:r,asked:n===!0}}function z(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?R(e,t).asked?`claim`:void 0:n}function B(e,t){return e.type===`agent`?t?.takesSteers(e)?void 0:`steering_off`:`not_agent`}function V(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||t.type===`builtin`||!n)return;let a=z(t,e.input);if(a===void 0)return;let o=B(t,e.agents);return{at:a,support:n,...o?{refuseSteers:o}:{},trace:n.openTrace(r.callId),reply:()=>{let e={finding:h(`tool.background_started`,{tool:t.name},i)},n=te(e),a=se(r,{phase:`background`,readBack:n});return M.parse(P({event:a,replay:{modelResult:e}}))}}}function pe(e,t){if(e&&!t?.detach)throw new x(`config`,`A request with a background service needs a coordinator with detach`)}function me(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new x(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!F.safeParse(n).success)throw new x(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var he=/^[\x21-\x7E]{1,256}$/;function H(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 ge(e){return e!==null&&he.test(e)}async function _e(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 U=`after`;function ve(){return a(t()).optional().describe(h(`tool.after_field`))}function W(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new x(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof d){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof u)return e(n.options.map(a));throw new x(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function G(e,t){return W(e,t,U,ve)}function ye(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[U]:n,...r}=t;return{input:r,names:n??[]}}function be(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 K=class{value;constructor(e){this.value=e}};function xe(e){return new K(e)}function Se(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return xe(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(h(`tool.page_timed_out`,{},i)):Error(h(`tool.page_no_answer`,{tool:e},i))}}var q=new WeakMap;function J(e,t){let n=q.get(e);n||(n=new WeakMap,q.set(e,n));let r=n.get(t);if(!r){let i=C(e,`input`);S(i,`input`);let a=C(t,`output`);S(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Y(e){let{inputSchema:t,outputSchema:n}=J(e.input,e.output);_(t,`Tool "${e.name}" input`,`input`),_(n,`Tool "${e.name}" output`,`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?ae(n,r[t]):void 0;if(i)throw new x(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Ce(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new x(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function X(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 x(`config`,`Tool "${e}" auth.queryParam ${r}`)}function we(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new x(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function Z(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new x(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Q(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new x(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Te(e){Q(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Q(e.name,`imageLimits.count`,t.count),Q(e.name,`imageLimits.bytes`,t.bytes),Q(e.name,`imageLimits.totalBytes`,t.totalBytes),Z(e.name,t.timeoutMs))}function $(e){if(e.type!==`builtin`&&me({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;Ce(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&w(e.endpoint),X(e.name,e.auth,e.mapping?.queryParams),we(e.name,e.limit),Z(e.name,e.timeoutMs)):X(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Te(e),e.type===`mcp`&&(Q(e.name,`session.idleMs`,e.session?.idleMs),Q(e.name,`session.max`,e.session?.max));let[t]=ne(e);if(t)throw new x(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function Ee(e){return w(e.endpoint),{...e,type:`http`,...Y(e)}}function De(e){return{...e,type:`mcp`,...Y(e)}}function Oe(e){let t=e.answeredBy===`page`?Se(e.name):e.handler;if(typeof t!=`function`)throw new x(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...Y(e)}}function ke(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=W(e.name,t,`background`,L);return{...e,askInputSchema:J(n,e.output).inputSchema}}function Ae(e,t,n){return $(e),ke(je(e,t,n))}function je(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=de(e,t,n),i=ee(r),a=ue({type:r.type,...i?{inputs:i}:{}},e),o=e.after?G(e.name,a):a,s=Y({...e,input:o,output:ce});return le(e,o,s)}let r=e.after?{...e,input:G(e.name,e.input)}:e;return r.type===`http`?Ee(r):r.type===`mcp`?De(r):Oe(r)}function Me(e=()=>void 0,t=()=>[]){let n=new Map,r=H(),i=e=>n.get(e),a=t=>{let r=Ae(t,e,i);return n.set(r.name,r),r};return{register:a,registerMany:e=>e.map(e=>a(e)),get:i,require(e){let t=i(e);if(!t)throw new x(`config`,`Tool '${e}' is not registered`);return t},has:e=>n.has(e),list:()=>[...n.values()],findProfile:e,structuredReplies:t,reset:()=>{n.clear(),r.clear()},mcpSessions:r}}export{N as _,be as a,_e as c,R as d,D as f,O as g,fe as h,ye as i,pe as l,P as m,Me as n,H as o,T as p,K as r,ge as s,$ as t,V as u,M as v,E as y};
|
|
1
|
+
import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as u,t as d,v as f}from"./schemas-D7cgkv3L.js";import{Cn as ee,Ia as p,Q as te,Qi as ne,Ra as re,Sa as m,hi as ie,it as ae,li as oe,lo as h,q as se,si as g,ut as _,vi as v,xa as y,za as b}from"./shaped-data-KV3CIOIt.js";import{c as x}from"./host-patterns-F-KZIzkF.js";import{c as ce,d as le,i as S,n as C,o as ue,t as w,u as de}from"./schema-2nKQb1q-.js";var fe=n({accepted:y,preparedInput:m});function T(e){return new x(`internal`,e)}function E(e,t,n){return new x(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function D(e){return E(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function O(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=m.parse(t(P(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 k=g.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),A=n({finding:t(),data:m.optional(),parts:a(oe).optional(),media:a(ie).optional(),hidden:f(!0).optional(),modelText:t().optional(),provenance:b.optional(),suspicious:a(re).optional()}),j=g.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),M=n({event:j,replay:n({modelResult:A})}),N=n({event:k,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:A.optional(),outputRaw:m.optional(),failure:n({code:t(),kind:p,message:t(),error:t().optional(),details:m.optional()}).optional(),awaiting:c().optional(),denied:f(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(v),released:r().int().nonnegative().optional(),promote:a(t().min(1)).optional()})).optional(),ended:f(!0).optional()})});function P(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw T(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw T(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw T(`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 T(`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 m.parse(n(e))}var F=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),I=`background`;function L(){return c().optional().describe(h(`tool.background_field`))}function R(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[I]:n,...r}=t;return{input:r,asked:n===!0}}function z(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?R(e,t).asked?`claim`:void 0:n}function B(e,t){return e.type===`agent`?t?.takesSteers(e)?void 0:`steering_off`:`not_agent`}function V(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||t.type===`builtin`||!n)return;let a=z(t,e.input);if(a===void 0)return;let o=B(t,e.agents);return{at:a,support:n,...o?{refuseSteers:o}:{},trace:n.openTrace(r.callId),reply:()=>{let e={finding:h(`tool.background_started`,{tool:t.name},i)},n=te(e),a=se(r,{phase:`background`,readBack:n});return M.parse(P({event:a,replay:{modelResult:e}}))}}}function pe(e,t){if(e&&!t?.detach)throw new x(`config`,`A request with a background service needs a coordinator with detach`)}function me(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new x(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!F.safeParse(n).success)throw new x(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var he=/^[\x21-\x7E]{1,256}$/;function H(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 ge(e){return e!==null&&he.test(e)}async function _e(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 U=`after`;function ve(){return a(t()).optional().describe(h(`tool.after_field`))}function W(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new x(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof d){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof u)return e(n.options.map(a));throw new x(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function G(e,t){return W(e,t,U,ve)}function ye(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[U]:n,...r}=t;return{input:r,names:n??[]}}function be(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 K=class{value;constructor(e){this.value=e}};function xe(e){return new K(e)}function Se(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return xe(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(h(`tool.page_timed_out`,{},i)):Error(h(`tool.page_no_answer`,{tool:e},i))}}var q=new WeakMap;function J(e,t){let n=q.get(e);n||(n=new WeakMap,q.set(e,n));let r=n.get(t);if(!r){let i=C(e,`input`);S(i,`input`);let a=C(t,`output`);S(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Y(e){let{inputSchema:t,outputSchema:n}=J(e.input,e.output);_(t,`Tool "${e.name}" input`,`input`),_(n,`Tool "${e.name}" output`,`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?ae(n,r[t]):void 0;if(i)throw new x(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Ce(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new x(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function X(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 x(`config`,`Tool "${e}" auth.queryParam ${r}`)}function we(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new x(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function Z(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new x(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Q(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new x(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Te(e){Q(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Q(e.name,`imageLimits.count`,t.count),Q(e.name,`imageLimits.bytes`,t.bytes),Q(e.name,`imageLimits.totalBytes`,t.totalBytes),Z(e.name,t.timeoutMs))}function $(e){if(e.type!==`builtin`&&me({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;Ce(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&w(e.endpoint),X(e.name,e.auth,e.mapping?.queryParams),we(e.name,e.limit),Z(e.name,e.timeoutMs)):X(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Te(e),e.type===`mcp`&&(Q(e.name,`session.idleMs`,e.session?.idleMs),Q(e.name,`session.max`,e.session?.max));let[t]=ne(e);if(t)throw new x(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function Ee(e){return w(e.endpoint),{...e,type:`http`,...Y(e)}}function De(e){return{...e,type:`mcp`,...Y(e)}}function Oe(e){let t=e.answeredBy===`page`?Se(e.name):e.handler;if(typeof t!=`function`)throw new x(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...Y(e)}}function ke(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=W(e.name,t,`background`,L);return{...e,askInputSchema:J(n,e.output).inputSchema}}function Ae(e,t,n){return $(e),ke(je(e,t,n))}function je(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=de(e,t,n),i=ee(r),a=ue({type:r.type,...i?{inputs:i}:{}},e),o=e.after?G(e.name,a):a,s=Y({...e,input:o,output:ce});return le(e,o,s)}let r=e.after?{...e,input:G(e.name,e.input)}:e;return r.type===`http`?Ee(r):r.type===`mcp`?De(r):Oe(r)}function Me(e=()=>void 0,t=()=>[]){let n=new Map,r=H(),i=e=>n.get(e),a=t=>{let r=Ae(t,e,i);return n.set(r.name,r),r};return{register:a,registerMany:e=>e.map(e=>a(e)),get:i,require(e){let t=i(e);if(!t)throw new x(`config`,`Tool '${e}' is not registered`);return t},has:e=>n.has(e),list:()=>[...n.values()],findProfile:e,structuredReplies:t,reset:()=>{n.clear(),r.clear()},mcpSessions:r}}export{N as _,be as a,_e as c,R as d,D as f,O as g,fe as h,ye as i,pe as l,P as m,Me as n,H as o,T as p,K as r,ge as s,$ as t,V as u,M as v,E as y};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{A as e,C as t,D as n,E as r,O as i,T as a,b as o,c as s,d as c,f as ee,v as l,x as te}from"./schemas-D7cgkv3L.js";import{Cn as ne,Da as u,Ni as d,Nt as re,Oa as f,Sn as p,Tn as m,at as ie,bn as ae,ct as oe,di as se,ft as ce,hi as le,hn as h,lo as ue,ot as de,pi as fe,xn as pe}from"./shaped-data-KV3CIOIt.js";import{c as g}from"./host-patterns-F-KZIzkF.js";var me=2,he=4,ge=3,_e=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,ve=/^[A-Za-z0-9+/]*={0,2}$/,ye=new Set([`text/csv`,`text/plain`,`text/markdown`]);function _(e){let{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}=e;if(t&&n&&r)return{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}}function be(e,t){if(t.limitsByMime){let n=m(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function v(e){return`uri`in e}function xe(e){if(e.type===`speech`)throw new g(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new g(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new g(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=_(e.inputs??{});if(!t)throw new g(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function Se(e){let t=0;return e.endsWith(`==`)?t=me:e.endsWith(`=`)&&(t=1),Math.floor(e.length*ge/he)-t}var y=[[`utf-8`,[239,187,191]],[`utf-16le`,[255,254]],[`utf-16be`,[254,255]]],b=32768,x=/(;\s*charset\s*=\s*)("[^"]*"|[^;\s]+)/i,S=`windows-1252`,C=new Map;function w(e){return x.exec(e)?.[2]?.replaceAll(`"`,``).toLowerCase()}function Ce(e){try{return new TextDecoder(e).encoding}catch{return}}function T(e){let t=C.get(e);if(t!==void 0)return t;let n=new TextDecoder(e),r=Array.from({length:256},(e,t)=>n.decode(Uint8Array.of(t))),i=new Map(r.map((e,t)=>[e,t])),a=r.every(e=>e.length===1)&&i.size===256?{chars:r,bytes:i}:null;return C.set(e,a),a}function we(e){try{return new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}).decode(e)}catch{return}}function Te(e,t){for(let[e,n]of y)if(n.every((e,n)=>t[n]===e)){let r=t.subarray(n.length);return{text:D({kind:e},r),encoding:{kind:e},bom:!0}}let n=w(e),r=n===void 0?void 0:Ce(n);if(r===`utf-16le`||r===`utf-16be`)return E({kind:r},t);let i=r===void 0||r===`utf-8`?null:T(r);if(i)return E({kind:`table`,table:i},t);if(r!==void 0&&r!==`utf-8`)return E({kind:`bytes`,name:r},t);let a=we(t);if(a!==void 0)return{text:a,encoding:{kind:`utf-8`},bom:!1};let o=T(S);if(!o)throw new g(`internal`,`${S} has no byte table`);return E({kind:`table`,table:o},t)}function E(e,t){return{text:D(e,t),encoding:e,bom:!1}}function D(e,t){if(e.kind===`utf-8`||e.kind===`utf-16le`||e.kind===`utf-16be`)return new TextDecoder(e.kind,{ignoreBOM:!0}).decode(t);let n=e.kind===`table`?e.table.chars:void 0,r=``;for(let e=0;e<t.length;e+=b){let i=t.subarray(e,e+b);r+=n?Array.from(i,e=>n[e]).join(``):String.fromCharCode(...i)}return r}function Ee(e,t){if(e.kind===`utf-8`)return new TextEncoder().encode(t);if(e.kind===`utf-16le`||e.kind===`utf-16be`){let n=new Uint8Array(t.length*2),r=new DataView(n.buffer);for(let n=0;n<t.length;n++)r.setUint16(n*2,t.charCodeAt(n),e.kind===`utf-16le`);return n}let n=e.kind===`table`?e.table.bytes:void 0,r=[];for(let e of t){let t=n?n.get(e):De(e);t===void 0?r.push(...new TextEncoder().encode(e)):r.push(t)}return Uint8Array.from(r)}function De(e){let t=e.charCodeAt(0);return e.length===1&&t<=255?t:void 0}function Oe(e){return e.replace(_e,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function O(e){return ye.has(m(e))}function k(e,t){let n;try{n=u(t)}catch{return null}return Te(e,n)}function ke(e,t){return k(e,t)!==null}function A(e,t){let n=k(e,t);if(n===null)throw new g(`internal`,`A text file was read before its bytes were checked`);return n.text}function j(e,t,n){let r=k(e,t);if(r===null)throw new g(`internal`,`A text file was written before its bytes were checked`);if(r.text===n)return t;let i=r.bom?y.find(([e])=>e===r.encoding.kind)?.[1]??[]:[],a=Ee(r.encoding,n),o=new Uint8Array(i.length+a.length);return o.set(i),o.set(a,i.length),f(o)}function M(e,t){let n=k(e,t);if(n===null)throw new g(`internal`,`A text file was read before its bytes were checked`);let r=n.encoding.kind===`bytes`?new TextDecoder(n.encoding.name).decode(u(t)):n.text,i=m(e)===`text/csv`?Oe(r):r;return n.encoding.kind===`utf-8`&&!n.bom&&i===n.text?{mimeType:e,data:t}:{mimeType:Ae(e),data:je(i)}}function Ae(e){return w(e)===void 0?e:e.replace(x,`$1utf-8`)}function je(e){return f(new TextEncoder().encode(e))}function N(e,t){return t?{...e,fileName:t}:e}function P(e,t,n){return t.filter(t=>!pe(e,t.mimeType)).map(e=>N({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function Me(e,t){let n=[];e.length>t.maxFiles&&n.push({code:`too_many_files`,params:{maxFiles:t.maxFiles}});let r=0;for(let i of e){if(i.sizeBytes===void 0)continue;let e=be(i.mimeType,t);i.sizeBytes>e&&n.push(N({code:`file_too_large`,params:{maxBytes:e}},i.name)),r+=i.sizeBytes}return r>t.maxTurnBytes&&n.push({code:`turn_too_large`,params:{maxTurnBytes:t.maxTurnBytes}}),n}function F(e,t,n){let r=[];return t.length>0&&!e.attachments&&r.push({code:`attachments_not_accepted`,params:{channel:`attachment`}}),n.length>0&&!e.voice&&r.push({code:`voice_not_accepted`,params:{channel:`voice`}}),r.length>0||t.length===0&&n.length===0?r:(e.attachments&&r.push(...P(e.attachments,t,`attachment`)),e.voice&&r.push(...P(e.voice,n,`voice`)),e.limits?[...r,...Me([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var Ne={mime_not_allowed:`attachments.mime_not_allowed`,too_many_files:`attachments.too_many_files`,too_many_of_kind:`attachments.too_many_of_kind`,file_too_large:`attachments.file_too_large`,turn_too_large:`attachments.turn_too_large`,attachments_not_accepted:`attachments.not_accepted`,voice_not_accepted:`attachments.not_accepted`,limits_unconfigured:`attachments.limits_unconfigured`};function I(e){let t={};for(let[n,r]of Object.entries(e.params??{}))r!==void 0&&(t[n]=r);return e.fileName!==void 0&&(t.fileName=e.fileName),{key:Ne[e.code],params:t}}function Pe(e,t){let n=I(e);return ue(n.key,n.params,t)}function Fe(e){return new g(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(I)})}function L(e){if(!ve.test(e))throw new g(`request`,`attachment data must be base64`);return Se(e)}function R(e){let t={mimeType:e.mimeType,name:e.name};return v(e)||(t.sizeBytes=L(e.data)),t}function Ie(e,t,n){if(!Le(t,n))return;let r=xe(e),i=F({attachments:p(e,`attachments`),voice:p(e,`voice`),limits:r},(t??[]).map(R),(n??[]).map(R));if(i.length>0)throw Fe(i)}function z(e,t){if(v(e))return e;let{mimeType:n,data:r}=e;if(!O(n))return e;let i=M(n,r),a=A(i.mimeType,i.data),o=t.read(a);return{...e,mimeType:i.mimeType,data:j(i.mimeType,i.data,o)}}function Le(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Re(e,t,n,r){return Ie(e,t,n),{attachments:t?.length?t.map(e=>z(e,r.attachment)):t,voice:n?.length?n.map(e=>z(e,r.voice)):n}}var ze=`
|
|
2
|
+
|
|
3
|
+
`;function Be(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function Ve(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=Be(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function B(e,t){let n=Ve(e,t);if(n)throw new g(`config`,n)}function He(e,t,n){return B(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Ue(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function V(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:ze,private:!0}),t.push(...n));return t}function We(e){return e.map(e=>e.text).join(``)}function Ge(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:We(e),private:t}}function Ke(e,t){return Ge(V([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var qe=/^[A-Za-z_][\w-]*$/,Je=/\{([A-Za-z_][\w-]*)\}/g,Ye=[`input`,`output`];function H(e){return e.choices.map(e=>e.value)}function U(e){return(e.type===`text`||e.type===`image`||e.type===`live`?e.identity.options:void 0)??{}}function Xe(e){return ne(e)?.options??{}}function Ze(e,t){let n={...U(e),...Xe(e)};return Object.hasOwn(n,t)?n[t]:void 0}function Qe(e,t){if(!qe.test(e))return`Option "${e}" needs a plain name.`;if(Ye.includes(e))return`Option "${e}" is a reserved name.`;let n=Array.isArray(t.choices)?H(t):[];if(n.length===0)return`Option "${e}" lists no values.`;let r=n.find(e=>!e.trim()||e===`null`);return r===void 0?void 0:`Option "${e}" can't take the value "${r}".`}function $e(e,t){for(let[n,r]of Object.entries({...e,...t})){if(e&&t&&Object.hasOwn(e,n)&&Object.hasOwn(t,n))return`"${n}" is on both identity.options and inputs.options.`;let i=Qe(n,r);if(i)return i}}function et(e,t,n,r){for(let[i,a]of Object.entries(r??{})){let r=Object.hasOwn(t,i)?t[i]:void 0;if(!r)throw new g(`request`,`Profile ${e} has no option '${i}' on ${n}`);let o=H(r);if(!o.includes(a))throw new g(`request`,`Profile ${e}: option '${i}' takes ${o.join(`, `)}, not '${a}'`)}}function tt(e,t){return Object.hasOwn(e,`path`)&&t.path!==void 0?{path:t.path}:{}}function nt(e,t){let n=U(e);if(t.options&&Object.hasOwn(t.options,`path`))throw new g(`request`,`Profile ${e.id}: the turn's own path states path`);et(e.id,n,`identity.options`,{...t.options,...tt(n,t)}),et(e.id,Xe(e),`inputs.options`,t.input?.options)}function rt(e,t){return{...t.options,...tt(U(e),t),...t.input?.options}}function it(e,t,n){let r=!0,i=t.replace(Je,(t,i)=>{if(!Ze(e,i))return t;let a=Object.hasOwn(n,i)?n[i]:void 0;return a===void 0&&(r=!1),a??t});return r?i:void 0}function at(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function ot(e){return typeof e==`string`?e:e.private}function st(e){return oe(e[0]===void 0?``:ot(e[0]))}function ct(e){let t={};for(let[n,r]of Object.entries(e))t[n]={type:`string`,enum:H(r)};return{type:`object`,properties:t}}function lt(e,t){if(e.length===0)return`It has no wording to send.`;let n=st(e);if(n.joined)return`A prompt line can't start with "+"; every line that fits is sent.`;if(n.when===`unreadable`)return`A line that opens with "when" needs an option and a colon, like "when path is web: …".`;for(let e of n.when){if(e.path.includes(`.`))return`"${e.path}" isn't one option.`;if(`has`in e)return`An option is one value, so it has no fields.`;if(e.expected===null)return`An option has no null value, so "is null" never fits.`;let n=de(e,t,`this profile’s options`);if(n)return n}if(n.when.length>0&&!n.text&&e.length===1)return`It has no wording to send.`}function ut(e,t,n){let r=$e(t,n);if(r)return r;let i=ct({...t,...n});for(let[t,n]of at(e).entries()){let e=lt(n,i);if(e)return`Line ${t+1}: ${e}`}}function dt(e,t){return e.when!==`unreadable`&&e.when.every(e=>ie(e,t))}function ft(e,t,n){let r=at(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=st(o);if(!dt(r,t))continue;let s=o.map((e,t)=>n(t===0?r.text:ot(e)));if(s.includes(void 0))continue;let c=o.flatMap((e,t)=>{let n=s[t];return n?[{text:n,private:typeof e!=`string`||!i}]:[]});a.push({line:e+1,pieces:c})}return a}function pt(e,t){if(typeof e!=`string`){if(!Array.isArray(e))throw new g(`config`,`${t} must be a string or an array of lines`);if(e.length===0)throw new g(`config`,`${t} must not be an empty array`);for(let[n,r]of e.entries())if(typeof r!=`string`){if(!Array.isArray(r))throw new g(`config`,`${t}[${n}] must be a string or a list of parts; put { private } inside the list`);B(r,`${t}[${n}]`)}}}function mt(e,t){let n=e?.path;if(!n)return;let r=H(n);for(let e of t){let t=e.paths?.find(e=>e!==`*`&&!r.includes(e));if(t!==void 0)return`Tool ${e.name} lists path "${t}", which is not one of ${r.join(`, `)}.`}}function W(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function G(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ht(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function K(e){return`tools`in e?e.tools.allow:[]}function q(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function gt(e){return`tools`in e?e.tools.parallel:void 0}function _t(e,t,n){return K(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||G(i.paths,n.path)})}function vt(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&G(r.paths,n.path)}):[]}function yt(e,t,n){let r=e.get(t);if(r&&r.type!==`builtin`)return{type:`function`,name:r.name,description:r.description,parameters:ce(n&&r.askInputSchema||r.inputSchema)}}function bt(e,t,n){let r=[];for(let i of t){let t=yt(e,i,n);t&&r.push(t)}return r}function xt(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=yt(e,n,t.modelBackground);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function St(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function Ct(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function wt(e,t,n){return ht(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function Tt(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=K(t).flatMap(t=>e.get(t)??[]),r=mt(t.identity.options,n);if(r)throw new g(`config`,`Profile ${t.id}: ${r}`)}function Et(e,t){let n=q(t)?.t2Loader,r=n===void 0?void 0:e.get(n);if(r&&r.type!==`builtin`&&(r.background??`never`)!==`never`)throw new g(`config`,`Profile ${t.id}: tools.t2Loader '${r.name}' sets background, and a loader cannot detach`)}function Dt(e,t,n,r){Tt(e,t),Et(e,t);let i=_t(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:vt(e,t,n,r),o=[...i,...a],s=wt(e,t,o),c=Ct(e,t,o),ee=c.filter(t=>W(e,t)),l=n.background!==void 0;return{builtins:s,gated:o,visible:c,executable:ee,path:n.path,sessionPermissions:n.sessionPermissions,wire:bt(e,c,l),...l?{modelBackground:l}:{}}}function Ot(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)})),...e.modelBackground?{modelBackground:e.modelBackground}:{}}}async function kt(e,t,n,r){try{await At(e,t,n,r)}catch(e){return{crashed:e}}}async function At(e,t,n,r){let i=q(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new g(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new g(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);jt(e,t,a)}function jt(e,t,n=[]){for(let r of n){if(!t.gated.includes(r))continue;let n=e.get(r);n?.loadTier===`T2`&&(n.type===`builtin`?St(e,t,r):xt(e,t,r))}t.executable=t.visible.filter(t=>W(e,t))}var Mt=new Set([`__proto__`,`constructor`,`prototype`]);function Nt(e){if(!h(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Pt(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Mt.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=Ft(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;G(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)xt(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>W(e,t)),{promoted:a}}function J(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function Ft(e,t,n){if(!K(n).includes(t))return J(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?J(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:J(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):J(`tools.t2Loader attempted to promote unknown tool '${t}'`)}var It=r().regex(/\S/),Lt=t(r(),i()).optional(),Rt=a({type:l(`text`),text:r()}),zt=a({type:s(d),mimeType:It,data:r().min(1),sent:l(!0).optional(),metadata:Lt}).refine(e=>!O(e.mimeType)||ke(e.mimeType,e.data),{path:[`data`],message:`A text file must be base64, so it can be decoded and read`}),Y=a({type:s(d),mimeType:It,uri:r().min(1),metadata:Lt}),Bt=n([Rt,zt,Y]);function Vt(e){return h(e)&&e.type===`text`?Rt:h(e)&&`uri`in e?Y:zt}function Ht(e){if(!h(e)||e.parts===void 0)return[];let t=c(i()).safeParse(e.parts);return t.success?t.data.flatMap((e,t)=>{let n=Vt(e).safeParse(e);return n.success?[]:n.error.issues.map(e=>X(e,[t]))}):t.error.issues.map(e=>X(e,[]))}function X(e,t){return{path:[`parts`,...t,...e.path],message:e.message}}function Ut(e){if(!h(e)||e.parts===void 0)return;let t=c(le).safeParse(e.parts);if(!t.success)throw new g(`internal`,`Tool parts were read before they were checked`);return t.data.length>0?t.data:void 0}var Wt=new Set([`text`,`image`,`speech`]),Gt=r().regex(/\S/),Kt=a({mimeType:r(),data:ee(),name:r().optional()}),qt=a({mimeType:r(),uri:r(),name:r().optional()}),Jt=a({voice:r().optional(),style:r().optional(),speed:o().positive().optional()});function Yt(e){return a(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=H(t);return[e,s(n).optional()]})))}var Xt=new Set([`text`,`attachments`,`voice`,`options`,`speech`]);function Zt(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,options:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{options:s}:{},...c?{speech:c}:{}},hostInput:r}}function Qt(e,t){let{inputs:r}=e,i={text:Gt};r?.attachments&&(i.attachments=c(n([Kt,qt])).optional()),r?.voice&&(i.voice=c(Kt).optional()),r?.options&&(i.options=Yt(r.options).optional()),e.type===`speech`&&(i.speech=Jt.optional());for(let e of t?.hostOnly??[]){if(!i[e])throw new g(`config`,`Tool '${t?.name}' keeps '${e}' for the host, which its profile does not take`);delete i[e]}for(let[e,n]of Object.entries(t?.fieldText??{})){let r=i[e];if(!r)throw new g(`config`,`Tool '${t?.name}' describes '${e}', which its profile does not take`);i[e]=r.describe(n)}for(let[e,n]of Object.entries(t?.hostFields??{})){if(Xt.has(e))throw new g(`config`,`Tool '${t?.name}' declares the host field '${e}', which is a field of every agent tool`);i[e]=n}return a(i)}var $t=te({text:r().optional(),structured:i().optional(),removed:c(te({path:r(),reason:r(),item:i()})).optional(),parts:c(Bt).optional(),sources:c(fe).optional()});function en(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function tn(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Z(e,t){if(!Wt.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!en(e))return`it does not take text`;for(let n of K(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(tn(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function nn(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new g(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new g(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=Z(a,n);if(o)throw new g(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function rn(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return K(e).length===0&&!t?`local`:`delegated`}function an(e){let t=se(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=re(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:ae(e.media.mimeType)??`document`,mimeType:e.media.mimeType,data:e.media.data,sent:!0}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function on(e,t,n){return{...e,type:`agent`,input:t,output:$t,sources:e=>e.sources??[],...n}}function sn(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function cn(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&Q(i,`${n}.properties.${t}`,r)}function Q(e,t,n){if(!sn(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&cn(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&Q(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&Q(e,`${t}.${r}[${i}]`,n)})}}function ln(e,t){let n=[];if(Q(e,`$`,n),n.length>0)throw new g(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}var un=`object`;function dn(t,n=`output`){let r=e(t,{target:`draft-7`,io:n});return delete r.$schema,r.type||=un,r}function $(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map($);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=$(e[n]));return t}function fn(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new g(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}export{H as A,Fe as B,jt as C,ut as D,ft as E,V as F,_ as G,O as H,He as I,A as J,j as K,Ue as L,Ze as M,rt as N,nt as O,Ke as P,Pe as R,Pt as S,pt as T,v as U,L as V,M as W,Ot as _,Z as a,gt as b,$t as c,on as d,Zt as f,kt as g,Y as h,ln as i,$e as j,it as k,an as l,Ht as m,dn as n,Qt as o,Ut as p,Re as q,$ as r,rn as s,fn as t,nn as u,Nt as v,Dt as w,q as x,K as y,F as z};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{i as e,o as t}from"./tool-schema-
|
|
1
|
+
import{i as e,o as t}from"./tool-schema-DllL3wqs.js";import{Ji as n,xi as r}from"./shaped-data-KV3CIOIt.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,8 +1,8 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/studio-monaco-C20o5PnA.js","assets/preload-helper-DpV6A1kQ.js","assets/editor.api-BldS301e.js","assets/editor-DjpsE8to.css","assets/studio-monaco-BkNqudm7.css","assets/register-BLInT6S0.js","assets/studio-type-checker-
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./preload-helper-DpV6A1kQ.js";import{
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/studio-monaco-C20o5PnA.js","assets/preload-helper-DpV6A1kQ.js","assets/editor.api-BldS301e.js","assets/editor-DjpsE8to.css","assets/studio-monaco-BkNqudm7.css","assets/register-BLInT6S0.js","assets/studio-type-checker-vtYkUAwV.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{t as r}from"./preload-helper-DpV6A1kQ.js";import{F as i,N as a,j as o}from"./tool-schema-DllL3wqs.js";import{Ha as s,It as c,Ka as l,Lt as u,Zi as d,ga as f,ra as p,wi as m}from"./shaped-data-KV3CIOIt.js";import{c as h}from"./host-patterns-F-KZIzkF.js";import{X as g,b as _,g as v,h as y,m as ee,w as b,x,y as S}from"./tree-I-6ZPGON.js";import{r as C}from"./live-ingress-OuSlQ6q7.js";import{t as te}from"./registry-BuJuTraO.js";import{n as ne,t as re}from"./types-Bl7WithI.js";import{n as ie}from"./stub-CXS-AHtL.js";import{I as w,M as ae,k as oe,r as se}from"./workspace-BI6bC1mm.js";import{O as ce,nt as le}from"./index-fyDzED1x.js";var T=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},ue=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 T(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 E(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function D(e){e.skip();let t=e.peek();t!==`'`&&t!==`"`&&e.fail(`Expected a string.`),e.bump();let n=``;for(;!e.done&&e.peek()!==t;){let t=e.bump();if(t!==`\\`){n+=t;continue}let r=e.bump(),i={n:`
|
|
6
6
|
`,r:`\r`,t:` `,"\\":`\\`,"'":`'`,'"':`"`};if(r in i)n+=i[r];else if(r===`u`){let t=``;for(let n=0;n<4;n+=1)t+=e.bump();n+=String.fromCharCode(Number.parseInt(t,16))}else n+=r}return e.peek()!==t&&e.fail(`This string never closes.`),e.bump(),n}function de(e){e.skip();let t=e.pos(),n=``;for(e.peek()===`-`&&(n+=e.bump());/^[0-9.eE+-]/.test(e.peek())&&n.length<64;)n+=e.bump();let r=Number(n);if(!Number.isFinite(r))throw new T(`'${n}' is not a number.`,t.line,t.column);return r}function O(e,t,n,r){let i=0;for(;!e.done;){if(r()&&i===0)return;let a=e.peek();a===`'`||a===`"`?D(e):(a!==``&&t.includes(a)?i+=1:a!==``&&n.includes(a)&&--i,e.bump())}}function fe(e){O(e,`<([{`,`>)]}`,()=>(e.skip(),e.peek()===`;`||e.peek()===`
|
|
7
7
|
`))}function pe(e){O(e,`{([`,`})]`,()=>e.peek()===`;`),e.peek()===`;`&&e.bump()}function me(e,t,n){e.expect(`{`);let r={};for(;!e.eat(`}`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`);let i=e.pos(),a;if(a=e.peek()===`'`||e.peek()===`"`?D(e):e.expectIdent(),a===`__proto__`)throw new T(`'__proto__' sets what an object inherits, not a setting.`,i.line,i.column);if(Object.hasOwn(r,a))throw new T(`'${a}' is set twice.`,i.line,i.column);let o=t?`${t}.${a}`:a;n.push({path:o,line:i.line,column:i.column}),e.expect(`:`),r[a]=F(e,o,n),e.eat(`,`),e.done&&e.fail(`This object never closes.`)}return r}function he(e,t,n){e.expect(`[`);let r=[],i=0;for(;!e.eat(`]`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`),e.skip();let a=e.pos(),o=t?`${t}.${String(i)}`:String(i);n.push({path:o,line:a.line,column:a.column}),r.push(F(e,o,n)),i+=1,e.eat(`,`),e.done&&e.fail(`This array never closes.`)}return r}function ge(e,t,n){let[r]=t;return e!==`z.fromJSONSchema`&&n.fail(`The studio reads a schema as JSON Schema: z.fromJSONSchema({ ... }), not '${e}'.`),E(r)||n.fail(`z.fromJSONSchema() needs a schema.`),r}function k(e){return E(e)&&e.kind===`member`}function _e(e,t){return{kind:`member`,object:e,name:t}}function A(e){if(typeof e.object==`string`)return`${e.object}.${e.name}`;if(k(e.object)){let t=A(e.object);return t?`${t}.${e.name}`:void 0}}function j(e,t,n){let r=e[0];return E(r)||t.fail(n),r}function ve(e,t){try{te({...e,name:L(e.name)})}catch(e){if(!(e instanceof h))throw e;let n=t.filter(t=>RegExp(`\\b${t.path}\\b`).test(e.message)).sort((e,t)=>t.path.length-e.path.length)[0]??t[0]??{line:1,column:1};throw new T(e.message,n.line,n.column)}}function ye(e,t,n){let r=j(e,t,`registerTool() needs the tool object.`),i=r.type,a=typeof i==`string`&&re.includes(i);if(i!==void 0&&!a){let e=n.findLast(e=>e.path===`type`)??t.pos();throw new T(ne,e.line,e.column)}return ve(r,n),{kind:`registerTool`,tool:r}}function be(e,t,n,r){if(n.of===`provider`){if(e!==`registerProvider`)return n.fail(`'${e}' isn't part of a provider's code.`);let[r,i={}]=t;return typeof r!=`string`&&n.fail(`registerProvider() needs the definition it registers from.`),(!E(i)||t.length>2)&&n.fail(`registerProvider() takes the definition and its settings.`),{kind:`provider`,definition:r,spec:i}}return e===`compileDetect`?j(t,n,`compileDetect() needs the detect object.`):e===`defineProfile`?j(t,n,`defineProfile() needs the profile object.`):e===`registerTool`?ye(t,n,r):e===`registerStructured`?{kind:`registerStructured`,args:t}:e===`registerProfile`||e===`registerProvider`?{kind:e}:n.fail(`'${e}' isn't part of this file.`)}function xe(e,t,n){return(typeof t!=`string`||e.some(e=>typeof e!=`string`))&&n.fail(`.join() here joins lines of one string.`),e.join(t)}function Se(e,t,n){if(e.name===`join`&&Array.isArray(e.object))return xe(e.object,t[0],n);if(e.name===`resolve`&&e.object===`Promise`)return t[0];let r=A(e);return r?.startsWith(`z.`)?ge(r,t,n):n.fail(`This call isn't part of this file.`)}function Ce(e,t,n,r){return typeof e==`string`?be(e,t,n,r):(k(e)||n.fail(`This call isn't part of this file.`),Se(e,t,n))}function we(e){return/^(async\s*)?\(\s*\)\s*=>/.test(e.rest())}function Te(e,t,n){return e.peekIdent()===`async`&&e.expectIdent(),e.expect(`(`),e.eat(`)`)||e.fail(`A handler here takes no arguments. It returns a fixed value.`),e.expect(`=>`),F(e,t,n)}var M=class{name;constructor(e){this.name=e}};function N(e){return e instanceof M?e.name:e}function P(e,t,n){return we(e)?Te(e,t,n):De(Ee(e,t,n),e,t,n)}function Ee(e,t,n){e.skip();let r=e.peek();if(r===`'`||r===`"`)return D(e);if(r==="`"&&e.fail(`This file doesn't use template strings.`),r===`-`||/^[0-9]/.test(r))return de(e);if(r===`{`)return me(e,t,n);if(r===`[`)return he(e,t,n);if(r===`(`){e.bump();let r=P(e,t,n);return e.expect(`)`),r}let i=e.ident();return i===`true`?!0:i===`false`?!1:i===`null`?null:(i===void 0&&e.fail(`Expected a value.`),new M(i))}function F(e,t,n){e.skip();let r=e.pos(),i=P(e,t,n);if(!(i instanceof M))return i;if(i.name!==`undefined`)throw new T(`'${i.name}' is set somewhere else. Write its value here.`,r.line,r.column)}function De(e,t,n,r){let i=e;for(;;)if(t.eat(`.`)){let e=t.expectIdent();i=_e(N(i),e)}else if(t.eat(`(`)){let e=r.length,a=[];for(;!t.eat(`)`);)a.push(N(P(t,n,r))),t.eat(`,`),t.done&&t.fail(`This call never closes.`);i=Ce(N(i),a,t,r.slice(e))}else return k(i)&&t.fail(`This file doesn't stop on a property.`),i}function Oe(e,t){e.expectIdent();let n=e.expectIdent();e.expect(`=`);let r=P(e,``,t.spans);(e.eat(`satisfies`)||e.eat(`as`))&&fe(e),e.eat(`;`),e.of===`provider`?e.fail(`A provider's code is its registerProvider() call and nothing else.`):n===`profile`?(E(r)||e.fail(`profile has to be the defineProfile() object.`),t.profile&&e.fail(`This file defines two profiles.`),t.profile=r):n===`questions`?(E(r)||e.fail(`questions has to be an object.`),t.questions=r):n===`images`&&(E(r)||e.fail(`images has to be an object.`),t.images=r)}function ke(e,t){let n=P(e,``,t.spans);if(e.eat(`;`),E(n)){if(n.kind===`provider`&&typeof n.definition==`string`&&E(n.spec))t.provider&&e.fail(`This code registers two providers.`),t.provider={definition:n.definition,spec:n.spec};else if(n.kind===`registerTool`){let r=n.tool;E(r)||e.fail(`registerTool() needs the tool object.`),t.tools.push(r)}else if(n.kind===`registerStructured`){let[r,i]=Array.isArray(n.args)?n.args:[];(typeof r!=`string`||!E(i))&&e.fail(`registerStructured() needs an id and a spec.`),t.structures.push({id:r,spec:i})}}}function I(e,t=`profile`){let n=new ue(e,t),r={tools:[],structures:[],spans:[]};for(n.skip();!n.done;n.skip())n.peekIdent()===`import`?(n.expectIdent(),pe(n)):(n.peekIdent()===`export`&&n.expectIdent(),n.peekIdent()===`const`?Oe(n,r):ke(n,r));return t===`provider`?r.provider||n.fail(`This code needs registerProvider().`):r.profile||n.fail(`This file needs defineProfile().`),r}function L(e,t=``){return typeof e==`string`?e:t}function R(e){return typeof e==`number`?e:null}function Ae(e){if(typeof e==`string`)return e;if(E(e)&&typeof e.private==`string`)return{private:e.private}}function je(e){let t=`The system prompt has to be text, or lines of text and { private } parts.`;if(e===void 0)return``;if(typeof e==`string`)return e;if(!Array.isArray(e))throw new T(t,1,1);return e.map(e=>{if(typeof e==`string`)return e;if(!Array.isArray(e))throw new T(t,1,1);return e.map(e=>Ae(e)??Me(t))})}function Me(e){throw new T(e,1,1)}function z(e,t,n){let r=new Map(n.map(e=>[e.name,e]));return Object.entries(U(e)??{}).map(([e,n])=>{let i=r.get(e),a=U(n),o=(Array.isArray(a?.choices)?a.choices:[]).map((e,t)=>{let n=U(e);return{key:i?.choices[t]?.key??b(`choice`),value:L(n?.value),description:L(n?.description)}});return{key:i?.key??b(`option`),name:e,label:L(a?.label),isShownInChat:t,choices:o}})}function B(e){return e===void 0?``:JSON.stringify(e,null,2)}function Ne(e,t){return w(e)===w(t)}function V(e){return E(e)?JSON.stringify(e,null,2):JSON.stringify(e)}function H(e){return Array.isArray(e)?e.map(e=>{if(!E(e)||typeof e.name!=`string`)throw new T(`A pattern needs a name.`,1,1);return Array.isArray(e.words)?{name:e.name,kind:`words`,pattern:``,flags:``,words:e.words.filter(e=>typeof e==`string`)}:{name:e.name,kind:`pattern`,pattern:L(e.pattern),flags:L(e.flags),words:[]}}):[]}function U(e){return E(e)?e:void 0}function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function G(e){return Array.isArray(e)?W(e):void 0}function K(e){return L(e)||void 0}function q(e){return Array.isArray(e)?W(e).join(`
|
|
8
|
-
`)||void 0:K(e)}function J(e,t,n){return E(e)?t(e):n}function Pe(e,t,n){if(!E(n))return;if(Array.isArray(n.names)){e.innocentNames=W(n.names);return}if(!(t in e.allow))return;let r=e.allow[t];r.hosts=W(n.hosts),r.fromTools=n.fromTools!==!1}function Fe(e,t,n){let r=e.sources[t];r&&(n.theorem===!1&&(r.theorem=!1),r.patterns=H(n.patterns),r.hint=L(n.hint)),Pe(e,t,n.allow)}function Ie(e,t){let n=l(s,()=>`ignore`);return E(t.at)&&Object.assign(n,t.at),{key:e,label:L(t.label),at:n,patterns:H(t.patterns),hint:L(t.hint)}}function Le(e){let t=S().guardrails;if(!E(e))return t;let n=f(e.detect),r={detect:l(p,e=>({...n[e]})),sources:structuredClone(t.sources),allow:structuredClone(t.allow),innocentNames:[...t.innocentNames]},i=[],a=new Set(p);for(let[t,n]of Object.entries(U(e.detect)??{}))E(n)&&(a.has(t)?Fe(r,t,n):i.push(Ie(t,n)));let o=U(e.quota),s=U(e.blockedReply),c=U(e.network),u=U(e.taint);return{...t,...r,own:i,quotaEnabled:o!==void 0,quotaPerDay:R(o?.perDay),blockedReplyOnBlock:L(s?.onBlock),blockedReplyMaxRetries:R(s?.maxRetries),allowPrivateNetworks:c?.allowPrivateNetworks===!0,allowedHosts:W(c?.allowedHosts),allowedSchemes:W(c?.allowedSchemes),taintAfterRemoteRead:L(u?.afterRemoteRead),taintRemoteDestination:L(u?.remoteDestination)}}var Re={"continue.instruction":(e,t)=>{e.turnBehaviour.continueInstruction=t},"canary.bind_note":(e,t)=>{e.guardrails.canaryBindNote=t},"quota.exhausted":(e,t)=>{e.guardrails.quotaMessage=t},"repair.default_guidance":(e,t)=>{e.outputs.repairGuidance=t},"egress.default_repair_guidance":(e,t)=>{e.guardrails.egressRepairGuidance=t},"egress.refusal":(e,t)=>{e.guardrails.egressRefusal=t}};function ze(e,t){if(!E(t))return;let n={};for(let[r,i]of Object.entries(t)){if(typeof i!=`string`)continue;let t=Re[r];t?t(e,i):ee[r]||(n[r]=i)}e.labels=n}function Be(e){if(E(e))return Object.fromEntries(y.map(({name:t})=>[t,R(e[t])]))}function Ve(e,t,n,r,i){let a=n??_({modelId:e});if(!E(t))return{...a,modelId:e};let o=E(t.efforts)?Object.entries(t.efforts).map(([e,t])=>({alias:e,level:t})):[],s=E(t.compaction)?t.compaction:void 0,c=L(s?.profile),l=R(t.timeoutMs);return{...a,modelId:e,protocol:L(t.protocol,a.protocol),provider:L(t.provider,a.provider),apiId:L(t.apiId),options:U(t.options)??{},timeoutMs:l,limits:Be(t.limits),efforts:o,defaultEffort:L(t.defaultEffort),allowEffortSelect:t.allowEffortSelect===!0,summaries:typeof t.summaries==`boolean`?t.summaries:null,maxOutputTokens:R(t.maxOutputTokens),temperature:typeof t.temperature==`number`?t.temperature:null,builtInTools:Array.isArray(t.builtInTools)?t.builtInTools.filter(e=>typeof e==`string`):[],keySlot:L(t.keySlot),fallbackKeySlot:L(t.fallbackKeySlot),compactTiming:L(s?.timing),compactMaxTokens:R(s?.maxTokens),compactAt:typeof s?.compactAt==`number`?s.compactAt:void 0,compactKeep:R(s?.previousExchanges),compactMeter:L(s?.meter),compactWith:c?He(c,r,`models.${e}.compaction.profile`,i):``}}function He(e,t,n,r){return t?t(e)??X(r,n,`'${e}' is not an agent here, so it can't write this model's summaries.`):``}function Ue(e,t){let n=t.output;if(e===`function`&&E(t.handler)&&E(n)&&!Ne(t.handler,ie(n)))return B(t.handler)}function We(e){let t=U(e.mapping)??{};return{endpoint:K(e.endpoint),method:K(e.method),headersJson:E(e.headers)?B(e.headers):void 0,pathParams:G(t.pathParams),queryParams:G(t.queryParams),bodyParam:K(t.bodyParam),serverUrl:K(e.serverUrl),mcpToolName:K(e.mcpToolName),maxResponseBytes:R(e.maxResponseBytes),sessionIdleMs:R(U(e.session)?.idleMs),sessionMax:R(U(e.session)?.max)}}function Ge(e){let t=U(e.auth)??{};return{authType:L(t.type),authSlot:K(t.slot),authService:K(t.service),authHeaderName:K(t.headerName),authHeaderPrefix:typeof t.headerPrefix==`string`?t.headerPrefix:void 0,authQueryParam:K(t.queryParam),authUnauthenticated:L(t.onUnauthenticated),authScopes:G(t.scopes),authClientId:K(t.clientId),authRedirectUri:K(t.redirectUri)}}function Ke(e,t,n){let r=t??x(),i=L(e.type,r.toolType),a=U(e.labels)??{},o=L(e.profile),s=e.answeredBy===`page`;return{...r,key:t?.key??b(`tool`),toolName:L(e.name,r.toolName),toolType:i,description:L(e.description),category:L(e.category,`studio`),access:L(e.access,r.access),permission:L(e.permission,r.permission),loadTier:L(e.loadTier,r.loadTier),paths:G(e.paths)??[`*`],inputJson:e.input===void 0?r.inputJson:V(e.input),outputJson:e.output===void 0?r.outputJson:V(e.output),activity:q(a.activity),activityPast:q(a.activityPast),activityFailed:q(a.activityFailed),request:q(a.request),stubOutputJson:s?t?.stubOutputJson:Ue(i,e),answeredBy:s?`page`:void 0,after:e.after===!0||void 0,background:e.background,...We(e),agentKey:o?n?.(o):void 0,maxCallsPerTurn:R(e.maxCallsPerTurn),...Ge(e)}}function qe(e,t){let n=new Map(t.map(e=>[e.id,e]));return Object.entries(e).map(([e,t])=>{let r=n.get(e),i=E(t)?t:{},a=L(i.type,`choice`),o=i.criteria,s=Array.isArray(o)?o.map((e,t)=>({key:r?.criteria[t]?.key??b(`criterion`),label:``,text:L(e)})):E(o)?Object.entries(o).map(([e,t],n)=>({key:r?.criteria[n]?.key??b(`criterion`),label:e,text:L(t)})):[];return{key:r?.key??b(`question`),id:e,type:a,instructions:L(i.instructions),criteria:s,...a===`box`&&L(i.image)?{image:L(i.image)}:{}}})}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)if(E(n)){if(typeof n.uri==`string`){let e=L(n.name);t.push({key:b(`reference`),uri:n.uri,...e?{name:e}:{}})}else typeof n.data==`string`&&t.push({key:b(`reference`),name:L(n.name),mimeType:L(n.mimeType),data:n.data})}return t}function Ye(e,t){return e?g.filter(n=>!n.optional||n.role===`branch`||!n.profileTypes.includes(e)?!1:n.profilePath in t).map(e=>e.id):S().included}function Xe(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Ke(o,t.get(L(o.name)),n);if(e.toolName&&a.has(e.toolName)){let t=r.filter(e=>e.path===`name`)[i.length]??{line:1,column:1};throw new T(`'${e.toolName}' is registered twice.`,t.line,t.column)}e.toolName&&a.add(e.toolName),i.push(e)}return i}function Ze(e,t,n){if(t===void 0)return[];let r=n.findLast(e=>e.path===`tools.allow`)??{line:1,column:1};if(!Array.isArray(t))throw new T(`tools.allow has to be a list of tool names.`,r.line,r.column);let i=new Map(e.map(e=>[e.toolName,e])),a=[],o=new Set;for(let[e,s]of t.entries()){let t=n.find(t=>t.path===`tools.allow.${String(e)}`)??r;if(typeof s!=`string`||s.trim()===``)throw new T(`tools.allow names tools.`,t.line,t.column);if(o.has(s))throw new T(`'${s}' is listed twice in tools.allow.`,t.line,t.column);o.add(s);let c=i.get(s);if(!c)throw new T(`'${s}' is in tools.allow, and this file has no registerTool for it.`,t.line,t.column);a.push(c)}return a}function Qe(e,t,n){let r=U(t.identity)??{};return{...e,agentId:L(t.id),profileType:n,handle:L(r.handle),system:je(r.system),options:[...z(r.options,!1,e.options),...z(U(t.inputs)?.options,!0,e.options)]}}function $e(e){return{...E(e.providerContinuation)&&(e.providerContinuation.history===`provider`||e.providerContinuation.history===`stateless`)?{providerHistory:e.providerContinuation.history}:{},defaultModel:L(e.defaultModel),allowModelSelect:e.allowModelSelect===!0,maxSteps:R(e.maxSteps),key:L(e.key),fallbackKey:L(e.fallbackKey)}}function et(e){return m.includes(e)}function tt(e){return Object.fromEntries(Object.entries(U(e)??{}).filter(e=>typeof e[1]==`number`))}function nt(e){let t=U(e.context);return{text:e.text!==!1,attachmentsAccept:W(U(e.attachments)?.accept),voiceAccept:W(U(e.voice)?.accept),maxFiles:R(e.maxFiles),maxBytes:R(e.maxBytes),maxTurnBytes:R(e.maxTurnBytes),limitsByMime:tt(e.limitsByMime),contextFrom:W(t?.from).filter(et),contextMaxChars:R(t?.maxChars)}}function rt(e){return Object.fromEntries(Object.entries(e??{}).map(([e,t])=>[e,U(t)?.onFail===`fix`?`fix`:`drop`]))}function it(e,t){let n=U(e?.structured),r=n?t.find(({id:e})=>e===L(n.fallback)):t[0],i=r?.id??L(e?.structured),a=Object.entries(U(n?.map)??{}).map(([e,n])=>({choice:e,schemaId:L(n),schemaJson:B(t.find(e=>e.id===n)?.spec.jsonSchema)})),o=U(e?.streaming),s=U(e?.validation);return{mode:i?`structured`:`text`,schemaId:i,schemaJson:B(r?.spec.jsonSchema),...n?{byOption:{option:L(n.by),shapes:a}}:{},streamMode:L(o?.mode),streamThoughts:o?.streamThoughts!==!1,validationEnabled:s!==void 0,maxRetries:R(s?.maxRetries),itemRules:rt(U(s?.items)),repairGuidance:``}}function at(e){let t=U(e.resumption),n=Array.isArray(t?.allowContinue)?t.allowContinue:[...c],r=Array.isArray(t?.autoContinue)?t.autoContinue:[...u];return{resumeEnabled:n.length>0||r.length>0,allowContinue:n,autoContinue:r,maxContinues:R(t?.maxContinues),continueInstruction:``,allowSteering:e.allowSteering!==!1,atStepLimit:e.atStepLimit===`answer`?`answer`:`stop`}}function ot(e){let t=S().observability,n=typeof e.writeTo==`string`&&e.writeTo?e.writeTo:t.destination;return{...t,writeTo:e.writeTo!==!1&&n,destination:n,sampleRate:typeof e.sampleRate==`number`?e.sampleRate:t.sampleRate,include:{...t.include,...U(e.include)},scrub:{...t.scrub,...U(e.scrub)},retainForDays:R(e.retainForDays),rotateAfterMiB:R(e.rotateAfterMiB),resourceJson:B(e.resource)}}function st(e){return{aspectRatio:L(e.aspectRatio),resolution:L(e.resolution),mimeType:L(e.mimeType),quality:L(e.quality),background:L(e.background),n:R(e.n),seed:R(e.seed),outputCompression:R(e.outputCompression),includeText:e.includeText===!0,references:Je(e.references)}}function ct(e){return{voice:L(e.voice),style:L(e.style),speed:R(e.speed),format:L(e.format)}}function Y(e,t){let n=e[t];return typeof n==`boolean`?n:C(t)}function lt(e){let t=U(e.ingress)??{},n=U(e.vad)??{},r=U(e.contextCompression),i=U(r?.slidingWindow),a=U(e.transcription);return{ingressAudio:Y(t,`audio`),ingressVideo:Y(t,`video`),ingressText:Y(t,`text`),voice:L(e.voice),sessionResumption:e.sessionResumption===!0,greeting:L(e.greeting),resumedPrompt:L(U(e.resumed)?.prompt),resumedAfterMs:R(U(e.resumed)?.afterMs),contextCompression:r!==void 0,compressionTriggerTokens:R(r?.triggerTokens),compressionTargetTokens:R(i?.targetTokens),transcriptionInput:a?.input===!0,transcriptionOutput:a?.output===!0,vadActivityHandling:L(n.activityHandling),vadStartSensitivity:L(n.startSensitivity),vadEndSensitivity:L(n.endSensitivity),vadPrefixPaddingMs:R(n.prefixPaddingMs),vadSilenceDurationMs:R(n.silenceDurationMs)}}function ut(e,t,n){let r=R(U(t.profile?.inputs)?.maxStateBytes);return{contract:L(e.contract),maxStateBytes:r,questions:t.questions?qe(t.questions,n.questions):[],images:t.images?dt(t.images,n.images):[]}}function dt(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(e).map(([e,t])=>{let r=e.replace(/^<|>$/g,``),i=E(t)?t:{};return{key:n.get(r)?.key??b(`image`),name:r,mimeType:L(i.mimeType),data:L(i.data)}})}function ft(e){let t=L(e.type);if(t&&!v.includes(t))throw new T(`'${t}' is not a profile type.`,1,1);return t}function pt(e,t){let[n]=d(e);n&&X(t,n.path,`${n.path} ${n.message}`)}function mt(e,t,n){let r=e.profile??{},i=ft(r);pt(r,e.spans);let a=new Map(t.modelBindings.map(e=>[e.modelId,e])),o=new Map(t.toolSpecs.map(e=>[e.toolName,e])),s=U(r.tools)??{},c=U(r.inputs),l=U(r.outputs),u={...t,identity:Qe(t.identity,r,i),included:Ye(i,r),models:$e(r),modelBindings:Object.entries(U(r.models)??{}).map(([t,r])=>Ve(t,r,a.get(t),n,e.spans)),tools:{t2Loader:L(s.t2Loader),parallel:s.parallel===!0},toolSpecs:[],inputs:c&&i!==`decision`?nt(c):t.inputs,outputs:l||e.structures.length?it(l,e.structures):t.outputs,turnBehaviour:J(r.turnBehaviour,at,t.turnBehaviour),guardrails:J(r.guardrails,Le,t.guardrails),observability:J(r.observability,ot,t.observability),image:J(r.image,st,t.image),speech:J(r.speech,ct,t.speech),live:J(r.live,lt,t.live),decision:J(r.decision,n=>ut(n,e,t.decision),t.decision),labels:{}},d=Xe(e.tools,o,n,e.spans),f=Ze(d,s.allow,e.spans);u.toolSpecs=f;let p=new Set(f.map(e=>e.toolName));return u.tools.t2Loader&&!p.has(u.tools.t2Loader)&&(u.tools={...u.tools,t2Loader:``}),ze(u,r.labels),{draft:u,registered:d}}function ht(e,t,n){try{let r=I(e),{draft:i,registered:a}=mt(r,t,n);return{ok:!0,draft:i,spans:r.spans,registered:a}}catch(e){if(e instanceof T)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}function X(e,t,n){let r=e.findLast(e=>e.path===t)??{line:1,column:1};throw new T(n,r.line,r.column)}var gt=new Set([`id`,`connection`,`keySlot`,`fallbackKeySlot`]);function _t(e,t,n){let{spec:r}=e;for(let e of Object.keys(r))gt.has(e)||X(n,e,`'${e}' isn't a provider setting the studio holds.`);r.id!==t.id&&X(n,`id`,`The id stays '${t.id}': models and code name the provider by it.`);let s=i(e.definition);if(!s){let t=o().flatMap(e=>a(e)??[]).join(`, `);X(n,``,`'${e.definition}' isn't one of the kernel's providers: ${t}.`)}let c=r.connection===void 0?{}:vt(r.connection,n),l=Object.keys(c).length===0&&t.connection===void 0,u={id:t.id,definition:s,...l?{}:{connection:c}};for(let e of[`keySlot`,`fallbackKeySlot`]){let t=r[e];t!==void 0&&(typeof t!=`string`&&X(n,e,`${e} names a key slot.`),u[e]=t)}return u}function vt(e,t){let n=`connection holds text settings here.`,r={};E(e)||X(t,`connection`,n);for(let[i,a]of Object.entries(e))typeof a!=`string`&&X(t,`connection`,n),r[i]=a;return r}function yt(e,t){try{let n=I(e,`provider`);if(!n.provider)throw new T(`This code needs registerProvider().`,1,1);return{ok:!0,provider:_t(n.provider,t,n.spans),spans:n.spans}}catch(e){if(e instanceof T)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}var Z=e(t(),1),Q=n(),bt=300,xt=2e3;function St({editor:e,monaco:t,spans:n,errors:r},i){let a=e?.getModel();t&&a&&t.editor.setModelMarkers(a,`studio`,[...r.map(e=>$(t,e.line,e.column,e.message)),...wt(t,n,i)])}function Ct({text:e,hold:t,isReadOnly:n=!1,issues:i,onApply:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(a),c=(0,Z.useRef)(e),l=(0,Z.useRef)(n);l.current=n;let u=(0,Z.useRef)(i),d=(0,Z.useRef)({spans:[],errors:[],setting:!1,dirty:!1});return s.current=a,c.current=e,u.current=i,(0,Z.useEffect)(()=>{let e=o.current;if(!e)return;let t={disposed:!1},n,i,a=0,f,p=!1,m=!1,h=()=>{a+=1,i&&clearTimeout(i),i=void 0,f?.stop(),f=void 0,p=!1,m=!1},g=t=>e.contains(t)?!0:t instanceof Element&&!!t.closest(`.suggest-widget, .parameter-hints-widget, .monaco-hover, .monaco-menu-container, .context-view`),_=()=>!!document.querySelector(`.suggest-widget.visible, .parameter-hints-widget.visible`),v,y=()=>{St(d.current,u.current)};return(async()=>{let o=await r(()=>import(`./studio-monaco-C20o5PnA.js`),__vite__mapDeps([0,1,2,3,4]));if(await r(()=>import(`./register-BLInT6S0.js`),__vite__mapDeps([5,1,2,3])),await o.serveMonacoWorkers(),t.disposed||!e.isConnected)return;let u=o.Uri.parse(`file:///agent.ts`);o.editor.getModel(u)?.dispose();let ee=o.editor.createModel(c.current,`typescript`,u),b=o.editor.create(e,{model:ee,readOnly:l.current,language:`typescript`,theme:o.studioMonacoTheme(),minimap:{enabled:!1},fontSize:13,wordWrap:`on`,wrappingIndent:`indent`,scrollBeyondLastLine:!1,automaticLayout:!0,fixedOverflowWidgets:!0,tabSize:2,padding:{top:12},quickSuggestions:{other:!0,comments:!1,strings:!0},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,tabCompletion:`on`,wordBasedSuggestions:`currentDocument`,parameterHints:{enabled:!0},suggest:{preview:!0,showIcons:!0}});d.current.editor=b,d.current.monaco=o;let x=()=>{i&&clearTimeout(i),i=setTimeout(()=>{t.disposed||(_()?x():h())},xt)},S=()=>{if(f){m&&x();return}if(p)return;let e=a,n=()=>t.disposed||e!==a;p=!0,r(async()=>{let{openTypeChecker:e}=await import(`./studio-type-checker-CoJzuBAo.js`);return{openTypeChecker:e}},__vite__mapDeps([6,1])).then(({openTypeChecker:r})=>{if(n())return;let i=r(o,b,()=>{t.disposed||e!==a||(m=!0,x())});n()?i.stop():f=i}).catch(()=>{}).finally(()=>{e===a&&(p=!1)})};b.onKeyDown(e=>{let t=e.browserEvent;t.metaKey||t.ctrlKey||t.altKey||m&&x()});let C=e=>{let t=e.target;t instanceof Node&&!g(t)&&h()};document.addEventListener(`pointerdown`,C,!0),v=()=>{document.removeEventListener(`pointerdown`,C,!0)},b.onDidBlurEditorText(()=>{queueMicrotask(()=>{if(t.disposed||b.hasTextFocus())return;let e=document.activeElement;e&&g(e)||h()})}),b.onDidChangeModelContent(()=>{if(d.current.setting)return;S();let e=b.getValue();d.current.dirty=e!==c.current,n&&clearTimeout(n),n=setTimeout(()=>{let t=s.current(e);d.current.spans=t.spans,d.current.errors=t.errors,y()},bt)}),y()})(),()=>{t.disposed=!0,v?.(),h(),n&&clearTimeout(n);let e=d.current.editor?.getModel();d.current.editor?.dispose(),e?.dispose(),d.current.editor=void 0}},[]),(0,Z.useEffect)(()=>{let{editor:n}=d.current;n&&!t&&(d.current.dirty&&n.getValue()!==e||(n.getValue()===e||(d.current.setting=!0,n.setValue(e),d.current.setting=!1),d.current.dirty=!1))},[e,t]),(0,Z.useEffect)(()=>{d.current.editor?.updateOptions({readOnly:n})},[n]),(0,Z.useEffect)(()=>{St(d.current,i)},[i]),(0,Q.jsx)(`div`,{ref:o,className:`studio-fill`})}function $(e,t,n,r){return{startLineNumber:t,startColumn:n,endLineNumber:t,endColumn:n+1,message:r,severity:e.MarkerSeverity.Error}}function wt(e,t,n){return n.flatMap(n=>{let r=n.field?`${n.nodeId}.${n.field}`:n.nodeId,i=t.find(e=>e.path===r)??(n.field?t.find(e=>e.path===n.field):void 0);return i?[$(e,i.line,i.column,n.message)]:[]})}function Tt({source:e,blocked:t,issues:n,state:r}){let i=(0,Z.useRef)(e);e&&(i.current=e);let a=(0,Z.useCallback)(e=>{let t=se(r.workspace,r.focus);if(!t)return{errors:[{message:`No agent is open.`,line:1,column:1}],spans:[]};let n=ht(e,{...t,toolSpecs:r.workspace.toolSpecs},e=>r.workspace.agents.find(t=>t.identity.agentId.trim()===e)?.key);return n.ok?(r.update(e=>oe(e,r.focus,n.draft,n.registered)),{errors:[],spans:n.spans}):{errors:n.errors,spans:[]}},[r]);return i.current?(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(Ct,{text:e??i.current,hold:e==null,issues:n,onApply:a})}):(0,Q.jsx)(ce,{title:`No code yet`,description:`${t??``} to generate the TypeScript.`})}function Et({provider:e,issues:t,state:n,isEditable:r}){let i=(0,Z.useCallback)(t=>{let r=n.workspace.providers.find(t=>t.id===e.id);if(!r)return{errors:[{message:`No provider is open.`,line:1,column:1}],spans:[]};let i=yt(t,r);return i.ok?(n.update(e=>ae(e,i.provider)),{errors:[],spans:i.spans}):{errors:i.errors,spans:[]}},[n,e.id]);return(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(Ct,{text:le(e),hold:!1,isReadOnly:!r||a(e.definition)===void 0,issues:t,onApply:i},e.id)})}export{Tt as CodeBody,Et as ProviderCode};
|
|
8
|
+
`)||void 0:K(e)}function J(e,t,n){return E(e)?t(e):n}function Pe(e,t,n){if(!E(n))return;if(Array.isArray(n.names)){e.innocentNames=W(n.names);return}if(!(t in e.allow))return;let r=e.allow[t];r.hosts=W(n.hosts),r.fromTools=n.fromTools!==!1}function Fe(e,t,n){let r=e.sources[t];r&&(n.theorem===!1&&(r.theorem=!1),r.patterns=H(n.patterns),r.hint=L(n.hint)),Pe(e,t,n.allow)}function Ie(e,t){let n=l(s,()=>`ignore`);return E(t.at)&&Object.assign(n,t.at),{key:e,label:L(t.label),at:n,patterns:H(t.patterns),hint:L(t.hint)}}function Le(e){let t=S().guardrails;if(!E(e))return t;let n=f(e.detect),r={detect:l(p,e=>({...n[e]})),sources:structuredClone(t.sources),allow:structuredClone(t.allow),innocentNames:[...t.innocentNames]},i=[],a=new Set(p);for(let[t,n]of Object.entries(U(e.detect)??{}))E(n)&&(a.has(t)?Fe(r,t,n):i.push(Ie(t,n)));let o=U(e.quota),s=U(e.blockedReply),c=U(e.network),u=U(e.taint);return{...t,...r,own:i,quotaEnabled:o!==void 0,quotaPerDay:R(o?.perDay),blockedReplyOnBlock:L(s?.onBlock),blockedReplyMaxRetries:R(s?.maxRetries),allowPrivateNetworks:c?.allowPrivateNetworks===!0,allowedHosts:W(c?.allowedHosts),allowedSchemes:W(c?.allowedSchemes),taintAfterRemoteRead:L(u?.afterRemoteRead),taintRemoteDestination:L(u?.remoteDestination)}}var Re={"continue.instruction":(e,t)=>{e.turnBehaviour.continueInstruction=t},"canary.bind_note":(e,t)=>{e.guardrails.canaryBindNote=t},"quota.exhausted":(e,t)=>{e.guardrails.quotaMessage=t},"repair.default_guidance":(e,t)=>{e.outputs.repairGuidance=t},"egress.default_repair_guidance":(e,t)=>{e.guardrails.egressRepairGuidance=t},"egress.refusal":(e,t)=>{e.guardrails.egressRefusal=t}};function ze(e,t){if(!E(t))return;let n={};for(let[r,i]of Object.entries(t)){if(typeof i!=`string`)continue;let t=Re[r];t?t(e,i):ee[r]||(n[r]=i)}e.labels=n}function Be(e){if(E(e))return Object.fromEntries(y.map(({name:t})=>[t,R(e[t])]))}function Ve(e,t,n,r,i){let a=n??_({modelId:e});if(!E(t))return{...a,modelId:e};let o=E(t.efforts)?Object.entries(t.efforts).map(([e,t])=>({alias:e,level:t})):[],s=E(t.compaction)?t.compaction:void 0,c=L(s?.profile),l=R(t.timeoutMs);return{...a,modelId:e,protocol:L(t.protocol,a.protocol),provider:L(t.provider,a.provider),apiId:L(t.apiId),options:U(t.options)??{},timeoutMs:l,limits:Be(t.limits),efforts:o,defaultEffort:L(t.defaultEffort),allowEffortSelect:t.allowEffortSelect===!0,summaries:typeof t.summaries==`boolean`?t.summaries:null,maxOutputTokens:R(t.maxOutputTokens),temperature:typeof t.temperature==`number`?t.temperature:null,builtInTools:Array.isArray(t.builtInTools)?t.builtInTools.filter(e=>typeof e==`string`):[],keySlot:L(t.keySlot),fallbackKeySlot:L(t.fallbackKeySlot),compactTiming:L(s?.timing),compactMaxTokens:R(s?.maxTokens),compactAt:typeof s?.compactAt==`number`?s.compactAt:void 0,compactKeep:R(s?.previousExchanges),compactMeter:L(s?.meter),compactWith:c?He(c,r,`models.${e}.compaction.profile`,i):``}}function He(e,t,n,r){return t?t(e)??X(r,n,`'${e}' is not an agent here, so it can't write this model's summaries.`):``}function Ue(e,t){let n=t.output;if(e===`function`&&E(t.handler)&&E(n)&&!Ne(t.handler,ie(n)))return B(t.handler)}function We(e){let t=U(e.mapping)??{};return{endpoint:K(e.endpoint),method:K(e.method),headersJson:E(e.headers)?B(e.headers):void 0,pathParams:G(t.pathParams),queryParams:G(t.queryParams),bodyParam:K(t.bodyParam),serverUrl:K(e.serverUrl),mcpToolName:K(e.mcpToolName),maxResponseBytes:R(e.maxResponseBytes),sessionIdleMs:R(U(e.session)?.idleMs),sessionMax:R(U(e.session)?.max)}}function Ge(e){let t=U(e.auth)??{};return{authType:L(t.type),authSlot:K(t.slot),authService:K(t.service),authHeaderName:K(t.headerName),authHeaderPrefix:typeof t.headerPrefix==`string`?t.headerPrefix:void 0,authQueryParam:K(t.queryParam),authUnauthenticated:L(t.onUnauthenticated),authScopes:G(t.scopes),authClientId:K(t.clientId),authRedirectUri:K(t.redirectUri)}}function Ke(e,t,n){let r=t??x(),i=L(e.type,r.toolType),a=U(e.labels)??{},o=L(e.profile),s=e.answeredBy===`page`;return{...r,key:t?.key??b(`tool`),toolName:L(e.name,r.toolName),toolType:i,description:L(e.description),category:L(e.category,`studio`),access:L(e.access,r.access),permission:L(e.permission,r.permission),loadTier:L(e.loadTier,r.loadTier),paths:G(e.paths)??[`*`],inputJson:e.input===void 0?r.inputJson:V(e.input),outputJson:e.output===void 0?r.outputJson:V(e.output),activity:q(a.activity),activityPast:q(a.activityPast),activityFailed:q(a.activityFailed),request:q(a.request),stubOutputJson:s?t?.stubOutputJson:Ue(i,e),answeredBy:s?`page`:void 0,after:e.after===!0||void 0,background:e.background,...We(e),agentKey:o?n?.(o):void 0,maxCallsPerTurn:R(e.maxCallsPerTurn),...Ge(e)}}function qe(e,t){let n=new Map(t.map(e=>[e.id,e]));return Object.entries(e).map(([e,t])=>{let r=n.get(e),i=E(t)?t:{},a=L(i.type,`choice`),o=i.criteria,s=Array.isArray(o)?o.map((e,t)=>({key:r?.criteria[t]?.key??b(`criterion`),label:``,text:L(e)})):E(o)?Object.entries(o).map(([e,t],n)=>({key:r?.criteria[n]?.key??b(`criterion`),label:e,text:L(t)})):[];return{key:r?.key??b(`question`),id:e,type:a,instructions:L(i.instructions),criteria:s,...a===`box`&&L(i.image)?{image:L(i.image)}:{}}})}function Je(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)if(E(n)){if(typeof n.uri==`string`){let e=L(n.name);t.push({key:b(`reference`),uri:n.uri,...e?{name:e}:{}})}else typeof n.data==`string`&&t.push({key:b(`reference`),name:L(n.name),mimeType:L(n.mimeType),data:n.data})}return t}function Ye(e,t){return e?g.filter(n=>!n.optional||n.role===`branch`||!n.profileTypes.includes(e)?!1:n.profilePath in t).map(e=>e.id):S().included}function Xe(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Ke(o,t.get(L(o.name)),n);if(e.toolName&&a.has(e.toolName)){let t=r.filter(e=>e.path===`name`)[i.length]??{line:1,column:1};throw new T(`'${e.toolName}' is registered twice.`,t.line,t.column)}e.toolName&&a.add(e.toolName),i.push(e)}return i}function Ze(e,t,n){if(t===void 0)return[];let r=n.findLast(e=>e.path===`tools.allow`)??{line:1,column:1};if(!Array.isArray(t))throw new T(`tools.allow has to be a list of tool names.`,r.line,r.column);let i=new Map(e.map(e=>[e.toolName,e])),a=[],o=new Set;for(let[e,s]of t.entries()){let t=n.find(t=>t.path===`tools.allow.${String(e)}`)??r;if(typeof s!=`string`||s.trim()===``)throw new T(`tools.allow names tools.`,t.line,t.column);if(o.has(s))throw new T(`'${s}' is listed twice in tools.allow.`,t.line,t.column);o.add(s);let c=i.get(s);if(!c)throw new T(`'${s}' is in tools.allow, and this file has no registerTool for it.`,t.line,t.column);a.push(c)}return a}function Qe(e,t,n){let r=U(t.identity)??{};return{...e,agentId:L(t.id),profileType:n,handle:L(r.handle),system:je(r.system),options:[...z(r.options,!1,e.options),...z(U(t.inputs)?.options,!0,e.options)]}}function $e(e){return{...E(e.providerContinuation)&&(e.providerContinuation.history===`provider`||e.providerContinuation.history===`stateless`)?{providerHistory:e.providerContinuation.history}:{},defaultModel:L(e.defaultModel),allowModelSelect:e.allowModelSelect===!0,maxSteps:R(e.maxSteps),key:L(e.key),fallbackKey:L(e.fallbackKey)}}function et(e){return m.includes(e)}function tt(e){return Object.fromEntries(Object.entries(U(e)??{}).filter(e=>typeof e[1]==`number`))}function nt(e){let t=U(e.context);return{text:e.text!==!1,attachmentsAccept:W(U(e.attachments)?.accept),voiceAccept:W(U(e.voice)?.accept),maxFiles:R(e.maxFiles),maxBytes:R(e.maxBytes),maxTurnBytes:R(e.maxTurnBytes),limitsByMime:tt(e.limitsByMime),contextFrom:W(t?.from).filter(et),contextMaxChars:R(t?.maxChars)}}function rt(e){return Object.fromEntries(Object.entries(e??{}).map(([e,t])=>[e,U(t)?.onFail===`fix`?`fix`:`drop`]))}function it(e,t){let n=U(e?.structured),r=n?t.find(({id:e})=>e===L(n.fallback)):t[0],i=r?.id??L(e?.structured),a=Object.entries(U(n?.map)??{}).map(([e,n])=>({choice:e,schemaId:L(n),schemaJson:B(t.find(e=>e.id===n)?.spec.jsonSchema)})),o=U(e?.streaming),s=U(e?.validation);return{mode:i?`structured`:`text`,schemaId:i,schemaJson:B(r?.spec.jsonSchema),...n?{byOption:{option:L(n.by),shapes:a}}:{},streamMode:L(o?.mode),streamThoughts:o?.streamThoughts!==!1,validationEnabled:s!==void 0,maxRetries:R(s?.maxRetries),itemRules:rt(U(s?.items)),repairGuidance:``}}function at(e){let t=U(e.resumption),n=Array.isArray(t?.allowContinue)?t.allowContinue:[...c],r=Array.isArray(t?.autoContinue)?t.autoContinue:[...u];return{resumeEnabled:n.length>0||r.length>0,allowContinue:n,autoContinue:r,maxContinues:R(t?.maxContinues),continueInstruction:``,allowSteering:e.allowSteering!==!1,atStepLimit:e.atStepLimit===`answer`?`answer`:`stop`}}function ot(e){let t=S().observability,n=typeof e.writeTo==`string`&&e.writeTo?e.writeTo:t.destination;return{...t,writeTo:e.writeTo!==!1&&n,destination:n,sampleRate:typeof e.sampleRate==`number`?e.sampleRate:t.sampleRate,include:{...t.include,...U(e.include)},scrub:{...t.scrub,...U(e.scrub)},retainForDays:R(e.retainForDays),rotateAfterMiB:R(e.rotateAfterMiB),resourceJson:B(e.resource)}}function st(e){return{aspectRatio:L(e.aspectRatio),resolution:L(e.resolution),mimeType:L(e.mimeType),quality:L(e.quality),background:L(e.background),n:R(e.n),seed:R(e.seed),outputCompression:R(e.outputCompression),includeText:e.includeText===!0,references:Je(e.references)}}function ct(e){return{voice:L(e.voice),style:L(e.style),speed:R(e.speed),format:L(e.format)}}function Y(e,t){let n=e[t];return typeof n==`boolean`?n:C(t)}function lt(e){let t=U(e.ingress)??{},n=U(e.vad)??{},r=U(e.contextCompression),i=U(r?.slidingWindow),a=U(e.transcription);return{ingressAudio:Y(t,`audio`),ingressVideo:Y(t,`video`),ingressText:Y(t,`text`),voice:L(e.voice),sessionResumption:e.sessionResumption===!0,greeting:L(e.greeting),resumedPrompt:L(U(e.resumed)?.prompt),resumedAfterMs:R(U(e.resumed)?.afterMs),contextCompression:r!==void 0,compressionTriggerTokens:R(r?.triggerTokens),compressionTargetTokens:R(i?.targetTokens),transcriptionInput:a?.input===!0,transcriptionOutput:a?.output===!0,vadActivityHandling:L(n.activityHandling),vadStartSensitivity:L(n.startSensitivity),vadEndSensitivity:L(n.endSensitivity),vadPrefixPaddingMs:R(n.prefixPaddingMs),vadSilenceDurationMs:R(n.silenceDurationMs)}}function ut(e,t,n){let r=R(U(t.profile?.inputs)?.maxStateBytes);return{contract:L(e.contract),maxStateBytes:r,questions:t.questions?qe(t.questions,n.questions):[],images:t.images?dt(t.images,n.images):[]}}function dt(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(e).map(([e,t])=>{let r=e.replace(/^<|>$/g,``),i=E(t)?t:{};return{key:n.get(r)?.key??b(`image`),name:r,mimeType:L(i.mimeType),data:L(i.data)}})}function ft(e){let t=L(e.type);if(t&&!v.includes(t))throw new T(`'${t}' is not a profile type.`,1,1);return t}function pt(e,t){let[n]=d(e);n&&X(t,n.path,`${n.path} ${n.message}`)}function mt(e,t,n){let r=e.profile??{},i=ft(r);pt(r,e.spans);let a=new Map(t.modelBindings.map(e=>[e.modelId,e])),o=new Map(t.toolSpecs.map(e=>[e.toolName,e])),s=U(r.tools)??{},c=U(r.inputs),l=U(r.outputs),u={...t,identity:Qe(t.identity,r,i),included:Ye(i,r),models:$e(r),modelBindings:Object.entries(U(r.models)??{}).map(([t,r])=>Ve(t,r,a.get(t),n,e.spans)),tools:{t2Loader:L(s.t2Loader),parallel:s.parallel===!0},toolSpecs:[],inputs:c&&i!==`decision`?nt(c):t.inputs,outputs:l||e.structures.length?it(l,e.structures):t.outputs,turnBehaviour:J(r.turnBehaviour,at,t.turnBehaviour),guardrails:J(r.guardrails,Le,t.guardrails),observability:J(r.observability,ot,t.observability),image:J(r.image,st,t.image),speech:J(r.speech,ct,t.speech),live:J(r.live,lt,t.live),decision:J(r.decision,n=>ut(n,e,t.decision),t.decision),labels:{}},d=Xe(e.tools,o,n,e.spans),f=Ze(d,s.allow,e.spans);u.toolSpecs=f;let p=new Set(f.map(e=>e.toolName));return u.tools.t2Loader&&!p.has(u.tools.t2Loader)&&(u.tools={...u.tools,t2Loader:``}),ze(u,r.labels),{draft:u,registered:d}}function ht(e,t,n){try{let r=I(e),{draft:i,registered:a}=mt(r,t,n);return{ok:!0,draft:i,spans:r.spans,registered:a}}catch(e){if(e instanceof T)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}function X(e,t,n){let r=e.findLast(e=>e.path===t)??{line:1,column:1};throw new T(n,r.line,r.column)}var gt=new Set([`id`,`connection`,`keySlot`,`fallbackKeySlot`]);function _t(e,t,n){let{spec:r}=e;for(let e of Object.keys(r))gt.has(e)||X(n,e,`'${e}' isn't a provider setting the studio holds.`);r.id!==t.id&&X(n,`id`,`The id stays '${t.id}': models and code name the provider by it.`);let s=a(e.definition);if(!s){let t=i().flatMap(e=>o(e)??[]).join(`, `);X(n,``,`'${e.definition}' isn't one of the kernel's providers: ${t}.`)}let c=r.connection===void 0?{}:vt(r.connection,n),l=Object.keys(c).length===0&&t.connection===void 0,u={id:t.id,definition:s,...l?{}:{connection:c}};for(let e of[`keySlot`,`fallbackKeySlot`]){let t=r[e];t!==void 0&&(typeof t!=`string`&&X(n,e,`${e} names a key slot.`),u[e]=t)}return u}function vt(e,t){let n=`connection holds text settings here.`,r={};E(e)||X(t,`connection`,n);for(let[i,a]of Object.entries(e))typeof a!=`string`&&X(t,`connection`,n),r[i]=a;return r}function yt(e,t){try{let n=I(e,`provider`);if(!n.provider)throw new T(`This code needs registerProvider().`,1,1);return{ok:!0,provider:_t(n.provider,t,n.spans),spans:n.spans}}catch(e){if(e instanceof T)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}var Z=e(t(),1),Q=n(),bt=300,xt=2e3;function St({editor:e,monaco:t,spans:n,errors:r},i){let a=e?.getModel();t&&a&&t.editor.setModelMarkers(a,`studio`,[...r.map(e=>$(t,e.line,e.column,e.message)),...wt(t,n,i)])}function Ct({text:e,hold:t,isReadOnly:n=!1,issues:i,onApply:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(a),c=(0,Z.useRef)(e),l=(0,Z.useRef)(n);l.current=n;let u=(0,Z.useRef)(i),d=(0,Z.useRef)({spans:[],errors:[],setting:!1,dirty:!1});return s.current=a,c.current=e,u.current=i,(0,Z.useEffect)(()=>{let e=o.current;if(!e)return;let t={disposed:!1},n,i,a=0,f,p=!1,m=!1,h=()=>{a+=1,i&&clearTimeout(i),i=void 0,f?.stop(),f=void 0,p=!1,m=!1},g=t=>e.contains(t)?!0:t instanceof Element&&!!t.closest(`.suggest-widget, .parameter-hints-widget, .monaco-hover, .monaco-menu-container, .context-view`),_=()=>!!document.querySelector(`.suggest-widget.visible, .parameter-hints-widget.visible`),v,y=()=>{St(d.current,u.current)};return(async()=>{let o=await r(()=>import(`./studio-monaco-C20o5PnA.js`),__vite__mapDeps([0,1,2,3,4]));if(await r(()=>import(`./register-BLInT6S0.js`),__vite__mapDeps([5,1,2,3])),await o.serveMonacoWorkers(),t.disposed||!e.isConnected)return;let u=o.Uri.parse(`file:///agent.ts`);o.editor.getModel(u)?.dispose();let ee=o.editor.createModel(c.current,`typescript`,u),b=o.editor.create(e,{model:ee,readOnly:l.current,language:`typescript`,theme:o.studioMonacoTheme(),minimap:{enabled:!1},fontSize:13,wordWrap:`on`,wrappingIndent:`indent`,scrollBeyondLastLine:!1,automaticLayout:!0,fixedOverflowWidgets:!0,tabSize:2,padding:{top:12},quickSuggestions:{other:!0,comments:!1,strings:!0},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,tabCompletion:`on`,wordBasedSuggestions:`currentDocument`,parameterHints:{enabled:!0},suggest:{preview:!0,showIcons:!0}});d.current.editor=b,d.current.monaco=o;let x=()=>{i&&clearTimeout(i),i=setTimeout(()=>{t.disposed||(_()?x():h())},xt)},S=()=>{if(f){m&&x();return}if(p)return;let e=a,n=()=>t.disposed||e!==a;p=!0,r(async()=>{let{openTypeChecker:e}=await import(`./studio-type-checker-vtYkUAwV.js`);return{openTypeChecker:e}},__vite__mapDeps([6,1])).then(({openTypeChecker:r})=>{if(n())return;let i=r(o,b,()=>{t.disposed||e!==a||(m=!0,x())});n()?i.stop():f=i}).catch(()=>{}).finally(()=>{e===a&&(p=!1)})};b.onKeyDown(e=>{let t=e.browserEvent;t.metaKey||t.ctrlKey||t.altKey||m&&x()});let C=e=>{let t=e.target;t instanceof Node&&!g(t)&&h()};document.addEventListener(`pointerdown`,C,!0),v=()=>{document.removeEventListener(`pointerdown`,C,!0)},b.onDidBlurEditorText(()=>{queueMicrotask(()=>{if(t.disposed||b.hasTextFocus())return;let e=document.activeElement;e&&g(e)||h()})}),b.onDidChangeModelContent(()=>{if(d.current.setting)return;S();let e=b.getValue();d.current.dirty=e!==c.current,n&&clearTimeout(n),n=setTimeout(()=>{let t=s.current(e);d.current.spans=t.spans,d.current.errors=t.errors,y()},bt)}),y()})(),()=>{t.disposed=!0,v?.(),h(),n&&clearTimeout(n);let e=d.current.editor?.getModel();d.current.editor?.dispose(),e?.dispose(),d.current.editor=void 0}},[]),(0,Z.useEffect)(()=>{let{editor:n}=d.current;n&&!t&&(d.current.dirty&&n.getValue()!==e||(n.getValue()===e||(d.current.setting=!0,n.setValue(e),d.current.setting=!1),d.current.dirty=!1))},[e,t]),(0,Z.useEffect)(()=>{d.current.editor?.updateOptions({readOnly:n})},[n]),(0,Z.useEffect)(()=>{St(d.current,i)},[i]),(0,Q.jsx)(`div`,{ref:o,className:`studio-fill`})}function $(e,t,n,r){return{startLineNumber:t,startColumn:n,endLineNumber:t,endColumn:n+1,message:r,severity:e.MarkerSeverity.Error}}function wt(e,t,n){return n.flatMap(n=>{let r=n.field?`${n.nodeId}.${n.field}`:n.nodeId,i=t.find(e=>e.path===r)??(n.field?t.find(e=>e.path===n.field):void 0);return i?[$(e,i.line,i.column,n.message)]:[]})}function Tt({source:e,blocked:t,issues:n,state:r}){let i=(0,Z.useRef)(e);e&&(i.current=e);let a=(0,Z.useCallback)(e=>{let t=se(r.workspace,r.focus);if(!t)return{errors:[{message:`No agent is open.`,line:1,column:1}],spans:[]};let n=ht(e,{...t,toolSpecs:r.workspace.toolSpecs},e=>r.workspace.agents.find(t=>t.identity.agentId.trim()===e)?.key);return n.ok?(r.update(e=>oe(e,r.focus,n.draft,n.registered)),{errors:[],spans:n.spans}):{errors:n.errors,spans:[]}},[r]);return i.current?(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(Ct,{text:e??i.current,hold:e==null,issues:n,onApply:a})}):(0,Q.jsx)(ce,{title:`No code yet`,description:`${t??``} to generate the TypeScript.`})}function Et({provider:e,issues:t,state:n,isEditable:r}){let i=(0,Z.useCallback)(t=>{let r=n.workspace.providers.find(t=>t.id===e.id);if(!r)return{errors:[{message:`No provider is open.`,line:1,column:1}],spans:[]};let i=yt(t,r);return i.ok?(n.update(e=>ae(e,i.provider)),{errors:[],spans:i.spans}):{errors:i.errors,spans:[]}},[n,e.id]);return(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(Ct,{text:le(e),hold:!1,isReadOnly:!r||o(e.definition)===void 0,issues:t,onApply:i},e.id)})}export{Tt as CodeBody,Et as ProviderCode};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{P as r}from"./useLayerDismissal-DwwLDEpO.js";import{t as i}from"./VStack-D1ZLA9g3.js";import{c as a}from"./index-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{P as r}from"./useLayerDismissal-DwwLDEpO.js";import{t as i}from"./VStack-D1ZLA9g3.js";import{c as a}from"./index-fyDzED1x.js";var o=e(t(),1),s=r();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=n();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),r=(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)(i,{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},r(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{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{c as r,n as i,s as a}from"./browser-transport-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,l as n}from"./themeProps-Bo2jNkIC.js";import{c as r,n as i,s as a}from"./browser-transport-BScpLZDa.js";import{h as o,m as s}from"./tool-schema-DllL3wqs.js";import{c}from"./reader-DoaMWQWB.js";import{p as l,u}from"./tree-I-6ZPGON.js";import{n as d,t as f}from"./labels-provider-CxUJe6Bn.js";import{S as p,a as m,f as h,h as g,i as _,o as v,p as y,r as b,s as x,t as S,v as C,x as w}from"./ConsoleFrame-DojYn-Ua.js";import{t as T}from"./studio-console-CjqEdyB3.js";import{i as E,t as D}from"./use-one-call-DZ3NX8RC.js";import{t as ee}from"./SchemaFields-GsJdP3wy.js";import{E as O,N as k,O as A,at as j,ct as te,k as M,st as N,v as P,w as F}from"./index-fyDzED1x.js";var I=(e,t,n,r,i)=>e.decide(n,t,r,i);function L(e){let{iface:t,describeFailure:n}=F(e),{call:r,...i}=D(e,`deciding`,I);return{iface:t,describeFailure:n,...i,decide:r}}var R=e(t(),1),z=n();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?o(e):{});return{schema:e,input:t,setInput:n,missing:e?s(e,t):[]}}function G({form:e,built:t,iface:n,images:r,onImages:i,note:a,isReady:o,isRunning:s,onRun:c,onStop:l}){let u=d(),{text:f,setText:m,check:x,shown:S,setView:w}=e,T=n.questions.some(e=>e.type===`box`)||Object.keys(r).length>0,E=S===`fields`?x.state:void 0,D=p(E);return(0,z.jsxs)(_,{title:u(`@theorem.decision.state`),view:S,hasFields:x.state!==void 0,onView:w,onRun:c,children:[t.schema?(0,z.jsx)(ee,{schema:t.schema,value:t.input,onChange:t.setInput}):null,E===void 0?(0,z.jsx)(b,{label:u(`@theorem.decision.state`),text:f,isInvalid:!x.ok,onChange:m}):(0,z.jsx)(y,{value:{images:r,onImages:i},children:(0,z.jsx)(h,{label:u(`@theorem.decision.state`),value:E,onChange:e=>{m(JSON.stringify(e,null,2))}})}),T&&D?(0,z.jsx)(g,{onImages:e=>{let t=C(e,{images:r,host:n.images,state:D});i(t.images),m(JSON.stringify(t.state,null,2))}}):null,(0,z.jsx)(v,{note:a,isReady:o,isRunning:s,runLabel:u(`@theorem.decision.decide`),runningLabel:u(`@theorem.decision.deciding`),stopLabel:u(`@theorem.decision.stop`),onRun:c,onStop:l})]})}function K({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=d(),o=t.status===`deciding`;return(0,z.jsxs)(z.Fragment,{children:[t.failure?(0,z.jsx)(O,{status:`error`,role:`alert`,title:t.failure.error}):null,o&&!t.result?(0,z.jsx)(M,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,z.jsx)(E,{iface:t.result.questions?{...e,questions:t.result.questions}:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:o}):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)(m,{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:o,maxWidth:s=`960px`,trace:c,flush:l,columns:u=!1,className:f,style:p}){let m=d(),h=x(),g=U(r,t.maxStateBytes),_=W(t.build?.input),{check:v}=g,[y,b]=(0,R.useState)(i??{}),[C,T]=(0,R.useState)(),E=k(t,e.traces,c);return(0,z.jsxs)(S,{inspector:E,maxWidth:s,flush:l,columns:u,requestLabel:m(`@theorem.decision.state`),className:f,style:p,children:[(0,z.jsx)(G,{form:g,built:_,iface:t,images:y,onImages:b,note:_.missing.length>0?m(`@theorem.host.missing`,{fields:_.missing.join(`, `)}):V(m,v,t.maxStateBytes,h),isReady:v.ok&&_.missing.length===0,isRunning:n.status===`deciding`,onRun:()=>{if(!v.ok||_.missing.length>0)return;let e=w(y,v.state);T({images:{...t.images,...e},state:v.state}),n.decide(v.state,Object.keys(e).length>0?e:void 0,_.schema?_.input:void 0)},onStop:n.cancel}),q(u,H(n),{answers:m(`@theorem.decision.answers`),deciding:m(`@theorem.decision.deciding`)},n.startedAt,(0,z.jsx)(K,{iface:t,decision:n,asked:C,onQuestion:a,questionText:o}))]})}function Y(e){let t=d(),n=L(e.transport);return n.describeFailure?(0,z.jsx)(A,{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:i,labels:o,...s}){let l=(0,R.useRef)(t);l.current=t;let u=(0,R.useMemo)(()=>n??c({...l.current,endpoint:e}),[n,e]);return(0,z.jsx)(a,{theme:r,mode:i,children:(0,z.jsx)(f,{labels:o,children:(0,z.jsx)(Y,{...s,transport:u})})})}var Z;function ne(e){if(e.agentId===`pantry.jev`)return Z??=te(),{defaultState:j,defaultImages:{...(0,R.use)(Z)}};if(e.agentId===`research.pagereader`)return{defaultState:N};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?l:u}}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=T(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)(P),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};
|