mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-27 08:00:17 +00:00
* feat: add inbound attachment support to WASM channel system Add attachment record to WIT interface and implement inbound media parsing across all four channel implementations (Telegram, Slack, WhatsApp, Discord). Attachments flow from WASM channels through EmittedMessage to IncomingMessage with validation (size limits, MIME allowlist, count caps) at the host boundary. - Add `attachment` record to `emitted-message` in wit/channel.wit - Add `IncomingAttachment` struct to channel.rs and re-export - Add host-side validation (20MB total, 10 max, MIME allowlist) - Telegram: parse photo, document, audio, video, voice, sticker - Slack: parse file attachments with url_private - WhatsApp: parse image, audio, video, document with captions - Discord: backward-compatible empty attachments - Update FEATURE_PARITY.md section 7 - Add fixture-based tests per channel and host integration tests [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: integrate outbound attachment support and reconcile WIT types (#409) Reconcile PR #409's outbound attachment work with our inbound attachment support into a unified design: WIT type split: - `inbound-attachment` in channel-host: metadata-only (id, mime_type, filename, size_bytes, source_url, storage_key, extracted_text) - `attachment` in channel: raw bytes (filename, mime_type, data) on agent-response for outbound sending Outbound features (from PR #409): - `on-broadcast` WIT export for proactive messages without prior inbound - Telegram: multipart sendPhoto/sendDocument with auto photo→document fallback for files >10MB - wrapper.rs: `call_on_broadcast`, `read_attachments` from disk, attachment params threaded through `call_on_respond` - HTTP tool: `save_to` param for binary downloads to /tmp/ (50MB limit, path traversal protection, SSRF-safe redirect following) - Message tool: allow /tmp/ paths for attachments alongside base_dir - Credential env var fallback in inject_channel_credentials Channel updates: - All 4 channels implement on_broadcast (Telegram full, others stub) - Telegram: polling_enabled config, adjusted poll timeout - Inbound attachment types renamed to InboundAttachment in all channels Tests: 1965 passing (9 new), 0 clippy warnings [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: add audio transcription pipeline and extensible WIT attachment design Add host-side transcription middleware (OpenAI Whisper) that detects audio attachments with inline data on incoming messages and transcribes them automatically. Refactor WIT inbound-attachment to use extras-json and a store-attachment-data host function instead of typed fields, so future attachment properties (dimensions, codec, etc.) don't require WIT changes that invalidate all channel plugins. - Add src/transcription/ module: TranscriptionProvider trait, TranscriptionMiddleware, AudioFormat enum, OpenAI Whisper provider - Add src/config/transcription.rs: TRANSCRIPTION_ENABLED/MODEL/BASE_URL - Wire middleware into agent message loop via AgentDeps - WIT: replace data + duration-secs with extras-json + store-attachment-data - Host: parse extras-json for well-known keys, merge stored binary data - Telegram: download voice files via store-attachment-data, add duration to extras-json, add /file/bot to HTTP allowlist, voice-only placeholder - Add reqwest multipart feature for Whisper API uploads - 5 regression tests for transcription middleware Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: wire attachment processing into LLM pipeline with multimodal image support Attachments on incoming messages are now augmented into user text via XML tags before entering the turn system, and images with data are passed as multimodal content parts (base64 data URIs) to LLM providers. This enables audio transcripts, document text, and image content to reach the LLM without changes to ChatMessage serialization or provider interfaces. - Add src/agent/attachments.rs with augment_with_attachments() and 9 unit tests - Add ContentPart/ImageUrl types to llm::provider with OpenAI-compatible serde - Carry image_content_parts transiently on Turn (skipped in serialization) - Update nearai_chat and rig_adapter to serialize multimodal content - Add 3 e2e tests verifying attachments flow through the full agent loop Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: CI failures — formatting, version bumps, and Telegram voice test - Fix cargo fmt formatting in attachments.rs, nearai_chat.rs, rig_adapter.rs, e2e_attachments.rs - Bump channel registry versions 0.1.0 → 0.2.0 (discord, slack, telegram, whatsapp) to satisfy version-bump CI check - Fix Telegram test_extract_attachments_voice: add missing required `duration` field to voice fixture JSON Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: bump WIT channel version to 0.3.0, fix Telegram voice test, add pre-commit hook - Bump wit/channel.wit package version 0.2.0 → 0.3.0 (interface changed with store-attachment-data) - Update WIT_CHANNEL_VERSION constant and registry wit_version fields to match - Fix Telegram test_extract_attachments_voice: gate voice download behind #[cfg(target_arch = "wasm32")] so host functions aren't called in native tests, update assertions for generated filename and extras_json duration - Add @0.3.0 linker stubs in wit_compat.rs - Add .githooks/pre-commit hook that runs scripts/check-version-bumps.sh when WIT or extension sources are staged - Symlink commit-msg regression hook into .githooks/ [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * refactor: extract voice download from extract_attachments into handle_message Move download_voice_file + store_attachment_data calls out of extract_attachments into a separate download_and_store_voice function called from handle_message. This keeps extract_attachments as a pure data-mapping function with no host calls, making it fully testable in native unit tests without #[cfg(target_arch)] gates. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: address PR review comments — security, correctness, and code quality Security fixes: - Add path validation to read_attachments (restrict to /tmp/) preventing arbitrary file reads from compromised tools - Escape XML special characters in attachment filenames, MIME types, and extracted text to prevent prompt injection via tag spoofing - Percent-encode file_id in Telegram getFile URL to prevent query injection - Clone SecretString directly instead of expose_secret().to_string() Correctness fixes: - Fix store_attachment_data overwrite accounting: subtract old entry size before adding new to prevent inflated totals and false rejections - Use max(reported, stored_size) for attachment size accounting to prevent WASM channels from under-reporting size_bytes to bypass limits - Add application/octet-stream to MIME allowlist (channels default unknown types to this) Code quality: - Extract send_response helper in Telegram, deduplicating on_respond and on_broadcast - Rename misleading Discord test to test_parse_slash_command_interaction - Fix .githooks/commit-msg to use relative symlink (portable across machines) [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: add tool_upgrade command + fix TOCTOU in save_to path validation Add `tool_upgrade` — a new extension management tool that automatically detects and reinstalls WASM extensions with outdated WIT versions. Preserves authentication secrets during upgrade. Supports upgrading a single extension by name or all installed WASM tools/channels at once. Fix TOCTOU in `validate_save_to_path`: validate the path *before* creating parent directories, so traversal paths like `/tmp/../../etc/` cannot cause filesystem mutations outside /tmp before being rejected. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: unify WIT package version to 0.3.0 across tool.wit and all capabilities tool.wit and channel.wit share the `near:agent` package namespace, so they must declare the same version. Bumps tool.wit from 0.2.0 to 0.3.0 and updates all capabilities files and registry entries to match. Fixes `cargo component build` failure: "package identifier near:[email protected] does not match previous package name of near:[email protected]" [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: move WIT file comments after package declaration WIT treats `//` comments before `package` as doc comments. When both tool.wit and channel.wit had header comments, the parser rejected them as "doc comments on multiple 'package' items". Move comments after the package declaration in both files. Also bumps tool registry versions to 0.2.0 to match the WIT 0.3.0 bump. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: display extension versions in gateway Extensions tab Add version field to InstalledExtension and RegistryEntry types, pipe through the web API (ExtensionInfo, RegistryEntryInfo), and render as a badge in the gateway UI for both installed and available extensions. For installed WASM extensions, version is read from the capabilities file with a fallback to the registry entry when the local file has no version (old installations). Bump all extension Cargo.toml and registry JSON versions from 0.1.0 to 0.2.0 to keep them in sync. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: add document text extraction middleware for PDF, Office, and text files Extract text from document attachments (PDF, DOCX, PPTX, XLSX, RTF, plain text, code files) so the LLM can reason about uploaded documents. Uses pdf-extract for PDFs, zip+XML parsing for Office XML formats, and UTF-8 decode for text files. Wired into the agent loop after transcription middleware. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: download document files in Telegram channel for text extraction The DocumentExtractionMiddleware needs file bytes in the attachment `data` field, but only voice files were being downloaded. Document attachments (PDFs, DOCX, etc.) had empty `data` and a source_url with a credential placeholder that only works inside the WASM host's http_request. Add `download_and_store_documents()` that downloads non-voice, non-image, non-audio attachments via the existing two-step getFile→download flow and stores bytes via `store_attachment_data` for host-side extraction. Also rename `download_voice_file` → `download_telegram_file` since it's generic for any file_id. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: allow Office MIME types and increase file download limit for Telegram Two issues preventing document extraction from Telegram: 1. PPTX/DOCX/XLSX MIME types (application/vnd.*) were dropped by the WASM host attachment allowlist — add application/vnd., application/msword, and application/rtf prefixes. 2. Telegram file downloads over 10 MB failed with "Response body too large" — set max_response_bytes to 20 MB in Telegram capabilities. [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: report document extraction errors back to user instead of silently skipping - Bump max_response_bytes to 50 MB for Telegram file downloads - When document extraction fails (too large, download error, parse error), set extracted_text to a user-friendly error message instead of leaving it None. This ensures the LLM tells the user what went wrong. - On Telegram download failure, set extracted_text with the error so the user sees feedback even when the file never reaches the extraction middleware. Co-Authored-By: Claude Opus 4.6 <[email protected]> * feat: store extracted document text in workspace memory for search/recall After document extraction succeeds, write the extracted text to workspace memory at `documents/{date}/{filename}`. This enables: - Full-text and semantic search over past uploaded documents - Cross-conversation recall ("what did that PDF say?") - Automatic chunking and embedding via the workspace pipeline Documents are stored with metadata header (uploader, channel, date, MIME type). Error messages (extraction failures) are not stored — only successful extractions. Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: CI failures — formatting, unused assignment warning - Run cargo fmt on document_extraction and agent_loop modules - Suppress unused_assignments warning on trace_llm_ref (used only behind #[cfg(feature = "libsql")]) [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: address PR review comments — security, correctness, and code quality Security fixes: - Remove SSRF-prone download() from DocumentExtractionMiddleware (#13) - Sanitize filenames in workspace path to prevent directory traversal (#11) - Pre-check file size before reading in WASM wrapper to prevent OOM (#2) - Percent-encode file_id in Telegram source URLs (#7) Correctness fixes: - Clear image_content_parts on turn end to prevent memory leak (#1) - Find first *successful* transcription instead of first overall (#3) - Enforce data.len() size limit in document extraction (#10) - Use UTF-8 safe truncation with char_indices() (#12) Robustness & code quality: - Add 120s timeout to OpenAI Whisper HTTP client (#5) - Trim trailing slash from Whisper base_url (#6) - Allow ~/.ironclaw/ paths in WASM wrapper (#8) - Return error from on_broadcast in Slack/Discord/WhatsApp (#9) - Fix doc comment in HTTP tool (#4) Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: formatting — cargo fmt Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: address latest PR review — doc comments, error messages, version bumps - Fix DocumentExtractionMiddleware doc comment (no longer downloads from source_url) - Fix error message: "no inline data" instead of "no download URL" - Log error + fallback instead of silent unwrap_or_default on Whisper HTTP client - Bump all capabilities.json versions from 0.1.0 to 0.2.0 to match Cargo.toml Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: remove unsupported profile: minimal from CI workflows [skip-regression-check] dtolnay/rust-toolchain@stable does not accept the 'profile' input (it was a parameter for the deprecated actions-rs/toolchain action). Co-Authored-By: Claude Opus 4.6 <[email protected]> * fix: merge with latest main — resolve compilation errors and PR review nits - Add version: None to RegistryEntry/InstalledExtension test constructors - Fix MessageContent type mismatches in nearai_chat tests (String → MessageContent::Text) - Fix .contains() calls on MessageContent — use .as_text().unwrap() - Remove redundant trace_llm_ref = None assignment in test_rig - Check data size before clone in document extraction to avoid unnecessary allocation [skip-regression-check] Co-Authored-By: Claude Opus 4.6 <[email protected]> --------- Co-authored-by: Claude Opus 4.6 <[email protected]>
939 lines
34 KiB
Rust
939 lines
34 KiB
Rust
//! Curated in-memory catalog of known extensions with fuzzy search.
|
|
//!
|
|
//! The registry holds well-known channels, tools, and MCP servers that can be
|
|
//! installed via conversational commands. Online discoveries are cached here too.
|
|
|
|
use tokio::sync::RwLock;
|
|
|
|
use crate::extensions::{
|
|
AuthHint, ExtensionKind, ExtensionSource, RegistryEntry, ResultSource, SearchResult,
|
|
};
|
|
|
|
/// Curated extension registry with fuzzy search.
|
|
pub struct ExtensionRegistry {
|
|
/// Built-in curated entries.
|
|
entries: Vec<RegistryEntry>,
|
|
/// Cached entries from online discovery (session-lived).
|
|
discovery_cache: RwLock<Vec<RegistryEntry>>,
|
|
}
|
|
|
|
impl ExtensionRegistry {
|
|
/// Create a new registry populated with known extensions.
|
|
pub fn new() -> Self {
|
|
Self {
|
|
entries: builtin_entries(),
|
|
discovery_cache: RwLock::new(Vec::new()),
|
|
}
|
|
}
|
|
|
|
/// Create a new registry merging builtin entries with catalog-provided entries.
|
|
///
|
|
/// Deduplicates by `(name, kind)` pair -- a builtin MCP "slack" and a registry
|
|
/// WASM "slack" can coexist since they're different kinds.
|
|
pub fn new_with_catalog(catalog_entries: Vec<RegistryEntry>) -> Self {
|
|
let mut entries = builtin_entries();
|
|
for entry in catalog_entries {
|
|
if !entries
|
|
.iter()
|
|
.any(|e| e.name == entry.name && e.kind == entry.kind)
|
|
{
|
|
entries.push(entry);
|
|
}
|
|
}
|
|
Self {
|
|
entries,
|
|
discovery_cache: RwLock::new(Vec::new()),
|
|
}
|
|
}
|
|
|
|
/// Search the registry by query string. Returns results sorted by relevance.
|
|
///
|
|
/// Splits the query into lowercase tokens and scores each entry by matches
|
|
/// in name, keywords, and description.
|
|
pub async fn search(&self, query: &str) -> Vec<SearchResult> {
|
|
let tokens: Vec<String> = query
|
|
.to_lowercase()
|
|
.split_whitespace()
|
|
.map(|s| s.to_string())
|
|
.collect();
|
|
|
|
if tokens.is_empty() {
|
|
// Return all entries when query is empty
|
|
return self
|
|
.entries
|
|
.iter()
|
|
.map(|e| SearchResult {
|
|
entry: e.clone(),
|
|
source: ResultSource::Registry,
|
|
validated: true,
|
|
})
|
|
.collect();
|
|
}
|
|
|
|
let mut scored: Vec<(SearchResult, u32)> = Vec::new();
|
|
|
|
// Score built-in entries
|
|
for entry in &self.entries {
|
|
let score = score_entry(entry, &tokens);
|
|
if score > 0 {
|
|
scored.push((
|
|
SearchResult {
|
|
entry: entry.clone(),
|
|
source: ResultSource::Registry,
|
|
validated: true,
|
|
},
|
|
score,
|
|
));
|
|
}
|
|
}
|
|
|
|
// Score cached discoveries
|
|
let cache = self.discovery_cache.read().await;
|
|
for entry in cache.iter() {
|
|
let score = score_entry(entry, &tokens);
|
|
if score > 0 {
|
|
scored.push((
|
|
SearchResult {
|
|
entry: entry.clone(),
|
|
source: ResultSource::Discovered,
|
|
validated: true,
|
|
},
|
|
score,
|
|
));
|
|
}
|
|
}
|
|
|
|
scored.sort_by_key(|b| std::cmp::Reverse(b.1));
|
|
scored.into_iter().map(|(r, _)| r).collect()
|
|
}
|
|
|
|
/// Look up an entry by exact name.
|
|
///
|
|
/// NOTE: Prefer [`get_with_kind`] when a kind hint is available, to avoid
|
|
/// returning the wrong entry when two entries share a name but differ in kind.
|
|
pub async fn get(&self, name: &str) -> Option<RegistryEntry> {
|
|
if let Some(entry) = self.entries.iter().find(|e| e.name == name) {
|
|
return Some(entry.clone());
|
|
}
|
|
let cache = self.discovery_cache.read().await;
|
|
cache.iter().find(|e| e.name == name).cloned()
|
|
}
|
|
|
|
/// Look up an entry by exact name, filtering by kind when provided.
|
|
///
|
|
/// When `kind` is `Some(...)`, only returns an entry matching both name and
|
|
/// kind — never falls back to a different kind. When `kind` is `None`,
|
|
/// returns the first name match (same as [`get`]).
|
|
pub async fn get_with_kind(
|
|
&self,
|
|
name: &str,
|
|
kind: Option<ExtensionKind>,
|
|
) -> Option<RegistryEntry> {
|
|
if let Some(kind) = kind {
|
|
if let Some(entry) = self
|
|
.entries
|
|
.iter()
|
|
.find(|e| e.name == name && e.kind == kind)
|
|
{
|
|
return Some(entry.clone());
|
|
}
|
|
let cache = self.discovery_cache.read().await;
|
|
if let Some(entry) = cache.iter().find(|e| e.name == name && e.kind == kind) {
|
|
return Some(entry.clone());
|
|
}
|
|
// Kind was specified but no entry matches — don't fall back to a
|
|
// different kind, as that would silently misroute the install.
|
|
return None;
|
|
}
|
|
self.get(name).await
|
|
}
|
|
|
|
/// Return all registry entries (builtins + cached discoveries).
|
|
pub async fn all_entries(&self) -> Vec<RegistryEntry> {
|
|
let mut entries = self.entries.clone();
|
|
let cache = self.discovery_cache.read().await;
|
|
for entry in cache.iter() {
|
|
if !entries
|
|
.iter()
|
|
.any(|e| e.name == entry.name && e.kind == entry.kind)
|
|
{
|
|
entries.push(entry.clone());
|
|
}
|
|
}
|
|
entries
|
|
}
|
|
|
|
/// Add discovered entries to the cache.
|
|
pub async fn cache_discovered(&self, entries: Vec<RegistryEntry>) {
|
|
let mut cache = self.discovery_cache.write().await;
|
|
for entry in entries {
|
|
// Deduplicate by (name, kind) — same pair as new_with_catalog()
|
|
if !cache
|
|
.iter()
|
|
.any(|e| e.name == entry.name && e.kind == entry.kind)
|
|
{
|
|
cache.push(entry);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for ExtensionRegistry {
|
|
fn default() -> Self {
|
|
Self::new()
|
|
}
|
|
}
|
|
|
|
/// Score an entry against search tokens. Higher = better match.
|
|
fn score_entry(entry: &RegistryEntry, tokens: &[String]) -> u32 {
|
|
let mut score = 0u32;
|
|
let name_lower = entry.name.to_lowercase();
|
|
let display_lower = entry.display_name.to_lowercase();
|
|
let desc_lower = entry.description.to_lowercase();
|
|
let keywords_lower: Vec<String> = entry.keywords.iter().map(|k| k.to_lowercase()).collect();
|
|
|
|
for token in tokens {
|
|
// Exact name match is the strongest signal
|
|
if name_lower == *token {
|
|
score += 100;
|
|
} else if name_lower.contains(token.as_str()) {
|
|
score += 50;
|
|
}
|
|
|
|
// Display name match
|
|
if display_lower.contains(token.as_str()) {
|
|
score += 30;
|
|
}
|
|
|
|
// Keyword match
|
|
for kw in &keywords_lower {
|
|
if kw == token {
|
|
score += 40;
|
|
} else if kw.contains(token.as_str()) {
|
|
score += 20;
|
|
}
|
|
}
|
|
|
|
// Description match (weakest signal)
|
|
if desc_lower.contains(token.as_str()) {
|
|
score += 10;
|
|
}
|
|
}
|
|
|
|
score
|
|
}
|
|
|
|
/// Well-known extensions that ship with ironclaw.
|
|
fn builtin_entries() -> Vec<RegistryEntry> {
|
|
vec![
|
|
// -- MCP Servers --
|
|
RegistryEntry {
|
|
name: "notion".to_string(),
|
|
display_name: "Notion".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Connect to Notion for reading and writing pages, databases, and comments"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"notes".into(),
|
|
"wiki".into(),
|
|
"docs".into(),
|
|
"pages".into(),
|
|
"database".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.notion.com/mcp".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "linear".to_string(),
|
|
display_name: "Linear".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to Linear for issue tracking, project management, and team workflows"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"issues".into(),
|
|
"tickets".into(),
|
|
"project".into(),
|
|
"tracking".into(),
|
|
"bugs".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.linear.app/sse".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "github".to_string(),
|
|
display_name: "GitHub".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to GitHub for repository management, issues, PRs, and code search"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"git".into(),
|
|
"repos".into(),
|
|
"code".into(),
|
|
"pull-request".into(),
|
|
"issues".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://api.githubcopilot.com/mcp/".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "slack-mcp".to_string(),
|
|
display_name: "Slack MCP".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to Slack via MCP for messaging, channel management, and team communication"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"messaging".into(),
|
|
"chat".into(),
|
|
"channels".into(),
|
|
"team".into(),
|
|
"communication".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.slack.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "sentry".to_string(),
|
|
display_name: "Sentry".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to Sentry for error tracking, performance monitoring, and debugging"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"errors".into(),
|
|
"monitoring".into(),
|
|
"debugging".into(),
|
|
"crashes".into(),
|
|
"performance".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.sentry.dev/mcp".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "stripe".to_string(),
|
|
display_name: "Stripe".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to Stripe for payment processing, subscriptions, and financial data"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"payments".into(),
|
|
"billing".into(),
|
|
"subscriptions".into(),
|
|
"invoices".into(),
|
|
"finance".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.stripe.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "cloudflare".to_string(),
|
|
display_name: "Cloudflare".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description:
|
|
"Connect to Cloudflare for DNS, Workers, KV, and infrastructure management"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"cdn".into(),
|
|
"dns".into(),
|
|
"workers".into(),
|
|
"hosting".into(),
|
|
"infrastructure".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.cloudflare.com/mcp".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "asana".to_string(),
|
|
display_name: "Asana".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Connect to Asana for task management, projects, and team coordination"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"tasks".into(),
|
|
"projects".into(),
|
|
"management".into(),
|
|
"team".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.asana.com/v2/mcp".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "intercom".to_string(),
|
|
display_name: "Intercom".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Connect to Intercom for customer messaging, support, and engagement"
|
|
.to_string(),
|
|
keywords: vec![
|
|
"support".into(),
|
|
"customers".into(),
|
|
"messaging".into(),
|
|
"chat".into(),
|
|
"helpdesk".into(),
|
|
],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://mcp.intercom.com/mcp".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
},
|
|
// WASM channels (telegram, slack, discord, whatsapp) come from the embedded
|
|
// registry catalog (registry/channels/*.json) with WasmDownload URLs pointing
|
|
// to GitHub release artifacts. See new_with_catalog() for merging.
|
|
]
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::extensions::registry::{ExtensionRegistry, score_entry};
|
|
use crate::extensions::{AuthHint, ExtensionKind, ExtensionSource, RegistryEntry};
|
|
|
|
#[test]
|
|
fn test_score_exact_name_match() {
|
|
let entry = RegistryEntry {
|
|
name: "notion".to_string(),
|
|
display_name: "Notion".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Workspace tool".to_string(),
|
|
keywords: vec!["notes".into()],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
};
|
|
|
|
let score = score_entry(&entry, &["notion".to_string()]);
|
|
assert!(
|
|
score >= 100,
|
|
"Exact name match should score >= 100, got {}",
|
|
score
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_score_partial_name_match() {
|
|
let entry = RegistryEntry {
|
|
name: "google-calendar".to_string(),
|
|
display_name: "Google Calendar".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Calendar management".to_string(),
|
|
keywords: vec!["events".into()],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
};
|
|
|
|
let score = score_entry(&entry, &["calendar".to_string()]);
|
|
assert!(
|
|
score > 0,
|
|
"Partial name match should score > 0, got {}",
|
|
score
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_score_keyword_match() {
|
|
let entry = RegistryEntry {
|
|
name: "notion".to_string(),
|
|
display_name: "Notion".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Workspace tool".to_string(),
|
|
keywords: vec!["wiki".into(), "notes".into()],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
};
|
|
|
|
let score = score_entry(&entry, &["wiki".to_string()]);
|
|
assert!(
|
|
score >= 40,
|
|
"Exact keyword match should score >= 40, got {}",
|
|
score
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_score_no_match() {
|
|
let entry = RegistryEntry {
|
|
name: "notion".to_string(),
|
|
display_name: "Notion".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Workspace tool".to_string(),
|
|
keywords: vec!["notes".into()],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
};
|
|
|
|
let score = score_entry(&entry, &["xyzfoobar".to_string()]);
|
|
assert_eq!(score, 0, "No match should score 0");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_search_returns_sorted() {
|
|
let registry = ExtensionRegistry::new();
|
|
let results = registry.search("notion").await;
|
|
|
|
assert!(!results.is_empty(), "Should find notion in registry");
|
|
assert_eq!(results[0].entry.name, "notion");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_search_empty_query_returns_all() {
|
|
let registry = ExtensionRegistry::new();
|
|
let results = registry.search("").await;
|
|
|
|
assert!(results.len() > 5, "Empty query should return all entries");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_search_by_keyword() {
|
|
let registry = ExtensionRegistry::new();
|
|
let results = registry.search("issues tickets").await;
|
|
|
|
assert!(
|
|
!results.is_empty(),
|
|
"Should find entries matching 'issues tickets'"
|
|
);
|
|
// Linear should be near the top since it has both keywords
|
|
let linear_pos = results.iter().position(|r| r.entry.name == "linear");
|
|
assert!(linear_pos.is_some(), "Linear should appear in results");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_get_exact_name() {
|
|
let registry = ExtensionRegistry::new();
|
|
|
|
let entry = registry.get("notion").await;
|
|
assert!(entry.is_some());
|
|
assert_eq!(entry.unwrap().display_name, "Notion");
|
|
|
|
let missing = registry.get("nonexistent").await;
|
|
assert!(missing.is_none());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_cache_discovered() {
|
|
let registry = ExtensionRegistry::new();
|
|
|
|
let discovered = RegistryEntry {
|
|
name: "custom-mcp".to_string(),
|
|
display_name: "Custom MCP".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "A custom MCP server".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://custom.example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
};
|
|
|
|
registry.cache_discovered(vec![discovered]).await;
|
|
|
|
let entry = registry.get("custom-mcp").await;
|
|
assert!(entry.is_some());
|
|
|
|
let results = registry.search("custom").await;
|
|
assert!(!results.is_empty());
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_cache_deduplication() {
|
|
let registry = ExtensionRegistry::new();
|
|
|
|
let entry = RegistryEntry {
|
|
name: "dup".to_string(),
|
|
display_name: "Dup".to_string(),
|
|
kind: ExtensionKind::McpServer,
|
|
description: "Test".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://example.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::None,
|
|
version: None,
|
|
};
|
|
|
|
registry.cache_discovered(vec![entry.clone()]).await;
|
|
registry.cache_discovered(vec![entry]).await;
|
|
|
|
let results = registry.search("dup").await;
|
|
assert_eq!(results.len(), 1, "Should not duplicate cached entries");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_new_with_catalog() {
|
|
let catalog_entries = vec![
|
|
RegistryEntry {
|
|
name: "telegram".to_string(),
|
|
display_name: "Telegram".to_string(),
|
|
kind: ExtensionKind::WasmChannel,
|
|
description: "Telegram Bot API channel".to_string(),
|
|
keywords: vec!["messaging".into(), "bot".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "channels-src/telegram".to_string(),
|
|
build_dir: Some("channels-src/telegram".to_string()),
|
|
crate_name: Some("telegram-channel".to_string()),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
// This shares a name with the builtin slack-mcp but has a different kind, so both should appear
|
|
RegistryEntry {
|
|
name: "slack-mcp".to_string(),
|
|
display_name: "Slack MCP WASM".to_string(),
|
|
kind: ExtensionKind::WasmTool,
|
|
description: "Slack WASM tool".to_string(),
|
|
keywords: vec!["messaging".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "tools-src/slack".to_string(),
|
|
build_dir: Some("tools-src/slack".to_string()),
|
|
crate_name: Some("slack-tool".to_string()),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
];
|
|
|
|
let registry = ExtensionRegistry::new_with_catalog(catalog_entries);
|
|
|
|
// Should find the new telegram entry
|
|
let results = registry.search("telegram").await;
|
|
assert!(!results.is_empty(), "Should find telegram from catalog");
|
|
assert_eq!(results[0].entry.name, "telegram");
|
|
|
|
// Should have both builtin MCP slack-mcp and catalog WASM slack-mcp
|
|
let results = registry.search("slack").await;
|
|
let slack_mcp = results
|
|
.iter()
|
|
.any(|r| r.entry.name == "slack-mcp" && r.entry.kind == ExtensionKind::McpServer);
|
|
let slack_wasm = results
|
|
.iter()
|
|
.any(|r| r.entry.name == "slack-mcp" && r.entry.kind == ExtensionKind::WasmTool);
|
|
assert!(slack_mcp, "Should have builtin MCP slack-mcp");
|
|
assert!(slack_wasm, "Should have catalog WASM slack-mcp");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_new_with_catalog_dedup_same_kind() {
|
|
// A catalog entry with same name AND kind as a builtin should be skipped
|
|
let catalog_entries = vec![RegistryEntry {
|
|
name: "slack-mcp".to_string(),
|
|
display_name: "Slack MCP Override".to_string(),
|
|
kind: ExtensionKind::McpServer, // same kind as builtin slack-mcp
|
|
description: "Should be skipped".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::McpUrl {
|
|
url: "https://other.slack.com".to_string(),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::Dcr,
|
|
version: None,
|
|
}];
|
|
|
|
let registry = ExtensionRegistry::new_with_catalog(catalog_entries);
|
|
|
|
let entry = registry.get("slack-mcp").await;
|
|
assert!(entry.is_some());
|
|
// Should still be the builtin, not the override
|
|
assert_eq!(entry.unwrap().display_name, "Slack MCP");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_get_with_kind_resolves_collision() {
|
|
// Two entries with the same name but different kinds (the telegram collision scenario)
|
|
let catalog_entries = vec![
|
|
RegistryEntry {
|
|
name: "telegram".to_string(),
|
|
display_name: "Telegram Tool".to_string(),
|
|
kind: ExtensionKind::WasmTool,
|
|
description: "Telegram MTProto tool".to_string(),
|
|
keywords: vec!["messaging".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "tools-src/telegram".to_string(),
|
|
build_dir: Some("tools-src/telegram".to_string()),
|
|
crate_name: Some("telegram-tool".to_string()),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "telegram".to_string(),
|
|
display_name: "Telegram Channel".to_string(),
|
|
kind: ExtensionKind::WasmChannel,
|
|
description: "Telegram Bot API channel".to_string(),
|
|
keywords: vec!["messaging".into(), "bot".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "channels-src/telegram".to_string(),
|
|
build_dir: Some("channels-src/telegram".to_string()),
|
|
crate_name: Some("telegram-channel".to_string()),
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
];
|
|
|
|
let registry = ExtensionRegistry::new_with_catalog(catalog_entries);
|
|
|
|
// Without kind hint, get() returns the first match (WasmTool)
|
|
let entry = registry.get("telegram").await;
|
|
assert!(entry.is_some());
|
|
assert_eq!(entry.unwrap().kind, ExtensionKind::WasmTool);
|
|
|
|
// With kind hint for WasmChannel, get_with_kind() returns the channel entry
|
|
let entry = registry
|
|
.get_with_kind("telegram", Some(ExtensionKind::WasmChannel))
|
|
.await;
|
|
assert!(entry.is_some());
|
|
let entry = entry.unwrap();
|
|
assert_eq!(entry.kind, ExtensionKind::WasmChannel);
|
|
assert_eq!(entry.display_name, "Telegram Channel");
|
|
|
|
// With kind hint for WasmTool, get_with_kind() returns the tool entry
|
|
let entry = registry
|
|
.get_with_kind("telegram", Some(ExtensionKind::WasmTool))
|
|
.await;
|
|
assert!(entry.is_some());
|
|
let entry = entry.unwrap();
|
|
assert_eq!(entry.kind, ExtensionKind::WasmTool);
|
|
assert_eq!(entry.display_name, "Telegram Tool");
|
|
|
|
// Without kind hint (None), get_with_kind() falls back to first match
|
|
let entry = registry.get_with_kind("telegram", None).await;
|
|
assert!(entry.is_some());
|
|
assert_eq!(entry.unwrap().kind, ExtensionKind::WasmTool);
|
|
|
|
// Kind mismatch: no McpServer named "telegram" exists — must return None,
|
|
// not silently fall back to the WasmTool entry.
|
|
let entry = registry
|
|
.get_with_kind("telegram", Some(ExtensionKind::McpServer))
|
|
.await;
|
|
assert!(
|
|
entry.is_none(),
|
|
"Should return None when kind doesn't match, not fall back to wrong kind"
|
|
);
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_get_with_kind_discovery_cache() {
|
|
let registry = ExtensionRegistry::new();
|
|
|
|
// Add two entries with the same name but different kinds to the discovery cache
|
|
let tool_entry = RegistryEntry {
|
|
name: "cached-ext".to_string(),
|
|
display_name: "Cached Tool".to_string(),
|
|
kind: ExtensionKind::WasmTool,
|
|
description: "A cached tool".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "tools-src/cached".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::None,
|
|
version: None,
|
|
};
|
|
let channel_entry = RegistryEntry {
|
|
name: "cached-ext".to_string(),
|
|
display_name: "Cached Channel".to_string(),
|
|
kind: ExtensionKind::WasmChannel,
|
|
description: "A cached channel".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "channels-src/cached".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::None,
|
|
version: None,
|
|
};
|
|
|
|
registry
|
|
.cache_discovered(vec![tool_entry, channel_entry])
|
|
.await;
|
|
|
|
// Kind-aware lookup should find the channel in the cache
|
|
let entry = registry
|
|
.get_with_kind("cached-ext", Some(ExtensionKind::WasmChannel))
|
|
.await;
|
|
assert!(entry.is_some());
|
|
assert_eq!(entry.unwrap().display_name, "Cached Channel");
|
|
|
|
// Kind-aware lookup should find the tool in the cache
|
|
let entry = registry
|
|
.get_with_kind("cached-ext", Some(ExtensionKind::WasmTool))
|
|
.await;
|
|
assert!(entry.is_some());
|
|
assert_eq!(entry.unwrap().display_name, "Cached Tool");
|
|
}
|
|
|
|
// Channel tests (telegram, slack, discord, whatsapp) require the embedded catalog
|
|
// to be loaded via new_with_catalog(). See test_new_with_catalog for catalog coverage.
|
|
|
|
// === QA Plan P2 - 2.4: Extension registry collision tests ===
|
|
|
|
#[tokio::test]
|
|
async fn test_same_name_different_kind_both_discoverable() {
|
|
// A WASM channel and WASM tool with the same name must coexist.
|
|
let catalog_entries = vec![
|
|
RegistryEntry {
|
|
name: "telegram".to_string(),
|
|
display_name: "Telegram Channel".to_string(),
|
|
kind: ExtensionKind::WasmChannel,
|
|
description: "Telegram messaging channel".to_string(),
|
|
keywords: vec!["messaging".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "channels-src/telegram".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "telegram".to_string(),
|
|
display_name: "Telegram Tool".to_string(),
|
|
kind: ExtensionKind::WasmTool,
|
|
description: "Telegram API tool".to_string(),
|
|
keywords: vec!["messaging".into()],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "tools-src/telegram".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::CapabilitiesAuth,
|
|
version: None,
|
|
},
|
|
];
|
|
|
|
let registry = ExtensionRegistry::new_with_catalog(catalog_entries);
|
|
let all = registry.all_entries().await;
|
|
|
|
// Both should exist since they have different kinds.
|
|
let channel = all
|
|
.iter()
|
|
.find(|e| e.name == "telegram" && e.kind == ExtensionKind::WasmChannel);
|
|
let tool = all
|
|
.iter()
|
|
.find(|e| e.name == "telegram" && e.kind == ExtensionKind::WasmTool);
|
|
|
|
assert!(channel.is_some(), "Channel entry missing");
|
|
assert!(tool.is_some(), "Tool entry missing");
|
|
|
|
// Search should return both.
|
|
let results = registry.search("telegram").await;
|
|
let channel_hit = results
|
|
.iter()
|
|
.any(|r| r.entry.name == "telegram" && r.entry.kind == ExtensionKind::WasmChannel);
|
|
let tool_hit = results
|
|
.iter()
|
|
.any(|r| r.entry.name == "telegram" && r.entry.kind == ExtensionKind::WasmTool);
|
|
assert!(channel_hit, "Search should find channel");
|
|
assert!(tool_hit, "Search should find tool");
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn test_get_returns_first_match_regardless_of_kind() {
|
|
// `get()` returns the first entry with a matching name. If a channel
|
|
// and tool share a name, callers that need a specific kind should
|
|
// filter by kind.
|
|
let catalog_entries = vec![
|
|
RegistryEntry {
|
|
name: "myext".to_string(),
|
|
display_name: "MyExt Channel".to_string(),
|
|
kind: ExtensionKind::WasmChannel,
|
|
description: "Channel".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "x".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::None,
|
|
version: None,
|
|
},
|
|
RegistryEntry {
|
|
name: "myext".to_string(),
|
|
display_name: "MyExt Tool".to_string(),
|
|
kind: ExtensionKind::WasmTool,
|
|
description: "Tool".to_string(),
|
|
keywords: vec![],
|
|
source: ExtensionSource::WasmBuildable {
|
|
source_dir: "y".to_string(),
|
|
build_dir: None,
|
|
crate_name: None,
|
|
},
|
|
fallback_source: None,
|
|
auth_hint: AuthHint::None,
|
|
version: None,
|
|
},
|
|
];
|
|
|
|
let registry = ExtensionRegistry::new_with_catalog(catalog_entries);
|
|
|
|
// get() is name-only, returns first match.
|
|
let entry = registry.get("myext").await;
|
|
assert!(entry.is_some());
|
|
// The first catalog entry added is the channel.
|
|
assert_eq!(entry.unwrap().kind, ExtensionKind::WasmChannel);
|
|
}
|
|
}
|