@theoremjs/studio 0.3.4-next.693.g4ab1526 → 0.3.4-next.715.geef22fd

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/agreement.js +35 -5
  2. package/compile.d.ts +3 -3
  3. package/compile.js +43 -20
  4. package/cookbooks/catalog.js +8 -10
  5. package/draft.d.ts +12 -9
  6. package/draft.js +4 -4
  7. package/mod.d.ts +1 -2
  8. package/mod.js +1 -2
  9. package/package.json +4 -4
  10. package/page/assets/Banner-CrhjYjDy.js +3 -0
  11. package/page/assets/{ConsoleFrame-BvgFGqp2.js → ConsoleFrame-dOTqIkpb.js} +1 -1
  12. package/page/assets/{MenuBottomSheet-BZecY8fw.js → MenuBottomSheet-DeuZCVb-.js} +1 -1
  13. package/page/assets/{SchemaFields-BNNkvyyO.js → SchemaFields-DeuNDrvj.js} +1 -1
  14. package/page/assets/{ToolResultCharts-C3CPsfXl.js → ToolResultCharts-B-pokquL.js} +1 -1
  15. package/page/assets/{TraceInspector-36e6ozKD.js → TraceInspector-CvJ0wx9n.js} +1 -1
  16. package/page/assets/{TraceOverview-CSdJ_cYY.js → TraceOverview-cIjJwpvK.js} +1 -1
  17. package/page/assets/{_virtual_studio-type-sources-DSpwr3WK.js → _virtual_studio-type-sources-BxnDf9BC.js} +225 -85
  18. package/page/assets/browser-connection-CuWeoI9s.js +3 -0
  19. package/page/assets/browser-engine-C3SeJyrA.js +13 -0
  20. package/page/assets/{browser-transport-GzhRiBdm.js → browser-transport-DKhZ4zo1.js} +3 -3
  21. package/page/assets/{crypto-B8dqEoWf.js → crypto-BnoW7FFO.js} +1 -1
  22. package/page/assets/{encode-files-CHeRLBO8.js → encode-files-DoLGXgup.js} +1 -1
  23. package/page/assets/{export-agent-botXSyoH.js → export-agent-CO4lAMum.js} +1 -1
  24. package/page/assets/{guardrail-tester-DYR7EPIy.js → guardrail-tester-Slctc2oI.js} +1 -1
  25. package/page/assets/{index-B7sK7d-l.js → index-CAK9cdCh.js} +72 -76
  26. package/page/assets/{labels-provider-t4c-5JMk.js → labels-provider-uONlWExD.js} +1 -1
  27. package/page/assets/{live-messages-DN_q2nBN.js → live-messages-M0vS3YB0.js} +1 -1
  28. package/page/assets/people-CIsR0-5R.js +1 -0
  29. package/page/assets/reader-747-Cvu8.js +5 -0
  30. package/page/assets/{shaped-data-CJQ3W_RE.js → shaped-data-7q5Be8sp.js} +3 -3
  31. package/page/assets/{stub-U6wDGe3P.js → stub--LOYiyQO.js} +1 -1
  32. package/page/assets/studio-code-pane-CuccT4Ur.js +10 -0
  33. package/page/assets/{studio-console-B7zL133d.js → studio-console-DwxLzV9_.js} +1 -1
  34. package/page/assets/{studio-decision-CbRjfbvG.js → studio-decision-w6OjVUM3.js} +1 -1
  35. package/page/assets/{studio-embedding-DQ0QrEsu.js → studio-embedding-CxFoTvOd.js} +1 -1
  36. package/page/assets/studio-host-console-BhQSkUhA.js +2 -0
  37. package/page/assets/{studio-labels-jYWBoEyP.js → studio-labels-q6eBFSru.js} +1 -1
  38. package/page/assets/{studio-live-D0YRu2zQ.js → studio-live-D5NjMEky.js} +1 -1
  39. package/page/assets/{studio-map-C4Ra1QqL.js → studio-map-DlkGoGam.js} +1 -1
  40. package/page/assets/studio-session-ClF2iNCX.js +1 -0
  41. package/page/assets/{studio-trace-replay-D-f2p7k9.js → studio-trace-replay-Ccv4ToIz.js} +1 -1
  42. package/page/assets/{studio-type-checker-CVNPnko-.js → studio-type-checker-Dm2eit0p.js} +1 -1
  43. package/page/assets/{tool-schema-BDG2_rlP.js → tool-schema-6RWBAqGO.js} +2 -2
  44. package/page/assets/{trace-record-DoXjxrmJ.js → trace-record-Dm2jEhUR.js} +1 -1
  45. package/page/assets/tree-DcCW259J.js +3 -0
  46. package/page/assets/turn-client-OLK12Fyi.js +2 -0
  47. package/page/assets/{use-one-call-B3t-kfc5.js → use-one-call-CLndFp2X.js} +1 -1
  48. package/page/assets/use-second-ticker-D6JSf9B3.js +1 -0
  49. package/page/assets/{workspace-DUfaxr-g.js → workspace-DSAX72vF.js} +1 -1
  50. package/page/index.html +18 -17
  51. package/read-source.js +41 -8
  52. package/registrations.d.ts +9 -1
  53. package/runtime.js +1 -0
  54. package/section-notes.d.ts +1 -0
  55. package/section-notes.js +1 -0
  56. package/serve-page.mjs +8 -4
  57. package/server/handler.d.ts +0 -3
  58. package/server/handler.js +4 -26
  59. package/server/live.d.ts +1 -2
  60. package/server/live.js +3 -4
  61. package/server/save-plan.js +2 -1
  62. package/system-markup.d.ts +9 -7
  63. package/system-markup.js +38 -19
  64. package/tools.js +1 -0
  65. package/types.d.ts +3 -0
  66. package/ui/inspector-context.d.ts +1 -8
  67. package/ui/inspector-context.js +0 -7
  68. package/ui/inspector.d.ts +43 -1
  69. package/ui/inspector.js +50 -9
  70. package/ui/lib/entries.d.ts +13 -0
  71. package/ui/lib/entries.js +43 -0
  72. package/ui/lib/project-traces.js +2 -10
  73. package/ui/lib/studio-prefs.d.ts +0 -4
  74. package/ui/lib/studio-prefs.js +0 -7
  75. package/ui/lib/studio-project.d.ts +2 -5
  76. package/ui/lib/studio-project.js +1 -4
  77. package/ui/profile-editor.js +37 -49
  78. package/ui/studio-screen.d.ts +0 -1
  79. package/ui/studio-screen.js +8 -18
  80. package/ui/studio-settings.js +1 -12
  81. package/asks.d.ts +0 -61
  82. package/asks.js +0 -78
  83. package/page/assets/Banner-DrRNC3MG.js +0 -4
  84. package/page/assets/browser-connection-dads1eyK.js +0 -3
  85. package/page/assets/browser-engine-CugH58NS.js +0 -13
  86. package/page/assets/reader-DHN96tSr.js +0 -5
  87. package/page/assets/studio-code-pane-Boy63AK2.js +0 -8
  88. package/page/assets/studio-host-console-DDA2Um2-.js +0 -2
  89. package/page/assets/studio-session-CPnJaHc-.js +0 -1
  90. package/page/assets/tree-CcEbNvms.js +0 -3
  91. package/page/assets/turn-client-BmOSpCgw.js +0 -2
  92. package/page/assets/use-second-ticker-CWjCHLG6.js +0 -1
  93. package/ui/confirm-write.d.ts +0 -12
  94. package/ui/confirm-write.js +0 -45
