diff --git a/src/client/src/api.ts b/src/client/src/api.ts index 3be94c2..fa2bb37 100644 --- a/src/client/src/api.ts +++ b/src/client/src/api.ts @@ -86,7 +86,7 @@ export const api = { prompt: (sessionId: string, text: string) => request<{ accepted: true }>(`/api/sessions/${sessionId}/prompt`, { method: "POST", body: JSON.stringify({ text }) }), runCommand: (sessionId: string, text: string) => request(`/api/sessions/${sessionId}/commands/run`, { method: "POST", body: JSON.stringify({ text }) }), respondToCommand: (sessionId: string, requestId: string, value: string) => request(`/api/sessions/${sessionId}/commands/respond`, { method: "POST", body: JSON.stringify({ requestId, value }) }), - close: (sessionId: string) => request<{ closed: true }>(`/api/sessions/${sessionId}/close`, { method: "POST" }), + stop: (sessionId: string) => request<{ stopped: true }>(`/api/sessions/${sessionId}/stop`, { method: "POST" }), }; export function sessionEvents(sessionId: string): WebSocket { diff --git a/src/client/src/components/Composer.ts b/src/client/src/components/Composer.ts index af57b6c..b7251e1 100644 --- a/src/client/src/components/Composer.ts +++ b/src/client/src/components/Composer.ts @@ -6,7 +6,7 @@ import { composerStyles } from "./shared"; export class Composer extends LitElement { @property({ type: Boolean }) disabled = false; @property({ attribute: false }) onSend?: (text: string) => void; - @property({ attribute: false }) onCloseSession?: () => void; + @property({ attribute: false }) onStopSession?: () => void; @state() private draft = ""; render() { @@ -25,7 +25,7 @@ export class Composer extends LitElement { placeholder="Message pi..." > - + `; } diff --git a/src/client/src/components/PiWebApp.ts b/src/client/src/components/PiWebApp.ts index 548b6e1..fdf9ade 100644 --- a/src/client/src/components/PiWebApp.ts +++ b/src/client/src/components/PiWebApp.ts @@ -107,7 +107,7 @@ export class PiWebApp extends LitElement { ${state.selectedSession ? html` - this.sessions.send(text)} .onCloseSession=${() => this.sessions.closeSession()}> + this.sessions.send(text)} .onStopSession=${() => this.sessions.stopSession()}> ${state.commandDialog ? html` this.sessions.respondToCommand(state.commandDialog!.requestId, value)} .onCancel=${() => this.sessions.cancelCommand()}>` : null} ` : html`
Select or start a session.
`} diff --git a/src/client/src/components/PromptEditor.ts b/src/client/src/components/PromptEditor.ts index 5299297..3a4289b 100644 --- a/src/client/src/components/PromptEditor.ts +++ b/src/client/src/components/PromptEditor.ts @@ -10,7 +10,7 @@ export class PromptEditor extends LitElement { @property() sessionId?: string; @property() cwd?: string; @property({ attribute: false }) onSend?: (text: string) => void; - @property({ attribute: false }) onCloseSession?: () => void; + @property({ attribute: false }) onStopSession?: () => void; @query("textarea") private textarea?: HTMLTextAreaElement; @state() private draft = ""; @state() private completions: CompletionItem[] = []; @@ -31,7 +31,7 @@ export class PromptEditor extends LitElement { this.pick(item)}> - + `; } diff --git a/src/client/src/controllers/sessionController.ts b/src/client/src/controllers/sessionController.ts index bf230f3..bd58ce0 100644 --- a/src/client/src/controllers/sessionController.ts +++ b/src/client/src/controllers/sessionController.ts @@ -88,11 +88,11 @@ export class SessionController { this.setState({ commandDialog: undefined }); } - async closeSession() { + async stopSession() { const session = this.getState().selectedSession; if (!session) return; try { - await api.close(session.id); + await api.stop(session.id); } catch (error) { this.setState({ error: String(error) }); } finally { diff --git a/src/server/index.ts b/src/server/index.ts index 667180e..54f1e2a 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -104,9 +104,9 @@ app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/abort", as return { aborted: true }; }); -app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/close", async (request) => { - sessions.close(request.params.sessionId); - return { closed: true }; +app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/stop", async (request) => { + sessions.stop(request.params.sessionId); + return { stopped: true }; }); app.get<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/events", { websocket: true }, (socket, request) => { diff --git a/src/server/sessions/piSessionService.ts b/src/server/sessions/piSessionService.ts index f98bd20..9298d45 100644 --- a/src/server/sessions/piSessionService.ts +++ b/src/server/sessions/piSessionService.ts @@ -108,11 +108,11 @@ export class PiSessionService { if (active) await active.runtime.session.abort(); } - close(sessionId: string): void { + stop(sessionId: string): void { const active = this.active.get(sessionId); if (!active) return; active.unsubscribe(); - void active.runtime.dispose(); + void active.runtime.session.abort().finally(() => active.runtime.dispose()); this.active.delete(sessionId); }