Keep track of API usage in user accounts, improve approval mechanism (#95)

This commit is contained in:
Brian Hackett
2025-04-04 14:40:10 -07:00
committed by GitHub
parent 4f5051dee5
commit 9389fb2afc
11 changed files with 190 additions and 120 deletions

View File

@@ -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 {

View File

@@ -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);