mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
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
|
|
kind?: "normal" | "thought"
|
|
media?: string[]
|
|
attachments?: {
|
|
type?: "image" | "audio" | "video" | "file"
|
|
url: string
|
|
filename?: string
|
|
content_type?: 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}`)
|
|
}
|
|
}
|