@cognipeer/agent-sdk 0.22.0 → 0.22.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 CHANGED
@@ -1288,7 +1288,7 @@ function cacheWriteTokensOf(raw) {
1288
1288
  init_content();
1289
1289
 
1290
1290
  // src/version.ts
1291
- var SDK_VERSION = "0.22.0";
1291
+ var SDK_VERSION = "0.22.1";
1292
1292
 
1293
1293
  // src/utils/otlp/content.ts
1294
1294
  init_content();
@@ -9463,6 +9463,24 @@ function extractToolItems(output) {
9463
9463
  });
9464
9464
  }
9465
9465
 
9466
+ // src/utils/syntheticMessages.ts
9467
+ function isSyntheticSummaryMessage(message) {
9468
+ if (!message) return false;
9469
+ if (message.role === "tool" && message.name === "summarize_context") {
9470
+ return true;
9471
+ }
9472
+ if (message.role === "assistant" && Array.isArray(message.tool_calls)) {
9473
+ return message.tool_calls.some((toolCall) => {
9474
+ const toolName = toolCall?.function?.name || toolCall?.name;
9475
+ return toolName === "summarize_context";
9476
+ });
9477
+ }
9478
+ return false;
9479
+ }
9480
+ function isCompactedToolContent(content) {
9481
+ return typeof content === "string" && (content === "SUMMARIZED" || content.startsWith("SUMMARIZED_TOOL_RESPONSE") || content.startsWith("ARCHIVED_TOOL_RESPONSE") || content.startsWith("STRUCTURED_TOOL_RESPONSE") || content.startsWith("DROPPED_TOOL_RESPONSE"));
9482
+ }
9483
+
9466
9484
  // src/utils/pendingToolCalls.ts
9467
9485
  function selectPendingToolCalls(messages) {
9468
9486
  if (!Array.isArray(messages) || messages.length === 0) return [];
@@ -9483,6 +9501,24 @@ function selectPendingToolCalls(messages) {
9483
9501
  }
9484
9502
  return [];
9485
9503
  }
9504
+ function hasUnresolvedToolCalls(messages) {
9505
+ if (!Array.isArray(messages) || messages.length === 0) return false;
9506
+ const role = messages[messages.length - 1]?.role;
9507
+ if (role !== "assistant" && role !== "tool") return false;
9508
+ return selectPendingToolCalls(messages).length > 0;
9509
+ }
9510
+ function unburyPendingToolCalls(messages) {
9511
+ if (!Array.isArray(messages) || messages.length === 0) return messages;
9512
+ let start = messages.length;
9513
+ while (start > 0 && isSyntheticSummaryMessage(messages[start - 1])) start -= 1;
9514
+ if (start === messages.length || start === 0) return messages;
9515
+ const body = messages.slice(0, start);
9516
+ if (!hasUnresolvedToolCalls(body)) return messages;
9517
+ let owner = body.length - 1;
9518
+ while (owner >= 0 && body[owner]?.role !== "assistant") owner -= 1;
9519
+ if (owner < 0) return messages;
9520
+ return [...body.slice(0, owner), ...messages.slice(start), ...body.slice(owner)];
9521
+ }
9486
9522
 
9487
9523
  // src/nodes/tools.ts
9488
9524
  function resolveNeedsApproval(tool, args) {
@@ -11365,26 +11401,6 @@ function createAskUserQuestionTool(stateRef, config) {
11365
11401
 
11366
11402
  // src/agent.ts
11367
11403
  init_utilTokens();
11368
-
11369
- // src/utils/syntheticMessages.ts
11370
- function isSyntheticSummaryMessage(message) {
11371
- if (!message) return false;
11372
- if (message.role === "tool" && message.name === "summarize_context") {
11373
- return true;
11374
- }
11375
- if (message.role === "assistant" && Array.isArray(message.tool_calls)) {
11376
- return message.tool_calls.some((toolCall) => {
11377
- const toolName = toolCall?.function?.name || toolCall?.name;
11378
- return toolName === "summarize_context";
11379
- });
11380
- }
11381
- return false;
11382
- }
11383
- function isCompactedToolContent(content) {
11384
- return typeof content === "string" && (content === "SUMMARIZED" || content.startsWith("SUMMARIZED_TOOL_RESPONSE") || content.startsWith("ARCHIVED_TOOL_RESPONSE") || content.startsWith("STRUCTURED_TOOL_RESPONSE") || content.startsWith("DROPPED_TOOL_RESPONSE"));
11385
- }
11386
-
11387
- // src/agent.ts
11388
11404
  init_content();
11389
11405
 
11390
11406
  // src/structuredOutput/manager.ts
@@ -16367,6 +16383,14 @@ ${pluginAppend}`;
16367
16383
  }
16368
16384
  async function trySummarize(currentState, currentRawMessages, ref, trigger) {
16369
16385
  if (!summarizer) return { state: currentState, rawMessages: currentRawMessages, compressed: false };
16386
+ if (hasUnresolvedToolCalls(currentRawMessages)) {
16387
+ const ctx2 = {
16388
+ ...currentState.ctx || {},
16389
+ __summarizationExhausted: true,
16390
+ __summarizationExhaustedAtToolCount: (currentState.toolHistory || []).length
16391
+ };
16392
+ return { state: { ...currentState, ctx: ctx2 }, rawMessages: currentRawMessages, compressed: false };
16393
+ }
16370
16394
  const compactHost = currentState.ctx?.__plugins;
16371
16395
  const tokensBefore = countMessagesTokens(currentState.messages || []);
16372
16396
  if (compactHost?.has("preCompact")) {
@@ -16585,10 +16609,11 @@ ${pluginAppend}`;
16585
16609
  subagentBlock = block;
16586
16610
  }
16587
16611
  const disclosureBlock = [skillBlock, subagentBlock].filter(Boolean).join("\n\n") || void 0;
16588
- const alreadyHasSystem = Array.isArray(input.messages) && input.messages[0]?.role === "system";
16589
- const seedMessages = alreadyHasSystem ? [...input.messages || []] : [
16612
+ const inputMessages = unburyPendingToolCalls(input.messages || []);
16613
+ const alreadyHasSystem = inputMessages[0]?.role === "system";
16614
+ const seedMessages = alreadyHasSystem ? [...inputMessages] : [
16590
16615
  systemMessage2(disclosureBlock, input.ctx?.__pluginSystemPromptAppend),
16591
- ...input.messages || []
16616
+ ...inputMessages
16592
16617
  ];
16593
16618
  let seedToolHistory = input.toolHistory;
16594
16619
  if (skillsEnabled && toolSet.skillRegistryRef) {