Skip to content

Commit 972b66a

Browse files
authored
fix(api): support gen UI components with hyphens (#1360)
1 parent f01f84e commit 972b66a

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

.changeset/little-tips-check.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@langchain/langgraph-api": patch
3+
"@langchain/langgraph-cli": patch
4+
"@langchain/langgraph-ui": patch
5+
---
6+
7+
Support gen UI components namespaced with a hyphen

libs/langgraph-api/src/ui/load.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ api.post(
4444
);
4545
}
4646

47+
const stableName = agent.replace(/[^a-zA-Z0-9]/g, "_");
4748
const js = files.find((i) => path.extname(i.basename) === ".js");
4849
if (js) {
4950
result.push(
50-
`<script src="http://${host}/ui/${agent}/${js.basename}" onload='__LGUI_${agent}.render(${messageName}, "{{shadowRootId}}")'></script>`
51+
`<script src="http://${host}/ui/${agent}/${js.basename}" onload='__LGUI_${stableName}.render(${messageName}, "{{shadowRootId}}")'></script>`
5152
);
5253
}
5354

libs/langgraph-api/tests/api.test.mts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,9 +2532,12 @@ it("dynamic graph", async () => {
25322532
});
25332533

25342534
it("generative ui", async () => {
2535-
const ui = await client["~ui"].getComponent("agent", "weather-component");
2535+
const ui = await client["~ui"].getComponent(
2536+
"agent-alias",
2537+
"weather-component"
2538+
);
25362539
expect(ui).toContain(
2537-
`<script src="http://localhost:2024/ui/agent/entrypoint.js" onload='__LGUI_agent.render("weather-component", "{{shadowRootId}}")'></script>`
2540+
`<script src="http://localhost:2024/ui/agent-alias/entrypoint.js" onload='__LGUI_agent_alias.render("weather-component", "{{shadowRootId}}")'></script>`
25382541
);
25392542

25402543
const match = /src="(?<src>[^"]+)"/.exec(ui);

libs/langgraph-api/tests/graphs/langgraph.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"agent_simple": "./agent_simple.mts:graph"
1111
},
1212
"ui": {
13-
"agent": "./agent/ui.tsx"
13+
"agent-alias": "./agent/ui.tsx"
1414
},
1515
"http": {
1616
"app": "./http.mts:app"

libs/langgraph-ui/src/bundler.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ function setup(
102102
...(args.config?.shared ?? []),
103103
],
104104
plugins: [tailwind(), entrypointPlugin(args), registerPlugin(onResult)],
105-
globalName: `__LGUI_${agentName}`,
105+
globalName: `__LGUI_${agentName.replace(/[^a-zA-Z0-9]/g, "_")}`,
106106
};
107107
}
108108

0 commit comments

Comments
 (0)