@linnlabs/linnkit 0.36.0 → 0.37.1

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.
@@ -210,6 +210,7 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
210
210
  conversationId?: string | undefined;
211
211
  turnId?: string | undefined;
212
212
  modelId?: string | undefined;
213
+ stepId?: string | undefined;
213
214
  route?: {
214
215
  modelId: string;
215
216
  capabilityId: string;
@@ -222,7 +223,6 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
222
223
  baseURL?: string | undefined;
223
224
  endpointModelId?: string | undefined;
224
225
  } | undefined;
225
- stepId?: string | undefined;
226
226
  createdAt?: number | undefined;
227
227
  }, {
228
228
  id: string;
@@ -244,6 +244,7 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
244
244
  conversationId?: string | undefined;
245
245
  turnId?: string | undefined;
246
246
  modelId?: string | undefined;
247
+ stepId?: string | undefined;
247
248
  route?: {
248
249
  modelId: string;
249
250
  capabilityId: string;
@@ -256,7 +257,6 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
256
257
  baseURL?: string | undefined;
257
258
  endpointModelId?: string | undefined;
258
259
  } | undefined;
259
- stepId?: string | undefined;
260
260
  createdAt?: number | undefined;
261
261
  }>;
262
262
  type LlmUsageTokenLedgerEntry = z.infer<typeof LlmUsageTokenLedgerEntry>;
@@ -413,6 +413,7 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
413
413
  parentRunId?: string | undefined;
414
414
  conversationId?: string | undefined;
415
415
  turnId?: string | undefined;
416
+ stepId?: string | undefined;
416
417
  route?: {
417
418
  modelId: string;
418
419
  capabilityId: string;
@@ -425,7 +426,6 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
425
426
  baseURL?: string | undefined;
426
427
  endpointModelId?: string | undefined;
427
428
  } | undefined;
428
- stepId?: string | undefined;
429
429
  createdAt?: number | undefined;
430
430
  }, {
431
431
  id: string;
@@ -458,6 +458,7 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
458
458
  parentRunId?: string | undefined;
459
459
  conversationId?: string | undefined;
460
460
  turnId?: string | undefined;
461
+ stepId?: string | undefined;
461
462
  route?: {
462
463
  modelId: string;
463
464
  capabilityId: string;
@@ -470,7 +471,6 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
470
471
  baseURL?: string | undefined;
471
472
  endpointModelId?: string | undefined;
472
473
  } | undefined;
473
- stepId?: string | undefined;
474
474
  createdAt?: number | undefined;
475
475
  }>;
476
476
  type ContextComponentTokenLedgerEntry = z.infer<typeof ContextComponentTokenLedgerEntry>;
@@ -583,6 +583,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
583
583
  conversationId?: string | undefined;
584
584
  turnId?: string | undefined;
585
585
  modelId?: string | undefined;
586
+ stepId?: string | undefined;
586
587
  route?: {
587
588
  modelId: string;
588
589
  capabilityId: string;
@@ -595,7 +596,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
595
596
  baseURL?: string | undefined;
596
597
  endpointModelId?: string | undefined;
597
598
  } | undefined;
598
- stepId?: string | undefined;
599
599
  createdAt?: number | undefined;
600
600
  }, {
601
601
  id: string;
@@ -617,6 +617,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
617
617
  conversationId?: string | undefined;
618
618
  turnId?: string | undefined;
619
619
  modelId?: string | undefined;
620
+ stepId?: string | undefined;
620
621
  route?: {
621
622
  modelId: string;
622
623
  capabilityId: string;
@@ -629,7 +630,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
629
630
  baseURL?: string | undefined;
630
631
  endpointModelId?: string | undefined;
631
632
  } | undefined;
632
- stepId?: string | undefined;
633
633
  createdAt?: number | undefined;
634
634
  }>, z.ZodObject<{
635
635
  id: z.ZodString;
@@ -784,6 +784,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
784
784
  parentRunId?: string | undefined;
785
785
  conversationId?: string | undefined;
786
786
  turnId?: string | undefined;
787
+ stepId?: string | undefined;
787
788
  route?: {
788
789
  modelId: string;
789
790
  capabilityId: string;
@@ -796,7 +797,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
796
797
  baseURL?: string | undefined;
797
798
  endpointModelId?: string | undefined;
798
799
  } | undefined;
799
- stepId?: string | undefined;
800
800
  createdAt?: number | undefined;
801
801
  }, {
802
802
  id: string;
@@ -829,6 +829,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
829
829
  parentRunId?: string | undefined;
830
830
  conversationId?: string | undefined;
831
831
  turnId?: string | undefined;
832
+ stepId?: string | undefined;
832
833
  route?: {
833
834
  modelId: string;
834
835
  capabilityId: string;
@@ -841,7 +842,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
841
842
  baseURL?: string | undefined;
842
843
  endpointModelId?: string | undefined;
843
844
  } | undefined;
844
- stepId?: string | undefined;
845
845
  createdAt?: number | undefined;
846
846
  }>]>;
