Skip to content

Commit ad01e66

Browse files
fix(OUT-2944): instantiate copilotAPI if apikey mismatch
1 parent 6186bc0 commit ad01e66

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

src/app/api/core/services/base.service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PrismaClient } from '@prisma/client'
66
declare 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

0 commit comments

Comments
 (0)