Skip to content

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

Merge remote-tracking branch 'upstream/main' into fix/cursor-reply-failure-6706

Absterrg09fc80ec7a356
diff --cc server/drivers/acp/core.ts
index 1508e692f7,8c02a60a55..f41a5c5203
--- a/server/drivers/acp/core.ts
+++ b/server/drivers/acp/core.ts
@@@ -66,7 -67,8 +66,8 @@@ import { commandSummary, toolDetailPrev
import { acpToolEndEvents } from "./tool-items.ts";
import { AcpHost } from "./host.ts"; import { SignInRequests, type AcpDriverHooks } from "./driver-hooks.ts";
import { exitBeforeResult } from "./exit-report.ts"; import { readNodeVersion } from "./node-version.ts";
- import { endTurn, receiveText, trackRunningTool, type AcpAskFinish, type AcpSession, type AcpTurn } from "./turn-state.ts";
+ import { decodeAcpConfig } from "./config-decode.ts";
-import { endTurn, trackAssistantImage, trackAssistantWords, trackThoughtAfterTool, trackRunningTool, trackToolEndShown, type AcpAskFinish, type AcpSession, type AcpTurn } from "./turn-state.ts";
++import { endTurn, receiveText, trackAssistantImage, trackAssistantWords, trackThoughtAfterTool, trackRunningTool, trackToolEndShown, type AcpAskFinish, type AcpSession, type AcpTurn } from "./turn-state.ts";
import { recoveryPromptFor } from "../../resume-recovery.ts";
import { noticeFailure } from "../../chat-notices.ts";
import { armIdleClose, engineIdleMs, sessionIdlePolicy, stopIdleClose } from "../session-idle.ts";
@@@ -1080,7 -1075,7 +1074,7 @@@ export function createAcpDriver(support
): Promise<any> =>
signIn.refused(session.host) ?? session.acp.request(method, params, timeoutMs, receive, idleMs, idleMessage);
- const state: AcpTurn["state"] = { settled: false, promptSent: false, text: "", textMessageId: null, producedItem: false, repliedText: false, startupActivity: false, stopped: false, usagePeak: null, usageLast: null, usageCompacted: false, failedChunk: null, cancelling: false };
- const state: AcpTurn["state"] = { settled: false, promptSent: false, text: "", textMessageId: null, producedItem: false, repliedText: false, startupActivity: false, stopped: false, toolsSinceShown: false, thoughtSinceTool: false, usagePeak: null, usageLast: null, usageCompacted: false, cancelling: false };
++ const state: AcpTurn["state"] = { settled: false, promptSent: false, text: "", textMessageId: null, producedItem: false, repliedText: false, startupActivity: false, stopped: false, toolsSinceShown: false, thoughtSinceTool: false, usagePeak: null, usageLast: null, usageCompacted: false, failedChunk: null, cancelling: false };
let acknowledge = () => {};
let rejectStartup = (_error: TurnNotStartedError) => {};
const startupAck = turn.startupRecovery ? new Promise<{ turnId: string }>((resolve, reject) => {
diff --cc server/drivers/acp/turn-state.ts
index 2bad904fe2,320949af59..dd4e81446e
--- a/server/drivers/acp/turn-state.ts
+++ b/server/drivers/acp/turn-state.ts
@@@ -82,17 -83,33 +86,44 @@@ export function trackRunningTool(curren
else if (status === "pending" || status === "in_progress") current.runningTools.add(update.toolCallId);
}
+/** 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 };
+ const received = failure === null ? released + delta : released;
+ state.text += received;
+ return received;
+}
+
+ /** Words the person can see: the turn has replied, and the wordless window after a tool is closed. */
+ export function trackAssistantWords(state: AcpTurn["state"]): void {
+ state.producedItem = true;
+ state.repliedText = true;
+ state.toolsSinceShown = false;
+ state.thoughtSinceTool = false;
+ }
+
+ /** An assistant image is itself a reply the person sees, so it closes the wordless window after a tool. */
+ export function trackAssistantImage(state: AcpTurn["state"]): void {
+ state.producedItem = true;
+ state.toolsSinceShown = false;
+ state.thoughtSinceTool = false;
+ }
+
+ /** A tool end that is actually emitted opens the wordless window; a repeat that names an already-ended tool emits nothing. */
+ export function trackToolEndShown(state: AcpTurn["state"]): void {
+ state.producedItem = true;
+ state.toolsSinceShown = true;
+ state.thoughtSinceTool = false;
+ }
+
+ /** Reasoning in the wordless window: if no reply lands after it, the turn ends midstream and the person sees nothing. */
+ export function trackThoughtAfterTool(state: AcpTurn["state"]): void {
+ if (state.toolsSinceShown) state.thoughtSinceTool = true;
+ }
+
export interface AcpTurnEnd {
ok: boolean;
stopReason: string | null;