stitchkit 0.62.0 → 0.64.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.
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKL,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAC;AAEnB,eAAO,MAAM,wBAAwB;;;iBAGnC,CAAC;AACH,eAAO,MAAM,wBAAwB;;iBAAgD,CAAC;AACtF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAGlC,CAAC;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBASpC,CAAC;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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G,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAEhF,MAAM,WAAW,iBAAiB;IAChC,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7D,uBAAuB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC3F,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACtE,sBAAsB,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACzF,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACnF,eAAe,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC3E,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACtE,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC/E,qBAAqB,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvF;;;;;;;OAOG;IACH,eAAe,CAAC,KAAK,EAAE;QACrB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,OAAO,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;CAC5D"}
@@ -1,4 +1,4 @@
1
- import { type AgentMessage, type AgentRun, type AgentSnapshot, type AgentTerminalReason } from './schemas';
1
+ import { type AgentMessage, type AgentRun, type AgentSnapshot, type AgentTerminalReason, type AgentUsage } from './schemas';
2
2
  import type { AgentRuntimeStore, AgentStoreMutationResult } from './store';
3
3
  export declare class AgentRuntimeConflictError extends Error {
4
4
  constructor(operation: string);
@@ -72,12 +72,40 @@ export declare function appliedSnapshot(result: AgentStoreMutationResult, operat
72
72
  conversationId: string;
73
73
  inputMessageIds: string[];
74
74
  assistantMessageId: string;
75
- state: "abandoned" | "cancelled" | "completed" | "failed" | "interrupt_requested" | "interrupted" | "queued" | "running" | "superseded";
75
+ state: "abandoned" | "absorbed" | "cancelled" | "completed" | "failed" | "interrupt_requested" | "interrupted" | "queued" | "running" | "superseded";
76
76
  revision: number;
77
77
  ownerId?: string | undefined;
78
78
  fencingToken?: number | undefined;
79
- terminalReason?: "abandoned" | "cancelled" | "interrupted" | "policy_stop" | "provider_failure" | "shutdown" | "success" | "superseded" | "timeout" | "tool_failure" | undefined;
79
+ terminalReason?: "abandoned" | "cancelled" | "interrupted" | "policy_stop" | "provider_failure" | "provider_stop" | "shutdown" | "success" | "superseded" | "timeout" | "tool_failure" | undefined;
80
80
  terminalPolicyName?: string | undefined;
81
+ absorbedIntoRunId?: string | undefined;
82
+ usage?: {
83
+ inputTokens: {
84
+ value?: number | undefined;
85
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
86
+ };
87
+ outputTokens: {
88
+ value?: number | undefined;
89
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
90
+ };
91
+ reasoningTokens?: {
92
+ value?: number | undefined;
93
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
94
+ } | undefined;
95
+ cacheReadTokens?: {
96
+ value?: number | undefined;
97
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
98
+ } | undefined;
99
+ cacheWriteTokens?: {
100
+ value?: number | undefined;
101
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
102
+ } | undefined;
103
+ cost?: {
104
+ value?: number | undefined;
105
+ currency?: string | undefined;
106
+ provenance: "computed" | "estimated" | "provider-reported" | "unavailable";
107
+ } | undefined;
108
+ } | undefined;
81
109
  createdAt: string;
82
110
  updatedAt: string;
83
111
  }[];
@@ -87,6 +115,8 @@ interface TerminalCommitCandidate {
87
115
  assistant: AgentMessage;
88
116
  reason: AgentTerminalReason;
89
117
  policyName?: string;
118
+ /** What this run cost, persisted with the terminal record. */
119
+ usage?: AgentUsage;
90
120
  }
91
121
  export interface AgentTerminalCommitResolution extends TerminalCommitCandidate {
92
122
  snapshot: AgentSnapshot;
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-commit.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAG3E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,SAAS,EAAE,MAAM,EAG5B;CACF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlF;AAED,UAAU,uBAAuB;IAC/B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAmFD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,iBAAiB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,uBAAuB,CAAC;IACnC,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA4CzC"}
1
+ {"version":3,"file":"terminal-commit.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-commit.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAG3E,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,SAAS,EAAE,MAAM,EAG5B;CACF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGlF;AAED,UAAU,uBAAuB;IAC/B,GAAG,EAAE,QAAQ,CAAC;IACd,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED,MAAM,WAAW,6BAA8B,SAAQ,uBAAuB;IAC5E,QAAQ,EAAE,aAAa,CAAC;IACxB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAoFD,wBAAsB,sBAAsB,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,iBAAiB,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,uBAAuB,CAAC;IACnC,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB,GAAG,OAAO,CAAC,6BAA6B,CAAC,CA6CzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"terminal-status.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACnE;;;;;;;;;GASG;AACH;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,OAAO,CAOlF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAWnF"}
1
+ {"version":3,"file":"terminal-status.d.ts","sourceRoot":"","sources":["../../src/agent-runtime/terminal-status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACnE;;;;;;;;;GASG;AACH;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,CAAC,QAAQ,CAAC,GAAG,OAAO,CAOlF;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAanF"}
@@ -4,13 +4,13 @@ export { AgentAdmissionEventSchema, AgentCheckpointEventSchema, AgentReasoningDe
4
4
  export { type AgentHistoryProjectionDecision, type AgentHistoryProjectionOptions, type AgentHistoryProjectionResult, projectAgentHistory, projectAgentHistoryDetailed, } from './agent-runtime/history';
5
5
  export { type AgentToolFenceConfig, type AgentToolFenceContext, createAgentToolFenceLifecycle, } from './agent-runtime/managed-tools';
6
6
  export { type AgentLanguageModelProvider, type AgentModelCapability, AgentModelCapabilitySchema, type AgentModelDescriptor, AgentModelDescriptorSchema, type AgentModelRegistry, type AgentModelRegistryConfig, type AgentModelRegistrySnapshot, AgentModelRegistrySnapshotSchema, type AgentModelSnapshotPolicy, type AgentResolvedModel, defineModelRegistry, validateAgentModelSnapshot, } from './agent-runtime/models';
7
- export { type AgentObservability, type AgentRunEvent, AgentRunEventSchema, type AgentRunSinkConfig, type AgentRunSinkDrop, type AgentRunSinkError, createAgentObservability, } from './agent-runtime/observability';
7
+ export { type AgentObservability, type AgentRunEvent, AgentRunEventSchema, type AgentRunSinkConfig, type AgentRunSinkDrop, type AgentRunSinkError, type AgentRunStartedEvent, AgentRunStartedEventSchema, type AgentRunTerminalEvent, AgentRunTerminalEventSchema, type AgentStepFinishedEvent, AgentStepFinishedEventSchema, createAgentObservability, } from './agent-runtime/observability';
8
8
  export { type AgentHistoryBudgetDecision, type AgentHistoryBudgetResult, type AgentPromptBudget, type AgentPromptSection, type AgentPromptSectionContext, type AgentTokenCount, AgentTokenCountSchema, type ComposeAgentPromptOptions, type ComposedAgentPrompt, composeAgentPrompt, type SelectAgentHistoryOptions, selectAgentHistory, } from './agent-runtime/prompt';
9
9
  export { type AgentProtocol, type AgentProtocolConfig, defineAgentProtocol, } from './agent-runtime/protocol';
10
10
  export { type AgentRuntime, type AgentRuntimeAdmission, type AgentRuntimeConfig, type AgentRuntimeInput, type AgentRuntimeInterruptInput, type AgentRuntimePrepareStep, type AgentRuntimeProtocolInput, type AgentRuntimeRecordIds, type AgentRuntimeRecoverOptions, type AgentRuntimeRecoveryDecision, type AgentRuntimeRecoveryInput, type AgentRuntimeRecoveryOutcome, type AgentRuntimeRunContext, type AgentRuntimeStopPolicy, createAgentRuntime, } from './agent-runtime/runtime';
11
11
  export type { AgentRuntimeResult } from './agent-runtime/runtime-result';
12
12
  export * from './agent-runtime/schemas';
13
- export { type AcceptInputAndAssignRun, AcceptInputAndAssignRunSchema, type AcquireAgentRun, AcquireAgentRunSchema, type AgentRuntimeStore, AgentStoreAppliedSchema, AgentStoreConflictSchema, AgentStoreDuplicateSchema, type AgentStoreMutationResult, AgentStoreMutationResultSchema, AgentStoreNotFoundSchema, type CheckpointRunAssistant, CheckpointRunAssistantSchema, type CommitRunTerminal, CommitRunTerminalSchema, type RecoverAgentRun, RecoverAgentRunSchema, type ReplaceCompactedRange, ReplaceCompactedRangeSchema, type RequestRunInterrupt, RequestRunInterruptSchema, } from './agent-runtime/store';
13
+ export { type AbsorbQueuedRun, AbsorbQueuedRunSchema, type AcceptInputAndAssignRun, AcceptInputAndAssignRunSchema, type AcquireAgentRun, AcquireAgentRunSchema, type AgentRuntimeStore, AgentStoreAppliedSchema, AgentStoreConflictSchema, AgentStoreDuplicateSchema, type AgentStoreMutationResult, AgentStoreMutationResultSchema, AgentStoreNotFoundSchema, type CheckpointRunAssistant, CheckpointRunAssistantSchema, type CommitRunTerminal, CommitRunTerminalSchema, type RecoverAgentRun, RecoverAgentRunSchema, type ReplaceCompactedRange, ReplaceCompactedRangeSchema, type RequestRunInterrupt, RequestRunInterruptSchema, } from './agent-runtime/store';
14
14
  export { type AgentAdmissionReceipt, AgentAdmissionReceiptSchema, type AgentHistoryMutation, AgentHistoryMutationSchema, type AgentRecoverableDescriptor, AgentRecoverableDescriptorSchema, type AgentRecoverablePage, AgentRecoverablePageSchema, type AgentRuntimeHead, AgentRuntimeHeadSchema, type AgentRuntimeStoreDriver, type AgentStoreCompareAndSwapResult, type AgentStoredRun, AgentStoredRunSchema, createAgentRuntimeStore, createMemoryAgentRuntimeStore, } from './agent-runtime/store-driver';
15
15
  export { AgentRuntimeConflictError } from './agent-runtime/terminal-commit';
16
16
  //# sourceMappingURL=agent-runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"agent-runtime.d.ts","sourceRoot":"","sources":["../src/agent-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,oBAAoB,GACrB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,6BAA6B,GAC9B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,8BAA8B,EAC9B,4BAA4B,EAC5B,8BAA8B,EAC9B,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,K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EACtB,uBAAuB,EACvB,wBAAwB,EACxB,yBAAyB,EACzB,KAAK,wBAAwB,EAC7B,8BAA8B,EAC9B,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,4BAA4B,EAC5B,KAAK,iBAAiB,EACtB,uBAAuB,EACvB,KAAK,eAAe,EACpB,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,mBAAmB,EACxB,yBAAyB,GAC1B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,qBAAqB,EAC1B,2BAA2B,EAC3B,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,0BAA0B,EAC/B,gCAAgC,EAChC,KAAK,oBAAoB,EACzB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACnC,KAAK,cAAc,EACnB,oBAAoB,EACpB,uBAAuB,EACvB,6BAA6B,GAC9B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -29,7 +29,7 @@ import {
29
29
  AgentToolResultPartSchema,
30
30
  AgentUsageSchema,
31
31
  AgentUsageValueSchema
32
- } from "./index-58vkx74h.js";
32
+ } from "./index-b1k33127.js";
33
33
  import"./index-6djpbnda.js";
34
34
  import"./index-cby4ar3v.js";
35
35
  import {
@@ -50,8 +50,9 @@ function isSpeakableAssistantStatus(status) {
50
50
  return status === "completed" || status === "interrupted" || status === "committed";
51
51
  }
52
52
  function assistantStatus(reason) {
53
- if (reason === "success" || reason === "policy_stop")
53
+ if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
54
54
  return "completed";
55
+ }
55
56
  if (reason === "superseded")
56
57
  return "superseded";
57
58
  if (reason === "interrupted" || reason === "cancelled" || reason === "shutdown") {
@@ -757,26 +758,41 @@ function validateAgentModelSnapshot(input, policy) {
757
758
  }
758
759
  // src/agent-runtime/observability.ts
759
760
  import { z as z3 } from "zod";
760
- var AgentRunEventSchema = z3.object({
761
+ var AgentRunEventBaseSchema = z3.object({
761
762
  schemaVersion: z3.literal(1),
762
763
  eventId: AgentRecordIdSchema,
763
- type: z3.enum(["run-started", "step-finished", "run-terminal"]),
764
764
  conversationId: AgentRecordIdSchema,
765
765
  runId: AgentRecordIdSchema,
766
766
  traceId: z3.string().min(1),
767
767
  spanId: z3.string().min(1),
768
768
  parentSpanId: z3.string().min(1).optional(),
769
769
  state: AgentRunStateSchema,
770
- terminalReason: AgentTerminalReasonSchema.optional(),
771
770
  modelId: z3.string().min(1).optional(),
772
- step: z3.int().nonnegative().optional(),
773
- queueWaitMs: z3.number().nonnegative().optional(),
774
771
  durationMs: z3.number().nonnegative().optional(),
772
+ emittedAt: AgentTimestampSchema
773
+ });
774
+ var AgentRunStartedEventSchema = AgentRunEventBaseSchema.extend({
775
+ type: z3.literal("run-started"),
776
+ queueWaitMs: z3.number().nonnegative().optional()
777
+ });
778
+ var AgentStepFinishedEventSchema = AgentRunEventBaseSchema.extend({
779
+ type: z3.literal("step-finished"),
780
+ step: z3.int().nonnegative(),
781
+ ttftMs: z3.number().nonnegative().optional(),
782
+ usage: AgentUsageSchema
783
+ });
784
+ var AgentRunTerminalEventSchema = AgentRunEventBaseSchema.extend({
785
+ type: z3.literal("run-terminal"),
786
+ terminalReason: AgentTerminalReasonSchema,
775
787
  ttftMs: z3.number().nonnegative().optional(),
776
- usage: AgentUsageSchema.optional(),
777
788
  internalCause: z3.unknown().optional(),
778
- emittedAt: AgentTimestampSchema
789
+ usage: AgentUsageSchema
779
790
  });
791
+ var AgentRunEventSchema = z3.discriminatedUnion("type", [
792
+ AgentRunStartedEventSchema,
793
+ AgentStepFinishedEventSchema,
794
+ AgentRunTerminalEventSchema
795
+ ]);
780
796
  function createAgentObservability(config) {
781
797
  const manager = createBoundedSinkManager({
782
798
  write: config.write,
@@ -807,7 +823,13 @@ function createAgentObservability(config) {
807
823
  if ((config.deduplicate ?? true) && emitted.has(parsed.eventId))
808
824
  return;
809
825
  remember(parsed.eventId);
810
- manager.submit(() => config.includeInternalCause ? parsed : AgentRunEventSchema.omit({ internalCause: true }).parse(parsed));
826
+ manager.submit(() => {
827
+ if (config.includeInternalCause)
828
+ return parsed;
829
+ if (parsed.type !== "run-terminal")
830
+ return parsed;
831
+ return AgentRunTerminalEventSchema.omit({ internalCause: true }).parse(parsed);
832
+ });
811
833
  },
812
834
  flush: () => manager.flush(),
813
835
  getStatus: () => manager.getStatus(),
@@ -1058,7 +1080,10 @@ function createRuntimeAdmissionLanes() {
1058
1080
  }
1059
1081
 
1060
1082
  // src/agent-runtime/run-execution.ts
1061
- import { stepCountIs, streamText } from "ai";
1083
+ import {
1084
+ stepCountIs,
1085
+ streamText
1086
+ } from "ai";
1062
1087
 
1063
1088
  // src/agent-runtime/runtime-internals.ts
1064
1089
  import { z as z5 } from "zod";
@@ -1089,7 +1114,8 @@ function canonicalTerminal(snapshot, runId, retainedAssistant) {
1089
1114
  assistant,
1090
1115
  reason: run.terminalReason,
1091
1116
  committedByCaller: false,
1092
- ...run.terminalPolicyName && { policyName: run.terminalPolicyName }
1117
+ ...run.terminalPolicyName && { policyName: run.terminalPolicyName },
1118
+ ...run.usage && { usage: run.usage }
1093
1119
  };
1094
1120
  }
1095
1121
  function interruptedCandidate(candidate, run, now) {
@@ -1126,7 +1152,8 @@ async function commitAgentRunTerminal(input) {
1126
1152
  },
1127
1153
  assistant: candidate.assistant,
1128
1154
  reason: candidate.reason,
1129
- ...candidate.policyName && { policyName: candidate.policyName }
1155
+ ...candidate.policyName && { policyName: candidate.policyName },
1156
+ ...candidate.usage && { usage: candidate.usage }
1130
1157
  });
1131
1158
  if (committed.outcome === "applied") {
1132
1159
  const terminal2 = canonicalTerminal(committed.snapshot, candidate.run.id);
@@ -1365,7 +1392,8 @@ function createRunExecutor(dependencies) {
1365
1392
  let eventCount = 0;
1366
1393
  let sequence = 0;
1367
1394
  let terminalReason = "success";
1368
- let usage;
1395
+ let usage = input.acceptedRun.usage;
1396
+ let sawProviderFinish = false;
1369
1397
  let step = 0;
1370
1398
  let selectedModel;
1371
1399
  let internalCause;
@@ -1407,13 +1435,14 @@ function createRunExecutor(dependencies) {
1407
1435
  expectedRevision: run.revision,
1408
1436
  ownerId: runtimeEpoch,
1409
1437
  ...run.fencingToken !== undefined && { fencingToken: run.fencingToken },
1410
- assistant
1438
+ assistant,
1439
+ usage: statedUsage(usage)
1411
1440
  }), "assistant checkpoint");
1412
1441
  run = findRun(snapshot.runs, run.id);
1413
1442
  const checkpointMetrics = {
1414
1443
  partial: true,
1415
1444
  durationMs: performance.now() - runStartedAt,
1416
- ...usage && { usage },
1445
+ usage: statedUsage(usage),
1417
1446
  ...firstOutputAt !== undefined && { ttftMs: firstOutputAt - runStartedAt }
1418
1447
  };
1419
1448
  await publish({
@@ -1436,6 +1465,8 @@ function createRunExecutor(dependencies) {
1436
1465
  });
1437
1466
  snapshot = compacted.snapshot;
1438
1467
  run = findRun(snapshot.runs, run.id);
1468
+ if (compacted.usage)
1469
+ usage = addUsage(usage, compacted.usage);
1439
1470
  }
1440
1471
  const assertCurrent = async () => {
1441
1472
  if (executionSignal.aborted)
@@ -1484,7 +1515,7 @@ function createRunExecutor(dependencies) {
1484
1515
  if (prompt.contextDecision === "requires-compaction") {
1485
1516
  throw new Error("Agent context still exceeds the model budget after compaction");
1486
1517
  }
1487
- const history = await (config.history?.project ? config.history.project(snapshot.messages) : projectAgentHistory(snapshot.messages, {
1518
+ const projectHistory = (source) => config.history?.project ? config.history.project(source.messages) : projectAgentHistory(source.messages, {
1488
1519
  ...config.history?.resolveFile && { resolveFile: config.history.resolveFile },
1489
1520
  ...config.history?.unresolvedFile && {
1490
1521
  unresolvedFile: config.history.unresolvedFile
@@ -1492,7 +1523,44 @@ function createRunExecutor(dependencies) {
1492
1523
  ...config.history?.interruptedAssistant && {
1493
1524
  interruptedAssistant: config.history.interruptedAssistant
1494
1525
  }
1495
- }));
1526
+ });
1527
+ const history = await projectHistory(snapshot);
1528
+ const absorbPending = async () => {
1529
+ if (!input.absorbable?.size || executionSignal.aborted)
1530
+ return;
1531
+ const latest = await config.store.loadSnapshot(run.conversationId);
1532
+ const current = latest.runs.find((candidate) => candidate.id === run.id);
1533
+ if (current?.state !== "running" || current.ownerId !== runtimeEpoch) {
1534
+ return;
1535
+ }
1536
+ const pending = latest.runs.find((candidate) => candidate.state === "queued" && input.absorbable?.has(candidate.id));
1537
+ if (!pending)
1538
+ return;
1539
+ const absorbed = await config.store.absorbQueuedRun({
1540
+ conversationId: run.conversationId,
1541
+ runningRunId: current.id,
1542
+ runningExpectedRevision: current.revision,
1543
+ ownerId: runtimeEpoch,
1544
+ ...current.fencingToken !== undefined && { fencingToken: current.fencingToken },
1545
+ queuedRunId: pending.id,
1546
+ queuedExpectedRevision: pending.revision
1547
+ });
1548
+ if (absorbed.outcome !== "applied")
1549
+ return;
1550
+ input.onAbsorbed?.(pending.id);
1551
+ snapshot = absorbed.snapshot;
1552
+ run = findRun(snapshot.runs, run.id);
1553
+ await publish({
1554
+ type: "run-state",
1555
+ eventId: agentDurableEventId("run-state", run.id, snapshot.version),
1556
+ conversationId: run.conversationId,
1557
+ runId: run.id,
1558
+ snapshotVersion: snapshot.version,
1559
+ state: run.state,
1560
+ emittedAt: now().toISOString()
1561
+ });
1562
+ return [...await projectHistory(snapshot)];
1563
+ };
1496
1564
  const maxStepCondition = stepCountIs(maxSteps);
1497
1565
  const stopConditions = [
1498
1566
  async (options) => {
@@ -1518,8 +1586,10 @@ function createRunExecutor(dependencies) {
1518
1586
  abortSignal: executionSignal,
1519
1587
  maxRetries: 0,
1520
1588
  stopWhen: stopConditions,
1521
- ...config.loop?.prepareStep && {
1522
- prepareStep: (options) => config.loop?.prepareStep?.({ ...options, ...runtimeContext })
1589
+ prepareStep: async (options) => {
1590
+ const absorbed = await absorbPending();
1591
+ const prepared = await config.loop?.prepareStep?.({ ...options, ...runtimeContext }) ?? {};
1592
+ return absorbed && !prepared.messages ? { ...prepared, messages: absorbed } : prepared;
1523
1593
  }
1524
1594
  });
1525
1595
  for await (const part of result.stream) {
@@ -1752,9 +1822,13 @@ function createRunExecutor(dependencies) {
1752
1822
  });
1753
1823
  step += 1;
1754
1824
  } else if (part.type === "finish" && part.finishReason !== "stop") {
1755
- terminalReason = "policy_stop";
1825
+ if (terminalReason === "success") {
1826
+ terminalReason = part.finishReason === "error" ? "provider_failure" : "provider_stop";
1827
+ internalCause ??= { finishReason: part.finishReason };
1828
+ }
1756
1829
  }
1757
1830
  if (part.type === "finish") {
1831
+ sawProviderFinish = true;
1758
1832
  usage = mergeRunTotals(normalizeSdkUsage(part.totalUsage), usage);
1759
1833
  }
1760
1834
  if (eventCount % checkpointEveryEvents === 0)
@@ -1822,7 +1896,8 @@ function createRunExecutor(dependencies) {
1822
1896
  run,
1823
1897
  assistant,
1824
1898
  reason: terminalReason,
1825
- ...terminalPolicyName && { policyName: terminalPolicyName }
1899
+ ...terminalPolicyName && { policyName: terminalPolicyName },
1900
+ usage: spent
1826
1901
  },
1827
1902
  now
1828
1903
  });
@@ -1840,7 +1915,7 @@ function createRunExecutor(dependencies) {
1840
1915
  terminalReason = terminal.reason;
1841
1916
  terminalPolicyName = terminal.policyName;
1842
1917
  const terminalMetrics = terminal.committedByCaller ? {
1843
- partial: false,
1918
+ partial: !sawProviderFinish,
1844
1919
  durationMs: performance.now() - runStartedAt,
1845
1920
  usage: spent,
1846
1921
  ...firstOutputAt !== undefined && { ttftMs: firstOutputAt - runStartedAt }
@@ -1898,6 +1973,9 @@ function createAgentRuntime(config) {
1898
1973
  if (idleTimeoutMs !== undefined && (!Number.isSafeInteger(idleTimeoutMs) || idleTimeoutMs < 1)) {
1899
1974
  throw new TypeError("idleTimeoutMs must be a positive safe integer");
1900
1975
  }
1976
+ const absorbable = new Set;
1977
+ const absorbedInto = new Map;
1978
+ const runResults = new Map;
1901
1979
  const policyNames = new Set(["max-steps"]);
1902
1980
  for (const policy of config.loop?.stopPolicies ?? []) {
1903
1981
  if (!policy.name || policyNames.has(policy.name)) {
@@ -2030,7 +2108,8 @@ function createAgentRuntime(config) {
2030
2108
  if (existingTicket)
2031
2109
  return existingTicket;
2032
2110
  const key = config.runs?.key?.(input) ?? input.conversationId;
2033
- const policy = typeof config.runs?.inputPolicy === "function" ? config.runs.inputPolicy(input) : config.runs?.inputPolicy ?? "queue";
2111
+ const declaredPolicy = typeof config.runs?.inputPolicy === "function" ? config.runs.inputPolicy(input) : config.runs?.inputPolicy ?? "queue";
2112
+ const policy = declaredPolicy === "inject" ? "queue" : declaredPolicy;
2034
2113
  const nowIso = now().toISOString();
2035
2114
  const inputMessageId = rawInput.recordIds?.inputMessageId ?? generateId();
2036
2115
  const runId = rawInput.recordIds?.runId ?? generateId();
@@ -2156,6 +2235,8 @@ function createAgentRuntime(config) {
2156
2235
  state: acceptedRun.state,
2157
2236
  emittedAt: now().toISOString()
2158
2237
  });
2238
+ if (declaredPolicy === "inject")
2239
+ absorbable.add(acceptedRun.id);
2159
2240
  outerAccepted.resolve();
2160
2241
  if (acceptance.outcome === "duplicate") {
2161
2242
  if (!acceptedRun.terminalReason) {
@@ -2204,7 +2285,25 @@ function createAgentRuntime(config) {
2204
2285
  await waitForAdmissionAcceptances(reservation.lane);
2205
2286
  return {
2206
2287
  runId: acceptedRun.id,
2207
- execute: () => executeRun({ acceptedRun, context, signal })
2288
+ execute: () => {
2289
+ const answeredBy = absorbedInto.get(acceptedRun.id);
2290
+ const answer = answeredBy ? runResults.get(answeredBy) : undefined;
2291
+ if (answer)
2292
+ return answer;
2293
+ const running = executeRun({
2294
+ acceptedRun,
2295
+ context,
2296
+ signal,
2297
+ absorbable,
2298
+ onAbsorbed: (absorbedRunId) => {
2299
+ absorbedInto.set(absorbedRunId, acceptedRun.id);
2300
+ }
2301
+ });
2302
+ runResults.set(acceptedRun.id, running);
2303
+ return running.finally(() => {
2304
+ absorbable.delete(acceptedRun.id);
2305
+ });
2306
+ }
2208
2307
  };
2209
2308
  }
2210
2309
  });
@@ -2437,7 +2536,8 @@ var CheckpointRunAssistantSchema = z6.object({
2437
2536
  expectedRevision: AgentRecordVersionSchema,
2438
2537
  ownerId: z6.string().min(1),
2439
2538
  fencingToken: AgentRecordVersionSchema.optional(),
2440
- assistant: AgentMessageSchema
2539
+ assistant: AgentMessageSchema,
2540
+ usage: AgentUsageSchema.optional()
2441
2541
  });
2442
2542
  var CommitRunTerminalSchema = z6.object({
2443
2543
  conversationId: AgentRecordIdSchema,
@@ -2447,7 +2547,17 @@ var CommitRunTerminalSchema = z6.object({
2447
2547
  fencingToken: AgentRecordVersionSchema.optional(),
2448
2548
  assistant: AgentMessageSchema,
2449
2549
  reason: AgentTerminalReasonSchema,
2450
- policyName: z6.string().min(1).optional()
2550
+ policyName: z6.string().min(1).optional(),
2551
+ usage: AgentUsageSchema.optional()
2552
+ });
2553
+ var AbsorbQueuedRunSchema = z6.object({
2554
+ conversationId: AgentRecordIdSchema,
2555
+ runningRunId: AgentRecordIdSchema,
2556
+ runningExpectedRevision: AgentRecordVersionSchema,
2557
+ ownerId: z6.string().min(1),
2558
+ fencingToken: AgentRecordVersionSchema.optional(),
2559
+ queuedRunId: AgentRecordIdSchema,
2560
+ queuedExpectedRevision: AgentRecordVersionSchema
2451
2561
  });
2452
2562
  var RequestRunInterruptSchema = z6.object({
2453
2563
  conversationId: AgentRecordIdSchema,
@@ -2593,8 +2703,9 @@ function conflict(actualVersion) {
2593
2703
  return { outcome: "conflict", actualVersion };
2594
2704
  }
2595
2705
  function terminalState(reason) {
2596
- if (reason === "success" || reason === "policy_stop")
2706
+ if (reason === "success" || reason === "policy_stop" || reason === "provider_stop") {
2597
2707
  return "completed";
2708
+ }
2598
2709
  if (reason === "interrupted")
2599
2710
  return "interrupted";
2600
2711
  if (reason === "superseded")
@@ -2616,6 +2727,7 @@ function applied(current, input, effects) {
2616
2727
  messages: input.messages ?? current.messages
2617
2728
  }),
2618
2729
  ...effects?.runRecord && { runRecord: effects.runRecord },
2730
+ ...effects?.secondaryRunRecord && { secondaryRunRecord: effects.secondaryRunRecord },
2619
2731
  ...effects?.admissionReceipt && { admissionReceipt: effects.admissionReceipt },
2620
2732
  ...effects?.historyMutation && { historyMutation: effects.historyMutation }
2621
2733
  };
@@ -2659,6 +2771,39 @@ function reduceStore(current, operation) {
2659
2771
  historyMutation: { type: "admit", input: input.input }
2660
2772
  });
2661
2773
  }
2774
+ if (operation.type === "absorb") {
2775
+ const input = operation.input;
2776
+ if (current.conversationId !== input.conversationId)
2777
+ return { outcome: "not_found" };
2778
+ const running = current.runs.find((candidate) => candidate.id === input.runningRunId);
2779
+ const queued = current.runs.find((candidate) => candidate.id === input.queuedRunId);
2780
+ if (!running || !queued)
2781
+ return { outcome: "not_found" };
2782
+ if (running.revision !== input.runningExpectedRevision || running.state !== "running" || running.ownerId !== input.ownerId || input.fencingToken !== undefined && running.fencingToken !== input.fencingToken) {
2783
+ return conflict(running.revision);
2784
+ }
2785
+ if (queued.revision !== input.queuedExpectedRevision || queued.state !== "queued" || queued.ownerId !== undefined || queued.terminalReason !== undefined || queued.id === running.id) {
2786
+ return conflict(queued.revision);
2787
+ }
2788
+ const stamp = new Date().toISOString();
2789
+ const grown = AgentRunSchema.parse({
2790
+ ...running,
2791
+ inputMessageIds: [...running.inputMessageIds, ...queued.inputMessageIds],
2792
+ revision: running.revision + 1,
2793
+ updatedAt: stamp
2794
+ });
2795
+ const emptied = AgentRunSchema.parse({
2796
+ ...queued,
2797
+ state: "absorbed",
2798
+ absorbedIntoRunId: running.id,
2799
+ revision: queued.revision + 1,
2800
+ updatedAt: stamp
2801
+ });
2802
+ return applied(current, { runs: replaceRun(replaceRun(current.runs, grown), emptied) }, {
2803
+ runRecord: AgentStoredRunSchema.parse({ schemaVersion: 1, run: grown }),
2804
+ secondaryRunRecord: AgentStoredRunSchema.parse({ schemaVersion: 1, run: emptied })
2805
+ });
2806
+ }
2662
2807
  const conversationId = operation.input.conversationId;
2663
2808
  const run = operation.type === "compact" ? undefined : current.runs.find((candidate) => candidate.id === operation.input.runId);
2664
2809
  if (operation.type !== "compact" && !run)
@@ -2688,6 +2833,7 @@ function reduceStore(current, operation) {
2688
2833
  }
2689
2834
  const next = AgentRunSchema.parse({
2690
2835
  ...run,
2836
+ ...input.usage && { usage: input.usage },
2691
2837
  revision: run.revision + 1,
2692
2838
  updatedAt: new Date().toISOString()
2693
2839
  });
@@ -2774,6 +2920,7 @@ function reduceStore(current, operation) {
2774
2920
  state: terminalState(input.reason),
2775
2921
  terminalReason: input.reason,
2776
2922
  ...input.policyName && { terminalPolicyName: input.policyName },
2923
+ ...input.usage && { usage: input.usage },
2777
2924
  revision: run.revision + 1,
2778
2925
  updatedAt: new Date().toISOString()
2779
2926
  });
@@ -2862,7 +3009,7 @@ function createAgentRuntimeStore(driver) {
2862
3009
  });
2863
3010
  const mutate = (operation) => driver.transaction(async (transaction) => {
2864
3011
  const conversationId = operationConversationId(operation);
2865
- const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" ? undefined : operation.input.runId;
3012
+ const operationRunId = operation.type === "accept" ? operation.input.coalesceIntoRunId : operation.type === "compact" ? undefined : operation.type === "absorb" ? operation.input.queuedRunId : operation.input.runId;
2866
3013
  const [stored, messages, activeRecords, operationRecord, duplicateReceipt] = await Promise.all([
2867
3014
  driver.head.load(transaction, conversationId),
2868
3015
  driver.history.load(transaction, conversationId),
@@ -2943,6 +3090,9 @@ function createAgentRuntimeStore(driver) {
2943
3090
  return conflict(outcome.actualVersion);
2944
3091
  if (reduced.runRecord)
2945
3092
  await driver.runs.save(transaction, reduced.runRecord);
3093
+ if (reduced.secondaryRunRecord) {
3094
+ await driver.runs.save(transaction, reduced.secondaryRunRecord);
3095
+ }
2946
3096
  if (reduced.admissionReceipt) {
2947
3097
  await driver.admissions.create(transaction, reduced.admissionReceipt);
2948
3098
  }
@@ -2966,6 +3116,7 @@ function createAgentRuntimeStore(driver) {
2966
3116
  type: "interrupt",
2967
3117
  input: RequestRunInterruptSchema.parse(input)
2968
3118
  }),
3119
+ absorbQueuedRun: (input) => mutate({ type: "absorb", input: AbsorbQueuedRunSchema.parse(input) }),
2969
3120
  recoverRun: (input) => mutate({ type: "recover", input: RecoverAgentRunSchema.parse(input) }),
2970
3121
  commitRunTerminal: (input) => mutate({ type: "terminal", input: CommitRunTerminalSchema.parse(input) }),
2971
3122
  replaceCompactedRange: (input) => mutate({
@@ -3138,6 +3289,7 @@ function createMemoryAgentRuntimeStore() {
3138
3289
  return createAgentRuntimeStore(driver);
3139
3290
  }
3140
3291
  export {
3292
+ AbsorbQueuedRunSchema,
3141
3293
  AcceptInputAndAssignRunSchema,
3142
3294
  AcquireAgentRunSchema,
3143
3295
  AgentAdmissionEventSchema,
@@ -3169,14 +3321,17 @@ export {
3169
3321
  AgentRunEventSchema,
3170
3322
  AgentRunMetricsSchema,
3171
3323
  AgentRunSchema,
3324
+ AgentRunStartedEventSchema,
3172
3325
  AgentRunStateEventSchema,
3173
3326
  AgentRunStateSchema,
3327
+ AgentRunTerminalEventSchema,
3174
3328
  AgentRuntimeConflictError,
3175
3329
  AgentRuntimeEventCursorSchema,
3176
3330
  AgentRuntimeEventSchema,
3177
3331
  AgentRuntimeHeadSchema,
3178
3332
  AgentSnapshotSchema,
3179
3333
  AgentSourcePartSchema,
3334
+ AgentStepFinishedEventSchema,
3180
3335
  AgentStoreAppliedSchema,
3181
3336
  AgentStoreConflictSchema,
3182
3337
  AgentStoreDuplicateSchema,