( ctx context.Context, ownerID uuid.UUID, provider database.AIProvider, )
| 8712 | } |
| 8713 | |
| 8714 | func (p *Server) resolveUserProviderAPIKeysForProvider( |
| 8715 | ctx context.Context, |
| 8716 | ownerID uuid.UUID, |
| 8717 | provider database.AIProvider, |
| 8718 | ) (chatprovider.ProviderAPIKeys, error) { |
| 8719 | configuredProvider, err := p.aiProviderConfig(ctx, provider) |
| 8720 | if err != nil { |
| 8721 | return chatprovider.ProviderAPIKeys{}, err |
| 8722 | } |
| 8723 | userKeys := []chatprovider.UserProviderKey{} |
| 8724 | if p.allowBYOK { |
| 8725 | userKey, err := p.db.GetUserAIProviderKeyByProviderID(ctx, database.GetUserAIProviderKeyByProviderIDParams{ |
| 8726 | UserID: ownerID, |
| 8727 | AIProviderID: provider.ID, |
| 8728 | }) |
| 8729 | if err != nil && !xerrors.Is(err, sql.ErrNoRows) { |
| 8730 | return chatprovider.ProviderAPIKeys{}, xerrors.Errorf("get user AI provider key: %w", err) |
| 8731 | } |
| 8732 | if err == nil { |
| 8733 | userKeys = append(userKeys, chatprovider.UserProviderKey{ |
| 8734 | ChatProviderID: userKey.AIProviderID, |
| 8735 | APIKey: userKey.APIKey, |
| 8736 | }) |
| 8737 | } |
| 8738 | } |
| 8739 | keys, _ := chatprovider.ResolveUserProviderKeys( |
| 8740 | chatprovider.ProviderAPIKeys{}, |
| 8741 | []chatprovider.ConfiguredProvider{configuredProvider}, |
| 8742 | userKeys, |
| 8743 | ) |
| 8744 | return keys, nil |
| 8745 | } |
| 8746 | |
| 8747 | func (p *Server) resolveUserProviderAPIKeysForProviderType( |
| 8748 | ctx context.Context, |
no test coverage detected