@theoremjs/studio 0.3.4-next.715.geef22fd → 0.3.4-next.721.g7ff150a
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/browser-execution.d.ts +3 -2
- package/browser-execution.js +2 -0
- package/browser-live.js +2 -1
- package/browser-transport.js +1 -0
- package/package.json +4 -4
- package/page/assets/Banner-CvzDCsXL.js +3 -0
- package/page/assets/{ConsoleFrame-dOTqIkpb.js → ConsoleFrame-DwVyTmlI.js} +1 -1
- package/page/assets/{MenuBottomSheet-DeuZCVb-.js → MenuBottomSheet-DfwpdQHV.js} +1 -1
- package/page/assets/{SchemaFields-DeuNDrvj.js → SchemaFields-DDqEu_Dl.js} +1 -1
- package/page/assets/{ToolResultCharts-B-pokquL.js → ToolResultCharts-DgVbZ6tY.js} +1 -1
- package/page/assets/{TraceInspector-CvJ0wx9n.js → TraceInspector-D0_MVLtt.js} +1 -1
- package/page/assets/{TraceOverview-cIjJwpvK.js → TraceOverview-DKnXuaLk.js} +1 -1
- package/page/assets/{_virtual_studio-type-sources-BxnDf9BC.js → _virtual_studio-type-sources-BSY0b1_W.js} +65 -115
- package/page/assets/browser-connection-DMLe-0pv.js +3 -0
- package/page/assets/browser-engine-Daccda1E.js +13 -0
- package/page/assets/{browser-transport-DKhZ4zo1.js → browser-transport-Ddqv2L5-.js} +3 -3
- package/page/assets/{crypto-BnoW7FFO.js → crypto-DjhcOJmp.js} +1 -1
- package/page/assets/{encode-files-DoLGXgup.js → encode-files-BF1rsZES.js} +1 -1
- package/page/assets/{export-agent-CO4lAMum.js → export-agent-CDiThjyY.js} +1 -1
- package/page/assets/{guardrail-tester-Slctc2oI.js → guardrail-tester-BjJ6KSvt.js} +1 -1
- package/page/assets/index-Cvl7QJ2f.js +149 -0
- package/page/assets/live-messages-eYYz6aFz.js +1 -0
- package/page/assets/reader-DAdKx3ZF.js +5 -0
- package/page/assets/{shaped-data-7q5Be8sp.js → shaped-data-BRffby3g.js} +1 -1
- package/page/assets/{stub--LOYiyQO.js → stub-4NoUUWes.js} +1 -1
- package/page/assets/{studio-code-pane-CuccT4Ur.js → studio-code-pane-OXpOLYem.js} +3 -3
- package/page/assets/{studio-console-DwxLzV9_.js → studio-console-DdjCZJRm.js} +1 -1
- package/page/assets/{studio-decision-w6OjVUM3.js → studio-decision-Dd4-ZPqy.js} +1 -1
- package/page/assets/{studio-embedding-CxFoTvOd.js → studio-embedding-BCfUGzri.js} +1 -1
- package/page/assets/{studio-host-console-BhQSkUhA.js → studio-host-console-CwErqojz.js} +2 -2
- package/page/assets/{studio-labels-q6eBFSru.js → studio-labels-BZFUS19x.js} +1 -1
- package/page/assets/studio-live-ChYgN-57.js +5 -0
- package/page/assets/{studio-map-DlkGoGam.js → studio-map-CKgv43yP.js} +1 -1
- package/page/assets/{studio-trace-replay-Ccv4ToIz.js → studio-trace-replay-vOG3xvRR.js} +2 -2
- package/page/assets/{studio-type-checker-Dm2eit0p.js → studio-type-checker-BO-lN_65.js} +1 -1
- package/page/assets/{tool-schema-6RWBAqGO.js → tool-schema-C7lMQU0w.js} +7 -7
- package/page/assets/{trace-record-Dm2jEhUR.js → trace-record-Doo6lYDI.js} +1 -1
- package/page/assets/tree-BpAzPK_j.js +3 -0
- package/page/assets/{turn-client-OLK12Fyi.js → turn-client-CMgd-m7p.js} +2 -2
- package/page/assets/{use-one-call-CLndFp2X.js → use-one-call-B_8i95fw.js} +1 -1
- package/page/assets/{use-second-ticker-D6JSf9B3.js → use-second-ticker-Bx4tqkhi.js} +1 -1
- package/page/assets/{workspace-DSAX72vF.js → workspace-CUvoWPwb.js} +1 -1
- package/page/index.html +15 -15
- package/replay.js +1 -0
- package/runtime-scope.d.ts +10 -1
- package/runtime-scope.js +7 -0
- package/runtime.js +3 -0
- package/server/handler.js +2 -1
- package/server/live.js +5 -1
- package/ui/profile-editor.js +34 -4
- package/page/assets/Banner-CrhjYjDy.js +0 -3
- package/page/assets/browser-connection-CuWeoI9s.js +0 -3
- package/page/assets/browser-engine-C3SeJyrA.js +0 -13
- package/page/assets/index-CAK9cdCh.js +0 -149
- package/page/assets/live-messages-M0vS3YB0.js +0 -1
- package/page/assets/reader-747-Cvu8.js +0 -5
- package/page/assets/studio-live-D5NjMEky.js +0 -5
- package/page/assets/tree-DcCW259J.js +0 -3
|
@@ -5319,8 +5319,33 @@ export interface CompactionSpec {
|
|
|
5319
5319
|
/** Replaces the default \`tokens > compactAt * maxTokens\` check. */
|
|
5320
5320
|
trigger?: (ctx: CompactionTriggerContext) => boolean | Promise<boolean>;
|
|
5321
5321
|
}
|
|
5322
|
+
/** What every request that runs a model takes: how to stop it, and where its trace goes. */
|
|
5323
|
+
export interface RunControls {
|
|
5324
|
+
/** Stops the run when it aborts, and cancels in-flight provider HTTP where the adapter supports it. */
|
|
5325
|
+
signal?: AbortSignal;
|
|
5326
|
+
/** Host-owned metadata preserved on the run's trace records; the kernel does not interpret it. */
|
|
5327
|
+
metadata?: Record<string, unknown>;
|
|
5328
|
+
/**
|
|
5329
|
+
* W3C \`traceparent\` of the host span this run goes under. The run's root span joins that trace
|
|
5330
|
+
* as its child; without it the run starts a new trace. A malformed value throws.
|
|
5331
|
+
*/
|
|
5332
|
+
traceparent?: string;
|
|
5333
|
+
/** Your project id, recorded on the trace. */
|
|
5334
|
+
projectId?: string;
|
|
5335
|
+
/** Host conversation id, recorded as \`gen_ai.conversation.id\`. */
|
|
5336
|
+
conversationId?: string;
|
|
5337
|
+
/** Earlier traces this run follows. */
|
|
5338
|
+
links?: TurnTraceLink[];
|
|
5339
|
+
}
|
|
5340
|
+
/** Which of the profile's models a run uses, and how hard it thinks. */
|
|
5341
|
+
export interface ModelChoice {
|
|
5342
|
+
/** Selected model id when \`profile.allowModelSelect\` is true. */
|
|
5343
|
+
model?: ModelId;
|
|
5344
|
+
/** Selected effort alias when the binding has \`allowEffortSelect\`. */
|
|
5345
|
+
effort?: string;
|
|
5346
|
+
}
|
|
5322
5347
|
/** \`compactHistory\` input, for \`timing: 'after'\`: the host passes back what \`done.compaction\` carried. */
|
|
5323
|
-
export interface CompactHistoryRequest {
|
|
5348
|
+
export interface CompactHistoryRequest extends RunControls {
|
|
5324
5349
|
/** The profile whose model binding carries the \`compaction\` spec. */
|
|
5325
5350
|
profile: ProfileId;
|
|
5326
5351
|
/** That binding; defaults to the profile's \`defaultModel\`. */
|
|
@@ -5328,10 +5353,6 @@ export interface CompactHistoryRequest {
|
|
|
5328
5353
|
history: TurnHistoryMessage[];
|
|
5329
5354
|
/** \`done.compaction.tokens\`: a failed compactor drops \`toCompact\` only when this is over \`maxTokens\`. */
|
|
5330
5355
|
tokens: number;
|
|
5331
|
-
signal?: AbortSignal;
|
|
5332
|
-
traceparent?: string;
|
|
5333
|
-
conversationId?: string;
|
|
5334
|
-
metadata?: Record<string, unknown>;
|
|
5335
5356
|
}
|
|
5336
5357
|
/** A structured-output schema given inline. */
|
|
5337
5358
|
export interface StructuredSpec {
|
|
@@ -5696,7 +5717,7 @@ export interface DecisionAsset {
|
|
|
5696
5717
|
data: string;
|
|
5697
5718
|
}
|
|
5698
5719
|
/** A request to \`runDecision\`: the profile, the state to judge, and the questions to answer. */
|
|
5699
|
-
export interface DecisionRequest {
|
|
5720
|
+
export interface DecisionRequest extends RunControls {
|
|
5700
5721
|
profile: ProfileId;
|
|
5701
5722
|
state: Exclude<DecisionJson, null>;
|
|
5702
5723
|
questions: Record<string, DecisionQuestion>;
|
|
@@ -5707,15 +5728,6 @@ export interface DecisionRequest {
|
|
|
5707
5728
|
* references are sent, so pick references that cannot occur in your text by accident.
|
|
5708
5729
|
*/
|
|
5709
5730
|
assets?: Record<string, DecisionAsset>;
|
|
5710
|
-
signal?: AbortSignal;
|
|
5711
|
-
/** Host-owned metadata preserved on the decision's trace record; the kernel does not interpret it. */
|
|
5712
|
-
metadata?: Record<string, unknown>;
|
|
5713
|
-
/**
|
|
5714
|
-
* W3C \`traceparent\` of the host span this decision runs under. The \`decide\`
|
|
5715
|
-
* root joins that trace as its child; without it the decision starts a new
|
|
5716
|
-
* trace. A malformed value throws.
|
|
5717
|
-
*/
|
|
5718
|
-
traceparent?: string;
|
|
5719
5731
|
}
|
|
5720
5732
|
/** The model's answer to one decision question. */
|
|
5721
5733
|
export type DecisionAnswer = {
|
|
@@ -5797,14 +5809,11 @@ export interface EmbeddingProfile extends Omit<ProfileCommon, 'identity' | 'outp
|
|
|
5797
5809
|
*/
|
|
5798
5810
|
export type EmbeddingTask = 'query' | 'document';
|
|
5799
5811
|
/** A request to \`runEmbedding\`. */
|
|
5800
|
-
export interface EmbeddingRequest {
|
|
5812
|
+
export interface EmbeddingRequest extends RunControls {
|
|
5801
5813
|
profile: ProfileId;
|
|
5802
5814
|
model?: ModelId;
|
|
5803
5815
|
input: EmbeddingInput | readonly EmbeddingInput[];
|
|
5804
5816
|
task?: EmbeddingTask;
|
|
5805
|
-
signal?: AbortSignal;
|
|
5806
|
-
metadata?: Record<string, unknown>;
|
|
5807
|
-
traceparent?: string;
|
|
5808
5817
|
}
|
|
5809
5818
|
/** One vector returned for one ordered embedding input. */
|
|
5810
5819
|
export interface EmbeddingVector {
|
|
@@ -5973,23 +5982,13 @@ export interface TurnTraceLink {
|
|
|
5973
5982
|
/** How the earlier turn stopped, when the host knows. */
|
|
5974
5983
|
stop?: TurnStopKind;
|
|
5975
5984
|
}
|
|
5976
|
-
/**
|
|
5977
|
-
export interface
|
|
5985
|
+
/** What \`runTurn\` and \`runSession\` both take: an agent's profile, its model, and the host's hooks and keys. */
|
|
5986
|
+
export interface AgentRunRequest extends RunControls, ModelChoice {
|
|
5978
5987
|
execution?: ToolExecutionCoordinator;
|
|
5979
5988
|
background?: ToolBackgroundService;
|
|
5980
5989
|
pageExecution?: PageToolExecution;
|
|
5981
5990
|
providerState?: ProviderCheckpoint;
|
|
5982
5991
|
profile: ProfileId;
|
|
5983
|
-
projectId?: string;
|
|
5984
|
-
/**
|
|
5985
|
-
* Sticky routing / cache session key for OpenRouter (\`session_id\`).
|
|
5986
|
-
* Not the same as \`projectId\` or Gemini \`previousInteractionId\`.
|
|
5987
|
-
*/
|
|
5988
|
-
sessionId?: string;
|
|
5989
|
-
/** Selected model id when \`profile.allowModelSelect\` is true. */
|
|
5990
|
-
model?: ModelId;
|
|
5991
|
-
/** Selected effort alias when the binding has \`allowEffortSelect\`. */
|
|
5992
|
-
effort?: string;
|
|
5993
5992
|
/**
|
|
5994
5993
|
* Args for built-in tools on the chosen model's \`builtInTools\`, by tool id.
|
|
5995
5994
|
* Each is parsed by the schema the provider's adapter declares for that tool.
|
|
@@ -5997,35 +5996,42 @@ export interface TurnRequest {
|
|
|
5997
5996
|
builtInArgs?: BuiltInArgs;
|
|
5998
5997
|
/** Host-provided dynamic system prompt combined with profile persona */
|
|
5999
5998
|
system?: SystemPrompt;
|
|
6000
|
-
/** This turn's voice, style, and speed, over \`profile.speech\`. Speech profiles only. */
|
|
6001
|
-
speech?: TurnSpeech;
|
|
6002
5999
|
sessionPermissions?: string[];
|
|
6003
6000
|
/** Host channel/path for catalog \`paths\` filtering. */
|
|
6004
6001
|
path?: string;
|
|
6005
|
-
/** This
|
|
6002
|
+
/** This run's facts, one value for each of \`profile.identity.conditions\` but \`path\`. */
|
|
6006
6003
|
conditions?: Readonly<Record<string, string>>;
|
|
6007
|
-
/** Host-owned metadata preserved for traces; the kernel does not interpret it. */
|
|
6008
|
-
metadata?: Record<string, unknown>;
|
|
6009
|
-
/**
|
|
6010
|
-
* W3C \`traceparent\` of the host span this turn runs under. The turn's root
|
|
6011
|
-
* span joins that trace as its child; without it the turn starts a new trace.
|
|
6012
|
-
* A malformed value throws.
|
|
6013
|
-
*/
|
|
6014
|
-
traceparent?: string;
|
|
6015
|
-
/** Host conversation id, recorded as \`gen_ai.conversation.id\`. */
|
|
6016
|
-
conversationId?: string;
|
|
6017
|
-
links?: TurnTraceLink[];
|
|
6018
6004
|
/**
|
|
6019
6005
|
* Opaque application context handed to tool \`handler\` / \`preTool\` and
|
|
6020
6006
|
* \`tools.t1Policy\` as \`ctx.host\`. The kernel never reads, logs, traces, or
|
|
6021
6007
|
* serializes it.
|
|
6022
6008
|
*/
|
|
6023
6009
|
host?: unknown;
|
|
6010
|
+
/** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
|
|
6011
|
+
credentials?: ToolCredentialSource;
|
|
6024
6012
|
/**
|
|
6025
|
-
*
|
|
6026
|
-
*
|
|
6013
|
+
* Resolves remote tool and OAuth host names before each request; a name that
|
|
6014
|
+
* resolves to a private address is refused (see \`fetchGuarded\`).
|
|
6027
6015
|
*/
|
|
6028
|
-
|
|
6016
|
+
resolveHost?: ResolveHost;
|
|
6017
|
+
/** Text \`runTurn\` and \`runSession\` emit stages and apply the returned affordances. A session's is set once. */
|
|
6018
|
+
onStage?: StageHandler;
|
|
6019
|
+
/**
|
|
6020
|
+
* Runs before each agent tool call in this run, and in the turns those
|
|
6021
|
+
* calls run. Shape the called agent's request (history, model, provider) or
|
|
6022
|
+
* refuse the call. Omit it: the agent runs on what the model sent.
|
|
6023
|
+
*/
|
|
6024
|
+
onAgentCall?: AgentCallHook;
|
|
6025
|
+
}
|
|
6026
|
+
/** A request to \`runTurn\`: the shared controls and the turn's input. */
|
|
6027
|
+
export interface TurnRequest extends AgentRunRequest {
|
|
6028
|
+
/**
|
|
6029
|
+
* Sticky routing / cache session key for OpenRouter (\`session_id\`).
|
|
6030
|
+
* Not the same as \`projectId\` or Gemini \`previousInteractionId\`.
|
|
6031
|
+
*/
|
|
6032
|
+
sessionId?: string;
|
|
6033
|
+
/** This turn's voice, style, and speed, over \`profile.speech\`. Speech profiles only. */
|
|
6034
|
+
speech?: TurnSpeech;
|
|
6029
6035
|
/**
|
|
6030
6036
|
* Continue a prior resumeable stop. On text profiles the turn's user message
|
|
6031
6037
|
* is the continue instruction (no \`input.text\`); the host passes the partial
|
|
@@ -6050,21 +6056,6 @@ export interface TurnRequest {
|
|
|
6050
6056
|
*/
|
|
6051
6057
|
stepsTaken?: number;
|
|
6052
6058
|
input?: TurnInput;
|
|
6053
|
-
/** Credentials for authenticated HTTP / MCP tools, read by auth slot when a tool needs one. */
|
|
6054
|
-
credentials?: ToolCredentialSource;
|
|
6055
|
-
/**
|
|
6056
|
-
* Resolves remote tool and OAuth host names before each request; a name that
|
|
6057
|
-
* resolves to a private address is refused (see \`fetchGuarded\`).
|
|
6058
|
-
*/
|
|
6059
|
-
resolveHost?: ResolveHost;
|
|
6060
|
-
/** Text \`runTurn\` emits stages and applies the returned affordances. */
|
|
6061
|
-
onStage?: StageHandler;
|
|
6062
|
-
/**
|
|
6063
|
-
* Runs before each agent tool call in this turn, and in the turns those
|
|
6064
|
-
* calls run. Shape the called agent's request (history, model, provider) or
|
|
6065
|
-
* refuse the call. Omit it: the agent runs on what the model sent.
|
|
6066
|
-
*/
|
|
6067
|
-
onAgentCall?: AgentCallHook;
|
|
6068
6059
|
}
|
|
6069
6060
|
/**
|
|
6070
6061
|
* How an application runs its turns: the one value its own call sites, its web handler and the
|
|
@@ -6179,19 +6170,9 @@ export interface TurnModel {
|
|
|
6179
6170
|
* Host request to open a long-lived live session (\`runSession\`).
|
|
6180
6171
|
* Profile must be \`type: 'live'\`.
|
|
6181
6172
|
*/
|
|
6182
|
-
export interface SessionRequest {
|
|
6183
|
-
providerState?: ProviderCheckpoint;
|
|
6184
|
-
profile: ProfileId;
|
|
6185
|
-
/** Host-built system prompt merged with profile identity.system. */
|
|
6186
|
-
system?: SystemPrompt;
|
|
6173
|
+
export interface SessionRequest extends AgentRunRequest {
|
|
6187
6174
|
/** Override \`profile.live.voice\` for this session. */
|
|
6188
6175
|
voice?: string;
|
|
6189
|
-
/** As \`TurnRequest.builtInArgs\`. */
|
|
6190
|
-
builtInArgs?: BuiltInArgs;
|
|
6191
|
-
path?: string;
|
|
6192
|
-
/** As \`TurnRequest.conditions\`. */
|
|
6193
|
-
conditions?: Readonly<Record<string, string>>;
|
|
6194
|
-
sessionPermissions?: string[];
|
|
6195
6176
|
history?: TurnHistoryMessage[];
|
|
6196
6177
|
/** The value chosen for each of the profile's \`inputs.slots\`. */
|
|
6197
6178
|
slots?: Record<string, string>;
|
|
@@ -6209,38 +6190,6 @@ export interface SessionRequest {
|
|
|
6209
6190
|
* \`tools.allow\`; ids outside it are refused.
|
|
6210
6191
|
*/
|
|
6211
6192
|
snapshot?: TurnToolSnapshot;
|
|
6212
|
-
signal?: AbortSignal;
|
|
6213
|
-
/** Host-owned metadata preserved on every record the session writes. */
|
|
6214
|
-
metadata?: Record<string, unknown>;
|
|
6215
|
-
/**
|
|
6216
|
-
* W3C \`traceparent\` of the host span this session runs under. The session's
|
|
6217
|
-
* root span joins that trace as its child; without it the session starts a
|
|
6218
|
-
* new trace. A malformed value throws.
|
|
6219
|
-
*/
|
|
6220
|
-
traceparent?: string;
|
|
6221
|
-
/** Host conversation id, recorded as \`gen_ai.conversation.id\`. */
|
|
6222
|
-
conversationId?: string;
|
|
6223
|
-
links?: TurnTraceLink[];
|
|
6224
|
-
/** Immutable for the session; there is no \`setOnStage\`. */
|
|
6225
|
-
onStage?: StageHandler;
|
|
6226
|
-
/**
|
|
6227
|
-
* As \`TurnRequest.onAgentCall\`, for the agent tools this session's calls run.
|
|
6228
|
-
* Omit it: each agent runs on what the model sent, with the session's own
|
|
6229
|
-
* provider options.
|
|
6230
|
-
*/
|
|
6231
|
-
onAgentCall?: AgentCallHook;
|
|
6232
|
-
/**
|
|
6233
|
-
* Default credentials for \`executeTool\` (per-call args override). Without one, the
|
|
6234
|
-
* session keeps keys typed at its sign-in gates in memory.
|
|
6235
|
-
*/
|
|
6236
|
-
credentials?: ToolCredentialSource;
|
|
6237
|
-
/**
|
|
6238
|
-
* Resolves remote tool and OAuth host names before each request; a name that
|
|
6239
|
-
* resolves to a private address is refused (see \`fetchGuarded\`).
|
|
6240
|
-
*/
|
|
6241
|
-
resolveHost?: ResolveHost;
|
|
6242
|
-
/** Opaque host slot for stages / tool execute (per-call args override). */
|
|
6243
|
-
host?: unknown;
|
|
6244
6193
|
}
|
|
6245
6194
|
/**
|
|
6246
6195
|
* Run a call the model made in this session, by its id: once, with the
|
|
@@ -10758,7 +10707,7 @@ export type TranscriptionProfileDefinition = Omit<ProfileDefinitionBase, 'identi
|
|
|
10758
10707
|
};
|
|
10759
10708
|
};
|
|
10760
10709
|
/** What a host writes to define a live profile. */
|
|
10761
|
-
export type LiveProfileDefinition = ProfileDefinitionBase & {
|
|
10710
|
+
export type LiveProfileDefinition = Omit<ProfileDefinitionBase, 'maxSteps'> & {
|
|
10762
10711
|
type: 'live';
|
|
10763
10712
|
live: NonNullable<LiveProfile['live']>;
|
|
10764
10713
|
inputs?: LiveProfile['inputs'];
|
|
@@ -11076,7 +11025,7 @@ import { type LabelOverrides } from '../../guardrails/labels.js';
|
|
|
11076
11025
|
import type { SpanHandle } from '../../observability/trace-span.js';
|
|
11077
11026
|
import type { ToolAccess } from '../schema.js';
|
|
11078
11027
|
import { type InjectUnit, type StageHandler, type StageResult, type StepCall } from '../stages.js';
|
|
11079
|
-
import type { Profile, TurnEvent, TurnHistoryMessage } from '../types.js';
|
|
11028
|
+
import type { Profile, TurnEvent, TurnHistoryMessage, TurnTokens } from '../types.js';
|
|
11080
11029
|
import { type ToolCallBase } from './events.js';
|
|
11081
11030
|
import type { ModelToolResult, ToolContext, ToolFailure, ToolGate, ToolLabels } from './types.js';
|
|
11082
11031
|
/** How a call's wait for other calls in its step ended: they settled, or the wait cannot end. */
|
|
@@ -11109,6 +11058,8 @@ export interface ToolStageSupport {
|
|
|
11109
11058
|
drafts?: boolean;
|
|
11110
11059
|
/** Told when the body has ended, before \`post_tool\` reads it. */
|
|
11111
11060
|
bodyEnded?: () => void;
|
|
11061
|
+
/** Told what an agent tool's turn has spent so far. */
|
|
11062
|
+
spent?: (tokens: TurnTokens) => void;
|
|
11112
11063
|
}
|
|
11113
11064
|
export type PreBodyOutcome = {
|
|
11114
11065
|
ok: true;
|
|
@@ -11511,7 +11462,7 @@ export { recordToolCheck, startToolTrace, toolSpanName };
|
|
|
11511
11462
|
`,"file:///node_modules/@theoremjs/agents/src/kernel/engine/turn-trace.d.ts":`import type { GuardrailEvent, GuardrailStage, TrustLevel } from '../../guardrails/types.js';
|
|
11512
11463
|
import { type SpanHandle, type SpanLinkInput, type SpanOptions, type TraceAttributes, type TraceAttributeValue } from '../../observability/trace-span.js';
|
|
11513
11464
|
import type { ToolFailure } from '../tools/types.js';
|
|
11514
|
-
import type { InteractionPart, ModelBinding, ModelEvent, ModelRequest, ProviderTransport, TurnEvent, TurnRequest, TurnStop, TurnTokens, TurnTraceLink } from '../types.js';
|
|
11465
|
+
import type { InteractionPart, ModelBinding, ModelChoice, ModelEvent, ModelRequest, ProviderTransport, RunControls, TurnEvent, TurnRequest, TurnStop, TurnTokens, TurnTraceLink } from '../types.js';
|
|
11515
11466
|
import type { CallUsage } from './runner/usage.js';
|
|
11516
11467
|
type TracePart = {
|
|
11517
11468
|
[key: string]: TraceAttributeValue;
|
|
@@ -11611,6 +11562,10 @@ declare function startCallTrace(open: (name: string, options: SpanOptions) => Sp
|
|
|
11611
11562
|
attempt?: number;
|
|
11612
11563
|
}): CallTrace;
|
|
11613
11564
|
declare function traceLinks(links: readonly TurnTraceLink[] | undefined): SpanLinkInput[];
|
|
11565
|
+
/** What a run's request says about the run, on its root span. */
|
|
11566
|
+
declare function runIdentity(req: Pick<RunControls, 'conversationId' | 'projectId'>): TraceAttributes;
|
|
11567
|
+
/** The pick a run's request made; absent when it took the defaults. */
|
|
11568
|
+
declare function runChoice(req: ModelChoice): TraceAttributes;
|
|
11614
11569
|
declare function turnSpanOptions(req: TurnRequest): SpanOptions;
|
|
11615
11570
|
interface TurnEnd {
|
|
11616
11571
|
seen: readonly TurnEvent[];
|
|
@@ -11628,7 +11583,7 @@ interface TurnEnd {
|
|
|
11628
11583
|
*/
|
|
11629
11584
|
declare function endTurnSpan(root: SpanHandle, end: TurnEnd): void;
|
|
11630
11585
|
export type { CallEnd, CallTrace, GuardrailCheck, SentToolCall, StreamCheck, TracePart, TurnEnd };
|
|
11631
|
-
export { endThrownSpan, endTurnSpan, guardrailAttributes, guardrailCheckAttributes, OutputFold, optional, recordException, startCallTrace, toolArgumentsText, traceLinks, tracePart, turnSpanOptions, urlAttributes, usageAttributes, };
|
|
11586
|
+
export { endThrownSpan, endTurnSpan, guardrailAttributes, guardrailCheckAttributes, OutputFold, optional, recordException, runChoice, runIdentity, startCallTrace, toolArgumentsText, traceLinks, tracePart, turnSpanOptions, urlAttributes, usageAttributes, };
|
|
11632
11587
|
`,"file:///node_modules/@theoremjs/agents/src/kernel/engine/runner/usage.d.ts":`import type { ToolCallRequest } from '../../tools/types.js';
|
|
11633
11588
|
import type { InteractionPart, ModelEvent, ResolvedGeneration, TurnEventOf, TurnHistoryMessage, TurnTokens } from '../../types.js';
|
|
11634
11589
|
import { type TokenCount } from '../token-estimate.js';
|
|
@@ -11936,15 +11891,10 @@ export { isModelProfile, pickModel, projectProfileInRegistry, projectProfileObje
|
|
|
11936
11891
|
`,"file:///node_modules/@theoremjs/agents/src/kernel/engine/session/mod.d.ts":`import type { TraceSink } from '../../../observability/trace-sink.js';
|
|
11937
11892
|
import type { ProviderHostOptions } from '../../protocols/runtime.js';
|
|
11938
11893
|
import type { KernelRegistry } from '../../registry/kernel-registry.js';
|
|
11939
|
-
import { type ToolBackgroundService } from '../../tools/background.js';
|
|
11940
|
-
import { type PageToolExecution, type ToolExecutionCoordinator } from '../../tools/operation.js';
|
|
11941
11894
|
import type { KeyVault, LiveSession, SessionRequest } from '../../types.js';
|
|
11942
11895
|
export type { LiveSession, SessionRequest };
|
|
11943
11896
|
/** Options for opening a live session: the key vault, a provider's own settings, a WebSocket opener, how long a gated call waits for its decision, and the sign-in gate policy. */
|
|
11944
11897
|
export interface RunSessionOptions extends ProviderHostOptions {
|
|
11945
|
-
execution?: ToolExecutionCoordinator;
|
|
11946
|
-
background?: ToolBackgroundService;
|
|
11947
|
-
pageExecution?: PageToolExecution;
|
|
11948
11898
|
/** The host's keys by slot; the session uses the slots its profile names. */
|
|
11949
11899
|
vault?: KeyVault;
|
|
11950
11900
|
/**
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{A as e,D as t,E as n,O as r,T as i,b as a,c as o,d as s,f as c,x as l}from"./schemas-D7cgkv3L.js";import{Ct as u,Et as ee,Gn as te,H as ne,Sn as d,Un as re,Vn as ie,Wt as ae,Yt as oe,bn as f,cn as se,dn as ce,er as le,ln as ue,wn as p,wt as de,xn as fe,yn as pe}from"./tool-schema-C7lMQU0w.js";import{c as m}from"./host-patterns-F-KZIzkF.js";import{A as me,Lr as h,Mn as he,Nn as ge,Nr as _e,Rr as ve,Un as ye,an as be,er as xe,fn as Se,jn as Ce,lr as g,pn as we,tn as _,tr as Te,vn as v,vr as Ee,wr as De}from"./shaped-data-BRffby3g.js";import{a as Oe,n as ke}from"./live-ingress-OuSlQ6q7.js";var Ae=2,je=4,Me=3,Ne=/(^|,)(\s*)("?)(?:([=@])|([+-])(?![0-9."]))/gm,Pe=/^[A-Za-z0-9+/]*={0,2}$/,Fe=new Set([`text/csv`,`text/plain`,`text/markdown`]);function y(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 Ie(e,t){if(t.limitsByMime){let n=p(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 b(e){return`uri`in e}function Le(e){if(e.type===`speech`)throw new m(`request`,`Profile ${e.id} (speech) does not accept media input`);if(e.type===`live`)throw new m(`request`,`Profile ${e.id} (live) does not accept turn attachment input`);if(e.type===`host`||e.type===`decision`||e.type===`embedding`)throw new m(`request`,`Profile ${e.id} (${e.type}) does not accept turn input`);let t=y(e.inputs??{});if(!t)throw new m(`config`,`Profile ${e.id} must set maxFiles, maxBytes, and maxTurnBytes`);return t}function Re(e){let t=0;return e.endsWith(`==`)?t=Ae:e.endsWith(`=`)&&(t=1),Math.floor(e.length*Me/je)-t}function ze(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return new TextDecoder(`latin1`).decode(e)}}function Be(e){return e.replace(Ne,(e,...t)=>{let[n,r,i,a,o]=t;return`${n}${r}${i}'${a??``}${o??``}`})}function Ve(e,t,n){let r=ze(t);return e===`text/csv`&&(r=Be(r)),new TextEncoder().encode(n.read(r))}function x(e,t){return t?{...e,fileName:t}:e}function S(e,t,n){return t.filter(t=>!f(e,t.mimeType)).map(e=>x({code:`mime_not_allowed`,params:{mimeType:e.mimeType,channel:n}},e.name))}function He(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=Ie(i.mimeType,t);i.sizeBytes>e&&n.push(x({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 C(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(...S(e.attachments,t,`attachment`)),e.voice&&r.push(...S(e.voice,n,`voice`)),e.limits?[...r,...He([...t,...n],e.limits)]:[...r,{code:`limits_unconfigured`}])}var Ue={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 w(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:Ue[e.code],params:t}}function We(e,t){let n=w(e);return h(n.key,n.params,t)}function Ge(e){return new m(`input`,`attachments refused: ${e.map(e=>e.code).join(`, `)}`,{copy:e.map(w)})}function Ke(e){if(!Pe.test(e))throw new m(`request`,`attachment data must be base64`);return Re(e)}function qe(e){let t={mimeType:e.mimeType,name:e.name};return b(e)||(t.sizeBytes=Ke(e.data)),t}function Je(e,t,n){if(!Xe(t,n))return;let r=Le(e),i=C({attachments:fe(e,`attachments`),voice:fe(e,`voice`),limits:r},(t??[]).map(qe),(n??[]).map(qe));if(i.length>0)throw Ge(i)}function Ye(e,t){if(b(e))return e;let{mimeType:n,data:r}=e;if(!Fe.has(p(n)))return e;let i=Ve(n,xe(r),t);return{...e,data:Te(i)}}function Xe(e,t){return(e?.length??0)>0||(t?.length??0)>0}function Ze(e,t,n,r){return Je(e,t,n),{attachments:t?.length?t.map(e=>Ye(e,r.attachment)):t,voice:n?.length?n.map(e=>Ye(e,r.voice)):n}}var Qe=`
|
|
2
|
+
|
|
3
|
+
`;function $e(e){if(typeof e==`string`)return;if(typeof e!=`object`||!e||Array.isArray(e))return`must be a string or { private: string }`;let t=Object.keys(e);if(t.length!==1||t[0]!==`private`)return`must have exactly one key, private`;let n=e.private;if(typeof n!=`string`)return`must be a string`;if(n===``)return`must not be empty`}function et(e,t){if(typeof e!=`string`){if(!Array.isArray(e))return`${t} must be a string or an array of parts`;if(e.length===0)return`${t} must not be an empty array`;for(let[n,r]of e.entries()){let e=$e(r);if(e)return`${t}[${n}]${typeof r==`object`&&r&&`private`in r?`.private`:``} ${e}`}}}function tt(e,t){let n=et(e,t);if(n)throw new m(`config`,n)}function nt(e,t,n){return tt(e,t),typeof e==`string`?n(e):e.map(e=>typeof e==`string`?n(e):{private:n(e.private)})}function rt(e){if(typeof e==`string`)return[{text:e,private:!0}];let t=e.some(e=>typeof e!=`string`);return e.map(e=>typeof e==`string`?{text:e,private:!t}:{text:e.private,private:!0})}function it(e){let t=[];for(let n of e)n.some(e=>e.text)&&(t.length>0&&t.push({text:Qe,private:!0}),t.push(...n));return t}function at(e){return e.map(e=>e.text).join(``)}function ot(e){let t=[],n=``;for(let r of e)r.private?n+=r.text:(n.trim()&&t.push(n),n=``);return n.trim()&&t.push(n),{text:at(e),private:t}}function st(e,t){return ot(it([e,...t.map(e=>e?[{text:e,private:!0}]:[])]))}function T(e){let t=Object.keys(e);return t.length===1?t[0]:void 0}var ct=/^[A-Za-z_][\w-]*$/,lt=/^\S+$/;function ut(e){return typeof e==`string`?[[e]]:e.map(e=>typeof e==`string`?[e]:e)}function dt(e){return typeof e==`string`?e:e.private}function E(e){return ee(e[0]===void 0?``:dt(e[0]))}function ft(e,t){let n={};for(let[r,i]of Object.entries({...e,...t}))n[r]={type:`string`,enum:[...i]};return{type:`object`,properties:n}}function pt(e,t){for(let[n,r]of Object.entries(e??{})){if(!ct.test(n))return`Condition "${n}" needs a plain name.`;if(n===`input`||n===`output`)return`Condition "${n}" is a reserved name.`;if(Object.hasOwn(t,n))return`"${n}" is both a condition and a slot.`;if(r.length===0)return`Condition "${n}" lists no values.`;let e=r.find(e=>!lt.test(e)||e===`null`);if(e!==void 0)return`Condition "${n}" can't take the value "${e}".`}}function mt(e,t){if(e.length===0)return`It has no wording to send.`;let n=E(e);if(n.joined)return`A prompt line can't start with "+"; every line that fits is sent.`;if(n.when===`unreadable`)return`A line that opens with "when" needs a condition and a colon, like "when path is web: …".`;for(let e of n.when){if(e.path.includes(`.`))return`"${e.path}" isn't one condition or slot.`;if(e.expected===null)return`A condition always has a value, so "is null" never fits.`;let n=de(e,t,`this profile’s conditions or slots`);if(n)return n}if(n.when.length>0&&!n.text&&e.length===1)return`It has no wording to send.`}function D(e,t,n){let r=pt(t,n);if(r)return r;let i=ft(t,n);for(let[t,n]of ut(e).entries()){let e=mt(n,i);if(e)return`Line ${t+1}: ${e}`}}function ht(e,t,n,r){let i=n.conditions??{};if(t===void 0){if(n.conditions)throw new m(`request`,`Profile ${e} declares no conditions`);return{...r}}if(Object.hasOwn(i,`path`))throw new m(`request`,`Profile ${e}: the turn's own path states path`);for(let n of Object.keys(i))if(!Object.hasOwn(t,n))throw new m(`request`,`Profile ${e} has no condition '${n}'`);let a={...r};for(let[r,o]of Object.entries(t)){let t=r===`path`?n.path:i[r];if(t===void 0)throw new m(`request`,`Profile ${e}: the turn left condition '${r}' unset`);if(!o.includes(t))throw new m(`request`,`Profile ${e}: '${t}' is no value of condition '${r}'`);a[r]=t}return a}function gt(e,t){return e.when!==`unreadable`&&e.when.every(e=>u(e,t))}function _t(e,t,n){let r=ut(e),i=r.flat().some(e=>typeof e!=`string`),a=[];for(let[e,o]of r.entries()){let r=E(o);if(!gt(r,t))continue;let s=[];for(let[e,t]of o.entries()){let a=n(e===0?r.text:dt(t));a&&s.push({text:a,private:typeof t!=`string`||!i})}a.push({line:e+1,pieces:s})}return a}function vt(e,t){if(typeof e!=`string`){if(!Array.isArray(e))throw new m(`config`,`${t} must be a string or an array of lines`);if(e.length===0)throw new m(`config`,`${t} must not be an empty array`);for(let[n,r]of e.entries())if(typeof r!=`string`){if(!Array.isArray(r))throw new m(`config`,`${t}[${n}] must be a string or a list of parts; put { private } inside the list`);tt(r,`${t}[${n}]`)}}}function yt(e,t){let n=e?.path;if(n)for(let e of t){let t=e.paths?.find(e=>e!==`*`&&!n.includes(e));if(t!==void 0)return`Tool ${e.name} lists path "${t}", which is not one of ${n.join(`, `)}.`}}function O(e,t){let n=e.get(t);return n!==void 0&&n.type!==`builtin`}function k(e,t){return!e||e.includes(`*`)?!0:t?e.includes(t):!1}function bt(e,t){return t.filter(n=>{let r=e.get(n);return r?.type!==`builtin`||!(r.conflictsWith??[]).some(e=>t.includes(e))})}function A(e){return`tools`in e?e.tools.allow:[]}function j(e){return e.type===`text`||e.type===`image`?e.tools:void 0}function xt(e){return`tools`in e?e.tools.parallel:void 0}function St(e,t,n){return A(t).filter(r=>{let i=e.get(r);return!i||i.type===`builtin`?!1:t.type===`host`||k(i.paths,n.path)})}function Ct(e,t,n,r){let i=t.models[r];return i?(i.builtInTools??[]).filter(t=>{let r=e.get(t);return r?.type===`builtin`&&k(r.paths,n.path)}):[]}function M(e,t,n){let r=e.get(t);if(r&&r.type!==`builtin`)return{type:`function`,name:r.name,description:r.description,parameters:n&&r.askInputSchema||r.inputSchema}}function wt(e,t,n){let r=[];for(let i of t){let t=M(e,i,n);t&&r.push(t)}return r}function N(e,t,n){if(t.visible.includes(n))return;t.visible.push(n);let r=M(e,n,t.modelBackground);r&&!t.wire.some(e=>e.name===n)&&t.wire.push(r)}function Tt(e,t,n){if(t.builtins.includes(n))return;let r=e.get(n);if(r?.type!==`builtin`)return;let i=r.conflictsWith??[];t.builtins=t.builtins.filter(t=>{if(i.includes(t))return!1;let r=e.get(t);return!(r?.type===`builtin`&&r.conflictsWith?.includes(n))}),t.builtins.push(n)}function Et(e,t,n){return t.type===`live`||t.type===`host`?[...n]:n.filter(t=>e.get(t)?.loadTier===`T0`)}function Dt(e,t,n){return bt(e,n.filter(n=>{let r=e.get(n);return r?.type===`builtin`&&(t.type===`live`||r.loadTier===`T0`)}))}function Ot(e,t){if(t.type!==`text`&&t.type!==`image`&&t.type!==`live`)return;let n=A(t).flatMap(t=>e.get(t)??[]),r=yt(t.identity.conditions,n);if(r)throw new m(`config`,`Profile ${t.id}: ${r}`)}function kt(e,t){let n=j(t)?.t2Loader,r=n===void 0?void 0:e.get(n);if(r&&r.type!==`builtin`&&(r.background??`never`)!==`never`)throw new m(`config`,`Profile ${t.id}: tools.t2Loader '${r.name}' sets background, and a loader cannot detach`)}function P(e,t,n,r){Ot(e,t),kt(e,t);let i=St(e,t,n),a=t.type===`host`||t.type===`decision`||t.type===`embedding`||r===void 0?[]:Ct(e,t,n,r),o=[...i,...a],s=Dt(e,t,o),c=Et(e,t,o),l=c.filter(t=>O(e,t)),u=n.background!==void 0;return{builtins:s,gated:o,visible:c,executable:l,path:n.path,sessionPermissions:n.sessionPermissions,wire:wt(e,c,u),...u?{modelBackground:u}:{}}}async function At(e,t,n,r){let i=P(e,t,n,r);return await F(e,i,t,n),i}function jt(e){return{builtins:[...e.builtins],gated:[...e.gated],visible:[...e.visible],executable:[...e.executable],path:e.path,sessionPermissions:e.sessionPermissions?[...e.sessionPermissions]:void 0,wire:e.wire.map(e=>({...e,parameters:structuredClone(e.parameters)})),...e.modelBackground?{modelBackground:e.modelBackground}:{}}}async function F(e,t,n,r){let i=j(n)?.t1Policy;if(!i)return;let a;try{a=await i({profile:n,input:r.input,path:r.path,sessionPermissions:r.sessionPermissions,gated:t.gated,host:r.host})}catch(e){let t=e instanceof Error?e.message:String(e);throw new m(`config`,`Profile '${n.id}' tools.t1Policy rejected: ${t}`,{cause:e})}if(!Array.isArray(a))throw new m(`config`,`Profile '${n.id}' tools.t1Policy must return ToolId[]`);I(e,t,a)}function I(e,t,n=[]){for(let r of n){if(!t.gated.includes(r))continue;let n=e.get(r);n?.loadTier===`T2`&&(n.type===`builtin`?Tt(e,t,r):N(e,t,r))}t.executable=t.visible.filter(t=>O(e,t))}var Mt=new Set([`__proto__`,`constructor`,`prototype`]);function Nt(e){if(!me(e))return;let{loaded:t}=e;if(Array.isArray(t)&&t.every(e=>typeof e==`string`))return t}function Pt(e,t,n,r){if(r.type===`live`||r.type===`host`)return{promoted:[]};let i=[];for(let a of n){if(typeof a!=`string`||Mt.has(a))return{promoted:[],failure:{code:`invalid_output`,kind:`bad_response`,message:`tools.t2Loader loaded ids must be plain strings`}};let n=Ft(e,a,r);if(`failure`in n)return{promoted:[],failure:n.failure};let{tool:o}=n;k(o.paths,t.path)&&t.gated.includes(a)&&i.push(a)}let a=[];for(let n of i)N(e,t,n),a.push(n);return t.executable=t.visible.filter(t=>O(e,t)),{promoted:a}}function L(e){return{failure:{code:`invalid_output`,kind:`bad_response`,message:e}}}function Ft(e,t,n){if(!A(n).includes(t))return L(`tools.t2Loader attempted to promote tool '${t}' outside profile allow`);let r=e.get(t);return r?r.type===`builtin`?L(`tools.t2Loader attempted to promote builtin '${t}' — only custom tools may be promoted`):r.loadTier===`T2`?{tool:r}:L(`tools.t2Loader attempted to promote tool '${t}' with loadTier '${r.loadTier}' — only T2 tools may be promoted`):L(`tools.t2Loader attempted to promote unknown tool '${t}'`)}function R(e){return Array.isArray(e)?[...e]:e.choices.map(e=>e.value)}function It(e){return Array.isArray(e)?{choices:e.map(e=>({value:e}))}:{...e.label!==void 0&&e.label!==``?{label:e.label}:{},choices:e.choices.map(e=>({value:e.value,...e.description!==void 0&&e.description!==``?{description:e.description}:{}}))}}function z(e){if(e)return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,It(t)]))}function B(e){return e?.slots?{...e,slots:z(e.slots)}:e}function V(e){return e==null}function H(e){return V(e)||typeof e!=`object`||Array.isArray(e)?null:e}function U(e){let t=H(e);return!t||t.type!==void 0&&t.type!==`object`?null:t}function W(e){let t=e.required;return Array.isArray(t)?t.filter(e=>typeof e==`string`):[]}function G(e){let t=e.properties;return H(t)??{}}function Lt(e,t){return e?`${e}.${t}`:t}function Rt(e,t){t.push({path:e,error:`required field '${e}' is missing`})}async function zt(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 Bt(e){let{path:t,propSchema:n,child:r,isRequired:i,fields:a,slots:o,failures:s}=e;if(V(r)){i&&Rt(t,s);return}await zt(t,r,a?.[t],o,s);let c=U(n),l=c?H(r):null;c&&l&&await Vt(c,l,t,a,o,s)}async function Vt(e,t,n,r,i,a){let o=G(e),s=new Set(W(e)),c=new Set([...Object.keys(o),...s]),l=H(t);for(let e of c)await Bt({path:Lt(n,e),propSchema:o[e],child:l?.[e],isRequired:s.has(e),fields:r,slots:i,failures:a})}async function Ht(e,t,n,r){let i=U(e);if(!i)throw new m(`config`,`structured validation requires a JSON Schema object root`);let a=[];if(!H(t)){for(let e of W(i))Rt(e,a);return a}return await Vt(i,t,``,n,r,a),a}function Ut(e,t){let n=e;for(let e of t.split(`.`)){let t=U(n);if(!t)return!1;let r=G(t);if(!Object.hasOwn(r,e)&&!W(t).includes(e))return!1;n=r[e]}return!0}function Wt(e){return e.map(e=>e.error).join(`; `)}function Gt(e,t){let n=e;for(let e of t.split(`.`))n=H(n)?.[e];return n}function Kt(e,t,n){let[r,...i]=t.split(`.`),a=H(e)??{};return r===void 0?e:{...a,[r]:i.length?Kt(a[r],i.join(`.`),n):n}}async function qt(e,t,n){let r=[];for(let[i,a]of Object.entries(t??{})){let t=Gt(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 Jt(e,t){let n=e;for(let e of t.split(`.`)){let t=U(n);if(!t)return;n=G(t)[e]}let r=H(n);if(r?.type===`array`)return H(r.items)??void 0}var Yt=class extends Error{failure;constructor(e){super(e.message),this.failure=e}},Xt=new Set([`text`,`image`,`speech`]),Zt=n().regex(/\S/),Qt=i({mimeType:n(),data:c(),name:n().optional()}),$t=i({mimeType:n(),uri:n(),name:n().optional()}),en=i({voice:n().optional(),style:n().optional(),speed:a().positive().optional()});function tn(e){return i(Object.fromEntries(Object.entries(e).map(([e,t])=>{let n=R(t);return[e,o(n).optional()]})))}var nn=new Set([`text`,`attachments`,`voice`,`slots`,`speech`]);function rn(e,t){if(!e.hostFields)return{sent:t};let n={...t},r={};for(let t of Object.keys(e.hostFields))n[t]!==void 0&&(r[t]=n[t]);let{text:i,attachments:a,voice:o,slots:s,speech:c}=t;return{sent:{text:i,...a?{attachments:a}:{},...o?{voice:o}:{},...s?{slots:s}:{},...c?{speech:c}:{}},hostInput:r}}function an(e,n){let{inputs:r}=e,a={text:Zt};r?.attachments&&(a.attachments=s(t([Qt,$t])).optional()),r?.voice&&(a.voice=s(Qt).optional()),r?.slots&&(a.slots=tn(r.slots).optional()),e.type===`speech`&&(a.speech=en.optional());for(let e of n?.hostOnly??[]){if(!a[e])throw new m(`config`,`Tool '${n?.name}' keeps '${e}' for the host, which its profile does not take`);delete a[e]}for(let[e,t]of Object.entries(n?.fieldText??{})){let r=a[e];if(!r)throw new m(`config`,`Tool '${n?.name}' describes '${e}', which its profile does not take`);a[e]=r.describe(t)}for(let[e,t]of Object.entries(n?.hostFields??{})){if(nn.has(e))throw new m(`config`,`Tool '${n?.name}' declares the host field '${e}', which is a field of every agent tool`);a[e]=t}return i(a)}var on=l({text:n().optional(),structured:r().optional(),removed:s(l({path:n(),reason:n(),item:r()})).optional(),parts:s(ie).optional(),sources:s(te).optional()});function sn(e){return e.type===`speech`||(e.type===`text`||e.type===`image`)&&e.inputs.text!==!1}function cn(e){return e.type===`builtin`?!1:e.permission!==`auto`||`auth`in e&&e.auth!==void 0&&(e.auth.onUnauthenticated??`gate`)===`gate`}function ln(e,t){if(!Xt.has(e.type))return`it is a ${e.type} profile; an agent tool runs a text, image, or speech profile`;if(!sn(e))return`it does not take text`;for(let n of A(e)){let e=t(n);if(!e)return`its tool '${n}' is not registered; register it first`;if(cn(e))return`its tool '${n}' can stop on a gate; give it permission 'auto' and no sign-in`}}function un(e,t,n){let r=`Agent tool "${e.name}"`,i=e.maxCallsPerTurn;if(i!==void 0&&!(Number.isInteger(i)&&i>0))throw new m(`config`,`${r}: maxCallsPerTurn must be a whole number above 0`);let a=t(e.profile);if(!a)throw new m(`config`,`${r}: profile '${e.profile}' must be registered before the tool`);let o=ln(a,n);if(o)throw new m(`config`,`${r} can't run '${e.profile}': ${o}`);return a}function dn(e){if(!e)return`delegated`;let t=`models`in e&&Object.values(e.models).some(e=>(e.builtInTools?.length??0)>0);return A(e).length===0&&!t?`local`:`delegated`}function fn(e){let t=re(e),n=t.flatMap(e=>e.type===`text`?[e.text]:[]).join(``),r=ae(t,e=>e.type===`structured`),i=r?.structured,a=t.flatMap(e=>e.type===`media`?[{type:e.media.mimeType.startsWith(`audio/`)?`audio`:`image`,mimeType:e.media.mimeType,data:e.media.data}]:[]),o=t.flatMap(e=>e.type===`citation`?e.sources:[]);return{...i===void 0?{text:n}:{structured:i},...r?.removed?.length?{removed:r.removed}:{},...a.length>0?{parts:a}:{},...o.length>0?{sources:o}:{}}}function pn(e,t,n){return{...e,type:`agent`,input:t,output:on,sources:e=>e.sources??[],...n}}function mn(e,t,n){if(!e||typeof e!=`object`||Array.isArray(e))return n.push(`${t}: schema must be an object`),!1;let r=typeof e.type==`string`||Array.isArray(e.type),i=e.anyOf!==void 0||e.oneOf!==void 0;if(!r&&!i){if(t!==`$`)return!0;n.push(`${t}: missing type or combinator`)}return e.type===`array`&&e.items===void 0&&n.push(`${t}: array schema must define items`),!0}function hn(e,t,n,r){let i=Array.isArray(t)?t:[];for(let t of i)typeof t==`string`&&!Object.hasOwn(e,t)&&r.push(`${n}: required key '${t}' missing from properties`);for(let[t,i]of Object.entries(e))i&&typeof i==`object`&&K(i,`${n}.properties.${t}`,r)}function K(e,t,n){if(!mn(e,t,n))return;let r=e.properties;r&&typeof r==`object`&&!Array.isArray(r)&&hn(r,e.required,t,n),e.items&&typeof e.items==`object`&&!Array.isArray(e.items)&&K(e.items,`${t}.items`,n);for(let r of[`anyOf`,`oneOf`]){let i=e[r];Array.isArray(i)&&i.forEach((e,i)=>{e&&typeof e==`object`&&K(e,`${t}.${r}[${i}]`,n)})}}function gn(e,t){let n=[];if(K(e,`$`,n),n.length>0)throw new m(`config`,`Invalid tool ${t} schema: ${n.join(`; `)}`)}function _n(t,n=`output`){let r=e(t,{target:`draft-7`,io:n});return delete r.$schema,r.type||=`object`,r}function q(e){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(q);let t={};for(let n of Object.keys(e))n!==`__proto__`&&n!==`constructor`&&n!==`prototype`&&(t[n]=q(e[n]));return t}function vn(e){let t=/^[a-z][a-z0-9+.-]*:\/\/[^/?#]*/i.exec(e)?.[0];if(!t||/[{}]/.test(t))throw new m(`config`,`Endpoint "${e}" must start with a fixed scheme and host; placeholders belong in the path or query`)}function yn(e,t,n,r){if(!n.provider?.trim()||!n.apiId?.trim())throw new m(`config`,h(`provider.binding_identity`))}function bn(e){J(e.id,e.models),Q(e.id,e.observability),hr(e.id,e.inputs);for(let[t,n]of Object.entries(e.models))Y(e.id,t,n);return{type:`embedding`,id:e.id,identity:{handle:e.identity.handle},models:e.models,defaultModel:An(e.id,e),allowModelSelect:e.allowModelSelect,inputs:e.inputs,guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function xn(e){J(e.id,e.models),Z(e.id,e.guardrails),Q(e.id,e.observability);for(let[t,n]of Object.entries(e.models))Y(e.id,t,n);if(`text`in e.inputs&&e.inputs.text!==!1)throw new m(`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},...Mn(e),providerContinuation:void 0,maxSteps:void 0,inputs:{...e.inputs,text:!1},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function Sn(e,t,n,r){let i=r.safeParse(n);if(!i.success)throw new m(`config`,`Profile ${e} model '${t}': ${i.error.issues.map(e=>`${e.path.join(`.`)}: ${e.message}`).join(`; `)}`)}function Cn(e,t,n){if(Sn(e,t,n,ue),yn(e,t,n,`decision`),`retry`in n)throw new m(`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 m(`config`,`Profile ${e} model '${t}' timeoutMs must be > 0`)}function wn(e){let t=e.models?T(e.models):void 0;if(!t)throw new m(`config`,`Profile ${e.id}: type 'decision' must declare exactly one model`);Cn(e.id,t,e.models[t])}function Tn(e){if(e.inputs.state!==`json`)throw new m(`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 m(`config`,`Profile ${e.id}: decision inputs.maxStateBytes must be a positive integer`);if(!e.decision.contract.trim())throw new m(`config`,`Profile ${e.id}: decision.contract must be non-empty`)}function En(e){return wn(e),Tn(e),Q(e.id,e.observability),{...e,identity:{handle:e.identity.handle}}}function Dn(e){return e===void 0?{}:{parallel:e}}function On(e){return kn(e.id,e.tools),Q(e.id,e.observability),{type:`host`,id:e.id,tools:{allow:e.tools.allow,...Dn(e.tools.parallel)},guardrails:e.guardrails,observability:e.observability,labels:e.labels}}function kn(e,t){if(!Array.isArray(t.allow))throw new m(`config`,`Profile ${e}: type 'host' must set tools.allow`)}function J(e,t){if(Object.keys(t).length===0)throw new m(`config`,`Profile ${e} must declare at least one model`)}function An(e,t){let n=t.defaultModel??T(t.models);if(!n)throw new m(`config`,`Profile ${e} must set defaultModel when more than one model is declared`);if(!t.models[n])throw new m(`config`,`Profile ${e} defaultModel '${n}' is not declared`);return n}function Y(e,t,n){jn(e,t,n),Sn(e,t,n,ce),jn(e,t,n)}function jn(e,t,n){let r=n.efforts;if(!r||Object.keys(r).length===0){if(n.defaultEffort||n.allowEffortSelect)throw new m(`config`,`Profile ${e} model '${t}': defaultEffort and allowEffortSelect require efforts`);return}for(let[n,i]of Object.entries(r))if(!v.includes(i))throw new m(`config`,`Profile ${e} model '${t}' effort '${n}': '${i}' is not a thinking level (${v.join(`, `)})`);let i=Object.keys(r),a=n.defaultEffort??(i.length===1?i[0]:void 0);if(!a)throw new m(`config`,`Profile ${e} model '${t}' must set defaultEffort when more than one effort is declared`);if(!r[a])throw new m(`config`,`Profile ${e} model '${t}' defaultEffort '${a}' is not declared`);if(n.allowEffortSelect&&i.length<2)throw new m(`config`,`Profile ${e} model '${t}' allowEffortSelect requires at least two efforts`)}function Mn(e){return{providerContinuation:e.providerContinuation?le.parse(e.providerContinuation):{},models:e.models,defaultModel:An(e.id,e),allowModelSelect:e.allowModelSelect,maxSteps:e.maxSteps}}function Nn(e,t,n){if(n?.length){for(let r of n)if(!oe(r))throw new m(`config`,`Profile ${e}: turnBehaviour.resumption.${t} may only include ContinueStopKind (length | stream_incomplete | provider_error); got '${r}'`)}}function Pn(e,t){t&&(Nn(e,`allowContinue`,t.allowContinue),Nn(e,`autoContinue`,t.autoContinue))}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Fn(e,t){let n=[e];for(let e of t)n=n.flatMap(t=>X(t)?e===`*`?Object.values(t):[t[e]]:[]);return n}var In=Object.entries(Se).filter(([,e])=>e.required===!0).map(([e,t])=>[e,t.profileTypes]).sort(([e],[t])=>e.split(`.`).length-t.split(`.`).length);function Ln(e){if(!X(e))throw new m(`config`,`Profile definition must be an object`);let t=typeof e.id==`string`&&e.id.trim()?e.id:void 0;if(!t)throw new m(`config`,`Profile definition must set id`);if(!we.find(t=>t===e.type))throw new m(`config`,`Profile ${t}: type must be one of ${we.join(`, `)}`)}function Rn(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 m(`config`,`Profile ${e.id.slice(0,64)}: ${t} must be at most ${i} characters`)}function zn(e){let{id:t,type:n}=e,r=e;for(let[e,i]of In){if(i&&!i.includes(n))continue;let a=he(e),o=Fn(r,a.slice(0,-1)),s=a[a.length-1];if(o.some(e=>{if(!X(e))return!1;let t=e[s];return t==null||t===``}))throw new m(`config`,`Profile ${t}: type '${n}' must set ${a.join(`.`)}`)}}function Bn(e){let{id:t,type:n}=e;if(n!==`live`&&ge(`inputs`).includes(n)&&e.inputs==null)throw new m(`config`,`Profile ${t}: type '${n}' must set inputs`)}function Vn(e){let[t]=Ce(e);if(!t)return;let{offValue:n,reason:r}=t.scope,i=n===void 0?``:` (other than ${n})`;throw new m(`config`,`Profile ${e.id}: type '${e.type}' must not set ${t.path}${i} — ${r}`)}function Hn(e,t){let n=t.turnBehaviour;Pn(e,n?.resumption)}function Un(e,t){let n=t=>new m(`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 Z(e,t){let n=t=>new m(`config`,`Profile ${e}: ${t}`),r=Object.keys(t??{}).find(e=>!Wn.includes(e));if(r!==void 0)throw n(`guardrails.${r} is not a setting; it takes ${Wn.join(`, `)}`);Kn(t?.blockedReply,n)}var Wn=[`quota`,`detect`,`blockedReply`,`network`,`taint`],Gn=[`onBlock`,`maxRetries`];function Kn(e,t){if(e===void 0)return;let n=Object.keys(e).find(e=>!Gn.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&&!g.includes(r))throw t(`guardrails.blockedReply.onBlock must be one of ${g.join(`, `)}`);if(i!==void 0&&(!Number.isInteger(i)||i<0))throw t(`guardrails.blockedReply.maxRetries must be a non-negative integer`)}function qn(e){let t=e.guardrails?.detect,n=e.type===`host`?ye(`guardrails.detect`,t,Ee):ye(`guardrails.detect`,t);if(n!==void 0)throw new m(`config`,`Profile ${e.id}: ${n}`)}function Q(e,t){try{let n=Oe(t);if(!Number.isFinite(n.retainForDays))throw new m(`config`,`Profile ${e}: observability.retainForDays must be a finite number`);if(n.rotateAfterMiB<=0||!Number.isFinite(n.rotateAfterMiB))throw new m(`config`,`Profile ${e}: observability.rotateAfterMiB must be a positive number`)}catch(t){if(t instanceof m&&t.message.startsWith(`Profile `))throw t;let n=t instanceof Error?t.message:String(t);throw new m(De(t),`Profile ${e}: ${n}`,{cause:t})}}function Jn(e){if(e.type===`host`||e.type===`decision`||e.type===`speech`||e.type===`transcription`||e.type===`embedding`)return;let{conditions:t,system:n}=e.identity,r={};for(let[t,n]of Object.entries(B(e.inputs)?.slots??{}))r[t]=R(n);let i=n??``;vt(i,`Profile ${e.id} identity.system`);let a=D(i,t,r);if(a)throw new m(`config`,`Profile ${e.id} identity.system: ${a}`)}function Yn(e){Ln(e);for(let t of[`key`,`fallbackKey`,`protocol`,`provider`])if(t in e)throw new m(`config`,h(`provider.profile_configuration`,{profile:e.id,field:t}));Vn(e),Bn(e),zn(e),Rn(e),e.labels&&ve(e.labels,`Profile ${e.id}`);for(let t of _e)if(e.labels?.[t]!==void 0)throw new m(`config`,`Profile ${e.id}: labels '${t}' is a host line, which a profile cannot change; set it with overrideLabels`);if(Jn(e),qn(e),e.type===`host`)return On(e);if(e.type===`decision`)return En(e);if(e.type===`embedding`)return bn(e);if(e.type===`transcription`)return xn(e);J(e.id,e.models),Hn(e.id,e),Z(e.id,e.guardrails),e.type===`text`&&Un(e.id,e.outputs?.validation),Q(e.id,e.observability);for(let[t,n]of Object.entries(e.models))Y(e.id,t,n);let t=e.type===`speech`?{handle:e.identity.handle}:{handle:e.identity.handle,conditions:e.identity.conditions,system:e.identity.system},n=e.guardrails,r=e.observability,i=e.labels,a=Mn(e),o;switch(e.type){case`text`:o={type:`text`,id:e.id,identity:t,...a,tools:e.tools,inputs:B(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:B(e.inputs),outputs:e.outputs,turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},tr(o.id,o.inputs.attachments?.accept),er(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?B(e.inputs):e.inputs,tools:{allow:e.tools.allow,...Dn(e.tools.parallel)},turnBehaviour:e.turnBehaviour,guardrails:n,observability:r,labels:i},ke(o),rr(o.id,o.live.contextCompression),nr(o);break;default:throw new m(`config`,`Unknown profile type '${String(e)}'`)}return Qn(o),Xn(o),Zn(o),o}function Xn(e){let{maxSteps:t}=e;if(!(t===void 0||Number.isInteger(t)&&t>0))throw new m(`config`,`Profile ${e.id}: maxSteps must be a whole number of 1 or more; leave it out for the default of 20`)}function Zn(e){if(e.type===`text`&&e.turnBehaviour?.atStepLimit===`answer`&&e.maxSteps===1)throw new m(`config`,`Profile ${e.id}: turnBehaviour.atStepLimit 'answer' with maxSteps 1 leaves no step that can call a tool`)}function Qn(e){if(e.type===`live`)return;let t=e.outputs?.structured;if(!t||typeof t==`string`)return;let n=d(e)?.slots?.[t.by];if(!n)throw new m(`config`,`Profile ${e.id}: outputs.structured.by '${t.by}' is not a slot in inputs.slots`);let r=R(n),i=Object.keys(t.map).filter(e=>!r.includes(e));if(i.length)throw new m(`config`,`Profile ${e.id}: outputs.structured.map maps ${i.join(`, `)}, not a choice of slot '${t.by}'`)}var $n={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 er(e,t){for(let[n,{ok:r,rule:i}]of Object.entries($n)){let a=t[n];if(a!==void 0&&!r(a))throw new m(`config`,`Profile ${e}: image.${n} must be ${i}`)}t.references?.forEach((t,n)=>{let r=`Profile ${e}: image.references[${n}]`;if(pe(t.mimeType)!==`image`)throw new m(`config`,`${r} must be an image, not '${t.mimeType}'`);if(!(b(t)?t.uri:t.data))throw new m(`config`,`${r} needs its bytes or its uri`)})}function tr(e,t){let n=t?.filter(e=>!f(be,e));if(n?.length)throw new m(`config`,`Profile ${e}: an image profile's attachments take images, video, and PDF only, not ${n.join(`, `)}`)}function nr(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 m(`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 m(`config`,`${i}.resumed.prompt must be a prompt`);let{afterMs:a}=n;if(a!==void 0&&!(Number.isFinite(a)&&a>=0))throw new m(`config`,`${i}.resumed.afterMs must be 0 or more milliseconds`);if(!r)throw new m(`config`,`${i}.resumed needs live.sessionResumption: without it no call resumes`)}function rr(e,t){if(!t)return;let n=`Profile ${e} live.contextCompression`,r=t.triggerTokens,i=t.slidingWindow.targetTokens;if(ir(`${n}.triggerTokens`,r),ir(`${n}.slidingWindow.targetTokens`,i),r!==void 0&&i!==void 0&&i>=r)throw new m(`config`,`${n}: slidingWindow.targetTokens must be below triggerTokens`)}function ir(e,t){if(!(t===void 0||Number.isInteger(t)&&t>0))throw new m(`config`,`${e} must be a whole number above 0`)}function ar(e,t,n,r){let i=`Profile ${t.id} model ${n} compaction`;if(or(i,r),sr(i,r),r.meter!=null&&r.meter!==`history`&&r.meter!==`input`)throw new m(`config`,`${i}: meter must be 'history' or 'input'`);if(r.profile===void 0){if(t.type!==`text`||t.inputs.text===!1)throw new m(`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 m(`config`,`${i}: compaction profile '${r.profile}' must be registered before '${t.id}'`);if(a.type!==`text`||a.inputs.text===!1)throw new m(`config`,`${i}: compaction profile '${r.profile}' must be a text profile that takes text`)}function or(e,t){if(t.maxTokens<=0)throw new m(`config`,`${e}: maxTokens must be > 0`);if(t.compactAt<=0||t.compactAt>=1)throw new m(`config`,`${e}: compactAt must be in (0, 1)`)}function sr(e,t){if(t.previousExchanges<0)throw new m(`config`,`${e}: previousExchanges must be >= 0`);if(t.previousExchanges<1&&t.previousExchanges>=t.compactAt)throw new m(`config`,`${e}: previousExchanges as fraction (${t.previousExchanges}) must be < compactAt (${t.compactAt})`);if(t.previousExchanges>1&&!Number.isInteger(t.previousExchanges))throw new m(`config`,`${e}: previousExchanges >= 1 must be an integer`)}function cr(e,t){for(let n of A(t))if(e.get(n)?.type===`builtin`)throw new m(`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 lr(e,t){let n=j(t)?.t2Loader;if(n){if(!A(t).includes(n))throw new m(`config`,`Profile ${t.id} tools.t2Loader '${n}' must also be listed in tools.allow`);if(e.get(n)?.type!==`function`)throw new m(`config`,`Profile ${t.id} tools.t2Loader '${n}' must be a registered type: 'function' tool`)}}function*ur(e){for(let[t,n]of Object.entries(e.models))for(let e of n.builtInTools??[])yield{modelId:t,id:e}}function dr(e,t){for(let{modelId:n,id:r}of ur(t))if(e.get(r)?.type!==`builtin`)throw new m(`config`,`Profile ${t.id} model '${n}' lists '${r}' in builtInTools — not a registered builtin`)}function fr(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 pr(e,t){let n=fr(t).map(n=>{let r=e.find(n);if(!r)throw new m(`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 m(`config`,`Profile ${t.id}: outputs.validation checks a structured reply, so it needs outputs.structured`);let o=a.filter(e=>!n.some(t=>Jt(t.jsonSchema,e)));if(o.length)throw new m(`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=>Ut(t.jsonSchema,e)));if(s.length)throw new m(`config`,`Profile ${t.id}: outputs.validation.fields has ${s.join(`, `)}, which no structured schema reaches through object properties`)}function mr(e){let t=d(e)?.context;if(!t)return;let n=_;if(t.from.length===0||t.from.some(e=>!n.includes(e)))throw new m(`config`,`Profile ${e.id}: inputs.context.from must list ${_.join(` or `)}`);if(!(Number.isInteger(t.maxChars)&&t.maxChars>0))throw new m(`config`,`Profile ${e.id}: inputs.context.maxChars must be a positive integer`)}function hr(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 m(`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 m(`config`,`Profile ${e}: inputs.${t} must be a positive integer`)}function gr(e,t,n){let r=new Map,i=i=>{let a=Yn(i),o=n&&a.type!==`host`?{...a,models:Object.fromEntries(Object.entries(a.models).map(([e,t])=>[e,se(n.require(t.provider,t.apiId),t,a.type)]))}:a;if(cr(e,o),lr(e,o),o.type!==`host`&&o.type!==`decision`&&o.type!==`embedding`){dr(e,o),hr(o.id,d(o)),mr(o),pr(t,o);for(let[e,t]of Object.entries(o.models))t.compaction&&ar(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 m(`config`,`Unknown profile '${e}'`);return t},find:e=>r.get(e),has:e=>r.has(e),list:()=>[...r.values()],clear:()=>r.clear()}}function _r(e){let t=e?.trim()??``;if(t.startsWith(`AIza`))return`gemini`;if(t.startsWith(`sk-or-`))return`openrouter`}function vr(e){let t;try{t=new URL(e.baseUrl)}catch{throw new m(`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 m(`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 m(`blocked`,`Local requests must stay on the configured origin.`))}}var yr=l({data:s(l({id:n().min(1)}))});async function br(e,t){let n=vr(e);if(!n?.fetch)throw new m(`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 m(`network`,`Local model list returned HTTP ${r.status}.`);let i=yr.safeParse(await r.json());if(!i.success)throw new m(`request`,`The endpoint returned an invalid model list.`);return[...new Set(i.data.data.map(e=>e.id))]}var xr=`https://openrouter.ai/api/v1/models`,Sr=`https://openrouter.ai/api/v1/embeddings/models`,Cr=[{id:`gemini-embedding-2-preview`,label:`Gemini Embeddings 2 (preview)`},{id:`gemini-embedding-001`,label:`Gemini Embedding 001`}],wr=[{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)`}],Tr={text:`text`,image:`image`,speech:`speech`,transcription:`transcription`,live:void 0,embedding:void 0},Er=l({data:s(l({id:n().min(1),name:n().optional(),architecture:l({output_modalities:s(n()).optional()}).optional()}))}),Dr=l({data:s(l({id:n().min(1),name:n().optional()}))}),Or=l({models:s(l({name:n().min(1),displayName:n().optional(),supportedGenerationMethods:s(n()).optional()})).optional(),nextPageToken:n().optional()}),kr=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 m(`auth`,`${e} refused the key.`);if(!r.ok)throw new m(`network`,`${e} model list returned HTTP ${r.status}.`);return await r.json()}async function Ar(e,t,n,r){let i=n?.trim();if(t===`embedding`&&!i)return[...e===`openrouter`?wr:Cr];if(e===`openrouter`)return await jr(t,i,r);if(!i)throw new m(`auth`,`Choose a key to list Gemini models.`);return await Nr(t,i,r)}async function jr(e,t,n){let r={signal:n,headers:{Accept:`application/json`,...t?{Authorization:[`Bearer`,t].join(` `)}:{}}};if(e===`embedding`){let e=Dr.safeParse(await $(`OpenRouter`,Sr,r));if(!e.success)throw new m(`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=Tr[e];if(!i)return[];let a=Er.safeParse(await $(`OpenRouter`,`${xr}?output_modalities=${i}`,r));if(!a.success)throw new m(`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 Mr={live:`bidiGenerateContent`,embedding:`embedContent`};async function Nr(e,t,n){let r=Mr[e]??`generateContent`,i=[],a;for(let e=0;e<kr;e++){let e=new URL(ne);e.searchParams.set(`pageSize`,`1000`),a&&e.searchParams.set(`pageToken`,a);let o=Or.safeParse(await $(`Google`,e.href,{signal:n,headers:{Accept:`application/json`,"x-goog-api-key":t}}));if(!o.success)throw new m(`bad_response`,`Google returned an invalid model list.`);for(let e of o.data.models??[]){if(!e.supportedGenerationMethods?.includes(r))continue;let t=e.name.replace(/^models\//,``);i.push({id:t,label:e.displayName??t})}if(a=o.data.nextPageToken,!a)break}return i}function Pr(e){return[...new Set([e.key,e.fallbackKey,...Object.values(e.models??{}).flatMap(e=>[e.keySlot,e.fallbackKeySlot])].filter(e=>!!e))]}function Fr(e,t){return Object.fromEntries(e.map(e=>[e,Object.hasOwn(t,e)?t[e]:void 0]))}export{y as $,jt as A,_t as B,Ht as C,Kt as D,Gt as E,xt as F,it as G,ht as H,j as I,We as J,nt as K,Pt as L,Nt as M,At as N,z as O,A as P,b as Q,I as R,qt as S,Jt as T,T as U,D as V,st as W,Ge as X,C as Y,Ke as Z,on as _,Pr as a,pn as b,Yn as c,q as d,Ze as et,gn as f,dn as g,an as h,vr as i,F as j,R as k,vn as l,ln as m,br as n,Fr as o,Yt as p,rt as q,Ar as r,gr as s,_r as t,_n as u,fn as v,Wt as w,rn as x,un as y,P as z};
|