sandbox connected and streaming
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { BetterAuthInstance } from './better-auth-config.js';
|
||||
import type { FastifyBaseLogger } from 'fastify';
|
||||
import type { Pool } from 'pg';
|
||||
import { LICENSE_TIER_TEMPLATES } from '../types/user.js';
|
||||
|
||||
export interface AuthServiceConfig {
|
||||
auth: BetterAuthInstance;
|
||||
@@ -202,11 +203,11 @@ export class AuthService {
|
||||
);
|
||||
|
||||
if (licenseCheck.rows.length === 0) {
|
||||
// Create default free license
|
||||
// Create default free license — copy the full tier template so every field is present
|
||||
await client.query(
|
||||
`INSERT INTO user_licenses (user_id, email, license_type, mcp_server_url)
|
||||
VALUES ($1, $2, 'free', 'pending')`,
|
||||
[userId, email]
|
||||
`INSERT INTO user_licenses (user_id, email, license, mcp_server_url)
|
||||
VALUES ($1, $2, $3::jsonb, 'pending')`,
|
||||
[userId, email, JSON.stringify(LICENSE_TIER_TEMPLATES.free)]
|
||||
);
|
||||
|
||||
this.config.logger.info({ userId }, 'Created default free license for new user');
|
||||
|
||||
@@ -56,7 +56,7 @@ export class Authenticator {
|
||||
this.config.logger.info({ userId }, 'Ensuring user container is running');
|
||||
const { mcpEndpoint, wasCreated, isSpinningUp } = await this.config.containerManager.ensureContainerRunning(
|
||||
userId,
|
||||
license,
|
||||
license.license,
|
||||
false // Don't wait for ready
|
||||
);
|
||||
|
||||
@@ -72,9 +72,6 @@ export class Authenticator {
|
||||
);
|
||||
}
|
||||
|
||||
// Update license with actual MCP endpoint
|
||||
license.mcpServerUrl = mcpEndpoint;
|
||||
|
||||
const sessionId = `ws_${userId}_${Date.now()}`;
|
||||
|
||||
return {
|
||||
@@ -83,7 +80,8 @@ export class Authenticator {
|
||||
channelType: ChannelType.WEBSOCKET,
|
||||
channelUserId: userId, // For WebSocket, same as userId
|
||||
sessionId,
|
||||
license,
|
||||
license: license.license,
|
||||
mcpServerUrl: mcpEndpoint,
|
||||
authenticatedAt: new Date(),
|
||||
},
|
||||
isSpinningUp,
|
||||
@@ -123,7 +121,7 @@ export class Authenticator {
|
||||
this.config.logger.info({ userId }, 'Ensuring user container is running');
|
||||
const { mcpEndpoint, wasCreated } = await this.config.containerManager.ensureContainerRunning(
|
||||
userId,
|
||||
license
|
||||
license.license
|
||||
);
|
||||
|
||||
this.config.logger.info(
|
||||
@@ -131,9 +129,6 @@ export class Authenticator {
|
||||
'Container is ready'
|
||||
);
|
||||
|
||||
// Update license with actual MCP endpoint
|
||||
license.mcpServerUrl = mcpEndpoint;
|
||||
|
||||
const sessionId = `tg_${telegramUserId}_${Date.now()}`;
|
||||
|
||||
return {
|
||||
@@ -141,7 +136,8 @@ export class Authenticator {
|
||||
channelType: ChannelType.TELEGRAM,
|
||||
channelUserId: telegramUserId,
|
||||
sessionId,
|
||||
license,
|
||||
license: license.license,
|
||||
mcpServerUrl: mcpEndpoint,
|
||||
authenticatedAt: new Date(),
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user