Something went wrong. Try again.
MCP based ACP agent
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171"""Constructors for ACP v1 wire types.
Upstream deleted ``acp.helpers`` in python-sdk ``713cbc1`` ("remove schema helperAPI"): the position is that applications should build the pydantic modelsdirectly. These are the ten constructors crow actually uses, vendored verbatimso the v1 surface keeps working while ``acp.experimental.v2`` is developedagainst the same install.
v2 renames most of these types (``ToolCallStart``/``ToolCallProgress`` collapseinto one upsert ``SessionToolCallUpdate``, chunks gain a required ``messageId``),so nothing here is reusable on the v2 path -- it exists to keep v1 alive."""
from __future__ import annotations
from collections.abc import Sequencefrom typing import Any
from acp.schema import ( AgentMessageChunk, AgentThoughtChunk, ContentToolCallContent, FileEditToolCallContent, ImageContentBlock, TerminalToolCallContent, TextContentBlock, ToolCallLocation, ToolCallProgress, ToolCallStart, ToolCallStatus, ToolKind,)
__all__ = [ "image_block", "start_edit_tool_call", "start_read_tool_call", "start_tool_call", "text_block", "tool_content", "tool_diff_content", "tool_terminal_ref", "update_agent_message", "update_agent_thought", "update_tool_call",]
ContentBlock = TextContentBlock | ImageContentBlockToolCallContentVariant = ContentToolCallContent | FileEditToolCallContent | TerminalToolCallContent
def text_block(text: str) -> TextContentBlock: return TextContentBlock(type="text", text=text)
def image_block(data: str, mime_type: str, *, uri: str | None = None) -> ImageContentBlock: return ImageContentBlock(type="image", data=data, mime_type=mime_type, uri=uri)
def tool_content(block: ContentBlock) -> ContentToolCallContent: return ContentToolCallContent(type="content", content=block)
def tool_diff_content(path: str, new_text: str, old_text: str | None = None) -> FileEditToolCallContent: return FileEditToolCallContent(type="diff", path=path, new_text=new_text, old_text=old_text)
def tool_terminal_ref(terminal_id: str) -> TerminalToolCallContent: return TerminalToolCallContent(type="terminal", terminal_id=terminal_id)
def update_agent_message(content: ContentBlock) -> AgentMessageChunk: return AgentMessageChunk(session_update="agent_message_chunk", content=content)
def update_agent_thought(content: ContentBlock) -> AgentThoughtChunk: return AgentThoughtChunk(session_update="agent_thought_chunk", content=content)
def start_tool_call( tool_call_id: str, title: str, *, name: str | None = None, kind: ToolKind | None = None, status: ToolCallStatus | None = None, content: Sequence[ToolCallContentVariant] | None = None, locations: Sequence[ToolCallLocation] | None = None, raw_input: Any | None = None, raw_output: Any | None = None,) -> ToolCallStart: return ToolCallStart( session_update="tool_call", tool_call_id=tool_call_id, title=title, name=name, kind=kind, status=status, content=list(content) if content is not None else None, locations=list(locations) if locations is not None else None, raw_input=raw_input, raw_output=raw_output, )
def start_read_tool_call( tool_call_id: str, title: str, path: str, *, name: str | None = None, extra_options: Sequence[ToolCallContentVariant] | None = None,) -> ToolCallStart: return start_tool_call( tool_call_id, title, name=name, kind="read", status="pending", content=list(extra_options) if extra_options is not None else None, locations=[ToolCallLocation(path=path)], raw_input={"path": path}, )
def start_edit_tool_call( tool_call_id: str, title: str, path: str, content: Any, *, name: str | None = None, extra_options: Sequence[ToolCallContentVariant] | None = None,) -> ToolCallStart: return start_tool_call( tool_call_id, title, name=name, kind="edit", status="pending", content=list(extra_options) if extra_options is not None else None, locations=[ToolCallLocation(path=path)], raw_input={"path": path, "content": content}, )
def update_tool_call( tool_call_id: str, *, title: str | None = None, name: str | None = None, kind: ToolKind | None = None, status: ToolCallStatus | None = None, content: Sequence[ToolCallContentVariant] | None = None, locations: Sequence[ToolCallLocation] | None = None, raw_input: Any | None = None, raw_output: Any | None = None,) -> ToolCallProgress: return ToolCallProgress( session_update="tool_call_update", tool_call_id=tool_call_id, title=title, name=name, kind=kind, status=status, content=list(content) if content is not None else None, locations=list(locations) if locations is not None else None, raw_input=raw_input, raw_output=raw_output, )