Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
3.4 kB · 85 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586import type { DeleteSessionFileResult } from "../../core/session-file-actions.js";import type { AgentConnectionSavedSessionInfo, AgentConnectionSavedSessionScope, AgentConnectionSessionListCallbacks,} from "../agent-connection/types.js";import type { DaemonTransportClient } from "./daemon-client.js";import { deserializeDaemonError } from "./daemon-errors.js";import type { DaemonCommand, DaemonDeleteSavedSessionResult, DaemonSavedSessionInfo, DaemonSavedSessionListCommand,} from "./daemon-protocol.js";import { deserializeSavedSessionInfo } from "./saved-session-info.js";
export { deserializeSavedSessionInfo } from "./saved-session-info.js";
export type DaemonSavedSessionCatalogContext = { activeSessionId: string } | { cwd: string; sessionDir?: string };
export async function listDaemonSavedSessions( client: DaemonTransportClient, context: DaemonSavedSessionCatalogContext, scope: AgentConnectionSavedSessionScope, callbacks?: AgentConnectionSessionListCallbacks,): Promise<AgentConnectionSavedSessionInfo[]> { // The streamed items are the same rows the response would repeat. const streamOnly = client.supportsServerCapability?.("session_list_stream_only") ? { streamOnly: true as const } : {}; const command: DaemonSavedSessionListCommand = "activeSessionId" in context ? { type: "list_saved_sessions", activeSessionId: context.activeSessionId, scope, ...streamOnly } : { type: "list_saved_sessions", cwd: context.cwd, sessionDir: context.sessionDir, scope, ...streamOnly }; const streamed: AgentConnectionSavedSessionInfo[] = []; const response = await client.request(command, 30000, { onProgress: (update) => { if (update.type === "session_list_progress") { callbacks?.onProgress?.(update.loaded, update.total); } else { const session = deserializeSavedSessionInfo(update.session); streamed.push(session); callbacks?.onSession?.(session); } }, }); if (!response.success) { throw deserializeDaemonError(response); } const data = response.data as { sessions: DaemonSavedSessionInfo[] }; // A daemon that does not know streamOnly repeats the rows in the response. return data.sessions.length > 0 ? data.sessions.map(deserializeSavedSessionInfo) : streamed;}
export async function renameDaemonSavedSession( client: DaemonTransportClient, context: DaemonSavedSessionCatalogContext, sessionPath: string, name: string,): Promise<void> { const command: Extract<DaemonCommand, { type: "rename_saved_session" }> = "activeSessionId" in context ? { type: "rename_saved_session", activeSessionId: context.activeSessionId, sessionPath, name } : { type: "rename_saved_session", sessionPath, name }; const response = await client.request(command); if (!response.success) { throw deserializeDaemonError(response); }}
export async function deleteDaemonSavedSession( client: DaemonTransportClient, context: DaemonSavedSessionCatalogContext, sessionPath: string,): Promise<DeleteSessionFileResult> { const command: Extract<DaemonCommand, { type: "delete_saved_session" }> = "activeSessionId" in context ? { type: "delete_saved_session", activeSessionId: context.activeSessionId, sessionPath } : { type: "delete_saved_session", sessionPath }; const response = await client.request(command); if (!response.success) { throw deserializeDaemonError(response); } return response.data as DaemonDeleteSavedSessionResult;}