Same agent Smaller bill. The tools and infrastructure to get more work from your AI. Fewer tokens. Less compute. Lower cost.
TypeScript agent-harnessagent-harness-engineeringai-engineeringai-observabilityamd-gpuclaude-codeclickhousecodexcoding-agentcoding-agentscursorgenaigpu-monitoringllm-observabilityllmopsnvidia-smiobservabilityopen-sourceopenaiopentelemetry
fix(client): guard WidgetTypeIcon against undefined so one bad widget doesn't crash the dashboard (React #130) (#1420)
amoha-enwithai0bfa7c18b40f
diff --git a/src/client/src/__tests__/clickhouse/seed/dashboards.test.ts b/src/client/src/__tests__/clickhouse/seed/dashboards.test.tsnew file mode 100644index 00000000..76abd650--- /dev/null+++ b/src/client/src/__tests__/clickhouse/seed/dashboards.test.ts@@ -0,0 +1,90 @@+jest.mock("@/lib/platform/manage-dashboard/board", () => ({+ boardExistsByTitle: jest.fn(),+ importBoardLayout: jest.fn(),+ isBoardTableEmpty: jest.fn(),+}));+jest.mock("@/lib/platform/manage-dashboard/widget", () => ({+ createWidget: jest.fn(),+ getWidgets: jest.fn(),+ updateWidget: jest.fn(),+}));++import { syncWidgetSqlFromSeed } from "@/clickhouse/seed/dashboards";+import {+ createWidget,+ getWidgets,+ updateWidget,+} from "@/lib/platform/manage-dashboard/widget";++const mockCreateWidget = createWidget as jest.Mock;+const mockGetWidgets = getWidgets as jest.Mock;+const mockUpdateWidget = updateWidget as jest.Mock;++beforeEach(() => {+ jest.clearAllMocks();+});++describe("syncWidgetSqlFromSeed", () => {+ const layout = {+ widgets: {+ "missing-id": {+ id: "missing-id",+ title: "Top models",+ type: "BAR_CHART",+ properties: {},+ config: { query: "SELECT 1" },+ },+ "existing-id": {+ id: "existing-id",+ title: "Total Cost",+ type: "STAT_CARD",+ properties: { color: "#fff" },+ config: { query: "SELECT 2" },+ },+ },+ };++ it("recreates missing seeded widgets and syncs config for existing ones", async () => {+ mockGetWidgets.mockResolvedValue({+ data: [{ id: "existing-id", title: "Total Cost", type: "STAT_CARD" }],+ err: null,+ });+ mockCreateWidget.mockResolvedValue({ data: { id: "missing-id" } });+ mockUpdateWidget.mockResolvedValue({ data: "ok" });++ await syncWidgetSqlFromSeed(layout, "db-1");++ expect(mockGetWidgets).toHaveBeenCalledWith(+ ["missing-id", "existing-id"],+ "db-1"+ );+ expect(mockCreateWidget).toHaveBeenCalledWith(+ expect.objectContaining({+ id: "missing-id",+ title: "Top models",+ type: "BAR_CHART",+ }),+ "db-1"+ );+ expect(mockUpdateWidget).toHaveBeenCalledWith(+ { id: "existing-id", config: { query: "SELECT 2" } },+ "db-1"+ );+ expect(mockUpdateWidget).not.toHaveBeenCalledWith(+ expect.objectContaining({ id: "missing-id" }),+ expect.anything()+ );+ });++ it("throws when recreating a missing widget fails", async () => {+ mockGetWidgets.mockResolvedValue({ data: [], err: null });+ mockCreateWidget+ .mockResolvedValueOnce({ err: "insert failed" })+ .mockResolvedValueOnce({ data: { id: "existing-id" } });++ await expect(syncWidgetSqlFromSeed(layout, "db-1")).rejects.toThrow(+ /Failed to recreate missing seeded widget missing-id/+ );+ expect(mockCreateWidget).toHaveBeenCalledTimes(2);+ });+});diff --git a/src/client/src/__tests__/lib/platform/manage-dashboard/board.test.ts b/src/client/src/__tests__/lib/platform/manage-dashboard/board.test.tsnew file mode 100644index 00000000..ef107907--- /dev/null+++ b/src/client/src/__tests__/lib/platform/manage-dashboard/board.test.ts@@ -0,0 +1,300 @@+jest.mock("@/lib/platform/common", () => ({+ dataCollector: jest.fn(),+}));+jest.mock("@/lib/platform/manage-dashboard/table-details", () => ({+ OPENLIT_BOARD_TABLE_NAME: "openlit_board",+ OPENLIT_BOARD_WIDGET_TABLE_NAME: "openlit_board_widget",+ OPENLIT_WIDGET_TABLE_NAME: "openlit_widget",+}));+jest.mock("@/constants/messages", () => ({+ __esModule: true,+ default: jest.fn(() => ({+ BOARD_CREATE_FAILED: "Board create failed!",+ BOARD_DELETE_FAILED: "Board delete failed!",+ BOARD_DELETED_SUCCESSFULLY: "Board deleted successfully!",+ BOARD_DATA_NOT_FOUND: "Board data not found!",+ BOARD_IMPORT_FAILED: "Board import failed!",+ BOARD_LAYOUT_UPDATED_SUCCESSFULLY: "Board layout updated successfully!",+ BOARD_UPDATE_FAILED: "Board update failed!",+ BOARD_UPDATED_SUCCESSFULLY: "Board updated successfully!",+ MAIN_DASHBOARD_NOT_FOUND: "Main dashboard not found!",+ WIDGET_CREATE_FAILED: "Widget create failed!",+ WIDGET_FETCH_FAILED: "Widget fetch failed!",+ })),+}));+jest.mock("@/utils/sanitizer", () => ({+ __esModule: true,+ default: {+ sanitizeValue: jest.fn((value: string) => value),+ sanitizeObject: jest.fn((value: unknown) => value),+ },+}));+jest.mock("@/helpers/server/widget", () => ({+ normalizeWidgetToClient: jest.fn((widget: any) => widget),+ sanitizeWidget: jest.fn((widget: any) => widget),+ escapeSingleQuotes: jest.fn((value: string) => value),+}));+jest.mock("@/lib/platform/manage-dashboard/widget", () => ({+ createWidget: jest.fn(),+ deleteWidget: jest.fn(),+ getWidgets: jest.fn(),+}));++import { dataCollector } from "@/lib/platform/common";+import {+ getBoardLayout,+ importBoardLayout,+} from "@/lib/platform/manage-dashboard/board";+import {+ createWidget,+ deleteWidget,+ getWidgets,+} from "@/lib/platform/manage-dashboard/widget";++const mockDataCollector = dataCollector as jest.Mock;+const mockCreateWidget = createWidget as jest.Mock;+const mockDeleteWidget = deleteWidget as jest.Mock;+const mockGetWidgets = getWidgets as jest.Mock;++beforeEach(() => {+ jest.clearAllMocks();+ mockDeleteWidget.mockResolvedValue({ data: true, err: null });+});++describe("getBoardLayout", () => {+ it("omits dangling board_widget mappings whose widget row is missing", async () => {+ mockDataCollector+ .mockResolvedValueOnce({+ data: [+ {+ boardId: "board-1",+ boardTitle: "LLM dashboard",+ boardDescription: "",+ isMainDashboard: true,+ isPinned: false,+ boardCreatedAt: "2026-01-01",+ boardUpdatedAt: "2026-01-01",+ tags: "[]",+ },+ ],+ err: null,+ })+ .mockResolvedValueOnce({+ data: [+ {+ boardWidgetId: "bw-ok",+ widgetId: "widget-ok",+ position: JSON.stringify({ x: 0, y: 0, w: 2, h: 2 }),+ boardWidgetCreatedAt: "2026-01-01",+ boardWidgetUpdatedAt: "2026-01-01",+ },+ {+ boardWidgetId: "bw-dangling",+ widgetId: "widget-missing",+ position: JSON.stringify({ x: 2, y: 0, w: 2, h: 2 }),+ boardWidgetCreatedAt: "2026-01-01",+ boardWidgetUpdatedAt: "2026-01-01",+ },+ ],+ err: null,+ });++ mockGetWidgets.mockResolvedValue({+ data: [+ {+ id: "widget-ok",+ title: "Total Requests",+ description: "ok",+ type: "STAT_CARD",+ properties: {},+ config: { query: "SELECT 1" },+ createdAt: "2026-01-01",+ updatedAt: "2026-01-01",+ },+ ],+ err: null,+ });++ const result = await getBoardLayout("board-1", "db-1");++ expect(mockGetWidgets).toHaveBeenCalledWith(+ ["widget-ok", "widget-missing"],+ "db-1"+ );+ expect(result.err).toBeUndefined();+ expect(result.data?.layouts.lg).toEqual([+ { i: "widget-ok", x: 0, y: 0, w: 2, h: 2 },+ ]);+ expect(Object.keys(result.data?.widgets || {})).toEqual(["widget-ok"]);+ expect(result.data?.widgets["widget-ok"].type).toBe("STAT_CARD");+ expect(result.data?.widgets["widget-missing"]).toBeUndefined();+ });++ it("returns an error when widget fetch fails instead of treating every mapping as dangling", async () => {+ mockDataCollector+ .mockResolvedValueOnce({+ data: [+ {+ boardId: "board-1",+ boardTitle: "LLM dashboard",+ boardDescription: "",+ isMainDashboard: true,+ isPinned: false,+ boardCreatedAt: "2026-01-01",+ boardUpdatedAt: "2026-01-01",+ tags: "[]",+ },+ ],+ err: null,+ })+ .mockResolvedValueOnce({+ data: [+ {+ boardWidgetId: "bw-ok",+ widgetId: "widget-ok",+ position: JSON.stringify({ x: 0, y: 0, w: 2, h: 2 }),+ boardWidgetCreatedAt: "2026-01-01",+ boardWidgetUpdatedAt: "2026-01-01",+ },+ ],+ err: null,+ });++ mockGetWidgets.mockResolvedValue({+ data: undefined,+ err: "Widget fetch failed!",+ });++ const result = await getBoardLayout("board-1", "db-1");++ expect(result).toEqual({ err: "Widget fetch failed!" });+ expect(result.data).toBeUndefined();+ });+});++describe("importBoardLayout", () => {+ const importPayload = {+ title: "LLM dashboard",+ description: "desc",+ isPinned: false,+ isMainDashboard: true,+ tags: "[]",+ layouts: {+ lg: [+ { i: "seed-w1", x: 0, y: 0, w: 2, h: 2 },+ { i: "seed-w2", x: 2, y: 0, w: 2, h: 2 },+ ],+ },+ widgets: {+ "seed-w1": {+ id: "seed-w1",+ title: "W1",+ type: "STAT_CARD",+ properties: {},+ config: {},+ },+ "seed-w2": {+ id: "seed-w2",+ title: "W2",+ type: "STAT_CARD",+ properties: {},+ config: {},+ },+ },+ };++ it("does not write board_widget rows when any createWidget fails, and rolls back", async () => {+ mockDataCollector+ // getMainDashboard+ .mockResolvedValueOnce({+ data: [{ id: "main", isMainDashboard: true }],+ err: null,+ })+ // createBoard insert+ .mockResolvedValueOnce({+ data: { query_id: "q1" },+ err: null,+ })+ // deleteBoard: board_widget mappings+ .mockResolvedValueOnce({ data: { query_id: "del-bw" }, err: null })+ // deleteBoard: board row+ .mockResolvedValueOnce({ data: { query_id: "del-b" }, err: null });++ mockCreateWidget+ .mockResolvedValueOnce({ data: { id: "seed-w1" } })+ .mockResolvedValueOnce({ err: "Widget create failed!" });++ const result = await importBoardLayout(importPayload, "db-1", {+ preserveWidgetIds: true,+ });++ expect(result).toEqual({ err: "Widget create failed!" });+ expect(mockCreateWidget).toHaveBeenCalledTimes(2);+ // deleteBoard: board_widget delete + board delete+ expect(mockDataCollector).toHaveBeenCalledWith(+ expect.objectContaining({+ query: expect.stringContaining("DELETE FROM openlit_board_widget"),+ }),+ "exec",+ "db-1"+ );+ expect(mockDataCollector).toHaveBeenCalledWith(+ expect.objectContaining({+ query: expect.stringContaining("DELETE FROM openlit_board"),+ }),+ "exec",+ "db-1"+ );+ expect(mockDeleteWidget).toHaveBeenCalledWith("seed-w1", "db-1");+ // Never reached updateBoardLayout's existing-widgets SELECT+ expect(mockDataCollector).not.toHaveBeenCalledWith(+ expect.objectContaining({+ query: expect.stringContaining("SELECT widget_id, id"),+ }),+ "query",+ "db-1"+ );+ });++ it("attaches layout when every createWidget succeeds", async () => {+ mockDataCollector+ // getMainDashboard+ .mockResolvedValueOnce({+ data: [{ id: "main", isMainDashboard: true }],+ err: null,+ })+ // createBoard insert+ .mockResolvedValueOnce({+ data: { query_id: "q1" },+ err: null,+ })+ // updateBoardLayout: existing mappings+ .mockResolvedValueOnce({+ data: [],+ err: null,+ })+ // updateBoardLayout: insert mapping 1+ .mockResolvedValueOnce({ data: { query_id: "ins1" }, err: null })+ // updateBoardLayout: insert mapping 2+ .mockResolvedValueOnce({ data: { query_id: "ins2" }, err: null });++ mockCreateWidget+ .mockResolvedValueOnce({ data: { id: "seed-w1" } })+ .mockResolvedValueOnce({ data: { id: "seed-w2" } });++ const result = await importBoardLayout(importPayload, "db-1", {+ preserveWidgetIds: true,+ });++ expect(result.err).toBeUndefined();+ expect(result.data?.title).toBe("LLM dashboard");+ expect(mockDeleteWidget).not.toHaveBeenCalled();+ expect(mockDataCollector).toHaveBeenCalledWith(+ expect.objectContaining({+ table: "openlit_board_widget",+ }),+ "insert",+ "db-1"+ );+ });+});diff --git a/src/client/src/clickhouse/seed/dashboards.ts b/src/client/src/clickhouse/seed/dashboards.tsindex 1d4cb4d4..2a570c28 100644--- a/src/client/src/clickhouse/seed/dashboards.ts+++ b/src/client/src/clickhouse/seed/dashboards.ts@@ -3,7 +3,11 @@ import {importBoardLayout,isBoardTableEmpty,} from "@/lib/platform/manage-dashboard/board";-import { updateWidget } from "@/lib/platform/manage-dashboard/widget";+import {+ createWidget,+ getWidgets,+ updateWidget,+} from "@/lib/platform/manage-dashboard/widget";import llmDashboard from "../seed-data/openlit-dashboard-LLM-dashboard-layout.json";import vectorDbDashboard from "../seed-data/openlit-dashboard-Vector-DB-layout.json";import gpuDashboard from "../seed-data/openlit-dashboard-GPU-dashboard-layout.json";@@ -70,17 +74,13 @@ export default async function CreateCustomDashboardsSeed(if (exists) {skippedCount++;- // Existing seeds get a per-widget SQL sync. We update only- // the `config` field (which holds the SQL `query` for each- // widget) so layout / title / properties the user might- // have nudged stay intact. Widget IDs are stable in the- // seed JSON which makes this a safe by-id upsert. Without- // this step, fixes to the seed SQL (e.g. the canonical- // per-session cost formula in the Total Cost widget) would- // only land for brand-new installs, never for stacks that- // already had the board.+ // Existing seeds get a heal + SQL sync:+ // 1. Recreate any seed widgets missing from openlit_widget+ // (heals dangling openlit_board_widget refs from older+ // partial imports).+ // 2. Refresh `config` (SQL) for widgets that already exist.try {- await syncWidgetSqlFromSeed(entry.layout);+ await syncWidgetSqlFromSeed(entry.layout, databaseConfigId);} catch (e: any) {failures.push(`${entry.seedTitle} sync: thrown ${e?.message || String(e)}`@@ -134,30 +134,68 @@ export default async function CreateCustomDashboardsSeed(}/**- * Rewrite widget SQL from the seed JSON onto already-seeded widgets,- * matched by widget id. Only the `config` field is touched, which- * holds the SQL `query` (and any rendering knobs the widget needs to- * execute its query). User-editable surfaces — title, description,- * properties (color / value paths) — are left alone so a workspace- * that re-themed a widget doesn't get reset on the next boot.+ * Heal + refresh seeded widgets by stable id.*- * Why we do this without a version bump: shipping a fix to the- * canonical cost formula needs to take effect everywhere the- * dashboard widgets read it (Total Cost stat card today; any future- * per-vendor / per-user widgets the same way). The widget IDs in- * the seed JSON are stable UUIDs, so by-id targeting is safe — and- * gives us a one-line escape hatch for any "the seed got wrong"- * fixes. The cost is a few extra UPDATEs on each boot, which is- * cheap (4 widgets × 1 UPDATE each).+ * - Missing widgets (dangling board_widget refs) are recreated from the+ * seed JSON so already-deployed stacks recover on next boot.+ * - Existing widgets only get their `config` field updated (SQL /+ * rendering knobs). User-editable surfaces — title, description,+ * properties — are left alone.*/-async function syncWidgetSqlFromSeed(layout: any): Promise<void> {+export async function syncWidgetSqlFromSeed(+ layout: any,+ databaseConfigId?: string+): Promise<void> {const widgets = (layout?.widgets || {}) as Record<string, any>;- for (const id of Object.keys(widgets)) {+ const ids = Object.keys(widgets);+ if (ids.length === 0) return;++ const { data: existingWidgets, err } = await getWidgets(+ ids,+ databaseConfigId+ );+ if (err) {+ throw new Error(String(err));+ }++ const existingIds = new Set(+ (existingWidgets ?? []).map((widget) => widget.id)+ );++ const healErrors: string[] = [];+ for (const id of ids) {const seed = widgets[id];- if (!seed?.config) continue;- await updateWidget({- id,- config: seed.config,- } as any);+ if (!seed) continue;++ if (!existingIds.has(id)) {+ const { err: createErr } = await createWidget(+ { ...seed, id },+ databaseConfigId+ );+ if (createErr) {+ healErrors.push(+ `Failed to recreate missing seeded widget ${id}: ${String(createErr)}`+ );+ }+ continue;+ }++ if (!seed.config) continue;+ const { err: updateErr } = await updateWidget(+ {+ id,+ config: seed.config,+ } as any,+ databaseConfigId+ );+ if (updateErr) {+ healErrors.push(+ `Failed to sync seeded widget ${id}: ${String(updateErr)}`+ );+ }+ }++ if (healErrors.length > 0) {+ throw new Error(healErrors.join("; "));}}diff --git a/src/client/src/components/(playground)/manage-dashboard/board-creator/widgets/widget-renderer.tsx b/src/client/src/components/(playground)/manage-dashboard/board-creator/widgets/widget-renderer.tsxindex a7c67f72..f795e46f 100644--- a/src/client/src/components/(playground)/manage-dashboard/board-creator/widgets/widget-renderer.tsx+++ b/src/client/src/components/(playground)/manage-dashboard/board-creator/widgets/widget-renderer.tsx@@ -33,10 +33,14 @@ const WidgetRenderer: React.FC<WidgetRendererProps> = ({}}, [runFilters]);- // Get widget type icon+ // Get widget type icon. Guard against a missing icon component —+ // runtime `widget.type` can be empty/unknown (e.g. legacy dangling+ // board_widget rows). Rendering <undefined /> crashes the whole+ // board with React error #130.const WidgetTypeIcon = () => {const IconComponent =SUPPORTED_WIDGETS[widget.type as keyof typeof SUPPORTED_WIDGETS]?.icon;+ if (!IconComponent) return null;return <IconComponent className="h-4 w-4" />;};diff --git a/src/client/src/lib/platform/manage-dashboard/board.ts b/src/client/src/lib/platform/manage-dashboard/board.tsindex 35c2d146..8ffd8633 100644--- a/src/client/src/lib/platform/manage-dashboard/board.ts+++ b/src/client/src/lib/platform/manage-dashboard/board.ts@@ -6,7 +6,7 @@ import {} from "./table-details";import getMessage from "@/constants/messages";import Sanitizer from "@/utils/sanitizer";-import { createWidget, getWidgets } from "./widget";+import { createWidget, deleteWidget, getWidgets } from "./widget";import { pluck } from "lodash/fp";import { jsonStringify } from "@/utils/json";import { normalizeImportedDashboard } from "./board-format";@@ -160,7 +160,7 @@ export async function updateBoard(board: Board & { updateParent?: boolean }) {return { data: boardData };}-export async function deleteBoard(id: string) {+export async function deleteBoard(id: string, databaseConfigId?: string) {const query_board_widgets = `DELETE FROM ${OPENLIT_BOARD_WIDGET_TABLE_NAME}WHERE board_id = '${Sanitizer.sanitizeValue(id)}'@@ -173,12 +173,17 @@ export async function deleteBoard(id: string) {const { err: err_board_widgets } = await dataCollector({ query: query_board_widgets },- "exec"+ "exec",+ databaseConfigId);if (err_board_widgets) return { err: getMessage().BOARD_DELETE_FAILED };- const { err: err_board } = await dataCollector({ query }, "exec");+ const { err: err_board } = await dataCollector(+ { query },+ "exec",+ databaseConfigId+ );if (err_board) return { err: getMessage().BOARD_DELETE_FAILED };@@ -247,8 +252,14 @@ export async function getBoardLayout(id: string, databaseConfigId?: string) {let widgetsResult: Array<Widget> = [];- if (widgetIds) {- const { data: widgetsData } = await getWidgets(widgetIds);+ if (widgetIds?.length) {+ const { data: widgetsData, err: widgetsErr } = await getWidgets(+ widgetIds,+ databaseConfigId+ );+ if (widgetsErr) {+ return { err: widgetsErr };+ }widgetsResult = (widgetsData || []) as typeof widgetsResult;}@@ -292,12 +303,18 @@ export async function getBoardLayout(id: string, databaseConfigId?: string) {widgets: {},};- // Map widgets and create layout config- board.widgets = mappingsResult.map((mapping) => {+ // Map widgets and create layout config. Skip dangling+ // openlit_board_widget rows whose widget record is missing — those+ // used to be synthesized as empty-type placeholders and crashed the+ // dashboard renderer (React #130).+ board.widgets = mappingsResult.flatMap((mapping) => {const widgetDetails = widgetDetailsMap.get(mapping.widgetId);+ if (!widgetDetails) {+ return [];+ }+const position = JSON.parse(mapping.position || "{}");- // Add to layoutslayoutConfig.layouts.lg.push({i: mapping.widgetId,x: position.x,@@ -306,30 +323,30 @@ export async function getBoardLayout(id: string, databaseConfigId?: string) {h: position.h,});- // Add to widgets mapconst widgetData = {id: mapping.widgetId,- title: widgetDetails?.title || "",- description: widgetDetails?.description || "",- type: widgetDetails?.type || "",- properties: widgetDetails?.properties || {},- config: widgetDetails?.config || {},- createdAt: widgetDetails?.createdAt || "",- updatedAt: widgetDetails?.updatedAt || "",+ title: widgetDetails.title || "",+ description: widgetDetails.description || "",+ type: widgetDetails.type,+ properties: widgetDetails.properties || {},+ config: widgetDetails.config || {},+ createdAt: widgetDetails.createdAt || "",+ updatedAt: widgetDetails.updatedAt || "",} as const;layoutConfig.widgets[mapping.widgetId] = widgetData;- // Return the board widget mapping- return {- id: mapping.boardWidgetId,- boardId: board.id,- widgetId: mapping.widgetId,- position: position || {},- createdAt: mapping.boardWidgetCreatedAt,- updatedAt: mapping.boardWidgetUpdatedAt,- widget: widgetData,- };+ return [+ {+ id: mapping.boardWidgetId,+ boardId: board.id,+ widgetId: mapping.widgetId,+ position: position || {},+ createdAt: mapping.boardWidgetCreatedAt,+ updatedAt: mapping.boardWidgetUpdatedAt,+ widget: widgetData,+ },+ ];});return {@@ -544,11 +561,33 @@ export async function importBoardLayout(}).filter((layout): layout is NonNullable<typeof layout> => !!layout);- await Promise.all(- updatedWidgets.map(async (widget) => {- return await createWidget(widget, databaseConfigId);- })- );+ const rollbackImport = async (widgetIds: string[]) => {+ await deleteBoard(newBoardId, databaseConfigId);+ await Promise.all(+ widgetIds.map((widgetId) => deleteWidget(widgetId, databaseConfigId))+ );+ };++ // createWidget returns `{ err }` instead of throwing, so a bare+ // Promise.all cannot detect partial insert failures. Writing+ // board_widget rows for widgets that never landed creates dangling+ // refs that crash /home (React #130).+ //+ // Creates run sequentially: each createWidget is insert + readback,+ // and the ClickHouse pool is max 20 / maxWaitingClients 5. Coding+ // Agents seeds 21 widgets; parallel creates are a plausible cause+ // of the original partial seed.+ const createdWidgetIds: string[] = [];+ for (const widget of updatedWidgets) {+ const result = await createWidget(widget, databaseConfigId);+ if (result.err) {+ await rollbackImport(createdWidgetIds);+ return {+ err: result.err || getMessage().BOARD_IMPORT_FAILED,+ };+ }+ createdWidgetIds.push(widget.id);+ }const layoutConfigData = {layouts: {@@ -573,6 +612,7 @@ export async function importBoardLayout(return { data: boardResult.data };}+ await rollbackImport(createdWidgetIds);return { err: layoutErr || getMessage().BOARD_IMPORT_FAILED };}diff --git a/src/client/src/lib/platform/manage-dashboard/widget.ts b/src/client/src/lib/platform/manage-dashboard/widget.tsindex 126c1c99..f0eb4edc 100644--- a/src/client/src/lib/platform/manage-dashboard/widget.ts+++ b/src/client/src/lib/platform/manage-dashboard/widget.ts@@ -173,7 +173,10 @@ export async function getWidgetById(id: string) {return { data: normalizeWidgetToClient((data as DatabaseWidget[])[0]) };}-export async function getWidgets(widgetIds?: string[]) {+export async function getWidgets(+ widgetIds?: string[],+ databaseConfigId?: string+) {let query = "";if (!widgetIds || widgetIds.length === 0) {query = `@@ -198,13 +201,24 @@ export async function getWidgets(widgetIds?: string[]) {`;}- const { data, err } = await dataCollector({ query });+ const { data, err } = await dataCollector(+ { query },+ "query",+ databaseConfigId+ );if (err) {return { err: err.toString() || getMessage().WIDGET_FETCH_FAILED };}- return { data: (data as Array<DatabaseWidget>).map(normalizeWidgetToClient) };+ // normalizeWidgetToClient is typed from the narrow DatabaseWidget+ // shape (properties/config strings). The SELECT always returns full+ // widget rows, so widen back to Widget for callers.+ return {+ data: (data as Array<DatabaseWidget>).map(+ normalizeWidgetToClient+ ) as unknown as Widget[],+ };}export async function createWidget(widget: Widget, databaseConfigId?: string) {@@ -279,7 +293,10 @@ export async function createWidget(widget: Widget, databaseConfigId?: string) {};}-export async function updateWidget(widget: Widget) {+export async function updateWidget(+ widget: Widget,+ databaseConfigId?: string+) {const sanitizedWidget = sanitizeWidget(widget);const updateValues = [@@ -301,7 +318,11 @@ export async function updateWidget(widget: Widget) {WHERE id = '${sanitizedWidget.id}'`;- const { err, data } = await dataCollector({ query }, "exec");+ const { err, data } = await dataCollector(+ { query },+ "exec",+ databaseConfigId+ );if (err || !(data as { query_id: string }).query_id) {return { err: err || getMessage().WIDGET_UPDATE_FAILED };@@ -310,13 +331,13 @@ export async function updateWidget(widget: Widget) {return { data: getMessage().WIDGET_UPDATED_SUCCESSFULLY };}-export function deleteWidget(id: string) {+export function deleteWidget(id: string, databaseConfigId?: string) {const query = `DELETE FROM ${OPENLIT_WIDGET_TABLE_NAME}WHERE id = '${Sanitizer.sanitizeValue(id)}'`;- return dataCollector({ query }, "exec");+ return dataCollector({ query }, "exec", databaseConfigId);}function validateQuery(query: string): { valid: boolean; error?: string } {