@theoremjs/studio 0.3.5-next.932.g295cc67 → 0.3.5-next.935.ga3dc485
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/README.md +1 -1
- package/package.json +4 -4
- package/page/assets/{BottomSheet-Cv7INToq.js → BottomSheet-BeZNOmva.js} +1 -1
- package/page/assets/{ConsoleFrame-CMNAaDWQ.js → ConsoleFrame-Durgrfa8.js} +1 -1
- package/page/assets/{ContextMenu-ChxNyHAG.js → ContextMenu-CdZPGyrH.js} +2 -2
- package/page/assets/{DateInput-CrMFIN2X.js → DateInput-DxxKNbFy.js} +1 -1
- package/page/assets/{DropdownMenu-B2GM8SDE.js → DropdownMenu-CLdHjD_O.js} +2 -2
- package/page/assets/{Link-DHqi_7FT.js → Link-B8qtW9Me.js} +1 -1
- package/page/assets/{MenuBottomSheet-DP5xlrG6.js → MenuBottomSheet-BJz5pzDE.js} +1 -1
- package/page/assets/{PowerSearchBottomSheet-Brhh0FeQ.js → PowerSearchBottomSheet-xO313kak.js} +1 -1
- package/page/assets/{RankedBars-BkiIdYzB.js → RankedBars-D0yn-ri0.js} +1 -1
- package/page/assets/{SchemaFields-lk7ziQz6.js → SchemaFields-Dvwzr5ZO.js} +1 -1
- package/page/assets/{ShapedData-VoYK59i_.js → ShapedData-DYRlNRy_.js} +1 -1
- package/page/assets/{TokenizerBottomSheet-DN1XQs0d.js → TokenizerBottomSheet-DhPibEHt.js} +1 -1
- package/page/assets/{ToolResultCharts-Tfv-ShfO.js → ToolResultCharts-BGJbKsDT.js} +1 -1
- package/page/assets/{Toolbar-qH5PhVfZ.js → Toolbar-DVp0Jb7c.js} +1 -1
- package/page/assets/{TraceInspector-DqefLyxC.js → TraceInspector-Cs8SNp3b.js} +2 -2
- package/page/assets/{TraceOverview-Cm_395pE.js → TraceOverview-BN5UDJe8.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-Bi_HqS6g.js → _virtual_studio-type-sources-ekRa45Mf.js} +105 -27
- package/page/assets/{browser-connection-DzO00xRy.js → browser-connection-BWOEEs03.js} +1 -1
- package/page/assets/browser-engine-BxtG9nJ-.js +16 -0
- package/page/assets/{browser-transport-DrR6R-s6.js → browser-transport-rFxtbMn0.js} +2 -2
- package/page/assets/{compile-oGEpwgkY.js → compile-C4Q50p5E.js} +2 -2
- package/page/assets/{encode-files-Bn5i8t9U.js → encode-files-MPtLTYyk.js} +1 -1
- package/page/assets/{export-agent-SuzfEXr6.js → export-agent-CEB-vrfl.js} +1 -1
- package/page/assets/{getRadiusAndStrokeWidthFromDot-qmvx1b0x.js → getRadiusAndStrokeWidthFromDot-Ck-kRNvB.js} +1 -1
- package/page/assets/{guardrail-health-C8M6d_Ov.js → guardrail-health-DMd_p8rH.js} +2 -2
- package/page/assets/{guardrail-tester-BP8cjCn1.js → guardrail-tester-DAis9Gsd.js} +1 -1
- package/page/assets/{index-Qx8_TLvh.js → index-C6pyNvXU.js} +16 -16
- package/page/assets/{json-code-Bqqs6mfl.js → json-code-DqpAF4hg.js} +1 -1
- package/page/assets/{labels-provider-D_7O3BSI.js → labels-provider-BOmB5WmP.js} +1 -1
- package/page/assets/{live-messages-DvMnxecr.js → live-messages-DekE0UkG.js} +1 -1
- package/page/assets/{prompt-row-B5Gjd6ix.js → prompt-row-BHTY1SfP.js} +1 -1
- package/page/assets/reader-BZ-mDuss.js +5 -0
- package/page/assets/{registry-Bjkfo9zx.js → registry-CqweoU_Q.js} +1 -1
- package/page/assets/{schema-DI2QKpYi.js → schema-Do4wX6Sr.js} +2 -2
- package/page/assets/{shaped-data-BxGL5na3.js → shaped-data-BxDmEUJe.js} +17 -17
- package/page/assets/{stub-CY0cuGPg.js → stub-CUHiDLLw.js} +1 -1
- package/page/assets/{studio-code-pane-Dk2LIsBA.js → studio-code-pane-i0bu-gwb.js} +3 -3
- package/page/assets/{studio-console-DgRN_cwB.js → studio-console-Cn5vtx-w.js} +1 -1
- package/page/assets/{studio-decision-BxQoABT5.js → studio-decision-CwWJLFnm.js} +1 -1
- package/page/assets/{studio-embedding-D3uQMUz8.js → studio-embedding-Dya8zKKM.js} +1 -1
- package/page/assets/{studio-host-console-BO9pKihD.js → studio-host-console-BbnDPTbG.js} +2 -2
- package/page/assets/studio-live-uS2TgNK2.js +5 -0
- package/page/assets/{studio-map-xClpozpN.js → studio-map-Bqv8T8BY.js} +1 -1
- package/page/assets/{studio-media-Cx8T9Apu.js → studio-media-C6h3z2kJ.js} +1 -1
- package/page/assets/{studio-trace-replay-DKH5CUnn.js → studio-trace-replay-B-WZNREk.js} +1 -1
- package/page/assets/{studio-type-checker-B1S5xema.js → studio-type-checker-2_B50AHd.js} +1 -1
- package/page/assets/{tool-schema-Bfe2TkD-.js → tool-schema-CnrGGkcr.js} +1 -1
- package/page/assets/{trace-record--OEcC7x1.js → trace-record-CRYVqBZW.js} +1 -1
- package/page/assets/{tree-CMulctlY.js → tree-CZVr90dg.js} +2 -2
- package/page/assets/{turn-client-sADYJHV9.js → turn-client-C_-rA6KF.js} +2 -2
- package/page/assets/types-DfwVnkMI.js +1 -0
- package/page/assets/{use-one-call-BZ5_lFAJ.js → use-one-call-By1S3qBT.js} +1 -1
- package/page/assets/{useDismissSearchOnTouchDrag-CoWT1_YM.js → useDismissSearchOnTouchDrag-L_mBp0Dm.js} +1 -1
- package/page/assets/{workspace-BrQUhBOf.js → workspace-ChRm7M3S.js} +1 -1
- package/page/index.html +21 -21
- package/server/handler.d.ts +2 -2
- package/server/handler.js +1 -1
- package/server/project.js +1 -1
- package/page/assets/browser-engine-Bdy2GijR.js +0 -16
- package/page/assets/reader-Bz6rc3qr.js +0 -5
- package/page/assets/studio-live-Dw2GjZqE.js +0 -5
- package/page/assets/types-7mVE39E8.js +0 -1
|
@@ -5320,7 +5320,7 @@ export interface ProviderLimits {
|
|
|
5320
5320
|
export declare const providerLimitsSchema: z.ZodType<ProviderLimits>;
|
|
5321
5321
|
`,"file:///node_modules/@theoremjs/agents/src/kernel/types.d.ts":`import type { ProviderCheckpoint, ProviderContinuationPolicy } from './checkpoint.js';
|
|
5322
5322
|
import type { JsonObject } from './json.js';
|
|
5323
|
-
import type { CompactionMeter, CompactionOutcome, CompactionTiming, ContextSender, ContinueStopKind, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveStartSensitivity, MediaInputKind, ProfileType, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnStage, TurnStopKind } from './schema.js';
|
|
5323
|
+
import type { CompactionMeter, CompactionOutcome, CompactionTiming, ContextSender, ContinueStopKind, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveEndSensitivity, LiveStartSensitivity, MediaInputKind, ProfileType, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnInjectStage, TurnStage, TurnStopKind } from './schema.js';
|
|
5324
5324
|
import type { StageHandler } from './stages.js';
|
|
5325
5325
|
import type { ToolBackgroundService } from './tools/background.js';
|
|
5326
5326
|
import type { GateDecision } from './tools/gate-answer.js';
|
|
@@ -6354,16 +6354,6 @@ export interface TurnInput {
|
|
|
6354
6354
|
voice?: TurnBlob[];
|
|
6355
6355
|
/** The earlier messages of the conversation, when the host keeps them. */
|
|
6356
6356
|
history?: TurnHistoryMessage[];
|
|
6357
|
-
/**
|
|
6358
|
-
* Background tool calls that settled after their turn, as the host stored them. The model reads
|
|
6359
|
-
* each as a tool result, and this reply counts it as a remote read when the call was remote. Pass
|
|
6360
|
-
* each one once: the turn emits it as a late_results event, so a history built from events holds
|
|
6361
|
-
* it.
|
|
6362
|
-
*
|
|
6363
|
-
* @remarks Tool calls that settled after their turn, as the host stored them. Each counts as read
|
|
6364
|
-
* in this reply.
|
|
6365
|
-
*/
|
|
6366
|
-
lateResults?: ToolOperationOutcome[];
|
|
6367
6357
|
/** A reply your host rejected and why, so that the model writes it again. */
|
|
6368
6358
|
repair?: TurnRepairRequest;
|
|
6369
6359
|
/**
|
|
@@ -6499,6 +6489,21 @@ export interface AgentRunRequest extends RunControls, ModelChoice {
|
|
|
6499
6489
|
}
|
|
6500
6490
|
/** A request to \`runTurn\`: the shared controls and the turn's input. */
|
|
6501
6491
|
export interface TurnRequest extends AgentRunRequest {
|
|
6492
|
+
/**
|
|
6493
|
+
* Your function that gives the background tool calls that settled after their turn, as you
|
|
6494
|
+
* stored them. A text turn asks it when it opens, after each step whose calls settled, and once
|
|
6495
|
+
* the model has answered. The model reads each result as a tool result, and the turn counts it
|
|
6496
|
+
* as a remote read when the call was remote. A result lands once: one the conversation already
|
|
6497
|
+
* holds is not read again. Each landing is a late_results event, so a history built from events
|
|
6498
|
+
* holds it, and the event names the moment it landed. Once the model has answered, a landing
|
|
6499
|
+
* runs another step, so the model answers what it read.
|
|
6500
|
+
*
|
|
6501
|
+
* @remarks Asked only where the model reads what it gives: not mid-turn when the profile's
|
|
6502
|
+
* \`turnBehaviour.allowSteering\` is false, and not when another step would pass \`maxSteps\`. What
|
|
6503
|
+
* it gives at a moment it is not asked waits for a later turn. A throw is reported as
|
|
6504
|
+
* hook_failed, and the turn goes on without results.
|
|
6505
|
+
*/
|
|
6506
|
+
lateResults?: LateResultsSource;
|
|
6502
6507
|
/**
|
|
6503
6508
|
* A session key a provider may use to route and cache this session's calls together.
|
|
6504
6509
|
*
|
|
@@ -6564,6 +6569,72 @@ export interface TurnRequest extends AgentRunRequest {
|
|
|
6564
6569
|
/** What the user sent for the turn. */
|
|
6565
6570
|
input?: TurnInput;
|
|
6566
6571
|
}
|
|
6572
|
+
/** Where a text turn asks for late results. */
|
|
6573
|
+
export interface LateResultsMoment {
|
|
6574
|
+
/**
|
|
6575
|
+
* \`pre_turn\` as the turn opens, \`post_tool\` after a step whose calls settled, \`before_end\` once
|
|
6576
|
+
* the model has answered.
|
|
6577
|
+
*/
|
|
6578
|
+
stage: TurnInjectStage;
|
|
6579
|
+
/** The model steps the turn has taken; 0 as it opens. */
|
|
6580
|
+
step: number;
|
|
6581
|
+
/** The turn's \`host\`: what the app makes of the request. */
|
|
6582
|
+
host: unknown;
|
|
6583
|
+
signal?: AbortSignal;
|
|
6584
|
+
}
|
|
6585
|
+
/** Gives the late results a turn reads at a moment; see {@linkcode TurnRequest.lateResults}. */
|
|
6586
|
+
export type LateResultsSource = (moment: LateResultsMoment) => readonly ToolOperationOutcome[] | Promise<readonly ToolOperationOutcome[]>;
|
|
6587
|
+
/** A background call's end that the model has not read. */
|
|
6588
|
+
export interface LateResult {
|
|
6589
|
+
/** The id the session keeps the call under. */
|
|
6590
|
+
operationId: string;
|
|
6591
|
+
outcome: ToolOperationOutcome;
|
|
6592
|
+
}
|
|
6593
|
+
/** A chat's ended results that no reply has read, as a {@linkcode LateResultsDecider} is asked. */
|
|
6594
|
+
export interface LateResultsAsk {
|
|
6595
|
+
/** The turn's \`host\`: what the app makes of the request. */
|
|
6596
|
+
host: unknown;
|
|
6597
|
+
/** The conversation reference the page holds. */
|
|
6598
|
+
conversation: string;
|
|
6599
|
+
results: readonly LateResult[];
|
|
6600
|
+
}
|
|
6601
|
+
/** A background call ended, and what Theorem lets the decider do about it. */
|
|
6602
|
+
export interface LateResultEnded {
|
|
6603
|
+
/** The \`host\` of the request that started the call. */
|
|
6604
|
+
host: unknown;
|
|
6605
|
+
result: LateResult;
|
|
6606
|
+
/**
|
|
6607
|
+
* Runs a reply to no message in \`conversation\`, as a page's wake does: the decider's \`give\` is
|
|
6608
|
+
* asked with \`reason: 'wake'\`. It runs nothing while a reply waits on gates or answers a
|
|
6609
|
+
* message, and a message posted meanwhile wins. The reference must stay the same across
|
|
6610
|
+
* writes, so a store whose reference changes with each write cannot wake from the server.
|
|
6611
|
+
*/
|
|
6612
|
+
wake(conversation: string): Promise<void>;
|
|
6613
|
+
/** Tells the pages open on the session to read the chat again. */
|
|
6614
|
+
notify(): Promise<void>;
|
|
6615
|
+
}
|
|
6616
|
+
/**
|
|
6617
|
+
* Who tells the model that a background call ended. Theorem runs; the decider decides, and it
|
|
6618
|
+
* keeps its own count of what it told, such as a cap or quiet hours.
|
|
6619
|
+
*/
|
|
6620
|
+
export interface LateResultsDecider {
|
|
6621
|
+
/**
|
|
6622
|
+
* The results a reply gives the model, by \`operationId\`. \`reason\` is \`'message'\` for a reply to
|
|
6623
|
+
* the person's message and \`'wake'\` for a reply to no message. Asked once for each reply, before
|
|
6624
|
+
* its model runs. The model reads each result you return once. One you leave out stays for a
|
|
6625
|
+
* later reply. A wake you give nothing runs no reply and leaves no mark.
|
|
6626
|
+
*/
|
|
6627
|
+
give(ask: LateResultsAsk & {
|
|
6628
|
+
reason: 'message' | 'wake';
|
|
6629
|
+
}): readonly string[] | Promise<readonly string[]>;
|
|
6630
|
+
/**
|
|
6631
|
+
* Whether a page open on the chat wakes it now. Asked each time a page reads the chat, so it
|
|
6632
|
+
* must change nothing. Say yes only when \`give\` would give something. Unset, no page wakes it.
|
|
6633
|
+
*/
|
|
6634
|
+
due?(ask: LateResultsAsk): boolean | Promise<boolean>;
|
|
6635
|
+
/** A background call ended. Use \`wake\` to reply from the server, with no page open. */
|
|
6636
|
+
ended?(ended: LateResultEnded): void | Promise<void>;
|
|
6637
|
+
}
|
|
6567
6638
|
/**
|
|
6568
6639
|
* How an application runs its turns: the one value its own call sites, its web handler and the
|
|
6569
6640
|
* studio all use, so they cannot run a turn differently. An app that calls \`runTurn\` itself
|
|
@@ -6583,15 +6654,12 @@ export interface TurnWiring {
|
|
|
6583
6654
|
*/
|
|
6584
6655
|
prepare?: (turn: NormalizedTurnRequest) => TurnRequest | Promise<TurnRequest>;
|
|
6585
6656
|
/**
|
|
6586
|
-
*
|
|
6587
|
-
*
|
|
6588
|
-
*
|
|
6589
|
-
*
|
|
6657
|
+
* Who tells the model that a background call ended, and when. Theorem runs the replies; this
|
|
6658
|
+
* decides. Unset, the model is never told: no page wakes the chat, and no reply reads a late
|
|
6659
|
+
* result. \`pageWakes\` from \`@theoremjs/web/server\` lets the open page wake the chat, for an app
|
|
6660
|
+
* with no server of its own.
|
|
6590
6661
|
*/
|
|
6591
|
-
|
|
6592
|
-
host: unknown;
|
|
6593
|
-
conversation: string;
|
|
6594
|
-
}) => boolean | Promise<boolean>;
|
|
6662
|
+
lateResultsDecider?: LateResultsDecider;
|
|
6595
6663
|
}
|
|
6596
6664
|
/** A profile projected for a client, with its secrets and server-only fields removed. */
|
|
6597
6665
|
export interface ProjectedProfile extends ProfileModelFields {
|
|
@@ -6936,7 +7004,7 @@ import { z } from 'zod';
|
|
|
6936
7004
|
import { type ErrorCopies, type GuardrailEvent } from '../guardrails/event-schemas.js';
|
|
6937
7005
|
import type { ErrorKind } from '../guardrails/theorem-error.js';
|
|
6938
7006
|
import { type JsonObject, type JsonValue } from './json.js';
|
|
6939
|
-
import { AWAITING_USER_INPUT_STATUS, type CompactionMeter, type CompactionOutcome, type MediaInputKind, type StageApplyWarningCode, type ToolAccess, type ToolAuthType, type ToolPermission, type TurnStage, type TurnStopKind } from './schema.js';
|
|
7007
|
+
import { AWAITING_USER_INPUT_STATUS, type CompactionMeter, type CompactionOutcome, type MediaInputKind, type StageApplyWarningCode, type ToolAccess, type ToolAuthType, type ToolPermission, type TurnInjectStage, type TurnStage, type TurnStopKind } from './schema.js';
|
|
6940
7008
|
export type { ErrorCopies, ErrorKind, GuardrailEvent };
|
|
6941
7009
|
/** A text part of a history message. */
|
|
6942
7010
|
export interface InteractionTextPart {
|
|
@@ -7212,7 +7280,7 @@ export type SessionEventOf<K extends SessionEventKind> = Extract<SessionEvent, {
|
|
|
7212
7280
|
kind: K;
|
|
7213
7281
|
}>;
|
|
7214
7282
|
/** The host hooks whose crash the turn survives and reports as \`hook_failed\`. */
|
|
7215
|
-
declare const HOOK_NAMES: readonly ["execution", "background", "onStage", "onEvent", "onAgentCall", "tools.preTool", "tools.t1Policy", "outputs.validation", "compaction.trigger"];
|
|
7283
|
+
declare const HOOK_NAMES: readonly ["execution", "background", "onStage", "lateResults", "onEvent", "onAgentCall", "tools.preTool", "tools.t1Policy", "outputs.validation", "compaction.trigger"];
|
|
7216
7284
|
/** A host hook a \`hook_failed\` event names. */
|
|
7217
7285
|
export type HookName = (typeof HOOK_NAMES)[number];
|
|
7218
7286
|
/** Why a tool call failed, for the builder and for the user. */
|
|
@@ -7617,13 +7685,18 @@ export type TurnEvent = {
|
|
|
7617
7685
|
reason: AttemptReason;
|
|
7618
7686
|
}
|
|
7619
7687
|
/**
|
|
7620
|
-
* The message \`
|
|
7621
|
-
*
|
|
7688
|
+
* The message \`lateResults\` put in the conversation, role \`user\`. It enters a history built from
|
|
7689
|
+
* events like any other message. \`operationIds\` are the calls whose results it holds; \`stage\` and
|
|
7690
|
+
* \`step\` are where it landed. \`inReply\` is true when it landed inside a reply: after the person's
|
|
7691
|
+
* message, mid-turn, or as a paused reply went on. Otherwise it opened the reply.
|
|
7622
7692
|
*/
|
|
7623
7693
|
| {
|
|
7624
7694
|
type: 'late_results';
|
|
7625
7695
|
text: string;
|
|
7626
7696
|
operationIds: string[];
|
|
7697
|
+
stage: TurnInjectStage;
|
|
7698
|
+
step: number;
|
|
7699
|
+
inReply: boolean;
|
|
7627
7700
|
} | {
|
|
7628
7701
|
type: 'media';
|
|
7629
7702
|
media: {
|
|
@@ -14076,15 +14149,20 @@ export interface ToolDataRead {
|
|
|
14076
14149
|
*/
|
|
14077
14150
|
declare function readToolData(content: string): ToolDataRead[];
|
|
14078
14151
|
/**
|
|
14079
|
-
* Whether a role \`user\` message holds tool results that \`
|
|
14152
|
+
* Whether a role \`user\` message holds tool results that \`TurnRequest.lateResults\` gave. It is no one's
|
|
14080
14153
|
* word to the model. A person who types a fence only makes their own reply stricter.
|
|
14081
14154
|
*/
|
|
14082
14155
|
declare function isLateResult(message: TurnHistoryMessage): boolean;
|
|
14083
|
-
/**
|
|
14084
|
-
|
|
14156
|
+
/**
|
|
14157
|
+
* The history message \`TurnRequest.lateResults\` lands. Its metadata names the calls it holds, and
|
|
14158
|
+
* says when it landed inside a reply rather than opening one.
|
|
14159
|
+
*/
|
|
14160
|
+
declare function lateResultsMessage(text: string, operationIds: readonly string[], inReply: boolean): TurnHistoryMessage;
|
|
14161
|
+
/** Whether \`message\` is a late result that landed inside a reply. Such a message opens no reply. */
|
|
14162
|
+
declare function landedInReply(message: TurnHistoryMessage): boolean;
|
|
14085
14163
|
/** The calls whose late results a history message holds. */
|
|
14086
14164
|
declare function lateResultIds(message: TurnHistoryMessage): string[];
|
|
14087
|
-
export { isLateResult, lateResultIds, lateResultsMessage, readToolData, TOOL_CLOSE };
|
|
14165
|
+
export { isLateResult, landedInReply, lateResultIds, lateResultsMessage, readToolData, TOOL_CLOSE };
|
|
14088
14166
|
`,"file:///node_modules/@theoremjs/agents/src/guardrails/tool-directives.d.ts":`import type { AdvisoryLevel } from './types.js';
|
|
14089
14167
|
/**
|
|
14090
14168
|
* What of a tool's text reads as an instruction to the agent: an order to set its instructions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{H as r}from"./tool-schema-Bfe2TkD-.js";import{$i as i,$t as a,Ci as o,Cn as s,Di as c,Ea as l,Ha as u,Ja as ee,Ni as te,Pi as d,Qi as ne,Qt as re,Ra as f,Ri as p,Sn as m,Ta as ie,Tn as h,Y as ae,Yi as oe,bn as se,co as ce,ea as le,nn as ue,ro as de,so as g,ua as fe,va as pe,wi as me,xn as _,zt as he}from"./shaped-data-BxGL5na3.js";import{c as v}from"./host-patterns-F-KZIzkF.js";import{D as ge,S as _e,g as y,k as ve,v as ye,w as be}from"./schema-DI2QKpYi.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 b(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=h(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function x(e){return`uri`in e}function Ae(e){if(e.type===`speech`)throw new v(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new v(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new v(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=b(e.inputs??{});if(!t)throw new v(`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 S(e,t){return t?{...e,fileName:t}:e}function C(e,t,n){return t.filter(t=>!_(e,t.mimeType)).map(e=>S({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(S({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 w(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(...C(e.attachments,t,`attachment`)),e.voice&&r.push(...C(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 Le(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 Re(e,t){let n=Le(e);return g(n.key,n.params,t)}function T(e){return new v(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(Le)})}function E(e){if(!De.test(e))throw new v(`request`,`attachment data must be base64`);return je(e)}function D(e){let t={mimeType:e.mimeType,name:e.name};return x(e)||(t.sizeBytes=E(e.data)),t}function ze(e,t,n){if(!Be(t,n))return;let r=Ae(e),i=w({attachments:m(e,`attachments`),voice:m(e,`voice`),limits:r},(t??[]).map(D),(n??[]).map(D));if(i.length>0)throw T(i)}function O(e,t){if(x(e))return e;let{mimeType:n,data:r}=e;if(!Oe.has(h(n)))return e;let i=Pe(n,ie(r),t);return{...e,data:l(i)}}function Be(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Ve(e,t,n,r){return ze(e,t,n),{attachments:t?.length?t.map(e=>O(e,r.attachment)):t,voice:n?.length?n.map(e=>O(e,r.voice)):n}}function k(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function A(e){return e==null}function j(e){return A(e)||typeof e!=`object`||Array.isArray(e)?null:e}function M(e){let t=j(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function N(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function P(e){let t=e.properties;return j(t)??{}}function He(e,t){return e?`${e}.${t}`:t}function F(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function Ue(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 We(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,options:o,failures:s,crashes:c}=e;if(A(r)){i&&F(t,s);return}await Ue(t,r,a?.[t],o,s,c);let l=M(n),u=l?j(r):null;l&&u&&await I(l,u,t,a,o,s,c)}async function I(e,t,n,r,i,a,o){let s=P(e),c=new Set(N(e)),l=new Set([...Object.keys(s),...c]),u=j(t);for(let e of l)await We({path:He(n,e),propSchema:s[e],child:u?.[e],isRequired:c.has(e),fields:r,options:i,failures:a,crashes:o})}async function Ge(e,t,n,r,i=[]){let a=M(e);if(!a)throw new v(`config`,`structured validation requires a JSON Schema object root`);let o=[];if(!j(t)){for(let e of N(a))F(e,o);return o}return await I(a,t,``,n,r,o,i),o}function Ke(e,t){let n=e;for(let e of t.split(`.`)){let t=M(n);if(!t)return!1;let r=P(t);if(!Object.hasOwn(r,e)&&!N(t).includes(e))return!1;n=r[e]}return!0}function qe(e){return e.map(e=>e.error).join(`; `)}function L(e,t){let n=e;for(let e of t.split(`.`))n=j(n)?.[e];return n}function R(e,t,n){let[r,...i]=t.split(`.`),a=j(e)??{};return r===void 0?e:{...a,[r]:i.length?R(a[r],i.join(`.`),n):n}}async function Je(e,t,n,r=[]){let i=[];for(let[a,o]of Object.entries(t??{})){let t=L(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 z(e,t){let n=e;for(let e of t.split(`.`)){let t=M(n);if(!t)return;n=P(t)[e]}let r=j(n);if(r?.type===`array`)return j(r.items)??void 0}function Ye(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new v(`config`,g(`provider.binding_identity`))}function Xe(e){V(e.id,e.models),X(e.id,e.observability),zt(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))U(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:H(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Ze(e){V(e.id,e.models),J(e.id,e.guardrails),X(e.id,e.observability);for(let[t,n]of Object.entries(e.models))U(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new v(`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},...G(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Qe(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new v(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${ae(e.path)}: ${e.message}`).join(`; `)}`)}function $e(e,t,n){if(Qe(e,t,n,a),Ye(e,t,n,`decision`),`retry`in n)throw new v(`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 v(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function et(e){let t=e.models?k(e.models):void 0;if(!t)throw new v(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);$e(e.id,t,e.models[t])}function tt(e){if(e.inputs.state!==`json`)throw new v(`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 v(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new v(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function nt(e){return et(e),tt(e),X(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function B(e){return e===void 0?{}:{parallel:e}}function rt(e){return it(e.id,e.tools),X(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...B(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function it(e,t){if(!Array.isArray(t.allow))throw new v(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function V(e,t){if(Object.keys(t).length===0)throw new v(`config`,`Profile ${e} must declare at least one model`)}function H(e,t){let n=t.defaultModel??k(t.models);if(!n)throw new v(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new v(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function U(e,t,n){W(e,t,n),Qe(e,t,n,ue),W(e,t,n)}function W(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new v(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!p.includes(i))throw new v(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${p.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new v(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new v(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new v(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function G(e){return{providerContinuation:e.providerContinuation?pe.parse(e.providerContinuation):{},models:e.models,defaultModel:H(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function K(e,t,n){if(n?.length){for(let r of n)if(!he(r))throw new v(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (${me.join(` | `)}); got '${r}'`)}}function at(e,t){t&&(K(e,`allowContinue`,t.allowContinue),K(e,`autoContinue`,t.autoContinue))}function q(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=>q(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var st=Object.entries(te).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function ct(e){if(!q(e))throw new v(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new v(`config`,`Profile definition must set id`);if(!d.find(t=>t===e.type))throw new v(`config`,`Profile ${t}: type must be one of ${d.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 v(`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,a]of st){if(a&&!a.includes(n))continue;let o=i(e),s=ot(r,o.slice(0,-1)),c=o[o.length-1];if(s.some(e=>{if(!q(e))return!1;let t=e[c];return t==null||t===``}))throw new v(`config`,`Profile ${t}: type '${n}' must set ${o.join(`.`)}`)}}function dt(e){let{id:t,type:n}=e;if(n!==`live`&&le(`inputs`).includes(n)&&e.inputs==null)throw new v(`config`,`Profile ${t}: type '${n}' must set inputs`)}function ft(e){let[t]=ne(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new v(`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 v(`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 J(e,t){let n=t=>new v(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Y.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Y.join(`, `)}`);gt(t?.blockedReply,n)}var Y=[`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&&!f.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${f.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`?fe(`guardrails.detect`,t,u):fe(`guardrails.detect`,t);if(n!==void 0)throw new v(`config`,`Profile ${e.id}: ${n}`)}function X(e,t){try{let n=xe(t);if(!Number.isFinite(n.retainForDays))throw new v(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new v(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof v&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new v(ee(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??``;_e(r,`Profile ${e.id} identity.system`);let i=be(r,t,e.inputs?.options);if(i)throw new v(`config`,`Profile ${e.id} identity.system: ${i}`)}function Z(e){let t=yt(e),[n]=oe(e);if(n)throw new v(`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 v(`config`,g(`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 de)if(e.labels?.[t]!==void 0)throw new v(`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 nt(e);if(e.type===`embedding`)return Xe(e);if(e.type===`transcription`)return Ze(e);V(e.id,e.models),pt(e.id,e),J(e.id,e.guardrails),e.type===`text`&&mt(e.id,e.outputs?.validation),X(e.id,e.observability);for(let[t,n]of Object.entries(e.models))U(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=G(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,...B(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 v(`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 v(`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 v(`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 v(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not one of the profile's options`);let r=ge(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new v(`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 v(`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 v(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(x(t)?t.uri:t.data))throw new v(`config`,`${r} needs its bytes or its uri`)})}function Tt(e,t){let n=t?.filter(e=>!_(c,e));if(n?.length)throw new v(`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 v(`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 v(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new v(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new v(`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(Q(`${n}.triggerTokens`,r),Q(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new v(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function Q(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new v(`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 v(`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 v(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new v(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function kt(e,t){if(t.maxTokens<=0)throw new v(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new v(`config`,`${e}: compactAt must be in (0, 1)`)}function At(e,t){if(t.previousExchanges<0)throw new v(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new v(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new v(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function jt(e,t){for(let n of y(t))if(e.get(n)?.type===`builtin`)throw new v(`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=ye(t)?.t2Loader;if(n){if(!y(t).includes(n))throw new v(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new v(`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 v(`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){return t?.type===`text`?Ft(t).flatMap(t=>{let n=e.find(t);return n?[n.jsonSchema]:[]}):[]}function Lt(e,t){let n=Ft(t).map(n=>{let r=e.find(n);if(!r)throw new v(`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 v(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>z(t.jsonSchema,e)));if(o.length)throw new v(`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 v(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function Rt(e){let t=s(e)?.context;if(!t)return;let n=o;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new v(`config`,`Profile ${e.id}: inputs.context.from must list ${o.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new v(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function zt(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 v(`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 v(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Bt(e,t,n){let r=new Map,i=i=>{let a=Z(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,re(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),zt(o.id,s(o)),Rt(o),Lt(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 v(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function Vt(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Ht(e){let t;try{t=new URL(e.baseUrl)}catch{throw new v(`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 v(`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 v(`blocked`,`Local requests must stay on the configured origin.`))}}var Ut=n({data:t(n({id:e().min(1)}))});async function Wt(e,t){let n=Ht(e);if(!n?.fetch)throw new v(`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 v(`network`,`Local model list returned HTTP ${r.status}.`);let i=Ut.safeParse(await r.json());if(!i.success)throw new v(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var Gt=`https://openrouter.ai/api/v1/models`,Kt=`https://openrouter.ai/api/v1/embeddings/models`,qt=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],Jt=[{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},Xt=n({data:t(n({id:e().min(1),name:e().optional(),architecture:n({output_modalities:t(e()).optional()}).optional()}))}),Zt=n({data:t(n({id:e().min(1),name:e().optional()}))}),Qt=n({models:t(n({name:e().min(1),displayName:e().optional(),supportedGenerationMethods:t(e()).optional()})).optional(),nextPageToken:e().optional()}),$t=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 v(`auth`,`${e} refused the key.`);if(!r.ok)throw new v(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function en(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?Jt:qt];if(e===`openrouter`)return await tn(t,i,r);if(!i)throw new v(`auth`,`Choose a key to list Gemini models.`);return await rn(t,i,r)}async function tn(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Zt.safeParse(await $(`OpenRouter`,Kt,r));if(!e.success)throw new v(`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=Xt.safeParse(await $(`OpenRouter`,`${Gt}?output_modalities=${i}`,r));if(!a.success)throw new v(`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 nn={live:`bidiGenerateContent`,embedding:`embedContent`};async function rn(e,t,n){let i=nn[e]??`generateContent`,a=[],o;for(let e=0;e<$t;e++){let e=new URL(r);e.searchParams.set(`pageSize`,`1000`),o&&e.searchParams.set(`pageToken`,o);let s=Qt.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!s.success)throw new v(`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 an(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function on(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{Ve as C,b as S,Re as _,an as a,E as b,Z as c,Ge as d,qe as f,k as g,R as h,Ht as i,It as l,L as m,Wt as n,on as o,z as p,en as r,Bt as s,Vt as t,Je as u,w as v,x,T as y};
|
|
1
|
+
import{E as e,d as t,x as n}from"./schemas-D7cgkv3L.js";import{H as r}from"./tool-schema-CnrGGkcr.js";import{$i as i,$t as a,Cn as o,Da as s,Ea as c,Fi as l,Oi as u,Pi as ee,Qt as te,Sn as d,Ti as ne,Tn as f,Ua as re,Xi as ie,Y as ae,Ya as oe,bn as se,co as p,da as m,ea as ce,io as le,lo as ue,nn as de,ta as fe,wi as h,xn as g,ya as pe,za as me,zi as _,zt as he}from"./shaped-data-BxDmEUJe.js";import{c as v}from"./host-patterns-F-KZIzkF.js";import{D as ge,S as _e,g as y,k as ve,v as ye,w as be}from"./schema-Do4wX6Sr.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 b(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=f(e);if(t.limitsByMime[n])return t.limitsByMime[n];let[r]=n.split(`/`),i=`${r}/*`;if(t.limitsByMime[i])return t.limitsByMime[i]}return t.maxBytes}function x(e){return`uri`in e}function Ae(e){if(e.type===`speech`)throw new v(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new v(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new v(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=b(e.inputs??{});if(!t)throw new v(`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 S(e,t){return t?{...e,fileName:t}:e}function C(e,t,n){return t.filter(t=>!g(e,t.mimeType)).map(e=>S({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(S({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 w(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(...C(e.attachments,t,`attachment`)),e.voice&&r.push(...C(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 Le(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 Re(e,t){let n=Le(e);return p(n.key,n.params,t)}function T(e){return new v(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(Le)})}function E(e){if(!De.test(e))throw new v(`request`,`attachment data must be base64`);return je(e)}function D(e){let t={mimeType:e.mimeType,name:e.name};return x(e)||(t.sizeBytes=E(e.data)),t}function ze(e,t,n){if(!Be(t,n))return;let r=Ae(e),i=w({attachments:d(e,`attachments`),voice:d(e,`voice`),limits:r},(t??[]).map(D),(n??[]).map(D));if(i.length>0)throw T(i)}function O(e,t){if(x(e))return e;let{mimeType:n,data:r}=e;if(!Oe.has(f(n)))return e;let i=Pe(n,c(r),t);return{...e,data:s(i)}}function Be(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Ve(e,t,n,r){return ze(e,t,n),{attachments:t?.length?t.map(e=>O(e,r.attachment)):t,voice:n?.length?n.map(e=>O(e,r.voice)):n}}function k(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}function A(e){return e==null}function j(e){return A(e)||typeof e!=`object`||Array.isArray(e)?null:e}function M(e){let t=j(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function N(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function P(e){let t=e.properties;return j(t)??{}}function He(e,t){return e?`${e}.${t}`:t}function F(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function Ue(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 We(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,options:o,failures:s,crashes:c}=e;if(A(r)){i&&F(t,s);return}await Ue(t,r,a?.[t],o,s,c);let l=M(n),u=l?j(r):null;l&&u&&await I(l,u,t,a,o,s,c)}async function I(e,t,n,r,i,a,o){let s=P(e),c=new Set(N(e)),l=new Set([...Object.keys(s),...c]),u=j(t);for(let e of l)await We({path:He(n,e),propSchema:s[e],child:u?.[e],isRequired:c.has(e),fields:r,options:i,failures:a,crashes:o})}async function Ge(e,t,n,r,i=[]){let a=M(e);if(!a)throw new v(`config`,`structured validation requires a JSON Schema object root`);let o=[];if(!j(t)){for(let e of N(a))F(e,o);return o}return await I(a,t,``,n,r,o,i),o}function Ke(e,t){let n=e;for(let e of t.split(`.`)){let t=M(n);if(!t)return!1;let r=P(t);if(!Object.hasOwn(r,e)&&!N(t).includes(e))return!1;n=r[e]}return!0}function qe(e){return e.map(e=>e.error).join(`; `)}function L(e,t){let n=e;for(let e of t.split(`.`))n=j(n)?.[e];return n}function R(e,t,n){let[r,...i]=t.split(`.`),a=j(e)??{};return r===void 0?e:{...a,[r]:i.length?R(a[r],i.join(`.`),n):n}}async function Je(e,t,n,r=[]){let i=[];for(let[a,o]of Object.entries(t??{})){let t=L(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 z(e,t){let n=e;for(let e of t.split(`.`)){let t=M(n);if(!t)return;n=P(t)[e]}let r=j(n);if(r?.type===`array`)return j(r.items)??void 0}function Ye(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new v(`config`,p(`provider.binding_identity`))}function Xe(e){V(e.id,e.models),X(e.id,e.observability),zt(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))U(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:H(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Ze(e){V(e.id,e.models),J(e.id,e.guardrails),X(e.id,e.observability);for(let[t,n]of Object.entries(e.models))U(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new v(`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},...G(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Qe(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new v(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${ae(e.path)}: ${e.message}`).join(`; `)}`)}function $e(e,t,n){if(Qe(e,t,n,a),Ye(e,t,n,`decision`),`retry`in n)throw new v(`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 v(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function et(e){let t=e.models?k(e.models):void 0;if(!t)throw new v(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);$e(e.id,t,e.models[t])}function tt(e){if(e.inputs.state!==`json`)throw new v(`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 v(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new v(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function nt(e){return et(e),tt(e),X(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function B(e){return e===void 0?{}:{parallel:e}}function rt(e){return it(e.id,e.tools),X(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...B(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function it(e,t){if(!Array.isArray(t.allow))throw new v(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function V(e,t){if(Object.keys(t).length===0)throw new v(`config`,`Profile ${e} must declare at least one model`)}function H(e,t){let n=t.defaultModel??k(t.models);if(!n)throw new v(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new v(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function U(e,t,n){W(e,t,n),Qe(e,t,n,de),W(e,t,n)}function W(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new v(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!_.includes(i))throw new v(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${_.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new v(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new v(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new v(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function G(e){return{providerContinuation:e.providerContinuation?pe.parse(e.providerContinuation):{},models:e.models,defaultModel:H(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function K(e,t,n){if(n?.length){for(let r of n)if(!he(r))throw new v(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (${ne.join(` | `)}); got '${r}'`)}}function at(e,t){t&&(K(e,`allowContinue`,t.allowContinue),K(e,`autoContinue`,t.autoContinue))}function q(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=>q(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var st=Object.entries(ee).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function ct(e){if(!q(e))throw new v(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new v(`config`,`Profile definition must set id`);if(!l.find(t=>t===e.type))throw new v(`config`,`Profile ${t}: type must be one of ${l.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 v(`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=ce(e),o=ot(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!q(e))return!1;let t=e[s];return t==null||t===``}))throw new v(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function dt(e){let{id:t,type:n}=e;if(n!==`live`&&fe(`inputs`).includes(n)&&e.inputs==null)throw new v(`config`,`Profile ${t}: type '${n}' must set inputs`)}function ft(e){let[t]=i(e);if(!t)return;let{offValue:n,reason:r}=t.scope,a=n===void 0?``:` (other than ${n})`;throw new v(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${a} — ${r}`)}function pt(e,t){let n=t.turnBehaviour;at(e,n?.resumption)}function mt(e,t){let n=t=>new v(`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 J(e,t){let n=t=>new v(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Y.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Y.join(`, `)}`);gt(t?.blockedReply,n)}var Y=[`quota`,`detect`,`blockedReply`,`network`,`taint`],ht=[`onBlock`,`maxRetries`];function gt(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!ht.includes(e));if(n!==void 0)throw t(`guardrails.blockedReply.${n} is not a setting; it takes onBlock and maxRetries`);let{onBlock:r,maxRetries:i}=e;if(r!==void 0&&!me.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${me.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function _t(e){let t=e.guardrails?.detect,n=e.type===`host`?m(`guardrails.detect`,t,re):m(`guardrails.detect`,t);if(n!==void 0)throw new v(`config`,`Profile ${e.id}: ${n}`)}function X(e,t){try{let n=xe(t);if(!Number.isFinite(n.retainForDays))throw new v(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new v(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof v&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new v(oe(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??``;_e(r,`Profile ${e.id} identity.system`);let i=be(r,t,e.inputs?.options);if(i)throw new v(`config`,`Profile ${e.id} identity.system: ${i}`)}function Z(e){let t=yt(e),[n]=ie(e);if(n)throw new v(`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 v(`config`,p(`provider.profile_configuration`,{profile:e.id,field:t}));ft(e),dt(e),ut(e),lt(e),e.labels&&ue(e.labels,`Profile ${e.id}`);for(let t of le)if(e.labels?.[t]!==void 0)throw new v(`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 nt(e);if(e.type===`embedding`)return Xe(e);if(e.type===`transcription`)return Ze(e);V(e.id,e.models),pt(e.id,e),J(e.id,e.guardrails),e.type===`text`&&mt(e.id,e.outputs?.validation),X(e.id,e.observability);for(let[t,n]of Object.entries(e.models))U(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=G(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,...B(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 v(`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 v(`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 v(`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 v(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not one of the profile's options`);let r=ge(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new v(`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 v(`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 v(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(x(t)?t.uri:t.data))throw new v(`config`,`${r} needs its bytes or its uri`)})}function Tt(e,t){let n=t?.filter(e=>!g(u,e));if(n?.length)throw new v(`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 v(`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 v(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new v(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new v(`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(Q(`${n}.triggerTokens`,r),Q(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new v(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function Q(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new v(`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 v(`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 v(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new v(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function kt(e,t){if(t.maxTokens<=0)throw new v(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new v(`config`,`${e}: compactAt must be in (0, 1)`)}function At(e,t){if(t.previousExchanges<0)throw new v(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new v(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new v(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function jt(e,t){for(let n of y(t))if(e.get(n)?.type===`builtin`)throw new v(`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=ye(t)?.t2Loader;if(n){if(!y(t).includes(n))throw new v(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new v(`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 v(`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){return t?.type===`text`?Ft(t).flatMap(t=>{let n=e.find(t);return n?[n.jsonSchema]:[]}):[]}function Lt(e,t){let n=Ft(t).map(n=>{let r=e.find(n);if(!r)throw new v(`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 v(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>z(t.jsonSchema,e)));if(o.length)throw new v(`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 v(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function Rt(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 v(`config`,`Profile ${e.id}: inputs.context.from must list ${h.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new v(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function zt(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 v(`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 v(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function Bt(e,t,n){let r=new Map,i=i=>{let a=Z(i),s=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,s),Mt(e,s),s.type!==`host`&&s.type!==`decision`&&s.type!==`embedding`){Pt(e,s),zt(s.id,o(s)),Rt(s),Lt(t,s);for(let[e,t]of Object.entries(s.models))t.compaction&&Ot(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 v(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function Vt(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function Ht(e){let t;try{t=new URL(e.baseUrl)}catch{throw new v(`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 v(`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 v(`blocked`,`Local requests must stay on the configured origin.`))}}var Ut=n({data:t(n({id:e().min(1)}))});async function Wt(e,t){let n=Ht(e);if(!n?.fetch)throw new v(`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 v(`network`,`Local model list returned HTTP ${r.status}.`);let i=Ut.safeParse(await r.json());if(!i.success)throw new v(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var Gt=`https://openrouter.ai/api/v1/models`,Kt=`https://openrouter.ai/api/v1/embeddings/models`,qt=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],Jt=[{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},Xt=n({data:t(n({id:e().min(1),name:e().optional(),architecture:n({output_modalities:t(e()).optional()}).optional()}))}),Zt=n({data:t(n({id:e().min(1),name:e().optional()}))}),Qt=n({models:t(n({name:e().min(1),displayName:e().optional(),supportedGenerationMethods:t(e()).optional()})).optional(),nextPageToken:e().optional()}),$t=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 v(`auth`,`${e} refused the key.`);if(!r.ok)throw new v(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function en(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?Jt:qt];if(e===`openrouter`)return await tn(t,i,r);if(!i)throw new v(`auth`,`Choose a key to list Gemini models.`);return await rn(t,i,r)}async function tn(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Zt.safeParse(await $(`OpenRouter`,Kt,r));if(!e.success)throw new v(`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=Xt.safeParse(await $(`OpenRouter`,`${Gt}?output_modalities=${i}`,r));if(!a.success)throw new v(`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 nn={live:`bidiGenerateContent`,embedding:`embedContent`};async function rn(e,t,n){let i=nn[e]??`generateContent`,a=[],o;for(let e=0;e<$t;e++){let e=new URL(r);e.searchParams.set(`pageSize`,`1000`),o&&e.searchParams.set(`pageToken`,o);let s=Qt.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!s.success)throw new v(`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 an(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function on(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{Ve as C,b as S,Re as _,an as a,E as b,Z as c,Ge as d,qe as f,k as g,R as h,Ht as i,It as l,L as m,Wt as n,on as o,z as p,en as r,Bt as s,Vt as t,Je as u,w as v,x,T as y};
|