@ai-sdk/harness 1.0.117 → 1.0.118
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 +12 -0
- package/dist/agent/index.js +64 -18
- package/dist/agent/index.js.map +1 -1
- package/dist/utils/index.d.ts +19 -3
- package/dist/utils/index.js +220 -53
- package/dist/utils/index.js.map +1 -1
- package/package.json +3 -3
- package/src/agent/internal/strip-work-dir.ts +91 -20
- package/src/utils/index.ts +2 -0
- package/src/utils/sandbox-channel.ts +220 -57
- package/src/utils/sleep.ts +30 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/harness
|
|
2
2
|
|
|
3
|
+
## 1.0.118
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- d975097: feat(harness): add `AbortSignal` to `SandboxChannel.connect`, plus a `sleep()` helper function
|
|
8
|
+
- b2baeba: fix(harness): preserve work directory text inside longer path segments
|
|
9
|
+
- Updated dependencies [3f6852a]
|
|
10
|
+
- Updated dependencies [6317504]
|
|
11
|
+
- Updated dependencies [3cb2dcd]
|
|
12
|
+
- Updated dependencies [ccf98e7]
|
|
13
|
+
- ai@7.0.108
|
|
14
|
+
|
|
3
15
|
## 1.0.117
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/agent/index.js
CHANGED
|
@@ -1014,30 +1014,44 @@ function translateStreamPart(event, options = {}) {
|
|
|
1014
1014
|
function createToolInputWorkDirStripper({
|
|
1015
1015
|
sessionWorkDir
|
|
1016
1016
|
}) {
|
|
1017
|
-
const
|
|
1017
|
+
const stateByToolCallId = /* @__PURE__ */ new Map();
|
|
1018
1018
|
return (part) => {
|
|
1019
1019
|
var _a4;
|
|
1020
1020
|
if (sessionWorkDir.length === 0) return [part];
|
|
1021
1021
|
if (part.type === "tool-input-start") {
|
|
1022
|
-
|
|
1022
|
+
stateByToolCallId.set(part.id, {
|
|
1023
|
+
pending: "",
|
|
1024
|
+
precedingCharacter: void 0
|
|
1025
|
+
});
|
|
1023
1026
|
return [part];
|
|
1024
1027
|
}
|
|
1025
1028
|
if (part.type === "tool-input-delta") {
|
|
1029
|
+
const state2 = (_a4 = stateByToolCallId.get(part.id)) != null ? _a4 : {
|
|
1030
|
+
pending: "",
|
|
1031
|
+
precedingCharacter: void 0
|
|
1032
|
+
};
|
|
1033
|
+
const value = state2.pending + part.delta;
|
|
1026
1034
|
const stripped2 = stripStreamingString({
|
|
1027
|
-
value
|
|
1035
|
+
value,
|
|
1028
1036
|
workDir: sessionWorkDir,
|
|
1029
|
-
final: false
|
|
1037
|
+
final: false,
|
|
1038
|
+
precedingCharacter: state2.precedingCharacter
|
|
1039
|
+
});
|
|
1040
|
+
const pendingStart = value.length - stripped2.pending.length;
|
|
1041
|
+
stateByToolCallId.set(part.id, {
|
|
1042
|
+
pending: stripped2.pending,
|
|
1043
|
+
precedingCharacter: stripped2.pending.length > 0 ? pendingStart > 0 ? value[pendingStart - 1] : state2.precedingCharacter : value.length > 0 ? value[value.length - 1] : state2.precedingCharacter
|
|
1030
1044
|
});
|
|
1031
|
-
pendingByToolCallId.set(part.id, stripped2.pending);
|
|
1032
1045
|
return stripped2.output.length === 0 ? [] : [{ ...part, delta: stripped2.output }];
|
|
1033
1046
|
}
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
if (
|
|
1047
|
+
const state = stateByToolCallId.get(part.id);
|
|
1048
|
+
stateByToolCallId.delete(part.id);
|
|
1049
|
+
if (state == null || state.pending.length === 0) return [part];
|
|
1037
1050
|
const stripped = stripStreamingString({
|
|
1038
|
-
value: pending,
|
|
1051
|
+
value: state.pending,
|
|
1039
1052
|
workDir: sessionWorkDir,
|
|
1040
|
-
final: true
|
|
1053
|
+
final: true,
|
|
1054
|
+
precedingCharacter: state.precedingCharacter
|
|
1041
1055
|
});
|
|
1042
1056
|
return stripped.output.length === 0 ? [part] : [
|
|
1043
1057
|
{ type: "tool-input-delta", id: part.id, delta: stripped.output },
|
|
@@ -1064,34 +1078,59 @@ function stripWorkDir(part, sessionWorkDir) {
|
|
|
1064
1078
|
}
|
|
1065
1079
|
}
|
|
1066
1080
|
function stripString(value, workDir) {
|
|
1067
|
-
return
|
|
1081
|
+
return stripStreamingString({
|
|
1082
|
+
value,
|
|
1083
|
+
workDir,
|
|
1084
|
+
final: true,
|
|
1085
|
+
precedingCharacter: void 0
|
|
1086
|
+
}).output;
|
|
1068
1087
|
}
|
|
1069
1088
|
function stripStreamingString({
|
|
1070
1089
|
value,
|
|
1071
1090
|
workDir,
|
|
1072
|
-
final
|
|
1091
|
+
final,
|
|
1092
|
+
precedingCharacter
|
|
1073
1093
|
}) {
|
|
1074
1094
|
let remaining = value;
|
|
1075
1095
|
let output = "";
|
|
1096
|
+
let characterBeforeRemaining = precedingCharacter;
|
|
1076
1097
|
while (remaining.length > 0) {
|
|
1077
1098
|
const matchIndex = remaining.indexOf(workDir);
|
|
1078
1099
|
if (matchIndex >= 0) {
|
|
1079
|
-
output += remaining.slice(0, matchIndex);
|
|
1080
1100
|
const followingIndex = matchIndex + workDir.length;
|
|
1081
|
-
|
|
1082
|
-
|
|
1101
|
+
const hasPathBoundary = isPathBoundary(
|
|
1102
|
+
remaining,
|
|
1103
|
+
matchIndex,
|
|
1104
|
+
characterBeforeRemaining
|
|
1105
|
+
);
|
|
1106
|
+
if (hasPathBoundary && followingIndex === remaining.length && !final) {
|
|
1107
|
+
return {
|
|
1108
|
+
output: output + remaining.slice(0, matchIndex),
|
|
1109
|
+
pending: remaining.slice(matchIndex)
|
|
1110
|
+
};
|
|
1083
1111
|
}
|
|
1084
|
-
|
|
1112
|
+
const isPath = hasPathBoundary && (followingIndex === remaining.length || remaining[followingIndex] === "/" || isPathTerminator(remaining[followingIndex]));
|
|
1113
|
+
if (!isPath) {
|
|
1114
|
+
output += remaining.slice(0, followingIndex);
|
|
1115
|
+
characterBeforeRemaining = remaining[followingIndex - 1];
|
|
1116
|
+
remaining = remaining.slice(followingIndex);
|
|
1117
|
+
} else if (remaining[followingIndex] === "/") {
|
|
1118
|
+
output += remaining.slice(0, matchIndex);
|
|
1119
|
+
characterBeforeRemaining = remaining[followingIndex];
|
|
1085
1120
|
remaining = remaining.slice(followingIndex + 1);
|
|
1086
1121
|
} else {
|
|
1087
|
-
output += ".";
|
|
1122
|
+
output += remaining.slice(0, matchIndex) + ".";
|
|
1088
1123
|
remaining = remaining.slice(followingIndex);
|
|
1089
1124
|
}
|
|
1090
1125
|
continue;
|
|
1091
1126
|
}
|
|
1092
1127
|
if (final) return { output: output + remaining, pending: "" };
|
|
1093
1128
|
let pendingLength = Math.min(remaining.length, workDir.length - 1);
|
|
1094
|
-
while (pendingLength > 0 && !workDir.startsWith(remaining.slice(-pendingLength))
|
|
1129
|
+
while (pendingLength > 0 && (!workDir.startsWith(remaining.slice(-pendingLength)) || !isPathBoundary(
|
|
1130
|
+
remaining,
|
|
1131
|
+
remaining.length - pendingLength,
|
|
1132
|
+
characterBeforeRemaining
|
|
1133
|
+
))) {
|
|
1095
1134
|
pendingLength -= 1;
|
|
1096
1135
|
}
|
|
1097
1136
|
const outputLength = remaining.length - pendingLength;
|
|
@@ -1102,6 +1141,13 @@ function stripStreamingString({
|
|
|
1102
1141
|
}
|
|
1103
1142
|
return { output, pending: "" };
|
|
1104
1143
|
}
|
|
1144
|
+
function isPathBoundary(value, index, precedingCharacter) {
|
|
1145
|
+
const character = index === 0 ? precedingCharacter : value[index - 1];
|
|
1146
|
+
return character === void 0 || /[\s"'`=]/.test(character);
|
|
1147
|
+
}
|
|
1148
|
+
function isPathTerminator(character) {
|
|
1149
|
+
return character === void 0 || /[\s"'`;|&<>()]/.test(character);
|
|
1150
|
+
}
|
|
1105
1151
|
function stripDeep(value, workDir) {
|
|
1106
1152
|
if (typeof value === "string") return stripString(value, workDir);
|
|
1107
1153
|
if (Array.isArray(value)) return value.map((item) => stripDeep(item, workDir));
|