@linnlabs/linnkit 0.44.0 → 0.46.0

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 (38) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/cli.cjs +61 -8
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/cli.js +61 -8
  5. package/dist/cli.js.map +1 -1
  6. package/dist/context-manager.cjs +2 -1
  7. package/dist/context-manager.cjs.map +1 -1
  8. package/dist/context-manager.js +2 -1
  9. package/dist/context-manager.js.map +1 -1
  10. package/dist/index.cjs +62 -8
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.js +62 -8
  13. package/dist/index.js.map +1 -1
  14. package/dist/quickstart.cjs +61 -8
  15. package/dist/quickstart.cjs.map +1 -1
  16. package/dist/quickstart.js +61 -8
  17. package/dist/quickstart.js.map +1 -1
  18. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.cts +3 -0
  19. package/dist/runtime-kernel/graph-engine/nodes/toolNode.d.ts +3 -0
  20. package/dist/runtime-kernel/graph-engine/types.d.cts +1 -3
  21. package/dist/runtime-kernel/graph-engine/types.d.ts +1 -3
  22. package/dist/runtime-kernel/tools/toolContextRuntime.d.cts +1 -1
  23. package/dist/runtime-kernel/tools/toolContextRuntime.d.ts +1 -1
  24. package/dist/runtime-kernel/tools/toolExecutionContext.d.cts +10 -0
  25. package/dist/runtime-kernel/tools/toolExecutionContext.d.ts +10 -0
  26. package/dist/runtime-kernel.cjs +62 -8
  27. package/dist/runtime-kernel.cjs.map +1 -1
  28. package/dist/runtime-kernel.js +62 -8
  29. package/dist/runtime-kernel.js.map +1 -1
  30. package/dist/testkit.cjs +62 -8
  31. package/dist/testkit.cjs.map +1 -1
  32. package/dist/testkit.js +62 -8
  33. package/dist/testkit.js.map +1 -1
  34. package/docs/integration/agent-registration-guide.md +1 -1
  35. package/docs/integration/context-engineering.md +5 -5
  36. package/docs/integration/run-supervisor.md +1 -0
  37. package/docs/integration/tool-development-guide.md +4 -2
  38. package/package.json +2 -1
@@ -5162,13 +5162,11 @@ function createExecuteLlmStage(dependencies) {
5162
5162
  "llmCallStartedAt",
5163
5163
  "llmResp",
5164
5164
  "llmCallDurationMs",
5165
- "executorLocalPatch",
5166
5165
  "contextUsage"
5167
5166
  ],
5168
5167
  async run(ctx) {
5169
5168
  let cloudQuotaFallbackAppliedModelId;
5170
5169
  let modelFallbackAudit;
5171
- let lastSuccessfulLlmModelId;
5172
5170
  let contextUsage;
5173
5171
  const modelFallbackRejections = [];
5174
5172
  const promptBudget = ctx.promptBudget;
@@ -5189,8 +5187,7 @@ function createExecuteLlmStage(dependencies) {
5189
5187
  onCloudQuotaFallbackApplied(fallbackModelId) {
5190
5188
  cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
5191
5189
  },
5192
- onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
5193
- lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
5190
+ onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
5194
5191
  contextUsage = attemptContextUsage;
5195
5192
  },
5196
5193
  onModelFallbackApplied(info) {
@@ -5291,7 +5288,6 @@ function createExecuteLlmStage(dependencies) {
5291
5288
  llmCallStartedAt,
5292
5289
  llmResp,
5293
5290
  llmCallDurationMs,
5294
- executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
5295
5291
  contextUsage
5296
5292
  };
5297
5293
  }
@@ -8473,6 +8469,12 @@ function parseToolArgs(call) {
8473
8469
  };
8474
8470
  }
8475
8471
  }
8472
+ function readRunLockedModelId(local) {
8473
+ const executorLocal = local.executorLocal;
8474
+ if (!isRecord9(executorLocal)) return void 0;
8475
+ const lockedModelId = executorLocal.runLockedModelId;
8476
+ return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
8477
+ }
8476
8478
  function prepareToolNodeContext(state) {
8477
8479
  const local = state.local || {};
8478
8480
  const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
@@ -8490,6 +8492,7 @@ function prepareToolNodeContext(state) {
8490
8492
  }
8491
8493
  });
8492
8494
  attachWorkingHistoryView({ state, toolContext });
