@theoremjs/studio 0.3.5-next.959.g351c307 → 0.3.5-next.960.g9f17ea5

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 (50) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{BottomSheet-DVdX9BBE.js → BottomSheet-B76bYV7l.js} +1 -1
  3. package/page/assets/{ConsoleFrame-THhhAEP5.js → ConsoleFrame-Br18-H-L.js} +1 -1
  4. package/page/assets/{ContextMenu-Cboog74g.js → ContextMenu-CWCFt_A9.js} +2 -2
  5. package/page/assets/{DateInput-uC-fDXyG.js → DateInput-CHgeGI72.js} +1 -1
  6. package/page/assets/{DropdownMenu-C7h8h-0w.js → DropdownMenu-B7qlpJMN.js} +2 -2
  7. package/page/assets/{Link-kFun-IlM.js → Link-CoZ2PEEH.js} +1 -1
  8. package/page/assets/{MenuBottomSheet-CwS_YI1q.js → MenuBottomSheet-DTWrKjqd.js} +1 -1
  9. package/page/assets/{PowerSearchBottomSheet-zdGqCDgu.js → PowerSearchBottomSheet-JEzrA2S1.js} +1 -1
  10. package/page/assets/{RankedBars-3xJdmdQX.js → RankedBars-B7JtgEd8.js} +1 -1
  11. package/page/assets/{SchemaFields-DmhGgfyh.js → SchemaFields-rpQ2ndVm.js} +1 -1
  12. package/page/assets/{ShapedData-BTuvDXEZ.js → ShapedData-DANaXMJn.js} +1 -1
  13. package/page/assets/{TokenizerBottomSheet-oXeJnDQc.js → TokenizerBottomSheet-DDSCJrAx.js} +1 -1
  14. package/page/assets/{ToolResultCharts-gFpTjBvh.js → ToolResultCharts-Tw5-hBtI.js} +1 -1
  15. package/page/assets/{Toolbar-DCD06BBq.js → Toolbar-DWnKfd9u.js} +1 -1
  16. package/page/assets/{TraceInspector-CizL3CHe.js → TraceInspector-BWk5scIX.js} +2 -2
  17. package/page/assets/{TraceOverview-BZxHxBRZ.js → TraceOverview-BWtz7u6z.js} +1 -1
  18. package/page/assets/{_virtual_studio-type-sources-Dgfw_yrN.js → _virtual_studio-type-sources-CpwSCeT4.js} +12 -41
  19. package/page/assets/{browser-connection-B_d6mC7E.js → browser-connection-i2GAg2Qq.js} +1 -1
  20. package/page/assets/browser-engine-BXIwcNZY.js +16 -0
  21. package/page/assets/{browser-transport-BvCk51WP.js → browser-transport-D22c6aTk.js} +2 -2
  22. package/page/assets/{compile-B6NPCubN.js → compile-BJ0hioSk.js} +1 -1
  23. package/page/assets/{export-agent-C6yZsFmc.js → export-agent-GhQdRXOF.js} +1 -1
  24. package/page/assets/{getRadiusAndStrokeWidthFromDot-DTs8vzee.js → getRadiusAndStrokeWidthFromDot-8x8WbODw.js} +1 -1
  25. package/page/assets/{guardrail-health-Ba59KccZ.js → guardrail-health-CoKlrXPK.js} +1 -1
  26. package/page/assets/{guardrail-tester-DeAOsVuR.js → guardrail-tester-BxATAiSd.js} +1 -1
  27. package/page/assets/{index-BgC0zUqN.js → index-CIBF2GPN.js} +9 -9
  28. package/page/assets/{json-code-DxJPohHd.js → json-code-BOR-Xpv5.js} +1 -1
  29. package/page/assets/{live-messages-Cggih6Yv.js → live-messages-BD2DHFi0.js} +1 -1
  30. package/page/assets/{prompt-row-DJi0XgHd.js → prompt-row-jPg6xjte.js} +1 -1
  31. package/page/assets/reader-C-rxg61s.js +5 -0
  32. package/page/assets/{registry-C0KSfYFL.js → registry-sNoz1vt0.js} +1 -1
  33. package/page/assets/schema-C6vwXzod.js +3 -0
  34. package/page/assets/{studio-code-pane-CAIGE2-u.js → studio-code-pane-DeXQdsv-.js} +3 -3
  35. package/page/assets/{studio-console-Dkaz4IQW.js → studio-console-BciG1nqS.js} +1 -1
  36. package/page/assets/{studio-decision-DV29rXST.js → studio-decision-9z7f-u6K.js} +1 -1
  37. package/page/assets/{studio-embedding-BST4FYgn.js → studio-embedding-CPwaBQN4.js} +1 -1
  38. package/page/assets/{studio-host-console-DCf1JPzw.js → studio-host-console-C5r2jNwL.js} +2 -2
  39. package/page/assets/{studio-live-C-IPx4_8.js → studio-live-B9yfow3V.js} +1 -1
  40. package/page/assets/{studio-map-uyRhvDzU.js → studio-map-DQHxJMdR.js} +1 -1
  41. package/page/assets/{studio-media-9m4YcyAv.js → studio-media-Cxt3K0AZ.js} +1 -1
  42. package/page/assets/{studio-trace-replay-TGycm64u.js → studio-trace-replay-B0TXgWAc.js} +1 -1
  43. package/page/assets/{studio-type-checker-BmGciI0m.js → studio-type-checker-7fLd-Niu.js} +1 -1
  44. package/page/assets/{turn-client-BfTi2B2k.js → turn-client-D1-EN8SX.js} +1 -1
  45. package/page/assets/{use-one-call-B9_erjJm.js → use-one-call-BWrjmvLX.js} +1 -1
  46. package/page/assets/{useDismissSearchOnTouchDrag-DiK31rqG.js → useDismissSearchOnTouchDrag-D8C62kG8.js} +1 -1
  47. package/page/index.html +13 -13
  48. package/page/assets/browser-engine-CcgdHuwJ.js +0 -17
  49. package/page/assets/reader-Vt-mQ6zw.js +0 -5
  50. package/page/assets/schema-BbzFAyIO.js +0 -3
