Make WordPress Core

Opened 5 weeks ago

Last modified 3 weeks ago

#64873 new enhancement

WP AI Client: Add JavaScript client (`wp-ai-client`)

Reported by: gziolo's profile gziolo 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 fluent PromptBuilder class 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/data store (wp-ai-client/providers-models) with selectors/resolvers for getProviders(), 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.
  • GenerativeAiResult wrapper with convenience extraction methods (toText(), toTexts(), toFile(), toImageFile(), toAudioFile(), etc.).

References

Change History (3)

#1 @JeffPaul
5 weeks ago

  • Keywords ai-client added

This ticket was mentioned in Slack in #core-ai by gziolo. View the logs.


4 weeks ago

#3 @gziolo
3 weeks ago

  • Keywords 2nd-opinion added

@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.

Note: See TracTickets for help on using tickets.