| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — AI Copilot settings + capability helpers. | |
| 3 | + * OpenStation — AI Copilot settings + capability helpers. | |
| 4 | 4 | * |
| 5 | 5 | * The Copilot no longer stores credentials of its own. WordPress 7.0 owns |
| 6 | 6 | * provider credentials (Settings → Connectors) and model routing |
| 7 | 7 | * (`wp_ai_client_prompt()`, which injects the configured key automatically). |
| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * (`ai.enabled`) and expose the Core capability signals the shell uses to |
| 10 | 10 | * decide whether to surface the assistant at all. Provider + model selection |
| 11 | 11 | * is delegated entirely to the Core AI Client — nothing is persisted here. |
| 12 | 12 | * |
| 13 | - * @package WPDesktopMode | |
| 13 | + * @package OpenStation | |
| 14 | 14 | */ |
| 15 | 15 | |
| 16 | 16 | defined( 'ABSPATH' ) || exit; |
| 17 | 17 | |
| @@ -24,10 +24,10 @@ | ||
| 24 | 24 | * |
| 25 | 25 | * @param int $user_id |
| 26 | 26 | * @return array{ enabled: bool } |
| 27 | 27 | */ |
| 28 | -function desktop_mode_ai_get_settings( $user_id ) { | |
| 29 | - $os = desktop_mode_get_os_settings( (int) $user_id ); | |
| 28 | +function openstation_ai_get_settings( $user_id ) { | |
| 29 | + $os = openstation_get_os_settings( (int) $user_id ); | |
| 30 | 30 | $ai = isset( $os['ai'] ) && is_array( $os['ai'] ) ? $os['ai'] : array(); |
| 31 | 31 | return array( |
| 32 | 32 | 'enabled' => isset( $ai['enabled'] ) ? (bool) $ai['enabled'] : false, |
| 33 | 33 | ); |
| @@ -42,9 +42,9 @@ | ||
| 42 | 42 | * via `wp_supports_ai()` — the shell hides the assistant entirely. |
| 43 | 43 | * |
| 44 | 44 | * @return bool |
| 45 | 45 | */ |
| 46 | -function desktop_mode_ai_is_available() { | |
| 46 | +function openstation_ai_is_available() { | |
| 47 | 47 | return function_exists( 'wp_ai_client_prompt' ) |
| 48 | 48 | && function_exists( 'wp_get_connectors' ) |
| 49 | 49 | && function_exists( 'wp_register_ability' ) |
| 50 | 50 | && function_exists( 'wp_supports_ai' ) |
| @@ -56,11 +56,11 @@ | ||
| 56 | 56 | * |
| 57 | 57 | * The baseline capability gate: a no-network, deterministic |
| 58 | 58 | * `is_supported_for_text_generation()` probe against the AI Client registry |
| 59 | 59 | * (which Core populates from the configured Connectors). This is what plain |
| 60 | - * text-generation features — e.g. comment scoring, which only needs structured | |
| 61 | - * text output — gate on. The agentic assistant needs more; see | |
| 62 | - * {@see desktop_mode_ai_assistant_provider_configured()}. | |
| 60 | + * text-generation features — the on-demand comment analysis ability, which | |
| 61 | + * only needs structured text output — gate on. The agentic assistant needs more; see | |
| 62 | + * {@see openstation_ai_assistant_provider_configured()}. | |
| 63 | 63 | * |
| 64 | 64 | * Credentials are supplied by Core from the configured Connector; no API request |
| 65 | 65 | * is made. |
| 66 | 66 | * |
| @@ -65,10 +65,10 @@ | ||
| 65 | 65 | * is made. |
| 66 | 66 | * |
| 67 | 67 | * @return bool |
| 68 | 68 | */ |
| 69 | -function desktop_mode_ai_provider_configured() { | |
| 70 | - if ( ! desktop_mode_ai_is_available() ) { | |
| 69 | +function openstation_ai_provider_configured() { | |
| 70 | + if ( ! openstation_ai_is_available() ) { | |
| 71 | 71 | return false; |
| 72 | 72 | } |
| 73 | 73 | return (bool) wp_ai_client_prompt( 'test' )->is_supported_for_text_generation(); |
| 74 | 74 | } |
| @@ -88,16 +88,16 @@ | ||
| 88 | 88 | * class isn't present (e.g. older WordPress). |
| 89 | 89 | * |
| 90 | 90 | * @return bool |
| 91 | 91 | */ |
| 92 | -function desktop_mode_ai_assistant_provider_configured() { | |
| 93 | - if ( ! desktop_mode_ai_is_available() ) { | |
| 92 | +function openstation_ai_assistant_provider_configured() { | |
| 93 | + if ( ! openstation_ai_is_available() ) { | |
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $probe = desktop_mode_ai_capability_probe_declaration(); | |
| 97 | + $probe = openstation_ai_capability_probe_declaration(); | |
| 98 | 98 | if ( ! $probe ) { |
| 99 | - return desktop_mode_ai_provider_configured(); | |
| 99 | + return openstation_ai_provider_configured(); | |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | return (bool) wp_ai_client_prompt( 'test' ) |
| 103 | 103 | ->using_function_declarations( $probe ) |
| @@ -113,9 +113,9 @@ | ||
| 113 | 113 | * text-generation check. |
| 114 | 114 | * |
| 115 | 115 | * @return object|null A `FunctionDeclaration`, or null. |
| 116 | 116 | */ |
| 117 | -function desktop_mode_ai_capability_probe_declaration() { | |
| 117 | +function openstation_ai_capability_probe_declaration() { | |
| 118 | 118 | $class = '\WordPress\AiClient\Tools\DTO\FunctionDeclaration'; |
| 119 | 119 | if ( ! class_exists( $class ) ) { |
| 120 | 120 | return null; |
| 121 | 121 | } |
| @@ -134,16 +134,16 @@ | ||
| 134 | 134 | * Whether the AI assistant is active for a given user. |
| 135 | 135 | * |
| 136 | 136 | * This is purely the per-user toggle (default off, opt-in). Availability of the Core |
| 137 | 137 | * APIs and whether a provider key is set are separate, orthogonal checks |
| 138 | - * ({@see desktop_mode_ai_is_available()} / {@see desktop_mode_ai_provider_configured()}) | |
| 138 | + * ({@see openstation_ai_is_available()} / {@see openstation_ai_provider_configured()}) | |
| 139 | 139 | * so callers can distinguish "user turned it off" from "not set up yet". |
| 140 | 140 | * |
| 141 | 141 | * @param int $user_id |
| 142 | 142 | * @return bool |
| 143 | 143 | */ |
| 144 | -function desktop_mode_ai_is_enabled( $user_id ) { | |
| 145 | - $ai = desktop_mode_ai_get_settings( (int) $user_id ); | |
| 144 | +function openstation_ai_is_enabled( $user_id ) { | |
| 145 | + $ai = openstation_ai_get_settings( (int) $user_id ); | |
| 146 | 146 | return ! empty( $ai['enabled'] ); |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
| @@ -155,11 +155,11 @@ | ||
| 155 | 155 | * |
| 156 | 156 | * - `assistantProviderConfigured` — a provider that supports text generation |
| 157 | 157 | * *and* function calling (what the agentic assistant needs). Gates the Cmd+K |
| 158 | 158 | * assistant, its admin-bar icon, and the "AI assistant" toggle in Features. |
| 159 | - * - `providerConfigured` — the baseline text-generation gate. Comment scoring | |
| 160 | - * (which only needs text output) gates on this; the client uses it for the | |
| 161 | - * "Score new comments with AI" mirror. | |
| 159 | + * - `providerConfigured` — the baseline text-generation gate, for the calls | |
| 160 | + * that need text output but not function calling (the Drafts writing | |
| 161 | + * assistant, the on-demand comment analysis ability). | |
| 162 | 162 | * |
| 163 | 163 | * Provider + model selection is delegated to the Core AI Client, so there is no |
| 164 | 164 | * per-user preference to carry here. |
| 165 | 165 | * |
| @@ -165,14 +165,14 @@ | ||
| 165 | 165 | * |
| 166 | 166 | * @param int|null $user_id Defaults to the current user. |
| 167 | 167 | * @return array{ available: bool, providerConfigured: bool, assistantProviderConfigured: bool, enabled: bool, connectorsUrl: string } |
| 168 | 168 | */ |
| 169 | -function desktop_mode_ai_assistant_config( $user_id = null ) { | |
| 169 | +function openstation_ai_assistant_config( $user_id = null ) { | |
| 170 | 170 | $user_id = null === $user_id ? get_current_user_id() : (int) $user_id; |
| 171 | 171 | |
| 172 | 172 | $connectors_url = admin_url( 'options-connectors.php' ); |
| 173 | 173 | |
| 174 | - if ( ! desktop_mode_ai_is_available() ) { | |
| 174 | + if ( ! openstation_ai_is_available() ) { | |
| 175 | 175 | return array( |
| 176 | 176 | 'available' => false, |
| 177 | 177 | 'providerConfigured' => false, |
| 178 | 178 | 'assistantProviderConfigured' => false, |
| @@ -180,14 +180,14 @@ | ||
| 180 | 180 | 'connectorsUrl' => $connectors_url, |
| 181 | 181 | ); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - $ai = desktop_mode_ai_get_settings( $user_id ); | |
| 184 | + $ai = openstation_ai_get_settings( $user_id ); | |
| 185 | 185 | |
| 186 | 186 | return array( |
| 187 | 187 | 'available' => true, |
| 188 | - 'providerConfigured' => desktop_mode_ai_provider_configured(), | |
| 189 | - 'assistantProviderConfigured' => desktop_mode_ai_assistant_provider_configured(), | |
| 188 | + 'providerConfigured' => openstation_ai_provider_configured(), | |
| 189 | + 'assistantProviderConfigured' => openstation_ai_assistant_provider_configured(), | |
| 190 | 190 | 'enabled' => (bool) $ai['enabled'], |
| 191 | 191 | 'connectorsUrl' => $connectors_url, |
| 192 | 192 | ); |
| 193 | 193 | } |
| @@ -194,19 +194,19 @@ | ||
| 194 | 194 | |
| 195 | 195 | /** |
| 196 | 196 | * REST: GET `desktop-mode/v1/ai/status`. |
| 197 | 197 | * |
| 198 | - * Returns the current {@see desktop_mode_ai_assistant_config()} so the shell | |
| 198 | + * Returns the current {@see openstation_ai_assistant_config()} so the shell | |
| 199 | 199 | * can re-check provider availability without a page reload — e.g. after the |
| 200 | 200 | * user configures an AI provider in Settings → Connectors. |
| 201 | 201 | */ |
| 202 | -function desktop_mode_register_ai_status_rest_route() { | |
| 202 | +function openstation_register_ai_status_rest_route() { | |
| 203 | 203 | register_rest_route( |
| 204 | 204 | 'desktop-mode/v1', |
| 205 | 205 | '/ai/status', |
| 206 | 206 | array( |
| 207 | 207 | 'methods' => WP_REST_Server::READABLE, |
| 208 | - 'callback' => 'desktop_mode_rest_ai_status', | |
| 208 | + 'callback' => 'openstation_rest_ai_status', | |
| 209 | 209 | 'permission_callback' => static function () { |
| 210 | 210 | return is_user_logged_in() && current_user_can( 'read' ); |
| 211 | 211 | }, |
| 212 | 212 | ) |
| @@ -211,9 +211,9 @@ | ||
| 211 | 211 | }, |
| 212 | 212 | ) |
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | -add_action( 'rest_api_init', 'desktop_mode_register_ai_status_rest_route' ); | |
| 215 | +add_action( 'rest_api_init', 'openstation_register_ai_status_rest_route' ); | |
| 216 | 216 | |
| 217 | 217 | /** |
| 218 | 218 | * REST handler for the AI status probe. |
| 219 | 219 | * |
| @@ -218,8 +218,7 @@ | ||
| 218 | 218 | * REST handler for the AI status probe. |
| 219 | 219 | * |
| 220 | 220 | * @return WP_REST_Response |
| 221 | 221 | */ |
| 222 | -function desktop_mode_rest_ai_status() { | |
| 223 | - return rest_ensure_response( desktop_mode_ai_assistant_config() ); | |
| 222 | +function openstation_rest_ai_status() { | |
| 223 | + return rest_ensure_response( openstation_ai_assistant_config() ); | |
| 224 | 224 | } |
| 225 | - | |