@@ -7596,17 +7596,12 @@ export interface RefusedMedia {
7596
7596
  from: 'input' | 'history' | 'tool';
7597
7597
  }
7598
7598
  /**
7599
- * The turn went on without files: first those the profile does not take (its \`accept\` lists and
7600
- * byte limits), left out before any call, then those the provider refused. A refused file is
7601
- * listed only when the same call, sent without it, was accepted: that is the proof it was at fault.
7599
+ * The turn went on without files the provider refused. Set only when the same call, sent
7600
+ * without them, was accepted: that is the proof the files were at fault.
7602
7601
  */
7603
7602
  export interface MediaRefused {
7604
7603
  dropped: RefusedMedia[];
7605
- /**
7606
- * Why, for the builder only: \`forClient\` strips the whole report. A line per file left out
7607
- * names its type and each check it failed (\`image/gif: mime_not_allowed\`); then the provider's
7608
- * own reason.
7609
- */
7604
+ /** The provider's own reason, for the builder only: \`forClient\` strips the whole report. */
7610
7605
  said: string;
7611
7606
  }
7612
7607
  export interface DoneBase {
@@ -13861,10 +13856,7 @@ export interface AttachmentRules {
13861
13856
  voice?: string[];
13862
13857
  limits?: MediaLimits;
13863
13858
  }
13864
- /**
13865
- * The one attachment check. The headless interface runs it before a send; at ingress the kernel
13866
- * runs it on each file, leaves out the files it names, and throws only on what names no file.
13867
- */
13859
+ /** The one attachment check: the kernel throws on it at ingress and the headless interface runs it before a send. */
13868
13860
  declare function attachmentIssues(rules: AttachmentRules, files: AttachmentFacts[], clips: AttachmentFacts[]): AttachmentValidationIssue[];
13869
13861
  /** The user-facing wording key and params for an attachment issue. */
13870
13862
  declare function attachmentIssueCopy(issue: AttachmentValidationIssue): ErrorCopy;
@@ -13874,32 +13866,17 @@ declare function attachmentIssueText(issue: AttachmentValidationIssue, labels?:
13874
13866
  declare function attachmentsRefused(issues: readonly AttachmentValidationIssue[]): TheoremError;
13875
13867
  /** The decoded size of inline base64 data; throws when it is not base64. */
13876
13868
  declare function base64Bytes(data: string): number;
13877
- /** Throws on every issue the check finds: a host's own check before a send. */
13869
+ /** Provider references are checked for MIME and count; byte limits apply to inline blobs only. */
13878
13870
  declare function assertTurnAttachments(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined): void;
13879
- /** A file the turn goes without, and what the check found wrong with it. */
13880
- interface LeftOutFile {
13881
- mimeType: string;
13882
- channel: 'attachment' | 'voice';
13883
- issues: AttachmentValidationIssue[];
13884
- }
13885
- interface TurnFiles {
13886
- attachments?: Array<TurnBlob | TurnMediaRef>;
13887
- voice?: TurnBlob[];
13888
- leftOut: LeftOutFile[];
13889
- }
13890
- /**
13891
- * invariant: a file the profile does not take is left out and the turn goes on; what names no file
13892
- * (too many files, too many bytes in all) refuses the turn, since no one file is at fault.
13893
- * Provider references are checked for MIME and count; byte limits apply to inline blobs only.
13894
- */
13895
- declare function splitTurnAttachments(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined): TurnFiles;
13896
13871
  /** Provider file references pass through unsanitized: the kernel has no bytes to scan. */
13897
13872
  declare function sanitizeTurnBlobs(profile: Profile, attachments: Array<TurnBlob | TurnMediaRef> | undefined, voice: TurnBlob[] | undefined, at: {
13898
13873
  attachment: BoundaryReader;
13899
13874
  voice: BoundaryReader;
13900
- }): TurnFiles;
13901
- export type { LeftOutFile, TurnFiles };
13902
- export { assertTurnAttachments, attachmentIssueCopy, attachmentIssues, attachmentIssueText, attachmentsRefused, base64Bytes, isTextFile, isTextFileData, isTurnMediaRef, maxBytesForMime, modelTextFile, requireMediaLimits, resolveMediaLimits, rewriteTextFile, sanitizeCsvText, sanitizeTurnBlobs, splitTurnAttachments, textFileText, };
13875
+ }): {
13876
+ attachments?: Array<TurnBlob | TurnMediaRef>;
13877
+ voice?: TurnBlob[];
13878
+ };
13879
+ export { assertTurnAttachments, attachmentIssueCopy, attachmentIssues, attachmentIssueText, attachmentsRefused, base64Bytes, isTextFile, isTextFileData, isTurnMediaRef, maxBytesForMime, modelTextFile, requireMediaLimits, resolveMediaLimits, rewriteTextFile, sanitizeCsvText, sanitizeTurnBlobs, textFileText, };
13903
13880
  `,"file:///node_modules/@theoremjs/agents/src/kernel/registry/catalog.d.ts":`import type { MediaInputKind, ModelBinding, ModelId, ModelProfile, Profile, ProfileInputsSpec, ThinkingLevel } from '../types.js';
