feat(cli): add sessions list/resume/destroy subcommands (#146)
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
This commit was merged in pull request #146.
This commit is contained in:
@@ -15,6 +15,21 @@ export interface ProviderInfo {
|
||||
models: ModelInfo[];
|
||||
}
|
||||
|
||||
export interface SessionInfo {
|
||||
id: string;
|
||||
provider: string;
|
||||
modelId: string;
|
||||
createdAt: string;
|
||||
promptCount: number;
|
||||
channels: string[];
|
||||
durationMs: number;
|
||||
}
|
||||
|
||||
export interface SessionListResult {
|
||||
sessions: SessionInfo[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the list of available models from the gateway.
|
||||
* Returns an empty array on network or auth errors so the TUI can still function.
|
||||
@@ -60,3 +75,40 @@ export async function fetchProviders(
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the list of active agent sessions from the gateway.
|
||||
* Throws on network or auth errors.
|
||||
*/
|
||||
export async function fetchSessions(
|
||||
gatewayUrl: string,
|
||||
sessionCookie: string,
|
||||
): Promise<SessionListResult> {
|
||||
const res = await fetch(`${gatewayUrl}/api/sessions`, {
|
||||
headers: { Cookie: sessionCookie, Origin: gatewayUrl },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const body = await res.text().catch(() => '');
|
||||
throw new Error(`Failed to list sessions (${res.status}): ${body}`);
|
||||
}
|
||||
return (await res.json()) as SessionListResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy (terminate) an agent session on the gateway.
|
||||
* Throws on network or auth errors.
|
||||
*/
|
||||
export async function deleteSession(
|
||||
gatewayUrl: string,
|
||||
sessionCookie: string,
|
||||
sessionId: string,
|
||||
): Promise<void> {
|
||||
const res = await fetch(`${gatewayUrl}/api/sessions/${encodeURIComponent(sessionId)}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Cookie: sessionCookie, Origin: gatewayUrl },
|
||||
});
|
||||
if (!res.ok && res.status !== 204) {
|
||||
const body = await res.text().catch(() => '');
|
||||
throw new Error(`Failed to destroy session (${res.status}): ${body}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user