Skip to content

Commit 4047f90

Browse files
committed
Move web and chat layouts out of component
1 parent 0c18f65 commit 4047f90

File tree

1 file changed

+51
-38
lines changed

1 file changed

+51
-38
lines changed

llmstack/client/src/components/apps/renderer/AppRenderer.jsx

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Liquid } from "liquidjs";
2-
import React, { useCallback, useEffect, useRef, useState } from "react";
2+
import React, {
3+
useCallback,
4+
useEffect,
5+
useMemo,
6+
useRef,
7+
useState,
8+
} from "react";
39
import ReactGA from "react-ga4";
410
import { stitchObjects } from "../../../data/utils";
511
import LayoutRenderer from "./LayoutRenderer";
@@ -14,9 +20,40 @@ import {
1420
import { appRunDataState } from "../../../data/atoms";
1521
import { useSetRecoilState } from "recoil";
1622

23+
const defaultWorkflowLayout = `<pa-layout>
24+
<pa-paper style="padding: 10px;">
25+
<pa-grid container="true" spacing="2" style="width: 100%">
26+
<pa-grid item="true" xs="12">
27+
<pa-input-form />
28+
</pa-grid>
29+
<pa-grid item="true" xs="12">
30+
<br/>
31+
</pa-grid>
32+
<pa-grid item="true" xs="12">
33+
<pa-workflow-output showHeader="true" />
34+
</pa-grid>
35+
</pa-grid>
36+
</pa-paper>
37+
</pa-layout>`;
38+
39+
const defaultChatLayout = `<pa-layout>
40+
<pa-paper style="padding: 10px;">
41+
<pa-grid container="true" spacing="2" style="width: 100%">
42+
<pa-grid item="true" xs="12">
43+
<pa-chat-output sx='{"height": "70vh", "minHeight": "90%"}'/>
44+
</pa-grid>
45+
<pa-grid item="true" xs="12">
46+
<pa-input-form clearonsubmit="true" />
47+
</pa-grid>
48+
</pa-grid>
49+
</pa-paper>
50+
</pa-layout>`;
51+
1752
export function AppRenderer({ app, ws }) {
1853
const [appSessionId, setAppSessionId] = useState(null);
19-
const templateEngine = new Liquid();
54+
const [layout, setLayout] = useState("");
55+
const templateEngine = useMemo(() => new Liquid(), []);
56+
2057
const outputTemplate = templateEngine.parse(
2158
app?.data?.output_template?.markdown || "",
2259
);
@@ -94,6 +131,18 @@ export function AppRenderer({ app, ws }) {
94131
});
95132
};
96133

134+
useEffect(() => {
135+
if (app?.data?.config?.layout) {
136+
setLayout(app?.data?.config?.layout);
137+
} else {
138+
setLayout(
139+
app?.data?.type_slug === "web"
140+
? defaultWorkflowLayout
141+
: defaultChatLayout,
142+
);
143+
}
144+
}, [app?.data?.config?.layout, app?.data?.type_slug]);
145+
97146
useEffect(() => {
98147
setAppRunData((prevState) => ({
99148
...prevState,
@@ -227,41 +276,5 @@ export function AppRenderer({ app, ws }) {
227276
[appSessionId, ws, app, setAppRunData],
228277
);
229278

230-
let layout = app.data?.config?.layout;
231-
232-
if (!layout) {
233-
const typeSlug = app?.data?.type_slug;
234-
if (typeSlug === "text-chat" || typeSlug === "agent") {
235-
layout = `<pa-layout>
236-
<pa-paper style="padding: 10px;">
237-
<pa-grid container="true" spacing="2" style="width: 100%">
238-
<pa-grid item="true" xs="12">
239-
<pa-chat-output sx='{"height": "70vh", "minHeight": "90%"}'/>
240-
</pa-grid>
241-
<pa-grid item="true" xs="12">
242-
<pa-input-form clearonsubmit="true" />
243-
</pa-grid>
244-
</pa-grid>
245-
</pa-paper>
246-
</pa-layout>`;
247-
} else {
248-
layout = `<pa-layout>
249-
<pa-paper style="padding: 10px;">
250-
<pa-grid container="true" spacing="2" style="width: 100%">
251-
<pa-grid item="true" xs="12">
252-
<pa-input-form />
253-
</pa-grid>
254-
<pa-grid item="true" xs="12">
255-
<br/>
256-
</pa-grid>
257-
<pa-grid item="true" xs="12">
258-
<pa-workflow-output showHeader="true" />
259-
</pa-grid>
260-
</pa-grid>
261-
</pa-paper>
262-
</pa-layout>`;
263-
}
264-
}
265-
266279
return <LayoutRenderer runApp={runApp}>{layout}</LayoutRenderer>;
267280
}

0 commit comments

Comments
 (0)