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 }) }),
|
||||
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 {
|
||||
|
||||
@@ -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>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user