| 1409 | } |
| 1410 | |
| 1411 | func (p *Server) checkSubagentCompletion( |
| 1412 | ctx context.Context, |
| 1413 | chatID uuid.UUID, |
| 1414 | ) (database.Chat, string, bool, error) { |
| 1415 | chat, err := p.db.GetChatByID(ctx, chatID) |
| 1416 | if err != nil { |
| 1417 | return database.Chat{}, "", false, xerrors.Errorf("get chat: %w", err) |
| 1418 | } |
| 1419 | |
| 1420 | if chat.Status == database.ChatStatusPending || chat.Status == database.ChatStatusRunning { |
| 1421 | return database.Chat{}, "", false, nil |
| 1422 | } |
| 1423 | |
| 1424 | report, err := latestSubagentAssistantMessage(ctx, p.db, chatID) |
| 1425 | if err != nil { |
| 1426 | return database.Chat{}, "", false, err |
| 1427 | } |
| 1428 | |
| 1429 | return chat, report, true, nil |
| 1430 | } |
| 1431 | |
| 1432 | func latestSubagentAssistantMessage( |
| 1433 | ctx context.Context, |