13904
13881
  import { mimeEssence } from '../util/mime.js';
13905
13882
  /** Where a media input arrives: as an attachment or as voice. */
@@ -14187,8 +14164,7 @@ export declare function getProvider(id: string): RegisteredProvider | undefined;
14187
14164
  export declare function listProviders(): RegisteredProvider[];
14188
14165
  /** Every protocol the default scope's providers serve. */
14189
14166
  export declare function listProtocols(): Protocol[];
14190
- `,"file:///node_modules/@theoremjs/agents/src/guardrails/sanitize.d.ts":`import { type LeftOutFile } from '../kernel/registry/attachments.js';
14191
- import type { NormalizedTurnRequest, Profile, TurnContext, TurnEvent, TurnHistoryMessage, TurnRequest } from '../kernel/types.js';
14167
+ `,"file:///node_modules/@theoremjs/agents/src/guardrails/sanitize.d.ts":`import type { NormalizedTurnRequest, Profile, TurnContext, TurnEvent, TurnHistoryMessage, TurnRequest } from '../kernel/types.js';
14192
14168
  import { type Boundary } from './boundaries.js';
14193
14169
  import { type BoundaryReader } from './detect-at.js';
14194
14170
  import { TheoremError } from './theorem-error.js';
@@ -14217,8 +14193,6 @@ interface SanitizedTurnRequest {
14217
14193
  events: TurnEvent[];
14218
14194
  /** Set when a match blocks: the request does not reach the model, and the turn ends on this. */
14219
14195
  refusal?: TheoremError;
14220
- /** The files the profile does not take, left out of \`request\`; the turn goes on without them. */
14221
- leftOut: LeftOutFile[];
14222
14196
  }
14223
14197
  /**
14224
14198
  * \`req.system\` is host-assembled per turn — it interpolates retrieval and user
@@ -14226,10 +14200,7 @@ interface SanitizedTurnRequest {
14226
14200
  * path and stays verbatim.
14227
14201
  */
14228
14202
  declare function sanitizeTurnRequestWithEvents(req: TurnRequest, profile: Profile): SanitizedTurnRequest;
14229
- /**
14230
- * The turn request with its input cleaned under the profile's guardrails. Throws when a match
14231
- * blocks it, and when the profile does not take one of its files: nothing here goes on without it.
14232
- */
14203
+ /** The turn request with its input cleaned under the profile's guardrails. Throws when a match blocks it. */
14233
14204
  declare function sanitizeTurnRequest(req: TurnRequest, profile: Profile): NormalizedTurnRequest;
14234
14205
  export type { SanitizedTurnRequest };
14235
14206
  export { contextText, requestRefused, sanitizeContext, sanitizeHistory, sanitizeProjectId, sanitizeTurnRequest, sanitizeTurnRequestWithEvents, };
