11import { db } from '@sim/db'
22import { account , mcpServers } from '@sim/db/schema'
33import { and , eq , inArray , isNull } from 'drizzle-orm'
4- import { getApiKeyWithBYOK } from '@/lib/api-key/byok'
54import { createLogger } from '@/lib/logs/console/logger'
65import { createMcpToolId } from '@/lib/mcp/utils'
76import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
@@ -1007,23 +1006,13 @@ export class AgentBlockHandler implements BlockHandler {
10071006 responseFormat : any ,
10081007 providerStartTime : number
10091008 ) {
1010- let finalApiKey : string
1011- let isBYOK = false
1009+ let finalApiKey : string | undefined = providerRequest . apiKey
10121010
10131011 if ( providerId === 'vertex' && providerRequest . vertexCredential ) {
10141012 finalApiKey = await this . resolveVertexCredential (
10151013 providerRequest . vertexCredential ,
10161014 ctx . workflowId
10171015 )
1018- } else {
1019- const result = await this . getApiKeyWithBYOK (
1020- providerId ,
1021- model ,
1022- ctx . workspaceId ,
1023- providerRequest . apiKey
1024- )
1025- finalApiKey = result . apiKey
1026- isBYOK = result . isBYOK
10271016 }
10281017
10291018 const { blockData, blockNameMapping } = collectBlockData ( ctx )
@@ -1036,14 +1025,13 @@ export class AgentBlockHandler implements BlockHandler {
10361025 temperature : providerRequest . temperature ,
10371026 maxTokens : providerRequest . maxTokens ,
10381027 apiKey : finalApiKey ,
1039- isBYOK,
10401028 azureEndpoint : providerRequest . azureEndpoint ,
10411029 azureApiVersion : providerRequest . azureApiVersion ,
10421030 vertexProject : providerRequest . vertexProject ,
10431031 vertexLocation : providerRequest . vertexLocation ,
10441032 responseFormat : providerRequest . responseFormat ,
10451033 workflowId : providerRequest . workflowId ,
1046- workspaceId : providerRequest . workspaceId ,
1034+ workspaceId : ctx . workspaceId ,
10471035 stream : providerRequest . stream ,
10481036 messages : 'messages' in providerRequest ? providerRequest . messages : undefined ,
10491037 environmentVariables : ctx . environmentVariables || { } ,
@@ -1121,25 +1109,6 @@ export class AgentBlockHandler implements BlockHandler {
11211109 return this . createMinimalStreamingExecution ( response . body ! )
11221110 }
11231111
1124- private async getApiKeyWithBYOK (
1125- providerId : string ,
1126- model : string ,
1127- workspaceId : string | undefined ,
1128- inputApiKey ?: string
1129- ) : Promise < { apiKey : string ; isBYOK : boolean } > {
1130- try {
1131- return await getApiKeyWithBYOK ( providerId , model , workspaceId , inputApiKey )
1132- } catch ( error ) {
1133- logger . error ( 'Failed to get API key:' , {
1134- provider : providerId ,
1135- model,
1136- error : error instanceof Error ? error . message : String ( error ) ,
1137- hasProvidedApiKey : ! ! inputApiKey ,
1138- } )
1139- throw new Error ( error instanceof Error ? error . message : 'API key error' )
1140- }
1141- }
1142-
11431112 /**
11441113 * Resolves a Vertex AI OAuth credential to an access token
11451114 */
0 commit comments