Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
use super::AnthropicToolContext;
use crate::types::request::CODE_EXECUTION_TOOL;
use crate::types::response::ResponseContentKind;
use crate::types::response::code_execution::TextEditorCodeExecutionResponse;
use ai_toolset::{AsyncTool, RequestContext, ServiceContext, ToolCallError, ToolResult};
use ai_toolset::{ToolAnnotated, ToolAnnotations};
use async_trait::async_trait;
use schemars::JsonSchema;
use serde::Deserialize;
/// Use Claude's built-in text editor in a sandboxed code execution environment.
#[derive(Deserialize, JsonSchema, Clone)]
#[schemars(
title = "TextEditorCodeExecution",
description = "Use a text editor in a sandboxed environment using Claude's built-in code execution tool. Its files live only in the sandbox: to create a document or file for the user, use CreateDocument."
)]
pub struct TextEditorCodeExecution {
/// The text editing instruction.
pub input: String,
}
impl ToolAnnotated for TextEditorCodeExecution {
const ANNOTATIONS: ToolAnnotations =
ToolAnnotations::destructive("Edit file in sandbox").with_open_world();
}
#[async_trait]
impl AsyncTool<AnthropicToolContext> for TextEditorCodeExecution {
type Output = TextEditorCodeExecutionResponse;
#[tracing::instrument(skip_all, err)]
async fn call(
&self,
service_context: ServiceContext<AnthropicToolContext>,
request_context: RequestContext,
) -> ToolResult<Self::Output> {
let ctx = &*service_context;
let blocks = super::invoke_server_tool(
ctx,
&request_context,
CODE_EXECUTION_TOOL.clone(),
&self.input,
)
.await?;
blocks
.into_iter()
.find_map(|b| match b {
ResponseContentKind::TextEditorCodeExecutionToolResult(r) => Some(r),
_ => None,
})
.ok_or_else(|| ToolCallError {
internal_error: anyhow::anyhow!("no text editor code execution result in response"),
description: "No text editor code execution result returned".into(),
})
}
}