@kenkaiiii/gg-agent 5.34.3 → 5.35.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.js CHANGED
@@ -8,7 +8,9 @@ import {
8
8
  EventStream,
9
9
  GGAIError,
10
10
  isHardBillingMessage,
11
- redactValue
11
+ redactValue,
12
+ sliceHead,
13
+ sliceTail
12
14
  } from "@kenkaiiii/gg-ai";
13
15
 
14
16
  // src/local-backend.ts
@@ -1316,9 +1318,9 @@ function capToolResults(toolResults, maxToolResultChars) {
1316
1318
  const originalChars = toolResult.content.length;
1317
1319
  const headChars = Math.floor(max * 0.7);
1318
1320
  const tailChars = max - headChars;
1319
- const head = toolResult.content.slice(0, headChars);
1320
- const tail = toolResult.content.slice(-tailChars);
1321
- const omitted = originalChars - headChars - tailChars;
1321
+ const head = sliceHead(toolResult.content, headChars);
1322
+ const tail = sliceTail(toolResult.content, tailChars);
1323
+ const omitted = originalChars - head.length - tail.length;
1322
1324
  toolResult.content = head + `
1323
1325
 
1324
1326
  [... ${omitted} characters omitted ...]
@@ -1353,11 +1355,11 @@ function capTurnToolResults(toolResults, maxTurnToolResultChars) {
1353
1355
  const headChars = Math.floor(fairShare * 0.7);
1354
1356
  const tailChars = fairShare - headChars;
1355
1357
  const omitted = originalChars - fairShare;
1356
- toolResult.content = toolResult.content.slice(0, headChars) + `
1358
+ toolResult.content = sliceHead(toolResult.content, headChars) + `
1357
1359
 
1358
1360
  [... ${omitted} characters trimmed: this turn's combined tool results exceeded the per-turn budget. Re-run this call alone with narrower filters or offset/limit if you need the omitted content ...]
1359
1361
 
1360
- ` + (tailChars > 0 ? toolResult.content.slice(-tailChars) : "");
1362
+ ` + sliceTail(toolResult.content, tailChars);
1361
1363
  toolResult.capped = {
1362
1364
  originalChars: toolResult.capped?.originalChars ?? originalChars,
1363
1365
  keptChars: toolResult.content.length,
@@ -1376,12 +1378,14 @@ function truncateToolResultText(text, maxChars) {
1376
1378
  if (text.length <= maxChars) return text;
1377
1379
  const tailChars = Math.min(Math.floor(maxChars * 0.3), 2e4);
1378
1380
  const headChars = Math.max(maxChars - tailChars, 0);
1379
- const omitted = text.length - headChars - tailChars;
1380
- return `${text.slice(0, headChars)}
1381
+ const head = sliceHead(text, headChars);
1382
+ const tail = sliceTail(text, tailChars);
1383
+ const omitted = text.length - head.length - tail.length;
1384
+ return `${head}
1381
1385
 
1382
1386
  [... ${omitted} characters omitted after context overflow ...]
1383
1387
 
1384
- ${text.slice(-tailChars)}`;
1388
+ ${tail}`;
1385
1389
  }
1386
1390
  function truncateOversizedToolResults(messages, maxChars) {
1387
1391
  if (maxChars <= 0) return false;