@vinhnt-sdk/durable-state 0.0.0-stage → 0.23.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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +186 -2
  3. package/dist/attachment/attachment-ref.d.ts +99 -0
  4. package/dist/attachment/attachment-ref.d.ts.map +1 -0
  5. package/dist/attachment/attachment-ref.js +117 -0
  6. package/dist/attachment/attachment-ref.js.map +1 -0
  7. package/dist/errors.d.ts +121 -0
  8. package/dist/errors.d.ts.map +1 -0
  9. package/dist/errors.js +166 -0
  10. package/dist/errors.js.map +1 -0
  11. package/dist/index.d.ts +16 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +84 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/state/channel.d.ts +115 -0
  16. package/dist/state/channel.d.ts.map +1 -0
  17. package/dist/state/channel.js +65 -0
  18. package/dist/state/channel.js.map +1 -0
  19. package/dist/state/checkpoint.d.ts +141 -0
  20. package/dist/state/checkpoint.d.ts.map +1 -0
  21. package/dist/state/checkpoint.js +109 -0
  22. package/dist/state/checkpoint.js.map +1 -0
  23. package/dist/state/executor.d.ts +42 -0
  24. package/dist/state/executor.d.ts.map +1 -0
  25. package/dist/state/executor.js +254 -0
  26. package/dist/state/executor.js.map +1 -0
  27. package/dist/state/graph-state.d.ts +113 -0
  28. package/dist/state/graph-state.d.ts.map +1 -0
  29. package/dist/state/graph-state.js +121 -0
  30. package/dist/state/graph-state.js.map +1 -0
  31. package/dist/state/interrupt.d.ts +97 -0
  32. package/dist/state/interrupt.d.ts.map +1 -0
  33. package/dist/state/interrupt.js +70 -0
  34. package/dist/state/interrupt.js.map +1 -0
  35. package/dist/state/session-adapter.d.ts +76 -0
  36. package/dist/state/session-adapter.d.ts.map +1 -0
  37. package/dist/state/session-adapter.js +210 -0
  38. package/dist/state/session-adapter.js.map +1 -0
  39. package/package.json +46 -4
