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

Method resolveUserProviderAPIKeysForProvider

coderd/x/chatd/chatd.go:8714–8745  ·  view source on GitHub ↗
(
	ctx context.Context,
	ownerID uuid.UUID,
	provider database.AIProvider,
)

Source from the content-addressed store, hash-verified

8712}
8713
8714func (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
8747func (p *Server) resolveUserProviderAPIKeysForProviderType(
8748 ctx context.Context,

Calls 5

aiProviderConfigMethod · 0.95
ResolveUserProviderKeysFunction · 0.92
IsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected