@theoremjs/studio 0.3.4-next.755.g88665bd → 0.3.4-next.759.g46e0e27

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 (106) hide show
  1. package/README.md +1 -1
  2. package/compile.d.ts +3 -3
  3. package/compile.js +70 -101
  4. package/cookbooks/catalog.js +14 -28
  5. package/draft.d.ts +24 -28
  6. package/draft.js +11 -12
  7. package/guardrail-probe.js +1 -30
  8. package/mod.d.ts +2 -2
  9. package/mod.js +2 -2
  10. package/package.json +4 -4
  11. package/page/assets/{ConsoleFrame-CrkjBcNX.js → ConsoleFrame-IP80BbVy.js} +1 -1
  12. package/page/assets/{MenuBottomSheet-BwRXL_tC.js → MenuBottomSheet-B90IZU5_.js} +1 -1
  13. package/page/assets/{SchemaFields-DDZ9Ydq2.js → SchemaFields-BBCNN0DQ.js} +1 -1
  14. package/page/assets/{ToolResultCharts-BUdWXhtV.js → ToolResultCharts-BA5C4s_d.js} +1 -1
  15. package/page/assets/{Toolbar-DVge1x9X.js → Toolbar-cLeL30W1.js} +1 -1
  16. package/page/assets/{TraceInspector-C7_3QCWN.js → TraceInspector-6xElMxMt.js} +1 -1
  17. package/page/assets/{TraceOverview-jII-Bu5d.js → TraceOverview-BgjbNvh5.js} +1 -1
  18. package/page/assets/{_virtual_studio-type-sources-Cc4WAdgD.js → _virtual_studio-type-sources-_88V0ngH.js} +37 -44
  19. package/page/assets/browser-connection-C1_PJcSQ.js +1 -0
  20. package/page/assets/browser-engine-VzmlJFEv.js +16 -0
  21. package/page/assets/browser-transport-JN5LOARG.js +45 -0
  22. package/page/assets/compile-BJuLB_as.js +2 -0
  23. package/page/assets/{encode-files-CeZxxjYd.js → encode-files-CCet4LKE.js} +1 -1
  24. package/page/assets/{export-agent-DdEWpt6u.js → export-agent-BzdhT7lw.js} +8 -8
  25. package/page/assets/{guardrail-tester-B4Yww5k5.js → guardrail-tester-M-A7EKhq.js} +1 -1
  26. package/page/assets/index-BHZr7HfC.js +149 -0
  27. package/page/assets/index-BYDlXF8Q.css +1 -0
  28. package/page/assets/live-messages-tG47aB12.js +1 -0
  29. package/page/assets/{prompt-row-Bk7GFhYO.js → prompt-row-BUe2Ni0Y.js} +2 -2
  30. package/page/assets/reader-SzTjS7rw.js +5 -0
  31. package/page/assets/{registry-DP0ArymS.js → registry-BrmnEhgs.js} +1 -1
  32. package/page/assets/schema-BztznKB7.js +3 -0
  33. package/page/assets/{shaped-data-DCfLI4gb.js → shaped-data-D15FDUcH.js} +3 -3
  34. package/page/assets/{stub-REBz-ZC7.js → stub-CJG-5zBe.js} +1 -1
  35. package/page/assets/studio-code-pane-k8fWxZOU.js +10 -0
  36. package/page/assets/{studio-console-DBBO9MHS.js → studio-console-BANFk07G.js} +1 -1
  37. package/page/assets/{studio-decision-BHYhB2Cb.js → studio-decision-DFj8AA2c.js} +1 -1
  38. package/page/assets/{studio-embedding-Dl4VphLm.js → studio-embedding-CZy7UHg8.js} +1 -1
  39. package/page/assets/{studio-host-console-0TjvULFQ.js → studio-host-console-CRxuC6E-.js} +2 -2
  40. package/page/assets/{studio-labels-D3Lfl3hb.js → studio-labels-3Sq86Mzp.js} +1 -1
  41. package/page/assets/studio-live-BcOCiV63.js +5 -0
  42. package/page/assets/{studio-map-CdvXdFHw.js → studio-map-CCtcfniD.js} +1 -1
  43. package/page/assets/{studio-trace-replay-DpdJ0JHL.js → studio-trace-replay-C5t6OfXY.js} +1 -1
  44. package/page/assets/{studio-type-checker-JZuu4iVI.js → studio-type-checker-o2Q6t4mP.js} +1 -1
  45. package/page/assets/{tool-schema-BwaPiLtT.js → tool-schema-D26IAEC3.js} +1 -1
  46. package/page/assets/trace-record-jocyYEPa.js +1 -0
  47. package/page/assets/tree-B0fXPCwG.js +3 -0
  48. package/page/assets/{turn-client-B3jV7UKH.js → turn-client-eM8VIbMd.js} +1 -1
  49. package/page/assets/{types-BDx4pnrt.js → types-CfC3vRXO.js} +1 -1
  50. package/page/assets/{use-one-call-BsQ7BdIB.js → use-one-call-Drfw4kwV.js} +1 -1
  51. package/page/assets/{workspace-B6d08n7C.js → workspace-BlOYHATA.js} +1 -1
  52. package/page/index.html +17 -17
  53. package/prompt-doc.d.ts +1 -1
  54. package/prompt-doc.js +2 -2
  55. package/read-source.js +26 -39
  56. package/section-notes.d.ts +1 -2
  57. package/section-notes.js +1 -2
  58. package/server/events.d.ts +2 -4
  59. package/server/events.js +4 -11
  60. package/server/handler.d.ts +3 -1
  61. package/server/handler.js +8 -1
  62. package/server/kept-sessions.d.ts +32 -0
  63. package/server/kept-sessions.js +103 -0
  64. package/server/project.d.ts +3 -1
  65. package/server/project.js +2 -0
  66. package/server/serve.js +38 -30
  67. package/server/test-connection.js +6 -6
  68. package/system-markup.d.ts +1 -1
  69. package/system-markup.js +1 -1
  70. package/ui/lib/export-agent.js +9 -26
  71. package/ui/lib/studio-page.d.ts +9 -16
  72. package/ui/lib/studio-page.js +28 -38
  73. package/ui/lib/studio-watch.d.ts +0 -6
  74. package/ui/lib/studio-watch.js +0 -16
  75. package/ui/profile-editor.js +46 -93
  76. package/ui/prompt-editor.d.ts +1 -1
  77. package/ui/prompt-editor.js +11 -11
  78. package/ui/prompt-line-node.d.ts +5 -5
  79. package/ui/prompt-line-node.js +9 -9
  80. package/ui/prompt-row.d.ts +3 -3
  81. package/ui/prompt-row.js +3 -3
  82. package/ui/studio-compare.d.ts +4 -2
  83. package/ui/studio-compare.js +7 -40
  84. package/ui/studio-live.d.ts +1 -1
  85. package/ui/studio-live.js +2 -2
  86. package/ui/studio-runner.d.ts +4 -3
  87. package/ui/studio-runner.js +9 -9
  88. package/ui/studio-save.d.ts +0 -2
  89. package/ui/studio-save.js +2 -10
  90. package/ui/studio-screen.js +5 -2
  91. package/ui/studio.css +3 -3
  92. package/page/assets/browser-connection-159CdeHX.js +0 -1
  93. package/page/assets/browser-engine-CBH9AXVa.js +0 -16
  94. package/page/assets/browser-transport-Di-GC8aq.js +0 -45
  95. package/page/assets/compile-iB2CAmRL.js +0 -2
  96. package/page/assets/index-CLDHVoB_.js +0 -149
  97. package/page/assets/index-DakRjE8R.css +0 -1
  98. package/page/assets/live-messages-D-SPyR3e.js +0 -1
  99. package/page/assets/reader-DtOL_I1x.js +0 -5
  100. package/page/assets/schema-Cv4HAfBT.js +0 -3
  101. package/page/assets/studio-code-pane-R4MAbIzr.js +0 -10
  102. package/page/assets/studio-live-BD9Ilm1M.js +0 -5
  103. package/page/assets/trace-record--uEnDt_D.js +0 -1
  104. package/page/assets/tree-CL4ETBd5.js +0 -3
  105. package/slot-values.d.ts +0 -2
  106. package/slot-values.js +0 -22
