@ai-sdk/harness 1.0.133 → 1.0.134

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/dist/index.js CHANGED
@@ -1,695 +1,730 @@
1
- // src/v1/harness-v1-builtin-tool.ts
2
1
  import { tool } from "@ai-sdk/provider-utils";
3
- import { z as z2 } from "zod/v4";
4
-
5
- // src/v1/harness-v1-questions-tool.ts
6
2
  import { z } from "zod/v4";
7
- var harnessV1QuestionSchema = z.object({
8
- id: z.string().min(1),
9
- question: z.string().min(1),
10
- header: z.string().optional(),
11
- options: z.array(
12
- z.object({
13
- id: z.string().min(1),
14
- label: z.string().min(1),
15
- description: z.string().optional(),
16
- preview: z.string().optional()
17
- })
18
- ).optional(),
19
- allowMultiple: z.boolean().optional(),
20
- allowFreeForm: z.union([
21
- z.boolean(),
22
- z.object({
23
- secret: z.boolean()
24
- })
25
- ]).optional()
26
- });
27
- var harnessV1QuestionsToolInputSchema = z.object({
28
- allowPartialAnswers: z.boolean(),
29
- questions: z.array(harnessV1QuestionSchema).min(1)
30
- });
31
- var harnessV1QuestionAnswerSchema = z.object({
32
- optionIds: z.array(z.string()),
33
- freeform: z.string().optional()
34
- });
35
- var harnessV1QuestionsToolOutputSchema = z.discriminatedUnion(
36
- "action",
37
- [
38
- z.object({
39
- action: z.literal("answered"),
40
- answers: z.record(z.string(), harnessV1QuestionAnswerSchema)
41
- }),
42
- z.object({
43
- action: z.literal("partially-answered"),
44
- answers: z.record(z.string(), harnessV1QuestionAnswerSchema)
45
- }),
46
- z.object({ action: z.literal("declined") }),
47
- z.object({ action: z.literal("cancelled") })
48
- ]
49
- );
50
- var harnessV1QuestionsTool = {
51
- description: "Ask the user one or more questions",
52
- inputSchema: harnessV1QuestionsToolInputSchema,
53
- outputSchema: harnessV1QuestionsToolOutputSchema
3
+ import { posix } from "node:path";
4
+ import { AISDKError } from "@ai-sdk/provider";
5
+ //#region src/v1/harness-v1-questions-tool.ts
6
+ const harnessV1QuestionSchema = z.object({
7
+ id: z.string().min(1),
8
+ question: z.string().min(1),
9
+ header: z.string().optional(),
10
+ options: z.array(z.object({
11
+ id: z.string().min(1),
12
+ label: z.string().min(1),
13
+ description: z.string().optional(),
14
+ preview: z.string().optional()
15
+ })).optional(),
16
+ allowMultiple: z.boolean().optional(),
17
+ allowFreeForm: z.union([z.boolean(), z.object({ secret: z.boolean() })]).optional()
18
+ });
19
+ const harnessV1QuestionsToolInputSchema = z.object({
20
+ allowPartialAnswers: z.boolean(),
21
+ questions: z.array(harnessV1QuestionSchema).min(1)
22
+ });
23
+ const harnessV1QuestionAnswerSchema = z.object({
24
+ optionIds: z.array(z.string()),
25
+ freeform: z.string().optional()
26
+ });
27
+ const harnessV1QuestionsToolOutputSchema = z.discriminatedUnion("action", [
28
+ z.object({
29
+ action: z.literal("answered"),
30
+ answers: z.record(z.string(), harnessV1QuestionAnswerSchema)
31
+ }),
32
+ z.object({
33
+ action: z.literal("partially-answered"),
34
+ answers: z.record(z.string(), harnessV1QuestionAnswerSchema)
35
+ }),
36
+ z.object({ action: z.literal("declined") }),
37
+ z.object({ action: z.literal("cancelled") })
38
+ ]);
39
+ const harnessV1QuestionsTool = {
40
+ description: "Ask the user one or more questions",
41
+ inputSchema: harnessV1QuestionsToolInputSchema,
42
+ outputSchema: harnessV1QuestionsToolOutputSchema
54
43
  };
55
-
56
- // src/v1/harness-v1-builtin-tool.ts
57
- var HARNESS_V1_BUILTIN_TOOLS = {
58
- read: tool({
59
- description: "Read file contents",
60
- inputSchema: z2.object({ file_path: z2.string() }),
61
- outputSchema: z2.unknown()
62
- }),
63
- write: tool({
64
- description: "Write content to a file",
65
- inputSchema: z2.object({ file_path: z2.string(), content: z2.string() }),
66
- outputSchema: z2.unknown()
67
- }),
68
- edit: tool({
69
- description: "Edit a file by replacing text",
70
- inputSchema: z2.object({
71
- file_path: z2.string(),
72
- old_string: z2.string(),
73
- new_string: z2.string()
74
- }),
75
- outputSchema: z2.unknown()
76
- }),
77
- bash: tool({
78
- description: "Execute a shell command",
79
- inputSchema: z2.object({ command: z2.string() }),
80
- outputSchema: z2.unknown()
81
- }),
82
- grep: tool({
83
- description: "Search file contents with regex",
84
- inputSchema: z2.object({ pattern: z2.string() }),
85
- outputSchema: z2.unknown()
86
- }),
87
- glob: tool({
88
- description: "Find files matching a glob pattern",
89
- inputSchema: z2.object({ pattern: z2.string() }),
90
- outputSchema: z2.unknown()
91
- }),
92
- webSearch: tool({
93
- description: "Search the web",
94
- inputSchema: z2.object({ query: z2.string() }),
95
- outputSchema: z2.unknown()
96
- }),
97
- askUserQuestions: harnessV1QuestionsTool
44
+ //#endregion
45
+ //#region src/v1/harness-v1-builtin-tool.ts
46
+ /**
47
+ * Cross-harness vocabulary of common built-in tool names with their baseline
48
+ * input schemas. Adapters that declare a built-in with one of these
49
+ * `commonName`s must accept (at least) every input the baseline schema
50
+ * accepts. Extra optional fields are encouraged.
51
+ *
52
+ * Used both as runtime values (spread into `ToolSet`s for inspection) and as
53
+ * a vocabulary source — `HarnessV1BuiltinToolName` is derived from its keys.
54
+ */
55
+ const HARNESS_V1_BUILTIN_TOOLS = {
56
+ read: tool({
57
+ description: "Read file contents",
58
+ inputSchema: z.object({ file_path: z.string() }),
59
+ outputSchema: z.unknown()
60
+ }),
61
+ write: tool({
62
+ description: "Write content to a file",
63
+ inputSchema: z.object({
64
+ file_path: z.string(),
65
+ content: z.string()
66
+ }),
67
+ outputSchema: z.unknown()
68
+ }),
69
+ edit: tool({
70
+ description: "Edit a file by replacing text",
71
+ inputSchema: z.object({
72
+ file_path: z.string(),
73
+ old_string: z.string(),
74
+ new_string: z.string()
75
+ }),
76
+ outputSchema: z.unknown()
77
+ }),
78
+ bash: tool({
79
+ description: "Execute a shell command",
80
+ inputSchema: z.object({ command: z.string() }),
81
+ outputSchema: z.unknown()
82
+ }),
83
+ grep: tool({
84
+ description: "Search file contents with regex",
85
+ inputSchema: z.object({ pattern: z.string() }),
86
+ outputSchema: z.unknown()
87
+ }),
88
+ glob: tool({
89
+ description: "Find files matching a glob pattern",
90
+ inputSchema: z.object({ pattern: z.string() }),
91
+ outputSchema: z.unknown()
92
+ }),
93
+ webSearch: tool({
94
+ description: "Search the web",
95
+ inputSchema: z.object({ query: z.string() }),
96
+ outputSchema: z.unknown()
97
+ }),
98
+ askUserQuestions: harnessV1QuestionsTool
98
99
  };
99
- var HARNESS_V1_BUILTIN_TOOL_NAMES = Object.keys(
100
- HARNESS_V1_BUILTIN_TOOLS
101
- );
100
+ const HARNESS_V1_BUILTIN_TOOL_NAMES = Object.keys(HARNESS_V1_BUILTIN_TOOLS);
101
+ /**
102
+ * Declare a built-in tool that maps to a cross-harness common name. The
103
+ * adapter's input schema must accept every input the standard schema for
104
+ * `commonName` accepts. Extra optional fields are encouraged.
105
+ *
106
+ * If the schema is missing a field the standard requires (or has an
107
+ * incompatible type), the return type collapses to a tagged error tuple,
108
+ * which fails the surrounding `as const satisfies ToolSet` assignment and
109
+ * surfaces a readable TypeScript error at the offending entry.
110
+ */
102
111
  function commonTool(commonName, opts) {
103
- return {
104
- ...tool({
105
- description: opts.description,
106
- inputSchema: opts.inputSchema
107
- }),
108
- nativeName: opts.nativeName,
109
- commonName,
110
- toolUseKind: opts.toolUseKind
111
- };
112
+ return {
113
+ ...tool({
114
+ description: opts.description,
115
+ inputSchema: opts.inputSchema
116
+ }),
117
+ nativeName: opts.nativeName,
118
+ commonName,
119
+ toolUseKind: opts.toolUseKind
120
+ };
112
121
  }
113
-
114
- // src/v1/harness-v1-network-sandbox-session.ts
115
- import { posix } from "path";
116
- var HARNESS_V1_STATE_DIRECTORY_NAME = ".ai-sdk-harness";
117
- function harnessStateDirectoryPath({
118
- sandboxHomeDir
119
- }) {
120
- return posix.join(sandboxHomeDir, HARNESS_V1_STATE_DIRECTORY_NAME);
122
+ //#endregion
123
+ //#region src/v1/harness-v1-network-sandbox-session.ts
124
+ /**
125
+ * Fixed directory, relative to the sandbox's own HOME, that holds every
126
+ * piece of state the harness machinery generates.
127
+ */
128
+ const HARNESS_V1_STATE_DIRECTORY_NAME = ".ai-sdk-harness";
129
+ /**
130
+ * Fixed, non-configurable path for harness-generated state (bootstrap files,
131
+ * markers, and `.agent-runs`) under the sandbox's own HOME, never under
132
+ * {@link HarnessV1NetworkSandboxSession.defaultWorkingDirectory}. Resolve HOME
133
+ * with `resolveSandboxHomeDir` when it is not already known. This works from
134
+ * provider creation hooks that only have a plain sandbox session. The
135
+ * framework also calls this with a symbolic `$HOME` when hashing bootstrap
136
+ * recipes, so changes to the state path invalidate existing templates.
137
+ */
138
+ function harnessStateDirectoryPath({ sandboxHomeDir }) {
139
+ return posix.join(sandboxHomeDir, HARNESS_V1_STATE_DIRECTORY_NAME);
121
140
  }
122
-
123
- // src/v1/harness-session-data-directory-path.ts
124
- import { posix as posix2 } from "path";
141
+ //#endregion
142
+ //#region src/v1/harness-session-data-directory-path.ts
125
143
  function encodeHarnessPathSegment(value) {
126
- const encoded = encodeURIComponent(value);
127
- if (encoded === "") return "%";
128
- if (encoded === ".") return "%2E";
129
- if (encoded === "..") return "%2E%2E";
130
- return encoded;
144
+ const encoded = encodeURIComponent(value);
145
+ if (encoded === "") return "%";
146
+ if (encoded === ".") return "%2E";
147
+ if (encoded === "..") return "%2E%2E";
148
+ return encoded;
131
149
  }
132
- function harnessSessionDataDirectoryPath({
133
- stateDirectory,
134
- sessionId
135
- }) {
136
- return posix2.join(
137
- stateDirectory,
138
- ".agent-runs",
139
- encodeHarnessPathSegment(sessionId)
140
- );
150
+ /**
151
+ * Return the per-session harness state path under `.agent-runs`. Session IDs
152
+ * occupy one encoded path segment, so path separators and parent-directory
153
+ * references cannot move session data outside the harness state directory.
154
+ */
155
+ function harnessSessionDataDirectoryPath({ stateDirectory, sessionId }) {
156
+ return posix.join(stateDirectory, ".agent-runs", encodeHarnessPathSegment(sessionId));
141
157
  }
142
-
143
- // src/v1/harness-v1-stream-part.ts
144
- import { z as z3 } from "zod/v4";
145
- var harnessV1JsonValueSchema = z3.lazy(
146
- () => z3.union([
147
- z3.string(),
148
- z3.number(),
149
- z3.boolean(),
150
- z3.null(),
151
- z3.array(harnessV1JsonValueSchema),
152
- z3.record(z3.string(), harnessV1JsonValueSchema)
153
- ])
154
- );
155
- var harnessV1ToolResultValueSchema = harnessV1JsonValueSchema;
156
- var harnessV1JsonObjectSchema = z3.record(
157
- z3.string(),
158
- harnessV1JsonValueSchema
159
- );
160
- var harnessV1MetadataSchema = z3.record(
161
- z3.string(),
162
- z3.record(z3.string(), harnessV1JsonValueSchema)
163
- );
164
- var harnessV1ProviderMetadataSchema = z3.record(
165
- z3.string(),
166
- z3.record(z3.string(), harnessV1JsonValueSchema)
167
- );
168
- var harnessV1CallWarningSchema = z3.union([
169
- z3.object({
170
- type: z3.literal("unsupported-setting"),
171
- setting: z3.string(),
172
- details: z3.string().optional()
173
- }),
174
- z3.object({
175
- type: z3.literal("unsupported-tool"),
176
- tool: z3.string(),
177
- details: z3.string().optional()
178
- }),
179
- z3.object({ type: z3.literal("other"), message: z3.string() })
158
+ //#endregion
159
+ //#region src/v1/harness-v1-stream-part.ts
160
+ const harnessV1JsonValueSchema = z.lazy(() => z.union([
161
+ z.string(),
162
+ z.number(),
163
+ z.boolean(),
164
+ z.null(),
165
+ z.array(harnessV1JsonValueSchema),
166
+ z.record(z.string(), harnessV1JsonValueSchema)
167
+ ]));
168
+ const harnessV1ToolResultValueSchema = harnessV1JsonValueSchema;
169
+ const harnessV1JsonObjectSchema = z.record(z.string(), harnessV1JsonValueSchema);
170
+ const harnessV1MetadataSchema = z.record(z.string(), z.record(z.string(), harnessV1JsonValueSchema));
171
+ const harnessV1ProviderMetadataSchema = z.record(z.string(), z.record(z.string(), harnessV1JsonValueSchema));
172
+ const harnessV1CallWarningSchema = z.union([
173
+ z.object({
174
+ type: z.literal("unsupported-setting"),
175
+ setting: z.string(),
176
+ details: z.string().optional()
177
+ }),
178
+ z.object({
179
+ type: z.literal("unsupported-tool"),
180
+ tool: z.string(),
181
+ details: z.string().optional()
182
+ }),
183
+ z.object({
184
+ type: z.literal("other"),
185
+ message: z.string()
186
+ })
180
187
  ]);
181
- var harnessV1UsageSchema = z3.object({
182
- inputTokens: z3.object({
183
- total: z3.number().optional(),
184
- noCache: z3.number().optional(),
185
- cacheRead: z3.number().optional(),
186
- cacheWrite: z3.number().optional()
187
- }),
188
- outputTokens: z3.object({
189
- total: z3.number().optional(),
190
- text: z3.number().optional(),
191
- reasoning: z3.number().optional()
192
- }),
193
- raw: harnessV1JsonObjectSchema.optional()
194
- });
195
- var harnessV1FinishReasonSchema = z3.object({
196
- unified: z3.enum([
197
- "stop",
198
- "length",
199
- "content-filter",
200
- "tool-calls",
201
- "error",
202
- "other"
203
- ]),
204
- raw: z3.string().optional()
205
- });
206
- var harnessV1StreamStartPartSchema = z3.object({
207
- type: z3.literal("stream-start"),
208
- warnings: z3.array(harnessV1CallWarningSchema).readonly().optional(),
209
- modelId: z3.string().optional()
210
- });
211
- var harnessV1TextStartPartSchema = z3.object({
212
- type: z3.literal("text-start"),
213
- id: z3.string(),
214
- harnessMetadata: harnessV1MetadataSchema.optional()
215
- });
216
- var harnessV1TextDeltaPartSchema = z3.object({
217
- type: z3.literal("text-delta"),
218
- id: z3.string(),
219
- delta: z3.string(),
220
- harnessMetadata: harnessV1MetadataSchema.optional()
221
- });
222
- var harnessV1TextEndPartSchema = z3.object({
223
- type: z3.literal("text-end"),
224
- id: z3.string(),
225
- harnessMetadata: harnessV1MetadataSchema.optional()
226
- });
227
- var harnessV1ReasoningStartPartSchema = z3.object({
228
- type: z3.literal("reasoning-start"),
229
- id: z3.string(),
230
- harnessMetadata: harnessV1MetadataSchema.optional()
231
- });
232
- var harnessV1ReasoningDeltaPartSchema = z3.object({
233
- type: z3.literal("reasoning-delta"),
234
- id: z3.string(),
235
- delta: z3.string(),
236
- harnessMetadata: harnessV1MetadataSchema.optional()
237
- });
238
- var harnessV1ReasoningEndPartSchema = z3.object({
239
- type: z3.literal("reasoning-end"),
240
- id: z3.string(),
241
- harnessMetadata: harnessV1MetadataSchema.optional()
242
- });
243
- var harnessV1ToolInputStartPartSchema = z3.object({
244
- type: z3.literal("tool-input-start"),
245
- id: z3.string(),
246
- toolName: z3.string(),
247
- providerMetadata: harnessV1ProviderMetadataSchema.optional(),
248
- providerExecuted: z3.boolean().optional(),
249
- dynamic: z3.boolean().optional(),
250
- title: z3.string().optional()
251
- });
252
- var harnessV1ToolInputDeltaPartSchema = z3.object({
253
- type: z3.literal("tool-input-delta"),
254
- id: z3.string(),
255
- delta: z3.string(),
256
- providerMetadata: harnessV1ProviderMetadataSchema.optional()
257
- });
258
- var harnessV1ToolInputEndPartSchema = z3.object({
259
- type: z3.literal("tool-input-end"),
260
- id: z3.string(),
261
- providerMetadata: harnessV1ProviderMetadataSchema.optional()
262
- });
263
- var harnessV1ToolCallPartSchema = z3.object({
264
- type: z3.literal("tool-call"),
265
- toolCallId: z3.string(),
266
- toolName: z3.string(),
267
- input: z3.string(),
268
- providerExecuted: z3.boolean().optional(),
269
- dynamic: z3.boolean().optional(),
270
- providerMetadata: harnessV1ProviderMetadataSchema.optional(),
271
- nativeName: z3.string().optional(),
272
- stepToolCallCount: z3.number().int().positive().optional()
273
- });
274
- var harnessV1ToolApprovalRequestPartSchema = z3.object({
275
- type: z3.literal("tool-approval-request"),
276
- approvalId: z3.string(),
277
- toolCallId: z3.string(),
278
- providerMetadata: harnessV1ProviderMetadataSchema.optional()
279
- });
280
- var harnessV1ToolResultPartSchema = z3.object({
281
- type: z3.literal("tool-result"),
282
- toolCallId: z3.string(),
283
- toolName: z3.string(),
284
- result: harnessV1ToolResultValueSchema,
285
- isError: z3.boolean().optional(),
286
- preliminary: z3.boolean().optional(),
287
- dynamic: z3.boolean().optional(),
288
- providerMetadata: harnessV1ProviderMetadataSchema.optional()
289
- });
290
- var harnessV1FinishStepPartSchema = z3.object({
291
- type: z3.literal("finish-step"),
292
- finishReason: harnessV1FinishReasonSchema,
293
- usage: harnessV1UsageSchema,
294
- harnessMetadata: harnessV1MetadataSchema.optional()
295
- });
296
- var harnessV1FinishPartSchema = z3.object({
297
- type: z3.literal("finish"),
298
- finishReason: harnessV1FinishReasonSchema,
299
- totalUsage: harnessV1UsageSchema,
300
- harnessMetadata: harnessV1MetadataSchema.optional()
301
- });
302
- var harnessV1FileChangePartSchema = z3.object({
303
- type: z3.literal("file-change"),
304
- event: z3.enum(["create", "modify", "delete"]),
305
- path: z3.string(),
306
- harnessMetadata: harnessV1MetadataSchema.optional()
307
- });
308
- var harnessV1CompactionPartSchema = z3.object({
309
- type: z3.literal("compaction"),
310
- trigger: z3.enum(["manual", "auto"]),
311
- summary: z3.string(),
312
- tokensBefore: z3.number().optional(),
313
- tokensAfter: z3.number().optional(),
314
- harnessMetadata: harnessV1MetadataSchema.optional()
315
- });
316
- var harnessV1ErrorPartSchema = z3.object({
317
- type: z3.literal("error"),
318
- error: z3.unknown()
319
- });
320
- var harnessV1RawPartSchema = z3.object({
321
- type: z3.literal("raw"),
322
- rawValue: z3.unknown()
323
- });
324
- var harnessV1StreamPartSchema = z3.discriminatedUnion("type", [
325
- harnessV1StreamStartPartSchema,
326
- harnessV1TextStartPartSchema,
327
- harnessV1TextDeltaPartSchema,
328
- harnessV1TextEndPartSchema,
329
- harnessV1ReasoningStartPartSchema,
330
- harnessV1ReasoningDeltaPartSchema,
331
- harnessV1ReasoningEndPartSchema,
332
- harnessV1ToolInputStartPartSchema,
333
- harnessV1ToolInputDeltaPartSchema,
334
- harnessV1ToolInputEndPartSchema,
335
- harnessV1ToolCallPartSchema,
336
- harnessV1ToolApprovalRequestPartSchema,
337
- harnessV1ToolResultPartSchema,
338
- harnessV1FinishStepPartSchema,
339
- harnessV1FinishPartSchema,
340
- harnessV1FileChangePartSchema,
341
- harnessV1CompactionPartSchema,
342
- harnessV1ErrorPartSchema,
343
- harnessV1RawPartSchema
188
+ const harnessV1UsageSchema = z.object({
189
+ inputTokens: z.object({
190
+ total: z.number().optional(),
191
+ noCache: z.number().optional(),
192
+ cacheRead: z.number().optional(),
193
+ cacheWrite: z.number().optional()
194
+ }),
195
+ outputTokens: z.object({
196
+ total: z.number().optional(),
197
+ text: z.number().optional(),
198
+ reasoning: z.number().optional()
199
+ }),
200
+ raw: harnessV1JsonObjectSchema.optional()
201
+ });
202
+ const harnessV1FinishReasonSchema = z.object({
203
+ unified: z.enum([
204
+ "stop",
205
+ "length",
206
+ "content-filter",
207
+ "tool-calls",
208
+ "error",
209
+ "other"
210
+ ]),
211
+ raw: z.string().optional()
212
+ });
213
+ const harnessV1StreamStartPartSchema = z.object({
214
+ type: z.literal("stream-start"),
215
+ warnings: z.array(harnessV1CallWarningSchema).readonly().optional(),
216
+ modelId: z.string().optional()
217
+ });
218
+ const harnessV1TextStartPartSchema = z.object({
219
+ type: z.literal("text-start"),
220
+ id: z.string(),
221
+ harnessMetadata: harnessV1MetadataSchema.optional()
222
+ });
223
+ const harnessV1TextDeltaPartSchema = z.object({
224
+ type: z.literal("text-delta"),
225
+ id: z.string(),
226
+ delta: z.string(),
227
+ harnessMetadata: harnessV1MetadataSchema.optional()
228
+ });
229
+ const harnessV1TextEndPartSchema = z.object({
230
+ type: z.literal("text-end"),
231
+ id: z.string(),
232
+ harnessMetadata: harnessV1MetadataSchema.optional()
233
+ });
234
+ const harnessV1ReasoningStartPartSchema = z.object({
235
+ type: z.literal("reasoning-start"),
236
+ id: z.string(),
237
+ harnessMetadata: harnessV1MetadataSchema.optional()
238
+ });
239
+ const harnessV1ReasoningDeltaPartSchema = z.object({
240
+ type: z.literal("reasoning-delta"),
241
+ id: z.string(),
242
+ delta: z.string(),
243
+ harnessMetadata: harnessV1MetadataSchema.optional()
244
+ });
245
+ const harnessV1ReasoningEndPartSchema = z.object({
246
+ type: z.literal("reasoning-end"),
247
+ id: z.string(),
248
+ harnessMetadata: harnessV1MetadataSchema.optional()
249
+ });
250
+ const harnessV1ToolInputStartPartSchema = z.object({
251
+ type: z.literal("tool-input-start"),
252
+ id: z.string(),
253
+ toolName: z.string(),
254
+ providerMetadata: harnessV1ProviderMetadataSchema.optional(),
255
+ providerExecuted: z.boolean().optional(),
256
+ dynamic: z.boolean().optional(),
257
+ title: z.string().optional()
258
+ });
259
+ const harnessV1ToolInputDeltaPartSchema = z.object({
260
+ type: z.literal("tool-input-delta"),
261
+ id: z.string(),
262
+ delta: z.string(),
263
+ providerMetadata: harnessV1ProviderMetadataSchema.optional()
264
+ });
265
+ const harnessV1ToolInputEndPartSchema = z.object({
266
+ type: z.literal("tool-input-end"),
267
+ id: z.string(),
268
+ providerMetadata: harnessV1ProviderMetadataSchema.optional()
269
+ });
270
+ const harnessV1ToolCallPartSchema = z.object({
271
+ type: z.literal("tool-call"),
272
+ toolCallId: z.string(),
273
+ toolName: z.string(),
274
+ input: z.string(),
275
+ providerExecuted: z.boolean().optional(),
276
+ dynamic: z.boolean().optional(),
277
+ providerMetadata: harnessV1ProviderMetadataSchema.optional(),
278
+ nativeName: z.string().optional(),
279
+ stepToolCallCount: z.number().int().positive().optional()
280
+ });
281
+ const harnessV1ToolApprovalRequestPartSchema = z.object({
282
+ type: z.literal("tool-approval-request"),
283
+ approvalId: z.string(),
284
+ toolCallId: z.string(),
285
+ providerMetadata: harnessV1ProviderMetadataSchema.optional()
286
+ });
287
+ const harnessV1ToolResultPartSchema = z.object({
288
+ type: z.literal("tool-result"),
289
+ toolCallId: z.string(),
290
+ toolName: z.string(),
291
+ result: harnessV1ToolResultValueSchema,
292
+ isError: z.boolean().optional(),
293
+ preliminary: z.boolean().optional(),
294
+ dynamic: z.boolean().optional(),
295
+ providerMetadata: harnessV1ProviderMetadataSchema.optional()
296
+ });
297
+ const harnessV1FinishStepPartSchema = z.object({
298
+ type: z.literal("finish-step"),
299
+ finishReason: harnessV1FinishReasonSchema,
300
+ usage: harnessV1UsageSchema,
301
+ harnessMetadata: harnessV1MetadataSchema.optional()
302
+ });
303
+ const harnessV1FinishPartSchema = z.object({
304
+ type: z.literal("finish"),
305
+ finishReason: harnessV1FinishReasonSchema,
306
+ totalUsage: harnessV1UsageSchema,
307
+ harnessMetadata: harnessV1MetadataSchema.optional()
308
+ });
309
+ const harnessV1FileChangePartSchema = z.object({
310
+ type: z.literal("file-change"),
311
+ event: z.enum([
312
+ "create",
313
+ "modify",
314
+ "delete"
315
+ ]),
316
+ path: z.string(),
317
+ harnessMetadata: harnessV1MetadataSchema.optional()
318
+ });
319
+ const harnessV1CompactionPartSchema = z.object({
320
+ type: z.literal("compaction"),
321
+ trigger: z.enum(["manual", "auto"]),
322
+ summary: z.string(),
323
+ tokensBefore: z.number().optional(),
324
+ tokensAfter: z.number().optional(),
325
+ harnessMetadata: harnessV1MetadataSchema.optional()
326
+ });
327
+ const harnessV1ErrorPartSchema = z.object({
328
+ type: z.literal("error"),
329
+ error: z.unknown()
330
+ });
331
+ const harnessV1RawPartSchema = z.object({
332
+ type: z.literal("raw"),
333
+ rawValue: z.unknown()
334
+ });
335
+ /**
336
+ * Assembled discriminated union over every `HarnessV1StreamPart` variant. Left
337
+ * un-annotated so it keeps its precise inferred type — the protocol layer
338
+ * composes the individual member schemas, and the type test asserts the
339
+ * inferred union equals `HarnessV1StreamPart`.
340
+ */
341
+ const harnessV1StreamPartSchema = z.discriminatedUnion("type", [
342
+ harnessV1StreamStartPartSchema,
343
+ harnessV1TextStartPartSchema,
344
+ harnessV1TextDeltaPartSchema,
345
+ harnessV1TextEndPartSchema,
346
+ harnessV1ReasoningStartPartSchema,
347
+ harnessV1ReasoningDeltaPartSchema,
348
+ harnessV1ReasoningEndPartSchema,
349
+ harnessV1ToolInputStartPartSchema,
350
+ harnessV1ToolInputDeltaPartSchema,
351
+ harnessV1ToolInputEndPartSchema,
352
+ harnessV1ToolCallPartSchema,
353
+ harnessV1ToolApprovalRequestPartSchema,
354
+ harnessV1ToolResultPartSchema,
355
+ harnessV1FinishStepPartSchema,
356
+ harnessV1FinishPartSchema,
357
+ harnessV1FileChangePartSchema,
358
+ harnessV1CompactionPartSchema,
359
+ harnessV1ErrorPartSchema,
360
+ harnessV1RawPartSchema
344
361
  ]);
345
-
346
- // src/v1/harness-v1-bridge-protocol.ts
347
- import { z as z5 } from "zod/v4";
348
-
349
- // src/v1/harness-v1-diagnostic.ts
350
- import { z as z4 } from "zod/v4";
351
- var harnessV1DebugLevelSchema = z4.enum([
352
- "error",
353
- "warn",
354
- "info",
355
- "debug",
356
- "trace"
362
+ //#endregion
363
+ //#region src/v1/harness-v1-diagnostic.ts
364
+ /** Severity of a diagnostic, ordered most → least severe. */
365
+ const harnessV1DebugLevelSchema = z.enum([
366
+ "error",
367
+ "warn",
368
+ "info",
369
+ "debug",
370
+ "trace"
357
371
  ]);
358
- var harnessV1DebugConfigSchema = z4.object({
359
- enabled: z4.boolean().optional(),
360
- level: harnessV1DebugLevelSchema.optional(),
361
- subsystems: z4.array(z4.string()).optional()
362
- });
363
-
364
- // src/v1/harness-v1-bridge-protocol.ts
365
- var harnessV1BridgeToolWireSchema = z5.object({
366
- name: z5.string(),
367
- description: z5.string().optional(),
368
- inputSchema: z5.unknown().optional()
369
- });
370
- var harnessV1BridgePermissionModeSchema = z5.enum([
371
- "allow-reads",
372
- "allow-edits",
373
- "allow-all"
372
+ /**
373
+ * Per-session diagnostics configuration the framework hands an adapter (and the
374
+ * host sends on `start.debug`). When absent or `enabled` is false the adapter
375
+ * captures and emits nothing. `subsystems` filters structured events by dotted
376
+ * prefix; console capture is independent of the subsystem filter.
377
+ */
378
+ const harnessV1DebugConfigSchema = z.object({
379
+ enabled: z.boolean().optional(),
380
+ level: harnessV1DebugLevelSchema.optional(),
381
+ subsystems: z.array(z.string()).optional()
382
+ });
383
+ //#endregion
384
+ //#region src/v1/harness-v1-bridge-protocol.ts
385
+ /**
386
+ * The subset of a host-defined tool that travels on the `start` message. The
387
+ * runtime only needs the name, description, and JSON-Schema input to surface
388
+ * the tool; `execute` stays on the host.
389
+ */
390
+ const harnessV1BridgeToolWireSchema = z.object({
391
+ name: z.string(),
392
+ description: z.string().optional(),
393
+ inputSchema: z.unknown().optional()
394
+ });
395
+ const harnessV1BridgePermissionModeSchema = z.enum([
396
+ "allow-reads",
397
+ "allow-edits",
398
+ "allow-all"
374
399
  ]);
375
- var harnessV1BridgeBuiltinToolFilteringSchema = z5.discriminatedUnion(
376
- "mode",
377
- [
378
- z5.object({
379
- mode: z5.literal("allow"),
380
- toolNames: z5.array(z5.string())
381
- }),
382
- z5.object({
383
- mode: z5.literal("deny"),
384
- toolNames: z5.array(z5.string())
385
- })
386
- ]
387
- );
388
- var harnessV1BridgeResponseFormatSchema = z5.discriminatedUnion("type", [
389
- z5.object({ type: z5.literal("text") }),
390
- z5.object({
391
- type: z5.literal("json"),
392
- schema: z5.record(z5.string(), z5.json()).optional(),
393
- name: z5.string().optional(),
394
- description: z5.string().optional()
395
- })
400
+ const harnessV1BridgeBuiltinToolFilteringSchema = z.discriminatedUnion("mode", [z.object({
401
+ mode: z.literal("allow"),
402
+ toolNames: z.array(z.string())
403
+ }), z.object({
404
+ mode: z.literal("deny"),
405
+ toolNames: z.array(z.string())
406
+ })]);
407
+ const harnessV1BridgeResponseFormatSchema = z.discriminatedUnion("type", [z.object({ type: z.literal("text") }), z.object({
408
+ type: z.literal("json"),
409
+ schema: z.record(z.string(), z.json()).optional(),
410
+ name: z.string().optional(),
411
+ description: z.string().optional()
412
+ })]);
413
+ /**
414
+ * Common fields of the inbound `start` message. Each adapter extends this with
415
+ * its runtime-specific configuration (e.g. `thinking`/`continue` for Claude
416
+ * Code, `reasoningEffort`/`webSearch`/`skills`/`resumeThreadId` for Codex) and
417
+ * assembles the final inbound union from the shared command members below.
418
+ *
419
+ * `debug` carries the general `HarnessV1DebugConfig` — diagnostics config is not
420
+ * a bridge concept, it just happens to ride the `start` frame for bridge-backed
421
+ * adapters.
422
+ */
423
+ const harnessV1BridgeStartBaseSchema = z.object({
424
+ type: z.literal("start"),
425
+ prompt: z.string(),
426
+ tools: z.array(harnessV1BridgeToolWireSchema).optional(),
427
+ model: z.string().optional(),
428
+ debug: harnessV1DebugConfigSchema.optional(),
429
+ permissionMode: harnessV1BridgePermissionModeSchema.optional(),
430
+ builtinToolFiltering: harnessV1BridgeBuiltinToolFilteringSchema.optional(),
431
+ responseFormat: harnessV1BridgeResponseFormatSchema.optional()
432
+ });
433
+ /**
434
+ * Sent the instant the bridge accepts an authenticated WS connection. The host
435
+ * waits for it before sending `start`/`resume`, because some sandbox runtimes
436
+ * complete the upstream WS handshake before the connection is wired through to
437
+ * the bridge process — anything sent in that gap is dropped. Carries the
438
+ * bridge's lifecycle `state` and highest emitted `seq` for reconnect.
439
+ */
440
+ const harnessV1BridgeHelloSchema = z.object({
441
+ type: z.literal("bridge-hello"),
442
+ state: z.string().optional(),
443
+ lastSeq: z.number().optional(),
444
+ capabilities: z.object({ experimental_userMessageResponses: z.boolean().optional() }).optional()
445
+ });
446
+ const experimental_harnessV1BridgeUserMessageResponseSchema = z.object({
447
+ type: z.literal("user-message-response"),
448
+ messageId: z.string(),
449
+ accepted: z.boolean(),
450
+ error: z.object({ message: z.string() }).optional()
451
+ });
452
+ /**
453
+ * The bridge's reply to an inbound `stop`. Carries the adapter-specific
454
+ * payload the host serializes into lifecycle state `data`.
455
+ */
456
+ const harnessV1BridgeStopSchema = z.object({
457
+ type: z.literal("bridge-stop"),
458
+ data: z.unknown()
459
+ });
460
+ /**
461
+ * A resume coordinate the bridge proactively announces (e.g. Codex's thread id)
462
+ * so the host can cache it for a later resume without waiting for `stop`.
463
+ */
464
+ const harnessV1BridgeThreadSchema = z.object({
465
+ type: z.literal("bridge-thread"),
466
+ threadId: z.string()
467
+ });
468
+ /**
469
+ * One captured console line from inside the sandbox. The bridge line-buffers
470
+ * `process.stdout`/`process.stderr` and emits one of these per complete line.
471
+ * Routed host-side to the diagnostics sink, never to the consumer stream.
472
+ */
473
+ const harnessV1BridgeSandboxLogSchema = z.object({
474
+ type: z.literal("sandbox-log"),
475
+ source: z.string(),
476
+ stream: z.enum(["stdout", "stderr"]),
477
+ line: z.string()
478
+ });
479
+ /**
480
+ * A structured diagnostic an adapter emits from inside the bridge via
481
+ * `turn.bridgeLog(...)`. Gated by the session's debug level + subsystem filter.
482
+ */
483
+ const harnessV1BridgeDebugEventSchema = z.object({
484
+ type: z.literal("debug-event"),
485
+ level: harnessV1DebugLevelSchema,
486
+ subsystem: z.string(),
487
+ message: z.string(),
488
+ attrs: z.record(z.string(), z.unknown()).optional(),
489
+ error: z.object({
490
+ name: z.string().optional(),
491
+ message: z.string(),
492
+ stack: z.string().optional()
493
+ }).optional()
494
+ });
495
+ /**
496
+ * Every frame a bridge can send to the host: the stream-part events plus the
497
+ * transport/control frames. This is the schema the host `SandboxChannel`
498
+ * validates inbound frames against.
499
+ */
500
+ const harnessV1BridgeOutboundMessageSchema = z.discriminatedUnion("type", [
501
+ harnessV1StreamStartPartSchema,
502
+ harnessV1TextStartPartSchema,
503
+ harnessV1TextDeltaPartSchema,
504
+ harnessV1TextEndPartSchema,
505
+ harnessV1ReasoningStartPartSchema,
506
+ harnessV1ReasoningDeltaPartSchema,
507
+ harnessV1ReasoningEndPartSchema,
508
+ harnessV1ToolInputStartPartSchema,
509
+ harnessV1ToolInputDeltaPartSchema,
510
+ harnessV1ToolInputEndPartSchema,
511
+ harnessV1ToolCallPartSchema,
512
+ harnessV1ToolApprovalRequestPartSchema,
513
+ harnessV1ToolResultPartSchema,
514
+ harnessV1FinishStepPartSchema,
515
+ harnessV1FinishPartSchema,
516
+ harnessV1FileChangePartSchema,
517
+ harnessV1CompactionPartSchema,
518
+ harnessV1ErrorPartSchema,
519
+ harnessV1RawPartSchema,
520
+ harnessV1BridgeHelloSchema,
521
+ experimental_harnessV1BridgeUserMessageResponseSchema,
522
+ harnessV1BridgeStopSchema,
523
+ harnessV1BridgeThreadSchema,
524
+ harnessV1BridgeSandboxLogSchema,
525
+ harnessV1BridgeDebugEventSchema
396
526
  ]);
397
- var harnessV1BridgeStartBaseSchema = z5.object({
398
- type: z5.literal("start"),
399
- prompt: z5.string(),
400
- tools: z5.array(harnessV1BridgeToolWireSchema).optional(),
401
- model: z5.string().optional(),
402
- debug: harnessV1DebugConfigSchema.optional(),
403
- permissionMode: harnessV1BridgePermissionModeSchema.optional(),
404
- builtinToolFiltering: harnessV1BridgeBuiltinToolFilteringSchema.optional(),
405
- responseFormat: harnessV1BridgeResponseFormatSchema.optional()
406
- });
407
- var harnessV1BridgeHelloSchema = z5.object({
408
- type: z5.literal("bridge-hello"),
409
- state: z5.string().optional(),
410
- lastSeq: z5.number().optional(),
411
- capabilities: z5.object({
412
- experimental_userMessageResponses: z5.boolean().optional()
413
- }).optional()
414
- });
415
- var experimental_harnessV1BridgeUserMessageResponseSchema = z5.object({
416
- type: z5.literal("user-message-response"),
417
- messageId: z5.string(),
418
- accepted: z5.boolean(),
419
- error: z5.object({ message: z5.string() }).optional()
420
- });
421
- var harnessV1BridgeStopSchema = z5.object({
422
- type: z5.literal("bridge-stop"),
423
- data: z5.unknown()
424
- });
425
- var harnessV1BridgeThreadSchema = z5.object({
426
- type: z5.literal("bridge-thread"),
427
- threadId: z5.string()
428
- });
429
- var harnessV1BridgeSandboxLogSchema = z5.object({
430
- type: z5.literal("sandbox-log"),
431
- source: z5.string(),
432
- stream: z5.enum(["stdout", "stderr"]),
433
- line: z5.string()
434
- });
435
- var harnessV1BridgeDebugEventSchema = z5.object({
436
- type: z5.literal("debug-event"),
437
- level: harnessV1DebugLevelSchema,
438
- subsystem: z5.string(),
439
- message: z5.string(),
440
- attrs: z5.record(z5.string(), z5.unknown()).optional(),
441
- error: z5.object({
442
- name: z5.string().optional(),
443
- message: z5.string(),
444
- stack: z5.string().optional()
445
- }).optional()
446
- });
447
- var harnessV1BridgeOutboundMessageSchema = z5.discriminatedUnion(
448
- "type",
449
- [
450
- harnessV1StreamStartPartSchema,
451
- harnessV1TextStartPartSchema,
452
- harnessV1TextDeltaPartSchema,
453
- harnessV1TextEndPartSchema,
454
- harnessV1ReasoningStartPartSchema,
455
- harnessV1ReasoningDeltaPartSchema,
456
- harnessV1ReasoningEndPartSchema,
457
- harnessV1ToolInputStartPartSchema,
458
- harnessV1ToolInputDeltaPartSchema,
459
- harnessV1ToolInputEndPartSchema,
460
- harnessV1ToolCallPartSchema,
461
- harnessV1ToolApprovalRequestPartSchema,
462
- harnessV1ToolResultPartSchema,
463
- harnessV1FinishStepPartSchema,
464
- harnessV1FinishPartSchema,
465
- harnessV1FileChangePartSchema,
466
- harnessV1CompactionPartSchema,
467
- harnessV1ErrorPartSchema,
468
- harnessV1RawPartSchema,
469
- harnessV1BridgeHelloSchema,
470
- experimental_harnessV1BridgeUserMessageResponseSchema,
471
- harnessV1BridgeStopSchema,
472
- harnessV1BridgeThreadSchema,
473
- harnessV1BridgeSandboxLogSchema,
474
- harnessV1BridgeDebugEventSchema
475
- ]
476
- );
527
+ /**
528
+ * Normalize a bridge diagnostics wire frame into the transport-agnostic
529
+ * `HarnessV1Diagnostic` an adapter reports to the framework. A captured console
530
+ * line maps `stderr` → `warn` and `stdout` → `info`; a structured event passes
531
+ * its fields through. This is the seam where the bridge's serialization is
532
+ * lifted into the general emission shape every harness shares.
533
+ */
477
534
  function harnessV1DiagnosticFromBridgeFrame(frame, context) {
478
- if (frame.type === "sandbox-log") {
479
- return {
480
- level: frame.stream === "stderr" ? "warn" : "info",
481
- message: frame.line,
482
- subsystem: `sandbox.log.${frame.source}`,
483
- kind: "log",
484
- source: frame.source,
485
- stream: frame.stream,
486
- sessionId: context.sessionId,
487
- timestamp: context.timestamp
488
- };
489
- }
490
- return {
491
- level: frame.level,
492
- message: frame.message,
493
- subsystem: frame.subsystem,
494
- kind: "event",
495
- attrs: frame.attrs,
496
- error: frame.error,
497
- sessionId: context.sessionId,
498
- timestamp: context.timestamp
499
- };
535
+ if (frame.type === "sandbox-log") return {
536
+ level: frame.stream === "stderr" ? "warn" : "info",
537
+ message: frame.line,
538
+ subsystem: `sandbox.log.${frame.source}`,
539
+ kind: "log",
540
+ source: frame.source,
541
+ stream: frame.stream,
542
+ sessionId: context.sessionId,
543
+ timestamp: context.timestamp
544
+ };
545
+ return {
546
+ level: frame.level,
547
+ message: frame.message,
548
+ subsystem: frame.subsystem,
549
+ kind: "event",
550
+ attrs: frame.attrs,
551
+ error: frame.error,
552
+ sessionId: context.sessionId,
553
+ timestamp: context.timestamp
554
+ };
500
555
  }
501
- var harnessV1BridgeToolResultInboundSchema = z5.object({
502
- type: z5.literal("tool-result"),
503
- toolCallId: z5.string(),
504
- output: z5.unknown(),
505
- isError: z5.boolean().optional(),
506
- toolResult: z5.unknown().optional()
507
- });
508
- var harnessV1BridgeToolApprovalResponseInboundSchema = z5.object({
509
- type: z5.literal("tool-approval-response"),
510
- approvalId: z5.string(),
511
- approved: z5.boolean(),
512
- reason: z5.string().optional()
513
- });
514
- var harnessV1BridgeUserMessageInboundSchema = z5.object({
515
- type: z5.literal("user-message"),
516
- messageId: z5.string().optional(),
517
- text: z5.string()
518
- });
519
- var experimental_harnessV1BridgeUserMessageInboundSchema = harnessV1BridgeUserMessageInboundSchema.extend({
520
- messageId: z5.string()
521
- });
522
- var harnessV1BridgeAbortInboundSchema = z5.object({
523
- type: z5.literal("abort")
524
- });
525
- var harnessV1BridgeDestroyInboundSchema = z5.object({
526
- type: z5.literal("destroy")
527
- });
528
- var harnessV1BridgeResumeInboundSchema = z5.object({
529
- type: z5.literal("resume"),
530
- lastSeenEventId: z5.number()
531
- });
532
- var harnessV1BridgeStopInboundSchema = z5.object({
533
- type: z5.literal("stop")
534
- });
535
- var harnessV1BridgeInboundCommandSchemas = [
536
- harnessV1BridgeToolResultInboundSchema,
537
- harnessV1BridgeToolApprovalResponseInboundSchema,
538
- harnessV1BridgeUserMessageInboundSchema,
539
- harnessV1BridgeAbortInboundSchema,
540
- harnessV1BridgeDestroyInboundSchema,
541
- harnessV1BridgeResumeInboundSchema,
542
- harnessV1BridgeStopInboundSchema
556
+ const harnessV1BridgeToolResultInboundSchema = z.object({
557
+ type: z.literal("tool-result"),
558
+ toolCallId: z.string(),
559
+ output: z.unknown(),
560
+ isError: z.boolean().optional(),
561
+ toolResult: z.unknown().optional()
562
+ });
563
+ const harnessV1BridgeToolApprovalResponseInboundSchema = z.object({
564
+ type: z.literal("tool-approval-response"),
565
+ approvalId: z.string(),
566
+ approved: z.boolean(),
567
+ reason: z.string().optional()
568
+ });
569
+ const harnessV1BridgeUserMessageInboundSchema = z.object({
570
+ type: z.literal("user-message"),
571
+ messageId: z.string().optional(),
572
+ text: z.string()
573
+ });
574
+ const experimental_harnessV1BridgeUserMessageInboundSchema = harnessV1BridgeUserMessageInboundSchema.extend({ messageId: z.string() });
575
+ const harnessV1BridgeAbortInboundSchema = z.object({ type: z.literal("abort") });
576
+ const harnessV1BridgeDestroyInboundSchema = z.object({ type: z.literal("destroy") });
577
+ /**
578
+ * Reconnect: after re-establishing the socket the host asks the bridge to
579
+ * replay every buffered event with `seq > lastSeenEventId`.
580
+ */
581
+ const harnessV1BridgeResumeInboundSchema = z.object({
582
+ type: z.literal("resume"),
583
+ lastSeenEventId: z.number()
584
+ });
585
+ /**
586
+ * The bridge replies with `bridge-stop` carrying any runtime resume data,
587
+ * then exits.
588
+ */
589
+ const harnessV1BridgeStopInboundSchema = z.object({ type: z.literal("stop") });
590
+ /**
591
+ * The inbound command members shared by every bridge adapter. Spread these
592
+ * alongside the adapter's own `start` schema to build the final inbound union:
593
+ * `z.discriminatedUnion('type', [adapterStartSchema, ...harnessV1BridgeInboundCommandSchemas])`.
594
+ */
595
+ const harnessV1BridgeInboundCommandSchemas = [
596
+ harnessV1BridgeToolResultInboundSchema,
597
+ harnessV1BridgeToolApprovalResponseInboundSchema,
598
+ harnessV1BridgeUserMessageInboundSchema,
599
+ harnessV1BridgeAbortInboundSchema,
600
+ harnessV1BridgeDestroyInboundSchema,
601
+ harnessV1BridgeResumeInboundSchema,
602
+ harnessV1BridgeStopInboundSchema
543
603
  ];
544
- var harnessV1BridgeReadySchema = z5.object({
545
- type: z5.literal("bridge-ready"),
546
- port: z5.number()
547
- });
548
-
549
- // src/v1/harness-v1-tool-filtering.ts
604
+ /**
605
+ * The JSON line the bridge writes to stdout once its WebSocket server is bound,
606
+ * announcing the port the host should connect to.
607
+ */
608
+ const harnessV1BridgeReadySchema = z.object({
609
+ type: z.literal("bridge-ready"),
610
+ port: z.number()
611
+ });
612
+ //#endregion
613
+ //#region src/v1/harness-v1-tool-filtering.ts
550
614
  function isHarnessV1BuiltinToolIncluded(input) {
551
- if (input.toolFiltering == null) return true;
552
- return input.toolFiltering.mode === "allow" ? input.toolFiltering.toolNames.includes(input.toolName) : !input.toolFiltering.toolNames.includes(input.toolName);
615
+ if (input.toolFiltering == null) return true;
616
+ return input.toolFiltering.mode === "allow" ? input.toolFiltering.toolNames.includes(input.toolName) : !input.toolFiltering.toolNames.includes(input.toolName);
553
617
  }
554
618
  function getHarnessV1BuiltinToolFilteringDenialReason(input) {
555
- return `Tool '${input.toolName}' is inactive due to the HarnessAgent tool filtering policy.`;
619
+ return `Tool '${input.toolName}' is inactive due to the HarnessAgent tool filtering policy.`;
556
620
  }
557
-
558
- // src/errors/harness-error.ts
559
- import { AISDKError } from "@ai-sdk/provider";
560
- var name = "AI_HarnessError";
561
- var marker = `vercel.ai.error.${name}`;
562
- var symbol = Symbol.for(marker);
563
- var _a, _b;
564
- var HarnessError = class extends (_b = AISDKError, _a = symbol, _b) {
565
- constructor({ message, cause }) {
566
- super({ name, message, cause });
567
- this[_a] = true;
568
- }
569
- static isInstance(error) {
570
- return AISDKError.hasMarker(error, marker);
571
- }
621
+ //#endregion
622
+ //#region src/errors/harness-error.ts
623
+ const name$3 = "AI_HarnessError";
624
+ const marker$3 = `vercel.ai.error.${name$3}`;
625
+ const symbol$3 = Symbol.for(marker$3);
626
+ /**
627
+ * Base error type for failures originating in or signalled by a harness
628
+ * adapter. Specific failure modes (e.g. unsupported capability) extend this
629
+ * class.
630
+ */
631
+ var HarnessError = class extends AISDKError {
632
+ constructor({ message, cause }) {
633
+ super({
634
+ name: name$3,
635
+ message,
636
+ cause
637
+ });
638
+ this[symbol$3] = true;
639
+ }
640
+ static isInstance(error) {
641
+ return AISDKError.hasMarker(error, marker$3);
642
+ }
572
643
  };
573
-
574
- // src/errors/harness-capability-unsupported-error.ts
575
- import { AISDKError as AISDKError2 } from "@ai-sdk/provider";
576
- var name2 = "AI_HarnessCapabilityUnsupportedError";
577
- var marker2 = `vercel.ai.error.${name2}`;
578
- var symbol2 = Symbol.for(marker2);
579
- var _a2, _b2;
580
- var HarnessCapabilityUnsupportedError = class extends (_b2 = HarnessError, _a2 = symbol2, _b2) {
581
- constructor({
582
- message,
583
- harnessId,
584
- cause
585
- }) {
586
- super({ message, cause });
587
- this[_a2] = true;
588
- Object.defineProperty(this, "name", { value: name2 });
589
- this.harnessId = harnessId;
590
- }
591
- static isInstance(error) {
592
- return AISDKError2.hasMarker(error, marker2);
593
- }
644
+ //#endregion
645
+ //#region src/errors/harness-capability-unsupported-error.ts
646
+ const name$2 = "AI_HarnessCapabilityUnsupportedError";
647
+ const marker$2 = `vercel.ai.error.${name$2}`;
648
+ const symbol$2 = Symbol.for(marker$2);
649
+ /**
650
+ * Thrown when a caller asks the harness to do something the adapter (or the
651
+ * supplied sandbox) does not support, e.g. requesting manual compaction from
652
+ * an adapter that only auto-compacts, or invoking `getPortEndpoint` on a
653
+ * sandbox that does not expose one.
654
+ *
655
+ * The caller supplies the full human-readable message. Optional `harnessId`
656
+ * is recorded as structured context for tooling.
657
+ */
658
+ var HarnessCapabilityUnsupportedError = class extends HarnessError {
659
+ constructor({ message, harnessId, cause }) {
660
+ super({
661
+ message,
662
+ cause
663
+ });
664
+ this[symbol$2] = true;
665
+ Object.defineProperty(this, "name", { value: name$2 });
666
+ this.harnessId = harnessId;
667
+ }
668
+ static isInstance(error) {
669
+ return AISDKError.hasMarker(error, marker$2);
670
+ }
594
671
  };
595
-
596
- // src/errors/harness-history-unavailable-error.ts
597
- import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
598
- var name3 = "AI_HarnessHistoryUnavailableError";
599
- var marker3 = `vercel.ai.error.${name3}`;
600
- var symbol3 = Symbol.for(marker3);
601
- var _a3, _b3;
602
- var HarnessHistoryUnavailableError = class extends (_b3 = HarnessError, _a3 = symbol3, _b3) {
603
- constructor({
604
- message,
605
- harnessId,
606
- cause
607
- }) {
608
- super({ message, cause });
609
- this[_a3] = true;
610
- Object.defineProperty(this, "name", { value: name3 });
611
- this.harnessId = harnessId;
612
- }
613
- static isInstance(error) {
614
- return AISDKError3.hasMarker(error, marker3);
615
- }
672
+ //#endregion
673
+ //#region src/errors/harness-history-unavailable-error.ts
674
+ const name$1 = "AI_HarnessHistoryUnavailableError";
675
+ const marker$1 = `vercel.ai.error.${name$1}`;
676
+ const symbol$1 = Symbol.for(marker$1);
677
+ /**
678
+ * Thrown by `readHistory` when the adapter supports history reads but cannot
679
+ * reach the runtime's store from the current environment — for example the
680
+ * store lives inside a remote sandbox, or the transcript directory is
681
+ * missing or unreadable.
682
+ *
683
+ * Distinct from `HarnessCapabilityUnsupportedError` (the adapter does not
684
+ * implement history reads at all) so hosts can retry or degrade differently.
685
+ * A conversation with no recorded messages yet is not an error; it resolves
686
+ * to an empty result instead.
687
+ */
688
+ var HarnessHistoryUnavailableError = class extends HarnessError {
689
+ constructor({ message, harnessId, cause }) {
690
+ super({
691
+ message,
692
+ cause
693
+ });
694
+ this[symbol$1] = true;
695
+ Object.defineProperty(this, "name", { value: name$1 });
696
+ this.harnessId = harnessId;
697
+ }
698
+ static isInstance(error) {
699
+ return AISDKError.hasMarker(error, marker$1);
700
+ }
616
701
  };
617
-
618
- // src/errors/harness-sandbox-authentication-error.ts
619
- import { AISDKError as AISDKError4 } from "@ai-sdk/provider";
620
- var name4 = "AI_HarnessSandboxAuthenticationError";
621
- var marker4 = `vercel.ai.error.${name4}`;
622
- var symbol4 = Symbol.for(marker4);
623
- var _a4, _b4;
624
- var HarnessSandboxAuthenticationError = class extends (_b4 = HarnessError, _a4 = symbol4, _b4) {
625
- constructor({
626
- message,
627
- sandboxProviderId,
628
- cause
629
- }) {
630
- super({ message, cause });
631
- this[_a4] = true;
632
- Object.defineProperty(this, "name", { value: name4 });
633
- this.sandboxProviderId = sandboxProviderId;
634
- }
635
- static isInstance(error) {
636
- return AISDKError4.hasMarker(error, marker4);
637
- }
638
- };
639
- export {
640
- HARNESS_V1_BUILTIN_TOOLS,
641
- HARNESS_V1_BUILTIN_TOOL_NAMES,
642
- HarnessCapabilityUnsupportedError,
643
- HarnessError,
644
- HarnessHistoryUnavailableError,
645
- HarnessSandboxAuthenticationError,
646
- commonTool,
647
- experimental_harnessV1BridgeUserMessageInboundSchema,
648
- experimental_harnessV1BridgeUserMessageResponseSchema,
649
- getHarnessV1BuiltinToolFilteringDenialReason,
650
- harnessSessionDataDirectoryPath,
651
- harnessStateDirectoryPath,
652
- harnessV1BridgeAbortInboundSchema,
653
- harnessV1BridgeBuiltinToolFilteringSchema,
654
- harnessV1BridgeDebugEventSchema,
655
- harnessV1BridgeDestroyInboundSchema,
656
- harnessV1BridgeHelloSchema,
657
- harnessV1BridgeInboundCommandSchemas,
658
- harnessV1BridgeOutboundMessageSchema,
659
- harnessV1BridgePermissionModeSchema,
660
- harnessV1BridgeReadySchema,
661
- harnessV1BridgeResponseFormatSchema,
662
- harnessV1BridgeResumeInboundSchema,
663
- harnessV1BridgeSandboxLogSchema,
664
- harnessV1BridgeStartBaseSchema,
665
- harnessV1BridgeStopInboundSchema,
666
- harnessV1BridgeStopSchema,
667
- harnessV1BridgeThreadSchema,
668
- harnessV1BridgeToolApprovalResponseInboundSchema,
669
- harnessV1BridgeToolResultInboundSchema,
670
- harnessV1BridgeToolWireSchema,
671
- harnessV1BridgeUserMessageInboundSchema,
672
- harnessV1DebugConfigSchema,
673
- harnessV1DebugLevelSchema,
674
- harnessV1DiagnosticFromBridgeFrame,
675
- harnessV1ErrorPartSchema,
676
- harnessV1FileChangePartSchema,
677
- harnessV1FinishPartSchema,
678
- harnessV1FinishStepPartSchema,
679
- harnessV1QuestionsToolInputSchema,
680
- harnessV1QuestionsToolOutputSchema,
681
- harnessV1RawPartSchema,
682
- harnessV1ReasoningDeltaPartSchema,
683
- harnessV1ReasoningEndPartSchema,
684
- harnessV1ReasoningStartPartSchema,
685
- harnessV1StreamPartSchema,
686
- harnessV1StreamStartPartSchema,
687
- harnessV1TextDeltaPartSchema,
688
- harnessV1TextEndPartSchema,
689
- harnessV1TextStartPartSchema,
690
- harnessV1ToolApprovalRequestPartSchema,
691
- harnessV1ToolCallPartSchema,
692
- harnessV1ToolResultPartSchema,
693
- isHarnessV1BuiltinToolIncluded
702
+ //#endregion
703
+ //#region src/errors/harness-sandbox-authentication-error.ts
704
+ const name = "AI_HarnessSandboxAuthenticationError";
705
+ const marker = `vercel.ai.error.${name}`;
706
+ const symbol = Symbol.for(marker);
707
+ /**
708
+ * Thrown when a sandbox provider cannot authenticate or authorize the
709
+ * operation needed to create or resume a harness sandbox. Providers should
710
+ * preserve the underlying SDK failure as `cause` and supply a message that
711
+ * explains how the consumer can configure credentials.
712
+ */
713
+ var HarnessSandboxAuthenticationError = class extends HarnessError {
714
+ constructor({ message, sandboxProviderId, cause }) {
715
+ super({
716
+ message,
717
+ cause
718
+ });
719
+ this[symbol] = true;
720
+ Object.defineProperty(this, "name", { value: name });
721
+ this.sandboxProviderId = sandboxProviderId;
722
+ }
723
+ static isInstance(error) {
724
+ return AISDKError.hasMarker(error, marker);
725
+ }
694
726
  };
727
+ //#endregion
728
+ export { HARNESS_V1_BUILTIN_TOOLS, HARNESS_V1_BUILTIN_TOOL_NAMES, HarnessCapabilityUnsupportedError, HarnessError, HarnessHistoryUnavailableError, HarnessSandboxAuthenticationError, commonTool, experimental_harnessV1BridgeUserMessageInboundSchema, experimental_harnessV1BridgeUserMessageResponseSchema, getHarnessV1BuiltinToolFilteringDenialReason, harnessSessionDataDirectoryPath, harnessStateDirectoryPath, harnessV1BridgeAbortInboundSchema, harnessV1BridgeBuiltinToolFilteringSchema, harnessV1BridgeDebugEventSchema, harnessV1BridgeDestroyInboundSchema, harnessV1BridgeHelloSchema, harnessV1BridgeInboundCommandSchemas, harnessV1BridgeOutboundMessageSchema, harnessV1BridgePermissionModeSchema, harnessV1BridgeReadySchema, harnessV1BridgeResponseFormatSchema, harnessV1BridgeResumeInboundSchema, harnessV1BridgeSandboxLogSchema, harnessV1BridgeStartBaseSchema, harnessV1BridgeStopInboundSchema, harnessV1BridgeStopSchema, harnessV1BridgeThreadSchema, harnessV1BridgeToolApprovalResponseInboundSchema, harnessV1BridgeToolResultInboundSchema, harnessV1BridgeToolWireSchema, harnessV1BridgeUserMessageInboundSchema, harnessV1DebugConfigSchema, harnessV1DebugLevelSchema, harnessV1DiagnosticFromBridgeFrame, harnessV1ErrorPartSchema, harnessV1FileChangePartSchema, harnessV1FinishPartSchema, harnessV1FinishStepPartSchema, harnessV1QuestionsToolInputSchema, harnessV1QuestionsToolOutputSchema, harnessV1RawPartSchema, harnessV1ReasoningDeltaPartSchema, harnessV1ReasoningEndPartSchema, harnessV1ReasoningStartPartSchema, harnessV1StreamPartSchema, harnessV1StreamStartPartSchema, harnessV1TextDeltaPartSchema, harnessV1TextEndPartSchema, harnessV1TextStartPartSchema, harnessV1ToolApprovalRequestPartSchema, harnessV1ToolCallPartSchema, harnessV1ToolResultPartSchema, isHarnessV1BuiltinToolIncluded };
729
+
695
730
  //# sourceMappingURL=index.js.map