refactor(core): remove provider module, migrate to LLMProvider, add client mode handling, improve serialization error handling, update workspace edition, and clean up conditionals and imports
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
use anyhow::{Context, Result};
|
||||
use handlebars::Handlebars;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{json, Value};
|
||||
use serde_json::{Value, json};
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
@@ -14,8 +14,8 @@ use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use owlen_core::mcp::protocol::{
|
||||
methods, ErrorCode, InitializeParams, InitializeResult, RequestId, RpcError, RpcErrorResponse,
|
||||
RpcRequest, RpcResponse, ServerCapabilities, ServerInfo, PROTOCOL_VERSION,
|
||||
ErrorCode, InitializeParams, InitializeResult, PROTOCOL_VERSION, RequestId, RpcError,
|
||||
RpcErrorResponse, RpcRequest, RpcResponse, ServerCapabilities, ServerInfo, methods,
|
||||
};
|
||||
use owlen_core::mcp::{McpToolCall, McpToolDescriptor, McpToolResponse};
|
||||
use tokio::io::{self, AsyncBufReadExt, AsyncWriteExt};
|
||||
@@ -148,7 +148,7 @@ FINAL_ANSWER: Summary of what was done"#
|
||||
template.name, e
|
||||
);
|
||||
} else {
|
||||
let mut templates = futures::executor::block_on(self.templates.write());
|
||||
let mut templates = self.templates.blocking_write();
|
||||
templates.insert(template.name.clone(), template);
|
||||
}
|
||||
}
|
||||
@@ -284,10 +284,10 @@ async fn handle_request(
|
||||
supports_streaming: Some(false),
|
||||
},
|
||||
};
|
||||
Ok(RpcResponse::new(
|
||||
req.id,
|
||||
serde_json::to_value(result).unwrap(),
|
||||
))
|
||||
let payload = serde_json::to_value(result).map_err(|e| {
|
||||
RpcError::internal_error(format!("Failed to serialize initialize result: {}", e))
|
||||
})?;
|
||||
Ok(RpcResponse::new(req.id, payload))
|
||||
}
|
||||
methods::TOOLS_LIST => {
|
||||
let tools = vec![
|
||||
@@ -349,9 +349,17 @@ async fn handle_request(
|
||||
|
||||
let srv = server.lock().await;
|
||||
match srv.get_template(name).await {
|
||||
Some(template) => {
|
||||
json!({"success": true, "template": serde_json::to_value(template).unwrap()})
|
||||
}
|
||||
Some(template) => match serde_json::to_value(template) {
|
||||
Ok(serialized) => {
|
||||
json!({"success": true, "template": serialized})
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(RpcError::internal_error(format!(
|
||||
"Failed to serialize template '{}': {}",
|
||||
name, e
|
||||
)));
|
||||
}
|
||||
},
|
||||
None => json!({"success": false, "error": "Template not found"}),
|
||||
}
|
||||
}
|
||||
@@ -397,10 +405,10 @@ async fn handle_request(
|
||||
duration_ms: 0,
|
||||
};
|
||||
|
||||
Ok(RpcResponse::new(
|
||||
req.id,
|
||||
serde_json::to_value(resp).unwrap(),
|
||||
))
|
||||
let payload = serde_json::to_value(resp).map_err(|e| {
|
||||
RpcError::internal_error(format!("Failed to serialize tool response: {}", e))
|
||||
})?;
|
||||
Ok(RpcResponse::new(req.id, payload))
|
||||
}
|
||||
_ => Err(RpcError::method_not_found(&req.method)),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user