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 | |
| parent | 2b5a33e476ae3c6b5c6345777d20792786836dda (diff) | |
| download | opencode-2de51274177432b559be3b7deb1f14b9539f2994.tar.gz opencode-2de51274177432b559be3b7deb1f14b9539f2994.zip | |
initial tool call stream
Diffstat (limited to 'internal/message')
| -rw-r--r-- | internal/message/content.go | 43 | ||||
| -rw-r--r-- | internal/message/message.go | 2 |
2 files changed, 45 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) } diff --git a/internal/message/message.go b/internal/message/message.go index f165fcfc7..20ace7b41 100644 --- a/internal/message/message.go +++ b/internal/message/message.go @@ -5,6 +5,7 @@ import ( "database/sql" "encoding/json" "fmt" + "time" "github.com/google/uuid" "github.com/kujtimiihoxha/opencode/internal/db" @@ -116,6 +117,7 @@ func (s *service) Update(ctx context.Context, message Message) error { if err != nil { return err } + message.UpdatedAt = time.Now().Unix() s.Publish(pubsub.UpdatedEvent, message) return nil } |
