@cuylabs/agent-core 0.4.0 → 0.6.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 (66) hide show
  1. package/README.md +81 -323
  2. package/dist/builder-BKkipazh.d.ts +34 -0
  3. package/dist/capabilities/index.d.ts +97 -0
  4. package/dist/capabilities/index.js +46 -0
  5. package/dist/chunk-3C4VKG4P.js +2149 -0
  6. package/dist/chunk-6TDTQJ4P.js +116 -0
  7. package/dist/chunk-7MUFEN4K.js +559 -0
  8. package/dist/chunk-BDBZ3SLK.js +745 -0
  9. package/dist/chunk-DWYX7ASF.js +26 -0
  10. package/dist/chunk-FG4MD5MU.js +54 -0
  11. package/dist/chunk-IVUJDISU.js +556 -0
  12. package/dist/chunk-LRHOS4ZN.js +584 -0
  13. package/dist/chunk-O2ZCFQL6.js +764 -0
  14. package/dist/chunk-P6YF7USR.js +182 -0
  15. package/dist/chunk-QAQADS4X.js +258 -0
  16. package/dist/chunk-QWFMX226.js +879 -0
  17. package/dist/{chunk-6VKLWNRE.js → chunk-SDSBEQXG.js} +1 -132
  18. package/dist/chunk-VBWWUHWI.js +724 -0
  19. package/dist/chunk-VEKUXUVF.js +41 -0
  20. package/dist/chunk-X635CM2F.js +305 -0
  21. package/dist/chunk-YUUJK53A.js +91 -0
  22. package/dist/chunk-ZXAKHMWH.js +283 -0
  23. package/dist/config-D2xeGEHK.d.ts +52 -0
  24. package/dist/context/index.d.ts +259 -0
  25. package/dist/context/index.js +26 -0
  26. package/dist/identifiers-BLUxFqV_.d.ts +12 -0
  27. package/dist/index-DZQJD_hp.d.ts +1067 -0
  28. package/dist/index-ipP3_ztp.d.ts +198 -0
  29. package/dist/index.d.ts +210 -5736
  30. package/dist/index.js +2132 -7767
  31. package/dist/mcp/index.d.ts +26 -0
  32. package/dist/mcp/index.js +14 -0
  33. package/dist/messages-BYWGn8TY.d.ts +110 -0
  34. package/dist/middleware/index.d.ts +8 -0
  35. package/dist/middleware/index.js +12 -0
  36. package/dist/models/index.d.ts +33 -0
  37. package/dist/models/index.js +12 -0
  38. package/dist/network-D76DS5ot.d.ts +5 -0
  39. package/dist/prompt/index.d.ts +225 -0
  40. package/dist/prompt/index.js +45 -0
  41. package/dist/reasoning/index.d.ts +71 -0
  42. package/dist/reasoning/index.js +47 -0
  43. package/dist/registry-CuRWWtcT.d.ts +164 -0
  44. package/dist/resolver-DOfZ-xuk.d.ts +254 -0
  45. package/dist/runner-G1wxEgac.d.ts +852 -0
  46. package/dist/runtime/index.d.ts +357 -0
  47. package/dist/runtime/index.js +64 -0
  48. package/dist/session-manager-Uawm2Le7.d.ts +274 -0
  49. package/dist/skill/index.d.ts +103 -0
  50. package/dist/skill/index.js +39 -0
  51. package/dist/storage/index.d.ts +167 -0
  52. package/dist/storage/index.js +50 -0
  53. package/dist/sub-agent/index.d.ts +14 -0
  54. package/dist/sub-agent/index.js +15 -0
  55. package/dist/tool/index.d.ts +174 -1
  56. package/dist/tool/index.js +12 -3
  57. package/dist/tool-DYp6-cC3.d.ts +239 -0
  58. package/dist/tool-pFAnJc5Y.d.ts +419 -0
  59. package/dist/tracker-DClqYqTj.d.ts +96 -0
  60. package/dist/tracking/index.d.ts +109 -0
  61. package/dist/tracking/index.js +20 -0
  62. package/dist/types-BWo810L_.d.ts +648 -0
  63. package/dist/types-CQaXbRsS.d.ts +47 -0
  64. package/dist/types-VQgymC1N.d.ts +156 -0
  65. package/package.json +89 -5
  66. package/dist/index-BlSTfS-W.d.ts +0 -470
