PicoBot/src/tools/traits.rs
xiaoski d957f9c649 feat(send_message): support file sending via Feishu; fix upload endpoint and message format
- OutboundMessenger trait: add media: Vec<MediaItem> param to send_message()
- send_message tool: add optional 'files' param with path-to-MediaItem conversion
- SessionManager::send_message(): forward media to OutboundMessage
- Feishu: fix image upload endpoint (/im/v1/images/upload → /im/v1/images)
- Feishu: fix post image tag (image → img)
- Feishu: fix file upload file_type mapping (use valid Feishu types)
- Feishu: send files as separate messages (file/audio/media msg_type), not embedded in post
- Feishu: add debug logging for upload/send responses
- Skip [message from] prefix for pure file messages to same session
2026-05-13 12:06:55 +08:00

46 lines
1.2 KiB
Rust

use async_trait::async_trait;
use crate::bus::{MediaItem, MessageSource};
#[derive(Debug, Clone)]
pub struct ToolResult {
pub success: bool,
pub output: String,
pub error: Option<String>,
}
#[async_trait]
pub trait Tool: Send + Sync + 'static {
fn name(&self) -> &str;
fn description(&self) -> &str;
fn parameters_schema(&self) -> serde_json::Value;
async fn execute(&self, args: serde_json::Value) -> anyhow::Result<ToolResult>;
/// Whether this tool is side-effect free and safe to parallelize.
fn read_only(&self) -> bool {
false
}
/// Whether this tool can run alongside other concurrency-safe tools.
fn concurrency_safe(&self) -> bool {
self.read_only() && !self.exclusive()
}
/// Whether this tool should run alone even if concurrency is enabled.
fn exclusive(&self) -> bool {
false
}
}
#[async_trait]
pub trait OutboundMessenger: Send + Sync {
async fn send_message(
&self,
channel: &str,
chat_id: &str,
dialog_id: Option<&str>,
content: &str,
source: MessageSource,
media: Vec<MediaItem>,
) -> Result<(), String>;
}