Prevent login-page 401 noise by deferring project/chat API calls until auth is confirmed, use public-config for registration policy, and add client-side duty assignment checks before saving workflow plans. Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { DailyDigest } from '../types/workbench';
|
|
import { mergeAuthHeaders, getBearerAuthHeaders } from './authHeaders';
|
|
|
|
export async function fetchDailyDigests(
|
|
sessionId: string,
|
|
from?: string,
|
|
to?: string
|
|
): Promise<DailyDigest[]> {
|
|
const url = new URL('/api/v1/chat/digests', window.location.origin);
|
|
url.searchParams.set('session_id', sessionId);
|
|
if (from) url.searchParams.set('from', from);
|
|
if (to) url.searchParams.set('to', to);
|
|
|
|
const res = await fetch(url.toString(), {
|
|
method: 'GET',
|
|
headers: mergeAuthHeaders({ Accept: 'application/json' }),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`fetchDailyDigests failed: HTTP ${res.status}`);
|
|
}
|
|
|
|
const data = await res.json();
|
|
return Array.isArray(data) ? data : [];
|
|
}
|
|
|
|
export async function generateDailyDigest(
|
|
sessionId: string,
|
|
dayKey: string
|
|
): Promise<{ queued: boolean; digest: DailyDigest }> {
|
|
const res = await fetch('/api/v1/chat/digests/generate', {
|
|
method: 'POST',
|
|
headers: getBearerAuthHeaders('application/json'),
|
|
body: JSON.stringify({
|
|
session_id: sessionId,
|
|
day_key: dayKey,
|
|
}),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`generateDailyDigest failed: HTTP ${res.status}`);
|
|
}
|
|
|
|
return res.json();
|
|
}
|