Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(acp): stream Cursor's failure line only once later words release it
Absterrg09cd3a660f012
diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.tsindex 5849949e48..1508e692f7 100644--- a/server/drivers/acp/core.ts+++ b/server/drivers/acp/core.ts@@ -842,12 +842,12 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>if (support.resendsReasoningReply && messageId && messageId === current.state.textMessageId&& isHermesReasoningReplay(delta, current.state.text)) break;current.state.textMessageId = messageId;- receiveText(current.state, delta, support.replyFailure);+ const streamed = receiveText(current.state, delta, support.replyFailure);const trimmed = current.state.text.trimStart();- if (!trimmed.startsWith("<SYSTEM_MESSAGE") &&+ if (streamed && !trimmed.startsWith("<SYSTEM_MESSAGE") &&!trimmed.startsWith("The following is a <SYSTEM_MESSAGE") &&!trimmed.startsWith("<SYSTEM_NOTIFICATION")) {- emit({ ...base(threadId, current.turnId), type: "content.delta", streamKind: "assistant_text", delta });+ emit({ ...base(threadId, current.turnId), type: "content.delta", streamKind: "assistant_text", delta: streamed });}}break;diff --git a/server/drivers/acp/cursor.test.ts b/server/drivers/acp/cursor.test.tsindex 6d5d1bf9e6..481f71ee30 100644--- a/server/drivers/acp/cursor.test.ts+++ b/server/drivers/acp/cursor.test.ts@@ -748,7 +748,8 @@ describe("CursorAgentDriver", () => {await instance.adapter.sendTurn({ threadId, text: "go" });const done = await recorder.until((e) => e.type === "turn.completed");const replies = recorder.events.flatMap((e) => e.type === "item.completed" && e.itemType === "assistant_text" ? [e.text] : []);- return { done, replies, errors: recorder.events.filter((e) => e.type === "runtime.error") };+ const streamed = recorder.events.flatMap((e) => e.type === "content.delta" && e.streamKind === "assistant_text" ? [e.delta] : []).join("");+ return { done, replies, streamed, errors: recorder.events.filter((e) => e.type === "runtime.error") };} finally {recorder.stop();await instance.dispose();@@ -761,17 +762,19 @@ describe("CursorAgentDriver", () => {{ sessionUpdate: "tool_call_update", toolCallId: "watch-1", status: "completed" },];- it("fails the turn when a tool call follows the failure line, and never sends the line as a reply", async () => {- const { done, replies, errors } = await scripted("t-cursor-503-watching", [text("\n\nError: RetriableError: [unavailable] HTTP 503"), ...watching]);+ it("fails the turn when a tool call follows the failure line, and never streams or sends the line as a reply", async () => {+ const { done, replies, streamed, errors } = await scripted("t-cursor-503-watching", [text("\n\nError: RetriableError: [unavailable] HTTP 503"), ...watching]);expect(done).toMatchObject({ ok: false, stopReason: "rpc_error" });expect(replies.some((reply) => reply.includes("RetriableError"))).toBe(false);+ expect(streamed).not.toContain("RetriableError");expect(errors).toEqual([expect.objectContaining({ message: expect.stringMatching(/^Cursor had a temporary server problem \(HTTP 503/) })]);});it("puts the line back in the reply when the agent goes on writing after it", async () => {const line = "\n\nError: RetriableError: [unavailable] HTTP 503";- const { done, replies, errors } = await scripted("t-cursor-503-went-on", [text(line), ...watching, text(" Retried, and it went through.")]);+ const { done, replies, streamed, errors } = await scripted("t-cursor-503-went-on", [text(line), ...watching, text(" Retried, and it went through.")]);expect(done).toMatchObject({ ok: true, stopReason: null });+ expect(streamed.endsWith(`${line} Retried, and it went through.`)).toBe(true);expect(replies.at(-1)).toBe("Error: RetriableError: [unavailable] HTTP 503 Retried, and it went through.");expect(errors).toEqual([]);});diff --git a/server/drivers/acp/turn-state.ts b/server/drivers/acp/turn-state.tsindex 95026c6323..2bad904fe2 100644--- a/server/drivers/acp/turn-state.ts+++ b/server/drivers/acp/turn-state.ts@@ -82,13 +82,15 @@ export function trackRunningTool(current: AcpTurn, update: { toolCallId?: unknowelse if (status === "pending" || status === "in_progress") current.runningTools.add(update.toolCallId);}-/** Adds a text chunk to the unsent reply. A chunk `read` names a failed model call is held back instead, so no flush- * sends it; later words return it to the reply, as it was not the agent's last. */-export function receiveText(state: AcpTurn["state"], delta: string, read: AcpDriverHooks["replyFailure"]): void {- if (state.failedChunk) state.text += state.failedChunk.chunk;+/** Adds a text chunk to the unsent reply and gives the text to stream. A chunk `read` names a failed model call is held+ * back from both, so no flush sends it; later words return it ahead of themselves, as it was not the agent's last. */+export function receiveText(state: AcpTurn["state"], delta: string, read: AcpDriverHooks["replyFailure"]): string {+ const released = state.failedChunk?.chunk ?? "";const failure = read?.(delta) ?? null;state.failedChunk = failure === null ? null : { chunk: delta, failure };- if (failure === null) state.text += delta;+ const received = failure === null ? released + delta : released;+ state.text += received;+ return received;}export interface AcpTurnEnd {