Add OpenRouter GLM-V CUA support#45
Open
rgarcia wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 4 potential issues.
Bugbot Autofix prepared fixes for all 4 issues found in the latest run.
- ✅ Fixed: OpenRouter y fallback copies scalar x
- I changed y normalization to use tuple-only fallback from x so scalar x values no longer get copied into y when y is missing.
- ✅ Fixed: Arrays pass through coordinate normalization
- Normalization now either converts tuple/scalar coordinates to finite numbers, clears invalid optional scroll coordinates, or throws for invalid required coordinates so arrays are never forwarded.
- ✅ Fixed: Duplicate OpenRouter integration test titles
- I updated the integration test title template to include modelRef, making the two OpenRouter cases uniquely identifiable in Vitest output.
- ✅ Fixed: Exported OpenRouter APIs lack TSDoc
- I added TSDoc comments to the exported OpenRouter executor override and normalization helper, including context about the GLM tuple behavior and a provider doc link.
Or push these changes by commenting:
@cursor push 167c37b0d4
Preview (167c37b0d4)
diff --git a/packages/ai/src/providers/openrouter/index.ts b/packages/ai/src/providers/openrouter/index.ts
--- a/packages/ai/src/providers/openrouter/index.ts
+++ b/packages/ai/src/providers/openrouter/index.ts
@@ -31,6 +31,13 @@
return [OPENROUTER_COMPUTER_INSTRUCTIONS, opts.suffix].filter(Boolean).join("\n\n");
}
+/**
+ * Wrap the shared canonical executors with OpenRouter-specific normalization.
+ *
+ * OpenRouter's GLM-V models can emit tuple-shaped coordinates (`[x, y]`) for
+ * scalar fields, so this override unwraps those payloads before browser
+ * execution.
+ */
export function computerToolExecutors(options: ComputerToolsOptions = {}): CuaToolExecutorSpec[] {
return createCuaActionToolExecutors(options.actions).map((executor) => ({
...executor,
@@ -40,6 +47,12 @@
}));
}
+/**
+ * Normalize OpenRouter canonical actions into finite scalar coordinates.
+ *
+ * Source: OpenRouter exposes Z.AI GLM-V models that can return tuple-like
+ * coordinate arguments; see https://openrouter.ai/z-ai/glm-4.6v.
+ */
export function normalizeOpenRouterAction(action: CuaAction): CuaAction {
// GLM-4.6V via OpenRouter can return [x, y] tuples in scalar coordinate
// fields even when the function schema asks for numbers.
@@ -48,25 +61,35 @@
case "double_click":
case "mouse_down":
case "mouse_up":
- case "move":
+ case "move": {
+ const x = coordinateNumber(action.x, 0);
+ const y = coordinateNumber(action.y, 1) ?? coordinateTupleNumber(action.x, 1);
return {
...action,
- x: coordinateNumber(action.x, 0) ?? action.x,
- y: coordinateNumber(action.y, 1) ?? coordinateNumber(action.x, 1) ?? action.y,
+ x: requiredCoordinate(x, action.type, "x"),
+ y: requiredCoordinate(y, action.type, "y"),
};
- case "scroll":
+ }
+ case "scroll": {
+ const x = coordinateNumber(action.x, 0);
+ const y = coordinateNumber(action.y, 1) ?? coordinateTupleNumber(action.x, 1);
return {
...action,
- x: coordinateNumber(action.x, 0) ?? action.x,
- y: coordinateNumber(action.y, 1) ?? coordinateNumber(action.x, 1) ?? action.y,
+ x,
+ y,
};
+ }
case "drag":
return {
...action,
- path: action.path.map((point) => ({
- x: coordinateNumber(point.x, 0) ?? point.x,
- y: coordinateNumber(point.y, 1) ?? coordinateNumber(point.x, 1) ?? point.y,
- })),
+ path: action.path.map((point) => {
+ const x = coordinateNumber(point.x, 0);
+ const y = coordinateNumber(point.y, 1) ?? coordinateTupleNumber(point.x, 1);
+ return {
+ x: requiredCoordinate(x, action.type, "x"),
+ y: requiredCoordinate(y, action.type, "y"),
+ };
+ }),
};
default:
return action;
@@ -74,14 +97,28 @@
}
function coordinateNumber(value: unknown, index: number): number | undefined {
- if (typeof value === "number" && Number.isFinite(value)) return value;
- if (Array.isArray(value)) {
- const next = value[index] ?? value[0];
- return typeof next === "number" && Number.isFinite(next) ? next : undefined;
- }
- return undefined;
+ return finiteNumber(value) ?? coordinateTupleNumber(value, index);
}
+function coordinateTupleNumber(value: unknown, index: number): number | undefined {
+ if (!Array.isArray(value)) return undefined;
+ const next = value[index] ?? value[0];
+ return finiteNumber(next);
+}
+
+function finiteNumber(value: unknown): number | undefined {
+ return typeof value === "number" && Number.isFinite(value) ? value : undefined;
+}
+
+function requiredCoordinate(
+ value: number | undefined,
+ actionType: CuaAction["type"],
+ axis: "x" | "y",
+): number {
+ if (value !== undefined) return value;
+ throw new Error(`OpenRouter ${actionType} action is missing a finite ${axis} coordinate`);
+}
+
export const providerModule = {
toolDefinitions: computerTools,
toolExecutors: computerToolExecutors,
diff --git a/packages/ai/test/computer-tool.integration.test.ts b/packages/ai/test/computer-tool.integration.test.ts
--- a/packages/ai/test/computer-tool.integration.test.ts
+++ b/packages/ai/test/computer-tool.integration.test.ts
@@ -130,7 +130,7 @@
const ciEnabled = !c.ciOptInEnvVar || !process.env.CI || process.env[c.ciOptInEnvVar] === "1";
const test = hasKey ? it : it.skip;
- (ciEnabled ? test : it.skip)(`${c.provider} returns a canonical click tool call`, async () => {
+ (ciEnabled ? test : it.skip)(`${c.modelRef} returns a canonical click tool call`, async () => {
const model = getCuaModel(c.modelRef);
const context = await buildContext(c.tools);
const response = await complete(model, context, {
diff --git a/packages/ai/test/openrouter-provider.test.ts b/packages/ai/test/openrouter-provider.test.ts
--- a/packages/ai/test/openrouter-provider.test.ts
+++ b/packages/ai/test/openrouter-provider.test.ts
@@ -12,6 +12,41 @@
expect(openrouter.normalizeOpenRouterAction(action)).toEqual({ type: "click", x: 929, y: 294 });
});
+ it("does not copy scalar x into missing y", () => {
+ const action = {
+ type: "click",
+ x: 929,
+ } as unknown as openrouter.OpenRouterAction;
+
+ expect(() => openrouter.normalizeOpenRouterAction(action)).toThrow(/missing a finite y coordinate/);
+ });
+
+ it("rejects invalid coordinate arrays for required actions", () => {
+ const action = {
+ type: "click",
+ x: ["bad", "data"],
+ y: ["still", "bad"],
+ } as unknown as openrouter.OpenRouterAction;
+
+ expect(() => openrouter.normalizeOpenRouterAction(action)).toThrow(/missing a finite x coordinate/);
+ });
+
+ it("drops invalid scroll coordinate arrays instead of passing arrays through", () => {
+ const action = {
+ type: "scroll",
+ x: ["bad", "data"],
+ y: ["still", "bad"],
+ scroll_y: 120,
+ } as unknown as openrouter.OpenRouterAction;
+
+ expect(openrouter.normalizeOpenRouterAction(action)).toEqual({
+ type: "scroll",
+ x: undefined,
+ y: undefined,
+ scroll_y: 120,
+ });
+ });
+
it("applies the coordinate normalization through tool executors", () => {
const click = openrouter.computerToolExecutors({ actions: ["click"] })[0]!;
expect(click.toActions({ x: [929, 294], y: [294, 294] })).toEqual([{ type: "click", x: 929, y: 294 }]);You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 72565d2. Configure here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
openrouter:z-ai/glm-5v-turbo/openrouter:z-ai/glm-4.6vOPENROUTER_API_KEYenvTests
npm run build --workspace @onkernel/cua-ainpm test --workspace @onkernel/cua-aienv -u OPENAI_API_KEY -u ANTHROPIC_API_KEY -u GOOGLE_API_KEY -u GEMINI_API_KEY -u TZAFON_API_KEY -u YUTORI_API_KEY OPENROUTER_API_KEY=*** npm run test:integration --workspace @onkernel/cua-ai -- test/computer-tool.integration.test.tsnpm run build --workspace @onkernel/cua-agent && npx tsc -benv -u OPENAI_API_KEY -u ANTHROPIC_API_KEY -u GOOGLE_API_KEY -u GEMINI_API_KEY -u TZAFON_API_KEY -u YUTORI_API_KEY OPENROUTER_API_KEY=*** CUA_E2E_LIVE=1 npm test --workspace @onkernel/cua-agent -- test/e2e.live.test.ts -t openrouternpm test --workspace @onkernel/cua-agent -- --exclude "**/*.live.test.ts"npm test --workspace @onkernel/cua-cligit diff --checkOpenRouter live tests require the
OPENROUTER_API_KEYsecret. The agent e2e OpenRouter case is gated byCUA_E2E_OPENROUTER.Note
Medium Risk
Adds a new model provider path and coordinate normalization on the browser execution hot path; mistakes could mis-click or break GLM-V tool calls, but scope is additive with dedicated tests and no changes to existing providers' payload hooks.
Overview
Adds OpenRouter as a first-class CUA provider so agents and the CLI can drive
openrouter:z-ai/glm-5v-turboandopenrouter:z-ai/glm-4.6vvia OpenAI-compatible chat completions, canonical browser tools, andOPENROUTER_API_KEYauth.The new
openrouterprovider module uses pixel coordinates and wraps tool executors withnormalizeOpenRouterActionso GLM-V models that emit tuple-shapedx/yarguments still map to numeric click/scroll/drag actions before Kernel execution. Model catalog,resolveCuaRuntimeSpec, and API-key helpers are extended accordingly (no payload middleware, unlike Tzafon/Yutori).CI passes
OPENROUTER_API_KEYinto integration and agent live e2e jobs; agent smoke adds an OpenRouter case gated byCUA_E2E_OPENROUTER. Integration tests assert click tool calls through executors (not raw arguments) for both GLM-V refs. Docs, quickstart, andcuahelp/README document the new model refs and env vars.Reviewed by Cursor Bugbot for commit faf93f5. Bugbot is set up for automated code reviews on this repo. Configure here.