Skip to content

Commit d025af7

Browse files
authored
fix: logviewer and widget (#1051)
1 parent b084dea commit d025af7

File tree

6 files changed

+1076
-15
lines changed

6 files changed

+1076
-15
lines changed

core/src/ten_manager/designer_frontend/bun.lock

Lines changed: 1038 additions & 0 deletions
Large diffs are not rendered by default.
-232 KB
Binary file not shown.

core/src/ten_manager/designer_frontend/src/components/Popup/LogViewer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const LogViewerPopupContent = (props: { widget: ILogViewerWidget }) => {
6464
});
6565
}
6666
// eslint-disable-next-line react-hooks/exhaustive-deps
67-
}, [backstageWidgets, widget.metadata.scriptType, widget.metadata.script]);
67+
}, [widget.metadata.scriptType, widget.metadata.script]);
6868

6969
return (
7070
<LogViewerFrontStageWidget

core/src/ten_manager/designer_frontend/src/components/Widget/LogViewerWidget.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import AutoSizer from "react-virtualized-auto-sizer";
1212
import { Input } from "@/components/ui/Input";
1313
import { Button } from "@/components/ui/Button";
1414
import { cn } from "@/lib/utils";
15-
import { useWidgetStore } from "@/store/widget";
15+
import { useWidgetStore, appendLogsById } from "@/store/widget";
1616
import { ILogViewerWidget, ILogViewerWidgetOptions } from "@/types/widgets";
1717
import { EWSMessageType } from "@/types/apps";
1818

@@ -22,8 +22,6 @@ export function LogViewerBackstageWidget(props: ILogViewerWidget) {
2222
metadata: { wsUrl, scriptType, script, postActions } = {},
2323
} = props;
2424

25-
const { appendLogViewerHistory } = useWidgetStore();
26-
2725
const wsRef = React.useRef<WebSocket | null>(null);
2826

2927
React.useEffect(() => {
@@ -47,32 +45,28 @@ export function LogViewerBackstageWidget(props: ILogViewerWidget) {
4745
msg.type === EWSMessageType.STANDARD_ERROR
4846
) {
4947
const line = msg.data;
50-
appendLogViewerHistory(id, [line]);
48+
appendLogsById(id, [line]);
5149
} else if (msg.type === EWSMessageType.NORMAL_LINE) {
5250
const line = msg.data;
53-
appendLogViewerHistory(id, [line]);
51+
appendLogsById(id, [line]);
5452
} else if (msg.type === EWSMessageType.EXIT) {
5553
const code = msg.code;
5654
const errMsg = msg?.error_message;
57-
appendLogViewerHistory(id, [
55+
appendLogsById(id, [
5856
errMsg,
5957
`Process exited with code ${code}. Closing...`,
6058
]);
6159

6260
wsRef.current?.close();
6361
} else if (msg.status === "fail") {
64-
appendLogViewerHistory(id, [
65-
`Error: ${msg.message || "Unknown error"}\n`,
66-
]);
62+
appendLogsById(id, [`Error: ${msg.message || "Unknown error"}\n`]);
6763
} else {
68-
appendLogViewerHistory(id, [
69-
`Unknown message: ${JSON.stringify(msg)}`,
70-
]);
64+
appendLogsById(id, [`Unknown message: ${JSON.stringify(msg)}`]);
7165
}
7266
// eslint-disable-next-line @typescript-eslint/no-unused-vars
7367
} catch (err) {
7468
// If it's not JSON, output it directly as text.
75-
appendLogViewerHistory(id, [event.data]);
69+
appendLogsById(id, [event.data]);
7670
}
7771
};
7872

core/src/ten_manager/designer_frontend/src/constants/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ export const TEN_FRAMEWORK_GH_OWNER = "Ten-framework";
4141
export const TEN_FRAMEWORK_GH_REPO = "ten-framework";
4242

4343
// --- Doc
44-
export const TEN_DOC_URL = "https://doc.theten.ai/";
44+
export const TEN_DOC_URL = "https://theten.ai/";

core/src/ten_manager/designer_frontend/src/store/widget.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,32 @@ export const useWidgetStore = create<{
239239
}) => set((state) => ({ extFilter: { ...state.extFilter, ...filter } })),
240240
}))
241241
);
242+
243+
const logBuffer: {
244+
[id: string]: {
245+
history: string[];
246+
};
247+
} = {};
248+
let timer: null | NodeJS.Timeout = null;
249+
250+
// debounced function to append logs
251+
// to the logViewerHistory in the store
252+
export const appendLogsById = (id: string, logs: string[]) => {
253+
if (!logBuffer[id]) {
254+
logBuffer[id] = { history: logs };
255+
} else {
256+
logBuffer[id].history.push(...logs);
257+
}
258+
259+
if (!timer) {
260+
timer = setTimeout(() => {
261+
Object.entries(logBuffer).forEach(([id, log]) => {
262+
if (log.history.length > 0) {
263+
useWidgetStore.getState().appendLogViewerHistory(id, log.history);
264+
}
265+
logBuffer[id].history = [];
266+
});
267+
timer = null;
268+
}, 100); // Adjust the time interval as needed
269+
}
270+
};

0 commit comments

Comments
 (0)