@langchain/langgraph-api 0.0.30 → 0.0.31
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/api/assistants.d.mts +3 -0
- package/dist/api/assistants.mjs +37 -21
- package/dist/api/meta.d.mts +3 -0
- package/dist/api/runs.d.mts +3 -0
- package/dist/api/store.d.mts +3 -0
- package/dist/api/threads.d.mts +3 -0
- package/dist/auth/custom.d.mts +12 -0
- package/dist/auth/index.d.mts +1 -1
- package/dist/cli/entrypoint.d.mts +1 -0
- package/dist/cli/utils/ipc/client.d.mts +5 -0
- package/dist/cli/utils/ipc/utils/get-pipe-path.d.mts +1 -0
- package/dist/cli/utils/ipc/utils/temporary-directory.d.mts +5 -0
- package/dist/command.d.mts +11 -0
- package/dist/graph/load.d.mts +16 -0
- package/dist/graph/load.hooks.d.mts +2 -0
- package/dist/graph/load.mjs +17 -4
- package/dist/graph/load.utils.d.mts +22 -0
- package/dist/graph/load.utils.mjs +4 -36
- package/dist/graph/parser/index.d.mts +17 -0
- package/dist/graph/parser/index.mjs +41 -0
- package/dist/graph/parser/parser.d.mts +63 -0
- package/dist/graph/parser/parser.mjs +3 -3
- package/dist/graph/parser/parser.worker.d.mts +1 -0
- package/dist/graph/parser/schema/types.d.mts +154 -0
- package/dist/graph/parser/schema/types.mjs +0 -111
- package/dist/graph/parser/schema/types.template.d.mts +1 -0
- package/dist/http/custom.d.mts +6 -0
- package/dist/http/middleware.d.mts +11 -0
- package/dist/logging.d.mts +7 -0
- package/dist/loopback.d.mts +3 -0
- package/dist/preload.d.mts +1 -0
- package/dist/queue.d.mts +1 -0
- package/dist/schemas.d.mts +1369 -0
- package/dist/server.d.mts +157 -0
- package/dist/state.d.mts +3 -0
- package/dist/storage/checkpoint.d.mts +19 -0
- package/dist/storage/importMap.d.mts +55 -0
- package/dist/storage/ops.d.mts +284 -0
- package/dist/storage/persist.d.mts +18 -0
- package/dist/storage/store.d.mts +17 -0
- package/dist/stream.d.mts +38 -0
- package/dist/ui/load.d.mts +8 -0
- package/dist/utils/abort.d.mts +1 -0
- package/dist/utils/hono.d.mts +5 -0
- package/dist/utils/importMap.d.mts +55 -0
- package/dist/utils/runnableConfig.d.mts +3 -0
- package/dist/utils/serde.d.mts +5 -0
- package/dist/webhook.d.mts +11 -0
- package/package.json +10 -6
package/dist/api/assistants.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { Hono } from "hono";
|
|
|
2
2
|
import { zValidator } from "@hono/zod-validator";
|
|
3
3
|
import { v4 as uuid } from "uuid";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
import { getAssistantId, getGraph,
|
|
5
|
+
import { getAssistantId, getGraph, getCachedStaticGraphSchema, } from "../graph/load.mjs";
|
|
6
|
+
import { getRuntimeGraphSchema } from "../graph/parser/index.mjs";
|
|
6
7
|
import { Assistants } from "../storage/ops.mjs";
|
|
7
8
|
import * as schemas from "../schemas.mjs";
|
|
8
9
|
import { HTTPException } from "hono/http-exception";
|
|
@@ -84,21 +85,29 @@ api.get("/assistants/:assistant_id/graph", zValidator("query", z.object({ xray:
|
|
|
84
85
|
});
|
|
85
86
|
return c.json(drawable.toJSON());
|
|
86
87
|
});
|
|
87
|
-
api.get("/assistants/:assistant_id/schemas", async (c) => {
|
|
88
|
+
api.get("/assistants/:assistant_id/schemas", zValidator("json", z.object({ config: RunnableConfigSchema.optional() })), async (c) => {
|
|
88
89
|
// Get Assistant Schemas
|
|
90
|
+
const json = c.req.valid("json");
|
|
89
91
|
const assistantId = getAssistantId(c.req.param("assistant_id"));
|
|
90
92
|
const assistant = await Assistants.get(assistantId, c.var.auth);
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const config = getRunnableConfig(json.config);
|
|
94
|
+
const graph = await getGraph(assistant.graph_id, config);
|
|
95
|
+
const schema = await (async () => {
|
|
96
|
+
const runtimeSchema = await getRuntimeGraphSchema(graph);
|
|
97
|
+
if (runtimeSchema)
|
|
98
|
+
return runtimeSchema;
|
|
99
|
+
const graphSchema = await getCachedStaticGraphSchema(assistant.graph_id);
|
|
100
|
+
const rootGraphId = Object.keys(graphSchema).find((i) => !i.includes("|"));
|
|
101
|
+
if (!rootGraphId)
|
|
102
|
+
throw new HTTPException(404, { message: "Failed to find root graph" });
|
|
103
|
+
return graphSchema[rootGraphId];
|
|
104
|
+
})();
|
|
96
105
|
return c.json({
|
|
97
106
|
graph_id: assistant.graph_id,
|
|
98
|
-
input_schema:
|
|
99
|
-
output_schema:
|
|
100
|
-
state_schema:
|
|
101
|
-
config_schema:
|
|
107
|
+
input_schema: schema.input,
|
|
108
|
+
output_schema: schema.output,
|
|
109
|
+
state_schema: schema.state,
|
|
110
|
+
config_schema: schema.config,
|
|
102
111
|
});
|
|
103
112
|
});
|
|
104
113
|
api.get("/assistants/:assistant_id/subgraphs/:namespace?", zValidator("param", z.object({ assistant_id: z.string(), namespace: z.string().optional() })), zValidator("query", z.object({ recurse: schemas.coercedBoolean.optional() })), async (c) => {
|
|
@@ -109,21 +118,28 @@ api.get("/assistants/:assistant_id/subgraphs/:namespace?", zValidator("param", z
|
|
|
109
118
|
const assistant = await Assistants.get(assistantId, c.var.auth);
|
|
110
119
|
const config = getRunnableConfig(assistant.config);
|
|
111
120
|
const graph = await getGraph(assistant.graph_id, config);
|
|
112
|
-
const graphSchema = await getGraphSchema(assistant.graph_id);
|
|
113
|
-
const rootGraphId = Object.keys(graphSchema).find((i) => !i.includes("|"));
|
|
114
|
-
if (!rootGraphId) {
|
|
115
|
-
throw new HTTPException(404, { message: "Failed to find root graph" });
|
|
116
|
-
}
|
|
117
121
|
const result = [];
|
|
118
122
|
const subgraphsGenerator = "getSubgraphsAsync" in graph
|
|
119
123
|
? graph.getSubgraphsAsync.bind(graph)
|
|
120
124
|
: // @ts-expect-error older versions of langgraph don't have getSubgraphsAsync
|
|
121
125
|
graph.getSubgraphs.bind(graph);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
let graphSchemaPromise;
|
|
127
|
+
for await (const [ns, subgraph] of subgraphsGenerator(namespace, recurse)) {
|
|
128
|
+
const schema = await (async () => {
|
|
129
|
+
const runtimeSchema = await getRuntimeGraphSchema(subgraph);
|
|
130
|
+
if (runtimeSchema)
|
|
131
|
+
return runtimeSchema;
|
|
132
|
+
graphSchemaPromise ??= getCachedStaticGraphSchema(assistant.graph_id);
|
|
133
|
+
const graphSchema = await graphSchemaPromise;
|
|
134
|
+
const rootGraphId = Object.keys(graphSchema).find((i) => !i.includes("|"));
|
|
135
|
+
if (!rootGraphId) {
|
|
136
|
+
throw new HTTPException(404, {
|
|
137
|
+
message: "Failed to find root graph",
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return graphSchema[`${rootGraphId}|${ns}`] || graphSchema[rootGraphId];
|
|
141
|
+
})();
|
|
142
|
+
result.push([ns, schema]);
|
|
127
143
|
}
|
|
128
144
|
return c.json(Object.fromEntries(result));
|
|
129
145
|
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthEventValueMap } from "@langchain/langgraph-sdk/auth";
|
|
2
|
+
import type { MiddlewareHandler } from "hono";
|
|
3
|
+
import { type AuthContext, type AuthFilters } from "./index.mjs";
|
|
4
|
+
declare module "hono" {
|
|
5
|
+
interface ContextVariableMap {
|
|
6
|
+
auth?: AuthContext | undefined;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export declare function isAuthMatching(metadata: Record<string, unknown> | undefined, filters: AuthFilters): boolean;
|
|
10
|
+
export declare const handleAuthEvent: <T extends keyof AuthEventValueMap>(context: AuthContext | undefined, event: T, value: AuthEventValueMap[T]) => Promise<[AuthFilters | undefined, value: AuthEventValueMap[T]]>;
|
|
11
|
+
export declare const auth: () => MiddlewareHandler;
|
|
12
|
+
export { registerAuth } from "./index.mjs";
|
package/dist/auth/index.d.mts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPipePath: (processId: number) => string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Command } from "@langchain/langgraph";
|
|
2
|
+
export interface RunSend {
|
|
3
|
+
node: string;
|
|
4
|
+
input?: unknown;
|
|
5
|
+
}
|
|
6
|
+
export interface RunCommand {
|
|
7
|
+
goto?: string | RunSend | Array<RunSend | string>;
|
|
8
|
+
update?: Record<string, unknown> | [string, unknown][];
|
|
9
|
+
resume?: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare const getLangGraphCommand: (command: RunCommand) => Command<unknown>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaseCheckpointSaver, BaseStore, CompiledGraph, LangGraphRunnableConfig } from "@langchain/langgraph";
|
|
2
|
+
import { type CompiledGraphFactory } from "./load.utils.mjs";
|
|
3
|
+
import type { GraphSchema, GraphSpec } from "./parser/index.mjs";
|
|
4
|
+
export declare const GRAPHS: Record<string, CompiledGraph<string> | CompiledGraphFactory<string>>;
|
|
5
|
+
export declare const GRAPH_SPEC: Record<string, GraphSpec>;
|
|
6
|
+
export declare const GRAPH_SCHEMA: Record<string, Record<string, GraphSchema>>;
|
|
7
|
+
export declare const NAMESPACE_GRAPH: Uint8Array;
|
|
8
|
+
export declare const getAssistantId: (graphId: string) => string;
|
|
9
|
+
export declare function registerFromEnv(specs: Record<string, string>, options: {
|
|
10
|
+
cwd: string;
|
|
11
|
+
}): Promise<(CompiledGraph<string, any, any, Record<string, any>, any, any> | CompiledGraphFactory<string>)[]>;
|
|
12
|
+
export declare function getGraph(graphId: string, config: LangGraphRunnableConfig | undefined, options?: {
|
|
13
|
+
checkpointer?: BaseCheckpointSaver | null;
|
|
14
|
+
store?: BaseStore;
|
|
15
|
+
}): Promise<CompiledGraph<string, any, any, Record<string, any>, any, any>>;
|
|
16
|
+
export declare function getCachedStaticGraphSchema(graphId: string): Promise<Record<string, GraphSchema>>;
|
package/dist/graph/load.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import * as uuid from "uuid";
|
|
3
3
|
import { Assistants } from "../storage/ops.mjs";
|
|
4
4
|
import { HTTPException } from "hono/http-exception";
|
|
5
|
-
import { resolveGraph
|
|
5
|
+
import { resolveGraph } from "./load.utils.mjs";
|
|
6
|
+
import { getStaticGraphSchema } from "./parser/index.mjs";
|
|
6
7
|
import { checkpointer } from "../storage/checkpoint.mjs";
|
|
7
8
|
import { store } from "../storage/store.mjs";
|
|
8
9
|
import { logger } from "../logging.mjs";
|
|
@@ -56,14 +57,26 @@ export async function getGraph(graphId, config, options) {
|
|
|
56
57
|
compiled.store = options?.store ?? store;
|
|
57
58
|
return compiled;
|
|
58
59
|
}
|
|
59
|
-
export async function
|
|
60
|
+
export async function getCachedStaticGraphSchema(graphId) {
|
|
60
61
|
if (!GRAPH_SPEC[graphId])
|
|
61
62
|
throw new HTTPException(404, {
|
|
62
63
|
message: `Spec for "${graphId}" not found`,
|
|
63
64
|
});
|
|
64
|
-
if (!GRAPH_SCHEMA[graphId]
|
|
65
|
+
if (!GRAPH_SCHEMA[graphId]) {
|
|
66
|
+
let timeoutMs = 30_000;
|
|
65
67
|
try {
|
|
66
|
-
|
|
68
|
+
const envTimeout = Number.parseInt(process.env.LANGGRAPH_SCHEMA_RESOLVE_TIMEOUT_MS ?? "0", 10);
|
|
69
|
+
if (!Number.isNaN(envTimeout) && envTimeout > 0) {
|
|
70
|
+
timeoutMs = envTimeout;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
// ignore
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
GRAPH_SCHEMA[graphId] = await getStaticGraphSchema(GRAPH_SPEC[graphId], {
|
|
78
|
+
timeoutMs,
|
|
79
|
+
});
|
|
67
80
|
}
|
|
68
81
|
catch (error) {
|
|
69
82
|
throw new Error(`Failed to extract schema for "${graphId}"`, {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CompiledGraph } from "@langchain/langgraph";
|
|
2
|
+
export declare const GRAPHS: Record<string, CompiledGraph<string>>;
|
|
3
|
+
export declare const NAMESPACE_GRAPH: Uint8Array;
|
|
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,8 +1,7 @@
|
|
|
1
|
-
import { Worker } from "node:worker_threads";
|
|
2
|
-
import * as fs from "node:fs/promises";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
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";
|
|
6
5
|
export const GRAPHS = {};
|
|
7
6
|
export const NAMESPACE_GRAPH = uuid.parse("6ba7b821-9dad-11d1-80b4-00c04fd430c8");
|
|
8
7
|
export async function resolveGraph(spec, options) {
|
|
@@ -11,7 +10,7 @@ export async function resolveGraph(spec, options) {
|
|
|
11
10
|
// validate file exists
|
|
12
11
|
await fs.stat(sourceFile);
|
|
13
12
|
if (options?.onlyFilePresence) {
|
|
14
|
-
return { sourceFile
|
|
13
|
+
return { sourceFile, exportSymbol, resolved: undefined };
|
|
15
14
|
}
|
|
16
15
|
const isGraph = (graph) => {
|
|
17
16
|
if (typeof graph !== "object" || graph == null)
|
|
@@ -37,34 +36,3 @@ export async function resolveGraph(spec, options) {
|
|
|
37
36
|
})();
|
|
38
37
|
return { sourceFile, exportSymbol, resolved };
|
|
39
38
|
}
|
|
40
|
-
export async function runGraphSchemaWorker(spec, options) {
|
|
41
|
-
let SCHEMA_RESOLVE_TIMEOUT_MS = 30_000;
|
|
42
|
-
try {
|
|
43
|
-
const envTimeout = Number.parseInt(process.env.LANGGRAPH_SCHEMA_RESOLVE_TIMEOUT_MS ?? "0", 10);
|
|
44
|
-
if (!Number.isNaN(envTimeout) && envTimeout > 0) {
|
|
45
|
-
SCHEMA_RESOLVE_TIMEOUT_MS = envTimeout;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
// ignore
|
|
50
|
-
}
|
|
51
|
-
if (options?.mainThread) {
|
|
52
|
-
const { SubgraphExtractor } = await import("./parser/parser.mjs");
|
|
53
|
-
return SubgraphExtractor.extractSchemas(spec.sourceFile, spec.exportSymbol, { strict: false });
|
|
54
|
-
}
|
|
55
|
-
return await new Promise((resolve, reject) => {
|
|
56
|
-
const worker = new Worker(fileURLToPath(new URL("./parser/parser.worker.mjs", import.meta.url)), { argv: process.argv.slice(-1) });
|
|
57
|
-
// Set a timeout to reject if the worker takes too long
|
|
58
|
-
const timeoutId = setTimeout(() => {
|
|
59
|
-
worker.terminate();
|
|
60
|
-
reject(new Error("Schema extract worker timed out"));
|
|
61
|
-
}, SCHEMA_RESOLVE_TIMEOUT_MS);
|
|
62
|
-
worker.on("message", (result) => {
|
|
63
|
-
worker.terminate();
|
|
64
|
-
clearTimeout(timeoutId);
|
|
65
|
-
resolve(result);
|
|
66
|
-
});
|
|
67
|
-
worker.on("error", reject);
|
|
68
|
-
worker.postMessage(spec);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
export declare function getStaticGraphSchema(spec: GraphSpec, options?: {
|
|
14
|
+
mainThread?: boolean;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
}): Promise<Record<string, GraphSchema>>;
|
|
17
|
+
export declare function getRuntimeGraphSchema(graph: Pregel<any, any, any, any, any>): Promise<GraphSchema | undefined>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { Worker } from "node:worker_threads";
|
|
3
|
+
export async function getStaticGraphSchema(spec, options) {
|
|
4
|
+
if (options?.mainThread) {
|
|
5
|
+
const { SubgraphExtractor } = await import("./parser.mjs");
|
|
6
|
+
return SubgraphExtractor.extractSchemas(spec.sourceFile, spec.exportSymbol, { strict: false });
|
|
7
|
+
}
|
|
8
|
+
return await new Promise((resolve, reject) => {
|
|
9
|
+
const worker = new Worker(fileURLToPath(new URL("./parser.worker.mjs", import.meta.url)), { argv: process.argv.slice(-1) });
|
|
10
|
+
// Set a timeout to reject if the worker takes too long
|
|
11
|
+
const timeoutId = setTimeout(() => {
|
|
12
|
+
worker.terminate();
|
|
13
|
+
reject(new Error("Schema extract worker timed out"));
|
|
14
|
+
}, options?.timeoutMs ?? 30000);
|
|
15
|
+
worker.on("message", (result) => {
|
|
16
|
+
worker.terminate();
|
|
17
|
+
clearTimeout(timeoutId);
|
|
18
|
+
resolve(result);
|
|
19
|
+
});
|
|
20
|
+
worker.on("error", reject);
|
|
21
|
+
worker.postMessage(spec);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export async function getRuntimeGraphSchema(graph) {
|
|
25
|
+
try {
|
|
26
|
+
const { getInputTypeSchema, getOutputTypeSchema, getUpdateTypeSchema, getConfigTypeSchema, } = await import("@langchain/langgraph/zod/schema");
|
|
27
|
+
const result = {
|
|
28
|
+
state: getUpdateTypeSchema(graph),
|
|
29
|
+
input: getInputTypeSchema(graph),
|
|
30
|
+
output: getOutputTypeSchema(graph),
|
|
31
|
+
config: getConfigTypeSchema(graph),
|
|
32
|
+
};
|
|
33
|
+
if (Object.values(result).every((i) => i == null))
|
|
34
|
+
return undefined;
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// ignore
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
interface GraphSchema {
|
|
4
|
+
state: JSONSchema7 | undefined;
|
|
5
|
+
input: JSONSchema7 | undefined;
|
|
6
|
+
output: JSONSchema7 | undefined;
|
|
7
|
+
config: JSONSchema7 | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare class SubgraphExtractor {
|
|
10
|
+
protected program: ts.Program;
|
|
11
|
+
protected checker: ts.TypeChecker;
|
|
12
|
+
protected sourceFile: ts.SourceFile;
|
|
13
|
+
protected inferFile: ts.SourceFile;
|
|
14
|
+
protected anyPregelType: ts.Type;
|
|
15
|
+
protected anyGraphType: ts.Type;
|
|
16
|
+
protected strict: boolean;
|
|
17
|
+
constructor(program: ts.Program, sourceFile: ts.SourceFile, inferFile: ts.SourceFile, options?: {
|
|
18
|
+
strict?: boolean;
|
|
19
|
+
});
|
|
20
|
+
private findTypeByName;
|
|
21
|
+
private find;
|
|
22
|
+
protected findSubgraphs: (node: ts.Node, namespace?: string[]) => {
|
|
23
|
+
node: string;
|
|
24
|
+
namespace: string[];
|
|
25
|
+
subgraph: {
|
|
26
|
+
name: string;
|
|
27
|
+
node: ts.Node;
|
|
28
|
+
};
|
|
29
|
+
}[];
|
|
30
|
+
protected getSubgraphsVariables: (name: string) => {
|
|
31
|
+
node: string;
|
|
32
|
+
namespace: string[];
|
|
33
|
+
subgraph: {
|
|
34
|
+
name: string;
|
|
35
|
+
node: ts.Node;
|
|
36
|
+
};
|
|
37
|
+
}[];
|
|
38
|
+
getAugmentedSourceFile: (name: string) => {
|
|
39
|
+
files: [filePath: string, contents: string][];
|
|
40
|
+
exports: {
|
|
41
|
+
typeName: string;
|
|
42
|
+
valueName: string;
|
|
43
|
+
graphName: string;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
protected findSubgraphIdentifiers: (acc: {
|
|
47
|
+
node: ts.Node;
|
|
48
|
+
name: string;
|
|
49
|
+
}[], node: ts.Node) => {
|
|
50
|
+
node: ts.Node;
|
|
51
|
+
name: string;
|
|
52
|
+
}[];
|
|
53
|
+
protected isGraphOrPregelType: (type: ts.Type) => boolean;
|
|
54
|
+
protected getText(node: ts.Node): string;
|
|
55
|
+
protected reduceChildren<Acc>(node: ts.Node, fn: (acc: Acc, node: ts.Node) => Acc, initial: Acc): Acc;
|
|
56
|
+
static extractSchemas(target: string | {
|
|
57
|
+
contents: string;
|
|
58
|
+
files?: [fileName: string, contents: string][];
|
|
59
|
+
}, name: string, options?: {
|
|
60
|
+
strict?: boolean;
|
|
61
|
+
}): Record<string, GraphSchema>;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
@@ -161,7 +161,7 @@ export class SubgraphExtractor {
|
|
|
161
161
|
this.getText(this.sourceFile),
|
|
162
162
|
...typeExports.map(({ typeName, valueName }) => `export type ${typeName} = typeof ${valueName}`),
|
|
163
163
|
].join("\n\n");
|
|
164
|
-
const inferFilePath = "
|
|
164
|
+
const inferFilePath = "__langgraph__infer.mts";
|
|
165
165
|
const inferContents = [
|
|
166
166
|
...typeExports.map(({ typeName }) => `import type { ${typeName}} from "./__langgraph__source.mts"`),
|
|
167
167
|
this.inferFile.getText(this.inferFile),
|
|
@@ -281,7 +281,7 @@ export class SubgraphExtractor {
|
|
|
281
281
|
system.writeFile(vfsPath(path.resolve(dirname, name)), source);
|
|
282
282
|
}
|
|
283
283
|
const extract = ts.createProgram({
|
|
284
|
-
rootNames: [path.resolve(dirname, "./
|
|
284
|
+
rootNames: [path.resolve(dirname, "./__langgraph__infer.mts")],
|
|
285
285
|
options: compilerOptions,
|
|
286
286
|
host,
|
|
287
287
|
});
|
|
@@ -298,9 +298,9 @@ export class SubgraphExtractor {
|
|
|
298
298
|
return Object.fromEntries(exports.map(({ typeName, graphName }) => [
|
|
299
299
|
graphName,
|
|
300
300
|
{
|
|
301
|
+
state: trySymbol(schemaGenerator, `${typeName}__update`),
|
|
301
302
|
input: trySymbol(schemaGenerator, `${typeName}__input`),
|
|
302
303
|
output: trySymbol(schemaGenerator, `${typeName}__output`),
|
|
303
|
-
state: trySymbol(schemaGenerator, `${typeName}__update`),
|
|
304
304
|
config: trySymbol(schemaGenerator, `${typeName}__config`),
|
|
305
305
|
},
|
|
306
306
|
]));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import type { JSONSchema7 } from "json-schema";
|
|
3
|
+
type Args = {
|
|
4
|
+
ref: boolean;
|
|
5
|
+
aliasRef: boolean;
|
|
6
|
+
topRef: boolean;
|
|
7
|
+
titles: boolean;
|
|
8
|
+
defaultProps: boolean;
|
|
9
|
+
noExtraProps: boolean;
|
|
10
|
+
propOrder: boolean;
|
|
11
|
+
typeOfKeyword: boolean;
|
|
12
|
+
required: boolean;
|
|
13
|
+
strictNullChecks: boolean;
|
|
14
|
+
esModuleInterop: boolean;
|
|
15
|
+
experimentalDecorators: boolean;
|
|
16
|
+
out: string;
|
|
17
|
+
validationKeywords: string[];
|
|
18
|
+
include: string[];
|
|
19
|
+
excludePrivate: boolean;
|
|
20
|
+
uniqueNames: boolean;
|
|
21
|
+
rejectDateType: boolean;
|
|
22
|
+
id: string;
|
|
23
|
+
defaultNumberType: "number" | "integer";
|
|
24
|
+
constAsEnum: boolean;
|
|
25
|
+
};
|
|
26
|
+
type PartialArgs = Partial<Args>;
|
|
27
|
+
type RedefinedFields = "items" | "additionalItems" | "contains" | "properties" | "patternProperties" | "additionalProperties" | "dependencies" | "propertyNames" | "if" | "then" | "else" | "allOf" | "anyOf" | "oneOf" | "not" | "definitions";
|
|
28
|
+
type DefinitionOrBoolean = Definition | boolean;
|
|
29
|
+
interface Definition extends Omit<JSONSchema7, RedefinedFields> {
|
|
30
|
+
propertyOrder?: string[];
|
|
31
|
+
defaultProperties?: string[];
|
|
32
|
+
typeof?: "function";
|
|
33
|
+
items?: DefinitionOrBoolean | DefinitionOrBoolean[];
|
|
34
|
+
additionalItems?: DefinitionOrBoolean;
|
|
35
|
+
contains?: JSONSchema7;
|
|
36
|
+
properties?: {
|
|
37
|
+
[key: string]: DefinitionOrBoolean;
|
|
38
|
+
};
|
|
39
|
+
patternProperties?: {
|
|
40
|
+
[key: string]: DefinitionOrBoolean;
|
|
41
|
+
};
|
|
42
|
+
additionalProperties?: DefinitionOrBoolean;
|
|
43
|
+
dependencies?: {
|
|
44
|
+
[key: string]: DefinitionOrBoolean | string[];
|
|
45
|
+
};
|
|
46
|
+
propertyNames?: DefinitionOrBoolean;
|
|
47
|
+
if?: DefinitionOrBoolean;
|
|
48
|
+
then?: DefinitionOrBoolean;
|
|
49
|
+
else?: DefinitionOrBoolean;
|
|
50
|
+
allOf?: DefinitionOrBoolean[];
|
|
51
|
+
anyOf?: DefinitionOrBoolean[];
|
|
52
|
+
oneOf?: DefinitionOrBoolean[];
|
|
53
|
+
not?: DefinitionOrBoolean;
|
|
54
|
+
definitions?: {
|
|
55
|
+
[key: string]: DefinitionOrBoolean;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
type SymbolRef = {
|
|
59
|
+
name: string;
|
|
60
|
+
typeName: string;
|
|
61
|
+
fullyQualifiedName: string;
|
|
62
|
+
symbol: ts.Symbol;
|
|
63
|
+
};
|
|
64
|
+
declare class JsonSchemaGenerator {
|
|
65
|
+
private args;
|
|
66
|
+
private tc;
|
|
67
|
+
/**
|
|
68
|
+
* Holds all symbols within a custom SymbolRef object, containing useful
|
|
69
|
+
* information.
|
|
70
|
+
*/
|
|
71
|
+
private symbols;
|
|
72
|
+
/**
|
|
73
|
+
* All types for declarations of classes, interfaces, enums, and type aliases
|
|
74
|
+
* defined in all TS files.
|
|
75
|
+
*/
|
|
76
|
+
private allSymbols;
|
|
77
|
+
/**
|
|
78
|
+
* All symbols for declarations of classes, interfaces, enums, and type aliases
|
|
79
|
+
* defined in non-default-lib TS files.
|
|
80
|
+
*/
|
|
81
|
+
private userSymbols;
|
|
82
|
+
/**
|
|
83
|
+
* Maps from the names of base types to the names of the types that inherit from
|
|
84
|
+
* them.
|
|
85
|
+
*/
|
|
86
|
+
private inheritingTypes;
|
|
87
|
+
/**
|
|
88
|
+
* This map holds references to all reffed definitions, including schema
|
|
89
|
+
* overrides and generated definitions.
|
|
90
|
+
*/
|
|
91
|
+
private reffedDefinitions;
|
|
92
|
+
/**
|
|
93
|
+
* This map only holds explicit schema overrides. This helps differentiate between
|
|
94
|
+
* user defined schema overrides and generated definitions.
|
|
95
|
+
*/
|
|
96
|
+
private schemaOverrides;
|
|
97
|
+
/**
|
|
98
|
+
* This is a set of all the user-defined validation keywords.
|
|
99
|
+
*/
|
|
100
|
+
private userValidationKeywords;
|
|
101
|
+
/**
|
|
102
|
+
* If true, this makes constants be defined as enums with a single value. This is useful
|
|
103
|
+
* for cases where constant values are not supported, such as OpenAPI.
|
|
104
|
+
*/
|
|
105
|
+
private constAsEnum;
|
|
106
|
+
/**
|
|
107
|
+
* Types are assigned names which are looked up by their IDs. This is the
|
|
108
|
+
* map from type IDs to type names.
|
|
109
|
+
*/
|
|
110
|
+
private typeNamesById;
|
|
111
|
+
/**
|
|
112
|
+
* Whenever a type is assigned its name, its entry in this dictionary is set,
|
|
113
|
+
* so that we don't give the same name to two separate types.
|
|
114
|
+
*/
|
|
115
|
+
private typeIdsByName;
|
|
116
|
+
constructor(symbols: SymbolRef[], allSymbols: {
|
|
117
|
+
[name: string]: ts.Type;
|
|
118
|
+
}, userSymbols: {
|
|
119
|
+
[name: string]: ts.Symbol;
|
|
120
|
+
}, inheritingTypes: {
|
|
121
|
+
[baseName: string]: string[];
|
|
122
|
+
}, tc: ts.TypeChecker, args?: Args);
|
|
123
|
+
get ReffedDefinitions(): {
|
|
124
|
+
[key: string]: Definition;
|
|
125
|
+
};
|
|
126
|
+
private isFromDefaultLib;
|
|
127
|
+
private resetSchemaSpecificProperties;
|
|
128
|
+
/**
|
|
129
|
+
* Parse the comments of a symbol into the definition and other annotations.
|
|
130
|
+
*/
|
|
131
|
+
private parseCommentsIntoDefinition;
|
|
132
|
+
private getDefinitionForRootType;
|
|
133
|
+
private getReferencedTypeSymbol;
|
|
134
|
+
private getDefinitionForProperty;
|
|
135
|
+
private getEnumDefinition;
|
|
136
|
+
private getUnionDefinition;
|
|
137
|
+
private getIntersectionDefinition;
|
|
138
|
+
private getClassDefinition;
|
|
139
|
+
/**
|
|
140
|
+
* Gets/generates a globally unique type name for the given type
|
|
141
|
+
*/
|
|
142
|
+
private getTypeName;
|
|
143
|
+
private makeTypeNameUnique;
|
|
144
|
+
private recursiveTypeRef;
|
|
145
|
+
private getTypeDefinition;
|
|
146
|
+
setSchemaOverride(symbolName: string, schema: Definition): void;
|
|
147
|
+
getSchemaForSymbol(symbolName: string, includeReffedDefinitions?: boolean, includeAllOverrides?: boolean): Definition;
|
|
148
|
+
getSchemaForSymbols(symbolNames: string[], includeReffedDefinitions?: boolean, includeAllOverrides?: boolean): Definition;
|
|
149
|
+
getSymbols(name?: string): SymbolRef[];
|
|
150
|
+
getUserSymbols(): string[];
|
|
151
|
+
getMainFileSymbols(program: ts.Program, onlyIncludeFiles?: string[]): string[];
|
|
152
|
+
}
|
|
153
|
+
export declare function buildGenerator(program: ts.Program, args?: PartialArgs): JsonSchemaGenerator | null;
|
|
154
|
+
export {};
|