(ctx context.Context, db database.Store, dbInterceptions []database.ListAIBridgeInterceptionsRow)
| 651 | } |
| 652 | |
| 653 | func populatedAndConvertAIBridgeInterceptions(ctx context.Context, db database.Store, dbInterceptions []database.ListAIBridgeInterceptionsRow) ([]codersdk.AIBridgeInterception, error) { |
| 654 | if len(dbInterceptions) == 0 { |
| 655 | return []codersdk.AIBridgeInterception{}, nil |
| 656 | } |
| 657 | |
| 658 | ids := make([]uuid.UUID, len(dbInterceptions)) |
| 659 | for i, row := range dbInterceptions { |
| 660 | ids[i] = row.AIBridgeInterception.ID |
| 661 | } |
| 662 | |
| 663 | tokenUsagesRows, err := db.ListAIBridgeTokenUsagesByInterceptionIDs(ctx, ids) |
| 664 | if err != nil { |
| 665 | return nil, xerrors.Errorf("get linked aibridge token usages from database: %w", err) |
| 666 | } |
| 667 | tokenUsagesMap := make(map[uuid.UUID][]database.AIBridgeTokenUsage, len(dbInterceptions)) |
| 668 | for _, row := range tokenUsagesRows { |
| 669 | tokenUsagesMap[row.InterceptionID] = append(tokenUsagesMap[row.InterceptionID], row) |
| 670 | } |
| 671 | |
| 672 | userPromptRows, err := db.ListAIBridgeUserPromptsByInterceptionIDs(ctx, ids) |
| 673 | if err != nil { |
| 674 | return nil, xerrors.Errorf("get linked aibridge user prompts from database: %w", err) |
| 675 | } |
| 676 | userPromptsMap := make(map[uuid.UUID][]database.AIBridgeUserPrompt, len(dbInterceptions)) |
| 677 | for _, row := range userPromptRows { |
| 678 | userPromptsMap[row.InterceptionID] = append(userPromptsMap[row.InterceptionID], row) |
| 679 | } |
| 680 | |
| 681 | toolUsagesRows, err := db.ListAIBridgeToolUsagesByInterceptionIDs(ctx, ids) |
| 682 | if err != nil { |
| 683 | return nil, xerrors.Errorf("get linked aibridge tool usages from database: %w", err) |
| 684 | } |
| 685 | toolUsagesMap := make(map[uuid.UUID][]database.AIBridgeToolUsage, len(dbInterceptions)) |
| 686 | for _, row := range toolUsagesRows { |
| 687 | toolUsagesMap[row.InterceptionID] = append(toolUsagesMap[row.InterceptionID], row) |
| 688 | } |
| 689 | |
| 690 | items := make([]codersdk.AIBridgeInterception, len(dbInterceptions)) |
| 691 | for i, row := range dbInterceptions { |
| 692 | items[i] = db2sdk.AIBridgeInterception( |
| 693 | row.AIBridgeInterception, |
| 694 | row.VisibleUser, |
| 695 | tokenUsagesMap[row.AIBridgeInterception.ID], |
| 696 | userPromptsMap[row.AIBridgeInterception.ID], |
| 697 | toolUsagesMap[row.AIBridgeInterception.ID], |
| 698 | ) |
| 699 | } |
| 700 | |
| 701 | return items, nil |
| 702 | } |
| 703 | |
| 704 | // @Summary Get group AI budget |
| 705 | // @ID get-group-ai-budget |
no test coverage detected