@theoremjs/studio 0.3.5-next.933.gfc0e83b → 0.3.5-next.935.ga3dc485

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 (60) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{BottomSheet-CFmWCLNs.js → BottomSheet-BeZNOmva.js} +1 -1
  3. package/page/assets/{ConsoleFrame-sWIg1UlI.js → ConsoleFrame-Durgrfa8.js} +1 -1
  4. package/page/assets/{ContextMenu-kJvPbe2l.js → ContextMenu-CdZPGyrH.js} +2 -2
  5. package/page/assets/{DateInput-DFW6ZGmz.js → DateInput-DxxKNbFy.js} +1 -1
  6. package/page/assets/{DropdownMenu-kC1ynF9P.js → DropdownMenu-CLdHjD_O.js} +2 -2
  7. package/page/assets/{Link-cEUGqR4E.js → Link-B8qtW9Me.js} +1 -1
  8. package/page/assets/{MenuBottomSheet-CXQHH9x8.js → MenuBottomSheet-BJz5pzDE.js} +1 -1
  9. package/page/assets/{PowerSearchBottomSheet-DT2J58Od.js → PowerSearchBottomSheet-xO313kak.js} +1 -1
  10. package/page/assets/{RankedBars-DBJRNmPe.js → RankedBars-D0yn-ri0.js} +1 -1
  11. package/page/assets/{SchemaFields-Cjm83Nt8.js → SchemaFields-Dvwzr5ZO.js} +1 -1
  12. package/page/assets/{ShapedData-DYOCaGlk.js → ShapedData-DYRlNRy_.js} +1 -1
  13. package/page/assets/{TokenizerBottomSheet-BU9l3CaI.js → TokenizerBottomSheet-DhPibEHt.js} +1 -1
  14. package/page/assets/{ToolResultCharts-CSyUS1-z.js → ToolResultCharts-BGJbKsDT.js} +1 -1
  15. package/page/assets/{Toolbar-BmuypKxW.js → Toolbar-DVp0Jb7c.js} +1 -1
  16. package/page/assets/{TraceInspector-CPWC9lS8.js → TraceInspector-Cs8SNp3b.js} +2 -2
  17. package/page/assets/{TraceOverview-DKAyP6oW.js → TraceOverview-BN5UDJe8.js} +1 -1
  18. package/page/assets/{_virtual_studio-type-sources-C6e3ZJtP.js → _virtual_studio-type-sources-ekRa45Mf.js} +49 -19
  19. package/page/assets/{browser-connection-DzO00xRy.js → browser-connection-BWOEEs03.js} +1 -1
  20. package/page/assets/browser-engine-BxtG9nJ-.js +16 -0
  21. package/page/assets/{browser-transport-BPAKt_cc.js → browser-transport-rFxtbMn0.js} +2 -2
  22. package/page/assets/{compile-oGEpwgkY.js → compile-C4Q50p5E.js} +2 -2
  23. package/page/assets/{encode-files-Bn5i8t9U.js → encode-files-MPtLTYyk.js} +1 -1
  24. package/page/assets/{export-agent-BcjOjktu.js → export-agent-CEB-vrfl.js} +1 -1
  25. package/page/assets/{getRadiusAndStrokeWidthFromDot-CuVjZhu8.js → getRadiusAndStrokeWidthFromDot-Ck-kRNvB.js} +1 -1
  26. package/page/assets/{guardrail-health-DzeSNMix.js → guardrail-health-DMd_p8rH.js} +2 -2
  27. package/page/assets/{guardrail-tester-BQ7BHdiW.js → guardrail-tester-DAis9Gsd.js} +1 -1
  28. package/page/assets/{index-hSIwfi4j.js → index-C6pyNvXU.js} +16 -16
  29. package/page/assets/{json-code-D6l475BW.js → json-code-DqpAF4hg.js} +1 -1
  30. package/page/assets/{labels-provider-D_7O3BSI.js → labels-provider-BOmB5WmP.js} +1 -1
  31. package/page/assets/{live-messages-DvMnxecr.js → live-messages-DekE0UkG.js} +1 -1
  32. package/page/assets/{prompt-row-OoetsUr1.js → prompt-row-BHTY1SfP.js} +1 -1
  33. package/page/assets/reader-BZ-mDuss.js +5 -0
  34. package/page/assets/{registry-Bjkfo9zx.js → registry-CqweoU_Q.js} +1 -1
  35. package/page/assets/{schema-DI2QKpYi.js → schema-Do4wX6Sr.js} +2 -2
  36. package/page/assets/{shaped-data-BxGL5na3.js → shaped-data-BxDmEUJe.js} +17 -17
  37. package/page/assets/{stub-CY0cuGPg.js → stub-CUHiDLLw.js} +1 -1
  38. package/page/assets/{studio-code-pane-CXo-J0fe.js → studio-code-pane-i0bu-gwb.js} +3 -3
  39. package/page/assets/{studio-console-BA7bGrU2.js → studio-console-Cn5vtx-w.js} +1 -1
  40. package/page/assets/{studio-decision-C1U7AGDn.js → studio-decision-CwWJLFnm.js} +1 -1
  41. package/page/assets/{studio-embedding-DS7pVE5l.js → studio-embedding-Dya8zKKM.js} +1 -1
  42. package/page/assets/{studio-host-console-C3uC7P_C.js → studio-host-console-BbnDPTbG.js} +2 -2
  43. package/page/assets/studio-live-uS2TgNK2.js +5 -0
  44. package/page/assets/{studio-map-CqLgnQNk.js → studio-map-Bqv8T8BY.js} +1 -1
  45. package/page/assets/{studio-media-CmbCThcX.js → studio-media-C6h3z2kJ.js} +1 -1
  46. package/page/assets/{studio-trace-replay-R8IQNP3s.js → studio-trace-replay-B-WZNREk.js} +1 -1
  47. package/page/assets/{studio-type-checker-BQAMVf_u.js → studio-type-checker-2_B50AHd.js} +1 -1
  48. package/page/assets/{tool-schema-Bfe2TkD-.js → tool-schema-CnrGGkcr.js} +1 -1
  49. package/page/assets/{trace-record--OEcC7x1.js → trace-record-CRYVqBZW.js} +1 -1
  50. package/page/assets/{tree-CMulctlY.js → tree-CZVr90dg.js} +2 -2
  51. package/page/assets/{turn-client-sADYJHV9.js → turn-client-C_-rA6KF.js} +2 -2
  52. package/page/assets/types-DfwVnkMI.js +1 -0
  53. package/page/assets/{use-one-call-CJqcEomh.js → use-one-call-By1S3qBT.js} +1 -1
  54. package/page/assets/{useDismissSearchOnTouchDrag-Cjqhp30f.js → useDismissSearchOnTouchDrag-L_mBp0Dm.js} +1 -1
  55. package/page/assets/{workspace-BrQUhBOf.js → workspace-ChRm7M3S.js} +1 -1
  56. package/page/index.html +21 -21
  57. package/page/assets/browser-engine-BciA9NL-.js +0 -16
  58. package/page/assets/reader-Bz6rc3qr.js +0 -5
  59. package/page/assets/studio-live-DaQMlVSh.js +0 -5
  60. package/page/assets/types-7mVE39E8.js +0 -1
