@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/testkit.cjs CHANGED
@@ -5363,13 +5363,11 @@ function createExecuteLlmStage(dependencies) {
5363
5363
  "llmCallStartedAt",
5364
5364
  "llmResp",
5365
5365
  "llmCallDurationMs",
5366
- "executorLocalPatch",
5367
5366
  "contextUsage"
5368
5367
  ],
5369
5368
  async run(ctx) {
5370
5369
  let cloudQuotaFallbackAppliedModelId;
5371
5370
  let modelFallbackAudit;
5372
- let lastSuccessfulLlmModelId;
5373
5371
  let contextUsage;
5374
5372
  const modelFallbackRejections = [];
5375
5373
  const promptBudget = ctx.promptBudget;
@@ -5390,8 +5388,7 @@ function createExecuteLlmStage(dependencies) {
5390
5388
  onCloudQuotaFallbackApplied(fallbackModelId) {
5391
5389
  cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
5392
5390
  },
5393
- onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
5394
- lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
5391
+ onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
5395
5392
  contextUsage = attemptContextUsage;
5396
5393
  },
5397
5394
  onModelFallbackApplied(info) {
@@ -5492,7 +5489,6 @@ function createExecuteLlmStage(dependencies) {
5492
5489
  llmCallStartedAt,
5493
5490
  llmResp,
5494
5491
  llmCallDurationMs,
5495
- executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
5496
5492
  contextUsage
5497
5493
  };
5498
5494
  }
@@ -8401,6 +8397,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
8401
8397
  "conversationView",
8402
8398
  "userQuery",
8403
8399
  "modelId",
8400
+ "activeModelId",
8404
8401
  "conversationId",
8405
8402
  "turnId",
8406
8403
  "runId",
@@ -8734,6 +8731,12 @@ function parseToolArgs(call) {
8734
8731
  };
8735
8732
  }
8736
8733
  }
8734
+ function readRunLockedModelId(local) {
8735
+ const executorLocal = local.executorLocal;
8736
+ if (!isRecord9(executorLocal)) return void 0;
8737
+ const lockedModelId = executorLocal.runLockedModelId;
8738
+ return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
8739
+ }
8737
8740
  function prepareToolNodeContext(state) {
8738
8741
  const local = state.local || {};
8739
8742
  const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
@@ -8751,6 +8754,7 @@ function prepareToolNodeContext(state) {
8751
8754
  }
8752
8755
  });
8753
8756
  attachWorkingHistoryView({ state, toolContext });
8757
+ toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
8754
8758
  return {
8755
8759
  state,
8756
8760
  local,
@@ -8993,9 +8997,49 @@ function recordToolProtocolError(params) {
8993
8997
  }
8994
8998
 
8995
8999
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
9000
+ var DEFAULT_TOOL_ABORT_GRACE_MS = 3e3;
9001
+ function settleToolWithinAbortGrace(input) {
9002
+ const { execution, signal, graceMs } = input;
9003
+ if (!signal) return execution;
9004
+ return new Promise((resolve, reject) => {
9005
+ let timer;
9006
+ const cleanup = () => {
9007
+ if (timer !== void 0) clearTimeout(timer);
9008
+ signal.removeEventListener("abort", startGrace);
9009
+ };
9010
+ function startGrace() {
9011
+ timer = setTimeout(() => {
9012
+ cleanup();
9013
+ execution.catch(() => void 0);
9014
+ input.onAbandon?.();
9015
+ const error = new Error("Tool did not stop within the abort grace period; its late outcome is discarded.");
9016
+ error.name = "AbortError";
9017
+ reject(error);
9018
+ }, graceMs);
9019
+ }
9020
+ if (signal.aborted) startGrace();
9021
+ else signal.addEventListener("abort", startGrace, { once: true });
9022
+ execution.then(
9023
+ (value) => {
9024
+ cleanup();
9025
+ resolve(value);
9026
+ },
9027
+ (error) => {
9028
+ cleanup();
9029
+ reject(error);
9030
+ }
9031
+ );
9032
+ });
9033
+ }
8996
9034
  async function executeRecoverableTool(input) {
8997
9035
  const local = input.state.local;
8998
- if (!local?.commitExecutionBoundary) return input.execute();
9036
+ const run = () => settleToolWithinAbortGrace({
9037
+ execution: input.execute(),
9038
+ signal: local?.signal,
9039
+ graceMs: input.abortGraceMs ?? DEFAULT_TOOL_ABORT_GRACE_MS,
9040
+ onAbandon: input.onAbandon
9041
+ });
9042
+ if (!local?.commitExecutionBoundary) return run();
8999
9043
  if (local.executingToolCallId) {
9000
9044
  if (local.executingToolCallId !== input.call.id) {
9001
9045
  throw new RunRecoveryBlockedError("Pending tool identity does not match execution intent");
@@ -9008,7 +9052,7 @@ async function executeRecoverableTool(input) {
9008
9052
  }
9009
9053
  local.executingToolCallId = input.call.id;
9010
9054
  await local.commitExecutionBoundary(input.state);
9011
- const result = await input.execute();
9055
+ const result = await run();
9012
9056
  if (!result.success && isRunPauseSignal(local.signal)) {
9013
9057
  const error = new Error("Tool execution paused before its outcome was confirmed");
9014
9058
  error.name = "AbortError";
@@ -9128,7 +9172,9 @@ var ToolNode = class {
9128
9172
  auditPort;
9129
9173
  modelInputResolver;
9130
9174
  idempotencyInFlight = /* @__PURE__ */ new Map();
9175
+ abortGraceMs;
9131
9176
  constructor(dependencies) {
9177
+ this.abortGraceMs = dependencies.abortGraceMs;
9132
9178
  this.toolRuntime = dependencies.toolRuntime;
9133
9179
  this.observationPreview = dependencies.observationPreview;
9134
9180
  this.telemetryPort = dependencies.telemetryPort ?? noopTelemetry;
@@ -9346,6 +9392,13 @@ var ToolNode = class {
9346
9392
  state,
9347
9393
  call,
9348
9394
  context: prepared.toolContext,
9395
+ abortGraceMs: this.abortGraceMs,
9396
+ 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", {
9397
+ toolName: execution.toolName,
9398
+ toolCallId: execution.toolCallId,
9399
+ conversationId: prepared.conversationId,
9400
+ turnId: prepared.turnId
9401
+ }),
9349
9402
  execute: () => executeToolWithIdempotency({
9350
9403
  idempotencyKey: execution.idempotencyKey,
9351
9404
  inFlight: this.idempotencyInFlight,
@@ -9967,6 +10020,7 @@ var executor = zod.z.object({
9967
10020
  systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
9968
10021
  toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
9969
10022
  runLockedModelId: zod.z.string().optional(),
10023
+ // 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
9970
10024
  lastSuccessfulLlmModelId: zod.z.string().optional(),
9971
10025
  llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
9972
10026
  llmInvocationCount: counter.optional(),
@@ -9976,7 +10030,7 @@ var executor = zod.z.object({
9976
10030
  committedCount: counter,
9977
10031
  lastCommittedFingerprint: zod.z.string().optional()
9978
10032
  }).strict().optional()
9979
- }).strict();
10033
+ }).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
9980
10034
  var checkpoint = zod.z.object({
9981
10035
  nodeId: zod.z.string().min(1),
9982
10036
  schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),