@theoremjs/studio 0.3.4-next.649.gf83cea1 → 0.3.4-next.671.gfa09ab2

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 (92) hide show
  1. package/README.md +8 -5
  2. package/cookbooks/catalog.js +18 -5
  3. package/cookbooks/tools.js +3 -3
  4. package/mod.d.ts +3 -3
  5. package/mod.js +3 -3
  6. package/package.json +4 -4
  7. package/page/assets/Banner-DEVAsFER.js +4 -0
  8. package/page/assets/{ConsoleFrame-B7ruuMVo.js → ConsoleFrame-CqUUcrR4.js} +1 -1
  9. package/page/assets/{MenuBottomSheet-Bso4osRe.js → MenuBottomSheet-DOa09vl1.js} +1 -1
  10. package/page/assets/{SchemaFields-DEqlS2cS.js → SchemaFields-CMwMU1Px.js} +1 -1
  11. package/page/assets/{ToolResultCharts-DV0Cds5H.js → ToolResultCharts-CW23-D1x.js} +1 -1
  12. package/page/assets/{TraceInspector-CBybmNzh.js → TraceInspector-h030OQ82.js} +1 -1
  13. package/page/assets/{TraceOverview-CO9Oh2_v.js → TraceOverview-BsON_uZj.js} +1 -1
  14. package/page/assets/{_virtual_studio-type-sources-hU0nQlME.js → _virtual_studio-type-sources-BwSqfSwd.js} +17 -3
  15. package/page/assets/{browser-connection-Dim6ghw7.js → browser-connection-DSUHVCT5.js} +2 -2
  16. package/page/assets/browser-engine-Cf6d-zNH.js +11 -0
  17. package/page/assets/browser-transport-BK4cbTE_.js +45 -0
  18. package/page/assets/{crypto-CgKfdKF3.js → crypto-CD14HeXH.js} +1 -1
  19. package/page/assets/{encode-files-mmy8V0Ya.js → encode-files-DhoC5hWG.js} +1 -1
  20. package/page/assets/{export-agent-CuUh1bR8.js → export-agent-CaHsJPsM.js} +1 -1
  21. package/page/assets/{guardrail-tester-Bi8kF5JO.js → guardrail-tester-BDhFLvT5.js} +1 -1
  22. package/page/assets/index-CqwmMJ4C.js +145 -0
  23. package/page/assets/{live-messages-MuPbOsZr.js → live-messages-CiLmR89m.js} +1 -1
  24. package/page/assets/reader-DrOfMM8I.js +5 -0
  25. package/page/assets/{shaped-data-BIkh6Bis.js → shaped-data-H1miOZm2.js} +1 -1
  26. package/page/assets/{stub-fr8Q8_U3.js → stub-nxRsh1jo.js} +4 -4
  27. package/page/assets/{studio-code-pane-DnKDFRIG.js → studio-code-pane-C1wH63Y2.js} +3 -3
  28. package/page/assets/{studio-console-C8I1MOzW.js → studio-console-DRzo4yTy.js} +1 -1
  29. package/page/assets/{studio-decision-wzSt60HL.js → studio-decision-C7QWMm7Q.js} +1 -1
  30. package/page/assets/{studio-embedding-DOOXOgyT.js → studio-embedding-D8KroBXY.js} +1 -1
  31. package/page/assets/{studio-host-console-Dz8tEAST.js → studio-host-console-HkX8BerX.js} +2 -2
  32. package/page/assets/{studio-labels-C5heV8lN.js → studio-labels-6w1SKC2D.js} +1 -1
  33. package/page/assets/studio-live-BmVeXAu4.js +5 -0
  34. package/page/assets/{studio-map-DzrF-FCH.js → studio-map-5ZU1nicW.js} +1 -1
  35. package/page/assets/studio-session-CjUQSXx0.js +1 -0
  36. package/page/assets/studio-trace-replay-CSbJSN5e.js +3 -0
  37. package/page/assets/{studio-type-checker-DCAG9kT0.js → studio-type-checker-BbUSqqOS.js} +1 -1
  38. package/page/assets/tool-schema-BmRYaywn.js +17 -0
  39. package/page/assets/{trace-record-CGww68wU.js → trace-record-DxgSKmYY.js} +1 -1
  40. package/page/assets/tree-3N-1RPZz.js +3 -0
  41. package/page/assets/{turn-client-Bn130DZC.js → turn-client-DN8PawJr.js} +2 -2
  42. package/page/assets/{use-one-call-B_dBxZ07.js → use-one-call-Br2IVJLU.js} +1 -1
  43. package/page/assets/{use-second-ticker-DtnVtLQo.js → use-second-ticker-CEwOSS-d.js} +1 -1
  44. package/page/assets/{workspace-Cy2likdd.js → workspace-CTSW941G.js} +1 -1
  45. package/page/index.html +16 -16
  46. package/replay.d.ts +13 -8
  47. package/replay.js +33 -31
  48. package/run-payload.d.ts +20 -6
  49. package/run-payload.js +85 -13
  50. package/runtime-scope.js +1 -0
  51. package/runtime.js +1 -0
  52. package/server/project.js +5 -32
  53. package/transport.d.ts +1 -3
  54. package/transport.js +0 -9
  55. package/ui/lib/acting-as.js +1 -6
  56. package/ui/lib/run-keys.d.ts +15 -5
  57. package/ui/lib/run-keys.js +80 -16
  58. package/ui/lib/studio-conversation.d.ts +2 -3
  59. package/ui/lib/studio-conversation.js +28 -65
  60. package/ui/lib/studio-keep.d.ts +34 -0
  61. package/ui/lib/studio-keep.js +202 -0
  62. package/ui/lib/studio-map-kept.d.ts +2 -2
  63. package/ui/lib/studio-map-kept.js +5 -10
  64. package/ui/lib/studio-open.d.ts +1 -1
  65. package/ui/lib/studio-open.js +5 -5
  66. package/ui/lib/studio-page.js +1 -7
  67. package/ui/lib/studio-restore.d.ts +2 -3
  68. package/ui/lib/studio-restore.js +8 -48
  69. package/ui/lib/studio-run-open.d.ts +10 -5
  70. package/ui/lib/studio-run-open.js +18 -9
  71. package/ui/lib/studio-session.d.ts +38 -5
  72. package/ui/lib/studio-session.js +133 -3
  73. package/ui/lib/studio-store.js +8 -30
  74. package/ui/profile-editor.js +3 -6
  75. package/ui/studio-compare.js +237 -48
  76. package/ui/studio-run.js +29 -15
  77. package/ui/studio-screen.d.ts +1 -1
  78. package/ui/studio-screen.js +8 -9
  79. package/ui/studio-trace-replay.js +39 -14
  80. package/vite.mjs +1 -1
  81. package/page/assets/Banner-DnfOgQq4.js +0 -4
  82. package/page/assets/browser-engine-BQs_4RXH.js +0 -11
  83. package/page/assets/browser-transport-K6LWGuCA.js +0 -45
  84. package/page/assets/index-8zuMVtQh.js +0 -145
  85. package/page/assets/reader-YWCb-VWE.js +0 -5
  86. package/page/assets/studio-live-ed1SR-Py.js +0 -5
  87. package/page/assets/studio-session-yEqFQo5o.js +0 -1
  88. package/page/assets/studio-trace-replay-WLO52a22.js +0 -3
  89. package/page/assets/tool-schema-BJnLgvo3.js +0 -17
  90. package/page/assets/tree-CvHjrQ-G.js +0 -3
  91. package/run-payload-core.d.ts +0 -28
  92. package/run-payload-core.js +0 -117
