@kenkaiiii/gg-agent 5.49.9 → 5.49.11
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 +32 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +30 -25
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -401,6 +401,20 @@ declare function isBillingError(err: unknown): boolean;
|
|
|
401
401
|
*/
|
|
402
402
|
declare function isUsageLimitError(err: unknown): boolean;
|
|
403
403
|
declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGenerator<AgentEvent, AgentResult>;
|
|
404
|
+
/**
|
|
405
|
+
* A tool call that never reached its tool. Nothing ran, so nothing changed.
|
|
406
|
+
*/
|
|
407
|
+
declare function cancelledBeforeStartText(name: string): string;
|
|
408
|
+
/**
|
|
409
|
+
* A tool call that started running and was cut off before reporting back.
|
|
410
|
+
*
|
|
411
|
+
* The distinction from {@link cancelledBeforeStartText} is the whole point: a
|
|
412
|
+
* dispatched `git push`, deploy or MCP call may well have COMPLETED before the
|
|
413
|
+
* abort landed. Telling the model it was "interrupted" reads as "it did not
|
|
414
|
+
* happen", so the model repeats the side effect — or reports to the user that
|
|
415
|
+
* something never ran when it did.
|
|
416
|
+
*/
|
|
417
|
+
declare function indeterminateOutcomeText(name: string): string;
|
|
404
418
|
|
|
405
419
|
/**
|
|
406
420
|
* A local inference server (llama.cpp, vLLM, Ollama, LM Studio) can spend
|
|
@@ -411,4 +425,4 @@ declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGen
|
|
|
411
425
|
*/
|
|
412
426
|
declare function isLocalBackendUrl(baseUrl?: string): boolean;
|
|
413
427
|
|
|
414
|
-
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
|
428
|
+
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, cancelledBeforeStartText, indeterminateOutcomeText, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
package/dist/index.d.ts
CHANGED
|
@@ -401,6 +401,20 @@ declare function isBillingError(err: unknown): boolean;
|
|
|
401
401
|
*/
|
|
402
402
|
declare function isUsageLimitError(err: unknown): boolean;
|
|
403
403
|
declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGenerator<AgentEvent, AgentResult>;
|
|
404
|
+
/**
|
|
405
|
+
* A tool call that never reached its tool. Nothing ran, so nothing changed.
|
|
406
|
+
*/
|
|
407
|
+
declare function cancelledBeforeStartText(name: string): string;
|
|
408
|
+
/**
|
|
409
|
+
* A tool call that started running and was cut off before reporting back.
|
|
410
|
+
*
|
|
411
|
+
* The distinction from {@link cancelledBeforeStartText} is the whole point: a
|
|
412
|
+
* dispatched `git push`, deploy or MCP call may well have COMPLETED before the
|
|
413
|
+
* abort landed. Telling the model it was "interrupted" reads as "it did not
|
|
414
|
+
* happen", so the model repeats the side effect — or reports to the user that
|
|
415
|
+
* something never ran when it did.
|
|
416
|
+
*/
|
|
417
|
+
declare function indeterminateOutcomeText(name: string): string;
|
|
404
418
|
|
|
405
419
|
/**
|
|
406
420
|
* A local inference server (llama.cpp, vLLM, Ollama, LM Studio) can spend
|
|
@@ -411,4 +425,4 @@ declare function agentLoop(messages: Message[], options: AgentOptions): AsyncGen
|
|
|
411
425
|
*/
|
|
412
426
|
declare function isLocalBackendUrl(baseUrl?: string): boolean;
|
|
413
427
|
|
|
414
|
-
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
|
428
|
+
export { Agent, type AgentDoneEvent, type AgentErrorEvent, type AgentEvent, type AgentFollowUpMessageEvent, type AgentOptions, type AgentResult, type AgentRetryEvent, type AgentServerToolCallEvent, type AgentServerToolResultEvent, type AgentSteeringMessageEvent, AgentStream, type AgentTextDeltaEvent, type AgentThinkingDeltaEvent, type AgentTool, type AgentToolCallDeltaEvent, type AgentToolCallEndEvent, type AgentToolCallStartEvent, type AgentToolCallUpdateEvent, type AgentTurnEndEvent, type AgentTurnTiming, type StreamDiagnosticFn, type StructuredToolResult, type ToolContext, type ToolExecuteResult, type ToolExecutionMode, type TransformContextOptions, agentLoop, cancelledBeforeStartText, indeterminateOutcomeText, isAbortError, isBillingError, isContextOverflow, isLocalBackendUrl, isUsageLimitError, setStreamDiagnostic };
|
package/dist/index.js
CHANGED
|
@@ -1320,6 +1320,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1320
1320
|
const eventStream = new EventStream();
|
|
1321
1321
|
const state = { finalized: false };
|
|
1322
1322
|
const resultsById = /* @__PURE__ */ new Map();
|
|
1323
|
+
const dispatchedIds = /* @__PURE__ */ new Set();
|
|
1323
1324
|
const abortHandler = () => eventStream.abort(new Error("aborted"));
|
|
1324
1325
|
options.signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1325
1326
|
const phases = [];
|
|
@@ -1344,6 +1345,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1344
1345
|
for (const phase of phases) {
|
|
1345
1346
|
if (options.signal?.aborted) break;
|
|
1346
1347
|
if (phase.sequential) {
|
|
1348
|
+
dispatchedIds.add(phase.sequential.id);
|
|
1347
1349
|
const record = await executeSingleToolCall(
|
|
1348
1350
|
phase.sequential,
|
|
1349
1351
|
options,
|
|
@@ -1351,6 +1353,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1351
1353
|
);
|
|
1352
1354
|
resultsById.set(record.toolCallId, record);
|
|
1353
1355
|
} else if (phase.parallel.length === 1) {
|
|
1356
|
+
dispatchedIds.add(phase.parallel[0].id);
|
|
1354
1357
|
const record = await executeSingleToolCall(
|
|
1355
1358
|
phase.parallel[0],
|
|
1356
1359
|
options,
|
|
@@ -1360,6 +1363,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1360
1363
|
} else {
|
|
1361
1364
|
await Promise.all(
|
|
1362
1365
|
phase.parallel.map(async (toolCall) => {
|
|
1366
|
+
dispatchedIds.add(toolCall.id);
|
|
1363
1367
|
const record = await executeSingleToolCall(
|
|
1364
1368
|
toolCall,
|
|
1365
1369
|
options,
|
|
@@ -1390,7 +1394,7 @@ async function* executeToolCallsMixed(toolCalls, initialToolResults, options) {
|
|
|
1390
1394
|
options.signal?.removeEventListener("abort", abortHandler);
|
|
1391
1395
|
state.finalized = true;
|
|
1392
1396
|
}
|
|
1393
|
-
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById);
|
|
1397
|
+
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1394
1398
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1395
1399
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1396
1400
|
return { toolResults, aborted };
|
|
@@ -1399,10 +1403,12 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
1399
1403
|
const eventStream = new EventStream();
|
|
1400
1404
|
const state = { finalized: false };
|
|
1401
1405
|
const resultsById = /* @__PURE__ */ new Map();
|
|
1406
|
+
const dispatchedIds = /* @__PURE__ */ new Set();
|
|
1402
1407
|
const abortHandler = () => eventStream.abort(new Error("aborted"));
|
|
1403
1408
|
options.signal?.addEventListener("abort", abortHandler, { once: true });
|
|
1404
1409
|
Promise.all(
|
|
1405
1410
|
toolCalls.map(async (toolCall) => {
|
|
1411
|
+
dispatchedIds.add(toolCall.id);
|
|
1406
1412
|
const record = await executeSingleToolCall(
|
|
1407
1413
|
toolCall,
|
|
1408
1414
|
options,
|
|
@@ -1430,12 +1436,18 @@ async function* executeToolCallsParallel(toolCalls, initialToolResults, options)
|
|
|
1430
1436
|
options.signal?.removeEventListener("abort", abortHandler);
|
|
1431
1437
|
state.finalized = true;
|
|
1432
1438
|
}
|
|
1433
|
-
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById);
|
|
1439
|
+
const toolResults = buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds);
|
|
1434
1440
|
capToolResults(toolResults, options.maxToolResultChars);
|
|
1435
1441
|
capTurnToolResults(toolResults, options.maxTurnToolResultChars);
|
|
1436
1442
|
return { toolResults, aborted };
|
|
1437
1443
|
}
|
|
1438
|
-
function
|
|
1444
|
+
function cancelledBeforeStartText(name) {
|
|
1445
|
+
return `\`${name}\` was cancelled before it started, so it had no effect. Safe to retry.`;
|
|
1446
|
+
}
|
|
1447
|
+
function indeterminateOutcomeText(name) {
|
|
1448
|
+
return `\`${name}\` started running and was cut off before it reported back, so its outcome is UNKNOWN \u2014 it may have completed. Check the real state (re-read the file, re-run a status command) before retrying it, and do not tell the user it did not happen.`;
|
|
1449
|
+
}
|
|
1450
|
+
function buildToolResults(initialToolResults, toolCalls, resultsById, dispatchedIds) {
|
|
1439
1451
|
const toolResults = [...initialToolResults];
|
|
1440
1452
|
for (const toolCall of toolCalls) {
|
|
1441
1453
|
const result = resultsById.get(toolCall.id);
|
|
@@ -1447,10 +1459,11 @@ function buildToolResults(initialToolResults, toolCalls, resultsById) {
|
|
|
1447
1459
|
isError: result.isError || void 0
|
|
1448
1460
|
});
|
|
1449
1461
|
} else {
|
|
1462
|
+
const dispatched = dispatchedIds?.has(toolCall.id) ?? true;
|
|
1450
1463
|
toolResults.push({
|
|
1451
1464
|
type: "tool_result",
|
|
1452
1465
|
toolCallId: toolCall.id,
|
|
1453
|
-
content:
|
|
1466
|
+
content: dispatched ? indeterminateOutcomeText(toolCall.name) : cancelledBeforeStartText(toolCall.name),
|
|
1454
1467
|
isError: true
|
|
1455
1468
|
});
|
|
1456
1469
|
}
|
|
@@ -1598,32 +1611,22 @@ function repairToolPairingAdjacent(messages) {
|
|
|
1598
1611
|
const msg = messages[i];
|
|
1599
1612
|
if (msg.role !== "assistant") continue;
|
|
1600
1613
|
if (typeof msg.content === "string" || !Array.isArray(msg.content)) continue;
|
|
1601
|
-
const
|
|
1602
|
-
if (
|
|
1614
|
+
const orphanCalls = msg.content.filter((p) => p.type === "tool_call").map((p) => p);
|
|
1615
|
+
if (orphanCalls.length === 0) continue;
|
|
1616
|
+
const repaired = (call) => ({
|
|
1617
|
+
type: "tool_result",
|
|
1618
|
+
toolCallId: call.id,
|
|
1619
|
+
content: indeterminateOutcomeText(call.name),
|
|
1620
|
+
isError: true
|
|
1621
|
+
});
|
|
1603
1622
|
const next = messages[i + 1];
|
|
1604
1623
|
if (next?.role === "tool" && Array.isArray(next.content)) {
|
|
1605
1624
|
const existingIds = new Set(next.content.map((r) => r.toolCallId));
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
for (const id of missing) {
|
|
1609
|
-
next.content.push({
|
|
1610
|
-
type: "tool_result",
|
|
1611
|
-
toolCallId: id,
|
|
1612
|
-
content: "Tool execution was interrupted.",
|
|
1613
|
-
isError: true
|
|
1614
|
-
});
|
|
1615
|
-
}
|
|
1625
|
+
for (const call of orphanCalls) {
|
|
1626
|
+
if (!existingIds.has(call.id)) next.content.push(repaired(call));
|
|
1616
1627
|
}
|
|
1617
1628
|
} else {
|
|
1618
|
-
messages.splice(i + 1, 0, {
|
|
1619
|
-
role: "tool",
|
|
1620
|
-
content: toolCallIds.map((id) => ({
|
|
1621
|
-
type: "tool_result",
|
|
1622
|
-
toolCallId: id,
|
|
1623
|
-
content: "Tool execution was interrupted.",
|
|
1624
|
-
isError: true
|
|
1625
|
-
}))
|
|
1626
|
-
});
|
|
1629
|
+
messages.splice(i + 1, 0, { role: "tool", content: orphanCalls.map(repaired) });
|
|
1627
1630
|
}
|
|
1628
1631
|
}
|
|
1629
1632
|
const toolCallIdSet = /* @__PURE__ */ new Set();
|
|
@@ -1782,6 +1785,8 @@ export {
|
|
|
1782
1785
|
Agent,
|
|
1783
1786
|
AgentStream,
|
|
1784
1787
|
agentLoop,
|
|
1788
|
+
cancelledBeforeStartText,
|
|
1789
|
+
indeterminateOutcomeText,
|
|
1785
1790
|
isAbortError,
|
|
1786
1791
|
isBillingError,
|
|
1787
1792
|
isContextOverflow,
|