MCPcopy Index your code
hub / github.com/coder/coder / populatedAndConvertAIBridgeInterceptions

Function populatedAndConvertAIBridgeInterceptions

enterprise/coderd/aibridge.go:653–702  ·  view source on GitHub ↗
(ctx context.Context, db database.Store, dbInterceptions []database.ListAIBridgeInterceptionsRow)

Source from the content-addressed store, hash-verified

651}
652
653func 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

Callers 1

Tested by

no test coverage detected