Skip to content

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

fix(skill-burger): explain input renames that exceed field limits

Afloat967883b92b78
diff --git a/shared/skill-burger/draft-view.test.ts b/shared/skill-burger/draft-view.test.ts
index 27cbd8e828..19ac799a53 100644
--- a/shared/skill-burger/draft-view.test.ts
+++ b/shared/skill-burger/draft-view.test.ts
@@ -54,4 +54,26 @@ describe("the person's choices", () => {
expect(applyChoices(workflow, { inputs: { url: { name: "page" } } })).toEqual({ error: "There is already an input named page." });
expect(applyChoices(workflow, { inputs: { url: { name: "9x" } } })).toMatchObject({ error: expect.stringContaining("can't be an input's name") });
});
+
+ const boundedFields = [
+ { field: "AI prompt", limit: 4_000, token: "{a}", renamed: "{website}", step: (text: string) => ({ kind: "ai", deterministic: false, prompt: text }) },
+ { field: "decision prompt", limit: 2_000, token: "{a}", renamed: "{website}", step: (text: string) => ({ kind: "decide", cases: ["yes"], prompt: text }) },
+ { field: "check text", limit: 1_000, token: "{a}", renamed: "{website}", step: (text: string) => ({ kind: "shell", run: "echo ok", check: { says: text } }) },
+ { field: "shell command", limit: 20_000, token: "$OMB_ARG_A", renamed: "$OMB_ARG_WEBSITE", step: (text: string) => ({ kind: "shell", run: text }) },
+ ];
+
+ it.each(boundedFields)("explains a rename that exceeds the $field limit", ({ limit, token, step }) => {
+ const original = wf([{ id: "s1", label: "Work", ...step("x".repeat(limit - token.length) + token) }], { a: { default: "value" } });
+ const snapshot = structuredClone(original);
+ const chosen = applyChoices(original, { inputs: { a: { name: "website" } } });
+ expect(chosen).toEqual({ error: `Renaming input names ("a" to "website") makes "Work" exceed its ${limit}-character limit.` });
+ expect(original).toEqual(snapshot);
+ });
+
+ it.each(boundedFields)("accepts a rename that exactly reaches the $field limit", ({ limit, token, renamed, step }) => {
+ const original = wf([{ id: "s1", label: "Work", ...step("x".repeat(limit - renamed.length) + token) }], { a: { default: "value" } });
+ const chosen = applyChoices(original, { inputs: { a: { name: "website" } } });
+ expect(workflowSchema.safeParse(chosen).success).toBe(true);
+ expect(JSON.stringify(chosen)).toContain(renamed);
+ });
});
diff --git a/shared/skill-burger/draft-view.ts b/shared/skill-burger/draft-view.ts
index 7ef24a9291..ec5b48bcc9 100644
--- a/shared/skill-burger/draft-view.ts
+++ b/shared/skill-burger/draft-view.ts
@@ -3,7 +3,7 @@
// step repeats exactly or is the bot's to redo with judgement. Built on the server from the same draft a save writes,
// so the step ids the person unticks are the ids that are saved. The person's choices (steps left out, inputs renamed
// or given another value) are applied here too, the same way the save applies them.
-import { textLine, type Workflow, type WorkflowStep } from "./format.ts";
+import { textLine, workflowSchema, type Workflow, type WorkflowStep } from "./format.ts";
import { askOf, type BurgerLayer, type LayerKind, type RunMessage } from "./layers.ts";
const ASKED_MAX = 1_200;
@@ -167,5 +167,15 @@ export function applyChoices(workflow: Workflow, choices: DraftChoices | undefin
if (!used(to)) continue;
args[to] = { ...arg, ...(choice?.value !== undefined ? { default: choice.value } : {}) };
}
- return { ...workflow, args, steps };
+ const chosen = { ...workflow, args, steps };
+ const renamed = [...names].filter(([from, to]) => from !== to);
+ if (renamed.length) {
+ const parsed = workflowSchema.safeParse(chosen);
+ const limit = !parsed.success && parsed.error.issues.find((issue) => issue.code === "too_big" && issue.origin === "string" && issue.path[0] === "steps");
+ if (limit && limit.code === "too_big") {
+ const inputs = renamed.map(([from, to]) => `"${from}" to "${to}"`).join(", ");
+ return { error: `Renaming input names (${inputs}) makes "${steps[Number(limit.path[1])]!.label}" exceed its ${limit.maximum}-character limit.` };
+ }
+ }
+ return chosen;
}