@ai-sdk/harness 1.0.54 → 1.0.55
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 +9 -0
- package/README.md +1 -3
- package/agent/index.ts +2 -0
- package/dist/agent/index.d.ts +37 -11
- package/dist/agent/index.js +137 -107
- package/dist/agent/index.js.map +1 -1
- package/dist/bridge/index.d.ts +11 -4
- package/dist/bridge/index.js +8 -7
- package/dist/bridge/index.js.map +1 -1
- package/dist/index.d.ts +41 -23
- package/dist/index.js +35 -12
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +9 -9
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/get-harness-error-message.ts +23 -0
- package/src/agent/internal/bootstrap-recipe.ts +1 -7
- package/src/bridge/index.ts +23 -15
- package/src/errors/harness-sandbox-authentication-error.ts +38 -0
- package/src/index.ts +1 -0
- package/src/utils/sandbox-channel.ts +2 -2
- package/src/v1/harness-v1-bootstrap.ts +0 -6
- package/src/v1/harness-v1-bridge-protocol.ts +13 -13
- package/src/v1/harness-v1-sandbox-provider.ts +6 -0
- package/src/v1/index.ts +3 -3
package/dist/agent/index.js
CHANGED
|
@@ -974,12 +974,12 @@ function normalizeUsage(usage) {
|
|
|
974
974
|
};
|
|
975
975
|
}
|
|
976
976
|
function createTurnTelemetry(opts) {
|
|
977
|
-
var
|
|
977
|
+
var _a4;
|
|
978
978
|
if (opts.telemetry == null) return NOOP;
|
|
979
979
|
const dispatcher = createTelemetryDispatcher({ telemetry: opts.telemetry });
|
|
980
980
|
const callId = generateId3();
|
|
981
981
|
const provider = opts.harnessId;
|
|
982
|
-
let modelId = (
|
|
982
|
+
let modelId = (_a4 = opts.modelId) != null ? _a4 : "";
|
|
983
983
|
const runtimeContext = opts.runtimeContext;
|
|
984
984
|
const inputMessages = [
|
|
985
985
|
{ role: "user", content: opts.promptText }
|
|
@@ -995,10 +995,10 @@ function createTurnTelemetry(opts) {
|
|
|
995
995
|
const openTools = /* @__PURE__ */ new Map();
|
|
996
996
|
const cast = (event) => event;
|
|
997
997
|
const fireStart = async () => {
|
|
998
|
-
var
|
|
998
|
+
var _a5;
|
|
999
999
|
if (started) return;
|
|
1000
1000
|
started = true;
|
|
1001
|
-
await ((
|
|
1001
|
+
await ((_a5 = dispatcher.onStart) == null ? void 0 : _a5.call(
|
|
1002
1002
|
dispatcher,
|
|
1003
1003
|
cast({
|
|
1004
1004
|
callId,
|
|
@@ -1026,11 +1026,11 @@ function createTurnTelemetry(opts) {
|
|
|
1026
1026
|
await fireStart();
|
|
1027
1027
|
};
|
|
1028
1028
|
const ensureStepOpen = async () => {
|
|
1029
|
-
var
|
|
1029
|
+
var _a5, _b4;
|
|
1030
1030
|
if (!started) await fireStart();
|
|
1031
1031
|
if (stepOpen || ended) return;
|
|
1032
1032
|
stepOpen = true;
|
|
1033
|
-
await ((
|
|
1033
|
+
await ((_a5 = dispatcher.onStepStart) == null ? void 0 : _a5.call(
|
|
1034
1034
|
dispatcher,
|
|
1035
1035
|
cast({
|
|
1036
1036
|
callId,
|
|
@@ -1047,7 +1047,7 @@ function createTurnTelemetry(opts) {
|
|
|
1047
1047
|
messages: inputMessages
|
|
1048
1048
|
})
|
|
1049
1049
|
));
|
|
1050
|
-
await ((
|
|
1050
|
+
await ((_b4 = dispatcher.onLanguageModelCallStart) == null ? void 0 : _b4.call(
|
|
1051
1051
|
dispatcher,
|
|
1052
1052
|
cast({
|
|
1053
1053
|
callId,
|
|
@@ -1059,10 +1059,10 @@ function createTurnTelemetry(opts) {
|
|
|
1059
1059
|
));
|
|
1060
1060
|
};
|
|
1061
1061
|
const inferenceEnd = async (info) => {
|
|
1062
|
-
var
|
|
1062
|
+
var _a5;
|
|
1063
1063
|
const finishReason = normalizeFinishReason(info.finishReason);
|
|
1064
1064
|
const usage = normalizeUsage(info.usage);
|
|
1065
|
-
await ((
|
|
1065
|
+
await ((_a5 = dispatcher.onLanguageModelCallEnd) == null ? void 0 : _a5.call(
|
|
1066
1066
|
dispatcher,
|
|
1067
1067
|
cast({
|
|
1068
1068
|
callId,
|
|
@@ -1092,9 +1092,9 @@ function createTurnTelemetry(opts) {
|
|
|
1092
1092
|
}
|
|
1093
1093
|
};
|
|
1094
1094
|
const closeOpenTools = async () => {
|
|
1095
|
-
var
|
|
1095
|
+
var _a5;
|
|
1096
1096
|
for (const call of openTools.values()) {
|
|
1097
|
-
await ((
|
|
1097
|
+
await ((_a5 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a5.call(
|
|
1098
1098
|
dispatcher,
|
|
1099
1099
|
cast({
|
|
1100
1100
|
callId,
|
|
@@ -1118,9 +1118,9 @@ function createTurnTelemetry(opts) {
|
|
|
1118
1118
|
start,
|
|
1119
1119
|
ensureStepOpen,
|
|
1120
1120
|
async stepFinish(info) {
|
|
1121
|
-
var
|
|
1121
|
+
var _a5, _b4;
|
|
1122
1122
|
if (!stepOpen) return;
|
|
1123
|
-
const content = (
|
|
1123
|
+
const content = (_a5 = info.content) != null ? _a5 : [];
|
|
1124
1124
|
const finishReason = normalizeFinishReason(info.finishReason);
|
|
1125
1125
|
const usage = normalizeUsage(info.usage);
|
|
1126
1126
|
recordOutputContent(content);
|
|
@@ -1131,7 +1131,7 @@ function createTurnTelemetry(opts) {
|
|
|
1131
1131
|
usage,
|
|
1132
1132
|
content
|
|
1133
1133
|
});
|
|
1134
|
-
await ((
|
|
1134
|
+
await ((_b4 = dispatcher.onStepEnd) == null ? void 0 : _b4.call(
|
|
1135
1135
|
dispatcher,
|
|
1136
1136
|
cast({
|
|
1137
1137
|
callId,
|
|
@@ -1152,11 +1152,11 @@ function createTurnTelemetry(opts) {
|
|
|
1152
1152
|
stepNumber += 1;
|
|
1153
1153
|
},
|
|
1154
1154
|
async toolStart(call) {
|
|
1155
|
-
var
|
|
1155
|
+
var _a5;
|
|
1156
1156
|
await ensureStepOpen();
|
|
1157
1157
|
if (openTools.has(call.toolCallId)) return;
|
|
1158
1158
|
openTools.set(call.toolCallId, call);
|
|
1159
|
-
await ((
|
|
1159
|
+
await ((_a5 = dispatcher.onToolExecutionStart) == null ? void 0 : _a5.call(
|
|
1160
1160
|
dispatcher,
|
|
1161
1161
|
cast({
|
|
1162
1162
|
callId,
|
|
@@ -1177,12 +1177,12 @@ function createTurnTelemetry(opts) {
|
|
|
1177
1177
|
return await dispatcher.executeTool({ callId, toolCallId, execute });
|
|
1178
1178
|
},
|
|
1179
1179
|
async toolEnd(toolCallId, output) {
|
|
1180
|
-
var
|
|
1180
|
+
var _a5;
|
|
1181
1181
|
const call = openTools.get(toolCallId);
|
|
1182
1182
|
const normalizedOutput = output.ok ? { type: "tool-result", output: output.output } : { type: "error", error: output.error };
|
|
1183
1183
|
if (call == null) return;
|
|
1184
1184
|
openTools.delete(toolCallId);
|
|
1185
|
-
await ((
|
|
1185
|
+
await ((_a5 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a5.call(
|
|
1186
1186
|
dispatcher,
|
|
1187
1187
|
cast({
|
|
1188
1188
|
callId,
|
|
@@ -1201,7 +1201,7 @@ function createTurnTelemetry(opts) {
|
|
|
1201
1201
|
));
|
|
1202
1202
|
},
|
|
1203
1203
|
async end(info) {
|
|
1204
|
-
var
|
|
1204
|
+
var _a5, _b4;
|
|
1205
1205
|
if (ended) return;
|
|
1206
1206
|
const finishReason = normalizeFinishReason(info.finishReason);
|
|
1207
1207
|
const usage = normalizeUsage(info.usage);
|
|
@@ -1213,7 +1213,7 @@ function createTurnTelemetry(opts) {
|
|
|
1213
1213
|
usage,
|
|
1214
1214
|
content: []
|
|
1215
1215
|
});
|
|
1216
|
-
await ((
|
|
1216
|
+
await ((_a5 = dispatcher.onStepEnd) == null ? void 0 : _a5.call(
|
|
1217
1217
|
dispatcher,
|
|
1218
1218
|
cast({
|
|
1219
1219
|
callId,
|
|
@@ -1233,7 +1233,7 @@ function createTurnTelemetry(opts) {
|
|
|
1233
1233
|
stepOpen = false;
|
|
1234
1234
|
}
|
|
1235
1235
|
ended = true;
|
|
1236
|
-
await ((
|
|
1236
|
+
await ((_b4 = dispatcher.onEnd) == null ? void 0 : _b4.call(
|
|
1237
1237
|
dispatcher,
|
|
1238
1238
|
cast({
|
|
1239
1239
|
callId,
|
|
@@ -1261,12 +1261,12 @@ function createTurnTelemetry(opts) {
|
|
|
1261
1261
|
));
|
|
1262
1262
|
},
|
|
1263
1263
|
async error(err) {
|
|
1264
|
-
var
|
|
1264
|
+
var _a5;
|
|
1265
1265
|
if (ended) return;
|
|
1266
1266
|
if (!started) await fireStart();
|
|
1267
1267
|
await closeOpenTools();
|
|
1268
1268
|
ended = true;
|
|
1269
|
-
await ((
|
|
1269
|
+
await ((_a5 = dispatcher.onError) == null ? void 0 : _a5.call(dispatcher, err));
|
|
1270
1270
|
}
|
|
1271
1271
|
};
|
|
1272
1272
|
}
|
|
@@ -1274,16 +1274,16 @@ function createTurnTelemetry(opts) {
|
|
|
1274
1274
|
// src/agent/internal/permission-mode.ts
|
|
1275
1275
|
var DEFAULT_PERMISSION_MODE = "allow-all";
|
|
1276
1276
|
function resolvePermissionMode(input) {
|
|
1277
|
-
var
|
|
1278
|
-
return (
|
|
1277
|
+
var _a4;
|
|
1278
|
+
return (_a4 = input.permissionMode) != null ? _a4 : DEFAULT_PERMISSION_MODE;
|
|
1279
1279
|
}
|
|
1280
1280
|
function permissionModeNeedsBuiltinSupport(input) {
|
|
1281
1281
|
return input.permissionMode !== "allow-all";
|
|
1282
1282
|
}
|
|
1283
1283
|
function resolveCustomToolApproval(input) {
|
|
1284
|
-
var
|
|
1284
|
+
var _a4;
|
|
1285
1285
|
const status = normalizeToolApprovalStatus({
|
|
1286
|
-
status: (
|
|
1286
|
+
status: (_a4 = input.toolApproval) == null ? void 0 : _a4[input.toolName]
|
|
1287
1287
|
});
|
|
1288
1288
|
switch (status.type) {
|
|
1289
1289
|
case "not-applicable":
|
|
@@ -1314,12 +1314,12 @@ function stringifyUnknown(value) {
|
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
1316
1316
|
function formatBridgeError(error) {
|
|
1317
|
-
var
|
|
1317
|
+
var _a4, _b4;
|
|
1318
1318
|
if (error instanceof Error) {
|
|
1319
|
-
return (
|
|
1319
|
+
return (_a4 = error.stack) != null ? _a4 : `${error.name}: ${error.message}`;
|
|
1320
1320
|
}
|
|
1321
1321
|
if (isSerializedError(error)) {
|
|
1322
|
-
return (
|
|
1322
|
+
return (_b4 = error.stack) != null ? _b4 : `${error.name ? `${error.name}: ` : ""}${error.message}`;
|
|
1323
1323
|
}
|
|
1324
1324
|
return stringifyUnknown(error);
|
|
1325
1325
|
}
|
|
@@ -1355,14 +1355,14 @@ var sandboxChannelEventCheckpointSymbol = /* @__PURE__ */ Symbol.for(
|
|
|
1355
1355
|
"vercel.ai.harness.sandboxChannelEventCheckpoint"
|
|
1356
1356
|
);
|
|
1357
1357
|
function pinSandboxChannelEventCheckpoint(event) {
|
|
1358
|
-
var
|
|
1358
|
+
var _a4;
|
|
1359
1359
|
if (event == null || typeof event !== "object") return void 0;
|
|
1360
|
-
return (
|
|
1360
|
+
return (_a4 = event[sandboxChannelEventCheckpointSymbol]) == null ? void 0 : _a4.pin();
|
|
1361
1361
|
}
|
|
1362
1362
|
|
|
1363
1363
|
// src/agent/internal/run-prompt.ts
|
|
1364
1364
|
function runPrompt(input) {
|
|
1365
|
-
var
|
|
1365
|
+
var _a4, _b4, _c, _d, _e, _f, _g;
|
|
1366
1366
|
const result = new HarnessStreamTextResult({
|
|
1367
1367
|
tools: input.tools,
|
|
1368
1368
|
runtimeContext: input.runtimeContext,
|
|
@@ -1371,8 +1371,8 @@ function runPrompt(input) {
|
|
|
1371
1371
|
harnessId: input.harness.harnessId,
|
|
1372
1372
|
sessionId: input.session.sessionId
|
|
1373
1373
|
});
|
|
1374
|
-
const pendingToolApprovals = (
|
|
1375
|
-
const pendingToolResults = (
|
|
1374
|
+
const pendingToolApprovals = (_a4 = input.pendingToolApprovals) != null ? _a4 : [];
|
|
1375
|
+
const pendingToolResults = (_b4 = input.pendingToolResults) != null ? _b4 : [];
|
|
1376
1376
|
const onPendingToolApproval = (_c = input.onPendingToolApproval) != null ? _c : (() => {
|
|
1377
1377
|
});
|
|
1378
1378
|
const onToolApprovalSettled = (_d = input.onToolApprovalSettled) != null ? _d : (() => {
|
|
@@ -1391,9 +1391,9 @@ function runPrompt(input) {
|
|
|
1391
1391
|
runtimeContext: input.runtimeContext
|
|
1392
1392
|
});
|
|
1393
1393
|
const settleFailure = (err) => {
|
|
1394
|
-
var
|
|
1395
|
-
if (!((
|
|
1396
|
-
(
|
|
1394
|
+
var _a5, _b5, _c2;
|
|
1395
|
+
if (!((_a5 = input.isTurnSuspending) == null ? void 0 : _a5.call(input))) {
|
|
1396
|
+
(_b5 = input.onTurnFailed) == null ? void 0 : _b5.call(input);
|
|
1397
1397
|
}
|
|
1398
1398
|
if ((_c2 = input.abortSignal) == null ? void 0 : _c2.aborted) {
|
|
1399
1399
|
result.abort({
|
|
@@ -1405,7 +1405,7 @@ function runPrompt(input) {
|
|
|
1405
1405
|
result.fail(err);
|
|
1406
1406
|
};
|
|
1407
1407
|
const done = (async () => {
|
|
1408
|
-
var
|
|
1408
|
+
var _a5, _b5, _c2, _d2, _e2, _f2, _g2, _h, _i, _j, _k, _l;
|
|
1409
1409
|
let bridge;
|
|
1410
1410
|
try {
|
|
1411
1411
|
bridge = await toHarnessStream({
|
|
@@ -1450,7 +1450,7 @@ function runPrompt(input) {
|
|
|
1450
1450
|
pendingToolApprovals.map((approval) => [approval.toolCallId, approval])
|
|
1451
1451
|
);
|
|
1452
1452
|
const continuationsByApprovalId = new Map(
|
|
1453
|
-
((
|
|
1453
|
+
((_a5 = input.toolApprovalContinuations) != null ? _a5 : []).map((continuation) => [
|
|
1454
1454
|
continuation.approvalResponse.approvalId,
|
|
1455
1455
|
continuation
|
|
1456
1456
|
])
|
|
@@ -1462,7 +1462,7 @@ function runPrompt(input) {
|
|
|
1462
1462
|
])
|
|
1463
1463
|
);
|
|
1464
1464
|
const continuationsByToolCallId = new Map(
|
|
1465
|
-
((
|
|
1465
|
+
((_b5 = input.toolResultContinuations) != null ? _b5 : []).map((continuation) => [
|
|
1466
1466
|
continuation.toolCallId,
|
|
1467
1467
|
continuation
|
|
1468
1468
|
])
|
|
@@ -1473,8 +1473,8 @@ function runPrompt(input) {
|
|
|
1473
1473
|
let finalFinish;
|
|
1474
1474
|
const completedSteps = [];
|
|
1475
1475
|
const releasePendingStopBoundary = () => {
|
|
1476
|
-
var
|
|
1477
|
-
(
|
|
1476
|
+
var _a6;
|
|
1477
|
+
(_a6 = pendingStopBoundary == null ? void 0 : pendingStopBoundary.releaseCheckpoint) == null ? void 0 : _a6.call(pendingStopBoundary);
|
|
1478
1478
|
pendingStopBoundary = void 0;
|
|
1479
1479
|
};
|
|
1480
1480
|
let stepText = "";
|
|
@@ -1569,8 +1569,8 @@ function runPrompt(input) {
|
|
|
1569
1569
|
});
|
|
1570
1570
|
};
|
|
1571
1571
|
const recordPendingToolResult = (options) => {
|
|
1572
|
-
var
|
|
1573
|
-
const pendingResult = (
|
|
1572
|
+
var _a6;
|
|
1573
|
+
const pendingResult = (_a6 = pendingResultsByToolCallId.get(options.toolCall.toolCallId)) != null ? _a6 : {
|
|
1574
1574
|
toolCallId: options.toolCall.toolCallId,
|
|
1575
1575
|
toolName: options.toolCall.toolName,
|
|
1576
1576
|
input: options.toolCall.input
|
|
@@ -1618,7 +1618,7 @@ function runPrompt(input) {
|
|
|
1618
1618
|
});
|
|
1619
1619
|
};
|
|
1620
1620
|
const processPendingApprovalContinuation = async (approval, continuation) => {
|
|
1621
|
-
var
|
|
1621
|
+
var _a6;
|
|
1622
1622
|
enqueueApprovalResponse(approval, continuation);
|
|
1623
1623
|
onToolApprovalSettled(approval.approvalId);
|
|
1624
1624
|
pendingApprovalsByApprovalId.delete(approval.approvalId);
|
|
@@ -1647,7 +1647,7 @@ function runPrompt(input) {
|
|
|
1647
1647
|
});
|
|
1648
1648
|
return "continued";
|
|
1649
1649
|
}
|
|
1650
|
-
const rawToolCall = (
|
|
1650
|
+
const rawToolCall = (_a6 = rawToolCallsByToolCallId.get(approval.toolCallId)) != null ? _a6 : {
|
|
1651
1651
|
type: "tool-call",
|
|
1652
1652
|
toolCallId: approval.toolCallId,
|
|
1653
1653
|
toolName: approval.toolName,
|
|
@@ -2172,7 +2172,7 @@ var HarnessAgentSession = class {
|
|
|
2172
2172
|
this.sessionState = "active";
|
|
2173
2173
|
this.turnSequence = 0;
|
|
2174
2174
|
this.activeTurnSequence = 0;
|
|
2175
|
-
var
|
|
2175
|
+
var _a4, _b4, _c;
|
|
2176
2176
|
this.sessionId = options.sessionId;
|
|
2177
2177
|
this.harness = options.harness;
|
|
2178
2178
|
this.underlyingSession = options.underlyingSession;
|
|
@@ -2181,10 +2181,10 @@ var HarnessAgentSession = class {
|
|
|
2181
2181
|
this.leasedBridgePort = options.leasedBridgePort;
|
|
2182
2182
|
this.sessionWorkDir = options.sessionWorkDir;
|
|
2183
2183
|
this.toolApproval = options.toolApproval;
|
|
2184
|
-
for (const approval of (
|
|
2184
|
+
for (const approval of (_a4 = options.pendingToolApprovals) != null ? _a4 : []) {
|
|
2185
2185
|
this.pendingToolApprovals.set(approval.approvalId, approval);
|
|
2186
2186
|
}
|
|
2187
|
-
for (const pendingResult of (
|
|
2187
|
+
for (const pendingResult of (_b4 = options.pendingToolResults) != null ? _b4 : []) {
|
|
2188
2188
|
this.pendingToolResults.set(pendingResult.toolCallId, pendingResult);
|
|
2189
2189
|
}
|
|
2190
2190
|
this.turnState = (_c = options.turnState) != null ? _c : this.pendingToolApprovals.size > 0 ? "awaiting-approval" : this.pendingToolResults.size > 0 ? "awaiting-tool-result" : "idle";
|
|
@@ -2409,7 +2409,7 @@ var HarnessAgentSession = class {
|
|
|
2409
2409
|
* the provider supports destruction; otherwise it is stopped.
|
|
2410
2410
|
*/
|
|
2411
2411
|
async destroy() {
|
|
2412
|
-
var
|
|
2412
|
+
var _a4, _b4;
|
|
2413
2413
|
if (this.sessionState !== "active") return;
|
|
2414
2414
|
const session = this.underlyingSession;
|
|
2415
2415
|
const sandboxSession = this.getSandboxSession();
|
|
@@ -2419,7 +2419,7 @@ var HarnessAgentSession = class {
|
|
|
2419
2419
|
});
|
|
2420
2420
|
}
|
|
2421
2421
|
await Promise.resolve(
|
|
2422
|
-
(
|
|
2422
|
+
(_b4 = (_a4 = sandboxSession.destroy) == null ? void 0 : _a4.call(sandboxSession)) != null ? _b4 : sandboxSession.stop()
|
|
2423
2423
|
).catch(() => {
|
|
2424
2424
|
});
|
|
2425
2425
|
}
|
|
@@ -2481,8 +2481,8 @@ var HarnessAgentSession = class {
|
|
|
2481
2481
|
};
|
|
2482
2482
|
}
|
|
2483
2483
|
async suspendCurrentTurn(options) {
|
|
2484
|
-
var
|
|
2485
|
-
(
|
|
2484
|
+
var _a4;
|
|
2485
|
+
(_a4 = this.suspendedTurnState) != null ? _a4 : this.suspendedTurnState = (async () => {
|
|
2486
2486
|
const raw = await options.session.doSuspendTurn();
|
|
2487
2487
|
const validated = await validateLifecycleStateData({
|
|
2488
2488
|
harness: this.harness,
|
|
@@ -2779,10 +2779,7 @@ ${mkdirResult.stderr || mkdirResult.stdout}`
|
|
|
2779
2779
|
for (const cmd of recipe.commands) {
|
|
2780
2780
|
const result = await session.run({
|
|
2781
2781
|
command: cmd.command,
|
|
2782
|
-
workingDirectory:
|
|
2783
|
-
path: cmd.workingDirectory,
|
|
2784
|
-
defaultWorkingDirectory
|
|
2785
|
-
}),
|
|
2782
|
+
workingDirectory: bootstrapDir,
|
|
2786
2783
|
abortSignal
|
|
2787
2784
|
});
|
|
2788
2785
|
if (result.exitCode !== 0) {
|
|
@@ -3002,8 +2999,8 @@ function parseList(value) {
|
|
|
3002
2999
|
return items.length > 0 ? items : void 0;
|
|
3003
3000
|
}
|
|
3004
3001
|
function resolveDebugConfig(debug, env = process.env) {
|
|
3005
|
-
var
|
|
3006
|
-
const enabled = (
|
|
3002
|
+
var _a4, _b4, _c, _d;
|
|
3003
|
+
const enabled = (_b4 = debug == null ? void 0 : debug.enabled) != null ? _b4 : ENV_TRUTHY.has(((_a4 = env.HARNESS_DEBUG) != null ? _a4 : "").toLowerCase());
|
|
3007
3004
|
const level = (_d = (_c = debug == null ? void 0 : debug.level) != null ? _c : env.HARNESS_DEBUG_LEVEL) != null ? _d : "debug";
|
|
3008
3005
|
const subsystems = (debug == null ? void 0 : debug.subsystems) ? [...debug.subsystems] : parseList(env.HARNESS_DEBUG_SUBSYSTEMS);
|
|
3009
3006
|
return { enabled, level, subsystems };
|
|
@@ -3023,28 +3020,28 @@ function toHarnessDiagnostic(d) {
|
|
|
3023
3020
|
};
|
|
3024
3021
|
}
|
|
3025
3022
|
function formatForStderr(d) {
|
|
3026
|
-
var
|
|
3023
|
+
var _a4;
|
|
3027
3024
|
const parts = [`[harness:${d.level}]`, d.subsystem, d.message].filter(
|
|
3028
3025
|
Boolean
|
|
3029
3026
|
);
|
|
3030
3027
|
let line = parts.join(" ");
|
|
3031
3028
|
if (d.error) {
|
|
3032
|
-
line += ` (${(
|
|
3029
|
+
line += ` (${(_a4 = d.error.name) != null ? _a4 : "Error"}: ${d.error.message})`;
|
|
3033
3030
|
}
|
|
3034
3031
|
return `${line}
|
|
3035
3032
|
`;
|
|
3036
3033
|
}
|
|
3037
3034
|
function buildObservability(options) {
|
|
3038
|
-
var
|
|
3035
|
+
var _a4;
|
|
3039
3036
|
const resolved = resolveDebugConfig(options.settings.debug);
|
|
3040
3037
|
if (!resolved.enabled) return void 0;
|
|
3041
3038
|
const onLog = options.settings.onLog;
|
|
3042
|
-
const integrations = ((
|
|
3039
|
+
const integrations = ((_a4 = options.settings.telemetry) == null ? void 0 : _a4.integrations) ? asArray(options.settings.telemetry.integrations) : [];
|
|
3043
3040
|
const diagnosticConsumers = integrations.filter(
|
|
3044
3041
|
(integration) => typeof integration.ingestDiagnostic === "function"
|
|
3045
3042
|
);
|
|
3046
3043
|
const report = (emitted) => {
|
|
3047
|
-
var
|
|
3044
|
+
var _a5;
|
|
3048
3045
|
const diagnostic = toHarnessDiagnostic(emitted);
|
|
3049
3046
|
try {
|
|
3050
3047
|
process.stderr.write(formatForStderr(diagnostic));
|
|
@@ -3052,7 +3049,7 @@ function buildObservability(options) {
|
|
|
3052
3049
|
}
|
|
3053
3050
|
onLog == null ? void 0 : onLog(diagnostic);
|
|
3054
3051
|
for (const consumer of diagnosticConsumers) {
|
|
3055
|
-
(
|
|
3052
|
+
(_a5 = consumer.ingestDiagnostic) == null ? void 0 : _a5.call(consumer, diagnostic);
|
|
3056
3053
|
}
|
|
3057
3054
|
};
|
|
3058
3055
|
return {
|
|
@@ -3081,13 +3078,13 @@ function resolveHarnessAgentToolFiltering(input) {
|
|
|
3081
3078
|
availableToolNames: allToolNames
|
|
3082
3079
|
});
|
|
3083
3080
|
const userToolNames = Object.keys(input.userTools);
|
|
3084
|
-
const activeUserToolNames = activeTools != null ? userToolNames.filter((
|
|
3081
|
+
const activeUserToolNames = activeTools != null ? userToolNames.filter((name4) => activeTools.includes(name4)) : inactiveTools != null ? userToolNames.filter((name4) => !inactiveTools.includes(name4)) : userToolNames;
|
|
3085
3082
|
const builtinToolNames = Object.keys(input.harness.builtinTools);
|
|
3086
|
-
const disabledBuiltinToolNames = activeTools != null ? builtinToolNames.filter((
|
|
3083
|
+
const disabledBuiltinToolNames = activeTools != null ? builtinToolNames.filter((name4) => !activeTools.includes(name4)) : inactiveTools != null ? builtinToolNames.filter((name4) => inactiveTools.includes(name4)) : [];
|
|
3087
3084
|
const builtinToolFiltering = disabledBuiltinToolNames.length > 0 ? activeTools != null ? {
|
|
3088
3085
|
mode: "allow",
|
|
3089
3086
|
toolNames: builtinToolNames.filter(
|
|
3090
|
-
(
|
|
3087
|
+
(name4) => activeTools.includes(name4)
|
|
3091
3088
|
)
|
|
3092
3089
|
} : { mode: "deny", toolNames: disabledBuiltinToolNames } : void 0;
|
|
3093
3090
|
if (builtinToolFiltering != null && input.harness.supportsBuiltinToolFiltering !== true && input.harness.supportsBuiltinToolApprovals !== true) {
|
|
@@ -3121,7 +3118,7 @@ function validateToolNames(input) {
|
|
|
3121
3118
|
function filterToolSet(input) {
|
|
3122
3119
|
const allowed = new Set(input.toolNames);
|
|
3123
3120
|
return Object.fromEntries(
|
|
3124
|
-
Object.entries(input.tools).filter(([
|
|
3121
|
+
Object.entries(input.tools).filter(([name4]) => allowed.has(name4))
|
|
3125
3122
|
);
|
|
3126
3123
|
}
|
|
3127
3124
|
|
|
@@ -3129,14 +3126,14 @@ function filterToolSet(input) {
|
|
|
3129
3126
|
var HarnessAgent = class {
|
|
3130
3127
|
constructor(settings) {
|
|
3131
3128
|
this.version = "agent-v1";
|
|
3132
|
-
var
|
|
3129
|
+
var _a4;
|
|
3133
3130
|
const sandboxConfig = resolveSandboxConfig(settings);
|
|
3134
3131
|
validateSandboxBootstrapSettings(sandboxConfig);
|
|
3135
3132
|
this.settings = settings;
|
|
3136
3133
|
this.stopConditions = settings.stopWhen == null ? [] : asArray2(settings.stopWhen);
|
|
3137
3134
|
this.sandboxConfig = sandboxConfig;
|
|
3138
3135
|
this.id = settings.id;
|
|
3139
|
-
const userTools = (
|
|
3136
|
+
const userTools = (_a4 = settings.tools) != null ? _a4 : {};
|
|
3140
3137
|
this.permissionMode = resolvePermissionMode({
|
|
3141
3138
|
permissionMode: settings.permissionMode
|
|
3142
3139
|
});
|
|
@@ -3175,8 +3172,8 @@ var HarnessAgent = class {
|
|
|
3175
3172
|
* `session.destroy()`.
|
|
3176
3173
|
*/
|
|
3177
3174
|
async createSession(options) {
|
|
3178
|
-
var
|
|
3179
|
-
const sessionId = (
|
|
3175
|
+
var _a4;
|
|
3176
|
+
const sessionId = (_a4 = options == null ? void 0 : options.sessionId) != null ? _a4 : generateId5();
|
|
3180
3177
|
const resumeFrom = options == null ? void 0 : options.resumeFrom;
|
|
3181
3178
|
const continueFrom = options == null ? void 0 : options.continueFrom;
|
|
3182
3179
|
const abortSignal = options == null ? void 0 : options.abortSignal;
|
|
@@ -3332,14 +3329,14 @@ var HarnessAgent = class {
|
|
|
3332
3329
|
* consuming a turn that crossed a process boundary.
|
|
3333
3330
|
*/
|
|
3334
3331
|
async continueGenerate(options) {
|
|
3335
|
-
var
|
|
3332
|
+
var _a4, _b4;
|
|
3336
3333
|
const runtimeContext = {};
|
|
3337
3334
|
const { result, done } = this._startTurn({
|
|
3338
3335
|
session: options.session,
|
|
3339
3336
|
turnInput: {
|
|
3340
3337
|
mode: "continue",
|
|
3341
|
-
toolApprovalContinuations: (
|
|
3342
|
-
toolResultContinuations: (
|
|
3338
|
+
toolApprovalContinuations: (_a4 = options.toolApprovalContinuations) != null ? _a4 : [],
|
|
3339
|
+
toolResultContinuations: (_b4 = options.toolResultContinuations) != null ? _b4 : []
|
|
3343
3340
|
},
|
|
3344
3341
|
runtimeContext,
|
|
3345
3342
|
abortSignal: options.abortSignal
|
|
@@ -3356,14 +3353,14 @@ var HarnessAgent = class {
|
|
|
3356
3353
|
* follows from how the adapter resumed the session.
|
|
3357
3354
|
*/
|
|
3358
3355
|
async continueStream(options) {
|
|
3359
|
-
var
|
|
3356
|
+
var _a4, _b4;
|
|
3360
3357
|
const runtimeContext = {};
|
|
3361
3358
|
const { result } = this._startTurn({
|
|
3362
3359
|
session: options.session,
|
|
3363
3360
|
turnInput: {
|
|
3364
3361
|
mode: "continue",
|
|
3365
|
-
toolApprovalContinuations: (
|
|
3366
|
-
toolResultContinuations: (
|
|
3362
|
+
toolApprovalContinuations: (_a4 = options.toolApprovalContinuations) != null ? _a4 : [],
|
|
3363
|
+
toolResultContinuations: (_b4 = options.toolResultContinuations) != null ? _b4 : []
|
|
3367
3364
|
},
|
|
3368
3365
|
runtimeContext,
|
|
3369
3366
|
abortSignal: options.abortSignal
|
|
@@ -3462,7 +3459,7 @@ var HarnessAgent = class {
|
|
|
3462
3459
|
*/
|
|
3463
3460
|
_toToolSpecs() {
|
|
3464
3461
|
const specs = [];
|
|
3465
|
-
for (const [
|
|
3462
|
+
for (const [name4, tool] of Object.entries(
|
|
3466
3463
|
this.activeUserTools
|
|
3467
3464
|
)) {
|
|
3468
3465
|
const t = tool;
|
|
@@ -3475,7 +3472,7 @@ var HarnessAgent = class {
|
|
|
3475
3472
|
} catch (e) {
|
|
3476
3473
|
}
|
|
3477
3474
|
}
|
|
3478
|
-
specs.push({ name:
|
|
3475
|
+
specs.push({ name: name4, description: t.description, inputSchema });
|
|
3479
3476
|
}
|
|
3480
3477
|
return specs;
|
|
3481
3478
|
}
|
|
@@ -3536,8 +3533,8 @@ var HarnessGenerateTextResult = class {
|
|
|
3536
3533
|
}
|
|
3537
3534
|
get warnings() {
|
|
3538
3535
|
return this.steps.flatMap((step) => {
|
|
3539
|
-
var
|
|
3540
|
-
return (
|
|
3536
|
+
var _a4;
|
|
3537
|
+
return (_a4 = step.warnings) != null ? _a4 : [];
|
|
3541
3538
|
});
|
|
3542
3539
|
}
|
|
3543
3540
|
get reasoning() {
|
|
@@ -3562,7 +3559,7 @@ var HarnessGenerateTextResult = class {
|
|
|
3562
3559
|
}
|
|
3563
3560
|
};
|
|
3564
3561
|
function resolveSandboxConfig(settings) {
|
|
3565
|
-
var
|
|
3562
|
+
var _a4;
|
|
3566
3563
|
if (settings.onSandboxSession != null) {
|
|
3567
3564
|
console.warn(
|
|
3568
3565
|
"HarnessAgent: `onSandboxSession` is deprecated. Use `sandboxConfig.onSession` instead."
|
|
@@ -3570,7 +3567,7 @@ function resolveSandboxConfig(settings) {
|
|
|
3570
3567
|
}
|
|
3571
3568
|
return {
|
|
3572
3569
|
...settings.sandboxConfig,
|
|
3573
|
-
...((
|
|
3570
|
+
...((_a4 = settings.sandboxConfig) == null ? void 0 : _a4.onSession) == null && settings.onSandboxSession != null ? { onSession: settings.onSandboxSession } : {}
|
|
3574
3571
|
};
|
|
3575
3572
|
}
|
|
3576
3573
|
function applyPortLease(input) {
|
|
@@ -3609,10 +3606,10 @@ async function cleanupAfterStartFailure(input) {
|
|
|
3609
3606
|
|
|
3610
3607
|
// src/agent/prepare-harness-sandbox-template.ts
|
|
3611
3608
|
async function prepareHarnessSandboxTemplate(options) {
|
|
3612
|
-
var
|
|
3613
|
-
const sandboxConfig = (
|
|
3609
|
+
var _a4, _b4, _c;
|
|
3610
|
+
const sandboxConfig = (_a4 = options.sandboxConfig) != null ? _a4 : {};
|
|
3614
3611
|
validateSandboxBootstrapSettings(sandboxConfig);
|
|
3615
|
-
const recipe = await ((_c = (
|
|
3612
|
+
const recipe = await ((_c = (_b4 = options.harness).getBootstrap) == null ? void 0 : _c.call(_b4, {
|
|
3616
3613
|
abortSignal: options.abortSignal
|
|
3617
3614
|
}));
|
|
3618
3615
|
const bootstrapPlan = await createSandboxBootstrapPlan({
|
|
@@ -3647,8 +3644,8 @@ var prewarmHarness = prepareHarnessSandboxTemplate;
|
|
|
3647
3644
|
// src/agent/prepare-sandbox-for-harness.ts
|
|
3648
3645
|
var PREPARED_SANDBOX_IDENTITY_VERSION = 1;
|
|
3649
3646
|
async function prepareSandboxForHarness(options) {
|
|
3650
|
-
var
|
|
3651
|
-
const sandboxConfig = (
|
|
3647
|
+
var _a4, _b4;
|
|
3648
|
+
const sandboxConfig = (_a4 = options.sandboxConfig) != null ? _a4 : {};
|
|
3652
3649
|
validateSandboxBootstrapSettings(sandboxConfig);
|
|
3653
3650
|
if (options.harnesses.length === 0) {
|
|
3654
3651
|
throw new Error(
|
|
@@ -3664,7 +3661,7 @@ async function prepareSandboxForHarness(options) {
|
|
|
3664
3661
|
const skippedHarnessIds = [];
|
|
3665
3662
|
let defaultWorkingDirectory;
|
|
3666
3663
|
for (const harness of harnesses) {
|
|
3667
|
-
const recipe = await ((
|
|
3664
|
+
const recipe = await ((_b4 = harness.getBootstrap) == null ? void 0 : _b4.call(harness, {
|
|
3668
3665
|
abortSignal: options.abortSignal
|
|
3669
3666
|
}));
|
|
3670
3667
|
if (recipe == null) {
|
|
@@ -3756,13 +3753,44 @@ async function resolvePreparedSandboxIdentity({
|
|
|
3756
3753
|
return hex;
|
|
3757
3754
|
}
|
|
3758
3755
|
|
|
3756
|
+
// src/errors/harness-sandbox-authentication-error.ts
|
|
3757
|
+
import { AISDKError as AISDKError3 } from "@ai-sdk/provider";
|
|
3758
|
+
var name3 = "AI_HarnessSandboxAuthenticationError";
|
|
3759
|
+
var marker3 = `vercel.ai.error.${name3}`;
|
|
3760
|
+
var symbol3 = Symbol.for(marker3);
|
|
3761
|
+
var _a3, _b3;
|
|
3762
|
+
var HarnessSandboxAuthenticationError = class extends (_b3 = HarnessError, _a3 = symbol3, _b3) {
|
|
3763
|
+
constructor({
|
|
3764
|
+
message,
|
|
3765
|
+
sandboxProviderId,
|
|
3766
|
+
cause
|
|
3767
|
+
}) {
|
|
3768
|
+
super({ message, cause });
|
|
3769
|
+
this[_a3] = true;
|
|
3770
|
+
Object.defineProperty(this, "name", { value: name3 });
|
|
3771
|
+
this.sandboxProviderId = sandboxProviderId;
|
|
3772
|
+
}
|
|
3773
|
+
static isInstance(error) {
|
|
3774
|
+
return AISDKError3.hasMarker(error, marker3);
|
|
3775
|
+
}
|
|
3776
|
+
};
|
|
3777
|
+
|
|
3778
|
+
// src/agent/get-harness-error-message.ts
|
|
3779
|
+
var defaultErrorMessage = "An error occurred.";
|
|
3780
|
+
function getHarnessErrorMessage(error) {
|
|
3781
|
+
if (HarnessCapabilityUnsupportedError.isInstance(error) || HarnessSandboxAuthenticationError.isInstance(error) || HarnessError.isInstance(error) && error.name === "AI_HarnessError") {
|
|
3782
|
+
return error.message;
|
|
3783
|
+
}
|
|
3784
|
+
return defaultErrorMessage;
|
|
3785
|
+
}
|
|
3786
|
+
|
|
3759
3787
|
// src/agent/observability/file-reporter.ts
|
|
3760
3788
|
import { appendFileSync, mkdirSync } from "fs";
|
|
3761
3789
|
function createFileReporter(options) {
|
|
3762
|
-
var
|
|
3763
|
-
const fileName = (
|
|
3790
|
+
var _a4, _b4;
|
|
3791
|
+
const fileName = (_a4 = options.fileName) != null ? _a4 : "events.jsonl";
|
|
3764
3792
|
const path = `${options.dir}/${fileName}`;
|
|
3765
|
-
const failOnly = (
|
|
3793
|
+
const failOnly = (_b4 = options.failOnly) != null ? _b4 : false;
|
|
3766
3794
|
const turns = /* @__PURE__ */ new Map();
|
|
3767
3795
|
let lastOpenCallId;
|
|
3768
3796
|
let dirReady = false;
|
|
@@ -3861,14 +3889,14 @@ function createFileReporter(options) {
|
|
|
3861
3889
|
});
|
|
3862
3890
|
},
|
|
3863
3891
|
onEnd(event) {
|
|
3864
|
-
var
|
|
3892
|
+
var _a5;
|
|
3865
3893
|
const e = event;
|
|
3866
3894
|
record(e.callId, {
|
|
3867
3895
|
ts: Date.now(),
|
|
3868
3896
|
kind: "turn-finish",
|
|
3869
3897
|
callId: e.callId,
|
|
3870
3898
|
finishReason: e.finishReason,
|
|
3871
|
-
usage: (
|
|
3899
|
+
usage: (_a5 = e.totalUsage) != null ? _a5 : e.usage
|
|
3872
3900
|
});
|
|
3873
3901
|
finishTurn(e.callId);
|
|
3874
3902
|
},
|
|
@@ -3895,8 +3923,8 @@ function createFileReporter(options) {
|
|
|
3895
3923
|
|
|
3896
3924
|
// src/agent/observability/trace-tree-reporter.ts
|
|
3897
3925
|
function createTraceTreeReporter(options = {}) {
|
|
3898
|
-
var
|
|
3899
|
-
const write = (
|
|
3926
|
+
var _a4;
|
|
3927
|
+
const write = (_a4 = options.write) != null ? _a4 : ((chunk) => void process.stderr.write(chunk));
|
|
3900
3928
|
const turns = /* @__PURE__ */ new Map();
|
|
3901
3929
|
const render = (node, depth) => {
|
|
3902
3930
|
const indent = " ".repeat(depth);
|
|
@@ -3908,11 +3936,11 @@ function createTraceTreeReporter(options = {}) {
|
|
|
3908
3936
|
};
|
|
3909
3937
|
return {
|
|
3910
3938
|
onStart(event) {
|
|
3911
|
-
var
|
|
3939
|
+
var _a5;
|
|
3912
3940
|
const e = event;
|
|
3913
3941
|
turns.set(e.callId, {
|
|
3914
3942
|
root: {
|
|
3915
|
-
label: `${(
|
|
3943
|
+
label: `${(_a5 = e.operationId) != null ? _a5 : "turn"}${e.modelId ? ` ${e.modelId}` : ""}`,
|
|
3916
3944
|
startMs: Date.now(),
|
|
3917
3945
|
children: []
|
|
3918
3946
|
},
|
|
@@ -3920,12 +3948,12 @@ function createTraceTreeReporter(options = {}) {
|
|
|
3920
3948
|
});
|
|
3921
3949
|
},
|
|
3922
3950
|
onStepStart(event) {
|
|
3923
|
-
var
|
|
3951
|
+
var _a5;
|
|
3924
3952
|
const e = event;
|
|
3925
3953
|
const turn = turns.get(e.callId);
|
|
3926
3954
|
if (!turn) return;
|
|
3927
3955
|
const step = {
|
|
3928
|
-
label: `step ${((
|
|
3956
|
+
label: `step ${((_a5 = e.stepNumber) != null ? _a5 : turn.root.children.length) + 1}`,
|
|
3929
3957
|
startMs: Date.now(),
|
|
3930
3958
|
children: []
|
|
3931
3959
|
};
|
|
@@ -3933,10 +3961,10 @@ function createTraceTreeReporter(options = {}) {
|
|
|
3933
3961
|
turn.root.children.push(step);
|
|
3934
3962
|
},
|
|
3935
3963
|
onToolExecutionStart(event) {
|
|
3936
|
-
var
|
|
3964
|
+
var _a5;
|
|
3937
3965
|
const e = event;
|
|
3938
3966
|
const turn = turns.get(e.callId);
|
|
3939
|
-
const parent = (
|
|
3967
|
+
const parent = (_a5 = turn == null ? void 0 : turn.step) != null ? _a5 : turn == null ? void 0 : turn.root;
|
|
3940
3968
|
if (!turn || !parent) return;
|
|
3941
3969
|
const node = {
|
|
3942
3970
|
label: `tool ${e.toolCall.toolName}`,
|
|
@@ -3947,9 +3975,9 @@ function createTraceTreeReporter(options = {}) {
|
|
|
3947
3975
|
parent.children.push(node);
|
|
3948
3976
|
},
|
|
3949
3977
|
onToolExecutionEnd(event) {
|
|
3950
|
-
var
|
|
3978
|
+
var _a5;
|
|
3951
3979
|
const e = event;
|
|
3952
|
-
const node = (
|
|
3980
|
+
const node = (_a5 = turns.get(e.callId)) == null ? void 0 : _a5.tools.get(e.toolCall.toolCallId);
|
|
3953
3981
|
if (!node) return;
|
|
3954
3982
|
node.endMs = Date.now();
|
|
3955
3983
|
if (e.toolOutput.type === "error") node.label += " [error]";
|
|
@@ -3981,10 +4009,12 @@ export {
|
|
|
3981
4009
|
HarnessAgentSession,
|
|
3982
4010
|
HarnessCapabilityUnsupportedError,
|
|
3983
4011
|
HarnessError,
|
|
4012
|
+
HarnessSandboxAuthenticationError,
|
|
3984
4013
|
collectHarnessAgentToolApprovalContinuations,
|
|
3985
4014
|
collectHarnessAgentToolResultContinuations,
|
|
3986
4015
|
createFileReporter,
|
|
3987
4016
|
createTraceTreeReporter,
|
|
4017
|
+
getHarnessErrorMessage,
|
|
3988
4018
|
prepareHarnessSandboxTemplate,
|
|
3989
4019
|
prepareSandboxForHarness,
|
|
3990
4020
|
prewarmHarness
|