@@ -1 +1 @@
1
- import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{J as r}from"./tool-schema-BxxcS67z.js";import{$t as i,Ba as a,Cn as o,Fi as s,Oi as c,Pi as l,Qt as u,Ti as ee,Wa as te,Xa as ne,Y as re,Zi as ie,ao as ae,ba as oe,bn as se,ea as ce,fa as d,lo as f,na as le,nn as ue,ta as p,uo as m,wi as h,xn as de,zi as g,zt as fe}from"./shaped-data-6dHnx8Ju.js";import{c as _}from"./host-patterns-DzBJj2uE.js";import{E as pe,G as me,N as he,O as ge,S as _e,b as v,j as ve}from"./schema-BbzFAyIO.js";import{a as ye,n as be}from"./live-ingress-ZR7rtkDx.js";function y(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function b(e){return e==null}function x(e){return b(e)||typeof e!=`object`||Array.isArray(e)?null:e}function S(e){let t=x(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function C(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function w(e){let t=e.properties;return x(t)??{}}function xe(e,t){return e?`${e}.${t}`:t}function T(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function E(e,t,n,r,i,a){if(!n)return;let o;try{o=await n(t,r)}catch(e){a.push(e),o={isValid:!1}}o.isValid||i.push({path:e,error:o.error||o.finding||`Validation failed for '${e}'`})}async function D(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,options:o,failures:s,crashes:c}=e;if(b(r)){i&&T(t,s);return}await E(t,r,a?.[t],o,s,c);let l=S(n),u=l?x(r):null;l&&u&&await O(l,u,t,a,o,s,c)}async function O(e,t,n,r,i,a,o){let s=w(e),c=new Set(C(e)),l=new Set([...Object.keys(s),...c]),u=x(t);for(let e of l)await D({path:xe(n,e),propSchema:s[e],child:u?.[e],isRequired:c.has(e),fields:r,options:i,failures:a,crashes:o})}async function k(e,t,n,r,i=[]){let a=S(e);if(!a)throw new _(`config`,`structured validation requires a JSON Schema object root`);let o=[];if(!x(t)){for(let e of C(a))T(e,o);return o}return await O(a,t,``,n,r,o,i),o}function A(e,t){let n=e;for(let e of t.split(`.`)){let t=S(n);if(!t)return!1;let r=w(t);if(!Object.hasOwn(r,e)&&!C(t).includes(e))return!1;n=r[e]}return!0}function j(e){return e.map(e=>e.error).join(`; `)}function M(e,t){let n=e;for(let e of t.split(`.`))n=x(n)?.[e];return n}function N(e,t,n){let[r,...i]=t.split(`.`),a=x(e)??{};return r===void 0?e:{...a,[r]:i.length?N(a[r],i.join(`.`),n):n}}async function Se(e,t,n,r=[]){let i=[];for(let[a,o]of Object.entries(t??{})){let t=M(e,a);if(Array.isArray(t))for(let[e,s]of t.entries()){let t;try{t=await o.check(s,n)}catch(e){r.push(e),t={isValid:!1}}t.isValid||i.push({path:a,index:e,item:s,reason:t.error||t.finding||`Validation failed for '${a}'`,onFail:o.onFail})}}return i}function P(e,t){let n=e;for(let e of t.split(`.`)){let t=S(n);if(!t)return;n=w(t)[e]}let r=x(n);if(r?.type===`array`)return x(r.items)??void 0}function Ce(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new _(`config`,f(`provider.binding_identity`))}function we(e){L(e.id,e.models),K(e.id,e.observability),X(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:R(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Te(e){L(e.id,e.models),W(e.id,e.guardrails),K(e.id,e.observability);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new _(`config`,`Profile ${e.id}: a transcription takes a voice clip, so inputs.text must be false`);return{type:`transcription`,id:e.id,identity:{handle:e.identity.handle},...V(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function F(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new _(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${re(e.path)}: ${e.message}`).join(`; `)}`)}function Ee(e,t,n){if(F(e,t,n,i),Ce(e,t,n,`decision`),`retry`in n)throw new _(`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 _(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function De(e){let t=e.models?y(e.models):void 0;if(!t)throw new _(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);Ee(e.id,t,e.models[t])}function Oe(e){if(e.inputs.state!==`json`)throw new _(`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 _(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new _(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function ke(e){return De(e),Oe(e),K(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function I(e){return e===void 0?{}:{parallel:e}}function Ae(e){return je(e.id,e.tools),K(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...I(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function je(e,t){if(!Array.isArray(t.allow))throw new _(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function L(e,t){if(Object.keys(t).length===0)throw new _(`config`,`Profile ${e} must declare at least one model`)}function R(e,t){let n=t.defaultModel??y(t.models);if(!n)throw new _(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new _(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function z(e,t,n){B(e,t,n),F(e,t,n,ue),B(e,t,n)}function B(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new _(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!g.includes(i))throw new _(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${g.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new _(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new _(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new _(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function V(e){return{providerContinuation:e.providerContinuation?oe.parse(e.providerContinuation):{},models:e.models,defaultModel:R(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function H(e,t,n){if(n?.length){for(let r of n)if(!fe(r))throw new _(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (${ee.join(` | `)}); got '${r}'`)}}function Me(e,t){t&&(H(e,`allowContinue`,t.allowContinue),H(e,`autoContinue`,t.autoContinue))}function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ne(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>U(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var Pe=Object.entries(l).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Fe(e){if(!U(e))throw new _(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new _(`config`,`Profile definition must set id`);if(!s.find(t=>t===e.type))throw new _(`config`,`Profile ${t}: type must be one of ${s.join(`, `)}`)}function Ie(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 _(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function Le(e){let{id:t,type:n}=e,r=e;for(let[e,i]of Pe){if(i&&!i.includes(n))continue;let a=p(e),o=Ne(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!U(e))return!1;let t=e[s];return t==null||t===``}))throw new _(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Re(e){let{id:t,type:n}=e;if(n!==`live`&&le(`inputs`).includes(n)&&e.inputs==null)throw new _(`config`,`Profile ${t}: type '${n}' must set inputs`)}function ze(e){let[t]=ce(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new _(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Be(e,t){let n=t.turnBehaviour;Me(e,n?.resumption)}function Ve(e,t){let n=t=>new _(`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 W(e,t){let n=t=>new _(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!G.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${G.join(`, `)}`);Ue(t?.blockedReply,n)}var G=[`quota`,`detect`,`blockedReply`,`network`,`taint`],He=[`onBlock`,`maxRetries`];function Ue(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!He.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&&!a.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${a.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function We(e){let t=e.guardrails?.detect,n=e.type===`host`?d(`guardrails.detect`,t,te):d(`guardrails.detect`,t);if(n!==void 0)throw new _(`config`,`Profile ${e.id}: ${n}`)}function K(e,t){try{let n=ye(t);if(!Number.isFinite(n.retainForDays))throw new _(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new _(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof _&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new _(ne(t),`Profile ${e}: ${n}`,{cause:t})}}function Ge(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`transcription`||e.type===`embedding`)return;let{options:t,system:n}=e.identity,r=n??``;pe(r,`Profile ${e.id} identity.system`);let i=ge(r,t,e.inputs?.options);if(i)throw new _(`config`,`Profile ${e.id} identity.system: ${i}`)}function q(e){let t=Ke(e),[n]=ie(e);if(n)throw new _(`config`,`Profile ${e.id}: ${n.path} ${n.message}`);return t}function Ke(e){Fe(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new _(`config`,f(`provider.profile_configuration`,{profile:e.id,field:t}));ze(e),Re(e),Le(e),Ie(e),e.labels&&m(e.labels,`Profile ${e.id}`);for(let t of ae)if(e.labels?.[t]!==void 0)throw new _(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(Ge(e),We(e),e.type===`host`)return Ae(e);if(e.type===`decision`)return ke(e);if(e.type===`embedding`)return we(e);if(e.type===`transcription`)return Te(e);L(e.id,e.models),Be(e.id,e),W(e.id,e.guardrails),e.type===`text`&&Ve(e.id,e.outputs?.validation),K(e.id,e.observability);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,options:e.identity.options,system:e.identity.system},n=e.guardrails,r=e.observability,i=e.labels,a=V(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Qe(o.id,o.inputs.attachments?.accept),Ze(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs,tools:{allow:e.tools.allow,...I(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},be(o),et(o.id,o.live.contextCompression),$e(o);break;default:throw new _(`config`,`Unknown profile type '${String(e)}'`)}return Ye(o),qe(o),Je(o),o}function qe(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new _(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function Je(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new _(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function Ye(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=he(e,t.by);if(!n)throw new _(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not one of the profile's options`);let r=ve(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new _(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of option '${t.by}'`)}var Xe={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 Ze(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(Xe)){let a=t[n];if(a!==void 0&&!r(a))throw new _(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(se(t.mimeType)!==`image`)throw new _(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(me(t)?t.uri:t.data))throw new _(`config`,`${r} needs its bytes or its uri`)})}function Qe(e,t){let n=t?.filter(e=>!de(c,e));if(n?.length)throw new _(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function $e(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 _(`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 _(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new _(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new _(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function et(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(J(`${n}.triggerTokens`,r),J(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new _(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function J(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new _(`config`,`${e} must be a whole number above 0`)}function tt(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(nt(i,r),rt(i,r),r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new _(`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 _(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new _(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function nt(e,t){if(t.maxTokens<=0)throw new _(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new _(`config`,`${e}: compactAt must be in (0, 1)`)}function rt(e,t){if(t.previousExchanges<0)throw new _(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new _(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new _(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function it(e,t){for(let n of v(t))if(e.get(n)?.type===`builtin`)throw new _(`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 at(e,t){let n=_e(t)?.t2Loader;if(n){if(!v(t).includes(n))throw new _(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new _(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*ot(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function st(e,t){for(let{modelId:n,id:r}of ot(t))if(e.get(r)?.type!==`builtin`)throw new _(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function Y(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 ct(e,t){return t?.type===`text`?Y(t).flatMap(t=>{let n=e.find(t);return n?[n.jsonSchema]:[]}):[]}function lt(e,t){let n=Y(t).map(n=>{let r=e.find(n);if(!r)throw new _(`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 _(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>P(t.jsonSchema,e)));if(o.length)throw new _(`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=>A(t.jsonSchema,e)));if(s.length)throw new _(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function ut(e){let t=o(e)?.context;if(!t)return;let n=h;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new _(`config`,`Profile ${e.id}: inputs.context.from must list ${h.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new _(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function X(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 _(`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 _(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function dt(e,t,n){let r=new Map,i=i=>{let a=q(i),s=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,u(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(it(e,s),at(e,s),s.type!==`host`&&s.type!==`decision`&&s.type!==`embedding`){st(e,s),X(s.id,o(s)),ut(s),lt(t,s);for(let[e,t]of Object.entries(s.models))t.compaction&&tt(r,s,e,t.compaction)}r.set(s.id,s)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new _(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function ft(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Z(e){let t;try{t=new URL(e.baseUrl)}catch{throw new _(`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 _(`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 _(`blocked`,`Local requests must stay on the configured origin.`))}}var pt=n({data:t(n({id:e().min(1)}))});async function mt(e,t){let n=Z(e);if(!n?.fetch)throw new _(`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 _(`network`,`Local model list returned HTTP ${r.status}.`);let i=pt.safeParse(await r.json());if(!i.success)throw new _(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var ht=`https://openrouter.ai/api/v1/models`,gt=`https://openrouter.ai/api/v1/embeddings/models`,_t=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],vt=[{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)`}],yt={text:`text`,image:`image`,speech:`speech`,transcription:`transcription`,live:void 0,embedding:void 0},bt=n({data:t(n({id:e().min(1),name:e().optional(),architecture:n({output_modalities:t(e()).optional()}).optional()}))}),Q=n({data:t(n({id:e().min(1),name:e().optional()}))}),xt=n({models:t(n({name:e().min(1),displayName:e().optional(),supportedGenerationMethods:t(e()).optional()})).optional(),nextPageToken:e().optional()}),St=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 _(`auth`,`${e} refused the key.`);if(!r.ok)throw new _(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Ct(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?vt:_t];if(e===`openrouter`)return await wt(t,i,r);if(!i)throw new _(`auth`,`Choose a key to list Gemini models.`);return await Et(t,i,r)}async function wt(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Q.safeParse(await $(`OpenRouter`,gt,r));if(!e.success)throw new _(`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=yt[e];if(!i)return[];let a=bt.safeParse(await $(`OpenRouter`,`${ht}?output_modalities=${i}`,r));if(!a.success)throw new _(`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 Tt={live:`bidiGenerateContent`,embedding:`embedContent`};async function Et(e,t,n){let i=Tt[e]??`generateContent`,a=[],o;for(let e=0;e<St;e++){let e=new URL(r);e.searchParams.set(`pageSize`,`1000`),o&&e.searchParams.set(`pageToken`,o);let s=xt.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!s.success)throw new _(`bad_response`,`Google returned an invalid model list.`);for(let e of s.data.models??[]){if(!e.supportedGenerationMethods?.includes(i))continue;let t=e.name.replace(/^models\//,``);a.push({id:t,label:e.displayName??t})}if(o=s.data.nextPageToken,!o)break}return a}function Dt(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Ot(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{Dt as a,q as c,k as d,j as f,y as g,N as h,Z as i,ct as l,M as m,mt as n,Ot as o,P as p,Ct as r,dt as s,ft as t,Se as u};
1
+ import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{J as r}from"./tool-schema-BxxcS67z.js";import{$t as i,Ba as a,Cn as o,Fi as s,Oi as c,Pi as l,Qt as u,Ti as ee,Wa as te,Xa as ne,Y as re,Zi as ie,ao as ae,ba as oe,bn as se,ea as ce,fa as d,lo as f,na as le,nn as ue,ta as p,uo as m,wi as h,xn as de,zi as g,zt as fe}from"./shaped-data-6dHnx8Ju.js";import{c as _}from"./host-patterns-DzBJj2uE.js";import{E as pe,N as me,O as he,S as ge,W as _e,b as v,j as ve}from"./schema-C6vwXzod.js";import{a as ye,n as be}from"./live-ingress-ZR7rtkDx.js";function y(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function b(e){return e==null}function x(e){return b(e)||typeof e!=`object`||Array.isArray(e)?null:e}function S(e){let t=x(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function C(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function w(e){let t=e.properties;return x(t)??{}}function xe(e,t){return e?`${e}.${t}`:t}function T(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function E(e,t,n,r,i,a){if(!n)return;let o;try{o=await n(t,r)}catch(e){a.push(e),o={isValid:!1}}o.isValid||i.push({path:e,error:o.error||o.finding||`Validation failed for '${e}'`})}async function D(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,options:o,failures:s,crashes:c}=e;if(b(r)){i&&T(t,s);return}await E(t,r,a?.[t],o,s,c);let l=S(n),u=l?x(r):null;l&&u&&await O(l,u,t,a,o,s,c)}async function O(e,t,n,r,i,a,o){let s=w(e),c=new Set(C(e)),l=new Set([...Object.keys(s),...c]),u=x(t);for(let e of l)await D({path:xe(n,e),propSchema:s[e],child:u?.[e],isRequired:c.has(e),fields:r,options:i,failures:a,crashes:o})}async function k(e,t,n,r,i=[]){let a=S(e);if(!a)throw new _(`config`,`structured validation requires a JSON Schema object root`);let o=[];if(!x(t)){for(let e of C(a))T(e,o);return o}return await O(a,t,``,n,r,o,i),o}function A(e,t){let n=e;for(let e of t.split(`.`)){let t=S(n);if(!t)return!1;let r=w(t);if(!Object.hasOwn(r,e)&&!C(t).includes(e))return!1;n=r[e]}return!0}function j(e){return e.map(e=>e.error).join(`; `)}function M(e,t){let n=e;for(let e of t.split(`.`))n=x(n)?.[e];return n}function N(e,t,n){let[r,...i]=t.split(`.`),a=x(e)??{};return r===void 0?e:{...a,[r]:i.length?N(a[r],i.join(`.`),n):n}}async function Se(e,t,n,r=[]){let i=[];for(let[a,o]of Object.entries(t??{})){let t=M(e,a);if(Array.isArray(t))for(let[e,s]of t.entries()){let t;try{t=await o.check(s,n)}catch(e){r.push(e),t={isValid:!1}}t.isValid||i.push({path:a,index:e,item:s,reason:t.error||t.finding||`Validation failed for '${a}'`,onFail:o.onFail})}}return i}function P(e,t){let n=e;for(let e of t.split(`.`)){let t=S(n);if(!t)return;n=w(t)[e]}let r=x(n);if(r?.type===`array`)return x(r.items)??void 0}function Ce(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new _(`config`,f(`provider.binding_identity`))}function we(e){L(e.id,e.models),K(e.id,e.observability),X(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:R(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Te(e){L(e.id,e.models),W(e.id,e.guardrails),K(e.id,e.observability);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new _(`config`,`Profile ${e.id}: a transcription takes a voice clip, so inputs.text must be false`);return{type:`transcription`,id:e.id,identity:{handle:e.identity.handle},...V(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function F(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new _(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${re(e.path)}: ${e.message}`).join(`; `)}`)}function Ee(e,t,n){if(F(e,t,n,i),Ce(e,t,n,`decision`),`retry`in n)throw new _(`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 _(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function De(e){let t=e.models?y(e.models):void 0;if(!t)throw new _(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);Ee(e.id,t,e.models[t])}function Oe(e){if(e.inputs.state!==`json`)throw new _(`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 _(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new _(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function ke(e){return De(e),Oe(e),K(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function I(e){return e===void 0?{}:{parallel:e}}function Ae(e){return je(e.id,e.tools),K(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...I(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function je(e,t){if(!Array.isArray(t.allow))throw new _(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function L(e,t){if(Object.keys(t).length===0)throw new _(`config`,`Profile ${e} must declare at least one model`)}function R(e,t){let n=t.defaultModel??y(t.models);if(!n)throw new _(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new _(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function z(e,t,n){B(e,t,n),F(e,t,n,ue),B(e,t,n)}function B(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new _(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!g.includes(i))throw new _(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${g.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new _(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new _(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new _(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function V(e){return{providerContinuation:e.providerContinuation?oe.parse(e.providerContinuation):{},models:e.models,defaultModel:R(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function H(e,t,n){if(n?.length){for(let r of n)if(!fe(r))throw new _(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (${ee.join(` | `)}); got '${r}'`)}}function Me(e,t){t&&(H(e,`allowContinue`,t.allowContinue),H(e,`autoContinue`,t.autoContinue))}function U(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ne(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>U(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var Pe=Object.entries(l).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Fe(e){if(!U(e))throw new _(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new _(`config`,`Profile definition must set id`);if(!s.find(t=>t===e.type))throw new _(`config`,`Profile ${t}: type must be one of ${s.join(`, `)}`)}function Ie(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 _(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function Le(e){let{id:t,type:n}=e,r=e;for(let[e,i]of Pe){if(i&&!i.includes(n))continue;let a=p(e),o=Ne(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!U(e))return!1;let t=e[s];return t==null||t===``}))throw new _(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Re(e){let{id:t,type:n}=e;if(n!==`live`&&le(`inputs`).includes(n)&&e.inputs==null)throw new _(`config`,`Profile ${t}: type '${n}' must set inputs`)}function ze(e){let[t]=ce(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new _(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Be(e,t){let n=t.turnBehaviour;Me(e,n?.resumption)}function Ve(e,t){let n=t=>new _(`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 W(e,t){let n=t=>new _(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!G.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${G.join(`, `)}`);Ue(t?.blockedReply,n)}var G=[`quota`,`detect`,`blockedReply`,`network`,`taint`],He=[`onBlock`,`maxRetries`];function Ue(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!He.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&&!a.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${a.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function We(e){let t=e.guardrails?.detect,n=e.type===`host`?d(`guardrails.detect`,t,te):d(`guardrails.detect`,t);if(n!==void 0)throw new _(`config`,`Profile ${e.id}: ${n}`)}function K(e,t){try{let n=ye(t);if(!Number.isFinite(n.retainForDays))throw new _(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new _(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof _&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new _(ne(t),`Profile ${e}: ${n}`,{cause:t})}}function Ge(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`transcription`||e.type===`embedding`)return;let{options:t,system:n}=e.identity,r=n??``;pe(r,`Profile ${e.id} identity.system`);let i=he(r,t,e.inputs?.options);if(i)throw new _(`config`,`Profile ${e.id} identity.system: ${i}`)}function q(e){let t=Ke(e),[n]=ie(e);if(n)throw new _(`config`,`Profile ${e.id}: ${n.path} ${n.message}`);return t}function Ke(e){Fe(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new _(`config`,f(`provider.profile_configuration`,{profile:e.id,field:t}));ze(e),Re(e),Le(e),Ie(e),e.labels&&m(e.labels,`Profile ${e.id}`);for(let t of ae)if(e.labels?.[t]!==void 0)throw new _(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(Ge(e),We(e),e.type===`host`)return Ae(e);if(e.type===`decision`)return ke(e);if(e.type===`embedding`)return we(e);if(e.type===`transcription`)return Te(e);L(e.id,e.models),Be(e.id,e),W(e.id,e.guardrails),e.type===`text`&&Ve(e.id,e.outputs?.validation),K(e.id,e.observability);for(let[t,n]of Object.entries(e.models))z(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,options:e.identity.options,system:e.identity.system},n=e.guardrails,r=e.observability,i=e.labels,a=V(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`image`:o={type:`image`,id:e.id,identity:t,...a,image:e.image,tools:e.tools,inputs:e.inputs,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Qe(o.id,o.inputs.attachments?.accept),Ze(o.id,o.image);break;case`speech`:o={type:`speech`,id:e.id,identity:t,...a,speech:e.speech,outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i};break;case`live`:o={type:`live`,id:e.id,identity:t,...a,live:e.live,inputs:e.inputs,tools:{allow:e.tools.allow,...I(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},be(o),et(o.id,o.live.contextCompression),$e(o);break;default:throw new _(`config`,`Unknown profile type '${String(e)}'`)}return Ye(o),qe(o),Je(o),o}function qe(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new _(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function Je(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new _(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function Ye(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=me(e,t.by);if(!n)throw new _(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not one of the profile's options`);let r=ve(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new _(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of option '${t.by}'`)}var Xe={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 Ze(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(Xe)){let a=t[n];if(a!==void 0&&!r(a))throw new _(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(se(t.mimeType)!==`image`)throw new _(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(_e(t)?t.uri:t.data))throw new _(`config`,`${r} needs its bytes or its uri`)})}function Qe(e,t){let n=t?.filter(e=>!de(c,e));if(n?.length)throw new _(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function $e(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 _(`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 _(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new _(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new _(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function et(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(J(`${n}.triggerTokens`,r),J(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new _(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function J(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new _(`config`,`${e} must be a whole number above 0`)}function tt(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(nt(i,r),rt(i,r),r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new _(`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 _(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new _(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function nt(e,t){if(t.maxTokens<=0)throw new _(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new _(`config`,`${e}: compactAt must be in (0, 1)`)}function rt(e,t){if(t.previousExchanges<0)throw new _(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new _(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new _(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function it(e,t){for(let n of v(t))if(e.get(n)?.type===`builtin`)throw new _(`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 at(e,t){let n=ge(t)?.t2Loader;if(n){if(!v(t).includes(n))throw new _(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new _(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*ot(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function st(e,t){for(let{modelId:n,id:r}of ot(t))if(e.get(r)?.type!==`builtin`)throw new _(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function Y(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 ct(e,t){return t?.type===`text`?Y(t).flatMap(t=>{let n=e.find(t);return n?[n.jsonSchema]:[]}):[]}function lt(e,t){let n=Y(t).map(n=>{let r=e.find(n);if(!r)throw new _(`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 _(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>P(t.jsonSchema,e)));if(o.length)throw new _(`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=>A(t.jsonSchema,e)));if(s.length)throw new _(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function ut(e){let t=o(e)?.context;if(!t)return;let n=h;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new _(`config`,`Profile ${e.id}: inputs.context.from must list ${h.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new _(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function X(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 _(`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 _(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function dt(e,t,n){let r=new Map,i=i=>{let a=q(i),s=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,u(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(it(e,s),at(e,s),s.type!==`host`&&s.type!==`decision`&&s.type!==`embedding`){st(e,s),X(s.id,o(s)),ut(s),lt(t,s);for(let[e,t]of Object.entries(s.models))t.compaction&&tt(r,s,e,t.compaction)}r.set(s.id,s)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new _(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function ft(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Z(e){let t;try{t=new URL(e.baseUrl)}catch{throw new _(`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 _(`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 _(`blocked`,`Local requests must stay on the configured origin.`))}}var pt=n({data:t(n({id:e().min(1)}))});async function mt(e,t){let n=Z(e);if(!n?.fetch)throw new _(`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 _(`network`,`Local model list returned HTTP ${r.status}.`);let i=pt.safeParse(await r.json());if(!i.success)throw new _(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var ht=`https://openrouter.ai/api/v1/models`,gt=`https://openrouter.ai/api/v1/embeddings/models`,_t=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],vt=[{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)`}],yt={text:`text`,image:`image`,speech:`speech`,transcription:`transcription`,live:void 0,embedding:void 0},bt=n({data:t(n({id:e().min(1),name:e().optional(),architecture:n({output_modalities:t(e()).optional()}).optional()}))}),Q=n({data:t(n({id:e().min(1),name:e().optional()}))}),xt=n({models:t(n({name:e().min(1),displayName:e().optional(),supportedGenerationMethods:t(e()).optional()})).optional(),nextPageToken:e().optional()}),St=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 _(`auth`,`${e} refused the key.`);if(!r.ok)throw new _(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Ct(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?vt:_t];if(e===`openrouter`)return await wt(t,i,r);if(!i)throw new _(`auth`,`Choose a key to list Gemini models.`);return await Et(t,i,r)}async function wt(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Q.safeParse(await $(`OpenRouter`,gt,r));if(!e.success)throw new _(`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=yt[e];if(!i)return[];let a=bt.safeParse(await $(`OpenRouter`,`${ht}?output_modalities=${i}`,r));if(!a.success)throw new _(`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 Tt={live:`bidiGenerateContent`,embedding:`embedContent`};async function Et(e,t,n){let i=Tt[e]??`generateContent`,a=[],o;for(let e=0;e<St;e++){let e=new URL(r);e.searchParams.set(`pageSize`,`1000`),o&&e.searchParams.set(`pageToken`,o);let s=xt.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!s.success)throw new _(`bad_response`,`Google returned an invalid model list.`);for(let e of s.data.models??[]){if(!e.supportedGenerationMethods?.includes(i))continue;let t=e.name.replace(/^models\//,``);a.push({id:t,label:e.displayName??t})}if(o=s.data.nextPageToken,!o)break}return a}function Dt(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Ot(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{Dt as a,q as c,k as d,j as f,y as g,N as h,Z as i,ct as l,M as m,mt as n,Ot as o,P as p,Ct as r,dt as s,ft as t,Se as u};