@langchain/langgraph-ui 0.0.19

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License Copyright (c) 2025 LangChain
2
+
3
+ Permission is hereby granted, free
4
+ of charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use, copy, modify, merge,
7
+ publish, distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ (including the next paragraph) shall be included in all copies or substantial
13
+ portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # LangGraph.js UI
2
+
3
+ Contains the logic for creating Generative UI bundles served via LangGraph API.
@@ -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}`,
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,32 @@
1
+ import { watch } from "./bundler.mjs";
2
+ import * as fs from "node:fs/promises";
3
+ import * as url from "node:url";
4
+ import * as path from "node:path";
5
+ import { z } from "zod";
6
+ const cmd = process.argv.at(-1);
7
+ if (cmd !== "dev")
8
+ throw new Error(`Invalid command "${cmd}"`);
9
+ const cwd = process.cwd();
10
+ const defs = z
11
+ .record(z.string(), z.string())
12
+ .parse(JSON.parse(process.env.LANGGRAPH_UI || "{}"));
13
+ const config = z
14
+ .object({ shared: z.array(z.string()).optional() })
15
+ .parse(JSON.parse(process.env.LANGGRAPH_UI_CONFIG || "{}"));
16
+ const UI_DIR = url.fileURLToPath(new URL("../../ui", import.meta.url));
17
+ // clear the files in the ui directory
18
+ await fs.rm(UI_DIR, { recursive: true, force: true });
19
+ // watch the files in the ui directory
20
+ await Promise.all(Object.entries(defs).map(async ([graphId, userPath]) => {
21
+ const folder = path.resolve(UI_DIR, graphId);
22
+ await fs.mkdir(folder, { recursive: true });
23
+ let promiseSeq = Promise.resolve();
24
+ await watch(graphId, { cwd, userPath, config }, (files) => {
25
+ promiseSeq = promiseSeq.then(async () => {
26
+ await Promise.all(files.map(async ({ basename, contents }) => {
27
+ const target = path.join(folder, basename);
28
+ await fs.writeFile(target, contents);
29
+ }));
30
+ }, (e) => console.error(e));
31
+ });
32
+ }));
@@ -0,0 +1 @@
1
+ export { build, watch } from "./bundler.mjs";
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export { build, watch } from "./bundler.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 ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@langchain/langgraph-ui",
3
+ "version": "0.0.19",
4
+ "type": "module",
5
+ "engines": {
6
+ "node": "^18.19.0 || >=20.16.0"
7
+ },
8
+ "license": "MIT",
9
+ "main": "./dist/index.mjs",
10
+ "bin": {
11
+ "langgraphjs-ui": "./dist/cli.mjs"
12
+ },
13
+ "files": [
14
+ "dist/"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git@github.com:langchain-ai/langgraphjs-api.git"
19
+ },
20
+ "dependencies": {
21
+ "zod": "^3.23.8",
22
+ "esbuild": "^0.25.0",
23
+ "esbuild-plugin-tailwindcss": "^2.0.1"
24
+ },
25
+ "devDependencies": {
26
+ "@types/react": "^19.0.8",
27
+ "@types/node": "^22.2.0",
28
+ "@types/react-dom": "^19.0.3",
29
+ "prettier": "^3.3.3",
30
+ "vitest": "^3.0.5",
31
+ "typescript": "^5.5.4"
32
+ },
33
+ "scripts": {
34
+ "clean": "npx -y bun scripts/clean.mjs",
35
+ "build": "npx -y bun scripts/build.mjs",
36
+ "typecheck": "tsc --noEmit",
37
+ "format": "prettier --write .",
38
+ "format:check": "prettier --check ."
39
+ }
40
+ }