Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(mcp): give the store file a type that always carries the spent-refresh map
Cybor627e0c83fad1
diff --git a/server/mcp-oauth-store.ts b/server/mcp-oauth-store.tsindex 4e7d2a7c2b..9360b2c360 100644--- a/server/mcp-oauth-store.ts+++ b/server/mcp-oauth-store.ts@@ -34,7 +34,11 @@ const fileSchema = z.object({export type McpOAuthTokens = z.infer<typeof tokensSchema>;export type McpOAuthRecord = z.infer<typeof recordSchema>;-type StoreFile = z.infer<typeof fileSchema>;+/** The file as it is kept on disk. Both maps are always present: the schema fills the missing one in. */+interface StoreFile {+ servers: Record<string, McpOAuthRecord>;+ spentRefresh: Record<string, string>;+}/** One sign-in as this store keeps it, from anywhere else (a sign-in moved from the person's own computer); null if not. */export function parseMcpOAuthRecord(value: unknown): McpOAuthRecord | null {@@ -62,23 +66,23 @@ export class McpOAuthStore {delete(name: string): void {const data = this.read();- if (!Object.hasOwn(data.servers, name) && !Object.hasOwn(data.spentRefresh ?? {}, name)) return;+ if (!Object.hasOwn(data.servers, name) && !Object.hasOwn(data.spentRefresh, name)) return;delete data.servers[name];- delete data.spentRefresh?.[name];+ delete data.spentRefresh[name];this.write(data);}/** Forget the refresh token marked as spent for this server: a new sign-in brings a new token. */forgetSpentRefresh(name: string): void {const data = this.read();- if (!Object.hasOwn(data.spentRefresh ?? {}, name)) return;- delete data.spentRefresh?.[name];+ if (!Object.hasOwn(data.spentRefresh, name)) return;+ delete data.spentRefresh[name];this.write(data);}/** The refresh token already sent for this server, when presenting it again could be a replay. */spentRefreshFor(name: string): string | undefined {- return this.read().spentRefresh?.[name];+ return this.read().spentRefresh[name];}/** Remember a refresh token that has been sent, before its answer arrives: a lost answer may mean the server@@ -92,8 +96,8 @@ export class McpOAuthStore {/** Forget a sent refresh token once the server has answered and kept it: it is still valid. */clearSpentRefresh(name: string, token: string): void {const data = this.read();- if (data.spentRefresh?.[name] !== token) return;- delete data.spentRefresh?.[name];+ if (data.spentRefresh[name] !== token) return;+ delete data.spentRefresh[name];this.write(data);}@@ -104,7 +108,7 @@ export class McpOAuthStore {if (parsed.success) return parsed.data;} catch {}- return { servers: {} };+ return { servers: {}, spentRefresh: {} };}private write(data: StoreFile): void {