Opened 2 months ago
Last modified 8 days ago
#66146 new enhancement
Connectors API: document the `type` argument of WP_Connector_Registry::register()
| Reported by: | juanml | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | AI | Version: | 7.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: | docs |
Description
WP_Connector_Registry::register() documents one value for type, ai_provider, which is special-cased: the key is handed to the PHP AI Client and validated on save, and reset when validation fails (https://github.com/WordPress/wordpress-develop/pull/13031 describes the re-validation). A non-generative AI service, one that returns probabilities and confidence rather than text, cannot pass that validation, so registering it as ai_provider would clear a working key.
https://core.trac.wordpress.org/ticket/64791 established that plugin-defined types are intended (its use cases include "add a non-AI connector"), and that works: registering under a type of one's own renders the card in its own group on Settings › Connectors, the key is stored and masked by core, and it resolves with the usual env/constant/option precedence. Two gaps remain:
- The
register()docblock still reads as ifai_providerwere the vocabulary:@type string $type Required. The connector type, e.g. 'ai_provider'.Nothing states that other values are supported or how the Connectors screen treats them.
- An AI service outside the AI Client is neither
ai_providernor a plain non-AI service, and there is no name for it. Each such plugin invents a type, and the screen groups by type, so two judgement-model connectors from two authors would land under two headings. A documented core value (ai_service, or whatever name fits) would let them group together, and would give the AI plugin something to recognise when it decides whether AI credentials exist.
Ask: document that plugin-defined types are supported, and add or name one for AI services the AI Client does not drive.
Working example: https://github.com/juanlentino/jev-connector, registered as ai_decision, verified on 7.1. Companion request on the PHP AI Client side, for a capability that would let such models be first-class there: https://github.com/WordPress/php-ai-client/issues/296.
Attachments (1)
Change History (14)
This ticket was mentioned in Slack in #core-ai by juan. View the logs.
2 months ago
#3
follow-up:
↓ 4
@
8 weeks ago
Hi @juanml, Thanks for the ticket.
Since the type is confirmed to be a free-form string with no registry-level uniqueness check, is a collision between two plugins independently choosing the same value (e.g., both landing on ai_decision or similar?) worth a mention in the docs, even just a naming-convention recommendation (vendor-prefixed values) so this doesn't turn into a de facto standard with silent clashes later?
#4
in reply to: ↑ 3
;
follow-up:
↓ 5
@
8 weeks ago
Good question. I checked rather than guessed, and the answer cuts both ways.
Nothing keys off type today except the comparison with ai_provider: core uses it for the default providers, logo resolution and AI Client validation on save, the Connectors screen for the install callout, and the AI plugin in get_ai_connectors(). The unique key is the id. WP_Connector_Registry::register() requires /^[a-z0-9_-]+$/ and refuses a duplicate with _doing_it_wrong: Connector "%s" is already registered. Auto-generated setting names follow connectors_{$type}_{$id}_{$method}, which carries the id, so two plugins sharing a type still get distinct option names. Two plugins both landing on ai_decision has no functional consequence at present.
On the naming convention I would argue the other way for this particular field. type is a category rather than an identifier: it only becomes useful when more than one plugin picks the same value, which is what this ticket is asking for. A vendor-prefixed type guarantees no two plugins ever match, which is the outcome to avoid. Prefixing belongs on the things that must be unique, and here that is the id.
What does seem worth documenting, closer to your concern:
idis the unique key, and duplicates are refused.typeis free-form, andai_provideris the only value core treats specially.- A shared
typecarries no behaviour today, so choosing one is a bet on a future convention rather than a claim on a namespace. - Declare
setting_nameexplicitly. Since the generated name embeds the type, changing a connector's type later moves the option and orphans a stored key.
Replying to abcd95:
Hi @juanml, Thanks for the ticket.
Since the type is confirmed to be a free-form string with no registry-level uniqueness check, is a collision between two plugins independently choosing the same value (e.g., both landing on ai_decision or similar?) worth a mention in the docs, even just a naming-convention recommendation (vendor-prefixed values) so this doesn't turn into a de facto standard with silent clashes later?
#5
in reply to: ↑ 4
@
8 weeks ago
Replying to juanml:
Makes sense, and thanks for actually checking this.
#6
follow-up:
↓ 7
@
6 weeks ago
A non-generative AI service, one that returns probabilities and confidence rather than text, cannot pass that validation
@juanml can you clarify what validation is failing for your non-generative service?
From my own review, I would expect any service registered as an ai-provider to be able to pass validation trivially (the main check is the provider's own availability() and isConfigured() checks), so if you're encountering issues with that it would help to know more.
Then in general, the preference of the Core AI team would be to add support for decision models (and future new model types) within the AI Client as you've suggested in issue 296 , rather than creating a sub-ecosystem of AI-based "services the AI Client does not drive".
#7
in reply to: ↑ 6
@
6 weeks ago
@nikskyverge You're right, and my description has the mechanism wrong. The PR I linked is about the check running on every settings save, not about provider types.
What actually happens: on a /wp/v2/settings update, _wp_connectors_rest_settings_dispatch() validates each ai_provider key with _wp_connectors_is_ai_api_key_valid() and resets it unless the result is exactly true. That function returns null when $registry->hasProvider( $provider_id ) is false. My connector registers a card with no AI Client provider class behind it, so it hit that branch. Nothing about a non-generative model fails validation; with a provider class the check is availability()->isConfigured(), which the provider controls.
So the second ask here, a separate type for services the AI Client does not drive, should be dropped in favour of the team's direction: support for decision models inside the AI Client (https://github.com/WordPress/php-ai-client/issues/296). The first ask stands on its own: the register() docblock should say that type is free-form and that ai_provider is the value core treats specially.
Replying to nikskyverge:
A non-generative AI service, one that returns probabilities and confidence rather than text, cannot pass that validation
@juanml can you clarify what validation is failing for your non-generative service?
From my own review, I would expect any service registered as an
ai-providerto be able to pass validation trivially (the main check is the provider's ownavailability()andisConfigured()checks), so if you're encountering issues with that it would help to know more.
Then in general, the preference of the Core AI team would be to add support for decision models (and future new model types) within the AI Client as you've suggested in issue 296 , rather than creating a sub-ecosystem of AI-based "services the AI Client does not drive".
This ticket was mentioned in PR #14851 on WordPress/wordpress-develop by @nofearinc.
3 weeks ago
#8
- Keywords has-patch added
Documents the connector type argument of WP_Connector_Registry::register(), following comment:4 and comment:7 on the ticket: type is free-form and may be shared; what core does differently for 'ai_provider' (not registered when wp_supports_ai() is false, key checked with the AI Client on save and cleared if invalid, passed to the AI Client, which also decides whether it is connected); how other types behave; and that the type is part of the default setting_name. Each statement was checked against connectors.php and class-wp-connector-registry.php.
Testing
- Docs only. PHPCS is clean, and
vendor/bin/phpunit --filter Tests_Connectorspasses.
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: drafting the docblock and checking each statement against the code. I reviewed every line.
---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.
🤖 Generated with Claude Code
#9
follow-up:
↓ 10
@
3 weeks ago
Refreshed docblock for WP_Connector_Registry::register(), following comment:4 and comment:7: https://github.com/WordPress/wordpress-develop/pull/14851
It documents that type is free-form and may be shared, what core does differently for 'ai_provider' (not registered when wp_supports_ai() is false, the key is checked with the AI Client on save and cleared if invalid, passed to the AI Client, and the AI Client decides whether it is connected), how other types behave, and that the type is part of the default setting_name, so it should be set explicitly if the type may change. Each statement was checked against connectors.php and class-wp-connector-registry.php.
AI assistance: Claude Code (Claude Opus 5.5) for drafting the docblock and checking it against the code; reviewed by me.
#10
in reply to: ↑ 9
@
3 weeks ago
Thanks @nofearinc, this matches comments 4 and 7, and I checked each statement against trunk. One precision: the key behavior described applies to connectors whose authentication method is
api_key. An application_password connector counts as connected when both username and password are stored, whatever its type, and the AI Client steps don’t apply to it. Scoping that sentence (“For connectors using the api_key method, …”) would keep the docblock exact. I’ve also retitled the ticket to match what remains of it.
Replying to nofearinc:
Refreshed docblock for
WP_Connector_Registry::register(), following comment:4 and comment:7: https://github.com/WordPress/wordpress-develop/pull/14851
It documents that
typeis free-form and may be shared, what core does differently for 'ai_provider' (not registered whenwp_supports_ai()is false, the key is checked with the AI Client on save and cleared if invalid, passed to the AI Client, and the AI Client decides whether it is connected), how other types behave, and that the type is part of the defaultsetting_name, so it should be set explicitly if the type may change. Each statement was checked againstconnectors.phpandclass-wp-connector-registry.php.
AI assistance: Claude Code (Claude Opus 5.5) for drafting the docblock and checking it against the code; reviewed by me.
#11
@
3 weeks ago
- Summary Connectors API: a documented connector type for AI services the AI Client does not drive → Connectors API: document the `type` argument of WP_Connector_Registry::register()
#12
@
3 weeks ago
Thanks @juanml, good catch. Scoped in https://github.com/WordPress/wordpress-develop/pull/14851 (new commit): the AI Client check, the handoff and the key-based connection status now apply to connectors using the api_key method, and application_password connectors are described as connected when both a username and a password are stored, whatever their type. The wp_supports_ai() rule stays unscoped, since it only checks the type.
AI assistance: Claude Code (Claude Opus 5.5) for checking the code paths and updating the docblock; reviewed by me.
Thanks for the quick patch. Before it goes further I need to correct my own description, because the patch repeats the error.
The Connectors screen does not group connectors by type.
routes/connectors-home/stage.tsxrenders one flat list, and the only thing it does with type is check=== 'ai_provider'to decide which provider plugins to offer in the install callout. Core checks the same value to register the default providers and resolve their logos, and the AI plugin checks it inget_ai_connectors(). So the "two headings" argument in my description is wrong, and the sentence "The Connectors screen groups connectors by type" should not go into the docblocks.That also changes what ai_service would be. As patched it is a name in a docblock with no code that recognises it, which documents something that does not exist. I would rather the docblock say only what is true: type is any string;
ai_provideris the one value core treats specially (default providers, logo resolution, and AI Client validation of the key on save); any other value is stored and displayed as is. If a second core value is wanted later, it needs a constant and at least one behaviour attached to it, and the natural first behaviour lives in the AI plugin, not here.