@theoremjs/studio 0.3.5-next.906.g6f050f4 → 0.3.5-next.911.g193d75c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser-connection.d.ts +1 -2
- package/package.json +4 -4
- package/page/assets/{BottomSheet-v4keekfB.js → BottomSheet-gvxs6HLX.js} +1 -1
- package/page/assets/{ConsoleFrame-CHnnxxNA.js → ConsoleFrame-DjKftiM3.js} +1 -1
- package/page/assets/{DateInput-CYFXY_3W.js → DateInput-BpXRJu6W.js} +1 -1
- package/page/assets/{MenuBottomSheet-BR8JYBqn.js → MenuBottomSheet-C-aSCSIv.js} +1 -1
- package/page/assets/{PowerSearchBottomSheet-DSkpQQys.js → PowerSearchBottomSheet-CadUl0hQ.js} +1 -1
- package/page/assets/{RankedBars-C_arZO1h.js → RankedBars-BqvXkuhw.js} +1 -1
- package/page/assets/{SchemaFields-DvOp5_M3.js → SchemaFields-BA_tTlTT.js} +1 -1
- package/page/assets/{TokenizerBottomSheet-DjiTJgA9.js → TokenizerBottomSheet-BVgCEcFv.js} +1 -1
- package/page/assets/{ToolResultCharts-t1kqy-J6.js → ToolResultCharts-Ju_2APDe.js} +1 -1
- package/page/assets/{Toolbar-CkD1V_z_.js → Toolbar-Bodaemo6.js} +1 -1
- package/page/assets/{TraceInspector-CGGxz_g-.js → TraceInspector-CCjkzWyI.js} +2 -2
- package/page/assets/TraceOverview-BtC8GQVd.js +57 -0
- package/page/assets/{_virtual_studio-type-sources-CuPTbB69.js → _virtual_studio-type-sources-CdnMqL-n.js} +115 -66
- package/page/assets/browser-connection-8HG8E7-I.js +1 -0
- package/page/assets/browser-engine-nrFEmQVr.js +16 -0
- package/page/assets/{browser-transport-Dq9itWDy.js → browser-transport-C4b9Cns1.js} +2 -2
- package/page/assets/compile--gO-Z1FH.js +4 -0
- package/page/assets/{encode-files-Dc2wHsb6.js → encode-files-7UPrYBrF.js} +1 -1
- package/page/assets/{export-agent-Y0Y8mdbB.js → export-agent-CJU4yuZq.js} +1 -1
- package/page/assets/{getRadiusAndStrokeWidthFromDot-bzD-VA8b.js → getRadiusAndStrokeWidthFromDot-Ecj-jR5D.js} +1 -1
- package/page/assets/{guardrail-health-BGyQi_jA.js → guardrail-health-DFvepe74.js} +2 -2
- package/page/assets/{guardrail-tester-DbR85sml.js → guardrail-tester-D0nvciLt.js} +1 -1
- package/page/assets/{index-Cfhzi3KD.js → index-DdfSX5Od.js} +18 -18
- package/page/assets/{json-code-D2imJbsd.js → json-code-ChVouP8g.js} +1 -1
- package/page/assets/{labels-provider-CTjEbRdu.js → labels-provider-BO_XYaPQ.js} +1 -1
- package/page/assets/{live-messages-Bp_b714P.js → live-messages-BrXwocbM.js} +1 -1
- package/page/assets/{prompt-row-eETPWTfK.js → prompt-row-D7xmJLxc.js} +1 -1
- package/page/assets/reader-CfENH3jS.js +5 -0
- package/page/assets/registry-BOVP_lQO.js +1 -0
- package/page/assets/{schema-D4bn5YDU.js → schema-dtr41Lr7.js} +2 -2
- package/page/assets/shaped-data-9kDvR1de.js +25 -0
- package/page/assets/{stub-CZ_Xswg8.js → stub-B275bXj-.js} +1 -1
- package/page/assets/{studio-code-pane-lxwvQgJE.js → studio-code-pane-epOb7YCi.js} +3 -3
- package/page/assets/{studio-console-BNOXf-xr.js → studio-console-KObtCJyc.js} +1 -1
- package/page/assets/{studio-decision-C9oxa1xo.js → studio-decision-CJWMloET.js} +1 -1
- package/page/assets/{studio-embedding-D8rA6MOH.js → studio-embedding-CGKFrG_-.js} +1 -1
- package/page/assets/{studio-host-console-XPl__wj7.js → studio-host-console-C5oeUj4u.js} +2 -2
- package/page/assets/studio-labels-EVPkcfTG.js +3 -0
- package/page/assets/{studio-live-B3gN-hIU.js → studio-live-B6Iy_esj.js} +1 -1
- package/page/assets/{studio-map-Cf2DHvn2.js → studio-map-DnuXEuzm.js} +1 -1
- package/page/assets/{studio-trace-replay-BCOqVguH.js → studio-trace-replay-Dxc3ePxC.js} +1 -1
- package/page/assets/{studio-type-checker-BWW15y7M.js → studio-type-checker-Cg2BuLET.js} +1 -1
- package/page/assets/{tool-schema-BMNs-MyH.js → tool-schema-D6i-fwc5.js} +1 -1
- package/page/assets/{trace-record-CS_K7b8l.js → trace-record-DFHRIoSR.js} +1 -1
- package/page/assets/tree-DXvClIpQ.js +3 -0
- package/page/assets/{turn-client-8TS8z-jZ.js → turn-client-Cl1P1QP9.js} +2 -2
- package/page/assets/types-Bl2lxigr.js +1 -0
- package/page/assets/{use-one-call-Ch9fKeMJ.js → use-one-call-BKua0dRg.js} +1 -1
- package/page/assets/{useDismissSearchOnTouchDrag-DJ9Di3hZ.js → useDismissSearchOnTouchDrag-lH0YZH1H.js} +1 -1
- package/page/assets/{workspace-CCtOtOGD.js → workspace-BpEiFb5f.js} +1 -1
- package/page/index.html +17 -17
- package/page/assets/TraceOverview-C3RFiWfu.js +0 -57
- package/page/assets/browser-connection-UWxIyv6u.js +0 -1
- package/page/assets/browser-engine-Ds0-ThtZ.js +0 -16
- package/page/assets/compile-NWqVUG3a.js +0 -4
- package/page/assets/reader-C8mnJAB6.js +0 -5
- package/page/assets/registry-DJBxNVIO.js +0 -1
- package/page/assets/shaped-data-yrTrXPh4.js +0 -25
- package/page/assets/studio-labels-CUJQgb-k.js +0 -3
- package/page/assets/tree-D6WoHLJe.js +0 -3
- package/page/assets/types-D9SHTHld.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{D as e,E as t,T as n,b as r,c as i,d as a,h as o,o as s,p as c,pt as l,s as u,t as d,v as ee}from"./schemas-D7cgkv3L.js";import{Aa as te,Cn as ne,Ki as re,Ma as ie,Na as ae,Q as oe,ga as f,ha as p,ii as m,it as h,mi as g,oi as se,q as ce,ro as _,ut as v}from"./shaped-data-9kDvR1de.js";import{c as y}from"./host-patterns-F-KZIzkF.js";import{d as le,f as ue,i as b,l as de,n as x,s as fe,t as S}from"./schema-dtr41Lr7.js";var pe=n({accepted:p,preparedInput:f});function C(e){return new y(`internal`,e)}function w(e,t,n){return new y(e,t,{copy:{key:`tool.execution_uncertain`},cause:n})}function T(e){return w(`conflict`,`The tool operation is ${e}, so it does not run again until the host settles it`)}async function E(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=f.parse(t(M(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 D=m.tool.transform((e,t)=>e.tool.phase===`complete`||e.tool.phase===`error`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),O=n({finding:t(),data:f.optional(),parts:a(se).optional(),modelText:t().optional(),provenance:ae.optional(),suspicious:a(ie).optional()}),k=m.tool.transform((e,t)=>e.tool.phase===`background`?{...e,tool:e.tool}:(t.addIssue({code:`custom`}),l)),A=n({event:k,replay:n({modelResult:O})}),j=n({event:D,effects:i([`not_started`,`completed`,`unknown`]),replay:n({modelResult:O.optional(),outputRaw:f.optional(),failure:n({code:t(),kind:te,message:t(),error:t().optional(),details:f.optional()}).optional(),awaiting:c().optional(),denied:ee(!0).optional(),callNotStarted:c().optional(),aborted:e([c(),n({reason:t().optional()})]).optional(),pendingInject:a(n({id:t().optional(),messages:a(g),released:r().int().nonnegative().optional()})).optional()})});function M(e){let t=new Set,n=e=>{if(!e||typeof e!=`object`)return e;if(t.has(e))throw C(`Tool operation value has a cycle`);let r=Object.getPrototypeOf(e);if(!Array.isArray(e)&&r!==Object.prototype&&r!==null)throw C(`Tool operation value holds an object that is not plain data`);if(Object.hasOwn(e,`__proto__`))throw C(`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 C(`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 f.parse(n(e))}var N=e([i([`always`,`ask`,`never`]),n({afterMs:r().finite().nonnegative()})]),P=`background`;function F(){return c().optional().describe(_(`tool.background_field`))}function I(e,t){if(e?.background!==`ask`||typeof t!=`object`||!t)return{input:t,asked:!1};let{[P]:n,...r}=t;return{input:r,asked:n===!0}}function L(e,t){let{background:n}=e;if(n!==void 0&&n!==`never`)return n===`always`?`claim`:n===`ask`?I(e,t).asked?`claim`:void 0:n}function R(e,t){return e.type===`agent`?t?.takesSteers(e)?void 0:`steering_off`:`not_agent`}function z(e){let{tool:t,support:n,base:r,labels:i}=e;if(!t||t.type===`builtin`||!n)return;let a=L(t,e.input);if(a===void 0)return;let o=R(t,e.agents);return{at:a,support:n,...o?{refuseSteers:o}:{},trace:n.openTrace(r.callId),reply:()=>{let e={finding:_(`tool.background_started`,{tool:t.name},i)},n=oe(e),a=ce(r,{phase:`background`,readBack:n});return A.parse(M({event:a,replay:{modelResult:e}}))}}}function B(e,t){if(e&&!t?.detach)throw new y(`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 y(`config`,`Tool '${t}' sets background, which a tool answered by the page cannot`);if(!N.safeParse(n).success)throw new y(`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 V(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 H=`after`;function ve(){return a(t()).optional().describe(_(`tool.after_field`))}function U(t,n,r,i){let a=n=>{if(n instanceof s){if(r in n.shape)throw new y(`config`,`Tool '${t}' sets ${r}, and its input already has a field of that name`);return n.safeExtend({[r]:i()})}if(n instanceof d){let e=n.options.map(a);return o(n.def.discriminator,e)}if(n instanceof u)return e(n.options.map(a));throw new y(`config`,`Tool '${t}' sets ${r}, which needs an object input or a union of objects`)};return a(n)}function W(e,t){return U(e,t,H,ve)}function ye(e,t){if(!e.after||typeof t!=`object`||!t)return{input:t,names:[]};let{[H]: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 G=class{value;constructor(e){this.value=e}};function xe(e){return new G(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(_(`tool.page_timed_out`,{},i)):Error(_(`tool.page_no_answer`,{tool:e},i))}}var K=new WeakMap;function q(e,t){let n=K.get(e);n||(n=new WeakMap,K.set(e,n));let r=n.get(t);if(!r){let i=x(e,`input`);b(i,`input`);let a=x(t,`output`);b(a,`output`),r={inputSchema:i,outputSchema:a},n.set(t,r)}return r}function J(e){let{inputSchema:t,outputSchema:n}=q(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?h(n,r[t]):void 0;if(i)throw new y(`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 y(`config`,`Tool "${e}" signs in with slot "${t.slot}" but names no service`)}function Y(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 y(`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 y(`config`,`Tool "${e}" limit needs a whole number of requests above 0 and a window above 0 ms`)}function X(e,t){if(!(t===void 0||Number.isFinite(t)&&t>0))throw new y(`config`,`Tool "${e}" timeoutMs needs a finite number of ms above 0`)}function Z(e,t,n){if(!(n===void 0||Number.isInteger(n)&&n>0))throw new y(`config`,`Tool "${e}" ${t} needs a whole number above 0`)}function Q(e){Z(e.name,`maxResponseBytes`,e.maxResponseBytes);let t=e.imageLimits;t&&(Z(e.name,`imageLimits.count`,t.count),Z(e.name,`imageLimits.bytes`,t.bytes),Z(e.name,`imageLimits.totalBytes`,t.totalBytes),X(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()&&S(e.endpoint),Y(e.name,e.auth,e.mapping?.queryParams),we(e.name,e.limit),X(e.name,e.timeoutMs)):Y(e.name,e.auth),(e.type===`http`||e.type===`mcp`)&&Q(e),e.type===`mcp`&&(Z(e.name,`session.idleMs`,e.session?.idleMs),Z(e.name,`session.max`,e.session?.max));let[t]=re(e);if(t)throw new y(`config`,`Tool "${e.name}" ${t.path} ${t.message}`)}function Te(e){return S(e.endpoint),{...e,type:`http`,...J(e)}}function Ee(e){return{...e,type:`mcp`,...J(e)}}function De(e){let t=e.answeredBy===`page`?Se(e.name):e.handler;if(typeof t!=`function`)throw new y(`config`,`Tool '${e.name}' needs a handler, or answeredBy: 'page'`);return{...e,handler:t,type:`function`,...J(e)}}function Oe(e){if(e.type===`builtin`||e.background!==`ask`)return e;let t=e.input,n=U(e.name,t,`background`,F);return{...e,askInputSchema:q(n,e.output).inputSchema}}function ke(e,t,n){return $(e),Oe(Ae(e,t,n))}function Ae(e,t,n){if(e.type===`builtin`)return e;if(e.type===`agent`){let r=le(e,t,n),i=ne(r),a=fe({type:r.type,...i?{inputs:i}:{}},e),o=e.after?W(e.name,a):a,s=J({...e,input:o,output:de});return ue(e,o,s)}let r=e.after?{...e,input:W(e.name,e.input)}:e;return r.type===`http`?Te(r):r.type===`mcp`?Ee(r):De(r)}function je(e=()=>void 0,t=()=>[]){let n=new Map,r=V(),i=e=>n.get(e),a=t=>{let r=ke(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 y(`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{j as _,be as a,_e as c,I as d,T as f,E as g,pe as h,ye as i,B as l,M as m,je as n,V as o,C as p,G as r,ge as s,$ as t,z as u,A as v,w 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{
|
|
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,ci as ne,ct as re,ft as ie,hn as ae,oi as oe,ot as d,ui as f}from"./shaped-data-9kDvR1de.js";import{c as p}from"./host-patterns-F-KZIzkF.js";var se=`
|
|
2
2
|
|
|
3
|
-
`;function ce(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 le(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=ce(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function m(e,t){let n=le(e,t);if(n)throw new p(`config`,n)}function h(e,t,n){return m(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function g(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 _(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:se,private:!0}),t.push(...n));return t}function v(e){return e.map(e=>e.text).join(``)}function y(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:v(e),private:t}}function ue(e,t){return y(_([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var de=/^[A-Za-z_][\w-]*$/,fe=/\{([A-Za-z_][\w-]*)\}/g,pe=[`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 f(e)?.options??{}}function C(e,t){let n={...x(e),...S(e)};return Object.hasOwn(n,t)?n[t]:void 0}function me(e,t){if(!de.test(e))return`Option "${e}" needs a plain name.`;if(pe.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 w(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=me(n,r);if(i)return i}}function T(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 E(e,t){return Object.hasOwn(e,`path`)&&t.path!==void 0?{path:t.path}:{}}function D(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`);T(e.id,n,`identity.options`,{...t.options,...E(n,t)}),T(e.id,S(e),`inputs.options`,t.input?.options)}function O(e,t){return{...t.options,...E(x(e),t),...t.input?.options}}function k(e,t,n){let r=!0,i=t.replace(fe,(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 A(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function j(e){return typeof e==`string`?e:e.private}function M(e){return ie(e[0]===void 0?``:j(e[0]))}function N(e){let t={};for(let[n,r]of Object.entries(e))t[n]={type:`string`,enum:b(r)};return{type:`object`,properties:t}}function P(e,t){if(e.length===0)return`It has no wording to send.`;let n=M(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=te(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 F(e,t,n){let r=w(t,n);if(r)return r;let i=N({...t,...n});for(let[t,n]of A(e).entries()){let e=P(n,i);if(e)return`Line ${t+1}: ${e}`}}function I(e,t){return e.when!==`unreadable`&&e.when.every(e=>oe(e,t))}function L(e,t,n){let r=A(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=M(o);if(!I(r,t))continue;let s=o.map((e,t)=>n(t===0?r.text:j(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 R(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`);m(r,`${t}[${n}]`)}}}function z(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 he(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 ge(e){return`tools`in e?e.tools.parallel:void 0}function _e(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 ve(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:d(n&&r.askInputSchema||r.inputSchema)}}function G(e,t,n){let r=[];for(let i of t){let t=W(e,i,n);t&&r.push(t)}return r}function K(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 ye(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 be(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function xe(e,t,n){return he(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function Se(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=H(t).flatMap(t=>e.get(t)??[]),r=z(t.identity.options,n);if(r)throw new p(`config`,`Profile ${t.id}: ${r}`)}function Ce(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 we(e,t,n,r){Se(e,t),Ce(e,t);let i=_e(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ve(e,t,n,r),o=[...i,...a],s=xe(e,t,o),c=be(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:G(e,c,u),...u?{modelBackground:u}:{}}}function Te(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 Ee(e,t,n,r){try{await De(e,t,n,r)}catch(e){return{crashed:e}}}async function De(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[]`);q(e,t,a)}function q(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`?ye(e,t,r):K(e,t,r))}t.executable=t.visible.filter(t=>B(e,t))}var Oe=new Set([`__proto__`,`constructor`,`prototype`]);function ke(e){if(!ae(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Ae(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Oe.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=je(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)K(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>B(e,t)),{promoted:a}}function J(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function je(e,t,n){if(!H(n).includes(t))return J(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?J(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:J(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):J(`tools.t2Loader attempted to promote unknown tool '${t}'`)}var Me=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Ne=new Set([`text`,`image`,`speech`]),Pe=n().regex(/\S/),Y=i({mimeType:n(),data:c(),name:n().optional()}),Fe=i({mimeType:n(),uri:n(),name:n().optional()}),Ie=i({voice:n().optional(),style:n().optional(),speed:a().positive().optional()});function Le(e){return i(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=b(t);return[e,o(n).optional()]})))}var Re=new Set([`text`,`attachments`,`voice`,`options`,`speech`]);function ze(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 Be(e,n){let{inputs:r}=e,a={text:Pe};r?.attachments&&(a.attachments=s(t([Y,Fe])).optional()),r?.voice&&(a.voice=s(Y).optional()),r?.options&&(a.options=Le(r.options).optional()),e.type===`speech`&&(a.speech=Ie.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(Re.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 X=l({text:n().optional(),structured:r().optional(),removed:s(l({path:n(),reason:n(),item:r()})).optional(),parts:s(ee).optional(),sources:s(u).optional()});function Ve(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function He(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Z(e,t){if(!Ne.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!Ve(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(He(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Ue(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=Z(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function We(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 Ge(e){let t=re(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ne(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ke(e,t,n){return{...e,type:`agent`,input:t,output:X,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{C as A,R as C,k as D,D as E,g as F,ue as M,_ as N,b as O,h as P,we as S,F as T,H as _,Me as a,Ae as b,We as c,Ue as d,Ke as f,ke as g,Te as h,Ye as i,O as j,w as k,X as l,Ee as m,Xe as n,Z as o,ze as p,$ as r,Be as s,Ze as t,Ge as u,ge as v,L as w,q as x,U as y};
|
|
3
|
+
`;function ce(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 le(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=ce(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function m(e,t){let n=le(e,t);if(n)throw new p(`config`,n)}function h(e,t,n){return m(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function g(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 _(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:se,private:!0}),t.push(...n));return t}function v(e){return e.map(e=>e.text).join(``)}function y(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:v(e),private:t}}function ue(e,t){return y(_([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}var de=/^[A-Za-z_][\w-]*$/,fe=/\{([A-Za-z_][\w-]*)\}/g,pe=[`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 me(e,t){if(!de.test(e))return`Option "${e}" needs a plain name.`;if(pe.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 w(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=me(n,r);if(i)return i}}function T(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 E(e,t){return Object.hasOwn(e,`path`)&&t.path!==void 0?{path:t.path}:{}}function D(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`);T(e.id,n,`identity.options`,{...t.options,...E(n,t)}),T(e.id,S(e),`inputs.options`,t.input?.options)}function O(e,t){return{...t.options,...E(x(e),t),...t.input?.options}}function k(e,t,n){let r=!0,i=t.replace(fe,(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 A(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function j(e){return typeof e==`string`?e:e.private}function M(e){return re(e[0]===void 0?``:j(e[0]))}function N(e){let t={};for(let[n,r]of Object.entries(e))t[n]={type:`string`,enum:b(r)};return{type:`object`,properties:t}}function P(e,t){if(e.length===0)return`It has no wording to send.`;let n=M(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 F(e,t,n){let r=w(t,n);if(r)return r;let i=N({...t,...n});for(let[t,n]of A(e).entries()){let e=P(n,i);if(e)return`Line ${t+1}: ${e}`}}function I(e,t){return e.when!==`unreadable`&&e.when.every(e=>te(e,t))}function L(e,t,n){let r=A(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=M(o);if(!I(r,t))continue;let s=o.map((e,t)=>n(t===0?r.text:j(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 R(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`);m(r,`${t}[${n}]`)}}}function z(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 he(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 ge(e){return`tools`in e?e.tools.parallel:void 0}function _e(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 ve(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:ie(n&&r.askInputSchema||r.inputSchema)}}function G(e,t,n){let r=[];for(let i of t){let t=W(e,i,n);t&&r.push(t)}return r}function K(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 ye(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 be(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function xe(e,t,n){return he(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function Se(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=H(t).flatMap(t=>e.get(t)??[]),r=z(t.identity.options,n);if(r)throw new p(`config`,`Profile ${t.id}: ${r}`)}function Ce(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 we(e,t,n,r){Se(e,t),Ce(e,t);let i=_e(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ve(e,t,n,r),o=[...i,...a],s=xe(e,t,o),c=be(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:G(e,c,u),...u?{modelBackground:u}:{}}}function Te(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 Ee(e,t,n,r){try{await De(e,t,n,r)}catch(e){return{crashed:e}}}async function De(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[]`);q(e,t,a)}function q(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`?ye(e,t,r):K(e,t,r))}t.executable=t.visible.filter(t=>B(e,t))}var Oe=new Set([`__proto__`,`constructor`,`prototype`]);function ke(e){if(!ae(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Ae(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Oe.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=je(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)K(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>B(e,t)),{promoted:a}}function J(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function je(e,t,n){if(!H(n).includes(t))return J(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?J(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:J(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):J(`tools.t2Loader attempted to promote unknown tool '${t}'`)}var Me=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Ne=new Set([`text`,`image`,`speech`]),Pe=n().regex(/\S/),Y=i({mimeType:n(),data:c(),name:n().optional()}),Fe=i({mimeType:n(),uri:n(),name:n().optional()}),Ie=i({voice:n().optional(),style:n().optional(),speed:a().positive().optional()});function Le(e){return i(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=b(t);return[e,o(n).optional()]})))}var Re=new Set([`text`,`attachments`,`voice`,`options`,`speech`]);function ze(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 Be(e,n){let{inputs:r}=e,a={text:Pe};r?.attachments&&(a.attachments=s(t([Y,Fe])).optional()),r?.voice&&(a.voice=s(Y).optional()),r?.options&&(a.options=Le(r.options).optional()),e.type===`speech`&&(a.speech=Ie.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(Re.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 X=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 Ve(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function He(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Z(e,t){if(!Ne.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!Ve(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(He(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Ue(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=Z(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function We(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 Ge(e){let t=ne(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:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function Ke(e,t,n){return{...e,type:`agent`,input:t,output:X,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{C as A,R as C,k as D,D as E,g as F,ue as M,_ as N,b as O,h as P,we as S,F as T,H as _,Me as a,Ae as b,We as c,Ue as d,Ke as f,ke as g,Te as h,Ye as i,O as j,w as k,X as l,Ee as m,Xe as n,Z as o,ze as p,$ as r,Be as s,Ze as t,Ge as u,ge as v,L as w,q as x,U as y};
|