Skip to content

Commit 1317838

Browse files
committed
fix: gate typed chat stops
1 parent f699aeb commit 1317838

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎ui/src/pages/chat/chat-commands.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function currentSessionAccessSnapshot(
9595
};
9696
}
9797

98-
function requireChatSessionAction(
98+
export function requireChatSessionAction(
9999
host: ChatCommandHost,
100100
action: "abort" | "compact" | "reset",
101101
): boolean {

‎ui/src/pages/chat/chat-send-submit.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
getChatAttachmentDataUrl,
1010
releaseChatAttachmentPayloads,
1111
} from "./attachment-payload-store.ts";
12-
import { dispatchChatSlashCommand, shouldQueueLocalSlashCommand } from "./chat-commands.ts";
12+
import {
13+
dispatchChatSlashCommand,
14+
requireChatSessionAction,
15+
shouldQueueLocalSlashCommand,
16+
} from "./chat-commands.ts";
1317
import type { ChatState } from "./chat-history.ts";
1418
import {
1519
admitQueuedMessageForSession,
@@ -213,6 +217,9 @@ export async function handleSendChat(
213217
isChatStopCommand(message) &&
214218
(message.trim().startsWith("/") || hasAbortableSessionRun(host))
215219
) {
220+
if (!requireChatSessionAction(host, "abort")) {
221+
return;
222+
}
216223
if (messageOverride == null) {
217224
recordNonTranscriptInputHistory(host, message);
218225
}

‎ui/src/pages/chat/chat-send.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8688,6 +8688,28 @@ describe("handleAbortChat", () => {
86888688
},
86898689
);
86908690

8691+
it("blocks a typed stop before aborting when the operator lacks write scope", async () => {
8692+
const host = makeHost({
8693+
requestHandlers: {},
8694+
chatRunId: "run-main",
8695+
chatMessage: "/stop",
8696+
hello: {
8697+
type: "hello-ok",
8698+
protocol: 4,
8699+
auth: { role: "operator", scopes: ["operator.read"] },
8700+
features: { methods: ["chat.abort"] },
8701+
},
8702+
sessionKey: "agent:main",
8703+
});
8704+
8705+
await handleSendChat(host);
8706+
8707+
expect(host.request).not.toHaveBeenCalled();
8708+
expect(host.lastError).toBeTruthy();
8709+
expect(host.chatError).toBe(host.lastError);
8710+
expect(host.chatMessage).toBe("/stop");
8711+
});
8712+
86918713
it("queues the active run abort while disconnected", async () => {
86928714
const client = { request: vi.fn() } as unknown as NonNullable<ChatHost["client"]>;
86938715
const host = makeHost({

0 commit comments

Comments
 (0)