stopAndStoreRecording stops the desktop recording, downloads the multipart response containing the MP4 and optional thumbnail, and stores them in chat_files. Only called when the subagent completed successfully. Returns file IDs on success, empty fields on any failure. All errors are logged but not
( ctx context.Context, conn workspacesdk.AgentConn, recordingID string, parentChatID uuid.UUID, ownerID uuid.UUID, workspaceID uuid.NullUUID, )
| 30 | // failure. All errors are logged but not propagated; recording is |
| 31 | // best-effort. |
| 32 | func (p *Server) stopAndStoreRecording( |
| 33 | ctx context.Context, |
| 34 | conn workspacesdk.AgentConn, |
| 35 | recordingID string, |
| 36 | parentChatID uuid.UUID, |
| 37 | ownerID uuid.UUID, |
| 38 | workspaceID uuid.NullUUID, |
| 39 | ) recordingResult { |
| 40 | var result recordingResult |
| 41 | |
| 42 | workspaceIDValue := "" |
| 43 | if workspaceID.Valid { |
| 44 | workspaceIDValue = workspaceID.UUID.String() |
| 45 | } |
| 46 | recordingWarnFields := []slog.Field{ |
| 47 | slog.F("recording_id", recordingID), |
| 48 | slog.F("parent_chat_id", parentChatID.String()), |
| 49 | slog.F("workspace_id", workspaceIDValue), |
| 50 | } |
| 51 | warn := func(msg string, fields ...slog.Field) { |
| 52 | allFields := make([]slog.Field, 0, len(recordingWarnFields)+len(fields)) |
| 53 | allFields = append(allFields, recordingWarnFields...) |
| 54 | allFields = append(allFields, fields...) |
| 55 | p.logger.Warn(ctx, msg, allFields...) |
| 56 | } |
| 57 | |
| 58 | select { |
| 59 | case p.recordingSem <- struct{}{}: |
| 60 | defer func() { <-p.recordingSem }() |
| 61 | case <-ctx.Done(): |
| 62 | warn("context canceled waiting for recording semaphore", slog.Error(ctx.Err())) |
| 63 | return result |
| 64 | } |
| 65 | |
| 66 | resp, err := conn.StopDesktopRecording(ctx, |
| 67 | workspacesdk.StopDesktopRecordingRequest{RecordingID: recordingID}) |
| 68 | if err != nil { |
| 69 | warn("failed to stop desktop recording", |
| 70 | slog.Error(err)) |
| 71 | return result |
| 72 | } |
| 73 | defer resp.Body.Close() |
| 74 | |
| 75 | _, params, err := mime.ParseMediaType(resp.ContentType) |
| 76 | if err != nil { |
| 77 | warn("failed to parse content type from recording response", |
| 78 | slog.F("content_type", resp.ContentType), |
| 79 | slog.Error(err)) |
| 80 | return result |
| 81 | } |
| 82 | boundary := params["boundary"] |
| 83 | if boundary == "" { |
| 84 | warn("missing boundary in recording response content type", |
| 85 | slog.F("content_type", resp.ContentType)) |
| 86 | return result |
| 87 | } |
| 88 | |
| 89 | if !workspaceID.Valid { |