@dev-anywhere/proxy 0.5.31 → 0.5.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-HRGSR2CX.js → chunk-LGP5L5XQ.js} +23 -1
- package/dist/chunk-LGP5L5XQ.js.map +1 -0
- package/dist/{chunk-H2YPV2AW.js → chunk-UOA6KK75.js} +2 -2
- package/dist/index.js +2 -2
- package/dist/serve.js +334 -4
- package/dist/serve.js.map +1 -1
- package/dist/session-worker.js +1 -1
- package/dist/{terminal-MAN4GKAD.js → terminal-JSGTN5UF.js} +3 -3
- package/dist/terminal-worker.js +2 -2
- package/package.json +3 -3
- package/dist/chunk-HRGSR2CX.js.map +0 -1
- /package/dist/{chunk-H2YPV2AW.js.map → chunk-UOA6KK75.js.map} +0 -0
- /package/dist/{terminal-MAN4GKAD.js.map → terminal-JSGTN5UF.js.map} +0 -0
package/dist/serve.js
CHANGED
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
serializeIpc,
|
|
57
57
|
serializeWorkerMsg,
|
|
58
58
|
summarizeToolActivity
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-LGP5L5XQ.js";
|
|
60
60
|
import {
|
|
61
61
|
buildProviderEnv,
|
|
62
62
|
loadConfig,
|
|
@@ -1156,7 +1156,6 @@ function parseToolInput(value) {
|
|
|
1156
1156
|
}
|
|
1157
1157
|
function normalizeHistoryToolName(name) {
|
|
1158
1158
|
switch (name) {
|
|
1159
|
-
case "exec":
|
|
1160
1159
|
case "exec_command":
|
|
1161
1160
|
case "shell":
|
|
1162
1161
|
case "shell_command":
|
|
@@ -1169,10 +1168,331 @@ function normalizeHistoryToolName(name) {
|
|
|
1169
1168
|
return "Write";
|
|
1170
1169
|
case "search_query":
|
|
1171
1170
|
return "WebSearch";
|
|
1171
|
+
case "view_image":
|
|
1172
|
+
return "ViewImage";
|
|
1173
|
+
case "update_plan":
|
|
1174
|
+
return "TodoWrite";
|
|
1175
|
+
case "web__run":
|
|
1176
|
+
return "Web";
|
|
1172
1177
|
default:
|
|
1173
1178
|
return name;
|
|
1174
1179
|
}
|
|
1175
1180
|
}
|
|
1181
|
+
function decodeJavascriptStringLiteral(source) {
|
|
1182
|
+
const quote = source[0];
|
|
1183
|
+
if (quote !== '"' && quote !== "'" && quote !== "`" || source.at(-1) !== quote) return null;
|
|
1184
|
+
if (quote === "`" && source.includes("${")) return null;
|
|
1185
|
+
let result = "";
|
|
1186
|
+
for (let index = 1; index < source.length - 1; index += 1) {
|
|
1187
|
+
const character = source[index];
|
|
1188
|
+
if (character !== "\\") {
|
|
1189
|
+
result += character;
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
index += 1;
|
|
1193
|
+
if (index >= source.length - 1) return null;
|
|
1194
|
+
const escaped = source[index];
|
|
1195
|
+
switch (escaped) {
|
|
1196
|
+
case "n":
|
|
1197
|
+
result += "\n";
|
|
1198
|
+
break;
|
|
1199
|
+
case "r":
|
|
1200
|
+
result += "\r";
|
|
1201
|
+
break;
|
|
1202
|
+
case "t":
|
|
1203
|
+
result += " ";
|
|
1204
|
+
break;
|
|
1205
|
+
case "b":
|
|
1206
|
+
result += "\b";
|
|
1207
|
+
break;
|
|
1208
|
+
case "f":
|
|
1209
|
+
result += "\f";
|
|
1210
|
+
break;
|
|
1211
|
+
case "v":
|
|
1212
|
+
result += "\v";
|
|
1213
|
+
break;
|
|
1214
|
+
case "0":
|
|
1215
|
+
result += "\0";
|
|
1216
|
+
break;
|
|
1217
|
+
case "\n":
|
|
1218
|
+
break;
|
|
1219
|
+
case "\r":
|
|
1220
|
+
if (source[index + 1] === "\n") index += 1;
|
|
1221
|
+
break;
|
|
1222
|
+
default:
|
|
1223
|
+
result += escaped;
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return result;
|
|
1228
|
+
}
|
|
1229
|
+
function findJavascriptStringLiteralEnd(source, start) {
|
|
1230
|
+
const quote = source[start];
|
|
1231
|
+
if (quote !== '"' && quote !== "'" && quote !== "`") return null;
|
|
1232
|
+
let escaped = false;
|
|
1233
|
+
for (let index = start + 1; index < source.length; index += 1) {
|
|
1234
|
+
const character = source[index];
|
|
1235
|
+
if (escaped) {
|
|
1236
|
+
escaped = false;
|
|
1237
|
+
} else if (character === "\\") {
|
|
1238
|
+
escaped = true;
|
|
1239
|
+
} else if (character === quote) {
|
|
1240
|
+
return index + 1;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
function findJavascriptValueEnd(source, start) {
|
|
1246
|
+
const stack = [];
|
|
1247
|
+
let quote = "";
|
|
1248
|
+
let escaped = false;
|
|
1249
|
+
for (let index = start; index < source.length; index += 1) {
|
|
1250
|
+
const character = source[index];
|
|
1251
|
+
if (quote) {
|
|
1252
|
+
if (escaped) {
|
|
1253
|
+
escaped = false;
|
|
1254
|
+
} else if (character === "\\") {
|
|
1255
|
+
escaped = true;
|
|
1256
|
+
} else if (character === quote) {
|
|
1257
|
+
quote = "";
|
|
1258
|
+
}
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
if (character === '"' || character === "'" || character === "`") {
|
|
1262
|
+
quote = character;
|
|
1263
|
+
continue;
|
|
1264
|
+
}
|
|
1265
|
+
if (character === "{" || character === "[" || character === "(") {
|
|
1266
|
+
stack.push(character);
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
if (character === "}" || character === "]" || character === ")") {
|
|
1270
|
+
if (stack.length === 0) return index;
|
|
1271
|
+
stack.pop();
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
if ((character === "," || character === ";") && stack.length === 0) return index;
|
|
1275
|
+
}
|
|
1276
|
+
return source.length;
|
|
1277
|
+
}
|
|
1278
|
+
function parseJavascriptPrimitive(source) {
|
|
1279
|
+
const value = source.trim();
|
|
1280
|
+
const stringValue = decodeJavascriptStringLiteral(value);
|
|
1281
|
+
if (stringValue !== null) return stringValue;
|
|
1282
|
+
if (value.startsWith("[")) {
|
|
1283
|
+
const arrayValue = parseJavascriptArrayLiteral(value, 0);
|
|
1284
|
+
if (arrayValue) return arrayValue;
|
|
1285
|
+
}
|
|
1286
|
+
if (value.startsWith("{")) {
|
|
1287
|
+
const objectValue = parseJavascriptObjectLiteral(value, 0);
|
|
1288
|
+
if (objectValue) return objectValue;
|
|
1289
|
+
}
|
|
1290
|
+
if (value === "true") return true;
|
|
1291
|
+
if (value === "false") return false;
|
|
1292
|
+
if (value === "null") return null;
|
|
1293
|
+
if (/^-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/iu.test(value)) return Number(value);
|
|
1294
|
+
try {
|
|
1295
|
+
return JSON.parse(value);
|
|
1296
|
+
} catch {
|
|
1297
|
+
return value;
|
|
1298
|
+
}
|
|
1299
|
+
}
|
|
1300
|
+
function parseJavascriptArrayLiteral(source, start) {
|
|
1301
|
+
let index = start;
|
|
1302
|
+
while (/\s/u.test(source[index] ?? "")) index += 1;
|
|
1303
|
+
if (source[index] !== "[") return null;
|
|
1304
|
+
index += 1;
|
|
1305
|
+
const result = [];
|
|
1306
|
+
while (index < source.length) {
|
|
1307
|
+
while (/[\s,]/u.test(source[index] ?? "")) index += 1;
|
|
1308
|
+
if (source[index] === "]") return result;
|
|
1309
|
+
const valueEnd = findJavascriptValueEnd(source, index);
|
|
1310
|
+
result.push(parseJavascriptPrimitive(source.slice(index, valueEnd)));
|
|
1311
|
+
index = valueEnd;
|
|
1312
|
+
if (source[index] === "]") return result;
|
|
1313
|
+
if (source[index] !== ",") return null;
|
|
1314
|
+
index += 1;
|
|
1315
|
+
}
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
function parseJavascriptObjectLiteral(source, start) {
|
|
1319
|
+
let index = start;
|
|
1320
|
+
while (/\s/u.test(source[index] ?? "")) index += 1;
|
|
1321
|
+
if (source[index] !== "{") return null;
|
|
1322
|
+
index += 1;
|
|
1323
|
+
const result = {};
|
|
1324
|
+
while (index < source.length) {
|
|
1325
|
+
while (/[\s,]/u.test(source[index] ?? "")) index += 1;
|
|
1326
|
+
if (source[index] === "}") return result;
|
|
1327
|
+
let key = "";
|
|
1328
|
+
if (source[index] === '"' || source[index] === "'") {
|
|
1329
|
+
const keyEnd = findJavascriptStringLiteralEnd(source, index);
|
|
1330
|
+
if (keyEnd === null) return null;
|
|
1331
|
+
const decodedKey = decodeJavascriptStringLiteral(source.slice(index, keyEnd));
|
|
1332
|
+
if (decodedKey === null) return null;
|
|
1333
|
+
key = decodedKey;
|
|
1334
|
+
index = keyEnd;
|
|
1335
|
+
} else {
|
|
1336
|
+
const keyMatch = source.slice(index).match(/^[$A-Z_a-z][$\w]*/u);
|
|
1337
|
+
if (!keyMatch) return null;
|
|
1338
|
+
key = keyMatch[0];
|
|
1339
|
+
index += key.length;
|
|
1340
|
+
}
|
|
1341
|
+
while (/\s/u.test(source[index] ?? "")) index += 1;
|
|
1342
|
+
if (source[index] === "," || source[index] === "}") {
|
|
1343
|
+
result[key] = void 0;
|
|
1344
|
+
if (source[index] === "}") return result;
|
|
1345
|
+
index += 1;
|
|
1346
|
+
continue;
|
|
1347
|
+
}
|
|
1348
|
+
if (source[index] !== ":") return null;
|
|
1349
|
+
index += 1;
|
|
1350
|
+
while (/\s/u.test(source[index] ?? "")) index += 1;
|
|
1351
|
+
const valueEnd = findJavascriptValueEnd(source, index);
|
|
1352
|
+
result[key] = parseJavascriptPrimitive(source.slice(index, valueEnd));
|
|
1353
|
+
index = valueEnd;
|
|
1354
|
+
if (source[index] === "}") return result;
|
|
1355
|
+
if (source[index] !== ",") return null;
|
|
1356
|
+
index += 1;
|
|
1357
|
+
}
|
|
1358
|
+
return null;
|
|
1359
|
+
}
|
|
1360
|
+
function resolveJavascriptVariable(input, variableName) {
|
|
1361
|
+
if (!/^[$A-Z_a-z][$\w]*$/u.test(variableName)) return void 0;
|
|
1362
|
+
const assignment = new RegExp(`\\b(?:const|let|var)\\s+${variableName}\\s*=\\s*`, "u").exec(
|
|
1363
|
+
input
|
|
1364
|
+
);
|
|
1365
|
+
if (assignment?.index === void 0) return void 0;
|
|
1366
|
+
const valueStart = assignment.index + assignment[0].length;
|
|
1367
|
+
const valueEnd = findJavascriptStringLiteralEnd(input, valueStart) ?? findJavascriptValueEnd(input, valueStart);
|
|
1368
|
+
return parseJavascriptPrimitive(input.slice(valueStart, valueEnd));
|
|
1369
|
+
}
|
|
1370
|
+
function stringArray(value) {
|
|
1371
|
+
return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
|
|
1372
|
+
}
|
|
1373
|
+
function batchCommands(value) {
|
|
1374
|
+
if (!Array.isArray(value)) return [];
|
|
1375
|
+
return value.flatMap((item) => {
|
|
1376
|
+
if (Array.isArray(item)) {
|
|
1377
|
+
const command2 = item.find((entry, index) => index > 0 && typeof entry === "string");
|
|
1378
|
+
return typeof command2 === "string" ? [command2] : [];
|
|
1379
|
+
}
|
|
1380
|
+
const record = asRecord(item);
|
|
1381
|
+
const command = record && (record.command ?? record.cmd);
|
|
1382
|
+
return typeof command === "string" ? [command] : [];
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1385
|
+
function findJavascriptToolCall(source) {
|
|
1386
|
+
let quote = "";
|
|
1387
|
+
let escaped = false;
|
|
1388
|
+
for (let index = 0; index < source.length; index += 1) {
|
|
1389
|
+
const character = source[index];
|
|
1390
|
+
if (quote) {
|
|
1391
|
+
if (escaped) {
|
|
1392
|
+
escaped = false;
|
|
1393
|
+
} else if (character === "\\") {
|
|
1394
|
+
escaped = true;
|
|
1395
|
+
} else if (character === quote) {
|
|
1396
|
+
quote = "";
|
|
1397
|
+
}
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
if (character === '"' || character === "'" || character === "`") {
|
|
1401
|
+
quote = character;
|
|
1402
|
+
continue;
|
|
1403
|
+
}
|
|
1404
|
+
if (source.startsWith("//", index)) {
|
|
1405
|
+
const newline = source.indexOf("\n", index + 2);
|
|
1406
|
+
if (newline < 0) return null;
|
|
1407
|
+
index = newline;
|
|
1408
|
+
continue;
|
|
1409
|
+
}
|
|
1410
|
+
if (source.startsWith("/*", index)) {
|
|
1411
|
+
const commentEnd = source.indexOf("*/", index + 2);
|
|
1412
|
+
if (commentEnd < 0) return null;
|
|
1413
|
+
index = commentEnd + 1;
|
|
1414
|
+
continue;
|
|
1415
|
+
}
|
|
1416
|
+
if (!source.startsWith("tools.", index)) continue;
|
|
1417
|
+
const nameStart = index + "tools.".length;
|
|
1418
|
+
const nameMatch = source.slice(nameStart).match(/^[$A-Z_a-z][$\w]*/u);
|
|
1419
|
+
if (!nameMatch) continue;
|
|
1420
|
+
let argumentsStart = nameStart + nameMatch[0].length;
|
|
1421
|
+
while (/\s/u.test(source[argumentsStart] ?? "")) argumentsStart += 1;
|
|
1422
|
+
if (source[argumentsStart] !== "(") continue;
|
|
1423
|
+
return { toolName: nameMatch[0], argumentsStart: argumentsStart + 1 };
|
|
1424
|
+
}
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
function decodeCodexExecInput(input) {
|
|
1428
|
+
const call = findJavascriptToolCall(input);
|
|
1429
|
+
if (!call) return null;
|
|
1430
|
+
const { argumentsStart, toolName: nestedToolName } = call;
|
|
1431
|
+
const argumentEnd = findJavascriptValueEnd(input, argumentsStart);
|
|
1432
|
+
const argument = input.slice(argumentsStart, argumentEnd).trim();
|
|
1433
|
+
let parameters = parseJavascriptObjectLiteral(input, argumentsStart);
|
|
1434
|
+
if (!parameters && /^[$A-Z_a-z][$\w]*$/u.test(argument)) {
|
|
1435
|
+
parameters = asRecord(resolveJavascriptVariable(input, argument));
|
|
1436
|
+
}
|
|
1437
|
+
if (nestedToolName === "apply_patch") {
|
|
1438
|
+
let content = typeof parameters?.content === "string" ? parameters.content : "";
|
|
1439
|
+
if (!content && /^[$A-Z_a-z][$\w]*$/u.test(argument)) {
|
|
1440
|
+
const assignment = new RegExp(`\\b(?:const|let|var)\\s+${argument}\\s*=\\s*`, "u").exec(
|
|
1441
|
+
input
|
|
1442
|
+
);
|
|
1443
|
+
if (assignment?.index !== void 0) {
|
|
1444
|
+
const valueStart = assignment.index + assignment[0].length;
|
|
1445
|
+
const valueEnd = findJavascriptStringLiteralEnd(input, valueStart) ?? findJavascriptValueEnd(input, valueStart);
|
|
1446
|
+
const value = parseJavascriptPrimitive(input.slice(valueStart, valueEnd));
|
|
1447
|
+
if (typeof value === "string") content = value;
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
if (!content) return { toolName: "Patch", parameters: {} };
|
|
1451
|
+
const paths = Array.from(
|
|
1452
|
+
content.matchAll(/^\*\*\* (?:Add|Delete|Update) File: (.+)$/gmu),
|
|
1453
|
+
(match) => match[1]
|
|
1454
|
+
);
|
|
1455
|
+
return { toolName: "Patch", parameters: { content, ...paths.length ? { paths } : {} } };
|
|
1456
|
+
}
|
|
1457
|
+
if (nestedToolName === "exec_command" && !parameters) {
|
|
1458
|
+
const commands = batchCommands(resolveJavascriptVariable(input, "cmds"));
|
|
1459
|
+
if (commands.length > 0) return { toolName: "BashBatch", parameters: { commands } };
|
|
1460
|
+
return { toolName: "Bash", parameters: {} };
|
|
1461
|
+
}
|
|
1462
|
+
if (!parameters) {
|
|
1463
|
+
return { toolName: normalizeHistoryToolName(nestedToolName), parameters: {} };
|
|
1464
|
+
}
|
|
1465
|
+
if (nestedToolName === "exec_command") {
|
|
1466
|
+
const command = typeof parameters.cmd === "string" ? parameters.cmd : "";
|
|
1467
|
+
if (!command) {
|
|
1468
|
+
const commands = batchCommands(resolveJavascriptVariable(input, "cmds"));
|
|
1469
|
+
if (commands.length > 0) return { toolName: "BashBatch", parameters: { commands } };
|
|
1470
|
+
return { toolName: "Bash", parameters: {} };
|
|
1471
|
+
}
|
|
1472
|
+
const normalized = { ...parameters, command };
|
|
1473
|
+
delete normalized.cmd;
|
|
1474
|
+
return { toolName: "Bash", parameters: normalized };
|
|
1475
|
+
}
|
|
1476
|
+
if (nestedToolName === "write_stdin") {
|
|
1477
|
+
const chars = typeof parameters.chars === "string" ? parameters.chars : "";
|
|
1478
|
+
return {
|
|
1479
|
+
toolName: chars ? "ProcessInput" : "ProcessWait",
|
|
1480
|
+
parameters: chars ? { ...parameters, input: chars } : parameters
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
if (nestedToolName === "view_image" && typeof parameters.path !== "string") {
|
|
1484
|
+
const paths = stringArray(resolveJavascriptVariable(input, "paths"));
|
|
1485
|
+
if (paths.length > 0) return { toolName: "ViewImageBatch", parameters: { paths } };
|
|
1486
|
+
}
|
|
1487
|
+
if (nestedToolName === "update_plan" && parameters.plan === void 0) {
|
|
1488
|
+
const plan = resolveJavascriptVariable(input, "plan");
|
|
1489
|
+
return {
|
|
1490
|
+
toolName: "TodoWrite",
|
|
1491
|
+
parameters: plan === void 0 ? {} : { plan }
|
|
1492
|
+
};
|
|
1493
|
+
}
|
|
1494
|
+
return { toolName: normalizeHistoryToolName(nestedToolName), parameters };
|
|
1495
|
+
}
|
|
1176
1496
|
function normalizeHistoryToolParameters(rawToolName, input) {
|
|
1177
1497
|
const parameters = parseToolInput(input);
|
|
1178
1498
|
const toolName = normalizeHistoryToolName(rawToolName);
|
|
@@ -1196,10 +1516,20 @@ function normalizeHistoryToolParameters(rawToolName, input) {
|
|
|
1196
1516
|
}
|
|
1197
1517
|
return parameters;
|
|
1198
1518
|
}
|
|
1519
|
+
function normalizeHistoryToolCall(rawToolName, input) {
|
|
1520
|
+
if (rawToolName === "exec" && typeof input === "string") {
|
|
1521
|
+
const decoded = decodeCodexExecInput(input);
|
|
1522
|
+
if (decoded) return decoded;
|
|
1523
|
+
if (/\btools\./u.test(input)) {
|
|
1524
|
+
return { toolName: "ToolScript", parameters: {} };
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
const toolName = normalizeHistoryToolName(rawToolName);
|
|
1528
|
+
return { toolName, parameters: normalizeHistoryToolParameters(rawToolName, input) };
|
|
1529
|
+
}
|
|
1199
1530
|
function toolUseHistoryItem(toolId, rawToolName, input, timestamp) {
|
|
1200
1531
|
if (!toolId || !rawToolName) return null;
|
|
1201
|
-
const toolName =
|
|
1202
|
-
const parameters = normalizeHistoryToolParameters(rawToolName, input);
|
|
1532
|
+
const { toolName, parameters } = normalizeHistoryToolCall(rawToolName, input);
|
|
1203
1533
|
return {
|
|
1204
1534
|
kind: "message",
|
|
1205
1535
|
message: {
|