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