initial tool call stream
This commit is contained in:
parent
2b5a33e476
commit
2de5127417
11 changed files with 261 additions and 136 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue