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
59 changes: 59 additions & 0 deletions apps/tauri/extensions/hello-panel/README.md
Original file line number Diff line number Diff line change
@@ -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
```
26 changes: 26 additions & 0 deletions apps/tauri/extensions/hello-panel/manifest.json
Original file line number Diff line number Diff line change
@@ -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"]
}
]
}
}
4 changes: 4 additions & 0 deletions apps/tauri/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [] }

Expand Down
124 changes: 124 additions & 0 deletions apps/tauri/src-tauri/src/bin/querya_ext_hello_panel.rs
Original file line number Diff line number Diff line change
@@ -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::<Value>(&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()
}
6 changes: 6 additions & 0 deletions apps/tauri/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,3 +1012,9 @@ pub async fn ext_host_list(
) -> Result<Vec<crate::extensions::ExtensionSessionInfo>, String> {
Ok(host.list().await)
}

/// Resolve the sample hello-panel extension executable (#1905).
#[tauri::command]
pub fn ext_hello_panel_executable() -> Result<String, String> {
crate::extensions::hello_panel_executable().map(|p| p.display().to_string())
}
2 changes: 2 additions & 0 deletions apps/tauri/src-tauri/src/extensions/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions apps/tauri/src-tauri/src/extensions/paths.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf, String> {
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/<test>` → 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)"
))
}
2 changes: 2 additions & 0 deletions apps/tauri/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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");
Expand Down
42 changes: 42 additions & 0 deletions apps/tauri/src-tauri/tests/extension_hello_panel.rs
Original file line number Diff line number Diff line change
@@ -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");
}
8 changes: 8 additions & 0 deletions apps/tauri/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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",
Expand All @@ -220,6 +226,7 @@ const commands = computed<AppCommand[]>(() =>
openTour: onOpenTour,
openAbout: onOpenAbout,
openSduiSample: onOpenSduiSample,
openHelloPanel: onOpenHelloPanel,
openPalette: onOpenPalette,
openQuickSwitcher: onOpenQuickSwitcher,
launchDemo: onLaunchDemo,
Expand Down Expand Up @@ -331,6 +338,7 @@ onUnmounted(() => {
/>
<AboutDialog :open="aboutOpen" @close="aboutOpen = false" />
<SduiSampleDialog :open="sduiSampleOpen" @close="sduiSampleOpen = false" />
<HelloPanelDialog :open="helloPanelOpen" @close="helloPanelOpen = false" />
<NewFolderDialog
:open="newFolderOpen"
@close="newFolderOpen = false"
Expand Down
Loading
Loading