@linnlabs/linnkit 0.37.3 → 0.37.5

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/cli.cjs +2 -1
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +2 -1
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager/profiles/agent/context/config.d.cts +2 -2
  7. package/dist/context-manager/profiles/agent/context/config.d.ts +2 -2
  8. package/dist/context-manager.cjs +36 -24
  9. package/dist/context-manager.cjs.map +1 -1
  10. package/dist/context-manager.js +36 -24
  11. package/dist/context-manager.js.map +1 -1
  12. package/dist/contracts/contextPolicy.d.cts +2 -0
  13. package/dist/contracts/contextPolicy.d.ts +2 -0
  14. package/dist/contracts/events.d.cts +7 -7
  15. package/dist/contracts/events.d.ts +7 -7
  16. package/dist/contracts.cjs +1 -0
  17. package/dist/contracts.cjs.map +1 -1
  18. package/dist/contracts.js +1 -0
  19. package/dist/contracts.js.map +1 -1
  20. package/dist/index.cjs +2 -1
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.js +2 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/quickstart.cjs +2 -1
  25. package/dist/quickstart.cjs.map +1 -1
  26. package/dist/quickstart.js +2 -1
  27. package/dist/quickstart.js.map +1 -1
  28. package/dist/runtime-kernel/events.cjs +1 -0
  29. package/dist/runtime-kernel/events.cjs.map +1 -1
  30. package/dist/runtime-kernel/events.js +1 -0
  31. package/dist/runtime-kernel/events.js.map +1 -1
  32. package/dist/runtime-kernel.cjs +2 -1
  33. package/dist/runtime-kernel.cjs.map +1 -1
  34. package/dist/runtime-kernel.js +2 -1
  35. package/dist/runtime-kernel.js.map +1 -1
  36. package/dist/testkit.cjs +2 -1
  37. package/dist/testkit.cjs.map +1 -1
  38. package/dist/testkit.js +2 -1
  39. package/dist/testkit.js.map +1 -1
  40. package/docs/integration/context-engineering.md +7 -1
  41. package/docs/integration/llm-provider.md +5 -0
  42. package/docs/integration/tool-history.md +23 -0
  43. package/package.json +2 -2
@@ -42,8 +42,8 @@ declare const AGENT_CONTEXT_BUILDER_CONFIG: {
42
42
  */
43
43
  P3_HISTORICAL_TOOL_PRIORITY: number;
44
44
  /**
45
- * 工具调用配对搜索范围
46
- * - 在多少条消息范围内搜索工具调用的配对
45
+ * 工具调用配对距离:只计非同批结果消息,相邻结果为 1。
46
+ * - 批量结果不消耗窗口;user_input 或后续 assistant 始终关闭旧批次。
47
47
  */
48
48
  TOOL_PAIRING_SEARCH_RANGE: number;
49
49
  /**
@@ -42,8 +42,8 @@ declare const AGENT_CONTEXT_BUILDER_CONFIG: {
42
42
  */
43
43
  P3_HISTORICAL_TOOL_PRIORITY: number;
44
44
  /**
45
- * 工具调用配对搜索范围
46
- * - 在多少条消息范围内搜索工具调用的配对
45
+ * 工具调用配对距离:只计非同批结果消息,相邻结果为 1。
46
+ * - 批量结果不消耗窗口;user_input 或后续 assistant 始终关闭旧批次。
47
47
  */
48
48
  TOOL_PAIRING_SEARCH_RANGE: number;
49
49
  /**
@@ -896,6 +896,7 @@ var AgentSpecWorkingMemoryPolicy = zod.z.object({
896
896
  /** @deprecated Use maxRecentToolRuns. Kept as a compatibility alias for older AgentSpec configs. */
897
897
  maxRecentToolInteractions: zod.z.number().int().nonnegative().optional(),
898
898
  minToolInteractionsToKeep: zod.z.number().int().nonnegative().optional(),
899
+ /** 配对距离只计非同批结果消息;相邻结果为 1,不能跨 user_input 或后续 assistant。 */
899
900
  toolPairingSearchRange: zod.z.number().int().positive().optional()
900
901
  });
