Skip to content

Commit c195bc1

Browse files
Copilotswissspidy
andcommitted
Improve backward compatibility and add tests
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 818b905 commit c195bc1

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
"bundled": false,
5151
"commands": [
5252
"ai",
53+
"ai credentials list",
54+
"ai credentials set",
55+
"ai credentials delete",
5356
"mcp prompt",
5457
"mcp server add",
5558
"mcp server list",

features/ai-credentials.feature

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: AI Credentials command
2+
Scenario: Credentials management with WP AI Client
3+
Given a WP installation
4+
5+
When I try `wp ai credentials list`
6+
Then STDERR should contain:
7+
"""
8+
The WP AI Client is not available.
9+
"""
10+
11+
# TODO: Add tests for when WP AI Client is available
12+
# This would require installing the AI plugin or WordPress 7.0+

features/ai.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Feature: AI command
1616
When I try `wp ai "Hello World"`
1717
Then STDERR should contain:
1818
"""
19-
This command currently requires the AI Services plugin.
19+
This command requires the AI Services plugin for MCP tool integration.
2020
"""
2121

2222
When I run `wp plugin install ai-services --activate`

src/AiCommand.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,29 @@ public function __invoke( array $args, array $assoc_args ): void {
7575
WP_CLI::error( 'Not implemented yet.' );
7676
}
7777

78-
// Check if WP AI Client is available (preferred).
79-
$use_wp_ai_client = class_exists( '\WordPress\AI_Client\AI_Client' );
80-
81-
// Fallback to AI Services if WP AI Client is not available.
82-
if ( ! $use_wp_ai_client && ! function_exists( '\ai_services' ) ) {
83-
WP_CLI::error( 'This command requires either the WP AI Client (WordPress 7.0+) or the AI Services plugin. You can install the AI Services plugin with `wp plugin install ai-services --activate`.' );
84-
}
85-
8678
$approval_mode = (bool) Utils\get_flag_value( $assoc_args, 'approval-mode', false );
8779
$service = Utils\get_flag_value( $assoc_args, 'service' );
8880
$model = Utils\get_flag_value( $assoc_args, 'model' );
8981

90-
// If using WP AI Client and no MCP tools are needed, use simplified path.
82+
// Check if WP AI Client is available (preferred for simple prompts).
83+
$use_wp_ai_client = class_exists( '\WordPress\AI_Client\AI_Client' );
84+
85+
// If using WP AI Client and no MCP tools/approval is needed, use simplified path.
9186
if ( $use_wp_ai_client && ! $approval_mode ) {
92-
$ai_client = new AI\WpAiClient( [], $approval_mode, $service, $model );
93-
$ai_client->call_ai_service_with_prompt( $args[0] );
94-
return;
87+
$skip_builtin_servers = Utils\get_flag_value( $assoc_args, 'skip-builtin-servers' );
88+
// Only use WP AI Client if MCP servers are skipped.
89+
if ( $skip_builtin_servers ) {
90+
$ai_client = new AI\WpAiClient( [], $approval_mode, $service, $model );
91+
$ai_client->call_ai_service_with_prompt( $args[0] );
92+
return;
93+
}
94+
}
95+
96+
// Otherwise, use the full MCP integration with AI Services (required for tools).
97+
if ( ! function_exists( '\ai_services' ) ) {
98+
WP_CLI::error( 'This command requires the AI Services plugin for MCP tool integration. You can install it with `wp plugin install ai-services --activate`. Alternatively, use `--skip-builtin-servers=all` to use WP AI Client without MCP tools.' );
9599
}
96100

97-
// Otherwise, use the full MCP integration with AI Services.
98101
$skip_builtin_servers = Utils\get_flag_value( $assoc_args, 'skip-builtin-servers', 'all' );
99102

100103
$sessions = $this->get_sessions( $with_wordpress && 'cli' === $skip_builtin_servers, 'wp' === $skip_builtin_servers );

0 commit comments

Comments
 (0)