fix(agent-client): respect action hooks configuration (load/change)#1541
fix(agent-client): respect action hooks configuration (load/change)#1541
Conversation
1 new issue
|
|
Coverage Impact This PR will not change total coverage. Modified Files with Diff Coverage (3)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
When api_endpoint has no trailing slash and action endpoints have no leading slash, the URL concatenation produces broken paths like /backoffice/v1forest/actions/... instead of /backoffice/v1/forest/actions/... Extract a buildUrl() method that ensures the path always starts with / before concatenation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
loadInitialState was called unconditionally, even for actions with hooks.load: false, causing 404 errors. Similarly, setFieldValue always called /hooks/change even when hooks.change was empty. Pass hooks config from the schema through to FieldFormStates, and skip the HTTP calls when the hooks are disabled. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
189a6c6 to
c8216e9
Compare
The Node agent responds to POST /hooks/load even when hooks.load is false (returning static fields). The Ruby agent returns 404. Instead of skipping the call entirely (which breaks Node), always attempt it and gracefully catch the error when hooks.load is false. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The catch block was too broad — it swallowed all errors (401, 500, network failures) when hooks.load was false. Now it only catches 404 specifically, matching the Ruby backend behavior. Other errors are rethrown so they surface properly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When hooks.load is false and the Ruby backend returns 404, use the static fields from the schema as fallback instead of returning an empty form. This ensures the AI knows which fields to fill. Also moves is404Error to HttpRequester (where HTTP errors are created) and narrows the catch to only swallow 404 errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Medium
In loadChanges, this.layout.push(...queryResults.layout) spreads queryResults.layout without a null-coalescing fallback. If the /hooks/change endpoint returns a response without a layout property, this throws a TypeError. The same operation in loadInitialState uses queryResults.layout ?? [] — the inconsistency suggests this is an oversight.
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file packages/agent-client/src/action-fields/field-form-states.ts around line 167:
In `loadChanges`, `this.layout.push(...queryResults.layout)` spreads `queryResults.layout` without a null-coalescing fallback. If the `/hooks/change` endpoint returns a response without a `layout` property, this throws a TypeError. The same operation in `loadInitialState` uses `queryResults.layout ?? []` — the inconsistency suggests this is an oversight.
Evidence trail:
packages/agent-client/src/action-fields/field-form-states.ts lines 102: `this.layout.push(...(queryResults.layout ?? []));` in loadInitialState method. packages/agent-client/src/action-fields/field-form-states.ts line 170: `this.layout.push(...queryResults.layout);` in loadChanges method. Both methods query similar ResponseBody type from HTTP requests to /hooks/load and /hooks/change endpoints respectively.
ForestSchemaAction.fields is typed as { field: string }[] but the
actual JSON contains type, isRequired, defaultValue. Cast to the
expected type until the ForestSchemaAction type is updated.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Summary
loadInitialStatewas called unconditionally even for actions withhooks.load: false, causing 404 errors on backends that reject the/hooks/loadrequestsetFieldValuealways called/hooks/changeeven whenhooks.changewas empty, causing 404 errorshooksconfig from the schema throughActionEndpointsByCollection→Collection→FieldFormStateshooksis not provided (old schema format), behavior is unchangedTest plan
hooks.load: falseno longer trigger/hooks/loadhooks.change: []no longer trigger/hooks/change🤖 Generated with Claude Code
Note
Fix action hooks configuration to skip load/change requests when hooks are absent or empty
FieldFormStates.setFieldValueno longer calls the/hooks/changeendpoint whenhooks.changeis empty, avoiding unnecessary requests.FieldFormStates.loadInitialStateswallows 404 errors from/hooks/loadwhenhooks.loadis false, optionally populating fields fromfallbackFieldsinstead of throwing.Collection.actionnow passeshooksandfieldsfrom the action schema through toFieldFormStates, using a newgetActionInfo()method that replacesgetActionPath().HttpRequestergains a staticis404Error(error)helper and normalizes paths missing a leading slash inbuildUrl().SchemaConverter.extractActionEndpointsandgetActionEndpointsin the MCP server now includehooksandfieldsin their returned action metadata.Macroscope summarized 5944ae6.