Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 65d1d68

Browse files
julionavopencode
andauthored
fix: ensure JSON encoding uses consistent request/response format (#1158)
The JSON encoding path in handleAction was expecting a raw array for action arguments, while the client was sending {a: [...]} format. This caused "Invalid JSON" errors when explicitly specifying encoding: "json" in the client. This fix ensures both JSON and CBOR encodings use the same ActionRequestSchema format for consistency, matching the client's expected behavior. 🤖 Generated with [opencode](https://opencode.ai) Co-authored-by: opencode <noreply@opencode.ai>
1 parent b90093d commit 65d1d68

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

packages/core/src/actor/router-endpoints.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -430,16 +430,21 @@ export async function handleAction(
430430
let actionArgs: unknown[];
431431
if (encoding === "json") {
432432
try {
433-
actionArgs = await c.req.json();
433+
const body = await c.req.json();
434+
435+
// Validate using the action schema
436+
const result = protoHttpAction.ActionRequestSchema.safeParse(body);
437+
if (!result.success) {
438+
throw new errors.InvalidActionRequest("Invalid action request format");
439+
}
440+
441+
actionArgs = result.data.a;
434442
} catch (err) {
443+
if (err instanceof errors.InvalidActionRequest) {
444+
throw err;
445+
}
435446
throw new errors.InvalidActionRequest("Invalid JSON");
436447
}
437-
438-
if (!Array.isArray(actionArgs)) {
439-
throw new errors.InvalidActionRequest(
440-
"Action arguments must be an array",
441-
);
442-
}
443448
} else if (encoding === "cbor") {
444449
try {
445450
const value = await c.req.arrayBuffer();
@@ -496,7 +501,10 @@ export async function handleAction(
496501

497502
// Encode the response
498503
if (encoding === "json") {
499-
return c.json(output as Record<string, unknown>);
504+
const responseData = {
505+
o: output, // Use the format expected by ResponseOkSchema
506+
};
507+
return c.json(responseData);
500508
} else if (encoding === "cbor") {
501509
// Use serialize from serde.ts instead of custom encoder
502510
const responseData = {

0 commit comments

Comments
 (0)