mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Keep track of API usage in user accounts, improve approval mechanism (#95)
This commit is contained in:
@@ -56,20 +56,28 @@ class DevelopmentServerManager {
|
||||
|
||||
let gActiveDevelopmentServer: DevelopmentServerManager | undefined;
|
||||
|
||||
export async function updateDevelopmentServer(repositoryId: string) {
|
||||
export async function updateDevelopmentServer(repositoryId: string | undefined) {
|
||||
console.log('UpdateDevelopmentServer', new Date().toISOString(), repositoryId);
|
||||
|
||||
workbenchStore.showWorkbench.set(true);
|
||||
workbenchStore.showWorkbench.set(repositoryId !== undefined);
|
||||
workbenchStore.repositoryId.set(repositoryId);
|
||||
workbenchStore.previewURL.set(undefined);
|
||||
workbenchStore.previewError.set(false);
|
||||
|
||||
if (!repositoryId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gActiveDevelopmentServer) {
|
||||
gActiveDevelopmentServer = new DevelopmentServerManager();
|
||||
}
|
||||
|
||||
const url = await gActiveDevelopmentServer.setRepositoryContents(repositoryId);
|
||||
|
||||
if (workbenchStore.repositoryId.get() != repositoryId) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (url) {
|
||||
workbenchStore.previewURL.set(url);
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ import type { Message } from '~/lib/persistence/message';
|
||||
import { database } from '~/lib/persistence/db';
|
||||
import { chatStore } from '~/lib/stores/chat';
|
||||
import { debounce } from '~/utils/debounce';
|
||||
import { getSupabase } from '~/lib/supabase/client';
|
||||
|
||||
function createRepositoryIdPacket(repositoryId: string): SimulationPacket {
|
||||
return {
|
||||
@@ -64,6 +65,15 @@ class ChatManager {
|
||||
|
||||
await this.client.initialize();
|
||||
|
||||
const {
|
||||
data: { user },
|
||||
} = await getSupabase().auth.getUser();
|
||||
const userId = user?.id || null;
|
||||
|
||||
if (userId) {
|
||||
await this.client.sendCommand({ method: 'Nut.setUserId', params: { userId } });
|
||||
}
|
||||
|
||||
const { chatId } = (await this.client.sendCommand({ method: 'Nut.startChat', params: {} })) as { chatId: string };
|
||||
|
||||
console.log('ChatStarted', new Date().toISOString(), chatId);
|
||||
@@ -235,7 +245,7 @@ function startChat(repositoryId: string | undefined, pageData: SimulationData) {
|
||||
* Called when the repository has changed. We'll start a new chat
|
||||
* and update the remote development server.
|
||||
*/
|
||||
export const simulationRepositoryUpdated = debounce((repositoryId: string) => {
|
||||
export const simulationRepositoryUpdated = debounce((repositoryId: string | undefined) => {
|
||||
startChat(repositoryId, []);
|
||||
updateDevelopmentServer(repositoryId);
|
||||
}, 500);
|
||||
|
||||
Reference in New Issue
Block a user