package/dist/errors.js ADDED
@@ -0,0 +1,166 @@
1
+ import { SdkError } from "@vinhnt-sdk/schema";
2
+ /**
3
+ * Base error for all @vinhnt-sdk/durable-state errors.
4
+ *
5
+ * Extends {@link SdkError} with machine-readable code, retryable flag,
6
+ * correlation IDs (requestId, traceId), and structured context.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * throw new DurableStateError(
11
+ * "CHANNEL_NOT_FOUND",
12
+ * `Channel "messages" not declared in graph "my-graph"`,
13
+ * { channel: "messages", graphId: "my-graph" }
14
+ * );
15
+ * if (error.code === "CHANNEL_NOT_FOUND") { ... }
16
+ * ```
17
+ */
18
+ export class DurableStateError extends SdkError {
19
+ /** Additional structured context attached to the error. */
20
+ context;
21
+ constructor(code, message, options) {
22
+ super(code, message, {
23
+ retryable: options?.retryable ?? false,
24
+ cause: options?.cause,
25
+ requestId: options?.requestId,
26
+ traceId: options?.traceId,
27
+ });
28
+ this.name = "DurableStateError";
29
+ this.context = options?.context;
30
+ }
31
+ static isInstance(error) {
32
+ return error instanceof DurableStateError;
33
+ }
34
+ }
35
+ /**
36
+ * Thrown when a state channel is referenced but not declared in the graph.
37
+ */
38
+ export class ChannelNotFoundError extends DurableStateError {
39
+ channel;
40
+ graphId;
41
+ constructor(channel, graphId, ctx) {
42
+ super("CHANNEL_NOT_FOUND", `Channel "${channel}" not declared in state graph "${graphId}"`, {
43
+ requestId: ctx?.requestId,
44
+ traceId: ctx?.traceId,
45
+ context: { channel, graphId },
46
+ });
47
+ this.name = "ChannelNotFoundError";
48
+ this.channel = channel;
49
+ this.graphId = graphId;
50
+ }
51
+ static isInstance(error) {
52
+ return error instanceof ChannelNotFoundError;
53
+ }
54
+ }
55
+ /**
56
+ * Thrown when a checkpoint operation fails (storage unavailable, corrupt data).
57
+ */
58
+ export class CheckpointError extends DurableStateError {
59
+ checkpointId;
60
+ threadId;
61
+ constructor(message, options) {
62
+ super("CHECKPOINT_ERROR", message, {
63
+ retryable: options?.retryable ?? true,
64
+ cause: options?.cause,
65
+ requestId: options?.requestId,
66
+ traceId: options?.traceId,
67
+ context: {
68
+ ...(options?.checkpointId !== undefined ? { checkpointId: options.checkpointId } : {}),
69
+ ...(options?.threadId !== undefined ? { threadId: options.threadId } : {}),
70
+ },
71
+ });
72
+ this.name = "CheckpointError";
73
+ this.checkpointId = options?.checkpointId;
74
+ this.threadId = options?.threadId;
75
+ }
76
+ static isInstance(error) {
77
+ return error instanceof CheckpointError;
78
+ }
79
+ }
80
+ /**
81
+ * Thrown when an interrupt is triggered during graph execution.
82
+ *
83
+ * This is a control-flow exception, not a failure. The graph pauses at the
84
+ * interrupt point and can be resumed with `Command({ resume: value })`.
85
+ */
86
+ export class GraphInterrupt extends DurableStateError {
87
+ /** The value passed to interrupt(), available on resume. */
88
+ interruptValue;
89
+ /** Stable interrupt id for multi-interrupt resume mapping. */
90
+ interruptId;
91
+ /** Node that raised the interrupt. */
92
+ nodeId;
93
+ constructor(interruptValue, options) {
94
+ super("GRAPH_INTERRUPT", `Graph interrupted at node "${options?.nodeId ?? "unknown"}"`, {
95
+ retryable: false,
96
+ requestId: options?.requestId,
97
+ traceId: options?.traceId,
98
+ context: {
99
+ interruptId: options?.interruptId,
100
+ nodeId: options?.nodeId,
101
+ interruptValue,
102
+ },
103
+ });
104
+ this.name = "GraphInterrupt";
105
+ this.interruptValue = interruptValue;
106
+ this.interruptId = options?.interruptId ?? crypto.randomUUID();
107
+ this.nodeId = options?.nodeId ?? "unknown";
108
+ }
109
+ static isInstance(error) {
110
+ return error instanceof GraphInterrupt;
111
+ }
112
+ }
113
+ /**
114
+ * Thrown when a Command is issued but the graph is not in a resumable state.
115
+ */
116
+ export class CommandError extends DurableStateError {
117
+ commandType;
118
+ constructor(message, commandType, options) {
119
+ super("COMMAND_ERROR", message, {
120
+ retryable: false,
121
+ requestId: options?.requestId,
122
+ traceId: options?.traceId,
123
+ context: { ...options?.context, commandType },
124
+ });
125
+ this.name = "CommandError";
126
+ this.commandType = commandType;
127
+ }
128
+ static isInstance(error) {
129
+ return error instanceof CommandError;
130
+ }
131
+ }
132
+ /**
133
+ * Thrown when an attachment reference cannot be resolved (missing file, corrupt ref).
134
+ */
135
+ export class AttachmentRefError extends DurableStateError {
136
+ attachmentId;
137
+ constructor(attachmentId, message, options) {
138
+ super("ATTACHMENT_REF_ERROR", message, {
139
+ retryable: false,
140
+ cause: options?.cause,
141
+ requestId: options?.requestId,
142
+ traceId: options?.traceId,
143
+ context: { attachmentId },
144
+ });
145
+ this.name = "AttachmentRefError";
146
+ this.attachmentId = attachmentId;
147
+ }
148
+ static isInstance(error) {
149
+ return error instanceof AttachmentRefError;
150
+ }
151
+ }
152
+ /**
153
+ * Type-safe guard for DurableStateError across module boundaries.
154
+ */
155
+ export function isDurableStateError(value) {
156
+ return value instanceof DurableStateError;
157
+ }
158
+ /**
159
+ * Structural error-code check — safe across duplicated package installs.
160
+ */
161
+ export function hasDurableStateErrorCode(value, code) {
162
+ return (typeof value === "object" &&
163
+ value !== null &&
164
+ value.code === code);
165
+ }
166
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAa9C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAC7C,2DAA2D;IAClD,OAAO,CAA2B;IAE3C,YACE,IAAY,EACZ,OAAe,EACf,OAOC;QAED,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE;YACnB,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,KAAK;YACtC,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,SAAS,EAAE,OAAO,EAAE,SAA+D;YACnF,OAAO,EAAE,OAAO,EAAE,OAA2D;SAC9E,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,EAAE,OAA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C,IAAI,KAAK,IAAI,CAC5C,CAAC;AACJ,CAAC"}
@@ -0,0 +1,16 @@
1
+ export type { StateChannel, Overwrite, ChannelDelta, ChannelName, Reducer, } from "./state/channel.js";
2
+ export { createChannel, createChannelWithReducer, overwriteReducer, appendReducer, mergeReducer, channelName, isOverwrite, } from "./state/channel.js";
3
+ export type { StateSchema, StateValues, PartialState, StateGraphDefinition, } from "./state/graph-state.js";
4
+ export { StateGraphBuilder, findChannel, findReducer, initialState, applyDelta, } from "./state/graph-state.js";
5
+ export type { GraphConfig, StateSnapshot, PendingTask, InterruptRecord, ResumeResult, Checkpointer, } from "./state/checkpoint.js";
6
+ export { MemoryCheckpointer, createMemoryCheckpointer, serializeSnapshot, deserializeSnapshot, createSnapshot, } from "./state/checkpoint.js";
7
+ export { StateGraphExecutor, } from "./state/executor.js";
8
+ export type { InterruptResult, InterruptId } from "./state/interrupt.js";
9
+ export { Command, interrupt, isCommand, interruptId, } from "./state/interrupt.js";
10
+ export type { AttachmentKind, AttachmentRef, BinaryAttachmentStore, } from "./attachment/attachment-ref.js";
11
+ export { createAttachmentRef, InMemoryBinaryAttachmentStore, createInMemoryBinaryAttachmentStore, } from "./attachment/attachment-ref.js";
12
+ export type { DurableStateDomain, DurableStateCategory } from "./errors.js";
13
+ export { DurableStateError, ChannelNotFoundError, CheckpointError, GraphInterrupt, CommandError, AttachmentRefError, isDurableStateError, hasDurableStateErrorCode, } from "./errors.js";
14
+ export type { SerializedRunState } from "@vinhnt-sdk/session";
15
+ export { runStateToSnapshot, snapshotToRunState, snapshotFromDefinition, applyDeltaToSnapshot, SessionStoreCheckpointer, isChannelNotFoundError, } from "./state/session-adapter.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AA4EA,YAAY,EACV,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,WAAW,EACX,OAAO,GACR,MAAM,oBAA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xB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,84 @@
1
+ // @vinhnt-sdk/durable-state
2
+ // Durable state management for agent orchestration.
3
+ //
4
+ // This package provides durable, checkpointable state for vinhnt-sdk:
5
+ // StateChannel, Reducer, StateGraph, Checkpointer, StateSnapshot,
6
+ // interrupt()/Command(resume), and AttachmentRef (binary attachment refs
7
+ // stored outside JSON checkpoints).
8
+ //
9
+ // ## Design principles
10
+ //
11
+ // - **Library, not framework**: receives config from outside, never decides
12
+ // for the user, no hardcoded models/URLs/pricing.
13
+ // - **Additive to vinhnt-sdk**: keeps `SessionRuntimeState`,
14
+ // `RunEventSnapshot`, and `SerializedRunState` intact; durable-state is a
15
+ // separate channel state that can be checkpointed independently.
16
+ // - **Binary attachments outside JSON**: `AttachmentRef` points to external
17
+ // storage; snapshots stay small and JSON-serializable.
18
+ //
19
+ // ## Installation
20
+ //
21
+ // ```bash
22
+ // npm install @vinhnt-sdk/durable-state
23
+ // # or
24
+ // pnpm add @vinhnt-sdk/durable-state
25
+ // ```
26
+ //
27
+ // ## Quick start
28
+ //
29
+ // ```typescript
30
+ // import {
31
+ // StateGraphBuilder,
32
+ // StateGraphExecutor,
33
+ // createChannel,
34
+ // appendReducer,
35
+ // overwriteReducer,
36
+ // createMemoryCheckpointer,
37
+ // interrupt,
38
+ // Command,
39
+ // } from "@vinhnt-sdk/durable-state";
40
+ //
41
+ // // 1. Define state schema (typed channels)
42
+ // const builder = new StateGraphBuilder("my-graph", "My Graph");
43
+ // builder.addChannel("messages", createChannel<MessageContentPart[]>("messages", {
44
+ // reducer: appendReducer(),
45
+ // default: [],
46
+ // }));
47
+ // builder.addChannel("step", createChannel<number>("step", {
48
+ // reducer: overwriteReducer(),
49
+ // default: 0,
50
+ // }));
51
+ // const graph = builder.build();
52
+ //
53
+ // // 2. Create checkpointer (MemoryCheckpointer for dev; SQLite/Postgres for prod)
54
+ // const checkpointer = createMemoryCheckpointer();
55
+ //
56
+ // // 3. Create executor and register node implementations
57
+ // const executor = new StateGraphExecutor(graph, checkpointer);
58
+ // executor.addNode("process", async (state, config) => {
59
+ // // ... node logic, returns PartialState or Command
60
+ // return { messages: [...state.messages, { type: "text", text: "done" }] };
61
+ // });
62
+ //
63
+ // // 4. Run — threadId maps to vinhnt sessionId
64
+ // const result = await executor.run("process", {
65
+ // threadId: "session_123",
66
+ // checkpointNs: "",
67
+ // });
68
+ //
69
+ // // 5. Resume from interrupt (if result.interrupt is set)
70
+ // const resumed = await executor.resume(
71
+ // { threadId: "session_123", checkpointNs: "" },
72
+ // Command.resume("user approved"),
73
+ // );
74
+ // ```
75
+ export { createChannel, createChannelWithReducer, overwriteReducer, appendReducer, mergeReducer, channelName, isOverwrite, } from "./state/channel.js";
76
+ export { StateGraphBuilder, findChannel, findReducer, initialState, applyDelta, } from "./state/graph-state.js";
77
+ export { MemoryCheckpointer, createMemoryCheckpointer, serializeSnapshot, deserializeSnapshot, createSnapshot, } from "./state/checkpoint.js";
78
+ // ===== Executor =====
79
+ export { StateGraphExecutor, } from "./state/executor.js";
80
+ export { Command, interrupt, isCommand, interruptId, } from "./state/interrupt.js";
81
+ export { createAttachmentRef, InMemoryBinaryAttachmentStore, createInMemoryBinaryAttachmentStore, } from "./attachment/attachment-ref.js";
82
+ export { DurableStateError, ChannelNotFoundError, CheckpointError, GraphInterrupt, CommandError, AttachmentRefError, isDurableStateError, hasDurableStateErrorCode, } from "./errors.js";
83
+ export { runStateToSnapshot, snapshotToRunState, snapshotFromDefinition, applyDeltaToSnapshot, SessionStoreCheckpointer, isChannelNotFoundError, } from "./state/session-adapter.js";
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,oDAAoD;AACpD,EAAE;AACF,sEAAsE;AACtE,kEAAkE;AAClE,yEAAyE;AACzE,oCAAoC;AACpC,EAAE;AAC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B,OAAO,EACL,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EACL,OAAO,EACP,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,sBAAsB,CAAC;AAQ9B,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,mCAAmC,GACpC,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * A state channel — a named, typed slot in the graph's state.
3
+ *
4
+ * Each channel owns a slice of the graph state. When a node returns a delta
5
+ * for a channel, the channel's reducer is applied:
6
+ *
7
+ * newValue = reducer(currentValue, delta)
8
+ *
9
+ * Channels are immutable in the sense that the graph never mutates a channel
10
+ * value in place; it always produces a new value via the reducer.
11
+ *
12
+ * @typeParam T - The channel's value type.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createChannel } from "@vinhnt-sdk/langgraph";
17
+ *
18
+ * const messages = createChannel<MessageContentPart[]>("messages", {
19
+ * reducer: (current, delta) => [...current, ...delta],
20
+ * default: [],
21
+ * });
22
+ * ```
23
+ */
24
+ export interface StateChannel<T, UpdateT = T> {
25
+ /** Channel name — must be unique within a state graph. */
26
+ readonly name: string;
27
+ /** Channel value type tag for documentation/debugging. */
28
+ readonly type: string;
29
+ /** Reducer function: merge current value with an incoming delta. */
30
+ readonly reducer: (current: T, delta: UpdateT) => T;
31
+ /** Default value used when the channel is first initialized. */
32
+ readonly default: T;
33
+ /** Whether the channel supports overwrite via {@link Overwrite}. */
34
+ readonly supportsOverwrite: boolean;
35
+ }
36
+ /**
37
+ * Marker type to bypass the reducer and set a channel value directly.
38
+ *
39
+ * Wrap a value in `Overwrite<T>` when a node wants to replace the entire
40
+ * channel value instead of merging via the reducer.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * // Replace messages entirely instead of appending
45
+ * return { messages: Overwrite([newMessage]) };
46
+ * ```
47
+ */
48
+ export type Overwrite<T> = {
49
+ readonly __overwriteBrand: true;
50
+ readonly value: T;
51
+ };
52
+ /**
53
+ * Type helper to extract the delta (update) type from a channel.
54
+ */
55
+ export type ChannelDelta<C extends StateChannel<any, any>> = C extends StateChannel<any, infer D> ? D : never;
56
+ /**
57
+ * Create a state channel with last-write-wins semantics (default reducer
58
+ * replaces the value entirely).
59
+ *
60
+ * @typeParam T - Channel value type.
61
+ * @param name - Unique channel name within the graph.
62
+ * @param defaultValue - Initial value.
63
+ * @returns A {@link StateChannel} with overwrite-only reducer.
64
+ */
65
+ export declare function createChannel<T>(name: string, defaultValue: T): StateChannel<T, T>;
66
+ /**
67
+ * Create a state channel with a custom merge reducer.
68
+ *
69
+ * @typeParam T - Channel value type.
70
+ * @typeParam D - Delta/update type (defaults to T).
71
+ * @param name - Unique channel name.
72
+ * @param reducer - Merge function (current, delta) => new value.
73
+ * @param defaultValue - Initial value.
74
+ * @param options - Channel options.
75
+ * @returns A {@link StateChannel}.
76
+ */
77
+ export declare function createChannelWithReducer<T, D = T>(name: string, reducer: (current: T, delta: D) => T, defaultValue: T, options?: {
78
+ type?: string;
79
+ supportsOverwrite?: boolean;
80
+ }): StateChannel<T, D>;
81
+ /**
82
+ * Reducer type signature: merge current state with an incoming delta.
83
+ *
84
+ * @typeParam S - State type.
85
+ * @typeParam D - Delta/update type.
86
+ */
87
+ export type Reducer<S, D = S> = (current: S, delta: D) => S;
88
+ /**
89
+ * Last-write-wins reducer — ignores current value, returns delta.
90
+ */
91
+ export declare const overwriteReducer: <T>() => Reducer<T, T>;
92
+ /**
93
+ * Append reducer — concatenates delta array to current array.
94
+ */
95
+ export declare const appendReducer: <T>() => Reducer<T[], T[]>;
96
+ /**
97
+ * Merge reducer — shallow merges delta object into current object.
98
+ */
99
+ export declare const mergeReducer: <T extends Record<string, unknown>>() => Reducer<T, Partial<T>>;
100
+ /**
101
+ * Branded type for a channel name — prevents mixing up channel names across
102
+ * different graphs.
103
+ */
104
+ export type ChannelName = string & {
105
+ readonly __channelBrand: unique symbol;
106
+ };
107
+ /**
108
+ * Create a branded channel name.
109
+ */
110
+ export declare function channelName(name: string): ChannelName;
111
+ /**
112
+ * Check whether a value is an Overwrite marker.
113
+ */
114
+ export declare function isOverwrite(value: unknown): value is Overwrite<unknown>;
115
+ //# sourceMappingURL=channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/state/channel.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC;IAC1C,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,KAAK,CAAC,CAAC;IACpD,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,oEAAoE;IACpE,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;CACrC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IAAE,QAAQ,CAAC,gBAAgB,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAElF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,YAAY,CA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gB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAErD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAAC,OAAO,CAAC,CAMvE"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Create a state channel with last-write-wins semantics (default reducer
3
+ * replaces the value entirely).
4
+ *
5
+ * @typeParam T - Channel value type.
6
+ * @param name - Unique channel name within the graph.
7
+ * @param defaultValue - Initial value.
8
+ * @returns A {@link StateChannel} with overwrite-only reducer.
9
+ */
10
+ export function createChannel(name, defaultValue) {
11
+ return {
12
+ name,
13
+ type: typeof defaultValue,
14
+ reducer: (_current, delta) => delta,
15
+ default: defaultValue,
16
+ supportsOverwrite: true,
17
+ };
18
+ }
19
+ /**
20
+ * Create a state channel with a custom merge reducer.
21
+ *
22
+ * @typeParam T - Channel value type.
23
+ * @typeParam D - Delta/update type (defaults to T).
24
+ * @param name - Unique channel name.
25
+ * @param reducer - Merge function (current, delta) => new value.
26
+ * @param defaultValue - Initial value.
27
+ * @param options - Channel options.
28
+ * @returns A {@link StateChannel}.
29
+ */
30
+ export function createChannelWithReducer(name, reducer, defaultValue, options) {
31
+ return {
32
+ name,
33
+ type: options?.type ?? typeof defaultValue,
34
+ reducer,
35
+ default: defaultValue,
36
+ supportsOverwrite: options?.supportsOverwrite ?? false,
37
+ };
38
+ }
39
+ /**
40
+ * Last-write-wins reducer — ignores current value, returns delta.
41
+ */
42
+ export const overwriteReducer = () => (_current, delta) => delta;
43
+ /**
44
+ * Append reducer — concatenates delta array to current array.
45
+ */
46
+ export const appendReducer = () => (current, delta) => [...current, ...delta];
47
+ /**
48
+ * Merge reducer — shallow merges delta object into current object.
49
+ */
50
+ export const mergeReducer = () => (current, delta) => ({ ...current, ...delta });
51
+ /**
52
+ * Create a branded channel name.
53
+ */
54
+ export function channelName(name) {
55
+ return name;
56
+ }
57
+ /**
58
+ * Check whether a value is an Overwrite marker.
59
+ */
60
+ export function isOverwrite(value) {
61
+ return (typeof value === "object" &&
62
+ value !== null &&
63
+ "__overwriteBrand" in value);
64
+ }
65
+ //# sourceMappingURL=channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"channel.js","sourceRoot":"","sources":["../../src/state/channel.ts"],"names":[],"mappings":"AA0DA;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAAI,IAAY,EAAE,YAAe;IAC5D,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,OAAO,YAAY;QACzB,OAAO,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK;QACnC,OAAO,EAAE,YAAY;QACrB,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAY,EACZ,OAAoC,EACpC,YAAe,EACf,OAAwD;IAExD,OAAO;QACL,IAAI;QACJ,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,OAAO,YAAY;QAC1C,OAAO;QACP,OAAO,EAAE,YAAY;QACrB,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,IAAI,KAAK;KACvD,CAAC;AACJ,CAAC;AAUD;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAqB,EAAE,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;AAEnF;;GAEG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,GAAyB,EAAE,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,KAAK,CAAC,CAAC;AAEpG;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,GAA8D,EAAE,CAAC,CAC3F,OAAO,EACP,KAAK,EACL,EAAE,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;AAQhC;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAmB,CAAC;AAC7B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,kBAAkB,IAAI,KAAK,CAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { StateValues } from "./graph-state.js";
2
+ import type { TraceId } from "@vinhnt-sdk/schema";
3
+ /**
4
+ * Configuration for a graph execution thread — identifies the conversation
5
+ * and optional checkpoint namespace (for subgraphs).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const config: GraphConfig = {
10
+ * threadId: "thread_123",
11
+ * checkpointNs: "", // root graph
12
+ * checkpointId: "cp_abc", // specific checkpoint to resume from
13
+ * };
14
+ * ```
15
+ */
16
+ export interface GraphConfig {
17
+ /** Conversation/thread identifier — maps to vinhnt sessionId. */
18
+ readonly threadId: string;
19
+ /** Checkpoint namespace — "" for root, namespaced for subgraphs. */
20
+ readonly checkpointNs?: string;
21
+ /** Specific checkpoint id to resume from (optional). */
22
+ readonly checkpointId?: string;
23
+ /** Correlation id for tracing. */
24
+ readonly traceId?: TraceId;
25
+ /** Request id for tracing. */
26
+ readonly requestId?: string;
27
+ /** Metadata attached to this execution. */
28
+ readonly metadata?: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * A snapshot of graph state at a point in time — the durable checkpoint.
32
+ * Contains everything needed to resume execution.
33
+ */
34
+ export interface StateSnapshot {
35
+ /** Current channel values. */
36
+ readonly values: StateValues;
37
+ /** Next node(s) to execute — empty array means completed. */
38
+ readonly next: readonly string[];
39
+ /** Graph configuration (thread, checkpoint namespace, ids). */
40
+ readonly config: GraphConfig;
41
+ /** Metadata about this snapshot (source, writes, step, etc.). */
42
+ readonly metadata: Readonly<Record<string, unknown>>;
43
+ /** ISO timestamp when the snapshot was created. */
44
+ readonly createdAt: string;
45
+ /** Parent checkpoint id — null for the first checkpoint. */
46
+ readonly parentConfig: GraphConfig | null;
47
+ /** Pending tasks at the snapshot point (interrupts, in-flight steps). */
48
+ readonly tasks: readonly PendingTask[];
49
+ }
50
+ /**
51
+ * A pending task recorded at snapshot time — used for interrupt/resume.
52
+ */
53
+ export interface PendingTask {
54
+ readonly id: string;
55
+ readonly name: string;
56
+ readonly error?: string;
57
+ readonly interrupts: readonly InterruptRecord[];
58
+ readonly state?: StateValues;
59
+ }
60
+ /**
61
+ * An interrupt record — a pause point waiting for user input.
62
+ */
63
+ export interface InterruptRecord {
64
+ readonly id: string;
65
+ readonly value: unknown;
66
+ readonly resumed: boolean;
67
+ }
68
+ /**
69
+ * Result of resuming a graph from a checkpoint with a Command.
70
+ */
71
+ export interface ResumeResult {
72
+ readonly snapshot: StateSnapshot;
73
+ readonly completed: boolean;
74
+ readonly output?: unknown;
75
+ }
76
+ /**
77
+ * Checkpointer interface — abstract storage for graph snapshots.
78
+ *
79
+ * Implementations can be in-memory (dev), SQLite (production via vinhnt
80
+ * session store), Postgres, MongoDB, Redis, etc.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { SqliteCheckpointer } from "@vinhnt-sdk/durable-state-checkpoint-sqlite";
85
+ * const checkpointer = new SqliteCheckpointer(db);
86
+ * ```
87
+ */
88
+ export interface Checkpointer {
89
+ /** Save a snapshot for a thread. */
90
+ put(config: GraphConfig, snapshot: StateSnapshot): Promise<void>;
91
+ /** Save intermediate writes (node outputs) before the next checkpoint. */
92
+ putWrites(config: GraphConfig, writes: readonly [string, unknown][]): Promise<void>;
93
+ /** Get the latest snapshot for a thread. */
94
+ getTuple(config: GraphConfig): Promise<StateSnapshot | null>;
95
+ /** List snapshots for a thread (newest first). */
96
+ list(threadId: string): Promise<readonly StateSnapshot[]>;
97
+ /** Delete a snapshot (optional — may throw if not supported). */
98
+ delete?(config: GraphConfig): Promise<void>;
99
+ }
100
+ /**
101
+ * In-memory checkpointer — suitable for development and testing. Not durable
102
+ * across process restarts. Use a durable implementation (SQLite, Postgres,
103
+ * etc.) for production.
104
+ */
105
+ export declare class MemoryCheckpointer implements Checkpointer {
106
+ private readonly snapshots;
107
+ private readonly writes;
108
+ private key;
109
+ put(config: GraphConfig, snapshot: StateSnapshot): Promise<void>;
110
+ putWrites(config: GraphConfig, writes: readonly [string, unknown][]): Promise<void>;
111
+ getTuple(config: GraphConfig): Promise<StateSnapshot | null>;
112
+ list(threadId: string): Promise<readonly StateSnapshot[]>;
113
+ delete(config: GraphConfig): Promise<void>;
114
+ }
115
+ /**
116
+ * Create a default MemoryCheckpointer instance.
117
+ */
118
+ export declare function createMemoryCheckpointer(): MemoryCheckpointer;
119
+ /**
120
+ * Serialize a StateSnapshot to a plain JSON-safe object.
121
+ *
122
+ * @internal
123
+ */
124
+ export declare function serializeSnapshot(snapshot: StateSnapshot): unknown;
125
+ /**
126
+ * Deserialize a StateSnapshot from a plain object.
127
+ *
128
+ * @internal
129
+ */
130
+ export declare function deserializeSnapshot(raw: unknown): StateSnapshot;
131
+ /**
132
+ * Create a new StateSnapshot.
133
+ */
134
+ export declare function createSnapshot(config: GraphConfig, values: StateValues, options?: {
135
+ next?: readonly string[];
136
+ metadata?: Record<string, unknown>;
137
+ parentConfig?: GraphConfig | null;
138
+ tasks?: readonly PendingTask[];
139
+ createdAt?: string;
140
+ }): StateSnapshot;
141
+ //# sourceMappingURL=checkpoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint.d.ts","sourceRoot":"","sources":["../../src/state/checkpoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,WAAW;IAC1B,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAA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