mirror of https://github.com/buster-so/buster.git
commit
c4da2a6af3
|
@ -32,9 +32,9 @@ const useSupabaseContextInternal = ({
|
|||
const decoded = jwtDecode(token || accessToken);
|
||||
const expiresAtDecoded = (decoded as { exp?: number } | undefined)?.exp ?? 0;
|
||||
const expiresAtMs = millisecondsFromUnixTimestamp(expiresAtDecoded);
|
||||
const msUntilExpiry = Math.max(0, expiresAtMs - Date.now());
|
||||
return msUntilExpiry;
|
||||
return expiresAtMs;
|
||||
} catch {
|
||||
console.error('Error decoding token', token);
|
||||
// If token is missing/invalid, report that it is effectively expired now
|
||||
return 0;
|
||||
}
|
||||
|
@ -126,6 +126,7 @@ const useSupabaseContextInternal = ({
|
|||
});
|
||||
return { access_token: fallbackToken, isTokenValid: true };
|
||||
}
|
||||
console.error('Error refreshing session', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
@ -155,6 +156,7 @@ const useSupabaseContextInternal = ({
|
|||
const setupRefreshTimer = () => {
|
||||
const expiresInMs = getExpiresAt();
|
||||
const refreshBuffer = PREEMTIVE_REFRESH_MINUTES * 60000; // Refresh minutes before expiration
|
||||
|
||||
const timeUntilRefresh = Math.max(0, expiresInMs - refreshBuffer);
|
||||
|
||||
if (refreshTimerRef.current) {
|
||||
|
@ -181,14 +183,16 @@ const useSupabaseContextInternal = ({
|
|||
// Keep access token in sync with Supabase client (captures auto-refresh events)
|
||||
const { data: subscription } = supabase.auth.onAuthStateChange((event, session) => {
|
||||
const newToken = session?.access_token;
|
||||
if (event === 'SIGNED_OUT' || !newToken) {
|
||||
if (event === 'SIGNED_OUT' || (!newToken && event !== 'INITIAL_SESSION')) {
|
||||
setAccessToken('');
|
||||
if (refreshTimerRef.current) {
|
||||
clearTimeout(refreshTimerRef.current);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (newToken) {
|
||||
void onUpdateToken({ accessToken: newToken, expiresAt: session?.expires_at ?? 0 });
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
|
|
@ -287,7 +287,7 @@ Today's date is ${new Date().toISOString().split('T')[0]}.
|
|||
export const getAnalystInstructions = async ({
|
||||
runtimeContext,
|
||||
}: { runtimeContext: RuntimeContext<AnalystRuntimeContext> }): Promise<string> => {
|
||||
const userId = runtimeContext.get('userId');
|
||||
const _userId = runtimeContext.get('userId');
|
||||
const dataSourceSyntax = runtimeContext.get('dataSourceSyntax');
|
||||
|
||||
// Get dialect-specific guidance
|
||||
|
|
|
@ -497,7 +497,7 @@ Today's date is ${new Date().toLocaleDateString()}.
|
|||
export const getThinkAndPrepInstructions = async ({
|
||||
runtimeContext,
|
||||
}: { runtimeContext: RuntimeContext<AnalystRuntimeContext> }): Promise<string> => {
|
||||
const userId = runtimeContext.get('userId');
|
||||
const _userId = runtimeContext.get('userId');
|
||||
const dataSourceSyntax = runtimeContext.get('dataSourceSyntax');
|
||||
|
||||
// Get dialect-specific guidance
|
||||
|
|
|
@ -271,7 +271,7 @@ const analystExecution = async ({
|
|||
.join('\n---\n');
|
||||
|
||||
// Get dialect-specific guidance
|
||||
const sqlDialectGuidance = getSqlDialectGuidance(dataSourceSyntax);
|
||||
const _sqlDialectGuidance = getSqlDialectGuidance(dataSourceSyntax);
|
||||
|
||||
// Create dataset system message
|
||||
const createDatasetSystemMessage = (databaseContext: string): string => {
|
||||
|
|
|
@ -186,7 +186,7 @@ const thinkAndPrepExecution = async ({
|
|||
.join('\n---\n');
|
||||
|
||||
// Get dialect-specific guidance
|
||||
const sqlDialectGuidance = getSqlDialectGuidance(dataSourceSyntax);
|
||||
const _sqlDialectGuidance = getSqlDialectGuidance(dataSourceSyntax);
|
||||
|
||||
// Create dataset system message
|
||||
const createDatasetSystemMessage = (databaseContext: string): string => {
|
||||
|
|
Loading…
Reference in New Issue