Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: preserve plain-text array fallback for numeric-looking input
Afloat91d75f1d1708
diff --git a/server/connector-arguments.test.ts b/server/connector-arguments.test.tsindex 39ba36ee96..63f982f85d 100644--- a/server/connector-arguments.test.ts+++ b/server/connector-arguments.test.ts@@ -210,4 +210,18 @@ describe("numeric text preservation", () => {const args = '{"value": 12,}';expect(fitArguments(args, { type: "object", properties: { value: { type: "number" } } })).toEqual({ args, changed: [] });});++ it.each(["string items", "one-field objects"])("keeps numeric-looking plain text fallback for %s", (kind) => {+ const items = kind === "string items"+ ? { type: "string" }+ : { type: "object", properties: { use_case: { type: "string" } }, required: ["use_case"] };+ const schema = { type: "object", properties: { values: { type: "array", items } } };+ for (const value of ["9007199254740993", "1e400", "0.10000000000000001", '{"value":9007199254740993}', '{"value":1e400}']) {+ const expected = kind === "string items" ? [value] : [{ use_case: value }];+ const fitted = fitArguments({ values: value }, schema);+ expect(fitted.args).toEqual({ values: expected });+ expect(fitted.changed).toHaveLength(1);+ }+ });+});diff --git a/server/connector-arguments.ts b/server/connector-arguments.tsindex d1b0e615b5..7c06bbe647 100644--- a/server/connector-arguments.ts+++ b/server/connector-arguments.ts@@ -57,13 +57,14 @@ function preservesNumericText(text: string, value: number): boolean {const UNSAFE_JSON_NUMBER = Symbol("unsafe-json-number");-function parsedJson(text: string): unknown {+function parsedJson(text: string, expectedShape: "object" | "array"): unknown {try {let unsafe = false;const parsed = JSON.parse(text, (_key: string, value: unknown, context?: { source?: string }) => {if (typeof value === "number" && (context?.source === undefined || !preservesNumericText(context.source, value))) unsafe = true;return value;});+ if (expectedShape === "array" ? !Array.isArray(parsed) : !isObject(parsed)) return undefined;return unsafe ? UNSAFE_JSON_NUMBER : parsed;} catch {return undefined;@@ -77,7 +78,7 @@ function coerce(value: unknown, node: Json | null, root: Json, path: string, chaconst items = resolved(node!.items, root);const field = soleStringField(items, root);if (typeof value === "string") {- const parsed = parsedJson(value);+ const parsed = parsedJson(value, "array");if (parsed === UNSAFE_JSON_NUMBER) return value;if (Array.isArray(parsed)) {changed.push(`${path} from text to a list`);@@ -105,7 +106,7 @@ function coerce(value: unknown, node: Json | null, root: Json, path: string, chareturn value;}if (type === "object") {- const parsed = typeof value === "string" ? parsedJson(value) : undefined;+ const parsed = typeof value === "string" ? parsedJson(value, "object") : undefined;if (parsed === UNSAFE_JSON_NUMBER) return value;if (isObject(parsed)) changed.push(`${path} from text to an object`);const object = isObject(parsed) ? parsed : value;@@ -152,7 +153,7 @@ export function fitArguments(args: unknown, schema: unknown): { args: unknown; cconst root = resolved(schema, isObject(schema) ? schema : {});if (!root || typeOf(root) !== "object" || !isObject(root.properties)) return { args, changed: [] };const changed: string[] = [];- const parsed = typeof args === "string" ? parsedJson(args) : args;+ const parsed = typeof args === "string" ? parsedJson(args, "object") : args;if (parsed === UNSAFE_JSON_NUMBER) return { args, changed: [] };if (typeof args === "string" && isObject(parsed)) changed.push("the arguments from text to an object");if (!isObject(parsed)) return { args, changed: [] };diff --git a/server/connector-proxy.test.ts b/server/connector-proxy.test.tsindex 5d0ff5e0f8..1ad6f8a622 100644--- a/server/connector-proxy.test.ts+++ b/server/connector-proxy.test.ts@@ -602,7 +602,7 @@ describe("connected-app tools by name", () => {response.writeHead(200, { "content-type": "application/json" });if (rpc.method === "tools/list") {response.end(JSON.stringify({ jsonrpc: "2.0", id: rpc.id, result: { tools: [- { name: "FIXTURE_NUMBER", inputSchema: { type: "object", properties: { value: { type: "number" }, payload: { type: "object" }, numbers: { type: "array", items: { type: "number" } } } } },+ { name: "FIXTURE_NUMBER", inputSchema: { type: "object", properties: { value: { type: "number" }, payload: { type: "object" }, numbers: { type: "array", items: { type: "number" } }, labels: { type: "array", items: { type: "string" } }, queries: { type: "array", items: { type: "object", properties: { use_case: { type: "string" } }, required: ["use_case"] } } } } },{ name: "FIXTURE_INTEGER", inputSchema: { type: "object", properties: { value: { type: "integer" } } } },] } }));return;@@ -624,6 +624,8 @@ describe("connected-app tools by name", () => {{ name: "FIXTURE_NUMBER", args: { numbers: "[9007199254740993]" }, expected: { numbers: "[9007199254740993]" } },{ name: "FIXTURE_NUMBER", args: '{"value":4.2e1}', expected: { value: 42 } },{ name: "FIXTURE_INTEGER", args: { value: "42.0" }, expected: { value: 42 } },+ { name: "FIXTURE_NUMBER", args: { labels: "9007199254740993" }, expected: { labels: ["9007199254740993"] } },+ { name: "FIXTURE_NUMBER", args: { queries: "1e400" }, expected: { queries: [{ use_case: "1e400" }] } },];for (const [index, sample] of cases.entries()) {const reply = nextJson(lines);