theorum 1.0.0 → 1.1.3
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 +81 -25
- package/esm/mod.d.ts +48 -29
- package/esm/mod.js +37 -24
- package/esm/src/cli/commands/bench.js +13 -16
- package/esm/src/cli/commands/fuzz-canary.js +25 -29
- package/esm/src/cli/commands/guardrails-eval.d.ts +14 -0
- package/esm/src/cli/commands/guardrails-eval.js +15 -0
- package/esm/src/cli/commands/profile.js +12 -3
- package/esm/src/cli/commands/run.js +8 -9
- package/esm/src/cli/commands/test.js +8 -8
- package/esm/src/cli/event-log.d.ts +1 -1
- package/esm/src/cli/index.js +12 -0
- package/esm/src/cli/matrix/synthesizer.d.ts +6 -6
- package/esm/src/cli/matrix/synthesizer.js +23 -22
- package/esm/src/guardrails/canary-gate.d.ts +2 -1
- package/esm/src/guardrails/canary-gate.js +2 -1
- package/esm/src/guardrails/canary.d.ts +9 -1
- package/esm/src/guardrails/canary.js +21 -10
- package/esm/src/guardrails/corpus/canary-egress-attacks.d.ts +1 -0
- package/esm/src/guardrails/corpus/fuzz-inbound.js +12 -15
- package/esm/src/guardrails/corpus/inbound-payloads.js +1 -0
- package/esm/src/guardrails/corpus/live-attacks.js +0 -1
- package/esm/src/guardrails/corpus/mod.d.ts +1 -0
- package/esm/src/guardrails/corpus/secrets.d.ts +1 -0
- package/esm/src/guardrails/corpus/secrets.js +1 -0
- package/esm/src/guardrails/corpus/strings.d.ts +1 -0
- package/esm/src/guardrails/corpus/strings.js +1 -0
- package/esm/src/guardrails/corpus/types.d.ts +1 -0
- package/esm/src/guardrails/egress.d.ts +26 -3
- package/esm/src/guardrails/egress.js +69 -18
- package/esm/src/guardrails/error.d.ts +14 -23
- package/esm/src/guardrails/error.js +86 -77
- package/esm/src/guardrails/eval/corpus.d.ts +108 -0
- package/esm/src/guardrails/eval/corpus.js +978 -0
- package/esm/src/guardrails/eval/mod.d.ts +51 -0
- package/esm/src/guardrails/eval/mod.js +133 -0
- package/esm/src/guardrails/eval/score.d.ts +66 -0
- package/esm/src/guardrails/eval/score.js +114 -0
- package/esm/src/guardrails/events.d.ts +25 -0
- package/esm/src/guardrails/events.js +56 -0
- package/esm/src/guardrails/hits.d.ts +24 -0
- package/esm/src/guardrails/hits.js +45 -0
- package/esm/src/guardrails/lexicon.d.ts +39 -0
- package/esm/src/guardrails/lexicon.js +200 -0
- package/esm/src/guardrails/live-outbound-gate.d.ts +15 -13
- package/esm/src/guardrails/live-outbound-gate.js +131 -89
- package/esm/src/guardrails/mod.d.ts +19 -4
- package/esm/src/guardrails/mod.js +12 -3
- package/esm/src/guardrails/network.d.ts +19 -0
- package/esm/src/guardrails/network.js +234 -0
- package/esm/src/guardrails/policy.d.ts +35 -0
- package/esm/src/guardrails/policy.js +50 -0
- package/esm/src/guardrails/progressive-yield.d.ts +51 -0
- package/esm/src/guardrails/progressive-yield.js +98 -0
- package/esm/src/guardrails/quota.d.ts +17 -3
- package/esm/src/guardrails/quota.js +18 -4
- package/esm/src/guardrails/sanitize.d.ts +36 -6
- package/esm/src/guardrails/sanitize.js +152 -60
- package/esm/src/guardrails/serialize.d.ts +35 -0
- package/esm/src/guardrails/serialize.js +58 -0
- package/esm/src/guardrails/testing.d.ts +7 -0
- package/esm/src/guardrails/testing.js +4 -0
- package/esm/src/guardrails/theorum-error.d.ts +12 -0
- package/esm/src/guardrails/theorum-error.js +15 -0
- package/esm/src/guardrails/tool-directives.d.ts +48 -0
- package/esm/src/guardrails/tool-directives.js +124 -0
- package/esm/src/guardrails/tool-result.d.ts +93 -0
- package/esm/src/guardrails/tool-result.js +276 -0
- package/esm/src/guardrails/types.d.ts +291 -0
- package/esm/src/guardrails/types.js +72 -0
- package/esm/src/host/client-turn.js +4 -0
- package/esm/src/host/mint-trace.d.ts +1 -1
- package/esm/src/kernel/auth/crypto.d.ts +42 -0
- package/esm/src/kernel/auth/crypto.js +106 -0
- package/esm/src/kernel/auth/mod.d.ts +11 -0
- package/esm/src/kernel/auth/mod.js +11 -0
- package/esm/src/kernel/auth/oauth.d.ts +47 -0
- package/esm/src/kernel/auth/oauth.js +278 -0
- package/esm/src/kernel/auth/types.d.ts +133 -0
- package/esm/src/kernel/auth/types.js +13 -0
- package/esm/src/kernel/engine/delta.js +43 -2
- package/esm/src/kernel/engine/live-inbound.d.ts +15 -3
- package/esm/src/kernel/engine/live-inbound.js +22 -8
- package/esm/src/kernel/engine/live-ingress.d.ts +19 -0
- package/esm/src/kernel/engine/live-ingress.js +47 -0
- package/esm/src/kernel/engine/repair.js +13 -12
- package/esm/src/kernel/engine/runner/gates.js +127 -40
- package/esm/src/kernel/engine/runner/mod.d.ts +6 -4
- package/esm/src/kernel/engine/runner/mod.js +182 -43
- package/esm/src/kernel/engine/runner/schema-validation.js +3 -3
- package/esm/src/kernel/engine/runner/stages.d.ts +39 -0
- package/esm/src/kernel/engine/runner/stages.js +89 -0
- package/esm/src/kernel/engine/runner/state.d.ts +24 -0
- package/esm/src/kernel/engine/runner/steps.js +128 -61
- package/esm/src/kernel/engine/runner/stream.d.ts +9 -2
- package/esm/src/kernel/engine/runner/stream.js +114 -55
- package/esm/src/kernel/engine/session/mod.d.ts +3 -1
- package/esm/src/kernel/engine/session/mod.js +386 -34
- package/esm/src/kernel/interaction-parts.d.ts +14 -0
- package/esm/src/kernel/interaction-parts.js +23 -0
- package/esm/src/kernel/mod.d.ts +19 -7
- package/esm/src/kernel/mod.js +10 -5
- package/esm/src/kernel/profile-graph.d.ts +159 -0
- package/esm/src/kernel/profile-graph.js +156 -0
- package/esm/src/kernel/registry/attachments.d.ts +10 -10
- package/esm/src/kernel/registry/attachments.js +29 -26
- package/esm/src/kernel/registry/catalog.d.ts +25 -11
- package/esm/src/kernel/registry/catalog.js +59 -24
- package/esm/src/kernel/registry/ingress.js +34 -22
- package/esm/src/kernel/registry/profile-outputs.d.ts +4 -0
- package/esm/src/kernel/registry/profile-outputs.js +8 -0
- package/esm/src/kernel/registry/profiles.d.ts +34 -14
- package/esm/src/kernel/registry/profiles.js +306 -59
- package/esm/src/kernel/registry/provider-request.js +2 -0
- package/esm/src/kernel/registry/resolve.d.ts +7 -6
- package/esm/src/kernel/registry/resolve.js +102 -117
- package/esm/src/kernel/registry/schemas.js +1 -1
- package/esm/src/kernel/registry/sole-model.d.ts +8 -0
- package/esm/src/kernel/registry/sole-model.js +10 -0
- package/esm/src/kernel/registry/system-prompt.d.ts +10 -0
- package/esm/src/kernel/registry/system-prompt.js +40 -0
- package/esm/src/kernel/registry/system-role.d.ts +8 -0
- package/esm/src/kernel/registry/system-role.js +14 -0
- package/esm/src/kernel/registry/vault.d.ts +2 -2
- package/esm/src/kernel/registry/vault.js +4 -4
- package/esm/src/kernel/schema.d.ts +97 -11
- package/esm/src/kernel/schema.js +256 -111
- package/esm/src/kernel/stages.d.ts +175 -0
- package/esm/src/kernel/stages.js +476 -0
- package/esm/src/kernel/stop.d.ts +65 -11
- package/esm/src/kernel/stop.js +46 -11
- package/esm/src/kernel/tools/events.d.ts +41 -0
- package/esm/src/kernel/tools/events.js +71 -0
- package/esm/src/kernel/tools/execute.d.ts +63 -24
- package/esm/src/kernel/tools/execute.js +475 -224
- package/esm/src/kernel/tools/harness.js +16 -14
- package/esm/src/kernel/tools/invoke.js +26 -8
- package/esm/src/kernel/tools/mod.d.ts +3 -1
- package/esm/src/kernel/tools/mod.js +2 -1
- package/esm/src/kernel/tools/permission.d.ts +15 -0
- package/esm/src/kernel/tools/permission.js +47 -0
- package/esm/src/kernel/tools/project.js +5 -3
- package/esm/src/kernel/tools/registry.js +20 -10
- package/esm/src/kernel/tools/remote.d.ts +94 -0
- package/esm/src/kernel/tools/remote.js +577 -0
- package/esm/src/kernel/tools/resolve.d.ts +17 -7
- package/esm/src/kernel/tools/resolve.js +38 -17
- package/esm/src/kernel/tools/schema.d.ts +2 -0
- package/esm/src/kernel/tools/schema.js +23 -6
- package/esm/src/kernel/tools/stage-run.d.ts +105 -0
- package/esm/src/kernel/tools/stage-run.js +155 -0
- package/esm/src/kernel/tools/types.d.ts +198 -20
- package/esm/src/kernel/types.d.ts +253 -114
- package/esm/src/kernel/util/find-last.d.ts +2 -0
- package/esm/src/kernel/util/find-last.js +10 -0
- package/esm/src/observability/destinations.d.ts +31 -0
- package/esm/src/observability/destinations.js +67 -0
- package/esm/src/observability/mod.d.ts +10 -3
- package/esm/src/observability/mod.js +6 -2
- package/esm/src/observability/policy.d.ts +27 -0
- package/esm/src/observability/policy.js +80 -0
- package/esm/src/observability/resolve-policy.d.ts +16 -0
- package/esm/src/observability/resolve-policy.js +64 -0
- package/esm/src/observability/trace-attach.d.ts +3 -1
- package/esm/src/observability/trace-attach.js +17 -10
- package/esm/src/observability/trace-record.d.ts +12 -4
- package/esm/src/observability/trace-record.js +63 -19
- package/esm/src/observability/trace-sink.d.ts +19 -0
- package/esm/src/observability/trace-sink.js +10 -0
- package/esm/src/observability/trace.d.ts +14 -11
- package/esm/src/observability/trace.js +23 -14
- package/esm/src/observability/types.d.ts +113 -0
- package/esm/src/observability/types.js +11 -0
- package/esm/src/providers/create-provider.d.ts +7 -4
- package/esm/src/providers/create-provider.js +21 -7
- package/esm/src/providers/google/interactions/framing.d.ts +8 -0
- package/esm/src/providers/google/interactions/framing.js +74 -13
- package/esm/src/providers/google/live/framing.d.ts +5 -2
- package/esm/src/providers/google/live/framing.js +49 -12
- package/esm/src/providers/google/live/openapi-schema.js +3 -2
- package/esm/src/providers/google/live/stream.d.ts +9 -0
- package/esm/src/providers/google/live/stream.js +16 -3
- package/esm/src/providers/openrouter/cache-control.d.ts +24 -0
- package/esm/src/providers/openrouter/cache-control.js +23 -0
- package/esm/src/providers/openrouter/chat.d.ts +21 -1
- package/esm/src/providers/openrouter/chat.js +51 -6
- package/esm/src/providers/openrouter/image.js +8 -19
- package/esm/src/providers/openrouter/openai/chat-payload.js +23 -1
- package/esm/src/providers/openrouter/openai/compat.d.ts +7 -1
- package/esm/src/providers/openrouter/openai/compat.js +23 -4
- package/esm/src/providers/openrouter/openai/image-payload.js +8 -2
- package/esm/src/providers/openrouter/openai/sdk-messages.d.ts +1 -1
- package/esm/src/providers/openrouter/openai/sdk-messages.js +32 -5
- package/package.json +1 -1
- package/esm/src/interface/blocks.d.ts +0 -20
- package/esm/src/interface/blocks.js +0 -180
- package/esm/src/interface/from-profile.d.ts +0 -14
- package/esm/src/interface/from-profile.js +0 -104
- package/esm/src/interface/inputs.d.ts +0 -8
- package/esm/src/interface/inputs.js +0 -127
- package/esm/src/interface/mod.d.ts +0 -10
- package/esm/src/interface/mod.js +0 -9
- package/esm/src/interface/types.d.ts +0 -153
- package/esm/src/interface/types.js +0 -13
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import type { z } from 'zod';
|
|
10
|
-
import type {
|
|
11
|
-
import type {
|
|
12
|
-
|
|
10
|
+
import type { GuardrailHit, Provenance, TurnTaint } from '../../guardrails/types.js';
|
|
11
|
+
import type { ToolCredential } from '../auth/types.js';
|
|
12
|
+
import type { AuthUnauthenticatedPolicy, HttpMethod, ToolAccess, ToolAuthType, ToolGateKind, ToolLoadTier, ToolPermission } from '../schema.js';
|
|
13
|
+
import type { InteractionPart, Profile, ToolId, TurnInput } from '../types.js';
|
|
14
|
+
export type { AuthUnauthenticatedPolicy, HttpMethod, ToolAccess, ToolAuthType, ToolGateKind, ToolPermission, };
|
|
13
15
|
export interface ToolLabels {
|
|
14
16
|
activity?: string;
|
|
15
17
|
activityPast?: string;
|
|
@@ -43,11 +45,18 @@ export interface InteractiveRender {
|
|
|
43
45
|
options?: string[];
|
|
44
46
|
[key: string]: unknown;
|
|
45
47
|
}
|
|
46
|
-
export interface InteractiveConfig<TIn = unknown> {
|
|
47
|
-
render: (input: TIn) => InteractiveRender;
|
|
48
|
-
}
|
|
49
48
|
export interface InvokeToolResume {
|
|
49
|
+
/**
|
|
50
|
+
* Legacy interactive value — unused for gates / ask_user answers.
|
|
51
|
+
* @deprecated Prefer a new user turn for ask_user answers.
|
|
52
|
+
*/
|
|
50
53
|
value?: unknown;
|
|
54
|
+
/**
|
|
55
|
+
* Gate resume:
|
|
56
|
+
* - `true` — skip confirm / permission / `preTool` re-ask and run the body
|
|
57
|
+
* - `false` — settle as deny (synthetic failure + `post_tool`, no body)
|
|
58
|
+
* - omit — first attempt (or auth credential retry without grant)
|
|
59
|
+
*/
|
|
51
60
|
granted?: boolean;
|
|
52
61
|
}
|
|
53
62
|
export interface ToolContext {
|
|
@@ -56,10 +65,15 @@ export interface ToolContext {
|
|
|
56
65
|
sessionPermissions?: string[];
|
|
57
66
|
path?: string;
|
|
58
67
|
signal?: AbortSignal;
|
|
68
|
+
/** Turn-scoped facts: the step index and what this turn has already ingested. */
|
|
59
69
|
turn?: {
|
|
60
70
|
step: number;
|
|
71
|
+
taint?: TurnTaint;
|
|
61
72
|
};
|
|
62
73
|
resume?: InvokeToolResume;
|
|
74
|
+
credentials?: Record<string, ToolCredential>;
|
|
75
|
+
/** Opaque application context from `TurnRequest.host` / `InvokeToolRequest.host`; the kernel never reads it. */
|
|
76
|
+
host?: unknown;
|
|
63
77
|
}
|
|
64
78
|
export interface ToolFailure {
|
|
65
79
|
code: string;
|
|
@@ -67,12 +81,34 @@ export interface ToolFailure {
|
|
|
67
81
|
details?: unknown;
|
|
68
82
|
}
|
|
69
83
|
export interface ToolPause {
|
|
70
|
-
kind: 'interactive' | 'confirmation' | 'permission';
|
|
84
|
+
kind: 'interactive' | 'confirmation' | 'permission' | 'auth';
|
|
71
85
|
tool: string;
|
|
72
86
|
render?: InteractiveRender;
|
|
73
87
|
summary?: string;
|
|
74
88
|
input: unknown;
|
|
75
89
|
permission?: ToolPermission;
|
|
90
|
+
/** Auth challenge metadata when kind is 'auth' */
|
|
91
|
+
authChallenge?: {
|
|
92
|
+
slot: string;
|
|
93
|
+
authType: ToolAuthType;
|
|
94
|
+
message: string;
|
|
95
|
+
authorizationUrl?: string;
|
|
96
|
+
state?: string;
|
|
97
|
+
issuer?: string;
|
|
98
|
+
resource?: string;
|
|
99
|
+
requiredScopes?: string[];
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Confirm-to-run / permission / auth gate (stages contract).
|
|
104
|
+
* Not ask_user / awaiting — those complete the tool. Replaces ToolPause for gates.
|
|
105
|
+
*/
|
|
106
|
+
export interface ToolGate {
|
|
107
|
+
kind: ToolGateKind;
|
|
108
|
+
tool: string;
|
|
109
|
+
permission?: ToolPermission;
|
|
110
|
+
summary?: string;
|
|
111
|
+
authChallenge?: NonNullable<ToolPause['authChallenge']>;
|
|
76
112
|
}
|
|
77
113
|
export interface ToolWarning {
|
|
78
114
|
code: string;
|
|
@@ -105,22 +141,80 @@ export type ToolStreamEvent<TOut = unknown> = {
|
|
|
105
141
|
export type SyncToolHandler<TIn, TOut> = (input: TIn, ctx: ToolContext) => TOut | Promise<TOut>;
|
|
106
142
|
export type StreamToolHandler<TIn, TOut> = (input: TIn, ctx: ToolContext) => AsyncGenerator<ToolStreamEvent<TOut>>;
|
|
107
143
|
export type ToolHandler<TIn, TOut> = SyncToolHandler<TIn, TOut> | StreamToolHandler<TIn, TOut>;
|
|
108
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Host lifecycle hooks and JSON schemas shared by every kernel-executed tool.
|
|
146
|
+
*
|
|
147
|
+
* Only members that depend on `TIn` live here. `input` and `output` stay declared
|
|
148
|
+
* on each concrete tool so `TOut` is still inferred from `output` rather than from
|
|
149
|
+
* a handler's return type — moving them here silently breaks inference for stream
|
|
150
|
+
* handlers. Builtins are provider-native and do not extend this.
|
|
151
|
+
*/
|
|
152
|
+
export interface ToolHostHooks<TIn = unknown> {
|
|
153
|
+
inputSchema: Record<string, unknown>;
|
|
154
|
+
outputSchema: Record<string, unknown>;
|
|
155
|
+
/**
|
|
156
|
+
* Tool-local `pre_tool` registrant (`docs/contracts/stages.md`).
|
|
157
|
+
* Runs before host `onStage` for `pre_tool`. May return deny / confirm / mutate.
|
|
158
|
+
*/
|
|
159
|
+
preTool?: (input: TIn, ctx: ToolContext) => import('../stages.js').StageResult | undefined | Promise<import('../stages.js').StageResult | undefined>;
|
|
160
|
+
exposeToModel?: boolean;
|
|
161
|
+
}
|
|
162
|
+
export interface FunctionToolDef<TIn = unknown, TOut = unknown> extends ToolBase, ToolHostHooks<TIn> {
|
|
109
163
|
type: 'function';
|
|
110
164
|
input: z.ZodType<TIn>;
|
|
111
165
|
output: z.ZodType<TOut>;
|
|
112
|
-
inputSchema: Record<string, unknown>;
|
|
113
|
-
outputSchema: Record<string, unknown>;
|
|
114
166
|
handler: ToolHandler<TIn, TOut>;
|
|
115
|
-
interactive?: InteractiveConfig<TIn>;
|
|
116
|
-
canExecute?: (input: TIn, ctx: ToolContext) => boolean | Promise<boolean>;
|
|
117
|
-
preflight?: (input: TIn, ctx: ToolContext) => undefined | ToolFailure | ToolPause | Promise<undefined | ToolFailure | ToolPause>;
|
|
118
|
-
exposeToModel?: boolean;
|
|
119
167
|
}
|
|
120
|
-
export
|
|
168
|
+
export interface HttpToolAuthConfig {
|
|
169
|
+
slot: string;
|
|
170
|
+
type: ToolAuthType;
|
|
171
|
+
headerName?: string;
|
|
172
|
+
headerPrefix?: string;
|
|
173
|
+
onUnauthenticated?: AuthUnauthenticatedPolicy;
|
|
174
|
+
/** Pre-resolved AS/resource metadata to bypass network discovery */
|
|
175
|
+
preResolved?: {
|
|
176
|
+
issuer?: string;
|
|
177
|
+
authorizationEndpoint?: string;
|
|
178
|
+
tokenEndpoint?: string;
|
|
179
|
+
resource?: string;
|
|
180
|
+
};
|
|
181
|
+
scopes?: string[];
|
|
182
|
+
clientId?: string;
|
|
183
|
+
redirectUri?: string;
|
|
184
|
+
}
|
|
185
|
+
export interface HttpToolDef<TIn = unknown, TOut = unknown> extends ToolBase, ToolHostHooks<TIn> {
|
|
186
|
+
type: 'http';
|
|
187
|
+
input: z.ZodType<TIn>;
|
|
188
|
+
output: z.ZodType<TOut>;
|
|
189
|
+
endpoint: string;
|
|
190
|
+
method: HttpMethod;
|
|
191
|
+
headers?: Record<string, string>;
|
|
192
|
+
auth?: HttpToolAuthConfig;
|
|
193
|
+
mapping?: {
|
|
194
|
+
pathParams?: string[];
|
|
195
|
+
queryParams?: string[];
|
|
196
|
+
bodyParam?: string;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
export interface McpToolDef<TIn = unknown, TOut = unknown> extends ToolBase, ToolHostHooks<TIn> {
|
|
200
|
+
type: 'mcp';
|
|
201
|
+
input: z.ZodType<TIn>;
|
|
202
|
+
output: z.ZodType<TOut>;
|
|
203
|
+
serverUrl: string;
|
|
204
|
+
mcpToolName: string;
|
|
205
|
+
headers?: Record<string, string>;
|
|
206
|
+
auth?: HttpToolAuthConfig;
|
|
207
|
+
}
|
|
208
|
+
export type RegisteredTool<TIn = unknown, TOut = unknown> = BuiltinToolDef | FunctionToolDef<TIn, TOut> | HttpToolDef<TIn, TOut> | McpToolDef<TIn, TOut>;
|
|
121
209
|
export type ToolDefinitionInput<TIn = unknown, TOut = unknown> = BuiltinToolDef | (Omit<FunctionToolDef<TIn, TOut>, 'inputSchema' | 'outputSchema'> & {
|
|
122
210
|
input: z.ZodType<TIn>;
|
|
123
211
|
output: z.ZodType<TOut>;
|
|
212
|
+
}) | (Omit<HttpToolDef<TIn, TOut>, 'inputSchema' | 'outputSchema'> & {
|
|
213
|
+
input: z.ZodType<TIn>;
|
|
214
|
+
output: z.ZodType<TOut>;
|
|
215
|
+
}) | (Omit<McpToolDef<TIn, TOut>, 'inputSchema' | 'outputSchema'> & {
|
|
216
|
+
input: z.ZodType<TIn>;
|
|
217
|
+
output: z.ZodType<TOut>;
|
|
124
218
|
});
|
|
125
219
|
export interface WireFunctionTool {
|
|
126
220
|
type: 'function';
|
|
@@ -152,6 +246,8 @@ export interface ToolLoadContext {
|
|
|
152
246
|
sessionPermissions?: string[];
|
|
153
247
|
/** Tool ids eligible this turn. */
|
|
154
248
|
gated: ToolId[];
|
|
249
|
+
/** Opaque application context from `TurnRequest.host`; the kernel never reads it. */
|
|
250
|
+
host?: unknown;
|
|
155
251
|
}
|
|
156
252
|
/** Profile-owned T1 selection — which eligible T1 tools to wire at turn start. */
|
|
157
253
|
export type ToolPolicy = (ctx: ToolLoadContext) => ToolId[] | Promise<ToolId[]>;
|
|
@@ -166,37 +262,116 @@ export interface InvokeToolRequest {
|
|
|
166
262
|
* Host must have run tools.t2Loader (or equivalent) before listing ids here.
|
|
167
263
|
*/
|
|
168
264
|
promoted?: ToolId[];
|
|
169
|
-
/**
|
|
170
|
-
|
|
265
|
+
/** Selected model id — same as `TurnRequest.model` (builtins resolve from that model). */
|
|
266
|
+
model?: string;
|
|
171
267
|
/**
|
|
172
|
-
* Optional turn snapshot from a
|
|
268
|
+
* Optional turn snapshot from a gated turn. Cloned before use so concurrent host
|
|
173
269
|
* invokes do not share mutable visibility state.
|
|
174
270
|
*/
|
|
175
271
|
snapshot?: TurnToolSnapshot;
|
|
176
272
|
resume?: InvokeToolResume;
|
|
177
273
|
sessionPermissions?: string[];
|
|
274
|
+
/** Host credentials for authenticated HTTP / MCP tools keyed by auth slot. */
|
|
275
|
+
credentials?: Record<string, ToolCredential>;
|
|
178
276
|
path?: string;
|
|
179
277
|
signal?: AbortSignal;
|
|
278
|
+
/** Opaque application context handed to the tool as `ctx.host`; the kernel never reads it. */
|
|
279
|
+
host?: unknown;
|
|
280
|
+
/**
|
|
281
|
+
* Optional stage handler for this invoke — `pre_tool` / `post_tool` only
|
|
282
|
+
* (`docs/contracts/stages.md`).
|
|
283
|
+
*/
|
|
284
|
+
onStage?: import('../stages.js').StageHandler;
|
|
180
285
|
}
|
|
181
286
|
export interface ProfileToolsSpec {
|
|
182
|
-
/** Custom function tools this profile may run. Builtins live on
|
|
287
|
+
/** Custom function tools this profile may run. Builtins live on models.*.builtInTools. */
|
|
183
288
|
allow: ToolId[];
|
|
184
289
|
/**
|
|
185
290
|
* Optional T1 policy — returns which eligible T1 tools to wire at turn start.
|
|
186
291
|
* Tools must already be on `allow` (custom) or `builtInTools` (builtin) and `loadTier: 'T1'`.
|
|
292
|
+
* Not supported on `type: 'live'` (Gemini Live wires declarations once at session setup).
|
|
187
293
|
*/
|
|
188
294
|
t1Policy?: ToolPolicy;
|
|
189
295
|
/**
|
|
190
296
|
* Optional designated function tool id for T2 promotion.
|
|
191
297
|
* Must be in `allow`. When that tool completes with `{ loaded: string[] }`, those T2 ids are promoted.
|
|
298
|
+
* Not supported on `type: 'live'`.
|
|
192
299
|
*/
|
|
193
300
|
t2Loader?: ToolId;
|
|
194
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Live session tools — Gemini Live (and similar) fix function declarations at setup.
|
|
304
|
+
*
|
|
305
|
+
* Shape excludes `t1Policy` / `t2Loader`. Every id in `allow` (and each model's
|
|
306
|
+
* `builtInTools`) is wired at session setup regardless of `loadTier` —
|
|
307
|
+
* declarations cannot be added mid-session, so on live every allowed tool is
|
|
308
|
+
* effectively T0.
|
|
309
|
+
*/
|
|
310
|
+
export interface LiveProfileToolsSpec {
|
|
311
|
+
/** Custom tools wired once at session setup (every load tier). */
|
|
312
|
+
allow: ToolId[];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Host profile tools — the explicit ceiling for host-driven `invokeTool` calls.
|
|
316
|
+
* Every id in `allow` is executable with no visibility tiers and no path gating.
|
|
317
|
+
*/
|
|
318
|
+
export interface HostProfileToolsSpec {
|
|
319
|
+
/** Custom function tools the host may invoke. */
|
|
320
|
+
allow: ToolId[];
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* What a tool body produced, before settlement projects, guards, and runs
|
|
324
|
+
* `post_tool`. Every transport returns this; one settlement consumes it.
|
|
325
|
+
*/
|
|
326
|
+
export type ToolBodyOutcome = {
|
|
327
|
+
kind: 'ok';
|
|
328
|
+
outputRaw: unknown;
|
|
329
|
+
modelResult: ModelToolResult;
|
|
330
|
+
} | {
|
|
331
|
+
kind: 'gated';
|
|
332
|
+
gate: ToolGate;
|
|
333
|
+
} | {
|
|
334
|
+
kind: 'aborted';
|
|
335
|
+
aborted: true | {
|
|
336
|
+
reason?: string;
|
|
337
|
+
};
|
|
338
|
+
} | {
|
|
339
|
+
kind: 'failed';
|
|
340
|
+
failure: ToolFailure;
|
|
341
|
+
/** True when the body never ran. */
|
|
342
|
+
callNotStarted: boolean;
|
|
343
|
+
};
|
|
195
344
|
export interface ModelToolResult {
|
|
196
345
|
finding: string;
|
|
346
|
+
/** Lean JSON for model reasoning — must not carry media bytes. */
|
|
197
347
|
data?: unknown;
|
|
348
|
+
/**
|
|
349
|
+
* Multimodal tool-result parts (text / image / audio / video / document).
|
|
350
|
+
* Adapters wire these with the same fidelity as user input parts.
|
|
351
|
+
*/
|
|
352
|
+
parts?: InteractionPart[];
|
|
353
|
+
/**
|
|
354
|
+
* Model-facing text, already fenced and redacted at the tool boundary.
|
|
355
|
+
*
|
|
356
|
+
* Set by `executeRegisteredTool`, which knows the tool's origin and the
|
|
357
|
+
* profile's policy. `formatToolResult` prefers it; when it is absent — a host
|
|
358
|
+
* formatting a recorded result outside the execution path — that function
|
|
359
|
+
* guards the composed text itself under full detection.
|
|
360
|
+
*/
|
|
361
|
+
modelText?: string;
|
|
362
|
+
/** Where these bytes came from. Set alongside `modelText`. */
|
|
363
|
+
provenance?: Provenance;
|
|
364
|
+
/** Directive signals found in the content; raises the turn's taint. */
|
|
365
|
+
suspicious?: GuardrailHit[];
|
|
198
366
|
}
|
|
199
|
-
export type ToolCallPhase = 'running' | 'progress' | 'trace' | 'artifact' | 'warning' | 'complete'
|
|
367
|
+
export type ToolCallPhase = 'running' | 'progress' | 'trace' | 'artifact' | 'warning' | 'complete'
|
|
368
|
+
/**
|
|
369
|
+
* @deprecated Shipping interactive/confirm pause. Target: `gate` for
|
|
370
|
+
* confirm/permission/auth; awaiting is `complete` + awaiting payload.
|
|
371
|
+
*/
|
|
372
|
+
| 'pause'
|
|
373
|
+
/** pre_tool confirm / permission / auth — body did not run. */
|
|
374
|
+
| 'gate' | 'error'
|
|
200
375
|
/** Provider cancelled an in-flight tool call (e.g. live barge-in). */
|
|
201
376
|
| 'cancel';
|
|
202
377
|
export interface ToolCallEvent {
|
|
@@ -211,6 +386,9 @@ export interface ToolCallEvent {
|
|
|
211
386
|
artifact?: unknown;
|
|
212
387
|
warning?: ToolWarning;
|
|
213
388
|
output?: unknown;
|
|
389
|
+
/** @deprecated Target: `gate` for confirm/permission/auth. */
|
|
214
390
|
pause?: ToolPause;
|
|
391
|
+
/** pre_tool gate — body did not run. */
|
|
392
|
+
gate?: ToolGate;
|
|
215
393
|
failure?: ToolFailure;
|
|
216
394
|
}
|