@theoremjs/studio 0.3.5-next.951.gc40a24e → 0.3.5-next.953.gf255d6a

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 (62) hide show
  1. package/package.json +4 -4
  2. package/page/assets/{BottomSheet-C23uYni9.js → BottomSheet-Dqu4JNyD.js} +1 -1
  3. package/page/assets/{ConsoleFrame-DojYn-Ua.js → ConsoleFrame-DPrqoO63.js} +1 -1
  4. package/page/assets/{ContextMenu-scP4QtAy.js → ContextMenu-CCkYC5oC.js} +2 -2
  5. package/page/assets/{DateInput-DPnVtBuk.js → DateInput-DwjJ32WU.js} +1 -1
  6. package/page/assets/{DropdownMenu--j6BmlDw.js → DropdownMenu-BRiIS7y5.js} +2 -2
  7. package/page/assets/{Link-BnF6JNw_.js → Link-BJzFzYZZ.js} +1 -1
  8. package/page/assets/{MenuBottomSheet-DwZ1A0ZP.js → MenuBottomSheet-Cyn-X5mT.js} +1 -1
  9. package/page/assets/{PowerSearchBottomSheet-CtXQOyfT.js → PowerSearchBottomSheet-D5BDnFGs.js} +1 -1
  10. package/page/assets/{RankedBars-DOBs3j5V.js → RankedBars-BXzW5iyc.js} +1 -1
  11. package/page/assets/{SchemaFields-GsJdP3wy.js → SchemaFields-ALf11yt1.js} +1 -1
  12. package/page/assets/{ShapedData-DAjQUJgj.js → ShapedData-BrCc-5Nm.js} +1 -1
  13. package/page/assets/{TokenizerBottomSheet-M_4Fynh0.js → TokenizerBottomSheet-_Po-O1nL.js} +1 -1
  14. package/page/assets/{ToolResultCharts-DcX0_JRq.js → ToolResultCharts-B25Wz9N0.js} +1 -1
  15. package/page/assets/{Toolbar-S-NvSzN4.js → Toolbar-BIbNDUSH.js} +1 -1
  16. package/page/assets/{TraceInspector-DnQoUd5L.js → TraceInspector-BmEdTqRp.js} +2 -2
  17. package/page/assets/{TraceOverview-nRk6pOxZ.js → TraceOverview-mRMoiRtX.js} +1 -1
  18. package/page/assets/{_virtual_studio-type-sources-BZlYhM7H.js → _virtual_studio-type-sources-CUh9eCnG.js} +16 -5
  19. package/page/assets/{browser-connection-Lruy-qTV.js → browser-connection-CGupl9NP.js} +1 -1
  20. package/page/assets/{browser-engine-B5LWYMgo.js → browser-engine-BglZe00s.js} +9 -9
  21. package/page/assets/{browser-transport-BScpLZDa.js → browser-transport-BMKJqyTU.js} +2 -2
  22. package/page/assets/{compile-Ci6XGHY4.js → compile-CFGS7Xyf.js} +1 -1
  23. package/page/assets/{compile-egress-C3etX-3o.js → compile-egress-BAQfp0hq.js} +1 -1
  24. package/page/assets/{encode-files-Ds3y6S6n.js → encode-files-D8MkiRgr.js} +1 -1
  25. package/page/assets/{export-agent-BQFIIF1w.js → export-agent-BPjy13tY.js} +1 -1
  26. package/page/assets/{getRadiusAndStrokeWidthFromDot-D8AmY_nJ.js → getRadiusAndStrokeWidthFromDot-DzvtGV5n.js} +1 -1
  27. package/page/assets/{guardrail-health-BzI8GZot.js → guardrail-health-BqzfgVwd.js} +1 -1
  28. package/page/assets/{guardrail-tester-DeAAj-Ww.js → guardrail-tester-BmMnSNZC.js} +1 -1
  29. package/page/assets/host-patterns-DzBJj2uE.js +1 -0
  30. package/page/assets/{index-fyDzED1x.js → index-1UzYNcXu.js} +8 -8
  31. package/page/assets/{json-code-UNgQyCLH.js → json-code-DGEtlWGK.js} +1 -1
  32. package/page/assets/{labels-provider-CxUJe6Bn.js → labels-provider-3Sbk2Bjb.js} +1 -1
  33. package/page/assets/{live-ingress-OuSlQ6q7.js → live-ingress-ZR7rtkDx.js} +1 -1
  34. package/page/assets/{live-messages-dgQBMP8j.js → live-messages-CJ07JRrf.js} +1 -1
  35. package/page/assets/{prompt-row-Bace3EuD.js → prompt-row-bMhO_cjO.js} +1 -1
  36. package/page/assets/{reader-DoaMWQWB.js → reader-D3Gh1gq-.js} +2 -2
  37. package/page/assets/registry-CoAjLZ3F.js +1 -0
  38. package/page/assets/{schema-2nKQb1q-.js → schema-JVGuH9o3.js} +1 -1
  39. package/page/assets/{shaped-data-KV3CIOIt.js → shaped-data-CRpw7JlX.js} +9 -9
  40. package/page/assets/{stub-CXS-AHtL.js → stub-u1_pPFZW.js} +1 -1
  41. package/page/assets/{studio-code-pane-BWTLV4RT.js → studio-code-pane-9n_JT7Xe.js} +3 -3
  42. package/page/assets/{studio-console-CjqEdyB3.js → studio-console-CVLcXMgl.js} +1 -1
  43. package/page/assets/{studio-decision-DmQs0n67.js → studio-decision-BJbqzh-i.js} +1 -1
  44. package/page/assets/{studio-embedding-_Kx6Nz3-.js → studio-embedding-C49c_URE.js} +1 -1
  45. package/page/assets/{studio-host-console-DG4ViMWJ.js → studio-host-console-CgZNhDaO.js} +2 -2
  46. package/page/assets/{studio-live-B7O4qpG_.js → studio-live-B6AxEhrA.js} +1 -1
  47. package/page/assets/{studio-map-Br_kabfa.js → studio-map-BDxiF8IC.js} +1 -1
  48. package/page/assets/{studio-media-orN5UNpz.js → studio-media-BbimKgrs.js} +1 -1
  49. package/page/assets/{studio-trace-replay-DV2HMKFc.js → studio-trace-replay-DOIf9BGF.js} +1 -1
  50. package/page/assets/{studio-type-checker-vtYkUAwV.js → studio-type-checker-DuCCZTVo.js} +1 -1
  51. package/page/assets/{tool-schema-DllL3wqs.js → tool-schema-UsTCet4o.js} +1 -1
  52. package/page/assets/{trace-record-BOw-semK.js → trace-record-BhrZGQoo.js} +1 -1
  53. package/page/assets/{tree-I-6ZPGON.js → tree-Db8E16o-.js} +1 -1
  54. package/page/assets/{turn-client-RIvnewgM.js → turn-client-DCxJT6xY.js} +1 -1
  55. package/page/assets/types-CPBggAgB.js +1 -0
  56. package/page/assets/{use-one-call-DZ3NX8RC.js → use-one-call-CxoNRi9H.js} +1 -1
  57. package/page/assets/{useDismissSearchOnTouchDrag-CCqPhJ4f.js → useDismissSearchOnTouchDrag-B5-quEz5.js} +1 -1
  58. package/page/assets/{workspace-BI6bC1mm.js → workspace-RYi4swYS.js} +1 -1
  59. package/page/index.html +23 -23
  60. package/page/assets/host-patterns-F-KZIzkF.js +0 -1
  61. package/page/assets/registry-BuJuTraO.js +0 -1
  62. package/page/assets/types-Bl7WithI.js +0 -1
