@langgraph-js/ui 4.0.1 → 4.0.3

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.
Binary file
File without changes
package/cli.mjs CHANGED
@@ -18,9 +18,11 @@ console.log("启动 LangGraph UI...");
18
18
  console.log(`命令: vite preview ${args.join(" ")}`);
19
19
 
20
20
  // 使用 spawn 而不是 exec,以便更好地处理输入/输出流和参数
21
- const childProcess = spawn("npx", ["vite", "preview", ...args], {
21
+ const childProcess = spawn("npx", ["vite", "dev", "--config", "../vite.config.preview.ts", ...args], {
22
22
  stdio: "inherit", // 继承父进程的 stdio,使输出直接显示在控制台
23
23
  shell: true,
24
+ // cwd 是 ./dist
25
+ cwd: "./dist",
24
26
  });
25
27
 
26
28
  // 处理子进程退出
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langgraph-js/ui",
3
- "version": "4.0.1",
3
+ "version": "4.0.3",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -0,0 +1,39 @@
1
+ import { Plugin } from "vite";
2
+ import { Readable } from "stream";
3
+ import { app } from "@langgraph-js/open-smith/dist/app.js";
4
+ export const OpenSmithPlugin = () =>
5
+ ({
6
+ name: "open-smith",
7
+ configureServer(server) {
8
+ console.log("open-smith is open on http://localhost:4173/api/open-smith/ui/index.html");
9
+ server.middlewares.use("/api/open-smith", async (req, res, next) => {
10
+ try {
11
+ const body = Readable.toWeb(req);
12
+ // Build a compatible Request for Fetch API
13
+ const url = `http://localhost${req.url}`;
14
+ const fetchRequest = new Request(url, {
15
+ method: req.method,
16
+ headers: req.headers as any,
17
+ body: req.method && !["GET", "HEAD"].includes(req.method.toUpperCase()) && body ? (body as any) : undefined,
18
+ ...(req.method && !["GET", "HEAD"].includes(req.method.toUpperCase()) && body ? { duplex: "half" as const } : {}),
19
+ });
20
+
21
+ // Proxy the request to app.basePath handler
22
+ const response = await app.basePath("/api/open-smith").fetch(fetchRequest);
23
+
24
+ // Set status and headers
25
+ res.statusCode = response.status;
26
+ // @ts-ignore
27
+ for (const [key, value] of response.headers.entries()) {
28
+ res.setHeader(key, value);
29
+ }
30
+
31
+ // Send the response body
32
+ const arrayBuffer = await response.arrayBuffer();
33
+ res.end(Buffer.from(arrayBuffer));
34
+ } catch (error) {
35
+ console.log(error);
36
+ }
37
+ });
38
+ },
39
+ }) as Plugin;
@@ -5,5 +5,5 @@
5
5
  "moduleResolution": "bundler",
6
6
  "allowSyntheticDefaultImports": true
7
7
  },
8
- "include": ["vite.config.ts"]
8
+ "include": ["vite.config.ts", "src/OpenSmithPlugin.ts"]
9
9
  }
@@ -0,0 +1,35 @@
1
+ import { defineConfig, Plugin } from "vite";
2
+ import basicSsl from "@vitejs/plugin-basic-ssl";
3
+ import { OpenSmithPlugin } from "./src/OpenSmithPlugin";
4
+
5
+ // https://vitejs.dev/config/
6
+ export default defineConfig(({ mode }) => {
7
+ const isHttps = mode === "https";
8
+ return {
9
+ plugins: [isHttps ? basicSsl() : undefined, OpenSmithPlugin()],
10
+ resolve: {
11
+ alias: {
12
+ "@langgraph-js/sdk": new URL("../langgraph-client/src", import.meta.url).pathname,
13
+ "@/": new URL("./src/", import.meta.url).pathname,
14
+ },
15
+ },
16
+ optimizeDeps: {
17
+ exclude: ["@langgraph-js/ui", "@langgraph-js/sdk"],
18
+ },
19
+ server: {
20
+ proxy: {
21
+ "/api/langgraph": {
22
+ target: "http://localhost:8123",
23
+ changeOrigin: true,
24
+ rewrite: (path) => path.replace(/^\/api\/langgraph/, ""),
25
+ },
26
+ },
27
+ // headers: {
28
+ // "Cross-Origin-Opener-Policy": "same-origin",
29
+ // "Cross-Origin-Embedder-Policy": "require-corp",
30
+ // "cross-origin-resource-policy": "cross-origin",
31
+ // },
32
+ port: 1111,
33
+ },
34
+ };
35
+ });
package/vite.config.ts CHANGED
@@ -2,49 +2,12 @@ import react from "@vitejs/plugin-react";
2
2
  import { defineConfig, Plugin } from "vite";
3
3
  import basicSsl from "@vitejs/plugin-basic-ssl";
4
4
  import tailwindcss from "@tailwindcss/vite";
5
- import { Readable } from "stream";
6
- const OpenSmithPlugin = () =>
7
- ({
8
- name: "open-smith",
9
- configureServer(server) {
10
- server.middlewares.use("/api/open-smith", async (req, res, next) => {
11
- const { app } = await import("@langgraph-js/open-smith/dist/app.js");
12
- try {
13
- const body = Readable.toWeb(req);
14
- // Build a compatible Request for Fetch API
15
- const url = `http://localhost${req.url}`;
16
- const fetchRequest = new Request(url, {
17
- method: req.method,
18
- headers: req.headers as any,
19
- body: req.method && !["GET", "HEAD"].includes(req.method.toUpperCase()) && body ? body : undefined,
20
- ...(req.method && !["GET", "HEAD"].includes(req.method.toUpperCase()) && body ? { duplex: "half" as const } : {}),
21
- });
22
-
23
- // Proxy the request to app.basePath handler
24
- const response = await app.basePath("/api/open-smith").fetch(fetchRequest);
25
-
26
- // Set status and headers
27
- res.statusCode = response.status;
28
- // @ts-ignore
29
- for (const [key, value] of response.headers.entries()) {
30
- res.setHeader(key, value);
31
- }
32
-
33
- // Send the response body
34
- const arrayBuffer = await response.arrayBuffer();
35
- res.end(Buffer.from(arrayBuffer));
36
- } catch (error) {
37
- console.log(error);
38
- }
39
- });
40
- },
41
- }) as Plugin;
42
5
 
43
6
  // https://vitejs.dev/config/
44
- export default defineConfig(({ mode }) => {
7
+ export default defineConfig(({ mode, command }) => {
45
8
  const isHttps = mode === "https";
46
9
  return {
47
- plugins: [react(), tailwindcss(), isHttps ? basicSsl() : undefined, process.env.NODE_ENV === "development" && OpenSmithPlugin()],
10
+ plugins: [react(), tailwindcss(), isHttps ? basicSsl() : undefined],
48
11
  resolve: {
49
12
  alias: {
50
13
  "@langgraph-js/sdk": new URL("../langgraph-client/src", import.meta.url).pathname,