44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { DailyDigest } from '../types/workbench';
|
|
|
|
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: { Accept: 'application/json' },
|
|
});
|
|
|
|
if (!res.ok) {
|
|
throw new Error(`fetchDailyDigests failed: HTTP ${res.status}`);
|
|
}
|
|
|
|
return res.json();
|
|
}
|
|
|
|
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: { 'Content-Type': '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();
|
|
}
|