diff --git a/apps/tauri/src/App.vue b/apps/tauri/src/App.vue index 37fddc99..b4210a04 100644 --- a/apps/tauri/src/App.vue +++ b/apps/tauri/src/App.vue @@ -25,6 +25,7 @@ import CommandPalette from "./ui/CommandPalette.vue"; import QuickSwitcher from "./ui/QuickSwitcher.vue"; import WelcomeTourDialog from "./ui/WelcomeTourDialog.vue"; import AboutDialog from "./ui/AboutDialog.vue"; +import SduiSampleDialog from "./ui/sdui/SduiSampleDialog.vue"; import NewFolderDialog from "./ui/NewFolderDialog.vue"; import NewConnectionDialog, { type MongoConnectPayload, @@ -47,6 +48,7 @@ const paletteOpen = ref(false); const switcherOpen = ref(false); const tourOpen = ref(false); const aboutOpen = ref(false); +const sduiSampleOpen = ref(false); const newFolderOpen = ref(false); const newConnectionOpen = ref(false); @@ -191,6 +193,10 @@ function onOpenAbout() { aboutOpen.value = true; } +function onOpenSduiSample() { + sduiSampleOpen.value = true; +} + function onCheckUpdates() { status.setQueryMetrics({ message: "Updater stub — check for updates lands with packaging epic", @@ -213,6 +219,7 @@ const commands = computed(() => toggleSidebar: () => shell.toggleSidebar(), openTour: onOpenTour, openAbout: onOpenAbout, + openSduiSample: onOpenSduiSample, openPalette: onOpenPalette, openQuickSwitcher: onOpenQuickSwitcher, launchDemo: onLaunchDemo, @@ -323,6 +330,7 @@ onUnmounted(() => { @open-preferences="onOpenPreferences" /> + { toggleSidebar: noop, openTour: noop, openAbout: noop, + openSduiSample: noop, openPalette: noop, openQuickSwitcher: noop, launchDemo: noop, diff --git a/apps/tauri/src/commands/registry.ts b/apps/tauri/src/commands/registry.ts index adae2ab5..8b110257 100644 --- a/apps/tauri/src/commands/registry.ts +++ b/apps/tauri/src/commands/registry.ts @@ -11,6 +11,7 @@ export type CommandHandlers = { toggleSidebar: () => void; openTour: () => void; openAbout: () => void; + openSduiSample: () => void; openPalette: () => void; openQuickSwitcher: () => void; launchDemo: () => void; @@ -87,6 +88,12 @@ export function buildCoreCommands(h: CommandHandlers): AppCommand[] { keywords: ["version"], run: h.openAbout, }, + { + id: "sdui-sample", + title: "Preview SDUI Sample Panel", + keywords: ["extension", "sdui", "hello", "panel"], + run: h.openSduiSample, + }, { id: "updates", title: "Check for Updates…", diff --git a/apps/tauri/src/sdui/index.ts b/apps/tauri/src/sdui/index.ts new file mode 100644 index 00000000..99f36c35 --- /dev/null +++ b/apps/tauri/src/sdui/index.ts @@ -0,0 +1,14 @@ +export type { + SduiActionEvent, + SduiButtonNode, + SduiButtonVariant, + SduiDividerNode, + SduiNode, + SduiPanelNode, + SduiStackDirection, + SduiStackNode, + SduiTextNode, + SduiTextRole, +} from "./types"; +export { parseSduiNode, parseSduiPanel, SduiParseError } from "./parse"; +export { SAMPLE_HELLO_PANEL_DESCRIPTOR } from "./sampleHelloPanel"; diff --git a/apps/tauri/src/sdui/parse.test.ts b/apps/tauri/src/sdui/parse.test.ts new file mode 100644 index 00000000..d7d8e2b6 --- /dev/null +++ b/apps/tauri/src/sdui/parse.test.ts @@ -0,0 +1,35 @@ +import { describe, expect, it } from "vitest"; +import { parseSduiPanel, SduiParseError } from "./parse"; +import { SAMPLE_HELLO_PANEL_DESCRIPTOR } from "./sampleHelloPanel"; + +describe("parseSduiPanel", () => { + it("accepts the sample hello-panel descriptor", () => { + const panel = parseSduiPanel( + JSON.parse(JSON.stringify(SAMPLE_HELLO_PANEL_DESCRIPTOR)), + ); + expect(panel.type).toBe("panel"); + expect(panel.id).toBe("querya.hello-panel"); + expect(panel.title).toBe("Hello panel"); + expect(panel.children.length).toBeGreaterThanOrEqual(4); + const stack = panel.children.find((n) => n.type === "stack"); + expect(stack?.type).toBe("stack"); + if (stack?.type === "stack") { + expect(stack.children.some((c) => c.type === "button")).toBe(true); + } + }); + + it("rejects non-panel roots", () => { + expect(() => parseSduiPanel({ type: "text", text: "x" })).toThrow( + SduiParseError, + ); + }); + + it("rejects unknown node types", () => { + expect(() => + parseSduiPanel({ + type: "panel", + children: [{ type: "wizard", steps: [] }], + }), + ).toThrow(/unknown/); + }); +}); diff --git a/apps/tauri/src/sdui/parse.ts b/apps/tauri/src/sdui/parse.ts new file mode 100644 index 00000000..1331cb42 --- /dev/null +++ b/apps/tauri/src/sdui/parse.ts @@ -0,0 +1,125 @@ +import type { + SduiButtonVariant, + SduiNode, + SduiPanelNode, + SduiStackDirection, + SduiTextRole, +} from "./types"; + +const BUTTON_VARIANTS = new Set([ + "primary", + "secondary", + "ghost", + "destructive", +]); +const TEXT_ROLES = new Set(["heading", "body", "muted"]); +const STACK_DIRS = new Set(["column", "row"]); +const GAPS = new Set(["sm", "md", "lg"]); + +export class SduiParseError extends Error { + constructor(message: string) { + super(message); + this.name = "SduiParseError"; + } +} + +function asRecord(value: unknown, path: string): Record { + if (value === null || typeof value !== "object" || Array.isArray(value)) { + throw new SduiParseError(`${path}: expected object`); + } + return value as Record; +} + +function parseChildren(raw: unknown, path: string): SduiNode[] { + if (!Array.isArray(raw)) { + throw new SduiParseError(`${path}: expected array`); + } + return raw.map((item, i) => parseSduiNode(item, `${path}[${i}]`)); +} + +/** Parse one SDUI node; throws [SduiParseError] on invalid input. */ +export function parseSduiNode(raw: unknown, path = "$"): SduiNode { + const obj = asRecord(raw, path); + const type = obj.type; + if (typeof type !== "string") { + throw new SduiParseError(`${path}.type: required string`); + } + + switch (type) { + case "panel": { + const title = obj.title; + const id = obj.id; + return { + type: "panel", + id: typeof id === "string" ? id : undefined, + title: typeof title === "string" ? title : undefined, + children: parseChildren(obj.children ?? [], `${path}.children`), + }; + } + case "text": { + if (typeof obj.text !== "string") { + throw new SduiParseError(`${path}.text: required string`); + } + const role = obj.role; + return { + type: "text", + text: obj.text, + role: + typeof role === "string" && TEXT_ROLES.has(role as SduiTextRole) + ? (role as SduiTextRole) + : "body", + }; + } + case "button": { + if (typeof obj.id !== "string" || !obj.id) { + throw new SduiParseError(`${path}.id: required non-empty string`); + } + if (typeof obj.label !== "string") { + throw new SduiParseError(`${path}.label: required string`); + } + const variant = obj.variant; + const action = obj.action; + return { + type: "button", + id: obj.id, + label: obj.label, + variant: + typeof variant === "string" && + BUTTON_VARIANTS.has(variant as SduiButtonVariant) + ? (variant as SduiButtonVariant) + : "secondary", + action: typeof action === "string" ? action : undefined, + }; + } + case "divider": + return { type: "divider" }; + case "stack": { + const direction = obj.direction; + const gap = obj.gap; + return { + type: "stack", + direction: + typeof direction === "string" && + STACK_DIRS.has(direction as SduiStackDirection) + ? (direction as SduiStackDirection) + : "column", + gap: + typeof gap === "string" && GAPS.has(gap) + ? (gap as "sm" | "md" | "lg") + : "md", + children: parseChildren(obj.children ?? [], `${path}.children`), + }; + } + default: + throw new SduiParseError(`${path}.type: unknown "${type}"`); + } +} + +/** Root must be a `panel` node (host mounts one panel surface). */ +export function parseSduiPanel(raw: unknown): SduiPanelNode { + const node = parseSduiNode(raw, "$"); + if (node.type !== "panel") { + throw new SduiParseError(`$: root must be type "panel", got "${node.type}"`); + } + return node; +} diff --git a/apps/tauri/src/sdui/sampleHelloPanel.ts b/apps/tauri/src/sdui/sampleHelloPanel.ts new file mode 100644 index 00000000..ac51f9a2 --- /dev/null +++ b/apps/tauri/src/sdui/sampleHelloPanel.ts @@ -0,0 +1,47 @@ +import type { SduiPanelNode } from "./types"; + +/** Canonical sample descriptor for #1904 / hello-panel (#1905). */ +export const SAMPLE_HELLO_PANEL_DESCRIPTOR: SduiPanelNode = { + type: "panel", + id: "querya.hello-panel", + title: "Hello panel", + children: [ + { + type: "text", + role: "heading", + text: "Hello from SDUI", + }, + { + type: "text", + role: "body", + text: "This panel is rendered by the Querya Vue host from a JSON descriptor.", + }, + { + type: "text", + role: "muted", + text: "Extensions will mount panels like this over NDJSON RPC.", + }, + { type: "divider" }, + { + type: "stack", + direction: "row", + gap: "sm", + children: [ + { + type: "button", + id: "hello.dismiss", + label: "Dismiss", + variant: "primary", + action: "dismiss", + }, + { + type: "button", + id: "hello.ping", + label: "Ping host", + variant: "secondary", + action: "ping", + }, + ], + }, + ], +}; diff --git a/apps/tauri/src/sdui/types.ts b/apps/tauri/src/sdui/types.ts new file mode 100644 index 00000000..44c1fad4 --- /dev/null +++ b/apps/tauri/src/sdui/types.ts @@ -0,0 +1,52 @@ +/** Host-driven SDUI panel descriptors (extension → Querya Vue). */ + +export type SduiButtonVariant = "primary" | "secondary" | "ghost" | "destructive"; + +export type SduiTextRole = "heading" | "body" | "muted"; + +export type SduiStackDirection = "column" | "row"; + +export type SduiTextNode = { + type: "text"; + text: string; + role?: SduiTextRole; +}; + +export type SduiButtonNode = { + type: "button"; + id: string; + label: string; + variant?: SduiButtonVariant; + /** Opaque action id the host/extension understands (e.g. `dismiss`). */ + action?: string; +}; + +export type SduiDividerNode = { + type: "divider"; +}; + +export type SduiStackNode = { + type: "stack"; + direction?: SduiStackDirection; + gap?: "sm" | "md" | "lg"; + children: SduiNode[]; +}; + +export type SduiPanelNode = { + type: "panel"; + id?: string; + title?: string; + children: SduiNode[]; +}; + +export type SduiNode = + | SduiPanelNode + | SduiTextNode + | SduiStackNode + | SduiButtonNode + | SduiDividerNode; + +export type SduiActionEvent = { + nodeId: string; + action: string; +}; diff --git a/apps/tauri/src/ui/sdui/SduiNodeList.vue b/apps/tauri/src/ui/sdui/SduiNodeList.vue new file mode 100644 index 00000000..94da59c0 --- /dev/null +++ b/apps/tauri/src/ui/sdui/SduiNodeList.vue @@ -0,0 +1,130 @@ + + + + + diff --git a/apps/tauri/src/ui/sdui/SduiPanelRenderer.vue b/apps/tauri/src/ui/sdui/SduiPanelRenderer.vue new file mode 100644 index 00000000..8eab74d1 --- /dev/null +++ b/apps/tauri/src/ui/sdui/SduiPanelRenderer.vue @@ -0,0 +1,58 @@ + + + + + diff --git a/apps/tauri/src/ui/sdui/SduiSampleDialog.vue b/apps/tauri/src/ui/sdui/SduiSampleDialog.vue new file mode 100644 index 00000000..b2581f5d --- /dev/null +++ b/apps/tauri/src/ui/sdui/SduiSampleDialog.vue @@ -0,0 +1,96 @@ + + + + +