@langchain/langgraph-api 1.4.0 → 1.4.1

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.
@@ -0,0 +1,35 @@
1
+ import type { StartServerOptions } from "../server.mjs";
2
+ /** Default loader: tsx CLI with built-in watch. */
3
+ export declare const DEFAULT_NODE_LOADER = "tsx";
4
+ type LoaderRegistration = {
5
+ specifier: string;
6
+ flag: "--loader" | "--import";
7
+ };
8
+ /**
9
+ * Shorthand loader names mapped to Node registration hooks.
10
+ * Use `"tsx"` (not `"tsx/esm"`) to spawn via the tsx CLI instead.
11
+ *
12
+ * `ts-node` uses `--loader` (not `--import`) because `ts-node/esm` is a
13
+ * custom ESM loader hook. Node 20+ deprecates `--loader` in favor of
14
+ * `module.register()`, but ts-node still documents this entrypoint.
15
+ */
16
+ export declare const LOADER_REGISTRATIONS: Record<string, LoaderRegistration>;
17
+ export declare function resolveNodeLoader(configLoader: string | undefined, env?: NodeJS.ProcessEnv): string;
18
+ export declare function resolveLoaderRegistration(loader: string, resolve: (specifier: string) => string): LoaderRegistration & {
19
+ path: string;
20
+ };
21
+ export declare function resolveLoaderPath(specifier: string, loader: string, resolve: (specifier: string) => string): string;
22
+ /** Convert a resolved filesystem path to a Node `--loader`/`--import` URL. */
23
+ export declare function toNodeModuleUrl(path: string): string;
24
+ export declare function usesTsxCli(loader: string): boolean;
25
+ export declare function buildSpawnArgs(options: {
26
+ nodeLoader: string;
27
+ reload: boolean;
28
+ pid: number;
29
+ payload: StartServerOptions;
30
+ resolve: (specifier: string) => string;
31
+ }): {
32
+ command: string;
33
+ args: string[];
34
+ };
35
+ export {};
@@ -0,0 +1,85 @@
1
+ import { isAbsolute } from "node:path";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ /** Default loader: tsx CLI with built-in watch. */
4
+ export const DEFAULT_NODE_LOADER = "tsx";
5
+ /**
6
+ * Shorthand loader names mapped to Node registration hooks.
7
+ * Use `"tsx"` (not `"tsx/esm"`) to spawn via the tsx CLI instead.
8
+ *
9
+ * `ts-node` uses `--loader` (not `--import`) because `ts-node/esm` is a
10
+ * custom ESM loader hook. Node 20+ deprecates `--loader` in favor of
11
+ * `module.register()`, but ts-node still documents this entrypoint.
12
+ */
13
+ export const LOADER_REGISTRATIONS = {
14
+ "ts-node": { specifier: "ts-node/esm", flag: "--loader" },
15
+ "ts-node/esm": { specifier: "ts-node/esm", flag: "--loader" },
16
+ };
17
+ export function resolveNodeLoader(configLoader, env = process.env) {
18
+ const envLoader = env.LANGGRAPH_NODE_LOADER?.trim();
19
+ if (envLoader)
20
+ return envLoader;
21
+ return configLoader ?? DEFAULT_NODE_LOADER;
22
+ }
23
+ export function resolveLoaderRegistration(loader, resolve) {
24
+ const registration = LOADER_REGISTRATIONS[loader] ?? {
25
+ specifier: loader,
26
+ flag: "--import",
27
+ };
28
+ const path = resolveLoaderPath(registration.specifier, loader, resolve);
29
+ return { ...registration, path };
30
+ }
31
+ export function resolveLoaderPath(specifier, loader, resolve) {
32
+ if (specifier.startsWith("file://")) {
33
+ return fileURLToPath(specifier);
34
+ }
35
+ if (isAbsolute(specifier)) {
36
+ return specifier;
37
+ }
38
+ try {
39
+ return fileURLToPath(new URL(resolve(specifier)));
40
+ }
41
+ catch {
42
+ const hint = loader === "ts-node" || loader.startsWith("ts-node/")
43
+ ? ' Install "ts-node" and enable "emitDecoratorMetadata" in tsconfig when using reflect-metadata.'
44
+ : "";
45
+ throw new Error(`node_loader "${loader}" could not be resolved.${hint} Install the package or provide a valid module specifier, file path, or file:// URL.`);
46
+ }
47
+ }
48
+ /** Convert a resolved filesystem path to a Node `--loader`/`--import` URL. */
49
+ export function toNodeModuleUrl(path) {
50
+ if (path.startsWith("file://"))
51
+ return path;
52
+ return pathToFileURL(path).href;
53
+ }
54
+ export function usesTsxCli(loader) {
55
+ return loader === DEFAULT_NODE_LOADER;
56
+ }
57
+ export function buildSpawnArgs(options) {
58
+ const payloadArg = JSON.stringify(options.payload);
59
+ const sharedArgs = [options.pid.toString(), payloadArg];
60
+ const preloadUrl = new URL(options.resolve("../preload.mjs")).toString();
61
+ const entrypointPath = fileURLToPath(new URL(options.resolve("./entrypoint.mjs")));
62
+ if (usesTsxCli(options.nodeLoader)) {
63
+ const args = [
64
+ fileURLToPath(new URL("../../cli.mjs", options.resolve("tsx/esm/api"))),
65
+ ...(options.reload ? ["watch"] : []),
66
+ "--clear-screen=false",
67
+ "--import",
68
+ preloadUrl,
69
+ entrypointPath,
70
+ ...sharedArgs,
71
+ ];
72
+ return { command: process.execPath, args };
73
+ }
74
+ const loader = resolveLoaderRegistration(options.nodeLoader, options.resolve);
75
+ const args = [
76
+ ...(options.reload ? ["--watch"] : []),
77
+ loader.flag,
78
+ toNodeModuleUrl(loader.path),
79
+ "--import",
80
+ preloadUrl,
81
+ entrypointPath,
82
+ ...sharedArgs,
83
+ ];
84
+ return { command: process.execPath, args };
85
+ }
@@ -1,7 +1,9 @@
1
+ import { type StartServerOptions } from "../server.mjs";
1
2
  export declare function spawnServer(args: {
2
3
  host: string;
3
4
  port: string;
4
5
  nJobsPerWorker: string;
6
+ reload?: boolean;
5
7
  }, context: {
6
8
  config: {
7
9
  graphs: Record<string, string | {
@@ -16,23 +18,8 @@ export declare function spawnServer(args: {
16
18
  path?: string;
17
19
  disable_studio_auth?: boolean;
18
20
  };
19
- http?: {
20
- app?: string;
21
- disable_assistants?: boolean;
22
- disable_threads?: boolean;
23
- disable_runs?: boolean;
24
- disable_store?: boolean;
25
- disable_meta?: boolean;
26
- cors?: {
27
- allow_origins?: string[];
28
- allow_methods?: string[];
29
- allow_headers?: string[];
30
- allow_credentials?: boolean;
31
- allow_origin_regex?: string;
32
- expose_headers?: string[];
33
- max_age?: number;
34
- };
35
- };
21
+ node_loader?: string;
22
+ http?: StartServerOptions["http"];
36
23
  };
37
24
  env: NodeJS.ProcessEnv;
38
25
  hostUrl: string;
@@ -1,5 +1,6 @@
1
- import { fileURLToPath } from "node:url";
2
1
  import { spawn } from "node:child_process";
2
+ import { StartServerSchema } from "../server.mjs";
3
+ import { buildSpawnArgs, resolveNodeLoader } from "./spawn-args.mjs";
3
4
  export async function spawnServer(args, context, options) {
4
5
  const localUrl = `http://${args.host}:${args.port}`;
5
6
  const studioUrl = `${context.hostUrl}/studio?baseUrl=${localUrl}`;
@@ -17,26 +18,26 @@ This in-memory server is designed for development and testing.
17
18
  For production use, please use LangSmith Deployment.
18
19
 
19
20
  `);
20
- return spawn(process.execPath, [
21
- fileURLToPath(new URL("../../cli.mjs", import.meta.resolve("tsx/esm/api"))),
22
- "watch",
23
- "--clear-screen=false",
24
- "--import",
25
- new URL(import.meta.resolve("../preload.mjs")).toString(),
26
- fileURLToPath(new URL(import.meta.resolve("./entrypoint.mjs"))),
27
- options.pid.toString(),
28
- JSON.stringify({
29
- port: Number.parseInt(args.port, 10),
30
- nWorkers: Number.parseInt(args.nJobsPerWorker, 10),
31
- host: args.host,
32
- graphs: context.config.graphs,
33
- auth: context.config.auth,
34
- ui: context.config.ui,
35
- ui_config: context.config.ui_config,
36
- cwd: options.projectCwd,
37
- http: context.config.http,
38
- }),
39
- ], {
21
+ const nodeLoader = resolveNodeLoader(context.config.node_loader, context.env);
22
+ const payload = StartServerSchema.parse({
23
+ port: Number.parseInt(args.port, 10),
24
+ nWorkers: Number.parseInt(args.nJobsPerWorker, 10),
25
+ host: args.host,
26
+ graphs: context.config.graphs,
27
+ auth: context.config.auth,
28
+ ui: context.config.ui,
29
+ ui_config: context.config.ui_config,
30
+ cwd: options.projectCwd,
31
+ http: context.config.http,
32
+ });
33
+ const { command, args: spawnArgs } = buildSpawnArgs({
34
+ nodeLoader,
35
+ reload: args.reload ?? true,
36
+ pid: options.pid,
37
+ payload,
38
+ resolve: (specifier) => import.meta.resolve(specifier),
39
+ });
40
+ return spawn(command, spawnArgs, {
40
41
  stdio: ["inherit", "inherit", "inherit", "ipc"],
41
42
  env: {
42
43
  ...context.env,
package/dist/server.d.mts CHANGED
@@ -167,7 +167,8 @@ export declare const StartServerSchema: z.ZodObject<{
167
167
  disable_meta?: boolean | undefined;
168
168
  } | undefined;
169
169
  }>;
170
- export declare function startServer(options: z.infer<typeof StartServerSchema>, storage?: {
170
+ export type StartServerOptions = z.infer<typeof StartServerSchema>;
171
+ export declare function startServer(options: StartServerOptions, storage?: {
171
172
  ops?: Ops;
172
173
  }): Promise<{
173
174
  host: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-api",
3
- "version": "1.4.0",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "^18.19.0 || >=20.16.0"
@@ -71,18 +71,22 @@
71
71
  "winston": "^3.17.0",
72
72
  "winston-console-format": "^1.0.8",
73
73
  "zod": "^3.25.76 || ^4",
74
- "@langchain/langgraph-ui": "1.4.0"
74
+ "@langchain/langgraph-ui": "1.4.1"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "@langchain/core": "^1.1.48",
78
78
  "@langchain/langgraph": "^1.3.6",
79
79
  "@langchain/langgraph-checkpoint": "~0.0.16 || ^0.1.0 || ^1.0.0",
80
80
  "@langchain/langgraph-sdk": "^1.9.3-rc.0",
81
+ "ts-node": "^10.9.2",
81
82
  "typescript": "^5.5.4"
82
83
  },
83
84
  "peerDependenciesMeta": {
84
85
  "@langchain/langgraph-sdk": {
85
86
  "optional": true
87
+ },
88
+ "ts-node": {
89
+ "optional": true
86
90
  }
87
91
  },
88
92
  "devDependencies": {
@@ -96,12 +100,13 @@
96
100
  "jose": "^6.0.10",
97
101
  "langchain": "^1.5.1",
98
102
  "postgres": "^3.4.5",
103
+ "ts-node": "^10.9.2",
99
104
  "typescript": "^4.9.5 || ^5.4.5",
100
105
  "vitest": "^4.1.0",
101
106
  "wait-port": "^1.1.0",
102
- "@langchain/langgraph": "1.4.5",
103
- "@langchain/langgraph-checkpoint": "1.1.2",
104
- "@langchain/langgraph-sdk": "1.9.24"
107
+ "@langchain/langgraph": "1.4.6",
108
+ "@langchain/langgraph-checkpoint": "1.1.3",
109
+ "@langchain/langgraph-sdk": "1.9.25"
105
110
  },
106
111
  "scripts": {
107
112
  "clean": "rm -rf dist/ .turbo/ ./tests/graphs/.langgraph_api/ ./tests/protocol-v2/graphs/.langgraph_api/",