@@ -0,0 +1,357 @@
1
+ import { A as AgentEvent } from '../runner-G1wxEgac.js';
2
+ import { T as TokenUsage, M as Message } from '../messages-BYWGn8TY.js';
3
+ import { n as AgentTurnStepCommitSnapshot, t as CreateAgentTurnStepCommitBatchOptions, f as AgentTurnCommitBatch, J as PrepareModelStepOptions, K as PreparedAgentModelStep, S as RunModelStepOptions, a as ProcessorOutput, U as RunToolBatchOptions, V as RunToolBatchResult, C as CommitOutputOptions, r as CommitStepOptions, l as AgentTurnState, p as AgentTurnStepCommitToolResult, o as AgentTurnStepCommitToolCall } from '../types-BWo810L_.js';
4
+ export { b as AgentTurnActiveToolCall, c as AgentTurnBoundaryMetadata, d as AgentTurnBoundarySnapshot, e as AgentTurnCommitApplier, g as AgentTurnCommitOptions, h as AgentTurnEngine, i as AgentTurnEngineOptions, j as AgentTurnPhase, k as AgentTurnResolvedToolCall, m as AgentTurnStateAdvanceOptions, q as AgentTurnStepRuntimeConfig, s as CreateAgentTurnStateOptions, X as advanceAgentTurnState, Z as createAgentTurnEngine, _ as createAgentTurnState, a1 as failAgentTurnState } from '../types-BWo810L_.js';
5
+ import { ModelMessage } from 'ai';
6
+ import '../tool-pFAnJc5Y.js';
7
+ import 'zod';
8
+ import '../tool-DYp6-cC3.js';
9
+ import '../types-CQaXbRsS.js';
10
+
11
+ declare function createAgentTurnStepCommitBatch(step: number, snapshot: AgentTurnStepCommitSnapshot, options?: CreateAgentTurnStepCommitBatchOptions): AgentTurnCommitBatch | undefined;
12
+
13
+ /**
14
+ * Prepare the next model step from the current committed messages.
15
+ */
16
+ declare function prepareModelStep(options: PrepareModelStepOptions): PreparedAgentModelStep;
17
+
18
+ /**
19
+ * Execute exactly one model/tool step and stream its events.
20
+ */
21
+ declare function runModelStep(options: RunModelStepOptions): AsyncGenerator<AgentEvent, ProcessorOutput>;
22
+
23
+ /**
24
+ * Execute planned tool calls outside the AI SDK loop.
25
+ */
26
+ declare function runToolBatch(options: RunToolBatchOptions): Promise<RunToolBatchResult>;
27
+
28
+ /**
29
+ * Persist the assistant tool-call message and tool-result messages for a step.
30
+ */
31
+ declare function commitStep(options: CommitStepOptions): AsyncGenerator<AgentEvent, boolean>;
32
+ /**
33
+ * Persist the final assistant output for a turn.
34
+ */
35
+ declare function commitOutput(options: CommitOutputOptions): AsyncGenerator<AgentEvent, boolean>;
36
+
37
+ interface AgentTaskPayload {
38
+ /** Prompt/message passed to the agent. */
39
+ message: string;
40
+ /** Optional explicit session id. If omitted, a runtime session id is generated. */
41
+ sessionId?: string;
42
+ /** Optional per-run system override forwarded to agent.chat(). */
43
+ system?: string;
44
+ }
45
+ interface AgentTaskExecutionContext {
46
+ /** Abort signal propagated to agent.chat(). */
47
+ signal?: AbortSignal;
48
+ /** Optional trigger descriptor from caller (for logging/routing). */
49
+ trigger?: string;
50
+ /**
51
+ * Optional stable key used when auto-generating session ids.
52
+ * For scheduled jobs, a job ID is a good candidate.
53
+ */
54
+ fallbackSessionKey?: string;
55
+ }
56
+ interface AgentTaskResult {
57
+ response: string;
58
+ sessionId: string;
59
+ usage: TokenUsage;
60
+ toolCalls: Array<{
61
+ name: string;
62
+ result: unknown;
63
+ }>;
64
+ }
65
+ type AgentTaskRunner<TPayload extends AgentTaskPayload = AgentTaskPayload> = (payload: TPayload, context?: AgentTaskExecutionContext) => Promise<AgentTaskResult>;
66
+ /**
67
+ * Minimal chat surface required by `createAgentTaskRunner(...)`.
68
+ *
69
+ * The concrete `Agent` class already satisfies this contract. Keeping the
70
+ * requirement this small makes runtime integration easier to test and reuse.
71
+ */
72
+ interface AgentTaskChatAdapter {
73
+ chat(sessionId: string, message: string, options?: {
74
+ abort?: AbortSignal;
75
+ system?: string;
76
+ }): AsyncIterable<AgentEvent>;
77
+ }
78
+
79
+ type AgentTaskCheckpointReason = "task-start" | "input-commit-start" | "input-commit-finish" | "intervention-commit-start" | "intervention-commit-finish" | "step-finish" | "step-commit-start" | "step-commit-finish" | "tool-result" | "tool-error" | "output-commit-start" | "output-commit-finish" | "task-complete" | "task-error";
80
+ interface AgentTaskExecutionRun<TPayload extends AgentTaskPayload = AgentTaskPayload> {
81
+ payload: Readonly<TPayload>;
82
+ context: Readonly<AgentTaskExecutionContext>;
83
+ sessionId: string;
84
+ startedAt: string;
85
+ }
86
+ interface AgentTaskExecutionSnapshot {
87
+ sessionId: string;
88
+ response: string;
89
+ usage: TokenUsage;
90
+ toolCalls: Array<{
91
+ name: string;
92
+ result: unknown;
93
+ }>;
94
+ eventCount: number;
95
+ activeStep?: number;
96
+ lastEvent?: AgentEvent;
97
+ error?: string;
98
+ startedAt: string;
99
+ updatedAt: string;
100
+ turnState: AgentTurnState;
101
+ }
102
+ interface AgentTaskExecutionCheckpoint<TPayload extends AgentTaskPayload = AgentTaskPayload> {
103
+ run: AgentTaskExecutionRun<TPayload>;
104
+ reason: AgentTaskCheckpointReason;
105
+ snapshot: AgentTaskExecutionSnapshot;
106
+ event?: AgentEvent;
107
+ createdAt: string;
108
+ }
109
+ interface AgentTaskObserver<TPayload extends AgentTaskPayload = AgentTaskPayload> {
110
+ onTaskStart?(run: AgentTaskExecutionRun<TPayload>, snapshot: AgentTaskExecutionSnapshot): void | Promise<void>;
111
+ onTaskEvent?(run: AgentTaskExecutionRun<TPayload>, event: AgentEvent, snapshot: AgentTaskExecutionSnapshot): void | Promise<void>;
112
+ onCheckpoint?(checkpoint: AgentTaskExecutionCheckpoint<TPayload>): void | Promise<void>;
113
+ onTaskComplete?(run: AgentTaskExecutionRun<TPayload>, result: AgentTaskResult, snapshot: AgentTaskExecutionSnapshot): void | Promise<void>;
114
+ onTaskError?(run: AgentTaskExecutionRun<TPayload>, error: Error, snapshot: AgentTaskExecutionSnapshot): void | Promise<void>;
115
+ /**
116
+ * Get the active OTel context for a session.
117
+ *
118
+ * Used for trace context propagation between layers — e.g. the
119
+ * workflow bridge retrieves the observer's span context and injects
120
+ * it into activities so child spans (AI SDK, tool calls) are
121
+ * correlated under the observer's root span.
122
+ */
123
+ getOtelContext?(sessionId: string): unknown;
124
+ /**
125
+ * Activate the OTel context for a session around a function call.
126
+ *
127
+ * Used by the task runner to ensure child spans (from middleware,
128
+ * AI SDK) are parented under the observer's root span in direct
129
+ * execution mode. The observer wraps `fn` in `context.with()` so
130
+ * that `context.active()` returns the session's trace context.
131
+ */
132
+ activateContext?<T>(sessionId: string, fn: () => T): T;
133
+ }
134
+ interface AgentTaskCheckpointStrategyInput<TPayload extends AgentTaskPayload = AgentTaskPayload> {
135
+ run: AgentTaskExecutionRun<TPayload>;
136
+ event: AgentEvent;
137
+ snapshot: AgentTaskExecutionSnapshot;
138
+ }
139
+ type AgentTaskCheckpointStrategy<TPayload extends AgentTaskPayload = AgentTaskPayload> = (input: AgentTaskCheckpointStrategyInput<TPayload>) => AgentTaskCheckpointReason | undefined;
140
+ /**
141
+ * Default checkpoint strategy for runtime integrations.
142
+ *
143
+ * This intentionally checkpoints at coarse-grained boundaries that are useful
144
+ * for external runtimes and durable adapters without creating excessive churn:
145
+ * - step completion
146
+ * - tool results/errors
147
+ * - task completion
148
+ */
149
+ declare function defaultAgentTaskCheckpointStrategy<TPayload extends AgentTaskPayload = AgentTaskPayload>(input: AgentTaskCheckpointStrategyInput<TPayload>): AgentTaskCheckpointReason | undefined;
150
+
151
+ interface AgentTaskRunnerOptions<TPayload extends AgentTaskPayload = AgentTaskPayload> {
152
+ /** Prefix used for generated runtime session IDs. Defaults to "runtime". */
153
+ sessionPrefix?: string;
154
+ /**
155
+ * Optional callback for resolving session IDs from payload/context.
156
+ * Ignored when payload.sessionId is provided.
157
+ */
158
+ resolveSessionId?: (payload: TPayload, context: AgentTaskExecutionContext) => string | undefined;
159
+ /**
160
+ * Optional execution observers. These are generic lifecycle hooks that can be
161
+ * consumed by runtime adapters (in-memory, Dapr, queues, etc.) without
162
+ * introducing infrastructure dependencies into `@cuylabs/agent-core`.
163
+ */
164
+ observers?: AgentTaskObserver<TPayload>[];
165
+ /**
166
+ * Optional checkpoint strategy for converting streamed agent events into
167
+ * coarse-grained execution checkpoints. Defaults to
168
+ * `defaultAgentTaskCheckpointStrategy(...)`.
169
+ */
170
+ checkpointStrategy?: AgentTaskCheckpointStrategy<TPayload>;
171
+ }
172
+ /**
173
+ * Create a reusable task runner that maps generic task payloads to `agent.chat()`.
174
+ *
175
+ * This helper is intentionally infrastructure-agnostic. It can be used by any
176
+ * runtime/orchestration package (in-memory, Dapr, queues, cron, etc.) without
177
+ * introducing infrastructure dependencies into `@cuylabs/agent-core`.
178
+ *
179
+ * The runner also exposes a neutral execution observer/checkpoint surface so
180
+ * external runtimes can persist progress, react to lifecycle events, or map
181
+ * streamed execution milestones into their own durability layer.
182
+ */
183
+ declare function createAgentTaskRunner<TPayload extends AgentTaskPayload = AgentTaskPayload>(agent: AgentTaskChatAdapter, options?: AgentTaskRunnerOptions<TPayload>): AgentTaskRunner<TPayload>;
184
+
185
+ interface AgentWorkflowToolCallSnapshot {
186
+ toolCallId: string;
187
+ toolName: string;
188
+ args: unknown;
189
+ }
190
+ interface AgentWorkflowUserMessageSnapshot {
191
+ id: string;
192
+ role: "user";
193
+ createdAt: string;
194
+ content: string;
195
+ system?: string;
196
+ }
197
+ interface AgentWorkflowAssistantMessageSnapshot {
198
+ id: string;
199
+ role: "assistant";
200
+ createdAt: string;
201
+ content: string;
202
+ finish?: "stop" | "length" | "tool-calls" | "content-filter" | "error" | "unknown";
203
+ tokens?: TokenUsage;
204
+ cost?: number;
205
+ error?: {
206
+ name: string;
207
+ message: string;
208
+ code?: string;
209
+ status?: number;
210
+ };
211
+ toolCalls?: AgentWorkflowToolCallSnapshot[];
212
+ }
213
+ interface AgentWorkflowToolMessageSnapshot {
214
+ id: string;
215
+ role: "tool";
216
+ createdAt: string;
217
+ content: string;
218
+ toolCallId: string;
219
+ toolName: string;
220
+ result: unknown;
221
+ compactedAt?: number;
222
+ }
223
+ interface AgentWorkflowSystemMessageSnapshot {
224
+ id: string;
225
+ role: "system";
226
+ createdAt: string;
227
+ content: string;
228
+ }
229
+ type AgentWorkflowMessageSnapshot = AgentWorkflowUserMessageSnapshot | AgentWorkflowAssistantMessageSnapshot | AgentWorkflowToolMessageSnapshot | AgentWorkflowSystemMessageSnapshot;
230
+ type AgentWorkflowTurnPhase = "model-step" | "tool-batch" | "step-commit" | "output-commit" | "completed" | "failed";
231
+ interface AgentWorkflowReplayDecision {
232
+ toolCallId: string;
233
+ toolName: string;
234
+ action: "replay" | "skip";
235
+ source: "policy" | "runtime" | "operator";
236
+ decidedAt: string;
237
+ reason?: string;
238
+ }
239
+ interface AgentWorkflowModelStepResult {
240
+ text: string;
241
+ usage?: TokenUsage;
242
+ finishReason?: string;
243
+ turnState: AgentTurnState;
244
+ stepCommit?: AgentTurnStepCommitSnapshot;
245
+ }
246
+ interface AgentWorkflowCommitResult {
247
+ messages: AgentWorkflowMessageSnapshot[];
248
+ }
249
+ interface AgentWorkflowToolBatchResult {
250
+ stepCommit: AgentTurnStepCommitSnapshot;
251
+ turnState?: AgentTurnState;
252
+ }
253
+ interface AgentWorkflowToolCallResult {
254
+ toolResult: AgentTurnStepCommitToolResult;
255
+ turnState?: AgentTurnState;
256
+ }
257
+ interface AgentWorkflowTurnState {
258
+ sessionId: string;
259
+ systemPrompts: string[];
260
+ messages: AgentWorkflowMessageSnapshot[];
261
+ phase: AgentWorkflowTurnPhase;
262
+ step: number;
263
+ maxSteps: number;
264
+ usage?: TokenUsage;
265
+ turnState?: AgentTurnState;
266
+ lastModelStep?: AgentWorkflowModelStepResult;
267
+ replayDecisions: Record<string, AgentWorkflowReplayDecision>;
268
+ finalResponse?: string;
269
+ error?: string;
270
+ startedAt: string;
271
+ updatedAt: string;
272
+ }
273
+ interface CreateAgentWorkflowTurnStateOptions {
274
+ sessionId: string;
275
+ startedAt: string;
276
+ maxSteps: number;
277
+ systemPrompts?: string[];
278
+ initialMessages?: AgentWorkflowMessageSnapshot[];
279
+ initialStep?: number;
280
+ }
281
+ declare function snapshotAgentWorkflowMessage(message: Message): AgentWorkflowMessageSnapshot;
282
+ declare function snapshotAgentWorkflowMessages(messages: Message[]): AgentWorkflowMessageSnapshot[];
283
+ declare function restoreAgentWorkflowMessage(snapshot: AgentWorkflowMessageSnapshot): Message;
284
+ declare function restoreAgentWorkflowMessages(snapshots: AgentWorkflowMessageSnapshot[]): Message[];
285
+ declare function createAgentWorkflowTurnState(options: CreateAgentWorkflowTurnStateOptions): AgentWorkflowTurnState;
286
+ declare function cloneAgentWorkflowTurnState(state: AgentWorkflowTurnState): AgentWorkflowTurnState;
287
+
288
+ interface AgentWorkflowModelStepPlan {
289
+ kind: "model-step";
290
+ sessionId: string;
291
+ step: number;
292
+ maxSteps: number;
293
+ systemPrompts: string[];
294
+ messages: AgentWorkflowMessageSnapshot[];
295
+ }
296
+ interface AgentWorkflowStepCommitPlan {
297
+ kind: "step-commit";
298
+ sessionId: string;
299
+ step: number;
300
+ snapshot: AgentTurnStepCommitSnapshot;
301
+ }
302
+ interface AgentWorkflowToolCallPlan {
303
+ kind: "tool-call";
304
+ step: number;
305
+ sessionId: string;
306
+ toolCall: AgentTurnStepCommitToolCall;
307
+ turnState: AgentWorkflowTurnState["turnState"];
308
+ replayDecision?: AgentWorkflowReplayDecision;
309
+ }
310
+ interface AgentWorkflowOutputCommitPlan {
311
+ kind: "output-commit";
312
+ sessionId: string;
313
+ text: string;
314
+ usage?: TokenUsage;
315
+ }
316
+ type AgentWorkflowOperationPlan = AgentWorkflowModelStepPlan | AgentWorkflowToolCallPlan | AgentWorkflowStepCommitPlan | AgentWorkflowOutputCommitPlan;
317
+
318
+ /**
319
+ * Decide which deterministic workflow operation should run next.
320
+ */
321
+ declare function planNextAgentWorkflowOperation(state: AgentWorkflowTurnState): AgentWorkflowOperationPlan | undefined;
322
+
323
+ /**
324
+ * Advance serializable workflow state after the model-step activity completes.
325
+ */
326
+ declare function applyAgentWorkflowModelStepResult(state: AgentWorkflowTurnState, result: AgentWorkflowModelStepResult, updatedAt: string): AgentWorkflowTurnState;
327
+ /**
328
+ * Advance serializable workflow state after a separate tool-batch activity.
329
+ */
330
+ declare function applyAgentWorkflowToolBatchResult(state: AgentWorkflowTurnState, result: AgentWorkflowToolBatchResult, updatedAt: string): AgentWorkflowTurnState;
331
+ /**
332
+ * Advance serializable workflow state after a single tool-call activity.
333
+ */
334
+ declare function applyAgentWorkflowToolCallResult(state: AgentWorkflowTurnState, result: AgentWorkflowToolCallResult, updatedAt: string): AgentWorkflowTurnState;
335
+ /**
336
+ * Advance serializable workflow state after a commit activity persists messages.
337
+ */
338
+ declare function applyAgentWorkflowCommitResult(state: AgentWorkflowTurnState, result: AgentWorkflowCommitResult, updatedAt: string): AgentWorkflowTurnState;
339
+ /**
340
+ * Record a concrete replay decision chosen by a runtime or operator.
341
+ */
342
+ declare function recordAgentWorkflowReplayDecision(state: AgentWorkflowTurnState, decision: AgentWorkflowReplayDecision, updatedAt: string): AgentWorkflowTurnState;
343
+ /**
344
+ * Mark the workflow-side turn state as failed.
345
+ */
346
+ declare function failAgentWorkflowTurnState(state: AgentWorkflowTurnState, error: Error, updatedAt: string): AgentWorkflowTurnState;
347
+
348
+ /**
349
+ * Convert framework messages into Vercel AI SDK model messages.
350
+ *
351
+ * This keeps the message translation logic reusable for workflow activities
352
+ * and other runtime integrations without forcing those integrations to reach
353
+ * into `Agent` internals.
354
+ */
355
+ declare function convertAgentMessagesToModelMessages(messages: Message[]): ModelMessage[];
356
+
357
+ export { type AgentTaskChatAdapter, type AgentTaskCheckpointReason, type AgentTaskCheckpointStrategy, type AgentTaskCheckpointStrategyInput, type AgentTaskExecutionCheckpoint, type AgentTaskExecutionContext, type AgentTaskExecutionRun, type AgentTaskExecutionSnapshot, type AgentTaskObserver, type AgentTaskPayload, type AgentTaskResult, type AgentTaskRunner, type AgentTaskRunnerOptions, AgentTurnCommitBatch, AgentTurnState, AgentTurnStepCommitSnapshot, AgentTurnStepCommitToolCall, AgentTurnStepCommitToolResult, type AgentWorkflowAssistantMessageSnapshot, type AgentWorkflowCommitResult, type AgentWorkflowMessageSnapshot, type AgentWorkflowModelStepPlan, type AgentWorkflowModelStepResult, type AgentWorkflowOperationPlan, type AgentWorkflowOutputCommitPlan, type AgentWorkflowReplayDecision, type AgentWorkflowStepCommitPlan, type AgentWorkflowSystemMessageSnapshot, type AgentWorkflowToolBatchResult, type AgentWorkflowToolCallPlan, type AgentWorkflowToolCallResult, type AgentWorkflowToolCallSnapshot, type AgentWorkflowToolMessageSnapshot, type AgentWorkflowTurnPhase, type AgentWorkflowTurnState, type AgentWorkflowUserMessageSnapshot, CommitOutputOptions, CommitStepOptions, CreateAgentTurnStepCommitBatchOptions, type CreateAgentWorkflowTurnStateOptions, PrepareModelStepOptions, PreparedAgentModelStep, RunModelStepOptions, RunToolBatchOptions, RunToolBatchResult, applyAgentWorkflowCommitResult, applyAgentWorkflowModelStepResult, applyAgentWorkflowToolBatchResult, applyAgentWorkflowToolCallResult, cloneAgentWorkflowTurnState, commitOutput, commitStep, convertAgentMessagesToModelMessages, createAgentTaskRunner, createAgentTurnStepCommitBatch, createAgentWorkflowTurnState, defaultAgentTaskCheckpointStrategy, failAgentWorkflowTurnState, planNextAgentWorkflowOperation, prepareModelStep, recordAgentWorkflowReplayDecision, restoreAgentWorkflowMessage, restoreAgentWorkflowMessages, runModelStep, runToolBatch, snapshotAgentWorkflowMessage, snapshotAgentWorkflowMessages };
@@ -0,0 +1,64 @@
1
+ import {
2
+ AgentTurnEngine,
3
+ advanceAgentTurnState,
4
+ applyAgentWorkflowCommitResult,
5
+ applyAgentWorkflowModelStepResult,
6
+ applyAgentWorkflowToolBatchResult,
7
+ applyAgentWorkflowToolCallResult,
8
+ cloneAgentWorkflowTurnState,
9
+ commitOutput,
10
+ commitStep,
11
+ convertAgentMessagesToModelMessages,
12
+ createAgentTaskRunner,
13
+ createAgentTurnEngine,
14
+ createAgentTurnState,
15
+ createAgentTurnStepCommitBatch,
16
+ createAgentWorkflowTurnState,
17
+ defaultAgentTaskCheckpointStrategy,
18
+ failAgentTurnState,
19
+ failAgentWorkflowTurnState,
20
+ planNextAgentWorkflowOperation,
21
+ prepareModelStep,
22
+ recordAgentWorkflowReplayDecision,
23
+ restoreAgentWorkflowMessage,
24
+ restoreAgentWorkflowMessages,
25
+ runModelStep,
26
+ runToolBatch,
27
+ snapshotAgentWorkflowMessage,
28
+ snapshotAgentWorkflowMessages
29
+ } from "../chunk-3C4VKG4P.js";
30
+ import "../chunk-FG4MD5MU.js";
31
+ import "../chunk-VEKUXUVF.js";
32
+ import "../chunk-QAQADS4X.js";
33
+ import "../chunk-X635CM2F.js";
34
+ import "../chunk-QWFMX226.js";
35
+ import "../chunk-DWYX7ASF.js";
36
+ export {
37
+ AgentTurnEngine,
38
+ advanceAgentTurnState,
39
+ applyAgentWorkflowCommitResult,
40
+ applyAgentWorkflowModelStepResult,
41
+ applyAgentWorkflowToolBatchResult,
42
+ applyAgentWorkflowToolCallResult,
43
+ cloneAgentWorkflowTurnState,
44
+ commitOutput,
45
+ commitStep,
46
+ convertAgentMessagesToModelMessages,
47
+ createAgentTaskRunner,
48
+ createAgentTurnEngine,
49
+ createAgentTurnState,
50
+ createAgentTurnStepCommitBatch,
51
+ createAgentWorkflowTurnState,
52
+ defaultAgentTaskCheckpointStrategy,
53
+ failAgentTurnState,
54
+ failAgentWorkflowTurnState,
55
+ planNextAgentWorkflowOperation,
56
+ prepareModelStep,
57
+ recordAgentWorkflowReplayDecision,
58
+ restoreAgentWorkflowMessage,
59
+ restoreAgentWorkflowMessages,
60
+ runModelStep,
61
+ runToolBatch,
62
+ snapshotAgentWorkflowMessage,
63
+ snapshotAgentWorkflowMessages
64
+ };
@@ -0,0 +1,274 @@
1
+ import { M as Message } from './messages-BYWGn8TY.js';
2
+
3
+ /**
4
+ * Storage Types
5
+ *
6
+ * Core types for session storage with tree structure support.
7
+ * Designed for append-only event sourcing with branching.
8
+ */
9
+ /**
10
+ * Base interface for all session entries
11
+ * Supports tree structure via id/parentId
12
+ */
13
+ interface EntryBase {
14
+ /** Unique entry ID (8-char hex) */
15
+ id: string;
16
+ /** Parent entry ID (null for first entry after header) */
17
+ parentId: string | null;
18
+ /** ISO timestamp */
19
+ timestamp: string;
20
+ }
21
+ /**
22
+ * Session header - always first entry in file
23
+ */
24
+ interface SessionHeader {
25
+ type: "header";
26
+ /** Storage format version */
27
+ version: number;
28
+ /** Session ID */
29
+ id: string;
30
+ /** Working directory */
31
+ cwd: string;
32
+ /** ISO timestamp */
33
+ timestamp: string;
34
+ /** Parent session ID (if forked) */
35
+ parentSessionId?: string;
36
+ /** Session title */
37
+ title?: string;
38
+ }
39
+ /**
40
+ * Serialized message (dates as ISO strings)
41
+ */
42
+ interface SerializedMessage {
43
+ id: string;
44
+ role: "user" | "assistant" | "tool" | "system";
45
+ content: string;
46
+ createdAt: string;
47
+ system?: string;
48
+ finish?: string;
49
+ tokens?: {
50
+ inputTokens?: number;
51
+ outputTokens?: number;
52
+ totalTokens?: number;
53
+ };
54
+ cost?: number;
55
+ error?: {
56
+ name: string;
57
+ message: string;
58
+ code?: string;
59
+ };
60
+ /** Tool calls for assistant messages with finish=tool-calls */
61
+ toolCalls?: Array<{
62
+ toolCallId: string;
63
+ toolName: string;
64
+ args: unknown;
65
+ }>;
66
+ toolCallId?: string;
67
+ toolName?: string;
68
+ result?: unknown;
69
+ }
70
+ /**
71
+ * Message entry
72
+ */
73
+ interface MessageEntry extends EntryBase {
74
+ type: "message";
75
+ message: SerializedMessage;
76
+ }
77
+ /**
78
+ * Compaction/summarization entry
79
+ * Replaces old messages with a summary
80
+ */
81
+ interface CompactionEntry extends EntryBase {
82
+ type: "compaction";
83
+ /** Summary of compacted messages */
84
+ summary: string;
85
+ /** ID of first entry that was kept (not compacted) */
86
+ firstKeptEntryId: string;
87
+ /** Token count before compaction */
88
+ tokensBefore: number;
89
+ /** Token count after compaction */
90
+ tokensAfter: number;
91
+ /** Files that were read during compacted messages */
92
+ readFiles?: string[];
93
+ /** Files that were modified during compacted messages */
94
+ modifiedFiles?: string[];
95
+ }
96
+ /**
97
+ * Session info/metadata update
98
+ */
99
+ interface MetadataEntry extends EntryBase {
100
+ type: "metadata";
101
+ /** Updated title */
102
+ title?: string;
103
+ /** User-defined name */
104
+ name?: string;
105
+ }
106
+ /**
107
+ * Branch marker - indicates a branch point
108
+ */
109
+ interface BranchEntry extends EntryBase {
110
+ type: "branch";
111
+ /** ID of the entry we're branching from */
112
+ branchFromId: string;
113
+ /** Optional summary of the branch */
114
+ summary?: string;
115
+ }
116
+ /**
117
+ * Model/config change entry
118
+ */
119
+ interface ConfigChangeEntry extends EntryBase {
120
+ type: "config_change";
121
+ /** What changed */
122
+ change: "model" | "reasoning_level" | "temperature" | "other";
123
+ /** Previous value */
124
+ from?: string;
125
+ /** New value */
126
+ to: string;
127
+ }
128
+ /**
129
+ * All entry types (excluding header)
130
+ */
131
+ type SessionEntry = MessageEntry | CompactionEntry | MetadataEntry | BranchEntry | ConfigChangeEntry;
132
+ /**
133
+ * All file entries (including header)
134
+ */
135
+ type FileEntry = SessionHeader | SessionEntry;
136
+ /**
137
+ * Session summary info (lightweight, for listing)
138
+ */
139
+ interface SessionInfo {
140
+ /** Session ID */
141
+ id: string;
142
+ /** File path */
143
+ path: string;
144
+ /** Working directory */
145
+ cwd: string;
146
+ /** Session title */
147
+ title?: string;
148
+ /** User-defined name */
149
+ name?: string;
150
+ /** Parent session ID (if forked) */
151
+ parentSessionId?: string;
152
+ /** Creation time */
153
+ createdAt: Date;
154
+ /** Last modified time */
155
+ updatedAt: Date;
156
+ /** Number of message entries */
157
+ messageCount: number;
158
+ /** First user message (preview) */
159
+ firstMessage?: string;
160
+ }
161
+ /**
162
+ * Session storage interface
163
+ * Pluggable backend for session persistence
164
+ */
165
+ interface SessionStorage {
166
+ /**
167
+ * Create a new session
168
+ */
169
+ create(header: SessionHeader): Promise<void>;
170
+ /**
171
+ * Append an entry to a session
172
+ */
173
+ append(sessionId: string, entry: SessionEntry): Promise<void>;
174
+ /**
175
+ * Append multiple entries atomically
176
+ */
177
+ appendBatch(sessionId: string, entries: SessionEntry[]): Promise<void>;
178
+ /**
179
+ * Read all entries from a session
180
+ */
181
+ read(sessionId: string): Promise<FileEntry[]>;
182
+ /**
183
+ * Delete a session
184
+ */
185
+ delete(sessionId: string): Promise<boolean>;
186
+ /**
187
+ * Check if session exists
188
+ */
189
+ exists(sessionId: string): Promise<boolean>;
190
+ /**
191
+ * List all sessions (lightweight info only)
192
+ */
193
+ list(): Promise<SessionInfo[]>;
194
+ /**
195
+ * Clear all sessions
196
+ */
197
+ clear(): Promise<void>;
198
+ }
199
+ /**
200
+ * Current storage format version
201
+ */
202
+ declare const STORAGE_VERSION = 1;
203
+
204
+ /**
205
+ * Options for creating a new session.
206
+ */
207
+ interface CreateSessionOptions {
208
+ /** Custom session ID (auto-generated if not provided) */
209
+ id?: string;
210
+ /** Working directory */
211
+ cwd: string;
212
+ /** Session title */
213
+ title?: string;
214
+ /** Parent session ID (if forking) */
215
+ parentSessionId?: string;
216
+ }
217
+ /**
218
+ * Session context for LLM calls.
219
+ */
220
+ interface SessionContext {
221
+ /** Messages for LLM context */
222
+ messages: Message[];
223
+ /** Current leaf entry ID */
224
+ leafId: string | null;
225
+ /** Session metadata */
226
+ metadata: {
227
+ id: string;
228
+ cwd: string;
229
+ title?: string;
230
+ name?: string;
231
+ };
232
+ }
233
+
234
+ /**
235
+ * Manages session lifecycle with tree-structured entries.
236
+ */
237
+ declare class SessionManager {
238
+ private storage;
239
+ private currentSessionId;
240
+ private currentLeafId;
241
+ private entriesCache;
242
+ private idsCache;
243
+ constructor(storage?: SessionStorage);
244
+ create(options: CreateSessionOptions): Promise<string>;
245
+ load(sessionId: string): Promise<void>;
246
+ getSessionId(): string | null;
247
+ getLeafId(): string | null;
248
+ addMessage(message: Message): Promise<string>;
249
+ addMessages(messages: Message[]): Promise<string[]>;
250
+ getMessages(leafId?: string): Message[];
251
+ addCompaction(options: {
252
+ summary: string;
253
+ firstKeptEntryId: string;
254
+ tokensBefore: number;
255
+ tokensAfter: number;
256
+ readFiles?: string[];
257
+ modifiedFiles?: string[];
258
+ }): Promise<string>;
259
+ branch(fromEntryId: string, summary?: string): Promise<string>;
260
+ switchToLeaf(leafId: string): void;
261
+ updateMetadata(updates: {
262
+ title?: string;
263
+ name?: string;
264
+ }): Promise<void>;
265
+ getContext(): SessionContext;
266
+ getEntries(): FileEntry[];
267
+ getHeader(): SessionHeader | null;
268
+ listSessions(): Promise<SessionInfo[]>;
269
+ deleteSession(sessionId: string): Promise<boolean>;
270
+ sessionExists(sessionId: string): Promise<boolean>;
271
+ getStorage(): SessionStorage;
272
+ }
273
+
274
+ export { type BranchEntry as B, type CompactionEntry as C, type EntryBase as E, type FileEntry as F, type MessageEntry as M, STORAGE_VERSION as S, type CreateSessionOptions as a, type MetadataEntry as b, type SessionContext as c, type SessionEntry as d, type SessionHeader as e, type SessionInfo as f, SessionManager as g, type SessionStorage as h, type SerializedMessage as i, type ConfigChangeEntry as j };