@theoremjs/studio 0.3.4-next.837.g097599a → 0.3.4-next.843.ga3bad83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cookbooks/catalog.js +2 -8
- package/cookbooks/fixtures/research.trace.json +2 -2
- package/guardrail-probe.js +2 -2
- package/package.json +4 -4
- package/page/assets/{BottomSheet-C-co_mp9.js → BottomSheet-Cw0lMJjl.js} +1 -1
- package/page/assets/{ConsoleFrame-4VBVqfrf.js → ConsoleFrame-B9JNg4CN.js} +1 -1
- package/page/assets/{DateInput-BsxtTkrQ.js → DateInput-De9JjeH_.js} +1 -1
- package/page/assets/{MenuBottomSheet-o9tZPcJm.js → MenuBottomSheet-DdSmYsNc.js} +1 -1
- package/page/assets/{SchemaFields-BPo2Mrp8.js → SchemaFields-DJkTusje.js} +1 -1
- package/page/assets/{TokenizerBottomSheet-C0DGGbWG.js → TokenizerBottomSheet-C1L_-KaG.js} +1 -1
- package/page/assets/{ToolResultCharts-DVGX5g66.js → ToolResultCharts-DZGGNGma.js} +1 -1
- package/page/assets/{Toolbar-DWMu-6iP.js → Toolbar-Btx1iaPT.js} +1 -1
- package/page/assets/{TraceInspector-Hpts4lYU.js → TraceInspector-0pNFF2YZ.js} +1 -1
- package/page/assets/{TraceOverview-CdzqWEvx.js → TraceOverview-C05Dq7VT.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-DsadDSMk.js → _virtual_studio-type-sources-DRTgBriS.js} +16 -14
- package/page/assets/{browser-connection-GqzboNG0.js → browser-connection-BMoCFhYy.js} +1 -1
- package/page/assets/{browser-engine-DKDARmez.js → browser-engine-BPK0G6Fx.js} +2 -2
- package/page/assets/{browser-transport-DUJofCYK.js → browser-transport-CGUAMEI8.js} +2 -2
- package/page/assets/{compile-CwMXuqar.js → compile-6eIfaXll.js} +1 -1
- package/page/assets/{encode-files-Cl-RDljl.js → encode-files-MOJXvlW9.js} +1 -1
- package/page/assets/{export-agent-2cOYacDp.js → export-agent-pIAn8z0b.js} +1 -1
- package/page/assets/{guardrail-tester-DfwGqg3T.js → guardrail-tester-2dfwTtJS.js} +1 -1
- package/page/assets/{index-DdcBxdl9.js → index-DneFNrzM.js} +11 -11
- package/page/assets/{json-code-BVwLOVXH.js → json-code-B1rVZeZr.js} +1 -1
- package/page/assets/{live-messages-BEv_iy9z.js → live-messages-d9BIeBEz.js} +1 -1
- package/page/assets/{prompt-row-Q3cIQ3ez.js → prompt-row-BJV0pnrQ.js} +1 -1
- package/page/assets/{reader-BaHOEbDK.js → reader-CXHCDEbW.js} +1 -1
- package/page/assets/{registry-B9Hi-BTx.js → registry-Dv2wwCfg.js} +1 -1
- package/page/assets/{schema-CH7ac-er.js → schema-G8cHvtht.js} +1 -1
- package/page/assets/shaped-data-OkTOsVE5.js +21 -0
- package/page/assets/{stub-29PdFgBk.js → stub-B7dxSuX6.js} +1 -1
- package/page/assets/{studio-code-pane-P3d8u6vf.js → studio-code-pane-Cx_dRvck.js} +3 -3
- package/page/assets/{studio-console-D9xU3yGE.js → studio-console-B7L5E-BA.js} +1 -1
- package/page/assets/{studio-decision-BbjhRU5L.js → studio-decision-BUQutOd_.js} +1 -1
- package/page/assets/{studio-embedding-PFrKg8rI.js → studio-embedding-BhQ4o-kG.js} +1 -1
- package/page/assets/{studio-host-console-D3dU4nQ5.js → studio-host-console-DSclsJeZ.js} +2 -2
- package/page/assets/{studio-labels-17QgyQYT.js → studio-labels-Bv6qm3lg.js} +1 -1
- package/page/assets/{studio-live-D8Lg8GTq.js → studio-live-BrdnB_o5.js} +1 -1
- package/page/assets/{studio-map-C3xP-C22.js → studio-map-Cnatnz-_.js} +1 -1
- package/page/assets/{studio-trace-replay-DQq6fQJ5.js → studio-trace-replay-VESTHfWb.js} +1 -1
- package/page/assets/{studio-type-checker-f2wzNB9Y.js → studio-type-checker-DBXU9bu4.js} +1 -1
- package/page/assets/{tool-schema-CxFeW-7S.js → tool-schema-Cphc-uXi.js} +7 -7
- package/page/assets/trace-record-D1fIfCpY.js +1 -0
- package/page/assets/{tree-BcwYNzqX.js → tree-BhFuh9Po.js} +1 -1
- package/page/assets/{turn-client-BJ-HvwcB.js → turn-client-DsZejesM.js} +1 -1
- package/page/assets/{types-DMhDBFVO.js → types-rNU69aPS.js} +1 -1
- package/page/assets/{use-one-call-DFsRHA22.js → use-one-call-DTURPTpy.js} +1 -1
- package/page/assets/{workspace-DtR9DDcj.js → workspace-DbaMrvjR.js} +1 -1
- package/page/index.html +16 -16
- package/page/assets/shaped-data-C1RR9L0q.js +0 -21
- package/page/assets/trace-record-CdblOhVY.js +0 -1
|
@@ -4446,7 +4446,7 @@ import { type CompiledPatterns, type HostMatcher, type HostPattern } from './hos
|
|
|
4446
4446
|
* kernel's markers, an image or link to an address the model was not given, and the names of its
|
|
4447
4447
|
* tools).
|
|
4448
4448
|
*/
|
|
4449
|
-
declare const DETECTORS: readonly ["ids", "financial", "network", "credentials", "email", "phone", "bank_account", "injection", "
|
|
4449
|
+
declare const DETECTORS: readonly ["ids", "financial", "network", "credentials", "email", "phone", "bank_account", "injection", "canary_leak", "prompt_leak", "marker_leak", "ungiven_images", "ungiven_links", "tool_leak"];
|
|
4450
4450
|
/** A detector recognizes a particular kind of content in text. Its configured action determines what happens when it finds a match. */
|
|
4451
4451
|
type Detector = (typeof DETECTORS)[number];
|
|
4452
4452
|
/** The detectors a text is cleaned with when no profile says how: every one but the working groups (\`WORKING_GROUPS\`). */
|
|
@@ -8015,7 +8015,7 @@ export { applySpans, blobAt, mergeSpans, OMIT_CANARY, OMIT_INJECTION, OMIT_PROMP
|
|
|
8015
8015
|
`,"file:///node_modules/@theoremjs/agents/src/guardrails/labels.d.ts":`/** Values that fill a label template's \`{param}\` placeholders. */
|
|
8016
8016
|
export type LabelParams = Record<string, string | number>;
|
|
8017
8017
|
/** Keys are stable API. */
|
|
8018
|
-
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.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.
|
|
8018
|
+
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.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", "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_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"];
|
|
8019
8019
|
/** One of {@linkcode LABEL_KEYS}. */
|
|
8020
8020
|
export type LabelKey = (typeof LABEL_KEYS)[number];
|
|
8021
8021
|
/**
|
|
@@ -8117,7 +8117,7 @@ export interface GuardrailHit {
|
|
|
8117
8117
|
/** The name of the host's pattern that matched; unset for a match of Theorem's own patterns. */
|
|
8118
8118
|
pattern?: string;
|
|
8119
8119
|
/**
|
|
8120
|
-
* What about the match made it one, for \`
|
|
8120
|
+
* What about the match made it one, for \`injection\` in what a tool returns: \`override\`, \`tool_name\`, \`order\`
|
|
8121
8121
|
* or \`authority\`. For a host's \`find\` that failed, how: \`find_threw\` or \`find_result\`.
|
|
8122
8122
|
*/
|
|
8123
8123
|
signal?: string;
|
|
@@ -8573,7 +8573,7 @@ export type ScrubSwitch = boolean | {
|
|
|
8573
8573
|
export interface TraceScrubSpec {
|
|
8574
8574
|
/** The data detectors (\`ids\`, \`financial\`, \`network\`, \`credentials\`) and the host's own. Default: true. */
|
|
8575
8575
|
sensitive?: ScrubSwitch;
|
|
8576
|
-
/** \`injection
|
|
8576
|
+
/** \`injection\`, with the orders to the agent it finds in what a tool returns. Default: true. */
|
|
8577
8577
|
injection?: ScrubSwitch;
|
|
8578
8578
|
/** Never persist the canary token. It is Theorem's alone, so the host side adds nothing. Default: true. */
|
|
8579
8579
|
canary?: ScrubSwitch;
|
|
@@ -11745,8 +11745,10 @@ interface DetectScope extends LeakScope, Pick<GuardrailContext, 'givenUrls' | 'o
|
|
|
11745
11745
|
note?: string;
|
|
11746
11746
|
/** What \`ungiven_images\` and \`ungiven_links\` let through besides the given URLs. */
|
|
11747
11747
|
allow?: ResolvedAllow;
|
|
11748
|
-
/** The tools the model can call this turn, for \`
|
|
11748
|
+
/** The tools the model can call this turn, for \`injection\` in what a tool returns: naming one is a match. */
|
|
11749
11749
|
callable?: readonly string[];
|
|
11750
|
+
/** Set where a tool's output or error is read: \`injection\` also reads it for orders aimed at the agent. */
|
|
11751
|
+
fromTool?: boolean;
|
|
11750
11752
|
}
|
|
11751
11753
|
/**
|
|
11752
11754
|
* The {@linkcode LeakScope} of a turn under \`detect\`: each part only while its detector is above
|
|
@@ -12503,9 +12505,9 @@ export interface GuardedToolText {
|
|
|
12503
12505
|
/** Emitted when the guard did anything worth recording. */
|
|
12504
12506
|
event?: GuardrailEvent;
|
|
12505
12507
|
/**
|
|
12506
|
-
* What \`
|
|
12507
|
-
* instruction-shaped, so the detector starts at \`flag\`; whatever its
|
|
12508
|
-
* these raise the turn's taint.
|
|
12508
|
+
* What \`injection\` found in a remote tool's text, a result or a failure's message. Legitimate
|
|
12509
|
+
* tool output is frequently instruction-shaped, so the detector starts at \`flag\`; whatever its
|
|
12510
|
+
* action, these raise the turn's taint.
|
|
12509
12511
|
*/
|
|
12510
12512
|
suspicious?: GuardrailHit[];
|
|
12511
12513
|
}
|
|
@@ -12519,9 +12521,9 @@ declare function composeToolText(finding: string, data: unknown): string;
|
|
|
12519
12521
|
* data the host did not write — but only remote origins are fenced, because
|
|
12520
12522
|
* fencing a local tool's output would change prompts hosts have already tuned.
|
|
12521
12523
|
* \`boundary\` is absent for text that crosses none: a provider builtin's, or a
|
|
12522
|
-
* failure already read at its own boundary
|
|
12524
|
+
* failure already read at its own boundary, whose findings come in as \`carried\`.
|
|
12523
12525
|
*/
|
|
12524
|
-
declare function guardToolResult(finding: string, data: unknown, provenance: Provenance, policy: ResolvedGuardrailPolicy, boundary: ToolBoundary | undefined, callableTools?: readonly string[], labels?: LabelOverrides): GuardedToolText;
|
|
12526
|
+
declare function guardToolResult(finding: string, data: unknown, provenance: Provenance, policy: ResolvedGuardrailPolicy, boundary: ToolBoundary | undefined, callableTools?: readonly string[], labels?: LabelOverrides, carried?: GuardrailHit[]): GuardedToolText;
|
|
12525
12527
|
/**
|
|
12526
12528
|
* A remote server authors its own error strings, so an unguarded failure message
|
|
12527
12529
|
* is the cleanest injection path across this boundary: it reaches the model
|
|
@@ -12619,7 +12621,7 @@ declare function mergedRanges(ranges: readonly [number, number][]): [number, num
|
|
|
12619
12621
|
* Real indirect injection rarely names what it attacks, so this looks for content that behaves
|
|
12620
12622
|
* like an instruction: each order, claim of authority, tool name, and destination, where it sits
|
|
12621
12623
|
* in \`text\`. A page documenting an email API legitimately says "call send_email", so the
|
|
12622
|
-
* detector that reads with this (\`
|
|
12624
|
+
* detector that reads with this (\`injection\`, in what a tool returns) starts at \`flag\`.
|
|
12623
12625
|
*
|
|
12624
12626
|
* \`callableTools\` is the set the model can invoke this turn. A result naming one is the
|
|
12625
12627
|
* highest-precision signal: ordinary data has no reason to, and no generic filter can check it
|
|
@@ -12630,8 +12632,9 @@ declare function mergedRanges(ranges: readonly [number, number][]): [number, num
|
|
|
12630
12632
|
*/
|
|
12631
12633
|
declare function directives(text: string, callableTools?: readonly string[]): Directive[];
|
|
12632
12634
|
/**
|
|
12633
|
-
* How strongly a tool's text reads as instructions, by the \`signals\` found in it: \`high\` for
|
|
12634
|
-
* order to drop instructions, a callable tool's
|
|
12635
|
+
* How strongly a tool's text reads as instructions, by the \`signals\` found in it: \`high\` for
|
|
12636
|
+
* injection phrasing (a match with no signal), an order to drop instructions, a callable tool's
|
|
12637
|
+
* name, or two signals together.
|
|
12635
12638
|
*/
|
|
12636
12639
|
declare function advisoryLevel(signals: readonly (string | undefined)[]): AdvisoryLevel;
|
|
12637
12640
|
export type { Directive, DirectiveSignal };
|
|
@@ -12720,7 +12723,6 @@ export declare const DETECT_RULES: {
|
|
|
12720
12723
|
readonly phone: "detect.phone";
|
|
12721
12724
|
readonly bank_account: "detect.bank_account";
|
|
12722
12725
|
readonly injection: "detect.injection";
|
|
12723
|
-
readonly tool_instructions: "detect.tool_instructions";
|
|
12724
12726
|
readonly canary_leak: "detect.canary_leak";
|
|
12725
12727
|
readonly prompt_leak: "detect.prompt_leak";
|
|
12726
12728
|
readonly marker_leak: "detect.marker_leak";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{Cn as r,Dn as i,H as a,Sn as o,Tn as s,Xt as c,fn as l,ir as ee,ln as te,un as ne,wn as u}from"./tool-schema-CxFeW-7S.js";import{c as d}from"./host-patterns-F-KZIzkF.js";import{Ar as re,In as ie,Ln as ae,Nn as oe,Rn as se,Ur as f,Wr as ce,Yn as p,cn as le,gn as m,hn as ue,hr as h,in as de,or as fe,sr as pe,wr as me,xn as g,zr as he}from"./shaped-data-C1RR9L0q.js";import{E as ge,b as _e,j as ve,k as ye,v as _,w as be}from"./schema-CH7ac-er.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=i(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),a=`${r}/*`;if(t.limitsByMime[a])return t.limitsByMime[a]}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=>!r(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:u(e,`attachments`),voice:u(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(i(n)))return e;let a=Pe(n,fe(r),t);return{...e,data:pe(a)}}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?ee.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(!c(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(ue).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&&!h.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${h.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,me):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(re(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&&ce(e.labels,`Profile ${e.id}`);for(let t of he)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(o(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=>!r(le,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=s(e)?.context;if(!t)return;let n=de;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new d(`config`,`Profile ${e.id}: inputs.context.from must list ${de.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 r=new Map,i=i=>{let a=Y(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,te(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(jt(e,o),Mt(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){Pt(e,o),Z(o.id,s(o)),Lt(o),It(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&Ot(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new d(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.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`,i=[],o;for(let e=0;e<Xt;e++){let e=new URL(a);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\//,``);i.push({id:t,label:e.displayName??t})}if(o=s.data.nextPageToken,!o)break}return i}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};
|
|
1
|
+
import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{Cn as r,Dn as i,H as a,Sn as o,Tn as s,Xt as c,fn as l,ir as ee,ln as te,un as ne,wn as u}from"./tool-schema-Cphc-uXi.js";import{c as d}from"./host-patterns-F-KZIzkF.js";import{Ar as re,In as ie,Ln as ae,Nn as oe,Rn as se,Ur as f,Wr as ce,Yn as p,cn as le,gn as m,hn as ue,hr as h,in as de,or as fe,sr as pe,wr as me,xn as g,zr as he}from"./shaped-data-OkTOsVE5.js";import{E as ge,b as _e,j as ve,k as ye,v as _,w as be}from"./schema-G8cHvtht.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=i(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),a=`${r}/*`;if(t.limitsByMime[a])return t.limitsByMime[a]}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=>!r(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:u(e,`attachments`),voice:u(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(i(n)))return e;let a=Pe(n,fe(r),t);return{...e,data:pe(a)}}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?ee.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(!c(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(ue).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&&!h.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${h.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,me):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(re(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&&ce(e.labels,`Profile ${e.id}`);for(let t of he)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(o(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=>!r(le,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=s(e)?.context;if(!t)return;let n=de;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new d(`config`,`Profile ${e.id}: inputs.context.from must list ${de.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 r=new Map,i=i=>{let a=Y(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,te(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(jt(e,o),Mt(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){Pt(e,o),Z(o.id,s(o)),Lt(o),It(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&Ot(r,o,e,t.compaction)}r.set(o.id,o)};return{register:i,registerMany(e){for(let t of e)i(t)},get(e){let t=r.get(e);if(!t)throw new d(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.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`,i=[],o;for(let e=0;e<Xt;e++){let e=new URL(a);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\//,``);i.push({id:t,label:e.displayName??t})}if(o=s.data.nextPageToken,!o)break}return i}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};
|