mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-15 20:15:48 +00:00
fix(teams): persist leader media as DB attachments on task creation
Leader-created tasks copied media files to workspace and stored paths in task metadata, but never inserted into team_task_attachments table. Members got auto-attached via WorkspaceInterceptor context, but leaders don't run inside a task context. Now explicitly call AttachFileToTask after CreateTask succeeds. Dedup handled by ON CONFLICT DO NOTHING.
This commit is contained in:
1 parent
5e936ebf8f
commit
07f43cad36
1 file changed
+30
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -234,6 +235,35 @@ func (t *TeamTasksTool) executeCreate(ctx context.Context, args map[string]any)
|
||||
return ErrorResult("failed to create task: " + err.Error())
|
||||
}
|
||||
|
||||
// Persist media files copied during task creation as DB attachments,
|
||||
// so the UI and queries see them in team_task_attachments table.
|
||||
// (Members get auto-attached via WorkspaceInterceptor, but leaders
|
||||
// don't run inside a task context — handle explicitly here.)
|
||||
if files, ok := taskMeta["attached_files"].([]any); ok {
|
||||
for _, f := range files {
|
||||
filePath, ok := f.(string)
|
||||
if !ok || filePath == "" {
|
||||
continue
|
||||
}
|
||||
var fileSize int64
|
||||
if info, err := os.Stat(filePath); err == nil {
|
||||
fileSize = info.Size()
|
||||
}
|
||||
att := &store.TeamTaskAttachmentData{
|
||||
TaskID: task.ID,
|
||||
TeamID: team.ID,
|
||||
ChatID: chatID,
|
||||
Path: filePath,
|
||||
FileSize: fileSize,
|
||||
MimeType: mimeFromExt(filepath.Ext(filePath)),
|
||||
CreatedByAgentID: &agentID,
|
||||
}
|
||||
if err := t.manager.teamStore.AttachFileToTask(ctx, att); err != nil {
|
||||
slog.Warn("executeCreate: auto-attach media failed", "task_id", task.ID, "path", filePath, "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
agentKey := t.manager.agentKeyFromID(ctx, agentID)
|
||||
t.manager.broadcastTeamEvent(ctx, protocol.EventTeamTaskCreated, protocol.TeamTaskEventPayload{
|
||||
TeamID: team.ID.String(),
|
||||
|
||||
Reference in new issue
Block a user