feat(agent-bff): expose the action execute endpoint with result normalization#1752
Open
nbouliol wants to merge 3 commits into
Conversation
…eld error Carry the native action Error result's html on ActionFormValidationError and throw a typed UnknownActionFieldError from the strict setFields, so consumers can render error markup and route unknown fields to a client error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…lization Serve POST /v1/:collection/actions/:action/execute: reject unknown submitted fields via setFields, run the action, and normalize the agent result into a flat wrapper (success/error/webhook/redirect), returning 501 for File results. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
6 new issues
|
Validate value shapes (not just key presence) when normalizing the execute result so malformed payloads fall through to 501 instead of a null-field 200, and keep an empty roleIdsAllowedToApprove array in the approval 403 details. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Exposes
POST /v1/:collection/actions/:action/executeon the BFF, stacked on the action-form PR (#1748). It rejects unknown submitted fields, runs the Smart Action, and normalizes the agent result into one flat wrapper — success / error / webhook / redirect — returning a structured 501 for File results, which are unimplemented in v1.Fixes PRD-674
How
agent-client(2 additive, backward-compatible changes — a version bump ships with this, so rollback is no longer "redeploy agent-bff alone"):ActionFormValidationErrornow carrieshtml;toActionErrorforwards it from the native actionErrorpayload ({ error, html }). Without this the html is dropped before reaching the BFF.setFieldsthrows a typedUnknownActionFieldError(same message as before) so callers route an unknown field to a client error instead of a generic 500. Existing consumers (mcp-server, workflow-executor) catch generically and are unaffected.agent-bff:action-execute-mapper.ts— pure mapper: the agent 200 payload is discriminated positively (webhook / redirect / success); any unrecognized body (a streamed File) falls through to a501 unsupported_action_result.HttpRequesterdoes not expose response headers, soContent-Dispositioncannot be read — the fall-through is the only viable File detection.agent-action-client.ts— a singleloadActionmethod (form and execute load the same agent-clientActionobject);Action extends ActionForm.action-routes-middleware.ts— one middleware matching both/formand/executewith shared body parsing and action resolution.execute()gets its own try/catch (it cannot use the genericcallAgent, which would mislabel the action-Error 400 as a transport 502):UnknownActionFieldError→ 400invalid_request,ActionFormValidationError→ 400{ type: "error", ..., html },ActionRequiresApprovalError→ 403action_requires_approval, transport 5xx →agent_unavailable.bff-local-errors.ts— newactionRequiresApproval(403).Result shapes
{ type: "success", message, invalidated: [...], html }{ type: "error", status: 400, message, html }{ type: "webhook", url, method, headers, body }{ type: "redirect", path }{ error: { type: "unsupported_action_result", status: 501 } }Out of scope / follow-ups
createApprovalRequest); they surface as403 action_requires_approval(withroleIdsAllowedToApprove). Full wiring depends on the auth foundation (PRD-637) providing a per-mode Forest-server token + rendering context, and would add anapprovalRequestedwrapper shape. To confirm with the spec author.action_not_allowed(403) still has no local trigger — every non-exposed action maps to 404, mirroring the collection/relation routes (existing TODO).Tests
agent-client: html carry on the error path, typedUnknownActionFieldErrorfromsetFields.agent-bff: pure execute mapper (all shapes + 501), the/executeroute (missing recordIds, unknown field, action Error + html, approval, File, unknown action, transport 5xx vs action-Error 400, success/webhook/redirect), and the sharedloadAction.setFieldsconsumers: mcp-server (24) and workflow-executor adapter (63) green.🤖 Generated with Claude Code
Note
Expose action execute endpoint in agent-bff with result normalization
/agent/v1/:collection/actions/:action/executeroute in action-routes-middleware.ts, dispatching alongside the existing/formroute via a unified regex.mapActionExecuteResultin action-execute-mapper.ts to normalize raw execute payloads into typed BFF responses:200 success,200 webhook,200 redirect, or501 unsupported_action_result.actionRequiresApproval(403) and mapsActionFormValidationError(400 with optionalhtml) andUnknownActionFieldError(400invalid_request) in the execute handler.AgentActionClientfromloadActionFormtoloadAction, returning a newActioninterface withsetFieldsandexecutemethods.ActionFormValidationErrorto carry anhtmlproperty and introducesUnknownActionFieldErrorwith afieldNamein agent-client errors.Macroscope summarized 911b16e.