fix(upsert): canonical JSON Schema for handler tool registrations#235
Merged
Conversation
Follow-up to PR #232. Converts the upsert_event handler tool registration to emit a canonical JSON Schema (type: object, properties, required) instead of a flat property bag. Required for DM 0.106.1 compatibility. PR #1900 in data-machine core makes RequestBuilder::normalizeToolParameters a passthrough, so handler tool definitions must already be canonical when registered. NOT backwards-compatible with DM 0.103.x at the provider return shape level: EventSchemaProvider and VenueParameterProvider now return canonical fragments ({properties, required?}) instead of flat property bags. The handler tool wire-up (EventUpsertFilters) is the only consumer of these providers in this plugin. No tests pin the old shape. TaxonomyHandler::getTaxonomyToolParameters() in data-machine core still returns a flat property bag. EventUpsertFilters' composer absorbs that shape transparently as a degenerate fragment with no required fields, so this PR works regardless of when DM core converts TaxonomyHandler to canonical fragments. Changes: - DynamicToolParametersTrait::filterByEngineData() now operates on canonical fragments and prunes filtered keys from both 'properties' and 'required'. - EventSchemaProvider::fieldsToToolParameters() emits canonical fragments. Per-property 'required' booleans are aggregated into a top-level required[] array. 'required' key omitted when empty. - VenueParameterProvider returns a canonical fragment with no required fields (venue presence is enforced upstream). - EventUpsertFilters::getDynamicEventTool() composes fragments via new composeCanonicalParameters() helper. Tolerates both canonical fragment shape and legacy flat property bag from TaxonomyHandler. - All array-typed properties carry an 'items' schema (already in source declarations; preserved through fieldsToToolParameters).
Contributor
Homeboy Results —
|
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.
Why
Follow-up to #232 (chat tools canonical schemas).
Data Machine 0.106.1 PR #1900 ("Require canonical AI tool schemas") removes the auto-normalization layer in
RequestBuilder::normalizeToolParametersthat previously converted legacy property-keyed parameter shapes into canonical JSON Schema before sending to providers. After 0.106.1, whatever a tool registration emits is sent to OpenAI as the tool schema literal — so handler-stage tools must already be canonical.PR #232 converted the chat tools (static schemas in
inc/Api/Chat/Tools/). This PR completes the work for the handler-stageupsert_eventtool registered via thedm_handlersfilter, whose schema is assembled at runtime by merging output from four provider methods.⚠ Backwards-compatibility warning
This PR is NOT backwards-compatible with DM 0.103.x at the provider return-shape level.
EventSchemaProvider::getCoreToolParameters(),EventSchemaProvider::getSchemaToolParameters(),EventSchemaProvider::getAllToolParameters(), andVenueParameterProvider::getToolParameters()now return canonical fragments ({ properties, required? }) instead of flat property bags ({ name => def }).The only consumer of these methods inside this plugin is
EventUpsertFilters::getDynamicEventTool(), which is updated in the same commit. There are no tests pinning the old shape (verified viagrep -rn ... tests/).Must merge + deploy in lockstep with the DM 0.106.1 upgrade so the runtime schema shape matches what the provider expects. Canonical schemas are accepted by both 0.103.x (via the soon-to-be-removed normalizer passthrough) and 0.106.1+, so this PR can ship cleanly ahead of or alongside the DM bump.
Caller audit
Ran:
```
grep -rn 'getCoreToolParameters|getSchemaToolParameters|getTaxonomyToolParameters|VenueParameterProvider::getToolParameters' inc/ tests/
grep -rn 'registerAITools|register_tool|registerTool' inc/Steps/
```
Cross-repo: `TaxonomyHandler` lives in data-machine core
`TaxonomyHandler::getTaxonomyToolParameters()` is owned by the data-machine plugin (`inc/Core/WordPress/TaxonomyHandler.php`), not this repo. It is also called from data-machine's own `WordPress.php` publish handler, which itself emits a legacy property-keyed schema with per-property `required => true|false` booleans. I did not modify those files per the orchestrator constraint to not touch other repos.
To stay decoupled, `EventUpsertFilters::composeCanonicalParameters()` accepts both shapes:
The flat shape is treated as a degenerate fragment with no required fields. As long as data-machine's `TaxonomyHandler` continues to emit valid property definitions (each with `type`, `description`, and `items` for arrays — confirmed by reading the source), this PR works whether or not data-machine core is ever updated to canonical fragments.
🚩 Blocker for orchestrator review (out of scope here)
`data-machine` core's WordPress publish handler (`Steps/Publish/Handlers/WordPress/WordPress.php`, around line 47–80) still emits a legacy property-keyed schema with per-property `required` booleans. That handler will fail OpenAI validation on DM 0.106.1 the same way the upsert_event handler would have failed without this PR. Needs a sibling fix in the data-machine repo before 0.106.1 can deploy cleanly to any site that uses the WordPress publish handler. This PR does not address that — surfacing it here for tracking.
Files changed
Test plan
Constraints honored