theorum 0.1.14 → 1.0.0
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 +178 -89
- package/esm/mod.d.ts +21 -11
- package/esm/mod.js +15 -8
- package/esm/src/cli/commands/bench.js +6 -3
- package/esm/src/cli/commands/fuzz-canary.d.ts +13 -0
- package/esm/src/cli/commands/fuzz-canary.js +195 -0
- package/esm/src/cli/commands/fuzz-guardrails.d.ts +3 -5
- package/esm/src/cli/commands/fuzz-guardrails.js +4 -581
- package/esm/src/cli/commands/profile.js +25 -14
- package/esm/src/cli/commands/run.d.ts +3 -0
- package/esm/src/cli/commands/run.js +22 -30
- package/esm/src/cli/commands/test.d.ts +10 -1
- package/esm/src/cli/commands/test.js +31 -31
- package/esm/src/cli/event-log.d.ts +19 -0
- package/esm/src/cli/event-log.js +147 -0
- package/esm/src/cli/index.js +45 -11
- package/esm/src/cli/matrix/synthesizer.d.ts +7 -9
- package/esm/src/cli/matrix/synthesizer.js +32 -106
- package/esm/src/guardrails/canary-gate.d.ts +20 -0
- package/esm/src/guardrails/canary-gate.js +31 -0
- package/esm/src/guardrails/canary.d.ts +26 -0
- package/esm/src/guardrails/canary.js +139 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +16 -0
- package/esm/src/guardrails/corpus/canary-egress-attacks.js +151 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.d.ts +11 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +216 -0
- package/esm/src/guardrails/corpus/inbound-payloads.d.ts +10 -0
- package/esm/src/guardrails/corpus/inbound-payloads.js +124 -0
- package/esm/src/guardrails/corpus/live-attacks.d.ts +20 -0
- package/esm/src/guardrails/corpus/live-attacks.js +232 -0
- package/esm/src/guardrails/corpus/mod.d.ts +13 -0
- package/esm/src/guardrails/corpus/mod.js +11 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +16 -0
- package/esm/src/guardrails/corpus/secrets.js +16 -0
- package/esm/src/guardrails/corpus/strings.d.ts +27 -0
- package/esm/src/guardrails/corpus/strings.js +33 -0
- package/esm/src/guardrails/corpus/types.d.ts +37 -0
- package/esm/src/guardrails/corpus/types.js +6 -0
- package/esm/src/guardrails/egress.d.ts +9 -0
- package/esm/src/guardrails/egress.js +36 -0
- package/esm/src/guardrails/error.js +6 -4
- package/esm/src/guardrails/injection.js +28 -5
- package/esm/src/guardrails/live-outbound-gate.d.ts +39 -0
- package/esm/src/guardrails/live-outbound-gate.js +180 -0
- package/esm/src/guardrails/mod.d.ts +13 -4
- package/esm/src/guardrails/mod.js +10 -4
- package/esm/src/guardrails/quota.js +1 -1
- package/esm/src/guardrails/sanitize.d.ts +11 -15
- package/esm/src/guardrails/sanitize.js +40 -49
- package/esm/src/guardrails/sensitive.js +2 -1
- package/esm/src/guardrails/testing.d.ts +10 -0
- package/esm/src/guardrails/testing.js +9 -0
- package/esm/src/host/client-turn.d.ts +19 -0
- package/esm/src/host/client-turn.js +32 -0
- package/esm/src/host/mod.d.ts +5 -3
- package/esm/src/host/mod.js +4 -3
- package/esm/src/interface/blocks.d.ts +20 -0
- package/esm/src/interface/blocks.js +180 -0
- package/esm/src/interface/from-profile.d.ts +14 -0
- package/esm/src/interface/from-profile.js +104 -0
- package/esm/src/interface/inputs.d.ts +8 -0
- package/esm/src/interface/inputs.js +127 -0
- package/esm/src/interface/mod.d.ts +10 -0
- package/esm/src/interface/mod.js +9 -0
- package/esm/src/interface/types.d.ts +153 -0
- package/esm/src/interface/types.js +13 -0
- package/esm/src/kernel/engine/delta.d.ts +24 -2
- package/esm/src/kernel/engine/delta.js +519 -29
- package/esm/src/kernel/engine/live-inbound.d.ts +9 -0
- package/esm/src/kernel/engine/live-inbound.js +17 -0
- package/esm/src/kernel/engine/repair.js +1 -1
- package/esm/src/kernel/engine/runner/gates.d.ts +1 -1
- package/esm/src/kernel/engine/runner/gates.js +7 -7
- package/esm/src/kernel/engine/runner/mod.js +13 -13
- package/esm/src/kernel/engine/runner/state.d.ts +7 -0
- package/esm/src/kernel/engine/runner/steps.d.ts +1 -1
- package/esm/src/kernel/engine/runner/steps.js +171 -37
- package/esm/src/kernel/engine/runner/stream.d.ts +1 -2
- package/esm/src/kernel/engine/runner/stream.js +66 -29
- package/esm/src/kernel/engine/session/mod.d.ts +23 -0
- package/esm/src/kernel/engine/session/mod.js +205 -0
- package/esm/src/kernel/mod.d.ts +9 -10
- package/esm/src/kernel/mod.js +6 -8
- package/esm/src/kernel/registry/attachments.d.ts +4 -2
- package/esm/src/kernel/registry/attachments.js +6 -3
- package/esm/src/kernel/registry/catalog.d.ts +3 -16
- package/esm/src/kernel/registry/catalog.js +5 -81
- package/esm/src/kernel/registry/ingress.d.ts +9 -4
- package/esm/src/kernel/registry/ingress.js +73 -63
- package/esm/src/kernel/registry/profiles.d.ts +35 -12
- package/esm/src/kernel/registry/profiles.js +159 -66
- package/esm/src/kernel/registry/provider-request.js +11 -7
- package/esm/src/kernel/registry/resolve.d.ts +5 -6
- package/esm/src/kernel/registry/resolve.js +100 -70
- package/esm/src/kernel/registry/vault.d.ts +12 -7
- package/esm/src/kernel/registry/vault.js +30 -8
- package/esm/src/kernel/schema.d.ts +145 -0
- package/esm/src/kernel/schema.js +462 -0
- package/esm/src/kernel/stop.d.ts +15 -10
- package/esm/src/kernel/stop.js +5 -5
- package/esm/src/kernel/tools/execute.d.ts +45 -0
- package/esm/src/kernel/tools/execute.js +363 -0
- package/esm/src/kernel/tools/harness.d.ts +8 -0
- package/esm/src/kernel/tools/harness.js +44 -0
- package/esm/src/kernel/tools/invoke.d.ts +10 -0
- package/esm/src/kernel/tools/invoke.js +83 -0
- package/esm/src/kernel/tools/mod.d.ts +11 -0
- package/esm/src/kernel/tools/mod.js +10 -0
- package/esm/src/kernel/tools/project.d.ts +12 -0
- package/esm/src/kernel/tools/project.js +34 -0
- package/esm/src/kernel/tools/registry.d.ts +23 -0
- package/esm/src/kernel/tools/registry.js +71 -0
- package/esm/src/kernel/tools/resolve.d.ts +29 -0
- package/esm/src/kernel/tools/resolve.js +262 -0
- package/esm/src/kernel/tools/schema.d.ts +13 -0
- package/esm/src/kernel/tools/schema.js +159 -0
- package/esm/src/kernel/tools/types.d.ts +216 -0
- package/esm/src/kernel/tools/types.js +9 -0
- package/esm/src/kernel/types.d.ts +338 -193
- package/esm/src/observability/trace-attach.d.ts +6 -4
- package/esm/src/observability/trace-attach.js +39 -25
- package/esm/src/observability/trace-record.d.ts +11 -9
- package/esm/src/observability/trace-record.js +36 -23
- package/esm/src/observability/trace-usage.d.ts +10 -3
- package/esm/src/observability/trace-usage.js +70 -17
- package/esm/src/observability/trace.d.ts +9 -1
- package/esm/src/observability/trace.js +11 -3
- package/esm/src/presets/google/speech-voices.d.ts +11 -0
- package/esm/src/presets/google/speech-voices.js +41 -0
- package/esm/src/presets/google.d.ts +36 -24
- package/esm/src/presets/google.js +50 -63
- package/esm/src/presets/mod.d.ts +2 -2
- package/esm/src/presets/mod.js +1 -1
- package/esm/src/providers/create-provider.d.ts +14 -14
- package/esm/src/providers/create-provider.js +55 -23
- package/esm/src/providers/google/interactions/framing.d.ts +15 -0
- package/esm/src/providers/google/interactions/framing.js +208 -0
- package/esm/src/providers/google/interactions/mod.d.ts +7 -0
- package/esm/src/providers/google/interactions/mod.js +7 -0
- package/esm/src/providers/google/interactions/stream.d.ts +83 -0
- package/esm/src/providers/google/interactions/stream.js +588 -0
- package/esm/src/providers/google/keys.d.ts +26 -0
- package/esm/src/providers/{keys.js → google/keys.js} +19 -31
- package/esm/src/providers/google/live/framing.d.ts +46 -0
- package/esm/src/providers/google/live/framing.js +515 -0
- package/esm/src/providers/google/live/openapi-schema.d.ts +6 -0
- package/esm/src/providers/google/live/openapi-schema.js +45 -0
- package/esm/src/providers/google/live/session.d.ts +25 -0
- package/esm/src/providers/google/live/session.js +134 -0
- package/esm/src/providers/google/live/stream.d.ts +36 -0
- package/esm/src/providers/google/live/stream.js +201 -0
- package/esm/src/providers/google/urls.d.ts +6 -0
- package/esm/src/providers/google/urls.js +6 -0
- package/esm/src/providers/local/local.d.ts +30 -0
- package/esm/src/providers/{local.js → local/local.js} +66 -126
- package/esm/src/providers/local/mod.d.ts +9 -0
- package/esm/src/providers/local/mod.js +9 -0
- package/esm/src/providers/mod.d.ts +6 -3
- package/esm/src/providers/mod.js +3 -1
- package/esm/src/providers/openrouter/chat.d.ts +87 -0
- package/esm/src/providers/{openrouter.js → openrouter/chat.js} +70 -229
- package/esm/src/providers/openrouter/image.d.ts +34 -0
- package/esm/src/providers/openrouter/image.js +286 -0
- package/esm/src/providers/openrouter/openai/chat-payload.d.ts +24 -0
- package/esm/src/providers/openrouter/openai/chat-payload.js +60 -0
- package/esm/src/providers/openrouter/openai/compat.d.ts +47 -0
- package/esm/src/providers/openrouter/openai/compat.js +194 -0
- package/esm/src/providers/openrouter/openai/image-payload.d.ts +18 -0
- package/esm/src/providers/openrouter/openai/image-payload.js +84 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +22 -0
- package/esm/src/providers/openrouter/openai/sdk-messages.js +95 -0
- package/esm/src/providers/openrouter/resolve-api-key.d.ts +9 -0
- package/esm/src/providers/openrouter/resolve-api-key.js +24 -0
- package/esm/src/providers/openrouter/speech.d.ts +23 -0
- package/esm/src/providers/{speech.js → openrouter/speech.js} +32 -55
- package/esm/src/providers/probe.d.ts +1 -0
- package/esm/src/providers/probe.js +22 -0
- package/esm/src/providers/shared/pcm.d.ts +12 -0
- package/esm/src/providers/{pcm.js → shared/pcm.js} +16 -3
- package/esm/src/providers/shared/sse.d.ts +18 -0
- package/esm/src/providers/shared/sse.js +87 -0
- package/esm/src/providers/shared/tool-args.d.ts +17 -0
- package/esm/src/providers/shared/tool-args.js +45 -0
- package/esm/src/providers/shared/upstream-tap.d.ts +5 -0
- package/esm/src/providers/{google-tap.js → shared/upstream-tap.js} +4 -7
- package/esm/src/providers/shared/upstream-tape.d.ts +6 -0
- package/esm/src/providers/{gemini-tape.js → shared/upstream-tape.js} +12 -22
- package/esm/src/providers/types.d.ts +27 -0
- package/esm/src/providers/types.js +1 -0
- package/package.json +11 -7
- package/docs/cli.md +0 -97
- package/docs/guardrails.md +0 -178
- package/docs/host.md +0 -97
- package/docs/kernel.md +0 -404
- package/docs/observability.md +0 -105
- package/docs/openrouter.md +0 -125
- package/docs/presets-google.md +0 -91
- package/docs/presets.md +0 -88
- package/docs/providers.md +0 -201
- package/docs/streaming.md +0 -96
- package/esm/src/kernel/engine/boundary.d.ts +0 -10
- package/esm/src/kernel/engine/boundary.js +0 -55
- package/esm/src/kernel/engine/runner/tools.d.ts +0 -13
- package/esm/src/kernel/engine/runner/tools.js +0 -198
- package/esm/src/kernel/registry/tools.d.ts +0 -12
- package/esm/src/kernel/registry/tools.js +0 -36
- package/esm/src/providers/expose-for-tests.d.ts +0 -1
- package/esm/src/providers/expose-for-tests.js +0 -25
- package/esm/src/providers/gemini-tape.d.ts +0 -2
- package/esm/src/providers/google-tap.d.ts +0 -3
- package/esm/src/providers/interactions.d.ts +0 -5
- package/esm/src/providers/interactions.js +0 -169
- package/esm/src/providers/keys.d.ts +0 -19
- package/esm/src/providers/local.d.ts +0 -29
- package/esm/src/providers/openrouter-mod.d.ts +0 -13
- package/esm/src/providers/openrouter-mod.js +0 -12
- package/esm/src/providers/openrouter-payload.d.ts +0 -39
- package/esm/src/providers/openrouter-payload.js +0 -195
- package/esm/src/providers/openrouter.d.ts +0 -15
- package/esm/src/providers/pcm.d.ts +0 -7
- package/esm/src/providers/provider.d.ts +0 -15
- package/esm/src/providers/provider.js +0 -176
- package/esm/src/providers/speech.d.ts +0 -23
- package/esm/src/providers/sse.d.ts +0 -7
- package/esm/src/providers/sse.js +0 -55
- package/esm/src/streaming/mod.d.ts +0 -9
- package/esm/src/streaming/mod.js +0 -8
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.d.ts +0 -0
- /package/esm/src/{streaming → host}/readStreamingJsonStringField.js +0 -0
|
@@ -7,51 +7,50 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import type { CompactionMeter, CompactionTiming, ControlId, EgressOnBlock, FieldMeta, KeySlot, KeyVault, LiveActivityHandling, LiveContextCompression, LiveSpeechSensitivity, MediaInputKind, OverflowKeySlot, ProfileType, ProfileTypeProtocol, Protocol, Provider, SchemaEnforcement, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolLoadTier, TurnStopKind } from './schema.js';
|
|
11
|
+
import type { InvokeToolRequest, ProfileToolsSpec, RegisteredTool, ToolCallEvent, ToolLoadContext, ToolPolicy, TurnToolSnapshot, WireFunctionTool } from './tools/types.js';
|
|
12
|
+
export type { CompactionMeter, CompactionTiming, ControlId, EgressOnBlock, FieldMeta, InvokeToolRequest, KeySlot, KeyVault, LiveActivityHandling, LiveContextCompression, LiveSpeechSensitivity, MediaInputKind, OverflowKeySlot, ProfileToolsSpec, ProfileType, ProfileTypeProtocol, Protocol, Provider, RegisteredTool, SchemaEnforcement, SpeechAudioFormat, StreamMode, SummaryMode, ThinkingLevel, ToolCallEvent, ToolLoadContext, ToolLoadTier, ToolPolicy, TurnStopKind, TurnToolSnapshot, WireFunctionTool, };
|
|
12
13
|
/** Any host-declared model id. */
|
|
13
14
|
export type ModelId = string;
|
|
14
15
|
/** Provider-projected builtin tool id (registered by presets/adapters). */
|
|
15
16
|
export type BuiltinToolId = string;
|
|
16
|
-
/** Harness custom tool that ships with THEORUM. */
|
|
17
|
-
export type HarnessToolId = 'askUser';
|
|
18
|
-
/** Host-owned or harness custom tool id. */
|
|
19
|
-
export type CustomToolId = HarnessToolId | (string & Record<never, never>);
|
|
20
17
|
/** Any tool id accepted by profile allowlists and per-turn gates. */
|
|
21
|
-
export type ToolId =
|
|
18
|
+
export type ToolId = string;
|
|
22
19
|
/** Id of a host-registered structured output schema. */
|
|
23
20
|
export type StructuredSchemaId = string;
|
|
24
|
-
/** Normalized multimodal part category (image, audio, video, document). */
|
|
25
|
-
export type MediaInputKind = 'image' | 'audio' | 'video' | 'document';
|
|
26
21
|
/** Host-owned profile identifier. */
|
|
27
22
|
export type ProfileId = string;
|
|
28
|
-
/** Named Gemini key bucket used by host-provided transports. */
|
|
29
|
-
export type GeminiBucket = 'freeA' | 'freeB' | 'freeC' | 'paid';
|
|
30
|
-
/** Gemini bucket that may overflow to the paid bucket after quota backoff. */
|
|
31
|
-
export type GeminiFreeBucket = Exclude<GeminiBucket, 'paid'>;
|
|
32
23
|
/** Message role accepted by provider history mappers. */
|
|
33
24
|
export type ChatRole = 'system' | 'user' | 'assistant';
|
|
34
|
-
/** Profile-level control a caller may toggle at turn time. */
|
|
35
|
-
export type ControlId = 'thinking';
|
|
36
25
|
/**
|
|
37
26
|
* Image-role output pins owned by the host profile.
|
|
38
27
|
* The image model itself lives in `model.allow` / `model.config`.
|
|
39
28
|
* Aspect/size/mime values are host strings (presets/apps own the vocabularies).
|
|
40
29
|
*/
|
|
41
30
|
export interface ProfileImageSpec {
|
|
42
|
-
/**
|
|
31
|
+
/** Optional output aspect ratio pin (provider default when omitted). */
|
|
43
32
|
aspectRatio?: string;
|
|
44
|
-
/**
|
|
33
|
+
/** Optional output size / resolution pin (provider default when omitted). */
|
|
45
34
|
size?: string;
|
|
46
35
|
/** Output MIME for generated images. */
|
|
47
36
|
mimeType?: string;
|
|
48
|
-
/** When false, grounding builtins are rejected on this profile. */
|
|
49
|
-
allowsGrounding?: boolean;
|
|
50
37
|
/** Cap on reference images in one turn. */
|
|
51
38
|
maxInputImages?: number;
|
|
39
|
+
/**
|
|
40
|
+
* When true, request interleaved assistant text alongside generated images
|
|
41
|
+
* (Google: `response_format` array with text + image entries).
|
|
42
|
+
*/
|
|
43
|
+
includeText?: boolean;
|
|
52
44
|
}
|
|
53
45
|
/** Public event types emitted by `runTurn` and provider adapters. */
|
|
54
|
-
export type TurnEventType = 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'evidence' | 'tokens' | 'done' | 'error';
|
|
46
|
+
export type TurnEventType = 'thought' | 'text' | 'tool' | 'structured' | 'media' | 'grounding' | 'evidence' | 'tokens' | 'session' | 'done' | 'error';
|
|
47
|
+
/** Live session control signals (provider-neutral). */
|
|
48
|
+
export type SessionEventKind = 'closing_soon' | 'waiting_for_input';
|
|
49
|
+
export interface SessionEvent {
|
|
50
|
+
kind: SessionEventKind;
|
|
51
|
+
/** Parsed drain window when the provider supplied a duration; omit when unknown. */
|
|
52
|
+
timeLeftMs?: number;
|
|
53
|
+
}
|
|
55
54
|
/** Provider thinking levels used when a boolean thinking control is on or off. */
|
|
56
55
|
export interface ThinkingMap {
|
|
57
56
|
on: ThinkingLevel;
|
|
@@ -59,44 +58,43 @@ export interface ThinkingMap {
|
|
|
59
58
|
}
|
|
60
59
|
/** Provider summary behavior used when a boolean thinking control is on or off. */
|
|
61
60
|
export interface SummaryMap {
|
|
62
|
-
on:
|
|
63
|
-
off:
|
|
61
|
+
on: SummaryMode;
|
|
62
|
+
off: SummaryMode;
|
|
64
63
|
}
|
|
65
64
|
/** Host-declared metadata THEORUM needs to call a model safely. */
|
|
66
65
|
export interface ModelSpec {
|
|
66
|
+
/** Provider wire model id for the configured provider. */
|
|
67
67
|
apiId: string;
|
|
68
|
-
/**
|
|
69
|
-
|
|
70
|
-
thinking: ThinkingMap;
|
|
68
|
+
/** Thinking on/off map when the profile lists `thinking` in controls. Omit → provider default. */
|
|
69
|
+
thinking?: ThinkingMap;
|
|
71
70
|
/** Levels this model accepts. Illegal values are clamped via `thinkingLevels`. */
|
|
72
|
-
thinkingLevels
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
thinkingLevels?: ThinkingLevel[];
|
|
72
|
+
/** Thinking-summary on/off map. Omit → provider default. */
|
|
73
|
+
summaries?: SummaryMap;
|
|
74
|
+
/** Cap on output tokens. Omit → provider default. */
|
|
75
|
+
maxOutputTokens?: number;
|
|
76
|
+
/** Sampling temperature. Omit → provider default. */
|
|
77
|
+
temperature?: number;
|
|
76
78
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* Host-owned policy — THEORUM does not infer tool pricing.
|
|
79
|
+
* Provider-native builtins this model supports.
|
|
80
|
+
* Omit or `[]` when none. Opt in per turn with `tools[id]: true`.
|
|
80
81
|
*/
|
|
81
|
-
|
|
82
|
+
builtInTools?: BuiltinToolId[];
|
|
82
83
|
/**
|
|
83
|
-
* Optional vault slot for this model. When set, overrides `profile.model.key
|
|
84
|
-
*
|
|
84
|
+
* Optional vault slot for this model. When set, overrides `profile.model.key`.
|
|
85
|
+
* Host-owned — e.g. pin image models to `paid`.
|
|
85
86
|
*/
|
|
86
|
-
key?:
|
|
87
|
-
/** Optional compaction policy for this model's context window. */
|
|
87
|
+
key?: KeySlot;
|
|
88
|
+
/** Optional compaction policy for this model's context window (chat profiles). */
|
|
88
89
|
compaction?: CompactionSpec;
|
|
90
|
+
/** Gemini Interactions: whether the provider stores the interaction. Omit → provider default. */
|
|
91
|
+
store?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Gemini Interactions: prefer server-side thread via `previous_interaction_id`
|
|
94
|
+
* instead of client-owned history. Omit → host/turn decides.
|
|
95
|
+
*/
|
|
96
|
+
persistViaInteractionId?: boolean;
|
|
89
97
|
}
|
|
90
|
-
/**
|
|
91
|
-
* What the compaction threshold meters.
|
|
92
|
-
*
|
|
93
|
-
* - `'history'` (default) — conversational history only (`TurnInput.historyTokens`
|
|
94
|
-
* or a local estimate of `history`). Excludes system, tool schemas, and this
|
|
95
|
-
* turn's attachments.
|
|
96
|
-
* - `'input'` — full-prompt provider input tokens (`TurnInput.inputTokens` for
|
|
97
|
-
* `timing: 'before'`, this turn's `tokens.input` for `timing: 'after'`).
|
|
98
|
-
*/
|
|
99
|
-
export type CompactionMeter = 'history' | 'input';
|
|
100
98
|
/**
|
|
101
99
|
* Context supplied to a custom compaction trigger.
|
|
102
100
|
*
|
|
@@ -144,7 +142,7 @@ export interface CompactionSpec {
|
|
|
144
142
|
* - `'before'`: kernel compacts synchronously before the turn; user pays latency on this turn.
|
|
145
143
|
* - `'after'`: kernel signals in the `done` event; host runs compaction asynchronously.
|
|
146
144
|
*/
|
|
147
|
-
timing:
|
|
145
|
+
timing: CompactionTiming;
|
|
148
146
|
/**
|
|
149
147
|
* Threshold meter. Defaults to `'history'`.
|
|
150
148
|
* Use `'input'` when the host prefers provider full-prompt usage (after
|
|
@@ -161,27 +159,11 @@ export interface CompactionSpec {
|
|
|
161
159
|
*/
|
|
162
160
|
trigger?: (ctx: CompactionTriggerContext) => boolean | Promise<boolean>;
|
|
163
161
|
}
|
|
164
|
-
/** Static metadata for harness, preset, and host-registered tools. */
|
|
165
|
-
export interface ToolCatalogEntry {
|
|
166
|
-
kind: 'builtin' | 'custom';
|
|
167
|
-
ui: boolean;
|
|
168
|
-
schema?: Record<string, unknown>;
|
|
169
|
-
/** Interactions API `tools[].type` when this builtin is projected. */
|
|
170
|
-
interactionsType?: string;
|
|
171
|
-
/** OpenRouter plugin id enabled when this builtin is on. */
|
|
172
|
-
openRouterPlugin?: string;
|
|
173
|
-
/** Drop this builtin when any listed sibling builtin is also requested. */
|
|
174
|
-
conflictsWith?: ToolId[];
|
|
175
|
-
}
|
|
176
162
|
/** Host-registered structured output schema and enforcement mode. */
|
|
177
163
|
export interface StructuredSpec {
|
|
178
|
-
enforced:
|
|
164
|
+
enforced: SchemaEnforcement;
|
|
179
165
|
jsonSchema?: Record<string, unknown>;
|
|
180
166
|
}
|
|
181
|
-
/** In-memory tool catalog shape. */
|
|
182
|
-
export interface Catalog {
|
|
183
|
-
tools: Record<ToolId, ToolCatalogEntry>;
|
|
184
|
-
}
|
|
185
167
|
/** Per-turn file, byte, and MIME-specific input limits. */
|
|
186
168
|
export interface MediaLimits {
|
|
187
169
|
maxFiles: number;
|
|
@@ -225,17 +207,10 @@ export interface ProfileValidationSpec {
|
|
|
225
207
|
maxRetries?: number;
|
|
226
208
|
repairGuidance?: string;
|
|
227
209
|
}
|
|
228
|
-
/**
|
|
229
|
-
* Audio container for speech generation output.
|
|
230
|
-
* - `openAi` speech (`/audio/speech`): sent as wire `response_format`.
|
|
231
|
-
* - `geminiInteractions`: only `pcm` (or omit). Google returns PCM; THEORUM emits WAV.
|
|
232
|
-
* `mp3` is rejected at resolve.
|
|
233
|
-
*/
|
|
234
|
-
export type SpeechAudioFormat = 'pcm' | 'mp3';
|
|
235
210
|
/**
|
|
236
211
|
* Speech-role output pins owned by the host profile.
|
|
237
212
|
* The speech model itself lives in `model.allow` / `model.config`.
|
|
238
|
-
*
|
|
213
|
+
* Declared top-level under `speech` so `voice` here is the TTS voice id,
|
|
239
214
|
* not ingress audio (`inputs.voice`).
|
|
240
215
|
*/
|
|
241
216
|
export interface ProfileSpeechSpec {
|
|
@@ -246,14 +221,50 @@ export interface ProfileSpeechSpec {
|
|
|
246
221
|
*/
|
|
247
222
|
format?: SpeechAudioFormat;
|
|
248
223
|
}
|
|
224
|
+
/** Voice activity detection & barge-in configuration for live bidirectional streaming. */
|
|
225
|
+
export interface LiveVadSpec {
|
|
226
|
+
activityHandling?: LiveActivityHandling;
|
|
227
|
+
startSensitivity?: LiveSpeechSensitivity;
|
|
228
|
+
endSensitivity?: LiveSpeechSensitivity;
|
|
229
|
+
prefixPaddingMs?: number;
|
|
230
|
+
silenceDurationMs?: number;
|
|
231
|
+
}
|
|
232
|
+
/** Audio transcription toggles for live sessions. */
|
|
233
|
+
export interface LiveTranscriptionSpec {
|
|
234
|
+
input?: boolean;
|
|
235
|
+
output?: boolean;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Output pins for a live-role profile (bidirectional WebSocket audio/video session).
|
|
239
|
+
* The live model itself lives in `model.allow` / `model.config`.
|
|
240
|
+
*/
|
|
241
|
+
export interface ProfileLiveSpec {
|
|
242
|
+
/** Output TTS voice name (e.g. 'Puck', 'Aoede', 'Charon'). */
|
|
243
|
+
voice?: string;
|
|
244
|
+
/** Voice activity detection & barge-in configuration. */
|
|
245
|
+
vad?: LiveVadSpec;
|
|
246
|
+
/** Whether session resumption updates and reconnection handles are enabled. */
|
|
247
|
+
sessionResumption?: boolean;
|
|
248
|
+
/** Context window compression mechanism (e.g. 'slidingWindow' or 'none'). */
|
|
249
|
+
contextCompression?: LiveContextCompression;
|
|
250
|
+
/** Proactivity: allow model to stay silent or ignore irrelevant input. */
|
|
251
|
+
proactiveAudio?: boolean;
|
|
252
|
+
/** Real-time input/output audio transcriptions. */
|
|
253
|
+
transcription?: LiveTranscriptionSpec;
|
|
254
|
+
}
|
|
249
255
|
/** Stream delivery controls enforced by the kernel. */
|
|
250
256
|
export interface ProfileStreamingSpec {
|
|
251
|
-
|
|
257
|
+
/**
|
|
258
|
+
* Profile-only source of truth for upstream stream vs batch.
|
|
259
|
+
* `sse` → stream; `buffered` → non-SSE where the transport supports it.
|
|
260
|
+
* Omit → THEORUM defaults to SSE (`ResolvedGeneration.stream === true`).
|
|
261
|
+
*/
|
|
262
|
+
mode?: StreamMode;
|
|
263
|
+
/** When false, filter `thought` events from the turn stream. */
|
|
252
264
|
streamThoughts?: boolean;
|
|
253
|
-
gateMedia?: boolean;
|
|
254
265
|
}
|
|
255
|
-
export type {
|
|
256
|
-
import type {
|
|
266
|
+
export type { ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop } from './stop.js';
|
|
267
|
+
import type { ProfileTurnResumptionSpec, TurnContinueFrom, TurnStop } from './stop.js';
|
|
257
268
|
/** Context passed to a host-owned outbound disclosure guard. */
|
|
258
269
|
export interface EgressContext {
|
|
259
270
|
text: string;
|
|
@@ -274,7 +285,7 @@ export type EgressEnforcer = (context: EgressContext) => EgressEnforcementResult
|
|
|
274
285
|
/** Profile egress policy for rejection, retry, or refusal behavior. */
|
|
275
286
|
export interface ProfileEgressSpec {
|
|
276
287
|
enforce: EgressEnforcer;
|
|
277
|
-
onBlock?:
|
|
288
|
+
onBlock?: EgressOnBlock;
|
|
278
289
|
maxRetries?: number;
|
|
279
290
|
repairGuidance?: string;
|
|
280
291
|
}
|
|
@@ -290,9 +301,9 @@ export interface ProfileGuardrailsSpec {
|
|
|
290
301
|
egress?: ProfileEgressSpec;
|
|
291
302
|
}
|
|
292
303
|
/** Model, provider, thinking, and step bounds for a profile. */
|
|
293
|
-
export interface ProfileModelSpec {
|
|
294
|
-
protocol:
|
|
295
|
-
provider:
|
|
304
|
+
export interface ProfileModelSpec<P extends Protocol = Protocol> {
|
|
305
|
+
protocol: P;
|
|
306
|
+
provider: Provider;
|
|
296
307
|
/** Ids this profile may select. Each id must exist in `config`. */
|
|
297
308
|
allow: ModelId[];
|
|
298
309
|
/** Host-owned wire config keyed by the same ids used in `allow` / `select`. */
|
|
@@ -300,9 +311,17 @@ export interface ProfileModelSpec {
|
|
|
300
311
|
select?: Record<string, ModelId>;
|
|
301
312
|
thinking?: ThinkingLevel | Record<string, ThinkingLevel>;
|
|
302
313
|
controls?: ControlId[];
|
|
314
|
+
/**
|
|
315
|
+
* Tool-loop ceiling. `<= 0` = unbounded; `1` = one-shot; `> 1` = hard cap.
|
|
316
|
+
* Omit → unbounded (no THEORUM invent of `1`).
|
|
317
|
+
*/
|
|
303
318
|
maxSteps?: number;
|
|
304
|
-
key?:
|
|
319
|
+
key?: OverflowKeySlot;
|
|
305
320
|
}
|
|
321
|
+
/** Wire model specification for turn-based profiles (text, image, speech). */
|
|
322
|
+
export type TurnProfileModelSpec = ProfileModelSpec<ProfileTypeProtocol<'text'>>;
|
|
323
|
+
/** Wire model specification for live bidirectional streaming profiles. */
|
|
324
|
+
export type LiveProfileModelSpec = ProfileModelSpec<ProfileTypeProtocol<'live'>>;
|
|
306
325
|
/** Text, attachment, voice, slot, and size rules for a profile. */
|
|
307
326
|
export interface ProfileInputsSpec {
|
|
308
327
|
text?: boolean;
|
|
@@ -318,35 +337,56 @@ export interface ProfileInputsSpec {
|
|
|
318
337
|
limitsByMime?: Record<string, number>;
|
|
319
338
|
slots?: Record<string, string[]>;
|
|
320
339
|
}
|
|
321
|
-
/**
|
|
340
|
+
/** Chat-shaped output schema, validation, and stream filters. */
|
|
322
341
|
export interface ProfileOutputsSpec {
|
|
323
342
|
structured?: StructuredSchemaId | StructuredBySlot | null;
|
|
324
|
-
/** Pins for an image-role profile. Model id is on `model`. */
|
|
325
|
-
image?: ProfileImageSpec;
|
|
326
|
-
/** Pins for a speech-role profile (`voice` / `format`). Model id is on `model`. */
|
|
327
|
-
speech?: ProfileSpeechSpec;
|
|
328
343
|
validation?: ProfileValidationSpec;
|
|
329
344
|
streaming?: ProfileStreamingSpec;
|
|
330
|
-
/** Resume / Continue policy for non-user stops. */
|
|
331
|
-
resume?: ProfileResumeSpec;
|
|
332
345
|
}
|
|
333
|
-
/**
|
|
334
|
-
export interface
|
|
346
|
+
/** Shared identity block for every profile type. */
|
|
347
|
+
export interface ProfileIdentity {
|
|
348
|
+
handle: string;
|
|
349
|
+
system?: string;
|
|
350
|
+
systemByRole?: Record<string, string>;
|
|
351
|
+
}
|
|
352
|
+
/** Fields shared by every typed profile. */
|
|
353
|
+
export interface ProfileCommon<P extends Protocol = Protocol> {
|
|
335
354
|
id: ProfileId;
|
|
336
|
-
identity:
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
};
|
|
355
|
+
identity: ProfileIdentity;
|
|
356
|
+
model: ProfileModelSpec<P>;
|
|
357
|
+
outputs?: ProfileOutputsSpec;
|
|
358
|
+
guardrails?: ProfileGuardrailsSpec;
|
|
359
|
+
}
|
|
360
|
+
/** Text / structured turn engine with optional tool execution. */
|
|
361
|
+
export interface TextProfile extends ProfileCommon<ProfileTypeProtocol<'text'>> {
|
|
362
|
+
type: 'text';
|
|
363
|
+
tools: ProfileToolsSpec;
|
|
346
364
|
inputs: ProfileInputsSpec;
|
|
347
|
-
|
|
348
|
-
guardrails: ProfileGuardrailsSpec;
|
|
365
|
+
turnResumption?: ProfileTurnResumptionSpec;
|
|
349
366
|
}
|
|
367
|
+
/** Image-generation primary role. */
|
|
368
|
+
export interface ImageProfile extends ProfileCommon<ProfileTypeProtocol<'image'>> {
|
|
369
|
+
type: 'image';
|
|
370
|
+
image: ProfileImageSpec;
|
|
371
|
+
tools: ProfileToolsSpec;
|
|
372
|
+
inputs: ProfileInputsSpec;
|
|
373
|
+
turnResumption?: ProfileTurnResumptionSpec;
|
|
374
|
+
}
|
|
375
|
+
/** Unary TTS — text-in locked by type; no tools / inputs block. */
|
|
376
|
+
export interface SpeechProfile extends ProfileCommon<ProfileTypeProtocol<'speech'>> {
|
|
377
|
+
type: 'speech';
|
|
378
|
+
speech: ProfileSpeechSpec;
|
|
379
|
+
turnResumption?: ProfileTurnResumptionSpec;
|
|
380
|
+
}
|
|
381
|
+
/** Bidirectional live session. */
|
|
382
|
+
export interface LiveProfile extends ProfileCommon<ProfileTypeProtocol<'live'>> {
|
|
383
|
+
type: 'live';
|
|
384
|
+
live: ProfileLiveSpec;
|
|
385
|
+
tools: ProfileToolsSpec;
|
|
386
|
+
inputs?: ProfileInputsSpec;
|
|
387
|
+
}
|
|
388
|
+
/** Complete host-owned agent contract consumed by the kernel. */
|
|
389
|
+
export type Profile = TextProfile | ImageProfile | SpeechProfile | LiveProfile;
|
|
350
390
|
/** Text part sent to provider adapters after input normalization. */
|
|
351
391
|
export interface InteractionTextPart {
|
|
352
392
|
type: 'text';
|
|
@@ -363,10 +403,17 @@ export type InteractionPart = InteractionTextPart | InteractionMediaPart;
|
|
|
363
403
|
/** Native image response request passed to image-capable providers. */
|
|
364
404
|
export interface ImageResponseFormat {
|
|
365
405
|
type: 'image';
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
|
|
406
|
+
/** Omitted when the profile does not pin MIME; providers use their default. */
|
|
407
|
+
mimeType?: string;
|
|
408
|
+
/** Omitted when the profile does not pin aspect; providers use their default. */
|
|
409
|
+
aspectRatio?: string;
|
|
410
|
+
/**
|
|
411
|
+
* Authoring / kernel name; adapters map to provider wire keys (e.g. Google `imageSize`).
|
|
412
|
+
* Omitted when the profile does not pin size; providers use their default.
|
|
413
|
+
*/
|
|
414
|
+
size?: string;
|
|
415
|
+
/** Request assistant text alongside generated images when the provider supports it. */
|
|
416
|
+
includeText: boolean;
|
|
370
417
|
}
|
|
371
418
|
/** Base64-encoded blob supplied by a host turn request. */
|
|
372
419
|
export interface TurnBlob {
|
|
@@ -391,39 +438,6 @@ export interface TurnHistoryMessage {
|
|
|
391
438
|
name?: string;
|
|
392
439
|
metadata?: Record<string, unknown>;
|
|
393
440
|
}
|
|
394
|
-
/** Tool visibility tier used by host dynamic-loading strategies. */
|
|
395
|
-
export type ToolLoadTier = 'T0' | 'T1' | 'T2';
|
|
396
|
-
/** Execution authorization tier for dynamic tools. */
|
|
397
|
-
export type ToolPermissionTier = 'auto' | 'session_consent' | 'always_confirm';
|
|
398
|
-
/** Context supplied to a dynamic tool authorization hook. */
|
|
399
|
-
export interface DynamicToolExecutionContext {
|
|
400
|
-
args: Record<string, unknown>;
|
|
401
|
-
profile: Profile;
|
|
402
|
-
sessionPermissions?: string[];
|
|
403
|
-
}
|
|
404
|
-
/** Context supplied to a host dynamic tool schema loader. */
|
|
405
|
-
export interface DynamicToolLoadContext {
|
|
406
|
-
name: string;
|
|
407
|
-
args: Record<string, unknown>;
|
|
408
|
-
profile: Profile;
|
|
409
|
-
currentTools: DynamicToolDeclaration[];
|
|
410
|
-
sessionPermissions?: string[];
|
|
411
|
-
}
|
|
412
|
-
/** Host function that loads more tool declarations during a turn. */
|
|
413
|
-
export type DynamicToolLoader = (context: DynamicToolLoadContext) => DynamicToolDeclaration[] | Promise<DynamicToolDeclaration[]>;
|
|
414
|
-
/** Runtime tool schema and execution policy supplied by the host app. */
|
|
415
|
-
export interface DynamicToolDeclaration {
|
|
416
|
-
name: string;
|
|
417
|
-
description?: string;
|
|
418
|
-
parameters?: Record<string, unknown>;
|
|
419
|
-
loadTier?: ToolLoadTier;
|
|
420
|
-
permissionTier?: ToolPermissionTier;
|
|
421
|
-
category?: string;
|
|
422
|
-
/** Marks this declaration as a schema-loader tool for T2 expansion. */
|
|
423
|
-
loadsDynamicTools?: boolean;
|
|
424
|
-
handler?: (args: Record<string, unknown>) => ToolEnvelope | Promise<ToolEnvelope>;
|
|
425
|
-
canExecute?: (context: DynamicToolExecutionContext) => boolean | Promise<boolean> | ToolEnvelope | Promise<ToolEnvelope>;
|
|
426
|
-
}
|
|
427
441
|
/** Generic repair request used for validation and egress retry turns. */
|
|
428
442
|
export interface TurnRepairRequest {
|
|
429
443
|
previousOutput: string;
|
|
@@ -450,6 +464,8 @@ export interface TurnInput {
|
|
|
450
464
|
* Ignored when `meter` is `'history'`.
|
|
451
465
|
*/
|
|
452
466
|
inputTokens?: number;
|
|
467
|
+
/** Optional session resumption handle for continuing live WebSocket sessions. */
|
|
468
|
+
sessionResumptionHandle?: string;
|
|
453
469
|
}
|
|
454
470
|
/** Host request after kernel ingress normalization. */
|
|
455
471
|
export type NormalizedTurnRequest = TurnRequest & {
|
|
@@ -462,7 +478,16 @@ export interface TurnRequest {
|
|
|
462
478
|
projectId?: string;
|
|
463
479
|
/** Google Interactions server-side conversation state. Omit for stateless/manual history. */
|
|
464
480
|
previousInteractionId?: string;
|
|
465
|
-
/**
|
|
481
|
+
/**
|
|
482
|
+
* Location bias for Interactions `google_maps` builtin.
|
|
483
|
+
* Wired as `tools: [{ type: "google_maps", latitude, longitude }]`.
|
|
484
|
+
* Ignored when `googleMaps` is not enabled for the selected model.
|
|
485
|
+
*/
|
|
486
|
+
googleMapsLocation?: {
|
|
487
|
+
latitude: number;
|
|
488
|
+
longitude: number;
|
|
489
|
+
};
|
|
490
|
+
/** Optional Interactions storage override. Omit to let profile model.config / provider decide. */
|
|
466
491
|
store?: boolean;
|
|
467
492
|
select?: string;
|
|
468
493
|
thinking?: boolean;
|
|
@@ -470,12 +495,8 @@ export interface TurnRequest {
|
|
|
470
495
|
system?: string;
|
|
471
496
|
/** Session permissions granted for this conversation turn */
|
|
472
497
|
sessionPermissions?: string[];
|
|
473
|
-
/**
|
|
474
|
-
|
|
475
|
-
/** Runtime tool declarations (e.g. load_when_needed strategy) */
|
|
476
|
-
dynamicTools?: DynamicToolDeclaration[];
|
|
477
|
-
/** Generic host-owned loader for T2 dynamic tool schema expansion. */
|
|
478
|
-
dynamicToolLoader?: DynamicToolLoader;
|
|
498
|
+
/** Host channel/path for catalog `paths` filtering. */
|
|
499
|
+
path?: string;
|
|
479
500
|
/** Host-owned metadata preserved for traces; the kernel does not interpret it. */
|
|
480
501
|
metadata?: Record<string, unknown>;
|
|
481
502
|
/**
|
|
@@ -488,71 +509,92 @@ export interface TurnRequest {
|
|
|
488
509
|
* the system prompt; hosts should also pass partial artifact via input/history.
|
|
489
510
|
*/
|
|
490
511
|
continueFrom?: TurnContinueFrom;
|
|
512
|
+
/**
|
|
513
|
+
* 1-based continue attempt when `continueFrom` is set.
|
|
514
|
+
* Compared to `profile.turnResumption.maxContinues` when that cap is set.
|
|
515
|
+
*/
|
|
516
|
+
continuation?: number;
|
|
491
517
|
input?: TurnInput;
|
|
492
|
-
toolInvoke?: {
|
|
493
|
-
name: CustomToolId;
|
|
494
|
-
arguments: Record<string, unknown>;
|
|
495
|
-
};
|
|
496
518
|
/** Provider for the compaction profile when `timing: 'before'`. Falls back to the turn provider. */
|
|
497
519
|
compactionProvider?: ModelProvider;
|
|
520
|
+
/** Optional session resumption handle for continuing live WebSocket sessions. */
|
|
521
|
+
sessionResumptionHandle?: string;
|
|
498
522
|
}
|
|
499
523
|
/** Safe profile projection suitable for UI or host inspection. */
|
|
500
524
|
export interface ProjectedProfile {
|
|
501
525
|
id: string;
|
|
526
|
+
type: ProfileType;
|
|
502
527
|
handle: string;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
models: ModelId[];
|
|
506
|
-
select: Record<string, ModelId> | null;
|
|
507
|
-
controls: ControlId[];
|
|
508
|
-
tools: Array<ToolCatalogEntry & {
|
|
528
|
+
model: ProfileModelSpec;
|
|
529
|
+
tools: Array<RegisteredTool | {
|
|
509
530
|
name: ToolId;
|
|
531
|
+
missing: true;
|
|
510
532
|
}>;
|
|
511
|
-
inputs:
|
|
512
|
-
|
|
513
|
-
outputs: Profile['outputs'];
|
|
533
|
+
inputs: ProfileInputsSpec | null;
|
|
534
|
+
outputs: ProfileOutputsSpec | null;
|
|
514
535
|
image?: ProfileImageSpec | null;
|
|
536
|
+
speech?: ProfileSpeechSpec | null;
|
|
537
|
+
live?: ProfileLiveSpec | null;
|
|
515
538
|
}
|
|
516
539
|
/** Provider selection and generation knobs shared before and after resolution. */
|
|
517
540
|
export interface ProviderGenerationConfig {
|
|
518
541
|
model: ModelId;
|
|
519
|
-
/** Provider
|
|
542
|
+
/** Provider wire model id taken from the profile model spec. */
|
|
520
543
|
apiId: string;
|
|
521
|
-
openRouterId?: string;
|
|
522
544
|
previousInteractionId?: string;
|
|
523
545
|
store?: boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Upstream stream vs batch, derived from `outputs.streaming.mode`.
|
|
548
|
+
* `true` = SSE (THEORUM default when mode is omitted); `false` = buffered.
|
|
549
|
+
*/
|
|
550
|
+
stream?: boolean;
|
|
524
551
|
thinking: ThinkingLevel;
|
|
525
|
-
summaries
|
|
526
|
-
maxOutputTokens
|
|
527
|
-
temperature
|
|
552
|
+
summaries?: SummaryMode;
|
|
553
|
+
maxOutputTokens?: number;
|
|
554
|
+
temperature?: number;
|
|
528
555
|
builtins: BuiltinToolId[];
|
|
556
|
+
/**
|
|
557
|
+
* Location bias for Interactions `google_maps`.
|
|
558
|
+
* Copied from `TurnRequest.googleMapsLocation` when present.
|
|
559
|
+
*/
|
|
560
|
+
googleMapsLocation?: {
|
|
561
|
+
latitude: number;
|
|
562
|
+
longitude: number;
|
|
563
|
+
};
|
|
529
564
|
}
|
|
565
|
+
/** Resolved provider transport derived once in `resolveTurn`. */
|
|
566
|
+
export type ProviderTransport = 'interactions' | 'geminiLive' | 'openAiCompat';
|
|
530
567
|
/** Fully-resolved provider request state created from a `TurnRequest`. */
|
|
531
568
|
export interface ResolvedGeneration extends ProviderGenerationConfig {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
569
|
+
/** Resolved transport — `'interactions'` for Google Gemini Interactions, `'geminiLive'` for Gemini Live WebSocket, `'openAiCompat'` otherwise. */
|
|
570
|
+
transport: ProviderTransport;
|
|
571
|
+
/** Mutable tool visibility and wire snapshot for this turn. */
|
|
572
|
+
tools: TurnToolSnapshot;
|
|
535
573
|
sessionPermissions?: string[];
|
|
536
574
|
history?: TurnHistoryMessage[];
|
|
537
|
-
|
|
575
|
+
/**
|
|
576
|
+
* Interactions-only: when set, sent as the request `input` array instead of
|
|
577
|
+
* history + user parts (e.g. a lone `function_result` continuation step).
|
|
578
|
+
*/
|
|
579
|
+
interactionOnlyInput?: Record<string, unknown>[];
|
|
580
|
+
/**
|
|
581
|
+
* Tool-loop ceiling. `undefined` or `<= 0` = unbounded.
|
|
582
|
+
* Taken from `profile.model.maxSteps` with no THEORUM invent.
|
|
583
|
+
*/
|
|
584
|
+
maxSteps?: number;
|
|
538
585
|
structured: StructuredSchemaId | null;
|
|
539
586
|
image: ImageResponseFormat | null;
|
|
540
587
|
speech?: ProfileSpeechSpec;
|
|
588
|
+
live?: ProfileLiveSpec;
|
|
541
589
|
input: InteractionPart[];
|
|
542
590
|
/**
|
|
543
|
-
*
|
|
544
|
-
*
|
|
591
|
+
* Vault key slot for credentialed transports (Google required; OpenRouter when
|
|
592
|
+
* the profile pins `model.key` or a builtin forces `paid`). Never sent on the wire.
|
|
545
593
|
*/
|
|
546
|
-
|
|
594
|
+
keySlot?: KeySlot;
|
|
547
595
|
canary: string;
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
export type ToolStatus = 'ok' | 'error' | 'pause';
|
|
551
|
-
/** Structured result envelope returned by deterministic tool handlers. */
|
|
552
|
-
export interface ToolEnvelope {
|
|
553
|
-
status: ToolStatus;
|
|
554
|
-
finding?: string;
|
|
555
|
-
data?: Record<string, unknown>;
|
|
596
|
+
/** Optional session resumption handle for continuing live WebSocket sessions. */
|
|
597
|
+
sessionResumptionHandle?: string;
|
|
556
598
|
}
|
|
557
599
|
/** Token accounting emitted by providers or fallback estimation. */
|
|
558
600
|
export interface TurnTokens {
|
|
@@ -560,6 +602,8 @@ export interface TurnTokens {
|
|
|
560
602
|
output: number;
|
|
561
603
|
thinking?: number;
|
|
562
604
|
toolUse?: number;
|
|
605
|
+
/** Google code-execution / tool intermediate tokens when the API reports them. */
|
|
606
|
+
intermediate?: number;
|
|
563
607
|
total: number;
|
|
564
608
|
}
|
|
565
609
|
/** Normalized citation or place source surfaced from a provider. */
|
|
@@ -567,6 +611,8 @@ export interface GroundingSource {
|
|
|
567
611
|
title: string;
|
|
568
612
|
uri: string;
|
|
569
613
|
type: 'maps' | 'web';
|
|
614
|
+
/** Google Place id when the source is a Maps place / place_citation. */
|
|
615
|
+
placeId?: string;
|
|
570
616
|
}
|
|
571
617
|
/** Google grounding metadata normalized into a stream event. */
|
|
572
618
|
export interface GroundingEvent {
|
|
@@ -575,13 +621,36 @@ export interface GroundingEvent {
|
|
|
575
621
|
searchHtml?: string;
|
|
576
622
|
sources: GroundingSource[];
|
|
577
623
|
}
|
|
578
|
-
/** Provider evidence such as OpenRouter citations or
|
|
624
|
+
/** Provider evidence such as OpenRouter citations or Google server-side tool steps. */
|
|
579
625
|
export interface ProviderEvidenceEvent {
|
|
580
626
|
provider: 'openrouter' | 'google' | string;
|
|
581
627
|
raw?: Record<string, unknown>;
|
|
582
628
|
citations?: string[];
|
|
583
629
|
annotations?: unknown[];
|
|
584
630
|
sources?: GroundingSource[];
|
|
631
|
+
/**
|
|
632
|
+
* Discriminant for evidence payloads.
|
|
633
|
+
* Live ASR uses `input_transcription` / `output_transcription`;
|
|
634
|
+
* resumption uses `session_resumption`; Interactions code execution uses
|
|
635
|
+
* `code_execution_call` / `code_execution_result`.
|
|
636
|
+
*/
|
|
637
|
+
kind?: 'code_execution_call' | 'code_execution_result' | 'input_transcription' | 'output_transcription' | 'session_resumption' | string;
|
|
638
|
+
/** Generated Python (or other) source from `code_execution_call.arguments.code`. */
|
|
639
|
+
code?: string;
|
|
640
|
+
/** Language of `code` when the API supplies it (typically `python`). */
|
|
641
|
+
language?: string;
|
|
642
|
+
/** Stdout / sandbox output from `code_execution_result.result`. */
|
|
643
|
+
result?: string;
|
|
644
|
+
/** `true` when the sandbox reported an execution error. */
|
|
645
|
+
isError?: boolean;
|
|
646
|
+
/** Step id (`code_execution_call.id`). */
|
|
647
|
+
id?: string;
|
|
648
|
+
/** Links a result to its call (`code_execution_result.call_id`). */
|
|
649
|
+
callId?: string;
|
|
650
|
+
/** Live ASR: partial/interim chunk (vs final transcription delta). */
|
|
651
|
+
interim?: boolean;
|
|
652
|
+
/** Live session resumption: whether the handle may be used to resume. */
|
|
653
|
+
resumable?: boolean;
|
|
585
654
|
}
|
|
586
655
|
/** Compaction signal emitted in the `done` event when `timing: 'after'`. */
|
|
587
656
|
export interface CompactionSignal {
|
|
@@ -601,11 +670,10 @@ export interface CompactionSignal {
|
|
|
601
670
|
export interface TurnEvent {
|
|
602
671
|
type: TurnEventType;
|
|
603
672
|
text?: string;
|
|
604
|
-
tool?: {
|
|
605
|
-
|
|
606
|
-
arguments?: Record<string, unknown>;
|
|
607
|
-
result?: ToolEnvelope;
|
|
673
|
+
tool?: ToolCallEvent & {
|
|
674
|
+
/** Provider-native tool call id when present. */
|
|
608
675
|
id?: string;
|
|
676
|
+
arguments?: Record<string, unknown>;
|
|
609
677
|
};
|
|
610
678
|
structured?: unknown;
|
|
611
679
|
media?: {
|
|
@@ -614,8 +682,13 @@ export interface TurnEvent {
|
|
|
614
682
|
};
|
|
615
683
|
grounding?: GroundingEvent;
|
|
616
684
|
evidence?: ProviderEvidenceEvent;
|
|
685
|
+
session?: SessionEvent;
|
|
617
686
|
tokens?: TurnTokens;
|
|
618
687
|
interactionId?: string;
|
|
688
|
+
/** Session resumption handle updated during live sessions. */
|
|
689
|
+
sessionResumptionHandle?: string;
|
|
690
|
+
/** True when a user utterance interrupted an in-flight live model response (barge-in). */
|
|
691
|
+
interrupted?: boolean;
|
|
619
692
|
/** Public-safe failure text for hosts to show users. */
|
|
620
693
|
error?: string;
|
|
621
694
|
/** Raw diagnostic detail for traces/logs; never surface to end users. */
|
|
@@ -625,23 +698,45 @@ export interface TurnEvent {
|
|
|
625
698
|
/** Why the turn ended. Present on terminal `done` events when known. */
|
|
626
699
|
stop?: TurnStop;
|
|
627
700
|
}
|
|
628
|
-
/**
|
|
629
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Provider-neutral request object sent from the kernel to a model adapter.
|
|
703
|
+
*
|
|
704
|
+
* Several fields are **Google Interactions-only** and omitted otherwise:
|
|
705
|
+
* `previousInteractionId`, `store`, `stream`, `summaries`,
|
|
706
|
+
* `interactionOnlyInput`.
|
|
707
|
+
* Adapters must tolerate their absence. `keySlot` is shared by Google and
|
|
708
|
+
* OpenRouter vault resolution (required for Google; optional for OpenRouter).
|
|
709
|
+
*/
|
|
710
|
+
export interface ProviderCompleteRequest extends Omit<ProviderGenerationConfig, 'summaries'> {
|
|
711
|
+
/**
|
|
712
|
+
* Interactions-only: thinking-summary behavior.
|
|
713
|
+
* Omitted (undefined) for non-Google providers.
|
|
714
|
+
*/
|
|
715
|
+
summaries?: SummaryMode;
|
|
630
716
|
system: string;
|
|
631
717
|
input: InteractionPart[];
|
|
632
718
|
history?: TurnHistoryMessage[];
|
|
633
|
-
|
|
634
|
-
|
|
719
|
+
/**
|
|
720
|
+
* Interactions-only: when set, sent as the request `input` array instead of
|
|
721
|
+
* history + user parts (e.g. a lone `function_result` continuation step).
|
|
722
|
+
* Omitted for non-Google providers.
|
|
723
|
+
*/
|
|
724
|
+
interactionOnlyInput?: Record<string, unknown>[];
|
|
725
|
+
/** Function tool wire declarations derived from the turn tool snapshot. */
|
|
726
|
+
wireTools?: WireFunctionTool[];
|
|
635
727
|
structured: StructuredSchemaId | null;
|
|
636
728
|
image: ImageResponseFormat | null;
|
|
637
729
|
speech?: ProfileSpeechSpec;
|
|
730
|
+
live?: ProfileLiveSpec;
|
|
731
|
+
/** Optional session resumption handle for continuing live WebSocket sessions. */
|
|
732
|
+
sessionResumptionHandle?: string;
|
|
638
733
|
/**
|
|
639
|
-
*
|
|
640
|
-
*
|
|
734
|
+
* Vault key slot. Required for Google; set for OpenRouter when the profile
|
|
735
|
+
* pins `model.key` or a builtin forces `paid`. Never sent on the wire.
|
|
641
736
|
*/
|
|
642
|
-
|
|
737
|
+
keySlot?: KeySlot;
|
|
643
738
|
/** Scrubbed SSE / HTTP rows for traces. */
|
|
644
|
-
|
|
739
|
+
tapUpstream?: (row: Record<string, unknown>) => void;
|
|
645
740
|
/** Host abort signal — adapters should pass this into fetch / SDK calls. */
|
|
646
741
|
signal?: AbortSignal;
|
|
647
742
|
}
|
|
@@ -649,3 +744,53 @@ export interface ProviderCompleteRequest extends ProviderGenerationConfig {
|
|
|
649
744
|
export interface ModelProvider {
|
|
650
745
|
complete: (req: ProviderCompleteRequest) => AsyncIterable<TurnEvent>;
|
|
651
746
|
}
|
|
747
|
+
/**
|
|
748
|
+
* Host request to open a long-lived live session (`runSession`).
|
|
749
|
+
* Profile must be `type: 'live'`.
|
|
750
|
+
*/
|
|
751
|
+
export interface SessionRequest {
|
|
752
|
+
profile: ProfileId;
|
|
753
|
+
/** Host-built system prompt merged with profile identity.system. */
|
|
754
|
+
system?: string;
|
|
755
|
+
/** Override `profile.live.voice` for this session. */
|
|
756
|
+
voice?: string;
|
|
757
|
+
path?: string;
|
|
758
|
+
sessionPermissions?: string[];
|
|
759
|
+
history?: TurnHistoryMessage[];
|
|
760
|
+
sessionResumptionHandle?: string;
|
|
761
|
+
/**
|
|
762
|
+
* Host-supplied function declarations for this session.
|
|
763
|
+
* When set, replaces `generation.tools.wire` on the provider request
|
|
764
|
+
* (Orchid-class hosts that resolve tools outside the Worker registry).
|
|
765
|
+
*/
|
|
766
|
+
wireTools?: WireFunctionTool[];
|
|
767
|
+
/** Optional realtime parts sent immediately after setup. */
|
|
768
|
+
input?: InteractionPart[];
|
|
769
|
+
signal?: AbortSignal;
|
|
770
|
+
metadata?: Record<string, unknown>;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Long-lived live session returned by `runSession`.
|
|
774
|
+
* `done` events mark conversational turn boundaries; the session stays open until `close()`.
|
|
775
|
+
*/
|
|
776
|
+
export interface LiveSession {
|
|
777
|
+
readonly profileId: ProfileId;
|
|
778
|
+
readonly canary: string;
|
|
779
|
+
events(): AsyncGenerator<TurnEvent, void, undefined>;
|
|
780
|
+
sendAudio(args: {
|
|
781
|
+
data: string;
|
|
782
|
+
mimeType?: string;
|
|
783
|
+
}): void;
|
|
784
|
+
sendVideo(args: {
|
|
785
|
+
data: string;
|
|
786
|
+
mimeType?: string;
|
|
787
|
+
}): void;
|
|
788
|
+
sendText(text: string): void;
|
|
789
|
+
sendToolResponse(id: string, name: string, output: unknown): void;
|
|
790
|
+
sendToolResponses(responses: Array<{
|
|
791
|
+
id: string;
|
|
792
|
+
name: string;
|
|
793
|
+
output: unknown;
|
|
794
|
+
}>): void;
|
|
795
|
+
close(reason?: string): Promise<void>;
|
|
796
|
+
}
|