847
847
  type TokenLedgerEntry = z.infer<typeof TokenLedgerEntry>;
@@ -210,6 +210,7 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
210
210
  conversationId?: string | undefined;
211
211
  turnId?: string | undefined;
212
212
  modelId?: string | undefined;
213
+ stepId?: string | undefined;
213
214
  route?: {
214
215
  modelId: string;
215
216
  capabilityId: string;
@@ -222,7 +223,6 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
222
223
  baseURL?: string | undefined;
223
224
  endpointModelId?: string | undefined;
224
225
  } | undefined;
225
- stepId?: string | undefined;
226
226
  createdAt?: number | undefined;
227
227
  }, {
228
228
  id: string;
@@ -244,6 +244,7 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
244
244
  conversationId?: string | undefined;
245
245
  turnId?: string | undefined;
246
246
  modelId?: string | undefined;
247
+ stepId?: string | undefined;
247
248
  route?: {
248
249
  modelId: string;
249
250
  capabilityId: string;
@@ -256,7 +257,6 @@ declare const LlmUsageTokenLedgerEntry: z.ZodObject<{
256
257
  baseURL?: string | undefined;
257
258
  endpointModelId?: string | undefined;
258
259
  } | undefined;
259
- stepId?: string | undefined;
260
260
  createdAt?: number | undefined;
261
261
  }>;
262
262
  type LlmUsageTokenLedgerEntry = z.infer<typeof LlmUsageTokenLedgerEntry>;
@@ -413,6 +413,7 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
413
413
  parentRunId?: string | undefined;
414
414
  conversationId?: string | undefined;
415
415
  turnId?: string | undefined;
416
+ stepId?: string | undefined;
416
417
  route?: {
417
418
  modelId: string;
418
419
  capabilityId: string;
@@ -425,7 +426,6 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
425
426
  baseURL?: string | undefined;
426
427
  endpointModelId?: string | undefined;
427
428
  } | undefined;
428
- stepId?: string | undefined;
429
429
  createdAt?: number | undefined;
430
430
  }, {
431
431
  id: string;
@@ -458,6 +458,7 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
458
458
  parentRunId?: string | undefined;
459
459
  conversationId?: string | undefined;
460
460
  turnId?: string | undefined;
461
+ stepId?: string | undefined;
461
462
  route?: {
462
463
  modelId: string;
463
464
  capabilityId: string;
@@ -470,7 +471,6 @@ declare const ContextComponentTokenLedgerEntry: z.ZodObject<{
470
471
  baseURL?: string | undefined;
471
472
  endpointModelId?: string | undefined;
472
473
  } | undefined;
473
- stepId?: string | undefined;
474
474
  createdAt?: number | undefined;
475
475
  }>;
476
476
  type ContextComponentTokenLedgerEntry = z.infer<typeof ContextComponentTokenLedgerEntry>;
@@ -583,6 +583,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
583
583
  conversationId?: string | undefined;
584
584
  turnId?: string | undefined;
585
585
  modelId?: string | undefined;
586
+ stepId?: string | undefined;
586
587
  route?: {
587
588
  modelId: string;
588
589
  capabilityId: string;
@@ -595,7 +596,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
595
596
  baseURL?: string | undefined;
596
597
  endpointModelId?: string | undefined;
597
598
  } | undefined;
598
- stepId?: string | undefined;
599
599
  createdAt?: number | undefined;
600
600
  }, {
601
601
  id: string;
@@ -617,6 +617,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
617
617
  conversationId?: string | undefined;
618
618
  turnId?: string | undefined;
619
619
  modelId?: string | undefined;
620
+ stepId?: string | undefined;
620
621
  route?: {
621
622
  modelId: string;
622
623
  capabilityId: string;
@@ -629,7 +630,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
629
630
  baseURL?: string | undefined;
630
631
  endpointModelId?: string | undefined;
631
632
  } | undefined;
632
- stepId?: string | undefined;
633
633
  createdAt?: number | undefined;
634
634
  }>, z.ZodObject<{
635
635
  id: z.ZodString;
@@ -784,6 +784,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
784
784
  parentRunId?: string | undefined;
785
785
  conversationId?: string | undefined;
786
786
  turnId?: string | undefined;
787
+ stepId?: string | undefined;
787
788
  route?: {
788
789
  modelId: string;
789
790
  capabilityId: string;
@@ -796,7 +797,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
796
797
  baseURL?: string | undefined;
797
798
  endpointModelId?: string | undefined;
798
799
  } | undefined;
799
- stepId?: string | undefined;
800
800
  createdAt?: number | undefined;
801
801
  }, {
802
802
  id: string;
@@ -829,6 +829,7 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
829
829
  parentRunId?: string | undefined;
830
830
  conversationId?: string | undefined;
831
831
  turnId?: string | undefined;
832
+ stepId?: string | undefined;
832
833
  route?: {
833
834
  modelId: string;
834
835
  capabilityId: string;
@@ -841,7 +842,6 @@ declare const TokenLedgerEntry: z.ZodDiscriminatedUnion<"kind", [z.ZodObject<{
841
842
  baseURL?: string | undefined;
842
843
  endpointModelId?: string | undefined;
843
844
  } | undefined;
844
- stepId?: string | undefined;
845
845
  createdAt?: number | undefined;
846
846
  }>]>;
847
847
  type TokenLedgerEntry = z.infer<typeof TokenLedgerEntry>;
package/dist/index.cjs CHANGED
@@ -3901,6 +3901,26 @@ function resolveAssistantReplayParts(response) {
3901
3901
  return response.assistant_replay_parts;
3902
3902
  }
3903
3903
 
3904
+ // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
3905
+ var RunRecoveryBlockedError = class extends Error {
3906
+ code = "RUN_RECOVERY_BLOCKED";
3907
+ constructor(message) {
3908
+ super(message);
3909
+ this.name = "RunRecoveryBlockedError";
3910
+ }
3911
+ };
3912
+ var RunPauseRequested = class extends Error {
3913
+ code = "RUN_PAUSE_REQUESTED";
3914
+ constructor(message = "Run paused by user") {
3915
+ super(message);
3916
+ this.name = "RunPauseRequested";
3917
+ }
3918
+ };
3919
+ function isRunPauseSignal(signal) {
3920
+ const reason = signal?.reason;
3921
+ return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
3922
+ }
3923
+
3904
3924
  // src/runtime-kernel/graph-engine/engine.ts
3905
3925
  var logger2 = new Logger("GraphExecutor");
3906
3926
  function isRecord4(value) {
@@ -4210,6 +4230,7 @@ var GraphExecutor = class {
4210
4230
  reportStepsUsed(stepCount);
4211
4231
  const signalRaw = state.local?.signal;
4212
4232
  if (isAbortSignal2(signalRaw) && signalRaw.aborted) {
4233
+ if (!isRunPauseSignal(signalRaw)) await this.nodes.get(state.nodeId)?.cancel?.(state);
4213
4234
  logger2.warn("[GraphExecutor] \u6536\u5230 AbortSignal\uFF0C\u7ACB\u5373\u505C\u6B62\u63A8\u7406\u5FAA\u73AF");
4214
4235
  this.ephemeralLocals.delete(checkpointKey);
4215
4236
  throwAbortError();
@@ -4260,6 +4281,12 @@ var GraphExecutor = class {
4260
4281
  allEvents.push(...stepResolution.events);
4261
4282
  }
4262
4283
  state = stepResolution.state;
4284
+ const completedSignal = state.local?.signal;
4285
+ if (isAbortSignal2(completedSignal) && completedSignal.aborted && !isRunPauseSignal(completedSignal)) {
4286
+ await this.nodes.get(state.nodeId)?.cancel?.(state);
4287
+ this.ephemeralLocals.delete(checkpointKey);
4288
+ throwAbortError();
4289
+ }
4263
4290
  if (stepResolution.action.kind === "route") {
4264
4291
  logger2.info("[GraphExecutor] \u8DEF\u7531\u5207\u6362", {
4265
4292
  fromNodeId: stepResolution.action.fromNodeId,
@@ -9486,26 +9513,6 @@ function recordToolProtocolError(params) {
9486
9513
  recorder?.recordToolProtocolError?.(params);
9487
9514
  }
9488
9515
 
9489
- // src/runtime-kernel/graph-engine/definitions/runContinuation.ts
9490
- var RunRecoveryBlockedError = class extends Error {
9491
- code = "RUN_RECOVERY_BLOCKED";
9492
- constructor(message) {
9493
- super(message);
9494
- this.name = "RunRecoveryBlockedError";
9495
- }
9496
- };
9497
- var RunPauseRequested = class extends Error {
9498
- code = "RUN_PAUSE_REQUESTED";
9499
- constructor(message = "Run paused by user") {
9500
- super(message);
9501
- this.name = "RunPauseRequested";
9502
- }
9503
- };
9504
- function isRunPauseSignal(signal) {
9505
- const reason = signal?.reason;
9506
- return signal?.aborted === true && typeof reason === "object" && reason !== null && "code" in reason && reason.code === "RUN_PAUSE_REQUESTED";
9507
- }
9508
-
9509
9516
  // src/runtime-kernel/graph-engine/nodes/toolNode.recovery.ts
9510
9517
  async function executeRecoverableTool(input) {
9511
9518
  const local = input.state.local;
@@ -9707,7 +9714,30 @@ var ToolNode = class {
9707
9714
  async run(state) {
9708
9715
  const events = [];
9709
9716
  while (true) {
9710
- const result = await this.runNextPendingToolCall(state);
9717
+ let result;
9718
+ try {
9719
+ result = await this.runNextPendingToolCall(state);
9720
+ } catch (error) {
9721
+ if (isToolExecutionAbort(error) && !isRunPauseSignal(state.local?.signal)) {
9722
+ await this.cancel(state);
9723
+ }
9724
+ throw error;
9725
+ }
9726
+ const signal = state.local?.signal;
9727
+ if (isAbortSignal(signal) && signal.aborted && !isRunPauseSignal(signal)) {
9728
+ await this.cancel(state);
9729
+ const error = new Error("The user aborted a request.");
9730
+ error.name = "AbortError";
9731
+ throw error;
9732
+ }
9733
+ if (result.kind === "interrupted") {
9734
+ await commitToolBoundary(state, {
9735
+ kind: "route",
9736
+ nextNodeId: "llm",
9737
+ events: result.events
9738
+ });
9739
+ throw result.error;
9740
+ }
9711
9741
  await commitToolBoundary(state, result);
9712
9742
  if (Array.isArray(result.events) && result.events.length > 0) {
9713
9743
  events.push(...result.events);
@@ -9721,6 +9751,14 @@ var ToolNode = class {
9721
9751
  };
9722
9752
  }
9723
9753
  }
9754
+ async cancel(state) {
9755
+ settlePendingToolCallsAfterAbort({
9756
+ state,
9757
+ calls: parsePendingToolCalls(state.local?.pendingToolCalls ?? []),
9758
+ toolCatalog: this.toolRuntime
9759
+ });
9760
+ await commitToolBoundary(state, { kind: "yield"});
9761
+ }
9724
9762
  async runNextPendingToolCall(state) {
9725
9763
  const calls = parsePendingToolCalls(state.local?.pendingToolCalls ?? []);
9726
9764
  const signalRaw = state.local?.signal;
@@ -10140,7 +10178,11 @@ var ToolNode = class {
10140
10178
  nextProtocolErrorCount: fuse.nextCount
10141
10179
  });
10142
10180
  if (fuse.shouldFuse && remainingCalls.length === 0) {
10143
- throw createToolProtocolFuseError(fuse.nextCount, context.exec.error);
10181
+ return {
10182
+ kind: "interrupted",
10183
+ error: createToolProtocolFuseError(fuse.nextCount, context.exec.error),
10184
+ events: context.bridge.getRuntimeEvents()
10185
+ };
10144
10186
  }
10145
10187
  if (remainingCalls.length === 0 && context.local.toolBatchCompletionMode === "yield_after_batch") {
10146
10188
  return { kind: "yield", events: context.bridge.getRuntimeEvents() };