@langchain/langgraph-api 1.1.2 → 1.1.8
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/package.json +9 -8
- package/CHANGELOG.md +0 -297
- package/dist/api/assistants.d.mts +0 -3
- package/dist/api/assistants.mjs +0 -193
- package/dist/api/meta.d.mts +0 -3
- package/dist/api/meta.mjs +0 -65
- package/dist/api/runs.d.mts +0 -3
- package/dist/api/runs.mjs +0 -324
- package/dist/api/store.d.mts +0 -3
- package/dist/api/store.mjs +0 -111
- package/dist/api/threads.d.mts +0 -3
- package/dist/api/threads.mjs +0 -143
- package/dist/auth/custom.d.mts +0 -9
- package/dist/auth/custom.mjs +0 -32
- package/dist/auth/index.d.mts +0 -43
- package/dist/auth/index.mjs +0 -163
- package/dist/cli/entrypoint.d.mts +0 -1
- package/dist/cli/entrypoint.mjs +0 -41
- package/dist/cli/spawn.d.mts +0 -42
- package/dist/cli/spawn.mjs +0 -47
- package/dist/cli/utils/ipc/client.d.mts +0 -5
- package/dist/cli/utils/ipc/client.mjs +0 -47
- package/dist/cli/utils/ipc/utils/get-pipe-path.d.mts +0 -1
- package/dist/cli/utils/ipc/utils/get-pipe-path.mjs +0 -29
- package/dist/cli/utils/ipc/utils/temporary-directory.d.mts +0 -5
- package/dist/cli/utils/ipc/utils/temporary-directory.mjs +0 -40
- package/dist/command.d.mts +0 -11
- package/dist/command.mjs +0 -15
- package/dist/experimental/embed.d.mts +0 -42
- package/dist/experimental/embed.mjs +0 -299
- package/dist/graph/api.d.mts +0 -1
- package/dist/graph/api.mjs +0 -2
- package/dist/graph/load.d.mts +0 -19
- package/dist/graph/load.hooks.d.mts +0 -2
- package/dist/graph/load.hooks.mjs +0 -52
- package/dist/graph/load.mjs +0 -96
- package/dist/graph/load.utils.d.mts +0 -22
- package/dist/graph/load.utils.mjs +0 -49
- package/dist/graph/parser/index.d.mts +0 -23
- package/dist/graph/parser/index.mjs +0 -58
- package/dist/graph/parser/parser.d.mts +0 -77
- package/dist/graph/parser/parser.mjs +0 -429
- package/dist/graph/parser/parser.worker.d.mts +0 -1
- package/dist/graph/parser/parser.worker.mjs +0 -7
- package/dist/graph/parser/schema/types.d.mts +0 -154
- package/dist/graph/parser/schema/types.mjs +0 -1496
- package/dist/graph/parser/schema/types.template.d.mts +0 -1
- package/dist/graph/parser/schema/types.template.mts +0 -92
- package/dist/http/custom.d.mts +0 -6
- package/dist/http/custom.mjs +0 -10
- package/dist/http/middleware.d.mts +0 -11
- package/dist/http/middleware.mjs +0 -57
- package/dist/logging.d.mts +0 -10
- package/dist/logging.mjs +0 -115
- package/dist/loopback.d.mts +0 -4
- package/dist/loopback.mjs +0 -10
- package/dist/preload.d.mts +0 -1
- package/dist/preload.mjs +0 -29
- package/dist/queue.d.mts +0 -2
- package/dist/queue.mjs +0 -119
- package/dist/schemas.d.mts +0 -1552
- package/dist/schemas.mjs +0 -492
- package/dist/semver/index.d.mts +0 -15
- package/dist/semver/index.mjs +0 -46
- package/dist/server.d.mts +0 -175
- package/dist/server.mjs +0 -181
- package/dist/state.d.mts +0 -3
- package/dist/state.mjs +0 -30
- package/dist/storage/checkpoint.d.mts +0 -19
- package/dist/storage/checkpoint.mjs +0 -127
- package/dist/storage/context.d.mts +0 -3
- package/dist/storage/context.mjs +0 -11
- package/dist/storage/importMap.d.mts +0 -55
- package/dist/storage/importMap.mjs +0 -55
- package/dist/storage/ops.d.mts +0 -169
- package/dist/storage/ops.mjs +0 -1262
- package/dist/storage/persist.d.mts +0 -18
- package/dist/storage/persist.mjs +0 -81
- package/dist/storage/store.d.mts +0 -17
- package/dist/storage/store.mjs +0 -41
- package/dist/storage/types.d.mts +0 -301
- package/dist/storage/types.mjs +0 -1
- package/dist/stream.d.mts +0 -43
- package/dist/stream.mjs +0 -235
- package/dist/ui/load.d.mts +0 -8
- package/dist/ui/load.mjs +0 -53
- package/dist/utils/abort.d.mts +0 -1
- package/dist/utils/abort.mjs +0 -8
- package/dist/utils/hono.d.mts +0 -5
- package/dist/utils/hono.mjs +0 -24
- package/dist/utils/importMap.d.mts +0 -55
- package/dist/utils/importMap.mjs +0 -55
- package/dist/utils/runnableConfig.d.mts +0 -3
- package/dist/utils/runnableConfig.mjs +0 -45
- package/dist/utils/serde.d.mts +0 -5
- package/dist/utils/serde.mjs +0 -20
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -12
- package/dist/webhook.d.mts +0 -11
- package/dist/webhook.mjs +0 -30
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
import { zValidator } from "@hono/zod-validator";
|
|
3
|
-
import { streamSSE } from "hono/streaming";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
import * as schemas from "../schemas.mjs";
|
|
6
|
-
import { z } from "zod/v3";
|
|
7
|
-
import { streamState } from "../stream.mjs";
|
|
8
|
-
import { serialiseAsDict, serializeError } from "../utils/serde.mjs";
|
|
9
|
-
import { getDisconnectAbortSignal, jsonExtra } from "../utils/hono.mjs";
|
|
10
|
-
import { stateSnapshotToThreadState } from "../state.mjs";
|
|
11
|
-
import { ensureContentType } from "../http/middleware.mjs";
|
|
12
|
-
function createStubRun(threadId, payload) {
|
|
13
|
-
const now = new Date();
|
|
14
|
-
const runId = uuidv4();
|
|
15
|
-
let streamMode = Array.isArray(payload.stream_mode)
|
|
16
|
-
? payload.stream_mode
|
|
17
|
-
: payload.stream_mode
|
|
18
|
-
? [payload.stream_mode]
|
|
19
|
-
: undefined;
|
|
20
|
-
if (streamMode == null || streamMode.length === 0)
|
|
21
|
-
streamMode = ["values"];
|
|
22
|
-
const config = Object.assign({}, payload.config ?? {}, {
|
|
23
|
-
configurable: {
|
|
24
|
-
run_id: runId,
|
|
25
|
-
thread_id: threadId,
|
|
26
|
-
graph_id: payload.assistant_id,
|
|
27
|
-
...(payload.checkpoint_id
|
|
28
|
-
? { checkpoint_id: payload.checkpoint_id }
|
|
29
|
-
: null),
|
|
30
|
-
...payload.checkpoint,
|
|
31
|
-
...(payload.langsmith_tracer
|
|
32
|
-
? {
|
|
33
|
-
langsmith_project: payload.langsmith_tracer.project_name,
|
|
34
|
-
langsmith_example_id: payload.langsmith_tracer.example_id,
|
|
35
|
-
}
|
|
36
|
-
: null),
|
|
37
|
-
},
|
|
38
|
-
}, { metadata: payload.metadata ?? {} });
|
|
39
|
-
return {
|
|
40
|
-
run_id: runId,
|
|
41
|
-
thread_id: threadId,
|
|
42
|
-
assistant_id: payload.assistant_id,
|
|
43
|
-
metadata: payload.metadata ?? {},
|
|
44
|
-
status: "running",
|
|
45
|
-
kwargs: {
|
|
46
|
-
input: payload.input,
|
|
47
|
-
command: payload.command,
|
|
48
|
-
config,
|
|
49
|
-
context: payload.context,
|
|
50
|
-
stream_mode: streamMode,
|
|
51
|
-
interrupt_before: payload.interrupt_before,
|
|
52
|
-
interrupt_after: payload.interrupt_after,
|
|
53
|
-
feedback_keys: payload.feedback_keys,
|
|
54
|
-
subgraphs: payload.stream_subgraphs,
|
|
55
|
-
temporary: false,
|
|
56
|
-
},
|
|
57
|
-
multitask_strategy: "reject",
|
|
58
|
-
created_at: now,
|
|
59
|
-
updated_at: now,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Create a Hono server with a subset of LangGraph Platform routes.
|
|
64
|
-
*
|
|
65
|
-
* @experimental Does not follow semver.
|
|
66
|
-
*/
|
|
67
|
-
export function createEmbedServer(options) {
|
|
68
|
-
async function getGraph(graphId) {
|
|
69
|
-
const targetGraph = options.graph[graphId];
|
|
70
|
-
targetGraph.store = options.store;
|
|
71
|
-
targetGraph.checkpointer = options.checkpointer;
|
|
72
|
-
return targetGraph;
|
|
73
|
-
}
|
|
74
|
-
const api = new Hono();
|
|
75
|
-
api.use(ensureContentType());
|
|
76
|
-
api.post("/threads", zValidator("json", schemas.ThreadCreate), async (c) => {
|
|
77
|
-
// create a new thread
|
|
78
|
-
const payload = c.req.valid("json");
|
|
79
|
-
const threadId = payload.thread_id || uuidv4();
|
|
80
|
-
return jsonExtra(c, await options.threads.set(threadId, {
|
|
81
|
-
kind: "put",
|
|
82
|
-
metadata: payload.metadata,
|
|
83
|
-
}));
|
|
84
|
-
});
|
|
85
|
-
api.get("/threads/:thread_id", zValidator("param", z.object({ thread_id: z.string().uuid() })), async (c) => {
|
|
86
|
-
// Get Thread
|
|
87
|
-
const { thread_id } = c.req.valid("param");
|
|
88
|
-
return jsonExtra(c, await options.threads.get(thread_id));
|
|
89
|
-
});
|
|
90
|
-
api.patch("/threads/:thread_id", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("json", schemas.ThreadCreate), async (c) => {
|
|
91
|
-
// Update Thread
|
|
92
|
-
const { thread_id } = c.req.valid("param");
|
|
93
|
-
const payload = c.req.valid("json");
|
|
94
|
-
return jsonExtra(c, await options.threads.set(thread_id, {
|
|
95
|
-
kind: "patch",
|
|
96
|
-
metadata: payload.metadata,
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
99
|
-
api.delete("/threads/:thread_id", zValidator("param", z.object({ thread_id: z.string().uuid() })), async (c) => {
|
|
100
|
-
// Delete Thread
|
|
101
|
-
const { thread_id } = c.req.valid("param");
|
|
102
|
-
await options.threads.delete(thread_id);
|
|
103
|
-
return new Response(null, { status: 204 });
|
|
104
|
-
});
|
|
105
|
-
api.post("/threads/search", zValidator("json", schemas.ThreadSearchRequest), async (c) => {
|
|
106
|
-
const payload = c.req.valid("json");
|
|
107
|
-
const result = [];
|
|
108
|
-
if (!options.threads.search)
|
|
109
|
-
return c.json({ error: "Threads search not implemented" }, 422);
|
|
110
|
-
const sortBy = payload.sort_by === "created_at" || payload.sort_by === "updated_at"
|
|
111
|
-
? payload.sort_by
|
|
112
|
-
: "created_at";
|
|
113
|
-
let total = 0;
|
|
114
|
-
for await (const item of options.threads.search({
|
|
115
|
-
metadata: payload.metadata,
|
|
116
|
-
limit: payload.limit ?? 10,
|
|
117
|
-
offset: payload.offset ?? 0,
|
|
118
|
-
sortBy,
|
|
119
|
-
sortOrder: payload.sort_order ?? "desc",
|
|
120
|
-
})) {
|
|
121
|
-
result.push(item.thread);
|
|
122
|
-
// Only set total if it's the first item
|
|
123
|
-
if (total === 0)
|
|
124
|
-
total = item.total;
|
|
125
|
-
}
|
|
126
|
-
c.res.headers.set("X-Pagination-Total", total.toString());
|
|
127
|
-
return jsonExtra(c, result);
|
|
128
|
-
});
|
|
129
|
-
api.get("/threads/:thread_id/state", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("query", z.object({ subgraphs: schemas.coercedBoolean.optional() })), async (c) => {
|
|
130
|
-
// Get Latest Thread State
|
|
131
|
-
const { thread_id } = c.req.valid("param");
|
|
132
|
-
const { subgraphs } = c.req.valid("query");
|
|
133
|
-
const thread = await options.threads.get(thread_id);
|
|
134
|
-
const graphId = thread.metadata?.graph_id;
|
|
135
|
-
const graph = graphId ? await getGraph(graphId) : undefined;
|
|
136
|
-
if (graph == null) {
|
|
137
|
-
return jsonExtra(c, stateSnapshotToThreadState({
|
|
138
|
-
values: {},
|
|
139
|
-
next: [],
|
|
140
|
-
config: {},
|
|
141
|
-
metadata: undefined,
|
|
142
|
-
createdAt: undefined,
|
|
143
|
-
parentConfig: undefined,
|
|
144
|
-
tasks: [],
|
|
145
|
-
}));
|
|
146
|
-
}
|
|
147
|
-
const config = { configurable: { thread_id } };
|
|
148
|
-
const result = await graph.getState(config, { subgraphs });
|
|
149
|
-
return jsonExtra(c, stateSnapshotToThreadState(result));
|
|
150
|
-
});
|
|
151
|
-
api.post("/threads/:thread_id/state", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("json", schemas.ThreadStateUpdate), async (c) => {
|
|
152
|
-
// Update Thread State
|
|
153
|
-
const { thread_id } = c.req.valid("param");
|
|
154
|
-
const payload = c.req.valid("json");
|
|
155
|
-
const config = { configurable: { thread_id } };
|
|
156
|
-
config.configurable ??= {};
|
|
157
|
-
if (payload.checkpoint_id) {
|
|
158
|
-
config.configurable.checkpoint_id = payload.checkpoint_id;
|
|
159
|
-
}
|
|
160
|
-
if (payload.checkpoint) {
|
|
161
|
-
Object.assign(config.configurable, payload.checkpoint);
|
|
162
|
-
}
|
|
163
|
-
const thread = await options.threads.get(thread_id);
|
|
164
|
-
const graphId = thread.metadata?.graph_id;
|
|
165
|
-
const graph = graphId ? await getGraph(graphId) : undefined;
|
|
166
|
-
if (graph == null)
|
|
167
|
-
return c.json({ error: "Graph not found" }, 404);
|
|
168
|
-
const result = await graph.updateState(config, payload.values, payload.as_node);
|
|
169
|
-
return jsonExtra(c, { checkpoint: result.configurable });
|
|
170
|
-
});
|
|
171
|
-
// get thread state at checkpoint
|
|
172
|
-
api.get("/threads/:thread_id/state/:checkpoint_id", zValidator("param", z.object({
|
|
173
|
-
thread_id: z.string().uuid(),
|
|
174
|
-
checkpoint_id: z.string().uuid(),
|
|
175
|
-
})), zValidator("query", z.object({ subgraphs: schemas.coercedBoolean.optional() })), async (c) => {
|
|
176
|
-
// Get Thread State At Checkpoint
|
|
177
|
-
const { thread_id, checkpoint_id } = c.req.valid("param");
|
|
178
|
-
const { subgraphs } = c.req.valid("query");
|
|
179
|
-
const thread = await options.threads.get(thread_id);
|
|
180
|
-
const graphId = thread.metadata?.graph_id;
|
|
181
|
-
const graph = graphId ? await getGraph(graphId) : undefined;
|
|
182
|
-
if (graph == null)
|
|
183
|
-
return c.json({ error: "Graph not found" }, 404);
|
|
184
|
-
const result = await graph.getState({ configurable: { thread_id, checkpoint_id } }, { subgraphs });
|
|
185
|
-
return jsonExtra(c, stateSnapshotToThreadState(result));
|
|
186
|
-
});
|
|
187
|
-
api.post("/threads/:thread_id/state/checkpoint", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("json", z.object({
|
|
188
|
-
subgraphs: schemas.coercedBoolean.optional(),
|
|
189
|
-
checkpoint: schemas.CheckpointSchema.nullish(),
|
|
190
|
-
})), async (c) => {
|
|
191
|
-
// Get Thread State At Checkpoint post
|
|
192
|
-
const { thread_id } = c.req.valid("param");
|
|
193
|
-
const { checkpoint, subgraphs } = c.req.valid("json");
|
|
194
|
-
const thread = await options.threads.get(thread_id);
|
|
195
|
-
const graphId = thread.metadata?.graph_id;
|
|
196
|
-
const graph = graphId ? await getGraph(graphId) : undefined;
|
|
197
|
-
if (graph == null)
|
|
198
|
-
return c.json({ error: "Graph not found" }, 404);
|
|
199
|
-
const result = await graph.getState({ configurable: { thread_id, ...checkpoint } }, { subgraphs });
|
|
200
|
-
return jsonExtra(c, stateSnapshotToThreadState(result));
|
|
201
|
-
});
|
|
202
|
-
api.post("/threads/:thread_id/history", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("json", schemas.ThreadHistoryRequest), async (c) => {
|
|
203
|
-
// Get Thread History Post
|
|
204
|
-
const { thread_id } = c.req.valid("param");
|
|
205
|
-
const { limit, before, metadata, checkpoint } = c.req.valid("json");
|
|
206
|
-
const thread = await options.threads.get(thread_id);
|
|
207
|
-
const graphId = thread.metadata?.graph_id;
|
|
208
|
-
const graph = graphId ? await getGraph(graphId) : undefined;
|
|
209
|
-
if (graph == null)
|
|
210
|
-
return jsonExtra(c, []);
|
|
211
|
-
const config = { configurable: { thread_id, ...checkpoint } };
|
|
212
|
-
const result = [];
|
|
213
|
-
const beforeConfig = typeof before === "string"
|
|
214
|
-
? { configurable: { checkpoint_id: before } }
|
|
215
|
-
: before;
|
|
216
|
-
for await (const state of graph.getStateHistory(config, {
|
|
217
|
-
limit,
|
|
218
|
-
before: beforeConfig,
|
|
219
|
-
filter: metadata,
|
|
220
|
-
})) {
|
|
221
|
-
result.push(stateSnapshotToThreadState(state));
|
|
222
|
-
}
|
|
223
|
-
return jsonExtra(c, result);
|
|
224
|
-
});
|
|
225
|
-
api.post("/threads/:thread_id/runs/stream", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("json", schemas.RunCreate), async (c) => {
|
|
226
|
-
// Stream Run
|
|
227
|
-
const { thread_id } = c.req.valid("param");
|
|
228
|
-
const payload = c.req.valid("json");
|
|
229
|
-
const thread = await options.threads.get(thread_id);
|
|
230
|
-
if (thread == null)
|
|
231
|
-
return c.json({ error: "Thread not found" }, 404);
|
|
232
|
-
return streamSSE(c, async (stream) => {
|
|
233
|
-
const signal = getDisconnectAbortSignal(c, stream);
|
|
234
|
-
const run = createStubRun(thread_id, payload);
|
|
235
|
-
await options.threads.set(thread_id, {
|
|
236
|
-
kind: "patch",
|
|
237
|
-
metadata: {
|
|
238
|
-
graph_id: payload.assistant_id,
|
|
239
|
-
assistant_id: payload.assistant_id,
|
|
240
|
-
},
|
|
241
|
-
});
|
|
242
|
-
try {
|
|
243
|
-
for await (const { event, data } of streamState(run, {
|
|
244
|
-
attempt: 1,
|
|
245
|
-
getGraph,
|
|
246
|
-
signal,
|
|
247
|
-
})) {
|
|
248
|
-
await stream.writeSSE({ data: serialiseAsDict(data), event });
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
catch (error) {
|
|
252
|
-
await stream.writeSSE({
|
|
253
|
-
data: serialiseAsDict(serializeError(error)),
|
|
254
|
-
event: "error",
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
api.post("/runs/stream", zValidator("json", schemas.RunCreate), async (c) => {
|
|
260
|
-
// Stream Stateless Run
|
|
261
|
-
return streamSSE(c, async (stream) => {
|
|
262
|
-
const payload = c.req.valid("json");
|
|
263
|
-
const signal = getDisconnectAbortSignal(c, stream);
|
|
264
|
-
const threadId = uuidv4();
|
|
265
|
-
await options.threads.set(threadId, {
|
|
266
|
-
kind: "put",
|
|
267
|
-
metadata: {
|
|
268
|
-
graph_id: payload.assistant_id,
|
|
269
|
-
assistant_id: payload.assistant_id,
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
try {
|
|
273
|
-
const run = createStubRun(threadId, payload);
|
|
274
|
-
try {
|
|
275
|
-
for await (const { event, data } of streamState(run, {
|
|
276
|
-
attempt: 1,
|
|
277
|
-
getGraph,
|
|
278
|
-
signal,
|
|
279
|
-
})) {
|
|
280
|
-
await stream.writeSSE({ data: serialiseAsDict(data), event });
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
catch (error) {
|
|
284
|
-
await stream.writeSSE({
|
|
285
|
-
data: serialiseAsDict(serializeError(error)),
|
|
286
|
-
event: "error",
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
finally {
|
|
291
|
-
await options.threads.delete(threadId);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
api.notFound((c) => {
|
|
296
|
-
return c.json({ error: `${c.req.method} ${c.req.path} not implemented` }, 404);
|
|
297
|
-
});
|
|
298
|
-
return api;
|
|
299
|
-
}
|
package/dist/graph/api.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { assertGraphExists, getAssistantId, getGraph, getGraphKeys, } from "./load.mjs";
|
package/dist/graph/api.mjs
DELETED
package/dist/graph/load.d.mts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AssistantsRepo } from "../storage/types.mjs";
|
|
2
|
-
import type { BaseCheckpointSaver, BaseStore, CompiledGraph, LangGraphRunnableConfig } from "@langchain/langgraph";
|
|
3
|
-
import { type CompiledGraphFactory } from "./load.utils.mjs";
|
|
4
|
-
import type { GraphSchema, GraphSpec } from "./parser/index.mjs";
|
|
5
|
-
export declare const GRAPHS: Record<string, CompiledGraph<string> | CompiledGraphFactory<string>>;
|
|
6
|
-
export declare const GRAPH_SPEC: Record<string, GraphSpec>;
|
|
7
|
-
export declare const GRAPH_SCHEMA: Record<string, Record<string, GraphSchema>>;
|
|
8
|
-
export declare const NAMESPACE_GRAPH: Uint8Array<ArrayBufferLike>;
|
|
9
|
-
export declare const getAssistantId: (graphId: string) => string;
|
|
10
|
-
export declare function registerFromEnv(assistants: AssistantsRepo, specs: Record<string, string>, options: {
|
|
11
|
-
cwd: string;
|
|
12
|
-
}): Promise<(CompiledGraph<string, any, any, Record<string, any>, any, any, unknown, unknown, any> | CompiledGraphFactory<string>)[]>;
|
|
13
|
-
export declare function getGraph(graphId: string, config: LangGraphRunnableConfig | undefined, options?: {
|
|
14
|
-
checkpointer?: BaseCheckpointSaver | null;
|
|
15
|
-
store?: BaseStore;
|
|
16
|
-
}): Promise<CompiledGraph<string, any, any, Record<string, any>, any, any, unknown, unknown, any>>;
|
|
17
|
-
export declare function assertGraphExists(graphId: string): void;
|
|
18
|
-
export declare function getGraphKeys(): string[];
|
|
19
|
-
export declare function getCachedStaticGraphSchema(graphId: string): Promise<Record<string, GraphSchema>>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// This module hook is used to ensure that @langchain/langgraph package
|
|
2
|
-
// is imported from a consistent location.
|
|
3
|
-
// Accepts `{ parentURL: string }` as argument when registering the hook.
|
|
4
|
-
const OVERRIDE_RESOLVE = [
|
|
5
|
-
// Override `@langchain/langgraph` or `@langchain/langgraph/prebuilt`,
|
|
6
|
-
// but not `@langchain/langgraph-sdk`
|
|
7
|
-
new RegExp(`^@langchain\/langgraph(\/.+)?$`),
|
|
8
|
-
new RegExp(`^@langchain\/langgraph-checkpoint(\/.+)?$`),
|
|
9
|
-
];
|
|
10
|
-
let parentURL;
|
|
11
|
-
let langgraphPackageURL;
|
|
12
|
-
export async function initialize(args) {
|
|
13
|
-
parentURL = args.parentURL;
|
|
14
|
-
}
|
|
15
|
-
export async function resolve(specifier, context, nextResolve) {
|
|
16
|
-
// HACK: @tailwindcss/node internally uses an ESM loader cache, which does not play nicely with `tsx`.
|
|
17
|
-
// Node.js crashes with "TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file".
|
|
18
|
-
// As it already is a valid URI, we can just short-circuit the resolution and avoid `tsx`.
|
|
19
|
-
if (specifier.includes("@tailwindcss/node/dist/esm-cache.loader") &&
|
|
20
|
-
specifier.startsWith("file://")) {
|
|
21
|
-
return {
|
|
22
|
-
shortCircuit: true,
|
|
23
|
-
// Node 18.x will for some reason attempt to load `.mts` instead of `.mjs`
|
|
24
|
-
url: specifier.replace(".mts", ".mjs"),
|
|
25
|
-
format: "module",
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
if (specifier === "@langchain/langgraph-checkpoint") {
|
|
29
|
-
// resolve relative to @langchain/langgraph package instead
|
|
30
|
-
// This is done to avoid adding a direct dependency on @langchain/langgraph-checkpoint
|
|
31
|
-
// in project, which if not present will cause `pnpm` to not find the package.
|
|
32
|
-
if (!langgraphPackageURL) {
|
|
33
|
-
const main = await nextResolve("@langchain/langgraph", {
|
|
34
|
-
...context,
|
|
35
|
-
parentURL,
|
|
36
|
-
});
|
|
37
|
-
langgraphPackageURL = main.url.toString();
|
|
38
|
-
}
|
|
39
|
-
return await nextResolve(specifier, {
|
|
40
|
-
...context,
|
|
41
|
-
parentURL: langgraphPackageURL,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (OVERRIDE_RESOLVE.some((regex) => regex.test(specifier))) {
|
|
45
|
-
const resolved = await nextResolve(specifier, { ...context, parentURL });
|
|
46
|
-
// If @langchain/langgraph is resolved first, cache it!
|
|
47
|
-
if (specifier === "@langchain/langgraph" && !langgraphPackageURL) {
|
|
48
|
-
langgraphPackageURL = resolved.url.toString();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return nextResolve(specifier, context);
|
|
52
|
-
}
|
package/dist/graph/load.mjs
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { z } from "zod/v3";
|
|
2
|
-
import * as uuid from "uuid";
|
|
3
|
-
import { HTTPException } from "hono/http-exception";
|
|
4
|
-
import { resolveGraph } from "./load.utils.mjs";
|
|
5
|
-
import { getStaticGraphSchema } from "./parser/index.mjs";
|
|
6
|
-
import { checkpointer } from "../storage/checkpoint.mjs";
|
|
7
|
-
import { store } from "../storage/store.mjs";
|
|
8
|
-
import { logger } from "../logging.mjs";
|
|
9
|
-
export const GRAPHS = {};
|
|
10
|
-
export const GRAPH_SPEC = {};
|
|
11
|
-
export const GRAPH_SCHEMA = {};
|
|
12
|
-
export const NAMESPACE_GRAPH = uuid.parse("6ba7b821-9dad-11d1-80b4-00c04fd430c8");
|
|
13
|
-
const ConfigSchema = z.record(z.record(z.unknown()));
|
|
14
|
-
export const getAssistantId = (graphId) => {
|
|
15
|
-
if (graphId in GRAPHS)
|
|
16
|
-
return uuid.v5(graphId, NAMESPACE_GRAPH);
|
|
17
|
-
return graphId;
|
|
18
|
-
};
|
|
19
|
-
export async function registerFromEnv(assistants, specs, options) {
|
|
20
|
-
const envConfig = process.env.LANGGRAPH_CONFIG
|
|
21
|
-
? ConfigSchema.parse(JSON.parse(process.env.LANGGRAPH_CONFIG))
|
|
22
|
-
: undefined;
|
|
23
|
-
return await Promise.all(Object.entries(specs).map(async ([graphId, rawSpec]) => {
|
|
24
|
-
logger.info(`Registering graph with id '${graphId}'`, {
|
|
25
|
-
graph_id: graphId,
|
|
26
|
-
});
|
|
27
|
-
const { context, ...config } = envConfig?.[graphId] ?? {};
|
|
28
|
-
const { resolved, ...spec } = await resolveGraph(rawSpec, {
|
|
29
|
-
cwd: options.cwd,
|
|
30
|
-
});
|
|
31
|
-
// registering the graph runtime
|
|
32
|
-
GRAPHS[graphId] = resolved;
|
|
33
|
-
GRAPH_SPEC[graphId] = spec;
|
|
34
|
-
await assistants.put(uuid.v5(graphId, NAMESPACE_GRAPH), {
|
|
35
|
-
graph_id: graphId,
|
|
36
|
-
metadata: { created_by: "system" },
|
|
37
|
-
config,
|
|
38
|
-
context,
|
|
39
|
-
if_exists: "do_nothing",
|
|
40
|
-
name: graphId,
|
|
41
|
-
}, undefined);
|
|
42
|
-
return resolved;
|
|
43
|
-
}));
|
|
44
|
-
}
|
|
45
|
-
export async function getGraph(graphId, config, options) {
|
|
46
|
-
assertGraphExists(graphId);
|
|
47
|
-
const compiled = typeof GRAPHS[graphId] === "function"
|
|
48
|
-
? await GRAPHS[graphId](config ?? { configurable: {} })
|
|
49
|
-
: GRAPHS[graphId];
|
|
50
|
-
if (typeof options?.checkpointer !== "undefined") {
|
|
51
|
-
compiled.checkpointer = options?.checkpointer ?? undefined;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
compiled.checkpointer = checkpointer;
|
|
55
|
-
}
|
|
56
|
-
compiled.store = options?.store ?? store;
|
|
57
|
-
return compiled;
|
|
58
|
-
}
|
|
59
|
-
export function assertGraphExists(graphId) {
|
|
60
|
-
if (!GRAPHS[graphId])
|
|
61
|
-
throw new HTTPException(404, {
|
|
62
|
-
message: `Graph "${graphId}" not found`,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
export function getGraphKeys() {
|
|
66
|
-
return Object.keys(GRAPHS);
|
|
67
|
-
}
|
|
68
|
-
export async function getCachedStaticGraphSchema(graphId) {
|
|
69
|
-
if (!GRAPH_SPEC[graphId])
|
|
70
|
-
throw new HTTPException(404, {
|
|
71
|
-
message: `Spec for "${graphId}" not found`,
|
|
72
|
-
});
|
|
73
|
-
if (!GRAPH_SCHEMA[graphId]) {
|
|
74
|
-
let timeoutMs = 30_000;
|
|
75
|
-
try {
|
|
76
|
-
const envTimeout = Number.parseInt(process.env.LANGGRAPH_SCHEMA_RESOLVE_TIMEOUT_MS ?? "0", 10);
|
|
77
|
-
if (!Number.isNaN(envTimeout) && envTimeout > 0) {
|
|
78
|
-
timeoutMs = envTimeout;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// ignore
|
|
83
|
-
}
|
|
84
|
-
try {
|
|
85
|
-
GRAPH_SCHEMA[graphId] = await getStaticGraphSchema(GRAPH_SPEC[graphId], {
|
|
86
|
-
timeoutMs,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
throw new Error(`Failed to extract schema for "${graphId}"`, {
|
|
91
|
-
cause: error,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return GRAPH_SCHEMA[graphId];
|
|
96
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { CompiledGraph } from "@langchain/langgraph";
|
|
2
|
-
export declare const GRAPHS: Record<string, CompiledGraph<string>>;
|
|
3
|
-
export declare const NAMESPACE_GRAPH: Uint8Array<ArrayBufferLike>;
|
|
4
|
-
export type CompiledGraphFactory<T extends string> = (config: {
|
|
5
|
-
configurable?: Record<string, unknown>;
|
|
6
|
-
}) => Promise<CompiledGraph<T>>;
|
|
7
|
-
export declare function resolveGraph(spec: string, options: {
|
|
8
|
-
cwd: string;
|
|
9
|
-
onlyFilePresence?: false;
|
|
10
|
-
}): Promise<{
|
|
11
|
-
sourceFile: string;
|
|
12
|
-
exportSymbol: string;
|
|
13
|
-
resolved: CompiledGraph<string> | CompiledGraphFactory<string>;
|
|
14
|
-
}>;
|
|
15
|
-
export declare function resolveGraph(spec: string, options: {
|
|
16
|
-
cwd: string;
|
|
17
|
-
onlyFilePresence: true;
|
|
18
|
-
}): Promise<{
|
|
19
|
-
sourceFile: string;
|
|
20
|
-
exportSymbol: string;
|
|
21
|
-
resolved: undefined;
|
|
22
|
-
}>;
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import * as uuid from "uuid";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
import * as fs from "node:fs/promises";
|
|
4
|
-
import { pathToFileURL } from "node:url";
|
|
5
|
-
export const GRAPHS = {};
|
|
6
|
-
export const NAMESPACE_GRAPH = uuid.parse("6ba7b821-9dad-11d1-80b4-00c04fd430c8");
|
|
7
|
-
export async function resolveGraph(spec, options) {
|
|
8
|
-
const [userFile, exportSymbol] = spec.split(":", 2);
|
|
9
|
-
const sourceFile = path.resolve(options.cwd, userFile);
|
|
10
|
-
// validate file exists
|
|
11
|
-
await fs.stat(sourceFile);
|
|
12
|
-
if (options?.onlyFilePresence) {
|
|
13
|
-
return { sourceFile, exportSymbol, resolved: undefined };
|
|
14
|
-
}
|
|
15
|
-
const isGraph = (graph) => {
|
|
16
|
-
if (typeof graph !== "object" || graph == null)
|
|
17
|
-
return false;
|
|
18
|
-
return "compile" in graph && typeof graph.compile === "function";
|
|
19
|
-
};
|
|
20
|
-
const isCompiledGraph = (graph) => {
|
|
21
|
-
if (typeof graph !== "object" || graph == null)
|
|
22
|
-
return false;
|
|
23
|
-
return ("builder" in graph &&
|
|
24
|
-
typeof graph.builder === "object" &&
|
|
25
|
-
graph.builder != null);
|
|
26
|
-
};
|
|
27
|
-
const graph = await import(pathToFileURL(sourceFile).toString()).then((module) => module[exportSymbol || "default"]);
|
|
28
|
-
// obtain the graph, and if not compiled, compile it
|
|
29
|
-
const resolved = await (async () => {
|
|
30
|
-
if (!graph)
|
|
31
|
-
throw new Error("Failed to load graph: graph is nullush");
|
|
32
|
-
const afterResolve = (graphLike) => {
|
|
33
|
-
const graph = isGraph(graphLike) ? graphLike.compile() : graphLike;
|
|
34
|
-
// TODO: hack, remove once LangChain 1.x createAgent is fixed
|
|
35
|
-
if (!isCompiledGraph(graph) && "graph" in graph) {
|
|
36
|
-
return graph.graph;
|
|
37
|
-
}
|
|
38
|
-
return graph;
|
|
39
|
-
};
|
|
40
|
-
if (typeof graph === "function") {
|
|
41
|
-
return async (config) => {
|
|
42
|
-
const graphLike = await graph(config);
|
|
43
|
-
return afterResolve(graphLike);
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
return afterResolve(await graph);
|
|
47
|
-
})();
|
|
48
|
-
return { sourceFile, exportSymbol, resolved };
|
|
49
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { JSONSchema7 } from "json-schema";
|
|
2
|
-
import type { Pregel } from "@langchain/langgraph";
|
|
3
|
-
export interface GraphSchema {
|
|
4
|
-
state: JSONSchema7 | undefined;
|
|
5
|
-
input: JSONSchema7 | undefined;
|
|
6
|
-
output: JSONSchema7 | undefined;
|
|
7
|
-
config: JSONSchema7 | undefined;
|
|
8
|
-
}
|
|
9
|
-
export interface GraphSpec {
|
|
10
|
-
sourceFile: string;
|
|
11
|
-
exportSymbol: string;
|
|
12
|
-
}
|
|
13
|
-
type GraphSchemaWithSubgraphs = Record<string, GraphSchema>;
|
|
14
|
-
export declare function getStaticGraphSchema(spec: GraphSpec, options?: {
|
|
15
|
-
mainThread?: boolean;
|
|
16
|
-
timeoutMs?: number;
|
|
17
|
-
}): Promise<GraphSchemaWithSubgraphs>;
|
|
18
|
-
export declare function getStaticGraphSchema(specMap: Record<string, GraphSpec>, options?: {
|
|
19
|
-
mainThread?: boolean;
|
|
20
|
-
timeoutMs?: number;
|
|
21
|
-
}): Promise<Record<string, GraphSchemaWithSubgraphs>>;
|
|
22
|
-
export declare function getRuntimeGraphSchema(graph: Pregel<any, any, any, any, any>): Promise<GraphSchema | undefined>;
|
|
23
|
-
export {};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from "node:url";
|
|
2
|
-
import { Worker } from "node:worker_threads";
|
|
3
|
-
const isGraphSpec = (spec) => {
|
|
4
|
-
if (typeof spec !== "object" || spec == null)
|
|
5
|
-
return false;
|
|
6
|
-
if (!("sourceFile" in spec) || typeof spec.sourceFile !== "string")
|
|
7
|
-
return false;
|
|
8
|
-
if (!("exportSymbol" in spec) || typeof spec.exportSymbol !== "string")
|
|
9
|
-
return false;
|
|
10
|
-
return true;
|
|
11
|
-
};
|
|
12
|
-
export async function getStaticGraphSchema(input, options) {
|
|
13
|
-
async function execute(specs) {
|
|
14
|
-
if (options?.mainThread) {
|
|
15
|
-
const { SubgraphExtractor } = await import("./parser.mjs");
|
|
16
|
-
return SubgraphExtractor.extractSchemas(specs, { strict: false });
|
|
17
|
-
}
|
|
18
|
-
return await new Promise((resolve, reject) => {
|
|
19
|
-
const worker = new Worker(fileURLToPath(new URL("./parser.worker.mjs", import.meta.url)), { argv: process.argv.slice(-1) });
|
|
20
|
-
// Set a timeout to reject if the worker takes too long
|
|
21
|
-
const timeoutId = setTimeout(() => {
|
|
22
|
-
worker.terminate();
|
|
23
|
-
reject(new Error("Schema extract worker timed out"));
|
|
24
|
-
}, options?.timeoutMs ?? 30000);
|
|
25
|
-
worker.on("message", (result) => {
|
|
26
|
-
worker.terminate();
|
|
27
|
-
clearTimeout(timeoutId);
|
|
28
|
-
resolve(result);
|
|
29
|
-
});
|
|
30
|
-
worker.on("error", reject);
|
|
31
|
-
worker.postMessage(specs);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
const specs = isGraphSpec(input) ? [input] : Object.values(input);
|
|
35
|
-
const results = await execute(specs);
|
|
36
|
-
if (isGraphSpec(input)) {
|
|
37
|
-
return results[0];
|
|
38
|
-
}
|
|
39
|
-
return Object.fromEntries(Object.keys(input).map((graphId, idx) => [graphId, results[idx]]));
|
|
40
|
-
}
|
|
41
|
-
export async function getRuntimeGraphSchema(graph) {
|
|
42
|
-
try {
|
|
43
|
-
const { getInputTypeSchema, getOutputTypeSchema, getUpdateTypeSchema, getConfigTypeSchema, } = await import("@langchain/langgraph/zod/schema");
|
|
44
|
-
const result = {
|
|
45
|
-
state: getUpdateTypeSchema(graph),
|
|
46
|
-
input: getInputTypeSchema(graph),
|
|
47
|
-
output: getOutputTypeSchema(graph),
|
|
48
|
-
config: getConfigTypeSchema(graph),
|
|
49
|
-
};
|
|
50
|
-
if (Object.values(result).every((i) => i == null))
|
|
51
|
-
return undefined;
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
// ignore
|
|
56
|
-
}
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|