diff --git a/app/icon.svg b/app/icon.svg index e68007e..6733f6c 100644 --- a/app/icon.svg +++ b/app/icon.svg @@ -1,52 +1,16 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + diff --git a/lib/auth.ts b/lib/auth.ts index a9d0c22..2d0f568 100644 --- a/lib/auth.ts +++ b/lib/auth.ts @@ -182,53 +182,80 @@ const buildProviders = () => { // This will automatically clear the cached service instance await updateUserKubeconfig(existingIdentity.user.id, sealosKubeconfig) - // Create aiproxy token + // Create aiproxy token if not already configured try { - const tokenInfo = await createAiproxyToken( - `fullstackagent-${sealosUserId}`, - sealosKubeconfig - ) - - if (tokenInfo?.token?.key && tokenInfo.anthropicBaseUrl) { - // Store ANTHROPIC_API_KEY in UserConfig - await prisma.userConfig.upsert({ - where: { - userId_key: { - userId: existingIdentity.user.id, - key: 'ANTHROPIC_API_KEY', - }, - }, - create: { - userId: existingIdentity.user.id, - key: 'ANTHROPIC_API_KEY', - value: tokenInfo.token.key, - category: 'anthropic', - isSecret: true, - }, - update: { - value: tokenInfo.token.key, + // Check if all four configs already exist + const existingConfigs = await prisma.userConfig.findMany({ + where: { + userId: existingIdentity.user.id, + key: { + in: ['ANTHROPIC_API_KEY', 'ANTHROPIC_API', 'ANTHROPIC_MODEL', 'ANTHROPIC_SMALL_FAST_MODEL'], }, - }) + }, + }) - // Store ANTHROPIC_API (base URL) in UserConfig - await prisma.userConfig.upsert({ - where: { - userId_key: { - userId: existingIdentity.user.id, - key: 'ANTHROPIC_API', - }, - }, - create: { - userId: existingIdentity.user.id, - key: 'ANTHROPIC_API', - value: tokenInfo.anthropicBaseUrl, - category: 'anthropic', - isSecret: false, - }, - update: { - value: tokenInfo.anthropicBaseUrl, - }, - }) + const existingKeys = new Set(existingConfigs.map(config => config.key)) + + // Only create token if at least one config is missing + if (existingKeys.size < 4) { + const tokenInfo = await createAiproxyToken( + `fullstackagent-${sealosUserId}`, + sealosKubeconfig + ) + + if (tokenInfo?.token?.key && tokenInfo.anthropicBaseUrl) { + // Create ANTHROPIC_API_KEY only if not exists + if (!existingKeys.has('ANTHROPIC_API_KEY')) { + await prisma.userConfig.create({ + data: { + userId: existingIdentity.user.id, + key: 'ANTHROPIC_API_KEY', + value: tokenInfo.token.key, + category: 'anthropic', + isSecret: true, + }, + }) + } + + // Create ANTHROPIC_API only if not exists + if (!existingKeys.has('ANTHROPIC_API')) { + await prisma.userConfig.create({ + data: { + userId: existingIdentity.user.id, + key: 'ANTHROPIC_API', + value: tokenInfo.anthropicBaseUrl, + category: 'anthropic', + isSecret: false, + }, + }) + } + + // Create ANTHROPIC_MODEL only if not exists and value is provided + if (!existingKeys.has('ANTHROPIC_MODEL') && tokenInfo.anthropicModel) { + await prisma.userConfig.create({ + data: { + userId: existingIdentity.user.id, + key: 'ANTHROPIC_MODEL', + value: tokenInfo.anthropicModel, + category: 'anthropic', + isSecret: false, + }, + }) + } + + // Create ANTHROPIC_SMALL_FAST_MODEL only if not exists and value is provided + if (!existingKeys.has('ANTHROPIC_SMALL_FAST_MODEL') && tokenInfo.anthropicSmallFastModel) { + await prisma.userConfig.create({ + data: { + userId: existingIdentity.user.id, + key: 'ANTHROPIC_SMALL_FAST_MODEL', + value: tokenInfo.anthropicSmallFastModel, + category: 'anthropic', + isSecret: false, + }, + }) + } + } } } catch (error) { logger.error(`Failed to create aiproxy token for user ${sealosUserId}: ${error}`) @@ -275,6 +302,25 @@ const buildProviders = () => { category: 'anthropic', isSecret: false, }) + + // Add model configs if provided + if (aiproxyTokenInfo.anthropicModel) { + configs.push({ + key: 'ANTHROPIC_MODEL', + value: aiproxyTokenInfo.anthropicModel, + category: 'anthropic', + isSecret: false, + }) + } + + if (aiproxyTokenInfo.anthropicSmallFastModel) { + configs.push({ + key: 'ANTHROPIC_SMALL_FAST_MODEL', + value: aiproxyTokenInfo.anthropicSmallFastModel, + category: 'anthropic', + isSecret: false, + }) + } } const newUser = await prisma.user.create({ diff --git a/lib/env.ts b/lib/env.ts index 26df3b5..4471211 100644 --- a/lib/env.ts +++ b/lib/env.ts @@ -29,6 +29,10 @@ export const env = createEnv({ // GitHub OAuth credentials GITHUB_CLIENT_ID: z.string().optional(), GITHUB_CLIENT_SECRET: z.string().optional(), + ANTHROPIC_BASE_URL: z.string().optional(), + AIPROXY_ENDPOINT: z.string().optional(), + ANTHROPIC_SMALL_FAST_MODEL: z.string().optional(), + ANTHROPIC_MODEL: z.string().optional(), }, /* * Environment variables available on the client (and server). diff --git a/lib/services/aiproxy.ts b/lib/services/aiproxy.ts index df03621..e4f4d61 100644 --- a/lib/services/aiproxy.ts +++ b/lib/services/aiproxy.ts @@ -1,4 +1,5 @@ import { prisma } from '@/lib/db' +import { env } from '@/lib/env' import { logger as baseLogger } from '@/lib/logger' const logger = baseLogger.child({ module: 'lib/services/aiproxy' }) @@ -20,6 +21,8 @@ type AiproxyResponse = { type AiproxyTokenResponse = { token: TokenInfo anthropicBaseUrl: string + anthropicModel?: string + anthropicSmallFastModel?: string } /** @@ -33,8 +36,8 @@ export async function createAiproxyToken( kubeconfig: string ): Promise { // Check if required environment variables are set - const aiproxyEndpoint = process.env.AIPROXY_ENDPOINT - const anthropicBaseUrl = process.env.ANTHROPIC_BASE_URL + const aiproxyEndpoint = env.AIPROXY_ENDPOINT + const anthropicBaseUrl = env.ANTHROPIC_BASE_URL if (!aiproxyEndpoint || !anthropicBaseUrl) { logger.warn('AIPROXY_ENDPOINT or ANTHROPIC_BASE_URL not configured, skipping token creation') @@ -71,6 +74,8 @@ export async function createAiproxyToken( return { token: result.data, anthropicBaseUrl: anthropicBaseUrl, + anthropicModel: env.ANTHROPIC_MODEL, + anthropicSmallFastModel: env.ANTHROPIC_SMALL_FAST_MODEL, } } catch (error) { logger.error(`Error creating aiproxy token: ${error}`) diff --git a/public/favicon.svg b/public/favicon.svg deleted file mode 100644 index e68007e..0000000 --- a/public/favicon.svg +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..6733f6c --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + +