diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-19 16:35:45 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-21 13:42:29 +0200 |
| commit | 2de51274177432b559be3b7deb1f14b9539f2994 (patch) | |
| tree | d47fff06ebf662f6bd7f594c78d0ae97e203a493 /internal/message/content.go | |
| parent | 2b5a33e476ae3c6b5c6345777d20792786836dda (diff) | |
| download | opencode-2de51274177432b559be3b7deb1f14b9539f2994.tar.gz opencode-2de51274177432b559be3b7deb1f14b9539f2994.zip | |
initial tool call stream
Diffstat (limited to 'internal/message/content.go')
| -rw-r--r-- | internal/message/content.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/message/content.go b/internal/message/content.go index f52449f4a..beebe354e 100644 --- a/internal/message/content.go +++ b/internal/message/content.go @@ -233,6 +233,40 @@ func (m *Message) AppendReasoningContent(delta string) { } } +func (m *Message) FinishToolCall(toolCallID string) { + for i, part := range m.Parts { + if c, ok := part.(ToolCall); ok { + if c.ID == toolCallID { + m.Parts[i] = ToolCall{ + ID: c.ID, + Name: c.Name, + Input: c.Input, + Type: c.Type, + Finished: true, + } + return + } + } + } +} + +func (m *Message) AppendToolCallInput(toolCallID string, inputDelta string) { + for i, part := range m.Parts { + if c, ok := part.(ToolCall); ok { + if c.ID == toolCallID { + m.Parts[i] = ToolCall{ + ID: c.ID, + Name: c.Name, + Input: c.Input + inputDelta, + Type: c.Type, + Finished: c.Finished, + } + return + } + } + } +} + func (m *Message) AddToolCall(tc ToolCall) { for i, part := range m.Parts { if c, ok := part.(ToolCall); ok { @@ -246,6 +280,15 @@ func (m *Message) AddToolCall(tc ToolCall) { } func (m *Message) SetToolCalls(tc []ToolCall) { + // remove any existing tool call part it could have multiple + parts := make([]ContentPart, 0) + for _, part := range m.Parts { + if _, ok := part.(ToolCall); ok { + continue + } + parts = append(parts, part) + } + m.Parts = parts for _, toolCall := range tc { m.Parts = append(m.Parts, toolCall) } |
