Add token-based authentication for the Launcher's embedded Web Dashboard. - Ephemeral token generated in-memory each run (or via PICOCLAW_LAUNCHER_TOKEN env var) - HMAC-SHA256 session cookie (HttpOnly, SameSite=Lax, Secure when HTTPS) - Bearer token support for API/script access - Rate limiting on login (10 attempts/IP/min) - Referrer-Policy: no-referrer on all responses - POST-only logout with JSON content-type (CSRF-safe) - System tray "Copy dashboard token" action - Login page shows contextual help (console/tray/log file path) - Path traversal protection via path.Clean - X-Forwarded-Host/Port/Proto support for reverse proxy deployments - Full i18n support (English, Chinese) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
// Sessions API — list and retrieve chat session history
|
|
|
|
import { launcherFetch } from "@/api/http"
|
|
|
|
export interface SessionSummary {
|
|
id: string
|
|
title: string
|
|
preview: string
|
|
message_count: number
|
|
created: string
|
|
updated: string
|
|
}
|
|
|
|
export interface SessionDetail {
|
|
id: string
|
|
messages: { role: "user" | "assistant"; content: string }[]
|
|
summary: string
|
|
created: string
|
|
updated: string
|
|
}
|
|
|
|
export async function getSessions(
|
|
offset: number = 0,
|
|
limit: number = 20,
|
|
): Promise<SessionSummary[]> {
|
|
const params = new URLSearchParams({
|
|
offset: offset.toString(),
|
|
limit: limit.toString(),
|
|
})
|
|
|
|
const res = await launcherFetch(`/api/sessions?${params.toString()}`)
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to fetch sessions: ${res.status}`)
|
|
}
|
|
return res.json()
|
|
}
|
|
|
|
export async function getSessionHistory(id: string): Promise<SessionDetail> {
|
|
const res = await launcherFetch(`/api/sessions/${encodeURIComponent(id)}`)
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to fetch session ${id}: ${res.status}`)
|
|
}
|
|
return res.json()
|
|
}
|
|
|
|
export async function deleteSession(id: string): Promise<void> {
|
|
const res = await launcherFetch(`/api/sessions/${encodeURIComponent(id)}`, {
|
|
method: "DELETE",
|
|
})
|
|
if (!res.ok) {
|
|
throw new Error(`Failed to delete session ${id}: ${res.status}`)
|
|
}
|
|
}
|