@ai-sdk/harness 1.0.40 → 1.0.41
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/dist/agent/index.js +63 -62
- package/dist/agent/index.js.map +1 -1
- package/package.json +2 -2
- package/src/agent/internal/run-prompt.ts +20 -19
- package/src/agent/internal/turn-telemetry.ts +43 -43
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @ai-sdk/harness
|
|
2
2
|
|
|
3
|
+
## 1.0.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a94425b: fix(harness): ensure harness telemetry hooks are awaited before stream processing continues
|
|
8
|
+
- 2de0611: fix(harness): avoid incorrectly marked invalid tool calls due to `dynamic` flag being dropped
|
|
9
|
+
- Updated dependencies [7fa85b2]
|
|
10
|
+
- ai@7.0.36
|
|
11
|
+
|
|
3
12
|
## 1.0.40
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/agent/index.js
CHANGED
|
@@ -919,22 +919,22 @@ function stripDeep(value, workDir) {
|
|
|
919
919
|
import { generateId as generateId3 } from "@ai-sdk/provider-utils";
|
|
920
920
|
import { createTelemetryDispatcher } from "ai/internal";
|
|
921
921
|
var NOOP = {
|
|
922
|
-
start() {
|
|
922
|
+
async start() {
|
|
923
923
|
},
|
|
924
|
-
ensureStepOpen() {
|
|
924
|
+
async ensureStepOpen() {
|
|
925
925
|
},
|
|
926
|
-
stepFinish() {
|
|
926
|
+
async stepFinish() {
|
|
927
927
|
},
|
|
928
928
|
async toolStart() {
|
|
929
929
|
},
|
|
930
930
|
async executeTool({ execute }) {
|
|
931
931
|
return await execute();
|
|
932
932
|
},
|
|
933
|
-
toolEnd() {
|
|
933
|
+
async toolEnd() {
|
|
934
934
|
},
|
|
935
|
-
end() {
|
|
935
|
+
async end() {
|
|
936
936
|
},
|
|
937
|
-
error() {
|
|
937
|
+
async error() {
|
|
938
938
|
}
|
|
939
939
|
};
|
|
940
940
|
function createTurnTelemetry(opts) {
|
|
@@ -954,11 +954,11 @@ function createTurnTelemetry(opts) {
|
|
|
954
954
|
let ended = false;
|
|
955
955
|
const openTools = /* @__PURE__ */ new Map();
|
|
956
956
|
const cast = (event) => event;
|
|
957
|
-
const fireStart = () => {
|
|
957
|
+
const fireStart = async () => {
|
|
958
958
|
var _a4;
|
|
959
959
|
if (started) return;
|
|
960
960
|
started = true;
|
|
961
|
-
(_a4 = dispatcher.onStart) == null ? void 0 : _a4.call(
|
|
961
|
+
await ((_a4 = dispatcher.onStart) == null ? void 0 : _a4.call(
|
|
962
962
|
dispatcher,
|
|
963
963
|
cast({
|
|
964
964
|
callId,
|
|
@@ -978,19 +978,19 @@ function createTurnTelemetry(opts) {
|
|
|
978
978
|
instructions: opts.instructions,
|
|
979
979
|
messages: inputMessages
|
|
980
980
|
})
|
|
981
|
-
);
|
|
981
|
+
));
|
|
982
982
|
};
|
|
983
|
-
const start = (overrideModelId) => {
|
|
983
|
+
const start = async (overrideModelId) => {
|
|
984
984
|
if (started) return;
|
|
985
985
|
if (overrideModelId) modelId = overrideModelId;
|
|
986
|
-
fireStart();
|
|
986
|
+
await fireStart();
|
|
987
987
|
};
|
|
988
|
-
const ensureStepOpen = () => {
|
|
988
|
+
const ensureStepOpen = async () => {
|
|
989
989
|
var _a4, _b3;
|
|
990
|
-
if (!started) fireStart();
|
|
990
|
+
if (!started) await fireStart();
|
|
991
991
|
if (stepOpen || ended) return;
|
|
992
992
|
stepOpen = true;
|
|
993
|
-
(_a4 = dispatcher.onStepStart) == null ? void 0 : _a4.call(
|
|
993
|
+
await ((_a4 = dispatcher.onStepStart) == null ? void 0 : _a4.call(
|
|
994
994
|
dispatcher,
|
|
995
995
|
cast({
|
|
996
996
|
callId,
|
|
@@ -1006,8 +1006,8 @@ function createTurnTelemetry(opts) {
|
|
|
1006
1006
|
runtimeContext,
|
|
1007
1007
|
messages: inputMessages
|
|
1008
1008
|
})
|
|
1009
|
-
);
|
|
1010
|
-
(_b3 = dispatcher.onLanguageModelCallStart) == null ? void 0 : _b3.call(
|
|
1009
|
+
));
|
|
1010
|
+
await ((_b3 = dispatcher.onLanguageModelCallStart) == null ? void 0 : _b3.call(
|
|
1011
1011
|
dispatcher,
|
|
1012
1012
|
cast({
|
|
1013
1013
|
callId,
|
|
@@ -1016,11 +1016,11 @@ function createTurnTelemetry(opts) {
|
|
|
1016
1016
|
messages: inputMessages,
|
|
1017
1017
|
tools: void 0
|
|
1018
1018
|
})
|
|
1019
|
-
);
|
|
1019
|
+
));
|
|
1020
1020
|
};
|
|
1021
|
-
const inferenceEnd = (info) => {
|
|
1021
|
+
const inferenceEnd = async (info) => {
|
|
1022
1022
|
var _a4;
|
|
1023
|
-
(_a4 = dispatcher.onLanguageModelCallEnd) == null ? void 0 : _a4.call(
|
|
1023
|
+
await ((_a4 = dispatcher.onLanguageModelCallEnd) == null ? void 0 : _a4.call(
|
|
1024
1024
|
dispatcher,
|
|
1025
1025
|
cast({
|
|
1026
1026
|
callId,
|
|
@@ -1029,12 +1029,12 @@ function createTurnTelemetry(opts) {
|
|
|
1029
1029
|
usage: info.usage,
|
|
1030
1030
|
content: info.content
|
|
1031
1031
|
})
|
|
1032
|
-
);
|
|
1032
|
+
));
|
|
1033
1033
|
};
|
|
1034
|
-
const closeOpenTools = () => {
|
|
1034
|
+
const closeOpenTools = async () => {
|
|
1035
1035
|
var _a4;
|
|
1036
1036
|
for (const call of openTools.values()) {
|
|
1037
|
-
(_a4 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a4.call(
|
|
1037
|
+
await ((_a4 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a4.call(
|
|
1038
1038
|
dispatcher,
|
|
1039
1039
|
cast({
|
|
1040
1040
|
callId,
|
|
@@ -1050,24 +1050,24 @@ function createTurnTelemetry(opts) {
|
|
|
1050
1050
|
toolContext: void 0,
|
|
1051
1051
|
toolOutput: { type: "error", error: new Error("tool span unclosed") }
|
|
1052
1052
|
})
|
|
1053
|
-
);
|
|
1053
|
+
));
|
|
1054
1054
|
}
|
|
1055
1055
|
openTools.clear();
|
|
1056
1056
|
};
|
|
1057
1057
|
return {
|
|
1058
1058
|
start,
|
|
1059
1059
|
ensureStepOpen,
|
|
1060
|
-
stepFinish(info) {
|
|
1060
|
+
async stepFinish(info) {
|
|
1061
1061
|
var _a4, _b3;
|
|
1062
1062
|
if (!stepOpen) return;
|
|
1063
1063
|
const content = (_a4 = info.content) != null ? _a4 : [];
|
|
1064
|
-
closeOpenTools();
|
|
1065
|
-
inferenceEnd({
|
|
1064
|
+
await closeOpenTools();
|
|
1065
|
+
await inferenceEnd({
|
|
1066
1066
|
finishReason: info.finishReason,
|
|
1067
1067
|
usage: info.usage,
|
|
1068
1068
|
content
|
|
1069
1069
|
});
|
|
1070
|
-
(_b3 = dispatcher.onStepEnd) == null ? void 0 : _b3.call(
|
|
1070
|
+
await ((_b3 = dispatcher.onStepEnd) == null ? void 0 : _b3.call(
|
|
1071
1071
|
dispatcher,
|
|
1072
1072
|
cast({
|
|
1073
1073
|
callId,
|
|
@@ -1083,13 +1083,13 @@ function createTurnTelemetry(opts) {
|
|
|
1083
1083
|
messages: []
|
|
1084
1084
|
}
|
|
1085
1085
|
})
|
|
1086
|
-
);
|
|
1086
|
+
));
|
|
1087
1087
|
stepOpen = false;
|
|
1088
1088
|
stepNumber += 1;
|
|
1089
1089
|
},
|
|
1090
1090
|
async toolStart(call) {
|
|
1091
1091
|
var _a4;
|
|
1092
|
-
ensureStepOpen();
|
|
1092
|
+
await ensureStepOpen();
|
|
1093
1093
|
if (openTools.has(call.toolCallId)) return;
|
|
1094
1094
|
openTools.set(call.toolCallId, call);
|
|
1095
1095
|
await ((_a4 = dispatcher.onToolExecutionStart) == null ? void 0 : _a4.call(
|
|
@@ -1112,12 +1112,12 @@ function createTurnTelemetry(opts) {
|
|
|
1112
1112
|
if (dispatcher.executeTool == null) return await execute();
|
|
1113
1113
|
return await dispatcher.executeTool({ callId, toolCallId, execute });
|
|
1114
1114
|
},
|
|
1115
|
-
toolEnd(toolCallId, output) {
|
|
1115
|
+
async toolEnd(toolCallId, output) {
|
|
1116
1116
|
var _a4;
|
|
1117
1117
|
const call = openTools.get(toolCallId);
|
|
1118
1118
|
if (call == null) return;
|
|
1119
1119
|
openTools.delete(toolCallId);
|
|
1120
|
-
(_a4 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a4.call(
|
|
1120
|
+
await ((_a4 = dispatcher.onToolExecutionEnd) == null ? void 0 : _a4.call(
|
|
1121
1121
|
dispatcher,
|
|
1122
1122
|
cast({
|
|
1123
1123
|
callId,
|
|
@@ -1133,20 +1133,20 @@ function createTurnTelemetry(opts) {
|
|
|
1133
1133
|
toolContext: void 0,
|
|
1134
1134
|
toolOutput: output.ok ? { type: "tool-result", output: output.output } : { type: "error", error: output.error }
|
|
1135
1135
|
})
|
|
1136
|
-
);
|
|
1136
|
+
));
|
|
1137
1137
|
},
|
|
1138
|
-
end(info) {
|
|
1138
|
+
async end(info) {
|
|
1139
1139
|
var _a4, _b3;
|
|
1140
1140
|
if (ended) return;
|
|
1141
|
-
if (!started) fireStart();
|
|
1141
|
+
if (!started) await fireStart();
|
|
1142
1142
|
if (stepOpen) {
|
|
1143
|
-
closeOpenTools();
|
|
1144
|
-
inferenceEnd({
|
|
1143
|
+
await closeOpenTools();
|
|
1144
|
+
await inferenceEnd({
|
|
1145
1145
|
finishReason: info.finishReason,
|
|
1146
1146
|
usage: info.usage,
|
|
1147
1147
|
content: []
|
|
1148
1148
|
});
|
|
1149
|
-
(_a4 = dispatcher.onStepEnd) == null ? void 0 : _a4.call(
|
|
1149
|
+
await ((_a4 = dispatcher.onStepEnd) == null ? void 0 : _a4.call(
|
|
1150
1150
|
dispatcher,
|
|
1151
1151
|
cast({
|
|
1152
1152
|
callId,
|
|
@@ -1162,11 +1162,11 @@ function createTurnTelemetry(opts) {
|
|
|
1162
1162
|
messages: []
|
|
1163
1163
|
}
|
|
1164
1164
|
})
|
|
1165
|
-
);
|
|
1165
|
+
));
|
|
1166
1166
|
stepOpen = false;
|
|
1167
1167
|
}
|
|
1168
1168
|
ended = true;
|
|
1169
|
-
(_b3 = dispatcher.onEnd) == null ? void 0 : _b3.call(
|
|
1169
|
+
await ((_b3 = dispatcher.onEnd) == null ? void 0 : _b3.call(
|
|
1170
1170
|
dispatcher,
|
|
1171
1171
|
cast({
|
|
1172
1172
|
callId,
|
|
@@ -1184,15 +1184,15 @@ function createTurnTelemetry(opts) {
|
|
|
1184
1184
|
},
|
|
1185
1185
|
runtimeContext
|
|
1186
1186
|
})
|
|
1187
|
-
);
|
|
1187
|
+
));
|
|
1188
1188
|
},
|
|
1189
|
-
error(err) {
|
|
1189
|
+
async error(err) {
|
|
1190
1190
|
var _a4;
|
|
1191
1191
|
if (ended) return;
|
|
1192
|
-
if (!started) fireStart();
|
|
1193
|
-
closeOpenTools();
|
|
1192
|
+
if (!started) await fireStart();
|
|
1193
|
+
await closeOpenTools();
|
|
1194
1194
|
ended = true;
|
|
1195
|
-
(_a4 = dispatcher.onError) == null ? void 0 : _a4.call(dispatcher, err);
|
|
1195
|
+
await ((_a4 = dispatcher.onError) == null ? void 0 : _a4.call(dispatcher, err));
|
|
1196
1196
|
}
|
|
1197
1197
|
};
|
|
1198
1198
|
}
|
|
@@ -1353,7 +1353,7 @@ function runPrompt(input) {
|
|
|
1353
1353
|
}
|
|
1354
1354
|
});
|
|
1355
1355
|
} catch (err) {
|
|
1356
|
-
telemetry.error(err);
|
|
1356
|
+
await telemetry.error(err);
|
|
1357
1357
|
logBridgeError({
|
|
1358
1358
|
harnessId: input.harness.harnessId,
|
|
1359
1359
|
sessionId: input.session.sessionId,
|
|
@@ -1433,8 +1433,8 @@ function runPrompt(input) {
|
|
|
1433
1433
|
unified: "tool-calls",
|
|
1434
1434
|
raw: void 0
|
|
1435
1435
|
};
|
|
1436
|
-
const completeStep = (input2) => {
|
|
1437
|
-
telemetry.stepFinish({
|
|
1436
|
+
const completeStep = async (input2) => {
|
|
1437
|
+
await telemetry.stepFinish({
|
|
1438
1438
|
finishReason: input2.finishReason,
|
|
1439
1439
|
usage: input2.usage,
|
|
1440
1440
|
providerMetadata: input2.providerMetadata,
|
|
@@ -1452,13 +1452,13 @@ function runPrompt(input) {
|
|
|
1452
1452
|
};
|
|
1453
1453
|
const finishForHostInputPause = async (options) => {
|
|
1454
1454
|
if (options.completeCurrentStep) {
|
|
1455
|
-
completeStep({
|
|
1455
|
+
await completeStep({
|
|
1456
1456
|
finishReason: toolCallsFinishReason,
|
|
1457
1457
|
usage: zeroUsage,
|
|
1458
1458
|
providerMetadata: void 0
|
|
1459
1459
|
});
|
|
1460
1460
|
}
|
|
1461
|
-
telemetry.end({
|
|
1461
|
+
await telemetry.end({
|
|
1462
1462
|
finishReason: toolCallsFinishReason,
|
|
1463
1463
|
usage: zeroUsage
|
|
1464
1464
|
});
|
|
@@ -1549,7 +1549,7 @@ function runPrompt(input) {
|
|
|
1549
1549
|
toolName: approval.toolName,
|
|
1550
1550
|
input: approval.input
|
|
1551
1551
|
};
|
|
1552
|
-
telemetry.start(input.session.modelId);
|
|
1552
|
+
await telemetry.start(input.session.modelId);
|
|
1553
1553
|
await telemetry.toolStart({
|
|
1554
1554
|
toolCallId: rawToolCall.toolCallId,
|
|
1555
1555
|
toolName: rawToolCall.toolName,
|
|
@@ -1587,7 +1587,7 @@ function runPrompt(input) {
|
|
|
1587
1587
|
await finishForHostInputPause({ completeCurrentStep: false });
|
|
1588
1588
|
return "awaiting-tool-result";
|
|
1589
1589
|
}
|
|
1590
|
-
telemetry.toolEnd(rawToolCall.toolCallId, execution.outcome);
|
|
1590
|
+
await telemetry.toolEnd(rawToolCall.toolCallId, execution.outcome);
|
|
1591
1591
|
return "continued";
|
|
1592
1592
|
};
|
|
1593
1593
|
try {
|
|
@@ -1632,7 +1632,7 @@ function runPrompt(input) {
|
|
|
1632
1632
|
await ((_c2 = input.onStopConditionMet) == null ? void 0 : _c2.call(input));
|
|
1633
1633
|
const { finishReason, usage } = pendingStopBoundary;
|
|
1634
1634
|
releasePendingStopBoundary();
|
|
1635
|
-
telemetry.end({ finishReason, usage });
|
|
1635
|
+
await telemetry.end({ finishReason, usage });
|
|
1636
1636
|
await result.finish();
|
|
1637
1637
|
return;
|
|
1638
1638
|
} else {
|
|
@@ -1640,10 +1640,10 @@ function runPrompt(input) {
|
|
|
1640
1640
|
}
|
|
1641
1641
|
}
|
|
1642
1642
|
if (value.type === "stream-start") {
|
|
1643
|
-
telemetry.start((_d2 = value.modelId) != null ? _d2 : input.session.modelId);
|
|
1643
|
+
await telemetry.start((_d2 = value.modelId) != null ? _d2 : input.session.modelId);
|
|
1644
1644
|
}
|
|
1645
1645
|
if (value.type !== "stream-start" && value.type !== "finish-step" && value.type !== "finish" && value.type !== "error") {
|
|
1646
|
-
telemetry.ensureStepOpen();
|
|
1646
|
+
await telemetry.ensureStepOpen();
|
|
1647
1647
|
}
|
|
1648
1648
|
const displayValue = stripWorkDir(value, input.sessionWorkDir);
|
|
1649
1649
|
const settledHostInputReplay = (displayValue.type === "tool-call" || displayValue.type === "tool-result" || displayValue.type === "tool-approval-request") && settledHostToolCallIds.has(displayValue.toolCallId);
|
|
@@ -1687,7 +1687,7 @@ function runPrompt(input) {
|
|
|
1687
1687
|
}
|
|
1688
1688
|
}
|
|
1689
1689
|
if (value.type === "error" && displayValue.type === "error") {
|
|
1690
|
-
telemetry.error(value.error);
|
|
1690
|
+
await telemetry.error(value.error);
|
|
1691
1691
|
logBridgeError({
|
|
1692
1692
|
harnessId: input.harness.harnessId,
|
|
1693
1693
|
sessionId: input.session.sessionId,
|
|
@@ -1729,7 +1729,7 @@ function runPrompt(input) {
|
|
|
1729
1729
|
});
|
|
1730
1730
|
}
|
|
1731
1731
|
if (value.type === "tool-result") {
|
|
1732
|
-
telemetry.toolEnd(
|
|
1732
|
+
await telemetry.toolEnd(
|
|
1733
1733
|
value.toolCallId,
|
|
1734
1734
|
value.isError ? { ok: false, error: value.result } : { ok: true, output: value.result }
|
|
1735
1735
|
);
|
|
@@ -1780,7 +1780,7 @@ function runPrompt(input) {
|
|
|
1780
1780
|
return;
|
|
1781
1781
|
}
|
|
1782
1782
|
if (value.type === "finish-step") {
|
|
1783
|
-
completeStep({
|
|
1783
|
+
await completeStep({
|
|
1784
1784
|
finishReason: value.finishReason,
|
|
1785
1785
|
usage: value.usage,
|
|
1786
1786
|
providerMetadata: value.harnessMetadata
|
|
@@ -1795,7 +1795,7 @@ function runPrompt(input) {
|
|
|
1795
1795
|
}
|
|
1796
1796
|
if (value.type === "finish") {
|
|
1797
1797
|
finalFinish = value;
|
|
1798
|
-
telemetry.end({
|
|
1798
|
+
await telemetry.end({
|
|
1799
1799
|
finishReason: value.finishReason,
|
|
1800
1800
|
usage: value.totalUsage
|
|
1801
1801
|
});
|
|
@@ -1819,7 +1819,7 @@ function runPrompt(input) {
|
|
|
1819
1819
|
toolCallId: toolCall.toolCallId,
|
|
1820
1820
|
output
|
|
1821
1821
|
});
|
|
1822
|
-
telemetry.toolEnd(toolCall.toolCallId, { ok: true, output });
|
|
1822
|
+
await telemetry.toolEnd(toolCall.toolCallId, { ok: true, output });
|
|
1823
1823
|
continue;
|
|
1824
1824
|
}
|
|
1825
1825
|
const customToolApprovalDecision = resolveCustomToolApproval({
|
|
@@ -1848,7 +1848,7 @@ function runPrompt(input) {
|
|
|
1848
1848
|
toolCallId: toolCall.toolCallId,
|
|
1849
1849
|
output
|
|
1850
1850
|
});
|
|
1851
|
-
telemetry.toolEnd(toolCall.toolCallId, { ok: true, output });
|
|
1851
|
+
await telemetry.toolEnd(toolCall.toolCallId, { ok: true, output });
|
|
1852
1852
|
continue;
|
|
1853
1853
|
}
|
|
1854
1854
|
const pendingApproval = (_i = pendingApprovalsByToolCallId.get(toolCall.toolCallId)) != null ? _i : customToolApprovalDecision.type === "request" ? {
|
|
@@ -1929,7 +1929,7 @@ function runPrompt(input) {
|
|
|
1929
1929
|
await finishForHostInputPause({ completeCurrentStep: true });
|
|
1930
1930
|
return;
|
|
1931
1931
|
}
|
|
1932
|
-
telemetry.toolEnd(toolCall.toolCallId, execution.outcome);
|
|
1932
|
+
await telemetry.toolEnd(toolCall.toolCallId, execution.outcome);
|
|
1933
1933
|
}
|
|
1934
1934
|
}
|
|
1935
1935
|
if (finalFinish != null) {
|
|
@@ -1945,7 +1945,7 @@ function runPrompt(input) {
|
|
|
1945
1945
|
} : void 0
|
|
1946
1946
|
);
|
|
1947
1947
|
} catch (err) {
|
|
1948
|
-
telemetry.error(err);
|
|
1948
|
+
await telemetry.error(err);
|
|
1949
1949
|
logBridgeError({
|
|
1950
1950
|
harnessId: input.harness.harnessId,
|
|
1951
1951
|
sessionId: input.session.sessionId,
|
|
@@ -2026,6 +2026,7 @@ async function validateToolCall(args) {
|
|
|
2026
2026
|
toolName: event.toolName,
|
|
2027
2027
|
input: event.input,
|
|
2028
2028
|
...event.providerExecuted !== void 0 ? { providerExecuted: event.providerExecuted } : {},
|
|
2029
|
+
...event.dynamic !== void 0 ? { dynamic: event.dynamic } : {},
|
|
2029
2030
|
...event.providerMetadata !== void 0 ? { providerMetadata: event.providerMetadata } : {}
|
|
2030
2031
|
};
|
|
2031
2032
|
const parsed = await parseToolCall({
|