@@ -5224,7 +5224,10 @@ export interface ProtocolDefinition<O = unknown, S = unknown> {
5224
5224
  * \`id\` when the reply names itself in \`X-Generation-Id\`.
5225
5225
  */
5226
5226
  framing?(response: Response, stream: boolean): AsyncIterable<JsonObject>;
5227
- /** Types a failed answer. Absent: the kind follows the HTTP status. */
5227
+ /**
5228
+ * Types a failed answer. Absent: the kind follows the HTTP status. A refusal that names the file
5229
+ * types the provider cannot read sets them as \`refusedMedia\`, so the turn goes on without only those.
5230
+ */
5228
5231
  error?(failure: UpstreamFailure): TheoremError;
5229
5232
  /** What the named embedding model takes. Absent: the kernel holds requests to the profile alone. */
5230
5233
  embeddingLimits?(apiId: string): EmbeddingModelLimits;
@@ -6896,7 +6899,8 @@ export interface ProfileTurnResumptionSpec {
6896
6899
  * \`stream_incomplete\`) again itself when this list is set and names that stop, and the call gave
6897
6900
  * no reply and no tool call: the turn keeps its history, its step count and what it has read. A
6898
6901
  * failure the same call would meet again (the provider refused the request) is not sent again,
6899
- * except once without its files when it carried any: accepted that way, the turn goes on and
6902
+ * except without its files when it carried any: once per type the provider named, or once a turn
6903
+ * without this turn's files when it named none. Accepted that way, the turn goes on and
6900
6904
  * \`done.mediaRefused\` names them. Named here, \`length\` also repairs a call the output limit cut
6901
6905
  * off: the model gets back what it wrote, or that it wrote nothing, and is asked again to fit.
6902
6906
  * Omitted, a turn sends nothing again.
@@ -7807,6 +7811,8 @@ export type TurnEvent = {
7807
7811
  errorCopy?: ErrorCopies;
7808
7812
  /** Raw diagnostic detail for traces/logs; never surface to end users (\`forClient\` strips it). */
7809
7813
  errorInternal?: string;
7814
+ /** The file types the provider said it cannot read; the turn may send again without them. */
7815
+ refusedMedia?: string[];
7810
7816
  };
7811
7817
  /** The \`type\` of a turn event. */
7812
7818
  export type TurnEventType = TurnEvent['type'];
@@ -8637,7 +8643,7 @@ export { applySpans, blobAt, mergeSpans, OMIT_CANARY, OMIT_INJECTION, OMIT_PROMP
8637
8643
  `,"file:///node_modules/@theoremjs/agents/src/guardrails/labels.d.ts":`/** Values that fill a label template's \`{param}\` placeholders. */
8638
8644
  export type LabelParams = Record<string, string | number>;
8639
8645
  /** Keys are stable API. */
8640
- export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "turn.media_refused_image", "turn.media_refused_video", "turn.media_refused_file", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "attachments.limits_unconfigured", "quota.exhausted", "quota.busy", "error.config", "error.request", "error.conflict", "error.not_found", "error.input", "error.action", "error.auth", "error.rate_limit", "error.busy", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.cut_off_guidance", "repair.reply_cut_off", "repair.call_cut_off", "repair.call_cut_off_guidance", "repair.nothing_written", "repair.nothing_written_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "structured.answer_tool", "structured.answer_missing", "structured.cut_off", "structured.not_json", "compaction.request", "compaction.tool_call", "compaction.tool_result", "compaction.tool_files", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.email", "detect.hint.phone", "detect.hint.bank_account", "detect.hint.injection", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "stop.answer_missing", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_host_fields", "tool.hook_failed", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.unreachable", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.after_field", "tool.background_field", "tool.background_started", "tool.late_result", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
8646
+ export declare const LABEL_KEYS: readonly ["provider.decision_failed", "provider.decision_unavailable", "provider.decision_model_missing", "provider.decision_ended", "provider.decision_images_off", "provider.decision_box_model", "provider.budget_exhausted", "provider.adapter_version", "provider.adapter_methods", "provider.adapter_schemas", "provider.fallback_slot", "provider.model_fallback_slot", "provider.host_model", "turn.media_refused_image", "turn.media_refused_video", "turn.media_refused_file", "turn.media_refused_tool", "provider.turn_profile", "provider.model_binding_missing", "provider.session_closed", "provider.settled_call", "provider.session_unavailable", "provider.live_input", "provider.tool_cancel_missing", "provider.kernel_gate", "provider.event_invalid", "provider.response_identity", "provider.credential_resolution", "provider.credential_shape", "provider.stored_continuation", "provider.continuation_mismatch", "provider.continuation_contract", "provider.stateless_history", "provider.events_after_completion", "provider.duplicate_call", "provider.tool_cancel_live", "provider.complete_unavailable", "provider.parallel_tools", "provider.binding_identity", "provider.profile_type", "provider.event_type", "provider.feature", "provider.input_kind", "provider.output_kind", "provider.builtin", "provider.credential_missing", "provider.profile_configuration", "continue.instruction", "canary.bind_note", "user_data.note", "context.note", "taint.blocked", "taint.reason_steered", "taint.reason_tainted", "taint.destination_blocked", "taint.destination_confirm", "advisory.notice_elevated", "advisory.notice_high", "advisory.guidance", "attachments.too_many_files", "attachments.too_many_of_kind", "attachments.file_too_large", "attachments.turn_too_large", "attachments.not_accepted", "attachments.mime_not_allowed", "attachments.limits_unconfigured", "quota.exhausted", "quota.busy", "error.config", "error.request", "error.conflict", "error.not_found", "error.input", "error.action", "error.auth", "error.rate_limit", "error.busy", "error.unsupported", "error.unavailable", "error.bad_response", "error.network", "error.timeout", "error.safety", "error.blocked", "error.declined", "error.failed", "error.cancelled", "error.internal", "repair.default_guidance", "repair.items_guidance", "repair.cut_off_guidance", "repair.reply_cut_off", "repair.call_cut_off", "repair.call_cut_off_guidance", "repair.nothing_written", "repair.nothing_written_guidance", "repair.prompt_header", "repair.prompt_intro", "repair.prompt_instructions", "repair.history_heading", "repair.section_previous_output", "repair.section_validator_rejection", "repair.section_repair_guidance", "repair.section_instructions", "structured.answer_tool", "structured.answer_missing", "structured.cut_off", "structured.not_json", "compaction.request", "compaction.tool_call", "compaction.tool_result", "compaction.tool_files", "decision.box_image", "detect.blocked", "detect.call_blocked", "detect.output_blocked", "detect.shown_blocked", "detect.hint.ids", "detect.hint.financial", "detect.hint.network", "detect.hint.credentials", "detect.hint.email", "detect.hint.phone", "detect.hint.bank_account", "detect.hint.injection", "detect.hint.canary_leak", "detect.hint.prompt_leak", "detect.hint.marker_leak", "detect.hint.ungiven_images", "detect.hint.ungiven_links", "detect.hint.tool_leak", "detect.hint.own", "egress.default_repair_guidance", "egress.refusal", "egress.refusal_cut", "egress.rejection", "egress.rejection_found", "egress.hint_unscannable", "egress.hint_provider_tool_leak", "thought.omitted_image", "thought.omitted_link", "thought.omitted_instructions", "session.abandon_gated", "session.tool_denied", "session.tool_aborted", "session.sign_in", "sign_in.link", "sign_in.pending", "sign_in.done", "sign_in.declined", "sign_in.expired", "sign_in.out_of_scope", "session.gate_expired", "session.provider_state_unowned", "session.conversation_unknown", "session.full", "session.busy", "session.turn_ended", "session.gate_pending", "session.part_skipped", "live.session_ended", "voice.unsupported", "voice.permission", "voice.unavailable", "voice.failed", "voice.empty", "stop.cancelled", "stop.interrupted", "stop.length", "stop.filtered", "stop.provider_error", "stop.stream_incomplete", "stop.step_limit", "stop.answer_missing", "composer.model", "composer.effort", "tool.awaiting_user", "tool.completed_hidden", "tool.t2_loader_needs_snapshot", "tool.t2_loader_shape", "tool.t2_loader_output_invalid", "tool.execution_uncertain", "tool.input_invalid", "tool.input_host_fields", "tool.hook_failed", "tool.input_invalid_after_mutate", "tool.output_invalid_after_mutate", "tool.handler_no_output", "tool.did_not_run", "tool.unreachable", "tool.page_no_answer", "tool.page_timed_out", "tool.output_invalid", "tool.not_loaded_t2", "tool.wait_unknown", "tool.wait_cycle", "tool.after_field", "tool.background_field", "tool.background_started", "tool.late_result", "tool.not_visible", "tool.builtin_not_enabled", "tool.provider_native", "tool.not_registered", "tool.builtin_needs_snapshot", "tool.not_allowed", "tool.not_eligible", "tool.unsupported_type", "tool.agent_call_limit", "tool.agent_failed", "tool.activity_failed", "protocol.not_served", "protocol.profile_type", "protocol.options", "protocol.option_clash", "protocol.base_options", "protocol.id_clash", "protocol.ws_headers", "protocol.builtin_unwritten", "protocol.provider_missing", "protocol.connection", "protocol.part_schema", "protocol.part_invalid", "protocol.key_invalid", "protocol.no_key", "protocol.reply_shape", "protocol.endpoint_url", "protocol.endpoint_host", "protocol.http", "protocol.no_operation", "protocol.definition", "protocol.provider_id_clash", "protocol.history_needed"];
8641
8647
  /** One of {@linkcode LABEL_KEYS}. */
8642
8648
  export type LabelKey = (typeof LABEL_KEYS)[number];
8643
8649
  /**
@@ -8806,6 +8812,8 @@ export type ErrorKind = (typeof ERROR_KINDS)[number];
8806
8812
  export interface TheoremErrorOptions extends ErrorOptions {
8807
8813
  /** User wording more specific than the kind's: one line, or one per problem found. */
8808
8814
  copy?: ErrorCopies;
8815
+ /** The file types the provider said it cannot read, as it named them. */
8816
+ refusedMedia?: readonly string[];
8809
8817
  }
8810
8818
  /**
8811
8819
  * The error Theorem throws; its kind tells your host which status and wording to use.
@@ -8815,6 +8823,7 @@ export interface TheoremErrorOptions extends ErrorOptions {
8815
8823
  export declare class TheoremError extends Error {
8816
8824
  readonly kind: ErrorKind;
8817
8825
  readonly copy?: ErrorCopies;
8826
+ readonly refusedMedia?: readonly string[];
8818
8827
  constructor(kind: ErrorKind, message: string, options?: TheoremErrorOptions);
8819
8828
  }
8820
8829
  `,"file:///node_modules/@theoremjs/agents/src/guardrails/egress-urls.d.ts":`/**
@@ -10170,7 +10179,7 @@ export interface ToolHostHooks<TIn = unknown> {
10170
10179
  * @remarks Runs before the host's \`pre_tool\` \`onStage\`.
10171
10180
  */
10172
10181
  preTool?: (input: TIn, ctx: ToolContext) => import('../stages.js').StageResult | undefined | Promise<import('../stages.js').StageResult | undefined>;
10173
- /** Whether the model can see and call the tool. */
10182
+ /** false: the model can call the tool but reads only \`Completed.\` (the tool.completed_hidden label); the person still sees the media it sends. */
10174
10183
  exposeToModel?: boolean;
10175
10184
  /**
10176
10185
  * Gives the model an after field on this tool: the tools called in the same step that must settle
@@ -10514,7 +10523,7 @@ export interface AgentToolDef extends ToolBase {
10514
10523
  * argument. A turn with no background service runs the tool inline.
10515
10524
  */
10516
10525
  background?: ToolHostHooks<AgentToolInput>['background'];
10517
- /** Whether the model can see and call the tool. */
10526
+ /** false: the model can call the tool but reads only \`Completed.\` (the tool.completed_hidden label); the person still sees the media it sends. */
10518
10527
  exposeToModel?: boolean;
10519
10528
  }
10520
10529
  export interface RegisteredAgentTool extends AgentToolDef, ToolHostHooks<AgentToolInput>, ToolOutputHooks<AgentToolOutput> {
@@ -10768,6 +10777,8 @@ export type ToolBodyOutcome = {
10768
10777
  kind: 'ok';
10769
10778
  outputRaw: unknown;
10770
10779
  modelResult: ModelToolResult;
10780
+ /** The tool is not signed in, and \`modelResult\` is the kernel's own words saying so; \`exposeToModel: false\` does not hide them. */
10781
+ unauthenticated?: true;
10771
10782
  } | {
10772
10783
  kind: 'gated';
10773
10784
  gate: ToolGate;
@@ -1 +1 @@
1
- import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{J as r}from"./tool-schema-DllL3wqs.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-KV3CIOIt.js";import{c as _}from"./host-patterns-F-KZIzkF.js";import{A as pe,D as me,M as he,T as ge,U as _e,x as ve,y as v}from"./schema-2nKQb1q-.js";import{a as ye,n as be}from"./live-ingress-OuSlQ6q7.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??``;ge(r,`Profile ${e.id} identity.system`);let i=me(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=pe(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=ve(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-UsTCet4o.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-CRpw7JlX.js";import{c as _}from"./host-patterns-DzBJj2uE.js";import{A as pe,D as me,M as he,T as ge,U as _e,x as ve,y as v}from"./schema-JVGuH9o3.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??``;ge(r,`Profile ${e.id} identity.system`);let i=me(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=pe(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=ve(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};