Rename session close to stop

This commit is contained in:
Federico Jaramillo Martinez
2026-05-07 13:05:32 +02:00
parent ad05497319
commit fa55723246
7 changed files with 13 additions and 13 deletions
+1 -1
View File
@@ -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<CommandResult>(`/api/sessions/${sessionId}/commands/run`, { method: "POST", body: JSON.stringify({ text }) }),
respondToCommand: (sessionId: string, requestId: string, value: string) => request<CommandResult>(`/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 {
+2 -2
View File
@@ -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..."
></textarea>
<button ?disabled=${this.disabled} @click=${this.send}>Send</button>
<button ?disabled=${this.disabled} @click=${() => this.onCloseSession?.()}>Close</button>
<button ?disabled=${this.disabled} @click=${() => this.onStopSession?.()}>Stop session</button>
</footer>
`;
}
+1 -1
View File
@@ -107,7 +107,7 @@ export class PiWebApp extends LitElement {
${state.selectedSession ? html`
<status-bar .status=${state.status} .workspace=${state.selectedWorkspace}></status-bar>
<chat-view .sessionId=${state.selectedSession.id} .messages=${state.messages}></chat-view>
<prompt-editor .sessionId=${state.selectedSession.id} .cwd=${state.selectedWorkspace?.path} .onSend=${(text: string) => this.sessions.send(text)} .onCloseSession=${() => this.sessions.closeSession()}></prompt-editor>
<prompt-editor .sessionId=${state.selectedSession.id} .cwd=${state.selectedWorkspace?.path} .onSend=${(text: string) => this.sessions.send(text)} .onStopSession=${() => this.sessions.stopSession()}></prompt-editor>
${state.commandDialog ? html`<command-picker .title=${state.commandDialog.title} .options=${state.commandDialog.options} .onPick=${(value: string) => this.sessions.respondToCommand(state.commandDialog!.requestId, value)} .onCancel=${() => this.sessions.cancelCommand()}></command-picker>` : null}
` : html`<div class="empty">Select or start a session.</div>`}
</main>
+2 -2
View File
@@ -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 {
<autocomplete-menu .items=${this.completions} .selectedIndex=${this.selectedIndex} .onPick=${(item: CompletionItem) => this.pick(item)}></autocomplete-menu>
</div>
<button ?disabled=${this.disabled} @click=${this.send}>Send</button>
<button ?disabled=${this.disabled} title="Stop this session runtime on the server" @click=${() => this.onCloseSession?.()}>Stop</button>
<button ?disabled=${this.disabled} title="Stop only this Pi session from continuing" @click=${() => this.onStopSession?.()}>Stop session</button>
</footer>
`;
}
@@ -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 {
+3 -3
View File
@@ -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) => {
+2 -2
View File
@@ -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);
}