Skip to content

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

Rooms: let a busy-room send follow the steer setting, like one-to-one

koeriafd5173715fab
diff --git a/src/state/group-queue-actions.ts b/src/state/group-queue-actions.ts
new file mode 100644
index 0000000000..58d49a3f04
--- /dev/null
+++ b/src/state/group-queue-actions.ts
@@ -0,0 +1,53 @@
+// 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.
+import { t } from "../lib/i18n";
+
+import { api } from "./api";
+import type { Action } from "./store";
+
+type Send = {
+ /** Straight into the reducer, past this module's own actions. */
+ dispatch: (action: Action) => void;
+ /** Back through the wrapped dispatch, for notices. */
+ notice: (action: Action) => void;
+ showError: (error: unknown) => void;
+};
+
+export function cancelGroupQueued(
+ action: Extract<Action, { type: "cancelGroupQueued" }>,
+ send: Send,
+): void {
+ void api(`/api/groups/${action.groupId}/queue/${action.queueId}`, { method: "DELETE" })
+ .then(() => {
+ send.dispatch(action);
+ action.onCancelled?.();
+ })
+ .catch(send.showError);
+}
+
+export function steerGroupQueued(
+ action: Extract<Action, { type: "steerGroupQueued" }>,
+ send: Send,
+): void {
+ void api(`/api/groups/${action.groupId}/queue/${action.queueId}/steer`, {
+ method: "POST",
+ body: JSON.stringify({ threadId: action.threadId }),
+ })
+ .then((body) => {
+ if (body?.steered === true && Array.isArray(body.messages) && typeof body.threadId === "string") {
+ for (const message of body.messages) {
+ send.dispatch({ type: "messageAdded", threadId: body.threadId, message });
+ }
+ for (const queueId of body.queueIds ?? []) {
+ send.dispatch({ type: "consumePendingQueued", threadId: body.threadId, queueId });
+ }
+ } else if (body?.queued === true) {
+ 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);
+ action.onError?.();
+ });
+}
diff --git a/src/state/store.tsx b/src/state/store.tsx
index 5fb52586a1..776998b20c 100644
--- a/src/state/store.tsx
+++ b/src/state/store.tsx
@@ -1,5 +1,6 @@
import { cloudAsleep, onCloudPower } from "../lib/cloud-power";
import { api, ApiError, retryRequest, snapshotArrays } from "./api"; import { serverFetch } from "@/lib/relay-server";
+import { cancelGroupQueued, steerGroupQueued } from "./group-queue-actions";
import { capHeldInBackground, loadOlderPage, MESSAGE_PAGE_SIZE, olderThanHeld, reduceOlderMessages, reduceTrimHeldMessages } from "./message-history";
import { readChatSnapshot } from "./chat-snapshot";
import { followHeldTails, noteAppPagePatch } from "./held-tails";
@@ -2318,35 +2319,10 @@ export function StoreProvider({ children }: { children: ReactNode }) {
});
break;
case "cancelGroupQueued":
- void api(`/api/groups/${action.groupId}/queue/${action.queueId}`, { method: "DELETE" })
- .then(() => {
- rawDispatch(action);
- action.onCancelled?.();
- })
- .catch(showError);
+ cancelGroupQueued(action, { dispatch: rawDispatch, notice: wrapped, showError });
break;
case "steerGroupQueued":
- void api(`/api/groups/${action.groupId}/queue/${action.queueId}/steer`, {
- method: "POST",
- body: JSON.stringify({ threadId: action.threadId }),
- })
- .then((body) => {
- if (body?.steered === true && Array.isArray(body.messages) && typeof body.threadId === "string") {
- for (const message of body.messages) {
- rawDispatch({ type: "messageAdded", threadId: body.threadId, message });
- }
- for (const queueId of body.queueIds ?? []) {
- rawDispatch({ type: "consumePendingQueued", threadId: body.threadId, queueId });
- }
- } else if (body?.queued === true) {
- wrapped({ 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) => {
- showError(error);
- action.onError?.();
- });
+ steerGroupQueued(action, { dispatch: rawDispatch, notice: wrapped, showError });
break;
case "send": {
if (quizBeforeSend) persistCard(action.botId, quizBeforeSend.id, { dismissed: true });