@@ -5106,6 +5106,11 @@ export interface ProtocolDefinition<O = unknown, S = unknown> {
5106
5106
  description: string;
5107
5107
  /** The path each profile type uses. A type with no entry is not served. */
5108
5108
  endpoints: Partial<Record<ModelProfileType, string>>;
5109
+ /**
5110
+ * The \`gen_ai.operation.name\` a call to each endpoint has, e.g. \`'chat'\`: one per endpoint. Use a
5111
+ * GenAI semconv well-known value where one applies.
5112
+ */
5113
+ operationNames: Partial<Record<ModelProfileType, string>>;
5109
5114
  /** Every field a binding may set, each described. */
5110
5115
  options: z.ZodType<O>;
5111
5116
  continuation?: Continuation<S>;
@@ -5167,6 +5172,8 @@ export interface ProtocolExtension<E = unknown, S = unknown> extends Pick<Protoc
5167
5172
  options?: z.ZodObject & z.ZodType<E>;
5168
5173
  /** Its own paths, where they differ from the base's. */
5169
5174
  endpoints?: Partial<Record<ModelProfileType, string>>;
5175
+ /** Its own operation names, where they differ from the base's. */
5176
+ operationNames?: Partial<Record<ModelProfileType, string>>;
5170
5177
  /** What it adds to the base's request (or a WebSocket's first frame), and the tools it wrote. */
5171
5178
  body?(body: JsonObject, at: ExtensionBodyAt<E>): {
5172
5179
  body: JsonObject;
@@ -6077,6 +6084,8 @@ export interface ResolvedGeneration extends ProviderGenerationConfig {
6077
6084
  execution?: ToolExecutionCoordinator;
6078
6085
  pageExecution?: PageToolExecution;
6079
6086
  transport: ProviderTransport;
6087
+ /** The protocol's \`gen_ai.operation.name\` for this profile type; absent when no provider is registered for the binding. */
6088
+ operationName?: string;
6080
6089
  tools: TurnToolSnapshot;
6081
6090
  sessionPermissions?: string[];
6082
6091
  history?: TurnHistoryMessage[];
@@ -7928,7 +7937,7 @@ declare function ownToolsWithout(own: OwnTools | undefined, innocent?: readonly
7928
7937
  export type { NamePattern, OwnTools };
7929
7938
  export { namePatterns, ownToolsWithout, toolLeakSpans };
7930
7939
  `,"file:///node_modules/@theoremjs/agents/src/observability/spans.d.ts":`declare const OMIT_INJECTION = "[omitted - injection]";
7931
- declare const OMIT_SENSITIVE = "[omitted -sensitive]";
7940
+ declare const OMIT_SENSITIVE = "[omitted - sensitive]";
7932
7941
  declare const OMIT_CANARY = "[omitted - canary]";
7933
7942
  declare const OMIT_PROMPT = "[omitted - instructions]";
7934
7943
  type RedactKind = 'injection' | 'sensitive' | 'canary' | 'prompt' | 'image' | 'link' | 'tool' | 'directive' | 'host';
@@ -8925,6 +8934,8 @@ export declare function keySlotsOf(provider: {
8925
8934
  export declare function bindingServe(provider: RegisteredProvider, binding: ModelBinding | DecisionModelBinding): RegisteredProvider['serves'][number];
8926
8935
  /** The protocol a binding speaks on its provider. */
8927
8936
  export declare function protocolOf(provider: RegisteredProvider, binding: ModelBinding | DecisionModelBinding): Protocol;
8937
+ /** The \`gen_ai.operation.name\` of a call the binding makes for \`profileType\`. */
8938
+ export declare function operationNameOf(provider: RegisteredProvider, binding: ModelBinding | DecisionModelBinding, profileType: ModelProfileType): string | undefined;
8928
8939
  /**
8929
8940
  * The one place a binding meets its provider, once, at registration, for fit only. Returns the
8930
8941
  * binding with its options parsed; changes nothing in place.
@@ -9779,8 +9790,9 @@ export type LabelTemplate = string | readonly string[];
9779
9790
  /** A tool's name as a label shows it: \`manage_alert\` reads "manage alert". */
9780
9791
  export declare function toolNameInWords(name: string): string;
9781
9792
  /**
9782
- * Fills each \`{path}\` or \`{path|fallback}\` from the call. Only text and numbers fill; a line fits
9783
- * when every placeholder has a value or a fallback and its \`when\` holds. A list shows its first
9793
+ * Fills each \`{path}\`, \`{path|fallback}\` or \`{count one|other}\` from the call. Only text and numbers
9794
+ * fill, and a count fills only from a number; a line fits when every placeholder has a value or a
9795
+ * fallback and its \`when\` holds. A list shows its first
9784
9796
  * line that fits, and a run of \`+\` lines shows every member that fits, joined in words. When no
9785
9797
  * line fits the label is \`undefined\`, and the transcript names the tool.
9786
9798
  */
@@ -11359,6 +11371,8 @@ declare function startCallTrace(open: (name: string, options: SpanOptions) => Sp
11359
11371
  usage: CallUsage;
11360
11372
  binding: ModelBinding | undefined;
11361
11373
  transport: ProviderTransport;
11374
+ /** The protocol's \`gen_ai.operation.name\`; absent when no provider is registered for the binding. */
11375
+ operation: string | undefined;
11362
11376
  step: number;
11363
11377
  /** The runner's validation attempt; Live has none. */
11364
11378
  attempt?: number;
@@ -1,3 +1,3 @@
1
- import{C as e,E as t,O as n,T as r,l as i,o as a,u as o,v as s,w as c,y as l}from"./schemas-BQ9Jydzb.js";import{Fn as ee,H as te,Jn as ne,Ln as re,Wt as ie,gn as u,hn as ae,in as oe,mn as d,nn as se,pn as ce,tn as le,vn as f,zn as ue,zt as de}from"./tool-schema-BJnLgvo3.js";import{c as p}from"./host-patterns-F-KZIzkF.js";import{A as fe,Lr as m,Mn as pe,Nn as me,Nr as he,Rr as ge,Un as h,an as _e,er as ve,fn as ye,jn as be,lr as xe,pn as Se,tn as Ce,tr as we,vn as Te,vr as Ee,wr as De}from"./shaped-data-BIkh6Bis.js";import{a as Oe,n as ke}from"./live-ingress-OuSlQ6q7.js";var Ae=2,je=4,Me=3,Ne=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,Pe=/^[A-Za-z0-9+/]*={0,2}$/,Fe=new Set([`text/csv`,`text/plain`,`text/markdown`]);function g(e){let{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}=e;if(t&&n&&r)return{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}}function Ie(e,t){if(t.limitsByMime){let n=f(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function _(e){return`uri`in e}function Le(e){if(e.type===`speech`)throw new p(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new p(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new p(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=g(e.inputs??{});if(!t)throw new p(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function Re(e){let t=0;return e.endsWith(`==`)?t=Ae:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Me/je)-t}function ze(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function Be(e){return e.replace(Ne,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function Ve(e,t,n){let r=ze(t);return e===`text/csv`&&(r=Be(r)),new TextEncoder().encode(n.read(r))}function He(e,t){return t?{...e,fileName:t}:e}function v(e,t,n){return t.filter(t=>!d(e,t.mimeType)).map(e=>He({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function Ue(e,t){let n=[];e.length>t.maxFiles&&n.push({code:`too_many_files`,params:{maxFiles:t.maxFiles}});let r=0;for(let i of e){if(i.sizeBytes===void 0)continue;let e=Ie(i.mimeType,t);i.sizeBytes>e&&n.push(He({code:`file_too_large`,params:{maxBytes:e}},i.name)),r+=i.sizeBytes}return r>t.maxTurnBytes&&n.push({code:`turn_too_large`,params:{maxTurnBytes:t.maxTurnBytes}}),n}function y(e,t,n){let r=[];return t.length>0&&!e.attachments&&r.push({code:`attachments_not_accepted`,params:{channel:`attachment`}}),n.length>0&&!e.voice&&r.push({code:`voice_not_accepted`,params:{channel:`voice`}}),r.length>0||t.length===0&&n.length===0?r:(e.attachments&&r.push(...v(e.attachments,t,`attachment`)),e.voice&&r.push(...v(e.voice,n,`voice`)),e.limits?[...r,...Ue([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var We={mime_not_allowed:`attachments.mime_not_allowed`,too_many_files:`attachments.too_many_files`,too_many_of_kind:`attachments.too_many_of_kind`,file_too_large:`attachments.file_too_large`,turn_too_large:`attachments.turn_too_large`,attachments_not_accepted:`attachments.not_accepted`,voice_not_accepted:`attachments.not_accepted`,limits_unconfigured:`attachments.limits_unconfigured`};function b(e){let t={};for(let[n,r]of Object.entries(e.params??{}))r!==void 0&&(t[n]=r);return e.fileName!==void 0&&(t.fileName=e.fileName),{key:We[e.code],params:t}}function Ge(e,t){let n=b(e);return m(n.key,n.params,t)}function x(e){return new p(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(b)})}function S(e){if(!Pe.test(e))throw new p(`request`,`attachment data must be base64`);return Re(e)}function C(e){let t={mimeType:e.mimeType,name:e.name};return _(e)||(t.sizeBytes=S(e.data)),t}function Ke(e,t,n){if(!qe(t,n))return;let r=Le(e),i=y({attachments:ae(e,`attachments`),voice:ae(e,`voice`),limits:r},(t??[]).map(C),(n??[]).map(C));if(i.length>0)throw x(i)}function w(e,t){if(_(e))return e;let{mimeType:n,data:r}=e;if(!Fe.has(f(n)))return e;let i=Ve(n,ve(r),t);return{...e,data:we(i)}}function qe(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Je(e,t,n,r){return Ke(e,t,n),{attachments:t?.length?t.map(e=>w(e,r.attachment)):t,voice:n?.length?n.map(e=>w(e,r.voice)):n}}var Ye=`
1
+ import{C as e,E as t,O as n,T as r,l as i,o as a,u as o,v as s,w as c,y as l}from"./schemas-BQ9Jydzb.js";import{Bn as ee,H as te,In as ne,Rn as re,Wt as ie,Yn as ae,_n as u,gn as oe,hn as d,in as se,mn as ce,on as le,rn as ue,yn as f,zt as de}from"./tool-schema-BmRYaywn.js";import{c as p}from"./host-patterns-F-KZIzkF.js";import{A as fe,Lr as m,Mn as pe,Nn as me,Nr as he,Rr as ge,Un as h,an as _e,er as ve,fn as ye,jn as be,lr as xe,pn as Se,tn as Ce,tr as we,vn as Te,vr as Ee,wr as De}from"./shaped-data-H1miOZm2.js";import{a as Oe,n as ke}from"./live-ingress-OuSlQ6q7.js";var Ae=2,je=4,Me=3,Ne=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,Pe=/^[A-Za-z0-9+/]*={0,2}$/,Fe=new Set([`text/csv`,`text/plain`,`text/markdown`]);function g(e){let{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}=e;if(t&&n&&r)return{maxFiles:t,maxBytes:n,maxTurnBytes:r,limitsByMime:i}}function Ie(e,t){if(t.limitsByMime){let n=f(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function _(e){return`uri`in e}function Le(e){if(e.type===`speech`)throw new p(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new p(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new p(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=g(e.inputs??{});if(!t)throw new p(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function Re(e){let t=0;return e.endsWith(`==`)?t=Ae:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Me/je)-t}function ze(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function Be(e){return e.replace(Ne,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function Ve(e,t,n){let r=ze(t);return e===`text/csv`&&(r=Be(r)),new TextEncoder().encode(n.read(r))}function He(e,t){return t?{...e,fileName:t}:e}function v(e,t,n){return t.filter(t=>!d(e,t.mimeType)).map(e=>He({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function Ue(e,t){let n=[];e.length>t.maxFiles&&n.push({code:`too_many_files`,params:{maxFiles:t.maxFiles}});let r=0;for(let i of e){if(i.sizeBytes===void 0)continue;let e=Ie(i.mimeType,t);i.sizeBytes>e&&n.push(He({code:`file_too_large`,params:{maxBytes:e}},i.name)),r+=i.sizeBytes}return r>t.maxTurnBytes&&n.push({code:`turn_too_large`,params:{maxTurnBytes:t.maxTurnBytes}}),n}function y(e,t,n){let r=[];return t.length>0&&!e.attachments&&r.push({code:`attachments_not_accepted`,params:{channel:`attachment`}}),n.length>0&&!e.voice&&r.push({code:`voice_not_accepted`,params:{channel:`voice`}}),r.length>0||t.length===0&&n.length===0?r:(e.attachments&&r.push(...v(e.attachments,t,`attachment`)),e.voice&&r.push(...v(e.voice,n,`voice`)),e.limits?[...r,...Ue([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var We={mime_not_allowed:`attachments.mime_not_allowed`,too_many_files:`attachments.too_many_files`,too_many_of_kind:`attachments.too_many_of_kind`,file_too_large:`attachments.file_too_large`,turn_too_large:`attachments.turn_too_large`,attachments_not_accepted:`attachments.not_accepted`,voice_not_accepted:`attachments.not_accepted`,limits_unconfigured:`attachments.limits_unconfigured`};function b(e){let t={};for(let[n,r]of Object.entries(e.params??{}))r!==void 0&&(t[n]=r);return e.fileName!==void 0&&(t.fileName=e.fileName),{key:We[e.code],params:t}}function Ge(e,t){let n=b(e);return m(n.key,n.params,t)}function x(e){return new p(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(b)})}function S(e){if(!Pe.test(e))throw new p(`request`,`attachment data must be base64`);return Re(e)}function C(e){let t={mimeType:e.mimeType,name:e.name};return _(e)||(t.sizeBytes=S(e.data)),t}function Ke(e,t,n){if(!qe(t,n))return;let r=Le(e),i=y({attachments:oe(e,`attachments`),voice:oe(e,`voice`),limits:r},(t??[]).map(C),(n??[]).map(C));if(i.length>0)throw x(i)}function w(e,t){if(_(e))return e;let{mimeType:n,data:r}=e;if(!Fe.has(f(n)))return e;let i=Ve(n,ve(r),t);return{...e,data:we(i)}}function qe(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Je(e,t,n,r){return Ke(e,t,n),{attachments:t?.length?t.map(e=>w(e,r.attachment)):t,voice:n?.length?n.map(e=>w(e,r.voice)):n}}var Ye=`
2
2
 
3
- `;function Xe(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 T(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=Xe(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function E(e,t){let n=T(e,t);if(n)throw new p(`config`,n)}function Ze(e,t,n){return E(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Qe(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(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Ye,private:!0}),t.push(...n));return t}function et(e){return e.map(e=>e.text).join(``)}function tt(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:et(e),private:t}}function nt(e,t){return tt($e([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}function D(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function O(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function k(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function rt(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function A(e){return`tools`in e?e.tools.allow:[]}function j(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function it(e){return`tools`in e?e.tools.parallel:void 0}function at(e,t,n){return A(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||k(i.paths,n.path)})}function ot(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&k(r.paths,n.path)}):[]}function M(e,t){let n=e.get(t);if(n&&n.type!==`builtin`)return{type:`function`,name:n.name,description:n.description,parameters:n.inputSchema}}function st(e,t){let n=[];for(let r of t){let t=M(e,r);t&&n.push(t)}return n}function N(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=M(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function ct(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 lt(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function ut(e,t,n){return rt(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function P(e,t,n,r){let i=at(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ot(e,t,n,r),o=[...i,...a],s=ut(e,t,o),c=lt(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>O(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:st(e,c)}}async function dt(e,t,n,r){let i=P(e,t,n,r);return await F(e,i,t,n),i}function ft(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)}))}}async function F(e,t,n,r){let i=j(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[]`);for(let n of a){if(!t.gated.includes(n))continue;let r=e.get(n);r?.loadTier===`T2`&&(r.type===`builtin`?ct(e,t,n):N(e,t,n))}t.executable=t.visible.filter(t=>O(e,t))}var pt=new Set([`__proto__`,`constructor`,`prototype`]);function mt(e){if(!fe(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function ht(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||pt.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=gt(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;k(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)N(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>O(e,t)),{promoted:a}}function I(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function gt(e,t,n){if(!A(n).includes(t))return I(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?I(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:I(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):I(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function L(e){return Array.isArray(e)?[...e]:e.choices.map(e=>e.value)}function _t(e){return Array.isArray(e)?{choices:e.map(e=>({value:e}))}:{...e.label!==void 0&&e.label!==``?{label:e.label}:{},choices:e.choices.map(e=>({value:e.value,...e.description!==void 0&&e.description!==``?{description:e.description}:{}}))}}function R(e){if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,_t(t)]))}function z(e){return e?.slots?{...e,slots:R(e.slots)}:e}function B(e){return e==null}function V(e){return B(e)||typeof e!=`object`||Array.isArray(e)?null:e}function H(e){let t=V(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function U(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function W(e){let t=e.properties;return V(t)??{}}function vt(e,t){return e?`${e}.${t}`:t}function G(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function yt(e,t,n,r,i){if(!n)return;let a=await n(t,r);a.isValid||i.push({path:e,error:a.error||a.finding||`Validation failed for '${e}'`})}async function bt(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(B(r)){i&&G(t,s);return}await yt(t,r,a?.[t],o,s);let c=H(n),l=c?V(r):null;c&&l&&await K(c,l,t,a,o,s)}async function K(e,t,n,r,i,a){let o=W(e),s=new Set(U(e)),c=new Set([...Object.keys(o),...s]),l=V(t);for(let e of c)await bt({path:vt(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function xt(e,t,n,r){let i=H(e);if(!i)throw new p(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!V(t)){for(let e of U(i))G(e,a);return a}return await K(i,t,``,n,r,a),a}function St(e,t){let n=e;for(let e of t.split(`.`)){let t=H(n);if(!t)return!1;let r=W(t);if(!Object.hasOwn(r,e)&&!U(t).includes(e))return!1;n=r[e]}return!0}function Ct(e){return e.map(e=>e.error).join(`; `)}function wt(e,t){let n=e;for(let e of t.split(`.`))n=V(n)?.[e];return n}function q(e,t,n){let[r,...i]=t.split(`.`),a=V(e)??{};return r===void 0?e:{...a,[r]:i.length?q(a[r],i.join(`.`),n):n}}async function Tt(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=wt(e,i);if(Array.isArray(t))for(let[e,o]of t.entries()){let t=await a.check(o,n);t.isValid||r.push({path:i,index:e,item:o,reason:t.error||t.finding||`Validation failed for '${i}'`,onFail:a.onFail})}}return r}function Et(e,t){let n=e;for(let e of t.split(`.`)){let t=H(n);if(!t)return;n=W(t)[e]}let r=V(n);if(r?.type===`array`)return V(r.items)??void 0}var Dt=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Ot=new Set([`text`,`image`,`speech`]),kt=c().regex(/\S/),At=e({mimeType:c(),data:o(),name:c().optional()}),jt=e({mimeType:c(),uri:c(),name:c().optional()}),Mt=e({voice:c().optional(),style:c().optional(),speed:s().positive().optional()});function Nt(t){return e(Object.fromEntries(Object.entries(t).map(([e,t])=>{let n=L(t);return[e,a(n).optional()]})))}var Pt=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function Ft(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function It(t,n){let{inputs:a}=t,o={text:kt};a?.attachments&&(o.attachments=i(r([At,jt])).optional()),a?.voice&&(o.voice=i(At).optional()),a?.slots&&(o.slots=Nt(a.slots).optional()),t.type===`speech`&&(o.speech=Mt.optional());for(let e of n?.hostOnly??[]){if(!o[e])throw new p(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete o[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=o[e];if(!r)throw new p(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);o[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(Pt.has(e))throw new p(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);o[e]=t}return e(o)}var Lt=l({text:c().optional(),structured:t().optional(),removed:i(l({path:c(),reason:c(),item:t()})).optional(),parts:i(ee).optional(),sources:i(ue).optional()});function Rt(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function zt(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Bt(e,t){if(!Ot.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!Rt(e))return`it does not take text`;for(let n of A(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(zt(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Vt(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=Bt(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ht(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return A(e).length===0&&!t?`local`:`delegated`}function Ut(e){let t=re(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=de(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 Wt(e,t,n){return{...e,type:`agent`,input:t,output:Lt,sources:e=>e.sources??[],...n}}function Gt(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 Kt(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`&&J(i,`${n}.properties.${t}`,r)}function J(e,t,n){if(!Gt(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Kt(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&J(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`&&J(e,`${t}.${r}[${i}]`,n)})}}function qt(e,t){let n=[];if(J(e,`$`,n),n.length>0)throw new p(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function Jt(e,t=`output`){let r=n(e,{target:`draft-7`,io:t});return delete r.$schema,r.type||=`object`,r}function Y(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Y);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=Y(e[n]));return t}function Yt(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`)}function Xt(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new p(`config`,m(`provider.binding_identity`))}function Zt(e){sn(e.id,e.models),Q(e.id,e.observability),Jn(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))ln(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:cn(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Qt(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new p(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function $t(e,t,n){if(Qt(e,t,n,se),Xt(e,t,n,`decision`),`retry`in n)throw new p(`config`,`Profile ${e} model '${t}': a decision binding takes no retry; a decision retries only a transient failure, by the kernel's rule`);if(n.timeoutMs!==void 0&&(!Number.isFinite(n.timeoutMs)||n.timeoutMs<=0))throw new p(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function en(e){let t=e.models?D(e.models):void 0;if(!t)throw new p(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);$t(e.id,t,e.models[t])}function tn(e){if(e.inputs.state!==`json`)throw new p(`config`,`Profile ${e.id}: decision inputs.state must be 'json'`);let t=e.inputs.maxStateBytes;if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw new p(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new p(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function nn(e){return en(e),tn(e),Q(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function rn(e){return e===void 0?{}:{parallel:e}}function an(e){return on(e.id,e.tools),Q(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...rn(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function on(e,t){if(!Array.isArray(t.allow))throw new p(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function sn(e,t){if(Object.keys(t).length===0)throw new p(`config`,`Profile ${e} must declare at least one model`)}function cn(e,t){let n=t.defaultModel??D(t.models);if(!n)throw new p(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new p(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function ln(e,t,n){un(e,t,n),Qt(e,t,n,oe),un(e,t,n)}function un(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new p(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!Te.includes(i))throw new p(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${Te.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new p(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new p(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new p(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function dn(e){return{providerContinuation:e.providerContinuation?ne.parse(e.providerContinuation):{},models:e.models,defaultModel:cn(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function X(e,t,n){if(n?.length){for(let r of n)if(!ie(r))throw new p(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function fn(e,t){t&&(X(e,`allowContinue`,t.allowContinue),X(e,`autoContinue`,t.autoContinue))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pn(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>Z(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var mn=Object.entries(ye).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function hn(e){if(!Z(e))throw new p(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new p(`config`,`Profile definition must set id`);if(!Se.find(t=>t===e.type))throw new p(`config`,`Profile ${t}: type must be one of ${Se.join(`, `)}`)}function gn(e){let t=e.identity?.handle,n=[[`id`,e.id,64],[`identity.handle`,typeof t==`string`?t:``,32]];for(let[t,r,i]of n)if(!(Array.from(r).length<=i))throw new p(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function _n(e){let{id:t,type:n}=e,r=e;for(let[e,i]of mn){if(i&&!i.includes(n))continue;let a=pe(e),o=pn(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!Z(e))return!1;let t=e[s];return t==null||t===``}))throw new p(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function vn(e){let{id:t,type:n}=e;if(n!==`live`&&me(`inputs`).includes(n)&&e.inputs==null)throw new p(`config`,`Profile ${t}: type '${n}' must set inputs`)}function yn(e){let[t]=be(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new p(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function bn(e,t){let n=t.turnBehaviour;fn(e,n?.resumption)}function xn(e,t){let n=t=>new p(`config`,`Profile ${e}: ${t}`),r=t?.maxRetries;if(r!==void 0&&(!Number.isInteger(r)||r<0))throw n(`outputs.validation.maxRetries must be a non-negative integer`)}function Sn(e,t){let n=t=>new p(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Cn.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Cn.join(`, `)}`);Tn(t?.blockedReply,n)}var Cn=[`quota`,`detect`,`blockedReply`,`network`,`taint`],wn=[`onBlock`,`maxRetries`];function Tn(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!wn.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!xe.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${xe.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function En(e){let t=e.guardrails?.detect,n=e.type===`host`?h(`guardrails.detect`,t,Ee):h(`guardrails.detect`,t);if(n!==void 0)throw new p(`config`,`Profile ${e.id}: ${n}`)}function Q(e,t){try{let n=Oe(t);if(!Number.isFinite(n.retainForDays))throw new p(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new p(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof p&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new p(De(t),`Profile ${e}: ${n}`,{cause:t})}}function Dn(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`embedding`)return;let{system:t,systemByRole:n}=e.identity;t!==void 0&&E(t,`Profile ${e.id} identity.system`);for(let[t,r]of Object.entries(n??{}))E(r,`Profile ${e.id} identity.systemByRole.${t}`)}function On(e){hn(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new p(`config`,m(`provider.profile_configuration`,{profile:e.id,field:t}));yn(e),vn(e),_n(e),gn(e),e.labels&&ge(e.labels,`Profile ${e.id}`);for(let t of he)if(e.labels?.[t]!==void 0)throw new p(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(Dn(e),En(e),e.type===`host`)return an(e);if(e.type===`decision`)return nn(e);if(e.type===`embedding`)return Zt(e);sn(e.id,e.models),bn(e.id,e),Sn(e.id,e.guardrails),e.type===`text`&&xn(e.id,e.outputs?.validation),Q(e.id,e.observability);for(let[t,n]of Object.entries(e.models))ln(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,system:e.identity.system,systemByRole:e.identity.systemByRole},n=e.guardrails,r=e.observability,i=e.labels,a=dn(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:z(e.inputs),outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:z(e.inputs),outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Pn(o.id,o.inputs.attachments?.accept),Nn(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs?z(e.inputs):e.inputs,tools:{allow:e.tools.allow,...rn(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},ke(o),In(o.id,o.live.contextCompression),Fn(o);break;default:throw new p(`config`,`Unknown profile type '${String(e)}'`)}return jn(o),kn(o),An(o),o}function kn(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new p(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function An(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new p(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function jn(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=u(e)?.slots?.[t.by];if(!n)throw new p(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=L(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new p(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of slot '${t.by}'`)}var Mn={n:{ok:e=>Number.isInteger(e)&&e>=1,rule:`a whole number of 1 or more`},seed:{ok:Number.isInteger,rule:`a whole number`},outputCompression:{ok:e=>Number.isInteger(e)&&e>=0&&e<=100,rule:`a whole number from 0 to 100`}};function Nn(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(Mn)){let a=t[n];if(a!==void 0&&!r(a))throw new p(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(ce(t.mimeType)!==`image`)throw new p(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(_(t)?t.uri:t.data))throw new p(`config`,`${r} needs its bytes or its uri`)})}function Pn(e,t){let n=t?.filter(e=>!d(_e,e));if(n?.length)throw new p(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function Fn(e){let{greeting:t,resumed:n,sessionResumption:r}=e.live,i=`Profile ${e.id} live`;if(t!==void 0&&(typeof t!=`string`||!t.trim()))throw new p(`config`,`${i}.greeting must be a prompt; leave it out to wait`);if(!n)return;if(typeof n.prompt!=`string`||!n.prompt.trim())throw new p(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new p(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new p(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function In(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(Ln(`${n}.triggerTokens`,r),Ln(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new p(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function Ln(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new p(`config`,`${e} must be a whole number above 0`)}function Rn(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(zn(i,r),Bn(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new p(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new p(`config`,`${i}: a profile that compacts itself must be a text profile that takes text`);return}let a=e.get(r.profile);if(!a)throw new p(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new p(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function zn(e,t){if(t.maxTokens<=0)throw new p(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new p(`config`,`${e}: compactAt must be in (0, 1)`)}function Bn(e,t){if(t.previousExchanges<0)throw new p(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new p(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new p(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function Vn(e,t){for(let n of A(t))if(e.get(n)?.type===`builtin`)throw new p(`config`,t.type===`host`?`Profile ${t.id} lists builtin '${n}' in tools.allow — type 'host' never runs a model`:`Profile ${t.id} lists builtin '${n}' in tools.allow — declare it on models.*.builtInTools instead`)}function Hn(e,t){let n=j(t)?.t2Loader;if(n){if(!A(t).includes(n))throw new p(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new p(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*Un(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function Wn(e,t){for(let{modelId:n,id:r}of Un(t))if(e.get(r)?.type!==`builtin`)throw new p(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function Gn(e){let t=e.type===`text`?e.outputs?.structured:void 0;return t?typeof t==`string`?[t]:[...new Set([...Object.values(t.map),t.fallback])]:[]}function Kn(e,t){let n=Gn(t).map(n=>{let r=e.find(n);if(!r)throw new p(`config`,`Profile ${t.id}: outputs.structured names '${n}', which is not a registered schema; register it before the profile`);return r}),r=t.type===`text`?t.outputs?.validation:void 0,i=Object.keys(r?.fields??{}),a=Object.keys(r?.items??{});if(!i.length&&!a.length)return;if(!n.length)throw new p(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Et(t.jsonSchema,e)));if(o.length)throw new p(`config`,`Profile ${t.id}: outputs.validation.items has ${o.join(`, `)}, which no structured schema reaches as a list with an items schema`);let s=i.filter(e=>!n.some(t=>St(t.jsonSchema,e)));if(s.length)throw new p(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function qn(e){let t=u(e)?.context;if(!t)return;let n=Ce;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new p(`config`,`Profile ${e.id}: inputs.context.from must list ${Ce.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new p(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function Jn(e,t){if(!t)return;let{attachments:n,voice:r,maxFiles:i,maxBytes:a,maxTurnBytes:o,limitsByMime:s}=t,c={maxFiles:i,maxBytes:a,maxTurnBytes:o};if((n||r)&&Object.values(c).some(e=>e===void 0))throw new p(`config`,`Profile ${e} must set maxFiles, maxBytes, and maxTurnBytes`);for(let[e,t]of Object.entries(s??{}))c[`limitsByMime['${e}']`]=t;for(let[t,n]of Object.entries(c))if(n!==void 0&&!(Number.isInteger(n)&&n>0))throw new p(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Yn(e,t,n){let r=new Map,i=i=>{let a=On(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,le(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(Vn(e,o),Hn(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){Wn(e,o),Jn(o.id,u(o)),qn(o),Kn(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&Rn(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new p(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function Xn(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Zn(e){let t;try{t=new URL(e.baseUrl)}catch{throw new p(`config`,`Enter a valid localhost URL.`)}if(![`http:`,`https:`].includes(t.protocol)||![`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)||t.username||t.password||t.search||t.hash)throw new p(`config`,`Use a localhost URL without credentials, query parameters or a fragment.`);return{baseUrl:t.href.replace(/\/$/,``),fetch:(e,n)=>new URL(e instanceof Request?e.url:String(e)).origin===t.origin?fetch(e,{...n,redirect:`error`,credentials:`omit`}):Promise.reject(new p(`blocked`,`Local requests must stay on the configured origin.`))}}var Qn=l({data:i(l({id:c().min(1)}))});async function $n(e,t){let n=Zn(e);if(!n?.fetch)throw new p(`config`,`Enter a local endpoint.`);let r=await n.fetch(`${n.baseUrl}/v1/models`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)throw new p(`network`,`Local model list returned HTTP ${r.status}.`);let i=Qn.safeParse(await r.json());if(!i.success)throw new p(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var er=`https://openrouter.ai/api/v1/models`,tr=`https://openrouter.ai/api/v1/embeddings/models`,nr=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],rr=[{id:`liquid/lfm-2.5-embedding-350m:free`,label:`Liquid LFM 2.5 Embedding 350M (free)`},{id:`nvidia/nemotron-3-embed-1b:free`,label:`NVIDIA Nemotron 3 Embed 1B (free)`},{id:`nvidia/llama-nemotron-embed-vl-1b-v2:free`,label:`NVIDIA Llama Nemotron Embed VL 1B v2 (free)`}],ir={text:`text`,image:`image`,speech:`speech`,live:void 0,embedding:void 0},ar=l({data:i(l({id:c().min(1),name:c().optional(),architecture:l({output_modalities:i(c()).optional()}).optional()}))}),or=l({data:i(l({id:c().min(1),name:c().optional()}))}),sr=l({models:i(l({name:c().min(1),displayName:c().optional(),supportedGenerationMethods:i(c()).optional()})).optional(),nextPageToken:c().optional()}),cr=5;async function $(e,t,n){let r=await fetch(t,{...n,redirect:`error`,credentials:`omit`});if(r.status===400||r.status===401||r.status===403)throw new p(`auth`,`${e} refused the key.`);if(!r.ok)throw new p(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function lr(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?rr:nr];if(e===`openrouter`)return await ur(t,i,r);if(!i)throw new p(`auth`,`Choose a key to list Gemini models.`);return await fr(t,i,r)}async function ur(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=or.safeParse(await $(`OpenRouter`,tr,r));if(!e.success)throw new p(`bad_response`,`OpenRouter returned an invalid embedding model list.`);return e.data.data.map(e=>({id:e.id,label:e.name??e.id}))}let i=ir[e];if(!i)return[];let a=ar.safeParse(await $(`OpenRouter`,`${er}?output_modalities=${i}`,r));if(!a.success)throw new p(`bad_response`,`OpenRouter returned an invalid model list.`);return a.data.data.filter(e=>e.architecture?.output_modalities?.includes(i)??!0).map(e=>({id:e.id,label:e.name??e.id}))}var dr={live:`bidiGenerateContent`,embedding:`embedContent`};async function fr(e,t,n){let r=dr[e]??`generateContent`,i=[],a;for(let e=0;e<cr;e++){let e=new URL(te);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=sr.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new p(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function pr(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function mr(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{ft as A,nt as B,xt as C,q as D,wt as E,it as F,Ge as G,Ze as H,j as I,S as J,y as K,ht as L,mt as M,dt as N,R as O,A as P,P as R,Tt as S,Et as T,Qe as U,$e as V,T as W,g as X,_ as Y,Je as Z,Lt as _,pr as a,Wt as b,On as c,Y as d,qt as f,Ht as g,It as h,Zn as i,F as j,L as k,Yt as l,Bt as m,$n as n,mr as o,Dt as p,x as q,lr as r,Yn as s,Xn as t,Jt as u,Ut as v,Ct as w,Ft as x,Vt as y,D as z};
3
+ `;function Xe(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 T(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=Xe(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function E(e,t){let n=T(e,t);if(n)throw new p(`config`,n)}function Ze(e,t,n){return E(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function Qe(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(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Ye,private:!0}),t.push(...n));return t}function et(e){return e.map(e=>e.text).join(``)}function tt(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:et(e),private:t}}function nt(e,t){return tt($e([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}function D(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function O(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function k(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function rt(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function A(e){return`tools`in e?e.tools.allow:[]}function j(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function it(e){return`tools`in e?e.tools.parallel:void 0}function at(e,t,n){return A(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||k(i.paths,n.path)})}function ot(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&k(r.paths,n.path)}):[]}function M(e,t){let n=e.get(t);if(n&&n.type!==`builtin`)return{type:`function`,name:n.name,description:n.description,parameters:n.inputSchema}}function st(e,t){let n=[];for(let r of t){let t=M(e,r);t&&n.push(t)}return n}function N(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=M(e,n);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function ct(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 lt(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function ut(e,t,n){return rt(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function P(e,t,n,r){let i=at(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:ot(e,t,n,r),o=[...i,...a],s=ut(e,t,o),c=lt(e,t,o);return{builtins:s,gated:o,visible:c,executable:c.filter(t=>O(e,t)),path:n.path,sessionPermissions:n.sessionPermissions,wire:st(e,c)}}async function dt(e,t,n,r){let i=P(e,t,n,r);return await F(e,i,t,n),i}function ft(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)}))}}async function F(e,t,n,r){let i=j(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[]`);for(let n of a){if(!t.gated.includes(n))continue;let r=e.get(n);r?.loadTier===`T2`&&(r.type===`builtin`?ct(e,t,n):N(e,t,n))}t.executable=t.visible.filter(t=>O(e,t))}var pt=new Set([`__proto__`,`constructor`,`prototype`]);function mt(e){if(!fe(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function ht(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||pt.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=gt(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;k(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)N(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>O(e,t)),{promoted:a}}function I(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function gt(e,t,n){if(!A(n).includes(t))return I(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?I(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:I(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):I(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function L(e){return Array.isArray(e)?[...e]:e.choices.map(e=>e.value)}function _t(e){return Array.isArray(e)?{choices:e.map(e=>({value:e}))}:{...e.label!==void 0&&e.label!==``?{label:e.label}:{},choices:e.choices.map(e=>({value:e.value,...e.description!==void 0&&e.description!==``?{description:e.description}:{}}))}}function R(e){if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,_t(t)]))}function z(e){return e?.slots?{...e,slots:R(e.slots)}:e}function B(e){return e==null}function V(e){return B(e)||typeof e!=`object`||Array.isArray(e)?null:e}function H(e){let t=V(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function U(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function W(e){let t=e.properties;return V(t)??{}}function vt(e,t){return e?`${e}.${t}`:t}function G(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function yt(e,t,n,r,i){if(!n)return;let a=await n(t,r);a.isValid||i.push({path:e,error:a.error||a.finding||`Validation failed for '${e}'`})}async function bt(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(B(r)){i&&G(t,s);return}await yt(t,r,a?.[t],o,s);let c=H(n),l=c?V(r):null;c&&l&&await K(c,l,t,a,o,s)}async function K(e,t,n,r,i,a){let o=W(e),s=new Set(U(e)),c=new Set([...Object.keys(o),...s]),l=V(t);for(let e of c)await bt({path:vt(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function xt(e,t,n,r){let i=H(e);if(!i)throw new p(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!V(t)){for(let e of U(i))G(e,a);return a}return await K(i,t,``,n,r,a),a}function St(e,t){let n=e;for(let e of t.split(`.`)){let t=H(n);if(!t)return!1;let r=W(t);if(!Object.hasOwn(r,e)&&!U(t).includes(e))return!1;n=r[e]}return!0}function Ct(e){return e.map(e=>e.error).join(`; `)}function wt(e,t){let n=e;for(let e of t.split(`.`))n=V(n)?.[e];return n}function q(e,t,n){let[r,...i]=t.split(`.`),a=V(e)??{};return r===void 0?e:{...a,[r]:i.length?q(a[r],i.join(`.`),n):n}}async function Tt(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=wt(e,i);if(Array.isArray(t))for(let[e,o]of t.entries()){let t=await a.check(o,n);t.isValid||r.push({path:i,index:e,item:o,reason:t.error||t.finding||`Validation failed for '${i}'`,onFail:a.onFail})}}return r}function Et(e,t){let n=e;for(let e of t.split(`.`)){let t=H(n);if(!t)return;n=W(t)[e]}let r=V(n);if(r?.type===`array`)return V(r.items)??void 0}var Dt=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Ot=new Set([`text`,`image`,`speech`]),kt=c().regex(/\S/),At=e({mimeType:c(),data:o(),name:c().optional()}),jt=e({mimeType:c(),uri:c(),name:c().optional()}),Mt=e({voice:c().optional(),style:c().optional(),speed:s().positive().optional()});function Nt(t){return e(Object.fromEntries(Object.entries(t).map(([e,t])=>{let n=L(t);return[e,a(n).optional()]})))}var Pt=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function Ft(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function It(t,n){let{inputs:a}=t,o={text:kt};a?.attachments&&(o.attachments=i(r([At,jt])).optional()),a?.voice&&(o.voice=i(At).optional()),a?.slots&&(o.slots=Nt(a.slots).optional()),t.type===`speech`&&(o.speech=Mt.optional());for(let e of n?.hostOnly??[]){if(!o[e])throw new p(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete o[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=o[e];if(!r)throw new p(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);o[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(Pt.has(e))throw new p(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);o[e]=t}return e(o)}var Lt=l({text:c().optional(),structured:t().optional(),removed:i(l({path:c(),reason:c(),item:t()})).optional(),parts:i(ne).optional(),sources:i(ee).optional()});function Rt(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function zt(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function Bt(e,t){if(!Ot.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!Rt(e))return`it does not take text`;for(let n of A(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(zt(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function Vt(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=Bt(a,n);if(o)throw new p(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function Ht(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return A(e).length===0&&!t?`local`:`delegated`}function Ut(e){let t=re(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=de(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 Wt(e,t,n){return{...e,type:`agent`,input:t,output:Lt,sources:e=>e.sources??[],...n}}function Gt(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 Kt(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`&&J(i,`${n}.properties.${t}`,r)}function J(e,t,n){if(!Gt(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&Kt(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&J(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`&&J(e,`${t}.${r}[${i}]`,n)})}}function qt(e,t){let n=[];if(J(e,`$`,n),n.length>0)throw new p(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function Jt(e,t=`output`){let r=n(e,{target:`draft-7`,io:t});return delete r.$schema,r.type||=`object`,r}function Y(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(Y);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=Y(e[n]));return t}function Yt(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`)}function Xt(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new p(`config`,m(`provider.binding_identity`))}function Zt(e){sn(e.id,e.models),Q(e.id,e.observability),Jn(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))ln(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:cn(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Qt(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new p(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function $t(e,t,n){if(Qt(e,t,n,se),Xt(e,t,n,`decision`),`retry`in n)throw new p(`config`,`Profile ${e} model '${t}': a decision binding takes no retry; a decision retries only a transient failure, by the kernel's rule`);if(n.timeoutMs!==void 0&&(!Number.isFinite(n.timeoutMs)||n.timeoutMs<=0))throw new p(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function en(e){let t=e.models?D(e.models):void 0;if(!t)throw new p(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);$t(e.id,t,e.models[t])}function tn(e){if(e.inputs.state!==`json`)throw new p(`config`,`Profile ${e.id}: decision inputs.state must be 'json'`);let t=e.inputs.maxStateBytes;if(t!==void 0&&!(Number.isInteger(t)&&t>0))throw new p(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new p(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function nn(e){return en(e),tn(e),Q(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function rn(e){return e===void 0?{}:{parallel:e}}function an(e){return on(e.id,e.tools),Q(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...rn(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function on(e,t){if(!Array.isArray(t.allow))throw new p(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function sn(e,t){if(Object.keys(t).length===0)throw new p(`config`,`Profile ${e} must declare at least one model`)}function cn(e,t){let n=t.defaultModel??D(t.models);if(!n)throw new p(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new p(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function ln(e,t,n){un(e,t,n),Qt(e,t,n,le),un(e,t,n)}function un(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new p(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!Te.includes(i))throw new p(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${Te.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new p(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new p(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new p(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function dn(e){return{providerContinuation:e.providerContinuation?ae.parse(e.providerContinuation):{},models:e.models,defaultModel:cn(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function X(e,t,n){if(n?.length){for(let r of n)if(!ie(r))throw new p(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function fn(e,t){t&&(X(e,`allowContinue`,t.allowContinue),X(e,`autoContinue`,t.autoContinue))}function Z(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pn(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>Z(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var mn=Object.entries(ye).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function hn(e){if(!Z(e))throw new p(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new p(`config`,`Profile definition must set id`);if(!Se.find(t=>t===e.type))throw new p(`config`,`Profile ${t}: type must be one of ${Se.join(`, `)}`)}function gn(e){let t=e.identity?.handle,n=[[`id`,e.id,64],[`identity.handle`,typeof t==`string`?t:``,32]];for(let[t,r,i]of n)if(!(Array.from(r).length<=i))throw new p(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function _n(e){let{id:t,type:n}=e,r=e;for(let[e,i]of mn){if(i&&!i.includes(n))continue;let a=pe(e),o=pn(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!Z(e))return!1;let t=e[s];return t==null||t===``}))throw new p(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function vn(e){let{id:t,type:n}=e;if(n!==`live`&&me(`inputs`).includes(n)&&e.inputs==null)throw new p(`config`,`Profile ${t}: type '${n}' must set inputs`)}function yn(e){let[t]=be(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new p(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function bn(e,t){let n=t.turnBehaviour;fn(e,n?.resumption)}function xn(e,t){let n=t=>new p(`config`,`Profile ${e}: ${t}`),r=t?.maxRetries;if(r!==void 0&&(!Number.isInteger(r)||r<0))throw n(`outputs.validation.maxRetries must be a non-negative integer`)}function Sn(e,t){let n=t=>new p(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Cn.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Cn.join(`, `)}`);Tn(t?.blockedReply,n)}var Cn=[`quota`,`detect`,`blockedReply`,`network`,`taint`],wn=[`onBlock`,`maxRetries`];function Tn(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!wn.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!xe.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${xe.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function En(e){let t=e.guardrails?.detect,n=e.type===`host`?h(`guardrails.detect`,t,Ee):h(`guardrails.detect`,t);if(n!==void 0)throw new p(`config`,`Profile ${e.id}: ${n}`)}function Q(e,t){try{let n=Oe(t);if(!Number.isFinite(n.retainForDays))throw new p(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new p(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof p&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new p(De(t),`Profile ${e}: ${n}`,{cause:t})}}function Dn(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`embedding`)return;let{system:t,systemByRole:n}=e.identity;t!==void 0&&E(t,`Profile ${e.id} identity.system`);for(let[t,r]of Object.entries(n??{}))E(r,`Profile ${e.id} identity.systemByRole.${t}`)}function On(e){hn(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new p(`config`,m(`provider.profile_configuration`,{profile:e.id,field:t}));yn(e),vn(e),_n(e),gn(e),e.labels&&ge(e.labels,`Profile ${e.id}`);for(let t of he)if(e.labels?.[t]!==void 0)throw new p(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(Dn(e),En(e),e.type===`host`)return an(e);if(e.type===`decision`)return nn(e);if(e.type===`embedding`)return Zt(e);sn(e.id,e.models),bn(e.id,e),Sn(e.id,e.guardrails),e.type===`text`&&xn(e.id,e.outputs?.validation),Q(e.id,e.observability);for(let[t,n]of Object.entries(e.models))ln(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,system:e.identity.system,systemByRole:e.identity.systemByRole},n=e.guardrails,r=e.observability,i=e.labels,a=dn(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:z(e.inputs),outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:z(e.inputs),outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Pn(o.id,o.inputs.attachments?.accept),Nn(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs?z(e.inputs):e.inputs,tools:{allow:e.tools.allow,...rn(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},ke(o),In(o.id,o.live.contextCompression),Fn(o);break;default:throw new p(`config`,`Unknown profile type '${String(e)}'`)}return jn(o),kn(o),An(o),o}function kn(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new p(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function An(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new p(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function jn(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=u(e)?.slots?.[t.by];if(!n)throw new p(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=L(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new p(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of slot '${t.by}'`)}var Mn={n:{ok:e=>Number.isInteger(e)&&e>=1,rule:`a whole number of 1 or more`},seed:{ok:Number.isInteger,rule:`a whole number`},outputCompression:{ok:e=>Number.isInteger(e)&&e>=0&&e<=100,rule:`a whole number from 0 to 100`}};function Nn(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(Mn)){let a=t[n];if(a!==void 0&&!r(a))throw new p(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(ce(t.mimeType)!==`image`)throw new p(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(_(t)?t.uri:t.data))throw new p(`config`,`${r} needs its bytes or its uri`)})}function Pn(e,t){let n=t?.filter(e=>!d(_e,e));if(n?.length)throw new p(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function Fn(e){let{greeting:t,resumed:n,sessionResumption:r}=e.live,i=`Profile ${e.id} live`;if(t!==void 0&&(typeof t!=`string`||!t.trim()))throw new p(`config`,`${i}.greeting must be a prompt; leave it out to wait`);if(!n)return;if(typeof n.prompt!=`string`||!n.prompt.trim())throw new p(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new p(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new p(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function In(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(Ln(`${n}.triggerTokens`,r),Ln(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new p(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function Ln(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new p(`config`,`${e} must be a whole number above 0`)}function Rn(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(zn(i,r),Bn(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new p(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new p(`config`,`${i}: a profile that compacts itself must be a text profile that takes text`);return}let a=e.get(r.profile);if(!a)throw new p(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new p(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function zn(e,t){if(t.maxTokens<=0)throw new p(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new p(`config`,`${e}: compactAt must be in (0, 1)`)}function Bn(e,t){if(t.previousExchanges<0)throw new p(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new p(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new p(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function Vn(e,t){for(let n of A(t))if(e.get(n)?.type===`builtin`)throw new p(`config`,t.type===`host`?`Profile ${t.id} lists builtin '${n}' in tools.allow — type 'host' never runs a model`:`Profile ${t.id} lists builtin '${n}' in tools.allow — declare it on models.*.builtInTools instead`)}function Hn(e,t){let n=j(t)?.t2Loader;if(n){if(!A(t).includes(n))throw new p(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new p(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*Un(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function Wn(e,t){for(let{modelId:n,id:r}of Un(t))if(e.get(r)?.type!==`builtin`)throw new p(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function Gn(e){let t=e.type===`text`?e.outputs?.structured:void 0;return t?typeof t==`string`?[t]:[...new Set([...Object.values(t.map),t.fallback])]:[]}function Kn(e,t){let n=Gn(t).map(n=>{let r=e.find(n);if(!r)throw new p(`config`,`Profile ${t.id}: outputs.structured names '${n}', which is not a registered schema; register it before the profile`);return r}),r=t.type===`text`?t.outputs?.validation:void 0,i=Object.keys(r?.fields??{}),a=Object.keys(r?.items??{});if(!i.length&&!a.length)return;if(!n.length)throw new p(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Et(t.jsonSchema,e)));if(o.length)throw new p(`config`,`Profile ${t.id}: outputs.validation.items has ${o.join(`, `)}, which no structured schema reaches as a list with an items schema`);let s=i.filter(e=>!n.some(t=>St(t.jsonSchema,e)));if(s.length)throw new p(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function qn(e){let t=u(e)?.context;if(!t)return;let n=Ce;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new p(`config`,`Profile ${e.id}: inputs.context.from must list ${Ce.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new p(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function Jn(e,t){if(!t)return;let{attachments:n,voice:r,maxFiles:i,maxBytes:a,maxTurnBytes:o,limitsByMime:s}=t,c={maxFiles:i,maxBytes:a,maxTurnBytes:o};if((n||r)&&Object.values(c).some(e=>e===void 0))throw new p(`config`,`Profile ${e} must set maxFiles, maxBytes, and maxTurnBytes`);for(let[e,t]of Object.entries(s??{}))c[`limitsByMime['${e}']`]=t;for(let[t,n]of Object.entries(c))if(n!==void 0&&!(Number.isInteger(n)&&n>0))throw new p(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Yn(e,t,n){let r=new Map,i=i=>{let a=On(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,ue(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(Vn(e,o),Hn(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){Wn(e,o),Jn(o.id,u(o)),qn(o),Kn(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&Rn(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new p(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function Xn(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Zn(e){let t;try{t=new URL(e.baseUrl)}catch{throw new p(`config`,`Enter a valid localhost URL.`)}if(![`http:`,`https:`].includes(t.protocol)||![`localhost`,`127.0.0.1`,`[::1]`].includes(t.hostname)||t.username||t.password||t.search||t.hash)throw new p(`config`,`Use a localhost URL without credentials, query parameters or a fragment.`);return{baseUrl:t.href.replace(/\/$/,``),fetch:(e,n)=>new URL(e instanceof Request?e.url:String(e)).origin===t.origin?fetch(e,{...n,redirect:`error`,credentials:`omit`}):Promise.reject(new p(`blocked`,`Local requests must stay on the configured origin.`))}}var Qn=l({data:i(l({id:c().min(1)}))});async function $n(e,t){let n=Zn(e);if(!n?.fetch)throw new p(`config`,`Enter a local endpoint.`);let r=await n.fetch(`${n.baseUrl}/v1/models`,{signal:t,headers:{Accept:`application/json`}});if(!r.ok)throw new p(`network`,`Local model list returned HTTP ${r.status}.`);let i=Qn.safeParse(await r.json());if(!i.success)throw new p(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var er=`https://openrouter.ai/api/v1/models`,tr=`https://openrouter.ai/api/v1/embeddings/models`,nr=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],rr=[{id:`liquid/lfm-2.5-embedding-350m:free`,label:`Liquid LFM 2.5 Embedding 350M (free)`},{id:`nvidia/nemotron-3-embed-1b:free`,label:`NVIDIA Nemotron 3 Embed 1B (free)`},{id:`nvidia/llama-nemotron-embed-vl-1b-v2:free`,label:`NVIDIA Llama Nemotron Embed VL 1B v2 (free)`}],ir={text:`text`,image:`image`,speech:`speech`,live:void 0,embedding:void 0},ar=l({data:i(l({id:c().min(1),name:c().optional(),architecture:l({output_modalities:i(c()).optional()}).optional()}))}),or=l({data:i(l({id:c().min(1),name:c().optional()}))}),sr=l({models:i(l({name:c().min(1),displayName:c().optional(),supportedGenerationMethods:i(c()).optional()})).optional(),nextPageToken:c().optional()}),cr=5;async function $(e,t,n){let r=await fetch(t,{...n,redirect:`error`,credentials:`omit`});if(r.status===400||r.status===401||r.status===403)throw new p(`auth`,`${e} refused the key.`);if(!r.ok)throw new p(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function lr(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?rr:nr];if(e===`openrouter`)return await ur(t,i,r);if(!i)throw new p(`auth`,`Choose a key to list Gemini models.`);return await fr(t,i,r)}async function ur(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=or.safeParse(await $(`OpenRouter`,tr,r));if(!e.success)throw new p(`bad_response`,`OpenRouter returned an invalid embedding model list.`);return e.data.data.map(e=>({id:e.id,label:e.name??e.id}))}let i=ir[e];if(!i)return[];let a=ar.safeParse(await $(`OpenRouter`,`${er}?output_modalities=${i}`,r));if(!a.success)throw new p(`bad_response`,`OpenRouter returned an invalid model list.`);return a.data.data.filter(e=>e.architecture?.output_modalities?.includes(i)??!0).map(e=>({id:e.id,label:e.name??e.id}))}var dr={live:`bidiGenerateContent`,embedding:`embedContent`};async function fr(e,t,n){let r=dr[e]??`generateContent`,i=[],a;for(let e=0;e<cr;e++){let e=new URL(te);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=sr.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new p(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function pr(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function mr(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{ft as A,nt as B,xt as C,q as D,wt as E,it as F,Ge as G,Ze as H,j as I,S as J,y as K,ht as L,mt as M,dt as N,R as O,A as P,P as R,Tt as S,Et as T,Qe as U,$e as V,T as W,g as X,_ as Y,Je as Z,Lt as _,pr as a,Wt as b,On as c,Y as d,qt as f,Ht as g,It as h,Zn as i,F as j,L as k,Yt as l,Bt as m,$n as n,mr as o,Dt as p,x as q,lr as r,Yn as s,Xn as t,Jt as u,Ut as v,Ct as w,Ft as x,Vt as y,D as z};