@@ -4677,11 +4677,11 @@ declare function toolBoundary<C extends ToolCrossing, K extends ToolKind>(crossi
4677
4677
  /** Every tool boundary, each crossing in turn for every kind of tool. */
4678
4678
  declare const TOOL_BOUNDARIES: readonly ToolBoundary[];
4679
4679
  /** Where text reaches the model from the person or the host. */
4680
- declare const INBOUND_BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user"];
4680
+ declare const INBOUND_BOUNDARIES: readonly ["user", "attachment", "voice", "options", "context", "history", "injected", "system", "repair", "live_user"];
4681
4681
  /** Where the model's own text reaches the person. */
4682
4682
  declare const OUTBOUND_BOUNDARIES: readonly ["reply", "reply_structured", "live_reply", "thought"];
4683
4683
  /** Every place the kernel reads text as it crosses, in the order a turn meets them. */
4684
- declare const BOUNDARIES: readonly ["user", "attachment", "voice", "slots", "context", "history", "injected", "system", "repair", "live_user", ...("tool_arguments_function" | "tool_arguments_http" | "tool_arguments_mcp" | "tool_arguments_agent" | "tool_output_function" | "tool_output_http" | "tool_output_mcp" | "tool_output_agent" | "tool_failure_function" | "tool_failure_http" | "tool_failure_mcp" | "tool_failure_agent" | "tool_shown_function" | "tool_shown_http" | "tool_shown_mcp" | "tool_shown_agent")[], "reply", "reply_structured", "live_reply", "thought"];
4684
+ declare const BOUNDARIES: readonly ["user", "attachment", "voice", "options", "context", "history", "injected", "system", "repair", "live_user", ...("tool_arguments_function" | "tool_arguments_http" | "tool_arguments_mcp" | "tool_arguments_agent" | "tool_output_function" | "tool_output_http" | "tool_output_mcp" | "tool_output_agent" | "tool_failure_function" | "tool_failure_http" | "tool_failure_mcp" | "tool_failure_agent" | "tool_shown_function" | "tool_shown_http" | "tool_shown_mcp" | "tool_shown_agent")[], "reply", "reply_structured", "live_reply", "thought"];
4685
4685
  /** One of {@linkcode BOUNDARIES}. */
4686
4686
  type Boundary = (typeof BOUNDARIES)[number];
4687
4687
  /** How a boundary is named and described to a builder. */
@@ -5396,8 +5396,8 @@ export interface AttachmentValidationIssue {
5396
5396
  params?: AttachmentValidationParams;
5397
5397
  fileName?: string;
5398
5398
  }
5399
- /** Picks the structured-output schema by the value of a turn slot, with a fallback. */
5400
- export interface StructuredBySlot {
5399
+ /** Picks the structured-output schema by the value of a turn's option, with a fallback. */
5400
+ export interface StructuredByOption {
5401
5401
  by: string;
5402
5402
  map: Record<string, string>;
5403
5403
  fallback: string;
@@ -5410,7 +5410,7 @@ export interface ValidationResult {
5410
5410
  data?: Record<string, unknown>;
5411
5411
  }
5412
5412
  /** A host function that checks one structured-output field. */
5413
- export type ProfileValidator = (candidate: unknown, slots?: Record<string, string>) => ValidationResult | Promise<ValidationResult>;
5413
+ export type ProfileValidator = (candidate: unknown, options?: Readonly<Record<string, string>>) => ValidationResult | Promise<ValidationResult>;
5414
5414
  /** A tool call the turn completed, as an item check reads it. */
5415
5415
  export interface TurnToolResult {
5416
5416
  tool: string;
@@ -5419,7 +5419,8 @@ export interface TurnToolResult {
5419
5419
  }
5420
5420
  /** What an item check reads of the turn whose reply it is checking. */
5421
5421
  export interface ItemCheckTurn {
5422
- slots?: Record<string, string>;
5422
+ /** The value of each option the turn set. */
5423
+ options?: Readonly<Record<string, string>>;
5423
5424
  /** Every tool call the turn completed, in order, across its attempts. */
5424
5425
  toolResults: readonly TurnToolResult[];
5425
5426
  }
@@ -5552,24 +5553,18 @@ export interface ProfileModelFields {
5552
5553
  /** Tool-loop ceiling. Omit = \`DEFAULT_MAX_STEPS\`; \`1\` = one-shot; \`> 1\` = hard cap. */
5553
5554
  maxSteps?: number;
5554
5555
  }
5555
- /**
5556
- * One allowed value for an \`inputs.slots\` entry. \`value\` is what the turn sends and what
5557
- * \`{name}\` fills; optional \`description\` is visitor-facing UI copy only.
5558
- */
5559
- export interface SlotChoice {
5556
+ /** One value an option can take. \`description\` is what a picker shows beside it. */
5557
+ export interface OptionChoice {
5560
5558
  value: string;
5561
5559
  description?: string;
5562
5560
  }
5563
- /**
5564
- * One named slot: optional group \`label\` for the UI, and its choices. A bare \`string[]\` is
5565
- * still accepted on define and normalized to \`{ choices: [{ value }] }\`.
5566
- */
5567
- export interface SlotDecl {
5561
+ /** One named option: its \`label\` for a picker, and the values it can take. */
5562
+ export interface OptionDecl {
5568
5563
  label?: string;
5569
- choices: SlotChoice[];
5564
+ choices: OptionChoice[];
5570
5565
  }
5571
- /** Authoring form for one slot: legacy value list, or a labeled declaration. */
5572
- export type SlotDeclInput = string[] | SlotDecl;
5566
+ /** A profile's options by name. Which object holds them says who drives them. */
5567
+ export type ProfileOptions = Readonly<Record<string, OptionDecl>>;
5573
5568
  /** What a profile accepts as input. */
5574
5569
  export interface ProfileInputsSpec {
5575
5570
  text?: boolean;
@@ -5583,11 +5578,12 @@ export interface ProfileInputsSpec {
5583
5578
  maxBytes?: number;
5584
5579
  maxTurnBytes?: number;
5585
5580
  limitsByMime?: Record<string, number>;
5586
- slots?: Record<string, SlotDeclInput>;
5581
+ /** The options a person picks: a host shows each one as a picker. */
5582
+ options?: ProfileOptions;
5587
5583
  context?: ProfileContextSpec;
5588
5584
  }
5589
5585
  /** What a live profile declares beside its ingress channels. */
5590
- export type LiveInputsSpec = Pick<ProfileInputsSpec, 'slots' | 'context'>;
5586
+ export type LiveInputsSpec = Pick<ProfileInputsSpec, 'options' | 'context'>;
5591
5587
  /** Who may send a turn its context, and how much. */
5592
5588
  export interface ProfileContextSpec {
5593
5589
  from: ContextSender[];
@@ -5597,7 +5593,7 @@ export interface ProfileContextSpec {
5597
5593
  export type TurnContext = Partial<Record<ContextSender, unknown>>;
5598
5594
  /** What a profile returns: its structured schema, validation, and streaming. */
5599
5595
  export interface ProfileOutputsSpec {
5600
- structured?: StructuredSchemaId | StructuredBySlot | null;
5596
+ structured?: StructuredSchemaId | StructuredByOption | null;
5601
5597
  validation?: ProfileValidationSpec;
5602
5598
  streaming?: ProfileStreamingSpec;
5603
5599
  }
@@ -5617,8 +5613,6 @@ export type SystemPrompt = string | readonly SystemPart[];
5617
5613
  export type SystemLine = string | readonly SystemPart[];
5618
5614
  /** A profile's prompt: a string, or lines. Every line that fits is sent, a blank line apart. */
5619
5615
  export type ProfileSystem = string | readonly SystemLine[];
5620
- /** The facts a host states on each turn, by name, each with the values it can take. */
5621
- export type ProfileConditions = Readonly<Record<string, readonly string[]>>;
5622
5616
  /** A stretch of the system prompt as sent, and whether a reply may repeat it. */
5623
5617
  export interface SystemPiece {
5624
5618
  text: string;
@@ -5627,8 +5621,8 @@ export interface SystemPiece {
5627
5621
  /** A profile's handle and system prompt. */
5628
5622
  export interface ProfileIdentity {
5629
5623
  handle: string;
5630
- /** The facts this agent's turns state, by name, with the values each can take. */
5631
- conditions?: ProfileConditions;
5624
+ /** The options the host's code states. A person never sees them. */
5625
+ options?: ProfileOptions;
5632
5626
  system?: ProfileSystem;
5633
5627
  }
5634
5628
  /** The fields every profile type shares. */
@@ -5944,10 +5938,11 @@ export interface TurnRepairRequest {
5944
5938
  rejection: string;
5945
5939
  guidance?: string;
5946
5940
  }
5947
- /** What the user sent for a turn: text, slots, attachments, voice, and history. */
5941
+ /** What the user sent for a turn: text, options, attachments, voice, and history. */
5948
5942
  export interface TurnInput {
5949
5943
  text?: string;
5950
- slots?: Record<string, string>;
5944
+ /** The value picked for each of the profile's \`inputs.options\`. */
5945
+ options?: Readonly<Record<string, string>>;
5951
5946
  /** What the page or the host wants the model to know, by sender; the profile's \`inputs.context\` allows it. */
5952
5947
  context?: TurnContext;
5953
5948
  attachments?: Array<TurnBlob | TurnMediaRef>;
@@ -6001,8 +5996,8 @@ export interface AgentRunRequest extends RunControls, ModelChoice {
6001
5996
  sessionPermissions?: string[];
6002
5997
  /** Host channel/path for catalog \`paths\` filtering. */
6003
5998
  path?: string;
6004
- /** This run's facts, one value for each of \`profile.identity.conditions\` but \`path\`. */
6005
- conditions?: Readonly<Record<string, string>>;
5999
+ /** This run's value for each of \`profile.identity.options\` it sets; \`path\` is the run's own. */
6000
+ options?: Readonly<Record<string, string>>;
6006
6001
  /**
6007
6002
  * Opaque application context handed to tool \`handler\` / \`preTool\` and
6008
6003
  * \`tools.t1Policy\` as \`ctx.host\`. The kernel never reads, logs, traces, or
@@ -6187,8 +6182,8 @@ export interface SessionRequest extends AgentRunRequest {
6187
6182
  /** Override \`profile.live.voice\` for this session. */
6188
6183
  voice?: string;
6189
6184
  history?: TurnHistoryMessage[];
6190
- /** The value chosen for each of the profile's \`inputs.slots\`. */
6191
- slots?: Record<string, string>;
6185
+ /** The value picked for each of the profile's \`inputs.options\`. */
6186
+ inputOptions?: Record<string, string>;
6192
6187
  /** What the page and the host tell the agent as the call opens; \`sendContext\` replaces it later. */
6193
6188
  context?: TurnContext;
6194
6189
  /** How long the caller was away before this resume, in milliseconds. The session keeps no clock across calls. */
@@ -7864,7 +7859,7 @@ export interface GuardrailContext {
7864
7859
  */
7865
7860
  privateSystem?: readonly string[];
7866
7861
  role?: string;
7867
- slots?: Record<string, string>;
7862
+ options?: Readonly<Record<string, string>>;
7868
7863
  /** Set on tool-shaped stages; absent for user and system text. */
7869
7864
  provenance?: Provenance;
7870
7865
  /**
@@ -9294,7 +9289,7 @@ export interface McpSessionLimits {
9294
9289
  * What an agent tool call carries: the text, and whatever else the called
9295
9290
  * profile's \`inputs\` declares. \`speech\` is for a speech profile.
9296
9291
  */
9297
- export interface AgentToolInput extends Pick<TurnInput, 'slots' | 'attachments' | 'voice'> {
9292
+ export interface AgentToolInput extends Pick<TurnInput, 'options' | 'attachments' | 'voice'> {
9298
9293
  text: string;
9299
9294
  speech?: TurnSpeech;
9300
9295
  }
@@ -9310,7 +9305,7 @@ export interface AgentToolOutput {
9310
9305
  sources?: Source[];
9311
9306
  }
9312
9307
  /** A channel of an agent tool's input that the called profile's \`inputs\` declares. */
9313
- export type AgentToolChannel = 'attachments' | 'voice' | 'slots';
9308
+ export type AgentToolChannel = 'attachments' | 'voice' | 'options';
9314
9309
  /**
9315
9310
  * A tool whose call runs one turn of another registered agent. That agent is a
9316
9311
  * standalone profile; the tool is how another agent's model calls it. Its input
@@ -11433,7 +11428,7 @@ declare function splitHostInput(tool: Pick<AgentToolDef, 'hostFields'>, input: A
11433
11428
  * called turn's own ingress checks MIME types and sizes.
11434
11429
  */
11435
11430
  declare function agentToolInputFor(agent: Pick<Profile, 'type'> & {
11436
- inputs?: Pick<ProfileInputsSpec, 'attachments' | 'voice' | 'slots'>;
11431
+ inputs?: Pick<ProfileInputsSpec, 'attachments' | 'voice' | 'options'>;
11437
11432
  }, tool?: Pick<AgentToolDef, 'name' | 'fieldText' | 'hostFields' | 'hostOnly'>): z.ZodType<AgentToolInput>;
11438
11433
  declare const agentToolOutput: z.ZodType<AgentToolOutput>;
11439
11434
  /** Why \`profile\` can't be run by an agent tool, or \`undefined\` when it can. */
@@ -11873,11 +11868,9 @@ export interface MemoryToolExecutionOptions {
11873
11868
  * A host that resumes across requests or workers supplies its own \`ToolExecutionCoordinator\`.
11874
11869
  */
11875
11870
  export declare function createMemoryToolExecution(options?: MemoryToolExecutionOptions): ToolExecutionCoordinator;
11876
- `,"file:///node_modules/@theoremjs/agents/src/kernel/system-lines.d.ts":`import type { ProfileConditions, ProfileSystem, SystemPiece, TurnRequest } from './types.js';
11877
- /** What is wrong with a prompt's conditions and lines, or undefined. */
11878
- export declare function systemLinesProblem(prompt: ProfileSystem, conditions: ProfileConditions | undefined, slots: Record<string, readonly string[]>): string | undefined;
11879
- /** The facts a turn's \`when\` reads, once the turn has stated every condition with a listed value. */
11880
- export declare function turnFacts(id: string, conditions: ProfileConditions | undefined, req: Pick<TurnRequest, 'path' | 'conditions'>, slots: Record<string, string> | undefined): Record<string, string>;
11871
+ `,"file:///node_modules/@theoremjs/agents/src/kernel/system-lines.d.ts":`import type { ProfileOptions, ProfileSystem, SystemPiece } from './types.js';
11872
+ /** What is wrong with a prompt's options and lines, or undefined. */
11873
+ export declare function systemLinesProblem(prompt: ProfileSystem, code: ProfileOptions | undefined, person: ProfileOptions | undefined): string | undefined;
11881
11874
  /** A line that fit a turn: its number in the prompt as written, from 1, and its pieces. */
11882
11875
  export type KeptSystemLine = {
11883
11876
  line: number;
@@ -11887,11 +11880,11 @@ export type KeptSystemLine = {
11887
11880
  * Every line that fits. Whether plain text is shareable is settled on the prompt as written, so a
11888
11881
  * line dropped on this turn never changes the marks of one that stayed.
11889
11882
  */
11890
- export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string): KeptSystemLine[];
11883
+ export declare function pickSystemLines(prompt: ProfileSystem, facts: Record<string, string>, fill: (text: string) => string | undefined): KeptSystemLine[];
11891
11884
  /** \`where\` names the prompt in the error. A bare \`{ private }\` must sit inside a line's own list. */
11892
11885
  export declare function assertSystemLines(prompt: unknown, where: string): asserts prompt is ProfileSystem;
11893
- /** The first tool in \`tools\` with a path \`conditions.path\` does not list, as a sentence. */
11894
- export declare function toolPathProblem(conditions: ProfileConditions | undefined, tools: readonly {
11886
+ /** The first tool in \`tools\` with a path \`options.path\` does not list, as a sentence. */
11887
+ export declare function toolPathProblem(options: ProfileOptions | undefined, tools: readonly {
11895
11888
  name: string;
11896
11889
  paths?: readonly string[];
11897
11890
  }[]): string | undefined;
@@ -0,0 +1 @@
1
+ import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{Cn as r,H as i,Sn as a,Tn as o,Xt as s,bn as c,fn as l,ln as ee,nr as te,un as ne,xn as u}from"./tool-schema-D26IAEC3.js";import{c as d}from"./host-patterns-F-KZIzkF.js";import{Cr as re,Hr as f,In as ie,Jn as p,Ln as ae,Nn as oe,Rn as se,Rr as ce,Ur as le,ar as ue,cn as de,gn as m,hn as fe,in as h,kr as pe,mr as me,or as he,xn as g}from"./shaped-data-D15FDUcH.js";import{E as ge,b as _e,j as ve,k as ye,v as _,w as be}from"./schema-BztznKB7.js";import{a as xe,n as Se}from"./live-ingress-OuSlQ6q7.js";var Ce=2,we=4,Te=3,Ee=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,De=/^[A-Za-z0-9+/]*={0,2}$/,Oe=new Set([`text/csv`,`text/plain`,`text/markdown`]);function v(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 ke(e,t){if(t.limitsByMime){let n=o(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 y(e){return`uri`in e}function Ae(e){if(e.type===`speech`)throw new d(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new d(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new d(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=v(e.inputs??{});if(!t)throw new d(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function je(e){let t=0;return e.endsWith(`==`)?t=Ce:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Te/we)-t}function Me(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function Ne(e){return e.replace(Ee,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function Pe(e,t,n){let r=Me(t);return e===`text/csv`&&(r=Ne(r)),new TextEncoder().encode(n.read(r))}function b(e,t){return t?{...e,fileName:t}:e}function x(e,t,n){return t.filter(t=>!u(e,t.mimeType)).map(e=>b({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function Fe(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=ke(i.mimeType,t);i.sizeBytes>e&&n.push(b({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 S(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(...x(e.attachments,t,`attachment`)),e.voice&&r.push(...x(e.voice,n,`voice`)),e.limits?[...r,...Fe([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var Ie={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 C(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:Ie[e.code],params:t}}function Le(e,t){let n=C(e);return f(n.key,n.params,t)}function Re(e){return new d(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(C)})}function w(e){if(!De.test(e))throw new d(`request`,`attachment data must be base64`);return je(e)}function T(e){let t={mimeType:e.mimeType,name:e.name};return y(e)||(t.sizeBytes=w(e.data)),t}function ze(e,t,n){if(!Be(t,n))return;let r=Ae(e),i=S({attachments:a(e,`attachments`),voice:a(e,`voice`),limits:r},(t??[]).map(T),(n??[]).map(T));if(i.length>0)throw Re(i)}function E(e,t){if(y(e))return e;let{mimeType:n,data:r}=e;if(!Oe.has(o(n)))return e;let i=Pe(n,ue(r),t);return{...e,data:he(i)}}function Be(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Ve(e,t,n,r){return ze(e,t,n),{attachments:t?.length?t.map(e=>E(e,r.attachment)):t,voice:n?.length?n.map(e=>E(e,r.voice)):n}}function D(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function O(e){return e==null}function k(e){return O(e)||typeof e!=`object`||Array.isArray(e)?null:e}function A(e){let t=k(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function j(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function M(e){let t=e.properties;return k(t)??{}}function He(e,t){return e?`${e}.${t}`:t}function N(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function Ue(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 We(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,options:o,failures:s}=e;if(O(r)){i&&N(t,s);return}await Ue(t,r,a?.[t],o,s);let c=A(n),l=c?k(r):null;c&&l&&await P(c,l,t,a,o,s)}async function P(e,t,n,r,i,a){let o=M(e),s=new Set(j(e)),c=new Set([...Object.keys(o),...s]),l=k(t);for(let e of c)await We({path:He(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,options:i,failures:a})}async function Ge(e,t,n,r){let i=A(e);if(!i)throw new d(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!k(t)){for(let e of j(i))N(e,a);return a}return await P(i,t,``,n,r,a),a}function Ke(e,t){let n=e;for(let e of t.split(`.`)){let t=A(n);if(!t)return!1;let r=M(t);if(!Object.hasOwn(r,e)&&!j(t).includes(e))return!1;n=r[e]}return!0}function qe(e){return e.map(e=>e.error).join(`; `)}function F(e,t){let n=e;for(let e of t.split(`.`))n=k(n)?.[e];return n}function I(e,t,n){let[r,...i]=t.split(`.`),a=k(e)??{};return r===void 0?e:{...a,[r]:i.length?I(a[r],i.join(`.`),n):n}}async function Je(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=F(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 L(e,t){let n=e;for(let e of t.split(`.`)){let t=A(n);if(!t)return;n=M(t)[e]}let r=k(n);if(r?.type===`array`)return k(r.items)??void 0}function Ye(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new d(`config`,f(`provider.binding_identity`))}function Xe(e){z(e.id,e.models),J(e.id,e.observability),Z(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))V(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:B(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Ze(e){z(e.id,e.models),K(e.id,e.guardrails),J(e.id,e.observability);for(let[t,n]of Object.entries(e.models))V(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new d(`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},...U(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function R(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new d(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function Qe(e,t,n){if(R(e,t,n,ne),Ye(e,t,n,`decision`),`retry`in n)throw new d(`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 d(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function $e(e){let t=e.models?D(e.models):void 0;if(!t)throw new d(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);Qe(e.id,t,e.models[t])}function et(e){if(e.inputs.state!==`json`)throw new d(`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 d(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new d(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function tt(e){return $e(e),et(e),J(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function nt(e){return e===void 0?{}:{parallel:e}}function rt(e){return it(e.id,e.tools),J(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...nt(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function it(e,t){if(!Array.isArray(t.allow))throw new d(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function z(e,t){if(Object.keys(t).length===0)throw new d(`config`,`Profile ${e} must declare at least one model`)}function B(e,t){let n=t.defaultModel??D(t.models);if(!n)throw new d(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new d(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function V(e,t,n){H(e,t,n),R(e,t,n,l),H(e,t,n)}function H(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new d(`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 d(`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 d(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new d(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new d(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function U(e){return{providerContinuation:e.providerContinuation?te.parse(e.providerContinuation):{},models:e.models,defaultModel:B(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function W(e,t,n){if(n?.length){for(let r of n)if(!s(r))throw new d(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function at(e,t){t&&(W(e,`allowContinue`,t.allowContinue),W(e,`autoContinue`,t.autoContinue))}function G(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ot(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>G(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var st=Object.entries(fe).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function ct(e){if(!G(e))throw new d(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new d(`config`,`Profile definition must set id`);if(!m.find(t=>t===e.type))throw new d(`config`,`Profile ${t}: type must be one of ${m.join(`, `)}`)}function lt(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 d(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function ut(e){let{id:t,type:n}=e,r=e;for(let[e,i]of st){if(i&&!i.includes(n))continue;let a=ae(e),o=ot(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!G(e))return!1;let t=e[s];return t==null||t===``}))throw new d(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function dt(e){let{id:t,type:n}=e;if(n!==`live`&&se(`inputs`).includes(n)&&e.inputs==null)throw new d(`config`,`Profile ${t}: type '${n}' must set inputs`)}function ft(e){let[t]=ie(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new d(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function pt(e,t){let n=t.turnBehaviour;at(e,n?.resumption)}function mt(e,t){let n=t=>new d(`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 K(e,t){let n=t=>new d(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!q.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${q.join(`, `)}`);gt(t?.blockedReply,n)}var q=[`quota`,`detect`,`blockedReply`,`network`,`taint`],ht=[`onBlock`,`maxRetries`];function gt(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!ht.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&&!me.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${me.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function _t(e){let t=e.guardrails?.detect,n=e.type===`host`?p(`guardrails.detect`,t,re):p(`guardrails.detect`,t);if(n!==void 0)throw new d(`config`,`Profile ${e.id}: ${n}`)}function J(e,t){try{let n=xe(t);if(!Number.isFinite(n.retainForDays))throw new d(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new d(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof d&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new d(pe(t),`Profile ${e}: ${n}`,{cause:t})}}function vt(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??``;be(r,`Profile ${e.id} identity.system`);let i=ge(r,t,e.inputs?.options);if(i)throw new d(`config`,`Profile ${e.id} identity.system: ${i}`)}function Y(e){let t=yt(e),[n]=oe(e);if(n)throw new d(`config`,`Profile ${e.id}: ${n.path} ${n.message}`);return t}function yt(e){ct(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new d(`config`,f(`provider.profile_configuration`,{profile:e.id,field:t}));ft(e),dt(e),ut(e),lt(e),e.labels&&le(e.labels,`Profile ${e.id}`);for(let t of ce)if(e.labels?.[t]!==void 0)throw new d(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(vt(e),_t(e),e.type===`host`)return rt(e);if(e.type===`decision`)return tt(e);if(e.type===`embedding`)return Xe(e);if(e.type===`transcription`)return Ze(e);z(e.id,e.models),pt(e.id,e),K(e.id,e.guardrails),e.type===`text`&&mt(e.id,e.outputs?.validation),J(e.id,e.observability);for(let[t,n]of Object.entries(e.models))V(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=U(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},Tt(o.id,o.inputs.attachments?.accept),wt(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,...nt(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},Se(o),Dt(o.id,o.live.contextCompression),Et(o);break;default:throw new d(`config`,`Unknown profile type '${String(e)}'`)}return St(o),bt(o),xt(o),o}function bt(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new d(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function xt(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new d(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function St(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=ve(e,t.by);if(!n)throw new d(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not one of the profile's options`);let r=ye(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new d(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of option '${t.by}'`)}var Ct={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 wt(e,t){for(let[n,{ok:r,rule:i}]of Object.entries(Ct)){let a=t[n];if(a!==void 0&&!r(a))throw new d(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(c(t.mimeType)!==`image`)throw new d(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(y(t)?t.uri:t.data))throw new d(`config`,`${r} needs its bytes or its uri`)})}function Tt(e,t){let n=t?.filter(e=>!u(de,e));if(n?.length)throw new d(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function Et(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 d(`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 d(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new d(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new d(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function Dt(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(X(`${n}.triggerTokens`,r),X(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new d(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function X(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new d(`config`,`${e} must be a whole number above 0`)}function Ot(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(kt(i,r),At(i,r),r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new d(`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 d(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new d(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function kt(e,t){if(t.maxTokens<=0)throw new d(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new d(`config`,`${e}: compactAt must be in (0, 1)`)}function At(e,t){if(t.previousExchanges<0)throw new d(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new d(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new d(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function jt(e,t){for(let n of _(t))if(e.get(n)?.type===`builtin`)throw new d(`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 Mt(e,t){let n=_e(t)?.t2Loader;if(n){if(!_(t).includes(n))throw new d(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new d(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*Nt(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function Pt(e,t){for(let{modelId:n,id:r}of Nt(t))if(e.get(r)?.type!==`builtin`)throw new d(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function Ft(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 It(e,t){let n=Ft(t).map(n=>{let r=e.find(n);if(!r)throw new d(`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 d(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>L(t.jsonSchema,e)));if(o.length)throw new d(`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=>Ke(t.jsonSchema,e)));if(s.length)throw new d(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function Lt(e){let t=r(e)?.context;if(!t)return;let n=h;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new d(`config`,`Profile ${e.id}: inputs.context.from must list ${h.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new d(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function Z(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 d(`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 d(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Rt(e,t,n){let i=new Map,a=a=>{let o=Y(a),s=n&&o.type!==`host`?{...o,models:Object.fromEntries(Object.entries(o.models).map(([e,t])=>[e,ee(n.require(t.provider,t.apiId),t,o.type)]))}:o;if(jt(e,s),Mt(e,s),s.type!==`host`&&s.type!==`decision`&&s.type!==`embedding`){Pt(e,s),Z(s.id,r(s)),Lt(s),It(t,s);for(let[e,t]of Object.entries(s.models))t.compaction&&Ot(i,s,e,t.compaction)}i.set(s.id,s)};return{register:a,registerMany(e){for(let t of e)a(t)},get(e){let t=i.get(e);if(!t)throw new d(`config`,`Unknown profile '${e}'`);return t},find:e=>i.get(e),has:e=>i.has(e),list:()=>[...i.values()],clear:()=>i.clear()}}function zt(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Q(e){let t;try{t=new URL(e.baseUrl)}catch{throw new d(`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 d(`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 d(`blocked`,`Local requests must stay on the configured origin.`))}}var Bt=n({data:t(n({id:e().min(1)}))});async function Vt(e,t){let n=Q(e);if(!n?.fetch)throw new d(`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 d(`network`,`Local model list returned HTTP ${r.status}.`);let i=Bt.safeParse(await r.json());if(!i.success)throw new d(`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`,Ut=`https://openrouter.ai/api/v1/embeddings/models`,Wt=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],Gt=[{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)`}],Kt={text:`text`,image:`image`,speech:`speech`,transcription:`transcription`,live:void 0,embedding:void 0},qt=n({data:t(n({id:e().min(1),name:e().optional(),architecture:n({output_modalities:t(e()).optional()}).optional()}))}),Jt=n({data:t(n({id:e().min(1),name:e().optional()}))}),Yt=n({models:t(n({name:e().min(1),displayName:e().optional(),supportedGenerationMethods:t(e()).optional()})).optional(),nextPageToken:e().optional()}),Xt=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 d(`auth`,`${e} refused the key.`);if(!r.ok)throw new d(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Zt(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?Gt:Wt];if(e===`openrouter`)return await Qt(t,i,r);if(!i)throw new d(`auth`,`Choose a key to list Gemini models.`);return await en(t,i,r)}async function Qt(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Jt.safeParse(await $(`OpenRouter`,Ut,r));if(!e.success)throw new d(`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=Kt[e];if(!i)return[];let a=qt.safeParse(await $(`OpenRouter`,`${Ht}?output_modalities=${i}`,r));if(!a.success)throw new d(`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 $t={live:`bidiGenerateContent`,embedding:`embedContent`};async function en(e,t,n){let r=$t[e]??`generateContent`,a=[],o;for(let e=0;e<Xt;e++){let e=new URL(i);e.searchParams.set(`pageSize`,`1000`),o&&e.searchParams.set(`pageToken`,o);let s=Yt.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!s.success)throw new d(`bad_response`,`Google returned an invalid model list.`);for(let e of s.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))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 tn(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function nn(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{Ve as S,S as _,tn as a,y as b,Y as c,qe as d,L as f,Le as g,D as h,Q as i,Je as l,I as m,Vt as n,nn as o,F as p,Zt as r,Rt as s,zt as t,Ge as u,Re as v,v as x,w as y};