MCPcopy Create free account
hub / github.com/enowdev/enowX-Coder / parse_anthropic_non_stream_response

Function parse_anthropic_non_stream_response

src-tauri/src/agents/runner.rs:1644–1683  ·  view source on GitHub ↗

Parse a non-streaming Anthropic Messages API response into an `LLMTurn`. Used as a fallback when the gateway returns an empty stream (some proxies don't support streaming for certain models).

(
    body: &Value,
    agent_run_id: &str,
    token_sink: &S,
    app_handle: &tauri::AppHandle,
)

Source from the content-addressed store, hash-verified

1642/// Used as a fallback when the gateway returns an empty stream (some proxies
1643/// don't support streaming for certain models).
1644fn parse_anthropic_non_stream_response<S: TokenSink + Sync>(
1645 body: &Value,
1646 agent_run_id: &str,
1647 token_sink: &S,
1648 app_handle: &tauri::AppHandle,
1649) -> AppResult<LLMTurn> {
1650 let mut text = String::new();
1651 let mut tool_calls = Vec::new();
1652
1653 if let Some(content) = body.get("content").and_then(Value::as_array) {
1654 for block in content {
1655 let block_type = block.get("type").and_then(Value::as_str).unwrap_or("");
1656 match block_type {
1657 "text" => {
1658 if let Some(t) = block.get("text").and_then(Value::as_str) {
1659 text.push_str(t);
1660 // Send tokens to UI so the user sees the response
1661 token_sink.send(t);
1662 let _ = app_handle.emit(
1663 "agent-token",
1664 AgentTokenEvent {
1665 agent_run_id: agent_run_id.to_string(),
1666 token: t.to_string(),
1667 },
1668 );
1669 }
1670 }
1671 "tool_use" => {
1672 let id = block.get("id").and_then(Value::as_str).unwrap_or("").to_string();
1673 let name = block.get("name").and_then(Value::as_str).unwrap_or("").to_string();
1674 let input = block.get("input").cloned().unwrap_or(Value::Object(Default::default()));
1675 tool_calls.push(ParsedToolCall { id, name, input });
1676 }
1677 _ => {}
1678 }
1679 }
1680 }
1681
1682 Ok(LLMTurn { text, tool_calls })
1683}
1684
1685#[derive(Debug, Clone)]
1686struct ToolExecutionOutcome {

Callers 1

Calls 1

sendMethod · 0.80

Tested by

no test coverage detected