@kenkaiiii/gg-agent 5.63.0 → 5.64.1
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/index.cjs +44 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
stream,
|
|
8
8
|
EventStream,
|
|
9
9
|
GGAIError,
|
|
10
|
+
environmentSecrets,
|
|
10
11
|
isHardBillingMessage,
|
|
11
12
|
redactValue,
|
|
12
13
|
sliceHead,
|
|
@@ -92,6 +93,11 @@ function clampOutputTokens(key, requested) {
|
|
|
92
93
|
// src/agent-loop.ts
|
|
93
94
|
var DEFAULT_MAX_TURNS = 300;
|
|
94
95
|
var DEFAULT_TOOL_TIMEOUT_MS = 3e5;
|
|
96
|
+
var _toolRedaction;
|
|
97
|
+
function toolRedactionOptions() {
|
|
98
|
+
_toolRedaction ??= { secrets: environmentSecrets(process.env) };
|
|
99
|
+
return _toolRedaction;
|
|
100
|
+
}
|
|
95
101
|
var _diagFn = null;
|
|
96
102
|
function setStreamDiagnostic(fn) {
|
|
97
103
|
_diagFn = fn;
|
|
@@ -1182,7 +1188,8 @@ async function* agentLoop(messages, options) {
|
|
|
1182
1188
|
maxTurnToolResultChars: options.maxTurnToolResultChars,
|
|
1183
1189
|
toolMap,
|
|
1184
1190
|
invalidToolArgumentCounts,
|
|
1185
|
-
markFatalToolArgumentError
|
|
1191
|
+
markFatalToolArgumentError,
|
|
1192
|
+
seenToolCalls: /* @__PURE__ */ new Set()
|
|
1186
1193
|
};
|
|
1187
1194
|
const hasSequentialToolCall = toolCalls.some(
|
|
1188
1195
|
(toolCall) => toolMap.get(toolCall.name)?.executionMode === "sequential"
|
|
@@ -1303,6 +1310,15 @@ async function* agentLoop(messages, options) {
|
|
|
1303
1310
|
totalUsage: { ...totalUsage }
|
|
1304
1311
|
};
|
|
1305
1312
|
}
|
|
1313
|
+
function canonicalToolArgs(value) {
|
|
1314
|
+
if (Array.isArray(value)) return value.map(canonicalToolArgs);
|
|
1315
|
+
if (value !== null && typeof value === "object") {
|
|
1316
|
+
return Object.fromEntries(
|
|
1317
|
+
Object.entries(value).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => [k, canonicalToolArgs(v)])
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
return value;
|
|
1321
|
+
}
|
|
1306
1322
|
function pushToolEvent(eventStream, state, event) {
|
|
1307
1323
|
if (!state.finalized) eventStream.push(event);
|
|
1308
1324
|
}
|
|
@@ -1319,6 +1335,21 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1319
1335
|
let isError = false;
|
|
1320
1336
|
let invalidArgAttempt;
|
|
1321
1337
|
const tool = options.toolMap.get(toolCall.name);
|
|
1338
|
+
if (tool) {
|
|
1339
|
+
const signature = JSON.stringify([toolCall.name, canonicalToolArgs(toolCall.args)]);
|
|
1340
|
+
if (options.seenToolCalls.has(signature)) {
|
|
1341
|
+
const content = "Tool call cancelled: an identical call already appeared in this response; this call was not executed.";
|
|
1342
|
+
pushEvent({
|
|
1343
|
+
type: "tool_call_end",
|
|
1344
|
+
toolCallId: toolCall.id,
|
|
1345
|
+
result: content,
|
|
1346
|
+
isError: true,
|
|
1347
|
+
durationMs: Date.now() - startTime
|
|
1348
|
+
});
|
|
1349
|
+
return { toolCallId: toolCall.id, content, isError: true };
|
|
1350
|
+
}
|
|
1351
|
+
options.seenToolCalls.add(signature);
|
|
1352
|
+
}
|
|
1322
1353
|
if (!tool) {
|
|
1323
1354
|
resultContent = `Unknown tool: ${toolCall.name}`;
|
|
1324
1355
|
isError = true;
|
|
@@ -1350,8 +1381,8 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1350
1381
|
};
|
|
1351
1382
|
const raw = await tool.execute(parsed, ctx);
|
|
1352
1383
|
const normalized = normalizeToolResult(raw);
|
|
1353
|
-
resultContent = redactValue(normalized.content);
|
|
1354
|
-
details = redactValue(normalized.details);
|
|
1384
|
+
resultContent = redactValue(normalized.content, toolRedactionOptions());
|
|
1385
|
+
details = redactValue(normalized.details, toolRedactionOptions());
|
|
1355
1386
|
for (const key of options.invalidToolArgumentCounts.keys()) {
|
|
1356
1387
|
if (key.startsWith(`${toolCall.name}:`)) options.invalidToolArgumentCounts.delete(key);
|
|
1357
1388
|
}
|
|
@@ -1380,12 +1411,15 @@ async function executeSingleToolCall(toolCall, options, pushEvent) {
|
|
|
1380
1411
|
);
|
|
1381
1412
|
}
|
|
1382
1413
|
} else {
|
|
1383
|
-
resultContent = redactValue(
|
|
1414
|
+
resultContent = redactValue(
|
|
1415
|
+
err instanceof Error ? err.message : String(err),
|
|
1416
|
+
toolRedactionOptions()
|
|
1417
|
+
);
|
|
1384
1418
|
}
|
|
1385
1419
|
}
|
|
1386
1420
|
}
|
|
1387
|
-
resultContent = redactValue(resultContent);
|
|
1388
|
-
details = redactValue(details);
|
|
1421
|
+
resultContent = redactValue(resultContent, toolRedactionOptions());
|
|
1422
|
+
details = redactValue(details, toolRedactionOptions());
|
|
1389
1423
|
const durationMs = Date.now() - startTime;
|
|
1390
1424
|
pushEvent({
|
|
1391
1425
|
type: "tool_call_end",
|
|
@@ -1427,6 +1461,11 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1427
1461
|
for (const phase of phases) {
|
|
1428
1462
|
if (options.signal?.aborted) break;
|
|
1429
1463
|
if (phase.sequential) {
|
|
1464
|
+
const signature = JSON.stringify([
|
|
1465
|
+
phase.sequential.name,
|
|
1466
|
+
canonicalToolArgs(phase.sequential.args)
|
|
1467
|
+
]);
|
|
1468
|
+
if (!options.seenToolCalls.has(signature)) options.seenToolCalls.clear();
|
|
1430
1469
|
dispatchedIds.add(phase.sequential.id);
|
|
1431
1470
|
const record = await executeSingleToolCall(
|
|
1432
1471
|
phase.sequential,
|