Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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",
Expand All @@ -213,6 +219,7 @@ const commands = computed<AppCommand[]>(() =>
toggleSidebar: () => shell.toggleSidebar(),
openTour: onOpenTour,
openAbout: onOpenAbout,
openSduiSample: onOpenSduiSample,
openPalette: onOpenPalette,
openQuickSwitcher: onOpenQuickSwitcher,
launchDemo: onLaunchDemo,
Expand Down Expand Up @@ -323,6 +330,7 @@ onUnmounted(() => {
@open-preferences="onOpenPreferences"
/>
<AboutDialog :open="aboutOpen" @close="aboutOpen = false" />
<SduiSampleDialog :open="sduiSampleOpen" @close="sduiSampleOpen = false" />
<NewFolderDialog
:open="newFolderOpen"
@close="newFolderOpen = false"
Expand Down
1 change: 1 addition & 0 deletions apps/tauri/src/commands/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("command registry", () => {
toggleSidebar: noop,
openTour: noop,
openAbout: noop,
openSduiSample: noop,
openPalette: noop,
openQuickSwitcher: noop,
launchDemo: noop,
Expand Down
7 changes: 7 additions & 0 deletions apps/tauri/src/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type CommandHandlers = {
toggleSidebar: () => void;
openTour: () => void;
openAbout: () => void;
openSduiSample: () => void;
openPalette: () => void;
openQuickSwitcher: () => void;
launchDemo: () => void;
Expand Down Expand Up @@ -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…",
Expand Down
14 changes: 14 additions & 0 deletions apps/tauri/src/sdui/index.ts
Original file line number Diff line number Diff line change
@@ -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";
35 changes: 35 additions & 0 deletions apps/tauri/src/sdui/parse.test.ts
Original file line number Diff line number Diff line change
@@ -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/);
});
});
125 changes: 125 additions & 0 deletions apps/tauri/src/sdui/parse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import type {
SduiButtonVariant,
SduiNode,
SduiPanelNode,
SduiStackDirection,
SduiTextRole,
} from "./types";

const BUTTON_VARIANTS = new Set<SduiButtonVariant>([
"primary",
"secondary",
"ghost",
"destructive",
]);
const TEXT_ROLES = new Set<SduiTextRole>(["heading", "body", "muted"]);
const STACK_DIRS = new Set<SduiStackDirection>(["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<string, unknown> {
if (value === null || typeof value !== "object" || Array.isArray(value)) {
throw new SduiParseError(`${path}: expected object`);
}
return value as Record<string, unknown>;
}

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;
}
47 changes: 47 additions & 0 deletions apps/tauri/src/sdui/sampleHelloPanel.ts
Original file line number Diff line number Diff line change
@@ -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",
},
],
},
],
};
52 changes: 52 additions & 0 deletions apps/tauri/src/sdui/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Loading
Loading