@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
@@ -5164,13 +5164,11 @@ function createExecuteLlmStage(dependencies) {
5164
5164
  "llmCallStartedAt",
5165
5165
  "llmResp",
5166
5166
  "llmCallDurationMs",
5167
- "executorLocalPatch",
5168
5167
  "contextUsage"
5169
5168
  ],
5170
5169
  async run(ctx) {
5171
5170
  let cloudQuotaFallbackAppliedModelId;
5172
5171
  let modelFallbackAudit;
5173
- let lastSuccessfulLlmModelId;
5174
5172
  let contextUsage;
5175
5173
  const modelFallbackRejections = [];
5176
5174
  const promptBudget = ctx.promptBudget;
@@ -5191,8 +5189,7 @@ function createExecuteLlmStage(dependencies) {
5191
5189
  onCloudQuotaFallbackApplied(fallbackModelId) {
5192
5190
  cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
5193
5191
  },
5194
- onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
5195
- lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
5192
+ onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
5196
5193
  contextUsage = attemptContextUsage;
5197
5194
  },
5198
5195
  onModelFallbackApplied(info) {
@@ -5293,7 +5290,6 @@ function createExecuteLlmStage(dependencies) {
5293
5290
  llmCallStartedAt,
5294
5291
  llmResp,
5295
5292
  llmCallDurationMs,
5296
- executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
5297
5293
  contextUsage
5298
5294
  };
5299
5295
  }
@@ -8475,6 +8471,12 @@ function parseToolArgs(call) {
8475
8471
  };
8476
8472
  }
8477
8473
  }
8474
+ function readRunLockedModelId(local) {
8475
+ const executorLocal = local.executorLocal;
8476
+ if (!isRecord9(executorLocal)) return void 0;
8477
+ const lockedModelId = executorLocal.runLockedModelId;
8478
+ return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
8479
+ }
8478
8480
  function prepareToolNodeContext(state) {
8479
8481
  const local = state.local || {};
8480
8482
  const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
@@ -8492,6 +8494,7 @@ function prepareToolNodeContext(state) {
8492
8494
  }
8493
8495
  });
8494
8496
  attachWorkingHistoryView({ state, toolContext });
8497
+ toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
8495
8498
  return {
8496
8499
  state,
8497
8500
  local,
@@ -8734,9 +8737,49 @@ function recordToolProtocolError(params) {
8734
8737
  }
8735
8738
 
8736
8739
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
8740
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
8741
+ function settleToolWithinAbortGrace(input) {
8742
+ const { execution, signal, graceMs } = input;
8743
+ if (!signal) return execution;
8744
+ return new Promise((resolve, reject) => {
8745
+ let timer;
8746
+ const cleanup = () => {
8747
+ if (timer !== void 0) clearTimeout(timer);
8748
+ signal.removeEventListener("abort", startGrace);
8749
+ };
8750
+ function startGrace() {
8751
+ timer = setTimeout(() => {
8752
+ cleanup();
8753
+ execution.catch(() => void 0);
8754
+ input.onAbandon?.();
8755
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
8756
+ error.name = "AbortError";
8757
+ reject(error);
8758
+ }, graceMs);
8759
+ }
8760
+ if (signal.aborted) startGrace();
8761
+ else signal.addEventListener("abort", startGrace, { once: true });
8762
+ execution.then(
8763
+ (value) => {
8764
+ cleanup();
8765
+ resolve(value);
8766
+ },
8767
+ (error) => {
8768
+ cleanup();
8769
+ reject(error);
8770
+ }
8771
+ );
8772
+ });
8773
+ }
8737
8774
  async function executeRecoverableTool(input) {
8738
8775
  const local = input.state.local;
8739
- if (!local?.commitExecutionBoundary) return input.execute();
8776
+ const run = () => settleToolWithinAbortGrace({
8777
+ execution: input.execute(),
8778
+ signal: local?.signal,
8779
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
8780
+ onAbandon: input.onAbandon
8781
+ });
8782
+ if (!local?.commitExecutionBoundary) return run();
8740
8783
  if (local.executingToolCallId) {
8741
8784
  if (local.executingToolCallId !== input.call.id) {
8742
8785
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -8749,7 +8792,7 @@ async function executeRecoverableTool(input) {
8749
8792
  }
8750
8793
  local.executingToolCallId = input.call.id;
8751
8794
  await local.commitExecutionBoundary(input.state);
8752
- const result = await input.execute();
8795
+ const result = await run();
8753
8796
  if (!result.success && isRunPauseSignal(local.signal)) {
8754
8797
  const error = new Error("Tool execution paused before its outcome was confirmed");
8755
8798
  error.name = "AbortError";
@@ -8869,7 +8912,9 @@ var ToolNode = class {
8869
8912
  auditPort;
8870
8913
  modelInputResolver;
8871
8914
  idempotencyInFlight = /* @__PURE__ */ new Map();
8915
+ abortGraceMs;
8872
8916
  constructor(dependencies) {
8917
+ this.abortGraceMs = dependencies.abortGraceMs;
8873
8918
  this.toolRuntime = dependencies.toolRuntime;
8874
8919
  this.observationPreview = dependencies.observationPreview;
8875
8920
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -9087,6 +9132,13 @@ var ToolNode = class {
9087
9132
  state,
9088
9133
  call,
9089
9134
  context: prepared.toolContext,
9135
+ abortGraceMs: this.abortGraceMs,
9136
+ 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", {
9137
+ toolName: execution.toolName,
9138
+ toolCallId: execution.toolCallId,
9139
+ conversationId: prepared.conversationId,
9140
+ turnId: prepared.turnId
9141
+ }),
9090
9142
  execute: () => executeToolWithIdempotency({
9091
9143
  idempotencyKey: execution.idempotencyKey,
9092
9144
  inFlight: this.idempotencyInFlight,
@@ -9708,6 +9760,7 @@ var executor = zod.z.object({
9708
9760
  systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
9709
9761
  toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
9710
9762
  runLockedModelId: zod.z.string().optional(),
9763
+ // 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
9711
9764
  lastSuccessfulLlmModelId: zod.z.string().optional(),
9712
9765
  llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
9713
9766
  llmInvocationCount: counter.optional(),
@@ -9717,7 +9770,7 @@ var executor = zod.z.object({
9717
9770
  committedCount: counter,
9718
9771
  lastCommittedFingerprint: zod.z.string().optional()
9719
9772
  }).strict().optional()
9720
- }).strict();
9773
+ }).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
9721
9774
  var checkpoint = zod.z.object({
9722
9775
  nodeId: zod.z.string().min(1),
9723
9776
  schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),