From d8ac5c11eb950060e6b29bec525f35d8e656851b Mon Sep 17 00:00:00 2001 From: Gerard Clos Date: Wed, 18 Sep 2024 11:14:09 +0200 Subject: [PATCH] feature: default provider api key per workspace --- apps/infra/Pulumi.core.yaml | 2 + apps/infra/src/core/secrets.ts | 10 +- apps/infra/src/deployments/shared.ts | 11 +- .../web/src/components/EditorHeader/index.tsx | 2 +- apps/web/src/services/user/setupService.ts | 14 + .../core/drizzle/0055_remarkable_slayback.sql | 2 + packages/core/drizzle/meta/0055_snapshot.json | 2212 +++++++++++++++++ packages/core/drizzle/meta/_journal.json | 7 + .../core/src/schema/models/providerApiKeys.ts | 9 +- packages/core/src/services/ai/helpers.ts | 8 +- packages/core/src/services/ai/index.ts | 4 +- packages/core/src/services/chains/run.ts | 19 +- .../commits/runDocumentAtCommit.test.ts | 8 +- .../documentLogs/addMessages/index.ts | 6 +- packages/env/src/index.ts | 6 +- 15 files changed, 2274 insertions(+), 46 deletions(-) create mode 100644 packages/core/drizzle/0055_remarkable_slayback.sql create mode 100644 packages/core/drizzle/meta/0055_snapshot.json diff --git a/apps/infra/Pulumi.core.yaml b/apps/infra/Pulumi.core.yaml index 5b6cbd6f1..6443836ee 100644 --- a/apps/infra/Pulumi.core.yaml +++ b/apps/infra/Pulumi.core.yaml @@ -4,6 +4,8 @@ config: secure: v1:WABt/tJjfsAKMplU:RRLtj5mTu301x4sn2Tr91u4O0Msd3mWVJutcDg== infra:DEFAULT_PROJECT_ID: secure: v1:M0giTdD2+Mjre0ps:YIaUlExLI41EFdcpf+6Fxec= + infra:DEFAULT_PROVIDER_API_KEY: + secure: v1:MQQUsg8lG76xgofP:ZzfbqWLvtWamnPHW7a4rX8A9f0SMaCx3jXUPZlfPbdcsPugv6ocLbdUQ75PoSzu4Xk9fPnx9Re6kKD/EoZkA2A5mX6QGgJFmJQ1E+0QDzatR3TGx1Jl2IZ2tgtUAkhreiP0T+gCBFdJ68bL0CG1D9OD5pDWa8//XgtHeXkR7j4Z1QeYtfkj2uvJJNLGUGOFprFleCnGMR8kVYeUDZfNMUIHVUh6pTuDeVBCbYF26qQT7JAEJDU2z8MGx infra:DEFAULT_PROVIDER_ID: secure: v1:N7RvQfTlIJlrU5N5:NdbEHtxvPSMIOhapDNuLVxU= infra:LATITUDE_LLM_AWS_ACCESS_KEY: diff --git a/apps/infra/src/core/secrets.ts b/apps/infra/src/core/secrets.ts index f11a3974a..2cfcbc212 100644 --- a/apps/infra/src/core/secrets.ts +++ b/apps/infra/src/core/secrets.ts @@ -58,14 +58,14 @@ const workersWebsocketsSecretToken = createSecretWithVersion( 'WORKERS_WEBSOCKET_SECRET_TOKEN', 'Secret token key for websockets in workers', ) -const defaultProviderId = createSecretWithVersion( - 'DEFAULT_PROVIDER_ID', - 'Default provider ID', -) const defaultProjectId = createSecretWithVersion( 'DEFAULT_PROJECT_ID', 'Default project ID', ) +const defaultProviderApiKey = createSecretWithVersion( + 'DEFAULT_PROVIDER_API_KEY', + 'Default provider API key', +) export const mailerApiKeyArn = mailerApiKey.arn export const sentryDsnArn = sentryDsn.arn @@ -76,5 +76,5 @@ export const awsAccessSecretArn = awsAccessSecret.arn export const websocketsSecretTokenArn = websocketsSecretToken.arn export const websocketsSecretRefreshTokenArn = websocketsSecretRefreshToken.arn export const workersWebsocketsSecretTokenArn = workersWebsocketsSecretToken.arn -export const defaultProviderIdArn = defaultProviderId.arn export const defaultProjectIdArn = defaultProjectId.arn +export const defaultProviderApiKeyArn = defaultProviderApiKey.arn diff --git a/apps/infra/src/deployments/shared.ts b/apps/infra/src/deployments/shared.ts index 16c176511..2461d29e1 100644 --- a/apps/infra/src/deployments/shared.ts +++ b/apps/infra/src/deployments/shared.ts @@ -25,8 +25,10 @@ const workersWebsocketsSecretTokenArn = coreStack.requireOutput( const sentryDsnArn = coreStack.requireOutput('sentryDsnArn') const sentryOrgArn = coreStack.requireOutput('sentryOrgArn') const sentryProjectArn = coreStack.requireOutput('sentryProjectArn') -const defaultProviderIdArn = coreStack.requireOutput('defaultProviderIdArn') const defaultProjectIdArn = coreStack.requireOutput('defaultProjectIdArn') +const defaultProviderApiKeyArn = coreStack.requireOutput( + 'defaultProviderApiKeyArn', +) const getSecretString = (arn: pulumi.Output) => { return arn.apply((secretId) => @@ -49,12 +51,12 @@ const websocketSecretRefreshToken = getSecretString( const workersWebsocketsSecretToken = getSecretString( workersWebsocketsSecretTokenArn, ) -const defaultProviderId = getSecretString(defaultProviderIdArn) const defaultProjectId = getSecretString(defaultProjectIdArn) export const sentryDsn = getSecretString(sentryDsnArn) export const sentryOrg = getSecretString(sentryOrgArn) export const sentryProject = getSecretString(sentryProjectArn) +export const defaultProviderApiKey = getSecretString(defaultProviderApiKeyArn) export const dbUrl = pulumi.interpolate`postgresql://${dbUsername}:${dbPassword}@${dbEndpoint}/${dbName}?sslmode=verify-full&sslrootcert=/app/packages/core/src/assets/eu-central-1-bundle.pem` export const environment = pulumi @@ -68,8 +70,8 @@ export const environment = pulumi sentryDsn, sentryOrg, sentryProject, - defaultProviderId, defaultProjectId, + defaultProviderApiKey, ]) .apply(() => { return [ @@ -107,7 +109,6 @@ export const environment = pulumi { name: 'AWS_ACCESS_KEY', value: awsAccessKey }, { name: 'AWS_ACCESS_SECRET', value: awsAccessSecret }, { name: 'DEFAULT_PROJECT_ID', value: defaultProjectId }, - { name: 'DEFAULT_PROVIDER_ID', value: defaultProviderId }, - { name: 'DEFAULT_PROVIDER_MODEL', value: 'gpt-4o-mini' }, + { name: 'DEFAULT_PROVIDER_API_KEY', value: defaultProviderApiKey }, ] }) diff --git a/apps/web/src/components/EditorHeader/index.tsx b/apps/web/src/components/EditorHeader/index.tsx index 98b87e140..a0b34fab8 100644 --- a/apps/web/src/components/EditorHeader/index.tsx +++ b/apps/web/src/components/EditorHeader/index.tsx @@ -206,7 +206,7 @@ export default function EditorHeader({