@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/CHANGELOG.md +14 -0
- package/dist/agent/index.d.ts +1546 -1509
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +4419 -5044
- package/dist/agent/index.js.map +1 -1
- package/dist/bridge/index.d.ts +141 -139
- package/dist/bridge/index.d.ts.map +1 -0
- package/dist/bridge/index.js +579 -650
- package/dist/bridge/index.js.map +1 -1
- package/dist/index.d.ts +1447 -1422
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +703 -668
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +551 -522
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +1910 -2465
- package/dist/utils/index.js.map +1 -1
- package/package.json +9 -9
- package/src/bridge/index.ts +1 -1
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
-
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
});
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
});
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
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
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
552
|
-
|
|
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
|
-
|
|
619
|
+
return `Tool '${input.toolName}' is inactive due to the HarnessAgent tool filtering policy.`;
|
|
556
620
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
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
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
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
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|