@linnlabs/linnkit 0.45.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.
@@ -21,8 +21,6 @@ interface ExecutorLocalState {
21
21
  systemReminderPolicy?: AgentSpecSystemReminderPolicy;
22
22
  toolObservationPolicy?: AgentSpecToolObservationGovernancePolicy;
23
23
  runLockedModelId?: string;
24
- /** 最近一次成功产生当前工具调用决策的真实 provider model。 */
25
- lastSuccessfulLlmModelId?: string;
26
24
  /**
27
25
  * 当前这一次 LLM 调用的业务来源。
28
26
  *
@@ -55,7 +53,7 @@ interface ExecutorLocalState {
55
53
  lastCommittedFingerprint?: string;
56
54
  };
57
55
  }
58
- type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'lastSuccessfulLlmModelId' | 'contextCompaction'>>;
56
+ type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'contextCompaction'>>;
59
57
  interface EngineLocalState extends Record<string, unknown> {
60
58
  runId?: RunId;
61
59
  parentRunId?: RunId;
@@ -21,8 +21,6 @@ interface ExecutorLocalState {
21
21
  systemReminderPolicy?: AgentSpecSystemReminderPolicy;
22
22
  toolObservationPolicy?: AgentSpecToolObservationGovernancePolicy;
23
23
  runLockedModelId?: string;
24
- /** 最近一次成功产生当前工具调用决策的真实 provider model。 */
25
- lastSuccessfulLlmModelId?: string;
26
24
  /**
27
25
  * 当前这一次 LLM 调用的业务来源。
28
26
  *
@@ -55,7 +53,7 @@ interface ExecutorLocalState {
55
53
  lastCommittedFingerprint?: string;
56
54
  };
57
55
  }
58
- type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'lastSuccessfulLlmModelId' | 'contextCompaction'>>;
56
+ type ExecutorLocalPatch = Partial<Pick<ExecutorLocalState, 'runLockedModelId' | 'contextCompaction'>>;
59
57
  interface EngineLocalState extends Record<string, unknown> {
60
58
  runId?: RunId;
61
59
  parentRunId?: RunId;
@@ -20,7 +20,7 @@ interface ToolContextRuntimeBinding {
20
20
  bindExecutionMeta(meta: ToolContextExecutionMeta): void;
21
21
  readExecutionMeta(): Readonly<ToolContextExecutionMeta>;
22
22
  }
23
- declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
23
+ declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "activeModelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
24
24
  declare function ensureToolContextRuntimeCapability(params: {
25
25
  context: ToolExecutionContext;
26
26
  persistedHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
@@ -20,7 +20,7 @@ interface ToolContextRuntimeBinding {
20
20
  bindExecutionMeta(meta: ToolContextExecutionMeta): void;
21
21
  readExecutionMeta(): Readonly<ToolContextExecutionMeta>;
22
22
  }
23
- declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
23
+ declare const TOOL_CONTEXT_RUNTIME_RESERVED_KEYS: readonly ["conversationView", "userQuery", "modelId", "activeModelId", "conversationId", "turnId", "runId", "parentRunId", "childRunDepth", "childRunContextInjections", "parentToolCallId"];
24
24
  declare function ensureToolContextRuntimeCapability(params: {
25
25
  context: ToolExecutionContext;
26
26
  persistedHistory?: ReadonlyArray<RuntimeEvent> | RuntimeEventSource;
@@ -17,6 +17,16 @@ interface ToolExecutionContext {
17
17
  userQuery?: string;
18
18
  /** 当前 run 已选定的模型 ID;需要继承模型的 child-run 从这里读取。 */
19
19
  modelId?: string;
20
+ /**
21
+ * 工具结果接下来交给的模型 ID(由 ToolNode 在执行工具前注入)。
22
+ *
23
+ * 中文备注:
24
+ * - 平时等于 `modelId`;云端额度兜底后 run 锁定到兜底模型,此时是兜底模型;
25
+ * - 决定工具结果里放什么给模型看(如是否附图)时按它判断,不能按 `modelId`,
26
+ * 否则会给不能看图的兜底模型附图,下一次请求在输入预检被拒;
27
+ * - child-run 继承模型仍读 `modelId`。
28
+ */
29
+ activeModelId?: string;
20
30
  /**
21
31
  * 当前对话 run 的唯一标识(由 host admission 注入)。
22
32
  * 说明:工具不得把 runId 当作业务数据身份;它只服务运行链路追踪和关联。
@@ -17,6 +17,16 @@ interface ToolExecutionContext {
17
17
  userQuery?: string;
18
18
  /** 当前 run 已选定的模型 ID;需要继承模型的 child-run 从这里读取。 */
19
19
  modelId?: string;
20
+ /**
21
+ * 工具结果接下来交给的模型 ID(由 ToolNode 在执行工具前注入)。
22
+ *
23
+ * 中文备注:
24
+ * - 平时等于 `modelId`;云端额度兜底后 run 锁定到兜底模型,此时是兜底模型;
25
+ * - 决定工具结果里放什么给模型看(如是否附图)时按它判断,不能按 `modelId`,
26
+ * 否则会给不能看图的兜底模型附图,下一次请求在输入预检被拒;
27
+ * - child-run 继承模型仍读 `modelId`。
28
+ */
29
+ activeModelId?: string;
20
30
  /**
21
31
  * 当前对话 run 的唯一标识(由 host admission 注入)。
22
32
  * 说明:工具不得把 runId 当作业务数据身份;它只服务运行链路追踪和关联。
@@ -5175,13 +5175,11 @@ function createExecuteLlmStage(dependencies) {
5175
5175
  "llmCallStartedAt",
5176
5176
  "llmResp",
5177
5177
  "llmCallDurationMs",
5178
- "executorLocalPatch",
5179
5178
  "contextUsage"
5180
5179
  ],
5181
5180
  async run(ctx) {
5182
5181
  let cloudQuotaFallbackAppliedModelId;
5183
5182
  let modelFallbackAudit;
5184
- let lastSuccessfulLlmModelId;
5185
5183
  let contextUsage;
5186
5184
  const modelFallbackRejections = [];
5187
5185
  const promptBudget = ctx.promptBudget;
@@ -5202,8 +5200,7 @@ function createExecuteLlmStage(dependencies) {
5202
5200
  onCloudQuotaFallbackApplied(fallbackModelId) {
5203
5201
  cloudQuotaFallbackAppliedModelId = readNonEmptyString3(fallbackModelId);
5204
5202
  },
5205
- onLlmAttemptSucceeded(activeModelId, attemptContextUsage) {
5206
- lastSuccessfulLlmModelId = readNonEmptyString3(activeModelId);
5203
+ onLlmAttemptSucceeded(_activeModelId, attemptContextUsage) {
5207
5204
  contextUsage = attemptContextUsage;
5208
5205
  },
5209
5206
  onModelFallbackApplied(info) {
@@ -5304,7 +5301,6 @@ function createExecuteLlmStage(dependencies) {
5304
5301
  llmCallStartedAt,
5305
5302
  llmResp,
5306
5303
  llmCallDurationMs,
5307
- executorLocalPatch: lastSuccessfulLlmModelId ? { lastSuccessfulLlmModelId } : void 0,
5308
5304
  contextUsage
5309
5305
  };
5310
5306
  }
@@ -8213,6 +8209,7 @@ var TOOL_CONTEXT_RUNTIME_RESERVED_KEYS = [
8213
8209
  "conversationView",
8214
8210
  "userQuery",
8215
8211
  "modelId",
8212
+ "activeModelId",
8216
8213
  "conversationId",
8217
8214
  "turnId",
8218
8215
  "runId",
@@ -8546,6 +8543,12 @@ function parseToolArgs(call) {
8546
8543
  };
8547
8544
  }
8548
8545
  }
8546
+ function readRunLockedModelId(local) {
8547
+ const executorLocal = local.executorLocal;
8548
+ if (!isRecord9(executorLocal)) return void 0;
8549
+ const lockedModelId = executorLocal.runLockedModelId;
8550
+ return typeof lockedModelId === "string" && lockedModelId.trim() ? lockedModelId : void 0;
8551
+ }
8549
8552
  function prepareToolNodeContext(state) {
8550
8553
  const local = state.local || {};
8551
8554
  const toolContext = isRecord9(local.toolContext) ? local.toolContext : {};
@@ -8563,6 +8566,7 @@ function prepareToolNodeContext(state) {
8563
8566
  }
8564
8567
  });
8565
8568
  attachWorkingHistoryView({ state, toolContext });
8569
+ toolContext.activeModelId = readRunLockedModelId(local) ?? toolContext.modelId;
8566
8570
  return {
8567
8571
  state,
8568
8572
  local,
@@ -9828,6 +9832,7 @@ var executor = zod.z.object({
9828
9832
  systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
9829
9833
  toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
9830
9834
  runLockedModelId: zod.z.string().optional(),
9835
+ // 0.45 及更早的 checkpoint 可能带这个已删除字段;照常接受,读入时丢弃。
9831
9836
  lastSuccessfulLlmModelId: zod.z.string().optional(),
9832
9837
  llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
9833
9838
  llmInvocationCount: counter.optional(),
@@ -9837,7 +9842,7 @@ var executor = zod.z.object({
9837
9842
  committedCount: counter,
9838
9843
  lastCommittedFingerprint: zod.z.string().optional()
9839
9844
  }).strict().optional()
9840
- }).strict();
9845
+ }).strict().transform(({ lastSuccessfulLlmModelId: _retired, ...state }) => state);
9841
9846
  var checkpoint = zod.z.object({
9842
9847
  nodeId: zod.z.string().min(1),
9843
9848
  schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),