@langchain/langgraph-ui 1.1.8 → 1.1.10

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.d.mts ADDED
@@ -0,0 +1,28 @@
1
+ import { z } from "zod/v3";
2
+ declare const ConfigSchema: z.ZodObject<{
3
+ shared: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
4
+ }, "strip", z.ZodTypeAny, {
5
+ shared?: string[];
6
+ }, {
7
+ shared?: string[];
8
+ }>;
9
+ declare const DefsSchema: z.ZodRecord<z.ZodString, z.ZodString>;
10
+ interface BuildEnvType {
11
+ cwd?: string;
12
+ defs?: z.infer<typeof DefsSchema>;
13
+ config?: z.infer<typeof ConfigSchema>;
14
+ }
15
+ interface BuildOptionsType extends BuildEnvType {
16
+ output: string;
17
+ }
18
+ export declare function build(options: BuildOptionsType): Promise<void>;
19
+ type WatchOptionsType = ({
20
+ output: string;
21
+ } | {
22
+ onOutput: (graphId: string, result: {
23
+ basename: string;
24
+ contents: Uint8Array;
25
+ }[]) => void;
26
+ }) & BuildEnvType;
27
+ export declare function watch(options: WatchOptionsType): Promise<void>;
28
+ export {};
package/dist/api.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { z } from "zod/v3";
2
+ import * as fs from "node:fs/promises";
3
+ import * as path from "node:path";
4
+ import * as bundler from "./bundler.mjs";
5
+ const ConfigSchema = z.object({ shared: z.array(z.string()).optional() });
6
+ const DefsSchema = z.record(z.string(), z.string());
7
+ function getBuildEnv(options) {
8
+ const cwd = options?.cwd ?? process.cwd();
9
+ const defs = options?.defs ??
10
+ DefsSchema.parse(JSON.parse(process.env.LANGGRAPH_UI || "{}"));
11
+ const config = options?.config ??
12
+ ConfigSchema.parse(JSON.parse(process.env.LANGGRAPH_UI_CONFIG || "{}"));
13
+ return { cwd, defs, config };
14
+ }
15
+ export async function build(options) {
16
+ const { cwd, defs, config } = getBuildEnv(options);
17
+ const fullPath = path.resolve(cwd, options.output);
18
+ const publicPath = path.resolve(fullPath, "public");
19
+ const schemasPath = path.resolve(fullPath, "schemas.json");
20
+ const schemas = {};
21
+ await Promise.all(Object.entries(defs).map(async ([graphId, userPath]) => {
22
+ const folder = path.resolve(publicPath, graphId);
23
+ await fs.mkdir(folder, { recursive: true });
24
+ const files = await bundler.build(graphId, { userPath, cwd, config });
25
+ await Promise.all(files.map(async (item) => {
26
+ const target = path.resolve(folder, item.basename);
27
+ await fs.writeFile(target, item.contents);
28
+ schemas[graphId] ??= { assets: [], name: graphId };
29
+ schemas[graphId].assets.push(path.relative(folder, target));
30
+ }));
31
+ }));
32
+ await fs.writeFile(schemasPath, JSON.stringify(schemas), {
33
+ encoding: "utf-8",
34
+ });
35
+ }
36
+ export async function watch(options) {
37
+ const { cwd, config, defs } = getBuildEnv(options);
38
+ if ("onOutput" in options) {
39
+ await Promise.all(Object.entries(defs).map(async ([graphId, userPath]) => {
40
+ await bundler.watch(graphId, { cwd, config, userPath }, (files) => options.onOutput(graphId, files));
41
+ }));
42
+ return;
43
+ }
44
+ const fullPath = path.resolve(cwd, options.output);
45
+ const publicPath = path.resolve(fullPath, "public");
46
+ const schemasPath = path.resolve(fullPath, "schemas.json");
47
+ let promiseSeq = Promise.resolve();
48
+ const schemas = {};
49
+ await Promise.all(Object.entries(defs).map(async ([graphId, userPath]) => {
50
+ const folder = path.resolve(publicPath, graphId);
51
+ await fs.mkdir(folder, { recursive: true });
52
+ await bundler.watch(graphId, { cwd, userPath, config }, (files) => {
53
+ promiseSeq = promiseSeq.then(async () => {
54
+ await Promise.all(files.map(async ({ basename, contents }) => {
55
+ const target = path.resolve(folder, basename);
56
+ await fs.writeFile(target, contents);
57
+ schemas[graphId] ??= { assets: [], name: graphId };
58
+ schemas[graphId].assets.push(path.relative(folder, target));
59
+ }));
60
+ await fs.writeFile(schemasPath, JSON.stringify(schemas), {
61
+ encoding: "utf-8",
62
+ });
63
+ }, (e) => console.error(e));
64
+ });
65
+ }));
66
+ }
@@ -0,0 +1,21 @@
1
+ import { type BuildOptions } from "esbuild";
2
+ export declare function build(agentName: string, args: {
3
+ cwd: string;
4
+ userPath: string;
5
+ config?: {
6
+ shared?: string[];
7
+ };
8
+ }): Promise<{
9
+ basename: string;
10
+ contents: Uint8Array;
11
+ }[]>;
12
+ export declare function watch(agentName: string, args: {
13
+ cwd: string;
14
+ userPath: string;
15
+ config?: {
16
+ shared?: string[];
17
+ };
18
+ }, onResult: (result: {
19
+ basename: string;
20
+ contents: Uint8Array;
21
+ }[]) => void): Promise<import("esbuild").BuildContext<BuildOptions>>;
@@ -0,0 +1,86 @@
1
+ import * as path from "node:path";
2
+ import * as url from "node:url";
3
+ import * as fs from "node:fs";
4
+ import { build as runBuild, context as runContext, } from "esbuild";
5
+ import tailwind from "esbuild-plugin-tailwindcss";
6
+ const renderTemplate = await fs.promises.readFile(url.fileURLToPath(new URL("./render.template.mts", import.meta.url)), "utf-8");
7
+ function entrypointPlugin(paths) {
8
+ const fullPath = path.resolve(paths.cwd, paths.userPath);
9
+ let relativeUiPath = path
10
+ .relative(paths.cwd, fullPath)
11
+ .replaceAll(path.sep, "/");
12
+ if (relativeUiPath.startsWith("../")) {
13
+ throw new Error(`UI path must be relative to the project root. Received: "${relativeUiPath}"`);
14
+ }
15
+ if (!relativeUiPath.startsWith("./"))
16
+ relativeUiPath = `./${relativeUiPath}`;
17
+ return {
18
+ name: "entrypoint",
19
+ setup(build) {
20
+ build.onResolve({ filter: /^entrypoint$/ }, () => ({
21
+ path: path.resolve(path.dirname(fullPath), "ui.entrypoint.tsx"),
22
+ namespace: "entrypoint-ns",
23
+ }));
24
+ build.onLoad({ filter: /.*/, namespace: "entrypoint-ns" }, () => ({
25
+ resolveDir: paths.cwd,
26
+ contents: [
27
+ `import ui from "${relativeUiPath}"`,
28
+ renderTemplate,
29
+ `export const render = createRenderer(ui)`,
30
+ ].join("\n"),
31
+ loader: "tsx",
32
+ }));
33
+ },
34
+ };
35
+ }
36
+ function registerPlugin(onEnd) {
37
+ const textEncoder = new TextEncoder();
38
+ return {
39
+ name: "require-transform",
40
+ setup(build) {
41
+ build.onEnd(async (result) => {
42
+ const newResult = [];
43
+ for (const item of result.outputFiles ?? []) {
44
+ let basename = path.basename(item.path);
45
+ let contents = item.contents;
46
+ if (basename === "entrypoint.js") {
47
+ contents = textEncoder.encode(item.text.replaceAll(`typeof require !== "undefined" ? require`, `typeof globalThis[Symbol.for("LGUI_REQUIRE")] !== "undefined" ? globalThis[Symbol.for("LGUI_REQUIRE")]`));
48
+ }
49
+ newResult.push({ basename, contents });
50
+ }
51
+ if (newResult.length > 0)
52
+ onEnd(newResult);
53
+ });
54
+ },
55
+ };
56
+ }
57
+ function setup(agentName, args, onResult) {
58
+ return {
59
+ write: false,
60
+ outdir: path.resolve(args.cwd, "dist"),
61
+ entryPoints: ["entrypoint"],
62
+ bundle: true,
63
+ platform: "browser",
64
+ target: "es2020",
65
+ jsx: "automatic",
66
+ external: [
67
+ "react",
68
+ "react-dom",
69
+ "@langchain/langgraph-sdk",
70
+ "@langchain/langgraph-sdk/react-ui",
71
+ ...(args.config?.shared ?? []),
72
+ ],
73
+ plugins: [tailwind(), entrypointPlugin(args), registerPlugin(onResult)],
74
+ globalName: `__LGUI_${agentName.replace(/[^a-zA-Z0-9]/g, "_")}`,
75
+ };
76
+ }
77
+ export async function build(agentName, args) {
78
+ let results = [];
79
+ await runBuild(setup(agentName, args, (result) => (results = result)));
80
+ return results;
81
+ }
82
+ export async function watch(agentName, args, onResult) {
83
+ const ctx = await runContext(setup(agentName, args, onResult));
84
+ await ctx.watch();
85
+ return ctx;
86
+ }
package/dist/cli.mjs ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from "@commander-js/extra-typings";
3
+ import * as api from "./api.mjs";
4
+ const builder = new Command().name("langgraphjs-ui");
5
+ builder
6
+ .command("build")
7
+ .requiredOption("-o, --output <string>", "Output directory")
8
+ .action(api.build);
9
+ builder
10
+ .command("watch")
11
+ .requiredOption("-o, --output <string>", "Output directory")
12
+ .action(api.watch);
13
+ builder.parse();
@@ -0,0 +1 @@
1
+ export { build, watch } from "./api.mjs";
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { build, watch } from "./api.mjs";
@@ -0,0 +1,27 @@
1
+ import type { ComponentClass, FunctionComponent } from "react";
2
+
3
+ const STORE_SYMBOL = Symbol.for("LGUI_EXT_STORE");
4
+
5
+ declare global {
6
+ interface Window {
7
+ [STORE_SYMBOL]: {
8
+ respond: (
9
+ shadowRootId: string,
10
+ component: FunctionComponent | ComponentClass,
11
+ renderEl: HTMLElement
12
+ ) => void;
13
+ };
14
+ }
15
+ }
16
+
17
+ // @ts-ignore
18
+ function createRenderer(
19
+ components: Record<string, FunctionComponent | ComponentClass>
20
+ ) {
21
+ return (name: string, shadowRootId: string) => {
22
+ const root = document.getElementById(shadowRootId)!.shadowRoot;
23
+ const renderEl = document.createElement("div");
24
+ root!.appendChild(renderEl);
25
+ window[STORE_SYMBOL].respond(shadowRootId, components[name], renderEl);
26
+ };
27
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-ui",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": "^18.19.0 || >=20.16.0"
@@ -18,15 +18,6 @@
18
18
  "url": "git+ssh://git@github.com/langchain-ai/langgraphjs.git",
19
19
  "directory": "libs/langgraph-ui"
20
20
  },
21
- "scripts": {
22
- "clean": "rm -rf dist/ .turbo/",
23
- "build": "yarn turbo:command build:internal --filter=@langchain/langgraph-ui",
24
- "build:internal": "yarn clean && node scripts/build.mjs",
25
- "prepublish": "yarn build",
26
- "typecheck": "tsc --noEmit",
27
- "format": "prettier --write .",
28
- "format:check": "prettier --check ."
29
- },
30
21
  "dependencies": {
31
22
  "@commander-js/extra-typings": "^13.0.0",
32
23
  "commander": "^13.0.0",
@@ -41,5 +32,14 @@
41
32
  "prettier": "^2.8.3",
42
33
  "typescript": "^4.9.5 || ^5.4.5",
43
34
  "vitest": "^3.2.4"
35
+ },
36
+ "scripts": {
37
+ "clean": "rm -rf dist/ .turbo/",
38
+ "build": "pnpm turbo build:internal --filter=@langchain/langgraph-ui",
39
+ "build:internal": "pnpm clean && node scripts/build.mjs",
40
+ "prepublish": "pnpm build",
41
+ "typecheck": "tsc --noEmit",
42
+ "format": "prettier --write .",
43
+ "format:check": "prettier --check ."
44
44
  }
45
- }
45
+ }