Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ wp connectors get <connector> [--fields=<fields>] [--format=<format>]
+-----------------+-----------------------------------------------+
| Field | Value |
+-----------------+-----------------------------------------------+
| id | openai |
| name | OpenAI |
| description | Text and image generation with GPT and Dall-E |
| status | connected |
Expand Down Expand Up @@ -323,13 +324,13 @@ wp connectors list [--status=<status>] [--fields=<fields>] [--format=<format>]

# List all connectors
$ wp connectors list
+-----------+-----------------------------------------------+---------------+
| name | description | status |
+-----------+-----------------------------------------------+---------------+
| Anthropic | Text generation with Claude. | not installed |
| Google | Text and image generation with Gemini... | not installed |
| OpenAI | Text and image generation with GPT and Dall-E | connected |
+-----------+-----------------------------------------------+---------------+
+-----------+-----------+-----------------------------------------------+---------------+
| id | name | description | status |
+-----------+-----------+-----------------------------------------------+---------------+
| anthropic | Anthropic | Text generation with Claude. | not installed |
| google | Google | Text and image generation with Gemini... | not installed |
| openai | OpenAI | Text and image generation with GPT and Dall-E | connected |
+-----------+-----------+-----------------------------------------------+---------------+

# List only connected connectors
$ wp connectors list --status=connected
Expand Down
75 changes: 37 additions & 38 deletions features/connectors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Feature: List and get AI connectors
Scenario: List connectors returns built-in providers with descriptions
When I run `wp connectors list --format=json`
Then STDOUT should contain:
"""
"id":"openai"
"""
And STDOUT should contain:
"""
"name":"OpenAI"
"""
Expand Down Expand Up @@ -49,32 +53,12 @@ Feature: List and get AI connectors
"""

@require-wp-7.0
Scenario: List connectors in table format shows name, description and status columns
Scenario: List connectors in table format shows id, name, description and status columns
When I run `wp connectors list`
Then STDOUT should contain:
"""
name
"""
And STDOUT should contain:
"""
description
"""
And STDOUT should contain:
"""
status
"""
And STDOUT should contain:
"""
OpenAI
"""
And STDOUT should contain:
"""
Anthropic
"""
And STDOUT should contain:
"""
Google
"""
Then STDOUT should match /^id\tname\tdescription\tstatus$/m
And STDOUT should match /^anthropic\tAnthropic\t/m
And STDOUT should match /^google\tGoogle\t/m
And STDOUT should match /^openai\tOpenAI\t/m

@require-wp-7.0
Scenario: List connectors supports --status filter
Expand All @@ -91,25 +75,17 @@ Feature: List and get AI connectors
@require-wp-7.0
Scenario: Get a specific connector shows key-value layout
When I run `wp connectors get openai`
Then STDOUT should contain:
"""
name
"""
And STDOUT should contain:
"""
OpenAI
"""
And STDOUT should contain:
"""
status
"""
Then STDOUT should match /^Field\tValue$/m
And STDOUT should match /^id\topenai$/m
And STDOUT should match /^name\tOpenAI$/m
And STDOUT should match /^status\t/m

@require-wp-7.0
Scenario: Get a specific connector in JSON format
When I run `wp connectors get openai --format=json`
Then STDOUT should be JSON containing:
"""
{"name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""}
{"id":"openai","name":"OpenAI","description":"Text and image generation with GPT and Dall-E.","status":"not installed","credentials_url":"https://platform.openai.com/api-keys","api_key":""}
"""

# TODO: Depends on https://core.trac.wordpress.org/ticket/64819.
Expand Down Expand Up @@ -143,6 +119,29 @@ Feature: List and get AI connectors
{"name":"OpenAI","auth_method":"api_key","type":"ai_provider","plugin_file":"ai-provider-for-openai/plugin.php"}
"""

@require-wp-7.0
Scenario: Connector ID from list can be passed to get
When I run `wp connectors list --fields=id --format=json`
Then STDOUT should contain:
"""
{"id":"openai"}
"""
And STDOUT should contain:
"""
{"id":"anthropic"}
"""
And STDOUT should contain:
"""
{"id":"google"}
"""
And save STDOUT '"id":"([a-z0-9_-]+)"' as {CONNECTOR_ID}

When I run `wp connectors get {CONNECTOR_ID} --fields=id --format=json`
Then STDOUT should be JSON containing:
"""
{"id":"{CONNECTOR_ID}"}
"""

Comment thread
coderabbitai[bot] marked this conversation as resolved.
@require-wp-7.0
Scenario: Error on non-existent connector
When I try `wp connectors get nonexistent`
Expand Down
21 changes: 12 additions & 9 deletions src/Connectors_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Connectors_Command extends WP_CLI_Command {
* @var string[]
*/
protected $default_fields = [
'id',
'name',
'description',
'status',
Expand Down Expand Up @@ -61,13 +62,13 @@ class Connectors_Command extends WP_CLI_Command {
*
* # List all connectors
* $ wp connectors list
* +-----------+-----------------------------------------------+---------------+
* | name | description | status |
* +-----------+-----------------------------------------------+---------------+
* | Anthropic | Text generation with Claude. | not installed |
* | Google | Text and image generation with Gemini... | not installed |
* | OpenAI | Text and image generation with GPT and Dall-E | connected |
* +-----------+-----------------------------------------------+---------------+
* +-----------+-----------+-----------------------------------------------+---------------+
* | id | name | description | status |
* +-----------+-----------+-----------------------------------------------+---------------+
* | anthropic | Anthropic | Text generation with Claude. | not installed |
* | google | Google | Text and image generation with Gemini... | not installed |
* | openai | OpenAI | Text and image generation with GPT and Dall-E | connected |
* +-----------+-----------+-----------------------------------------------+---------------+
*
* # List only connected connectors
* $ wp connectors list --status=connected
Expand Down Expand Up @@ -141,6 +142,7 @@ static function ( array $item ) use ( $status_filter ) {
* +-----------------+-----------------------------------------------+
* | Field | Value |
* +-----------------+-----------------------------------------------+
* | id | openai |
* | name | OpenAI |
* | description | Text and image generation with GPT and Dall-E |
* | status | connected |
Expand Down Expand Up @@ -180,7 +182,7 @@ public function get( $args, $assoc_args ) {

$item['api_key'] = $api_key;

$default_fields = array( 'name', 'description', 'status', 'credentials_url', 'api_key' );
$default_fields = array( 'id', 'name', 'description', 'status', 'credentials_url', 'api_key' );
$formatter = new \WP_CLI\Formatter( $assoc_args, $default_fields );
$formatter->display_item( $item );
}
Expand All @@ -190,14 +192,15 @@ public function get( $args, $assoc_args ) {
*
* @param string $connector_id The connector ID.
* @param mixed[] $connector Connector settings from wp_get_connectors().
* @return array{name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string}
* @return array{id: string, name: string, description: string, status: string, type: string, auth_method: string, credentials_url: string, plugin_file: string}
*/
private function build_connector_item( string $connector_id, array $connector ): array {
$auth = is_array( $connector['authentication'] ) ? $connector['authentication'] : array();
$plugin = isset( $connector['plugin'] ) && is_array( $connector['plugin'] ) ? $connector['plugin'] : array();
$plugin_file = isset( $plugin['file'] ) && is_string( $plugin['file'] ) ? $plugin['file'] : '';

return array(
'id' => $connector_id,
'name' => $this->scalar_to_string( $connector['name'] ?? '' ),
'description' => $this->scalar_to_string( $connector['description'] ?? '' ),
'status' => $this->get_connector_status( $connector_id, $connector ),
Expand Down