fix(api): support gen UI components with hyphens (#1360)

This commit is contained in:
David Duong
2025-07-07 15:26:30 +02:00
committed by GitHub
parent f01f84ed3e
commit 972b66ae62
5 changed files with 16 additions and 5 deletions
+7
View File
@@ -0,0 +1,7 @@
---
"@langchain/langgraph-api": patch
"@langchain/langgraph-cli": patch
"@langchain/langgraph-ui": patch
---
Support gen UI components namespaced with a hyphen
+2 -1
View File
@@ -44,10 +44,11 @@ api.post(
);
}
const stableName = agent.replace(/[^a-zA-Z0-9]/g, "_");
const js = files.find((i) => path.extname(i.basename) === ".js");
if (js) {
result.push(
`<script src="http://${host}/ui/${agent}/${js.basename}" onload='__LGUI_${agent}.render(${messageName}, "{{shadowRootId}}")'></script>`
`<script src="http://${host}/ui/${agent}/${js.basename}" onload='__LGUI_${stableName}.render(${messageName}, "{{shadowRootId}}")'></script>`
);
}
+5 -2
View File
@@ -2532,9 +2532,12 @@ it("dynamic graph", async () => {
});
it("generative ui", async () => {
const ui = await client["~ui"].getComponent("agent", "weather-component");
const ui = await client["~ui"].getComponent(
"agent-alias",
"weather-component"
);
expect(ui).toContain(
`<script src="http://localhost:2024/ui/agent/entrypoint.js" onload='__LGUI_agent.render("weather-component", "{{shadowRootId}}")'></script>`
`<script src="http://localhost:2024/ui/agent-alias/entrypoint.js" onload='__LGUI_agent_alias.render("weather-component", "{{shadowRootId}}")'></script>`
);
const match = /src="(?<src>[^"]+)"/.exec(ui);
@@ -10,7 +10,7 @@
"agent_simple": "./agent_simple.mts:graph"
},
"ui": {
"agent": "./agent/ui.tsx"
"agent-alias": "./agent/ui.tsx"
},
"http": {
"app": "./http.mts:app"
+1 -1
View File
@@ -102,7 +102,7 @@ function setup(
...(args.config?.shared ?? []),
],
plugins: [tailwind(), entrypointPlugin(args), registerPlugin(onResult)],
globalName: `__LGUI_${agentName}`,
globalName: `__LGUI_${agentName.replace(/[^a-zA-Z0-9]/g, "_")}`,
};
}