25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(dbx-cli): 补齐最小 runtime client 模块以恢复编译
Illuminated202001110945a1cb
diff --git a/Cargo.lock b/Cargo.lockindex c8f06c8e77..27dfd5fef9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1673,6 +1673,19 @@ dependencies = ["zip 4.6.1",]+[[package]]+name = "dbx-cli"+version = "0.5.2"+dependencies = [+ "chrono",+ "dbx-core",+ "reqwest 0.12.28",+ "serde",+ "serde_json",+ "tokio",+ "uuid",+]+[[package]]name = "dbx-core"version = "0.1.0"diff --git a/crates/dbx-cli/src/commands.rs b/crates/dbx-cli/src/commands.rsnew file mode 100644index 0000000000..60d828322f--- /dev/null+++ b/crates/dbx-cli/src/commands.rs@@ -0,0 +1,61 @@+use serde::Serialize;++#[derive(Debug, Serialize)]+#[serde(rename_all = "SCREAMING_SNAKE_CASE")]+pub(crate) enum CliErrorCode {+ GuiRuntimeRequired,+}++#[derive(Debug, Serialize)]+#[serde(rename_all = "kebab-case")]+pub(crate) enum CliSource {+ GuiRuntime,+ Headless,+}++#[derive(Debug, Serialize)]+pub(crate) struct CliError {+ code: CliErrorCode,+ message: String,+ recoverable: bool,+}++#[derive(Debug, Serialize)]+#[serde(untagged)]+pub(crate) enum CliEnvelope<T> {+ Success { ok: bool, source: CliSource, data: T },+ Failure { ok: bool, source: CliSource, error: CliError },+}++pub(crate) async fn run(args: Vec<String>) -> Result<(), CliEnvelope<()>> {+ let output = match args.as_slice() {+ [cmd, ..] if cmd == "context" => context().await,+ [cmd, ..] if cmd == "selection" => runtime_required("dbx selection requires DBX GUI runtime."),+ [cmd, sub, ..] if cmd == "result" && sub == "current" => {+ runtime_required("dbx result current requires DBX GUI runtime.")+ }+ _ => ok(CliSource::Headless, serde_json::json!({ "runtime": "headless" })),+ };++ println!("{}", serde_json::to_string_pretty(&output).unwrap());+ Ok(())+}++async fn context() -> CliEnvelope<serde_json::Value> {+ match crate::runtime_client::get_json("/context").await {+ Ok(data) => ok(CliSource::GuiRuntime, data),+ Err(_) => ok(CliSource::Headless, serde_json::json!({ "runtime": "headless" })),+ }+}++fn ok<T>(source: CliSource, data: T) -> CliEnvelope<T> {+ CliEnvelope::Success { ok: true, source, data }+}++fn runtime_required(message: &str) -> CliEnvelope<serde_json::Value> {+ CliEnvelope::Failure {+ ok: false,+ source: CliSource::Headless,+ error: CliError { code: CliErrorCode::GuiRuntimeRequired, message: message.to_string(), recoverable: true },+ }+}diff --git a/crates/dbx-cli/src/runtime_client.rs b/crates/dbx-cli/src/runtime_client.rsnew file mode 100644index 0000000000..a3db998113--- /dev/null+++ b/crates/dbx-cli/src/runtime_client.rs@@ -0,0 +1,42 @@+use serde::{Deserialize, Serialize};+use std::path::PathBuf;++#[derive(Debug, Clone, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct RuntimeDiscovery {+ pub port: u16,+ pub token: String,+}++pub fn app_data_dir() -> PathBuf {+ let home = std::env::var(if cfg!(windows) { "APPDATA" } else { "HOME" }).unwrap_or_else(|_| ".".to_string());++ if cfg!(target_os = "macos") {+ PathBuf::from(home).join("Library/Application Support/com.dbx.app")+ } else if cfg!(windows) {+ PathBuf::from(home).join("com.dbx.app")+ } else {+ PathBuf::from(home).join(".config/com.dbx.app")+ }+}++pub fn load_runtime() -> Option<RuntimeDiscovery> {+ let path = app_data_dir().join("agent-runtime.json");+ let json = std::fs::read_to_string(path).ok()?;+ serde_json::from_str(&json).ok()+}++pub async fn get_json(path: &str) -> Result<serde_json::Value, String> {+ let runtime = load_runtime().ok_or_else(|| "runtime unavailable".to_string())?;+ let url = format!("http://127.0.0.1:{}{}", runtime.port, path);++ reqwest::Client::new()+ .get(url)+ .bearer_auth(runtime.token)+ .send()+ .await+ .map_err(|err| err.to_string())?+ .json()+ .await+ .map_err(|err| err.to_string())+}