RegenerateChatTitle regenerates a chat title from the chat's visible messages, persists it when it changes, and broadcasts the update.
( ctx context.Context, chat database.Chat, )
| 3043 | // RegenerateChatTitle regenerates a chat title from the chat's visible |
| 3044 | // messages, persists it when it changes, and broadcasts the update. |
| 3045 | func (p *Server) RegenerateChatTitle( |
| 3046 | ctx context.Context, |
| 3047 | chat database.Chat, |
| 3048 | ) (database.Chat, error) { |
| 3049 | // Reuse chatd's scoped auth context for deployment-config lookups while |
| 3050 | // keeping chat ownership authorization at the HTTP layer. |
| 3051 | //nolint:gocritic // Non-admin users need chatd-scoped config reads here. |
| 3052 | chatdCtx := dbauthz.AsChatd(ctx) |
| 3053 | keys, err := p.resolveUserProviderAPIKeys(chatdCtx, chat.OwnerID, uuid.Nil) |
| 3054 | if err != nil { |
| 3055 | keys = chatprovider.ProviderAPIKeys{} |
| 3056 | } |
| 3057 | if err := p.acquireManualTitleLock(ctx, chat.ID); err != nil { |
| 3058 | return database.Chat{}, err |
| 3059 | } |
| 3060 | defer p.releaseManualTitleLock(chatdCtx, chat.ID) |
| 3061 | |
| 3062 | updatedChat, err := p.regenerateChatTitleWithStore( |
| 3063 | chatdCtx, |
| 3064 | p.db, |
| 3065 | chat, |
| 3066 | keys, |
| 3067 | ) |
| 3068 | if err != nil { |
| 3069 | return database.Chat{}, p.recordManualTitleGenerationFailure(ctx, chat, err) |
| 3070 | } |
| 3071 | return updatedChat, nil |
| 3072 | } |
| 3073 | |
| 3074 | // RenameChatTitle persists a user-supplied chat title. |
| 3075 | func (p *Server) RenameChatTitle( |