ai-sdk-graph 0.1.1 → 0.1.2
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.
- package/dist/graph.d.ts +9 -2
- package/dist/index.js +16 -5
- package/package.json +6 -2
package/dist/graph.d.ts
CHANGED
|
@@ -12,7 +12,11 @@ export declare class Graph<State extends Record<string, unknown>, NodeKeys exten
|
|
|
12
12
|
private readonly storage;
|
|
13
13
|
private readonly emitter;
|
|
14
14
|
private readonly stateManager;
|
|
15
|
-
|
|
15
|
+
private readonly onFinish;
|
|
16
|
+
constructor(options?: {
|
|
17
|
+
storage?: GraphSDK.GraphStorage<State, NodeKeys>;
|
|
18
|
+
onFinish?: (state: State) => Promise<void> | void;
|
|
19
|
+
});
|
|
16
20
|
node<NewKey extends string>(id: NewKey, execute: ({ state, writer, suspense, update }: {
|
|
17
21
|
state: () => Readonly<State>;
|
|
18
22
|
writer: Writer;
|
|
@@ -65,5 +69,8 @@ export declare class Graph<State extends Record<string, unknown>, NodeKeys exten
|
|
|
65
69
|
private deduplicateNodes;
|
|
66
70
|
private excludeTerminalNodes;
|
|
67
71
|
}
|
|
68
|
-
export declare function graph<State extends Record<string, unknown>, NodeKeys extends string = 'START' | 'END'>(
|
|
72
|
+
export declare function graph<State extends Record<string, unknown>, NodeKeys extends string = 'START' | 'END'>(options?: {
|
|
73
|
+
storage?: GraphSDK.GraphStorage<State, NodeKeys>;
|
|
74
|
+
onFinish?: (state: State) => Promise<void> | void;
|
|
75
|
+
}): Graph<State, NodeKeys>;
|
|
69
76
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -54,9 +54,11 @@ class Graph {
|
|
|
54
54
|
storage;
|
|
55
55
|
emitter = new NodeEventEmitter;
|
|
56
56
|
stateManager = new StateManager;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
onFinish;
|
|
58
|
+
constructor(options = {}) {
|
|
59
|
+
this.storage = options.storage ?? new InMemoryStorage;
|
|
59
60
|
this.registerBuiltInNodes();
|
|
61
|
+
this.onFinish = options.onFinish ?? ((state) => {});
|
|
60
62
|
}
|
|
61
63
|
node(id, execute) {
|
|
62
64
|
const node = { id, execute };
|
|
@@ -144,10 +146,16 @@ class Graph {
|
|
|
144
146
|
});
|
|
145
147
|
}
|
|
146
148
|
execute(runId, initialState) {
|
|
149
|
+
let context;
|
|
147
150
|
return createUIMessageStream({
|
|
148
151
|
execute: async ({ writer }) => {
|
|
149
|
-
|
|
152
|
+
context = await this.createExecutionContext(runId, initialState, writer);
|
|
150
153
|
await this.runExecutionLoop(context);
|
|
154
|
+
},
|
|
155
|
+
onFinish: async () => {
|
|
156
|
+
if (context) {
|
|
157
|
+
await this.onFinish(context.state);
|
|
158
|
+
}
|
|
151
159
|
}
|
|
152
160
|
});
|
|
153
161
|
}
|
|
@@ -337,8 +345,11 @@ class Graph {
|
|
|
337
345
|
return nodes.filter((node) => node.id !== BUILT_IN_NODES.END);
|
|
338
346
|
}
|
|
339
347
|
}
|
|
340
|
-
function graph(
|
|
341
|
-
return new Graph(
|
|
348
|
+
function graph(options = {}) {
|
|
349
|
+
return new Graph({
|
|
350
|
+
storage: options.storage,
|
|
351
|
+
onFinish: options.onFinish
|
|
352
|
+
});
|
|
342
353
|
}
|
|
343
354
|
|
|
344
355
|
class NodeEventEmitter {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ai-sdk-graph",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Graph-based workflows for the AI SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -18,9 +18,13 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "bun test",
|
|
21
|
-
"build": "bun build src/index.ts --outdir dist --target node --packages=external && tsc -p tsconfig.build.json"
|
|
21
|
+
"build": "bun build src/index.ts --outdir dist --target node --packages=external && tsc -p tsconfig.build.json",
|
|
22
|
+
"changeset": "changeset",
|
|
23
|
+
"version": "changeset version",
|
|
24
|
+
"release": "bun run build && changeset publish"
|
|
22
25
|
},
|
|
23
26
|
"devDependencies": {
|
|
27
|
+
"@changesets/cli": "^2.29.8",
|
|
24
28
|
"@types/bun": "latest"
|
|
25
29
|
},
|
|
26
30
|
"peerDependencies": {
|