@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.mjs CHANGED
@@ -1278,7 +1278,7 @@ function cacheWriteTokensOf(raw) {
1278
1278
  init_content();
1279
1279
 
1280
1280
  // src/version.ts
1281
- var SDK_VERSION = "0.22.0";
1281
+ var SDK_VERSION = "0.22.1";
1282
1282
 
1283
1283
  // src/utils/otlp/content.ts
1284
1284
  init_content();
@@ -9453,6 +9453,24 @@ function extractToolItems(output) {
9453
9453
  });
9454
9454
  }
9455
9455
 
9456
+ // src/utils/syntheticMessages.ts
9457
+ function isSyntheticSummaryMessage(message) {
9458
+ if (!message) return false;
9459
+ if (message.role === "tool" && message.name === "summarize_context") {
9460
+ return true;
9461
+ }
9462
+ if (message.role === "assistant" && Array.isArray(message.tool_calls)) {
9463
+ return message.tool_calls.some((toolCall) => {
9464
+ const toolName = toolCall?.function?.name || toolCall?.name;
9465
+ return toolName === "summarize_context";
9466
+ });
9467
+ }
9468
+ return false;
9469
+ }
9470
+ function isCompactedToolContent(content) {
9471
+ 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"));
9472
+ }
9473
+
9456
9474
  // src/utils/pendingToolCalls.ts
9457
9475
  function selectPendingToolCalls(messages) {
9458
9476
  if (!Array.isArray(messages) || messages.length === 0) return [];
@@ -9473,6 +9491,24 @@ function selectPendingToolCalls(messages) {
9473
9491
  }
9474
9492
  return [];
9475
9493
  }
9494
+ function hasUnresolvedToolCalls(messages) {
9495
+ if (!Array.isArray(messages) || messages.length === 0) return false;
9496
+ const role = messages[messages.length - 1]?.role;
9497
+ if (role !== "assistant" && role !== "tool") return false;
9498
+ return selectPendingToolCalls(messages).length > 0;
9499
+ }
9500
+ function unburyPendingToolCalls(messages) {
9501
+ if (!Array.isArray(messages) || messages.length === 0) return messages;
9502
+ let start = messages.length;
9503
+ while (start > 0 && isSyntheticSummaryMessage(messages[start - 1])) start -= 1;
9504
+ if (start === messages.length || start === 0) return messages;
9505
+ const body = messages.slice(0, start);
9506
+ if (!hasUnresolvedToolCalls(body)) return messages;
9507
+ let owner = body.length - 1;
9508
+ while (owner >= 0 && body[owner]?.role !== "assistant") owner -= 1;
9509
+ if (owner < 0) return messages;
9510
+ return [...body.slice(0, owner), ...messages.slice(start), ...body.slice(owner)];
9511
+ }
9476
9512
 
9477
9513
  // src/nodes/tools.ts
9478
9514
  function resolveNeedsApproval(tool, args) {
@@ -11355,26 +11391,6 @@ function createAskUserQuestionTool(stateRef, config) {
11355
11391
 
11356
11392
  // src/agent.ts
11357
11393
  init_utilTokens();
11358
-
11359
- // src/utils/syntheticMessages.ts
11360
- function isSyntheticSummaryMessage(message) {
11361
- if (!message) return false;
11362
- if (message.role === "tool" && message.name === "summarize_context") {
11363
- return true;
11364
- }
11365
- if (message.role === "assistant" && Array.isArray(message.tool_calls)) {
11366
- return message.tool_calls.some((toolCall) => {
11367
- const toolName = toolCall?.function?.name || toolCall?.name;
11368
- return toolName === "summarize_context";
11369
- });
11370
- }
11371
- return false;
11372
- }
11373
- function isCompactedToolContent(content) {
11374
- 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"));
11375
- }
11376
-
11377
- // src/agent.ts
11378
11394
  init_content();
11379
11395
 
11380
11396
  // src/structuredOutput/manager.ts
@@ -16357,6 +16373,14 @@ ${pluginAppend}`;
16357
16373
  }
16358
16374
  async function trySummarize(currentState, currentRawMessages, ref, trigger) {
16359
16375
  if (!summarizer) return { state: currentState, rawMessages: currentRawMessages, compressed: false };
16376
+ if (hasUnresolvedToolCalls(currentRawMessages)) {
16377
+ const ctx2 = {
16378
+ ...currentState.ctx || {},
16379
+ __summarizationExhausted: true,
16380
+ __summarizationExhaustedAtToolCount: (currentState.toolHistory || []).length
16381
+ };
16382
+ return { state: { ...currentState, ctx: ctx2 }, rawMessages: currentRawMessages, compressed: false };
16383
+ }
16360
16384
  const compactHost = currentState.ctx?.__plugins;
16361
16385
  const tokensBefore = countMessagesTokens(currentState.messages || []);
16362
16386
  if (compactHost?.has("preCompact")) {
@@ -16575,10 +16599,11 @@ ${pluginAppend}`;
16575
16599
  subagentBlock = block;
16576
16600
  }
16577
16601
  const disclosureBlock = [skillBlock, subagentBlock].filter(Boolean).join("\n\n") || void 0;
16578
- const alreadyHasSystem = Array.isArray(input.messages) && input.messages[0]?.role === "system";
16579
- const seedMessages = alreadyHasSystem ? [...input.messages || []] : [
16602
+ const inputMessages = unburyPendingToolCalls(input.messages || []);
16603
+ const alreadyHasSystem = inputMessages[0]?.role === "system";
16604
+ const seedMessages = alreadyHasSystem ? [...inputMessages] : [
16580
16605
  systemMessage2(disclosureBlock, input.ctx?.__pluginSystemPromptAppend),
16581
- ...input.messages || []
16606
+ ...inputMessages
16582
16607
  ];
16583
16608
  let seedToolHistory = input.toolHistory;
16584
16609
  if (skillsEnabled && toolSet.skillRegistryRef) {