Skip to content

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

6.5 KB
Raw Blame

Reactions

A person reacts to a message from the chat's action row. A πŸ‘ on a bot's message is their reply to it ("yes, go ahead") and reaches that bot at once. A πŸ‘Ž, like ❀️ πŸ˜‚ πŸŽ‰ πŸ‘€, posts nothing and starts no turn: the bot reads it once, in its next turn: in a 1:1 conversation ahead of the person's next message, in a room in its next turn in any of the room's conversations. A πŸ‘Ž still answers an open card (deny, or no) and a line in a person's inbox. The rule lives in server/reactions.ts, the route in server/routes/reactions.ts, and a πŸ‘ reply goes the way a late answer to a question card goes (server/person-replies.ts).

Server

pnpm exec vitest run server/reactions.e2e.test.ts

The first test starts the launcher-managed fixture with scripted fake-engine replies. The bot asks "I drafted the email to Sam. Shall I send it?"; a πŸ‘ through POST /api/threads/ID/messages/ID/reactions answers delivery: "started", records { emoji: "πŸ‘", by: "user" } on that message, and adds a user line { text: "πŸ‘", reaction: "πŸ‘", replyToId } that the bot's next turn answers ("Sent it to Sam."). The engine's prompt for that turn says the person reacted πŸ‘ to its earlier message, that πŸ‘ means yes, go ahead when that message asked something or offered to do something, and only "got it" (no new work) when it just told them something, and quotes the message as untrusted data. A second πŸ‘ with on: true, or taking the πŸ‘ back and setting it again, delivers nothing: the bot already has that answer. A ❀️ on the reply answers delivery: "noted", starts no turn, and opens the next typed turn's prompt with (User reacted ❀️ to your message β€œSent it to Sam.”.). Changing the question's πŸ‘ to πŸ‘Ž answers delivery: "noted", adds no line and starts no turn; the person's next typed message opens with (User reacted πŸ‘Ž to your message β€œI drafted the email to Sam. Shall I send it?”.) exactly once, and the turn after that does not repeat it. The system prompt tells the bot to ask a plain yes or no in one sentence instead of a widget, that a πŸ‘ comes back as the reply and a πŸ‘Ž as a note with the next message.

Another test reacts πŸ‘ to a new bot's greeting: the bot answers, and the conversation keeps its untitled name instead of being named "πŸ‘".

The card test holds a turn open, raises two Bash approvals through the fake engine's permission broker and answers them with πŸ‘ and πŸ‘Ž on their cards: the engine receives allow and deny, and each card records answeredBy: { kind: "loopback", via: "reaction" }.

The room test runs a room: a πŸ‘ on Otter's question adds the room line @Otter: πŸ‘ and Otter answers; the room's conversation window shows the line as User: [reacted πŸ‘ to Otter: β€œShall I post the launch note?”]. After a πŸŽ‰ on Otter's reply, Otter's next turn opens with (User reacted πŸŽ‰ to your message β€œPosted it.”.) once, and Otter's own lines carry no reaction marks in the transcript it reads (other members still see (User reacted πŸŽ‰) under them). A πŸ‘Ž on that line adds no line and starts no turn, and reaches Otter's next turn in another of the room's threads, once. These room notes are kept in memory: a restart drops the ones not yet told.

Evidence is written beside the fixture's server log as <server-log>.reactions.json, <server-log>.reaction-cards.json and <server-log>.reaction-room.json.

On a workspace several people share, each person reacts as their own key:

pnpm exec vitest run server/bot-visibility.e2e.test.ts -t "reaction their own"

Ada's and Bob's πŸ‘ sit side by side with their names, Ada's πŸ‘Ž replaces only her own, GET /api/auth/session returns each session's reactor key, the two πŸ‘ replies reach the bot attributed to the person who reacted, and Ada's πŸ‘Ž adds no line. The change streams to Bob, who sees the conversation; a reaction in a conversation Bob cannot see streams to Ada and never to him.

Renderer

Launch the headless chat UI, as in Chat UI, driven headlessly, with two scripted replies:

FAKE_CLAUDE_REPLIES='["I drafted the email to Sam about Friday. Shall I send it?","Sent it to Sam."]' \
FAKE_CLAUDE_REPLY_STATE=/tmp/reactions-reply-state \
  node --experimental-strip-types scripts/control-omb.ts ui launch --tool-calls '[]'

Then, with the printed handle:

H=/tmp/openmausbot-verify-data-XXXXXX/ui.json
pnpm control:omb ui type --ui $H --name "Message Pepper" --text "Draft an email to Sam about Friday."
pnpm control:omb ui press --ui $H --keys Enter
pnpm control:omb ui wait-settle --ui $H --timeout 60
pnpm control:omb ui snapshot --ui $H --interactive

The question's action row holds Add reaction; the snapshot lists one per bot message, so take the question's @eN ref. The row shows on hover or keyboard focus; hover it first with ui eval (a pointerenter with pointerType: "mouse" on its [data-message-row]), then:

pnpm control:omb ui click --ui $H --ref @eN
pnpm control:omb ui screenshot --ui $H --out .omb-scratch/verify-evidence/reactions-open.png
pnpm control:omb ui click --ui $H --name "Thumbs up: yes, go ahead"
pnpm control:omb ui wait-settle --ui $H --timeout 60
pnpm control:omb ui snapshot --ui $H
pnpm control:omb ui console --ui $H

Expected: the open row is a toolbar named Reactions with six toggle buttons, Thumbs up: yes, go ahead first and focused, then Thumbs down. After the click the question has a group Reactions holding Thumbs up: yes, go ahead: You, no πŸ‘ bubble is drawn, and the bot's next message Sent it to Sam. follows by itself. From the keyboard, Enter on a focused Add reaction opens the row, Arrow keys move, Enter chooses and focus returns to the button. The console has no error entries.

The reaction row open over a bot's question

The question with a πŸ‘ under it and the bot's reply after it

The components themselves:

pnpm exec vitest run src/components/Reactions.test.ts src/components/Reactions.shared.test.ts src/lib/activity-runs.test.ts

These mount the real components: the Add reaction button opens a toolbar of six labelled toggle buttons, Arrow keys, Home and End move between them, Escape closes it and returns focus to the button, and a choice is shown at once and sent with on. Chips list each reaction once with its count and who chose it; a viewer who cannot write in the conversation gets labels, not buttons. A reaction's own line draws no bubble.