Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Send typed card answers and the card PATCH refusal through refusalText
AdityaUmale9ee684e0f2fc
diff --git a/server/index.ts b/server/index.tsindex cf40752f13..a4f0bff299 100644--- a/server/index.ts+++ b/server/index.ts@@ -80,7 +80,7 @@ import { groupTurnCwd } from "./room-cwd.ts";import { RoomTurnDeadline, RoomTurnStallRegistry, effectiveRoomTurnTimeoutMinutes, parseConversationTurnTimeout, roomTurnTimeoutMessage } from "./room-turn-timeout.ts";import { roomTurnEnd, type RoomClaimEnd } from "./room-turn-end.ts";import { applyHoldDirective, classifyHoldDirective, heldMemberLine, rememberHeldMessage, stopWordPlacement } from "./room-holds.ts";-import { refusalBody, USER_ERROR, userError, userErrorFields, userErrorThrown } from "./user-errors.ts";+import { refusalBody, refusalText, USER_ERROR, userError, userErrorFields, userErrorThrown } from "./user-errors.ts";import { chatNotice, failedNoticeTool, noticeTool, runtimeNoticeTool } from "./chat-notices.ts";import type { ServerErrorBody } from "../shared/server-text.ts";import { emailSignInRoute } from "./routes/email-sign-in.ts";@@ -14846,7 +14846,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {return json(res, 409, { error: "request cards must be answered through the approval endpoint" });}const cloudRefusal = CLOUD_HOME && body.answered !== undefined && auth.kind === "session" ? cloudCardRefusal(auth) : null;- if (cloudRefusal) return json(res, 403, { error: cloudRefusal });+ if (cloudRefusal) return json(res, 403, refusalText(cloudRefusal));if (Object.keys(body).some((key) => key !== "answered" && key !== "dismissed" && key !== "threadId")) {return json(res, 400, { error: "only answered and dismissed may be changed" });}diff --git a/server/routes/bot-messages.test.ts b/server/routes/bot-messages.test.tsindex 36e4c373e5..5cb25e9ad3 100644--- a/server/routes/bot-messages.test.ts+++ b/server/routes/bot-messages.test.ts@@ -17,6 +17,7 @@ import { acceptedSendMatch, sendFingerprint, SendSequencer } from "../send-idempimport { _queuedCount, drainSteeredMessages, queuedSteeredMessage, queueSteeredMessage } from "../steer-queue.ts";import { Store, type Message } from "../store.ts";import { typedWords } from "../typed-sends.ts";+import { USER_ERROR } from "../user-errors.ts";import { createBotMessageRoutes, type BotMessageRouteDeps } from "./bot-messages.ts";import { dispatchRoutes } from "./table.ts";@@ -547,6 +548,15 @@ describe("POST /api/bots/:id/messages with widgetAction", () => {});});+describe("a typed answer to a card the server refuses", () => {+ it("returns the refusal with its language-pack key, like a pressed card's", async () => {+ const error = USER_ERROR["serverError.card.cloudOwnerOnly"];+ const { threadId, post, sent } = await fixture({ typedCardAnswer: async () => ({ status: 403, error }) });+ expect(await post({ threadId, text: "allow" })).toEqual({ status: 403, body: { error, errorKey: "serverError.card.cloudOwnerOnly" } });+ expect(sent()).toEqual([]);+ });+});+describe("POST /api/bots/:id/messages/guarded with a reaction another app relayed", () => {const relay = (threadId: string, replyToId: string | undefined, leaf: string | null, patch: Record<string, unknown> = {}) => ({threadId, sendId: SEND, reaction: "+1", replyToId, expectedActiveLeafId: leaf, expectedApprovalMode: "ask",diff --git a/server/routes/bot-messages.ts b/server/routes/bot-messages.tsindex 42933a05ab..9eab2d1d3c 100644--- a/server/routes/bot-messages.ts+++ b/server/routes/bot-messages.ts@@ -281,7 +281,7 @@ export function createBotMessageRoutes(deps: BotMessageRouteDeps): RouteHandlerconst passedBack = !guarded && !press && !appSent && !pointed && target ? deps.inboxReply?.(auth, threadId, target.id, text, { sendId, sender: messageSender(auth) }) : null;const typedAnswer = passedBack || guarded || press || appSent || pointed ? null : await deps.typedCardAnswer?.(auth, threadId, text, target, { sendId, sender: messageSender(auth) });const answeredBack = passedBack ?? typedAnswer;- if (answeredBack) return json(res, answeredBack.status, answeredBack.message ? { ok: true, threadId, message: answeredBack.message } : { error: answeredBack.error });+ if (answeredBack) return json(res, answeredBack.status, answeredBack.message ? { ok: true, threadId, message: answeredBack.message } : refusalText(answeredBack.error ?? ""));// Only a real press or reaction, or an app's own words, marks the reply; a typed reply to the same row never does, whatever its words.const records = press && target ? pressRecords(bot, press.action) : null;const replyTo: ReplyTarget | undefined = press && target ? { ...target, widgetPress: { label: press.label, action: press.action, ...(records ? { records } : {}) } }