mirror of
https://github.com/wavetermdev/waveterm
synced 2026-04-21 22:47:16 +00:00
This updates `pkg/aiusechat/anthropic` from partial implementation to
full backend parity for core tool-use orchestration and stream behavior.
The main gaps were unimplemented tool lifecycle methods, missing
persisted tool-use UI state, and weaker disconnect/error handling versus
the OpenAI backend.
- **Tool-use lifecycle parity (critical path)**
- Implemented Anthropic backend support for:
- `UpdateToolUseData`
- `RemoveToolUseCall`
- `GetFunctionCallInputByToolCallId`
- Wired `pkg/aiusechat/usechat-backend.go` to call Anthropic
implementations instead of stubs.
- Added Anthropic run-step nil-message guard so `nil` responses are not
wrapped into `[]GenAIMessage{nil}`.
- **Persisted tool-use state in Anthropic native messages**
- Added internal `ToolUseData` storage on Anthropic `tool_use` blocks.
- Ensured internal-only fields are stripped before API requests via
`Clean()`.
- **UI conversion parity for reloaded history**
- Extended `ConvertToUIMessage()` to emit `data-tooluse` parts when
tool-use metadata exists, in addition to `tool-{name}` parts.
- **Streaming UX parity for tool argument deltas**
- Added `aiutil.SendToolProgress(...)` calls during:
- `input_json_delta` (incremental updates)
- `content_block_stop` for `tool_use` (final update)
- **Disconnect/stream robustness**
- Added `sse.Err()` checks in event handling and decode-error path.
- Added partial-text extraction on client disconnect and deterministic
ordering of partial blocks.
- Cleans up completed blocks from in-flight state to avoid duplicate
partial extraction.
- **Correctness + hygiene alignment**
- Continuation model checks now use `AreModelsCompatible(...)` (instead
of strict string equality).
- Added hostname sanitization in Anthropic error paths (HTTP error
parsing and `httpClient.Do` failures).
- Replaced unconditional Anthropic debug `log.Printf` calls with
`logutil.DevPrintf`.
- **Targeted coverage additions**
- Added Anthropic tests for:
- function-call lookup by tool call id
- tool-use data update + removal
- `data-tooluse` UI conversion behavior
```go
// usechat-backend.go
func (b *anthropicBackend) RunChatStep(...) (..., []uctypes.GenAIMessage, ...) {
stopReason, msg, rateLimitInfo, err := anthropic.RunAnthropicChatStep(ctx, sseHandler, chatOpts, cont)
if msg == nil {
return stopReason, nil, rateLimitInfo, err
}
return stopReason, []uctypes.GenAIMessage{msg}, rateLimitInfo, err
}
```
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/wavetermdev/waveterm/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Co-authored-by: sawka <mike@commandline.dev>
|
||
|---|---|---|
| .. | ||
| aiutil | ||
| anthropic | ||
| chatstore | ||
| gemini | ||
| openai | ||
| openaichat | ||
| uctypes | ||
| toolapproval.go | ||
| tools.go | ||
| tools_builder.go | ||
| tools_readdir.go | ||
| tools_readdir_test.go | ||
| tools_readfile.go | ||
| tools_screenshot.go | ||
| tools_term.go | ||
| tools_tsunami.go | ||
| tools_web.go | ||
| tools_writefile.go | ||
| usechat-backend.go | ||
| usechat-mode.go | ||
| usechat-prompts.go | ||
| usechat-utils.go | ||
| usechat.go | ||
| usechat_mode_test.go | ||