CreateRun inserts a new debug run and emits a run update event.
( ctx context.Context, params CreateRunParams, )
| 272 | |
| 273 | // CreateRun inserts a new debug run and emits a run update event. |
| 274 | func (s *Service) CreateRun( |
| 275 | ctx context.Context, |
| 276 | params CreateRunParams, |
| 277 | ) (database.ChatDebugRun, error) { |
| 278 | now := s.clock.Now() |
| 279 | run, err := s.db.InsertChatDebugRun(chatdContext(ctx), |
| 280 | database.InsertChatDebugRunParams{ |
| 281 | ChatID: params.ChatID, |
| 282 | RootChatID: nullUUID(params.RootChatID), |
| 283 | ParentChatID: nullUUID(params.ParentChatID), |
| 284 | ModelConfigID: nullUUID(params.ModelConfigID), |
| 285 | TriggerMessageID: nullInt64(params.TriggerMessageID), |
| 286 | HistoryTipMessageID: nullInt64(params.HistoryTipMessageID), |
| 287 | Kind: string(params.Kind), |
| 288 | Status: string(params.Status), |
| 289 | Provider: nullString(params.Provider), |
| 290 | Model: nullString(params.Model), |
| 291 | Summary: s.nullJSON(ctx, params.Summary), |
| 292 | StartedAt: sql.NullTime{Time: now, Valid: true}, |
| 293 | UpdatedAt: sql.NullTime{Time: now, Valid: true}, |
| 294 | FinishedAt: sql.NullTime{}, |
| 295 | }) |
| 296 | if err != nil { |
| 297 | return database.ChatDebugRun{}, err |
| 298 | } |
| 299 | |
| 300 | s.publishEvent(ctx, run.ChatID, EventKindRunUpdate, run.ID, uuid.Nil) |
| 301 | return run, nil |
| 302 | } |
| 303 | |
| 304 | // UpdateRun updates an existing debug run and emits a run update event. |
| 305 | // When a terminal status is set without an explicit FinishedAt, the |