@ai-sdk/harness 0.0.0 → 1.0.0-canary.11
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/CHANGELOG.md +87 -0
- package/LICENSE +13 -0
- package/README.md +142 -0
- package/agent/index.ts +47 -0
- package/bridge/index.ts +10 -0
- package/dist/agent/index.d.ts +1521 -0
- package/dist/agent/index.js +2958 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/bridge/index.d.ts +111 -0
- package/dist/bridge/index.js +415 -0
- package/dist/bridge/index.js.map +1 -0
- package/dist/index.d.ts +1536 -0
- package/dist/index.js +15834 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/index.d.ts +225 -0
- package/dist/utils/index.js +12148 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +99 -1
- package/src/agent/harness-agent-session.ts +509 -0
- package/src/agent/harness-agent-settings.ts +131 -0
- package/src/agent/harness-agent-tool-approval-continuation.ts +94 -0
- package/src/agent/harness-agent-types.ts +50 -0
- package/src/agent/harness-agent.ts +819 -0
- package/src/agent/internal/bootstrap-recipe.ts +124 -0
- package/src/agent/internal/bridge-port-registry.ts +52 -0
- package/src/agent/internal/harness-stream-text-result.ts +720 -0
- package/src/agent/internal/lifecycle-state-validation.ts +95 -0
- package/src/agent/internal/permission-mode.ts +50 -0
- package/src/agent/internal/resolve-observability.ts +128 -0
- package/src/agent/internal/run-prompt.ts +813 -0
- package/src/agent/internal/strip-work-dir.ts +68 -0
- package/src/agent/internal/to-harness-stream.ts +75 -0
- package/src/agent/internal/translate-stream-part.ts +221 -0
- package/src/agent/internal/turn-telemetry.ts +359 -0
- package/src/agent/observability/file-reporter.ts +206 -0
- package/src/agent/observability/index.ts +15 -0
- package/src/agent/observability/trace-tree-reporter.ts +122 -0
- package/src/agent/observability/types.ts +86 -0
- package/src/agent/prewarm.ts +47 -0
- package/src/bridge/index.ts +702 -0
- package/src/errors/harness-capability-unsupported-error.ts +41 -0
- package/src/errors/harness-error.ts +22 -0
- package/src/index.ts +3 -0
- package/src/utils/bridge-ready.ts +277 -0
- package/src/utils/classify-disk-log.ts +43 -0
- package/src/utils/index.ts +15 -0
- package/src/utils/sandbox-channel.ts +453 -0
- package/src/v1/harness-v1-bootstrap.ts +46 -0
- package/src/v1/harness-v1-bridge-protocol.ts +310 -0
- package/src/v1/harness-v1-builtin-tool.ts +138 -0
- package/src/v1/harness-v1-call-warning.ts +22 -0
- package/src/v1/harness-v1-diagnostic.ts +66 -0
- package/src/v1/harness-v1-lifecycle-state.ts +65 -0
- package/src/v1/harness-v1-metadata.ts +13 -0
- package/src/v1/harness-v1-network-sandbox-session.ts +123 -0
- package/src/v1/harness-v1-observability.ts +20 -0
- package/src/v1/harness-v1-permission-mode.ts +11 -0
- package/src/v1/harness-v1-prompt-control.ts +41 -0
- package/src/v1/harness-v1-prompt.ts +11 -0
- package/src/v1/harness-v1-sandbox-provider.ts +76 -0
- package/src/v1/harness-v1-session.ts +272 -0
- package/src/v1/harness-v1-skill.ts +36 -0
- package/src/v1/harness-v1-stream-part.ts +363 -0
- package/src/v1/harness-v1-tool-spec.ts +31 -0
- package/src/v1/harness-v1.ts +83 -0
- package/src/v1/index.ts +93 -0
- package/utils/index.ts +1 -0
|
@@ -0,0 +1,1521 @@
|
|
|
1
|
+
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
2
|
+
import { Experimental_SandboxSession, UserModelMessage, ToolSet, FlexibleSchema, Tool, ToolApprovalResponse, ModelMessage, Context } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { ToolApprovalStatus, TelemetryOptions, StreamTextResult, Agent, AgentCallParameters, GenerateTextResult, AgentStreamParameters, Telemetry } from 'ai';
|
|
4
|
+
import { z } from 'zod/v4';
|
|
5
|
+
import { JSONValue, LanguageModelV4ToolCall, LanguageModelV4ToolApprovalRequest, LanguageModelV4ToolResult, LanguageModelV4FinishReason, LanguageModelV4Usage, JSONSchema7, AISDKError } from '@ai-sdk/provider';
|
|
6
|
+
|
|
7
|
+
/** Severity of a diagnostic. */
|
|
8
|
+
type HarnessDebugLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
9
|
+
/**
|
|
10
|
+
* Consumer-facing diagnostics configuration. Set on `HarnessAgentSettings` to
|
|
11
|
+
* enable bridge log forwarding and the `HARNESS_DEBUG` stderr default in code.
|
|
12
|
+
* `HARNESS_DEBUG` / `HARNESS_DEBUG_LEVEL` / `HARNESS_DEBUG_SUBSYSTEMS` env vars
|
|
13
|
+
* fill any unset field — a convenience default, never the only path.
|
|
14
|
+
*/
|
|
15
|
+
type HarnessDebugConfig = {
|
|
16
|
+
/** Master switch. Nothing is captured or forwarded when false/unset. */
|
|
17
|
+
readonly enabled?: boolean;
|
|
18
|
+
/** Threshold; events at or above this severity are emitted. Default `debug`. */
|
|
19
|
+
readonly level?: HarnessDebugLevel;
|
|
20
|
+
/** Dotted-prefix subsystem filter for structured events. */
|
|
21
|
+
readonly subsystems?: ReadonlyArray<string>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A forwarded bridge diagnostic, normalized for host consumers.
|
|
25
|
+
*
|
|
26
|
+
* The bridge emits two raw frame kinds — captured console lines (`sandbox-log`)
|
|
27
|
+
* and structured events (`debug-event`). The framework normalizes both into
|
|
28
|
+
* this single shape before handing them to a consumer's `onLog` callback, the
|
|
29
|
+
* `HARNESS_DEBUG` stderr default, and observability reporters. Diagnostics are
|
|
30
|
+
* kept first-class and per-line — they are never folded into telemetry spans.
|
|
31
|
+
*/
|
|
32
|
+
type HarnessDiagnostic = {
|
|
33
|
+
/**
|
|
34
|
+
* Severity. Structured events carry their own level; captured console lines
|
|
35
|
+
* map `stderr` → `'warn'` and `stdout` → `'info'`.
|
|
36
|
+
*/
|
|
37
|
+
readonly level: HarnessDebugLevel;
|
|
38
|
+
/** Human-readable line (console capture) or message (structured event). */
|
|
39
|
+
readonly message: string;
|
|
40
|
+
/**
|
|
41
|
+
* Dotted subsystem. For captured console output this is
|
|
42
|
+
* `sandbox.log.<source>`; for structured events it is the adapter-supplied
|
|
43
|
+
* subsystem (e.g. `bridge.turn`).
|
|
44
|
+
*/
|
|
45
|
+
readonly subsystem: string;
|
|
46
|
+
/** `'log'` = captured console line; `'event'` = structured `bridgeLog`. */
|
|
47
|
+
readonly kind: 'log' | 'event';
|
|
48
|
+
/** Originating sandbox source label (console capture). */
|
|
49
|
+
readonly source?: string;
|
|
50
|
+
/** Which standard stream the line came from (console capture). */
|
|
51
|
+
readonly stream?: 'stdout' | 'stderr';
|
|
52
|
+
/** Structured attributes (structured events only). */
|
|
53
|
+
readonly attrs?: Record<string, unknown>;
|
|
54
|
+
/** Error payload (structured events only). */
|
|
55
|
+
readonly error?: {
|
|
56
|
+
name?: string;
|
|
57
|
+
message: string;
|
|
58
|
+
stack?: string;
|
|
59
|
+
};
|
|
60
|
+
/** The harness session this diagnostic originated from. */
|
|
61
|
+
readonly sessionId?: string;
|
|
62
|
+
/** Host receipt time (epoch ms). */
|
|
63
|
+
readonly timestamp: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A telemetry integration that also wants the per-line diagnostics stream. The
|
|
67
|
+
* framework calls `ingestDiagnostic` for every forwarded bridge diagnostic in
|
|
68
|
+
* addition to driving the standard `Telemetry` span lifecycle, so a single
|
|
69
|
+
* reporter object (e.g. `createFileReporter`) registered in
|
|
70
|
+
* `telemetry.integrations` receives both spans and logs.
|
|
71
|
+
*/
|
|
72
|
+
interface HarnessDiagnosticConsumer {
|
|
73
|
+
ingestDiagnostic?(diagnostic: HarnessDiagnostic): void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* One file to write into the sandbox as part of an adapter's bootstrap recipe.
|
|
78
|
+
* Paths should live under {@link HarnessV1Bootstrap.bootstrapDir}.
|
|
79
|
+
*/
|
|
80
|
+
interface HarnessV1BootstrapFile {
|
|
81
|
+
readonly path: string;
|
|
82
|
+
readonly content: string;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* One command to run in the sandbox as part of an adapter's bootstrap recipe.
|
|
86
|
+
* Commands run sequentially after all files have been written; a non-zero exit
|
|
87
|
+
* aborts the bootstrap.
|
|
88
|
+
*/
|
|
89
|
+
interface HarnessV1BootstrapCommand {
|
|
90
|
+
readonly command: string;
|
|
91
|
+
readonly workingDirectory?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adapter-owned bootstrap recipe. The adapter declares the files and commands
|
|
95
|
+
* needed to set up its bridge inside any sandbox. The harness framework hashes
|
|
96
|
+
* the recipe into an identity used by sandbox providers for snapshot-based
|
|
97
|
+
* reuse, and applies the recipe idempotently before the bridge spawns.
|
|
98
|
+
*/
|
|
99
|
+
interface HarnessV1Bootstrap {
|
|
100
|
+
/**
|
|
101
|
+
* Stable id of the adapter that owns this recipe. Conventionally matches
|
|
102
|
+
* {@link HarnessV1.harnessId}. Contributes to the recipe hash.
|
|
103
|
+
*/
|
|
104
|
+
readonly harnessId: string;
|
|
105
|
+
/**
|
|
106
|
+
* Absolute path inside the sandbox where this recipe writes its state.
|
|
107
|
+
* The marker file lives directly under it. Files declared in {@link files}
|
|
108
|
+
* should also use this prefix so an adapter upgrade can sweep stale state
|
|
109
|
+
* by clearing the directory.
|
|
110
|
+
*/
|
|
111
|
+
readonly bootstrapDir: string;
|
|
112
|
+
/** Files to write into the sandbox before any command runs. */
|
|
113
|
+
readonly files: ReadonlyArray<HarnessV1BootstrapFile>;
|
|
114
|
+
/** Commands to run after files are written, in order. */
|
|
115
|
+
readonly commands: ReadonlyArray<HarnessV1BootstrapCommand>;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Network sandbox session returned by `HarnessV1SandboxProvider.createSession()`. The
|
|
120
|
+
* harness keeps this for the lifetime of a session. It is itself a
|
|
121
|
+
* {@link SandboxSession} (file I/O, exec, spawn) and adds the infra surface on
|
|
122
|
+
* top: port resolution, lifecycle, and network-policy mutation.
|
|
123
|
+
*
|
|
124
|
+
* Code that should only touch the filesystem and spawn processes receives the
|
|
125
|
+
* reduced view from {@link HarnessV1NetworkSandboxSession.restricted}, never the
|
|
126
|
+
* network sandbox session itself — so it cannot stop the sandbox or change its
|
|
127
|
+
* network policy.
|
|
128
|
+
*/
|
|
129
|
+
interface HarnessV1NetworkSandboxSession extends Experimental_SandboxSession {
|
|
130
|
+
/**
|
|
131
|
+
* Stable identifier for the underlying sandbox resource. Used by the
|
|
132
|
+
* harness session manager as the durable lookup key for cross-process
|
|
133
|
+
* resume — the framework persists this on lifecycle state so a future
|
|
134
|
+
* process can call `HarnessV1SandboxProvider.resume?({ sessionId })` and
|
|
135
|
+
* reach the same resource. Providers populate it from their native
|
|
136
|
+
* identifier (Vercel: the sandbox name; just-bash: a UUID minted at
|
|
137
|
+
* create time).
|
|
138
|
+
*/
|
|
139
|
+
readonly id: string;
|
|
140
|
+
/**
|
|
141
|
+
* The sandbox's default working directory — the absolute path that
|
|
142
|
+
* `run`/`spawn` resolve relative commands against when no `workingDirectory`
|
|
143
|
+
* is given. Read from the live sandbox (it is provider-specific and
|
|
144
|
+
* configurable at create time: Vercel defaults to `/vercel/sandbox`,
|
|
145
|
+
* just-bash to `/home/user`), never hardcoded.
|
|
146
|
+
*
|
|
147
|
+
* The framework composes each session's working directory underneath this
|
|
148
|
+
* path (`<defaultWorkingDirectory>/<harnessId>-<sessionId>`) so adapters do
|
|
149
|
+
* not bake a provider-specific base into their own paths.
|
|
150
|
+
*/
|
|
151
|
+
readonly defaultWorkingDirectory: string;
|
|
152
|
+
/** Ports the sandbox exposes; resolvable to public URLs via `getPortUrl`. */
|
|
153
|
+
readonly ports: ReadonlyArray<number>;
|
|
154
|
+
/**
|
|
155
|
+
* Resolve a publicly-reachable URL for a sandbox-exposed port. Bridge-backed
|
|
156
|
+
* adapters call this to open their WebSocket to the in-sandbox bridge.
|
|
157
|
+
*/
|
|
158
|
+
readonly getPortUrl: (options: {
|
|
159
|
+
port: number;
|
|
160
|
+
protocol?: 'http' | 'https' | 'ws';
|
|
161
|
+
}) => PromiseLike<string>;
|
|
162
|
+
/** Stop the sandbox. Idempotent. */
|
|
163
|
+
readonly stop: () => PromiseLike<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Destroy/delete the sandbox resource when supported. Optional because some
|
|
166
|
+
* providers only have a stop/dispose concept. Implementations must handle
|
|
167
|
+
* both a still-running sandbox and a previously stopped sandbox.
|
|
168
|
+
*/
|
|
169
|
+
readonly destroy?: () => PromiseLike<void>;
|
|
170
|
+
/**
|
|
171
|
+
* Update the sandbox's outbound network policy. Optional — implementations
|
|
172
|
+
* without a local enforcement primitive (e.g. just-bash) omit this. Callers
|
|
173
|
+
* use optional-call (`sandboxSession.setNetworkPolicy?.(policy)`); a
|
|
174
|
+
* missing implementation is a no-op.
|
|
175
|
+
*/
|
|
176
|
+
readonly setNetworkPolicy?: (policy: HarnessV1NetworkPolicy) => PromiseLike<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Replace the set of ports exposed by the sandbox. Full-replacement
|
|
179
|
+
* semantics: ports omitted from the array are deregistered. Optional —
|
|
180
|
+
* implementations that cannot expose ports (e.g. just-bash) omit this.
|
|
181
|
+
*/
|
|
182
|
+
readonly setPorts?: (ports: ReadonlyArray<number>, options?: {
|
|
183
|
+
abortSignal?: AbortSignal;
|
|
184
|
+
}) => PromiseLike<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Reduced view of this session, typed as the bare {@link SandboxSession}
|
|
187
|
+
* (file I/O, exec, spawn) — nothing that could stop the sandbox or change
|
|
188
|
+
* its network policy. Pass this to user-tool `execute()` calls and other
|
|
189
|
+
* code that must not reach the infra surface.
|
|
190
|
+
*
|
|
191
|
+
* The returned object points at exactly the same underlying sandbox
|
|
192
|
+
* resource as the network sandbox session it was produced from; it is only a
|
|
193
|
+
* narrower surface over the same resource, not a separate sandbox.
|
|
194
|
+
*/
|
|
195
|
+
readonly restricted: () => Experimental_SandboxSession;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Outbound network policy applied by the sandbox runtime.
|
|
199
|
+
*
|
|
200
|
+
* `'allow-all'` and `'deny-all'` are convenience presets. `'custom'` is an
|
|
201
|
+
* allow-list with an optional CIDR deny-list that takes precedence:
|
|
202
|
+
*
|
|
203
|
+
* - Reachable hosts are the union of `allowedHosts` and `allowedCIDRs`.
|
|
204
|
+
* - `deniedCIDRs` wins over both, useful for blocking cloud-metadata IPs while
|
|
205
|
+
* otherwise allowing broad access.
|
|
206
|
+
*
|
|
207
|
+
* The two `'custom'` branches share the same discriminator but each requires
|
|
208
|
+
* a different allow field. Specifying `'custom'` with only `deniedCIDRs`
|
|
209
|
+
* (deny-only) is rejected at compile time — functionally it would be
|
|
210
|
+
* equivalent to `'deny-all'`.
|
|
211
|
+
*/
|
|
212
|
+
type HarnessV1NetworkPolicy = {
|
|
213
|
+
mode: 'allow-all';
|
|
214
|
+
} | {
|
|
215
|
+
mode: 'deny-all';
|
|
216
|
+
} | {
|
|
217
|
+
mode: 'custom';
|
|
218
|
+
allowedHosts: ReadonlyArray<string>;
|
|
219
|
+
allowedCIDRs?: ReadonlyArray<string>;
|
|
220
|
+
deniedCIDRs?: ReadonlyArray<string>;
|
|
221
|
+
} | {
|
|
222
|
+
mode: 'custom';
|
|
223
|
+
allowedHosts?: ReadonlyArray<string>;
|
|
224
|
+
allowedCIDRs: ReadonlyArray<string>;
|
|
225
|
+
deniedCIDRs?: ReadonlyArray<string>;
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
/** Severity of a diagnostic, ordered most → least severe. */
|
|
229
|
+
declare const harnessV1DebugLevelSchema: z.ZodEnum<{
|
|
230
|
+
error: "error";
|
|
231
|
+
warn: "warn";
|
|
232
|
+
info: "info";
|
|
233
|
+
debug: "debug";
|
|
234
|
+
trace: "trace";
|
|
235
|
+
}>;
|
|
236
|
+
type HarnessV1DebugLevel = z.infer<typeof harnessV1DebugLevelSchema>;
|
|
237
|
+
/**
|
|
238
|
+
* Per-session diagnostics configuration the framework hands an adapter (and the
|
|
239
|
+
* host sends on `start.debug`). When absent or `enabled` is false the adapter
|
|
240
|
+
* captures and emits nothing. `subsystems` filters structured events by dotted
|
|
241
|
+
* prefix; console capture is independent of the subsystem filter.
|
|
242
|
+
*/
|
|
243
|
+
declare const harnessV1DebugConfigSchema: z.ZodObject<{
|
|
244
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
245
|
+
level: z.ZodOptional<z.ZodEnum<{
|
|
246
|
+
error: "error";
|
|
247
|
+
warn: "warn";
|
|
248
|
+
info: "info";
|
|
249
|
+
debug: "debug";
|
|
250
|
+
trace: "trace";
|
|
251
|
+
}>>;
|
|
252
|
+
subsystems: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
253
|
+
}, z.core.$strip>;
|
|
254
|
+
type HarnessV1DebugConfig = z.infer<typeof harnessV1DebugConfigSchema>;
|
|
255
|
+
/**
|
|
256
|
+
* A diagnostic as emitted by a harness adapter. Structurally identical to the
|
|
257
|
+
* host-facing `HarnessDiagnostic` today, but kept separate: this is the spec's
|
|
258
|
+
* emission shape, that is the external consumption shape.
|
|
259
|
+
*/
|
|
260
|
+
type HarnessV1Diagnostic = {
|
|
261
|
+
/** Severity. */
|
|
262
|
+
readonly level: HarnessV1DebugLevel;
|
|
263
|
+
/** Human-readable line (console capture) or message (structured event). */
|
|
264
|
+
readonly message: string;
|
|
265
|
+
/** Dotted subsystem (`sandbox.log.<source>` for console capture). */
|
|
266
|
+
readonly subsystem: string;
|
|
267
|
+
/** `'log'` = captured console line; `'event'` = structured emission. */
|
|
268
|
+
readonly kind: 'log' | 'event';
|
|
269
|
+
/** Originating source label (console capture). */
|
|
270
|
+
readonly source?: string;
|
|
271
|
+
/** Which standard stream the line came from (console capture). */
|
|
272
|
+
readonly stream?: 'stdout' | 'stderr';
|
|
273
|
+
/** Structured attributes (structured events only). */
|
|
274
|
+
readonly attrs?: Record<string, unknown>;
|
|
275
|
+
/** Error payload (structured events only). */
|
|
276
|
+
readonly error?: {
|
|
277
|
+
name?: string;
|
|
278
|
+
message: string;
|
|
279
|
+
stack?: string;
|
|
280
|
+
};
|
|
281
|
+
/** The harness session this diagnostic originated from. */
|
|
282
|
+
readonly sessionId?: string;
|
|
283
|
+
/** Emission time (epoch ms). */
|
|
284
|
+
readonly timestamp: number;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Diagnostics wiring the framework hands to an adapter's `doStart`. `report` is
|
|
289
|
+
* the general emission sink: a bridge adapter normalizes each wire frame into a
|
|
290
|
+
* `HarnessV1Diagnostic` (via `harnessV1DiagnosticFromBridgeFrame`) and calls it;
|
|
291
|
+
* a non-bridge adapter constructs a `HarnessV1Diagnostic` from its host-side
|
|
292
|
+
* logs/errors and calls it directly. `debug` gates what the adapter emits.
|
|
293
|
+
* Absent when the consumer has not enabled diagnostics.
|
|
294
|
+
*/
|
|
295
|
+
type HarnessV1Observability = {
|
|
296
|
+
/** Per-session debug config gating what the adapter captures/emits. */
|
|
297
|
+
readonly debug?: HarnessV1DebugConfig;
|
|
298
|
+
/** General emission sink — any adapter reports a `HarnessV1Diagnostic` here. */
|
|
299
|
+
readonly report?: (diagnostic: HarnessV1Diagnostic) => void;
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Baseline permission mode for adapter-native built-in tools.
|
|
304
|
+
*
|
|
305
|
+
* Custom host-executed tools are not controlled by this setting. They use
|
|
306
|
+
* `HarnessAgentSettings.toolApproval`, similar to AI SDK's per-tool approval
|
|
307
|
+
* status map.
|
|
308
|
+
*/
|
|
309
|
+
type HarnessV1PermissionMode = 'allow-reads' | 'allow-edits' | 'allow-all';
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Prompt shape passed to `HarnessV1Session.doPromptTurn`.
|
|
313
|
+
*
|
|
314
|
+
* A harness session represents an ongoing third-party agent runtime that
|
|
315
|
+
* owns its own conversation history. Each prompt turn carries only the
|
|
316
|
+
* fresh user input for that turn, either as a plain string or as a single
|
|
317
|
+
* `UserModelMessage`.
|
|
318
|
+
*/
|
|
319
|
+
type HarnessV1Prompt = string | UserModelMessage;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Bidirectional control surface returned by `doPromptTurn`.
|
|
323
|
+
*
|
|
324
|
+
* The host uses these methods to feed asynchronous responses back to the
|
|
325
|
+
* adapter while a turn is running. All methods are optional except those
|
|
326
|
+
* the adapter actively supports (host-executed tools require
|
|
327
|
+
* `submitToolResult`; approvals require `submitToolApproval`; mid-turn
|
|
328
|
+
* messages require `submitUserMessage`).
|
|
329
|
+
*/
|
|
330
|
+
type HarnessV1PromptControl = {
|
|
331
|
+
/**
|
|
332
|
+
* Provide a result for a `tool-call` the adapter emitted. The adapter
|
|
333
|
+
* forwards the result to the underlying runtime so the model can continue.
|
|
334
|
+
*/
|
|
335
|
+
submitToolResult(input: {
|
|
336
|
+
toolCallId: string;
|
|
337
|
+
output: unknown;
|
|
338
|
+
isError?: boolean;
|
|
339
|
+
}): PromiseLike<void>;
|
|
340
|
+
/**
|
|
341
|
+
* Respond to a `tool-approval-request` the adapter emitted.
|
|
342
|
+
*/
|
|
343
|
+
submitToolApproval?(input: {
|
|
344
|
+
approvalId: string;
|
|
345
|
+
approved: boolean;
|
|
346
|
+
reason?: string;
|
|
347
|
+
}): PromiseLike<void>;
|
|
348
|
+
/**
|
|
349
|
+
* Inject a fresh user message into a turn that is still in flight.
|
|
350
|
+
* Supported only by runtimes that accept interactive input.
|
|
351
|
+
*/
|
|
352
|
+
submitUserMessage?(text: string): PromiseLike<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Resolves when the adapter has finished the turn (success or failure).
|
|
355
|
+
* Rejects with the underlying error when the turn fails.
|
|
356
|
+
*/
|
|
357
|
+
readonly done: PromiseLike<void>;
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
type HarnessV1PendingToolApproval = {
|
|
361
|
+
readonly approvalId: string;
|
|
362
|
+
readonly toolCallId: string;
|
|
363
|
+
readonly toolName: string;
|
|
364
|
+
readonly input: string;
|
|
365
|
+
readonly kind: 'builtin' | 'custom';
|
|
366
|
+
readonly providerExecuted?: boolean;
|
|
367
|
+
readonly nativeName?: string;
|
|
368
|
+
};
|
|
369
|
+
type HarnessV1LifecycleStateBase = {
|
|
370
|
+
/**
|
|
371
|
+
* Identifier of the harness that produced this state. Used by adapters to
|
|
372
|
+
* refuse mismatched payloads.
|
|
373
|
+
*/
|
|
374
|
+
readonly harnessId: string;
|
|
375
|
+
/**
|
|
376
|
+
* Spec version of the harness that produced this state.
|
|
377
|
+
*/
|
|
378
|
+
readonly specificationVersion: 'harness-v1';
|
|
379
|
+
/**
|
|
380
|
+
* Adapter-defined payload. May be persisted as JSON; the adapter is
|
|
381
|
+
* responsible for any necessary encoding.
|
|
382
|
+
*/
|
|
383
|
+
readonly data: JSONValue;
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Opaque payload returned by between-turn session lifecycle methods and
|
|
387
|
+
* accepted by a future `HarnessV1.doStart({ resumeFrom })` to resume the same
|
|
388
|
+
* underlying session before starting a new turn.
|
|
389
|
+
*/
|
|
390
|
+
type HarnessV1ResumeSessionState = HarnessV1LifecycleStateBase & {
|
|
391
|
+
readonly type: 'resume-session';
|
|
392
|
+
/**
|
|
393
|
+
* Optional unfinished-turn state. When present, the session must be resumed
|
|
394
|
+
* before the turn is continued.
|
|
395
|
+
*/
|
|
396
|
+
readonly continueFrom?: HarnessV1ContinueTurnState;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Opaque payload returned by `doSuspendTurn` and accepted by a future
|
|
400
|
+
* `HarnessV1.doStart({ continueFrom })` to reconnect to the same session before
|
|
401
|
+
* continuing the interrupted turn.
|
|
402
|
+
*/
|
|
403
|
+
type HarnessV1ContinueTurnState = HarnessV1LifecycleStateBase & {
|
|
404
|
+
readonly type: 'continue-turn';
|
|
405
|
+
/**
|
|
406
|
+
* Framework-owned pending approval records. These are intentionally outside
|
|
407
|
+
* adapter-defined `data` so callers can persist the entire lifecycle payload
|
|
408
|
+
* without the harness framework owning storage.
|
|
409
|
+
*/
|
|
410
|
+
readonly pendingToolApprovals?: readonly HarnessV1PendingToolApproval[];
|
|
411
|
+
};
|
|
412
|
+
type HarnessV1LifecycleState = HarnessV1ResumeSessionState | HarnessV1ContinueTurnState;
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* A self-contained instruction bundle the underlying runtime can load into
|
|
416
|
+
* its context. Adapters decide how to surface skills to the runtime.
|
|
417
|
+
*/
|
|
418
|
+
type HarnessV1Skill = {
|
|
419
|
+
/** Stable identifier for the skill (kebab-case slug). */
|
|
420
|
+
readonly name: string;
|
|
421
|
+
/**
|
|
422
|
+
* Short, model-facing description. This is what the runtime sees to
|
|
423
|
+
* decide whether the skill is relevant.
|
|
424
|
+
*/
|
|
425
|
+
readonly description: string;
|
|
426
|
+
/** Full skill content the model loads when the skill is active. */
|
|
427
|
+
readonly content: string;
|
|
428
|
+
/**
|
|
429
|
+
* Additional files that belong to this skill. Adapters with native skill
|
|
430
|
+
* directories materialize these next to `SKILL.md`; adapters without native
|
|
431
|
+
* skill files include them with the skill content.
|
|
432
|
+
*/
|
|
433
|
+
readonly files?: ReadonlyArray<HarnessV1SkillFile>;
|
|
434
|
+
};
|
|
435
|
+
type HarnessV1SkillFile = {
|
|
436
|
+
/**
|
|
437
|
+
* Skill-relative POSIX path, for example `reference.md` or
|
|
438
|
+
* `references/codes.md`. Absolute paths and `..` segments are rejected by
|
|
439
|
+
* adapters before writing.
|
|
440
|
+
*/
|
|
441
|
+
readonly path: string;
|
|
442
|
+
/** UTF-8 text content for the file. */
|
|
443
|
+
readonly content: string;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Warning emitted by a harness adapter during a call.
|
|
448
|
+
*
|
|
449
|
+
* Surfaces non-fatal issues such as unsupported options or quirks of the
|
|
450
|
+
* underlying agent runtime. Mirrors the shape of `SharedV4Warning` but lives
|
|
451
|
+
* in the harness namespace.
|
|
452
|
+
*/
|
|
453
|
+
type HarnessV1CallWarning = {
|
|
454
|
+
type: 'unsupported-setting';
|
|
455
|
+
setting: string;
|
|
456
|
+
details?: string;
|
|
457
|
+
} | {
|
|
458
|
+
type: 'unsupported-tool';
|
|
459
|
+
tool: string;
|
|
460
|
+
details?: string;
|
|
461
|
+
} | {
|
|
462
|
+
type: 'other';
|
|
463
|
+
message: string;
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Adapter-namespaced opaque data attached to harness events.
|
|
468
|
+
*
|
|
469
|
+
* Mirrors the `providerMetadata` pattern from `@ai-sdk/provider`, but lives
|
|
470
|
+
* in the harness namespace because a harness is a peer concept to a
|
|
471
|
+
* provider, not a kind of provider.
|
|
472
|
+
*
|
|
473
|
+
* Keys are harness ids (e.g. `'claude-code'`). Inner values are arbitrary
|
|
474
|
+
* JSON-serializable data the adapter chooses to surface to callers.
|
|
475
|
+
*/
|
|
476
|
+
type HarnessV1Metadata = Record<string, Record<string, JSONValue>>;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* One event emitted by a harness adapter during a prompt turn.
|
|
480
|
+
*
|
|
481
|
+
* Mirrors `LanguageModelV4StreamPart` on the variants it shares so a
|
|
482
|
+
* `HarnessAgent` can pipe events through to AI SDK consumers with minimal
|
|
483
|
+
* translation. Primitive types from the V4 spec (`LanguageModelV4ToolCall`,
|
|
484
|
+
* `LanguageModelV4ToolResult`, `LanguageModelV4ToolApprovalRequest`,
|
|
485
|
+
* `LanguageModelV4Usage`, `LanguageModelV4FinishReason`) are reused
|
|
486
|
+
* verbatim — type-compat tests assert this stays the case.
|
|
487
|
+
*
|
|
488
|
+
* The metadata field is named `harnessMetadata` (not `providerMetadata`)
|
|
489
|
+
* because a harness is a peer to a provider, not a kind of provider. The
|
|
490
|
+
* agent rebinds it when forwarding to AI SDK consumers.
|
|
491
|
+
*/
|
|
492
|
+
type HarnessV1StreamPart = {
|
|
493
|
+
type: 'stream-start';
|
|
494
|
+
warnings?: ReadonlyArray<HarnessV1CallWarning>;
|
|
495
|
+
/**
|
|
496
|
+
* The model the runtime actually resolved to for this turn, when the
|
|
497
|
+
* adapter learns it at stream start (e.g. Claude Code's `init` message
|
|
498
|
+
* reports the resolved/default model). Surfaced into telemetry as
|
|
499
|
+
* `gen_ai.request.model`. Omitted when the adapter doesn't know it here.
|
|
500
|
+
*/
|
|
501
|
+
modelId?: string;
|
|
502
|
+
} | {
|
|
503
|
+
type: 'text-start';
|
|
504
|
+
id: string;
|
|
505
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
506
|
+
} | {
|
|
507
|
+
type: 'text-delta';
|
|
508
|
+
id: string;
|
|
509
|
+
delta: string;
|
|
510
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
511
|
+
} | {
|
|
512
|
+
type: 'text-end';
|
|
513
|
+
id: string;
|
|
514
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
515
|
+
} | {
|
|
516
|
+
type: 'reasoning-start';
|
|
517
|
+
id: string;
|
|
518
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
519
|
+
} | {
|
|
520
|
+
type: 'reasoning-delta';
|
|
521
|
+
id: string;
|
|
522
|
+
delta: string;
|
|
523
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
524
|
+
} | {
|
|
525
|
+
type: 'reasoning-end';
|
|
526
|
+
id: string;
|
|
527
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
528
|
+
} | (LanguageModelV4ToolCall & {
|
|
529
|
+
nativeName?: string;
|
|
530
|
+
}) | LanguageModelV4ToolApprovalRequest | LanguageModelV4ToolResult | {
|
|
531
|
+
type: 'finish-step';
|
|
532
|
+
finishReason: LanguageModelV4FinishReason;
|
|
533
|
+
usage: LanguageModelV4Usage;
|
|
534
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
535
|
+
} | {
|
|
536
|
+
type: 'finish';
|
|
537
|
+
finishReason: LanguageModelV4FinishReason;
|
|
538
|
+
totalUsage: LanguageModelV4Usage;
|
|
539
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
540
|
+
} | {
|
|
541
|
+
type: 'file-change';
|
|
542
|
+
event: 'create' | 'modify' | 'delete';
|
|
543
|
+
path: string;
|
|
544
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
545
|
+
} | {
|
|
546
|
+
type: 'compaction';
|
|
547
|
+
trigger: 'manual' | 'auto';
|
|
548
|
+
summary: string;
|
|
549
|
+
tokensBefore?: number;
|
|
550
|
+
tokensAfter?: number;
|
|
551
|
+
harnessMetadata?: HarnessV1Metadata;
|
|
552
|
+
} | {
|
|
553
|
+
type: 'error';
|
|
554
|
+
error: unknown;
|
|
555
|
+
} | {
|
|
556
|
+
type: 'raw';
|
|
557
|
+
rawValue: unknown;
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Description of a host-defined tool that the harness should make available
|
|
562
|
+
* to the underlying agent runtime.
|
|
563
|
+
*
|
|
564
|
+
* Adapters translate this into whatever shape their runtime expects (e.g.
|
|
565
|
+
* Claude Code's tool definitions, Codex CLI's tool config, an MCP server
|
|
566
|
+
* exposed to the runtime, …). The adapter does not execute the tool; when
|
|
567
|
+
* the runtime calls it, the adapter emits a `tool-call` event and waits for
|
|
568
|
+
* `submitToolResult` from the caller.
|
|
569
|
+
*/
|
|
570
|
+
type HarnessV1ToolSpec = {
|
|
571
|
+
/**
|
|
572
|
+
* Tool name the agent runtime sees. Must match the name on incoming
|
|
573
|
+
* `tool-call` events.
|
|
574
|
+
*/
|
|
575
|
+
readonly name: string;
|
|
576
|
+
/**
|
|
577
|
+
* Human-readable description handed to the runtime, used to help the model
|
|
578
|
+
* decide when to call the tool.
|
|
579
|
+
*/
|
|
580
|
+
readonly description?: string;
|
|
581
|
+
/**
|
|
582
|
+
* JSON Schema describing the expected input for the tool. Optional because
|
|
583
|
+
* some runtimes accept tools without schemas (free-form arguments).
|
|
584
|
+
*/
|
|
585
|
+
readonly inputSchema?: JSONSchema7;
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Options passed to `HarnessV1.doStart`.
|
|
590
|
+
*
|
|
591
|
+
* `sandboxSession` and `sessionWorkDir` are coupled and always present. The
|
|
592
|
+
* framework creates the sandbox and per-session working directory before
|
|
593
|
+
* calling the adapter, so adapters never need to derive provider-specific paths.
|
|
594
|
+
*/
|
|
595
|
+
type HarnessV1StartOptions = {
|
|
596
|
+
/**
|
|
597
|
+
* Stable identifier for this harness session. Used as the underlying
|
|
598
|
+
* resource name where the adapter has a notion of a named session
|
|
599
|
+
* (sandbox name, native session id, …).
|
|
600
|
+
*/
|
|
601
|
+
readonly sessionId: string;
|
|
602
|
+
/**
|
|
603
|
+
* Skills made available to the underlying runtime for the lifetime of
|
|
604
|
+
* the session. Adapters decide how to surface them.
|
|
605
|
+
*/
|
|
606
|
+
readonly skills?: ReadonlyArray<HarnessV1Skill>;
|
|
607
|
+
/**
|
|
608
|
+
* Optional resume payload returned by a prior session lifecycle method. When
|
|
609
|
+
* provided, the adapter should resume the existing session before accepting a
|
|
610
|
+
* new prompt or continuing a nested unfinished turn.
|
|
611
|
+
*/
|
|
612
|
+
readonly resumeFrom?: HarnessV1ResumeSessionState;
|
|
613
|
+
/**
|
|
614
|
+
* Optional continuation payload returned by `doSuspendTurn`, or nested in
|
|
615
|
+
* `resumeFrom`. When provided, the adapter should resume the existing session
|
|
616
|
+
* in a shape ready for `doContinueTurn` rather than for a fresh prompt.
|
|
617
|
+
*/
|
|
618
|
+
readonly continueFrom?: HarnessV1ContinueTurnState;
|
|
619
|
+
/**
|
|
620
|
+
* Approval policy for built-in adapter-native tool use. Custom host-executed
|
|
621
|
+
* tools are approved by the framework before results are submitted back to
|
|
622
|
+
* the adapter.
|
|
623
|
+
*/
|
|
624
|
+
readonly permissionMode?: HarnessV1PermissionMode;
|
|
625
|
+
/**
|
|
626
|
+
* Signal that aborts startup. The adapter must propagate cancellation to
|
|
627
|
+
* any spawned processes or network calls.
|
|
628
|
+
*/
|
|
629
|
+
readonly abortSignal?: AbortSignal;
|
|
630
|
+
/**
|
|
631
|
+
* Diagnostics wiring. The framework populates this; the adapter only
|
|
632
|
+
* forwards `observability.onDiagnostic` into its `SandboxChannel` and
|
|
633
|
+
* `observability.debug` into the bridge `start` message. Absent when the
|
|
634
|
+
* consumer has not enabled diagnostics.
|
|
635
|
+
*/
|
|
636
|
+
readonly observability?: HarnessV1Observability;
|
|
637
|
+
/**
|
|
638
|
+
* Network sandbox session the adapter operates against. It is owned and
|
|
639
|
+
* lifecycled by `HarnessAgent`. Adapters call `restricted()` for the
|
|
640
|
+
* tool-safe filesystem/exec/spawn surface, and use the infra methods
|
|
641
|
+
* (`getPortUrl`, `ports`, `setNetworkPolicy`) for bridge wiring. Adapters
|
|
642
|
+
* must not call `stop()` themselves; the agent does that during cleanup.
|
|
643
|
+
*/
|
|
644
|
+
readonly sandboxSession: HarnessV1NetworkSandboxSession;
|
|
645
|
+
/**
|
|
646
|
+
* Absolute path the adapter runs the agent in for this session. Composed by
|
|
647
|
+
* the framework as `<sandboxSession.defaultWorkingDirectory>/<harnessId>-<sessionId>`
|
|
648
|
+
* and created before `doStart`, so the adapter uses it directly instead of
|
|
649
|
+
* deriving its own provider-specific path.
|
|
650
|
+
*/
|
|
651
|
+
readonly sessionWorkDir: string;
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* Options passed to `HarnessV1Session.doPromptTurn`.
|
|
655
|
+
*/
|
|
656
|
+
type HarnessV1PromptTurnOptions = {
|
|
657
|
+
/**
|
|
658
|
+
* Fresh input for this turn — either a plain string or a single
|
|
659
|
+
* `ModelMessage`. The harness session owns its own conversation history,
|
|
660
|
+
* so prior turns are never replayed across the contract.
|
|
661
|
+
*/
|
|
662
|
+
readonly prompt: HarnessV1Prompt;
|
|
663
|
+
/**
|
|
664
|
+
* Host-defined tools to make available to the underlying runtime for this
|
|
665
|
+
* turn. The harness emits `tool-call` events when the runtime calls one
|
|
666
|
+
* and waits for `submitToolResult`.
|
|
667
|
+
*/
|
|
668
|
+
readonly tools?: ReadonlyArray<HarnessV1ToolSpec>;
|
|
669
|
+
/**
|
|
670
|
+
* Free-form instructions for the session. The framework supplies the same
|
|
671
|
+
* value on every turn; the adapter is responsible for applying it once, by
|
|
672
|
+
* prepending it to the first user message of a fresh (non-resumed) session.
|
|
673
|
+
* On a resumed session the adapter must not re-apply it — the original first
|
|
674
|
+
* message already carried it and lives in the runtime's persisted history.
|
|
675
|
+
*/
|
|
676
|
+
readonly instructions?: string;
|
|
677
|
+
/**
|
|
678
|
+
* Signal that aborts the in-flight turn. The adapter must cancel any
|
|
679
|
+
* underlying work and resolve `done` (with an error if appropriate).
|
|
680
|
+
*/
|
|
681
|
+
readonly abortSignal?: AbortSignal;
|
|
682
|
+
/**
|
|
683
|
+
* Callback invoked once for each event the adapter produces during the
|
|
684
|
+
* turn. The adapter is responsible for the ordering and completeness of
|
|
685
|
+
* events. `done` resolves once the adapter has emitted all events for the
|
|
686
|
+
* turn (success or failure).
|
|
687
|
+
*/
|
|
688
|
+
readonly emit: (event: HarnessV1StreamPart) => void;
|
|
689
|
+
};
|
|
690
|
+
/**
|
|
691
|
+
* Options passed to `HarnessV1Session.doContinueTurn`.
|
|
692
|
+
*
|
|
693
|
+
* Unlike `doPromptTurn`, there is no `prompt`: `doContinueTurn` continues the
|
|
694
|
+
* in-flight turn rather than starting a new one. It is used to continue a turn
|
|
695
|
+
* that was previously suspended temporarily, e.g. by the workflow slice loop.
|
|
696
|
+
*/
|
|
697
|
+
type HarnessV1ContinueTurnOptions = {
|
|
698
|
+
/**
|
|
699
|
+
* Host-defined tools to make available for the continued turn. Same shape
|
|
700
|
+
* as `doPromptTurn`'s `tools`. An adapter that purely attaches to a live turn
|
|
701
|
+
* may ignore them; an adapter that re-drives the turn (rerun) needs them.
|
|
702
|
+
*/
|
|
703
|
+
readonly tools?: ReadonlyArray<HarnessV1ToolSpec>;
|
|
704
|
+
/**
|
|
705
|
+
* Signal that aborts the continued turn. The adapter must cancel any
|
|
706
|
+
* underlying work and resolve `done` (with an error if appropriate).
|
|
707
|
+
*/
|
|
708
|
+
readonly abortSignal?: AbortSignal;
|
|
709
|
+
/**
|
|
710
|
+
* Callback invoked once for each event the adapter produces while the
|
|
711
|
+
* continued turn runs. Same contract as `doPromptTurn`'s `emit`.
|
|
712
|
+
*/
|
|
713
|
+
readonly emit: (event: HarnessV1StreamPart) => void;
|
|
714
|
+
};
|
|
715
|
+
/**
|
|
716
|
+
* Active harness session, returned by `HarnessV1.doStart`.
|
|
717
|
+
*
|
|
718
|
+
* A session is the unit of state continuity across multiple prompts (one
|
|
719
|
+
* sandbox, one conversation history, one running agent runtime). The host
|
|
720
|
+
* holds onto the session across `doPromptTurn` calls and ends the local
|
|
721
|
+
* instance via `doDetach`, `doStop`, or `doDestroy`.
|
|
722
|
+
*/
|
|
723
|
+
type HarnessV1Session = {
|
|
724
|
+
/**
|
|
725
|
+
* Stable identifier for this session. Same value the host passed in via
|
|
726
|
+
* `HarnessV1StartOptions.sessionId`.
|
|
727
|
+
*/
|
|
728
|
+
readonly sessionId: string;
|
|
729
|
+
/**
|
|
730
|
+
* Whether this session was created from `resumeFrom` or `continueFrom`. Fresh
|
|
731
|
+
* sessions report `false`; resumed sessions report `true`.
|
|
732
|
+
*/
|
|
733
|
+
readonly isResume: boolean;
|
|
734
|
+
/**
|
|
735
|
+
* The model id the underlying runtime is configured to use, if the adapter
|
|
736
|
+
* knows it (e.g. from its settings). Surfaced into telemetry as
|
|
737
|
+
* `gen_ai.request.model` and the trace span labels. Omitted when the adapter
|
|
738
|
+
* defers to the runtime's own default and has no concrete id.
|
|
739
|
+
*/
|
|
740
|
+
readonly modelId?: string;
|
|
741
|
+
/**
|
|
742
|
+
* Run one prompt turn. Returns a control handle the host uses to feed
|
|
743
|
+
* tool results, approvals, and user messages back into the turn while it
|
|
744
|
+
* is in flight. The handle's `done` promise resolves when the turn ends.
|
|
745
|
+
*/
|
|
746
|
+
doPromptTurn(options: HarnessV1PromptTurnOptions): PromiseLike<HarnessV1PromptControl>;
|
|
747
|
+
/**
|
|
748
|
+
* Request that the underlying runtime compact its context. The runtime owns
|
|
749
|
+
* the compaction — the harness neither implements nor schedules it; this is
|
|
750
|
+
* only the trigger. When compaction completes, the adapter surfaces a
|
|
751
|
+
* `compaction` stream part on the next/active turn.
|
|
752
|
+
*
|
|
753
|
+
* Required, but not every runtime can honour it: adapters whose transport
|
|
754
|
+
* exposes no manual compaction (e.g. Codex over `codex exec`, which still
|
|
755
|
+
* auto-compacts on its own) throw `HarnessCapabilityUnsupportedError`.
|
|
756
|
+
* `customInstructions`, when supported, steer the compaction summary.
|
|
757
|
+
*/
|
|
758
|
+
doCompact(customInstructions?: string): PromiseLike<void>;
|
|
759
|
+
/**
|
|
760
|
+
* Continue the in-flight turn **without a new user prompt**, returning the
|
|
761
|
+
* same control surface as `doPromptTurn`. Used to keep consuming a turn that
|
|
762
|
+
* was interrupted at a process boundary (the workflow slice loop), after the
|
|
763
|
+
* session itself has been resumed via `doStart({ continueFrom })`:
|
|
764
|
+
*
|
|
765
|
+
* - When the runtime's turn is still live and reachable (bridge `attach` /
|
|
766
|
+
* `replay`), the adapter subscribes to its events and resolves `done` on
|
|
767
|
+
* the turn's `finish` — **without** re-driving it. Lossless.
|
|
768
|
+
* - When the live turn is gone (bridge respawned `rerun`, or a host-resident
|
|
769
|
+
* runtime like Pi whose turn cannot survive its process), the adapter
|
|
770
|
+
* re-drives the runtime's own thread from its persisted state. Lossy: work
|
|
771
|
+
* in flight at the interruption is recomputed.
|
|
772
|
+
*
|
|
773
|
+
* Required on every adapter. The behaviour an adapter can guarantee follows
|
|
774
|
+
* from its architecture; the contract is uniform.
|
|
775
|
+
*/
|
|
776
|
+
doContinueTurn(options: HarnessV1ContinueTurnOptions): PromiseLike<HarnessV1PromptControl>;
|
|
777
|
+
/**
|
|
778
|
+
* Gracefully freeze the active turn **at a precise cursor while keeping the
|
|
779
|
+
* runtime alive**, returning the continuation payload.
|
|
780
|
+
*
|
|
781
|
+
* This is the slice-boundary primitive. The adapter stops host-side
|
|
782
|
+
* consumption of the in-flight turn without telling the runtime to stop:
|
|
783
|
+
* for a bridge adapter it closes the host socket (the bridge keeps the turn
|
|
784
|
+
* running and accumulates events for replay) and resolves the active
|
|
785
|
+
* `doPromptTurn`/`doContinueTurn` `done` **cleanly** (not as an error) once buffered
|
|
786
|
+
* events have drained, so the cursor in the returned state equals the last
|
|
787
|
+
* event delivered to the host — guaranteeing the next slice's attach replays
|
|
788
|
+
* with no gap and no duplicate. A host-resident adapter (Pi) cannot keep its
|
|
789
|
+
* turn alive, so it persists what it can and the in-flight tail is recomputed
|
|
790
|
+
* on continue.
|
|
791
|
+
*
|
|
792
|
+
* Like `doDetach`, the sandbox/runtime is left running. Unlike `doDetach`,
|
|
793
|
+
* this is for an active turn at a slice boundary rather than a between-turn
|
|
794
|
+
* session handoff. Required on every adapter.
|
|
795
|
+
*/
|
|
796
|
+
doSuspendTurn(): PromiseLike<HarnessV1ContinueTurnState>;
|
|
797
|
+
/**
|
|
798
|
+
* Detach from the underlying runtime without tearing it down, returning a
|
|
799
|
+
* payload the host can later pass to
|
|
800
|
+
* `HarnessV1.doStart({ resumeFrom })` to reconnect before a new turn. After
|
|
801
|
+
* `doDetach`, no further methods on this session instance may be called.
|
|
802
|
+
*
|
|
803
|
+
* Required. Adapters that cannot keep a live runtime parked still return the
|
|
804
|
+
* best resume session state they can while leaving the sandbox running.
|
|
805
|
+
*/
|
|
806
|
+
doDetach(): PromiseLike<HarnessV1ResumeSessionState>;
|
|
807
|
+
/**
|
|
808
|
+
* Persist enough state to resume later, then stop the underlying runtime.
|
|
809
|
+
* After `doStop`, no further methods on this session instance may be called.
|
|
810
|
+
*/
|
|
811
|
+
doStop(): PromiseLike<HarnessV1ResumeSessionState>;
|
|
812
|
+
/**
|
|
813
|
+
* Stop the underlying runtime without returning lifecycle state. After
|
|
814
|
+
* `doDestroy`, no further methods on this session instance may be called.
|
|
815
|
+
*/
|
|
816
|
+
doDestroy(): PromiseLike<void>;
|
|
817
|
+
};
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Versioned specification for a harness adapter — the integration point for
|
|
821
|
+
* one third-party coding-agent runtime (Claude Code, Codex, …).
|
|
822
|
+
*
|
|
823
|
+
* Modelled after `LanguageModelV4`: a tagged spec version, a small set of
|
|
824
|
+
* descriptive fields, and one entry-point method (`doStart`) that yields a
|
|
825
|
+
* session. There is intentionally no static "capabilities" object —
|
|
826
|
+
* optional features are signalled by the presence or absence of optional
|
|
827
|
+
* methods on the prompt-control handle. Adapters that cannot satisfy a request
|
|
828
|
+
* (manual compaction not supported, required port exposure unavailable, …)
|
|
829
|
+
* throw `HarnessCapabilityUnsupportedError` from the method that needs the
|
|
830
|
+
* capability.
|
|
831
|
+
*/
|
|
832
|
+
type HarnessV1<TBuiltinTools extends ToolSet = ToolSet> = {
|
|
833
|
+
/**
|
|
834
|
+
* Spec version this adapter implements. Always the literal `'harness-v1'`.
|
|
835
|
+
*/
|
|
836
|
+
readonly specificationVersion: 'harness-v1';
|
|
837
|
+
/**
|
|
838
|
+
* Stable identifier for this harness, used as the key inside
|
|
839
|
+
* `HarnessV1Metadata` objects. Conventionally a kebab-case slug matching
|
|
840
|
+
* the package name (`'claude-code'`, `'codex'`).
|
|
841
|
+
*/
|
|
842
|
+
readonly harnessId: string;
|
|
843
|
+
/**
|
|
844
|
+
* Tools the adapter's underlying runtime exposes natively, as a `ToolSet`
|
|
845
|
+
* keyed by what the bridge emits on `tool-call` events
|
|
846
|
+
* (`commonName ?? nativeName`). Each entry is a `HarnessV1BuiltinTool`
|
|
847
|
+
* (a `Tool` plus harness-specific `nativeName` / `commonName` metadata).
|
|
848
|
+
*
|
|
849
|
+
* The agent merges this with consumer-supplied user tools when validating
|
|
850
|
+
* inbound tool calls and when typing the consumer-facing stream.
|
|
851
|
+
*/
|
|
852
|
+
readonly builtinTools: TBuiltinTools;
|
|
853
|
+
/**
|
|
854
|
+
* Whether the adapter can emit approval requests for built-in tools when
|
|
855
|
+
* `permissionMode` is not `'allow-all'`.
|
|
856
|
+
*
|
|
857
|
+
* Custom host-executed tool approvals are handled by `HarnessAgent`, so this
|
|
858
|
+
* only describes adapter-native tool approval support.
|
|
859
|
+
*/
|
|
860
|
+
readonly supportsBuiltinToolApprovals?: boolean;
|
|
861
|
+
/**
|
|
862
|
+
* Optional schema for the adapter-defined `data` payload returned by session
|
|
863
|
+
* lifecycle methods. When present, the adapter promises that exported state
|
|
864
|
+
* validated by this schema can be re-imported in a future
|
|
865
|
+
* `doStart({ resumeFrom })` or `doStart({ continueFrom })` call.
|
|
866
|
+
*/
|
|
867
|
+
readonly lifecycleStateSchema?: FlexibleSchema<unknown>;
|
|
868
|
+
/**
|
|
869
|
+
* Optional bootstrap recipe. When defined, the harness session manager
|
|
870
|
+
* computes a stable identity from the recipe, passes it (along with a
|
|
871
|
+
* one-time recipe-application hook) to the sandbox provider, and applies
|
|
872
|
+
* the recipe idempotently after the provider returns the handle.
|
|
873
|
+
*
|
|
874
|
+
* Adapters with no bootstrap needs omit this. Adapters that need to install
|
|
875
|
+
* deps or ship bridge files into the sandbox declare them here so the
|
|
876
|
+
* provider can cache the result across sessions via snapshots when
|
|
877
|
+
* supported.
|
|
878
|
+
*/
|
|
879
|
+
readonly getBootstrap?: (options?: {
|
|
880
|
+
abortSignal?: AbortSignal;
|
|
881
|
+
}) => PromiseLike<HarnessV1Bootstrap>;
|
|
882
|
+
/**
|
|
883
|
+
* Start a fresh session, resume a parked session via `resumeFrom`, or resume
|
|
884
|
+
* an interrupted turn via `continueFrom`. The host then issues prompts against
|
|
885
|
+
* the returned session, ending with `doDetach`, `doStop`, or `doDestroy`.
|
|
886
|
+
*/
|
|
887
|
+
doStart(options: HarnessV1StartOptions): PromiseLike<HarnessV1Session>;
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* Cross-harness vocabulary of common built-in tool names with their baseline
|
|
892
|
+
* input schemas. Adapters that declare a built-in with one of these
|
|
893
|
+
* `commonName`s must accept (at least) every input the baseline schema
|
|
894
|
+
* accepts. Extra optional fields are encouraged.
|
|
895
|
+
*
|
|
896
|
+
* Used both as runtime values (spread into `ToolSet`s for inspection) and as
|
|
897
|
+
* a vocabulary source — `HarnessV1BuiltinToolName` is derived from its keys.
|
|
898
|
+
*/
|
|
899
|
+
declare const HARNESS_V1_BUILTIN_TOOLS: {
|
|
900
|
+
readonly read: Tool<{
|
|
901
|
+
file_path: string;
|
|
902
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
903
|
+
readonly write: Tool<{
|
|
904
|
+
file_path: string;
|
|
905
|
+
content: string;
|
|
906
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
907
|
+
readonly edit: Tool<{
|
|
908
|
+
file_path: string;
|
|
909
|
+
old_string: string;
|
|
910
|
+
new_string: string;
|
|
911
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
912
|
+
readonly bash: Tool<{
|
|
913
|
+
command: string;
|
|
914
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
915
|
+
readonly grep: Tool<{
|
|
916
|
+
pattern: string;
|
|
917
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
918
|
+
readonly glob: Tool<{
|
|
919
|
+
pattern: string;
|
|
920
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
921
|
+
readonly webSearch: Tool<{
|
|
922
|
+
query: string;
|
|
923
|
+
}, unknown, _ai_sdk_provider_utils.Context>;
|
|
924
|
+
};
|
|
925
|
+
type HarnessV1BuiltinToolName = keyof typeof HARNESS_V1_BUILTIN_TOOLS;
|
|
926
|
+
type HarnessV1BuiltinToolUseKind = 'readonly' | 'edit' | 'bash';
|
|
927
|
+
/**
|
|
928
|
+
* A tool that the adapter's underlying runtime exposes natively. Extends the
|
|
929
|
+
* AI SDK `Tool` shape with two optional harness-specific fields:
|
|
930
|
+
*
|
|
931
|
+
* - `nativeName`: the name as the underlying runtime knows it. Required
|
|
932
|
+
* only when the tool's key in the harness's `builtinTools` is not the
|
|
933
|
+
* native name — i.e. when the tool maps to a `commonName` (e.g. key
|
|
934
|
+
* `'bash'` for Claude Code's native `'Bash'`). Tools without a common
|
|
935
|
+
* equivalent are keyed by their native name directly, so `nativeName`
|
|
936
|
+
* is redundant and omitted.
|
|
937
|
+
* - `commonName`: cross-harness label drawn from
|
|
938
|
+
* `HARNESS_V1_BUILTIN_TOOL_NAMES`. Set when the tool maps to a familiar
|
|
939
|
+
* capability; consumers use it to recognize, e.g., that Claude Code's
|
|
940
|
+
* `Bash` and Codex's `shell` are the same kind of tool.
|
|
941
|
+
*
|
|
942
|
+
* Always set both fields together via the `commonTool` helper, or neither
|
|
943
|
+
* (declare the tool with the AI SDK's `tool()` directly).
|
|
944
|
+
*/
|
|
945
|
+
type HarnessV1BuiltinTool<INPUT = unknown, OUTPUT = unknown> = Tool<INPUT, OUTPUT, any> & {
|
|
946
|
+
readonly nativeName?: string;
|
|
947
|
+
readonly commonName?: HarnessV1BuiltinToolName;
|
|
948
|
+
readonly toolUseKind?: HarnessV1BuiltinToolUseKind;
|
|
949
|
+
};
|
|
950
|
+
|
|
951
|
+
/**
|
|
952
|
+
* Provider that produces network sandbox sessions for harness sessions. Lives at
|
|
953
|
+
* module scope as a stable, synchronous object — analogous to
|
|
954
|
+
* `LanguageModelV4` providers, no I/O performed at construction. The actual
|
|
955
|
+
* sandbox is created (or wrapped) when `HarnessAgent` calls `createSession()`.
|
|
956
|
+
*/
|
|
957
|
+
interface HarnessV1SandboxProvider {
|
|
958
|
+
readonly specificationVersion: 'harness-sandbox-v1';
|
|
959
|
+
readonly providerId: string;
|
|
960
|
+
/**
|
|
961
|
+
* Pool of ports the consumer reserved on a caller-provided sandbox for
|
|
962
|
+
* concurrent harness sessions. The session manager leases one port per
|
|
963
|
+
* session and releases on stop or destroy.
|
|
964
|
+
*
|
|
965
|
+
* Only meaningful when the provider wraps a caller-provided sandbox
|
|
966
|
+
* (the caller pre-declared the ports). In create-new modes the provider
|
|
967
|
+
* mints a fresh sandbox per session, so no leasing is needed; providers
|
|
968
|
+
* leave this undefined.
|
|
969
|
+
*/
|
|
970
|
+
readonly bridgePorts?: ReadonlyArray<number>;
|
|
971
|
+
readonly createSession: (options?: {
|
|
972
|
+
/**
|
|
973
|
+
* Stable per-session identifier. When supplied, the provider names the
|
|
974
|
+
* underlying resource deterministically so a future call to `resume`
|
|
975
|
+
* (potentially from a different process) can find the same sandbox.
|
|
976
|
+
* Omitted from prewarm and other paths that don't need a resumable
|
|
977
|
+
* resource — in that case the provider falls back to its native
|
|
978
|
+
* auto-naming.
|
|
979
|
+
*/
|
|
980
|
+
sessionId?: string;
|
|
981
|
+
abortSignal?: AbortSignal;
|
|
982
|
+
/**
|
|
983
|
+
* Stable identity for snapshot-based reuse. Providers that support
|
|
984
|
+
* persistence/snapshots use this as part of the persistent sandbox
|
|
985
|
+
* name; subsequent calls with the same identity resume from snapshot.
|
|
986
|
+
*
|
|
987
|
+
* Ignored when the provider is wrapping a caller-provided sandbox.
|
|
988
|
+
*/
|
|
989
|
+
identity?: string;
|
|
990
|
+
/**
|
|
991
|
+
* Called exactly once per identity, on fresh creation. Snapshot-capable
|
|
992
|
+
* providers wire this into the platform's one-time-setup hook so the
|
|
993
|
+
* side effects are baked into the snapshot. Providers without snapshot
|
|
994
|
+
* support run it immediately after fresh create.
|
|
995
|
+
*
|
|
996
|
+
* Not called when the provider is wrapping a caller-provided sandbox
|
|
997
|
+
* (the caller owns the sandbox; the framework applies its own
|
|
998
|
+
* idempotent bootstrap post-create instead).
|
|
999
|
+
*/
|
|
1000
|
+
onFirstCreate?: (session: Experimental_SandboxSession, opts: {
|
|
1001
|
+
abortSignal?: AbortSignal;
|
|
1002
|
+
}) => Promise<void>;
|
|
1003
|
+
}) => PromiseLike<HarnessV1NetworkSandboxSession>;
|
|
1004
|
+
/**
|
|
1005
|
+
* Reattach to an existing sandbox previously created with the same
|
|
1006
|
+
* `sessionId`. Optional — providers that cannot rehydrate by id (e.g.
|
|
1007
|
+
* just-bash) omit this; the harness throws
|
|
1008
|
+
* `HarnessCapabilityUnsupportedError` when resume is attempted against
|
|
1009
|
+
* them.
|
|
1010
|
+
*
|
|
1011
|
+
* The provider derives the sandbox identifier from `sessionId` using the
|
|
1012
|
+
* same deterministic naming scheme it used in `createSession`. Returns a
|
|
1013
|
+
* network sandbox session bound to the existing resource.
|
|
1014
|
+
*/
|
|
1015
|
+
readonly resumeSession?: (options: {
|
|
1016
|
+
sessionId: string;
|
|
1017
|
+
abortSignal?: AbortSignal;
|
|
1018
|
+
}) => PromiseLike<HarnessV1NetworkSandboxSession>;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
type HarnessAgentAdapter<TBuiltinTools extends ToolSet = ToolSet> = HarnessV1<TBuiltinTools>;
|
|
1022
|
+
type HarnessAgentBuiltinTool<INPUT = unknown, OUTPUT = unknown> = HarnessV1BuiltinTool<INPUT, OUTPUT>;
|
|
1023
|
+
type HarnessAgentBuiltinToolName = HarnessV1BuiltinToolName;
|
|
1024
|
+
type HarnessAgentBuiltinToolUseKind = HarnessV1BuiltinToolUseKind;
|
|
1025
|
+
type HarnessAgentBuiltinTools = typeof HARNESS_V1_BUILTIN_TOOLS;
|
|
1026
|
+
type HarnessAgentStartOptions = HarnessV1StartOptions;
|
|
1027
|
+
type HarnessAgentAdapterSession = HarnessV1Session;
|
|
1028
|
+
type HarnessAgentPrompt = HarnessV1Prompt;
|
|
1029
|
+
type HarnessAgentPromptControl = HarnessV1PromptControl;
|
|
1030
|
+
type HarnessAgentPromptTurnOptions = HarnessV1PromptTurnOptions;
|
|
1031
|
+
type HarnessAgentContinueTurnOptions = HarnessV1ContinueTurnOptions;
|
|
1032
|
+
type HarnessAgentStreamPart = HarnessV1StreamPart;
|
|
1033
|
+
type HarnessAgentToolSpec = HarnessV1ToolSpec;
|
|
1034
|
+
type HarnessAgentLifecycleState = HarnessV1LifecycleState;
|
|
1035
|
+
type HarnessAgentResumeSessionState = HarnessV1ResumeSessionState;
|
|
1036
|
+
type HarnessAgentContinueTurnState = HarnessV1ContinueTurnState;
|
|
1037
|
+
type HarnessAgentPendingToolApproval = HarnessV1PendingToolApproval;
|
|
1038
|
+
type HarnessAgentSkill = HarnessV1Skill;
|
|
1039
|
+
type HarnessAgentPermissionMode = HarnessV1PermissionMode;
|
|
1040
|
+
|
|
1041
|
+
type HarnessAgentToolApprovalConfiguration = Readonly<Record<string, ToolApprovalStatus>>;
|
|
1042
|
+
/**
|
|
1043
|
+
* Construction-time settings for a `HarnessAgent`.
|
|
1044
|
+
*
|
|
1045
|
+
* Per-call settings (prompt, abortSignal, callbacks) belong on the
|
|
1046
|
+
* `AgentCallParameters` / `AgentStreamParameters` passed to `generate` /
|
|
1047
|
+
* `stream` and are not duplicated here.
|
|
1048
|
+
*/
|
|
1049
|
+
type HarnessAgentSettings<THarness extends HarnessAgentAdapter<any> = HarnessAgentAdapter, TUserTools extends ToolSet = {}> = {
|
|
1050
|
+
/**
|
|
1051
|
+
* The harness adapter driving the underlying agent runtime. Its
|
|
1052
|
+
* `builtinTools` are merged with the user-defined `tools` and exposed to
|
|
1053
|
+
* AI SDK consumers in the typed `tool-call` stream.
|
|
1054
|
+
*/
|
|
1055
|
+
readonly harness: THarness;
|
|
1056
|
+
/**
|
|
1057
|
+
* Stable identifier for this agent instance. Exposed via `agent.id`.
|
|
1058
|
+
* If omitted, `agent.id` is `undefined`.
|
|
1059
|
+
*/
|
|
1060
|
+
readonly id?: string;
|
|
1061
|
+
/**
|
|
1062
|
+
* Tools available to the underlying runtime in addition to the harness's
|
|
1063
|
+
* own builtins. The agent forwards each tool to the harness as a
|
|
1064
|
+
* `HarnessAgentToolSpec`; when the runtime calls one, the agent executes
|
|
1065
|
+
* `tool.execute()` on the host and submits the result back to the harness.
|
|
1066
|
+
*
|
|
1067
|
+
* User tools take precedence over harness builtins on key collision —
|
|
1068
|
+
* declare a tool with the same name as a builtin to override.
|
|
1069
|
+
*/
|
|
1070
|
+
readonly tools?: TUserTools;
|
|
1071
|
+
/**
|
|
1072
|
+
* Skills made available to the underlying runtime for the lifetime of
|
|
1073
|
+
* the session. Each adapter decides how to surface skills (file in the
|
|
1074
|
+
* working tree, prompt prefix, …).
|
|
1075
|
+
*/
|
|
1076
|
+
readonly skills?: ReadonlyArray<HarnessAgentSkill>;
|
|
1077
|
+
/**
|
|
1078
|
+
* Instructions for the underlying agent runtime. Adapters prepend this to
|
|
1079
|
+
* the first user message of a fresh session, once — it is not re-applied on
|
|
1080
|
+
* later turns or when resuming a previously ended session.
|
|
1081
|
+
*/
|
|
1082
|
+
readonly instructions?: string;
|
|
1083
|
+
/**
|
|
1084
|
+
* Built-in tool permission mode. Defaults to `'allow-all'`, preserving the
|
|
1085
|
+
* existing bypass-permissions behavior unless users opt in.
|
|
1086
|
+
*/
|
|
1087
|
+
readonly permissionMode?: HarnessAgentPermissionMode;
|
|
1088
|
+
/**
|
|
1089
|
+
* Per custom-tool approval statuses. This mirrors AI SDK `toolApproval`
|
|
1090
|
+
* object configuration for host-executed tools, without callback support.
|
|
1091
|
+
*
|
|
1092
|
+
* `not-applicable` and `approved` run the tool, `user-approval` pauses the
|
|
1093
|
+
* turn for a user decision, and `denied` immediately submits an
|
|
1094
|
+
* `execution-denied` result.
|
|
1095
|
+
*/
|
|
1096
|
+
readonly toolApproval?: HarnessAgentToolApprovalConfiguration;
|
|
1097
|
+
/**
|
|
1098
|
+
* Sandbox provider whose `create()` produces the network sandbox session the
|
|
1099
|
+
* harness runs against. Its `restricted()` view is also propagated to user
|
|
1100
|
+
* tool `execute()` calls (as the `experimental_sandbox` field), typed as
|
|
1101
|
+
* `Experimental_SandboxSession` so tools cannot reach the infra surface.
|
|
1102
|
+
*/
|
|
1103
|
+
readonly sandbox: HarnessV1SandboxProvider;
|
|
1104
|
+
/**
|
|
1105
|
+
* Called after each sandbox session is acquired and the session work
|
|
1106
|
+
* directory exists, before the harness adapter starts. Runs for fresh and
|
|
1107
|
+
* resumed sessions.
|
|
1108
|
+
*
|
|
1109
|
+
* Use this to write per-session config, install lightweight tools, activate
|
|
1110
|
+
* licenses, or prepare files in `sessionWorkDir`. Keep it idempotent if the
|
|
1111
|
+
* agent may resume sessions.
|
|
1112
|
+
*/
|
|
1113
|
+
readonly onSandboxSession?: (opts: {
|
|
1114
|
+
readonly session: Experimental_SandboxSession;
|
|
1115
|
+
readonly sessionWorkDir: string;
|
|
1116
|
+
readonly abortSignal?: AbortSignal;
|
|
1117
|
+
}) => Promise<void>;
|
|
1118
|
+
/**
|
|
1119
|
+
* Telemetry configuration. The harness drives AI SDK's pluggable
|
|
1120
|
+
* `Telemetry` integration contract from the turn lifecycle, so a harness turn
|
|
1121
|
+
* appears in a consumer's traces with the same span shape as `streamText`.
|
|
1122
|
+
* Register an integration here (e.g. `@ai-sdk/otel`) or globally via
|
|
1123
|
+
* `registerTelemetry`. The harness itself stays OpenTelemetry-agnostic.
|
|
1124
|
+
*/
|
|
1125
|
+
readonly telemetry?: TelemetryOptions;
|
|
1126
|
+
/**
|
|
1127
|
+
* Diagnostics configuration. Enables bridge log forwarding (sandbox
|
|
1128
|
+
* console + structured `debug-event`s) and the `HARNESS_DEBUG` stderr default.
|
|
1129
|
+
* Set `{ enabled: true }` to turn it on in code; env vars fill unset fields.
|
|
1130
|
+
*/
|
|
1131
|
+
readonly debug?: HarnessDebugConfig;
|
|
1132
|
+
/**
|
|
1133
|
+
* Programmatic sink for forwarded bridge diagnostics. Receives every
|
|
1134
|
+
* captured console line and structured event, normalized. Independent of the
|
|
1135
|
+
* stderr default — wire this to capture diagnostics in code.
|
|
1136
|
+
*/
|
|
1137
|
+
readonly onLog?: (event: HarnessDiagnostic) => void;
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
type HarnessAgentToolApprovalContinuation = {
|
|
1141
|
+
readonly approvalResponse: ToolApprovalResponse;
|
|
1142
|
+
readonly toolCall: {
|
|
1143
|
+
readonly type: 'tool-call';
|
|
1144
|
+
readonly toolCallId: string;
|
|
1145
|
+
readonly toolName: string;
|
|
1146
|
+
readonly input: unknown;
|
|
1147
|
+
readonly providerExecuted?: boolean;
|
|
1148
|
+
};
|
|
1149
|
+
};
|
|
1150
|
+
/**
|
|
1151
|
+
* Extract approval decisions that should continue a suspended harness turn.
|
|
1152
|
+
*
|
|
1153
|
+
* AI SDK clients send approval decisions as a trailing `role: "tool"` message
|
|
1154
|
+
* containing `tool-approval-response` parts. The response only carries the
|
|
1155
|
+
* approval id, so the harness has to recover the matching approval request
|
|
1156
|
+
* locally to find the original tool call before it can resume the paused turn.
|
|
1157
|
+
* Responses that already have a tool result are ignored, because those
|
|
1158
|
+
* approvals were already consumed by a prior continuation.
|
|
1159
|
+
*/
|
|
1160
|
+
declare function collectHarnessAgentToolApprovalContinuations(input: {
|
|
1161
|
+
messages: readonly ModelMessage[];
|
|
1162
|
+
}): readonly HarnessAgentToolApprovalContinuation[];
|
|
1163
|
+
|
|
1164
|
+
type HarnessAgentTurnResult<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context> = {
|
|
1165
|
+
result: StreamTextResult<TOOLS, RUNTIME_CONTEXT, never>;
|
|
1166
|
+
done: Promise<void>;
|
|
1167
|
+
};
|
|
1168
|
+
type HarnessAgentTurnState = 'idle' | 'running' | 'awaiting-approval' | 'suspended';
|
|
1169
|
+
/**
|
|
1170
|
+
* Live harness session held by the caller.
|
|
1171
|
+
*
|
|
1172
|
+
* Created by {@link import('./harness-agent').HarnessAgent.createSession}.
|
|
1173
|
+
* Owns the underlying adapter session, the network sandbox session, and the
|
|
1174
|
+
* bridge-port lease (when the provider wraps a caller-provided sandbox with a
|
|
1175
|
+
* port pool).
|
|
1176
|
+
*
|
|
1177
|
+
* Pass the instance back to `agent.generate` / `agent.stream` on every
|
|
1178
|
+
* call; end the local handle with `detach()`, `stop()`, or `destroy()`.
|
|
1179
|
+
*
|
|
1180
|
+
* After any lifecycle method has resolved, the session is unusable — any
|
|
1181
|
+
* subsequent `generate`/`stream` call against it throws.
|
|
1182
|
+
*/
|
|
1183
|
+
declare class HarnessAgentSession {
|
|
1184
|
+
/**
|
|
1185
|
+
* Stable identifier the harness adapter saw in `doStart`. The same
|
|
1186
|
+
* string callers persist when they intend to resume the session in a
|
|
1187
|
+
* future process.
|
|
1188
|
+
*/
|
|
1189
|
+
readonly sessionId: string;
|
|
1190
|
+
private readonly harness;
|
|
1191
|
+
private readonly sandboxProvider;
|
|
1192
|
+
private readonly sessionWorkDir;
|
|
1193
|
+
private underlyingSession;
|
|
1194
|
+
private sandboxSession;
|
|
1195
|
+
private leasedBridgePort;
|
|
1196
|
+
private readonly toolApproval;
|
|
1197
|
+
private readonly pendingToolApprovals;
|
|
1198
|
+
private sessionState;
|
|
1199
|
+
private turnState;
|
|
1200
|
+
private turnSequence;
|
|
1201
|
+
private activeTurnSequence;
|
|
1202
|
+
/**
|
|
1203
|
+
* Whether this session was created from `resumeFrom` or `continueFrom`.
|
|
1204
|
+
* Captured at construction so it survives lifecycle cleanup.
|
|
1205
|
+
*/
|
|
1206
|
+
readonly isResume: boolean;
|
|
1207
|
+
constructor(options: {
|
|
1208
|
+
sessionId: string;
|
|
1209
|
+
harness: HarnessAgentAdapter;
|
|
1210
|
+
underlyingSession: HarnessAgentAdapterSession;
|
|
1211
|
+
sandboxSession: HarnessV1NetworkSandboxSession;
|
|
1212
|
+
sandboxProvider: HarnessV1SandboxProvider;
|
|
1213
|
+
leasedBridgePort?: number;
|
|
1214
|
+
sessionWorkDir: string;
|
|
1215
|
+
toolApproval: HarnessAgentToolApprovalConfiguration | undefined;
|
|
1216
|
+
pendingToolApprovals?: readonly HarnessAgentPendingToolApproval[];
|
|
1217
|
+
turnState?: HarnessAgentTurnState;
|
|
1218
|
+
});
|
|
1219
|
+
promptTurn<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context>(options: {
|
|
1220
|
+
prompt: HarnessAgentPrompt;
|
|
1221
|
+
instructions: string | undefined;
|
|
1222
|
+
tools: TOOLS;
|
|
1223
|
+
toolSpecs: HarnessAgentToolSpec[];
|
|
1224
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
1225
|
+
abortSignal: AbortSignal | undefined;
|
|
1226
|
+
telemetry: TelemetryOptions | undefined;
|
|
1227
|
+
}): HarnessAgentTurnResult<TOOLS, RUNTIME_CONTEXT>;
|
|
1228
|
+
continueTurn<TOOLS extends ToolSet, RUNTIME_CONTEXT extends Context>(options: {
|
|
1229
|
+
instructions: string | undefined;
|
|
1230
|
+
tools: TOOLS;
|
|
1231
|
+
toolSpecs: HarnessAgentToolSpec[];
|
|
1232
|
+
runtimeContext: RUNTIME_CONTEXT;
|
|
1233
|
+
abortSignal: AbortSignal | undefined;
|
|
1234
|
+
telemetry: TelemetryOptions | undefined;
|
|
1235
|
+
toolApprovalContinuations?: readonly HarnessAgentToolApprovalContinuation[] | undefined;
|
|
1236
|
+
}): HarnessAgentTurnResult<TOOLS, RUNTIME_CONTEXT>;
|
|
1237
|
+
/**
|
|
1238
|
+
* Ask the underlying runtime to compact its context. The runtime performs
|
|
1239
|
+
* the compaction itself; when it completes, a `compaction` part appears on
|
|
1240
|
+
* the active (or next) turn's stream. Safe to call between turns for
|
|
1241
|
+
* runtimes whose compaction is session-scoped (e.g. Pi).
|
|
1242
|
+
*
|
|
1243
|
+
* Throws `HarnessCapabilityUnsupportedError` for harnesses that cannot
|
|
1244
|
+
* trigger compaction manually (e.g. Codex, which still auto-compacts under
|
|
1245
|
+
* the hood). Throws if the session has ended.
|
|
1246
|
+
*/
|
|
1247
|
+
compact(customInstructions?: string): Promise<void>;
|
|
1248
|
+
/**
|
|
1249
|
+
* Park the session, returning a payload the caller can persist and later
|
|
1250
|
+
* pass to `agent.createSession({ sessionId, resumeFrom })` to reconnect.
|
|
1251
|
+
* The runtime and sandbox keep running; this local session handle becomes
|
|
1252
|
+
* unusable.
|
|
1253
|
+
*/
|
|
1254
|
+
detach(): Promise<HarnessAgentResumeSessionState>;
|
|
1255
|
+
/**
|
|
1256
|
+
* Persist enough state to resume later, then stop the runtime and sandbox.
|
|
1257
|
+
* Returns the resume state for a future
|
|
1258
|
+
* `agent.createSession({ sessionId, resumeFrom })` call.
|
|
1259
|
+
*/
|
|
1260
|
+
stop(): Promise<HarnessAgentResumeSessionState>;
|
|
1261
|
+
/**
|
|
1262
|
+
* Stop the runtime and discard resumability. The sandbox is destroyed when
|
|
1263
|
+
* the provider supports destruction; otherwise it is stopped.
|
|
1264
|
+
*/
|
|
1265
|
+
destroy(): Promise<void>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Gracefully freeze the active turn at the slice boundary and return the
|
|
1268
|
+
* continuation payload, **leaving the sandbox/runtime running** so the next
|
|
1269
|
+
* process can continue. Resolves once the in-flight `stream()` /
|
|
1270
|
+
* `continueStream()` has cleanly wound down at a precise cursor (see
|
|
1271
|
+
* `doSuspendTurn`).
|
|
1272
|
+
*
|
|
1273
|
+
* After this call the session is detached. This in-process handle no
|
|
1274
|
+
* longer drives turns; a future slice creates a fresh session from the
|
|
1275
|
+
* returned state. The sandbox is **not** stopped and no port lease is
|
|
1276
|
+
* released, because bridge-backed adapters may still have a live bridge on
|
|
1277
|
+
* that port.
|
|
1278
|
+
*/
|
|
1279
|
+
suspendTurn(): Promise<HarnessAgentContinueTurnState>;
|
|
1280
|
+
private getPendingToolApprovals;
|
|
1281
|
+
private addPendingToolApprovals;
|
|
1282
|
+
private suspendCurrentTurn;
|
|
1283
|
+
private toResumeStateWithContinuation;
|
|
1284
|
+
private requirePromptableTurn;
|
|
1285
|
+
private requireContinuableTurn;
|
|
1286
|
+
private markAwaitingApprovalIfActive;
|
|
1287
|
+
private startTrackedTurn;
|
|
1288
|
+
private trackTurnCompletion;
|
|
1289
|
+
private finishTrackedTurn;
|
|
1290
|
+
private endLocalHandle;
|
|
1291
|
+
private releasePortLease;
|
|
1292
|
+
private requireReusableSession;
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/** Extract the builtin tool set type from a harness adapter parameter. */
|
|
1296
|
+
type BuiltinToolsOf<H> = H extends HarnessAgentAdapter<infer T> ? T : never;
|
|
1297
|
+
/**
|
|
1298
|
+
* Type-level merge of a harness's builtin tools with user-defined tools.
|
|
1299
|
+
* User tools override builtins on key collision.
|
|
1300
|
+
*/
|
|
1301
|
+
type HarnessAllTools<THarness extends HarnessAgentAdapter<any>, TUserTools extends ToolSet> = Omit<BuiltinToolsOf<THarness>, keyof TUserTools> & TUserTools;
|
|
1302
|
+
/**
|
|
1303
|
+
* Required `session` extension on every `HarnessAgent.generate` /
|
|
1304
|
+
* `HarnessAgent.stream` call. The agent operates exclusively on the
|
|
1305
|
+
* `HarnessAgentSession` the caller passes in — it owns no session
|
|
1306
|
+
* state of its own.
|
|
1307
|
+
*/
|
|
1308
|
+
interface HarnessAgentCallExtensions {
|
|
1309
|
+
/**
|
|
1310
|
+
* Active session returned by `agent.createSession(...)`. Drives the
|
|
1311
|
+
* underlying harness adapter for this turn.
|
|
1312
|
+
*/
|
|
1313
|
+
session: HarnessAgentSession;
|
|
1314
|
+
}
|
|
1315
|
+
/**
|
|
1316
|
+
* AI SDK `Agent` implementation that drives a third-party agent runtime
|
|
1317
|
+
* through a harness adapter (Claude Code, Codex, …).
|
|
1318
|
+
*
|
|
1319
|
+
* Behaviour summary:
|
|
1320
|
+
* - **Stateless definition.** Construct once at module scope. The agent
|
|
1321
|
+
* holds the harness adapter, the merged tool surface, the sandbox
|
|
1322
|
+
* provider and other config — never a live session. Per-call data
|
|
1323
|
+
* (prompt, abort signal, the `HarnessAgentSession`) lives on
|
|
1324
|
+
* `generate()` / `stream()`.
|
|
1325
|
+
* - **Explicit sessions.** Callers spawn sessions with
|
|
1326
|
+
* `agent.createSession(...)`, pass the returned
|
|
1327
|
+
* `HarnessAgentSession` on every `generate` / `stream`, and end it via
|
|
1328
|
+
* `session.detach()`, `session.stop()`, or `session.destroy()`.
|
|
1329
|
+
* - **Cross-process resume.** `createSession({ sessionId, resumeFrom })`
|
|
1330
|
+
* resumes from state previously returned by `session.detach()` or
|
|
1331
|
+
* `session.stop()`. The framework validates `resumeFrom` against the
|
|
1332
|
+
* harness's `lifecycleStateSchema` before handing it to the adapter.
|
|
1333
|
+
* `createSession({ sessionId, continueFrom })` resumes from state returned
|
|
1334
|
+
* by `session.suspendTurn()` before `continueStream()` /
|
|
1335
|
+
* `continueGenerate()`.
|
|
1336
|
+
* - **Host tool execution.** User tools passed in `settings.tools` are
|
|
1337
|
+
* executed on the host whenever the underlying runtime calls them;
|
|
1338
|
+
* the result is fed back to the harness via `submitToolResult`.
|
|
1339
|
+
* Adapter builtin tools (e.g. Claude Code's `Bash`) pass through
|
|
1340
|
+
* untouched.
|
|
1341
|
+
* - **Sandbox propagation.** `settings.sandbox` is a sandbox provider.
|
|
1342
|
+
* On `createSession`, the agent calls `provider.createSession()` (or
|
|
1343
|
+
* `resumeSession()`) and passes the resulting network sandbox session into
|
|
1344
|
+
* `doStart`. Its `restricted()` view (a tool-safe
|
|
1345
|
+
* `Experimental_SandboxSession`) is handed to user-tool `execute()` calls
|
|
1346
|
+
* via `experimental_sandbox`.
|
|
1347
|
+
*/
|
|
1348
|
+
declare class HarnessAgent<THarness extends HarnessAgentAdapter<any> = HarnessAgentAdapter, TUserTools extends ToolSet = {}, RUNTIME_CONTEXT extends Context = Context> implements Agent<never, HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT, never> {
|
|
1349
|
+
readonly version: "agent-v1";
|
|
1350
|
+
readonly id: string | undefined;
|
|
1351
|
+
/**
|
|
1352
|
+
* Merged tool set exposed to AI SDK consumers: harness builtins +
|
|
1353
|
+
* user-defined tools, with user tools overriding builtins on key
|
|
1354
|
+
* collision. Built once at construction time so the typed surface is
|
|
1355
|
+
* stable across calls.
|
|
1356
|
+
*/
|
|
1357
|
+
readonly tools: HarnessAllTools<THarness, TUserTools>;
|
|
1358
|
+
private readonly settings;
|
|
1359
|
+
private readonly userTools;
|
|
1360
|
+
private readonly permissionMode;
|
|
1361
|
+
constructor(settings: HarnessAgentSettings<THarness, TUserTools>);
|
|
1362
|
+
/** Identifier of the harness backing this agent. */
|
|
1363
|
+
get harnessId(): string;
|
|
1364
|
+
/**
|
|
1365
|
+
* Start a fresh session, or resume from state previously returned by
|
|
1366
|
+
* `session.detach()` or `session.stop()`. The returned
|
|
1367
|
+
* `HarnessAgentSession` must be passed to subsequent `generate` / `stream`
|
|
1368
|
+
* calls; end it with `session.detach()`, `session.stop()`, or
|
|
1369
|
+
* `session.destroy()`.
|
|
1370
|
+
*/
|
|
1371
|
+
createSession(options?: {
|
|
1372
|
+
/**
|
|
1373
|
+
* Optional stable identifier for the underlying sandbox/session.
|
|
1374
|
+
* When omitted the agent generates one. Supply the original
|
|
1375
|
+
* `session.sessionId` together with `resumeFrom` to reattach a
|
|
1376
|
+
* previously ended session across processes.
|
|
1377
|
+
*/
|
|
1378
|
+
sessionId?: string;
|
|
1379
|
+
/**
|
|
1380
|
+
* Resume payload returned by a prior `session.detach()` or
|
|
1381
|
+
* `session.stop()`. Must be accompanied by the original `sessionId`; the
|
|
1382
|
+
* framework validates it against `harness.lifecycleStateSchema` before
|
|
1383
|
+
* handing it to the adapter.
|
|
1384
|
+
*/
|
|
1385
|
+
resumeFrom?: HarnessAgentResumeSessionState;
|
|
1386
|
+
/**
|
|
1387
|
+
* Continuation payload returned by a prior `session.suspendTurn()`. Must be
|
|
1388
|
+
* accompanied by the original `sessionId`; the framework validates it before
|
|
1389
|
+
* handing it to the adapter.
|
|
1390
|
+
*/
|
|
1391
|
+
continueFrom?: HarnessAgentContinueTurnState;
|
|
1392
|
+
abortSignal?: AbortSignal;
|
|
1393
|
+
}): Promise<HarnessAgentSession>;
|
|
1394
|
+
generate(options: AgentCallParameters<never, HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT> & HarnessAgentCallExtensions): Promise<GenerateTextResult<HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT, never>>;
|
|
1395
|
+
stream(options: AgentStreamParameters<never, HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT> & HarnessAgentCallExtensions): Promise<StreamTextResult<HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT, never>>;
|
|
1396
|
+
/**
|
|
1397
|
+
* Continue the in-flight turn **without a new prompt**, draining it like
|
|
1398
|
+
* {@link generate}. Used after `createSession({ continueFrom })` to finish
|
|
1399
|
+
* consuming a turn that crossed a process boundary.
|
|
1400
|
+
*/
|
|
1401
|
+
continueGenerate(options: {
|
|
1402
|
+
session: HarnessAgentSession;
|
|
1403
|
+
toolApprovalContinuations?: readonly HarnessAgentToolApprovalContinuation[];
|
|
1404
|
+
abortSignal?: AbortSignal;
|
|
1405
|
+
}): Promise<GenerateTextResult<HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT, never>>;
|
|
1406
|
+
/**
|
|
1407
|
+
* Continue the in-flight turn **without a new prompt**, streaming its events
|
|
1408
|
+
* like {@link stream}. Used to keep consuming a turn that is still running
|
|
1409
|
+
* (or finished) in the runtime after a process boundary — the workflow slice
|
|
1410
|
+
* loop calls this on every slice after the first. Routes through the adapter's
|
|
1411
|
+
* `doContinueTurn`; what it can guarantee (lossless attach vs. lossy rerun)
|
|
1412
|
+
* follows from how the adapter resumed the session.
|
|
1413
|
+
*/
|
|
1414
|
+
continueStream(options: {
|
|
1415
|
+
session: HarnessAgentSession;
|
|
1416
|
+
toolApprovalContinuations?: readonly HarnessAgentToolApprovalContinuation[];
|
|
1417
|
+
abortSignal?: AbortSignal;
|
|
1418
|
+
}): Promise<StreamTextResult<HarnessAllTools<THarness, TUserTools>, RUNTIME_CONTEXT, never>>;
|
|
1419
|
+
private _startTurn;
|
|
1420
|
+
private _acquireSandbox;
|
|
1421
|
+
private _resolveTurnInput;
|
|
1422
|
+
private _toToolSpecs;
|
|
1423
|
+
private _toGenerateResult;
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
/**
|
|
1427
|
+
* Pre-build a harness's sandbox template without running an agent. Idempotent:
|
|
1428
|
+
* if the template already exists (snapshot present, or marker on a non-snapshot
|
|
1429
|
+
* provider), this resolves quickly.
|
|
1430
|
+
*
|
|
1431
|
+
* Use from a CI/deploy script to amortize the first-session cost so production
|
|
1432
|
+
* sessions always resume from snapshot. For adapters without a bootstrap
|
|
1433
|
+
* recipe (no `getBootstrap`) this is a no-op.
|
|
1434
|
+
*
|
|
1435
|
+
* The temporary network sandbox session created during pre-warm is stopped
|
|
1436
|
+
* before the function resolves; the snapshot/template state persists in the
|
|
1437
|
+
* provider's native storage (for Vercel: as the `currentSnapshotId` of the
|
|
1438
|
+
* named template sandbox).
|
|
1439
|
+
*/
|
|
1440
|
+
declare function prewarmHarness(options: {
|
|
1441
|
+
readonly harness: HarnessAgentAdapter;
|
|
1442
|
+
readonly sandboxProvider: HarnessV1SandboxProvider;
|
|
1443
|
+
readonly abortSignal?: AbortSignal;
|
|
1444
|
+
}): Promise<void>;
|
|
1445
|
+
|
|
1446
|
+
declare const symbol$1: unique symbol;
|
|
1447
|
+
/**
|
|
1448
|
+
* Base error type for failures originating in or signalled by a harness
|
|
1449
|
+
* adapter. Specific failure modes (e.g. unsupported capability) extend this
|
|
1450
|
+
* class.
|
|
1451
|
+
*/
|
|
1452
|
+
declare class HarnessError extends AISDKError {
|
|
1453
|
+
private readonly [symbol$1];
|
|
1454
|
+
constructor({ message, cause }: {
|
|
1455
|
+
message: string;
|
|
1456
|
+
cause?: unknown;
|
|
1457
|
+
});
|
|
1458
|
+
static isInstance(error: unknown): error is HarnessError;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
declare const symbol: unique symbol;
|
|
1462
|
+
/**
|
|
1463
|
+
* Thrown when a caller asks the harness to do something the adapter (or the
|
|
1464
|
+
* supplied sandbox) does not support, e.g. requesting manual compaction from
|
|
1465
|
+
* an adapter that only auto-compacts, or invoking `getPortUrl` on a sandbox
|
|
1466
|
+
* that does not expose one.
|
|
1467
|
+
*
|
|
1468
|
+
* The caller supplies the full human-readable message. Optional `harnessId`
|
|
1469
|
+
* is recorded as structured context for tooling.
|
|
1470
|
+
*/
|
|
1471
|
+
declare class HarnessCapabilityUnsupportedError extends HarnessError {
|
|
1472
|
+
private readonly [symbol];
|
|
1473
|
+
readonly harnessId?: string;
|
|
1474
|
+
constructor({ message, harnessId, cause, }: {
|
|
1475
|
+
message: string;
|
|
1476
|
+
harnessId?: string;
|
|
1477
|
+
cause?: unknown;
|
|
1478
|
+
});
|
|
1479
|
+
static isInstance(error: unknown): error is HarnessCapabilityUnsupportedError;
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
/**
|
|
1483
|
+
* A harness observability reporter that writes a unified, non-lossy
|
|
1484
|
+
* `events.jsonl` containing **both** the telemetry span lifecycle (turn / step
|
|
1485
|
+
* / tool) **and** the forwarded bridge diagnostics (console lines + structured
|
|
1486
|
+
* events). It is a single object registered in `telemetry.integrations`: the
|
|
1487
|
+
* framework drives its `Telemetry` methods for spans and calls
|
|
1488
|
+
* `ingestDiagnostic` for diagnostics.
|
|
1489
|
+
*
|
|
1490
|
+
* No external collector or OTel setup required — this is the AI-SDK-idiomatic
|
|
1491
|
+
* replacement for the original SDK's host-side artifact files.
|
|
1492
|
+
*/
|
|
1493
|
+
interface FileReporterOptions {
|
|
1494
|
+
/** Directory for `events.jsonl` (created if absent). */
|
|
1495
|
+
dir: string;
|
|
1496
|
+
/**
|
|
1497
|
+
* Buffer a turn's records in memory and write them only if the turn produced
|
|
1498
|
+
* an error (an `error`-level diagnostic, a failed tool, or an error finish).
|
|
1499
|
+
* Default false (write everything).
|
|
1500
|
+
*/
|
|
1501
|
+
failOnly?: boolean;
|
|
1502
|
+
/** File name within `dir`. Default `events.jsonl`. */
|
|
1503
|
+
fileName?: string;
|
|
1504
|
+
}
|
|
1505
|
+
type FileReporter = Telemetry & HarnessDiagnosticConsumer;
|
|
1506
|
+
declare function createFileReporter(options: FileReporterOptions): FileReporter;
|
|
1507
|
+
|
|
1508
|
+
/**
|
|
1509
|
+
* A harness observability reporter that renders an ASCII trace tree of a
|
|
1510
|
+
* turn's span lifecycle (turn → steps → tools) to a stream at turn end. It is a
|
|
1511
|
+
* `Telemetry` integration — register it in `telemetry.integrations`. Useful for
|
|
1512
|
+
* zero-setup local debugging when no OTel collector is wired up; a real OTel
|
|
1513
|
+
* backend (via `@ai-sdk/otel`) is a strict superset.
|
|
1514
|
+
*/
|
|
1515
|
+
interface TraceTreeReporterOptions {
|
|
1516
|
+
/** Where to write the rendered tree. Default `process.stderr.write`. */
|
|
1517
|
+
write?: (chunk: string) => void;
|
|
1518
|
+
}
|
|
1519
|
+
declare function createTraceTreeReporter(options?: TraceTreeReporterOptions): Telemetry;
|
|
1520
|
+
|
|
1521
|
+
export { type FileReporter, type FileReporterOptions, HarnessAgent, type HarnessAgentAdapter, type HarnessAgentAdapterSession, type HarnessAgentBuiltinTool, type HarnessAgentBuiltinToolName, type HarnessAgentBuiltinToolUseKind, type HarnessAgentBuiltinTools, type HarnessAgentContinueTurnOptions, type HarnessAgentContinueTurnState, type HarnessAgentLifecycleState, type HarnessAgentPendingToolApproval, type HarnessAgentPermissionMode, type HarnessAgentPrompt, type HarnessAgentPromptControl, type HarnessAgentPromptTurnOptions, type HarnessAgentResumeSessionState, HarnessAgentSession, type HarnessAgentSettings, type HarnessAgentSkill, type HarnessAgentStartOptions, type HarnessAgentStreamPart, type HarnessAgentToolApprovalConfiguration, type HarnessAgentToolApprovalContinuation, type HarnessAgentToolSpec, HarnessCapabilityUnsupportedError, type HarnessDebugConfig, type HarnessDebugLevel, type HarnessDiagnostic, type HarnessDiagnosticConsumer, HarnessError, type TraceTreeReporterOptions, collectHarnessAgentToolApprovalContinuations, createFileReporter, createTraceTreeReporter, prewarmHarness };
|