@langchain/langgraph-api 1.1.1 → 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 +10 -9
- package/CHANGELOG.md +0 -290
- 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
package/dist/server.d.mts
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import type { Ops } from "./storage/types.mjs";
|
|
2
|
-
import { z } from "zod/v3";
|
|
3
|
-
export declare const StartServerSchema: z.ZodObject<{
|
|
4
|
-
port: z.ZodNumber;
|
|
5
|
-
nWorkers: z.ZodNumber;
|
|
6
|
-
host: z.ZodString;
|
|
7
|
-
cwd: z.ZodString;
|
|
8
|
-
graphs: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
9
|
-
path: z.ZodString;
|
|
10
|
-
description: z.ZodOptional<z.ZodString>;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
path: string;
|
|
13
|
-
description?: string | undefined;
|
|
14
|
-
}, {
|
|
15
|
-
path: string;
|
|
16
|
-
description?: string | undefined;
|
|
17
|
-
}>]>>;
|
|
18
|
-
auth: z.ZodOptional<z.ZodObject<{
|
|
19
|
-
path: z.ZodOptional<z.ZodString>;
|
|
20
|
-
disable_studio_auth: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
disable_studio_auth: boolean;
|
|
23
|
-
path?: string | undefined;
|
|
24
|
-
}, {
|
|
25
|
-
path?: string | undefined;
|
|
26
|
-
disable_studio_auth?: boolean | undefined;
|
|
27
|
-
}>>;
|
|
28
|
-
ui: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
29
|
-
ui_config: z.ZodOptional<z.ZodObject<{
|
|
30
|
-
shared: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
31
|
-
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
shared?: string[] | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
shared?: string[] | undefined;
|
|
35
|
-
}>>;
|
|
36
|
-
http: z.ZodOptional<z.ZodObject<{
|
|
37
|
-
app: z.ZodOptional<z.ZodString>;
|
|
38
|
-
disable_assistants: z.ZodDefault<z.ZodBoolean>;
|
|
39
|
-
disable_threads: z.ZodDefault<z.ZodBoolean>;
|
|
40
|
-
disable_runs: z.ZodDefault<z.ZodBoolean>;
|
|
41
|
-
disable_store: z.ZodDefault<z.ZodBoolean>;
|
|
42
|
-
disable_meta: z.ZodDefault<z.ZodBoolean>;
|
|
43
|
-
cors: z.ZodOptional<z.ZodObject<{
|
|
44
|
-
allow_origins: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
45
|
-
allow_methods: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
46
|
-
allow_headers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
47
|
-
allow_credentials: z.ZodOptional<z.ZodBoolean>;
|
|
48
|
-
allow_origin_regex: z.ZodOptional<z.ZodString>;
|
|
49
|
-
expose_headers: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
50
|
-
max_age: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
}, "strip", z.ZodTypeAny, {
|
|
52
|
-
allow_origin_regex?: string | undefined;
|
|
53
|
-
expose_headers?: string[] | undefined;
|
|
54
|
-
max_age?: number | undefined;
|
|
55
|
-
allow_methods?: string[] | undefined;
|
|
56
|
-
allow_headers?: string[] | undefined;
|
|
57
|
-
allow_credentials?: boolean | undefined;
|
|
58
|
-
allow_origins?: string[] | undefined;
|
|
59
|
-
}, {
|
|
60
|
-
allow_origin_regex?: string | undefined;
|
|
61
|
-
expose_headers?: string[] | undefined;
|
|
62
|
-
max_age?: number | undefined;
|
|
63
|
-
allow_methods?: string[] | undefined;
|
|
64
|
-
allow_headers?: string[] | undefined;
|
|
65
|
-
allow_credentials?: boolean | undefined;
|
|
66
|
-
allow_origins?: string[] | undefined;
|
|
67
|
-
}>>;
|
|
68
|
-
}, "strip", z.ZodTypeAny, {
|
|
69
|
-
disable_assistants: boolean;
|
|
70
|
-
disable_threads: boolean;
|
|
71
|
-
disable_runs: boolean;
|
|
72
|
-
disable_store: boolean;
|
|
73
|
-
disable_meta: boolean;
|
|
74
|
-
cors?: {
|
|
75
|
-
allow_origin_regex?: string | undefined;
|
|
76
|
-
expose_headers?: string[] | undefined;
|
|
77
|
-
max_age?: number | undefined;
|
|
78
|
-
allow_methods?: string[] | undefined;
|
|
79
|
-
allow_headers?: string[] | undefined;
|
|
80
|
-
allow_credentials?: boolean | undefined;
|
|
81
|
-
allow_origins?: string[] | undefined;
|
|
82
|
-
} | undefined;
|
|
83
|
-
app?: string | undefined;
|
|
84
|
-
}, {
|
|
85
|
-
cors?: {
|
|
86
|
-
allow_origin_regex?: string | undefined;
|
|
87
|
-
expose_headers?: string[] | undefined;
|
|
88
|
-
max_age?: number | undefined;
|
|
89
|
-
allow_methods?: string[] | undefined;
|
|
90
|
-
allow_headers?: string[] | undefined;
|
|
91
|
-
allow_credentials?: boolean | undefined;
|
|
92
|
-
allow_origins?: string[] | undefined;
|
|
93
|
-
} | undefined;
|
|
94
|
-
app?: string | undefined;
|
|
95
|
-
disable_assistants?: boolean | undefined;
|
|
96
|
-
disable_threads?: boolean | undefined;
|
|
97
|
-
disable_runs?: boolean | undefined;
|
|
98
|
-
disable_store?: boolean | undefined;
|
|
99
|
-
disable_meta?: boolean | undefined;
|
|
100
|
-
}>>;
|
|
101
|
-
}, "strip", z.ZodTypeAny, {
|
|
102
|
-
cwd: string;
|
|
103
|
-
host: string;
|
|
104
|
-
port: number;
|
|
105
|
-
nWorkers: number;
|
|
106
|
-
graphs: Record<string, string | {
|
|
107
|
-
path: string;
|
|
108
|
-
description?: string | undefined;
|
|
109
|
-
}>;
|
|
110
|
-
auth?: {
|
|
111
|
-
disable_studio_auth: boolean;
|
|
112
|
-
path?: string | undefined;
|
|
113
|
-
} | undefined;
|
|
114
|
-
ui?: Record<string, string> | undefined;
|
|
115
|
-
ui_config?: {
|
|
116
|
-
shared?: string[] | undefined;
|
|
117
|
-
} | undefined;
|
|
118
|
-
http?: {
|
|
119
|
-
disable_assistants: boolean;
|
|
120
|
-
disable_threads: boolean;
|
|
121
|
-
disable_runs: boolean;
|
|
122
|
-
disable_store: boolean;
|
|
123
|
-
disable_meta: boolean;
|
|
124
|
-
cors?: {
|
|
125
|
-
allow_origin_regex?: string | undefined;
|
|
126
|
-
expose_headers?: string[] | undefined;
|
|
127
|
-
max_age?: number | undefined;
|
|
128
|
-
allow_methods?: string[] | undefined;
|
|
129
|
-
allow_headers?: string[] | undefined;
|
|
130
|
-
allow_credentials?: boolean | undefined;
|
|
131
|
-
allow_origins?: string[] | undefined;
|
|
132
|
-
} | undefined;
|
|
133
|
-
app?: string | undefined;
|
|
134
|
-
} | undefined;
|
|
135
|
-
}, {
|
|
136
|
-
cwd: string;
|
|
137
|
-
host: string;
|
|
138
|
-
port: number;
|
|
139
|
-
nWorkers: number;
|
|
140
|
-
graphs: Record<string, string | {
|
|
141
|
-
path: string;
|
|
142
|
-
description?: string | undefined;
|
|
143
|
-
}>;
|
|
144
|
-
auth?: {
|
|
145
|
-
path?: string | undefined;
|
|
146
|
-
disable_studio_auth?: boolean | undefined;
|
|
147
|
-
} | undefined;
|
|
148
|
-
ui?: Record<string, string> | undefined;
|
|
149
|
-
ui_config?: {
|
|
150
|
-
shared?: string[] | undefined;
|
|
151
|
-
} | undefined;
|
|
152
|
-
http?: {
|
|
153
|
-
cors?: {
|
|
154
|
-
allow_origin_regex?: string | undefined;
|
|
155
|
-
expose_headers?: string[] | undefined;
|
|
156
|
-
max_age?: number | undefined;
|
|
157
|
-
allow_methods?: string[] | undefined;
|
|
158
|
-
allow_headers?: string[] | undefined;
|
|
159
|
-
allow_credentials?: boolean | undefined;
|
|
160
|
-
allow_origins?: string[] | undefined;
|
|
161
|
-
} | undefined;
|
|
162
|
-
app?: string | undefined;
|
|
163
|
-
disable_assistants?: boolean | undefined;
|
|
164
|
-
disable_threads?: boolean | undefined;
|
|
165
|
-
disable_runs?: boolean | undefined;
|
|
166
|
-
disable_store?: boolean | undefined;
|
|
167
|
-
disable_meta?: boolean | undefined;
|
|
168
|
-
} | undefined;
|
|
169
|
-
}>;
|
|
170
|
-
export declare function startServer(options: z.infer<typeof StartServerSchema>, storage?: {
|
|
171
|
-
ops?: Ops;
|
|
172
|
-
}): Promise<{
|
|
173
|
-
host: string;
|
|
174
|
-
cleanup: () => Promise<void>;
|
|
175
|
-
}>;
|
package/dist/server.mjs
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { serve } from "@hono/node-server";
|
|
2
|
-
import { Hono } from "hono";
|
|
3
|
-
import { contextStorage } from "hono/context-storage";
|
|
4
|
-
import { registerFromEnv } from "./graph/load.mjs";
|
|
5
|
-
import runs from "./api/runs.mjs";
|
|
6
|
-
import threads from "./api/threads.mjs";
|
|
7
|
-
import assistants from "./api/assistants.mjs";
|
|
8
|
-
import store from "./api/store.mjs";
|
|
9
|
-
import meta from "./api/meta.mjs";
|
|
10
|
-
import { zValidator } from "@hono/zod-validator";
|
|
11
|
-
import { z } from "zod/v3";
|
|
12
|
-
import { queue } from "./queue.mjs";
|
|
13
|
-
import { logger, requestLogger, registerRuntimeLogFormatter, registerSdkLogger, } from "./logging.mjs";
|
|
14
|
-
import { checkpointer } from "./storage/checkpoint.mjs";
|
|
15
|
-
import { FileSystemOps } from "./storage/ops.mjs";
|
|
16
|
-
import { store as graphStore } from "./storage/store.mjs";
|
|
17
|
-
import { auth } from "./auth/custom.mjs";
|
|
18
|
-
import { registerAuth } from "./auth/index.mjs";
|
|
19
|
-
import { registerHttp } from "./http/custom.mjs";
|
|
20
|
-
import { cors, ensureContentType } from "./http/middleware.mjs";
|
|
21
|
-
import { bindLoopbackFetch } from "./loopback.mjs";
|
|
22
|
-
import { checkLangGraphSemver } from "./semver/index.mjs";
|
|
23
|
-
import { getConfig } from "@langchain/langgraph";
|
|
24
|
-
import { FileSystemPersistence } from "./storage/persist.mjs";
|
|
25
|
-
export const StartServerSchema = z.object({
|
|
26
|
-
port: z.number(),
|
|
27
|
-
nWorkers: z.number(),
|
|
28
|
-
host: z.string(),
|
|
29
|
-
cwd: z.string(),
|
|
30
|
-
graphs: z.record(z.union([
|
|
31
|
-
z.string(),
|
|
32
|
-
z.object({ path: z.string(), description: z.string().optional() }),
|
|
33
|
-
])),
|
|
34
|
-
auth: z
|
|
35
|
-
.object({
|
|
36
|
-
path: z.string().optional(),
|
|
37
|
-
disable_studio_auth: z.boolean().default(false),
|
|
38
|
-
})
|
|
39
|
-
.optional(),
|
|
40
|
-
ui: z.record(z.string()).optional(),
|
|
41
|
-
ui_config: z.object({ shared: z.array(z.string()).optional() }).optional(),
|
|
42
|
-
http: z
|
|
43
|
-
.object({
|
|
44
|
-
app: z.string().optional(),
|
|
45
|
-
disable_assistants: z.boolean().default(false),
|
|
46
|
-
disable_threads: z.boolean().default(false),
|
|
47
|
-
disable_runs: z.boolean().default(false),
|
|
48
|
-
disable_store: z.boolean().default(false),
|
|
49
|
-
disable_meta: z.boolean().default(false),
|
|
50
|
-
cors: z
|
|
51
|
-
.object({
|
|
52
|
-
allow_origins: z.array(z.string()).optional(),
|
|
53
|
-
allow_methods: z.array(z.string()).optional(),
|
|
54
|
-
allow_headers: z.array(z.string()).optional(),
|
|
55
|
-
allow_credentials: z.boolean().optional(),
|
|
56
|
-
allow_origin_regex: z.string().optional(),
|
|
57
|
-
expose_headers: z.array(z.string()).optional(),
|
|
58
|
-
max_age: z.number().optional(),
|
|
59
|
-
})
|
|
60
|
-
.optional(),
|
|
61
|
-
})
|
|
62
|
-
.optional(),
|
|
63
|
-
});
|
|
64
|
-
export async function startServer(options, storage) {
|
|
65
|
-
const semver = await checkLangGraphSemver();
|
|
66
|
-
const invalidPackages = semver.filter((s) => !s.satisfies);
|
|
67
|
-
if (invalidPackages.length > 0) {
|
|
68
|
-
logger.warn(`Some LangGraph.js dependencies are not up to date. Please make sure to update them to the required version.`, Object.fromEntries(invalidPackages.map(({ name, version, required }) => [
|
|
69
|
-
name,
|
|
70
|
-
{ version, required },
|
|
71
|
-
])));
|
|
72
|
-
}
|
|
73
|
-
logger.info(`Initializing storage...`);
|
|
74
|
-
let initCalls = [
|
|
75
|
-
checkpointer.initialize(options.cwd),
|
|
76
|
-
graphStore.initialize(options.cwd),
|
|
77
|
-
];
|
|
78
|
-
let ops = storage?.ops;
|
|
79
|
-
if (ops == null) {
|
|
80
|
-
const opsConn = new FileSystemPersistence(".langgraphjs_ops.json", () => ({
|
|
81
|
-
runs: {},
|
|
82
|
-
threads: {},
|
|
83
|
-
assistants: {},
|
|
84
|
-
assistant_versions: [],
|
|
85
|
-
retry_counter: {},
|
|
86
|
-
}));
|
|
87
|
-
initCalls.push(opsConn.initialize(options.cwd));
|
|
88
|
-
ops = new FileSystemOps(opsConn);
|
|
89
|
-
}
|
|
90
|
-
const callbacks = await Promise.all(initCalls);
|
|
91
|
-
const cleanup = async () => {
|
|
92
|
-
logger.info(`Flushing to persistent storage, exiting...`);
|
|
93
|
-
await Promise.all(callbacks.map((c) => c.flush()));
|
|
94
|
-
};
|
|
95
|
-
// Register global logger that can be consumed via SDK
|
|
96
|
-
// We need to do this before we load the graphs in-case the logger is obtained at top-level.
|
|
97
|
-
registerSdkLogger();
|
|
98
|
-
logger.info(`Registering graphs from ${options.cwd}`);
|
|
99
|
-
let hasGraphDescriptions = false;
|
|
100
|
-
const graphPaths = Object.fromEntries(Object.entries(options.graphs).map(([graphId, rawSpec]) => {
|
|
101
|
-
if (typeof rawSpec === "string") {
|
|
102
|
-
return [graphId, rawSpec];
|
|
103
|
-
}
|
|
104
|
-
if (rawSpec.description) {
|
|
105
|
-
hasGraphDescriptions = true;
|
|
106
|
-
}
|
|
107
|
-
return [graphId, rawSpec.path];
|
|
108
|
-
}));
|
|
109
|
-
if (hasGraphDescriptions) {
|
|
110
|
-
logger.warn("A graph definition in `langgraph.json` has a `description` property. Local MCP features are not yet supported with the JS CLI and will be ignored.");
|
|
111
|
-
}
|
|
112
|
-
await registerFromEnv(ops.assistants, graphPaths, { cwd: options.cwd });
|
|
113
|
-
registerRuntimeLogFormatter((info) => {
|
|
114
|
-
const config = getConfig();
|
|
115
|
-
if (config == null)
|
|
116
|
-
return info;
|
|
117
|
-
const node = config.metadata?.["langgraph_node"];
|
|
118
|
-
if (node != null)
|
|
119
|
-
info.langgraph_node = node;
|
|
120
|
-
return info;
|
|
121
|
-
});
|
|
122
|
-
const app = new Hono();
|
|
123
|
-
app.use(contextStorage());
|
|
124
|
-
app.use(async (c, next) => {
|
|
125
|
-
c.set("LANGGRAPH_OPS", ops);
|
|
126
|
-
await next();
|
|
127
|
-
});
|
|
128
|
-
// Loopback fetch used by webhooks and custom routes
|
|
129
|
-
bindLoopbackFetch(app);
|
|
130
|
-
app.post("/internal/truncate", zValidator("json", z.object({
|
|
131
|
-
runs: z.boolean().optional(),
|
|
132
|
-
threads: z.boolean().optional(),
|
|
133
|
-
assistants: z.boolean().optional(),
|
|
134
|
-
checkpointer: z.boolean().optional(),
|
|
135
|
-
store: z.boolean().optional(),
|
|
136
|
-
})), (c) => {
|
|
137
|
-
const { runs, threads, assistants, checkpointer, store } = c.req.valid("json");
|
|
138
|
-
ops.truncate({ runs, threads, assistants, checkpointer, store });
|
|
139
|
-
return c.json({ ok: true });
|
|
140
|
-
});
|
|
141
|
-
app.use(cors(options.http?.cors));
|
|
142
|
-
app.use(requestLogger());
|
|
143
|
-
if (options.auth?.path) {
|
|
144
|
-
logger.info(`Loading auth from ${options.auth.path}`);
|
|
145
|
-
await registerAuth(options.auth, { cwd: options.cwd });
|
|
146
|
-
app.use(auth());
|
|
147
|
-
}
|
|
148
|
-
if (options.http?.app) {
|
|
149
|
-
logger.info(`Loading HTTP app from ${options.http.app}`);
|
|
150
|
-
const { api } = await registerHttp(options.http.app, { cwd: options.cwd });
|
|
151
|
-
app.route("/", api);
|
|
152
|
-
}
|
|
153
|
-
app.use(ensureContentType());
|
|
154
|
-
if (!options.http?.disable_meta)
|
|
155
|
-
app.route("/", meta);
|
|
156
|
-
if (!options.http?.disable_assistants)
|
|
157
|
-
app.route("/", assistants);
|
|
158
|
-
if (!options.http?.disable_runs)
|
|
159
|
-
app.route("/", runs);
|
|
160
|
-
if (!options.http?.disable_threads)
|
|
161
|
-
app.route("/", threads);
|
|
162
|
-
if (!options.http?.disable_store)
|
|
163
|
-
app.route("/", store);
|
|
164
|
-
if (options.ui) {
|
|
165
|
-
logger.info(`Registering UI from ${options.cwd}`);
|
|
166
|
-
const { api, registerGraphUi } = await import("./ui/load.mjs");
|
|
167
|
-
await registerGraphUi(options.ui, {
|
|
168
|
-
cwd: options.cwd,
|
|
169
|
-
config: options.ui_config,
|
|
170
|
-
});
|
|
171
|
-
app.route("/", api);
|
|
172
|
-
}
|
|
173
|
-
logger.info(`Starting ${options.nWorkers} workers`);
|
|
174
|
-
for (let i = 0; i < options.nWorkers; i++)
|
|
175
|
-
queue(ops);
|
|
176
|
-
return new Promise((resolve) => {
|
|
177
|
-
serve({ fetch: app.fetch, port: options.port, hostname: options.host }, (c) => {
|
|
178
|
-
resolve({ host: `${c.address}:${c.port}`, cleanup });
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
}
|
package/dist/state.d.mts
DELETED
package/dist/state.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { runnableConfigToCheckpoint } from "./utils/runnableConfig.mjs";
|
|
2
|
-
import { serializeError } from "./utils/serde.mjs";
|
|
3
|
-
const isStateSnapshot = (state) => {
|
|
4
|
-
return "values" in state && "next" in state;
|
|
5
|
-
};
|
|
6
|
-
export const stateSnapshotToThreadState = (state) => {
|
|
7
|
-
return {
|
|
8
|
-
values: state.values,
|
|
9
|
-
next: state.next,
|
|
10
|
-
tasks: state.tasks.map((task) => ({
|
|
11
|
-
id: task.id,
|
|
12
|
-
name: task.name,
|
|
13
|
-
error: task.error != null ? serializeError(task.error).message : null,
|
|
14
|
-
interrupts: task.interrupts,
|
|
15
|
-
path: task.path,
|
|
16
|
-
// TODO: too many type assertions, check if this is actually correct
|
|
17
|
-
checkpoint: task.state != null && "configurable" in task.state
|
|
18
|
-
? task.state.configurable ?? null
|
|
19
|
-
: null,
|
|
20
|
-
state: task.state != null && isStateSnapshot(task.state)
|
|
21
|
-
? stateSnapshotToThreadState(task.state)
|
|
22
|
-
: null,
|
|
23
|
-
result: task.result ?? null,
|
|
24
|
-
})),
|
|
25
|
-
metadata: state.metadata,
|
|
26
|
-
created_at: state.createdAt ? new Date(state.createdAt) : null,
|
|
27
|
-
checkpoint: runnableConfigToCheckpoint(state.config),
|
|
28
|
-
parent_checkpoint: runnableConfigToCheckpoint(state.parentConfig),
|
|
29
|
-
};
|
|
30
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { RunnableConfig } from "@langchain/core/runnables";
|
|
2
|
-
import { type Checkpoint, type CheckpointMetadata, MemorySaver } from "@langchain/langgraph";
|
|
3
|
-
import { FileSystemPersistence } from "./persist.mjs";
|
|
4
|
-
declare class InMemorySaver extends MemorySaver {
|
|
5
|
-
initialize(cwd: string): Promise<FileSystemPersistence<{
|
|
6
|
-
storage: typeof MemorySaver.prototype.storage;
|
|
7
|
-
writes: typeof MemorySaver.prototype.writes;
|
|
8
|
-
}>>;
|
|
9
|
-
clear(): void;
|
|
10
|
-
getTuple(...args: Parameters<MemorySaver["getTuple"]>): ReturnType<MemorySaver["getTuple"]>;
|
|
11
|
-
list(...args: Parameters<MemorySaver["list"]>): ReturnType<MemorySaver["list"]>;
|
|
12
|
-
putWrites(...args: Parameters<MemorySaver["putWrites"]>): Promise<void>;
|
|
13
|
-
put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
|
|
14
|
-
delete(threadId: string, runId: string | null | undefined): Promise<void>;
|
|
15
|
-
copy(threadId: string, newThreadId: string): Promise<void>;
|
|
16
|
-
toJSON(): string;
|
|
17
|
-
}
|
|
18
|
-
export declare const checkpointer: InMemorySaver;
|
|
19
|
-
export {};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { MemorySaver, } from "@langchain/langgraph";
|
|
2
|
-
import { FileSystemPersistence } from "./persist.mjs";
|
|
3
|
-
const EXCLUDED_KEYS = ["checkpoint_ns", "checkpoint_id", "run_id", "thread_id"];
|
|
4
|
-
const textDecoder = new TextDecoder();
|
|
5
|
-
const textEncoder = new TextEncoder();
|
|
6
|
-
const WriteKey = {
|
|
7
|
-
serialize: (key) => {
|
|
8
|
-
return JSON.stringify(key);
|
|
9
|
-
},
|
|
10
|
-
deserialize: (key) => {
|
|
11
|
-
const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);
|
|
12
|
-
return [threadId, checkpointNamespace, checkpointId];
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
const conn = new FileSystemPersistence(".langgraphjs_api.checkpointer.json", () => ({
|
|
16
|
-
storage: {},
|
|
17
|
-
writes: {},
|
|
18
|
-
}));
|
|
19
|
-
class InMemorySaver extends MemorySaver {
|
|
20
|
-
async initialize(cwd) {
|
|
21
|
-
await conn.initialize(cwd);
|
|
22
|
-
await conn.with(({ storage, writes }) => {
|
|
23
|
-
this.storage = storage;
|
|
24
|
-
this.writes = writes;
|
|
25
|
-
});
|
|
26
|
-
return conn;
|
|
27
|
-
}
|
|
28
|
-
clear() {
|
|
29
|
-
// { [threadId: string]: { [checkpointNs: string]: { [checkpointId]: [checkpoint, metadata, parentId] } }}
|
|
30
|
-
this.storage = {};
|
|
31
|
-
// { [WriteKey]: CheckpointPendingWrite[] }
|
|
32
|
-
this.writes = {};
|
|
33
|
-
}
|
|
34
|
-
// Patch every method that has access to this.storage or this.writes
|
|
35
|
-
// to also persist the changes to the filesystem in a non-blocking manner
|
|
36
|
-
async getTuple(...args) {
|
|
37
|
-
return await conn.with(() => super.getTuple(...args));
|
|
38
|
-
}
|
|
39
|
-
async *list(...args) {
|
|
40
|
-
yield* conn.withGenerator(super.list(...args));
|
|
41
|
-
}
|
|
42
|
-
async putWrites(...args) {
|
|
43
|
-
return await conn.with(() => super.putWrites(...args));
|
|
44
|
-
}
|
|
45
|
-
async put(config, checkpoint, metadata) {
|
|
46
|
-
return await conn.with(() => super.put(config, checkpoint, {
|
|
47
|
-
...Object.fromEntries(Object.entries(config.configurable ?? {}).filter(([key]) => !key.startsWith("__") && !EXCLUDED_KEYS.includes(key))),
|
|
48
|
-
...config.metadata,
|
|
49
|
-
...metadata,
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
async delete(threadId, runId) {
|
|
53
|
-
if (this.storage[threadId] == null)
|
|
54
|
-
return;
|
|
55
|
-
return await conn.with(() => {
|
|
56
|
-
if (runId != null) {
|
|
57
|
-
const writeKeysToDelete = [];
|
|
58
|
-
for (const ns of Object.keys(this.storage[threadId])) {
|
|
59
|
-
for (const id of Object.keys(this.storage[threadId][ns])) {
|
|
60
|
-
const [_checkpoint, metadata, _parentId] = this.storage[threadId][ns][id];
|
|
61
|
-
const jsonMetadata = JSON.parse(textDecoder.decode(metadata));
|
|
62
|
-
if (jsonMetadata.run_id === runId) {
|
|
63
|
-
delete this.storage[threadId][ns][id];
|
|
64
|
-
writeKeysToDelete.push(WriteKey.serialize([threadId, ns, id]));
|
|
65
|
-
if (Object.keys(this.storage[threadId][ns]).length === 0) {
|
|
66
|
-
delete this.storage[threadId][ns];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
for (const key of writeKeysToDelete) {
|
|
72
|
-
delete this.writes[key];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
delete this.storage[threadId];
|
|
77
|
-
// delete all writes for this thread
|
|
78
|
-
const writeKeys = Object.keys(this.writes);
|
|
79
|
-
for (const key of writeKeys) {
|
|
80
|
-
const [writeThreadId] = WriteKey.deserialize(key);
|
|
81
|
-
if (writeThreadId === threadId)
|
|
82
|
-
delete this.writes[key];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
async copy(threadId, newThreadId) {
|
|
88
|
-
return await conn.with(() => {
|
|
89
|
-
// copy storage over
|
|
90
|
-
const newThreadCheckpoints = {};
|
|
91
|
-
for (const oldNs of Object.keys(this.storage[threadId] ?? {})) {
|
|
92
|
-
const newNs = oldNs.replace(threadId, newThreadId);
|
|
93
|
-
for (const oldId of Object.keys(this.storage[threadId][oldNs])) {
|
|
94
|
-
const newId = oldId.replace(threadId, newThreadId);
|
|
95
|
-
const [checkpoint, metadata, oldParentId] = this.storage[threadId][oldNs][oldId];
|
|
96
|
-
const newParentId = oldParentId?.replace(threadId, newThreadId);
|
|
97
|
-
const rawMetadata = textDecoder
|
|
98
|
-
.decode(metadata)
|
|
99
|
-
.replaceAll(threadId, newThreadId);
|
|
100
|
-
newThreadCheckpoints[newNs] ??= {};
|
|
101
|
-
newThreadCheckpoints[newNs][newId] = [
|
|
102
|
-
checkpoint,
|
|
103
|
-
textEncoder.encode(rawMetadata),
|
|
104
|
-
newParentId,
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.storage[newThreadId] = newThreadCheckpoints;
|
|
109
|
-
// copy writes over (if any)
|
|
110
|
-
const outerKeys = [];
|
|
111
|
-
for (const keyJson of Object.keys(this.writes)) {
|
|
112
|
-
const key = WriteKey.deserialize(keyJson);
|
|
113
|
-
if (key[0] === threadId)
|
|
114
|
-
outerKeys.push(keyJson);
|
|
115
|
-
}
|
|
116
|
-
for (const keyJson of outerKeys) {
|
|
117
|
-
const [_threadId, checkpointNamespace, checkpointId] = WriteKey.deserialize(keyJson);
|
|
118
|
-
this.writes[WriteKey.serialize([newThreadId, checkpointNamespace, checkpointId])] = structuredClone(this.writes[keyJson]);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
toJSON() {
|
|
123
|
-
// Prevent serialization of internal state
|
|
124
|
-
return "[InMemorySaver]";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
export const checkpointer = new InMemorySaver();
|
package/dist/storage/context.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// Hono context helpers for accessing repositories, etc.
|
|
2
|
-
import { getContext } from "hono/context-storage";
|
|
3
|
-
export const assistants = () => {
|
|
4
|
-
return getContext().var.LANGGRAPH_OPS.assistants;
|
|
5
|
-
};
|
|
6
|
-
export const runs = () => {
|
|
7
|
-
return getContext().var.LANGGRAPH_OPS.runs;
|
|
8
|
-
};
|
|
9
|
-
export const threads = () => {
|
|
10
|
-
return getContext().var.LANGGRAPH_OPS.threads;
|
|
11
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { PromptTemplate, AIMessagePromptTemplate, ChatMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, ImagePromptTemplate, PipelinePromptTemplate } from "@langchain/core/prompts";
|
|
2
|
-
import { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk } from "@langchain/core/messages";
|
|
3
|
-
import { StringPromptValue } from "@langchain/core/prompt_values";
|
|
4
|
-
export declare const prompts__prompt: {
|
|
5
|
-
PromptTemplate: typeof PromptTemplate;
|
|
6
|
-
};
|
|
7
|
-
export declare const schema__messages: {
|
|
8
|
-
AIMessage: typeof AIMessage;
|
|
9
|
-
AIMessageChunk: typeof AIMessageChunk;
|
|
10
|
-
BaseMessage: typeof BaseMessage;
|
|
11
|
-
BaseMessageChunk: typeof BaseMessageChunk;
|
|
12
|
-
ChatMessage: typeof ChatMessage;
|
|
13
|
-
ChatMessageChunk: typeof ChatMessageChunk;
|
|
14
|
-
FunctionMessage: typeof FunctionMessage;
|
|
15
|
-
FunctionMessageChunk: typeof FunctionMessageChunk;
|
|
16
|
-
HumanMessage: typeof HumanMessage;
|
|
17
|
-
HumanMessageChunk: typeof HumanMessageChunk;
|
|
18
|
-
SystemMessage: typeof SystemMessage;
|
|
19
|
-
SystemMessageChunk: typeof SystemMessageChunk;
|
|
20
|
-
ToolMessage: typeof ToolMessage;
|
|
21
|
-
ToolMessageChunk: typeof ToolMessageChunk;
|
|
22
|
-
};
|
|
23
|
-
export declare const schema: {
|
|
24
|
-
AIMessage: typeof AIMessage;
|
|
25
|
-
AIMessageChunk: typeof AIMessageChunk;
|
|
26
|
-
BaseMessage: typeof BaseMessage;
|
|
27
|
-
BaseMessageChunk: typeof BaseMessageChunk;
|
|
28
|
-
ChatMessage: typeof ChatMessage;
|
|
29
|
-
ChatMessageChunk: typeof ChatMessageChunk;
|
|
30
|
-
FunctionMessage: typeof FunctionMessage;
|
|
31
|
-
FunctionMessageChunk: typeof FunctionMessageChunk;
|
|
32
|
-
HumanMessage: typeof HumanMessage;
|
|
33
|
-
HumanMessageChunk: typeof HumanMessageChunk;
|
|
34
|
-
SystemMessage: typeof SystemMessage;
|
|
35
|
-
SystemMessageChunk: typeof SystemMessageChunk;
|
|
36
|
-
ToolMessage: typeof ToolMessage;
|
|
37
|
-
ToolMessageChunk: typeof ToolMessageChunk;
|
|
38
|
-
};
|
|
39
|
-
export declare const prompts__chat: {
|
|
40
|
-
AIMessagePromptTemplate: typeof AIMessagePromptTemplate;
|
|
41
|
-
ChatMessagePromptTemplate: typeof ChatMessagePromptTemplate;
|
|
42
|
-
ChatPromptTemplate: typeof ChatPromptTemplate;
|
|
43
|
-
HumanMessagePromptTemplate: typeof HumanMessagePromptTemplate;
|
|
44
|
-
MessagesPlaceholder: typeof MessagesPlaceholder;
|
|
45
|
-
SystemMessagePromptTemplate: typeof SystemMessagePromptTemplate;
|
|
46
|
-
};
|
|
47
|
-
export declare const prompts__image: {
|
|
48
|
-
ImagePromptTemplate: typeof ImagePromptTemplate;
|
|
49
|
-
};
|
|
50
|
-
export declare const prompts__pipeline: {
|
|
51
|
-
PipelinePromptTemplate: typeof PipelinePromptTemplate;
|
|
52
|
-
};
|
|
53
|
-
export declare const prompts__base: {
|
|
54
|
-
StringPromptValue: typeof StringPromptValue;
|
|
55
|
-
};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { PromptTemplate, AIMessagePromptTemplate, ChatMessagePromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, ImagePromptTemplate, PipelinePromptTemplate, } from "@langchain/core/prompts";
|
|
2
|
-
import { AIMessage, AIMessageChunk, BaseMessage, BaseMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, } from "@langchain/core/messages";
|
|
3
|
-
import { StringPromptValue } from "@langchain/core/prompt_values";
|
|
4
|
-
export const prompts__prompt = {
|
|
5
|
-
PromptTemplate,
|
|
6
|
-
};
|
|
7
|
-
export const schema__messages = {
|
|
8
|
-
AIMessage,
|
|
9
|
-
AIMessageChunk,
|
|
10
|
-
BaseMessage,
|
|
11
|
-
BaseMessageChunk,
|
|
12
|
-
ChatMessage,
|
|
13
|
-
ChatMessageChunk,
|
|
14
|
-
FunctionMessage,
|
|
15
|
-
FunctionMessageChunk,
|
|
16
|
-
HumanMessage,
|
|
17
|
-
HumanMessageChunk,
|
|
18
|
-
SystemMessage,
|
|
19
|
-
SystemMessageChunk,
|
|
20
|
-
ToolMessage,
|
|
21
|
-
ToolMessageChunk,
|
|
22
|
-
};
|
|
23
|
-
export const schema = {
|
|
24
|
-
AIMessage,
|
|
25
|
-
AIMessageChunk,
|
|
26
|
-
BaseMessage,
|
|
27
|
-
BaseMessageChunk,
|
|
28
|
-
ChatMessage,
|
|
29
|
-
ChatMessageChunk,
|
|
30
|
-
FunctionMessage,
|
|
31
|
-
FunctionMessageChunk,
|
|
32
|
-
HumanMessage,
|
|
33
|
-
HumanMessageChunk,
|
|
34
|
-
SystemMessage,
|
|
35
|
-
SystemMessageChunk,
|
|
36
|
-
ToolMessage,
|
|
37
|
-
ToolMessageChunk,
|
|
38
|
-
};
|
|
39
|
-
export const prompts__chat = {
|
|
40
|
-
AIMessagePromptTemplate,
|
|
41
|
-
ChatMessagePromptTemplate,
|
|
42
|
-
ChatPromptTemplate,
|
|
43
|
-
HumanMessagePromptTemplate,
|
|
44
|
-
MessagesPlaceholder,
|
|
45
|
-
SystemMessagePromptTemplate,
|
|
46
|
-
};
|
|
47
|
-
export const prompts__image = {
|
|
48
|
-
ImagePromptTemplate,
|
|
49
|
-
};
|
|
50
|
-
export const prompts__pipeline = {
|
|
51
|
-
PipelinePromptTemplate,
|
|
52
|
-
};
|
|
53
|
-
export const prompts__base = {
|
|
54
|
-
StringPromptValue,
|
|
55
|
-
};
|