( ctx context.Context, parentChatID uuid.UUID, targetChatID uuid.UUID, )
| 1380 | } |
| 1381 | |
| 1382 | func (p *Server) closeSubagent( |
| 1383 | ctx context.Context, |
| 1384 | parentChatID uuid.UUID, |
| 1385 | targetChatID uuid.UUID, |
| 1386 | ) (database.Chat, error) { |
| 1387 | isDescendant, err := isSubagentDescendant(ctx, p.db, parentChatID, targetChatID) |
| 1388 | if err != nil { |
| 1389 | return database.Chat{}, err |
| 1390 | } |
| 1391 | if !isDescendant { |
| 1392 | return database.Chat{}, ErrSubagentNotDescendant |
| 1393 | } |
| 1394 | |
| 1395 | targetChat, err := p.db.GetChatByID(ctx, targetChatID) |
| 1396 | if err != nil { |
| 1397 | return database.Chat{}, xerrors.Errorf("get target chat: %w", err) |
| 1398 | } |
| 1399 | |
| 1400 | if targetChat.Status == database.ChatStatusWaiting { |
| 1401 | return targetChat, nil |
| 1402 | } |
| 1403 | |
| 1404 | updatedChat := p.InterruptChat(ctx, targetChat) |
| 1405 | if updatedChat.Status != database.ChatStatusWaiting { |
| 1406 | return database.Chat{}, xerrors.New("set target chat waiting") |
| 1407 | } |
| 1408 | return updatedChat, nil |
| 1409 | } |
| 1410 | |
| 1411 | func (p *Server) checkSubagentCompletion( |
| 1412 | ctx context.Context, |
no test coverage detected