Skip to content

Commit 5098add

Browse files
committed
fix(OUT-2944-re): removed globalThis on base service
- globalThis was causing copilot instance to be shared, swapping global instances while calling copilot methods. - The solution applied verifies a unique SDK instance for each service instance.
1 parent 0fc5e94 commit 5098add

1 file changed

Lines changed: 1 addition & 16 deletions

File tree

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { CopilotAPI } from '@/utils/CopilotAPI'
33
import User from '@api/core/models/User.model'
44
import { PrismaClient } from '@prisma/client'
55

6-
declare global {
7-
var copilot: CopilotAPI | undefined
8-
var token: string | undefined
9-
var copilotApiKey: string | undefined
10-
}
11-
126
/**
137
* Base Service with access to db and current user
148
*/
@@ -21,16 +15,7 @@ export class BaseService {
2115
constructor(user: User, customCopilotApiKey?: string) {
2216
this.user = user
2317
this.customApiKey = customCopilotApiKey
24-
25-
// If token or copiltoApiKey mismatches, or global copilot instance is not present, create a new one.
26-
// INFO: The token mismatch check is to make sure that fluid compute sharing serverless functions doesn't reuse the same SDK instance
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)
31-
}
32-
33-
this.copilot = globalThis.copilot
18+
this.copilot = new CopilotAPI(user.token)
3419
}
3520

3621
setTransaction(tx: PrismaClient) {

0 commit comments

Comments
 (0)