File tree Expand file tree Collapse file tree
src/app/api/core/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { PrismaClient } from '@prisma/client'
66declare global {
77 var copilot : CopilotAPI | undefined
88 var token : string | undefined
9+ var copilotApiKey : string | undefined
910}
1011
1112/**
@@ -21,15 +22,12 @@ export class BaseService {
2122 this . user = user
2223 this . customApiKey = customCopilotApiKey
2324
24- // Set a global token if not present. We use token as an identifier to issue a new SDK instance
25- if ( ! globalThis . token ) {
26- globalThis . token = user . token
27- }
28-
29- // If token mismatches, or global copilot instance is not present, create a new one.
25+ // If token or copiltoApiKey mismatches, or global copilot instance is not present, create a new one.
3026 // INFO: The token mismatch check is to make sure that fluid compute sharing serverless functions doesn't reuse the same SDK instance
31- if ( globalThis . token !== user . token || ! globalThis . copilot ) {
32- globalThis . copilot = new CopilotAPI ( user . token )
27+ if ( globalThis . token !== user . token || globalThis . copilotApiKey !== customCopilotApiKey || ! globalThis . copilot ) {
28+ globalThis . token = user . token
29+ globalThis . copilotApiKey = customCopilotApiKey
30+ globalThis . copilot = new CopilotAPI ( user . token , customCopilotApiKey )
3331 }
3432
3533 this . copilot = globalThis . copilot
You can’t perform that action at this time.
0 commit comments