chore: baseline Agent Workbench 1.0.0

This commit is contained in:
Agent Workbench Dev
2026-10-29 11:23:43 +08:00
commit bac87da23e
167 changed files with 30172 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
let accessToken = '';
export function setToken(token: string) { accessToken = token; }
export async function api<T>(path: string, input?: unknown): Promise<T> {
const response = await fetch('/api' + path, {
method: input === undefined ? 'GET' : 'POST',
headers: { 'Content-Type': 'application/json', ...(accessToken ? { 'X-Workbench-Token': accessToken } : {}) },
...(input === undefined ? {} : { body: JSON.stringify(input) }),
});
const body = await response.json();
if (!response.ok) throw new Error(body.error || '请求失败,请重试。');
return body as T;
}
export async function exportSession(id: string) {
const response = await fetch('/api/sessions/' + id + '/export', { headers: { 'X-Workbench-Token': accessToken } });
if (!response.ok) throw new Error('会话导出失败。');
const blob = await response.blob();
downloadBlob(blob, 'agent-workbench-session-' + id + '.json');
}
export function downloadBlob(blob: Blob, name: string) {
const url = URL.createObjectURL(blob);
const link = document.createElement('a'); link.href = url; link.download = name; link.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);
}