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