8495
+ toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
8493
8496
  return {
8494
8497
  state,
8495
8498
  local,
@@ -8732,9 +8735,49 @@ function recordToolProtocolError(params) {
8732
8735
  }
8733
8736
 
8734
8737
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8738
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
8739
+ function settleToolWithinAbortGrace(input) {
8740
+ const { execution, signal, graceMs } = input;
8741
+ if (!signal) return execution;
8742
+ return new Promise((resolve, reject) => {
8743
+ let timer;
8744
+ const cleanup = () => {
8745
+ if (timer !== void 0) clearTimeout(timer);
8746
+ signal.removeEventListener("abort", startGrace);
8747
+ };
8748
+ function startGrace() {
8749
+ timer = setTimeout(() => {
8750
+ cleanup();
8751
+ execution.catch(() => void 0);
8752
+ input.onAbandon?.();
8753
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
8754
+ error.name = "AbortError";
8755
+ reject(error);
8756
+ }, graceMs);
8757
+ }
8758
+ if (signal.aborted) startGrace();
8759
+ else signal.addEventListener("abort", startGrace, { once: true });
8760
+ execution.then(
8761
+ (value) => {
8762
+ cleanup();
8763
+ resolve(value);
8764
+ },
8765
+ (error) => {
8766
+ cleanup();
8767
+ reject(error);
8768
+ }
8769
+ );
8770
+ });
8771
+ }
8735
8772
  async function executeRecoverableTool(input) {
8736
8773
  const local = input.state.local;
8737
- if (!local?.commitExecutionBoundary) return input.execute();
8774
+ const run = () => settleToolWithinAbortGrace({
8775
+ execution: input.execute(),
8776
+ signal: local?.signal,
8777
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
8778
+ onAbandon: input.onAbandon
8779
+ });
8780
+ if (!local?.commitExecutionBoundary) return run();
8738
8781
  if (local.executingToolCallId) {
8739
8782
  if (local.executingToolCallId !== input.call.id) {
8740
8783
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -8747,7 +8790,7 @@ async function executeRecoverableTool(input) {
8747
8790
  }
8748
8791
  local.executingToolCallId = input.call.id;
8749
8792
  await local.commitExecutionBoundary(input.state);
8750
- const result = await input.execute();
8793
+ const result = await run();
8751
8794
  if (!result.success && isRunPauseSignal(local.signal)) {
8752
8795
  const error = new Error("Tool execution paused before its outcome was confirmed");
8753
8796
  error.name = "AbortError";
@@ -8867,7 +8910,9 @@ var ToolNode = class {
8867
8910
  auditPort;
8868
8911
  modelInputResolver;
8869
8912
  idempotencyInFlight = /* @__PURE__ */ new Map();
8913
+ abortGraceMs;
8870
8914
  constructor(dependencies) {
8915
+ this.abortGraceMs = dependencies.abortGraceMs;
8871
8916
  this.toolRuntime = dependencies.toolRuntime;
8872
8917
  this.observationPreview = dependencies.observationPreview;
8873
8918
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -9085,6 +9130,13 @@ var ToolNode = class {
9085
9130
  state,
9086
9131
  call,
9087
9132
  context: prepared.toolContext,
9133
+ abortGraceMs: this.abortGraceMs,
9134
+ onAbandon: () => logger11.warn("[ToolNode] \u5DE5\u5177\u672A\u5728\u505C\u6B62\u671F\u9650\u5185\u7ED3\u675F\uFF0C\u6309\u4E2D\u65AD\u5904\u7406\u5E76\u4E22\u5F03\u8FDF\u5230\u7ED3\u679C", {
9135
+ toolName: execution.toolName,
9136
+ toolCallId: execution.toolCallId,
9137
+ conversationId: prepared.conversationId,
9138
+ turnId: prepared.turnId
9139
+ }),
9088
9140
  execute: () => executeToolWithIdempotency({
9089
9141
  idempotencyKey: execution.idempotencyKey,
9090
9142
  inFlight: this.idempotencyInFlight,
@@ -9706,6 +9758,7 @@ var executor = z.object({
9706
9758
  systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
9707
9759
  toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
9708
9760
  runLockedModelId: z.string().optional(),
9761
+ // 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
9709
9762
  lastSuccessfulLlmModelId: z.string().optional(),
9710
9763
  llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
9711
9764
  llmInvocationCount: counter.optional(),
@@ -9715,7 +9768,7 @@ var executor = z.object({
9715
9768
  committedCount: counter,
9716
9769
  lastCommittedFingerprint: z.string().optional()
9717
9770
  }).strict().optional()
9718
- }).strict();
9771
+ }).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
9719
9772
  var checkpoint = z.object({
9720
9773
  nodeId: z.string().min(1),
9721
9774
  schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),