@theoremjs/studio 0.3.4-next.542.g59bcbcf → 0.3.4-next.548.gbb156b2
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/README.md +3 -3
- package/compile.js +58 -12
- package/cookbooks/catalog.d.ts +8 -3
- package/cookbooks/catalog.js +31 -53
- package/cookbooks/exchanges.d.ts +3 -0
- package/cookbooks/exchanges.js +7 -2
- package/cookbooks/mod.d.ts +2 -2
- package/cookbooks/mod.js +2 -2
- package/cookbooks/project.js +1 -3
- package/draft.d.ts +21 -5
- package/draft.js +10 -2
- package/media-accept.d.ts +7 -0
- package/media-accept.js +17 -0
- package/mod.d.ts +3 -3
- package/mod.js +3 -3
- package/package.json +4 -4
- package/page/assets/Banner-BP1TXM0J.js +2 -0
- package/page/assets/CollapsibleGroup-Bfnp4Aaz.js +1 -0
- package/page/assets/{ConsoleFrame-DL42_IMW.js → ConsoleFrame-Da49DUMV.js} +2 -2
- package/page/assets/{ContextMenu-D7JLUWJP.js → ContextMenu-DGeuOuIz.js} +2 -2
- package/page/assets/{ToolResultCharts-BrPTMzOi.js → ToolResultCharts-DQc5tTgc.js} +1 -1
- package/page/assets/{TraceInspector-CjnIyI8S.js → TraceInspector-Cn7_V-2C.js} +1 -1
- package/page/assets/{TraceOverview-Cb9elM8f.js → TraceOverview-DqhP_wzg.js} +2 -2
- package/page/assets/{_virtual_studio-type-sources-C1mRXxbj.js → _virtual_studio-type-sources-CvOETQ24.js} +19 -1
- package/page/assets/{browser-engine-DhYN8liY.js → browser-engine-BUuO2-Ve.js} +2 -2
- package/page/assets/browser-transport-FDq0Q4Fx.js +47 -0
- package/page/assets/{export-agent-HtS6EUj6.js → export-agent-D-Rj6FQy.js} +8 -8
- package/page/assets/{guardrail-tester-BYh_Ckam.js → guardrail-tester-lZGPnEIR.js} +2 -2
- package/page/assets/index-Bk_jhM4_.js +145 -0
- package/page/assets/{labels-provider-Gus3heEH.js → labels-provider-BObUoNKa.js} +1 -1
- package/page/assets/{live-messages-BNhCuiuF.js → live-messages-DuLSkEdL.js} +1 -1
- package/page/assets/reader-DJB6MzQf.js +7 -0
- package/page/assets/{stub-DPcZtI0s.js → stub-kLwOLu-h.js} +1 -1
- package/page/assets/{studio-code-pane-8jkdZ23I.js → studio-code-pane-D7R84b_Y.js} +3 -3
- package/page/assets/{studio-console-Dow7y-LU.js → studio-console-DgsrR6Qy.js} +1 -1
- package/page/assets/studio-decision-uyaB9Oo3.js +1 -0
- package/page/assets/{studio-embedding-BwrgSWuS.js → studio-embedding-tRaNKz_n.js} +1 -1
- package/page/assets/{studio-host-console-DjsXr0_Z.js → studio-host-console-DzpUuYer.js} +2 -2
- package/page/assets/{studio-labels-JfWwcGVh.js → studio-labels-CByQ2z3Y.js} +2 -2
- package/page/assets/{studio-live-DPIztJgG.js → studio-live-CWeuAs3g.js} +2 -2
- package/page/assets/{studio-map--6V3e7dz.js → studio-map-D7QZ6RAm.js} +1 -1
- package/page/assets/studio-trace-replay-BSts3p2O.js +2 -0
- package/page/assets/{studio-type-checker-B5DVxAZ0.js → studio-type-checker-BNljIXdE.js} +1 -1
- package/page/assets/{tool-schema-CxLtS_Zt.js → tool-schema--CLE7o0H.js} +1 -1
- package/page/assets/tree-CDqNZ8w-.js +3 -0
- package/page/assets/{turn-client-BCi5WnI6.js → turn-client-DXtNeRHG.js} +1 -1
- package/page/assets/types-DTbqRZ5l.js +1 -0
- package/page/assets/{use-one-call-BhUbHUNE.js → use-one-call-TAgOAnMo.js} +1 -1
- package/page/assets/use-trace-records-CZNBjTS0.js +1 -0
- package/page/assets/workspace-Cb6PICiw.js +1 -0
- package/page/index.html +15 -15
- package/read-source.js +30 -4
- package/replay.d.ts +3 -1
- package/replay.js +53 -5
- package/surface.js +1 -2
- package/ui/lib/export-agent.js +20 -2
- package/ui/lib/studio-examples.js +0 -4
- package/ui/lib/studio-page.d.ts +8 -3
- package/ui/lib/studio-page.js +34 -13
- package/ui/profile-editor.js +185 -33
- package/ui/studio-decision.js +4 -1
- package/ui/studio-screen.js +1 -7
- package/ui/studio-trace-replay.js +1 -8
- package/workspace.d.ts +1 -0
- package/workspace.js +3 -2
- package/page/assets/Banner-PRcG1I51.js +0 -2
- package/page/assets/CollapsibleGroup-PavPZ114.js +0 -1
- package/page/assets/browser-transport-DMP57Rqn.js +0 -47
- package/page/assets/index-CGU-m9fg.js +0 -149
- package/page/assets/reader-BT_YeHdq.js +0 -7
- package/page/assets/studio-decision-uF8of9Sn.js +0 -1
- package/page/assets/studio-trace-replay-Ek_RcQpj.js +0 -2
- package/page/assets/tree-Bi2FOU_h.js +0 -3
- package/page/assets/types-s-3wFTyD.js +0 -1
- package/page/assets/use-trace-records-BkAYJz0M.js +0 -1
- package/page/assets/workspace-BiCkglEt.js +0 -1
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,E as n,O as r,T as i,b as a,d as o,f as s,g as c,l,m as u,o as d,p as f,s as p,u as m,v as h,w as g,x as _,y as v}from"./schemas-BQ9Jydzb.js";import{$n as y,Ar as b,Cr as x,Er as S,Fn as ee,Gn as te,H as C,Hn as w,Jn as ne,Kt as re,Ln as T,Nn as E,Pn as ie,Pr as D,Rn as ae,Sr as oe,U as se,Un as ce,Ut as le,Vt as ue,X as de,Xn as fe,Xt as pe,Yn as O,Zt as me,_n as he,ar as ge,cr as _e,er as ve,fr as ye,gn as k,gr as be,hn as xe,in as Se,ir as Ce,jr as we,kr as Te,lr as Ee,mn as A,nn as De,nr as Oe,or as ke,pn as Ae,qn as je,s as Me,sr as Ne,tn as Pe,tr as Fe,vn as Ie,xr as Le,xt as Re,yn as ze,zn as Be}from"./tool-schema-CxLtS_Zt.js";import{c as j}from"./host-patterns-F-KZIzkF.js";import{A as Ve,An as He,B as Ue,Bt as We,En as Ge,Et as Ke,F as qe,Ft as Je,Gt as Ye,Ht as Xe,I as Ze,In as Qe,It as $e,L as et,Ln as tt,Lt as nt,M as rt,Mn as it,Mt as at,N as ot,Nt as st,On as ct,P as lt,Q as ut,Qt as dt,Rn as ft,Rt as pt,Sn as mt,St as ht,Un as M,Ut as gt,Vn as _t,Vt as vt,W as yt,Wn as bt,Wt as xt,X as St,bt as Ct,et as wt,ft as Tt,gn as Et,hn as Dt,it as Ot,jn as kt,jt as At,k as jt,mn as Mt,mt as N,nn as Nt,nt as Pt,pn as Ft,qt as It,rn as Lt,rt as Rt,tt as zt,ut as Bt,wn as Vt,wt as Ht,xn as Ut,zn as Wt,zt as Gt}from"./shaped-data-DYOBdvLJ.js";import{a as Kt,n as qt}from"./live-ingress-OuSlQ6q7.js";import{n as Jt,t as Yt}from"./trace-schema-9CdEyG6Q.js";import{n as Xt}from"./stub-DPcZtI0s.js";function Zt(e){return{type:`guardrail`,guardrail:e}}function Qt(e,t,n,r=`redact`,i){if(n.length!==0)return Zt({stage:e,trust:t,action:r,hits:n,...i?{provenance:i}:{}})}function $t(e,t){return e.type===`guardrail`?{...e,guardrail:Et(e.guardrail,t)}:e}var en=65536;function P(e){let t=e.classStarts.length,n=new Uint16Array(en);for(let r=0;r<t;r++)n.fill(r,e.classStarts[r],e.classStarts[r+1]??en);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 tn,F,nn;async function rn(){if(tn)return;let{FORWARD_AUTOMATON:t,REVERSED_AUTOMATON:n}=await e(async()=>{let{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}=await import(`./egress-automata-SiHQTP1i.js`);return{FORWARD_AUTOMATON:e,REVERSED_AUTOMATON:t}},[]);tn={forward:t,reversed:n}}function an(){if(!tn)throw Error(`A stream was opened before loadEgressAutomata() finished.`);return tn}var I;function on(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 sn(e){if(!I){I=new Map;for(let e=0;e<en;e++){let t=on(e),n=I.get(t);n?n.push(e):I.set(t,[e])}}return I.get(on(e))??[e]}function cn(e){let t=[0];for(let n of e)t.at(-1)!==n&&t.push(n),n+1<en&&t.push(n+1);return t}var ln=new Map;function un(e){let t=ln.get(e);if(t)return t;let n=Array.from({length:e.length},(t,n)=>sn(e.charCodeAt(n))),r=cn([...new Set(n.flat())].sort((e,t)=>e-t)),i=e=>r.indexOf(e),a=P({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 ln.set(e,a),a}function dn(e){let t=JSON.stringify(e),n=ln.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=cn(r),a=r.map(e=>[i.indexOf(e)]),o=[],s=P({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 ln.set(t,s),s}function fn(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 pn(e,t){e.text+=t,e.fresh+=t}function mn(e){return e.text.length-e.fresh.length}function L(e,t){let n=mn(e);return t>=n?e.fresh.charCodeAt(t-n):e.text.charCodeAt(t)}function hn(e,t,n=e.text.length){let r=mn(e);return t>=r?e.fresh.slice(t-r,n-r):e.text.slice(t,n)}function gn(e){let t={text:``,fresh:``,rawAt:e=>e,update(){t.text=e.text,t.fresh=e.fresh}};return t}function _n(e,t){let n={text:``,fresh:``,rawAt:e.rawAt,update(){n.fresh=``,pn(n,t(hn(e,n.text.length)))}};return n}var vn=/\w/,yn=Math.max(...nt.map(e=>e.length));function bn(e){return e.length<=yn+1&&/^[A-Za-z]*$/.test(e)}function xn(e){let t=0,n,r=!1,i=[],a=(e,t,n)=>{pn(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(L(e,t)),o=vn.test(i);o&&!r&&(n=``),r=o,o?n===void 0?a(i,t,1):n+=i:(n!==void 0&&a(vt(n),t-n.length,n.length),n=void 0,a(i,t,1))}n!==void 0&&!bn(n)&&(a(n,t-n.length,n.length),n=void 0)}};return o}function Sn(e){let t={text:``,fresh:``,from:[],rawAt:n=>n<t.from.length?t.from[n]:e(),update(){}};return t}function R(e,t,n){pn(e,t);for(let r=0;r<t.length;r++)e.from.push(n)}var Cn=55296,wn=56319,Tn=/[A-Za-z]/,En=56320,Dn=57343;function On(e){let t=0,n=``,r=[],i=``,a=[],o=!1,s=-1,c=Sn(()=>Math.min(t,r[0]??t,a[0]??t,s<0?t:s));function l(e,t){s>=0&&(Tn.test(e)||R(c,`\\`,s),s=-1),e===`\\`?s=t:R(c,e,t)}function u(e,t){if(Xe(e)&&(o||i)){i+=e;for(let n=0;n<e.length;n++)a.push(t)}else{if(i){if(!Tn.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=Tn.test(e)&&e.length===1}}function d(){let e=0;for(;e<n.length;){let t=n.charCodeAt(e),i=t>=Cn&&t<=wn;if(i&&e+1>=n.length)break;let a=n.charCodeAt(e+1),o=i&&a>=En&&a<=Dn?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=L(e,t),o=a>=Cn&&a<=wn;if(o&&t+1>=i)break;let s=L(e,t+1),c=o&&s>=En&&s<=Dn?2:1,l=gt(hn(e,t,t+c));n+=l;for(let e=0;e<l.length;e++)r.push(t);t+=c}d()},c}var kn=/[0-9A-Fa-f]/;function An(e){let t=0,n=-1,r=Sn(()=>n<0?t:n);r.update=()=>{r.fresh=``;let a=e.text.length;for(;t<a;){let a=String.fromCharCode(L(e,t));if(n<0){a===`%`?n=t:(R(r,a,t),t++);continue}let o=(t-n)%3;if(o===0?a===`%`:kn.test(a))t++;else{i(t-o);for(let n=t-o;n<t;n++)R(r,String.fromCharCode(L(e,n)),n)}}};function i(t){t>n&&R(r,pt(hn(e,n,t)),n),n=-1}return r}var jn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Mn=new Map($e.map(({pattern:e,hit:t})=>[e,t])),Nn=new Map(zt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function z(e){return{rule:Ut(e),severity:`high`,detector:e}}var Pn=z(`injection`),Fn=z(`marker_leak`),In=z(`tool_leak`);function Ln({kind:e,group:t}){if(jn.has(e))return Pn;switch(e){case`sensitive`:case`card`:return t===void 0?void 0:z(t);case`boundary`:return Fn;case`image`:return z(`ungiven_images`);default:return z(`ungiven_links`)}}function Rn(e,t,n){if(e===`card`)return{hit:Pt};if(e===`image`||e===`link`){let r=(e===`image`?Rt:Ot).indexOf(t),i=n[e][r];return`find`in i?{find:i.find}:{hit:i.test}}let r=Mn.get(t)??Nn.get(t);return r?{hit:r}:{}}function zn(e,{given:t,allow:n,skipImages:r}){let i=e=>({...e,...t?{given:t}:{}}),a={image:Bt(i(n?.ungiven_images)),link:Tt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return ut.forEach((t,n)=>{let r=Ln(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:Ye(t.pattern),...Rn(t.kind,t.pattern,a)})}),o}function Bn(){let e=[];return ut.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Mn.get(n);e.push({...Pn,id:r,regex:Ye(n),...i?{hit:i}:{}})}),e}function Vn(){return xt.map((e,t)=>({...Pn,id:t,regex:new RegExp(e.source,e.flags)}))}function Hn(e,t,n){let r=fn(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=mn(e),{classOf:_,has:v,edges:te,final:w,pattern:ne}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,re=(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[ne[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]&&re(n[t],r)}let T=r[e];for(let e=0;e<T.length;e++){let t=T[e],n=i[ne[t]],r=S[n],a=r<0?-1:C[r],o=a<0?p:a;re(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 ne(){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 re(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 T={text:``,lower:``},E=()=>(T.text!==e.text&&(T={text:e.text,lower:e.text.toLowerCase()}),T.lower);function ie(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,E)))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 D(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?re(e,t):ie(e,t);if(r)return r}}return{run(t){w();let n=ne();for(let e=D();e;e=D())t.push(e);return e.rawAt(n)}}}var Un=new WeakMap;function Wn(e){let t=Un.get(e);return t||(t=P(e),Un.set(e,t)),t}function Gn(e={}){let t={text:``,fresh:``},n=gn(t),r=[n],i=(e,t,n)=>(r.includes(e)||r.push(e),Hn(e,t,n)),a=[],o=e.detect??[],s=zn(o,e);if(s.length>0&&(F??=P(an().forward),a.push(i(n,F,s))),o.includes(`injection`)){F??=P(an().forward),nn??=P(an().reversed);let e=On(t),r=Bn();a.push(i(n,nn,Vn()),i(xn(n),F,r),i(e,F,r),i(xn(e),F,r),i(_n(n,We),F,r),i(_n(n,e=>Gt(e)??e),F,r),i(An(t),F,r))}if(o.includes(`marker_leak`)&&e.note){let t=wt(e.note);a.push(i(n,un(e.note),[{...Fn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=yt(e.tools),r=t.map(({regex:e},t)=>({...In,id:t,regex:e}));t.length>0&&a.push(i(n,dn(t.map(({literal:e})=>e)),r))}for(let{detector:t,compiled:r,matchers:o}of e.own??[]){let e=o.map(({regex:e},n)=>({...z(t),id:n,regex:new RegExp(e.source,e.flags)}));a.push(i(n,Wn(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 Kn(e,t,n={},r=[]){let i=qe(e,t).filter(e=>!(et(e)||r.includes(e))),a=Ze(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=Gn({detect:i.filter(e=>s[e]?.theorem!==!1),own:c.flatMap(({detector:e,compiled:t,matchers:n=[]})=>t?[{detector:e,compiled:t,matchers:n}]:[]),skipImages:t.ungiven_images[e]!==`ignore`,...n.allow?{allow:n.allow}:{},...n.givenUrls?{given:n.givenUrls}:{},...n.note?{note:n.note}:{},...n.ownTools?{tools:n.ownTools}:{}}),d=a.some(({find:e})=>e),f=e===`live_reply`?96:256,p=``,m=[];return{push(e){p+=e;for(let{start:t,detector:n}of u.push(e))n&&m.push({start:t,detector:n})},holdFrom(){if(l)return 0;let e=u.holdFrom();return d?Math.min(e,Math.max(0,p.length-f)):e},take(r,i,a=!1){let s=m.filter(({start:e})=>e<i);if(s.length===0&&!a&&!d)return{action:`allow`,text:p.slice(r,i),hits:[],taken:i-r};let c={from:r,to:i,settled:s.map(({detector:e})=>e)},l=lt(p,c,e,t,{detectors:o,scope:n});return m=m.filter(({start:e})=>e>=r+l.taken),l}}}function qn(e){let{context:t}=e,n=e.detect,r=n?Kn(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(-N),_=u,v=0,y=u,b=0,x=0,S=s?ht(s):void 0;S?.push(u);function ee(e){let n=[];if(S?.push(e)&&n.push([a,Dt]),c){let r=_.length;_+=e;let i=Je(_,r);_=_.slice(i),v+=i;let[a]=St(_,c,t.canary);a&&n.push([o,a])}for(let[e,t]of n)e!==`flag`||f.has(t.rule)||(f.add(t.rule),d.push(t));return n.filter(([e])=>e!==`flag`).map(([,e])=>e)}function te(e){let t=l?ee(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function C(){let e=s&&a!==`flag`?ne(s):h.length,n=c&&o!==`flag`?re(c,t.canary):h.length;return m+Math.min(e,n)}function w(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function ne(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-N),i=r+Ct(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+Ct(y,e)),x=Math.min(i,u.length+p.length-N);let a=Math.max(b,Math.max(t,x)-N);return y=y.slice(a-b),b=a,Math.max(0,i-t)}function re(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+st(i,e,t)-u.length-m)}function T(e){let t=te(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(C(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return w({blocked:!1,emit:E(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}:(E(s.taken),w({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function E(e){let t=h.slice(0,e);return h=h.slice(e),m+=t.length,l&&(g=(g+t).slice(-N)),t}return{process(e){return e?(p+=e,h+=e,l&&(y+=e),T(e)):{blocked:!1,emit:``}},flush:()=>T(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>E(h.length),carryOut:()=>l?Ke(u+p,s,c):``}}function B(e,t,n){return ot(t,e.detect,n)}async function Jn(e,t,n,r){return B(e,[n],t)?(await rn(),Yn(e,t,n,r)):null}function Yn(e,t,n,r){return B(e,[n],t)?qn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:n===`reply`,scope:Ue(e,t)},...r?{carry:r}:{}}):null}async function Xn(e,t,n,r){return B(e,[n],r??t)?(await rn(),qn({context:t,detect:{matrix:e.detect,boundary:n,rewrite:!1,scope:r??Ue(e,t)}})):null}var Zn=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}},Qn=2,$n=4,er=3,tr=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,nr=/^[A-Za-z0-9+/]*={0,2}$/,rr=new Set([`text/csv`,`text/plain`,`text/markdown`]);function ir(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 ar(e,t){if(t.limitsByMime){let n=Ie(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 or(e){return`uri`in e}function sr(e){if(e.type===`speech`)throw new j(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new j(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new j(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=ir(e.inputs??{});if(!t)throw new j(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function cr(e){let t=0;return e.endsWith(`==`)?t=Qn:e.endsWith(`=`)&&(t=1),Math.floor(e.length*er/$n)-t}function lr(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function ur(e){return e.replace(tr,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function dr(e,t,n){let r=lr(t);return e===`text/csv`&&(r=ur(r)),new TextEncoder().encode(n.read(r))}function fr(e,t){return t?{...e,fileName:t}:e}function pr(e,t,n){return t.filter(t=>!A(e,t.mimeType)).map(e=>fr({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function mr(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=ar(i.mimeType,t);i.sizeBytes>e&&n.push(fr({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 hr(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(...pr(e.attachments,t,`attachment`)),e.voice&&r.push(...pr(e.voice,n,`voice`)),e.limits?[...r,...mr([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var gr={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 _r(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:gr[e.code],params:t}}function vr(e,t){let n=_r(e);return M(n.key,n.params,t)}function yr(e){return new j(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(_r)})}function br(e){if(!nr.test(e))throw new j(`request`,`attachment data must be base64`);return cr(e)}function xr(e){let t={mimeType:e.mimeType,name:e.name};return or(e)||(t.sizeBytes=br(e.data)),t}function Sr(e,t,n){if(!wr(t,n))return;let r=sr(e),i=hr({attachments:xe(e,`attachments`),voice:xe(e,`voice`),limits:r},(t??[]).map(xr),(n??[]).map(xr));if(i.length>0)throw yr(i)}function Cr(e,t){if(or(e))return e;let{mimeType:n,data:r}=e;if(!rr.has(Ie(n)))return e;let i=dr(n,Ft(r),t);return{...e,data:Mt(i)}}function wr(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Tr(e,t,n,r){return Sr(e,t,n),{attachments:t?.length?t.map(e=>Cr(e,r.attachment)):t,voice:n?.length?n.map(e=>Cr(e,r.voice)):n}}var Er=`
|
|
2
|
-
|
|
3
|
-
`;function Dr(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 Or(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=Dr(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function kr(e,t){let n=Or(e,t);if(n)throw new j(`config`,n)}function Ar(e,t,n){return kr(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function jr(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 Mr(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Er,private:!0}),t.push(...n));return t}function Nr(e){return e.map(e=>e.text).join(``)}function Pr(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:Nr(e),private:t}}function Fr(e,t){return Pr(Mr([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var Ir=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function Lr(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var Rr={client:`untrusted`,server:`assembled`};function zr(e){return typeof e==`string`?e:JSON.stringify(e)}function Br(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of O){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(zr(o));let c=s.found(),l=rt(`context`,c);l&&n.push({...l,trust:Rr[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var Vr=/^[A-Za-z0-9._-]+$/;function Hr(e){let t=e?.trim();return t&&Vr.test(t)?t:void 0}function Ur(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 Wr(e,t){return e.map(e=>{let n=e.content===void 0?void 0:t.read(e.content),r=e.parts?.map(e=>e.type===`text`?{...e,text:t.read(e.text)}:e);return{role:e.role,...n===void 0?{}:{content:n},...r?{parts:r}:{},...e.tool_calls?{tool_calls:e.tool_calls}:{},...e.tool_call_id?{tool_call_id:e.tool_call_id}:{},...e.name?{name:e.name}:{},...e.metadata?{metadata:e.metadata}:{},...e.reasoning?{reasoning:e.reasoning}:{}}})}function Gr(e,t){let n=t?`: ${t}`:``;return new j(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function Kr(e,t){let{detect:n}=ze(t.guardrails),r=Ge(Ir,e=>Ve(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Ar(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=Lr(i.slots,r.slots),c=Br(i.context,()=>Ve(`context`,n)),l=Ur(i.repair,r.repair),u=i.history?Wr(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?Tr(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Ir){let t=r[e].found(),n=rt(e,t);n&&p.push(Zt(n)),t.action===`block`&&(m??=Gr(e,t.errorInternal))}return p.push(...c.events.map(Zt)),c.blocked&&(m??=Gr(`context`)),{request:{...e,system:o,projectId:Hr(e.projectId),input:{...i,text:a,slots:s,...c.context?{context:c.context}:{},repair:l,history:u,attachments:d,voice:f}},events:p,...m?{refusal:m}:{}}}function qr(e,t){let{request:n,refusal:r}=Kr(e,t);if(r)throw r;return n}function Jr(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function Yr(e,t){return[...new Set([...t.filter(t=>A(e,t)),...e.filter(e=>A(t,e))])]}function Xr(e,t){let n=e.attachments?t?Yr(e.attachments.accept,t.media.flatMap(e=>e.accept)):[...e.attachments.accept]:[],r=(t?.media??[]).flatMap(e=>e.maxPerInput===void 0?[]:[{accept:[...e.accept],max:e.maxPerInput}]);return{text:e.text!==!1,...n.length>0?{attachments:{accept:n}}:{},...e.maxFiles===void 0?{}:{maxFiles:e.maxFiles},...e.maxBytes===void 0?{}:{maxBytes:e.maxBytes},...e.maxTurnBytes===void 0?{}:{maxTurnBytes:e.maxTurnBytes},...e.limitsByMime===void 0?{}:{limitsByMime:{...e.limitsByMime}},...t?.maxInputs===void 0?{}:{maxInputs:t.maxInputs},...r.length>0?{perInput:r}:{}}}function Zr(e){let t=Ie(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function Qr(e,t){let n=ir(e),r=hr({attachments:e.attachments?.accept,...n?{limits:{...n,maxFiles:2**53-1}}:{}},t.flat(),[]);if(n)for(let i of t){i.length>n.maxFiles&&r.push({code:`too_many_files`,params:{maxFiles:n.maxFiles}});for(let t of e.perInput??[])i.filter(e=>A(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:Zr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var $r=`final_answer`;function ei(e){return e.structured!==null&&e.tools.wire.length>0}function ti(e,t,n){let{structured:r}=t;if(!r||!ei(t))return e;let i={type:`function`,name:$r,description:M(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function ni(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function ri(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ii(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function V(e){return`tools`in e?e.tools.allow:[]}function ai(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function oi(e){return`tools`in e?e.tools.parallel:void 0}function si(e,t,n){return V(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||ri(i.paths,n.path)})}function ci(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&ri(r.paths,n.path)}):[]}function li(e,t){let n=e.get(t);if(n&&n.type!==`builtin`)return{type:`function`,name:n.name,description:n.description,parameters:n.inputSchema}}function ui(e,t){let n=[];for(let r of t){let t=li(e,r);t&&n.push(t)}return n}function di(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=li(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function fi(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 pi(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function mi(e,t,n){return ii(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function hi(e,t,n,r){let i=si(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ci(e,t,n,r),o=[...i,...a],s=mi(e,t,o),c=pi(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>ni(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:ui(e,c)}}async function gi(e,t,n,r){let i=hi(e,t,n,r);return await vi(e,i,t,n),i}function _i(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)}))}}async function vi(e,t,n,r){let i=ai(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 j(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new j(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);for(let n of a){if(!t.gated.includes(n))continue;let r=e.get(n);r?.loadTier===`T2`&&(r.type===`builtin`?fi(e,t,n):di(e,t,n))}t.executable=t.visible.filter(t=>ni(e,t))}var yi=new Set([`__proto__`,`constructor`,`prototype`]);function bi(e){if(!jt(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function xi(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||yi.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=Ci(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;ri(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)di(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>ni(e,t)),{promoted:a}}function Si(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function Ci(e,t,n){if(!V(n).includes(t))return Si(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?Si(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:Si(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):Si(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function wi(e,t){return e.get(t)||{name:t,missing:!0}}function Ti(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 Ei(e,t){return[...V(t),...Ti(t)].map(t=>wi(e,t))}function Di(e,t){if(Array.isArray(e)){for(let n of e)Di(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),Di(r,t);for(let e of Object.values(r))Di(e,t)}function Oi(e,t){let n=Ei(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&Di(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function ki(e){return!e||e.length===0?[]:e.slice(-4)}function Ai(e,t){if(e.length===0)return``;let n=e.map(e=>`${e.role===`user`?`User`:`Assistant`}: ${e.content}`);return`${M(`repair.history_heading`,{count:e.length},t)}\n${n.join(`
|
|
4
|
-
`)}\n\n`}function ji(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||M(`repair.default_guidance`,{},t.labels),a=Ai(ki(r),t.labels),o=`${M(`repair.prompt_header`,{},t.labels)}\n\n`;return o+=`${M(`repair.prompt_intro`,{},t.labels)}\n\n`,o+=`${M(`repair.section_previous_output`,{},t.labels)}\n\`\`\`\n${n.previousOutput.trim()}\n\`\`\`\n\n`,o+=`${M(`repair.section_validator_rejection`,{},t.labels)}\n${n.rejection.trim()}\n\n`,i.trim()&&(o+=`${M(`repair.section_repair_guidance`,{},t.labels)}\n${i.trim()}\n\n`),a&&(o+=a),o+=`${M(`repair.section_instructions`,{},t.labels)}\n`,o+=M(`repair.prompt_instructions`,{},t.labels),o}function Mi(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function Ni(e,t){let n=Mi(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 Pi(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 Fi(e,t){return e.type===`speech`?{...e.speech,...Ii(t.speech)}:void 0}function Ii(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function Li(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 Ri(e){let t=Ae(e);if(!t)throw new j(`input`,`MIME '${e}' is not a supported media input type`);return t}function zi(e){return e.map(e=>{let t=Ri(e.mimeType),n=Ie(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return or(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Bi(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(k(e)?.text===!1&&n)throw new j(`request`,`Profile ${e.id} does not accept text input`);let a=r?ji({profile:e,repair:r,history:i}):Hi(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Vi(t),...a?[at(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
|
|
5
|
-
|
|
6
|
-
`)}:null}function Vi(e){let t=e.input?.context??{};return[...O].reverse().filter(e=>t[e]!==void 0).map(e=>At(e,zr(t[e])))}function Hi(e,t){if(t.continueFrom&&le.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 M(`continue.instruction`,{},e.labels)}}function Ui(e){return e.type===`image`&&e.image.references?zi(e.image.references):[]}function Wi(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Ui(e),...zi(n),...zi(r)]}function Gi(e,t){let n=[],r=Bi(e,t);return r&&n.push(r),n.push(...Wi(e,t)),n}function Ki(e,t){let n=t.input?.slots;if(!n)return;let r=k(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new j(`request`,`Profile ${e.id} has no slot '${t}'`);if(!n.includes(i))throw new j(`request`,`Profile ${e.id}: slot '${t}' takes ${n.join(`, `)}, not '${i}'`)}}function qi(e,t){let n=t.input?.context;if(!n)return;let r=k(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!O.includes(t)||!r?.from.some(e=>e===t))throw new j(`request`,`Profile ${e.id} takes no context from '${t}'`);if(zr(i).length>r.maxChars)throw new j(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Ji=/\{([A-Za-z_][\w-]*)\}/g;function Yi(e,t,n,r){let i=k(e)?.slots;return i?t.replace(Ji,(t,a)=>{if(!Object.hasOwn(i,a))return t;let o=n&&Object.hasOwn(n,a)?n[a]:void 0;if(o===void 0)throw new j(`request`,`Profile ${e.id}: ${r} uses slot '${a}', and the request chose no value for it`);return o}):t}function Xi(e,t){let{handle:n}=e.identity,r=e.type===`speech`?void 0:e.identity.systemByRole;return t&&r&&Object.hasOwn(r,t)?t:n}function Zi(e,t,n){if(e.type===`speech`)return[];let{systemByRole:r,system:i}=e.identity,a=r?.[t]||i||``;return a?jr(Ar(a,`Profile ${e.id} identity.system`,t=>Yi(e,t,n,`identity.system`))):[]}function Qi(e,t){return Mr([Zi(e,Xi(e,t.input?.role),t.input?.slots),t.system===void 0?[]:jr(t.system)])}function $i(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function ea(e,t){if($i(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 ta(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 na(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 ra(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function ia(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 aa(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function oa(e,t){return e.type===`live`?`live`:`turn`}function sa(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=me(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 ca(e,t){return B(ze(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function la(e){let{detect:t}=ze(e.guardrails);return e.type!==`speech`&&Lt(t,`canary_leak`)?Ht():``}function ua(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 da(e,t,n){let r=ea(e.profiles.get(t.profile),`resolveTurn`);Ki(r,t),qi(r,t);let i=qr(t,r),a=i.input??{};sa(r,i);let o=n??ta(r,i.model),s=he(r,o),c=hi(e.tools,r,i,o),l=c.builtins,u=ia(r,a.slots);if(Ni(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new j(`config`,`Profile ${r.id}: a structured turn answers through '${$r}', so no tool of its own may take that name`);Pi(r,i);let d=ua(r,o,s,i.builtInArgs),f=oa(r,s);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,stream:aa(r),thinking:na(r,s,o,i.effort),summaries:ra(s),maxOutputTokens:s.maxOutputTokens,temperature:s.temperature,builtins:l,builtInArgs:d,sessionId:i.sessionId,tools:c,sessionPermissions:i.sessionPermissions,execution:i.execution,pageExecution:i.pageExecution,history:a.history,maxSteps:r.maxSteps??20,structured:u?{id:u,jsonSchema:e.schemas.get(u).jsonSchema}:null,image:Li(r),speech:Fi(r,i),live:r.type===`live`?ca(r.live,r.guardrails):void 0,input:Gi(r,i),canary:la(r),resolvedSystem:Qi(r,i),host:i.host}}}function fa(e){return e.type===`image`?e.image:null}function pa(e,t){let n=ea(t,`projectProfile`),{identity:r}=n,i=k(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:Ei(e,n),inputs:i,outputs:a,image:fa(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function ma(e,t){return pa(e.tools,e.profiles.get(t))}function ha(e){return e==null}function H(e){return ha(e)||typeof e!=`object`||Array.isArray(e)?null:e}function ga(e){let t=H(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function _a(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function va(e){let t=e.properties;return H(t)??{}}function ya(e,t){return e?`${e}.${t}`:t}function ba(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function xa(e,t,n,r,i){if(!n)return;let a=await n(t,r);a.isValid||i.push({path:e,error:a.error||a.finding||`Validation failed for '${e}'`})}async function Sa(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(ha(r)){i&&ba(t,s);return}await xa(t,r,a?.[t],o,s);let c=ga(n),l=c?H(r):null;c&&l&&await Ca(c,l,t,a,o,s)}async function Ca(e,t,n,r,i,a){let o=va(e),s=new Set(_a(e)),c=new Set([...Object.keys(o),...s]),l=H(t);for(let e of c)await Sa({path:ya(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function wa(e,t,n,r){let i=ga(e);if(!i)throw new j(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!H(t)){for(let e of _a(i))ba(e,a);return a}return await Ca(i,t,``,n,r,a),a}function Ta(e,t){let n=e;for(let e of t.split(`.`)){let t=ga(n);if(!t)return!1;let r=va(t);if(!Object.hasOwn(r,e)&&!_a(t).includes(e))return!1;n=r[e]}return!0}function Ea(e){return e.map(e=>e.error).join(`; `)}function Da(e,t){let n=e;for(let e of t.split(`.`))n=H(n)?.[e];return n}function Oa(e,t,n){let[r,...i]=t.split(`.`),a=H(e)??{};return r===void 0?e:{...a,[r]:i.length?Oa(a[r],i.join(`.`),n):n}}async function ka(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=Da(e,i);if(Array.isArray(t))for(let[e,o]of t.entries()){let t=await a.check(o,n);t.isValid||r.push({path:i,index:e,item:o,reason:t.error||t.finding||`Validation failed for '${i}'`,onFail:a.onFail})}}return r}function Aa(e,t){let n=e;for(let e of t.split(`.`)){let t=ga(n);if(!t)return;n=va(t)[e]}let r=H(n);if(r?.type===`array`)return H(r.items)??void 0}var ja=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Ma=new Set([`text`,`image`,`speech`]),Na=g().regex(/\S/),Pa=t({mimeType:g(),data:m(),name:g().optional()}),Fa=t({mimeType:g(),uri:g(),name:g().optional()}),Ia=t({voice:g().optional(),style:g().optional(),speed:h().positive().optional()});function La(e){return t(Object.fromEntries(Object.entries(e).map(([e,t])=>[e,d(t).optional()])))}var Ra=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function za(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function Ba(e,n){let{inputs:r}=e,a={text:Na};r?.attachments&&(a.attachments=l(i([Pa,Fa])).optional()),r?.voice&&(a.voice=l(Pa).optional()),r?.slots&&(a.slots=La(r.slots).optional()),e.type===`speech`&&(a.speech=Ia.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new j(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new j(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(Ra.has(e))throw new j(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return t(a)}var Va=v({text:g().optional(),structured:n().optional(),removed:l(v({path:g(),reason:g(),item:n()})).optional(),parts:l(ee).optional(),sources:l(Be).optional()});function Ha(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function Ua(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Wa(e,t){if(!Ma.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!Ha(e))return`it does not take text`;for(let n of V(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(Ua(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Ga(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new j(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new j(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=Wa(a,n);if(o)throw new j(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ka(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return V(e).length===0&&!t?`local`:`delegated`}function qa(e){let t=T(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ue(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ja(e,t,n){return{...e,type:`agent`,input:t,output:Va,sources:e=>e.sources??[],...n}}var Ya=/^[\x21-\x7E]{1,256}$/;function Xa(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 Za(e){return e!==null&&Ya.test(e)}async function Qa(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}function $a(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 eo(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`&&to(i,`${n}.properties.${t}`,r)}function to(e,t,n){if(!$a(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&eo(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&to(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`&&to(e,`${t}.${r}[${i}]`,n)})}}function no(e,t){let n=[];if(to(e,`$`,n),n.length>0)throw new j(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function ro(e,t=`output`){let n=r(e,{target:`draft-7`,io:t});return delete n.$schema,n.type||=`object`,n}function io(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(io);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=io(e[n]));return t}function ao(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new j(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}var oo=class{value;constructor(e){this.value=e}};function so(e){return new oo(e)}function co(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return so(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(M(`tool.page_timed_out`,{},i)):Error(M(`tool.page_no_answer`,{tool:e},i))}}function lo(e){let t=ro(e.input,`input`);no(t,`input`);let n=ro(e.output,`output`);no(n,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?Re(n,r[t]):void 0;if(i)throw new j(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:t,outputSchema:n}}function uo(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new j(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function fo(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 j(`config`,`Tool "${e}" auth.queryParam ${r}`)}function po(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new j(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function mo(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new j(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function U(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new j(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function ho(e){U(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(U(e.name,`imageLimits.count`,t.count),U(e.name,`imageLimits.bytes`,t.bytes),U(e.name,`imageLimits.totalBytes`,t.totalBytes),mo(e.name,t.timeoutMs))}function go(e){return ao(e.endpoint),uo(e.name,e.auth),fo(e.name,e.auth,e.mapping?.queryParams),po(e.name,e.limit),mo(e.name,e.timeoutMs),ho(e),{...e,type:`http`,...lo(e)}}function _o(e){return uo(e.name,e.auth),fo(e.name,e.auth),ho(e),U(e.name,`session.idleMs`,e.session?.idleMs),U(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...lo(e)}}function vo(e){uo(e.name,e.auth),fo(e.name,e.auth);let t=e.answeredBy===`page`?co(e.name):e.handler;if(typeof t!=`function`)throw new j(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...lo(e)}}function yo(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=Ga(e,t,n),i=k(r),a=Ba({type:r.type,...i?{inputs:i}:{}},e);return Ja(e,a,lo({...e,input:a,output:Va}))}return e.type===`http`?go(e):e.type===`mcp`?_o(e):vo(e)}function bo(e=()=>void 0){let t=new Map,n=Xa(),r=e=>t.get(e),i=n=>{let i=yo(n,e,r);return t.set(i.name,i),i};return{register:i,registerMany:e=>e.map(e=>i(e)),get:r,require(e){let t=r(e);if(!t)throw new j(`config`,`Tool '${e}' is not registered`);return t},has:e=>t.has(e),list:()=>[...t.values()],findProfile:e,reset:()=>{t.clear(),n.clear()},mcpSessions:n}}function xo(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new j(`config`,M(`provider.binding_identity`))}function So(e){jo(e.id,e.models),$o(e.id,e.observability),xs(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))No(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:Mo(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Co(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new j(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function wo(e,t,n){if(Co(e,t,n,De),xo(e,t,n,`decision`),`retry`in n)throw new j(`config`,`Profile ${e} model '${t}': a decision binding takes no retry; a decision retries only a transient failure, by the kernel's rule`);if(n.timeoutMs!==void 0&&(!Number.isFinite(n.timeoutMs)||n.timeoutMs<=0))throw new j(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function To(e){let t=e.models?Jr(e.models):void 0;if(!t)throw new j(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);wo(e.id,t,e.models[t])}function Eo(e){if(e.inputs.state!==`json`)throw new j(`config`,`Profile ${e.id}: decision inputs.state must be 'json'`);let t=e.inputs.maxStateBytes;if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw new j(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new j(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function Do(e){return To(e),Eo(e),$o(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function Oo(e){return e===void 0?{}:{parallel:e}}function ko(e){return Ao(e.id,e.tools),$o(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...Oo(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Ao(e,t){if(!Array.isArray(t.allow))throw new j(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function jo(e,t){if(Object.keys(t).length===0)throw new j(`config`,`Profile ${e} must declare at least one model`)}function Mo(e,t){let n=t.defaultModel??Jr(t.models);if(!n)throw new j(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new j(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function No(e,t,n){Po(e,t,n),Co(e,t,n,Se),Po(e,t,n)}function Po(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new j(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!Ee.includes(i))throw new j(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${Ee.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new j(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new j(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new j(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function Fo(e){return{providerContinuation:e.providerContinuation?S.parse(e.providerContinuation):{},models:e.models,defaultModel:Mo(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function Io(e,t,n){if(n?.length){for(let r of n)if(!re(r))throw new j(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function Lo(e,t){t&&(Io(e,`allowContinue`,t.allowContinue),Io(e,`autoContinue`,t.autoContinue))}function Ro(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zo(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>Ro(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var Bo=Object.entries(Ce).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Vo(e){if(!Ro(e))throw new j(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new j(`config`,`Profile definition must set id`);if(!ge.find(t=>t===e.type))throw new j(`config`,`Profile ${t}: type must be one of ${ge.join(`, `)}`)}function Ho(e){let t=e.identity?.handle,n=[[`id`,e.id,64],[`identity.handle`,typeof t==`string`?t:``,32]];for(let[t,r,i]of n)if(!(Array.from(r).length<=i))throw new j(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function Uo(e){let{id:t,type:n}=e,r=e;for(let[e,i]of Bo){if(i&&!i.includes(n))continue;let a=oe(e),o=zo(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!Ro(e))return!1;let t=e[s];return t==null||t===``}))throw new j(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Wo(e){let{id:t,type:n}=e;if(n!==`live`&&x(`inputs`).includes(n)&&e.inputs==null)throw new j(`config`,`Profile ${t}: type '${n}' must set inputs`)}function Go(e){let[t]=Le(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new j(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Ko(e,t){let n=t.turnBehaviour;Lo(e,n?.resumption)}function qo(e,t){let n=t=>new j(`config`,`Profile ${e}: ${t}`),r=t?.maxRetries;if(r!==void 0&&(!Number.isInteger(r)||r<0))throw n(`outputs.validation.maxRetries must be a non-negative integer`)}function Jo(e,t){let n=t=>new j(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Yo.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Yo.join(`, `)}`);Zo(t?.blockedReply,n)}var Yo=[`quota`,`detect`,`blockedReply`,`network`,`taint`],Xo=[`onBlock`,`maxRetries`];function Zo(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!Xo.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!D.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${D.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function Qo(e){let t=e.guardrails?.detect,n=e.type===`host`?Nt(`guardrails.detect`,t,Vt):Nt(`guardrails.detect`,t);if(n!==void 0)throw new j(`config`,`Profile ${e.id}: ${n}`)}function $o(e,t){try{let n=Kt(t);if(!Number.isFinite(n.retainForDays))throw new j(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new j(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof j&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new j(He(t),`Profile ${e}: ${n}`,{cause:t})}}function es(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`embedding`)return;let{system:t,systemByRole:n}=e.identity;t!==void 0&&kr(t,`Profile ${e.id} identity.system`);for(let[t,r]of Object.entries(n??{}))kr(r,`Profile ${e.id} identity.systemByRole.${t}`)}function ts(e){Vo(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new j(`config`,M(`provider.profile_configuration`,{profile:e.id,field:t}));if(Go(e),Wo(e),Uo(e),Ho(e),e.labels&&bt(e.labels,`Profile ${e.id}`),es(e),Qo(e),e.type===`host`)return ko(e);if(e.type===`decision`)return Do(e);if(e.type===`embedding`)return So(e);jo(e.id,e.models),Ko(e.id,e),Jo(e.id,e.guardrails),e.type===`text`&&qo(e.id,e.outputs?.validation),$o(e.id,e.observability);for(let[t,n]of Object.entries(e.models))No(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,system:e.identity.system,systemByRole:e.identity.systemByRole},n=e.guardrails,r=e.observability,i=e.labels,a=Fo(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},ss(o.id,o.inputs.attachments?.accept),os(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs,tools:{allow:e.tools.allow,...Oo(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},qt(o),ls(o.id,o.live.contextCompression),cs(o);break;default:throw new j(`config`,`Unknown profile type '${String(e)}'`)}return is(o),ns(o),rs(o),o}function ns(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new j(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function rs(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new j(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function is(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=k(e)?.slots?.[t.by];if(!n)throw new j(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=Object.keys(t.map).filter(e=>!n.includes(e));if(r.length)throw new j(`config`,`Profile ${e.id}: outputs.structured.map maps ${r.join(`, `)}, not a choice of slot '${t.by}'`)}var as={n:{ok:e=>Number.isInteger(e)&&e>=1,rule:`a whole number of 1 or more`},seed:{ok:Number.isInteger,rule:`a whole number`},outputCompression:{ok:e=>Number.isInteger(e)&&e>=0&&e<=100,rule:`a whole number from 0 to 100`}};function os(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(as)){let a=t[n];if(a!==void 0&&!r(a))throw new j(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(Ae(t.mimeType)!==`image`)throw new j(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(or(t)?t.uri:t.data))throw new j(`config`,`${r} needs its bytes or its uri`)})}function ss(e,t){let n=t?.filter(e=>!A(y,e));if(n?.length)throw new j(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function cs(e){let{greeting:t,resumed:n,sessionResumption:r}=e.live,i=`Profile ${e.id} live`;if(t!==void 0&&(typeof t!=`string`||!t.trim()))throw new j(`config`,`${i}.greeting must be a prompt; leave it out to wait`);if(!n)return;if(typeof n.prompt!=`string`||!n.prompt.trim())throw new j(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new j(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new j(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function ls(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(us(`${n}.triggerTokens`,r),us(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new j(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function us(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new j(`config`,`${e} must be a whole number above 0`)}function ds(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(fs(i,r),ps(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new j(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new j(`config`,`${i}: a profile that compacts itself must be a text profile that takes text`);return}let a=e.get(r.profile);if(!a)throw new j(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new j(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function fs(e,t){if(t.maxTokens<=0)throw new j(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new j(`config`,`${e}: compactAt must be in (0, 1)`)}function ps(e,t){if(t.previousExchanges<0)throw new j(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new j(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new j(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function ms(e,t){for(let n of V(t))if(e.get(n)?.type===`builtin`)throw new j(`config`,t.type===`host`?`Profile ${t.id} lists builtin '${n}' in tools.allow — type 'host' never runs a model`:`Profile ${t.id} lists builtin '${n}' in tools.allow — declare it on models.*.builtInTools instead`)}function hs(e,t){let n=ai(t)?.t2Loader;if(n){if(!V(t).includes(n))throw new j(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new j(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*gs(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function _s(e,t){for(let{modelId:n,id:r}of gs(t))if(e.get(r)?.type!==`builtin`)throw new j(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function vs(e){let t=e.type===`text`?e.outputs?.structured:void 0;return t?typeof t==`string`?[t]:[...new Set([...Object.values(t.map),t.fallback])]:[]}function ys(e,t){let n=vs(t).map(n=>{let r=e.find(n);if(!r)throw new j(`config`,`Profile ${t.id}: outputs.structured names '${n}', which is not a registered schema; register it before the profile`);return r}),r=t.type===`text`?t.outputs?.validation:void 0,i=Object.keys(r?.fields??{}),a=Object.keys(r?.items??{});if(!i.length&&!a.length)return;if(!n.length)throw new j(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Aa(t.jsonSchema,e)));if(o.length)throw new j(`config`,`Profile ${t.id}: outputs.validation.items has ${o.join(`, `)}, which no structured schema reaches as a list with an items schema`);let s=i.filter(e=>!n.some(t=>Ta(t.jsonSchema,e)));if(s.length)throw new j(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function bs(e){let t=k(e)?.context;if(!t)return;let n=O;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new j(`config`,`Profile ${e.id}: inputs.context.from must list ${O.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new j(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function xs(e,t){if(!t)return;let{attachments:n,voice:r,maxFiles:i,maxBytes:a,maxTurnBytes:o,limitsByMime:s}=t,c={maxFiles:i,maxBytes:a,maxTurnBytes:o};if((n||r)&&Object.values(c).some(e=>e===void 0))throw new j(`config`,`Profile ${e} must set maxFiles, maxBytes, and maxTurnBytes`);for(let[e,t]of Object.entries(s??{}))c[`limitsByMime['${e}']`]=t;for(let[t,n]of Object.entries(c))if(n!==void 0&&!(Number.isInteger(n)&&n>0))throw new j(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Ss(e,t,n){let r=new Map,i=i=>{let a=ts(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,Pe(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(ms(e,o),hs(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){_s(e,o),xs(o.id,k(o)),bs(o),ys(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&ds(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new j(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function Cs(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function ws(e){let t;try{t=new URL(e.baseUrl)}catch{throw new j(`config`,`Enter a valid localhost URL.`)}if(![`http:`,`https:`].includes(t.protocol)||![`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)||t.username||t.password||t.search||t.hash)throw new j(`config`,`Use a localhost URL without credentials, query parameters or a fragment.`);return{baseUrl:t.href.replace(/\/$/,``),fetch:(e,n)=>new URL(e instanceof Request?e.url:String(e)).origin===t.origin?fetch(e,{...n,redirect:`error`,credentials:`omit`}):Promise.reject(new j(`blocked`,`Local requests must stay on the configured origin.`))}}var Ts=v({data:l(v({id:g().min(1)}))});async function Es(e,t){let n=ws(e);if(!n?.fetch)throw new j(`config`,`Enter a local endpoint.`);let r=await n.fetch(`${n.baseUrl}/v1/models`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)throw new j(`network`,`Local model list returned HTTP ${r.status}.`);let i=Ts.safeParse(await r.json());if(!i.success)throw new j(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var Ds=`https://openrouter.ai/api/v1/models`,Os=`https://openrouter.ai/api/v1/embeddings/models`,ks=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],As=[{id:`liquid/lfm-2.5-embedding-350m:free`,label:`Liquid LFM 2.5 Embedding 350M (free)`},{id:`nvidia/nemotron-3-embed-1b:free`,label:`NVIDIA Nemotron 3 Embed 1B (free)`},{id:`nvidia/llama-nemotron-embed-vl-1b-v2:free`,label:`NVIDIA Llama Nemotron Embed VL 1B v2 (free)`}],js={text:`text`,image:`image`,speech:`speech`,live:void 0,embedding:void 0},Ms=v({data:l(v({id:g().min(1),name:g().optional(),architecture:v({output_modalities:l(g()).optional()}).optional()}))}),Ns=v({data:l(v({id:g().min(1),name:g().optional()}))}),Ps=v({models:l(v({name:g().min(1),displayName:g().optional(),supportedGenerationMethods:l(g()).optional()})).optional(),nextPageToken:g().optional()}),Fs=5;async function Is(e,t,n){let r=await fetch(t,{...n,redirect:`error`,credentials:`omit`});if(r.status===400||r.status===401||r.status===403)throw new j(`auth`,`${e} refused the key.`);if(!r.ok)throw new j(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Ls(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?As:ks];if(e===`openrouter`)return await Rs(t,i,r);if(!i)throw new j(`auth`,`Choose a key to list Gemini models.`);return await Bs(t,i,r)}async function Rs(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Ns.safeParse(await Is(`OpenRouter`,Os,r));if(!e.success)throw new j(`bad_response`,`OpenRouter returned an invalid embedding model list.`);return e.data.data.map(e=>({id:e.id,label:e.name??e.id}))}let i=js[e];if(!i)return[];let a=Ms.safeParse(await Is(`OpenRouter`,`${Ds}?output_modalities=${i}`,r));if(!a.success)throw new j(`bad_response`,`OpenRouter returned an invalid model list.`);return a.data.data.filter(e=>e.architecture?.output_modalities?.includes(i)??!0).map(e=>({id:e.id,label:e.name??e.id}))}var zs={live:`bidiGenerateContent`,embedding:`embedContent`};async function Bs(e,t,n){let r=zs[e]??`generateContent`,i=[],a;for(let e=0;e<Fs;e++){let e=new URL(C);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=Ps.safeParse(await Is(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new j(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function Vs(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Hs(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}var Us=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function Ws(e){return e.join(`,`)}function Gs(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:Ws(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:e?.slots,context:e?.context}}function Ks(e){return{text:e.text,attachments:e.attachments?{accept:e.attachments.accept}:void 0,voice:e.voice?{accept:e.voice.accept}:void 0,maxFiles:e.maxFiles,maxBytes:e.maxBytes,maxTurnBytes:e.maxTurnBytes,limitsByMime:e.limitsByMime,slots:e.slots,context:e.context}}function qs(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=hr({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:ir(Ks(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Js(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(Us.filter(t=>A(e,t)))??e.find(n):r(Us)}var Ys=v({protocol:g(),provider:g(),apiId:g(),options:_(g(),u()).optional(),keySlot:g().optional(),fallbackKeySlot:g().optional(),efforts:_(g(),d(Ee)).optional(),defaultEffort:g().optional(),allowEffortSelect:o().optional(),summaries:o().optional(),maxOutputTokens:h().optional(),temperature:h().optional(),builtInTools:l(g()).optional(),compaction:v({maxTokens:h(),compactAt:h(),previousExchanges:h(),profile:g().optional(),timing:d(ne),meter:d(je).optional()}).optional(),limits:v({operationTimeoutMs:h().optional(),connectTimeoutMs:h().optional(),liveStepTimeoutMs:h().optional(),maxWireRecordBytes:h().optional(),maxWireResponseBytes:h().optional(),maxEventBytes:h().optional(),maxStepBytes:h().optional(),maxStepEvents:h().optional(),maxPendingToolCalls:h().optional()}).optional()}),Xs=v({structured:i([g(),v({by:g(),map:_(g(),g()),fallback:g()}),p()]).optional(),streaming:v({mode:d(_e).optional(),streamThoughts:o().optional()}).optional()}),Zs=v(Ge(mt,()=>d(dt))),Qs=v(Ge(It,()=>Zs)),$s=v({id:g(),label:g(),actions:Zs,names:l(g()),find:o()}),ec=v({hosts:l(g()),fromTools:o()}),tc=v({quota:v({perDay:h()}).optional(),detect:Qs,patterns:a(d(It),v({theorem:o(),names:l(g())})).optional(),host:l($s).optional(),allow:v({ungiven_images:ec,ungiven_links:ec}),blockedReply:v({onBlock:d(D),maxRetries:h()})}),nc=i([o(),v({theorem:o(),host:o()})]),rc=v({record:o(),writeTo:i([c(!1),g()]).optional(),sampleRate:h(),include:v({upstreamLog:o(),outboundWire:o(),evidenceRaw:o(),usage:o(),guardrailDecisions:o(),guardrailMatchPreview:o()}),scrub:v({sensitive:nc,injection:nc,canary:nc}),resource:Yt,retainForDays:h(),rotateAfterMiB:h(),hasOnWriteError:o()}),ic=v({text:o(),attachments:v({accept:l(g()),acceptAttr:g()}).nullable(),voice:v({accept:l(g())}).nullable(),maxFiles:h().optional(),maxBytes:h().optional(),maxTurnBytes:h().optional(),limitsByMime:_(g(),h()).optional(),slots:_(g(),l(g())).optional(),context:v({from:l(d(O)),maxChars:h()}).optional()}),ac=v({allowContinue:l(d(fe)).optional(),autoContinue:l(d(fe)).optional(),maxContinues:h().optional()}),oc=v({resumption:ac.optional()}),sc=v({allow:l(g()),page:l(g()),t2Loader:g().optional(),parallel:o().optional()}),cc={providerContinuation:v({history:d([`host`,`stateless`,`provider`]).optional()}).optional(),id:g(),models:_(g(),Ys),defaultModel:g(),allowModelSelect:o().optional(),maxSteps:h().optional(),labels:a(d(Wt),g()),guardrails:tc.optional(),observability:rc.optional()},lc=i([g(),l(i([g(),t({private:g().min(1)})])).min(1).readonly()]),uc=v({handle:g(),system:lc.optional(),systemByRole:_(g(),lc).optional()}),W=f(`type`,[v({...cc,type:c(`text`),identity:uc,outputs:Xs.optional(),inputs:ic,tools:sc,turnBehaviour:v({resumption:ac.optional(),allowSteering:o().optional(),atStepLimit:d(Ne).optional()}).optional(),canStop:c(!0),allowSteering:o()}),v({...cc,type:c(`image`),identity:uc,outputs:Xs.optional(),image:v({aspectRatio:g().optional(),resolution:g().optional(),mimeType:g().optional(),quality:g().optional(),background:g().optional(),n:h().int().min(1).optional(),seed:h().int().optional(),outputCompression:h().int().min(0).max(100).optional(),references:l(i([v({mimeType:g(),data:g(),name:g().optional()}),v({mimeType:g(),uri:g(),name:g().optional()})])).optional(),includeText:o().optional()}),inputs:ic,tools:sc,turnBehaviour:oc.optional(),canStop:c(!0)}),v({...cc,type:c(`speech`),identity:v({handle:g()}),outputs:Xs.optional(),speech:v({voice:g().optional(),style:g().optional(),speed:h().optional(),format:d(ke).optional()}),inputs:ic,turnBehaviour:oc.optional(),canStop:c(!0)}),v({...cc,type:c(`live`),identity:uc,inputs:ic.pick({slots:!0,context:!0}).optional(),live:v({ingress:v({audio:o().optional(),video:o().optional(),text:o().optional()}).optional(),voice:g().optional(),vad:v({activityHandling:d(ve).optional(),startSensitivity:d(Oe).optional(),endSensitivity:d(Fe).optional(),prefixPaddingMs:h().optional(),silenceDurationMs:h().optional()}).optional(),sessionResumption:o().optional(),contextCompression:v({triggerTokens:h().optional(),slidingWindow:v({targetTokens:h().optional()})}).optional(),transcription:v({input:o().optional(),output:o().optional()}).optional()}),tools:sc.pick({allow:!0,page:!0}),turnBehaviour:v({allowSteering:o().optional()}).optional()})]);function dc(e){let t=ze(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:fc(t.allow.ungiven_images),ungiven_links:fc(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function fc(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function pc(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function mc(e){if(!e)return;let t=Kt(e);return{record:t.record,writeTo:pc(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function hc(e){let{greeting:t,resumed:n,...r}=e??{};return r}function gc(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=ai(t),r=oi(t);return{allow:[...V(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 _c({allow:e,page:t}){return{allow:e,page:t}}function vc(e,t){let n=Gs(e.inputs),r=t?.identity??{handle:e.handle},i=t?dc(t.guardrails):void 0,a=t?mc(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:_t(t?.labels)};switch(e.type){case`text`:return W.parse({...s,type:`text`,inputs:n,tools:gc(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||pe(t)});case`image`:return W.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:gc(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return W.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`live`:return W.parse({...s,type:`live`,live:hc(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:_c(gc(e,t))});default:return e.type}}function yc(e,t){let n=ea(e,`interfaceFromProfile`);return vc(pa(t,n),n)}function bc(e){return s(t=>w.safeParse(e(t)).success)}var xc=[`running`,`gate`,`complete`,`error`,`cancel`],Sc=s(e=>{let t=w.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 xc.some(e=>e===n)}),Cc=_(g(),n()),wc=v({operationId:g().optional(),name:g(),callId:g(),arguments:Cc,draft:g().optional(),reasoning:l(ae).optional(),stepId:g().optional(),edited:v({from:Cc,to:Cc}).optional(),activity:g().optional(),activityPast:g().optional(),outputDraft:g().optional(),state:Sc.optional(),startedAt:h().optional(),endedAt:h().optional(),artifacts:l(n())}),Tc=v({kind:d(be),native:g().optional()}),G={id:g()},K=f(`kind`,[v({...G,kind:c(`user-text`),text:g()}),v({...G,kind:d([`user-attachment`,`user-voice`]),name:g(),mimeType:g(),sizeBytes:h(),data:g().optional()}),v({...G,kind:c(`thought`),text:g()}),v({...G,kind:c(`text`),text:g()}),v({...G,kind:c(`tool`),tool:wc}),v({...G,kind:c(`structured`),value:n(),draft:g().optional()}),v({...G,kind:c(`media`),mimeType:g(),data:g().optional(),url:g().optional(),previewUrl:g().optional()}),v({...G,kind:c(`grounding`),grounding:bc(e=>({type:`grounding`,grounding:e}))}),v({...G,kind:c(`citation`),sources:bc(e=>({type:`citation`,sources:e})),callId:g().optional()}),v({...G,kind:c(`evidence`),evidence:bc(e=>({type:`evidence`,evidence:e}))}),v({...G,kind:c(`guardrail`),guardrail:we}),v({...G,kind:c(`error`),message:g()}),v({...G,kind:c(`turn-done`),stop:Tc.optional(),tokens:bc(e=>({type:`tokens`,tokens:e})).optional(),interactionId:g().optional(),compaction:o().optional(),workedMs:h().optional(),endedAt:h().optional()})]),Ec=v({type:g()});function Dc(e,t){return Object.hasOwn(e,t)}function Oc(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=>Oc(e,n)).join(` | `)}]`}).join(`; `)}function kc(e){return Oc(e.issues,[])}function Ac(e,t){return new j(`bad_response`,`${e} failed its wire check: ${kc(t)}`)}function q(e,t,n){let r=e.safeParse(t);if(!r.success)throw Ac(n,r.error);return r.data}function jc(e){return{type:`malformed`,error:new j(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function Mc(e,t){let n=Ec.safeParse(t);if(!n.success)return jc(`a line without a kind failed its wire check: ${kc(n.error)}`);let{type:r}=n.data;if(!Dc(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:jc(`a '${r}' line failed its wire check: ${kc(i.error)}`)}function Nc(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Pc(e,t){let n=Nc(t);return n?Mc(e,n.value):jc(`a line is not JSON`)}function Fc(e){let t=Nc(e);if(!t)throw new j(`bad_response`,`a line is not JSON`);return t.value}var Ic=v({name:g(),mimeType:g(),data:g()}),Lc=v({slots:_(g(),g()).optional(),context:n().optional(),text:g().optional(),attachments:l(Ic).optional(),voice:l(Ic).optional()}),Rc=v({gateKind:d(ye).optional(),sessionPermissions:l(g()).optional(),name:g().optional(),input:n().optional(),snapshot:te.optional(),promoted:l(g()).optional(),model:g().optional(),effort:g().optional()}),J=g().trim().min(1);v({input:Lc,conversation:g().min(1).optional(),model:g().optional(),effort:g().optional(),turnId:J.optional(),abandon:l(ie).min(1).optional(),replay:Rc.pick({sessionPermissions:!0}).optional(),transcript:l(K).optional()});var zc=[`approve`,`deny`],Bc=i([t({unanswered:c(!0)}),t({output:n()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);v({gateId:g().min(1),operationId:g().min(1).max(256),decision:d(zc),input:n().optional(),secret:g().optional(),page:Bc.optional(),conversation:g().min(1).optional(),turnId:J.optional(),replay:Rc.optional()}),v({turnId:J,id:J,inject:l(ce).min(1)}),v({turnId:J});var Vc=v({type:c(`conversation`),ref:g().min(1),posted:c(!0).optional()}),Hc={...E,conversation:Vc},Uc=v({transcript:l(K),paused:v({events:l(w),blocks:l(K)}).optional()});v({conversation:g().min(1)}),v({conversation:g().min(1),at:h().int().min(-1)}),v({blocks:l(K)});var Wc=v({conversation:g().min(1),view:Uc}),Gc=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 Kc(e){return e instanceof Gc}function qc(e){return e?.trim()||void 0}var Jc=v({error:g().optional(),errorKind:b.optional(),errorCopy:Te.optional(),errorInternal:g().optional()}),Yc=Jc;function Xc(e,t){let n=qc(e.error),r=qc(e.errorInternal);return new Gc(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function Zc(e){return!Kc(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function Qc(e,t){let n=Pc(e,t);if(n.type===`error`)throw Xc(Jc.parse(n),`internal`);return n}function $c(e,t,n){let r=e.split(`
|
|
7
|
-
`),i=r.pop()??``;for(let e of r)e.trim()&&n(Qc(t,e));return i}async function el(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(;;){Qe(r);let{done:e,value:s}=await i.read();if(e)break;o=$c(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(Qc(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function tl(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 nl(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return Xc({errorInternal:`HTTP ${String(e.status)}`},it(e.status))}let i=Jc.safeParse(r);return i.success?Xc({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},it(e.status)):new j(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function rl(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await tl(n),credentials:n.credentials??`same-origin`})}catch(e){throw kt(e)?e:new j(`network`,ct(e),{cause:e})}}async function il(e,t,n,r,i={}){await el(await al(e,t,i),n,r,i.signal)}async function al(e,t,n){let r=await rl(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await nl(r);return r}async function ol(e,t,n={}){await al(e,t,n)}async function Y(e,t,n={}){let r=await rl(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await nl(r,t.failed);return Fc(await r.text())}async function sl(e,t,n={}){let{signal:r,...i}=n;return q(Uc,await Y(e,{body:t,signal:r},i),`the conversation`)}async function cl(e,t,n,r){let{signal:i,...a}=n;return q(Wc,await Y(e,{body:t,signal:i},a),r)}function ll(e,t,n={}){return cl(e,t,n,`the rewound conversation`)}function ul(e,t,n={}){return cl(e,t,n,`the started conversation`)}function dl(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var fl=v({interface:W});function pl(e={}){let t=dl(e.endpoint??`/api/theorem`);return{async describe(n){let r=await rl(t,{method:`GET`,signal:n},e);if(!r.ok)throw await nl(r);return q(fl,Fc(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>il(`${t}/turn`,r,Hc,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>il(`${t}/invoke`,r,Hc,i,{...e,signal:a}),conversation:(n,r)=>sl(`${t}/conversation`,n,{...e,signal:r}),rewind:(n,r)=>ll(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>ol(`${t}/page-result`,n,{...e,signal:r}),steer:n=>ol(`${t}/steer`,n,e),stop:n=>ol(`${t}/stop`,n,e)}}function ml(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?ml(n[0],t):t}function hl(e,t,n){return{type:`decision`,identity:{handle:e.identity.handle},contract:e.decision.contract,...e.inputs.maxStateBytes===void 0?{}:{maxStateBytes:e.inputs.maxStateBytes},questions:Object.entries(t).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>ml(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}})),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:Kt(e.observability).record}}:{}}}function gl(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=h().min(0).max(1),_l=_(g(),X),vl=f(`type`,[v({type:c(`choice`),choice:g(),confidence:X,probabilities:_l}),v({type:c(`noul`),noul:X}),v({type:c(`box`),box:v({top:X,bottom:X,left:X,right:X}),confidence:X}),v({type:c(`score`),score:h().nonnegative(),confidence:X,legend:_(g(),g().min(1)),probabilities:_l})]),yl=v({result:v({model:g().min(1),answers:_(g(),vl),usage:v({inputTokens:h().int().nonnegative(),outputTokens:h().int().nonnegative(),costUsd:h().nonnegative().optional()}).optional()}),traces:l(Jt).optional()}),bl=new WeakMap;function xl(e,t){return t.length>0&&typeof e==`object`&&e&&bl.set(e,t),e}function Sl(e){return typeof e==`object`&&!!e&&bl.get(e)||[]}var Cl=v({traces:l(Jt)});async function wl(e,t,n,r,i){let a=[],o=e=>{let t=Cl.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Y(e,{body:t,signal:n,failed:o},r))}catch(e){throw xl(e,a)}}function Tl(e,t,n,r={}){return wl(e,t,n,r,El)}function El(e){return q(yl,e,`the decision`)}var Dl=v({interface:v({type:c(`decision`),identity:v({handle:g()}),contract:g(),maxStateBytes:h().optional(),questions:l(v({id:g(),type:d([`choice`,`noul`,`score`,`box`]),labels:l(g()),image:g().optional()})),images:_(g(),v({mimeType:d([`image/png`,`image/jpeg`]),data:g()})).optional(),observability:v({record:o()}).optional()})});function Ol(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return q(Dl,await Y(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i)=>Tl(`${t}/decide`,{state:n,...i?{assets:i}:{}},r,e)}}function kl(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 Al(e){let t=new Set;return e.filter(e=>!t.has(e.uri)&&(t.add(e.uri),!0))}function jl(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 Al([...t,...n])}function Ml(e){if(Array.isArray(e))return e;if(!kl(e))return[];for(let t of[`items`,`results`,`search_results`,`models`,`datasets`]){let n=e[t];if(Array.isArray(n))return n}return[]}function Nl(e,t){return Al(e.flatMap(e=>kl(e)?t(e)??[]:[]))}function Pl(e,t){let n=t===`dataset`?`https://huggingface.co/datasets/`:`https://huggingface.co/`;return Nl(Ml(e),e=>{let t=Z(e,`id`)??Z(e,`modelId`);return t?Q(t,`${n}${t}`):void 0})}function Fl(e){return Nl(Ml(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 Il(e){return e.replace(/<[^>]+>/g,``).replace(/\s+/g,` `).trim()}function Ll(e){if(typeof e!=`string`)return jl(JSON.stringify(e));let t=[...e.matchAll(/<entry\b[\s\S]*?<\/entry>/g)];return t.length===0?jl(e):Al(t.flatMap(e=>{let t=/<id>(https?:\/\/[^<]+)<\/id>/.exec(e[0]??``)?.[1],n=/<title>([\s\S]*?)<\/title>/.exec(e[0]??``)?.[1];return t?Q(Il(n??t),t)??[]:[]}))}function $(e){if(typeof e==`string`)return jl(e);if(Array.isArray(e)||kl(e)){let t=Nl(Ml(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:jl(JSON.stringify(e))}return[]}var Rl={search_models:e=>Pl(e,`model`),search_datasets:e=>Pl(e,`dataset`),search_github:Fl,list_arxiv:Ll,search_web:$,read_pages:$,read_model_card:$,read_dataset_card:$,read_readme:$,find_library:$,read_library_docs:$,ask_repo_docs:$};function zl(e){return Rl[e]}function Bl(e,t){let n=zl(e);return n?{...t,sources:n}:t}function Vl(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:Me(t.inputSchema),output:Me(t.outputSchema)};if(t.type===`http`){e.register(Bl(t.name,{...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(Bl(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??Xt(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 Hl(e,t,n){e.registerMany([...se,...de]);for(let r of t)Vl(e,r,n)}function Ul(e,t,n,r,i){return Hl(e.tools,n,i),r&&t.type!==`live`&&e.schemas.register(r.id,r.spec),e.profiles.register(t),t}function Wl(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 Gl(e){if(e.type!==`error`&&e.type!==`session`&&e.type!==`tool`||e.errorInternal===void 0)return e;let{errorInternal:t,...n}=e;return n}function Kl(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function ql(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 Jl(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function Yl(e,t){let n=t?.reader===`builder`?Wl(e):Kl(ql(Gl(e)));return t?.includeEvidenceRaw||(n=Jl(n)),n=$t(n,!1),n}function Xl(e,t){return e.map(e=>Yl(e,t))}function Zl(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=Yl(ft(tt(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var Ql={reader:`builder`};function $l(e){return e.mode===`demo`?{reader:`visitor`}:Ql}export{Wa as $,Pc as A,Xr as At,Vs as B,yr as Bt,Yc as C,oi as Ct,il as D,ei as Dt,ol as E,$r as Et,qs as F,qr as Ft,oo as G,Yn as Gt,Ss as H,Zn as Ht,Cs as I,Kr as It,io as J,Gn as Jt,ao as K,B as Kt,Es as L,Fr as Lt,K as M,Gr as Mt,yc as N,Br as Nt,q as O,ti as Ot,Js as P,Wr as Pt,ja as Q,$t as Qt,Ls as R,Or as Rt,Xc as S,V as St,Zc as T,xi as Tt,ts as U,Xn as Ut,Hs as V,br as Vt,bo as W,Jn as Wt,Za as X,Qt as Xt,Xa as Y,rn as Yt,Qa as Z,Zt,pl as _,Oi as _t,Xl as a,ka as at,ll as b,bi as bt,Ol as c,Aa as ct,Sl as d,ta as dt,Ba as et,Tl as f,ma as ft,Gc as g,Gi as gt,Hc as h,qi as ht,Yl as i,za as it,Mc as j,Jr as jt,kc as k,Qr as kt,gl as l,Da as lt,xl as m,Yi as mt,$l as n,Va as nt,Ul as o,wa as ot,wl as p,da as pt,ro as q,Kn as qt,Zl as r,qa as rt,Hl as s,Ea as st,Ql as t,Ka as tt,hl as u,Oa as ut,sl as v,_i as vt,Kc as w,ai as wt,ul as x,gi as xt,Y as y,vi as yt,ws as z,vr as zt};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{h as r,n as i,s as a}from"./browser-transport-DMP57Rqn.js";import{n as o,t as s}from"./labels-provider-Gus3heEH.js";import{a as c,t as l}from"./Banner-PRcG1I51.js";import{c as u}from"./reader-BT_YeHdq.js";import{p as d,u as f}from"./tree-Bi2FOU_h.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-DL42_IMW.js";import{i as T,t as E}from"./use-one-call-BhUbHUNE.js";import{$ as D,Q as O,_ as k,g as A,l as j,m as M}from"./index-CGU-m9fg.js";import{t as N}from"./studio-console-Dow7y-LU.js";var P=(e,t,n,r)=>e.decide(n,t,r);function F(e){let{iface:t,describeFailure:n}=M(e),{call:r,...i}=E(e,`deciding`,P);return{iface:t,describeFailure:n,...i,decide:r}}var I=e(n(),1),L=t();function R(e,t){let n;try{n=JSON.parse(e)}catch{return{ok:!1,reason:`invalid_json`}}if(n===null)return{ok:!1,reason:`null_state`,state:n};let r=new TextEncoder().encode(JSON.stringify(n)).byteLength;return t!==void 0&&r>t?{ok:!1,reason:`too_large`,bytes:r,state:n}:{ok:!0,state:n,bytes:r}}function z(e,t,n,r){return t.ok?n===void 0?null:e(`@theorem.decision.state_size`,{size:r(t.bytes),limit:r(n)}):t.reason===`too_large`?e(`@theorem.decision.too_large`,{limit:r(n??0)}):e(t.reason===`invalid_json`?`@theorem.decision.invalid_json`:`@theorem.decision.null_state`)}function B(e){return e.failure||e.result?`settled`:e.status===`deciding`?`waiting`:`idle`}function V(e,t){let[n,r]=(0,I.useState)(e),i=R(n,t),[a,o]=(0,I.useState)(()=>i.state===void 0?`json`:`fields`);return{text:n,setText:r,check:i,shown:i.state===void 0?`json`:a,setView:o}}function H({form:e,iface:t,images:n,onImages:r,note:i,isRunning:a,onRun:s,onStop:c}){let l=o(),{text:u,setText:d,check:f,shown:m,setView:x}=e,S=t.questions.some(e=>e.type===`box`)||Object.keys(n).length>0,w=m===`fields`?f.state:void 0,T=p(w);return(0,L.jsxs)(_,{title:l(`@theorem.decision.state`),view:m,hasFields:f.state!==void 0,onView:x,onRun:s,children:[w===void 0?(0,L.jsx)(b,{label:l(`@theorem.decision.state`),text:u,isInvalid:!f.ok,onChange:d}):(0,L.jsx)(y,{value:{images:n,onImages:r},children:(0,L.jsx)(h,{label:l(`@theorem.decision.state`),value:w,onChange:e=>{d(JSON.stringify(e,null,2))}})}),S&&T?(0,L.jsx)(g,{onImages:e=>{let i=C(e,{images:n,host:t.images,state:T});r(i.images),d(JSON.stringify(i.state,null,2))}}):null,(0,L.jsx)(v,{note:i,isReady:f.ok,isRunning:a,runLabel:l(`@theorem.decision.decide`),runningLabel:l(`@theorem.decision.deciding`),stopLabel:l(`@theorem.decision.stop`),onRun:s,onStop:c})]})}function U({iface:e,decision:t,asked:n,onQuestion:r,questionText:i}){let a=o(),s=t.status===`deciding`;return(0,L.jsxs)(L.Fragment,{children:[t.failure?(0,L.jsx)(l,{status:`error`,role:`alert`,title:t.failure.error}):null,s&&!t.result?(0,L.jsx)(k,{label:a(`@theorem.decision.deciding`),since:t.startedAt}):null,t.result?(0,L.jsx)(T,{iface:e,result:t.result,asked:n,onQuestion:r,questionText:i,elapsedMs:t.elapsedMs,isStale:s}):null]})}function W(e,t,n,r,i){if(t===`idle`)return null;if(!e)return i;let a=t===`waiting`;return(0,L.jsx)(m,{label:n.answers,fill:a,children:a?(0,L.jsx)(k,{label:n.deciding,since:r}):i})}function G({transport:e,iface:t,decision:n,defaultState:r=`{}`,defaultImages:i,onQuestion:a,questionText:s,maxWidth:l=`960px`,trace:u,flush:d,columns:f=!1,className:p,style:m}){let h=o(),g=x(),_=V(r,t.maxStateBytes),{check:v}=_,[y,b]=(0,I.useState)(i??{}),[C,T]=(0,I.useState)(),E=c(t,e.traces,u);return(0,L.jsxs)(S,{inspector:E,maxWidth:l,flush:d,columns:f,requestLabel:h(`@theorem.decision.state`),className:p,style:m,children:[(0,L.jsx)(H,{form:_,iface:t,images:y,onImages:b,note:z(h,v,t.maxStateBytes,g),isRunning:n.status===`deciding`,onRun:()=>{if(!v.ok)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)},onStop:n.cancel}),W(f,B(n),{answers:h(`@theorem.decision.answers`),deciding:h(`@theorem.decision.deciding`)},n.startedAt,(0,L.jsx)(U,{iface:t,decision:n,asked:C,onQuestion:a,questionText:s}))]})}function K(e){let t=o(),n=F(e.transport);return n.describeFailure?(0,L.jsx)(A,{title:n.describeFailure.error}):n.iface?(0,L.jsx)(G,{...e,iface:n.iface,decision:n}):(0,L.jsx)(k,{label:t(`@theorem.chat.loading`)})}function q({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:o,...c}){let l=(0,I.useRef)(t);l.current=t;let d=(0,I.useMemo)(()=>n??u({...l.current,endpoint:e}),[n,e]);return(0,L.jsx)(a,{theme:r,mode:i,children:(0,L.jsx)(s,{labels:o,children:(0,L.jsx)(K,{...c,transport:d})})})}var J;function Y(e){if(e.agentId===`pantry.jev`)return J??=D(),{defaultState:O,defaultImages:{...(0,I.use)(J)}};let{profile:t}=e;return{defaultState:(t.type===`decision`?Object.values(t.models)[0]:void 0)?.apiId.startsWith(`respan/`)?d:f}}function X(e){return typeof e==`string`?e:Array.isArray(e)?e.map(X).join(` `):Object.entries(e).map(([e,t])=>`${e}: ${X(t)}`).join(` `)}function Z(e){let t=N(e,r,i);return(0,L.jsx)(Q,{...e,transport:t})}function Q({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let{open:o}=(0,I.useContext)(j),s=Y(e),{questions:c}=e,l=(0,I.useMemo)(()=>c&&Object.fromEntries(Object.entries(c).map(([e,t])=>[e,X(t.instructions)])),[c]);return(0,L.jsx)(q,{transport:t,...s,trace:n,flush:r,columns:i,className:a,onQuestion:o,questionText:l})}export{Q as DecisionView,Z as StudioDecision};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{n as r,t as i}from"./SegmentedControlItem-BLuJOusN.js";import{t as a}from"./VStack-CkVMcNiK.js";import{M as o,a as s,b as c,o as l,s as u,y as d}from"./browser-transport-DMP57Rqn.js";import{r as f}from"./IconButton-CG5klqF1.js";import{t as p}from"./Text-BsiAsowd.js";import{n as m,t as h}from"./labels-provider-Gus3heEH.js";import{a as g,t as _}from"./Banner-PRcG1I51.js";import{t as v,v as ee}from"./studio-labels-JfWwcGVh.js";import{c as y}from"./host-patterns-F-KZIzkF.js";import{w as b}from"./shaped-data-DYOBdvLJ.js";import{n as x}from"./trace-record-B2MF8flo.js";import{n as S}from"./trace-schema-9CdEyG6Q.js";import{_ as C}from"./turn-client-BCi5WnI6.js";import{a as w,i as T,o as E,t as D}from"./ConsoleFrame-DL42_IMW.js";import{S as te,a as O,b as ne,h as re,y as ie}from"./index-CGU-m9fg.js";var k=e=>typeof e==`object`&&!!e&&!Array.isArray(e),A=(e,t)=>e.attributes[t],j=(e,t)=>{let n=A(e,t);return typeof n==`string`?n:void 0};function M(e,t,n){let r=A(t,n);return r===void 0?void 0:x(e,r)}function N(e,t,n){let r=M(e,t,n);return r===void 0?``:typeof r==`string`?r:JSON.stringify(r)}function P(e,t,n){let r=M(e,t,n);return Array.isArray(r)?r.filter(k):[]}var F=e=>Array.isArray(e.parts)?e.parts.filter(k):[],I=e=>BigInt(String(e.startTimeUnixNano)),L=(e,t)=>{let n=I(e)-I(t);return n===0n?0:n<0n?-1:1},ae=e=>`content_sha256`in e||`json_sha256`in e;function R(e){let t=e.arguments;if(k(t))return t;if(typeof t!=`string`)return{};try{let e=JSON.parse(t);return k(e)?e:{}}catch{return{}}}function z(e){if(typeof e.content==`string`){if(e.type===`reasoning`)return{type:`thought`,text:e.content};if(e.type===`text`)return{type:`text`,text:e.content}}}function oe(e){let t=[],n=[],r=!1;for(let i of e){let e=F(i),a=e.some(e=>e.type===`text`);for(let i of e){let e=z(i);ae(i)?r=!0:e?t.push(e):i.type===`structured`&&!a?t.push({type:`text`,text:JSON.stringify(i.content)}):i.type===`tool_call`&&typeof i.name==`string`?(n.push(i.name),t.push({type:`tool`,tool:{name:i.name,callId:typeof i.id==`string`?i.id:`replay-${String(n.length)}`,arguments:R(i)}})):(i.type===`blob`||i.type===`uri`)&&(r=!0)}}return{events:t,calls:n,missing:r}}function se(e,t){for(let n=e;n;n=t.get(n.parentSpanId??``)){let e=j(n,`gen_ai.agent.name`);if(j(n,`gen_ai.operation.name`)===`invoke_agent`&&e)return e}return``}var B=e=>j(e,`gen_ai.operation.name`);function ce(e){let t=new Map(e.spans.map(e=>[e.spanId,e]));return e.spans.filter(e=>B(e)===`chat`).toSorted(L).map(n=>{let r=oe(P(e,n,`gen_ai.output.messages`)),i=j(n,`theorem.stop.kind`)??`completed`;return{agent:se(n,t),...r,events:[...r.events,{type:`done`,stop:{kind:i}}]}})}function le(e){return e.spans.filter(e=>B(e)===`execute_tool`).toSorted(L).map(t=>({name:j(t,`gen_ai.tool.name`)??``,result:N(e,t,`gen_ai.tool.call.result`),failed:j(t,`theorem.tool.outcome`)===`error`}))}function ue(e,t){let n=P(e,t,`gen_ai.input.messages`).findLast(e=>e.role===`user`),r=n?F(n):[];return{text:r.flatMap(e=>e.type===`text`&&typeof e.content==`string`?[e.content]:[]).join(`
|
|
2
|
-
`),attachments:r.filter(e=>e.type===`blob`||e.type===`uri`).length}}function de(e,t){let n=[];for(let r of t.events??[]){if(r.name!==`theorem.grounding`)continue;let i=r.attributes.sources;if(i===void 0)continue;let a=x(e,i);if(!Array.isArray(a))continue;let o=[];for(let e of a)k(e)&&typeof e.title==`string`&&typeof e.uri==`string`&&o.push({title:e.title,uri:e.uri,type:e.type===`maps`?`maps`:`web`,...typeof e.placeId==`string`?{placeId:e.placeId}:{}});if(o.length){let e=j(t,`gen_ai.tool.call.id`);n.push({type:`citation`,sources:o,...e?{callId:e}:{}})}}return n}function V(e,t){let n=e.spans.filter(e=>B(e)===`execute_tool`).toSorted(L),r=new Set,i=(e,t)=>{let i=n.find(t=>j(t,`gen_ai.tool.call.id`)===e)??n.find(e=>!r.has(e)&&j(e,`gen_ai.tool.name`)===t);return i&&r.add(i),i},a=[];for(let n of P(e,t,`gen_ai.output.messages`))for(let t of F(n)){let n=z(t);if(n)a.push(n);else if(t.type===`structured`&&t.content!==void 0)a.push({type:`structured`,structured:t.content});else if(t.type===`tool_call`&&typeof t.name==`string`){let n=typeof t.id==`string`?t.id:`call-${String(a.length)}`;a.push(...fe(e,t.name,n,R(t),i))}}let o=N(e,t,`theorem.error.public`);t.status.code===`ERROR`&&a.push({type:`error`,errorKind:`internal`,error:o||t.status.message});let s=j(t,`theorem.stop.kind`)??`completed`;return a.push({type:`done`,stop:{kind:s}}),a}function fe(e,t,n,r,i){let a=i(n,t),o={type:`tool`,tool:{name:t,callId:n,arguments:r}};if(!a)return[o];let s=Number(I(a)/1000000n),c=N(e,a,`gen_ai.tool.call.result`);return[o,{type:`tool`,tool:{name:t,callId:n,at:s,...j(a,`theorem.tool.outcome`)===`error`?{phase:`error`,failure:{code:j(a,`theorem.tool.failure.code`)??`failed`,kind:`internal`,message:c},readBack:c}:{phase:`complete`,output:H(c),readBack:c}}},...de(e,a)]}function H(e){try{return JSON.parse(e)}catch{return e}}function pe(e){let t=``,n,r=[];return e.forEach((e,i)=>{let a=b(e);if(!a||B(a)!==`invoke_agent`)return;let o=j(a,`gen_ai.agent.name`)??``;t||=o;let s=ce(e),c=le(e),l=r.at(-1);if(o!==t&&l){l.calls.push(...s),l.results.push(...c);return}n??=Number(I(a)/1000000n);let u=ue(e,a);r.push({...u,calls:s,results:c,blocks:C({text:u.text},V(e,a),{idPrefix:`recorded-${String(i)}`})})}),{agent:t,turns:r,...n===void 0?{}:{recordedAt:n}}}function me(e){if(e.failed)throw Error(e.result);let t=H(e.result);return k(t)?t:{result:t}}var he=e=>{let t=e%100,n=t>=11&&t<=13?`th`:{1:`st`,2:`nd`,3:`rd`}[e%10]??`th`;return`${String(e)}${n}`};function U(e,t,n){if(!e)return`The profile asked the model a ${he(t+1)} time this turn; the recording answered ${String(t)}.`;if(e.missing)return`The recording does not hold all of this reply.`;let r=new Set((n.wireTools??[]).map(e=>e.name)),i=e.calls.find(e=>!r.has(e));return i&&`The recording calls ${i}, which the profile no longer offers.`}function ge(e,t,n){let r=0,i=new Map,a=new Map,o=t=>{let n=a.get(t);if(!n){n=new Map;for(let r of e.turns[t]?.results??[])n.set(r.name,[...n.get(r.name)??[],r]);a.set(t,n)}return n},s=t=>({async*complete(a){let o=e.turns[r]?.calls.filter(e=>e.agent===t)??[],s=`${String(r)} ${t}`,c=i.get(s)??0;i.set(s,c+1);let l=U(o[c],o.length,a);if(l)throw n({turn:r,call:c+1,reason:l}),new y(`request`,`Replay stopped: ${l}`);yield*o[c]?.events??[]}}),c=e=>()=>{let t=o(r).get(e)?.shift();if(!t)throw Error(`The recording has no further result for ${e}.`);return me(t)},l=new Set(e.turns.flatMap(e=>e.results.map(e=>e.name)));return{provider:n=>s(n.id===t?e.agent:n.id),toolHandlers:Object.fromEntries([...l].map(e=>[e,c(e)])),startTurn:e=>{r=e}}}function W(e){return e.map(e=>{if(e.type===`agent`)return e;let{name:t,description:n,category:r,access:i,permission:a,loadTier:o,paths:s}=e;return{type:`function`,name:t,description:n,category:r,access:i,permission:a,loadTier:o,paths:s,inputSchema:e.inputSchema,outputSchema:e.outputSchema,...e.labels?{labels:e.labels}:{}}})}function _e(e){return{...e,customTools:W(e.customTools),...e.dependencies?{dependencies:e.dependencies.map(e=>({...e,customTools:W(e.customTools)}))}:{}}}function G(e){return e.turns.flatMap(e=>e.blocks)}function ve(e){let t=Array.isArray(e)?e:[e];return t.map((e,n)=>{let r=S.safeParse(e);if(r.success)return r.data;let i=t.length>1?` (record ${String(n+1)})`:``;throw new y(`request`,`This file is not a Theorem trace${i}.`)})}function ye(e){let t;try{t=JSON.parse(e)}catch{throw new y(`request`,`This file is not JSON.`)}return ve(t)}var K=e(n(),1),q=t();function be(e,t,n){return t?l(e,t,{conversationKey:O(),blocks:n}):d(e,n)}var J=e=>`turn ${String(e+1)}`;function Y({iface:e,feed:t,trace:n,card:r,conversation:i}){let a=g(e,t,n);return(0,q.jsxs)(D,{inspector:a,maxWidth:`960px`,requestLabel:`Trace`,children:[r,i]})}function X({iface:e,blocks:t,banner:n,chat:r}){let i=m();return(0,q.jsxs)(w,{label:`Conversation`,children:[n,(0,q.jsx)(te,{blocks:t,handle:i(`@theorem.agent.handle`,{handle:e.identity.handle}),labels:e.labels,streaming:r?.streaming,delivery:r?.delivery,answering:r?.answering,onToolDecision:r&&((e,t)=>{r.handleToolDecision(e,t)}),onAuthenticated:r&&((e,t)=>{r.handleAuthenticated(e,t)})})]})}function xe({onImport:e}){let[t,n]=(0,K.useState)(),[r,i]=(0,K.useState)(!1);return(0,q.jsxs)(a,{gap:2,children:[(0,q.jsx)(ne,{label:`Trace file`,isLabelHidden:!0,mode:`dropzone`,accept:`application/json,.json`,isLoading:r,placeholder:`Drop a trace (.json) or choose a file`,value:null,changeAction:async t=>{let r=Array.isArray(t)?t[0]:t;if(r){i(!0);try{e({name:r.name,records:ye(await r.text())}),n(void 0)}catch(e){n(e instanceof Error?e.message:String(e))}finally{i(!1)}}},onChange:()=>void 0}),t?(0,q.jsx)(_,{status:`error`,title:t}):null]})}var Se=e=>e.recordedAt===void 0?void 0:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`,timeStyle:`short`}).format(e.recordedAt);function Ce({shown:e,onShown:t}){return(0,q.jsxs)(r,{label:`Show`,size:`sm`,value:e,onChange:e=>{t(e===`replayed`?`replayed`:`recorded`)},children:[(0,q.jsx)(i,{value:`recorded`,label:`Recorded`}),(0,q.jsx)(i,{value:`replayed`,label:`Replayed`})]})}function we({controls:e}){let{script:t,payload:n}=e,r=t.turns.length,i=[t.agent||`No agent`,`${String(r)} ${r===1?`turn`:`turns`}`,Se(t)];return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(a,{gap:0,children:[(0,q.jsx)(p,{type:`label`,maxLines:1,children:e.opened.name}),(0,q.jsx)(p,{type:`supporting`,color:`secondary`,maxLines:1,children:i.filter(Boolean).join(` · `)})]}),t.agent&&t.agent!==n.profile.id?(0,q.jsx)(_,{status:`info`,title:`Recorded with ${t.agent}; a replay runs through ${n.profile.id}.`}):null,r===0?(0,q.jsx)(_,{status:`info`,title:`This trace holds no conversation to replay.`}):null,(0,q.jsx)(ie,{label:`Live tools`,description:`Run the profile's tools instead of answering them from the recording.`,value:e.liveTools,onChange:e.onLiveTools})]})}var Z=()=>void 0;function Q({onImport:e,controls:t}){let n=t?.onReplay??Z;return(0,q.jsxs)(T,{title:`Trace`,onRun:n,actions:t?.shown?(0,q.jsx)(Ce,{shown:t.shown,onShown:t.onShown}):null,children:[(0,q.jsx)(xe,{onImport:e}),t?(0,q.jsx)(we,{controls:t}):null,(0,q.jsx)(E,{note:t?`Answers each model call from the recording, so it needs no keys.`:null,isReady:(t?.script.turns.length??0)>0,isRunning:t?.isRunning??!1,runLabel:t?.shown?`Replay again`:`Replay`,runningLabel:`Replaying`,stopLabel:`Stop`,onRun:n,onStop:t?.onStop??Z})]})}function Te({status:e,turns:t,onContinue:n,onLive:r}){let[i,o]=(0,K.useState)(!1),[s,c]=(0,K.useState)(),l=e=>(0,q.jsx)(f,{label:`Continue live`,variant:`secondary`,size:`sm`,isLoading:i,onClick:async()=>{o(!0),c(void 0);try{await r(e)}catch(e){c(e instanceof Error?e.message:String(e)),o(!1)}}}),u=(()=>{switch(e.kind){case`running`:return(0,q.jsx)(_,{status:`info`,title:`Replaying ${J(e.turn)} of ${String(t)}`});case`waiting`:return(0,q.jsx)(_,{status:`info`,title:`${J(e.turn-1)} waits on you`,description:`Answer it in the conversation, then continue the replay.`,endContent:(0,q.jsx)(f,{label:`Continue replay`,variant:`secondary`,size:`sm`,onClick:()=>{n(e.turn)}})});case`missing`:return(0,q.jsx)(_,{status:`warning`,title:`Replay stopped before ${J(e.turn)}`,description:`It was sent with files, and a trace never holds a file's bytes. Continue live to send it again with yours.`,endContent:l(e.turn)});case`diverged`:{let{turn:t,call:n,reason:r}=e.divergence;return(0,q.jsx)(_,{status:`warning`,title:`Replay stopped at ${J(t)}, model call ${String(n)}`,description:r,endContent:l(t)})}case`failed`:return(0,q.jsx)(_,{status:`error`,title:`Replay stopped at ${J(e.turn)}`,description:e.message,endContent:l(e.turn)});case`done`:return(0,q.jsx)(_,{status:`success`,title:`Replayed ${String(t)} ${t===1?`turn`:`turns`}`,description:`Every model call this profile made was one the recording answered.`})}})();return(0,q.jsxs)(a,{gap:1,children:[u,s?(0,q.jsx)(_,{status:`error`,title:s}):null]})}function $(e){let t=o();for(let n of e)t.push(n);return t}function Ee({payload:e,iface:t,trace:n,card:r,opened:i,script:a,shown:c,liveTools:l,runtime:u,onLive:d}){let f=(0,K.useRef)(void 0),[p,m]=(0,K.useState)({kind:`running`,turn:0}),[h]=(0,K.useState)(o),g=(0,K.useMemo)(()=>$(i.records),[i.records]),_=(0,K.useMemo)(()=>ge(a,e.profile.id,e=>{f.current??=e}),[a,e.profile.id]),v=(0,K.useMemo)(()=>s(l?e:_e(e),{mode:`byok`,provider:_.provider,...l?{}:{toolHandlers:_.toolHandlers}},{conversationKey:O(),traces:h}),[e,_,l,h]),y=(0,K.useMemo)(()=>l?ee(e):void 0,[l,e]),b=re({transport:v,iface:t,pageTools:y}),{sendText:x,handleStop:S}=b,C=(0,K.useRef)(b.phase);C.current=b.phase;let[w,T]=(0,K.useState)(0);(0,K.useEffect)(()=>{let e=!1,t=async()=>{for(;!e&&C.current===`streaming`;)await new Promise(e=>requestAnimationFrame(e))};return(async()=>{for(let n=w;n<a.turns.length;n+=1){if(await t(),e)return;if(C.current===`gated`)return _.startTurn(n-1),m({kind:`waiting`,turn:n});let{text:r,attachments:i}=a.turns[n];if(i>0)return m({kind:`missing`,turn:n});_.startTurn(n),m({kind:`running`,turn:n});try{let t=await x(r);if(e)return;if(f.current)return m({kind:`diverged`,divergence:f.current});t||--n}catch(e){let t=e instanceof Error?e.message:String(e);return m({kind:`failed`,turn:n,message:t})}}m({kind:`done`})})(),()=>{e=!0,S()}},[w,_,a,x,S]);let E=async t=>{d({...await be(e,u,a.turns.slice(0,t).flatMap(e=>e.blocks)),text:a.turns[t]?.text??``})},D=c===`replayed`;return(0,q.jsx)(Y,{iface:t,feed:D?h:g,trace:n,card:r({isRunning:p.kind===`running`,onStop:()=>{S(),m({kind:`done`})}}),conversation:(0,q.jsx)(X,{iface:t,blocks:D?[...b.blocks,...b.streamBlocks]:G(a),chat:D?b:void 0,banner:D?(0,q.jsx)(Te,{status:p,turns:a.turns.length,onContinue:T,onLive:E}):void 0})})}function De(e){return(0,q.jsx)(u,{children:(0,q.jsx)(h,{labels:v,children:(0,q.jsx)(Oe,{...e})})})}function Oe({payload:e,trace:t,runtime:n,onLive:r}){let i=(0,K.useMemo)(()=>c(e),[e]),[a,o]=(0,K.useState)(),s=(0,K.useMemo)(()=>a&&pe(a.records),[a]),l=(0,K.useMemo)(()=>$(a?.records??[]),[a]),[u,d]=(0,K.useState)(0),[f,p]=(0,K.useState)(`recorded`),[m,h]=(0,K.useState)(!1),g=e=>{o(e),d(0),p(`recorded`)},_=()=>{d(e=>e+1),p(`replayed`)};if(i.type===`live`)return null;if(!a||!s)return(0,q.jsx)(Y,{iface:i,feed:l,trace:t,card:(0,q.jsx)(Q,{onImport:g}),conversation:null});let v=({isRunning:t,onStop:n})=>(0,q.jsx)(Q,{onImport:g,controls:{opened:a,script:s,payload:e,shown:u>0?f:null,onShown:p,liveTools:m,onLiveTools:e=>{h(e),u>0&&_()},isRunning:t,onReplay:_,onStop:n}});return u===0?(0,q.jsx)(Y,{iface:i,feed:l,trace:t,card:v({isRunning:!1,onStop:()=>void 0}),conversation:(0,q.jsx)(X,{iface:i,blocks:G(s)})}):(0,q.jsx)(Ee,{payload:e,iface:i,trace:t,card:v,opened:a,script:s,shown:f,liveTools:m,runtime:n,onLive:r},u)}export{De as TraceReplay};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{$n as e,C as t,Cr as n,M as r,Ut as i,Yt as a,ar as o,br as s,h as ee,j as c,mn as l,mr as te,n as ne,p as u,pr as re,t as ie,ur as ae,y as d,yn as oe,z as f}from"./tool-schema-CxLtS_Zt.js";import{En as p,Sn as m,qt as h,rn as g,tn as se}from"./shaped-data-DYOBdvLJ.js";import{a as ce,r as _}from"./live-ingress-OuSlQ6q7.js";var le=[{id:`identity`,profilePath:`identity`,role:`root`,optional:!1,editor:`structural`,label:`Identity`,ownsFields:[`profile.id`,`profile.type`]},{id:`models`,profilePath:`models`,role:`spine`,optional:!1,editor:`structural`,label:`Models`,ownsFields:[`profile.defaultModel`,`profile.allowModelSelect`,`profile.maxSteps`,`providerContinuation`]},{id:`modelBinding`,profilePath:`models.*`,role:`branch`,parent:`models`,optional:!1,editor:`structural`,label:`Model binding`},{id:`decision`,profilePath:`decision`,role:`spine`,optional:!1,editor:`structural`,label:`Decision`,ownsFields:[`inputs`]},{id:`image`,profilePath:`image`,role:`spine`,optional:!1,editor:`structural`,label:`Image`},{id:`speech`,profilePath:`speech`,role:`spine`,optional:!1,editor:`structural`,label:`Speech`},{id:`live`,profilePath:`live`,role:`spine`,optional:!1,editor:`structural`,label:`Live`},{id:`tools`,profilePath:`tools`,role:`spine`,optional:!1,editor:`structural`,label:`Tools`},{id:`toolSpec`,profilePath:`tools.allow`,role:`branch`,parent:`tools`,optional:!0,editor:`structural`,label:`Tool`},{id:`inputs`,profilePath:`inputs`,role:`spine`,optional:!1,editor:`structural`,label:`Inputs`},{id:`outputs`,profilePath:`outputs`,role:`spine`,optional:!0,editor:`structural`,label:`Outputs`},{id:`turnBehaviour`,profilePath:`turnBehaviour`,role:`spine`,optional:!0,editor:`structural`,label:`Turn behaviour`},{id:`guardrails`,profilePath:`guardrails`,role:`spine`,optional:!0,editor:`structural`,label:`Guardrails`},{id:`observability`,profilePath:`observability`,role:`spine`,optional:!0,editor:`structural`,label:`Observability`},{id:`labels`,profilePath:`labels`,role:`spine`,optional:!0,editor:`structural`,label:`Labels`}],ue={identity:s,inputs:n(`inputs`).filter(e=>e!==`decision`)},v=le.map(e=>({...e,profileTypes:ue[e.id]??n(e.profilePath)}));function de(e){return v.find(t=>t.id===e)}function fe(e){return e.modelBindings.length>1}function pe(e){return e.modelBindings.some(t=>t.provider!==`local`&&!r(e.providers,t).keySlot)}function me(e,t){let n={provider:t.provider,keySlot:t.keySlot||e.models.key,fallbackKeySlot:t.fallbackKeySlot||e.models.fallbackKey},i=r(e.providers,n);return{...i,given:{keySlot:!!i.keySlot&&!n.keySlot,fallbackKeySlot:!!i.fallbackKeySlot&&!n.fallbackKeySlot}}}function he(e){let t=e.efforts.map(({alias:e})=>e.trim()).filter(Boolean);return new Set(t).size>1}function ge(e){return e.attachmentsAccept.length>0||e.voiceAccept.length>0}var y=o,b=[{name:`operationTimeoutMs`,label:`Call timeout`,units:`ms`,isTimer:!0},{name:`connectTimeoutMs`,label:`Connect timeout`,units:`ms`,isTimer:!0},{name:`liveStepTimeoutMs`,label:`Live step timeout`,units:`ms`,isTimer:!0},{name:`maxWireRecordBytes`,label:`Wire record`,units:`bytes`,isTimer:!1},{name:`maxWireResponseBytes`,label:`Wire response`,units:`bytes`,isTimer:!1},{name:`maxEventBytes`,label:`Event`,units:`bytes`,isTimer:!1},{name:`maxStepBytes`,label:`Step`,units:`bytes`,isTimer:!1},{name:`maxStepEvents`,label:`Step events`,units:`events`,isTimer:!1},{name:`maxPendingToolCalls`,label:`Tool calls`,units:`calls`,isTimer:!1}],x=2147483647,S={compactMaxTokens:32e3,compactAt:.75,compactKeep:4},C={"continue.instruction":`turnBehaviour`,"canary.bind_note":`guardrails`,"quota.exhausted":`guardrails`,"repair.default_guidance":`outputs`,"egress.default_repair_guidance":`guardrails`,"egress.refusal":`guardrails`};function w(e){return`${e}-${crypto.randomUUID().slice(0,8)}`}function T(e){return{key:w(`model`),modelId:`fast`,protocol:`openRouterOpenAi`,provider:`openrouter`,apiId:``,options:{},timeoutMs:null,efforts:[],defaultEffort:``,allowEffortSelect:!1,summaries:null,maxOutputTokens:null,temperature:null,builtInTools:[],...e}}var E=`Studio stub tool — returns a fixed result.`;function D(e){return{key:w(`tool`),toolName:`my_tool`,toolType:`function`,description:E,category:`studio`,access:ae[0],permission:te[0],loadTier:re[0],paths:[`*`],inputJson:ie,outputJson:ne,...e}}function O(e,t,n){return(!e.description.trim()||e.description===E)&&n?{agentKey:t,description:`Asks ${n} and returns its answer.`}:{agentKey:t}}function k(){return{name:``,kind:`words`,pattern:``,flags:``,words:[]}}function A(){return{key:``,label:``,at:p(m,()=>`ignore`),patterns:[k()],hint:``}}function j(){let e=oe(void 0);return{canaryBindNote:``,detect:p(h,t=>({...e.detect[t]})),sources:Object.fromEntries(se.map(e=>[e,{theorem:!0,patterns:[],hint:``}])),own:[],quotaEnabled:!1,quotaPerDay:null,quotaMessage:``,allow:{ungiven_images:{hosts:[],fromTools:!0},ungiven_links:{hosts:[],fromTools:!0}},innocentNames:[],blockedReplyOnBlock:``,blockedReplyMaxRetries:null,egressRepairGuidance:``,egressRefusal:``,allowPrivateNetworks:!1,allowedHosts:[],allowedSchemes:[],taintAfterRemoteRead:``,taintRemoteDestination:``}}function M(){let e=ce({});return{writeTo:u,destination:u,sampleRate:e.sampleRate,include:{...e.include},scrub:{sensitive:!!e.scrub.sensitive,injection:!!e.scrub.injection,canary:!!e.scrub.canary},retainForDays:null,rotateAfterMiB:null,resourceJson:``}}function N(e){return e.map(([e,t])=>({key:w(`criterion`),label:e,text:t}))}function P(){return{contract:`guardrails.tool_call.v1`,maxStateBytes:null,questions:[{key:w(`question`),id:`verdict`,type:`choice`,instructions:`Given what the user asked for and what the call would do, should it run?`,criteria:N([[`allow`,`Safe, and what the user asked for.`],[`flag`,`Probably fine, but unusual or sensitive enough for a person to look first.`],[`block`,`Harmful, or clearly beyond what the user asked for.`]])},{key:w(`question`),id:`risk`,type:`score`,instructions:`How much harm would this call do if it were wrong?`,criteria:N([[``,`Low: reversible, and affects only the user.`],[``,`High: hard to undo, or affects other people or money.`]])}],images:[]}}var F=JSON.stringify({context:`The user asked the agent to tidy up old screenshots on their desktop.`,tool_call:{name:`delete_files`,path:`~/Documents`,recursive:!0},outcome:`Would delete 1,284 files, including tax_return_2025.pdf.`},null,2),I=JSON.stringify(`The user asked to tidy screenshots. The proposed call recursively deletes 1,284 files, including a tax return.`),L=`To clear your desktop, select the screenshots and move them to the Trash. Empty the Trash to delete them for good.(Screen captures save to the desktop by default. You can change where they go in the Screenshot app's Options menu.(Press Command-Shift-5 to record the screen or capture a window. Recordings are saved as movie files next to your screenshots.(Stacks group desktop files by kind, date or tag, so a cluttered desktop folds into a few piles you can open one at a time.(Deleted files stay in the Trash for 30 days. Drag a file out of the Trash to put it back where it was.(When your disk is almost full, open Storage settings and review the largest files. Old downloads and installers are safe to remove.(Offloading unused apps frees space and keeps their documents. Reinstalling an app brings its data back.(Photos you have backed up can be optimised so the originals live in the cloud and smaller copies stay on the device.(Your plan renews on the same date each month. You can see the next charge under Billing, then Upcoming invoices.(To get a refund, open the invoice and choose Request refund. Charges from the last 14 days are refunded in full.(Update your card under Billing, then Payment methods. The new card is used for the next renewal, not for past invoices.(Annual plans cost two months less than paying monthly. Switching mid-term credits the unused months to the new plan.(Invoices are emailed as PDFs and list your company name and tax number. Edit those details before the invoice is issued.(Turn on two-step verification under Security. You will be asked for a code from your authenticator app each time you sign in on a new device.(If you forget your password, choose Forgot password on the sign-in page. The reset link expires after one hour.(Review signed-in devices under Security and sign out any you don't recognise. This ends their sessions immediately.(Passkeys replace your password with your fingerprint or face. Create one under Security, then Passkeys.(To close your account, export your data first. Closing deletes your workspace after a 30-day grace period.(Share a folder by choosing Share, then entering an email address. Viewers can read; editors can change and delete.(Public links work for anyone who has them. Set an expiry date, or turn the link off to stop sharing at once.(Transfer ownership of a folder before you leave a team, or its contents will be archived with your account.(Lisbon has mild, wet winters and warm, dry summers. Expect highs near 28 °C in August.(The best months for the Algarve coast are May, June and September, when the beaches are warm and the crowds are thin.(Trams in Lisbon climb the steep hills of Alfama and Graça. Line 28 is the famous one, and the busiest.(For a crisp pizza base, preheat the oven and the baking tray together at the highest setting for at least thirty minutes.(Rest steak for five minutes after cooking so the juices settle back into the meat instead of running onto the board.`.split(`(`).join(`
|
|
2
|
-
|
|
3
|
-
`),R=`How do I delete every screenshot on my desktop?`;function _e(e,t=`choice`){let n=K(`question`,e.decision.questions.map(e=>e.id),e=>`question_${e}`);return{key:w(`question`),id:n,type:t,instructions:``,criteria:z(t)}}function ve(e,t,n){let r=t.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``)||`image`,i=K(r,e.decision.images.map(e=>e.name),e=>`${r}_${e}`);return{key:w(`image`),name:i,...n}}function z(e){return e===`noul`||e===`box`?[]:N(e===`choice`?[[`yes`,``],[`no`,``]]:[[``,``],[``,``]])}function ye(){return{identity:{agentId:``,profileType:``,handle:``,system:``,systemByRoleJson:``},included:[`observability`,`labels`],models:{defaultModel:``,allowModelSelect:!1,maxSteps:null,key:``},modelBindings:[],providers:[...t],tools:{t2Loader:``,parallel:!1},toolSpecs:[],inputs:{text:!0,attachmentsAccept:[],voiceAccept:[],maxFiles:null,maxBytes:null,maxTurnBytes:null,limitsByMimeJson:``,slotsJson:``,contextFrom:[],contextMaxChars:null},outputs:{mode:`text`,schemaId:``,schemaJson:``,streamMode:``,streamThoughts:!0,validationEnabled:!1,maxRetries:null,itemRules:{},repairGuidance:``},turnBehaviour:{resumeEnabled:!1,allowContinue:[],autoContinue:[],maxContinues:null,continueInstruction:``,allowSteering:a({type:`text`}),atStepLimit:`stop`},guardrails:j(),observability:M(),image:{aspectRatio:``,resolution:``,mimeType:``,quality:``,background:``,n:null,seed:null,outputCompression:null,includeText:!1,references:[]},speech:{voice:``,style:``,speed:null,format:``},live:{ingressAudio:_(`audio`),ingressVideo:_(`video`),ingressText:_(`text`),voice:``,sessionResumption:!1,greeting:``,resumedPrompt:``,resumedAfterMs:null,contextCompression:!1,compressionTriggerTokens:null,compressionTargetTokens:null,transcriptionInput:!1,transcriptionOutput:!1,vadActivityHandling:``,vadStartSensitivity:``,vadEndSensitivity:``,vadPrefixPaddingMs:null,vadSilenceDurationMs:null},decision:P(),labels:{}}}var be=new Set([`guardrails`]);function B(e,t){return e.profileTypes.includes(t)&&!(t===`decision`&&be.has(e.id))}function V(e){let t=e.identity.profileType;if(!t)return[`identity`];let n=new Set(e.included);return v.filter(e=>e.role!==`branch`&&B(e,t)&&(!e.optional||n.has(e.id))).map(e=>e.id)}function H(e,t){let r=e.identity.profileType;return r!==``&&n(t).includes(r)}function xe(e){return H(e,`identity.system`)&&g(e.guardrails.detect,`canary_leak`)}function Se(e){let t=e.identity.profileType;return t!==``&&i.includes(t)}function U(e){let t=e.identity.profileType;return t?v.filter(n=>n.role===`spine`&&n.optional&&B(n,t)&&!e.included.includes(n.id)).map(e=>e.id):[]}function Ce(t){return{...t,attachmentsAccept:t.attachmentsAccept.filter(t=>l(e,t)),voiceAccept:[]}}function we(e,t,n){let r=e.modelBindings.find(e=>e.key===t);return r?{...e,models:n.modelId!==void 0&&e.models.defaultModel===r.modelId?{...e.models,defaultModel:n.modelId}:e.models,modelBindings:e.modelBindings.map(e=>e.key===t?{...e,...n}:e)}:e}function W(e,t){if(t.some(t=>t.modelId===e))return e;let[n,...r]=t;return n&&!r.length?n.modelId:``}function Te(e,t){if(!e.modelBindings.find(e=>e.key===t))return e;let n=e.modelBindings.filter(e=>e.key!==t);return{...e,models:{...e.models,defaultModel:W(e.models.defaultModel,n)},modelBindings:n}}function G(e,t){let n=e.identity.profileType,r=n&&n!==`host`?n:`text`,i=e.modelBindings.map(e=>e.modelId),a=d(r,t),o=K(a.modelId,i,e=>`${a.modelId}${e}`);return T({...a,modelId:o})}function Ee(e){return D({toolName:K(`my_tool`,e.toolSpecs.map(e=>e.toolName),e=>`my_tool_${e}`)})}function K(e,t,n){let r=new Set(t),i=e;for(let e=2;r.has(i);e++)i=n(e);return i}function De(e,t,n){if(t===`host`)return{...e,identity:{...e.identity,profileType:t}};let r=e.modelBindings.filter(r=>{let i=c(e.providers,t,r),a=e.providers.find(e=>e.id===r.provider);return f(a,t,r.protocol)&&!Ae(n,t,i)}),i={...e,identity:{...e.identity,profileType:t},modelBindings:r},a=r.length?r:[G(i,n?.start)],o=!e.models.key&&pe({...i,modelBindings:a}),s=t===`speech`&&!e.speech.voice.trim()&&a.some(n=>ee(c(e.providers,t,n)));return{...i,inputs:t===`image`?Ce(e.inputs):e.inputs,...s?{speech:{...e.speech,voice:Oe}}:{},models:{...e.models,defaultModel:W(e.models.defaultModel,a),key:o?je:e.models.key},modelBindings:a}}var Oe=`Kore`,ke=[`text`,`image`,`speech`,`live`,`decision`];function Ae(e,t,n){if(!e)return!1;let r=t=>e.models(t,n.definition).some(e=>e.id===n.apiId.trim());return!r(t)&&ke.some(e=>e!==t&&r(e))}var je=`slot_a`;function Me(e,t){return U(e).includes(t)?{...e,included:[...e.included,t]}:e}function Ne(e,t){return{...e,included:e.included.filter(e=>e!==t)}}function q(e){return`modelBinding:${e}`}var J=`toolSpec:`;function Y(e){return`${J}${e}`}function X(e){return e.startsWith(J)?e.slice(9):void 0}var Z=`provider:`;function Pe(e){return`${Z}${e}`}function Fe(e){return e.startsWith(Z)?e.slice(9):void 0}var Ie=new Map(v.map(e=>[e.id,e.label]));function Q(e){return Ie.get(e)??e}function Le(e,t){let[n,r]=t.split(`:`,2);if(n===`modelBinding`&&r!==void 0)return e.modelBindings.some(e=>e.key===r)?{facet:n,key:r}:void 0;let i=X(t);if(i!==void 0)return e.toolSpecs.some(e=>e.key===i)?{facet:`toolSpec`,key:i}:void 0;let a=V(e);if(r===void 0&&a.includes(t))return{facet:t}}function Re(e,t){return t===`models`?e.modelBindings.map(e=>({id:q(e.key),ref:{facet:`modelBinding`,key:e.key},label:e.modelId.trim()||Q(`modelBinding`),children:[]})):t===`tools`?$(e.toolSpecs):[]}function $(e){return e.map(e=>({id:Y(e.key),ref:{facet:`toolSpec`,key:e.key},label:e.toolName.trim()||Q(`toolSpec`),children:[]}))}function ze(e){let t=V(e).filter(e=>e!==`identity`).map(t=>({id:t,ref:{facet:t},label:Q(t),children:Re(e,t)}));return{id:`identity`,ref:{facet:`identity`},label:e.identity.agentId.trim()||Q(`identity`),children:t}}export{ve as A,we as B,V as C,U as D,K as E,Ee as F,v as G,he as H,xe as I,de as K,Te as L,G as M,A as N,Me as O,k as P,De as R,H as S,Ne as T,fe as U,me as V,ge as W,x as _,ze as a,T as b,$ as c,R as d,L as f,y as g,b as h,Le as i,_e as j,z as k,S as l,C as m,Fe as n,X as o,I as p,Pe as r,Y as s,q as t,F as u,O as v,w,D as x,ye as y,Se as z};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hr as e}from"./tool-schema-CxLtS_Zt.js";var t=e.filter(e=>e!==`builtin`),n=`Tool type must be ${t.join(`, `).replace(/, ([^,]+)$/,`, or $1`)}.`;export{n,t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,l as n,n as r,u as i}from"./themeProps-3IqahpCr.js";import{h as a}from"./tokens.stylex-DkHf0P9C.js";import{_ as o,g as s,l as c,u as l,v as u}from"./SegmentedControlItem-BLuJOusN.js";import{a as ee,h as d,l as f,n as te,t as p,y as m}from"./padding.stylex-B76907Zf.js";import{t as h}from"./VStack-CkVMcNiK.js";import{n as g,t as _}from"./StackItem-CQviqAfM.js";import{t as v}from"./mergeProps-ptS-gIMz.js";import{t as y}from"./sharedResizeObserver-4U9Xq5Oq.js";import{r as b}from"./useLayerDismissal-BAnTRYTt.js";import{S as x}from"./fieldParts-Cs6Amprh.js";import{x as S}from"./Icon-ZfFwTt8n.js";import"./devWarning-DxuplmRl.js";import{r as C}from"./focusOutline.stylex-BT0kfa4t.js";import{t as w}from"./IconButton-CG5klqF1.js";import{r as ne,t as T}from"./Text-BsiAsowd.js";import{t as E}from"./Card-Ghe4ozhC.js";import{t as D}from"./Tooltip-CTEuMRLe.js";import{t as O}from"./createReactComponent-CZwsv6DD.js";import{t as k}from"./ScrollableArea-C8AVuqnt.js";var A=e(i(),1),j=t(),M={header:{kmuXW:`x2lah0s`,$$css:!0},inner:{kB7OPa:`x9f619`,ks0D6T:`xjl2t3p`,kUOVxO:`xvueqy4`,kZCmMZ:`xaku5ci`,kwRFfy:`x19eyx77`,kLKAdn:`xuqi0w`,kGO01o:`xg476vw`,"--container-padding-inline-start":`xt2a87w`,"--container-padding-inline-end":`xhq06x6`,"--container-padding-block-start":`x186o6qk`,"--container-padding-block-end":`xi9ns85`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},divider:{kt9PQ7:`xso031l`,kfdmCh:`x1q0q8m5`,kL6WhQ:`xw8gpjh`,$$css:!0}},N={sizing:e=>[{kZKoxP:e==null?e:`x16ye13r`,$$css:!0},{"--x-height":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function P({children:e,hasDivider:t,height:i,label:a,padding:o,paddingBlockEnd:c,role:l,xstyle:u,className:m,style:h,ref:g,..._}){let y=(0,A.use)(s),b=t??y?.defaultHasDividers??!1,x=o===0;return(0,j.jsx)(`div`,{ref:g,role:l,"aria-label":a,"data-divider":b||void 0,...v(r(`layout-header`),n(M.header,N.sizing(i??null),b&&M.divider,u),m,h),..._,children:(0,j.jsx)(`div`,{...n(M.inner,x&&M.fullBleed,o!=null&&d[o],o!=null&&ee[o],o!=null&&te[o],o!=null&&p[o],c!=null&&f[c],c!=null&&p[c]),children:e})})}P.displayName=`LayoutHeader`;var F={panel:{kB7OPa:`x9f619`,kmuXW:`x2lah0s`,kVQacm:`x7giv3`,kZCmMZ:`xwjyata`,kwRFfy:`x1peupej`,kLKAdn:`xqty4a`,kGO01o:`xg476vw`,"--container-padding-inline-start":`x408pgh`,"--container-padding-inline-end":`xikqloz`,"--container-padding-block-start":`xjmgx01`,"--container-padding-block-end":`xi9ns85`,$$css:!0},startPanel:{kZCmMZ:`xaku5ci`,$$css:!0},endPanel:{kwRFfy:`x19eyx77`,$$css:!0},noHeader:{kLKAdn:`xuqi0w`,$$css:!0},noFooter:{kGO01o:`x1363qu6`,$$css:!0},fullBleed:{kZCmMZ:`x1c1uobl`,kwRFfy:`xyri2b`,kLKAdn:`xexx8yu`,kGO01o:`x18d9i69`,"--container-padding-inline-start":`xrhngw9`,"--container-padding-inline-end":`xjsfl84`,"--container-padding-block-start":`x1047aw6`,"--container-padding-block-end":`xax9j7h`,$$css:!0},scrollable:{kVQacm:`xysyzu8`,$$css:!0},dividerEnd:{ke9TFa:`x1lun4ml`,k8ry5P:`x18b5jzi`,kBCPoo:`x1gejf6u`,$$css:!0},dividerStart:{k2ei4v:`xpilrb4`,kVhnKS:`x1t7ytsu`,kGJrpR:`x1j92z86`,$$css:!0},collapseStart:{keTefX:`x1wim8z0`,$$css:!0},collapseEnd:{k71WvV:`x1kpg4um`,$$css:!0}},I={sizing:e=>[{kzqmXN:e==null?e:`x5lhr3w`,$$css:!0},{"--x-width":(e=>typeof e==`number`?e+`px`:e??void 0)(e)}]};function L({children:e,hasDivider:t=!1,isScrollable:i=!0,label:a,padding:s,role:c,width:l,resizable:f,xstyle:m,className:h,style:g,ref:_,...y}){let b=(0,A.use)(u),{hasHeader:x,hasFooter:S}=(0,A.use)(o),C=f?f._size:l,w=b===`start`,ne=b===`end`,T=s===0,E=!t&&!T&&s==null,D=w?F.dividerEnd:ne?F.dividerStart:null,O=w?F.collapseEnd:ne?F.collapseStart:null;return(0,j.jsx)(`div`,{ref:_,role:c,"aria-label":a,...v(r(`layout-panel`),n(F.panel,I.sizing(C??null),w&&!T&&s==null&&F.startPanel,ne&&!T&&s==null&&F.endPanel,!x&&!T&&s==null&&F.noHeader,!S&&!T&&s==null&&F.noFooter,i&&F.scrollable,T&&F.fullBleed,s!=null&&d[s],s!=null&&ee[s],s!=null&&te[s],s!=null&&p[s],t&&D,E&&O,m),h,g),...y,children:e})}L.displayName=`LayoutPanel`;var R=O(`outline`,`eye-off`,`EyeOff`,[[`path`,{d:`M10.585 10.587a2 2 0 0 0 2.829 2.828`,key:`svg-0`}],[`path`,{d:`M16.681 16.673a8.717 8.717 0 0 1 -4.681 1.327c-3.6 0 -6.6 -2 -9 -6c1.272 -2.12 2.712 -3.678 4.32 -4.674m2.86 -1.146a9.055 9.055 0 0 1 1.82 -.18c3.6 0 6.6 2 9 6c-.666 1.11 -1.379 2.067 -2.138 2.87`,key:`svg-1`}],[`path`,{d:`M3 3l18 18`,key:`svg-2`}]]),re=O(`outline`,`info-circle`,`InfoCircle`,[[`path`,{d:`M3 12a9 9 0 1 0 18 0a9 9 0 0 0 -18 0`,key:`svg-0`}],[`path`,{d:`M12 9h.01`,key:`svg-1`}],[`path`,{d:`M11 12h1v4h1`,key:`svg-2`}]]),ie=(0,A.createContext)(null);ie.displayName=`CollapsibleGroupContext`;var z=m(null);z.displayName=`CollapsibleGroupPresentationContext`;function B(e){let{isCollapsible:t,value:n}=e,r=(0,A.use)(ie),i=r!=null&&n!=null,a=t===!0?{}:t||null,o=a!=null,[s,c]=(0,A.useState)(()=>i?!0:a?.isOpen===void 0?a?.defaultIsOpen??!0:a.isOpen),l;return l=i&&n!=null?r.isOpen(n):a?.isOpen===void 0?s:a.isOpen,{isEnabled:o,isOpen:l,toggle:()=>{if(i&&n!=null){r.toggle(n);return}let e=!l;a?.isOpen===void 0&&c(e),a?.onOpenChange?.(e)}}}var ae=50,oe=40,V=`astryx-resizable:`;function H(e,t,n,r){let i=Math.min(n,Math.max(t,e));if(r.length>0){let e=r[0],a=Math.abs(i-e);for(let t=1;t<r.length;t++){let n=Math.abs(i-r[t]);n<a&&(e=r[t],a=n)}return Math.min(n,Math.max(t,e))}return i}function se(e){if(typeof window>`u`)return null;try{let t=localStorage.getItem(V+e);if(t==null)return null;let n=JSON.parse(t);if(typeof n==`number`)return Number.isFinite(n)?n===0?{size:null,isCollapsed:!0}:{size:n,isCollapsed:null}:null;if(typeof n==`object`&&n){let{size:e,isCollapsed:t}=n,r=typeof e==`number`&&Number.isFinite(e)&&e>0;if(r||t===!0)return{size:r?e:null,isCollapsed:t===!0}}}catch{}return null}function ce(e,t){if(typeof window<`u`)try{localStorage.setItem(V+e,JSON.stringify(t))}catch{}}var U=1200,le=()=>()=>{},ue=250,de=`Use a non-negative number of pixels, an exact "Npx" string, an exact "N%" string from 0% to 100%, pixel(value), or percent(value, {min: pixel(value)}) / percent(value, {max: pixel(value)}).`,W=/^(\d+(?:\.\d+)?)px$/,fe=/^(\d+(?:\.\d+)?)%$/;function pe(e){let t=W.exec(e);if(t){let e=Number(t[1]);return Number.isFinite(e)?{kind:`px`,value:e}:null}let n=fe.exec(e);if(n){let e=Number(n[1]);return Number.isFinite(e)&&e<=100?{kind:`percent`,value:e}:null}return null}function G(e){if(typeof e!=`object`||!e||Array.isArray(e))return null;let t=e;return t.type===`pixel`&&typeof t.value==`number`&&Number.isFinite(t.value)&&t.value>=0?t.value:null}function me(e){if(Array.isArray(e))return null;let t=e;if(t.type!==`percent`||typeof t.value!=`number`||!Number.isFinite(t.value)||t.value<0||t.value>100)return null;let n=t.min!==void 0;if(n===(t.max!==void 0))return null;if(n){let e=G(t.min);return e==null?null:{kind:`percent`,value:t.value,min:e}}let r=G(t.max);return r==null?null:{kind:`percent`,value:t.value,max:r}}function he(e){if(typeof e==`number`)return Number.isFinite(e)&&e>=0?{kind:`px`,value:e}:null;if(typeof e==`string`)return pe(e);if(typeof e==`object`&&e){let t=G(e);return t==null?me(e):{kind:`px`,value:t}}return null}function ge(e){return e?.kind===`percent`}function _e(e,t){if(e.kind===`px`)return e.value;if(t==null)return null;let n=Math.round(e.value/100*t);return e.min===void 0?e.max===void 0?n:Math.min(n,e.max):Math.max(n,e.min)}function K(e){if(typeof e==`number`&&!Number.isFinite(e))return String(e);try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function ve(e){if(typeof e!=`object`||!e||Array.isArray(e))return K(e);let t=e;return t.type===`pixel`?`{"type":"pixel","value":${K(t.value)}}`:K(e)}function q(e){if(typeof e==`object`&&e&&!Array.isArray(e)){let t=e;if(t.type===`pixel`)return ve(e);if(t.type===`percent`){let e=[`"type":"percent"`,`"value":${K(t.value)}`];return t.min!==void 0&&e.push(`"min":${ve(t.min)}`),t.max!==void 0&&e.push(`"max":${ve(t.max)}`),`{${e.join(`,`)}}`}}return K(e)}function ye(e,t,n,r,i,a,o){return e===void 0?r:e===1/0&&r===1/0?1/0:t==null?(o.current||(o.current=!0,`${i}${q(e)}${a}${r}`),r):_e(t,n)??r}function be(e,t,n){let r=n?.contentBoxSize?.[0];if(r)return t===`vertical`?r.blockSize:r.inlineSize;let i=typeof window>`u`?null:window.getComputedStyle(e);if(i==null)return null;let a=t===`vertical`?e.clientHeight-parseFloat(i.paddingTop)-parseFloat(i.paddingBottom):e.clientWidth-parseFloat(i.paddingLeft)-parseFloat(i.paddingRight);return Number.isFinite(a)?a:null}function J(e){let{defaultSize:t,minSize:n,maxSize:r,containerRef:i,direction:a=`horizontal`,collapsible:o=!1,collapsedSize:s=oe,snaps:c,autoSaveId:l,defaultIsCollapsed:u,isCollapsed:ee,onSizeChange:d,onCollapseChange:f}=e,te=(0,A.useRef)([]),p=c??te.current,m=n,h=r,g=he(t),_=he(n),v=he(r),x=i!=null,S=l?se(l):null,C=(0,A.useRef)(null),[,w]=(0,A.useState)(0),ne=ge(g),T=ge(_)||ge(v),E=S?.size==null&&ne&&C.current?.isFinal!==!0,D=x&&(T||E),O=!x&&T,k=(0,A.useRef)(null),[,j]=(0,A.useState)(0),M=(0,A.useRef)(null),N=D?k.current:null;b(()=>{if(!D){k.current=null,M.current=null;return}let e=i?.current??null;e!==k.current&&(M.current=null,k.current=e,j(e=>e+1))});let P=(0,A.useCallback)(e=>!D||N==null||N!==i?.current?()=>{}:y(N,t=>{M.current=be(N,a,t),e()}),[N,D,a,i]),F=(0,A.useCallback)(()=>!D||N==null?(M.current=null,null):(M.current??=be(N,a),M.current),[N,D,a]),I=(0,A.useSyncExternalStore)(P,F,()=>null),L=(0,A.useCallback)(e=>x||!O||typeof window>`u`?()=>{}:(window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)),[x,O]),R=(0,A.useSyncExternalStore)(L,()=>typeof window>`u`?U:window.innerWidth,()=>U),re=(0,A.useSyncExternalStore)(le,()=>typeof window>`u`?null:a===`vertical`?window.innerHeight:window.innerWidth,()=>null),ie=D,z=I!=null&&I>0,B=x?z?I:U:R,V=!ie||z,W=(0,A.useRef)(null),[fe,pe]=(0,A.useState)(0),G=W.current??B,me=(0,A.useRef)(!1),_e=(0,A.useRef)(!1),K=(0,A.useRef)(!1),ve=(0,A.useRef)(!1),q=ye(m,_,G,ae,`minSize`,de,me),J=ye(h,v,G,1/0,`maxSize`,de,_e);(C.current==null||!C.current.isFinal)&&(C.current={px:ye(t,g,G,ue,`defaultSize`,de,K),isFinal:V});let xe=C.current.px,[we,Te]=(0,A.useState)(()=>S?.size==null?V?H(xe,q,J,p):null:S.size);x&&!T&&V&&E&&we!=null&&w(e=>e+1),V&&we==null&&Te(H(xe,q,J,p));let[Ee,De]=(0,A.useState)({min:q,max:J});V&&W.current==null&&(Ee.min!==q||Ee.max!==J)&&(De({min:q,max:J}),Te(e=>e==null?null:H(e,q,J,p)));let Y=H(we??xe,q,J,p),[Oe,ke]=(0,A.useState)(()=>S?.isCollapsed??u??!1),Ae=ee!==void 0,X=o&&(Ae?ee:Oe),Z=(0,A.useRef)(Y),Q=(0,A.useRef)(X);Q.current=X;let $=(0,A.useCallback)(e=>{Ae||(Q.current=e,ke(e))},[Ae]);(0,A.useEffect)(()=>{q>J&&!ve.current&&(ve.current=!0,`${q}${J}`)},[q,J]),(0,A.useEffect)(()=>{l&&V&&ce(l,{size:Y,isCollapsed:X})},[Y,X,l,V]);let je=(0,A.useCallback)(()=>{o&&!Q.current&&($(!0),f?.(!0),d?.(0))},[o,$,f,d]),Me=(0,A.useCallback)(()=>{let e=Q.current;$(!1),e&&f?.(!1),d?.(Y)},[$,Y,f,d]),Ne=(0,A.useCallback)(e=>{if(!Number.isFinite(e)||e<0){`${String(e)}`;return}let t=H(e,q,J,p),n=Q.current;Te(t),$(!1),n&&f?.(!1),d?.(t)},[q,J,p,$,f,d]),Pe=(0,A.useCallback)(()=>{W.current=B,Z.current=Q.current?0:Y},[Y,B]),Fe=(0,A.useCallback)(e=>{let t=Z.current+e;if(o&&t<s){Q.current||($(!0),f?.(!0),d?.(0));return}Q.current&&t>=s&&($(!1),f?.(!1));let n=H(t,q,J,p);Te(n),d?.(n)},[o,s,$,q,J,p,d,f]),Ie=(0,A.useCallback)(()=>{W.current!=null&&(W.current=null,pe(e=>e+1))},[]),Le=(0,A.useCallback)(()=>{Ie()},[Ie]),Re=Ie,ze=x?z&&D?I:null:re,Be=J===1/0?ze==null?void 0:Math.max(ze,X?q:Y):J,Ve={_size:X?0:Y,_isCollapsed:X,_onResizeStart:Pe,_onResizeMove:Fe,_onResizeEnd:Le,_onResizeCancel:Re,_minSizePx:q,_maxSizePx:J,_snaps:p,_collapsedSize:s,_collapsible:o,_direction:a,_isResizableProps:!0};return Se.set(Ve,{collapse:je,expand:Me}),Be!=null&&Ce.set(Ve,Be),{size:X?0:Y,isCollapsed:X,collapse:je,expand:Me,resize:Ne,props:Ve}}function xe(e){let{regions:t,autoSaveId:n,containerRef:r,direction:i}=e,a=Object.entries(t),o=a.map(([e,t])=>J({...t,containerRef:r,direction:i,autoSaveId:n?`${n}:${e}`:void 0})),s={};return a.forEach(([e],t)=>{s[e]=o[t]}),s}var Se=new WeakMap,Ce=new WeakMap;function we(e){return Ce.get(e)}function Te(e){return Se.get(e)}function Ee(e){return`regions`in e?xe(e):J(e)}var De=10,Y=50;function Oe(e,t,n){if(e!==`auto`)return e;let r=t?`end`:`start`;return n?r===`start`?`end`:`start`:r}function ke(e){return e===`center`?null:e===`start`?-1:1}function Ae(e){document.body.style.cursor=e?`col-resize`:`row-resize`,document.body.style.userSelect=`none`}function X(){document.body.style.cursor=``,document.body.style.userSelect=``}var Z={handle:{kVAEAm:`x1n2onr6`,kmuXW:`x2lah0s`,k1xSpc:`x78zum5`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kWkggS:`x1m4xfpy`,k1ekBW:`x15406qy`,kIyJzY:`xuedmi6`,kAMwcw:`xlr8y92`,$$css:!0},overlay:{kVAEAm:`x10l6tqk`,kY2c9j:`xhtitgo`,kWkggS:`xjbqb8w`,$$css:!0},overlayHorizontal:{kt4wiu:`xtijo5x`,k87sOh:`x13vifvy`,krVfgx:`x1ey2m1c`,kzqmXN:`xkhob8h`,$$css:!0},overlayVertical:{krVfgx:`x1ey2m1c`,kLqNvP:`x1o0tod`,kt4wiu:`xtijo5x`,kZKoxP:`x5kfih4`,$$css:!0},horizontal:{kzqmXN:`x1i1rx1s`,kZKoxP:`x5yr21d`,kkrTdU:`xicojor x16khyan`,$$css:!0},vertical:{kZKoxP:`xjm9jq1`,kzqmXN:`xh8yej3`,kkrTdU:`xyozgr7 x16khyan`,$$css:!0},noDividerHorizontal:{kWkggS:`xjbqb8w`,kzqmXN:`xnalus7`,$$css:!0},noDividerVertical:{kWkggS:`xjbqb8w`,kZKoxP:`xqtp20y`,$$css:!0},handleHover:{kWkggS:`x1m4xfpy`,$$css:!0},handleActive:{kWkggS:`x7njt3n`,$$css:!0},disabled:{kkrTdU:`xt0e3qv`,kfzvcC:`x47corl`,$$css:!0},hitArea:{kVAEAm:`x10l6tqk`,kY2c9j:`x1vjfegm`,kFalU9:`x5ve5x3`,kfSwDN:`x87ps6o`,$$css:!0},hitAreaHorizontal:{kzqmXN:`x12xnipv`,k87sOh:`x13vifvy`,krVfgx:`x1ey2m1c`,kkrTdU:`xicojor x16khyan`,$$css:!0},hitAreaVertical:{kZKoxP:`x6b6gus`,kLqNvP:`x1o0tod`,kt4wiu:`xtijo5x`,kkrTdU:`xyozgr7 x16khyan`,$$css:!0},hitAreaCenteredY:{k87sOh:`xwa60dl`,k3aq6I:`x1cb1t30`,$$css:!0},pill:{kVAEAm:`x10l6tqk`,kY2c9j:`xhtitgo`,kfzvcC:`x47corl`,kaIpWk:`xjspbzw`,kWkggS:`x1m4xfpy`,k1ekBW:`x1wbls7o`,kIyJzY:`xuedmi6`,kAMwcw:`xlr8y92`,k87sOh:`xwa60dl`,$$css:!0},pillHorizontal:{kzqmXN:`x1g8rjiy`,kZKoxP:`x18to7ep`,$$css:!0},pillVertical:{kzqmXN:`xgc8j7m`,kZKoxP:`xuoj239`,$$css:!0},pillHidden:{kSiTet:`xg01cxk`,$$css:!0},pillVisible:{kSiTet:`x1hc1fzr`,$$css:!0},pillHover:{kSiTet:`x1hc1fzr`,kWkggS:`x1m4xfpy`,$$css:!0},pillActive:{kSiTet:`x1hc1fzr`,kWkggS:`x7njt3n`,$$css:!0}},Q={kLqNvP:`x1o0tod`,k3aq6I:`x11wx31z x75qhwu`,$$css:!0},$={k87sOh:`x13vifvy`,k3aq6I:`xsqj5wx`,$$css:!0},je={kLqNvP:`x1o0tod`,k3aq6I:`xsqj5wx`,$$css:!0},Me={k87sOh:`x13vifvy`,k3aq6I:`xsqj5wx`,$$css:!0},Ne={hitAreaOffsetX:e=>[Q,{"--x-qthpiu":`translateX(calc(${e} * (3px + ${a[`--spacing-1`]}) - 6.5px))`==null?void 0:`translateX(calc(${e} * (3px + ${a[`--spacing-1`]}) - 6.5px))`,"--x-sj6hyi":`translateX(calc(${e} * (3px + ${a[`--spacing-1`]}) + 6.5px))`==null?void 0:`translateX(calc(${e} * (3px + ${a[`--spacing-1`]}) + 6.5px))`}],hitAreaOffsetY:e=>[$,{"--x-transform":`translateY(calc(${e} * (3px + ${a[`--spacing-1`]}) - 6.5px))`==null?void 0:`translateY(calc(${e} * (3px + ${a[`--spacing-1`]}) - 6.5px))`}],pillOffsetX:e=>[je,{"--x-transform":`translate(calc(${e} * (100% + ${a[`--spacing-1`]})), -50%)`==null?void 0:`translate(calc(${e} * (100% + ${a[`--spacing-1`]})), -50%)`}],pillOffsetY:e=>[Me,{"--x-transform":`translate(-50%, calc(${e} * (100% + ${a[`--spacing-1`]})))`==null?void 0:`translate(-50%, calc(${e} * (100% + ${a[`--spacing-1`]})))`}]};function Pe(e,t,n){let r=[...new Set(e._snaps.map(t=>Math.min(e._maxSizePx,Math.max(e._minSizePx,t))))].sort((e,t)=>e-t),i=e._size,a=t>0?r.filter(e=>e>i):r.filter(e=>e<i).reverse();return a.length===0?i:a[Math.min(n,a.length)-1]}function Fe(e){let t=Te(e);t?e._isCollapsed?t.expand():t.collapse():(e._onResizeStart(),e._onResizeMove(e._isCollapsed?e._minSizePx:-e._size),e._onResizeEnd())}function Ie({direction:e=`horizontal`,position:t=`inline`,isReversed:i=!1,isDisabled:a=!1,hasDivider:o=!1,isAlwaysVisible:s=!0,pillPlacement:c=`auto`,label:l,resizable:u,children:ee,xstyle:d,className:f,ref:te,...p}){let m=S(),h=l??m(`@astryx.resizable.handle.label`),g=(0,A.useRef)(null),_=(0,A.useRef)(null),[y,b]=(0,A.useState)(!1),[w,T]=(0,A.useState)(!1),[E,D]=(0,A.useState)(!1),O=e===`horizontal`,k=t===`overlay`,M=i?-1:1,N=Oe(c,i,u?._isCollapsed??!1),P=ke(N),F=(0,A.useCallback)(()=>{let e=g.current;return e&&getComputedStyle(e).direction===`rtl`?-1:1},[]),I=w||E,L=(0,A.useRef)(!1);(0,A.useEffect)(()=>{let t=u?._direction;t!=null&&t!==e&&!L.current&&(L.current=!0,`${e}${t}`)},[e,u]);let R=(0,A.useCallback)(()=>{_.current=null,b(!1),X()},[]),re=(0,A.useCallback)(e=>{a||!u||_.current||(e.preventDefault(),e.stopPropagation(),e.currentTarget.setPointerCapture?.(e.pointerId),_.current={pointerId:e.pointerId,startPos:O?e.clientX:e.clientY,rtl:O?F():1},b(!0),u._onResizeStart(),Ae(O))},[a,u,O,F]),ie=(0,A.useCallback)(e=>{let t=_.current;if(!t||t.pointerId!==e.pointerId||!u)return;let n=O?e.clientX:e.clientY;u._onResizeMove((n-t.startPos)*t.rtl*M)},[u,O,M]),z=(0,A.useCallback)(e=>{_.current?.pointerId===e.pointerId&&(R(),u?._onResizeEnd())},[R,u]),B=(0,A.useCallback)(e=>{_.current?.pointerId===e.pointerId&&(R(),u?._onResizeCancel?.())},[R,u]),ae=(0,A.useCallback)(e=>{if(a||!u)return;let t=e.shiftKey?Y:De,n=O?F():1,r=e=>(e===`ArrowRight`||e===`ArrowDown`?1:e===`ArrowLeft`||e===`ArrowUp`?-1:0)*(O?n:1)*M>0;switch(e.key){case`ArrowRight`:case`ArrowDown`:case`ArrowLeft`:case`ArrowUp`:{if(e.preventDefault(),u._isCollapsed){r(e.key)&&(u._onResizeStart(),u._onResizeMove(Math.max(u._minSizePx+t,u._collapsedSize)),u._onResizeEnd());break}if(u._snaps.length>0){u._onResizeStart(),u._onResizeMove(Pe(u,r(e.key)?1:-1,e.shiftKey?2:1)-u._size),u._onResizeEnd();break}let i=e.key===`ArrowRight`||e.key===`ArrowDown`?1:-1;u._onResizeStart(),u._onResizeMove(i*t*(O?n:1)*M),u._onResizeEnd();break}case`Home`:e.preventDefault(),u._onResizeStart(),u._onResizeMove(u._minSizePx-u._size),u._onResizeEnd();break;case`End`:e.preventDefault(),u._maxSizePx!==1/0&&(u._onResizeStart(),u._onResizeMove(u._maxSizePx-u._size),u._onResizeEnd());break;case`Enter`:e.preventDefault(),u._collapsible&&Fe(u)}},[a,u,O,F,M]),oe=(0,A.useCallback)(()=>{!a&&u&&u._collapsible&&Fe(u)},[a,u]),V=(0,A.useRef)(void 0);V.current=u?._onResizeCancel,(0,A.useEffect)(()=>()=>{_.current&&(_.current=null,X(),V.current?.())},[]);let H=u?._isCollapsed??!1,se=u?H?Math.max(u._size,u._minSizePx):u._size:void 0,ce=u?u._minSizePx:void 0,U=u?we(u)??(u._maxSizePx===1/0?void 0:u._maxSizePx):void 0,le=U!=null&&Number.isFinite(U)?U:void 0,ue=u&&H?m(`@astryx.resizable.collapsed`):void 0;return(0,j.jsxs)(`div`,{ref:ne(te,g),role:`separator`,"aria-orientation":O?`vertical`:`horizontal`,"aria-valuenow":se,"aria-valuemin":ce,"aria-valuemax":le,"aria-valuetext":ue,"aria-label":h,"aria-disabled":a||void 0,tabIndex:a?-1:0,onDoubleClick:oe,onFocus:()=>D(!0),onBlur:()=>D(!1),"data-resizing":y||void 0,...v(r(`resize-handle`),C.focusVisible(Z.handle,k&&Z.overlay,k&&(O?Z.overlayHorizontal:Z.overlayVertical),!k&&(O?Z.horizontal:Z.vertical),!k&&!o&&(O?Z.noDividerHorizontal:Z.noDividerVertical),!k&&o&&I&&!y&&Z.handleHover,!k&&o&&y&&Z.handleActive,a&&Z.disabled,d),f),...p,onKeyDown:e=>{p.onKeyDown?.(e),ae(e)},children:[(0,j.jsx)(`div`,{...n(Z.hitArea,O?Z.hitAreaHorizontal:Z.hitAreaVertical,P==null?O?x.centerInline(`0px`):Z.hitAreaCenteredY:O?Ne.hitAreaOffsetX(P):Ne.hitAreaOffsetY(P),a&&Z.disabled),onPointerDown:re,onPointerMove:ie,onPointerUp:z,onPointerCancel:B,onLostPointerCapture:B,onPointerEnter:()=>T(!0),onPointerLeave:()=>{y||T(!1)}}),ee??(0,j.jsx)(`div`,{...v(r(`resize-handle-pill`),n(Z.pill,O?Z.pillHorizontal:Z.pillVertical,N===`center`?x.centerInline(`-50%`):O?Ne.pillOffsetX(N===`start`?-1:1):Ne.pillOffsetY(N===`start`?-1:1),s?Z.pillVisible:Z.pillHidden,I&&!y&&Z.pillHover,y&&Z.pillActive))})]})}Ie.displayName=`ResizeHandle`;var Le={defaultSize:`33%`,minSize:280,maxSize:`50%`};function Re(e){return e>=Le.minSize*2}function ze(e,t){let n=(0,A.useId)(),[r,i]=(0,A.useState)(t);return{id:n,open:r,toggle:(0,A.useCallback)(()=>i(e=>!e),[]),resizable:Ee({...Le,containerRef:e})}}function Be({children:e,floating:t=!1}){return t?(0,j.jsx)(`div`,{style:{position:`absolute`,insetBlockStart:`var(--spacing-4)`,insetInlineEnd:`var(--spacing-4)`,zIndex:3},children:(0,j.jsx)(g,{hAlign:`end`,gap:1,children:e})}):(0,j.jsx)(P,{hasDivider:!1,children:(0,j.jsx)(g,{hAlign:`end`,gap:1,children:e})})}function Ve({labels:e,icon:t,panelId:n,open:r,onToggle:i}){let a=r?e.hide:e.show;return(0,j.jsx)(w,{label:a,tooltip:a,variant:r?`secondary`:`ghost`,"aria-expanded":r,"aria-controls":n,icon:t,onClick:i})}var He={background:`var(--theorem-pane-background, var(--color-background-card))`,borderRadius:`var(--radius-page)`,overflow:`hidden`};function Ue(e){return`var(--theorem-pane-edge, var(--spacing-${String(e)}))`}function We({padding:e,inset:t=`end`,className:n,children:r}){return(0,j.jsx)(h,{height:`100%`,className:n,paddingInlineStart:t===`end`?void 0:3,style:{paddingInlineEnd:t===`start`?void 0:Ue(3),paddingBlockEnd:Ue(4)},children:(0,j.jsx)(E,{variant:`transparent`,height:`100%`,padding:e,style:He,children:r})})}function Ge({label:e,padding:t,children:n}){return(0,j.jsx)(k,{className:`theorem-panel-scroll`,label:e,height:`100%`,padding:t,children:n})}function Ke({id:e,labels:t,resizable:n,open:r=!0,padding:i,side:a=`end`,className:o,children:s}){let c=r?(0,j.jsx)(Ie,{direction:`horizontal`,isReversed:a===`end`,hasDivider:!1,isAlwaysVisible:!1,resizable:n.props,label:t.resize}):null,l=(0,j.jsx)(L,{id:e,className:o,label:t.name,role:`complementary`,width:r?n.size:0,hasDivider:!1,padding:0,isScrollable:!1,inert:!r,children:(0,j.jsx)(We,{padding:i,inset:a,children:r?s:null})});return a===`start`?(0,j.jsxs)(j.Fragment,{children:[l,c]}):(0,j.jsxs)(j.Fragment,{children:[c,l]})}function qe(){let[e,t]=(0,A.useState)(0);return{ref:(0,A.useCallback)(e=>{if(!e)return;let n=new ResizeObserver(([e])=>t(e?.contentRect.width??0));return n.observe(e),()=>n.disconnect()},[]),width:e}}function Je({id:e,header:t,children:n}){let{ref:r,width:i}=qe();return(0,j.jsx)(l,{height:`fill`,style:{position:`relative`},header:t,content:(0,j.jsx)(c,{padding:0,isScrollable:!1,children:(0,j.jsx)(h,{height:`100%`,paddingInlineStart:3,paddingBlockStart:3,style:{paddingInlineEnd:Ue(3),paddingBlockEnd:Ue(3)},children:(0,j.jsx)(E,{variant:`transparent`,height:`100%`,padding:0,style:He,children:(0,j.jsx)(`div`,{id:e,ref:r,style:{height:`100%`},children:n(Re(i))})})})})})}function Ye({isWide:e,label:t,detailLabel:n,lead:r,overview:i,detail:a}){return e?(0,j.jsxs)(g,{height:`100%`,gap:0,children:[(0,j.jsx)(_,{size:`fill`,children:(0,j.jsxs)(Ge,{label:t,children:[r,i]})}),a?(0,j.jsx)(`div`,{style:{width:`48%`,flexShrink:0,height:`100%`,borderInlineStart:`1px solid var(--color-border)`},children:(0,j.jsx)(Ge,{label:n,children:a})}):null]}):(0,j.jsxs)(Ge,{label:t,children:[r,a||i]})}function Xe({title:e,doc:t,children:n}){return(0,j.jsx)(E,{padding:3,variant:`muted`,style:{background:`var(--color-background-surface)`},children:(0,j.jsxs)(h,{gap:2,children:[(0,j.jsx)(D,{content:t??e,children:(0,j.jsx)(T,{type:`supporting`,color:`secondary`,children:e})}),n]})})}function Ze({text:e}){return(0,j.jsx)(`span`,{style:{whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},children:e})}function Qe({view:e,children:t}){return(0,j.jsxs)(j.Fragment,{children:[e,(0,j.jsx)(`div`,{style:{display:e?`none`:`contents`},children:t})]})}var $e=[],et=()=>()=>{};function tt(e){return(0,A.useSyncExternalStore)(e?.subscribe??et,e?.records??(()=>$e))}export{R as C,re as S,P as T,Ie as _,We as a,ie as b,He as c,Be as d,Ve as f,qe as g,ze as h,Xe as i,Je as l,Ue as m,Qe as n,Ge as o,Re as p,Ye as r,Ze as s,tt as t,Ke as u,Ee as v,L as w,z as x,B as y};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{E as e,a as t,c as n,i as r,n as i,o as a,r as o,s,w as c,y as l}from"./tree-Bi2FOU_h.js";function u(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function d(e){let t=e=>{if(Array.isArray(e))return e.map(t);if(!u(e))return e;let n=Object.keys(e).filter(t=>e[t]!==void 0).sort();return Object.fromEntries(n.map(n=>[n,t(e[n])]))};return JSON.stringify(t(e))??`undefined`}var f=`agent:`;function p(e,t=`identity`){return t===`identity`?`${f}${e}`:`${f}${e}/${t}`}function m(e){if(!e.startsWith(f))return;let t=e.slice(6),n=t.indexOf(`/`);return n<0?{key:t,inner:`identity`}:{key:t.slice(0,n),inner:t.slice(n+1)}}function h(e,t){return a(t)===void 0?p(e,t):t}function g(e,t){let n=a(t);if(n!==void 0)return e.toolSpecs.some(e=>e.key===n)?{tool:n}:void 0;let o=i(t);if(o!==void 0)return e.providers.some(e=>e.id===o)?{provider:o}:void 0;let s=m(t),c=s&&e.agents.find(e=>e.key===s.key);if(!s||!c||a(s.inner)!==void 0)return;let l=r(_(c,[],e.providers),s.inner);return l?{agent:c.key,ref:l}:void 0}function _(e,t,n){let{key:r,tools:{allow:i,...a},...o}=e,s=new Map(t.map(e=>[e.key,e]));return{...o,providers:n,tools:a,toolSpecs:i.flatMap(e=>s.get(e)??[])}}function ee(e,t){let n=e.agents.find(e=>e.key===t);return n&&_(n,e.toolSpecs,e.providers)}function v(e,t=c(`agent`)){let{toolSpecs:n,tools:r,providers:i,...a}=e;return{...a,key:t,tools:{...r,allow:n.map(e=>e.key)}}}function y(e,t){let n=new Map(t.map(e=>[e.key,e])),r=new Set(e.map(e=>e.key)),i=t.filter(e=>!r.has(e.key));return!e.some(e=>(n.get(e.key)??e)!==e)&&i.length===0?e:[...e.map(e=>n.get(e.key)??e),...i]}function b(e,t,n){return e.agents.map(e=>e.key===t?n(e):e)}var x=e=>e.key,S=e=>e.id;function C(e){let t=Object.fromEntries(e.agents.map(t=>[t.key,e.starts.agents[t.key]??t])),n=new Map(e.toolSpecs.map(e=>[e.key,e])),r=new Set([...n.keys(),...Object.values(t).flatMap(e=>e.tools.allow)]),i={};for(let t of r){let r=e.starts.tools[t]??n.get(t);r&&(i[t]=r)}let a=Object.fromEntries(e.providers.map(t=>[t.id,e.starts.providers[t.id]??t]));for(let n of Object.values(t).flatMap(w)){let t=e.starts.providers[n];t&&!(n in a)&&(a[n]=t)}return{...e,starts:{agents:t,tools:i,providers:a}}}var w=e=>e.modelBindings.map(e=>e.provider);function te(e,t){let n=new Set(e.providers.map(S)),r=[...new Set(t.flatMap(w))].flatMap(t=>{let r=e.starts.providers[t];return r&&!n.has(t)?[r]:[]});return r.length?[...e.providers,...r]:e.providers}function ne(e,t){let n=e.agents.find(e=>e.key===t);return n?C({...e,starts:{...e.starts,agents:{...e.starts.agents,[t]:n}}}):e}function T(e,t,n,r){if(!e.agents.some(e=>e.key===t))return e;let i=r?y(e.toolSpecs,[...r]):e.toolSpecs;return C({...e,toolSpecs:y(i,n.toolSpecs),agents:b(e,t,()=>v(n,t))})}function E(e,t=`identity`){let n=v(e);return C({v:5,agents:[n],toolSpecs:e.toolSpecs,providers:e.providers,selected:h(n.key,t),chatWith:n.key,starts:{agents:{},tools:{},providers:{}}})}function D(e,t){let n=e.agents.find(e=>e.key===t);return n&&{..._(n,[],e.providers),toolSpecs:e.toolSpecs}}function O(e,t,n){if(!e.agents.find(e=>e.key===t))return e;let r=new Set(n.toolSpecs.map(e=>e.key)),i=new Set(e.toolSpecs.map(e=>e.key)),a=n.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.key),o=e=>e.filter(e=>r.has(e)),{toolSpecs:s,providers:c,tools:l,...u}=n;return C({...e,toolSpecs:n.toolSpecs,agents:e.agents.map(e=>e.key===t?{...u,key:t,tools:{...l,allow:[...o(e.tools.allow),...a]}}:e.tools.allow.every(e=>r.has(e))?e:{...e,tools:{...e.tools,allow:o(e.tools.allow)}})})}function re(t,n=l()){let r=new Map(t.toolSpecs.map(e=>[e.toolName,e.key])),i=n.identity.agentId.trim(),a=t.agents.map(e=>e.identity.agentId),o=i&&e(i,a,e=>`${i}_${e}`),s=v({...n,identity:{...n.identity,agentId:o}});return s.tools.allow=n.toolSpecs.map(e=>r.get(e.toolName)??e.key),C({...t,agents:[...t.agents,s],toolSpecs:[...t.toolSpecs,...n.toolSpecs.filter(e=>!r.has(e.toolName))],selected:p(s.key)})}function ie(t,n){let r=t.agents.findIndex(e=>e.key===n),i=t.agents[r];if(!i)return t;let a=i.identity.agentId.trim()||`agent`,o=t.agents.map(e=>e.identity.agentId),s={...structuredClone(i),key:c(`agent`)};s.identity.agentId=e(`${a}_copy`,o,e=>`${a}_copy${e}`);let l=[...t.agents];return l.splice(r+1,0,s),C({...t,agents:l,selected:p(s.key)})}function ae(e,t){let n=e.agents.findIndex(e=>e.key===t);if(n<0||e.agents.length===1)return e;let r=e.agents[n+1]??e.agents[n-1];if(!r)return e;let i=new Set(e.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t).map(e=>e.key)),a=e.agents.filter(e=>e.key!==t).map(e=>({...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>!i.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith===t?{...e,compactWith:void 0}:e)})),o=m(e.selected)?.key===t||[...i].some(t=>e.selected===s(t));return C({...e,agents:a,toolSpecs:e.toolSpecs.filter(e=>!i.has(e.key)).map(e=>e.stageAgentKey===t?{...e,stageAgentKey:void 0}:e),selected:o?p(r.key):e.selected,chatWith:e.chatWith===t?r.key:e.chatWith})}function oe(e,t,n,r){let i=e.agents.find(e=>e.key===t);if(!i||!e.toolSpecs.some(e=>e.key===n)||i.tools.allow.includes(n)===r)return e;let a=r?[...i.tools.allow,n]:i.tools.allow.filter(e=>e!==n);return{...e,agents:b(e,t,()=>({...i,tools:{...i.tools,allow:a}}))}}function se(e,t){if(!e.toolSpecs.some(e=>e.key===t))return e;let n=e.agents.map(e=>e.tools.allow.includes(t)?{...e,tools:{...e.tools,allow:e.tools.allow.filter(e=>e!==t)}}:e);return C({...e,agents:n,toolSpecs:e.toolSpecs.filter(e=>e.key!==t),selected:e.selected===s(t)?p(e.agents[0]?.key??``):e.selected})}var k=(e,t)=>d(e)===d(t),A=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function ce(e){let{agents:t,tools:n,providers:r}=e.starts;return e.agents.every(e=>k(e,t[e.key]))&&e.toolSpecs.every(e=>k(e,n[e.key]))&&e.providers.every(e=>k(e,r[e.id]))&&Object.keys(n).length===e.toolSpecs.length}function le(e){return{...e,starts:{agents:Object.fromEntries(e.agents.map(e=>[e.key,e])),tools:Object.fromEntries(e.toolSpecs.map(e=>[e.key,e])),providers:Object.fromEntries(e.providers.map(e=>[e.id,e]))}}}function ue(e,t,n,r){return{...e,identity:{...e.identity,agentId:t},tools:{...e.tools,allow:e.tools.allow.filter(e=>n.has(e))},modelBindings:e.modelBindings.map(e=>e.compactWith&&!r.has(e.compactWith)?{...e,compactWith:void 0}:e)}}function j(t,n){let r=t.starts.agents[n],i=t.agents.find(e=>e.key===n);if(!r||!i)return t;let a=new Set(t.agents.map(e=>e.key)),o=new Set(t.toolSpecs.map(e=>e.key)),s=t.toolSpecs.map(e=>e.toolName),c=[];for(let n of r.tools.allow){let r=t.starts.tools[n];if(o.has(n)||!r||r.toolType===`agent`&&!a.has(r.agentKey??``))continue;let i=e(r.toolName,s,e=>`${r.toolName}_${e}`);s.push(i),c.push({...r,toolName:i})}let l=c.length?[...t.toolSpecs,...c]:t.toolSpecs,u=new Set(l.map(e=>e.key)),d=r.identity.agentId,f=t.agents.filter(e=>e.key!==n).map(e=>e.identity.agentId),m=ue(r,d&&e(d,f,e=>`${d}_${e}`),u,a);if(c.length===0&&k(m,i))return t;let h=te(t,[r]),_={...t,agents:b(t,n,()=>m),toolSpecs:l,providers:h};return g(_,_.selected)?_:{..._,selected:p(n)}}function de(e,t,n){if(n.facet===`identity`)return j(e,t);if(n.facet===`toolSpec`)return Y(e,n.key);let r=j(e,t),i=r.agents.find(e=>e.key===t),a=e.agents.find(e=>e.key===t);if(r===e||!i||!a)return e;let o=fe(a,i,n);return k(o,a)?e:{...e,agents:b(e,t,()=>o),toolSpecs:n.facet===`tools`?r.toolSpecs:e.toolSpecs,providers:n.facet===`models`||n.facet===`modelBinding`?r.providers:e.providers}}function fe(e,t,n){if(n.facet===`models`)return{...e,models:t.models,modelBindings:t.modelBindings};if(n.facet===`modelBinding`){let r=t.modelBindings.find(e=>e.key===n.key);return r?{...e,modelBindings:e.modelBindings.map(e=>e.key===n.key?r:e)}:e}return n.facet===`toolSpec`?e:M(e,t,n.facet)}function M(e,t,n){return{...e,[n]:t[n]}}function N(e,t){let n=new Map(Object.values(t.starts.agents).map(e=>[e.identity.agentId,e.key])),r=new Map(Object.values(t.starts.tools).map(e=>[e.toolName,e.key])),i=JSON.stringify(e),a=(e,t)=>{t!==void 0&&t!==e&&(i=i.split(e).join(t))};for(let t of e.agents)a(t.key,n.get(t.identity.agentId));for(let t of e.toolSpecs)a(t.key,r.get(t.toolName));let o=JSON.parse(i);return{...o,selected:g(o,t.selected)?t.selected:o.selected,chatWith:o.agents.some(e=>e.key===t.chatWith)?t.chatWith:o.chatWith}}function P(e,t){let n=N(t,e),r=(e,t,n,r,i)=>{let a=new Map(r.map(t=>[e(t),t])),o=new Set([...t.map(e),...Object.keys(n)]),s=t.map(t=>k(t,n[e(t)])?a.get(e(t))??t:t),c=s.filter(t=>!(e(t)in i)).map(t=>[e(t),n[e(t)]??t]);return{held:[...s,...r.filter(t=>!o.has(e(t)))],starts:{...Object.fromEntries(c),...i}}},i=r(x,e.agents,e.starts.agents,n.agents,n.starts.agents),a=r(x,e.toolSpecs,e.starts.tools,n.toolSpecs,n.starts.tools),o=r(S,e.providers,e.starts.providers,n.providers,n.starts.providers);return{...e,agents:i.held,toolSpecs:a.held,providers:o.held,starts:{agents:i.starts,tools:a.starts,providers:o.starts}}}function F(e){let t=new Map,n=e=>{if(Array.isArray(e))for(let t of e)n(t);else if(typeof e==`object`&&e)for(let[r,i]of Object.entries(e))r!==`key`||typeof i!=`string`?n(i):t.has(i)||t.set(i,`#${t.size}`)},r=e=>typeof e==`string`?t.get(e)??e:Array.isArray(e)?e.map(r):typeof e!=`object`||!e?e:Object.fromEntries(Object.entries(e).map(([e,n])=>[t.get(e)??e,r(n)])),i={agents:e.agents,toolSpecs:e.toolSpecs,providers:e.providers};n(i);let a=JSON.stringify(r(i)),o=2166136261,s=16777619;for(let e=0;e<a.length;e+=1){let t=a.charCodeAt(e);o=Math.imul(o^t,16777619),s=Math.imul(s^t,2246822507)}return`${a.length.toString(36)}-${(o>>>0).toString(36)}${(s>>>0).toString(36)}`}function I(e,t){return F(e)!==t}var L=/^(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}$/;function R(e){let t=new Map;return JSON.stringify(e).replace(/\b(agent|model|tool|question|criterion|reference)-[0-9a-f]{8}\b/g,e=>(t.has(e)||t.set(e,`#${t.size}`),t.get(e)??e))}function z(e,t){let n=t.map(R),r=new Set,i=[],a=[];for(let o of e){let e=R(o),s=n.findIndex((t,n)=>t===e&&!r.has(n));s<0?a.push(o):(r.add(s),i.push([o,t[s]]))}let o=t.filter((e,t)=>!r.has(t));for(let[e,t]of a.slice(0,o.length).entries())i.push([t,o[e]]);return i}function B(e,t){let n=JSON.stringify(e),r=(e,t,r,i)=>{let a=new Set(r.map(e=>e.key)),o=new Set(e.map(e=>e.key)),s=e.flatMap(e=>a.has(e.key)?[]:t[e.key]??[]),c=r.filter(e=>!o.has(e.key)&&!t[e.key]),[l,u]=[s[0],c[0]];s.length===1&&c.length===1&&l&&u&&R(i(l))===R(i(u))&&(n=n.split(u.key).join(l.key))};return r(t.agents,t.starts.agents,e.agents,e=>({...e,identity:{...e.identity,agentId:``}})),r(t.toolSpecs,t.starts.tools,e.toolSpecs,e=>({...e,toolName:``})),JSON.parse(n)}function V(e,t){let n=JSON.stringify(e);for(let e=0;e<4;e+=1){let e=JSON.parse(n),r=new Map,i=(e,t)=>{if(Array.isArray(e)&&Array.isArray(t))for(let[n,r]of z(e,t))i(n,r);else if(A(e)&&A(t))for(let[n,a]of Object.entries(e)){let e=t[n];n===`key`?typeof a==`string`&&typeof e==`string`&&a!==e&&L.test(a)&&L.test(e)&&r.set(e,a):i(a,e)}};for(let n of e.agents)i(t.agents[n.key],n);for(let n of e.toolSpecs)i(t.tools[n.key],n);if(r.size===0)return e;for(let[e,t]of r)n=n.split(e).join(t)}return JSON.parse(n)}var H=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`)&&new Set(e).size===e.length,U=e=>Array.isArray(e)&&e.every(e=>A(e)&&typeof e.key==`string`);function W(e,t,n,r,i){if(k(e,n)||k(t,n))return t;if(A(e)&&A(t)&&A(n)){let a={};for(let o of new Set([...Object.keys(n),...Object.keys(t),...Object.keys(e)])){let s=W(e[o],t[o],n[o],[...r,o],i);s!==void 0&&(a[o]=s)}return a}if(U(e)&&U(t)&&U(n)){let a=new Map(e.map(e=>[e.key,e])),o=new Map(n.map(e=>[e.key,e])),s=[];for(let e of t){let[t,n]=[a.get(e.key),o.get(e.key)],c=[...r,s.length];t?n?s.push(W(t,e,n,c,i)):k(e,t)?i.updated(c):(i.conflict(c,e,void 0),s.push(e)):s.push(e)}let c=new Set(t.map(e=>e.key)),l=s.length;for(let e of n){if(c.has(e.key))continue;let t=a.get(e.key);t?k(e,t)||i.conflict([...r,l++],void 0,e):(i.updated([...r,s.length]),s.push(e),l+=1)}return s}if(k(e,t))return i.updated(r),n;if(H(e)&&H(t)&&H(n)){let a=e.filter(e=>!n.includes(e)),o=n.filter(n=>!e.includes(n)&&!t.includes(n));return i.updated(r),[...t.filter(e=>!a.includes(e)),...o]}return i.conflict(r,t,n),t}function G(e){let t=new Set(e.agents.map(e=>e.key)),n=e.toolSpecs.filter(e=>e.toolType!==`agent`||t.has(e.agentKey??``)).map(e=>e.stageAgentKey&&!t.has(e.stageAgentKey)?{...e,stageAgentKey:void 0}:e),r=new Set(n.map(e=>e.key)),i=e.agents.map(e=>{let n=e.tools.allow.filter(e=>r.has(e)),i=e.modelBindings.map(e=>e.compactWith&&!t.has(e.compactWith)?{...e,compactWith:void 0}:e),a={...e,tools:{...e.tools,allow:n},modelBindings:i};return k(a,e)?e:a}),a=C({...e,agents:i,toolSpecs:n}),o=i[0];return{...a,selected:g(a,a.selected)||!o?a.selected:p(o.key),chatWith:t.has(a.chatWith)||!o?a.chatWith:o.key}}function pe(e,t,n){let r=V(B(N(t,e),e),e.starts),i=[],a=[],o=(e,t,n,r,o,s,c,l)=>{let u=new Map(s.map(e=>[t(e),e])),d=new Set(r.map(e=>t(e))),f=new Set(r.map(e=>n(o[t(e)]??e))),p=new Set(l?.map(n)),m=[],h={...c};for(let s of r){let[r,c]=[o[t(s)],u.get(t(s))],l={kind:e,key:t(s),name:n(c??r??s)};!r||!c&&!p.has(n(r))?(m.push(s),h[t(s)]=r??s):c?m.push(W(r,s,c,[],{updated:e=>i.push({...l,path:e}),conflict:(e,t,n)=>a.push({...l,path:e,mine:t,theirs:n})})):k(s,r)?i.push({...l,path:[]}):(a.push({...l,path:[],mine:s,theirs:void 0}),m.push(s),h[t(s)]=r)}let g=e=>{let r=o[t(e)]??l?.find(t=>n(t)===n(e)&&!f.has(n(t)));if(r)return R(r)===R(e)?`unchanged`:`changed`};for(let r of s){if(d.has(t(r)))continue;let o={kind:e,key:t(r),name:n(r),path:[]},s=g(r);s===`changed`?a.push({...o,mine:void 0,theirs:r}):s===void 0&&(m.push(r),i.push(o))}return{held:m,starts:h}},s=o(`agent`,x,e=>e.identity.agentId,e.agents,e.starts.agents,r.agents,r.starts.agents,n?.agents),c=o(`tool`,x,e=>e.toolName,e.toolSpecs,e.starts.tools,r.toolSpecs,r.starts.tools,n?.toolSpecs),l=o(`provider`,S,S,e.providers,e.starts.providers,r.providers,r.starts.providers,n?.providers);return{workspace:G({...e,agents:s.held,toolSpecs:c.held,providers:l.held,starts:{agents:s.starts,tools:c.starts,providers:l.starts}}),updated:i,conflicts:a,files:r}}var K=Object.freeze({gone:!0});function q(e){if(Array.isArray(e))return e.filter(e=>e!==K).map(q);if(!A(e))return e;let t=Object.entries(e).map(([e,t])=>[e,q(t)]);return Object.fromEntries(t)}function J(e,t,n){let[r,...i]=t;if(r===void 0)return n;if(Array.isArray(e))return typeof r==`number`&&r>=e.length?n===void 0?e:[...e,n]:e.map((e,t)=>t===r?i.length===0&&n===void 0?K:J(e,i,n):e);let a={...A(e)?e:{}},o=J(a[r],i,n);return o===void 0?delete a[r]:a[r]=o,a}function me(e,t){let{agents:n,toolSpecs:r,providers:i}=e.workspace,a={agents:{...e.workspace.starts.agents},tools:{...e.workspace.starts.tools},providers:{...e.workspace.starts.providers}},o=(e,t,n,r)=>r.path.length>0?t.map(t=>e(t)===r.key?J(t,r.path,r.theirs):t):r.theirs===void 0?(delete n[r.key],t.filter(t=>e(t)!==r.key)):(n[r.key]=r.theirs,[...t,r.theirs]);for(let s of new Set(t)){let t=e.conflicts[s];if(t){if(t.kind===`tool`)r=o(x,r,a.tools,t);else if(t.kind===`provider`)i=o(S,i,a.providers,t);else{if(n=o(x,n,a.agents,t),t.path.length>0||t.theirs===void 0)continue;let i=new Set(r.map(e=>e.key)),s=e.files.toolSpecs.filter(e=>e.toolType===`agent`&&e.agentKey===t.key&&!i.has(e.key));for(let e of s)a.tools[e.key]=e;r=[...r,...s],n=n.map(t=>{let n=e.files.agents.find(e=>e.key===t.key)?.tools.allow??[],r=s.map(e=>e.key).filter(e=>n.includes(e)&&!t.tools.allow.includes(e));return r.length?{...t,tools:{...t.tools,allow:[...t.tools.allow,...r]}}:t})}}}return[n,r]=[q(n),q(r)],G({...e.workspace,agents:n,toolSpecs:r,providers:i,starts:a})}function Y(t,n){let r=t.starts.tools[n],i=t.toolSpecs.find(e=>e.key===n);if(!r||!i)return t;let a=t.toolSpecs.filter(e=>e.key!==n).map(e=>e.toolName),o={...r,toolName:e(r.toolName,a,e=>`${r.toolName}_${e}`)};return k(o,i)?t:{...t,toolSpecs:t.toolSpecs.map(e=>e.key===n?o:e)}}function X(e,t){let n=e.providers.find(e=>e.id===t.id);return!n||k(n,t)?e:{...e,providers:e.providers.map(e=>e.id===t.id?t:e)}}function Z(e,t){let n=e.agents.map(e=>w(e).filter(e=>e===t).length);return{models:n.reduce((e,t)=>e+t,0),agents:n.filter(e=>e>0).length}}function Q(e,t,n,r,i){let a=e=>e.provider===r&&e.apiId.trim()===i.trim();return{models:(e.agents.find(e=>e.key===t)?.modelBindings??[]).filter(e=>e.key!==n&&a(e)).map(e=>e.modelId.trim()||`new`),agents:e.agents.filter(e=>e.key!==t&&e.modelBindings.some(a)).map(e=>e.identity.agentId.trim()||`New agent`)}}function he(t,n){return{id:e(`provider`,t,e=>`provider_${e}`),definition:n,connection:{}}}function ge(e,t){return e.providers.some(e=>e.id===t.id)?e:C({...e,providers:[...e.providers,t],selected:o(t.id)})}function _e(e,t){return!e.providers.some(e=>e.id===t)||Z(e,t).models>0?e:C({...e,providers:e.providers.filter(e=>e.id!==t),selected:e.selected===o(t)?p(e.agents[0]?.key??``):e.selected})}function ve(e,t,n){let r=n.trim();if(!e.providers.some(e=>e.id===t)||!r||e.providers.some(e=>e.id===r))return e;let{[t]:i,...a}=e.starts.providers,s=e=>e.provider===t;return{...e,providers:e.providers.map(e=>e.id===t?{...e,id:r}:e),agents:e.agents.map(e=>e.modelBindings.some(s)?{...e,modelBindings:e.modelBindings.map(e=>s(e)?{...e,provider:r}:e)}:e),selected:e.selected===o(t)?o(r):e.selected,starts:{...e.starts,providers:i?{...a,[r]:{...i,id:r}}:a}}}function ye(e){return e.providers.flatMap(t=>{let n=e.starts.providers[t.id];return n&&k(n,t)?[t.id]:[]})}function be(e,t){let n=e.starts.providers[t];return n?X(e,n):e}function $(e,t){return{...t,id:p(e,t.id),children:t.children.map(t=>$(e,t))}}function xe(e,n){let r=$(e.key,t(_(e,[],n)));return e.identity.agentId.trim()?r:{...r,label:`New agent`}}function Se(e){return{agents:e.agents.map(t=>xe(t,e.providers)),tools:n(e.toolSpecs)}}export{me as A,de as C,oe as D,h as E,Se as F,d as I,X as M,E as N,le as O,g as P,j as S,be as T,ae as _,ce as a,ve as b,F as c,pe as d,Q as f,P as g,ye as h,p as i,O as j,T as k,D as l,Z as m,ge as n,ie as o,he as p,ee as r,I as s,re as t,ne as u,se as v,Y as w,N as x,_e as y};
|