chat screenshot

This commit is contained in:
Nate Kelley 2025-10-08 14:25:28 -06:00
parent ee623169c0
commit b2db16772d
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 58 additions and 2 deletions

View File

@ -1,5 +1,5 @@
import { screenshots_task_keys } from '@buster-app/trigger/task-keys';
import { TakeReportScreenshotTrigger } from '@buster-app/trigger/task-schemas';
import type { TakeReportScreenshotTrigger } from '@buster-app/trigger/task-schemas';
import { checkPermission } from '@buster/access-controls';
import {
type User,

View File

@ -1,6 +1,6 @@
import { createClient } from '@supabase/supabase-js';
export const createSupabaseClient = () => {
const createSupabaseClient = () => {
const supabaseUrl = process.env.SUPABASE_URL;
if (!supabaseUrl) {

View File

@ -24,7 +24,10 @@ import { type PermissionedDataset, getPermissionedDatasets } from '@buster/acces
import { type AnalystWorkflowInput, runAnalystWorkflow } from '@buster/ai';
import type { ModelMessage } from 'ai';
import { getSupabaseCookieKey, getSupabaseUser } from '../../utils/supabase';
import type { messagePostProcessingTask } from '../message-post-processing/message-post-processing';
import type { TakeDashboardScreenshotTrigger } from '../screenshots/schemas';
import { screenshots_task_keys } from '../screenshots/task-keys';
/**
* Resource usage tracker for the entire task execution
@ -512,6 +515,18 @@ export const analystAgentTask: ReturnType<
totalWorkflowTimeMs: totalWorkflowTime,
});
const supabaseUser = await getSupabaseUser(payload.access_token);
if (supabaseUser) {
await tasks.trigger(screenshots_task_keys.take_dashboard_screenshot, {
dashboardId: payload.message_id,
isOnSaveEvent: false,
organizationId: messageContext.organizationId,
supabaseCookieKey: getSupabaseCookieKey(),
accessToken: payload.access_token,
supabaseUser,
} satisfies TakeDashboardScreenshotTrigger);
}
// Log final performance metrics
logPerformanceMetrics(
'workflow-complete',

View File

@ -6,6 +6,7 @@ export const UUIDSchema = z.string().uuid('Must be a valid UUID');
// Simple input schema - just message_id
export const AnalystAgentTaskInputSchema = z.object({
message_id: UUIDSchema,
access_token: z.string(),
});
// Task execution result (for Trigger.dev monitoring)

View File

@ -0,0 +1,40 @@
import { type User, createClient } from '@supabase/supabase-js';
const createSupabaseClient = () => {
const supabaseUrl = process.env.SUPABASE_URL;
if (!supabaseUrl) {
throw new Error('SUPABASE_URL is not set');
}
const supabaseServiceRoleKey = process.env.SUPABASE_SERVICE_ROLE_KEY;
if (!supabaseServiceRoleKey) {
throw new Error('SUPABASE_SERVICE_ROLE_KEY is not set');
}
const supabase = createClient(supabaseUrl, supabaseServiceRoleKey);
return supabase;
};
let globalSupabase: ReturnType<typeof createSupabaseClient> | null = null;
export const getSupabaseClient = () => {
if (!globalSupabase) {
globalSupabase = createSupabaseClient();
}
return globalSupabase;
};
export const getSupabaseCookieKey = (): string => {
const supabase = getSupabaseClient();
const supabaseCookieKey = (supabase as unknown as { storageKey: string }).storageKey;
return supabaseCookieKey;
};
export const getSupabaseUser = async (jwtToken: string): Promise<User | null> => {
const supabase = getSupabaseClient();
const supabaseUser = await supabase.auth.getUser(jwtToken);
return supabaseUser.data.user;
};