Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(skill-burger): stop replay when an app result fails
Afloatd31254ea47a1
diff --git a/server/skill-burger/app-failures.test.ts b/server/skill-burger/app-failures.test.tsnew file mode 100644index 0000000000..632d99ee34--- /dev/null+++ b/server/skill-burger/app-failures.test.ts@@ -0,0 +1,56 @@+import { expect, it } from "vitest";++import { workflowSchema } from "../../shared/skill-burger/format.ts";+import { annotateFailedCall } from "../connector-scope-hint.ts";+import { createExecutors } from "./executors.ts";+import { startRun, type RunState } from "./runner.ts";++const slug = "GMAIL_CREATE_EMAIL_DRAFT";+const failure = "The recipient address is invalid";+const frame = (body: unknown) => ({ jsonrpc: "2.0", id: 1, result: { content: [{ type: "text", text: typeof body === "string" ? body : JSON.stringify(body) }] } });+const batch = (response: unknown) => frame({ successful: true, data: { results: [{ tool_slug: slug, response }] } });+const withHint = batch({ successful: false, error: failure, data: {} });+annotateFailedCall(withHint, /recipient address is invalid/, () => "Check the recipient before trying again.", [slug]);++async function replay(answer: Record<string, unknown>) {+ const calls: string[] = [];+ const saved: RunState[] = [];+ const workflow = workflowSchema.parse({+ version: 1, summary: "Create a draft and report completion", args: {},+ steps: [+ { id: "draft", kind: "app", label: "Create the draft", app: "gmail", tool: slug, args: { recipient_email: "[email protected]", subject: "Report", body: "Thanks" } },+ { id: "notify", kind: "app", label: "Post completion", app: "slack", tool: "SLACK_SEND_MESSAGE", args: { channel: "C123456", text: "The draft is ready" } },+ ],+ });+ const result = await startRun({ name: "draft", botId: "b", threadId: "t", sha256: "test", workflow }, {+ exec: createExecutors({ botId: "b", cwd: ".", internal: async (_kind, _path, body) => {+ const tool = (body as { params: { arguments: { tools: Array<{ tool_slug: string }> } } }).params.arguments.tools[0]!.tool_slug;+ calls.push(tool);+ return { ok: true, body: tool === slug ? answer : frame({ successful: true, data: { sent: true } }) };+ } }),+ events: { started() {}, ended() {} }, save: (state) => saved.push(structuredClone(state)),+ });+ return { result, calls, saved };+}++it.each([+ { name: "a direct tool failure", answer: frame({ successful: false, error: failure, data: {} }), error: failure },+ { name: "a failure inside a successful batch", answer: batch({ successful: false, error: failure, data: {} }), error: failure },+ { name: "a failure with the connector's appended hint", answer: withHint, error: failure },+ { name: "a shortened result without usable data", answer: batch({ successful: true, data_preview: { id: "preview" } }), error: "too large" },+])("stops before the next action on $name", async ({ answer, error }) => {+ const { result, calls, saved } = await replay(answer);+ expect(result).toMatchObject({ ok: false, error: { type: "step_failed", step: "draft", message: expect.stringContaining(error) } });+ expect(calls).toEqual([slug]);+ expect(saved).toHaveLength(1);+ expect(saved[0]).toMatchObject({ waiting: { type: "failed", step: "draft" }, results: { draft: { state: "failed" } } });+});++it.each([+ { name: "structured data", answer: batch({ successful: true, data: { id: "draft-1", example: { successful: false, error: "quoted text" } } }) },+ { name: "plain text", answer: frame("Created draft-1") },+])("keeps a successful $name result successful", async ({ answer }) => {+ const { result, calls } = await replay(answer);+ expect(result).toMatchObject({ ok: true, status: "ok" });+ expect(calls).toEqual([slug, "SLACK_SEND_MESSAGE"]);+});diff --git a/server/skill-burger/executors.ts b/server/skill-burger/executors.tsindex 8118d15a7a..220a67f393 100644--- a/server/skill-burger/executors.ts+++ b/server/skill-burger/executors.ts@@ -166,8 +166,15 @@ export function createExecutors(context: ExecutorContext): StepExecutors {try {return { ok: true, output: toolData(slug, answer.body) };} catch (error) {- const plain = callText(answer.body);- return plain.ok ? plain : { ok: false, error: error instanceof Error ? error.message : String(error) };+ const content = record(answer.body.result)?.content;+ const text = Array.isArray(content) ? content.map(record).find((part) => typeof part?.text === "string")?.text : undefined;+ if (typeof text === "string") {+ try { JSON.parse(text); } catch {+ const plain = callText(answer.body);+ if (plain.ok) return plain;+ }+ }+ return { ok: false, error: error instanceof Error ? error.message : String(error) };}},async browser(input) {