refactor(host): move chat_canvas_tools to op-web-daemon (Phase 2 leaf)
MCP chat-tool execution (tool defs, channel, execute, apply_design_modification, UiChatToolExecutor) shared by the chat bridges. Items promoted to pub; 7 consumers repointed to op_web_daemon::chat_canvas_tools. No dep/lock change.
This commit is contained in:
parent
4bc88e430b
commit
429246718a
|
|
@ -18,7 +18,7 @@ use serde_json::{json, Value};
|
|||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::chat_agent_loop::{run_anthropic_agent_loop, run_openai_agent_loop, AgentLoopConfig};
|
||||
use crate::chat_canvas_tools::MAX_TOOL_TURNS;
|
||||
use op_web_daemon::chat_canvas_tools::MAX_TOOL_TURNS;
|
||||
use crate::chat_runtime::{resolved_skill_preamble, shared_runtime, BlockingRecvIter};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ use op_editor_core::pen_node_ext::PenNodeExt;
|
|||
use op_editor_core::EditorState;
|
||||
use op_orchestrator::{AppendContext, DesignRequest};
|
||||
|
||||
use crate::chat_canvas_tools::UiChatToolExecutor;
|
||||
use op_web_daemon::chat_canvas_tools::UiChatToolExecutor;
|
||||
use crate::chat_provider_llm::ChatProviderLlmClient;
|
||||
use crate::design_session::{run_design_worker, DesignCmdReq, DesignDelta};
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use op_host_native::WidgetHostNative;
|
|||
use op_orchestrator::DesignRequest;
|
||||
|
||||
use super::*;
|
||||
use crate::chat_canvas_tools::{apply_design_modification, chat_tool_channel};
|
||||
use op_web_daemon::chat_canvas_tools::{apply_design_modification, chat_tool_channel};
|
||||
use crate::design_session::{pump_commands, pump_progress, DesignSession};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub use op_editor_host_core::chat::ChatPoll;
|
|||
pub use op_editor_host_core::chat::{apply_poll_to_message, ChatSession};
|
||||
use op_host_native::WidgetHostNative;
|
||||
|
||||
use crate::chat_canvas_tools::execute_chat_tool;
|
||||
use op_web_daemon::chat_canvas_tools::execute_chat_tool;
|
||||
|
||||
// Turn launch + provider routing (split out at the 800-line cap).
|
||||
// `launch_if_pending` and friends live in the sibling file; the
|
||||
|
|
@ -64,7 +64,7 @@ fn drain_tool_requests(state: &mut EditorState, session: &mut ChatSession) -> bo
|
|||
.and_then(|v| v.get("nodes").and_then(|n| n.as_array().cloned()))
|
||||
.unwrap_or_default();
|
||||
let (count, mutated) =
|
||||
crate::chat_canvas_tools::apply_design_modification(state, &nodes);
|
||||
op_web_daemon::chat_canvas_tools::apply_design_modification(state, &nodes);
|
||||
if mutated {
|
||||
changed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use op_orchestrator::{classify_intent, Intent};
|
|||
|
||||
use crate::chat_acp::AcpProvider;
|
||||
use crate::chat_builtin_http::ConfiguredBuiltinProvider;
|
||||
use crate::chat_canvas_tools::{chat_tool_channel, chat_tool_defs, ChatToolRequest};
|
||||
use op_web_daemon::chat_canvas_tools::{chat_tool_channel, chat_tool_defs, ChatToolRequest};
|
||||
use crate::chat_claude::ClaudeCodeProvider;
|
||||
use crate::chat_copilot::CopilotProvider;
|
||||
use crate::chat_http_server::OpenCodeProvider;
|
||||
|
|
|
|||
|
|
@ -536,7 +536,7 @@ fn pump_executes_scripted_tool_call_against_live_state() {
|
|||
.push(ChatMessage::assistant_streaming());
|
||||
let before = host.editor_state().active_children().len();
|
||||
|
||||
let (executor, tool_rx) = crate::chat_canvas_tools::chat_tool_channel();
|
||||
let (executor, tool_rx) = op_web_daemon::chat_canvas_tools::chat_tool_channel();
|
||||
let provider = Box::new(ToolLoopProvider {
|
||||
executor: std::sync::Arc::new(executor),
|
||||
tool: "insert_node",
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ mod chat_acp;
|
|||
mod chat_agent_loop;
|
||||
mod chat_attachment;
|
||||
mod chat_builtin_http;
|
||||
mod chat_canvas_tools;
|
||||
mod chat_claude;
|
||||
mod chat_copilot;
|
||||
mod chat_http_server;
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ fn stream_modify_route<W: Write>(
|
|||
.collect::<Vec<_>>();
|
||||
let (applied, version) = {
|
||||
let mut guard = state.lock().unwrap_or_else(|p| p.into_inner());
|
||||
let (count, mutated) = crate::chat_canvas_tools::apply_design_modification(
|
||||
let (count, mutated) = op_web_daemon::chat_canvas_tools::apply_design_modification(
|
||||
&mut guard.editor,
|
||||
&node_values,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
|
||||
use op_ai::chat_provider::{ChatToolDef, ChatToolResult};
|
||||
use op_editor_core::EditorState;
|
||||
pub(crate) use op_editor_host_core::chat::{
|
||||
pub use op_editor_host_core::chat::{
|
||||
chat_tool_channel, ChatToolRequest, UiChatToolExecutor,
|
||||
};
|
||||
use op_mcp::{ToolRegistry, ToolResponse};
|
||||
|
||||
/// TS `maxTurns` for the chat agent loop (`ai-chat-handlers.ts:254`).
|
||||
pub(crate) const MAX_TOOL_TURNS: usize = 20;
|
||||
pub const MAX_TOOL_TURNS: usize = 20;
|
||||
|
||||
/// The chat tool subset — the TS CRUD set (`getCrudToolDefs`) with the
|
||||
/// TS `TOOL_AUTH_MAP` auth levels. Design-pipeline tools
|
||||
|
|
@ -42,7 +42,7 @@ const CHAT_TOOLS: &[(&str, &str)] = &[
|
|||
];
|
||||
|
||||
/// Auth level for a chat tool name (`None` = not in the chat set).
|
||||
pub(crate) fn chat_tool_level(name: &str) -> Option<&'static str> {
|
||||
pub fn chat_tool_level(name: &str) -> Option<&'static str> {
|
||||
CHAT_TOOLS
|
||||
.iter()
|
||||
.find(|(tool, _)| *tool == name)
|
||||
|
|
@ -53,7 +53,7 @@ pub(crate) fn chat_tool_level(name: &str) -> Option<&'static str> {
|
|||
/// Descriptions follow the TS `getCrudToolDefs` text; schemas match
|
||||
/// the Rust `op_mcp` tools' argument surface (the executor dispatches
|
||||
/// into those tools verbatim).
|
||||
pub(crate) fn chat_tool_defs() -> Vec<ChatToolDef> {
|
||||
pub fn chat_tool_defs() -> Vec<ChatToolDef> {
|
||||
let def = |name: &str, description: &str, schema: &str| ChatToolDef {
|
||||
name: name.to_string(),
|
||||
description: description.to_string(),
|
||||
|
|
@ -108,7 +108,7 @@ pub(crate) fn chat_tool_defs() -> Vec<ChatToolDef> {
|
|||
/// dispatch through the wire parser's argument discipline, then apply
|
||||
/// any returned `EditorCommand` via `EditorState::apply` — the same
|
||||
/// pre-validate-then-mutate path the MCP server uses.
|
||||
pub(crate) fn execute_chat_tool(
|
||||
pub fn execute_chat_tool(
|
||||
state: &mut EditorState,
|
||||
name: &str,
|
||||
args_json: &str,
|
||||
|
|
@ -197,7 +197,7 @@ fn error_result(message: String) -> ChatToolResult {
|
|||
/// here every node is its own undo step — the same granularity the
|
||||
/// Rust design pipeline has until host batch mode lands
|
||||
/// (design_session.rs `BeginUndoBatch` TODO).
|
||||
pub(crate) fn apply_design_modification(
|
||||
pub fn apply_design_modification(
|
||||
state: &mut EditorState,
|
||||
nodes: &[serde_json::Value],
|
||||
) -> (usize, bool) {
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
//! `op-host-web-server` binary depend on this crate.
|
||||
|
||||
// Phase 2 — host-free leaf modules.
|
||||
pub mod chat_canvas_tools;
|
||||
pub mod chat_spawn;
|
||||
pub mod chat_subprocess_quirks;
|
||||
pub mod web_static;
|
||||
|
|
|
|||
Loading…
Reference in a new issue