Archived
Rename session close to stop
This commit is contained in:
@@ -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 }) }),
|
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 }) }),
|
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 }) }),
|
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 {
|
export function sessionEvents(sessionId: string): WebSocket {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { composerStyles } from "./shared";
|
|||||||
export class Composer extends LitElement {
|
export class Composer extends LitElement {
|
||||||
@property({ type: Boolean }) disabled = false;
|
@property({ type: Boolean }) disabled = false;
|
||||||
@property({ attribute: false }) onSend?: (text: string) => void;
|
@property({ attribute: false }) onSend?: (text: string) => void;
|
||||||
@property({ attribute: false }) onCloseSession?: () => void;
|
@property({ attribute: false }) onStopSession?: () => void;
|
||||||
@state() private draft = "";
|
@state() private draft = "";
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -25,7 +25,7 @@ export class Composer extends LitElement {
|
|||||||
placeholder="Message pi..."
|
placeholder="Message pi..."
|
||||||
></textarea>
|
></textarea>
|
||||||
<button ?disabled=${this.disabled} @click=${this.send}>Send</button>
|
<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>
|
</footer>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ export class PiWebApp extends LitElement {
|
|||||||
${state.selectedSession ? html`
|
${state.selectedSession ? html`
|
||||||
<status-bar .status=${state.status} .workspace=${state.selectedWorkspace}></status-bar>
|
<status-bar .status=${state.status} .workspace=${state.selectedWorkspace}></status-bar>
|
||||||
<chat-view .sessionId=${state.selectedSession.id} .messages=${state.messages}></chat-view>
|
<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}
|
${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>`}
|
` : html`<div class="empty">Select or start a session.</div>`}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export class PromptEditor extends LitElement {
|
|||||||
@property() sessionId?: string;
|
@property() sessionId?: string;
|
||||||
@property() cwd?: string;
|
@property() cwd?: string;
|
||||||
@property({ attribute: false }) onSend?: (text: string) => void;
|
@property({ attribute: false }) onSend?: (text: string) => void;
|
||||||
@property({ attribute: false }) onCloseSession?: () => void;
|
@property({ attribute: false }) onStopSession?: () => void;
|
||||||
@query("textarea") private textarea?: HTMLTextAreaElement;
|
@query("textarea") private textarea?: HTMLTextAreaElement;
|
||||||
@state() private draft = "";
|
@state() private draft = "";
|
||||||
@state() private completions: CompletionItem[] = [];
|
@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>
|
<autocomplete-menu .items=${this.completions} .selectedIndex=${this.selectedIndex} .onPick=${(item: CompletionItem) => this.pick(item)}></autocomplete-menu>
|
||||||
</div>
|
</div>
|
||||||
<button ?disabled=${this.disabled} @click=${this.send}>Send</button>
|
<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>
|
</footer>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,11 +88,11 @@ export class SessionController {
|
|||||||
this.setState({ commandDialog: undefined });
|
this.setState({ commandDialog: undefined });
|
||||||
}
|
}
|
||||||
|
|
||||||
async closeSession() {
|
async stopSession() {
|
||||||
const session = this.getState().selectedSession;
|
const session = this.getState().selectedSession;
|
||||||
if (!session) return;
|
if (!session) return;
|
||||||
try {
|
try {
|
||||||
await api.close(session.id);
|
await api.stop(session.id);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.setState({ error: String(error) });
|
this.setState({ error: String(error) });
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
+3
-3
@@ -104,9 +104,9 @@ app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/abort", as
|
|||||||
return { aborted: true };
|
return { aborted: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/close", async (request) => {
|
app.post<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/stop", async (request) => {
|
||||||
sessions.close(request.params.sessionId);
|
sessions.stop(request.params.sessionId);
|
||||||
return { closed: true };
|
return { stopped: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/events", { websocket: true }, (socket, request) => {
|
app.get<{ Params: { sessionId: string } }>("/api/sessions/:sessionId/events", { websocket: true }, (socket, request) => {
|
||||||
|
|||||||
@@ -108,11 +108,11 @@ export class PiSessionService {
|
|||||||
if (active) await active.runtime.session.abort();
|
if (active) await active.runtime.session.abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sessionId: string): void {
|
stop(sessionId: string): void {
|
||||||
const active = this.active.get(sessionId);
|
const active = this.active.get(sessionId);
|
||||||
if (!active) return;
|
if (!active) return;
|
||||||
active.unsubscribe();
|
active.unsubscribe();
|
||||||
void active.runtime.dispose();
|
void active.runtime.session.abort().finally(() => active.runtime.dispose());
|
||||||
this.active.delete(sessionId);
|
this.active.delete(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user