Opened 5 weeks ago
Last modified 3 weeks ago
#64873 new enhancement
WP AI Client: Add JavaScript client (`wp-ai-client`)
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.1 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | AI | Keywords: | ai-client has-patch 2nd-opinion |
| Focuses: | javascript | Cc: |
Description
This ticket tracks landing the wp-ai-client JavaScript package into WordPress Core as a discrete unit of work for the 7.1 cycle. The REST API endpoints it depends on are intentionally out of scope here and tracked separately in #64872.
The JS client was originally proposed as part of the broader WP AI Client merge (#64591) and has an existing implementation in PR #10915, but did not land in 7.0. This ticket scopes the JS surface for focused review and iteration, contingent on the REST API endpoints being available.
Proposed Surface
A wp.aiClient global (registered as the wp-ai-client script handle) that provides:
wp.aiClient.prompt()— A fluentPromptBuilderclass mirroring the PHP API:.withText(),.usingModel(),.usingTemperature(),.generateText(),.generateImage(),.isSupported(), etc. All generation methods return Promises that call the REST endpoints.- Provider/model data store — A
@wordpress/datastore (wp-ai-client/providers-models) with selectors/resolvers forgetProviders(),getProvider(),getProviderModels(),getProviderModel(). Data is fetched lazily via the REST API and cached in the store. - Enums — JS constants for
Capability,MessageRole,FileType,FinishReason,Modality,ProviderType, etc., matching the PHP SDK enums. GenerativeAiResultwrapper with convenience extraction methods (toText(),toTexts(),toFile(),toImageFile(),toAudioFile(), etc.).
References
- PR #10915 — existing implementation (REST + JS client combined; REST endpoints tracked separately)
- #64591 — original WP AI Client merge proposal and discussion
- Make post: Proposal for merging WP AI Client into WordPress 7.0
Change History (3)
Note: See
TracTickets for help on using
tickets.
@jason_the_adams and @flixos90, is it something we still want to add to WordPress Core? Should it get included as proposed directly or through the Gutenberg plugin? I flagged this ticket as needing opinion before we proceed.