feat(plugins): add AI tools and consent-gated data access
This commit is contained in:
71 files changed
+4613
-129
No files matched your search
@@ -1,3 +1,5 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Events emitted by the agent loop, streamed to the frontend via SSE.
|
||||
@@ -18,6 +20,25 @@ pub enum AgentEvent {
|
||||
ReasoningDelta { delta: String },
|
||||
/// The LLM wants to call a tool.
|
||||
ToolCallStart { tool_call_id: String, tool_name: String, args: serde_json::Value },
|
||||
/// A plugin tool call that may change state waits for the user's explicit
|
||||
/// approval. The run stays paused until the client answers through the
|
||||
/// approval command, the approval times out, or the run is cancelled.
|
||||
ToolApprovalRequired {
|
||||
approval_id: String,
|
||||
tool_call_id: String,
|
||||
tool_name: String,
|
||||
plugin_id: String,
|
||||
plugin_name: String,
|
||||
/// The tool name as the plugin declared it (without the DBX prefix).
|
||||
plugin_tool: String,
|
||||
connection_id: String,
|
||||
connection_name: String,
|
||||
/// Exactly the arguments DBX will forward if the user approves.
|
||||
args: serde_json::Value,
|
||||
timeout_secs: u64,
|
||||
},
|
||||
/// The approval requested by `ToolApprovalRequired` has been settled.
|
||||
ToolApprovalResolved { approval_id: String, tool_call_id: String, outcome: ToolApprovalOutcome },
|
||||
/// A tool execution has completed.
|
||||
ToolCallEnd { tool_call_id: String, tool_name: String, result: serde_json::Value, is_error: bool },
|
||||
/// A turn in the agent loop has ended.
|
||||
@@ -41,6 +62,18 @@ pub enum AgentEvent {
|
||||
Error { message: String },
|
||||
}
|
||||
|
||||
/// How a tool approval request ended.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ToolApprovalOutcome {
|
||||
Approved,
|
||||
Denied,
|
||||
/// Nobody answered before the approval deadline.
|
||||
TimedOut,
|
||||
/// The run was cancelled while the approval was pending.
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
/// A unified tool call extracted from any provider's response.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ToolCall {
|
||||
@@ -67,10 +100,13 @@ pub struct ToolResult {
|
||||
}
|
||||
|
||||
/// Definition of a tool available to the agent.
|
||||
///
|
||||
/// Built-in tools use static names and descriptions; tools contributed by
|
||||
/// plugins are discovered at run time, so both fields accept owned text too.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ToolDefinition {
|
||||
pub name: &'static str,
|
||||
pub description: &'static str,
|
||||
pub name: Cow<'static, str>,
|
||||
pub description: Cow<'static, str>,
|
||||
pub parameters: serde_json::Value,
|
||||
pub read_only: bool,
|
||||
/// Whether this tool can be executed in parallel with other tools.
|
||||
|
||||
@@ -5698,8 +5698,8 @@ mod tests {
|
||||
let (endpoint, server) = spawn_json_capture_server("text/event-stream", response).await;
|
||||
let request = anthropic_compatible_test_request(endpoint);
|
||||
let tools = [crate::agent_events::ToolDefinition {
|
||||
name: "get_tables",
|
||||
description: "List tables",
|
||||
name: "get_tables".into(),
|
||||
description: "List tables".into(),
|
||||
parameters: serde_json::json!({
|
||||
"type": "object",
|
||||
"properties": { "schema": { "type": "string" } }
|
||||
@@ -5754,8 +5754,8 @@ mod tests {
|
||||
let request = claude_http_test_request(endpoint);
|
||||
let client = build_ai_http_client(&request.config, 10).unwrap();
|
||||
let tools = [crate::agent_events::ToolDefinition {
|
||||
name: "get_tables",
|
||||
description: "List tables",
|
||||
name: "get_tables".into(),
|
||||
description: "List tables".into(),
|
||||
parameters: serde_json::json!({ "type": "object", "properties": {} }),
|
||||
read_only: true,
|
||||
parallel_ok: true,
|
||||
@@ -7330,8 +7330,8 @@ mod tests {
|
||||
assert_eq!(input[3]["call_id"], "call_1");
|
||||
|
||||
let tool = crate::agent_events::ToolDefinition {
|
||||
name: "list_tables",
|
||||
description: "List tables",
|
||||
name: "list_tables".into(),
|
||||
description: "List tables".into(),
|
||||
parameters: serde_json::json!({"type": "object"}),
|
||||
read_only: true,
|
||||
parallel_ok: true,
|
||||
|
||||
Reference in new issue
Block a user