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
265 changes: 168 additions & 97 deletions src-tauri/Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ rusqlite = { version = "0.32", features = ["bundled"] }
uuid = { version = "1", features = ["v4"] }
async-trait = "0.1"
rand = "0.8"
data-studio-agent = { git = "https://github.com/geek-fun/data-studio-agent", tag = "v0.1.4" }
# data-studio-agent: active development branch. Revert to tag after release.
data-studio-agent = { git = "https://github.com/geek-fun/data-studio-agent.git", branch = "feat/unified-capability-types" }
axum = "0.8"
portpicker = "0.1.1"
pageant = "0.2"
russh = "0.60"

[dev-dependencies]
wiremock = "0.6"
mockall = "0.13"
tauri = { version = "2.10", features = ["test"] }

[features]
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/agent/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ToolExecutor for DocKitToolExecutor {
Some(connection_config.clone())
};

let raw = crate::capabilities::registry::invoke_capability_inner(
let raw = data_studio_agent::capabilities::registry::invoke_capability_inner(
tool_name,
arguments.clone(),
conn_opt,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/agent_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn run_agent_loop(
.unwrap_or(Value::Null);

let is_parallel_ok = |name: &str| -> bool {
crate::capabilities::registry::registry()
data_studio_agent::capabilities::registry::registry()
.get(name)
.map(|c| c.parallel_ok)
.unwrap_or(false)
Expand Down
60 changes: 37 additions & 23 deletions src-tauri/src/capabilities/commands.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use data_studio_agent::capabilities::registry;
use data_studio_agent::capabilities::types::Capability;
use serde_json::{json, Value};
use tauri::AppHandle;

use super::registry;
use crate::common::connection_resolver::ConnectionResolver;
use crate::common::ssh_bridge::resolve_ssh_in_place;

Expand Down Expand Up @@ -62,7 +63,7 @@ pub async fn get_available_tools(source_kinds: Option<Vec<String>>) -> Result<St
serde_json::to_string(&result).map_err(|e| e.to_string())
}

fn to_openai_tool(cap: &super::Capability) -> Value {
fn to_openai_tool(cap: &Capability) -> Value {
json!({
"type": "function",
"function": {
Expand All @@ -73,7 +74,7 @@ fn to_openai_tool(cap: &super::Capability) -> Value {
})
}

fn to_metadata(cap: &super::Capability) -> Value {
fn to_metadata(cap: &Capability) -> Value {
json!({
"riskLevel": cap.risk_level,
"requiredPermission": cap.required_permission
Expand All @@ -82,7 +83,7 @@ fn to_metadata(cap: &super::Capability) -> Value {

#[cfg(test)]
mod tests {
use crate::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use async_trait::async_trait;
use serde_json::{json, Value};
use std::sync::Arc;
Expand All @@ -103,7 +104,7 @@ mod tests {
input_schema: json!({"type": "object", "properties": {}}),
risk_level: risk,
required_permission: perm,
source_kind: SourceKind::DocKit,
source_kind: SourceKind::AppLocal,
tags: &["agent"],
parallel_ok: false,
}
Expand Down Expand Up @@ -153,44 +154,57 @@ mod tests {
}

#[test]
fn test_get_available_tools_without_source_kinds() {
// The global registry needs to be initialized once.
let _ = crate::capabilities::registry::init_registry();

fn test_get_available_tools_variants() {
data_studio_agent::capabilities::registry::init_registry(&[|reg| {
reg.register(Capability {
name: "es__search",
description: "test",
handler: Arc::new(TestHandler),
input_schema: json!({"type": "object", "properties": {}}),
risk_level: RiskLevel::Safe,
required_permission: "read",
source_kind: SourceKind::Database("ELASTICSEARCH"),
tags: &["agent"],
parallel_ok: false,
});
reg.register(Capability {
name: "es__cat_indices",
description: "test",
handler: Arc::new(TestHandler),
input_schema: json!({"type": "object", "properties": {}}),
risk_level: RiskLevel::Safe,
required_permission: "read",
source_kind: SourceKind::Database("ELASTICSEARCH"),
tags: &["agent"],
parallel_ok: false,
});
}]);

// With no source filter: all tools returned
let result =
futures::executor::block_on(super::get_available_tools(None));
assert!(result.is_ok(), "got: {:?}", result.err());
let body = result.unwrap();
assert!(body.contains("tools"), "response should contain tools array");
assert!(body.contains("metadata"), "response should contain metadata");
}

#[test]
fn test_get_available_tools_with_es_source() {
let _ = crate::capabilities::registry::init_registry();

// With ES source: ES tools included
let result = futures::executor::block_on(super::get_available_tools(Some(
vec!["ELASTICSEARCH".to_string()],
)));
assert!(result.is_ok(), "got: {:?}", result.err());
let body = result.unwrap();
// Should include ES tools
assert!(body.contains("es__search"), "should include es__search");
assert!(body.contains("es__cat_indices"), "should include es__cat_indices");
}

#[test]
fn test_get_available_tools_with_empty_source_list() {
let _ = crate::capabilities::registry::init_registry();

// With empty source list: no DB tools
let result = futures::executor::block_on(super::get_available_tools(Some(
vec![],
)));
assert!(result.is_ok(), "got: {:?}", result.err());
let body = result.unwrap();
// Empty list should only return DocKit (env) tools, not DB-specific tools
assert!(!body.contains("es__search"), "should NOT include es__search");
assert!(!body.contains("dynamo__"), "should NOT include dynamo tools");
assert!(!body.contains("es__cat_indices"), "should NOT include ES tools");
}

#[test]
Expand All @@ -202,7 +216,7 @@ mod tests {
input_schema: json!({"type": "object", "properties": {}}),
risk_level: RiskLevel::Safe,
required_permission: "read",
source_kind: SourceKind::DocKit,
source_kind: SourceKind::AppLocal,
tags: &[],
parallel_ok: false,
};
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/capabilities/dockit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::sync::Arc;
use serde_json::Value;
use tauri_plugin_store::StoreExt;

use super::registry::CapabilityRegistry;
use super::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use data_studio_agent::capabilities::registry::CapabilityRegistry;
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};

// ---------------------------------------------------------------------------
// Connection store abstraction (testable via mockall)
Expand Down Expand Up @@ -100,7 +100,7 @@ pub(crate) fn register_all(registry: &mut CapabilityRegistry) {
}),
risk_level: RiskLevel::Safe,
required_permission: "none",
source_kind: SourceKind::DocKit,
source_kind: SourceKind::AppLocal,
tags: &["agent"],
parallel_ok: true,
});
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/capabilities/dynamo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;

use serde_json::Value;

use super::registry::CapabilityRegistry;
use super::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use data_studio_agent::capabilities::registry::CapabilityRegistry;
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};

use crate::dynamo::batch_write_item::{batch_write_item, BatchWriteInput};
use crate::dynamo::cloudwatch_metrics::{get_table_metrics, CloudWatchInput};
Expand Down
6 changes: 3 additions & 3 deletions src-tauri/src/capabilities/es.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::sync::Arc;

use serde_json::Value;

use super::registry::CapabilityRegistry;
use super::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use data_studio_agent::capabilities::registry::CapabilityRegistry;
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};

// ---------------------------------------------------------------------------
// ES capability handlers
Expand Down Expand Up @@ -980,7 +980,7 @@ mod tests {

#[tokio::test]
async fn test_es_register_all_registers_capabilities() {
use crate::capabilities::registry::CapabilityRegistry;
use data_studio_agent::capabilities::registry::CapabilityRegistry;

let mut reg = CapabilityRegistry::new();
super::register_all(&mut reg);
Expand Down
5 changes: 0 additions & 5 deletions src-tauri/src/capabilities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,3 @@ pub mod dockit;
pub mod dynamo;
pub mod es;
pub mod mongo;
pub mod registry;
pub mod types;

pub use registry::registry;
pub use types::Capability;
4 changes: 2 additions & 2 deletions src-tauri/src/capabilities/mongo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use serde_json::Value;

use crate::common::response::ApiResponse;

use super::registry::CapabilityRegistry;
use super::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};
use data_studio_agent::capabilities::registry::CapabilityRegistry;
use data_studio_agent::capabilities::types::{Capability, CapabilityHandler, RiskLevel, SourceKind};

// ---------------------------------------------------------------------------
// Mongo client factory abstraction (testable via mockall)
Expand Down
Loading
Loading