From 6208b5c737f4b3e14534bd90bc1ea2e5ffe9b359 Mon Sep 17 00:00:00 2001 From: ZhuchkaTriplesix Date: Mon, 16 Nov 2026 22:29:51 +0300 Subject: [PATCH] feat(marketplace): sample hello-panel extension over NDJSON SDUI Ship querya-ext-hello-panel with panel.get, a package manifest/README, and a Command Palette path that mounts the live descriptor (#1905). --- apps/tauri/extensions/hello-panel/README.md | 59 ++++++ .../extensions/hello-panel/manifest.json | 26 +++ apps/tauri/src-tauri/Cargo.toml | 4 + .../src/bin/querya_ext_hello_panel.rs | 124 +++++++++++++ apps/tauri/src-tauri/src/commands.rs | 6 + apps/tauri/src-tauri/src/extensions/mod.rs | 2 + apps/tauri/src-tauri/src/extensions/paths.rs | 47 +++++ apps/tauri/src-tauri/src/lib.rs | 2 + .../src-tauri/tests/extension_hello_panel.rs | 42 +++++ apps/tauri/src/App.vue | 8 + apps/tauri/src/api/extensions.ts | 67 +++++++ apps/tauri/src/commands/registry.test.ts | 1 + apps/tauri/src/commands/registry.ts | 7 + apps/tauri/src/ui/sdui/HelloPanelDialog.vue | 172 ++++++++++++++++++ 14 files changed, 567 insertions(+) create mode 100644 apps/tauri/extensions/hello-panel/README.md create mode 100644 apps/tauri/extensions/hello-panel/manifest.json create mode 100644 apps/tauri/src-tauri/src/bin/querya_ext_hello_panel.rs create mode 100644 apps/tauri/src-tauri/src/extensions/paths.rs create mode 100644 apps/tauri/src-tauri/tests/extension_hello_panel.rs create mode 100644 apps/tauri/src/api/extensions.ts create mode 100644 apps/tauri/src/ui/sdui/HelloPanelDialog.vue diff --git a/apps/tauri/extensions/hello-panel/README.md b/apps/tauri/extensions/hello-panel/README.md new file mode 100644 index 00000000..e7280b6d --- /dev/null +++ b/apps/tauri/extensions/hello-panel/README.md @@ -0,0 +1,59 @@ +# Hello Panel sample extension + +Minimal Querya extension that speaks NDJSON JSON-RPC over stdio and returns an +SDUI panel descriptor (`panel.get`) for the Vue host renderer (#1905). + +## Layout + +| Path | Role | +| --- | --- | +| `manifest.json` | Package id `querya.hello-panel`, command `helloPanel.open` | +| `querya-ext-hello-panel` (Cargo bin) | Process entry (`main`) | + +The executable lives in the Tauri crate as `querya-ext-hello-panel` (same package +as the desktop host). This folder is the marketplace-shaped sample package. + +## Build + +From the repo root: + +```bash +cd apps/tauri/src-tauri +cargo build --bin querya-ext-hello-panel +``` + +Binary: `apps/tauri/src-tauri/target/debug/querya-ext-hello-panel` +(or `target/release/…` after `--release`). + +## Run against the host (manual) + +1. Start the Tauri app (`cd apps/tauri && pnpm tauri dev`). +2. Command Palette (`Ctrl/Cmd+P`) → **Open Hello Panel Extension**. +3. Host resolves the binary (see below), runs `system.handshake`, then + `panel.get`, and renders the descriptor with `SduiPanelRenderer`. +4. **Dismiss** stops the session (`system.shutdown`). + +Override the binary path if needed: + +```bash +export QUERYA_HELLO_PANEL_BIN=/absolute/path/to/querya-ext-hello-panel +``` + +Without the env var, the host looks next to the running app / Cargo target +output (`ext_hello_panel_executable`). + +## RPC surface + +| Method | Result | +| --- | --- | +| `system.handshake` | `{ protocolVersion, extensionId }` | +| `system.ping` | `"pong"` | +| `panel.get` | SDUI `panel` descriptor (title, text, actions) | +| `system.shutdown` | `{ ok: true }` then process exit | + +## Automated check + +```bash +cd apps/tauri/src-tauri +cargo test --test extension_hello_panel +``` diff --git a/apps/tauri/extensions/hello-panel/manifest.json b/apps/tauri/extensions/hello-panel/manifest.json new file mode 100644 index 00000000..f35bc04c --- /dev/null +++ b/apps/tauri/extensions/hello-panel/manifest.json @@ -0,0 +1,26 @@ +{ + "manifestVersion": 1, + "id": "querya.hello-panel", + "name": "Hello Panel", + "version": "0.1.0", + "publisher": "QueryaHub", + "type": "script", + "description": "Minimal sample that mounts an SDUI hello panel over NDJSON RPC.", + "main": "querya-ext-hello-panel", + "engines": { + "querya_desktop": ">=0.1.0" + }, + "capabilities": { + "sduiPanels": true + }, + "contributions": { + "commands": [ + { + "id": "helloPanel.open", + "title": "Open Hello Panel", + "category": "Extensions", + "aliases": ["sdui", "hello"] + } + ] + } +} diff --git a/apps/tauri/src-tauri/Cargo.toml b/apps/tauri/src-tauri/Cargo.toml index 27fb6fef..2fccd6ee 100644 --- a/apps/tauri/src-tauri/Cargo.toml +++ b/apps/tauri/src-tauri/Cargo.toml @@ -17,6 +17,10 @@ path = "src/bin/querya_mcp.rs" name = "querya-ext-echo" path = "src/bin/querya_ext_echo.rs" +[[bin]] +name = "querya-ext-hello-panel" +path = "src/bin/querya_ext_hello_panel.rs" + [build-dependencies] tauri-build = { version = "2", features = [] } diff --git a/apps/tauri/src-tauri/src/bin/querya_ext_hello_panel.rs b/apps/tauri/src-tauri/src/bin/querya_ext_hello_panel.rs new file mode 100644 index 00000000..a430f9e4 --- /dev/null +++ b/apps/tauri/src-tauri/src/bin/querya_ext_hello_panel.rs @@ -0,0 +1,124 @@ +//! Sample hello-panel extension: NDJSON JSON-RPC + SDUI `panel.get` (#1905). +//! +//! Methods: `system.handshake`, `system.ping`, `system.shutdown`, `panel.get`. + +use serde_json::{json, Value}; +use std::io::{self, BufRead, Write}; + +fn hello_panel_descriptor() -> Value { + json!({ + "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": "Served live by querya-ext-hello-panel 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" + } + ] + } + ] + }) +} + +fn main() { + let stdin = io::stdin(); + let mut stdout = io::stdout(); + + for line in stdin.lock().lines() { + let Ok(line) = line else { + break; + }; + if line.trim().is_empty() { + continue; + } + let Ok(req) = serde_json::from_str::(&line) else { + continue; + }; + let id = req.get("id").cloned().unwrap_or(Value::Null); + let method = req.get("method").and_then(Value::as_str).unwrap_or(""); + let params = req.get("params").cloned(); + + let response = match method { + "system.handshake" => { + let extension_id = params + .as_ref() + .and_then(|p| p.get("pluginId")) + .and_then(Value::as_str) + .unwrap_or("querya.hello-panel"); + ok( + id, + json!({ + "protocolVersion": 1, + "extensionId": extension_id, + }), + ) + } + "system.ping" => ok(id, json!("pong")), + "panel.get" => ok(id, hello_panel_descriptor()), + "system.shutdown" => { + let line = ok(id, json!({ "ok": true })); + let _ = writeln!(stdout, "{line}"); + let _ = stdout.flush(); + break; + } + other => err(id, -32601, format!("method not found: {other}")), + }; + + if writeln!(stdout, "{response}").is_err() { + break; + } + if stdout.flush().is_err() { + break; + } + } +} + +fn ok(id: Value, result: Value) -> String { + json!({ + "jsonrpc": "2.0", + "id": id, + "result": result, + }) + .to_string() +} + +fn err(id: Value, code: i32, message: String) -> String { + json!({ + "jsonrpc": "2.0", + "id": id, + "error": { "code": code, "message": message }, + }) + .to_string() +} diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index 546d9741..b6a7ff2b 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -1012,3 +1012,9 @@ pub async fn ext_host_list( ) -> Result, String> { Ok(host.list().await) } + +/// Resolve the sample hello-panel extension executable (#1905). +#[tauri::command] +pub fn ext_hello_panel_executable() -> Result { + crate::extensions::hello_panel_executable().map(|p| p.display().to_string()) +} diff --git a/apps/tauri/src-tauri/src/extensions/mod.rs b/apps/tauri/src-tauri/src/extensions/mod.rs index e7456c80..e763346a 100644 --- a/apps/tauri/src-tauri/src/extensions/mod.rs +++ b/apps/tauri/src-tauri/src/extensions/mod.rs @@ -1,6 +1,8 @@ //! Extension host: spawn child processes and speak Flutter-compatible NDJSON JSON-RPC. pub mod host; +pub mod paths; pub mod rpc; pub use host::{ExtensionHost, ExtensionSessionInfo}; +pub use paths::hello_panel_executable; diff --git a/apps/tauri/src-tauri/src/extensions/paths.rs b/apps/tauri/src-tauri/src/extensions/paths.rs new file mode 100644 index 00000000..cfc8a9d6 --- /dev/null +++ b/apps/tauri/src-tauri/src/extensions/paths.rs @@ -0,0 +1,47 @@ +//! Resolve sample / packaged extension executables. + +use std::env; +use std::path::PathBuf; + +const HELLO_ENV: &str = "QUERYA_HELLO_PANEL_BIN"; +const HELLO_NAME: &str = if cfg!(windows) { + "querya-ext-hello-panel.exe" +} else { + "querya-ext-hello-panel" +}; + +/// Absolute path to the hello-panel sample binary. +/// +/// Order: `QUERYA_HELLO_PANEL_BIN` → sibling of current exe → Cargo target dir. +pub fn hello_panel_executable() -> Result { + if let Ok(raw) = env::var(HELLO_ENV) { + let path = PathBuf::from(raw.trim()); + if path.is_file() { + return Ok(path); + } + return Err(format!( + "{HELLO_ENV} is set but not a file: {}", + path.display() + )); + } + + if let Ok(mut exe) = env::current_exe() { + exe.pop(); + let sibling = exe.join(HELLO_NAME); + if sibling.is_file() { + return Ok(sibling); + } + // `target/{debug,release}/deps/` → parent target profile dir + if exe.ends_with("deps") { + exe.pop(); + let candidate = exe.join(HELLO_NAME); + if candidate.is_file() { + return Ok(candidate); + } + } + } + + Err(format!( + "hello-panel binary not found (set {HELLO_ENV} or build --bin querya-ext-hello-panel)" + )) +} diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index e9479d2b..c7d0ef87 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -37,6 +37,7 @@ use commands::{ profiles_list, profiles_upsert, redis_get, redis_key_metas, redis_ping, redis_read_key, redis_scan, redis_set, mcp_start, mcp_status, mcp_stop, ssh_tunnel_close, ssh_tunnel_list, ssh_tunnel_open, ext_host_start, ext_host_call, ext_host_ping, ext_host_stop, ext_host_list, + ext_hello_panel_executable, }; #[tauri::command] @@ -154,6 +155,7 @@ pub fn run() { ext_host_ping, ext_host_stop, ext_host_list, + ext_hello_panel_executable, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/apps/tauri/src-tauri/tests/extension_hello_panel.rs b/apps/tauri/src-tauri/tests/extension_hello_panel.rs new file mode 100644 index 00000000..46b6eec2 --- /dev/null +++ b/apps/tauri/src-tauri/tests/extension_hello_panel.rs @@ -0,0 +1,42 @@ +//! Live hello-panel extension: handshake → panel.get → shutdown (#1905). + +use querya_desktop_tauri_lib::ExtensionHost; +use serde_json::json; +use std::path::PathBuf; + +fn hello_bin() -> PathBuf { + PathBuf::from(env!("CARGO_BIN_EXE_querya-ext-hello-panel")) +} + +#[tokio::test] +async fn hello_panel_get_descriptor_roundtrip() { + let host = ExtensionHost::new(); + let info = host + .start( + "hello-1".into(), + hello_bin(), + vec![], + json!({ + "queryaVersion": "0.1.0", + "pluginId": "querya.hello-panel", + }), + ) + .await + .expect("start"); + + assert_eq!(info.extension_id, "querya.hello-panel"); + + let panel = host + .call("hello-1", "panel.get", None) + .await + .expect("panel.get"); + + assert_eq!(panel["type"], json!("panel")); + assert_eq!(panel["id"], json!("querya.hello-panel")); + assert_eq!(panel["title"], json!("Hello panel")); + let children = panel["children"].as_array().expect("children"); + assert!(children.iter().any(|n| n["type"] == "text")); + assert!(children.iter().any(|n| n["type"] == "stack")); + + host.stop("hello-1").await.expect("stop"); +} diff --git a/apps/tauri/src/App.vue b/apps/tauri/src/App.vue index b4210a04..4dad15a5 100644 --- a/apps/tauri/src/App.vue +++ b/apps/tauri/src/App.vue @@ -26,6 +26,7 @@ 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 HelloPanelDialog from "./ui/sdui/HelloPanelDialog.vue"; import NewFolderDialog from "./ui/NewFolderDialog.vue"; import NewConnectionDialog, { type MongoConnectPayload, @@ -49,6 +50,7 @@ const switcherOpen = ref(false); const tourOpen = ref(false); const aboutOpen = ref(false); const sduiSampleOpen = ref(false); +const helloPanelOpen = ref(false); const newFolderOpen = ref(false); const newConnectionOpen = ref(false); @@ -197,6 +199,10 @@ function onOpenSduiSample() { sduiSampleOpen.value = true; } +function onOpenHelloPanel() { + helloPanelOpen.value = true; +} + function onCheckUpdates() { status.setQueryMetrics({ message: "Updater stub — check for updates lands with packaging epic", @@ -220,6 +226,7 @@ const commands = computed(() => openTour: onOpenTour, openAbout: onOpenAbout, openSduiSample: onOpenSduiSample, + openHelloPanel: onOpenHelloPanel, openPalette: onOpenPalette, openQuickSwitcher: onOpenQuickSwitcher, launchDemo: onLaunchDemo, @@ -331,6 +338,7 @@ onUnmounted(() => { /> + { + return invoke("ext_hello_panel_executable"); +} + +export async function extHostStart(opts: { + sessionId: string; + executable: string; + args?: string[]; + handshakeParams?: Record; +}): Promise { + return invoke("ext_host_start", { + sessionId: opts.sessionId, + executable: opts.executable, + args: opts.args ?? [], + handshakeParams: opts.handshakeParams ?? {}, + }); +} + +export async function extHostCall( + sessionId: string, + method: string, + params?: unknown, +): Promise { + return invoke("ext_host_call", { sessionId, method, params: params ?? null }); +} + +export async function extHostStop(sessionId: string): Promise { + await invoke("ext_host_stop", { sessionId }); +} + +const HELLO_SESSION = "hello-panel"; + +/** Start hello-panel, fetch SDUI descriptor, leave session running for the caller. */ +export async function mountHelloPanel(): Promise<{ + sessionId: string; + descriptor: SduiPanelNode; +}> { + const executable = await resolveHelloPanelExecutable(); + await extHostStop(HELLO_SESSION).catch(() => undefined); + await extHostStart({ + sessionId: HELLO_SESSION, + executable, + handshakeParams: { + queryaVersion: "0.1.0", + pluginId: "querya.hello-panel", + }, + }); + try { + const raw = await extHostCall(HELLO_SESSION, "panel.get"); + const descriptor = parseSduiPanel(raw); + return { sessionId: HELLO_SESSION, descriptor }; + } catch (err) { + await extHostStop(HELLO_SESSION).catch(() => undefined); + throw err; + } +} diff --git a/apps/tauri/src/commands/registry.test.ts b/apps/tauri/src/commands/registry.test.ts index c3bfd576..67c90a74 100644 --- a/apps/tauri/src/commands/registry.test.ts +++ b/apps/tauri/src/commands/registry.test.ts @@ -10,6 +10,7 @@ describe("command registry", () => { openTour: noop, openAbout: noop, openSduiSample: noop, + openHelloPanel: noop, openPalette: noop, openQuickSwitcher: noop, launchDemo: noop, diff --git a/apps/tauri/src/commands/registry.ts b/apps/tauri/src/commands/registry.ts index 8b110257..d91bd776 100644 --- a/apps/tauri/src/commands/registry.ts +++ b/apps/tauri/src/commands/registry.ts @@ -12,6 +12,7 @@ export type CommandHandlers = { openTour: () => void; openAbout: () => void; openSduiSample: () => void; + openHelloPanel: () => void; openPalette: () => void; openQuickSwitcher: () => void; launchDemo: () => void; @@ -94,6 +95,12 @@ export function buildCoreCommands(h: CommandHandlers): AppCommand[] { keywords: ["extension", "sdui", "hello", "panel"], run: h.openSduiSample, }, + { + id: "hello-panel", + title: "Open Hello Panel Extension", + keywords: ["extension", "sdui", "hello", "panel", "rpc"], + run: h.openHelloPanel, + }, { id: "updates", title: "Check for Updates…", diff --git a/apps/tauri/src/ui/sdui/HelloPanelDialog.vue b/apps/tauri/src/ui/sdui/HelloPanelDialog.vue new file mode 100644 index 00000000..77e4b087 --- /dev/null +++ b/apps/tauri/src/ui/sdui/HelloPanelDialog.vue @@ -0,0 +1,172 @@ + + + + +