Fix boot state sharing across Next.js module boundaries
Use globalThis for all in-memory stores (credentials, models, agents, tasks) so the instrumentation hook and API route handlers share the same data. Next.js bundles these as separate chunks with independent module instances, causing boot-populated state to be invisible to API routes.
This commit is contained in:
@@ -13,8 +13,10 @@ export interface Credential {
|
||||
baseUrl?: string; // for self-hosted GitLab or custom endpoints
|
||||
}
|
||||
|
||||
// In-memory store. Will be replaced with encrypted persistent storage.
|
||||
const credentials: Map<string, Credential> = new Map();
|
||||
// In-memory store shared via globalThis to survive Next.js module re-bundling.
|
||||
const g = globalThis as unknown as { __harnessCredentials?: Map<string, Credential> };
|
||||
g.__harnessCredentials ??= new Map();
|
||||
const credentials = g.__harnessCredentials;
|
||||
|
||||
export function getAllCredentials(): Credential[] {
|
||||
return Array.from(credentials.values()).map(c => ({
|
||||
|
||||
Reference in New Issue
Block a user