From f6e1f9022541ca2952d86e8ad3e186c496e00e75 Mon Sep 17 00:00:00 2001 From: Daniel Salazar Date: Thu, 30 Apr 2026 23:56:18 -0700 Subject: [PATCH] fix: dbConfigs and ai routes (#2868) * fix: db configs Co-authored-by: Copilot * fix: ai routes Co-authored-by: Copilot --------- Co-authored-by: Copilot --- .../clients/database/MySQLDatabaseClient.ts | 11 ++++---- .../controllers/puterai/PuterAIController.ts | 27 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/backend/clients/database/MySQLDatabaseClient.ts b/src/backend/clients/database/MySQLDatabaseClient.ts index 693c401c2..6b6e618c6 100644 --- a/src/backend/clients/database/MySQLDatabaseClient.ts +++ b/src/backend/clients/database/MySQLDatabaseClient.ts @@ -60,7 +60,7 @@ export class MySQLDatabaseClient extends AbstractDatabaseClient { }); console.log('[mysql] connected to primary'); - this.db = new SQLBatcher(this.primaryPool, 40, 10); + this.db = new SQLBatcher(this.primaryPool, 30, 5); if (dbConf.replica) { this.replicaPool = this.createPool(dbConf.replica); @@ -71,7 +71,7 @@ export class MySQLDatabaseClient extends AbstractDatabaseClient { this.configuration = Configuration.SINGLE; } - this.dbReplica = new SQLBatcher(this.replicaPool, 10, 10); + this.dbReplica = new SQLBatcher(this.replicaPool, 10, 5); } override async onServerPrepareShutdown(): Promise { @@ -201,6 +201,7 @@ export class MySQLDatabaseClient extends AbstractDatabaseClient { private createPool(poolConfig: PoolConfig): Pool { return createPool({ maxPreparedStatements: 900, + connectionLimit: 30, ...poolConfig, multipleStatements: true, } as PoolConfig); @@ -219,11 +220,11 @@ export class MySQLDatabaseClient extends AbstractDatabaseClient { password: dbConf.password ?? '', database: dbConf.database ?? 'puter', }); - this.db = new SQLBatcher(this.primaryPool, 40, 10); + this.db = new SQLBatcher(this.primaryPool, 30, 5); if (this.configuration === Configuration.SINGLE) { this.replicaPool = this.primaryPool; - this.dbReplica = new SQLBatcher(this.primaryPool, 10, 10); + this.dbReplica = new SQLBatcher(this.primaryPool, 10, 5); } if (previous && previous !== this.primaryPool) { @@ -237,7 +238,7 @@ export class MySQLDatabaseClient extends AbstractDatabaseClient { const previous = this.replicaPool; this.replicaPool = this.createPool(this.config.database.replica); - this.dbReplica = new SQLBatcher(this.replicaPool, 10); + this.dbReplica = new SQLBatcher(this.replicaPool, 10, 5); if ( previous && diff --git a/src/backend/controllers/puterai/PuterAIController.ts b/src/backend/controllers/puterai/PuterAIController.ts index 4e477012d..4c4523beb 100644 --- a/src/backend/controllers/puterai/PuterAIController.ts +++ b/src/backend/controllers/puterai/PuterAIController.ts @@ -30,56 +30,61 @@ const GEMINI_DOWNLOAD_BASE = */ export class PuterAIController extends PuterController { registerRoutes(router: PuterRouter): void { - const apiOpts = { subdomain: 'api', requireAuth: true } as const; + const apiAuthOpts = { subdomain: 'api', requireAuth: true } as const; + const publicOpts = { subdomain: 'api', requireAuth: false } as const; // Every route below carries the `/puterai` prefix for wire // compatibility with puter-js and existing API tests. router.post( '/puterai/openai/v1/chat/completions', - apiOpts, + apiAuthOpts, this.openaiChatCompletions, ); router.post( '/puterai/openai/v1/completions', - apiOpts, + apiAuthOpts, this.openaiCompletions, ); router.post( '/puterai/openai/v1/responses', - apiOpts, + apiAuthOpts, this.openaiResponses, ); router.post( '/puterai/anthropic/v1/messages', - apiOpts, + apiAuthOpts, this.anthropicMessages, ); // Model listing — enumerate available models per AI service - router.get('/puterai/chat/models', apiOpts, this.#listModels('aiChat')); + router.get( + '/puterai/chat/models', + publicOpts, + this.#listModels('aiChat'), + ); router.get( '/puterai/chat/models/details', - apiOpts, + publicOpts, this.#modelDetails('aiChat'), ); router.get( '/puterai/image/models', - apiOpts, + publicOpts, this.#listModels('aiImage'), ); router.get( '/puterai/image/models/details', - apiOpts, + publicOpts, this.#modelDetails('aiImage'), ); router.get( '/puterai/video/models', - apiOpts, + publicOpts, this.#listModels('aiVideo'), ); router.get( '/puterai/video/models/details', - apiOpts, + publicOpts, this.#modelDetails('aiVideo'), );