@@ -1 +1 @@
1
- import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as ee,t as u,v as d}from"./schemas-D7cgkv3L.js";import{Cn as te,Ia as f,La as ne,Pa as re,Q as ie,Xi as p,_i as ae,ba as m,ci as h,it as g,mi as oe,oi as _,q as se,so as v,ut as y,ya as b}from"./shaped-data-BxGL5na3.js";import{c as x}from"./host-patterns-F-KZIzkF.js";import{c as ce,d as le,i as S,n as C,o as ue,t as w,u as de}from"./schema-DI2QKpYi.js";var fe=n({accepted:b,preparedInput:m});function T(e){return new x(`internal`,e)}function E(e,t,n){return new x(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function D(e){return E(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function O(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,n])=>[e,t(n)])):e,n=m.parse(t(P(e))),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(n)));return Array.from(new Uint8Array(r),e=>e.toString(16).padStart(2,`0`)).join(``)}var k=_.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),A=n({finding:t(),data:m.optional(),parts:a(h).optional(),media:a(oe).optional(),hidden:d(!0).optional(),modelText:t().optional(),provenance:ne.optional(),suspicious:a(f).optional()}),j=_.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),M=n({event:j,replay:n({modelResult:A})}),N=n({event:k,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:A.optional(),outputRaw:m.optional(),failure:n({code:t(),kind:re,message:t(),error:t().optional(),details:m.optional()}).optional(),awaiting:c().optional(),denied:d(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(ae),released:r().int().nonnegative().optional()})).optional(),ended:d(!0).optional()})});function P(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw T(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw T(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw T(`Tool operation value has an own __proto__ key`);t.add(e);try{if(Array.isArray(e))return e.map(n);let t=Object.entries(Object.getOwnPropertyDescriptors(e)),r=t.find(([,e])=>e.get||e.set);if(r)throw T(`Tool operation value has a getter or setter at '${r[0]}'`);return Object.fromEntries(t.filter(([,e])=>e.enumerable&&e.value!==void 0).map(([e,t])=>[e,n(t.value)]))}finally{t.delete(e)}};return m.parse(n(e))}var F=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),I=`background`;function L(){return c().optional().describe(v(`tool.background_field`))}function R(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[I]:n,...r}=t;return{input:r,asked:n===!0}}function z(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?R(e,t).asked?`claim`:void 0:n}function B(e,t){return e.type===`agent`?t?.takesSteers(e)?void 0:`steering_off`:`not_agent`}function V(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||t.type===`builtin`||!n)return;let a=z(t,e.input);if(a===void 0)return;let o=B(t,e.agents);return{at:a,support:n,...o?{refuseSteers:o}:{},trace:n.openTrace(r.callId),reply:()=>{let e={finding:v(`tool.background_started`,{tool:t.name},i)},n=ie(e),a=se(r,{phase:`background`,readBack:n});return M.parse(P({event:a,replay:{modelResult:e}}))}}}function pe(e,t){if(e&&!t?.detach)throw new x(`config`,`A request with a background service needs a coordinator with detach`)}function me(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new x(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!F.safeParse(n).success)throw new x(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var he=/^[\x21-\x7E]{1,256}$/;function H(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function ge(e){return e!==null&&he.test(e)}async function _e(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var U=`after`;function ve(){return a(t()).optional().describe(v(`tool.after_field`))}function W(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new x(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof u){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof ee)return e(n.options.map(a));throw new x(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function G(e,t){return W(e,t,U,ve)}function ye(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[U]:n,...r}=t;return{input:r,names:n??[]}}function be(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var K=class{value;constructor(e){this.value=e}};function xe(e){return new K(e)}function Se(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return xe(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(v(`tool.page_timed_out`,{},i)):Error(v(`tool.page_no_answer`,{tool:e},i))}}var q=new WeakMap;function J(e,t){let n=q.get(e);n||(n=new WeakMap,q.set(e,n));let r=n.get(t);if(!r){let i=C(e,`input`);S(i,`input`);let a=C(t,`output`);S(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Y(e){let{inputSchema:t,outputSchema:n}=J(e.input,e.output);y(t,`Tool "${e.name}" input`,`input`),y(n,`Tool "${e.name}" output`,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?g(n,r[t]):void 0;if(i)throw new x(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Ce(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new x(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function X(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new x(`config`,`Tool "${e}" auth.queryParam ${r}`)}function we(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new x(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function Z(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new x(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Q(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new x(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Te(e){Q(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Q(e.name,`imageLimits.count`,t.count),Q(e.name,`imageLimits.bytes`,t.bytes),Q(e.name,`imageLimits.totalBytes`,t.totalBytes),Z(e.name,t.timeoutMs))}function $(e){if(e.type!==`builtin`&&me({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;Ce(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&w(e.endpoint),X(e.name,e.auth,e.mapping?.queryParams),we(e.name,e.limit),Z(e.name,e.timeoutMs)):X(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Te(e),e.type===`mcp`&&(Q(e.name,`session.idleMs`,e.session?.idleMs),Q(e.name,`session.max`,e.session?.max));let[t]=p(e);if(t)throw new x(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function Ee(e){return w(e.endpoint),{...e,type:`http`,...Y(e)}}function De(e){return{...e,type:`mcp`,...Y(e)}}function Oe(e){let t=e.answeredBy===`page`?Se(e.name):e.handler;if(typeof t!=`function`)throw new x(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...Y(e)}}function ke(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=W(e.name,t,`background`,L);return{...e,askInputSchema:J(n,e.output).inputSchema}}function Ae(e,t,n){return $(e),ke(je(e,t,n))}function je(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=de(e,t,n),i=te(r),a=ue({type:r.type,...i?{inputs:i}:{}},e),o=e.after?G(e.name,a):a,s=Y({...e,input:o,output:ce});return le(e,o,s)}let r=e.after?{...e,input:G(e.name,e.input)}:e;return r.type===`http`?Ee(r):r.type===`mcp`?De(r):Oe(r)}function Me(e=()=>void 0,t=()=>[]){let n=new Map,r=H(),i=e=>n.get(e),a=t=>{let r=Ae(t,e,i);return n.set(r.name,r),r};return{register:a,registerMany:e=>e.map(e=>a(e)),get:i,require(e){let t=i(e);if(!t)throw new x(`config`,`Tool '${e}' is not registered`);return t},has:e=>n.has(e),list:()=>[...n.values()],findProfile:e,structuredReplies:t,reset:()=>{n.clear(),r.clear()},mcpSessions:r}}export{N as _,be as a,_e as c,R as d,D as f,O as g,fe as h,ye as i,pe as l,P as m,Me as n,H as o,T as p,K as r,ge as s,$ as t,V as u,M as v,E as y};
1
+ import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as ee,t as u,v as d}from"./schemas-D7cgkv3L.js";import{Cn as te,Fa as f,La as ne,Q as re,Ra as ie,Zi as p,ba as ae,co as m,hi as h,it as g,li as oe,q as se,si as _,ut as v,vi as y,xa as b}from"./shaped-data-BxDmEUJe.js";import{c as x}from"./host-patterns-F-KZIzkF.js";import{c as ce,d as le,i as S,n as C,o as ue,t as w,u as de}from"./schema-Do4wX6Sr.js";var fe=n({accepted:ae,preparedInput:b});function T(e){return new x(`internal`,e)}function E(e,t,n){return new x(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function D(e){return E(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function O(e){let t=e=>Array.isArray(e)?e.map(t):e&&typeof e==`object`?Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>e<t?-1:+(e>t)).map(([e,n])=>[e,t(n)])):e,n=b.parse(t(P(e))),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(JSON.stringify(n)));return Array.from(new Uint8Array(r),e=>e.toString(16).padStart(2,`0`)).join(``)}var k=_.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),A=n({finding:t(),data:b.optional(),parts:a(oe).optional(),media:a(h).optional(),hidden:d(!0).optional(),modelText:t().optional(),provenance:ie.optional(),suspicious:a(ne).optional()}),j=_.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),M=n({event:j,replay:n({modelResult:A})}),N=n({event:k,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:A.optional(),outputRaw:b.optional(),failure:n({code:t(),kind:f,message:t(),error:t().optional(),details:b.optional()}).optional(),awaiting:c().optional(),denied:d(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(y),released:r().int().nonnegative().optional()})).optional(),ended:d(!0).optional()})});function P(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw T(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw T(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw T(`Tool operation value has an own __proto__ key`);t.add(e);try{if(Array.isArray(e))return e.map(n);let t=Object.entries(Object.getOwnPropertyDescriptors(e)),r=t.find(([,e])=>e.get||e.set);if(r)throw T(`Tool operation value has a getter or setter at '${r[0]}'`);return Object.fromEntries(t.filter(([,e])=>e.enumerable&&e.value!==void 0).map(([e,t])=>[e,n(t.value)]))}finally{t.delete(e)}};return b.parse(n(e))}var F=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),I=`background`;function L(){return c().optional().describe(m(`tool.background_field`))}function R(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[I]:n,...r}=t;return{input:r,asked:n===!0}}function z(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?R(e,t).asked?`claim`:void 0:n}function B(e,t){return e.type===`agent`?t?.takesSteers(e)?void 0:`steering_off`:`not_agent`}function V(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||t.type===`builtin`||!n)return;let a=z(t,e.input);if(a===void 0)return;let o=B(t,e.agents);return{at:a,support:n,...o?{refuseSteers:o}:{},trace:n.openTrace(r.callId),reply:()=>{let e={finding:m(`tool.background_started`,{tool:t.name},i)},n=re(e),a=se(r,{phase:`background`,readBack:n});return M.parse(P({event:a,replay:{modelResult:e}}))}}}function pe(e,t){if(e&&!t?.detach)throw new x(`config`,`A request with a background service needs a coordinator with detach`)}function me(e){let{name:t,background:n}=e;if(n!==void 0&&n!==`never`){if(e.answeredBy===`page`)throw new x(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!F.safeParse(n).success)throw new x(`config`,typeof n==`object`?`Tool '${t}' sets background.afterMs, which must be a time in milliseconds`:`Tool '${t}' sets background to ${JSON.stringify(n)}; it takes 'always', 'ask', 'never' or { afterMs }`)}}var he=/^[\x21-\x7E]{1,256}$/;function H(e=Date.now){let t=new Map,n=new Map,r=({tool:e,max:n})=>{if(n===void 0)return;let r=[...t.values()].filter(t=>t.tool===e).length;for(let[i,a]of t){if(r<=n)break;a.tool===e&&(t.delete(i),r--)}};return{get(n,i){let a=t.get(n);if(a&&(t.delete(n),!(i.idleMs!==void 0&&e()-a.usedAt>i.idleMs)))return t.set(n,{...a,usedAt:e(),tool:i.tool}),r(i),{id:a.id,protocolVersion:a.protocolVersion}},open(i,a,o){let s=n.get(i);if(s)return s;let c=o().then(n=>(t.delete(i),t.set(i,{...n,usedAt:e(),tool:a.tool}),r(a),n)).finally(()=>n.delete(i));return n.set(i,c),c},drop(e,n){t.get(e)?.id===n&&t.delete(e)},clear(){t.clear(),n.clear()}}}function ge(e){return e!==null&&he.test(e)}async function _e(e,t){let n=JSON.stringify([e,Object.entries(t).map(([e,t])=>[e.toLowerCase(),t]).sort(([e],[t])=>e<t?-1:+(e>t))]),r=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(n));return[...new Uint8Array(r)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var U=`after`;function ve(){return a(t()).optional().describe(m(`tool.after_field`))}function W(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new x(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof u){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof ee)return e(n.options.map(a));throw new x(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function G(e,t){return W(e,t,U,ve)}function ye(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[U]:n,...r}=t;return{input:r,names:n??[]}}function be(e,t,n){return n?e.flatMap(e=>{let r=n.filter(n=>n.tool===e&&n.callId!==t).map(e=>e.callId);return r.length>0?r:[e]}):[]}var K=class{value;constructor(e){this.value=e}};function xe(e){return new K(e)}function Se(e){return(t,n)=>{let{page:r}=n;if(r&&`output`in r)return xe(r.output);let{labels:i}=n.profile;throw r?.timedOut?Error(m(`tool.page_timed_out`,{},i)):Error(m(`tool.page_no_answer`,{tool:e},i))}}var q=new WeakMap;function J(e,t){let n=q.get(e);n||(n=new WeakMap,q.set(e,n));let r=n.get(t);if(!r){let i=C(e,`input`);S(i,`input`);let a=C(t,`output`);S(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function Y(e){let{inputSchema:t,outputSchema:n}=J(e.input,e.output);v(t,`Tool "${e.name}" input`,`input`),v(n,`Tool "${e.name}" output`,`output`);let r={activity:{input:t},activityPast:{input:t,output:n},activityFailed:{input:t},request:{input:t}};for(let t of[`activity`,`activityPast`,`activityFailed`,`request`]){let n=e.labels?.[t],i=n?g(n,r[t]):void 0;if(i)throw new x(`config`,`Tool "${e.name}" ${t} label: ${i}`)}return{inputSchema:structuredClone(t),outputSchema:structuredClone(n)}}function Ce(e,t){if(t&&(typeof t.service!=`string`||!t.service.trim()))throw new x(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function X(e,t,n=[]){if(t?.queryParam===void 0)return;let r=t.queryParam.trim()?t.type===`api_key`?t.headerName!==void 0||t.headerPrefix!==void 0?`is set with headerName or headerPrefix; the key goes in one place`:n.includes(t.queryParam)?`"${t.queryParam}" is also one of mapping.queryParams`:void 0:`is set on a '${t.type}' sign-in; only an API key goes in the URL`:`is blank`;if(r)throw new x(`config`,`Tool "${e}" auth.queryParam ${r}`)}function we(e,t){if(t!==void 0&&!(Number.isInteger(t.requests)&&t.requests>0&&Number.isFinite(t.windowMs)&&t.windowMs>0))throw new x(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function Z(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new x(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Q(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new x(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Te(e){Q(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Q(e.name,`imageLimits.count`,t.count),Q(e.name,`imageLimits.bytes`,t.bytes),Q(e.name,`imageLimits.totalBytes`,t.totalBytes),Z(e.name,t.timeoutMs))}function $(e){if(e.type!==`builtin`&&me({name:e.name,...e.background===void 0?{}:{background:e.background},...e.answeredBy?{answeredBy:e.answeredBy}:{}}),e.type===`builtin`||e.type===`agent`)return;Ce(e.name,e.auth),e.type===`http`?(e.endpoint?.trim()&&w(e.endpoint),X(e.name,e.auth,e.mapping?.queryParams),we(e.name,e.limit),Z(e.name,e.timeoutMs)):X(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Te(e),e.type===`mcp`&&(Q(e.name,`session.idleMs`,e.session?.idleMs),Q(e.name,`session.max`,e.session?.max));let[t]=p(e);if(t)throw new x(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function Ee(e){return w(e.endpoint),{...e,type:`http`,...Y(e)}}function De(e){return{...e,type:`mcp`,...Y(e)}}function Oe(e){let t=e.answeredBy===`page`?Se(e.name):e.handler;if(typeof t!=`function`)throw new x(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...Y(e)}}function ke(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=W(e.name,t,`background`,L);return{...e,askInputSchema:J(n,e.output).inputSchema}}function Ae(e,t,n){return $(e),ke(je(e,t,n))}function je(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=de(e,t,n),i=te(r),a=ue({type:r.type,...i?{inputs:i}:{}},e),o=e.after?G(e.name,a):a,s=Y({...e,input:o,output:ce});return le(e,o,s)}let r=e.after?{...e,input:G(e.name,e.input)}:e;return r.type===`http`?Ee(r):r.type===`mcp`?De(r):Oe(r)}function Me(e=()=>void 0,t=()=>[]){let n=new Map,r=H(),i=e=>n.get(e),a=t=>{let r=Ae(t,e,i);return n.set(r.name,r),r};return{register:a,registerMany:e=>e.map(e=>a(e)),get:i,require(e){let t=i(e);if(!t)throw new x(`config`,`Tool '${e}' is not registered`);return t},has:e=>n.has(e),list:()=>[...n.values()],findProfile:e,structuredReplies:t,reset:()=>{n.clear(),r.clear()},mcpSessions:r}}export{N as _,be as a,_e as c,R as d,D as f,O as g,fe as h,ye as i,pe as l,P as m,Me as n,H as o,T as p,K as r,ge as s,$ as t,V as u,M as v,E as y};
@@ -1,3 +1,3 @@
1
- import{A as e,D as t,E as n,O as r,T as i,b as a,c as o,d as s,f as c,x as l}from"./schemas-D7cgkv3L.js";import{Cn as u,Nt as ee,at as te,bn as ne,ct as re,fi as ie,ft as ae,hn as oe,mi as se,ot as d,ui as f}from"./shaped-data-BxGL5na3.js";import{c as p}from"./host-patterns-F-KZIzkF.js";var ce=`
1
+ import{A as e,D as t,E as n,O as r,T as i,b as a,c as o,d as s,f as c,x as l}from"./schemas-D7cgkv3L.js";import{Cn as u,Nt as ee,at as te,bn as ne,ct as re,di as ie,ft as ae,hi as oe,hn as se,ot as d,pi as f}from"./shaped-data-BxDmEUJe.js";import{c as p}from"./host-patterns-F-KZIzkF.js";var ce=`
2
2
 
3
- `;function le(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function m(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=le(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function h(e,t){let n=m(e,t);if(n)throw new p(`config`,n)}function g(e,t,n){return h(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function _(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function v(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:ce,private:!0}),t.push(...n));return t}function y(e){return e.map(e=>e.text).join(``)}function ue(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:y(e),private:t}}function de(e,t){return ue(v([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var fe=/^[A-Za-z_][\w-]*$/,pe=/\{([A-Za-z_][\w-]*)\}/g,me=[`input`,`output`];function b(e){return e.choices.map(e=>e.value)}function x(e){return(e.type===`text`||e.type===`image`||e.type===`live`?e.identity.options:void 0)??{}}function S(e){return u(e)?.options??{}}function C(e,t){let n={...x(e),...S(e)};return Object.hasOwn(n,t)?n[t]:void 0}function w(e,t){if(!fe.test(e))return`Option "${e}" needs a plain name.`;if(me.includes(e))return`Option "${e}" is a reserved name.`;let n=Array.isArray(t.choices)?b(t):[];if(n.length===0)return`Option "${e}" lists no values.`;let r=n.find(e=>!e.trim()||e===`null`);return r===void 0?void 0:`Option "${e}" can't take the value "${r}".`}function T(e,t){for(let[n,r]of Object.entries({...e,...t})){if(e&&t&&Object.hasOwn(e,n)&&Object.hasOwn(t,n))return`"${n}" is on both identity.options and inputs.options.`;let i=w(n,r);if(i)return i}}function E(e,t,n,r){for(let[i,a]of Object.entries(r??{})){let r=Object.hasOwn(t,i)?t[i]:void 0;if(!r)throw new p(`request`,`Profile ${e} has no option '${i}' on ${n}`);let o=b(r);if(!o.includes(a))throw new p(`request`,`Profile ${e}: option '${i}' takes ${o.join(`, `)}, not '${a}'`)}}function D(e,t){return Object.hasOwn(e,`path`)&&t.path!==void 0?{path:t.path}:{}}function O(e,t){let n=x(e);if(t.options&&Object.hasOwn(t.options,`path`))throw new p(`request`,`Profile ${e.id}: the turn's own path states path`);E(e.id,n,`identity.options`,{...t.options,...D(n,t)}),E(e.id,S(e),`inputs.options`,t.input?.options)}function k(e,t){return{...t.options,...D(x(e),t),...t.input?.options}}function A(e,t,n){let r=!0,i=t.replace(pe,(t,i)=>{if(!C(e,i))return t;let a=Object.hasOwn(n,i)?n[i]:void 0;return a===void 0&&(r=!1),a??t});return r?i:void 0}function j(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function M(e){return typeof e==`string`?e:e.private}function N(e){return re(e[0]===void 0?``:M(e[0]))}function P(e){let t={};for(let[n,r]of Object.entries(e))t[n]={type:`string`,enum:b(r)};return{type:`object`,properties:t}}function F(e,t){if(e.length===0)return`It has no wording to send.`;let n=N(e);if(n.joined)return`A prompt line can't start with "+"; every line that fits is sent.`;if(n.when===`unreadable`)return`A line that opens with "when" needs an option and a colon, like "when path is web: …".`;for(let e of n.when){if(e.path.includes(`.`))return`"${e.path}" isn't one option.`;if(`has`in e)return`An option is one value, so it has no fields.`;if(e.expected===null)return`An option has no null value, so "is null" never fits.`;let n=d(e,t,`this profile’s options`);if(n)return n}if(n.when.length>0&&!n.text&&e.length===1)return`It has no wording to send.`}function I(e,t,n){let r=T(t,n);if(r)return r;let i=P({...t,...n});for(let[t,n]of j(e).entries()){let e=F(n,i);if(e)return`Line ${t+1}: ${e}`}}function L(e,t){return e.when!==`unreadable`&&e.when.every(e=>te(e,t))}function R(e,t,n){let r=j(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=N(o);if(!L(r,t))continue;let s=o.map((e,t)=>n(t===0?r.text:M(e)));if(s.includes(void 0))continue;let c=o.flatMap((e,t)=>{let n=s[t];return n?[{text:n,private:typeof e!=`string`||!i}]:[]});a.push({line:e+1,pieces:c})}return a}function z(e,t){if(typeof e!=`string`){if(!Array.isArray(e))throw new p(`config`,`${t} must be a string or an array of lines`);if(e.length===0)throw new p(`config`,`${t} must not be an empty array`);for(let[n,r]of e.entries())if(typeof r!=`string`){if(!Array.isArray(r))throw new p(`config`,`${t}[${n}] must be a string or a list of parts; put { private } inside the list`);h(r,`${t}[${n}]`)}}}function he(e,t){let n=e?.path;if(!n)return;let r=b(n);for(let e of t){let t=e.paths?.find(e=>e!==`*`&&!r.includes(e));if(t!==void 0)return`Tool ${e.name} lists path "${t}", which is not one of ${r.join(`, `)}.`}}function B(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function V(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ge(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function H(e){return`tools`in e?e.tools.allow:[]}function U(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function _e(e){return`tools`in e?e.tools.parallel:void 0}function ve(e,t,n){return H(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||V(i.paths,n.path)})}function ye(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&V(r.paths,n.path)}):[]}function W(e,t,n){let r=e.get(t);if(r&&r.type!==`builtin`)return{type:`function`,name:r.name,description:r.description,parameters:ae(n&&r.askInputSchema||r.inputSchema)}}function be(e,t,n){let r=[];for(let i of t){let t=W(e,i,n);t&&r.push(t)}return r}function G(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=W(e,n,t.modelBackground);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function xe(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function Se(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function Ce(e,t,n){return ge(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function we(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=H(t).flatMap(t=>e.get(t)??[]),r=he(t.identity.options,n);if(r)throw new p(`config`,`Profile ${t.id}: ${r}`)}function Te(e,t){let n=U(t)?.t2Loader,r=n===void 0?void 0:e.get(n);if(r&&r.type!==`builtin`&&(r.background??`never`)!==`never`)throw new p(`config`,`Profile ${t.id}: tools.t2Loader '${r.name}' sets background, and a loader cannot detach`)}function Ee(e,t,n,r){we(e,t),Te(e,t);let i=ve(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ye(e,t,n,r),o=[...i,...a],s=Ce(e,t,o),c=Se(e,t,o),l=c.filter(t=>B(e,t)),u=n.background!==void 0;return{builtins:s,gated:o,visible:c,executable:l,path:n.path,sessionPermissions:n.sessionPermissions,wire:be(e,c,u),...u?{modelBackground:u}:{}}}function De(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)})),...e.modelBackground?{modelBackground:e.modelBackground}:{}}}async function Oe(e,t,n,r){try{await ke(e,t,n,r)}catch(e){return{crashed:e}}}async function ke(e,t,n,r){let i=U(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new p(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new p(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);K(e,t,a)}function K(e,t,n=[]){for(let r of n){if(!t.gated.includes(r))continue;let n=e.get(r);n?.loadTier===`T2`&&(n.type===`builtin`?xe(e,t,r):G(e,t,r))}t.executable=t.visible.filter(t=>B(e,t))}var Ae=new Set([`__proto__`,`constructor`,`prototype`]);function je(e){if(!oe(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Me(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Ae.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=Ne(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;V(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)G(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>B(e,t)),{promoted:a}}function q(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function Ne(e,t,n){if(!H(n).includes(t))return q(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?q(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:q(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):q(`tools.t2Loader attempted to promote unknown tool '${t}'`)}var Pe=new Set([`text`,`image`,`speech`]),Fe=n().regex(/\S/),J=i({mimeType:n(),data:c(),name:n().optional()}),Ie=i({mimeType:n(),uri:n(),name:n().optional()}),Le=i({voice:n().optional(),style:n().optional(),speed:a().positive().optional()});function Re(e){return i(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=b(t);return[e,o(n).optional()]})))}var ze=new Set([`text`,`attachments`,`voice`,`options`,`speech`]);function Be(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,options:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{options:s}:{},...c?{speech:c}:{}},hostInput:r}}function Ve(e,n){let{inputs:r}=e,a={text:Fe};r?.attachments&&(a.attachments=s(t([J,Ie])).optional()),r?.voice&&(a.voice=s(J).optional()),r?.options&&(a.options=Re(r.options).optional()),e.type===`speech`&&(a.speech=Le.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new p(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new p(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(ze.has(e))throw new p(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return i(a)}var Y=l({text:n().optional(),structured:r().optional(),removed:s(l({path:n(),reason:n(),item:r()})).optional(),parts:s(se).optional(),sources:s(ie).optional()});function He(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function Ue(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function X(e,t){if(!Pe.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!He(e))return`it does not take text`;for(let n of H(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(Ue(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function We(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new p(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new p(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=X(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ge(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return H(e).length===0&&!t?`local`:`delegated`}function Z(e){let t=f(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ee(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:ne(e.media.mimeType)??`document`,mimeType:e.media.mimeType,data:e.media.data,sent:!0}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ke(e,t,n){return{...e,type:`agent`,input:t,output:Y,sources:e=>e.sources??[],...n}}function qe(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function Je(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&Q(i,`${n}.properties.${t}`,r)}function Q(e,t,n){if(!qe(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Je(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&Q(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&Q(e,`${t}.${r}[${i}]`,n)})}}function Ye(e,t){let n=[];if(Q(e,`$`,n),n.length>0)throw new p(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function Xe(t,n=`output`){let r=e(t,{target:`draft-7`,io:n});return delete r.$schema,r.type||=`object`,r}function $(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map($);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=$(e[n]));return t}function Ze(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new p(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}export{k as A,R as C,b as D,A as E,v as M,g as N,T as O,_ as P,z as S,O as T,_e as _,X as a,K as b,Y as c,Ke as d,Be as f,H as g,je as h,Ye as i,de as j,C as k,Z as l,De as m,Xe as n,Ve as o,Oe as p,$ as r,Ge as s,Ze as t,We as u,U as v,I as w,Ee as x,Me as y};
3
+ `;function le(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function m(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=le(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function h(e,t){let n=m(e,t);if(n)throw new p(`config`,n)}function g(e,t,n){return h(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function _(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function v(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:ce,private:!0}),t.push(...n));return t}function y(e){return e.map(e=>e.text).join(``)}function ue(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:y(e),private:t}}function de(e,t){return ue(v([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var fe=/^[A-Za-z_][\w-]*$/,pe=/\{([A-Za-z_][\w-]*)\}/g,me=[`input`,`output`];function b(e){return e.choices.map(e=>e.value)}function x(e){return(e.type===`text`||e.type===`image`||e.type===`live`?e.identity.options:void 0)??{}}function S(e){return u(e)?.options??{}}function C(e,t){let n={...x(e),...S(e)};return Object.hasOwn(n,t)?n[t]:void 0}function w(e,t){if(!fe.test(e))return`Option "${e}" needs a plain name.`;if(me.includes(e))return`Option "${e}" is a reserved name.`;let n=Array.isArray(t.choices)?b(t):[];if(n.length===0)return`Option "${e}" lists no values.`;let r=n.find(e=>!e.trim()||e===`null`);return r===void 0?void 0:`Option "${e}" can't take the value "${r}".`}function T(e,t){for(let[n,r]of Object.entries({...e,...t})){if(e&&t&&Object.hasOwn(e,n)&&Object.hasOwn(t,n))return`"${n}" is on both identity.options and inputs.options.`;let i=w(n,r);if(i)return i}}function E(e,t,n,r){for(let[i,a]of Object.entries(r??{})){let r=Object.hasOwn(t,i)?t[i]:void 0;if(!r)throw new p(`request`,`Profile ${e} has no option '${i}' on ${n}`);let o=b(r);if(!o.includes(a))throw new p(`request`,`Profile ${e}: option '${i}' takes ${o.join(`, `)}, not '${a}'`)}}function D(e,t){return Object.hasOwn(e,`path`)&&t.path!==void 0?{path:t.path}:{}}function O(e,t){let n=x(e);if(t.options&&Object.hasOwn(t.options,`path`))throw new p(`request`,`Profile ${e.id}: the turn's own path states path`);E(e.id,n,`identity.options`,{...t.options,...D(n,t)}),E(e.id,S(e),`inputs.options`,t.input?.options)}function k(e,t){return{...t.options,...D(x(e),t),...t.input?.options}}function A(e,t,n){let r=!0,i=t.replace(pe,(t,i)=>{if(!C(e,i))return t;let a=Object.hasOwn(n,i)?n[i]:void 0;return a===void 0&&(r=!1),a??t});return r?i:void 0}function j(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function M(e){return typeof e==`string`?e:e.private}function N(e){return re(e[0]===void 0?``:M(e[0]))}function P(e){let t={};for(let[n,r]of Object.entries(e))t[n]={type:`string`,enum:b(r)};return{type:`object`,properties:t}}function F(e,t){if(e.length===0)return`It has no wording to send.`;let n=N(e);if(n.joined)return`A prompt line can't start with "+"; every line that fits is sent.`;if(n.when===`unreadable`)return`A line that opens with "when" needs an option and a colon, like "when path is web: …".`;for(let e of n.when){if(e.path.includes(`.`))return`"${e.path}" isn't one option.`;if(`has`in e)return`An option is one value, so it has no fields.`;if(e.expected===null)return`An option has no null value, so "is null" never fits.`;let n=d(e,t,`this profile’s options`);if(n)return n}if(n.when.length>0&&!n.text&&e.length===1)return`It has no wording to send.`}function I(e,t,n){let r=T(t,n);if(r)return r;let i=P({...t,...n});for(let[t,n]of j(e).entries()){let e=F(n,i);if(e)return`Line ${t+1}: ${e}`}}function L(e,t){return e.when!==`unreadable`&&e.when.every(e=>te(e,t))}function R(e,t,n){let r=j(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=N(o);if(!L(r,t))continue;let s=o.map((e,t)=>n(t===0?r.text:M(e)));if(s.includes(void 0))continue;let c=o.flatMap((e,t)=>{let n=s[t];return n?[{text:n,private:typeof e!=`string`||!i}]:[]});a.push({line:e+1,pieces:c})}return a}function z(e,t){if(typeof e!=`string`){if(!Array.isArray(e))throw new p(`config`,`${t} must be a string or an array of lines`);if(e.length===0)throw new p(`config`,`${t} must not be an empty array`);for(let[n,r]of e.entries())if(typeof r!=`string`){if(!Array.isArray(r))throw new p(`config`,`${t}[${n}] must be a string or a list of parts; put { private } inside the list`);h(r,`${t}[${n}]`)}}}function he(e,t){let n=e?.path;if(!n)return;let r=b(n);for(let e of t){let t=e.paths?.find(e=>e!==`*`&&!r.includes(e));if(t!==void 0)return`Tool ${e.name} lists path "${t}", which is not one of ${r.join(`, `)}.`}}function B(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function V(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function ge(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function H(e){return`tools`in e?e.tools.allow:[]}function U(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function _e(e){return`tools`in e?e.tools.parallel:void 0}function ve(e,t,n){return H(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||V(i.paths,n.path)})}function ye(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&V(r.paths,n.path)}):[]}function W(e,t,n){let r=e.get(t);if(r&&r.type!==`builtin`)return{type:`function`,name:r.name,description:r.description,parameters:ae(n&&r.askInputSchema||r.inputSchema)}}function be(e,t,n){let r=[];for(let i of t){let t=W(e,i,n);t&&r.push(t)}return r}function G(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=W(e,n,t.modelBackground);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function xe(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function Se(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function Ce(e,t,n){return ge(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function we(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=H(t).flatMap(t=>e.get(t)??[]),r=he(t.identity.options,n);if(r)throw new p(`config`,`Profile ${t.id}: ${r}`)}function Te(e,t){let n=U(t)?.t2Loader,r=n===void 0?void 0:e.get(n);if(r&&r.type!==`builtin`&&(r.background??`never`)!==`never`)throw new p(`config`,`Profile ${t.id}: tools.t2Loader '${r.name}' sets background, and a loader cannot detach`)}function Ee(e,t,n,r){we(e,t),Te(e,t);let i=ve(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ye(e,t,n,r),o=[...i,...a],s=Ce(e,t,o),c=Se(e,t,o),l=c.filter(t=>B(e,t)),u=n.background!==void 0;return{builtins:s,gated:o,visible:c,executable:l,path:n.path,sessionPermissions:n.sessionPermissions,wire:be(e,c,u),...u?{modelBackground:u}:{}}}function De(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)})),...e.modelBackground?{modelBackground:e.modelBackground}:{}}}async function Oe(e,t,n,r){try{await ke(e,t,n,r)}catch(e){return{crashed:e}}}async function ke(e,t,n,r){let i=U(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new p(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new p(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);K(e,t,a)}function K(e,t,n=[]){for(let r of n){if(!t.gated.includes(r))continue;let n=e.get(r);n?.loadTier===`T2`&&(n.type===`builtin`?xe(e,t,r):G(e,t,r))}t.executable=t.visible.filter(t=>B(e,t))}var Ae=new Set([`__proto__`,`constructor`,`prototype`]);function je(e){if(!se(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Me(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Ae.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=Ne(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;V(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)G(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>B(e,t)),{promoted:a}}function q(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function Ne(e,t,n){if(!H(n).includes(t))return q(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?q(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:q(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):q(`tools.t2Loader attempted to promote unknown tool '${t}'`)}var Pe=new Set([`text`,`image`,`speech`]),Fe=n().regex(/\S/),J=i({mimeType:n(),data:c(),name:n().optional()}),Ie=i({mimeType:n(),uri:n(),name:n().optional()}),Le=i({voice:n().optional(),style:n().optional(),speed:a().positive().optional()});function Re(e){return i(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=b(t);return[e,o(n).optional()]})))}var ze=new Set([`text`,`attachments`,`voice`,`options`,`speech`]);function Be(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,options:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{options:s}:{},...c?{speech:c}:{}},hostInput:r}}function Ve(e,n){let{inputs:r}=e,a={text:Fe};r?.attachments&&(a.attachments=s(t([J,Ie])).optional()),r?.voice&&(a.voice=s(J).optional()),r?.options&&(a.options=Re(r.options).optional()),e.type===`speech`&&(a.speech=Le.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new p(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new p(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(ze.has(e))throw new p(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return i(a)}var Y=l({text:n().optional(),structured:r().optional(),removed:s(l({path:n(),reason:n(),item:r()})).optional(),parts:s(oe).optional(),sources:s(f).optional()});function He(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function Ue(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function X(e,t){if(!Pe.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!He(e))return`it does not take text`;for(let n of H(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(Ue(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function We(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new p(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new p(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=X(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ge(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return H(e).length===0&&!t?`local`:`delegated`}function Z(e){let t=ie(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ee(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:ne(e.media.mimeType)??`document`,mimeType:e.media.mimeType,data:e.media.data,sent:!0}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ke(e,t,n){return{...e,type:`agent`,input:t,output:Y,sources:e=>e.sources??[],...n}}function qe(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function Je(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&Q(i,`${n}.properties.${t}`,r)}function Q(e,t,n){if(!qe(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Je(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&Q(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&Q(e,`${t}.${r}[${i}]`,n)})}}function Ye(e,t){let n=[];if(Q(e,`$`,n),n.length>0)throw new p(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function Xe(t,n=`output`){let r=e(t,{target:`draft-7`,io:n});return delete r.$schema,r.type||=`object`,r}function $(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map($);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=$(e[n]));return t}function Ze(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new p(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}export{k as A,R as C,b as D,A as E,v as M,g as N,T as O,_ as P,z as S,O as T,_e as _,X as a,K as b,Y as c,Ke as d,Be as f,H as g,je as h,Ye as i,de as j,C as k,Z as l,De as m,Xe as n,Ve as o,Oe as p,$ as r,Ge as s,Ze as t,We as u,U as v,I as w,Ee as x,Me as y};