@@ -1,5 +0,0 @@
1
- import{t as e}from"./preload-helper-DpV6A1kQ.js";import{C as t,D as n,E as r,O as i,S as a,T as o,b as s,c,d as l,g as u,h as d,l as f,m as p,o as m,p as h,s as g,t as _,u as v,v as y,x as b}from"./schemas-D7cgkv3L.js";import{Cn as x,Hn as S,Kn as C,Ln as ee,Qt as w,Rn as T,Sn as E,St as D,U as O,Wt as k,X as te,Yn as ne,Zt as re,_n as ie,bn as A,nr as ae,qn as oe,rr as se,s as ce,tr as le,un as ue,vn as de,xn as fe}from"./tool-schema-BDG2_rlP.js";import{c as j}from"./host-patterns-F-KZIzkF.js";import{$ as pe,Ar as me,Bt as he,Ct as ge,Dt as _e,En as ve,Er as ye,F as be,Fr as xe,G as Se,Gt as Ce,Ht as we,I as Te,It as Ee,Kt as De,L as Oe,Lr as M,Lt as ke,Mr as Ae,Mt as je,N as Me,Nt as Ne,P as Pe,Pn as Fe,Pr as Ie,Pt as Le,Qt as Re,R as ze,Rt as Be,Sr as Ve,Tr as He,Tt as Ue,Ut as We,V as Ge,Vt as Ke,Wn as qe,Wt as Je,Z as Ye,_n as Xe,at as Ze,br as Qe,cn as $e,cr as et,dt as tt,en as nt,gn as rt,gr as it,ht as N,it as at,j as ot,jr as st,ln as ct,lr as lt,mn as ut,nn as dt,nr as ft,nt as pt,pt as mt,rr as ht,rt as gt,sn as _t,tn as vt,tt as yt,vn as bt,xn as xt,xt as St,zn as Ct,zt as wt}from"./shaped-data-CJQ3W_RE.js";import{$ as Tt,F as Et,G as Dt,I as Ot,J as kt,K as At,O as jt,P as Mt,Q as Nt,R as Pt,V as Ft,W as It,Z as Lt,_ as Rt,b as zt,f as Bt,h as Vt,k as Ht,l as Ut,u as Wt,y as Gt,z as Kt}from"./browser-connection-dads1eyK.js";import{a as qt}from"./live-ingress-OuSlQ6q7.js";import{n as Jt,t as Yt}from"./trace-schema--4IGmLeE.js";import{n as Xt}from"./stub-U6wDGe3P.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:ht(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(...Be.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(we(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(We(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=Je(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,wt(hn(e,n,t)),n),n=-1}return r}var jn=new Set([`injection`,`base64`,`hex`,`spaced`,`pipe`]),Mn=new Map(ke.map(({pattern:e,hit:t})=>[e,t])),Nn=new Map(pt.flatMap(({pattern:e,hit:t})=>t?[[e,t]]:[]));function z(e){return{rule:et(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:gt};if(e===`image`||e===`link`){let r=(e===`image`?at:Ze).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:tt(i(n?.ungiven_images)),link:mt(i(n?.ungiven_links),r??e.includes(`ungiven_images`))},o=[];return pe.forEach((t,n)=>{let r=Ln(t);r?.detector&&e.includes(r.detector)&&o.push({...r,id:n,regex:De(t.pattern),...Rn(t.kind,t.pattern,a)})}),o}function Bn(){let e=[];return pe.forEach(({kind:t,pattern:n},r)=>{if(t!==`injection`)return;let i=Mn.get(n);e.push({...Pn,id:r,regex:De(n),...i?{hit:i}:{}})}),e}function Vn(){return Ce.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),C=[...new Set(S)].filter(e=>e>=0),ee=n.flatMap((e,t)=>S[t]<0?[]:[t]),w=new Int32Array(t.has.length).fill(-1);function T(){let{text:n,fresh:h}=e,g=mn(e),{classOf:_,has:v,edges:ee,final:T,pattern:E}=t;for(;p<n.length;p++){let e=_[p>=g?h.charCodeAt(p-g):n.charCodeAt(p)];f++;let t=0,D=(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++,T[e]&&(m[i[E[e]]]=1)};for(let t=0;t<l;t++){let n=ee[a[t]],r=o[t];for(let t=0;t<n.length;t+=2)v[n[t+1]][e]&&D(n[t],r)}let O=r[e];for(let e=0;e<O.length;e++){let t=O[e],n=i[E[t]],r=S[n],a=r<0?-1:w[r],o=a<0?p:a;D(t,o),y[n]&&(x[n]=p,b[n]<0&&(b[n]=o))}for(let t of C)v[t][e]?w[t]<0&&(w[t]=p):w[t]=-1;[a,s]=[s,a],[o,c]=[c,o],l=t}}function E(){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 ee){let t=w[S[e]];t<0||(t<_[e]&&(_[e]=t),t<r&&(r=t))}return r}function D(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 O={text:``,lower:``},k=()=>(O.text!==e.text&&(O={text:e.text,lower:e.text.toLowerCase()}),O.lower);function te(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,k)))return g[t]=a.lastIndex,h[t]=1,{rule:s,severity:c,start:e.rawAt(n.index),detector:l};u||a.lastIndex++,g[t]=a.lastIndex}}function ne(){for(let e=0;e<n.length;e++){let t=_[e];if(t<=g[e])continue;let r=n[e].find?D(e,t):te(e,t);if(r)return r}}return{run(t){T();let n=E();for(let e=ne();e;e=ne())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,Ke),F,r),i(_n(n,e=>he(e)??e),F,r),i(An(t),F,r))}if(o.includes(`marker_leak`)&&e.note){let t=yt(e.note);a.push(i(n,un(e.note),[{...Fn,id:0,regex:t}]))}if(o.includes(`tool_leak`)&&e.tools){let t=Se(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=Te(e,t).filter(e=>!(ze(e)||r.includes(e))),a=Oe(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=be(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?ge(s):void 0;S?.push(u);function C(e){let n=[];if(S?.push(e)&&n.push([a,ft]),c){let r=_.length;_+=e;let i=Ee(_,r);_=_.slice(i),v+=i;let[a]=Ye(_,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 ee(e){let t=l?C(e??``):[];return e&&r?.push(e),t.length===0?null:{hits:t,...n?{boundary:n.boundary}:{}}}function w(){let e=s&&a!==`flag`?E(s):h.length,n=c&&o!==`flag`?D(c,t.canary):h.length;return m+Math.min(e,n)}function T(e){if(d.length===0)return e;let t=[...d,...e.found?.hits??[]];return d=[],{...e,found:{action:e.found?.action??`flag`,hits:t}}}function E(e){let t=u.length+m,n=Math.max(t,x),r=Math.max(b,n-N),i=r+St(y.slice(r-b),e);i<n&&n>t&&(y=g+h,b=t-g.length,i=b+St(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 D(e,t){let n=m===0?u:``,r=u.length+m-n.length,[i,a]=v>=r?[_,v]:[n+h,r];return Math.max(0,a+Le(i,e,t)-u.length-m)}function O(e){let t=ee(e);if(t)return{blocked:!0,...t};let i=e===void 0,a=i?p.length:Math.min(w(),r?.holdFrom()??p.length),o=Math.max(0,a-m);if(!(n&&r))return T({blocked:!1,emit:k(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}:(k(s.taken),T({blocked:!1,emit:s.text??``,...s.action===`allow`?{}:{found:{action:s.action,hits:s.hits}}}))}function k(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),O(e)):{blocked:!1,emit:``}},flush:()=>O(),accumulated:()=>p,unreleased:()=>h,drainUnreleased:()=>k(h.length),carryOut:()=>l?_e(u+p,s,c):``}}function B(e,t,n){return Pe(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:Ge(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??Ge(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=[`user`,`slots`,`repair`,`attachment`,`voice`,`history`,`system`];function $n(e,t){return e&&Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t.read(n)]))}var er={client:`untrusted`,server:`assembled`};function tr(e){return typeof e==`string`?e:JSON.stringify(e)}function nr(e,t){let n=[],r=!1;if(!e)return{context:e,events:n,blocked:r};let i={};for(let a of vt){let o=e[a];if(o===void 0)continue;let s=t();i[a]=s.read(tr(o));let c=s.found(),l=Me(`context`,c);l&&n.push({...l,trust:er[a]}),r||=c.action===`block`}return{context:i,events:n,blocked:r}}var rr=/^[A-Za-z0-9._-]+$/;function ir(e){let t=e?.trim();return t&&rr.test(t)?t:void 0}function ar(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 or(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 sr(e,t){let n=t?`: ${t}`:``;return new j(`input`,`guardrails.detect blocked the request at ${e}${n}`,{copy:{key:`detect.blocked`}})}function cr(e,t){let{detect:n}=x(t.guardrails),r=Qe(Qn,e=>ot(e,n)),i=e.input??{},a=i.text===void 0?void 0:r.user.read(i.text),o=e.system===void 0?void 0:Dt(e.system,`TurnRequest.system`,e=>r.system.read(e)),s=$n(i.slots,r.slots),c=nr(i.context,()=>ot(`context`,n)),l=ar(i.repair,r.repair),u=i.history?or(i.history,r.history):void 0,{attachments:d,voice:f}=i.attachments?.length||i.voice?.length?Tt(t,i.attachments,i.voice,r):i,p=[],m;for(let e of Qn){let t=r[e].found(),n=Me(e,t);n&&p.push(Zt(n)),t.action===`block`&&(m??=sr(e,t.errorInternal))}return p.push(...c.events.map(Zt)),c.blocked&&(m??=sr(`context`)),{request:{...e,system:o,projectId:ir(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 lr(e,t){let{request:n,refusal:r}=cr(e,t);if(r)throw r;return n}function ur(e,t){return[...new Set([...t.filter(t=>de(e,t)),...e.filter(e=>de(t,e))])]}function dr(e,t){let n=e.attachments?t?ur(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 fr(e){let t=E(e[0]??``);return t===`application/pdf`?`PDF`:t.split(`/`)[0]??t}function pr(e,t){let n=Nt(e),r=kt({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=>de(t.accept,e.mimeType)).length>t.max&&r.push({code:`too_many_of_kind`,params:{maxFiles:t.max,kind:fr(t.accept)}})}let i=new Set;return r.filter(e=>{let t=JSON.stringify(e);return!i.has(t)&&(i.add(t),!0)})}var mr=`final_answer`;function hr(e){return e.structured!==null&&e.tools.wire.length>0}function gr(e,t,n){let{structured:r}=t;if(!r||!hr(t))return e;let i={type:`function`,name:mr,description:M(`structured.answer_tool`,{},n),parameters:r.jsonSchema};return{...e,structured:null,wireTools:[...e.wireTools??[],i]}}function _r(e,t){return e.get(t)||{name:t,missing:!0}}function vr(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 yr(e,t){return[...Mt(t),...vr(t)].map(t=>_r(e,t))}function br(e,t){if(Array.isArray(e)){for(let n of e)br(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),br(r,t);for(let e of Object.values(r))br(e,t)}function xr(e,t){let n=yr(e,t);if(n.length===0)return;let r=new Set;for(let e of n)`inputSchema`in e&&br(e.inputSchema,r);return{names:n.map(({name:e})=>e),params:[...r]}}function Sr(e){return!e||e.length===0?[]:e.slice(-4)}function Cr(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(`
2
- `)}\n\n`}function wr(e){let{profile:t,repair:n,history:r}=e,i=n.guidance||M(`repair.default_guidance`,{},t.labels),a=Cr(Sr(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 Tr(e,t){let n=[];return t&&n.push(`structured`),e.type===`image`&&n.push(`image`),e.type===`speech`&&n.push(`speech`),n}function Er(e,t){let n=Tr(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 Dr(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 Or(e,t){if(e.type===`transcription`){if(t.system)throw new j(`config`,`Profile ${e.id} (transcription) takes no system prompt — the input is the clip`);if(!t.input?.voice?.length)throw new j(`request`,`Profile ${e.id} (transcription) requires a voice clip`)}}function kr(e,t){return e.type===`speech`?{...e.speech,...Ar(t.speech)}:void 0}function Ar(e){return Object.fromEntries(Object.entries(e??{}).filter(([,e])=>e!==void 0))}function jr(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 Mr(e){let t=ie(e);if(!t)throw new j(`input`,`MIME '${e}' is not a supported media input type`);return t}function Nr(e){return e.map(e=>{let t=Mr(e.mimeType),n=E(e.mimeType),r=n===`image/jpg`?`image/jpeg`:n;return Lt(e)?{type:t,mimeType:r,uri:e.uri}:{type:t,mimeType:r,data:e.data}})}function Pr(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(A(e)?.text===!1&&n)throw new j(`request`,`Profile ${e.id} does not accept text input`);let a=r?wr({profile:e,repair:r,history:i}):Ir(e,t)??n;if(e.type===`speech`)return a?{type:`text`,text:a}:null;let o=[...Fr(t),...a?[Ne(a)]:[]];return o.length>0?{type:`text`,text:o.join(`
3
-
4
- `)}:null}function Fr(e){let t=e.input?.context??{};return[...vt].reverse().filter(e=>t[e]!==void 0).map(e=>je(e,tr(t[e])))}function Ir(e,t){if(t.continueFrom&&k.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 Lr(e){return e.type===`image`&&e.image.references?Nr(e.image.references):[]}function Rr(e,t){let n=t.input?.attachments??[],r=t.input?.voice??[];return[...Lr(e),...Nr(n),...Nr(r)]}function zr(e,t){let n=[],r=Pr(e,t);return r&&n.push(r),n.push(...Rr(e,t)),n}function Br(e,t){let n=t.input?.slots;if(!n)return;let r=A(e)?.slots??{};for(let[t,i]of Object.entries(n)){let n=Object.hasOwn(r,t)?r[t]:void 0;if(!n)throw new j(`request`,`Profile ${e.id} has no slot '${t}'`);let a=Ht(n);if(!a.includes(i))throw new j(`request`,`Profile ${e.id}: slot '${t}' takes ${a.join(`, `)}, not '${i}'`)}}function Vr(e,t){let n=t.input?.context;if(!n)return;let r=A(e)?.context;for(let[t,i]of Object.entries(n))if(i!==void 0){if(!vt.includes(t)||!r?.from.some(e=>e===t))throw new j(`request`,`Profile ${e.id} takes no context from '${t}'`);if(tr(i).length>r.maxChars)throw new j(`request`,`Profile ${e.id}: context from '${t}' is over inputs.context.maxChars (${String(r.maxChars)})`)}}var Hr=/\{([A-Za-z_][\w-]*)\}/g;function Ur(e,t,n,r){let i=A(e)?.slots;return i?t.replace(Hr,(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 Wr(e,t,n){if(e.type===`speech`||e.type===`transcription`)return[];let r=e.identity.system;if(!r)return[];let i=Ft(e.id,e.identity.conditions,n,t);return Kt(r,i,n=>Ur(e,n,t,`identity.system`))}function Gr(e,t){let n=Wr(e,t.input?.slots,t);return{pieces:It([...n.map(({pieces:e})=>e),t.system===void 0?[]:At(t.system)]),lines:n.map(({line:e})=>e)}}function Kr(e){return e.type!==`host`&&e.type!==`decision`&&e.type!==`embedding`}function qr(e,t){if(Kr(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 Jr(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 Yr(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 Xr(e){if(e.summaries===!0)return`auto`;if(e.summaries===!1)return`none`}function Zr(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 Qr(e){return e.type===`live`||e.outputs?.streaming?.mode!==`buffered`}function $r(e,t){return e.type===`live`?`live`:`turn`}function ei(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=w(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 ti(e,t){return B(x(t),[`live_reply`])?{...e,transcription:{...e?.transcription,output:!0}}:e}function ni(e){let{detect:t}=x(e.guardrails);return e.type!==`speech`&&e.type!==`transcription`&&qe(t,`canary_leak`)?Ue():``}function ri(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 ii(e,t,n){let r=qr(e.profiles.get(t.profile),`resolveTurn`);Br(r,t),Vr(r,t);let i=lr(t,r),a=i.input??{};ei(r,i);let o=n??Jr(r,i.model),s=fe(r,o),c=Pt(e.tools,r,i,o),l=c.builtins,u=Zr(r,a.slots);if(Er(r,u),u&&c.wire.some(e=>e.name===`final_answer`))throw new j(`config`,`Profile ${r.id}: a structured turn answers through '${mr}', so no tool of its own may take that name`);Dr(r,i),Or(r,i);let d=ri(r,o,s,i.builtInArgs),f=$r(r,s),p=e.providers.get(s.provider),m=p&&ue(p,s,r.type),h=Gr(r,i);return{profile:r,generation:{model:o,apiId:s.apiId,transport:f,...m?{operationName:m}:{},stream:Qr(r),thinking:Yr(r,s,o,i.effort),summaries:Xr(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:jr(r),speech:kr(r,i),live:r.type===`live`?ti(r.live,r.guardrails):void 0,input:zr(r,i),canary:ni(r),resolvedSystem:h.pieces,systemLines:h.lines,host:i.host}}}function ai(e){return e.type===`image`?e.image:null}function oi(e,t){let n=qr(t,`projectProfile`),{identity:r}=n,i=A(n)??null,a=n.type===`live`?null:n.outputs??null;return{id:n.id,type:n.type,handle:r.handle,models:n.models,defaultModel:n.defaultModel,allowModelSelect:n.allowModelSelect,maxSteps:n.maxSteps,tools:yr(e,n),inputs:i,outputs:a,image:ai(n),speech:n.type===`speech`?n.speech:null,live:n.type===`live`?n.live:null}}function si(e,t){return oi(e.tools,e.profiles.get(t))}var ci=/^[\x21-\x7E]{1,256}$/;function li(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 ui(e){return e!==null&&ci.test(e)}async function di(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var fi=`after`;function pi(){return l(r()).optional().describe(M(`tool.after_field`))}function mi(e,t){let r=t=>{if(t instanceof m){if(fi in t.shape)throw new j(`config`,`Tool '${e}' sets after, and its input already has a field of that name`);return t.safeExtend({[fi]:pi()})}if(t instanceof _){let e=t.options.map(r);return d(t.def.discriminator,e)}if(t instanceof g)return n(t.options.map(r));throw new j(`config`,`Tool '${e}' sets after, which needs an object input or a union of objects`)};return r(t)}function hi(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[fi]:n,...r}=t;return{input:r,names:n??[]}}function gi(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var _i=class{value;constructor(e){this.value=e}};function vi(e){return new _i(e)}function yi(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return vi(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))}}var bi=new WeakMap;function xi(e,t){let n=bi.get(e);n||(n=new WeakMap,bi.set(e,n));let r=n.get(t);if(!r){let i=Wt(e,`input`);Bt(i,`input`);let a=Wt(t,`output`);Bt(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Si(e){let{inputSchema:t,outputSchema:n}=xi(e.input,e.output),r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?D(n,r[t]):void 0;if(i)throw new j(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Ci(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 wi(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 Ti(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 Ei(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 V(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 Di(e){V(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(V(e.name,`imageLimits.count`,t.count),V(e.name,`imageLimits.bytes`,t.bytes),V(e.name,`imageLimits.totalBytes`,t.totalBytes),Ei(e.name,t.timeoutMs))}function Oi(e){return Ut(e.endpoint),Ci(e.name,e.auth),wi(e.name,e.auth,e.mapping?.queryParams),Ti(e.name,e.limit),Ei(e.name,e.timeoutMs),Di(e),{...e,type:`http`,...Si(e)}}function ki(e){return Ci(e.name,e.auth),wi(e.name,e.auth),Di(e),V(e.name,`session.idleMs`,e.session?.idleMs),V(e.name,`session.max`,e.session?.max),{...e,type:`mcp`,...Si(e)}}function Ai(e){Ci(e.name,e.auth),wi(e.name,e.auth);let t=e.answeredBy===`page`?yi(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`,...Si(e)}}function ji(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=Gt(e,t,n),i=A(r),a=Vt({type:r.type,...i?{inputs:i}:{}},e),o=e.after?mi(e.name,a):a,s=Si({...e,input:o,output:Rt});return zt(e,o,s)}let r=e.after?{...e,input:mi(e.name,e.input)}:e;return r.type===`http`?Oi(r):r.type===`mcp`?ki(r):Ai(r)}function Mi(e=()=>void 0){let t=new Map,n=li(),r=e=>t.get(e),i=n=>{let i=ji(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}}var Ni=[`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/wav`,`audio/mpeg`];function Pi(e){return e.join(`,`)}function Fi(e){let t=e?.attachments?.accept,n=e?.voice?.accept;return{text:e?.text!==!1,attachments:t?.length?{accept:t,acceptAttr:Pi(t)}:null,voice:n?.length?{accept:n}:null,maxFiles:e?.maxFiles,maxBytes:e?.maxBytes,maxTurnBytes:e?.maxTurnBytes,limitsByMime:e?.limitsByMime,slots:jt(e?.slots),context:e?.context}}function Ii(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 Li(e,t){let n=e=>(e??[]).map(({name:e,mimeType:t,sizeBytes:n})=>({name:e,mimeType:t,sizeBytes:n})),r=kt({attachments:e.attachments?.accept,voice:e.voice?.accept,limits:Nt(Ii(e))},n(t.attachments),n(t.voice));return{ok:r.length===0,issues:r}}function Ri(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(Ni.filter(t=>de(e,t)))??e.find(n):r(Ni)}var zi=b({protocol:r(),provider:r(),apiId:r(),options:t(r(),u()).optional(),keySlot:r().optional(),fallbackKeySlot:r().optional(),efforts:t(r(),c(bt)).optional(),defaultEffort:r().optional(),allowEffortSelect:h().optional(),summaries:h().optional(),maxOutputTokens:s().optional(),temperature:s().optional(),builtInTools:l(r()).optional(),compaction:b({maxTokens:s(),compactAt:s(),previousExchanges:s(),profile:r().optional(),timing:c(nt),meter:c(Re).optional()}).optional(),limits:b({operationTimeoutMs:s().optional(),connectTimeoutMs:s().optional(),liveStepTimeoutMs:s().optional(),maxWireRecordBytes:s().optional(),maxWireResponseBytes:s().optional(),maxEventBytes:s().optional(),maxStepBytes:s().optional(),maxStepEvents:s().optional(),maxPendingToolCalls:s().optional()}).optional()}),Bi=b({structured:n([r(),b({by:r(),map:t(r(),r()),fallback:r()}),f()]).optional(),streaming:b({mode:c(Xe).optional(),streamThoughts:h().optional()}).optional()}),Vi=b(Qe(it,()=>c(Ct))),Hi=b(Qe(Fe,()=>Vi)),Ui=b({id:r(),label:r(),actions:Vi,names:l(r()),find:h()}),Wi=b({hosts:l(r()),fromTools:h()}),Gi=b({quota:b({perDay:s()}).optional(),detect:Hi,patterns:a(c(Fe),b({theorem:h(),names:l(r())})).optional(),host:l(Ui).optional(),allow:b({ungiven_images:Wi,ungiven_links:Wi}),blockedReply:b({onBlock:c(lt),maxRetries:s()})}),Ki=n([h(),b({theorem:h(),host:h()})]),qi=b({record:h(),writeTo:n([y(!1),r()]).optional(),sampleRate:s(),include:b({upstreamLog:h(),outboundWire:h(),evidenceRaw:h(),usage:h(),guardrailDecisions:h(),guardrailMatchPreview:h()}),scrub:b({sensitive:Ki,injection:Ki,canary:Ki}),resource:Yt,retainForDays:s(),rotateAfterMiB:s(),hasOnWriteError:h()}),H=b({text:h(),attachments:b({accept:l(r()),acceptAttr:r()}).nullable(),voice:b({accept:l(r())}).nullable(),maxFiles:s().optional(),maxBytes:s().optional(),maxTurnBytes:s().optional(),limitsByMime:t(r(),s()).optional(),slots:t(r(),b({label:r().optional(),choices:l(b({value:r(),description:r().optional()}))})).optional(),context:b({from:l(c(vt)),maxChars:s()}).optional()}),Ji=b({allowContinue:l(c(dt)).optional(),autoContinue:l(c(dt)).optional(),maxContinues:s().optional()}),Yi=b({resumption:Ji.optional()}),Xi=b({allow:l(r()),page:l(r()),t2Loader:r().optional(),parallel:h().optional()}),U={providerContinuation:b({history:c([`host`,`stateless`,`provider`]).optional()}).optional(),id:r(),models:t(r(),zi),defaultModel:r(),allowModelSelect:h().optional(),maxSteps:s().optional(),labels:a(c(Ie),r()),guardrails:Gi.optional(),observability:qi.optional()},Zi=n([r(),o({private:r().min(1)})]),Qi=n([r(),l(n([r(),l(Zi).readonly()])).min(1).readonly()]),$i=b({handle:r(),conditions:t(r(),l(r()).readonly()).readonly().optional(),system:Qi.optional()}),W=d(`type`,[b({...U,type:y(`text`),identity:$i,outputs:Bi.optional(),inputs:H,tools:Xi,turnBehaviour:b({resumption:Ji.optional(),allowSteering:h().optional(),atStepLimit:c(rt).optional()}).optional(),canStop:y(!0),allowSteering:h()}),b({...U,type:y(`image`),identity:$i,outputs:Bi.optional(),image:b({aspectRatio:r().optional(),resolution:r().optional(),mimeType:r().optional(),quality:r().optional(),background:r().optional(),n:s().int().min(1).optional(),seed:s().int().optional(),outputCompression:s().int().min(0).max(100).optional(),references:l(n([b({mimeType:r(),data:r(),name:r().optional()}),b({mimeType:r(),uri:r(),name:r().optional()})])).optional(),includeText:h().optional()}),inputs:H,tools:Xi,turnBehaviour:Yi.optional(),canStop:y(!0)}),b({...U,type:y(`transcription`),identity:b({handle:r()}),maxSteps:v().optional(),outputs:Bi.optional(),inputs:H,canStop:y(!0)}),b({...U,type:y(`speech`),identity:b({handle:r()}),outputs:Bi.optional(),speech:b({voice:r().optional(),style:r().optional(),speed:s().optional(),format:c(ut).optional()}),inputs:H,turnBehaviour:Yi.optional(),canStop:y(!0)}),b({...U,type:y(`live`),identity:$i,inputs:H.pick({slots:!0,context:!0}).optional(),live:b({ingress:b({audio:h().optional(),video:h().optional(),text:h().optional()}).optional(),voice:r().optional(),vad:b({activityHandling:c(_t).optional(),startSensitivity:c(ct).optional(),endSensitivity:c($e).optional(),prefixPaddingMs:s().optional(),silenceDurationMs:s().optional()}).optional(),sessionResumption:h().optional(),contextCompression:b({triggerTokens:s().optional(),slidingWindow:b({targetTokens:s().optional()})}).optional(),transcription:b({input:h().optional(),output:h().optional()}).optional()}),tools:Xi.pick({allow:!0,page:!0}),turnBehaviour:b({allowSteering:h().optional()}).optional()})]);function ea(e){let t=x(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:ta(t.allow.ungiven_images),ungiven_links:ta(t.allow.ungiven_links)},blockedReply:t.blockedReply}}function ta(e){return{hosts:[...e.hosts??[]],fromTools:e.fromTools??!0}}function na(e){return e===void 0||e===!1||typeof e==`string`?e:`custom`}function ra(e){if(!e)return;let t=qt(e);return{record:t.record,writeTo:na(t.writeTo),sampleRate:t.sampleRate,include:t.include,scrub:t.scrub,resource:t.resource,retainForDays:t.retainForDays,rotateAfterMiB:t.rotateAfterMiB,hasOnWriteError:!!t.onWriteError}}function ia(e){let{greeting:t,resumed:n,...r}=e??{};return r}function aa(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=Ot(t),r=Et(t);return{allow:[...Mt(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 oa({allow:e,page:t}){return{allow:e,page:t}}function sa(e,t){let n=Fi(e.inputs),r=t?.identity??{handle:e.handle},i=t?ea(t.guardrails):void 0,a=t?ra(t.observability):void 0,o=e.outputs??void 0,s={id:e.id,identity:r,models:e.models,defaultModel:e.defaultModel,allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps,providerContinuation:e.providerContinuation,outputs:o,guardrails:i,observability:a,labels:xe(t?.labels)};switch(e.type){case`text`:return W.parse({...s,type:`text`,inputs:n,tools:aa(e,t),turnBehaviour:t?.type===`text`?t.turnBehaviour:void 0,canStop:!0,allowSteering:!t||re(t)});case`image`:return W.parse({...s,type:`image`,image:e.image??{},inputs:n,tools:aa(e,t),turnBehaviour:t?.type===`image`?t.turnBehaviour:void 0,canStop:!0});case`speech`:return W.parse({...s,type:`speech`,speech:e.speech??{},inputs:n,turnBehaviour:t?.type===`speech`?t.turnBehaviour:void 0,canStop:!0});case`transcription`:return W.parse({...s,type:`transcription`,inputs:n,canStop:!0});case`live`:return W.parse({...s,type:`live`,live:ia(e.live),...e.inputs?{inputs:{slots:n.slots,context:n.context}}:{},tools:oa(aa(e,t))});default:return e.type}}function ca(e,t){let n=qr(e,`interfaceFromProfile`);return sa(oi(t,n),n)}function la(e){return p(t=>C.safeParse(e(t)).success)}var ua=[`running`,`gate`,`complete`,`error`,`cancel`],da=p(e=>{let t=C.safeParse({type:`tool`,tool:e});if(!t.success||t.data.type!==`tool`||!(`phase`in t.data.tool))return!1;let{phase:n}=t.data.tool;return ua.some(e=>e===n)}),fa=t(r(),i()),pa=b({operationId:r().optional(),name:r(),callId:r(),arguments:fa,draft:r().optional(),reasoning:l(S).optional(),stepId:r().optional(),edited:b({from:fa,to:fa}).optional(),activity:r().optional(),activityPast:r().optional(),outputDraft:r().optional(),state:da.optional(),startedAt:s().optional(),endedAt:s().optional(),artifacts:l(i()),get steps(){return l(pa).optional()}}),ma=b({kind:c(ve),native:r().optional()}),G={id:r()},K=d(`kind`,[b({...G,kind:y(`user-text`),text:r()}),b({...G,kind:c([`user-attachment`,`user-voice`]),name:r(),mimeType:r(),sizeBytes:s(),data:r().optional()}),b({...G,kind:y(`thought`),text:r()}),b({...G,kind:y(`text`),text:r()}),b({...G,kind:y(`tool`),tool:pa}),b({...G,kind:y(`structured`),value:i(),draft:r().optional()}),b({...G,kind:y(`media`),mimeType:r(),data:r().optional(),url:r().optional(),previewUrl:r().optional()}),b({...G,kind:y(`grounding`),grounding:la(e=>({type:`grounding`,grounding:e}))}),b({...G,kind:y(`citation`),sources:la(e=>({type:`citation`,sources:e})),callId:r().optional()}),b({...G,kind:y(`evidence`),evidence:la(e=>({type:`evidence`,evidence:e}))}),b({...G,kind:y(`guardrail`),guardrail:se}),b({...G,kind:y(`error`),message:r()}),b({...G,kind:y(`turn-done`),stop:ma.optional(),tokens:la(e=>({type:`tokens`,tokens:e})).optional(),interactionId:r().optional(),compaction:h().optional(),workedMs:s().optional(),endedAt:s().optional()})]),ha=b({type:r()});function ga(e,t){return Object.hasOwn(e,t)}function _a(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=>_a(e,n)).join(` | `)}]`}).join(`; `)}function va(e){return _a(e.issues,[])}function ya(e,t){return new j(`bad_response`,`${e} failed its wire check: ${va(t)}`)}function q(e,t,n){let r=e.safeParse(t);if(!r.success)throw ya(n,r.error);return r.data}function ba(e){return{type:`malformed`,error:new j(`bad_response`,e,{copy:{key:`session.part_skipped`}})}}function xa(e,t){let n=ha.safeParse(t);if(!n.success)return ba(`a line without a kind failed its wire check: ${va(n.error)}`);let{type:r}=n.data;if(!ga(e,r))return{type:`unsupported`,received:r,raw:t};let i=e[r].safeParse(t);return i.success?i.data:ba(`a '${r}' line failed its wire check: ${va(i.error)}`)}function Sa(e){try{return{value:JSON.parse(e)}}catch(e){if(e instanceof SyntaxError)return;throw e}}function Ca(e,t){let n=Sa(t);return n?xa(e,n.value):ba(`a line is not JSON`)}function wa(e){let t=Sa(e);if(!t)throw new j(`bad_response`,`a line is not JSON`);return t.value}var Ta=b({name:r(),mimeType:r(),data:r()}),Ea=b({slots:t(r(),r()).optional(),context:i().optional(),text:r().optional(),attachments:l(Ta).optional(),voice:l(Ta).optional()}),Da=b({gateKind:c(xt).optional(),sessionPermissions:l(r()).optional(),name:r().optional(),input:i().optional(),snapshot:ne.optional(),promoted:l(r()).optional(),model:r().optional(),effort:r().optional()}),J=r().trim().min(1),Oa=b({path:r().optional(),conditions:t(r(),r()).optional()}),ka=Oa;b({input:Ea,conversation:r().min(1).optional(),model:r().optional(),effort:r().optional(),stated:Oa.optional(),turnId:J.optional(),abandon:l(T).min(1).optional(),replay:Da.pick({sessionPermissions:!0}).optional(),transcript:l(K).optional()});var Aa=[`approve`,`deny`],ja=n([o({unanswered:y(!0)}),o({output:i()}).refine(e=>`output`in e).transform(e=>({output:e.output}))]);b({gateId:r().min(1),operationId:r().min(1).max(256),decision:c(Aa),input:i().optional(),secret:r().optional(),page:ja.optional(),conversation:r().min(1).optional(),turnId:J.optional(),replay:Da.optional()}),b({turnId:J,id:J,inject:l(oe).min(1)}),b({turnId:J});var Ma=b({type:y(`conversation`),ref:r().min(1),posted:y(!0).optional()}),Na={...ee,conversation:Ma},Pa=b({transcript:l(K),paused:b({events:l(C),blocks:l(K)}).optional()});b({conversation:r().min(1)}),b({conversation:r().min(1),at:s().int().min(-1)}),b({blocks:l(K)});var Fa=b({conversation:r().min(1),view:Pa}),Ia=class extends Error{kind;publicMessage;internalMessage;copy;constructor(e,t,n,r){super(n??t??e),this.name=`TheoremStreamError`,this.kind=e,t&&(this.publicMessage=t),n&&(this.internalMessage=n),r&&(this.copy=r)}};function La(e){return e instanceof Ia}function Ra(e){return e?.trim()||void 0}var za=b({error:r().optional(),errorKind:ae.optional(),errorCopy:le.optional(),errorInternal:r().optional()}),Ba=za;function Va(e,t){let n=Ra(e.error),r=Ra(e.errorInternal);return new Ia(e.errorKind??t,n,r&&r!==n?r:void 0,e.errorCopy)}function Ha(e){return!La(e)||e.copy===void 0?!1:(Array.isArray(e.copy)?e.copy:[e.copy]).some(e=>e.key===`session.conversation_unknown`)}function Ua(e,t){let n=Ca(e,t);if(n.type===`error`)throw Va(za.parse(n),`internal`);return n}function Wa(e,t,n){let r=e.split(`
5
- `),i=r.pop()??``;for(let e of r)e.trim()&&n(Ua(t,e));return i}async function Ga(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(;;){me(r);let{done:e,value:s}=await i.read();if(e)break;o=Wa(o+a.decode(s,{stream:!0}),t,n)}let e=o.trim();e&&n(Ua(t,e))}finally{r?.removeEventListener(`abort`,s)}}async function Ka(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 qa(e,t){let n=await e.text(),r;try{r=JSON.parse(n),t?.(r)}catch{return Va({errorInternal:`HTTP ${String(e.status)}`},ye(e.status))}let i=za.safeParse(r);return i.success?Va({...i.data,errorInternal:i.data.errorInternal??`HTTP ${String(e.status)}`},ye(e.status)):new j(`bad_response`,`HTTP ${String(e.status)} error body failed its wire check`)}async function Ja(e,t,n){let r=n.fetch??globalThis.fetch.bind(globalThis);try{return await r(e,{...t,headers:await Ka(n),credentials:n.credentials??`same-origin`})}catch(e){throw He(e)?e:new j(`network`,Ve(e),{cause:e})}}async function Ya(e,t,n,r,i={}){await Ga(await Xa(e,t,i),n,r,i.signal)}async function Xa(e,t,n){let r=await Ja(e,{method:`POST`,body:JSON.stringify(t),signal:n.signal},n);if(!r.ok)throw await qa(r);return r}async function Za(e,t,n={}){await Xa(e,t,n)}async function Y(e,t,n={}){let r=await Ja(e,{...t.body===void 0?{method:`GET`}:{method:`POST`,body:JSON.stringify(t.body)},signal:t.signal},n);if(!r.ok)throw await qa(r,t.failed);return wa(await r.text())}async function Qa(e,t,n={}){let{signal:r,...i}=n;return q(Pa,await Y(e,{body:t,signal:r},i),`the conversation`)}async function $a(e,t,n,r){let{signal:i,...a}=n;return q(Fa,await Y(e,{body:t,signal:i},a),r)}function eo(e,t,n={}){return $a(e,t,n,`the rewound conversation`)}function to(e,t,n={}){return $a(e,t,n,`the started conversation`)}function no(e){let t=e.length;for(;t>0&&e[t-1]===`/`;)--t;return e.slice(0,t)}var ro=b({interface:W});function io(e={}){let t=no(e.endpoint??`/api/theorem`);return{async describe(n){let r=await Ja(t,{method:`GET`,signal:n},e);if(!r.ok)throw await qa(r);return q(ro,wa(await r.text()),`the profile description`).interface},turn:({replay:n,...r},i,a)=>Ya(`${t}/turn`,r,Na,i,{...e,signal:a}),invoke:({replay:n,...r},i,a)=>Ya(`${t}/invoke`,r,Na,i,{...e,signal:a}),conversation:(n,r)=>Qa(`${t}/conversation`,n,{...e,signal:r}),rewind:(n,r)=>eo(`${t}/rewind`,n,{...e,signal:r}),pageResult:(n,r)=>Za(`${t}/page-result`,n,{...e,signal:r}),steer:n=>Za(`${t}/steer`,n,e),stop:n=>Za(`${t}/stop`,n,e)}}function ao(e,t){if(typeof e==`string`)return e;let n=Array.isArray(e)?e:Object.keys(e);return n.length?ao(n[0],t):t}function oo(e){return Object.entries(e).map(([e,t])=>({id:e,type:t.type,labels:t.type===`choice`?Object.keys(t.criteria):t.type===`score`?t.criteria.map((e,t)=>ao(e,String(t))):[],...t.type===`box`&&t.image!==void 0?{image:t.image}:{}}))}function so(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:oo(t),...n&&Object.keys(n).length>0?{images:n}:{},...e.observability?{observability:{record:qt(e.observability).record}}:{}}}function co(e,t){let n=Object.keys(t??{}).find(t=>e&&Object.hasOwn(e,t));if(n!==void 0)throw new j(`request`,`the image ${n} is the host's, so the page's needs another name`);let r={...e,...t};return Object.keys(r).length>0?r:void 0}var X=s().min(0).max(1),lo=t(r(),X),uo=d(`type`,[b({type:y(`choice`),choice:r(),confidence:X,probabilities:lo}),b({type:y(`noul`),noul:X}),b({type:y(`box`),box:b({top:X,bottom:X,left:X,right:X}),confidence:X}),b({type:y(`score`),score:s().nonnegative(),confidence:X,legend:t(r(),r().min(1)),probabilities:lo})]),fo=b({id:r(),type:c([`choice`,`noul`,`score`,`box`]),labels:l(r()),image:r().optional()}),po=b({result:b({model:r().min(1),questions:l(fo).optional(),answers:t(r(),uo),usage:b({inputTokens:s().int().nonnegative(),outputTokens:s().int().nonnegative(),costUsd:s().nonnegative().optional()}).optional()}),traces:l(Jt).optional()}),mo=new WeakMap;function ho(e,t){return t.length>0&&typeof e==`object`&&e&&mo.set(e,t),e}function go(e){return typeof e==`object`&&!!e&&mo.get(e)||[]}var _o=b({traces:l(Jt)});async function vo(e,t,n,r,i){let a=[],o=e=>{let t=_o.safeParse(e);t.success&&(a=t.data.traces)};try{return i(await Y(e,{body:t,signal:n,failed:o},r))}catch(e){throw ho(e,a)}}function yo(e,t,n,r={}){return vo(e,t,n,r,bo)}function bo(e){return q(po,e,`the decision`)}var xo=b({interface:b({type:y(`decision`),identity:b({handle:r()}),contract:r(),maxStateBytes:s().optional(),questions:l(fo),build:b({input:t(r(),i()).optional()}).optional(),images:t(r(),b({mimeType:c([`image/png`,`image/jpeg`]),data:r()})).optional(),observability:b({record:h()}).optional()})});function So(e={}){let t=(e.endpoint??`/api/decision`).replace(/\/$/,``);return{async describe(n){return q(xo,await Y(t,{signal:n},e),`the decision description`).interface},decide:(n,r,i,a)=>yo(`${t}/decide`,{state:n,...i?{assets:i}:{},...a===void 0?{}:{input:a}},r,e)}}function Co(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 wo(e){let t=new Set;return e.filter(e=>!t.has(e.uri)&&(t.add(e.uri),!0))}function To(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 wo([...t,...n])}function Eo(e){if(Array.isArray(e))return e;if(!Co(e))return[];for(let t of[`items`,`results`,`search_results`,`models`,`datasets`]){let n=e[t];if(Array.isArray(n))return n}return[]}function Do(e,t){return wo(e.flatMap(e=>Co(e)?t(e)??[]:[]))}function Oo(e,t){let n=t===`dataset`?`https://huggingface.co/datasets/`:`https://huggingface.co/`;return Do(Eo(e),e=>{let t=Z(e,`id`)??Z(e,`modelId`);return t?Q(t,`${n}${t}`):void 0})}function ko(e){return Do(Eo(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 Ao(e){return e.replace(/<[^>]+>/g,``).replace(/\s+/g,` `).trim()}function jo(e){if(typeof e!=`string`)return To(JSON.stringify(e));let t=[...e.matchAll(/<entry\b[\s\S]*?<\/entry>/g)];return t.length===0?To(e):wo(t.flatMap(e=>{let t=/<id>(https?:\/\/[^<]+)<\/id>/.exec(e[0]??``)?.[1],n=/<title>([\s\S]*?)<\/title>/.exec(e[0]??``)?.[1];return t?Q(Ao(n??t),t)??[]:[]}))}function $(e){if(typeof e==`string`)return To(e);if(Array.isArray(e)||Co(e)){let t=Do(Eo(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:To(JSON.stringify(e))}return[]}var Mo={search_models:e=>Oo(e,`model`),search_datasets:e=>Oo(e,`dataset`),search_github:ko,list_arxiv:jo,search_web:$,read_pages:$,read_model_card:$,read_dataset_card:$,read_readme:$,find_library:$,read_library_docs:$,ask_repo_docs:$};function No(e){return Mo[e]}function Po(e,t){let n=No(e);return n?{...t,sources:n}:t}function Fo(e,t,n={}){let r={name:t.name,description:t.description,category:t.category,access:t.access,paths:t.paths,loadTier:t.loadTier,permission:t.permission,...t.labels?{labels:t.labels}:{},...t.after?{after:!0}:{}};if(t.type===`agent`){e.register({...r,type:`agent`,profile:t.profile,...t.maxCallsPerTurn===void 0?{}:{maxCallsPerTurn:t.maxCallsPerTurn}});return}let i={...r,input:ce(t.inputSchema),output:ce(t.outputSchema)};if(t.type===`http`){e.register(Po(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(Po(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 Io(e,t,n){e.registerMany([...O,...te]);for(let r of t)Fo(e,r,n)}function Lo(e,t,n,r,i){if(Io(e.tools,n,i),r&&t.type!==`live`)for(let{id:t,spec:n}of[r,...r.also??[]])e.schemas.register(t,n);return e.profiles.register(t),t}function Ro(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 zo(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 Bo(e){if(e.type!==`compaction`||e.failure?.errorInternal===void 0)return e;let{errorInternal:t,...n}=e.failure;return{...e,failure:n}}function Vo(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 Ho(e){if(e.type!==`evidence`||!e.evidence?.raw)return e;let{raw:t,...n}=e.evidence;return{...e,evidence:n}}function Uo(e,t){let n=t?.reader===`builder`?Ro(e):Bo(Vo(zo(e)));return t?.includeEvidenceRaw||(n=Ho(n)),n=$t(n,!1),n}function Wo(e,t){return e.map(e=>Uo(e,t))}function Go(e,t,n){let{error:r=``,errorKind:i,errorCopy:a}=Uo(Ae(st(e),t),n);return{error:r,errorKind:i,...a?{errorCopy:a}:{}}}var Ko={reader:`builder`};function qo(e){return e.mode===`demo`?{reader:`visitor`}:Ko}export{gr as $,va as A,gi as B,Ba as C,Ya as D,Za as E,Ri as F,si as G,ui as H,Li as I,Vr as J,ii as K,Mi as L,xa as M,K as N,ka as O,ca as P,hr as Q,_i as R,Va as S,Ha as T,di as U,li as V,Jr as W,xr as X,zr as Y,mr as Z,io as _,$t as _t,Wo as a,lr as at,eo as b,So as c,Xn as ct,go as d,B as dt,pr as et,yo as f,Kn as ft,Ia as g,Zt as gt,Na as h,Qt as ht,Uo as i,or as it,Ca as j,q as k,co as l,Jn as lt,ho as m,rn as mt,qo as n,sr as nt,Lo as o,cr as ot,vo as p,Gn as pt,Ur as q,Go as r,nr as rt,Io as s,Zn as st,Ko as t,dr as tt,so as u,Yn as ut,Qa as v,La as w,to as x,Y as y,hi as z};
@@ -1,8 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/studio-monaco-xfyfezQS.js","assets/editor.api-Cd3ViPQa.js","assets/preload-helper-DpV6A1kQ.js","assets/editor-DjpsE8to.css","assets/studio-monaco-CbKf90i6.css","assets/register-CDgivxvX.js","assets/studio-type-checker-CVNPnko-.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{c as t,u as n}from"./themeProps-3IqahpCr.js";import{t as r}from"./preload-helper-DpV6A1kQ.js";import{D as i,Gt as a,Kt as o,T as s,k as c}from"./tool-schema-BDG2_rlP.js";import{Jn as l,On as u,Pn as d,br as f,gr as p,tn as m}from"./shaped-data-CJQ3W_RE.js";import{X as h,b as g,g as ee,h as _,m as v,w as y,x as b,y as x}from"./tree-CcEbNvms.js";import{r as S}from"./live-ingress-OuSlQ6q7.js";import{n as C,r as w}from"./use-second-ticker-CWjCHLG6.js";import{n as T}from"./stub-U6wDGe3P.js";import{I as te,M as ne,k as re,r as ie}from"./workspace-DUfaxr-g.js";import{ct as ae,y as oe}from"./index-B7sK7d-l.js";var E=class extends Error{line;column;constructor(e,t,n){super(e),this.line=t,this.column=n}},se=class{text;of;i=0;line=1;column=1;constructor(e,t=`profile`){this.text=e,this.of=t}get done(){return this.i>=this.text.length}pos(){return{line:this.line,column:this.column}}fail(e){throw new E(e,this.line,this.column)}peek(e=0){return this.text[this.i+e]??``}bump(){let e=this.text[this.i]??``;return this.i+=1,e===`
3
- `?(this.line+=1,this.column=1):this.column+=1,e}skip(){for(;;){let e=this.peek();if(e===` `||e===` `||e===`
4
- `||e===`\r`||e===``)this.bump();else if(e===`/`&&this.peek(1)===`/`)for(;!this.done&&this.peek()!==`
5
- `;)this.bump();else if(e===`/`&&this.peek(1)===`*`){for(this.bump(),this.bump();!this.done&&(this.peek()!==`*`||this.peek(1)!==`/`);)this.bump();this.done&&this.fail(`This comment never closes.`),this.bump(),this.bump()}else return}}starts(e){return this.skip(),this.text.startsWith(e,this.i)}eat(e){if(!this.starts(e))return!1;for(let t=0;t<e.length;t+=1)this.bump();return!0}expect(e){this.eat(e)||this.fail(`Expected '${e}'.`)}ident(){this.skip();let e=this.peek();if(!/^[A-Za-z_$]/.test(e))return;let t=``;for(;/^[A-Za-z0-9_$]/.test(this.peek());)t+=this.bump();return t}expectIdent(){let e=this.ident();return e===void 0&&this.fail(`Expected a name.`),e}peekIdent(){return this.skip(),/^[A-Za-z_$][A-Za-z0-9_$]*/.exec(this.text.slice(this.i))?.[0]}rest(){return this.skip(),this.text.slice(this.i)}};function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e){e.skip();let t=e.peek();t!==`'`&&t!==`"`&&e.fail(`Expected a string.`),e.bump();let n=``;for(;!e.done&&e.peek()!==t;){let t=e.bump();if(t!==`\\`){n+=t;continue}let r=e.bump(),i={n:`
6
- `,r:`\r`,t:` `,"\\":`\\`,"'":`'`,'"':`"`};if(r in i)n+=i[r];else if(r===`u`){let t=``;for(let n=0;n<4;n+=1)t+=e.bump();n+=String.fromCharCode(Number.parseInt(t,16))}else n+=r}return e.peek()!==t&&e.fail(`This string never closes.`),e.bump(),n}function ce(e){e.skip();let t=e.pos(),n=``;for(e.peek()===`-`&&(n+=e.bump());/^[0-9.eE+-]/.test(e.peek())&&n.length<64;)n+=e.bump();let r=Number(n);if(!Number.isFinite(r))throw new E(`'${n}' is not a number.`,t.line,t.column);return r}function k(e,t,n,r){let i=0;for(;!e.done;){if(r()&&i===0)return;let a=e.peek();a===`'`||a===`"`?O(e):(a!==``&&t.includes(a)?i+=1:a!==``&&n.includes(a)&&--i,e.bump())}}function le(e){k(e,`<([{`,`>)]}`,()=>(e.skip(),e.peek()===`;`||e.peek()===`
7
- `))}function ue(e){k(e,`{([`,`})]`,()=>e.peek()===`;`),e.peek()===`;`&&e.bump()}function de(e,t,n){e.expect(`{`);let r={};for(;!e.eat(`}`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`);let i=e.pos(),a;if(a=e.peek()===`'`||e.peek()===`"`?O(e):e.expectIdent(),a===`__proto__`)throw new E(`'__proto__' sets what an object inherits, not a setting.`,i.line,i.column);if(Object.hasOwn(r,a))throw new E(`'${a}' is set twice.`,i.line,i.column);let o=t?`${t}.${a}`:a;n.push({path:o,line:i.line,column:i.column}),e.expect(`:`),r[a]=I(e,o,n),e.eat(`,`),e.done&&e.fail(`This object never closes.`)}return r}function fe(e,t,n){e.expect(`[`);let r=[],i=0;for(;!e.eat(`]`);){e.eat(`...`)&&e.fail(`This file doesn't use spreads.`),e.skip();let a=e.pos(),o=t?`${t}.${String(i)}`:String(i);n.push({path:o,line:a.line,column:a.column}),r.push(I(e,o,n)),i+=1,e.eat(`,`),e.done&&e.fail(`This array never closes.`)}return r}function pe(e,t,n){let[r]=t;return e!==`z.fromJSONSchema`&&n.fail(`The studio reads a schema as JSON Schema: z.fromJSONSchema({ ... }), not '${e}'.`),D(r)||n.fail(`z.fromJSONSchema() needs a schema.`),r}function A(e){return D(e)&&e.kind===`member`}function me(e,t){return{kind:`member`,object:e,name:t}}function j(e){if(typeof e.object==`string`)return`${e.object}.${e.name}`;if(A(e.object)){let t=j(e.object);return t?`${t}.${e.name}`:void 0}}function M(e,t,n){let r=e[0];return D(r)||t.fail(n),r}function he(e,t,n){let r=M(e,t,`registerTool() needs the tool object.`),i=r.type,a=typeof i==`string`&&C.includes(i);if(i!==void 0&&!a){let e=n.findLast(e=>e.path===`type`)??t.pos();throw new E(w,e.line,e.column)}return{kind:`registerTool`,tool:r}}function ge(e,t,n,r){if(n.of===`provider`){if(e!==`registerProvider`)return n.fail(`'${e}' isn't part of a provider's code.`);let[r,i={}]=t;return typeof r!=`string`&&n.fail(`registerProvider() needs the definition it registers from.`),(!D(i)||t.length>2)&&n.fail(`registerProvider() takes the definition and its settings.`),{kind:`provider`,definition:r,spec:i}}return e===`compileDetect`?M(t,n,`compileDetect() needs the detect object.`):e===`defineProfile`?M(t,n,`defineProfile() needs the profile object.`):e===`registerTool`?he(t,n,r):e===`registerStructured`?{kind:`registerStructured`,args:t}:e===`registerProfile`||e===`registerProvider`?{kind:e}:n.fail(`'${e}' isn't part of this file.`)}function _e(e,t,n){return(typeof t!=`string`||e.some(e=>typeof e!=`string`))&&n.fail(`.join() here joins lines of one string.`),e.join(t)}function ve(e,t,n){if(e.name===`join`&&Array.isArray(e.object))return _e(e.object,t[0],n);if(e.name===`resolve`&&e.object===`Promise`)return t[0];let r=j(e);return r?.startsWith(`z.`)?pe(r,t,n):n.fail(`This call isn't part of this file.`)}function ye(e,t,n,r){return typeof e==`string`?ge(e,t,n,r):(A(e)||n.fail(`This call isn't part of this file.`),ve(e,t,n))}function be(e){return/^(async\s*)?\(\s*\)\s*=>/.test(e.rest())}function xe(e,t,n){return e.peekIdent()===`async`&&e.expectIdent(),e.expect(`(`),e.eat(`)`)||e.fail(`A handler here takes no arguments. It returns a fixed value.`),e.expect(`=>`),I(e,t,n)}var N=class{name;constructor(e){this.name=e}};function P(e){return e instanceof N?e.name:e}function F(e,t,n){return be(e)?xe(e,t,n):Ce(Se(e,t,n),e,t,n)}function Se(e,t,n){e.skip();let r=e.peek();if(r===`'`||r===`"`)return O(e);if(r==="`"&&e.fail(`This file doesn't use template strings.`),r===`-`||/^[0-9]/.test(r))return ce(e);if(r===`{`)return de(e,t,n);if(r===`[`)return fe(e,t,n);if(r===`(`){e.bump();let r=F(e,t,n);return e.expect(`)`),r}let i=e.ident();return i===`true`?!0:i===`false`?!1:i===`null`?null:(i===void 0&&e.fail(`Expected a value.`),new N(i))}function I(e,t,n){e.skip();let r=e.pos(),i=F(e,t,n);if(!(i instanceof N))return i;if(i.name!==`undefined`)throw new E(`'${i.name}' is set somewhere else. Write its value here.`,r.line,r.column)}function Ce(e,t,n,r){let i=e;for(;;)if(t.eat(`.`)){let e=t.expectIdent();i=me(P(i),e)}else if(t.eat(`(`)){let e=r.length,a=[];for(;!t.eat(`)`);)a.push(P(F(t,n,r))),t.eat(`,`),t.done&&t.fail(`This call never closes.`);i=ye(P(i),a,t,r.slice(e))}else return A(i)&&t.fail(`This file doesn't stop on a property.`),i}function we(e,t){e.expectIdent();let n=e.expectIdent();e.expect(`=`);let r=F(e,``,t.spans);(e.eat(`satisfies`)||e.eat(`as`))&&le(e),e.eat(`;`),e.of===`provider`?e.fail(`A provider's code is its registerProvider() call and nothing else.`):n===`profile`?(D(r)||e.fail(`profile has to be the defineProfile() object.`),t.profile&&e.fail(`This file defines two profiles.`),t.profile=r):n===`questions`?(D(r)||e.fail(`questions has to be an object.`),t.questions=r):n===`images`&&(D(r)||e.fail(`images has to be an object.`),t.images=r)}function Te(e,t){let n=F(e,``,t.spans);if(e.eat(`;`),D(n)){if(n.kind===`provider`&&typeof n.definition==`string`&&D(n.spec))t.provider&&e.fail(`This code registers two providers.`),t.provider={definition:n.definition,spec:n.spec};else if(n.kind===`registerTool`){let r=n.tool;D(r)||e.fail(`registerTool() needs the tool object.`),t.tools.push(r)}else if(n.kind===`registerStructured`){let[r,i]=Array.isArray(n.args)?n.args:[];(typeof r!=`string`||!D(i))&&e.fail(`registerStructured() needs an id and a spec.`),t.structures.push({id:r,spec:i})}}}function L(e,t=`profile`){let n=new se(e,t),r={tools:[],structures:[],spans:[]};for(n.skip();!n.done;n.skip())n.peekIdent()===`import`?(n.expectIdent(),ue(n)):(n.peekIdent()===`export`&&n.expectIdent(),n.peekIdent()===`const`?we(n,r):Te(n,r));return t===`provider`?r.provider||n.fail(`This code needs registerProvider().`):r.profile||n.fail(`This file needs defineProfile().`),r}function R(e,t=``){return typeof e==`string`?e:t}function z(e){return typeof e==`number`?e:null}function B(e,t){if(e===void 0)return``;if(typeof e==`string`)return e;if(!Array.isArray(e))throw new E(t,1,1);return e.map(e=>{if(typeof e==`string`)return e;if(Array.isArray(e))return B(e,t);if(D(e)&&typeof e.private==`string`)return`{private: ${e.private}}`;throw new E(t,1,1)}).join(``)}function Ee(e,t){let n=`The system prompt has to be text.`,r=(Array.isArray(e)?e:[e]).map(t=>{if(Array.isArray(e)&&typeof t!=`string`&&!Array.isArray(t))throw new E(n,1,1);return B(t,n)});return(r.length?r:[``]).map((e,n)=>({key:t[n]?.key??y(`line`),text:e}))}function V(e){return e===void 0?``:JSON.stringify(e,null,2)}function De(e,t){return te(e)===te(t)}function H(e){return D(e)?JSON.stringify(e,null,2):JSON.stringify(e)}function Oe(e){return Array.isArray(e)?e.map(e=>{if(!D(e)||typeof e.name!=`string`)throw new E(`A pattern needs a name.`,1,1);return Array.isArray(e.words)?{name:e.name,kind:`words`,pattern:``,flags:``,words:e.words.filter(e=>typeof e==`string`)}:{name:e.name,kind:`pattern`,pattern:R(e.pattern),flags:R(e.flags),words:[]}}):[]}function U(e){return D(e)?e:void 0}function W(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function G(e){return Array.isArray(e)?W(e):void 0}function K(e){return R(e)||void 0}function q(e){return Array.isArray(e)?W(e).join(`
8
- `)||void 0:K(e)}function J(e,t,n){return D(e)?t(e):n}function ke(e,t,n){if(!D(n))return;if(Array.isArray(n.names)){e.innocentNames=W(n.names);return}if(!(t in e.allow))return;let r=e.allow[t];r.hosts=W(n.hosts),r.fromTools=n.fromTools!==!1}function Ae(e,t,n){let r=e.sources[t];r&&(n.theorem===!1&&(r.theorem=!1),r.patterns=Oe(n.patterns),r.hint=R(n.hint)),ke(e,t,n.allow)}function je(e,t){let n=f(p,()=>`ignore`);return D(t.at)&&Object.assign(n,t.at),{key:e,label:R(t.label),at:n,patterns:Oe(t.patterns),hint:R(t.hint)}}function Me(e){let t=x().guardrails;if(!D(e))return t;let n=l(e.detect),r={detect:f(d,e=>({...n[e]})),sources:structuredClone(t.sources),allow:structuredClone(t.allow),innocentNames:[...t.innocentNames]},i=[],a=new Set(d);for(let[t,n]of Object.entries(U(e.detect)??{}))D(n)&&(a.has(t)?Ae(r,t,n):i.push(je(t,n)));let o=U(e.quota),s=U(e.blockedReply),c=U(e.network),u=U(e.taint);return{...t,...r,own:i,quotaEnabled:o!==void 0,quotaPerDay:z(o?.perDay),blockedReplyOnBlock:R(s?.onBlock),blockedReplyMaxRetries:z(s?.maxRetries),allowPrivateNetworks:c?.allowPrivateNetworks===!0,allowedHosts:W(c?.allowedHosts),allowedSchemes:W(c?.allowedSchemes),taintAfterRemoteRead:R(u?.afterRemoteRead),taintRemoteDestination:R(u?.remoteDestination)}}var Ne={"continue.instruction":(e,t)=>{e.turnBehaviour.continueInstruction=t},"canary.bind_note":(e,t)=>{e.guardrails.canaryBindNote=t},"quota.exhausted":(e,t)=>{e.guardrails.quotaMessage=t},"repair.default_guidance":(e,t)=>{e.outputs.repairGuidance=t},"egress.default_repair_guidance":(e,t)=>{e.guardrails.egressRepairGuidance=t},"egress.refusal":(e,t)=>{e.guardrails.egressRefusal=t}};function Pe(e,t){if(!D(t))return;let n={};for(let[r,i]of Object.entries(t)){if(typeof i!=`string`)continue;let t=Ne[r];t?t(e,i):v[r]||(n[r]=i)}e.labels=n}function Fe(e){if(D(e))return Object.fromEntries(_.map(({name:t})=>[t,z(e[t])]))}function Ie(e,t,n,r,i){let a=n??g({modelId:e});if(!D(t))return{...a,modelId:e};let o=D(t.efforts)?Object.entries(t.efforts).map(([e,t])=>({alias:e,level:t})):[],s=D(t.compaction)?t.compaction:void 0,c=R(s?.profile),l=z(t.timeoutMs);return{...a,modelId:e,protocol:R(t.protocol,a.protocol),provider:R(t.provider,a.provider),apiId:R(t.apiId),options:U(t.options)??{},timeoutMs:l,limits:Fe(t.limits),efforts:o,defaultEffort:R(t.defaultEffort),allowEffortSelect:t.allowEffortSelect===!0,summaries:typeof t.summaries==`boolean`?t.summaries:null,maxOutputTokens:z(t.maxOutputTokens),temperature:typeof t.temperature==`number`?t.temperature:null,builtInTools:Array.isArray(t.builtInTools)?t.builtInTools.filter(e=>typeof e==`string`):[],keySlot:R(t.keySlot),fallbackKeySlot:R(t.fallbackKeySlot),compactTiming:R(s?.timing),compactMaxTokens:z(s?.maxTokens),compactAt:typeof s?.compactAt==`number`?s.compactAt:void 0,compactKeep:z(s?.previousExchanges),compactMeter:R(s?.meter),compactWith:c?Le(c,r,`models.${e}.compaction.profile`,i):``}}function Le(e,t,n,r){return t?t(e)??X(r,n,`'${e}' is not an agent here, so it can't write this model's summaries.`):``}function Re(e,t){let n=t.output;if(e===`function`&&D(t.handler)&&D(n)&&!De(t.handler,T(n)))return V(t.handler)}function ze(e){let t=U(e.mapping)??{};return{endpoint:K(e.endpoint),method:K(e.method),headersJson:D(e.headers)?V(e.headers):void 0,pathParams:G(t.pathParams),queryParams:G(t.queryParams),bodyParam:K(t.bodyParam),serverUrl:K(e.serverUrl),mcpToolName:K(e.mcpToolName),maxResponseBytes:z(e.maxResponseBytes),sessionIdleMs:z(U(e.session)?.idleMs),sessionMax:z(U(e.session)?.max)}}function Be(e){let t=U(e.auth)??{};return{authType:R(t.type),authSlot:K(t.slot),authService:K(t.service),authHeaderName:K(t.headerName),authHeaderPrefix:typeof t.headerPrefix==`string`?t.headerPrefix:void 0,authQueryParam:K(t.queryParam),authUnauthenticated:R(t.onUnauthenticated),authScopes:G(t.scopes),authClientId:K(t.clientId),authRedirectUri:K(t.redirectUri)}}function Ve(e,t,n){let r=t??b(),i=R(e.type,r.toolType),a=U(e.labels)??{},o=R(e.profile),s=e.answeredBy===`page`;return{...r,key:t?.key??y(`tool`),toolName:R(e.name,r.toolName),toolType:i,description:R(e.description),category:R(e.category,`studio`),access:R(e.access,r.access),permission:R(e.permission,r.permission),loadTier:R(e.loadTier,r.loadTier),paths:G(e.paths)??[`*`],inputJson:e.input===void 0?r.inputJson:H(e.input),outputJson:e.output===void 0?r.outputJson:H(e.output),activity:q(a.activity),activityPast:q(a.activityPast),activityFailed:q(a.activityFailed),request:q(a.request),stubOutputJson:s?t?.stubOutputJson:Re(i,e),answeredBy:s?`page`:void 0,after:e.after===!0||void 0,...ze(e),agentKey:o?n?.(o):void 0,maxCallsPerTurn:z(e.maxCallsPerTurn),...Be(e)}}function He(e,t){let n=new Map(t.map(e=>[e.id,e]));return Object.entries(e).map(([e,t])=>{let r=n.get(e),i=D(t)?t:{},a=R(i.type,`choice`),o=i.criteria,s=Array.isArray(o)?o.map((e,t)=>({key:r?.criteria[t]?.key??y(`criterion`),label:``,text:R(e)})):D(o)?Object.entries(o).map(([e,t],n)=>({key:r?.criteria[n]?.key??y(`criterion`),label:e,text:R(t)})):[];return{key:r?.key??y(`question`),id:e,type:a,instructions:R(i.instructions),criteria:s,...a===`box`&&R(i.image)?{image:R(i.image)}:{}}})}function Ue(e){if(!Array.isArray(e))return[];let t=[];for(let n of e)if(D(n)){if(typeof n.uri==`string`){let e=R(n.name);t.push({key:y(`reference`),uri:n.uri,...e?{name:e}:{}})}else typeof n.data==`string`&&t.push({key:y(`reference`),name:R(n.name),mimeType:R(n.mimeType),data:n.data})}return t}function We(e,t){return e?h.filter(n=>!n.optional||n.role===`branch`||!n.profileTypes.includes(e)?!1:n.profilePath in t).map(e=>e.id):x().included}function Ge(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=Ve(o,t.get(R(o.name)),n);if(e.toolName&&a.has(e.toolName)){let t=r.filter(e=>e.path===`name`)[i.length]??{line:1,column:1};throw new E(`'${e.toolName}' is registered twice.`,t.line,t.column)}e.toolName&&a.add(e.toolName),i.push(e)}return i}function Ke(e,t,n){if(t===void 0)return[];let r=n.findLast(e=>e.path===`tools.allow`)??{line:1,column:1};if(!Array.isArray(t))throw new E(`tools.allow has to be a list of tool names.`,r.line,r.column);let i=new Map(e.map(e=>[e.toolName,e])),a=[],o=new Set;for(let[e,s]of t.entries()){let t=n.find(t=>t.path===`tools.allow.${String(e)}`)??r;if(typeof s!=`string`||s.trim()===``)throw new E(`tools.allow names tools.`,t.line,t.column);if(o.has(s))throw new E(`'${s}' is listed twice in tools.allow.`,t.line,t.column);o.add(s);let c=i.get(s);if(!c)throw new E(`'${s}' is in tools.allow, and this file has no registerTool for it.`,t.line,t.column);a.push(c)}return a}function qe(e,t,n){let r=U(t.identity)??{};return{...e,agentId:R(t.id),profileType:n,handle:R(r.handle),system:Ee(r.system,e.system),conditionsJson:D(r.conditions)?V(r.conditions):``}}function Je(e){return{...D(e.providerContinuation)&&(e.providerContinuation.history===`provider`||e.providerContinuation.history===`stateless`)?{providerHistory:e.providerContinuation.history}:{},defaultModel:R(e.defaultModel),allowModelSelect:e.allowModelSelect===!0,maxSteps:z(e.maxSteps),key:R(e.key),fallbackKey:R(e.fallbackKey)}}function Ye(e){return m.includes(e)}function Xe(e){return Object.fromEntries(Object.entries(U(e)??{}).filter(e=>typeof e[1]==`number`))}function Ze(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(U(e)??{}).map(([e,t])=>{let r=n.get(e),i=U(t),a=(Array.isArray(t)?t:Array.isArray(i?.choices)?i.choices:[]).map((e,t)=>{let n=U(e);return{key:r?.choices[t]?.key??y(`choice`),value:R(n?n.value:e),description:R(n?.description)}});return{key:r?.key??y(`slot`),name:e,label:R(i?.label),choices:a}})}function Qe(e,t){let n=U(e.context);return{text:e.text!==!1,attachmentsAccept:W(U(e.attachments)?.accept),voiceAccept:W(U(e.voice)?.accept),maxFiles:z(e.maxFiles),maxBytes:z(e.maxBytes),maxTurnBytes:z(e.maxTurnBytes),limitsByMime:Xe(e.limitsByMime),slots:Ze(e.slots,t.slots),contextFrom:W(n?.from).filter(Ye),contextMaxChars:z(n?.maxChars)}}function $e(e){return Object.fromEntries(Object.entries(e??{}).map(([e,t])=>[e,U(t)?.onFail===`fix`?`fix`:`drop`]))}function et(e,t){let n=U(e?.structured),r=n?t.find(({id:e})=>e===R(n.fallback)):t[0],i=r?.id??R(e?.structured),a=Object.entries(U(n?.map)??{}).map(([e,n])=>({choice:e,schemaId:R(n),schemaJson:V(t.find(e=>e.id===n)?.spec.jsonSchema)})),o=U(e?.streaming),s=U(e?.validation);return{mode:i?`structured`:`text`,schemaId:i,schemaJson:V(r?.spec.jsonSchema),...n?{bySlot:{slot:R(n.by),shapes:a}}:{},streamMode:R(o?.mode),streamThoughts:o?.streamThoughts!==!1,validationEnabled:s!==void 0,maxRetries:z(s?.maxRetries),itemRules:$e(U(s?.items)),repairGuidance:``}}function tt(e){let t=U(e.resumption),n=Array.isArray(t?.allowContinue)?t.allowContinue:[...a],r=Array.isArray(t?.autoContinue)?t.autoContinue:[...o];return{resumeEnabled:n.length>0||r.length>0,allowContinue:n,autoContinue:r,maxContinues:z(t?.maxContinues),continueInstruction:``,allowSteering:e.allowSteering!==!1,atStepLimit:e.atStepLimit===`answer`?`answer`:`stop`}}function nt(e){let t=x().observability,n=typeof e.writeTo==`string`&&e.writeTo?e.writeTo:t.destination;return{...t,writeTo:e.writeTo!==!1&&n,destination:n,sampleRate:typeof e.sampleRate==`number`?e.sampleRate:t.sampleRate,include:{...t.include,...U(e.include)},scrub:{...t.scrub,...U(e.scrub)},retainForDays:z(e.retainForDays),rotateAfterMiB:z(e.rotateAfterMiB),resourceJson:V(e.resource)}}function rt(e){return{aspectRatio:R(e.aspectRatio),resolution:R(e.resolution),mimeType:R(e.mimeType),quality:R(e.quality),background:R(e.background),n:z(e.n),seed:z(e.seed),outputCompression:z(e.outputCompression),includeText:e.includeText===!0,references:Ue(e.references)}}function it(e){return{voice:R(e.voice),style:R(e.style),speed:z(e.speed),format:R(e.format)}}function Y(e,t){let n=e[t];return typeof n==`boolean`?n:S(t)}function at(e){let t=U(e.ingress)??{},n=U(e.vad)??{},r=U(e.contextCompression),i=U(r?.slidingWindow),a=U(e.transcription);return{ingressAudio:Y(t,`audio`),ingressVideo:Y(t,`video`),ingressText:Y(t,`text`),voice:R(e.voice),sessionResumption:e.sessionResumption===!0,greeting:R(e.greeting),resumedPrompt:R(U(e.resumed)?.prompt),resumedAfterMs:z(U(e.resumed)?.afterMs),contextCompression:r!==void 0,compressionTriggerTokens:z(r?.triggerTokens),compressionTargetTokens:z(i?.targetTokens),transcriptionInput:a?.input===!0,transcriptionOutput:a?.output===!0,vadActivityHandling:R(n.activityHandling),vadStartSensitivity:R(n.startSensitivity),vadEndSensitivity:R(n.endSensitivity),vadPrefixPaddingMs:z(n.prefixPaddingMs),vadSilenceDurationMs:z(n.silenceDurationMs)}}function ot(e,t,n){let r=z(U(t.profile?.inputs)?.maxStateBytes);return{contract:R(e.contract),maxStateBytes:r,questions:t.questions?He(t.questions,n.questions):[],images:t.images?st(t.images,n.images):[]}}function st(e,t){let n=new Map(t.map(e=>[e.name,e]));return Object.entries(e).map(([e,t])=>{let r=e.replace(/^<|>$/g,``),i=D(t)?t:{};return{key:n.get(r)?.key??y(`image`),name:r,mimeType:R(i.mimeType),data:R(i.data)}})}function ct(e){let t=R(e.type);if(t&&!ee.includes(t))throw new E(`'${t}' is not a profile type.`,1,1);return t}var lt=[`turnBehaviour.atStepLimit`,`outputs.validation.items.*.onFail`];function ut(e,t){for(let n of lt){let r=u(n)?.options??[];for(let[i,a]of dt(e,n.split(`.`),[]))a!==void 0&&!r.includes(a)&&X(t,i,`${JSON.stringify(a)} is not one of ${r.map(e=>`'${e}'`).join(`, `)}.`)}}function dt(e,t,n){let[r,...i]=t;return r===void 0?[[n.join(`.`),e]]:D(e)?(r===`*`?Object.keys(e):[r]).flatMap(t=>dt(e[t],i,[...n,t])):[]}function ft(e,t,n){let r=e.profile??{},i=ct(r);ut(r,e.spans);let a=new Map(t.modelBindings.map(e=>[e.modelId,e])),o=new Map(t.toolSpecs.map(e=>[e.toolName,e])),s=U(r.tools)??{},c=U(r.inputs),l=U(r.outputs),u={...t,identity:qe(t.identity,r,i),included:We(i,r),models:Je(r),modelBindings:Object.entries(U(r.models)??{}).map(([t,r])=>Ie(t,r,a.get(t),n,e.spans)),tools:{t2Loader:R(s.t2Loader),parallel:s.parallel===!0},toolSpecs:[],inputs:c&&i!==`decision`?Qe(c,t.inputs):t.inputs,outputs:l||e.structures.length?et(l,e.structures):t.outputs,turnBehaviour:J(r.turnBehaviour,tt,t.turnBehaviour),guardrails:J(r.guardrails,Me,t.guardrails),observability:J(r.observability,nt,t.observability),image:J(r.image,rt,t.image),speech:J(r.speech,it,t.speech),live:J(r.live,at,t.live),decision:J(r.decision,n=>ot(n,e,t.decision),t.decision),labels:{}},d=Ge(e.tools,o,n,e.spans),f=Ke(d,s.allow,e.spans);u.toolSpecs=f;let p=new Set(f.map(e=>e.toolName));return u.tools.t2Loader&&!p.has(u.tools.t2Loader)&&(u.tools={...u.tools,t2Loader:``}),Pe(u,r.labels),{draft:u,registered:d}}function pt(e,t,n){try{let r=L(e),{draft:i,registered:a}=ft(r,t,n);return{ok:!0,draft:i,spans:r.spans,registered:a}}catch(e){if(e instanceof E)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}function X(e,t,n){let r=e.findLast(e=>e.path===t)??{line:1,column:1};throw new E(n,r.line,r.column)}var mt=new Set([`id`,`connection`,`keySlot`,`fallbackKeySlot`]);function ht(e,t,n){let{spec:r}=e;for(let e of Object.keys(r))mt.has(e)||X(n,e,`'${e}' isn't a provider setting the studio holds.`);r.id!==t.id&&X(n,`id`,`The id stays '${t.id}': models and code name the provider by it.`);let a=i(e.definition);if(!a){let t=c().flatMap(e=>s(e)??[]).join(`, `);X(n,``,`'${e.definition}' isn't one of the kernel's providers: ${t}.`)}let o=r.connection===void 0?{}:gt(r.connection,n),l=Object.keys(o).length===0&&t.connection===void 0,u={id:t.id,definition:a,...l?{}:{connection:o}};for(let e of[`keySlot`,`fallbackKeySlot`]){let t=r[e];t!==void 0&&(typeof t!=`string`&&X(n,e,`${e} names a key slot.`),u[e]=t)}return u}function gt(e,t){let n=`connection holds text settings here.`,r={};D(e)||X(t,`connection`,n);for(let[i,a]of Object.entries(e))typeof a!=`string`&&X(t,`connection`,n),r[i]=a;return r}function _t(e,t){try{let n=L(e,`provider`);if(!n.provider)throw new E(`This code needs registerProvider().`,1,1);return{ok:!0,provider:ht(n.provider,t,n.spans),spans:n.spans}}catch(e){if(e instanceof E)return{ok:!1,errors:[{message:e.message,line:e.line,column:e.column}]};throw e}}var Z=e(n(),1),Q=t(),vt=300,yt=2e3;function bt({editor:e,monaco:t,spans:n,errors:r},i){let a=e?.getModel();t&&a&&t.editor.setModelMarkers(a,`studio`,[...r.map(e=>$(t,e.line,e.column,e.message)),...St(t,n,i)])}function xt({text:e,hold:t,isReadOnly:n=!1,issues:i,onApply:a}){let o=(0,Z.useRef)(null),s=(0,Z.useRef)(a),c=(0,Z.useRef)(e),l=(0,Z.useRef)(n);l.current=n;let u=(0,Z.useRef)(i),d=(0,Z.useRef)({spans:[],errors:[],setting:!1,dirty:!1});return s.current=a,c.current=e,u.current=i,(0,Z.useEffect)(()=>{let e=o.current;if(!e)return;let t={disposed:!1},n,i,a=0,f,p=!1,m=!1,h=()=>{a+=1,i&&clearTimeout(i),i=void 0,f?.stop(),f=void 0,p=!1,m=!1},g=t=>e.contains(t)?!0:t instanceof Element&&!!t.closest(`.suggest-widget, .parameter-hints-widget, .monaco-hover, .monaco-menu-container, .context-view`),ee=()=>!!document.querySelector(`.suggest-widget.visible, .parameter-hints-widget.visible`),_,v=()=>{bt(d.current,u.current)};return(async()=>{let o=await r(()=>import(`./studio-monaco-xfyfezQS.js`),__vite__mapDeps([0,1,2,3,4]));await r(()=>import(`./register-CDgivxvX.js`),__vite__mapDeps([5,2,1,3]));let u=(await r(async()=>{let{default:e}=await import(`./editor.worker-6GY8RhDc.js`);return{default:e}},[])).default;if(self.MonacoEnvironment={getWorker(){return new u}},t.disposed||!e.isConnected)return;let y=document.documentElement.dataset.theme===`dark`||globalThis.matchMedia(`(prefers-color-scheme: dark)`).matches,b=o.Uri.parse(`file:///agent.ts`);o.editor.getModel(b)?.dispose();let x=o.editor.createModel(c.current,`typescript`,b),S=o.editor.create(e,{model:x,readOnly:l.current,language:`typescript`,theme:y?`vs-dark`:`vs`,minimap:{enabled:!1},fontSize:13,wordWrap:`on`,wrappingIndent:`indent`,scrollBeyondLastLine:!1,automaticLayout:!0,fixedOverflowWidgets:!0,tabSize:2,padding:{top:12},quickSuggestions:{other:!0,comments:!1,strings:!0},suggestOnTriggerCharacters:!0,acceptSuggestionOnEnter:`on`,tabCompletion:`on`,wordBasedSuggestions:`currentDocument`,parameterHints:{enabled:!0},suggest:{preview:!0,showIcons:!0}});d.current.editor=S,d.current.monaco=o;let C=()=>{i&&clearTimeout(i),i=setTimeout(()=>{t.disposed||(ee()?C():h())},yt)},w=()=>{if(f){m&&C();return}if(p)return;let e=a,n=()=>t.disposed||e!==a;p=!0,r(async()=>{let{openTypeChecker:e}=await import(`./studio-type-checker-CVNPnko-.js`);return{openTypeChecker:e}},__vite__mapDeps([6,2])).then(({openTypeChecker:r})=>{if(n())return;let i=r(o,S,()=>{t.disposed||e!==a||(m=!0,C())});n()?i.stop():f=i}).catch(()=>{}).finally(()=>{e===a&&(p=!1)})};S.onKeyDown(e=>{let t=e.browserEvent;t.metaKey||t.ctrlKey||t.altKey||m&&C()});let T=e=>{let t=e.target;t instanceof Node&&!g(t)&&h()};document.addEventListener(`pointerdown`,T,!0),_=()=>{document.removeEventListener(`pointerdown`,T,!0)},S.onDidBlurEditorText(()=>{queueMicrotask(()=>{if(t.disposed||S.hasTextFocus())return;let e=document.activeElement;e&&g(e)||h()})}),S.onDidChangeModelContent(()=>{if(d.current.setting)return;w();let e=S.getValue();d.current.dirty=e!==c.current,n&&clearTimeout(n),n=setTimeout(()=>{let t=s.current(e);d.current.spans=t.spans,d.current.errors=t.errors,v()},vt)}),v()})(),()=>{t.disposed=!0,_?.(),h(),n&&clearTimeout(n);let e=d.current.editor?.getModel();d.current.editor?.dispose(),e?.dispose(),d.current.editor=void 0}},[]),(0,Z.useEffect)(()=>{let{editor:n}=d.current;n&&!t&&(d.current.dirty&&n.getValue()!==e||(n.getValue()===e||(d.current.setting=!0,n.setValue(e),d.current.setting=!1),d.current.dirty=!1))},[e,t]),(0,Z.useEffect)(()=>{d.current.editor?.updateOptions({readOnly:n})},[n]),(0,Z.useEffect)(()=>{bt(d.current,i)},[i]),(0,Q.jsx)(`div`,{ref:o,className:`studio-fill`})}function $(e,t,n,r){return{startLineNumber:t,startColumn:n,endLineNumber:t,endColumn:n+1,message:r,severity:e.MarkerSeverity.Error}}function St(e,t,n){return n.flatMap(n=>{let r=n.field?`${n.nodeId}.${n.field}`:n.nodeId,i=t.find(e=>e.path===r)??(n.field?t.find(e=>e.path===n.field):void 0);return i?[$(e,i.line,i.column,n.message)]:[]})}function Ct({source:e,blocked:t,issues:n,state:r}){let i=(0,Z.useRef)(e);e&&(i.current=e);let a=(0,Z.useCallback)(e=>{let t=ie(r.workspace,r.focus);if(!t)return{errors:[{message:`No agent is open.`,line:1,column:1}],spans:[]};let n=pt(e,{...t,toolSpecs:r.workspace.toolSpecs},e=>r.workspace.agents.find(t=>t.identity.agentId.trim()===e)?.key);return n.ok?(r.update(e=>re(e,r.focus,n.draft,n.registered)),{errors:[],spans:n.spans}):{errors:n.errors,spans:[]}},[r]);return i.current?(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(xt,{text:e??i.current,hold:e==null,issues:n,onApply:a})}):(0,Q.jsx)(oe,{title:`No code yet`,description:`${t??``} to generate the TypeScript.`})}function wt({provider:e,issues:t,state:n,isEditable:r}){let i=(0,Z.useCallback)(t=>{let r=n.workspace.providers.find(t=>t.id===e.id);if(!r)return{errors:[{message:`No provider is open.`,line:1,column:1}],spans:[]};let i=_t(t,r);return i.ok?(n.update(e=>ne(e,i.provider)),{errors:[],spans:i.spans}):{errors:i.errors,spans:[]}},[n,e.id]);return(0,Q.jsx)(`div`,{className:`studio-fill`,children:(0,Q.jsx)(xt,{text:ae(e),hold:!1,isReadOnly:!r||s(e.definition)===void 0,issues:t,onApply:i},e.id)})}export{Ct as CodeBody,wt as ProviderCode};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ToolResultCharts-C3CPsfXl.js","assets/rolldown-runtime-hePW80VL.js","assets/themeProps-3IqahpCr.js","assets/VStack-CkVMcNiK.js","assets/padding.stylex-B76907Zf.js","assets/mergeProps-ptS-gIMz.js","assets/StackItem-CQviqAfM.js","assets/Text-BOqCfzZC.js","assets/sharedResizeObserver-4U9Xq5Oq.js","assets/preload-helper-DpV6A1kQ.js","assets/Card-DruykyeB.js","assets/Icon-BqkS-pIq.js","assets/tokens.stylex-DkHf0P9C.js","assets/devWarning-DxuplmRl.js","assets/useMediaQuery-BCT0NUeZ.js","assets/container.stylex-BmOi-8DQ.js","assets/shaped-data-CJQ3W_RE.js","assets/host-patterns-F-KZIzkF.js","assets/TraceOverview-CSdJ_cYY.js","assets/useTooltip-c097gL_-.js","assets/useLayerDismissal-BAnTRYTt.js","assets/labels-provider-t4c-5JMk.js","assets/IconButton-DVUFx-8p.js","assets/focusOutline.stylex-BT0kfa4t.js","assets/useAnnounce-DTSHZvjg.js","assets/CodeBlock-CfVOtDeO.js","assets/useClipboard-CbN9bb4J.js","assets/useScrollableArea-DuF_pz9m.js","assets/focusableSelector-DXZeMU85.js","assets/Tooltip-BWs5DLrM.js","assets/row-keys-WByP9Hsh.js","assets/createReactComponent-CZwsv6DD.js","assets/trace-record-DoXjxrmJ.js","assets/index-B7sK7d-l.js","assets/SegmentedControlItem-CZs-ycSA.js","assets/fieldParts-CoOpDoax.js","assets/useResolvedRequired-DbsOcDqy.js","assets/useDevWarning-Z9SoixOP.js","assets/isRtlElement-BG33-k_H.js","assets/plainDate-BHiJcj7o.js","assets/browser-transport-GzhRiBdm.js","assets/SidePanel-DEd3R1Q3.js","assets/ScrollableArea-ChTx-OVZ.js","assets/IconAlertTriangle-BqAEqqdU.js","assets/Banner-DrRNC3MG.js","assets/isRenderable-DHkzpAoQ.js","assets/tool-schema-BDG2_rlP.js","assets/schemas-D7cgkv3L.js","assets/tree-CcEbNvms.js","assets/live-ingress-OuSlQ6q7.js","assets/browser-connection-dads1eyK.js","assets/use-second-ticker-CWjCHLG6.js","assets/use-second-ticker-GWBt83pd.css","assets/Center-CgO0c-qo.js","assets/IconSearch-BTx66a40.js","assets/reader-DHN96tSr.js","assets/trace-schema--4IGmLeE.js","assets/stub-U6wDGe3P.js","assets/focusReturn-CTppP2k0.js","assets/CheckboxInput-CFZ_Wq8-.js","assets/useScrollLock-Dyf6PHJt.js","assets/Dialog-Sd04KQS2.js","assets/chainEventHandlers-C6ttXGfW.js","assets/HoverCard-DMyWUvwP.js","assets/IconEye-BB5aY-wQ.js","assets/studio-labels-jYWBoEyP.js","assets/turn-client-BmOSpCgw.js","assets/encode-files-CHeRLBO8.js","assets/CollapsibleGroup-BsIYDnJR.js","assets/crypto-B8dqEoWf.js","assets/workspace-DUfaxr-g.js","assets/lent-keys-C32ems-I.js","assets/editors-BJX_S59A.js","assets/project-address-DjxPZuyn.js","assets/studio-session-CPnJaHc-.js","assets/EmptyState-C_uF9Wyj.js","assets/useMenuPress-DLG1QOiE.js","assets/useAdaptivePresentation-Bma4-u1a.js","assets/useFocusReturnVisibility-BHKv5Jwr.js","assets/ListItem-QF7KFt0h.js","assets/index-C9rhrCGT.css","assets/trace-patterns-D6TbkLLr.js"])))=>i.map(i=>d[i]);
2
- import{n as e,r as t}from"./rolldown-runtime-hePW80VL.js";import{c as n,l as r,n as i,u as a}from"./themeProps-3IqahpCr.js";import{t as o}from"./VStack-CkVMcNiK.js";import{n as s}from"./StackItem-CQviqAfM.js";import{S as c,b as l,f as u,i as d,s as f}from"./browser-transport-GzhRiBdm.js";import{t as p}from"./mergeProps-ptS-gIMz.js";import{u as m}from"./fieldParts-CoOpDoax.js";import{t as h}from"./isRenderable-DHkzpAoQ.js";import{t as g}from"./Text-BOqCfzZC.js";import{t as ee}from"./preload-helper-DpV6A1kQ.js";import{i as te,l as ne,n as _,t as re}from"./labels-provider-t4c-5JMk.js";import{n as v}from"./Card-DruykyeB.js";import{t as ie}from"./Tooltip-BWs5DLrM.js";import{a as ae,t as y}from"./Banner-DrRNC3MG.js";import{t as oe}from"./row-keys-WByP9Hsh.js";import{_ as se,f as ce,g as le,m as ue,n as de,r as fe,t as pe,v as me}from"./studio-labels-jYWBoEyP.js";import{l as he,u as ge}from"./tool-schema-BDG2_rlP.js";import{_ as _e,a as b,b as x,c as S,f as ve,h as C,l as w,n as T,o as ye,r as be,t as xe,v as Se,x as Ce,y as E}from"./shaped-data-CJQ3W_RE.js";import{S as D,i as O,u as k}from"./turn-client-BmOSpCgw.js";import{t as A}from"./use-second-ticker-CWjCHLG6.js";import{t as we}from"./EmptyState-C_uF9Wyj.js";import{n as Te,t as Ee}from"./ListItem-QF7KFt0h.js";import{a as De,i as Oe,o as ke,r as Ae,t as je}from"./ConsoleFrame-BvgFGqp2.js";import{i as Me}from"./trace-patterns-D6TbkLLr.js";import{n as Ne,t as Pe}from"./studio-console-B7zL133d.js";import{t as Fe}from"./SchemaFields-BNNkvyyO.js";import{At as Ie,D as j,E as Le,I as Re,It as ze,K as Be,O as Ve,U as He,V as Ue,W as We,Y as Ge,_ as Ke,b as M,q as qe,y as Je}from"./index-B7sK7d-l.js";var Ye=4,Xe=3,Ze=3,N=8,Qe=6,P=3,$e=3,et=/(^|_)(id|ids|lat|lon|lng|latitude|longitude|offset|interval|index|rank|order)$|Id$|^(generationtime_ms|utc_offset_seconds)$/i,tt=/\.(png|jpe?g|gif|webp|avif|svg)$/i;function nt(e){if(/\s/.test(e))return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&tt.test(t.pathname)}catch{return!1}}function F(e){return!et.test(e)}function I(e){return/^[A-Z][A-Z0-9]{1,5}$/.test(e)?e:b(e)}function L(e,t){if(!F(e)||t&&e in t&&ve(t[e])===void 0)return;let{label:n,unit:r}=be(e,t);return{label:I(e)===e?e:n,unit:r}}function R(e,t){let n=[];for(let[r,i]of C(e)){if(typeof i!=`number`||!Number.isFinite(i))continue;let e=L(r,t);e&&n.push({key:r,value:i,...e})}return n.sort((e,t)=>Number(t.unit!==void 0)-Number(e.unit!==void 0)).slice(0,Ye)}function rt(e){if(!S(e))return[];for(let[t,n]of C(e)){let r=x(n);if(!S(r)||T(r))continue;let i=Object.values(r);if(i.length===0||!i.every(ye))continue;let a=R(r,E(e,t));if(a.length>0)return a}return R(e,void 0)}function z(e,t){return new Set(e.map(e=>e[t])).size}function B(e,t,n){return[...new Set(e.flatMap(e=>Object.keys(e)))].filter(n=>n!==t&&e.every(e=>typeof e[n]==`number`||e[n]===null)&&z(e,n)>1).flatMap(e=>{let t=L(e,n);return t?[{key:e,...t}]:[]})}function it(e){let[t]=e;if(t)return Object.keys(t).find(t=>e.every(e=>typeof e[t]==`string`&&xe.test(e[t])))}function at(e){let t=e.map(e=>e.label.split(` `)),[n=[]]=t,r=0;for(;r<n.length&&t.every(e=>e.length>r+1&&e[r]===n[r]);)r++;if(r)return{title:n.slice(0,r).join(` `),series:e.map((e,n)=>{let i=(t[n]??[]).slice(r).join(` `);return{...e,label:i.charAt(0).toUpperCase()+i.slice(1)}})}}function ot(e,t,n,r,i){let a=new Map;for(let e of B(n,r,i)){let t=a.get(e.unit??``)??[];t.push(e),a.set(e.unit??``,t)}return[...a.values()].map(i=>{let a=i.slice(0,Ze),o=a.length>1?at(a):void 0;return{kind:`time`,key:`${e}:${a.map(e=>e.key).join(`+`)}`,title:a.length===1?a[0]?.label??t:o?.title??(t||a.map(e=>e.label).join(` · `)),x:r,series:o?.series??a,rows:n}})}function st(e){let[t]=e,n=t?Se(t):void 0;if(!t||!n||!e.every(e=>typeof e[n]==`string`||typeof e[n]==`number`))return;if(z(e,n)===e.length)return n;let r=t=>e.reduce((e,n)=>e+String(n[t]).length,0),[i]=Object.keys(t).filter(t=>e.every(e=>typeof e[t]==`string`)&&z(e,t)===e.length).sort((e,t)=>r(e)-r(t));return i??n}function ct(e,t,n,r){let i=st(n);return i?B(n,i,r).sort((e,t)=>z(n,t.key)-z(n,e.key)).map(r=>({kind:`category`,key:`${e}:${r.key}`,title:t?`${t} · ${r.label}`:r.label,series:r,rows:n.filter(e=>typeof e[r.key]==`number`).map(e=>({label:String(e[i]),value:e[r.key]})).sort((e,t)=>t.value-e.value).slice(0,N)})):[]}function V(e,t,n,r){if(n.length<P)return[];let i=it(n);return i?ot(e,t,n,i,r):ct(e,t,n,r)}function H(e,t,n,r,i){if(i>$e)return[];if(Array.isArray(e)){let i=e.map(x);return i.every(S)?V(t,n,i,r):[]}if(!S(e))return[];let a=T(e);if(a)return V(t,n,_e(e,a),r);let o=C(e),s=o.filter(([e,t])=>typeof t==`number`&&F(e));if(i>0&&s.length>=P&&s.length===o.length){let e=s.map(([e,t])=>({label:I(e),value:t}));return[{kind:`category`,key:t,title:n,series:{key:`value`,label:n},rows:e.sort((e,t)=>t.value-e.value).slice(0,N)}]}return o.flatMap(([r,a])=>H(x(a),t?`${t}.${r}`:r,i===0?b(r):`${n} › ${b(r)}`,E(e,r),i+1))}function U(e,t,n,r){if(r.size>=Qe||n>4)return;let i=x(e);if(typeof i==`string`)nt(i)&&!r.has(i)&&r.set(i,{src:i,alt:b(t||`image`)});else if(Array.isArray(i))for(let e of i)U(e,t,n+1,r);else if(S(i))for(let[e,t]of Object.entries(i))U(t,e,n+1,r)}function lt(e){let t=x(e),n=new Map;return U(t,``,0,n),{figures:rt(t),charts:H(t,``,``,void 0,0).slice(0,Xe),images:[...n.values()]}}function ut(e){return e.mimeType&&e.data?`data:${e.mimeType};base64,${e.data}`:void 0}function dt(e,t,n){let r=t.flatMap(e=>{let t=ut(e);return t?[{type:e.type,src:t,mimeType:e.mimeType}]:[]});return{images:[...r.filter(e=>e.type===`image`).map(({src:e})=>({src:e,alt:n})),...e.images],audio:r.filter(e=>e.type===`audio`).map(({src:e,mimeType:t})=>({src:e,...t?{mimeType:t}:{}}))}}function ft(e,t){return e.figures.length+e.charts.length+t.images.length+t.audio.length>0}var pt=864e5,mt=10;function ht(e){return e.some(e=>e.includes(`T`))?{tick:Math.abs(Date.parse(e.at(-1)??``)-Date.parse(e[0]??``))<=pt?{hour:`numeric`}:{month:`short`,day:`numeric`},when:{dateStyle:`medium`,timeStyle:`short`}}:{tick:e.length<=mt?{weekday:`short`,timeZone:`UTC`}:{month:`short`,day:`numeric`,timeZone:`UTC`},when:{dateStyle:`medium`,timeZone:`UTC`}}}var W=n(),G={base:{k1xSpc:`x3nfvp2`,kGNEyG:`x6s0dn4`,kjj79g:`xl56j7k`,kaIpWk:`x16rqkct`,kmuXW:`x2lah0s`,kzqmXN:`x1xc55vz`,kZKoxP:`xdk7pt`,$$css:!0},pulsing:{kKVMdj:`x1mta51n`,k44tkh:`x1c74tu6`,kyAemX:`x4hg4is`,ko0y90:`xa4qsjk`,$$css:!0},reducedMotion:{kjO2d4:`x1aquc0h`,$$css:!0}},gt={success:{kWkggS:`xdsz4j9`,kMwMTN:`xri61p4`,$$css:!0},warning:{kWkggS:`x1q8g9m5`,kMwMTN:`xrebv38`,$$css:!0},error:{kWkggS:`x1pjz0fi`,kMwMTN:`x1m024r3`,$$css:!0},accent:{kWkggS:`x1ewilqj`,kMwMTN:`x17wrial`,$$css:!0},neutral:{kWkggS:`x1q5y3ey`,kMwMTN:`xrkvqaz`,$$css:!0}};function K({variant:e,label:t,isPulsing:n=!1,tooltip:a,icon:o,xstyle:s,className:c,style:l,ref:u,...d}){let f=h(o),m=(0,W.jsx)(`span`,{ref:u,role:`img`,"aria-label":t,...p(i(`status-dot`,{variant:e}),r(G.base,gt[e],n&&G.pulsing,n&&G.reducedMotion,s),c,l),...d,children:f&&(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`x78zum5 x6s0dn4 xl56j7k x14ju556 x1xc55vz xdk7pt`,children:o})});return a?(0,W.jsx)(ie,{content:a,children:m}):m}K.displayName=`StatusDot`;var _t=new Set([`gate`,`complete`,`error`,`cancel`]);function vt({call:e,failure:t,isRunning:n}){let r=e?.state?.phase;return r!==void 0&&_t.has(r)?r:t?`error`:n?`running`:`cancel`}function q({call:e,failure:t}){if(t)return{title:t.error};let n=e?.state;if(n?.phase!==`error`)return null;let{error:r,message:i}=n.failure;return r?r===i?{title:r}:{title:r,description:i}:{title:i}}function yt(e){let t=e.tools.find(t=>t.name===e.picked)??e.tools[0],n=t?e.drafts[t.name]??w(ge(t.inputSchema)):``,r=e.calls.filter(e=>e.name===t?.name),i=r.find(t=>t.id===e.shownId)??r[0]??null;return{tool:t,text:n,shown:i,earlier:e.calls.filter(e=>e!==i)}}var J=t(a(),1);function bt(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`call-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function xt(e,t){let n=[...e.events,t],r=t.type===`tool`&&t.tool.phase===`progress`?t.tool.data:e.progress;return{...e,events:n,call:D(n)[0]??null,progress:r}}function St(e,t){let n=(0,J.useMemo)(()=>me(e,t),[e,t]),{iface:r,describeFailure:i}=Ke(n),[a,o]=(0,J.useState)([]),s=(0,J.useRef)(new Map),l=(0,J.useRef)([]),u=(0,J.useRef)(a);u.current=a,(0,J.useEffect)(()=>{let e=s.current;return()=>{for(let t of e.values())t.abort()}},[]);let d=(0,J.useCallback)((e,t)=>{o(n=>n.map(n=>n.id===e?t(n):n))},[]),f=(0,J.useCallback)(async(e,t)=>{let n=new AbortController;s.current.set(e,n);let r=performance.now();d(e,e=>({...e,isRunning:!0,failure:null}));try{await t(t=>{t.type!==`unsupported`&&t.type!==`malformed`&&d(e,e=>xt(e,t))},n.signal),d(e,e=>({...e,isRunning:!1,answering:null,elapsedMs:performance.now()-r}))}catch(t){let i=n.signal.aborted?null:c(t);d(e,e=>({...e,isRunning:!1,answering:null,failure:i,elapsedMs:performance.now()-r}))}finally{s.current.get(e)===n&&s.current.delete(e)}},[d]);return{iface:r,describeFailure:i,calls:a,run:(0,J.useCallback)((e,t)=>{let r=bt();return o(n=>[{id:r,name:e,input:t,events:[],call:null,progress:void 0,isRunning:!0,failure:null,answering:null,startedAt:Date.now(),elapsedMs:null},...n]),f(r,(r,i)=>n.call({name:e,input:t},r,i)),r},[f,n]),answer:(0,J.useCallback)(async(e,t)=>{let r=u.current.find(t=>t.id===e),i=r?.call?.state;if(!r?.call||i?.phase!==`gate`)return;let a=r.call.callId,o=O(r.call),s=se({toolName:r.name,gate:i.gate,sessionPermissions:l.current,resolution:t});s.decision===`approve`&&(l.current=s.sessionPermissions);let c=k(r.events);d(e,e=>({...e,answering:t.action})),await f(e,(e,t)=>n.invoke({gateId:a,operationId:o,decision:s.decision,...s.decision===`approve`&&s.secret!==void 0?{secret:s.secret}:{},replay:{name:r.name,input:i.gate.preparedArguments??r.input,gateKind:i.gate.kind,sessionPermissions:l.current,...c?{snapshot:c}:{}}},e,t))},[f,n,d]),cancel:(0,J.useCallback)(e=>{s.current.get(e)?.abort(),s.current.delete(e)},[])}}function Ct(e){return(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,"aria-hidden":!0,...e,children:(0,W.jsx)(`path`,{d:`M13.85 0a4.16 4.16 0 0 0-2.95 1.217L1.456 10.66a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l9.442-9.442a2.49 2.49 0 0 1 3.541 0 2.49 2.49 0 0 1 0 3.541L8.59 12.97l-.1.1a.835.835 0 0 0 0 1.18.835.835 0 0 0 1.18 0l.1-.098 7.03-7.034a2.49 2.49 0 0 1 3.542 0l.049.05a2.49 2.49 0 0 1 0 3.54l-8.54 8.54a1.96 1.96 0 0 0 0 2.755l1.753 1.753a.835.835 0 0 0 1.18 0 .835.835 0 0 0 0-1.18l-1.753-1.753a.266.266 0 0 1 0-.394l8.54-8.54a4.185 4.185 0 0 0 0-5.9l-.05-.05a4.16 4.16 0 0 0-2.95-1.218c-.2 0-.401.02-.6.048a4.17 4.17 0 0 0-1.17-3.552A4.16 4.16 0 0 0 13.85 0m0 3.333a.84.84 0 0 0-.59.245L6.275 10.56a4.186 4.186 0 0 0 0 5.902 4.186 4.186 0 0 0 5.902 0L19.16 9.48a.835.835 0 0 0 0-1.18.835.835 0 0 0-1.18 0l-6.985 6.984a2.49 2.49 0 0 1-3.54 0 2.49 2.49 0 0 1 0-3.54l6.983-6.985a.835.835 0 0 0 0-1.18.84.84 0 0 0-.59-.245`})})}var wt=(0,J.lazy)(()=>ee(()=>import(`./ToolResultCharts-C3CPsfXl.js`).then(e=>({default:e.ToolResultChart})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81]))),Tt=236,Et=260;function Dt({layout:e,parts:t=[]}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.NumberFormat(r,{maximumFractionDigits:2}),[r]),a=(0,J.useMemo)(()=>dt(e,t,n(`@theorem.host.image`)),[e,t,n]),[s,c]=(0,J.useState)(null);if(!ft(e,a))return null;let{images:l,audio:u}=a;return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsxs)(Ne,{minWidth:Et,children:[e.figures.map(e=>(0,W.jsx)(j,{children:(0,W.jsx)(Me,{title:e.label,value:Ce(i.format(e.value),e.unit)})},`figure:${e.key}`)),e.charts.map(e=>(0,W.jsx)(J.Suspense,{fallback:(0,W.jsx)(j,{children:(0,W.jsx)(Be,{height:Tt})}),children:(0,W.jsx)(j,{children:(0,W.jsx)(wt,{chart:e})})},`chart:${e.key}`)),l.map((e,t)=>(0,W.jsx)(j,{children:(0,W.jsx)(We,{label:e.alt||`Open image`,padding:0,onClick:()=>c(t),children:(0,W.jsx)(ue,{ratio:4/3,fit:`cover`,children:(0,W.jsx)(`img`,{src:e.src,alt:e.alt,loading:`lazy`})})})},`image:${e.src}`))]}),l.length>0?(0,W.jsx)(Ue,{isOpen:s!==null,onOpenChange:e=>{e||c(null)},media:l.map(e=>({src:e.src,alt:e.alt})),index:s??0,onIndexChange:c}):null,oe(u,e=>e.src).map(({item:e,key:t})=>(0,W.jsx)(j,{children:(0,W.jsx)(He,{src:e.src,mimeType:e.mimeType})},t))]})}function Ot({output:e,parts:t}){let n=_(),r=(0,J.useMemo)(()=>lt(e),[e]),i=(0,J.useMemo)(()=>r.figures.map(e=>e.key),[r]);return(0,W.jsx)(Le,{value:e,title:n(`@theorem.host.response`),lead:(0,W.jsx)(Dt,{layout:r,parts:t}),ledKeys:i})}var kt=8,At={running:`accent`,gate:`warning`,complete:`success`,error:`error`,cancel:`neutral`};function jt(e,t,n){let r;try{r=JSON.parse(n)}catch{return{ok:!1,note:e(`@theorem.decision.invalid_json`)}}if(!S(r))return{ok:!1,note:e(`@theorem.decision.invalid_json`)};let i=he(t.inputSchema,r);return i.length>0?{ok:!1,note:e(`@theorem.host.missing`,{fields:i.join(`, `)}),input:r}:{ok:!0,input:r}}var Mt={function:ze,http:Ie,mcp:Ct},Nt=440,Pt=2;function Ft(e,t){let n=e(`@theorem.host.kind.${t.kind}`);return t.description?`${n} · ${t.description}`:n}function It({tool:e}){let t=_();return e.access===`read-only`?null:(0,W.jsx)(s,{gap:1,wrap:`wrap`,children:(0,W.jsx)(m,{label:t(`@theorem.tool.access.${e.access}`),size:`sm`,color:e.access===`destructive`?`red`:`orange`})})}function Lt(e,t,n){return{label:t.call?ce(t.call):t.name,duration:t.isRunning?te(e,n-t.startedAt):t.elapsedMs==null?null:ne(e,t.elapsedMs)}}function Y({call:e,onAnswer:t}){let n=e.call?.state;return n?.phase===`gate`?n.gate.kind===`auth`?(0,W.jsx)(fe,{gate:n.gate,toolName:e.name,submitted:e.answering===`auth`,onAuthenticated:n=>void t(e.id,{action:`auth`,secret:n})}):(0,W.jsx)(de,{gate:n.gate,toolName:e.name,input:e.input,decided:e.answering===`auth`?null:e.answering,onDecision:n=>void t(e.id,{action:n})}):null}function X(e){let t=e.call?.state;return!!q(e)||t?.phase===`complete`||!e.isRunning}function Z(e){let t=e.call?.state;return!X(e)&&t?.phase!==`gate`}function Rt({call:e,activity:t}){let n=e.call?.state,r=q(e);return(0,W.jsx)(Ve,{children:(0,W.jsxs)(o,{gap:3,children:[r?(0,W.jsx)(j,{children:(0,W.jsx)(y,{status:`error`,role:`alert`,title:r.title,description:r.description})}):null,n?.phase===`complete`?(0,W.jsx)(Ot,{output:n.output,parts:n.parts}):null,e.isRunning?null:(0,W.jsx)(j,{children:t})]})})}function zt({call:e,onAnswer:t}){let n=_(),{label:r,duration:i}=Lt(n,e,A(e.isRunning));if(Z(e))return(0,W.jsx)(M,{label:r,since:e.startedAt});let a=(0,W.jsx)(g,{size:`sm`,color:`secondary`,children:i?n(`@theorem.host.finished`,{activity:r,duration:i}):r});return(0,W.jsxs)(o,{gap:3,children:[(0,W.jsx)(Y,{call:e,onAnswer:t}),X(e)?(0,W.jsx)(Rt,{call:e,activity:a}):null]})}function Bt({calls:e,onPick:t}){let n=_(),r=v(),i=(0,J.useMemo)(()=>new Intl.DateTimeFormat(r,{timeStyle:`medium`}),[r]);return e.length===0?null:(0,W.jsxs)(o,{gap:1,children:[(0,W.jsx)(g,{type:`supporting`,color:`secondary`,as:`h3`,children:n(`@theorem.host.earlier`)}),(0,W.jsx)(Te,{hasDividers:!0,density:`compact`,children:e.slice(0,kt).map(e=>{let r=vt(e);return(0,W.jsx)(Ee,{label:e.name,startContent:(0,W.jsx)(K,{variant:At[r],label:n(`@theorem.host.status.${r}`),isPulsing:e.isRunning}),endContent:(0,W.jsx)(g,{type:`supporting`,color:`secondary`,hasTabularNumbers:!0,children:i.format(e.startedAt)}),onClick:()=>t(e)},e.id)})})]})}function Vt({tools:e,tool:t,check:n,text:r,view:i,shown:a,onText:s,onPick:c,onView:l,onRun:u,onStop:d}){let f=_(),p=`input`in n?n.input:void 0,m=i===`fields`&&p!==void 0;return(0,W.jsxs)(Oe,{title:f(`@theorem.host.request`),view:m?`fields`:`json`,hasFields:p!==void 0,onView:l,onRun:u,children:[(0,W.jsxs)(o,{gap:2,children:[(0,W.jsx)(qe,{label:f(`@theorem.host.tool`),size:`sm`,options:e.map(e=>({value:e.name,label:e.name,icon:Mt[e.kind],description:Ft(f,e)})),value:t.name,hasSearch:e.length>8,renderOption:e=>(0,W.jsx)(`div`,{style:{width:Nt,maxWidth:`100%`,minWidth:0},children:(0,W.jsx)(Ge,{icon:e.icon,label:e.label,description:e.description&&(0,W.jsx)(g,{type:`supporting`,color:`secondary`,maxLines:Pt,children:e.description})})}),onChange:c}),(0,W.jsx)(It,{tool:t})]}),m?(0,W.jsx)(Fe,{schema:t.inputSchema,value:p,onChange:e=>{s(w(e))}},t.name):(0,W.jsx)(Ae,{label:f(`@theorem.host.request`),text:r,isInvalid:p===void 0,onChange:s}),(0,W.jsx)(ke,{note:n.ok?f(`@theorem.host.shortcut`):n.note,isReady:n.ok,isRunning:a?.isRunning===!0,runLabel:f(`@theorem.host.run`),runningLabel:f(`@theorem.host.running`),stopLabel:f(`@theorem.host.stop`),onRun:u,onStop:()=>{a&&d(a.id)}})]})}function Ht(e,t,n,r){return!t||!n?.ok||r?.isRunning?null:e.run(t.name,n.input)}function Ut(e,t){let n=_(),[r,i]=(0,J.useState)(e.tools[0]?.name),[a,o]=(0,J.useState)({}),[s,c]=(0,J.useState)(null),[l,u]=(0,J.useState)(`fields`),{tool:d,text:f,shown:p,earlier:m}=yt({tools:e.tools,picked:r,drafts:a,calls:t.calls,shownId:s}),h=d?jt(n,d,f):null;return{tool:d,text:f,shown:p,earlier:m,check:h,view:l,setView:u,setPicked:i,setText:e=>{d&&o(t=>({...t,[d.name]:e}))},run:()=>{let e=Ht(t,d,h,p);e!==null&&c(e)},pick:e=>{i(e.name),o(t=>({...t,[e.name]:w(e.input)})),c(e.id)}}}function Wt({shown:e,earlier:t,onAnswer:n,onPick:r}){return(0,W.jsxs)(W.Fragment,{children:[e?(0,W.jsx)(zt,{call:e,onAnswer:n}):null,(0,W.jsx)(Bt,{calls:t,onPick:r})]})}function Gt(e,t,n,r,i){if(!e)return i;let a=r.length===0;return!n&&a?null:(0,W.jsx)(De,{label:t,fill:n!=null&&Z(n)&&a,children:i})}function Kt({transport:e,iface:t,host:n,maxWidth:r=`960px`,trace:i,flush:a,columns:o=!1,className:s,style:c}){let l=_(),u=ae(t,e.traces,i),d=Ut(t,n),{tool:f,check:p,shown:m,earlier:h}=d;return(0,W.jsxs)(je,{inspector:u,maxWidth:r,flush:a,columns:o,requestLabel:l(`@theorem.host.request`),className:s,style:c,children:[f&&p?(0,W.jsx)(Vt,{tools:t.tools,tool:f,check:p,text:d.text,view:d.view,shown:m,onText:d.setText,onPick:d.setPicked,onView:d.setView,onRun:d.run,onStop:n.cancel}):(0,W.jsx)(we,{title:l(`@theorem.host.no_tools`)}),Gt(o,l(`@theorem.host.response`),m,h,(0,W.jsx)(Wt,{shown:m,earlier:h,onAnswer:n.answer,onPick:d.pick}))]})}function qt(e){let t=_(),n=St(e.transport,e.pageTools);return n.describeFailure?(0,W.jsx)(Je,{title:n.describeFailure.error}):n.iface?(0,W.jsx)(Kt,{...e,iface:n.iface,host:n}):(0,W.jsx)(M,{label:t(`@theorem.chat.loading`)})}function Jt({endpoint:e,http:t,transport:n,theme:r,mode:i,labels:a,detectCodeLanguage:o,...s}){let c=(0,J.useRef)(t);c.current=t;let u=(0,J.useMemo)(()=>n??l({...c.current,endpoint:e}),[n,e]);return(0,W.jsx)(f,{theme:r,mode:i,children:(0,W.jsx)(re,{labels:a,children:(0,W.jsx)(Re,{detectCodeLanguage:o,children:(0,W.jsx)(qt,{...s,transport:u})})})})}var Yt=e({HostView:()=>$,StudioHostConsole:()=>Q});function Q(e){let t=Pe(e,u,d);return(0,W.jsx)($,{...e,transport:t})}function $({payload:e,transport:t,trace:n,flush:r,columns:i,className:a}){let o=(0,J.useMemo)(()=>le(e),[e]);return(0,W.jsx)(Jt,{detectCodeLanguage:!0,labels:pe,transport:t,pageTools:o,trace:n,flush:r,columns:i,className:a})}export{$ as HostView,Q as StudioHostConsole,ht as n,Yt as t};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{E as n,O as r,d as i,x as a}from"./schemas-D7cgkv3L.js";import{r as o}from"./editors-BJX_S59A.js";var s=`x-theorem-studio-acting-as`,c=`acting-as`,l=`theorem-studio-local`,u=a({id:n().min(1),label:n().min(1)}),d=a({place:n().min(1),person:u});a({places:i(u).min(1),existing:r().optional(),fresh:r().optional(),start:d.optional()});function f(e){return encodeURIComponent(JSON.stringify(e))}function p(e){return e?{[s]:f(e)}:{}}function m(e){return e?`${l}:${encodeURIComponent(e.place)}:${encodeURIComponent(e.person.id)}`:l}function h(e,t){let n=d.safeParse(e);if(!n.success)return{ok:!1,message:`The person this run acts as could not be read.`};let r=g(n.data.place,t);return r.ok?{ok:!0,actingAs:n.data}:r}function g(e,t){return typeof e!=`string`||e===``?{ok:!1,message:`The setup file needs a place to look in.`}:t.some(t=>t.id===e)?{ok:!0,place:e}:{ok:!1,message:`The setup file offers no place '${e}'.`}}function _(e,t){let n=u.safeParse(e);if(!n.success)throw Error(`The setup file's ${t} answered a person without an id and a label.`);return n.data}var v=e(t(),1),y={editor:``,watch:`on`,filesToast:`on`,askShared:`always`,askWrites:`always`},b={editor:`theorem.studio.editor`,watch:`theorem.studio.watch`,filesToast:`theorem.studio.files-toast`,askShared:`theorem.studio.ask-shared`,askWrites:`theorem.studio.ask-writes`},x={editor:o,watch:e=>e===`off`,filesToast:e=>e===`off`,askShared:e=>e===`never`,askWrites:e=>e===`destructive`};function ee(e,t){try{let n=e?.getItem(b[t]);if(typeof n==`string`&&x[t](n))return n}catch{}return y[t]}function te(e,t,n){try{n===y[t]||!x[t](n)?e?.removeItem(b[t]):e?.setItem(b[t],n)}catch{}}function S(){try{return typeof localStorage>`u`?null:localStorage}catch{return null}}var C=new Set;function w(e){return ee(S(),e)}function T(e,t){te(S(),e,t);for(let e of C)e()}function E(e){return C.add(e),globalThis.addEventListener?.(`storage`,e),()=>{C.delete(e),globalThis.removeEventListener?.(`storage`,e)}}function D(e){return(0,v.useSyncExternalStore)(E,()=>w(e),()=>y[e])}function O(e){return e===`destructive`||w(`askWrites`)===`always`}var k=6e4;function A(e,t,n,r){let i={seen:[],back:[],clear:[]};for(let a of new Set([...e,...t.keys()])){let e=t.get(a);n.has(a)?e!==void 0&&i.back.push(a):e===void 0?i.seen.push(a):r-e>=6e4&&i.clear.push(a)}return i}function j(){let e=new Map,t=new Map,n=new Map,r=t=>{let n=e.get(t)??new Map;return e.set(t,n),n};return{claim(t,i){if(n.delete(t),i!==void 0)for(let[n,a]of e.get(i)??[])r(t).set(n,a);return Promise.resolve([...r(t)])},put(e,t,n){r(e).set(t,n)},remove(t,n){e.get(t)?.delete(n)},handOff(e,n,r){t.set(e,{opener:n,value:r})},takeRun(e,n,i){let a=t.get(e);return a?(t.delete(e),r(n).set(i,a.value),Promise.resolve(a.value)):Promise.resolve(void 0)},sweep(r,i){let a=[...t.values()].map(e=>e.opener),o=A([...e.keys(),...a],n,r,i);for(let e of o.seen)n.set(e,i);for(let e of o.back)n.delete(e);for(let r of o.clear){e.delete(r),n.delete(r);for(let[e,n]of t)n.opener===r&&t.delete(e)}return Promise.resolve()}}}var M=`theorem.studio`,N=`tabs`,P=`runs`,F=`gone`;function I(e){return new Promise((t,n)=>{e.onsuccess=()=>{t(e.result)},e.onerror=()=>{n(e.error??Error(`IndexedDB refused the request.`))}})}function L(e){return new Promise((t,n)=>{e.oncomplete=()=>{t()},e.onerror=e.onabort=()=>{n(e.error??Error(`IndexedDB did not keep the change.`))}})}var R=e=>IDBKeyRange.bound([e],[e,[]]);async function ne(){let e=indexedDB.open(M,1);e.onupgradeneeded=()=>{let t=e.result;t.createObjectStore(N),t.createObjectStore(P),t.createObjectStore(F)};let t=await I(e),n=(e,n,r)=>{let i=t.transaction(e,`readwrite`);n(i),L(i).catch(()=>r?.())},r=(e,t)=>{n([N],n=>n.objectStore(N).delete([e,t]))};return{async claim(e,n){let r=t.transaction([N,F],`readwrite`),i=L(r),a=r.objectStore(N);if(r.objectStore(F).delete(e),n!==void 0){let[t,r]=await Promise.all([I(a.getAllKeys(R(n))),I(a.getAll(R(n)))]);t.forEach((t,n)=>{a.put(r[n],[e,t[1]])})}let[o,s]=await Promise.all([I(a.getAllKeys(R(e))),I(a.getAll(R(e)))]);return await i,o.map((e,t)=>[e[1],String(s[t])])},put(e,t,i){n([N],n=>n.objectStore(N).put(i,[e,t]),()=>{r(e,t)})},remove(e,t){r(e,t)},handOff(e,t,r){n([P],n=>n.objectStore(P).put({opener:t,value:r},e))},async takeRun(e,n,r){let i=t.transaction([P,N],`readwrite`),a=L(i),o=await I(i.objectStore(P).get(e));return o&&(i.objectStore(P).delete(e),i.objectStore(N).put(o.value,[n,r])),await a,o?.value},async sweep(e,n){let r=t.transaction([N,P,F],`readwrite`),i=L(r),a=r.objectStore(N),o=r.objectStore(P),s=r.objectStore(F),[c,l,u,d,f]=await Promise.all([I(a.getAllKeys()),I(o.getAllKeys()),I(o.getAll()),I(s.getAllKeys()),I(s.getAll())]),p=u.map(e=>e.opener),m=new Map(d.map((e,t)=>[String(e),Number(f[t])])),h=A([...c.map(e=>e[0]),...p],m,e,n);for(let e of h.seen)s.put(n,e);for(let e of h.back)s.delete(e);let g=new Set(h.clear);for(let e of g)a.delete(R(e)),s.delete(e);p.forEach((e,t)=>{let n=l[t];g.has(e)&&n!==void 0&&o.delete(n)}),await i}}}var z=`theorem.studio.v2`,B=e=>`${z}.project:${e}`,V=`theorem.studio.v2.chat:`,H=`theorem.studio.tab`,U=`theorem.studio.tab:`,W=`theorem.studio.leaving`,G=`theorem.studio.sweep`,K,q;function J(){return K?.storage??null}function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(){try{return typeof sessionStorage>`u`?null:sessionStorage}catch{return null}}function Z(e){try{e?X()?.setItem(W,JSON.stringify(e)):X()?.removeItem(W)}catch{}}function re(){try{let e=X()?.getItem(W);return e?JSON.parse(e):void 0}catch{return}}function Q(e,t){return new Promise(n=>{e.request(t,{ifAvailable:!0},e=>(n(e!==null),e?new Promise(()=>{}):void 0))})}async function ie(e,t){let n=X(),r=null;try{r=n?.getItem(H)??null}catch{}if(r&&(!e||await Q(e,`${U}${r}`)))return{id:r};let i=crypto.randomUUID();e&&await Q(e,`${U}${i}`);try{n?.setItem(H,i)}catch{}return r&&t?{id:i,from:r}:{id:i}}async function ae(e,t){await t.request(G,async()=>{let{held:n=[]}=await t.query(),r=new Set(n.flatMap(e=>e.name?.startsWith(U)?[e.name.slice(19)]:[]));await e.sweep(r,Date.now())})}async function oe(){let e=typeof navigator>`u`?void 0:navigator.locks;if(!e||typeof indexedDB>`u`)return{keep:j()};try{return{keep:await ne(),locks:e}}catch{return{keep:j()}}}async function se(e={}){let{keep:t,locks:n}=e.keep?{keep:e.keep,locks:e.locks}:await oe(),r=async()=>{let{id:r,from:i}=await ie(n,e.copy??!0);return{id:r,kept:await t.claim(r,i)}},{id:i,kept:a}=n?await n.request(G,r):await r(),o=new Map(a),s=(e,n)=>{o.set(e,n),t.put(i,e,n)},c=re();c&&s(c.name,c.value),Z();let l={getItem:e=>o.get(e)??null,setItem:(e,t)=>{s(e,t),Z()},setItemLeaving:(e,t)=>{s(e,t),Z({name:e,value:t})},removeItem:e=>{o.delete(e)&&t.remove(i,e)},keys:()=>[...o.keys()]};if(K={id:i,keep:t,records:o,storage:l},q=Promise.resolve(l),n){let e=()=>{ae(t,n).catch(()=>{})};e(),setInterval(e,k)}return l}function $(e){return q??=se(e),q}function ce(e,t){K?.keep.handOff(e,K.id,t)}var le=`theorem.studio.run:`;async function ue(e){if(await $({copy:!1}),!K)return;let t=`${le}${e}`,n=K.records.get(t);if(n!==void 0)return n;let r=await K.keep.takeRun(e,K.id,t);return r!==void 0&&K.records.set(t,r),r}export{m as _,B as a,$ as c,T as d,D as f,p as g,f as h,Y as i,ue as l,c as m,z as n,J as o,O as p,ce as r,X as s,V as t,w as u,_ as v,h as y};
@@ -1,3 +0,0 @@
1
- import{C as e,Cn as t,M as n,Wt as r,Xt as i,h as a,j as o,n as s,p as c,t as l,vn as ee,y as te,z as u}from"./tool-schema-BDG2_rlP.js";import{An as d,Cn as ne,Hn as re,Nn as f,Pn as ie,Sn as ae,Wn as oe,an as se,br as p,gr as m,pn as h,yn as g}from"./shaped-data-CJQ3W_RE.js";import{a as _,r as v}from"./live-ingress-OuSlQ6q7.js";var ce=[{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`}],le={identity:d,inputs:f(`inputs`).filter(e=>e!==`decision`)},y=ce.map(e=>({...e,profileTypes:le[e.id]??f(e.profilePath)}));function ue(e){return y.find(t=>t.id===e)}function de(e){return e.modelBindings.length>1}function fe(e){return e.modelBindings.some(t=>t.provider!==`local`&&!n(e.providers,t).keySlot)}function b(e,t){let r={provider:t.provider,keySlot:t.keySlot||e.models.key,fallbackKeySlot:t.fallbackKeySlot||e.models.fallbackKey},i=n(e.providers,r);return{...i,given:{keySlot:!!i.keySlot&&!r.keySlot,fallbackKeySlot:!!i.fallbackKeySlot&&!r.fallbackKeySlot}}}function pe(e,t){let n=new Set(e.modelBindings.filter(n=>{let r=b(e,n);return r.keySlot===t||r.fallbackKeySlot===t}).map(e=>e.provider));return e.providers.filter(e=>n.has(e.id))}function me(e){let t=e.efforts.map(({alias:e})=>e.trim()).filter(Boolean);return new Set(t).size>1}function he(e){return e.attachmentsAccept.length>0||e.voiceAccept.length>0}var ge=h,_e=[{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:g[0],permission:ne[0],loadTier:ae[0],paths:[`*`],inputJson:l,outputJson:s,...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=t(void 0);return{canaryBindNote:``,detect:p(ie,t=>({...e.detect[t]})),sources:Object.fromEntries(re.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=_({});return{writeTo:c,destination:c,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.`),ve=`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
- `),ye=`How do I delete every screenshot on my desktop?`;function be(e,t=`choice`){let n=q(`question`,e.decision.questions.map(e=>e.id),e=>`question_${e}`);return{key:w(`question`),id:n,type:t,instructions:``,criteria:B(t)}}function xe(e,t,n){let r=t.replace(/\.[^.]*$/,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_|_$/g,``)||`image`,i=q(r,e.decision.images.map(e=>e.name),e=>`${r}_${e}`);return{key:w(`image`),name:i,...n}}function Se(e){let t=q(`slot`,e.map(e=>e.name),e=>`slot_${String(e)}`);return{key:w(`slot`),name:t,label:``,choices:[R(),R()]}}function L(e=``){return{key:w(`line`),text:e}}function R(){return{key:w(`choice`),value:``,description:``}}function z(){return{key:w(`criterion`),label:``,text:``}}function B(e){return e===`noul`||e===`box`?[]:N(e===`choice`?[[`yes`,``],[`no`,``]]:[[``,``],[``,``]])}function Ce(){return{identity:{agentId:``,profileType:``,handle:``,system:[L()],conditionsJson:``},included:[`observability`,`labels`],models:{defaultModel:``,allowModelSelect:!1,maxSteps:null,key:``},modelBindings:[],providers:[...e],tools:{t2Loader:``,parallel:!1},toolSpecs:[],inputs:{text:!0,attachmentsAccept:[],voiceAccept:[],maxFiles:null,maxBytes:null,maxTurnBytes:null,limitsByMime:{},slots:[],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:i({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:v(`audio`),ingressVideo:v(`video`),ingressText:v(`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 we=new Set([`guardrails`]);function V(e,t){return e.profileTypes.includes(t)&&!(t===`decision`&&we.has(e.id))}function H(e){let t=e.identity.profileType;if(!t)return[`identity`];let n=new Set(e.included);return y.filter(e=>e.role!==`branch`&&V(e,t)&&(!e.optional||n.has(e.id))).map(e=>e.id)}function U(e,t){let n=e.identity.profileType;return n!==``&&f(t).includes(n)}function Te(e){return U(e,`identity.system`)&&oe(e.guardrails.detect,`canary_leak`)}function Ee(e){let t=e.identity.profileType;return t!==``&&r.includes(t)}function W(e){let t=e.identity.profileType;return t?y.filter(n=>n.role===`spine`&&n.optional&&V(n,t)&&!e.included.includes(n.id)).map(e=>e.id):[]}function De(e){return{...e,attachmentsAccept:e.attachmentsAccept.filter(e=>ee(se,e)),voiceAccept:[]}}function Oe(e){return{...e,text:!1,attachmentsAccept:[],voiceAccept:e.voiceAccept.length?e.voiceAccept:[`audio/*`]}}function ke(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 G(e,t){if(t.some(t=>t.modelId===e))return e;let[n,...r]=t;return n&&!r.length?n.modelId:``}function Ae(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:G(e.models.defaultModel,n)},modelBindings:n}}function K(e,t){let n=e.identity.profileType,r=n&&n!==`host`?n:`text`,i=e.modelBindings.map(e=>e.modelId),a=te(r,t),o=q(a.modelId,i,e=>`${a.modelId}${e}`);return T({...a,modelId:o})}function je(e){return D({toolName:q(`my_tool`,e.toolSpecs.map(e=>e.toolName),e=>`my_tool_${e}`)})}function q(e,t,n){let r=new Set(t),i=e;for(let e=2;r.has(i);e++)i=n(e);return i}function Me(e,t,n){if(t===`host`)return{...e,identity:{...e.identity,profileType:t}};let r=e.modelBindings.filter(r=>{let i=o(e.providers,t,r),a=e.providers.find(e=>e.id===r.provider);return u(a,t,r.protocol)&&!Fe(n,t,i)}),i={...e,identity:{...e.identity,profileType:t},modelBindings:r},s=r.length?r:[K(i,n?.start)],c=!e.models.key&&fe({...i,modelBindings:s}),l=t===`speech`&&!e.speech.voice.trim()&&s.some(n=>a(o(e.providers,t,n)));return{...i,inputs:t===`image`?De(e.inputs):t===`transcription`?Oe(e.inputs):e.inputs,...l?{speech:{...e.speech,voice:Ne}}:{},models:{...e.models,defaultModel:G(e.models.defaultModel,s),key:c?Ie:e.models.key},modelBindings:s}}var Ne=`Kore`,Pe=[`text`,`image`,`speech`,`transcription`,`live`,`decision`];function Fe(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)&&Pe.some(e=>e!==t&&r(e))}var Ie=`slot_a`;function Le(e,t){return W(e).includes(t)?{...e,included:[...e.included,t]}:e}function Re(e,t){return{...e,included:e.included.filter(e=>e!==t)}}function J(e){return`modelBinding:${e}`}var Y=`toolSpec:`;function X(e){return`${Y}${e}`}function Z(e){return e.startsWith(Y)?e.slice(9):void 0}var Q=`provider:`;function ze(e){return`${Q}${e}`}function Be(e){return e.startsWith(Q)?e.slice(9):void 0}var Ve=new Map(y.map(e=>[e.id,e.label]));function He(e){return Ve.get(e)??e}function Ue(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=Z(t);if(i!==void 0)return e.toolSpecs.some(e=>e.key===i)?{facet:`toolSpec`,key:i}:void 0;let a=H(e);if(r===void 0&&a.includes(t))return{facet:t}}function We(e,t){return t===`models`?e.modelBindings.map(e=>({id:J(e.key),ref:{facet:`modelBinding`,key:e.key},label:e.modelId.trim()||`Unnamed model`,children:[]})):t===`tools`?$(e.toolSpecs):[]}function $(e){return e.map(e=>({id:X(e.key),ref:{facet:`toolSpec`,key:e.key},label:e.toolName.trim()||`Unnamed tool`,children:[]}))}function Ge(e){let t=H(e).filter(e=>e!==`identity`).map(t=>({id:t,ref:{facet:t},label:He(t),children:We(e,t)}));return{id:`identity`,ref:{facet:`identity`},label:e.identity.agentId.trim()||`Unnamed agent`,children:t}}export{z as A,Te as B,H as C,W as D,q as E,k as F,b as G,Me as H,Se as I,he as J,me as K,R as L,be as M,K as N,Le as O,A as P,L as R,U as S,Re as T,Ee as U,Ae as V,ke as W,y as X,pe as Y,ue as Z,x as _,Ge as a,T as b,$ as c,ye as d,ve as f,ge as g,_e as h,Ue as i,xe as j,B as k,S as l,C as m,Be as n,Z as o,I as p,de as q,ze as r,X as s,J as t,F as u,O as v,w,D as x,Ce as y,je as z};
@@ -1,2 +0,0 @@
1
- import{Ht as e,Kn as t,Vn as n}from"./tool-schema-BDG2_rlP.js";import{c as r}from"./host-patterns-F-KZIzkF.js";import{Lr as i,M as a,Vn as o}from"./shaped-data-CJQ3W_RE.js";import{I as s}from"./reader-DHN96tSr.js";import{M as c}from"./browser-connection-dads1eyK.js";import{r as l}from"./encode-files-CHeRLBO8.js";function ee(e,t){let n=typeof t==`string`?t.trim():``;if(!n)throw new r(`request`,`A typed credential must be a non-empty string`);if(e===`bearer`)return{type:`bearer`,token:n};if(e===`api_key`)return{type:`api_key`,key:n};throw new r(`request`,`A '${e}' sign-in takes no typed credential; the host's callback saves it`)}function te(e,t){if(!e)throw new r(`request`,`a typed credential answers only a sign-in gate`);return{slot:e.slot,credential:ee(e.authType,t)}}function ne(e,t){if(t!==void 0){if(!Number.isFinite(t)||t<=0)throw new r(`config`,`${e} gateTtlMs must be a positive number of milliseconds; got ${t}.`);return t}}function re(e,t,n){return n!==void 0&&t-e>=n}var u=[`approve`,`deny`,`abandon`];function d(e,t=!1){return e.decision===`approve`?{granted:!0,...e.edited?{edited:e.edited}:{},...t?{signIn:t}:{}}:{granted:!1,cause:e.decision===`deny`?`declined`:`abandoned`,...t?{signIn:t}:{}}}function f(e,t,n){return n!==`session_consent`||e.includes(t)?[...e]:[...e,t]}function p(e,t,n){let{callId:i,decision:a,input:o,secret:s,page:c}=e;if((o!==void 0||s!==void 0||c!==void 0)&&a!==`approve`)throw new r(`request`,`only an approval takes edited input, a secret, or a page answer (call ${i})`);if(a!==`approve`)return{resume:d({decision:a},t.auth!==void 0),input:t.arguments,sessionPermissions:[...n]};let l=s===void 0?void 0:te(t.auth,s);return{resume:{...d(o===void 0?{decision:a}:{decision:a,edited:{from:t.arguments}},t.auth!==void 0),...t.gateKind?{gateKind:t.gateKind}:{}},input:o??t.arguments,sessionPermissions:f(n,t.name,t.permission),...l?{typed:l}:{},...c?{page:c}:{}}}var m={'"':`"`,"\\":`\\`,"/":`/`,b:`\b`,f:`\f`,n:`
2
- `,r:`\r`,t:` `};function h(e,t){let n=``,r=t+1;for(;r<e.length;){let t=e.charAt(r);if(t===`"`)return{text:n,end:r+1};if(t!==`\\`){n+=t,r++;continue}if(r+1>=e.length)break;let i=e.charAt(r+1);if(i===`u`){let t=e.slice(r+2,r+6);if(t.length<4)break;if(/^[0-9a-fA-F]{4}$/.test(t)){n+=String.fromCharCode(Number.parseInt(t,16)),r+=6;continue}}n+=m[i]??i,r+=2}return{text:n}}function g(e,t){let n=t;for(;/\s/.test(e.charAt(n));)n++;return n}function ie(e,t){if(e.charAt(t)===`"`){let n=h(e,t);return n.end===void 0?void 0:_(e,t,n.end)}let n=0;for(let r=t;r<e.length;r++){let i=e.charAt(r);if(i===`"`){let t=h(e,r).end;if(t===void 0)return;r=t-1}else if(i===`{`||i===`[`)n++;else if(i===`}`||i===`]`){if(n===0)return _(e,t,r);if(n--,n===0)return _(e,t,r+1)}else if(i===`,`&&n===0)return _(e,t,r)}}function _(e,t,n){try{return{value:JSON.parse(e.slice(t,n)),end:n}}catch{return}}function v(e){let t={},n=g(e,0);if(e.charAt(n)!==`{`)return t;for(n++;;){if(n=g(e,n),e.charAt(n)===`,`&&(n=g(e,n+1)),e.charAt(n)!==`"`)return t;let r=h(e,n);if(r.end===void 0||(n=g(e,r.end),e.charAt(n)!==`:`)||(n=g(e,n+1),n>=e.length))return t;let i=ie(e,n);if(!i)return e.charAt(n)===`"`&&(t[r.text]=h(e,n).text),t;t[r.text]=i.value,n=i.end}}function y(e,t){if(t.phase===void 0)return{name:t.name,callId:t.callId,...t.operationId?{operationId:t.operationId}:{},arguments:t.arguments,...t.reasoning?{reasoning:t.reasoning}:{},...t.stepId?{stepId:t.stepId}:{},artifacts:[]};if(e===void 0)throw new r(`bad_response`,`Tool event '${t.phase}' for call '${t.callId}' arrived before the call.`);if(e.callId!==t.callId||e.name!==t.name)throw new r(`bad_response`,i(`error.bad_response`));switch(t.phase){case`running`:{let{endedAt:n,outputDraft:r,...i}=e;return{...i,state:t,startedAt:t.at,...t.edited?{edited:t.edited}:{},...t.activity?{activity:t.activity}:{}}}case`complete`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`error`:return{...b(e),state:t,endedAt:t.at,...t.activityPast?{activityPast:t.activityPast}:{}};case`cancel`:case`gate`:return{...b(e),state:t,endedAt:t.at};case`draft`:return{...e,outputDraft:(e.outputDraft??``)+t.text};case`artifact`:return{...e,artifacts:[...e.artifacts,t.artifact]};case`progress`:return T(e,t.data);case`dispatch`:case`trace`:case`warning`:return e}}function b(e){let{outputDraft:t,...n}=e;return n}function x(e,t){return{arguments:{},artifacts:[],...e,name:t.name,callId:t.callId,draft:(e?.draft??``)+t.text}}function S(e,t){if(t.type===`tool_draft`){e.set(t.callId,x(e.get(t.callId),t));return}let{tool:n}=t,r=n.operationId??n.callId;n.phase===void 0&&e.get(n.callId)?.draft!==void 0&&e.delete(n.callId),e.set(r,y(e.get(r),n))}function C(e){let t=new Map;for(let n of e)(n.type===`tool_draft`||n.type===`tool`)&&S(t,n);return[...t.values()]}function w(e){if(typeof e!=`object`||!e||!(`agent`in e)||!(`event`in e))return;let{event:n}=e;if(n?.type!==`tool`&&n?.type!==`tool_draft`)return;let r=t.safeParse(n);return r.success?r.data:void 0}function T(e,t){let n=w(t),r=n&&ae(e.steps??[],n);return r?{...e,steps:r}:e}function ae(e,t){let n=new Map(e.map(e=>[e.operationId??e.callId,e]));if(t.type===`tool`&&t.tool.phase!==void 0){let e=n.get(t.tool.operationId??t.tool.callId);if(e?.callId!==t.tool.callId||e.name!==t.tool.name)return}return S(n,t),[...n.values()]}function oe(e){return(e.state?.phase===`gate`?e.state.gate.preparedArguments:void 0)??e.edited?.to??e.arguments}function se(e,t){return e.type!==`tool`||e.tool.callId!==t?!1:e.tool.phase===`complete`||e.tool.phase===`error`}var ce={avif:`image/avif`,gif:`image/gif`,heic:`image/heic`,heif:`image/heif`,jpeg:`image/jpeg`,jpg:`image/jpeg`,png:`image/png`,svg:`image/svg+xml`,webp:`image/webp`,mp4:`video/mp4`,webm:`video/webm`,mov:`video/quicktime`,ogv:`video/ogg`,mp3:`audio/mpeg`,m4a:`audio/mp4`,ogg:`audio/ogg`,wav:`audio/wav`};function le(e){let t=e.split(`/`).pop()??e,n=t.lastIndexOf(`.`);return n<=0||n===t.length-1?void 0:ce[t.slice(n+1).toLowerCase()]}function ue(e){let t=e.trim();if(t.length===0)return;let n;try{n=new URL(t)}catch{return}if(n.protocol!==`http:`&&n.protocol!==`https:`)return;let r=le(n.pathname);if(r)return{url:n.href,mimeType:r}}var de=/^(.*)\/thumb(\/.+\/([^/]+))\/(\d+)px-\3(?:\.[a-z0-9]+)?$/i;function fe(e){let t=new URL(e),n=t.hostname.split(`.`).slice(-2).join(`.`);for(let e of[...t.searchParams.keys()])e.startsWith(`utm_`)&&t.searchParams.delete(e);let r=de.exec(t.pathname);return{key:`${n}${r?`${r[1]}${r[2]}`:t.pathname}${t.search}`,width:r?Number(r[4]):1/0}}function pe(e){let t=new Map,n=[],r=e=>{if(typeof e==`string`){let r=ue(e);if(!r)return;let i=fe(r.url),a=t.get(i.key);if(!a){t.set(i.key,{index:n.length,largest:i.width,smallest:i.width}),n.push(r);return}let o=n[a.index];i.width>a.largest?(a.largest=i.width,n[a.index]={...o,url:r.url,previewUrl:o.previewUrl??o.url}):i.width<a.smallest&&(a.smallest=i.width,n[a.index]={...o,previewUrl:r.url})}else if(Array.isArray(e))for(let t of e)r(t);else if(typeof e==`object`&&e)for(let t of Object.values(e))r(t)};return r(e),n}var E=0;function D(e){return e===`user`?`user-${globalThis.crypto.randomUUID()}`:(E+=1,`${e}-${String(E)}`)}function O(e,t){return e?.kind===t}function k(e,t,n,r){let i=e.at(-1);O(i,t)?i.text+=n:e.push({id:D(r),kind:t,text:n})}function A(e,t){let n=e.at(-1),r=n?.kind===`text`||n?.kind===`thought`;e.splice(r?e.length-1:e.length,0,t)}function j(e,t){return e.find(e=>e.kind===`tool`&&e.id===t)}function M(e,t){let n=`tool-${t.operationId??t.callId}`,r=j(e,n),i=y(r?.tool,t);if(r){r.tool=i;return}let a=t.phase===void 0?j(e,`tool-${t.callId}`):void 0;a?.tool.draft===void 0?e.push({id:n,kind:`tool`,tool:i}):(a.id=n,a.tool=i)}function N(e,t){let n=`tool-${t.callId}`,r=j(e,n),i=x(r?.tool,t);r?r.tool=i:e.push({id:n,kind:`tool`,tool:i})}function P(e){return e.findLast(e=>e.kind===`structured`&&e.draft!==void 0)}function F(e,t,n){let r=P(e),i=(r?.draft??``)+t;r?(r.draft=i,r.value=v(i)):e.push({id:D(n),kind:`structured`,value:v(i),draft:i})}function I(e,t,n){let r=P(e);r?(r.value=t,delete r.draft):e.push({id:D(n),kind:`structured`,value:t})}function L(e,t){return e.type===t.type?e.placeId&&t.placeId?e.placeId===t.placeId:e.uri===t.uri:!1}function R(e,t,n){let r=e.find(e=>e.kind===`citation`&&e.callId===t.callId),i=r?[...r.sources]:[];for(let e of t.sources)i.some(t=>L(t,e))||i.push(e);r?r.sources=i:e.push({id:D(n),kind:`citation`,sources:i,...t.callId===void 0?{}:{callId:t.callId}})}function z(e,t,n,r){if(t.phase===`complete`&&t.output!==void 0)for(let i of pe(t.output))r.has(i.url)||(r.add(i.url),e.push({id:D(n),kind:`media`,mimeType:i.mimeType,url:i.url,...i.previewUrl?{previewUrl:i.previewUrl}:{}}))}function B(e,t){return e.messages.flatMap(e=>{if(e.role!==`user`)return[];let n=e.parts??[],r=[e.content??``,...n.map(e=>`text`in e?e.text:``)].join(``).trim();return[...r?[{id:D(t),kind:`user-text`,text:r}]:[],...n.flatMap(e=>`text`in e?[]:[{id:D(t),kind:e.type===`audio`?`user-voice`:`user-attachment`,name:e.mimeType,mimeType:e.mimeType,...`data`in e?{sizeBytes:Math.floor(e.data.length*3/4),data:e.data}:{sizeBytes:0}}])]})}function V(e,t=`user`){let n=[],r=e.text?.trim();r&&n.push({id:D(t),kind:`user-text`,text:r});for(let r of e.attachments??[])n.push({id:D(t),kind:`user-attachment`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});for(let r of e.voice??[])n.push({id:D(t),kind:`user-voice`,name:r.name,mimeType:r.mimeType,sizeBytes:r.sizeBytes,...r.data===void 0?{}:{data:r.data}});return n}function me(e,t){switch(e.type){case`media`:return e.media?{id:D(t),kind:`media`,mimeType:e.media.mimeType,data:e.media.data}:void 0;case`grounding`:return{id:D(t),kind:`grounding`,grounding:e.grounding};case`evidence`:return{id:D(t),kind:`evidence`,evidence:e.evidence};case`error`:return e.error?{id:D(t),kind:`error`,message:e.error}:void 0;case`done`:return{id:D(t),kind:`turn-done`,stop:e.stop,tokens:e.tokens,interactionId:e.interactionId,compaction:e.compaction!==void 0};default:return}}function he(e,t,n){if(t.phase===`complete`)for(let r of t.parts??[])r.type!==`text`&&e.push({id:D(n),kind:`media`,mimeType:r.mimeType,...`data`in r?{data:r.data}:{url:r.uri}})}function H(e,t={}){let r=t.idPrefix??`turn`,i=t.showThoughts??!0;E=0;let a=[],o=new Set;for(let t of n(e))switch(t.type){case`thought`:i&&t.text&&k(a,`thought`,t.text,r);break;case`text`:t.text&&k(a,`text`,t.text,r);break;case`tool_draft`:N(a,t);break;case`tool`:M(a,t.tool),z(a,t.tool,r,o),he(a,t.tool,r);break;case`structured_draft`:F(a,t.text,r);break;case`structured`:I(a,t.structured,r);break;case`citation`:R(a,t,r);break;case`guardrail`:A(a,{id:D(r),kind:`guardrail`,guardrail:t.guardrail});break;case`stage`:for(let e of t.injected??[])a.push(...B(e,r));break;default:{let e=me(t,r);e&&a.push(e)}}return a}function ge(e,t,n={}){return[...V(e,`user`),...H(t,n)]}function _e(e){if(!e)return o;let{detect:t,patterns:n}=e;if(!n)return t;let r=Object.fromEntries(Object.entries(n).map(([e,{theorem:t}])=>[e,{theorem:t,matchers:[]}]));return{...t,sources:r}}function ve(e,t){if(e.text===void 0)return e;let n=a(e.text,`user`,_e(t));return{...e,text:n.text??e.text}}function U(e,t,n){let r=s(e,t);if(!r.ok)return{ok:!1,issues:r.issues};let i=ve(t,n);return{ok:!0,draft:i,blocks:V(i)}}function W(e,t){if(t)return e.models[t]}function G(e){return!!(e.allowModelSelect&&Object.keys(e.models).length>=2)}function K(e,t){let n=W(e,t);return n?.allowEffortSelect?Object.keys(n.efforts??{}).length>=2:!1}function q(e,t){let n=W(e,t);if(!n?.efforts)return;let r=n.defaultEffort?.trim();return r&&n.efforts[r]?r:Object.keys(n.efforts)[0]}function ye(e){return G(e)?Object.entries(e.models).map(([e,t])=>({id:e,label:t.apiId})):[]}function be(e,t){if(!K(e,t))return[];let n=W(e,t);return n?.efforts?Object.entries(n.efforts).map(([e,t])=>({alias:e,level:t})):[]}function xe(e){let t=new Set;for(let n of e)if(n.type===`tool`&&n.tool.phase===`complete`)for(let e of c(n.tool.output)??[])t.add(e);return[...t]}function Se(t){let n=e(t,e=>e.type===`done`&&e.tools!==void 0);return n?.type===`done`?n.tools:void 0}function J(e){return e?.streaming?.streamThoughts!==!1}function Y(e){return e.defaultModel??Object.keys(e.models)[0]}function Ce(e,t,n){let r=t.model!==void 0&&Object.hasOwn(e.models,t.model)&&(n===void 0||t.model!==Y(n))?t.model:Y(e),i=r===void 0?void 0:e.models[r]?.efforts;return{model:r,effort:r===t.model&&t.effort!==void 0&&i!==void 0&&Object.hasOwn(i,t.effort)&&(n===void 0||t.effort!==q(n,r))?t.effort:q(e,r)}}function X(e){if(!e.operationId)throw new r(`request`,i(`session.gate_expired`));return e.operationId}function we(e,t){return t.selectedModel??Y(e)}function Te(e,t,n){let r=t.selectedEffort;if(!n||!Object.hasOwn(e.models,n))return r;let i=e.models[n];return i.allowEffortSelect?r??i.defaultEffort:r===q(e,n)?void 0:r}function Z(e,t){let n=we(e,t),r=e.allowModelSelect||n!==Y(e)?n:void 0,i=Te(e,t,n);return{...r?{model:r}:{},...i?{effort:i}:{}}}function Ee(e,t,n){return{name:n.name,input:n.input,...n.gateKind?{gateKind:n.gateKind}:{},sessionPermissions:n.sessionPermissions??t.sessionPermissions,...t.toolSnapshot?{snapshot:t.toolSnapshot}:{},...t.promotedToolIds.length?{promoted:[...t.promotedToolIds]}:{},...Z(e,t)}}function Q(e){return{...e.conversation?{conversation:e.conversation}:{},...e.turnId?{turnId:e.turnId}:{}}}function De(e,t,n,r={}){let i=(r.walkAway?.calls??[]).map(e=>({callId:e.callId,operationId:X(e)}));return{...Q(r),...Z(e,t),input:n,...i.length?{abandon:i}:{},replay:{sessionPermissions:t.sessionPermissions}}}function Oe(e,t,n,r={}){return{...Q(r),gateId:n.gateId,operationId:n.operationId,decision:n.decision,...n.secret===void 0?{}:{secret:n.secret},...n.page===void 0?{}:{page:n.page},replay:Ee(e,t,{...n,gateKind:n.gateKind??(t.gatedTool?.callId===n.gateId?t.gatedTool.gateKind:void 0)})}}function $(e,t){return U(e.inputs,t,e.guardrails)}function ke(e,t,n,r=[]){return $(e,{...t.trim()?{text:t}:{},...n.length?{attachments:l(n)}:{},...r.length?{voice:l(r)}:{}})}function Ae(e,t){return H(t,{showThoughts:J(e.outputs)})}export{u as C,d as D,ne as E,f as O,C as S,re as T,ge as _,ke as a,se as b,J as c,q as d,K as f,U as g,G as h,X as i,xe as l,ye as m,De as n,$ as o,be as p,Ae as r,Ce as s,Oe as t,Se as u,H as v,p as w,oe as x,y};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{u as t}from"./themeProps-3IqahpCr.js";import{wn as n}from"./shaped-data-CJQ3W_RE.js";var r=n.filter(e=>e!==`builtin`),i=`Tool type must be ${r.join(`, `).replace(/, ([^,]+)$/,`, or $1`)}.`,a=e(t(),1);function o(e){let[t,n]=(0,a.useState)(()=>Date.now());return(0,a.useEffect)(()=>{if(!e)return;n(Date.now());let t=globalThis.setInterval(()=>n(Date.now()),1e3);return()=>globalThis.clearInterval(t)},[e]),t}export{r as n,i as r,o as t};
@@ -1,12 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- import { type WriteAsk } from '../mod.ts';
3
- /**
4
- * The stop before a real run of a tool that writes: the input it would send, and Cancel or Run.
5
- * `confirm` answers once the builder chose; closing the dialog is Cancel. A second question while
6
- * one is open is refused, so each run is one the builder read. A run the builder's settings say
7
- * not to ask about goes ahead.
8
- */
9
- export declare function useConfirmWrite(): {
10
- confirm: (ask: WriteAsk) => Promise<boolean>;
11
- dialog: ReactNode;
12
- };
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button } from '@astryxdesign/core/Button';
3
- import { CodeBlock } from '@astryxdesign/core/CodeBlock';
4
- import { Dialog, DialogHeader } from '@astryxdesign/core/Dialog';
5
- import { HStack } from '@astryxdesign/core/HStack';
6
- import { Layout, LayoutContent, LayoutFooter } from '@astryxdesign/core/Layout';
7
- import { useCallback, useState } from 'react';
8
- import { writeAskLine } from "../mod.js";
9
- import { writeAsks } from "./lib/studio-prefs.js";
10
- const DIALOG_WIDTH = 520;
11
- /**
12
- * The stop before a real run of a tool that writes: the input it would send, and Cancel or Run.
13
- * `confirm` answers once the builder chose; closing the dialog is Cancel. A second question while
14
- * one is open is refused, so each run is one the builder read. A run the builder's settings say
15
- * not to ask about goes ahead.
16
- */
17
- export function useConfirmWrite() {
18
- const [open, setOpen] = useState();
19
- const confirm = useCallback((ask) => new Promise((resolve) => {
20
- if (!writeAsks(ask.access)) {
21
- resolve(true);
22
- return;
23
- }
24
- setOpen((current) => {
25
- if (current) {
26
- resolve(false);
27
- return current;
28
- }
29
- return { ask, answer: resolve };
30
- });
31
- }), []);
32
- const answer = (run) => {
33
- open?.answer(run);
34
- setOpen(undefined);
35
- };
36
- const dialog = (_jsx(Dialog, { isOpen: open !== undefined, purpose: "form", width: DIALOG_WIDTH, maxHeight: "80vh", onOpenChange: (isOpen) => {
37
- if (!isOpen)
38
- answer(false);
39
- }, children: open && (_jsx(Layout, { header: _jsx(DialogHeader, { title: `Run ${open.ask.tool}?`, subtitle: writeAskLine(open.ask) }), content: _jsx(LayoutContent, { children: _jsx(CodeBlock, { code: open.ask.input, language: "json", title: "Input", size: "sm", isWrapped: true, maxHeight: 320 }) }), footer: _jsx(LayoutFooter, { children: _jsxs(HStack, { gap: 2, justify: "end", children: [_jsx(Button, { label: "Cancel", variant: "ghost", onClick: () => {
40
- answer(false);
41
- } }), _jsx(Button, { label: "Run", variant: open.ask.access === 'destructive' ? 'destructive' : 'primary', onClick: () => {
42
- answer(true);
43
- } })] }) }) })) }));
44
- return { confirm, dialog };
45
- }