Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Rooms: Enter steers a busy room quietly, and only its own fresh queue head

milind-soniabb7a08e7506
diff --git a/src/components/Composer.tsx b/src/components/Composer.tsx
index 8a648502ae..43dbf4012d 100644
--- a/src/components/Composer.tsx
+++ b/src/components/Composer.tsx
@@ -526,7 +526,8 @@ export function Composer({
const stopInSlot = simpleDock && stoppable && !locked && !hasContent && !calling;
const callShown = singleRow || !hasContent || busy || Boolean(!group && bot?.waitingForTeammates) || calling;
const slot = slotColors(bot?.color, Boolean(group));
- // A bot at work: Enter does the chosen follow-up and Ctrl/⌘ with it the other one. A room joins in when its speaking engine can steer.
+ // A bot at work: Enter does the chosen follow-up and Ctrl/⌘ with it the other one. A room joins in when its speaking engine can steer,
+ // without the send menu: a room's turn has no restart.
const followUpFor = (alternate: boolean) => resolveFollowUp({ running: busy && (group ? roomSteers : Boolean(bot)), alternate, preferred: followUpDefault, canSteer }) ?? undefined;
const steersNow = followUpFor(false) === "steer";
const sendNames = fork.command ? { label: t("composer.command.forkDesc"), title: t("composer.command.forkDesc") }
@@ -964,7 +965,7 @@ export function Composer({
{hasContent && !locked && (
<ComposerSendButton compact={simpleDock} waits={!fork.command && busy && !steersNow} label={sendNames.label} title={sendNames.title} look={slot.button}
disabled={attachmentPending} onSend={(alternate) => send(followUpFor(alternate))} onChoose={send}
- menu={!fork.command && followUpFor(false) ? { choices: followUpChoices(followUpDefault, canSteer), name: busyName, sendKey: sendLabel, alternateKey: alternateSendLabel(sendKey) } : undefined} />
+ menu={!fork.command && !group && followUpFor(false) ? { choices: followUpChoices(followUpDefault, canSteer), name: busyName, sendKey: sendLabel, alternateKey: alternateSendLabel(sendKey) } : undefined} />
)}
</div>
</div>
diff --git a/src/components/send-key.test.ts b/src/components/send-key.test.ts
index 726472eb31..02d2dba920 100644
--- a/src/components/send-key.test.ts
+++ b/src/components/send-key.test.ts
@@ -358,16 +358,28 @@ describe("a message sent while a one-to-one bot works", () => {
]);
});
- it("leaves an idle bot and a room's queue as they were", () => {
+ it("leaves an idle bot as it was", () => {
fixture.instances = [steers];
render(createElement(Composer, { bot }));
type(textarea(), "idle");
press(textarea(), { ctrlKey: true });
expect(chooser()).toBeNull();
+ expect(sends().map((action) => [action.type, "followUp" in action])).toEqual([["send", false]]);
+ });
+
+ it("lets a busy room follow the same setting with Enter and Ctrl+Enter, without the send menu", () => {
+ fixture.instances = [steers];
render(createElement(Composer, { group: { ...room, busyBotId: "bot" }, members: [bot] }));
- type(textarea(), "room");
+ type(textarea(), "steer");
+ press(textarea());
+ type(textarea(), "queue");
press(textarea(), { ctrlKey: true });
expect(chooser()).toBeNull();
- expect(sends().map((action) => [action.type, "followUp" in action])).toEqual([["send", false], ["sendGroup", false]]);
+ expect(sends().map((action) => [action.type, (action as { followUp?: string }).followUp])).toEqual([["sendGroup", "steer"], ["sendGroup", "queue"]]);
+ fixture.instances = [cannotSteer];
+ render(createElement(Composer, { group: { ...room, busyBotId: "bot" }, members: [bot] }));
+ type(textarea(), "held");
+ press(textarea());
+ expect(sends().at(-1)).toMatchObject({ type: "sendGroup", followUp: "queue" });
});
});
diff --git a/src/state/group-queue-actions.ts b/src/state/group-queue-actions.ts
index 58d49a3f04..c499a1d0ef 100644
--- a/src/state/group-queue-actions.ts
+++ b/src/state/group-queue-actions.ts
@@ -1,5 +1,6 @@
// Room queue actions that talk to the server, kept out of the store file: cancelling a queued room message
-// and steering the queue head into the running room turn.
+// and steering the queue head into the running room turn. A quiet steer (Enter in a busy room) says nothing
+// when it cannot steer: the message just stays queued.
import { t } from "../lib/i18n";
import { api } from "./api";
@@ -41,13 +42,13 @@ export function steerGroupQueued(
for (const queueId of body.queueIds ?? []) {
send.dispatch({ type: "consumePendingQueued", threadId: body.threadId, queueId });
}
- } else if (body?.queued === true) {
+ } else if (body?.queued === true && !action.quiet) {
send.notice({ type: "notice", notice: body.blockedBy === "images" ? { kind: "steer-images", botName: null, threadId: body.threadId } : { kind: "note", botName: null, text: t("composer.queued.roomSteerHeld"), threadId: body.threadId } });
}
action.onSettled?.();
})
.catch((error) => {
- send.showError(error);
+ if (!action.quiet) send.showError(error);
action.onError?.();
});
}
diff --git a/src/state/store.test.ts b/src/state/store.test.ts
index 25b3eec42b..9b798626b0 100644
--- a/src/state/store.test.ts
+++ b/src/state/store.test.ts
@@ -3067,6 +3067,40 @@ describe("restoring the open conversation", () => {
expect(steered).toEqual([]);
});
+ it("a room's Enter steer says nothing when it cannot steer, and never reaches past a message queued ahead", async () => {
+ const { stream } = await boot();
+ stream.send(hello());
+ await settle();
+ const steered: string[] = [];
+ let queueId = "q-refused";
+ vi.stubGlobal("fetch", (path: string) => {
+ const clean = path.replace(/\?since=[^&]*$/, "");
+ if (clean === "/api/groups/room-1/messages") {
+ return Promise.resolve(new Response(JSON.stringify({ ok: true, queued: true, threadId: "room-thread", queueId })));
+ }
+ steered.push(clean);
+ if (clean === "/api/groups/room-1/queue/q-refused/steer") {
+ return Promise.resolve(new Response(JSON.stringify({ error: "only the first queued message can steer" }), { status: 409 }));
+ }
+ return Promise.resolve(new Response(JSON.stringify({ ok: true, queued: true, threadId: "room-thread" })));
+ });
+
+ flushSync(() => dispatch({ type: "sendGroup", groupId: "room-1", text: "first", sendId: "s-1", followUp: "steer" }));
+ await settle();
+ expect(steered).toEqual(["/api/groups/room-1/queue/q-refused/steer"]);
+ expect(seen.error).toBeFalsy();
+ expect(seen.notice).toBeNull();
+
+ steered.length = 0;
+ queueId = "q-behind";
+ flushSync(() => dispatch({ type: "sendGroup", groupId: "room-1", text: "second", sendId: "s-2", followUp: "steer" }));
+ await settle();
+ expect(steered, "q-refused is still queued ahead of it").toEqual([]);
+ expect(seen.pendingQueued["room-thread"]?.map((entry) => entry.queueId)).toEqual(["q-refused", "q-behind"]);
+ expect(seen.error).toBeFalsy();
+ expect(seen.notice).toBeNull();
+ });
+
it("a Steer send that stays queued because of pictures says why", async () => {
const { stream } = await boot();
stream.send(hello());
diff --git a/src/state/store.tsx b/src/state/store.tsx
index 623d767581..40058272fa 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -674,7 +674,7 @@ export type Action =
| { type: "cancelQueued"; botId: string; queueId: string; threadId?: string; onCancelled?: () => void }
| { type: "steerQueued"; botId: string; queueId: string; threadId?: string; onError?: () => void; onSettled?: () => void }
| { type: "cancelGroupQueued"; groupId: string; threadId: string; queueId: string; onCancelled?: () => void }
- | { type: "steerGroupQueued"; groupId: string; queueId: string; threadId?: string; onError?: () => void; onSettled?: () => void }
+ | { type: "steerGroupQueued"; groupId: string; queueId: string; threadId?: string; quiet?: boolean; onError?: () => void; onSettled?: () => void }
| { type: "editMessage"; botId: string; messageId: string; text: string; threadId?: string; sendId?: string }
| { type: "switchBranch"; botId: string; messageId: string; threadId?: string }
| { type: "threadActive"; threadId: string; activeLeafId: string }
@@ -2609,16 +2609,11 @@ export function StoreProvider({ children }: { children: ReactNode }) {
queueId: body.queueId,
text: action.text,
});
- // The chosen "Sending while a bot works" applies in rooms too: hand the fresh queue head
- // to the running turn. A driver that cannot steer keeps the queue and says so.
- if (action.followUp === "steer") {
- wrapped({
- type: "steerGroupQueued",
- groupId: action.groupId,
- threadId: body.threadId,
- queueId: body.queueId,
- onSettled: () => {},
- });
+ // "Sending while a bot works" applies in rooms too: a fresh queue head is handed to the running
+ // turn, quietly. One that cannot steer (a message ahead of it, the turn just ended) stays queued.
+ const ahead = (stateRef.current.pendingQueued[body.threadId] ?? []).some((entry) => entry.queueId !== body.queueId);
+ if (action.followUp === "steer" && !ahead) {
+ wrapped({ type: "steerGroupQueued", groupId: action.groupId, threadId: body.threadId, queueId: body.queueId, quiet: true });
}
}
})