@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
package/dist/index.cjs CHANGED
@@ -6200,13 +6200,11 @@ function createExecuteLlmStage(dependencies) {
6200
6200
  "llmCallStartedAt",
6201
6201
  "llmResp",
6202
6202
  "llmCallDurationMs",
6203
- "executorLocalPatch",
6204
6203
  "contextUsage"
6205
6204
  ],
6206
6205
  async run(ctx) {
6207
6206
  let cloudQuotaFallbackAppliedModelId;
6208
6207
  let modelFallbackAudit;
6209
- let lastSuccessfulLlmModelId;
6210
6208
  let contextUsage;
6211
6209
  const modelFallbackRejections = [];
6212
6210
  const promptBudget = ctx.promptBudget;
@@ -6227,8 +6225,7 @@ function createExecuteLlmStage(dependencies) {
6227
6225
  onCloudQuotaFallbackApplied(fallbackModelId) {
6228
6226
  cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
6229
6227
  },
6230
- onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
6231
- lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
6228
+ onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
6232
6229
  contextUsage = attemptContextUsage;
6233
6230
  },
6234
6231
  onModelFallbackApplied(info) {
@@ -6329,7 +6326,6 @@ function createExecuteLlmStage(dependencies) {
6329
6326
  llmCallStartedAt,
6330
6327
  llmResp,
6331
6328
  llmCallDurationMs,
6332
- executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
6333
6329
  contextUsage
6334
6330
  };
6335
6331
  }
@@ -9238,6 +9234,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
9238
9234
  "conversationView",
9239
9235
  "userQuery",
9240
9236
  "modelId",
9237
+ "activeModelId",
9241
9238
  "conversationId",
9242
9239
  "turnId",
9243
9240
  "runId",
@@ -9571,6 +9568,12 @@ function parseToolArgs(call) {
9571
9568
  };
9572
9569
  }
9573
9570
  }
9571
+ function readRunLockedModelId(local) {
9572
+ const executorLocal = local.executorLocal;
9573
+ if (!isRecord9(executorLocal)) return void 0;
9574
+ const lockedModelId = executorLocal.runLockedModelId;
9575
+ return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
9576
+ }
9574
9577
  function prepareToolNodeContext(state) {
9575
9578
  const local = state.local || {};
9576
9579
  const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
@@ -9588,6 +9591,7 @@ function prepareToolNodeContext(state) {
9588
9591
  }
9589
9592
  });
9590
9593
  attachWorkingHistoryView({ state, toolContext });
9594
+ toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
9591
9595
  return {
9592
9596
  state,
9593
9597
  local,
@@ -9837,9 +9841,49 @@ function recordToolProtocolError(params) {
9837
9841
  }
9838
9842
 
9839
9843
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
9844
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
9845
+ function settleToolWithinAbortGrace(input) {
9846
+ const { execution, signal, graceMs } = input;
9847
+ if (!signal) return execution;
9848
+ return new Promise((resolve, reject) => {
9849
+ let timer;
9850
+ const cleanup = () => {
9851
+ if (timer !== void 0) clearTimeout(timer);
9852
+ signal.removeEventListener("abort", startGrace);
9853
+ };
9854
+ function startGrace() {
9855
+ timer = setTimeout(() => {
9856
+ cleanup();
9857
+ execution.catch(() => void 0);
9858
+ input.onAbandon?.();
9859
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
9860
+ error.name = "AbortError";
9861
+ reject(error);
9862
+ }, graceMs);
9863
+ }
9864
+ if (signal.aborted) startGrace();
9865
+ else signal.addEventListener("abort", startGrace, { once: true });
9866
+ execution.then(
9867
+ (value) => {
9868
+ cleanup();
9869
+ resolve(value);
9870
+ },
9871
+ (error) => {
9872
+ cleanup();
9873
+ reject(error);
9874
+ }
9875
+ );
9876
+ });
9877
+ }
9840
9878
  async function executeRecoverableTool(input) {
9841
9879
  const local = input.state.local;
9842
- if (!local?.commitExecutionBoundary) return input.execute();
9880
+ const run = () => settleToolWithinAbortGrace({
9881
+ execution: input.execute(),
9882
+ signal: local?.signal,
9883
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
9884
+ onAbandon: input.onAbandon
9885
+ });
9886
+ if (!local?.commitExecutionBoundary) return run();
9843
9887
  if (local.executingToolCallId) {
9844
9888
  if (local.executingToolCallId !== input.call.id) {
9845
9889
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -9852,7 +9896,7 @@ async function executeRecoverableTool(input) {
9852
9896
  }
9853
9897
  local.executingToolCallId = input.call.id;
9854
9898
  await local.commitExecutionBoundary(input.state);
9855
- const result = await input.execute();
9899
+ const result = await run();
9856
9900
  if (!result.success && isRunPauseSignal(local.signal)) {
9857
9901
  const error = new Error("Tool execution paused before its outcome was confirmed");
9858
9902
  error.name = "AbortError";
@@ -9972,7 +10016,9 @@ var ToolNode = class {
9972
10016
  auditPort;
9973
10017
  modelInputResolver;
9974
10018
  idempotencyInFlight = /* @__PURE__ */ new Map();
10019
+ abortGraceMs;
9975
10020
  constructor(dependencies) {
10021
+ this.abortGraceMs = dependencies.abortGraceMs;
9976
10022
  this.toolRuntime = dependencies.toolRuntime;
9977
10023
  this.observationPreview = dependencies.observationPreview;
9978
10024
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -10190,6 +10236,13 @@ var ToolNode = class {
10190
10236
  state,
10191
10237
  call,
10192
10238
  context: prepared.toolContext,
10239
+ abortGraceMs: this.abortGraceMs,
10240
+ 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", {
10241
+ toolName: execution.toolName,
10242
+ toolCallId: execution.toolCallId,
10243
+ conversationId: prepared.conversationId,
10244
+ turnId: prepared.turnId
10245
+ }),
10193
10246
  execute: () => executeToolWithIdempotency({
10194
10247
  idempotencyKey: execution.idempotencyKey,
10195
10248
  inFlight: this.idempotencyInFlight,
@@ -10811,6 +10864,7 @@ var executor = zod.z.object({
10811
10864
  systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
10812
10865
  toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
10813
10866
  runLockedModelId: zod.z.string().optional(),
10867
+ // 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
10814
10868
  lastSuccessfulLlmModelId: zod.z.string().optional(),
10815
10869
  llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
10816
10870
  llmInvocationCount: counter.optional(),
@@ -10820,7 +10874,7 @@ var executor = zod.z.object({
10820
10874
  committedCount: counter,
10821
10875
  lastCommittedFingerprint: zod.z.string().optional()
10822
10876
  }).strict().optional()
10823
- }).strict();
10877
+ }).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
10824
10878
  var checkpoint = zod.z.object({
10825
10879
  nodeId: zod.z.string().min(1),
10826
10880
  schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),