Changeset 0.37.18 (#230)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -963,6 +963,9 @@ func (h *CompletionHandler) streamCompletion(
|
||||
log.Printf("Failed to persist assistant message: %v", err)
|
||||
}
|
||||
|
||||
// Record tool_output file refs (v0.37.18)
|
||||
h.recordToolFileRefs(c.Request.Context(), result.FileRefs, channelID, userID, asstMsgID)
|
||||
|
||||
// Broadcast assistant message to other channel participants
|
||||
if h.hub != nil && asstMsgID != "" {
|
||||
broadcastAssistantMessage(c.Request.Context(), h.hub, channelID, asstMsgID, result.Content, model, userID, personaID)
|
||||
@@ -1049,10 +1052,14 @@ func (h *CompletionHandler) syncCompletion(
|
||||
finalContent := result.Content
|
||||
|
||||
// Persist assistant response
|
||||
if _, err := h.persistMessage(channelID, userID, "assistant", finalContent, model, result.InputTokens, result.OutputTokens, nil, toolActivityJSON(result.ToolActivity), configID, personaID); err != nil {
|
||||
syncAsstMsgID, err := h.persistMessage(channelID, userID, "assistant", finalContent, model, result.InputTokens, result.OutputTokens, nil, toolActivityJSON(result.ToolActivity), configID, personaID)
|
||||
if err != nil {
|
||||
log.Printf("Failed to persist assistant message: %v", err)
|
||||
}
|
||||
|
||||
// Record tool_output file refs (v0.37.18)
|
||||
h.recordToolFileRefs(c.Request.Context(), result.FileRefs, channelID, userID, syncAsstMsgID)
|
||||
|
||||
// AI-to-AI chaining
|
||||
go func() {
|
||||
defer func() {
|
||||
@@ -1770,6 +1777,31 @@ func (h *CompletionHandler) loadConversation(channelID, userID, personaSystemPro
|
||||
|
||||
// ── Message Persistence ─────────────────────
|
||||
|
||||
// recordToolFileRefs creates file records with origin=tool_output for workspace
|
||||
// files produced by tools during a completion. Links each file to the assistant
|
||||
// message so the UI can show "files generated by this response".
|
||||
func (h *CompletionHandler) recordToolFileRefs(ctx context.Context, refs []FileRef, channelID, userID, asstMsgID string) {
|
||||
if len(refs) == 0 || asstMsgID == "" {
|
||||
return
|
||||
}
|
||||
for _, ref := range refs {
|
||||
f := &models.File{
|
||||
ChannelID: channelID,
|
||||
UserID: userID,
|
||||
Origin: models.FileOriginToolOutput,
|
||||
Filename: ref.Path,
|
||||
ContentType: "application/octet-stream",
|
||||
DisplayHint: "download",
|
||||
}
|
||||
if asstMsgID != "" {
|
||||
f.MessageID = &asstMsgID
|
||||
}
|
||||
if err := h.stores.Files.Create(ctx, f); err != nil {
|
||||
log.Printf("[file_ref] Failed to record tool_output file ref %s: %v", ref.Path, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// persistMessage inserts a message into the tree, updates the cursor, and
|
||||
// returns the new message's ID.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user