Skip to content
Closed
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
21 changes: 21 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# AGENTS.md — ai-provider-for-anthropic-max

WordPress plugin.

## Local Development Environment

The shared WordPress dev install for testing this plugin is at `../wordpress` (relative to this repo root).

- **URL**: http://wordpress.local:8080
- **Admin**: http://wordpress.local:8080/wp-admin — `admin` / `admin`
- **WordPress version**: 7.0-RC2
- **This plugin**: symlinked into `../wordpress/wp-content/plugins/$(basename $PWD)`
- **Reset to clean state**: `cd ../wordpress && ./reset.sh`

WP-CLI is configured via `wp-cli.yml` in this repo root — run `wp` commands directly from here without specifying `--path`.

```bash
wp plugin activate $(basename $PWD) # activate this plugin
wp plugin deactivate $(basename $PWD) # deactivate
wp db reset --yes && cd ../wordpress && ./reset.sh # full reset
```
9 changes: 7 additions & 2 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,21 @@
* is loaded only where it is needed.
*/
function enqueue_connector_module(): void {
$asset_file = __DIR__ . '/../build/connector.js';
$version = file_exists( $asset_file )
? filemtime( $asset_file )
: ANTHROPIC_MAX_AI_PROVIDER_VERSION;

wp_register_script_module(
'ai-provider-for-anthropic-max',
plugins_url( 'build/connector.js', __DIR__ ),
ANTHROPIC_MAX_AI_PROVIDER_URL . 'build/connector.js',
[
[
'id' => '@wordpress/connectors',
'import' => 'static',
],
],
ANTHROPIC_MAX_AI_PROVIDER_VERSION
$version
);
wp_enqueue_script_module( 'ai-provider-for-anthropic-max' );
}
16 changes: 6 additions & 10 deletions js/connector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,9 @@ function AddAccountForm( { onComplete, onCancel } ) {
window.open( data.authorize_url, '_blank', 'noopener' );
setStep( 'code' );
} catch ( err ) {
setError(
err instanceof Error
? err.message
: __( 'Failed to start OAuth flow.' )
);
// apiFetch throws a plain object {code, message, data} for WP_Error responses,
// not an Error instance. Use err?.message to surface the actual server message.
setError( err?.message || __( 'Failed to start OAuth flow.' ) );
} finally {
setIsBusy( false );
}
Expand All @@ -207,11 +205,9 @@ function AddAccountForm( { onComplete, onCancel } ) {
} );
onComplete();
} catch ( err ) {
setError(
err instanceof Error
? err.message
: __( 'Code exchange failed.' )
);
// apiFetch throws a plain object {code, message, data} for WP_Error responses,
// not an Error instance. Use err?.message to surface the actual server message.
setError( err?.message || __( 'Code exchange failed.' ) );
} finally {
setIsBusy( false );
}
Expand Down
1 change: 1 addition & 0 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
}

define( 'ANTHROPIC_MAX_AI_PROVIDER_VERSION', '1.0.0' );
define( 'ANTHROPIC_MAX_AI_PROVIDER_URL', plugin_dir_url( __FILE__ ) );

// ---------------------------------------------------------------------------
// PSR-4 autoloader for src/ classes.
Expand Down
9 changes: 9 additions & 0 deletions src/OAuthPool/PoolManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,16 +705,25 @@ public function exchangeCode(string $code, string $state, string $email): ?array
);

if (is_wp_error($response)) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[AnthropicMax] Token exchange wp_error: ' . $response->get_error_message());
}
return null;
}

$status = wp_remote_retrieve_response_code($response);
if ($status !== 200) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[AnthropicMax] Token exchange HTTP ' . $status . ': ' . wp_remote_retrieve_body($response));
}
return null;
}

$data = json_decode(wp_remote_retrieve_body($response), true);
if (!is_array($data) || empty($data['access_token'])) {
if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('[AnthropicMax] Token exchange bad response body: ' . wp_remote_retrieve_body($response));
}
return null;
}

Expand Down
2 changes: 2 additions & 0 deletions wp-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path: ../wordpress
url: http://wordpress.local:8080