901
902
  var AgentSpecTokenEstimationPolicy = zod.z.object({
@@ -3012,8 +3013,8 @@ var AGENT_CONTEXT_BUILDER_CONFIG = {
3012
3013
  P3_HISTORICAL_TOOL_PRIORITY: 3,
3013
3014
  // === 工具交互特殊配置 ===
3014
3015
  /**
3015
- * 工具调用配对搜索范围
3016
- * - 在多少条消息范围内搜索工具调用的配对
3016
+ * 工具调用配对距离:只计非同批结果消息,相邻结果为 1。
3017
+ * - 批量结果不消耗窗口;user_input 或后续 assistant 始终关闭旧批次。
3017
3018
  */
3018
3019
  TOOL_PAIRING_SEARCH_RANGE: 10,
3019
3020
  /**
@@ -3370,19 +3371,24 @@ function getRawOutput(message) {
3370
3371
  }
3371
3372
  function buildToolInteractionGroups(entries, options = {}) {
3372
3373
  const groups = [];
3373
- const activeToolCallIdToGroupIndex = /* @__PURE__ */ new Map();
3374
+ const activeToolCalls = /* @__PURE__ */ new Map();
3375
+ const runToolCallOwners = /* @__PURE__ */ new Map();
3374
3376
  let currentRunOrdinal = 0;
3375
3377
  for (const entry of entries) {
3376
3378
  const { message } = entry;
3377
3379
  if (message.role === "user" && message.type === "user_input") {
3378
3380
  currentRunOrdinal += 1;
3381
+ activeToolCalls.clear();
3382
+ runToolCallOwners.clear();
3383
+ }
3384
+ if (message.role === "assistant") {
3385
+ activeToolCalls.clear();
3379
3386
  }
3380
3387
  if (message.role === "assistant" && message.type === "tool_calls") {
3381
3388
  const toolCalls = getToolCalls(message);
3382
3389
  if (toolCalls.length === 0) {
3383
3390
  continue;
3384
3391
  }
3385
- const groupIndex2 = groups.length;
3386
3392
  const itemList = toolCalls.map((toolCall) => {
3387
3393
  const toolName = typeof toolCall.function?.name === "string" && toolCall.function.name.trim().length > 0 ? toolCall.function.name : "unknown_tool";
3388
3394
  return {
@@ -3405,11 +3411,18 @@ function buildToolInteractionGroups(entries, options = {}) {
3405
3411
  startIndex: entry.originalIndex,
3406
3412
  endIndex: entry.originalIndex,
3407
3413
  isCompressed: false,
3414
+ hasIdentityConflict: false,
3408
3415
  items: itemList
3409
3416
  };
3410
3417
  groups.push(group2);
3411
3418
  for (const item2 of itemList) {
3412
- activeToolCallIdToGroupIndex.set(item2.toolCallId, groupIndex2);
3419
+ const previousOwner = runToolCallOwners.get(item2.toolCallId);
3420
+ if (previousOwner) {
3421
+ previousOwner.hasIdentityConflict = true;
3422
+ group2.hasIdentityConflict = true;
3423
+ }
3424
+ runToolCallOwners.set(item2.toolCallId, group2);
3425
+ activeToolCalls.set(item2.toolCallId, { group: group2, item: item2 });
3413
3426
  }
3414
3427
  continue;
3415
3428
  }
@@ -3420,17 +3433,16 @@ function buildToolInteractionGroups(entries, options = {}) {
3420
3433
  if (typeof toolCallId !== "string" || toolCallId.trim().length === 0) {
3421
3434
  continue;
3422
3435
  }
3423
- const groupIndex = activeToolCallIdToGroupIndex.get(toolCallId);
3424
- if (groupIndex === void 0) {
3436
+ const pairing = activeToolCalls.get(toolCallId);
3437
+ if (!pairing) {
3425
3438
  continue;
3426
3439
  }
3427
- const group = groups[groupIndex];
3428
- if (options.maxPairingDistance !== void 0 && entry.originalIndex - group.assistantIndex > options.maxPairingDistance) {
3440
+ const { group, item } = pairing;
3441
+ if (options.maxPairingDistance !== void 0 && entry.originalIndex - group.assistantIndex - group.toolOutputs.length > options.maxPairingDistance) {
3429
3442
  continue;
3430
3443
  }
3431
- const item = group.items.find((candidate) => candidate.toolCallId === toolCallId);
3432
- if (!item) {
3433
- continue;
3444
+ if (message.metadata?.tool_name !== void 0 && message.metadata.tool_name !== item.toolName) {
3445
+ group.hasIdentityConflict = true;
3434
3446
  }
3435
3447
  const outputEntry = { value: entry.value, message, index: entry.originalIndex };
3436
3448
  item.toolOutputs.push(outputEntry);
@@ -3442,9 +3454,9 @@ function buildToolInteractionGroups(entries, options = {}) {
3442
3454
  group.endIndex = Math.max(group.endIndex, entry.originalIndex);
3443
3455
  }
3444
3456
  return groups.map((group) => {
3445
- const sortedOutputs = [...group.toolOutputs].sort((left, right) => left.index - right.index);
3446
- const sortedItems = group.items.map((item) => {
3447
- const itemOutputs = [...item.toolOutputs].sort((left, right) => left.index - right.index);
3457
+ const outputs = group.toolOutputs;
3458
+ const items = group.items.map((item) => {
3459
+ const itemOutputs = item.toolOutputs;
3448
3460
  return {
3449
3461
  toolCallId: item.toolCallId,
3450
3462
  toolName: item.toolName,
@@ -3461,19 +3473,19 @@ function buildToolInteractionGroups(entries, options = {}) {
3461
3473
  assistantState: group.assistantState,
3462
3474
  assistantMessage: group.assistantMessage,
3463
3475
  assistantIndex: group.assistantIndex,
3464
- toolOutputs: sortedOutputs.map((output) => output.value),
3465
- toolOutputMessages: sortedOutputs.map((output) => output.message),
3466
- toolOutputIndexes: sortedOutputs.map((output) => output.index),
3467
- toolCallIds: sortedItems.map((item) => item.toolCallId),
3468
- toolNames: sortedItems.map((item) => item.toolName),
3476
+ toolOutputs: outputs.map((output) => output.value),
3477
+ toolOutputMessages: outputs.map((output) => output.message),
3478
+ toolOutputIndexes: outputs.map((output) => output.index),
3479
+ toolCallIds: items.map((item) => item.toolCallId),
3480
+ toolNames: items.map((item) => item.toolName),
3469
3481
  sourceMessageIds: Array.from(group.sourceMessageIds),
3470
- messageIndexes: [group.assistantIndex, ...sortedOutputs.map((output) => output.index)],
3482
+ messageIndexes: [group.assistantIndex, ...outputs.map((output) => output.index)],
3471
3483
  startIndex: group.startIndex,
3472
3484
  endIndex: group.endIndex,
3473
- isComplete: sortedItems.every((item) => item.toolOutputs.length > 0),
3485
+ isComplete: !group.hasIdentityConflict && items.every((item) => item.toolOutputs.length === 1),
3474
3486
  isCompressed: group.isCompressed,
3475
- items: sortedItems,
3476
- messages: [group.assistantState, ...sortedOutputs.map((output) => output.value)]
3487
+ items,
3488
+ messages: [group.assistantState, ...outputs.map((output) => output.value)]
3477
3489
  };
3478
3490
  });
3479
3491
  }