| @@ -2,13 +2,16 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * OpenStation — AI Copilot WP-Cron jobs. |
| 4 | 4 | * |
| 5 | 5 | * Registers the async comment-analysis hook that scores a comment for |
| 6 | - * spam/harmful content and stores the verdict in comment meta. The job is | |
| 7 | - * scheduled by the Comments-window moderation feature (which is opt-in and | |
| 8 | - * off by default) with a short delay so it runs outside the HTTP request that | |
| 9 | - * triggered the comment. | |
| 6 | + * spam/harmful content and stores the verdict in comment meta. | |
| 10 | 7 | * |
| 8 | + * Nothing in the plugin schedules this hook: automatic comment scoring was | |
| 9 | + * removed (`docs/migration-comments-ai-scoring.md`). The callback is kept | |
| 10 | + * because the hook name is a frozen identifier that a site may still have | |
| 11 | + * queued events for, and because an external plugin re-implementing the | |
| 12 | + * feature can schedule it rather than re-deriving the prompt and schema. | |
| 13 | + * | |
| 11 | 14 | * Generation routes through the WordPress AI Client (`wp_ai_client_prompt()`), |
| 12 | 15 | * which sources credentials from Settings → Connectors — the copilot never |
| 13 | 16 | * handles an API key. |
| 14 | 17 | * |
| @@ -34,10 +37,10 @@ | ||
| 34 | 37 | $comment_id = (int) $comment_id; |
| 35 | 38 | $user_id = (int) $user_id; |
| 36 | 39 | |
| 37 | 40 | // No usable text-generation provider is configured in Connectors — nothing |
| 38 | - // to do. The scheduler already checks this, but the job runs async so we | |
| 39 | - // re-check to avoid emitting failed requests if the provider was removed. | |
| 41 | + // to do. Whoever queued the event may have checked already, but the job runs | |
| 42 | + // async, so re-check to avoid failed requests if the provider was removed. | |
| 40 | 43 | if ( ! openstation_ai_provider_configured() ) { |
| 41 | 44 | return; |
| 42 | 45 | } |
| 43 | 46 | |
| @@ -78,12 +81,9 @@ | ||
| 78 | 81 | * into a system instruction + user prompt, requests JSON constrained to the |
| 79 | 82 | * comment schema, and decodes the result. |
| 80 | 83 | * |
| 81 | 84 | * @param WP_Comment $comment The comment to analyze. |
| 82 | - * @param int $user_id Requesting user id. Currently unused — the builder | |
| 83 | - * is built from the prompt alone and the provider | |
| 84 | - * comes from Connectors; retained for signature | |
| 85 | - * stability and future attribution. | |
| 85 | + * @param int $user_id Requesting user id. | |
| 86 | 86 | * @return array|WP_Error Structured `{ topic, ai_summary, harmful, spam }` or an error. |
| 87 | 87 | */ |
| 88 | 88 | function openstation_ai_analyze_comment_now( WP_Comment $comment, $user_id ) { |
| 89 | 89 | $messages = openstation_ai_messages_for_comment( $comment ); |
| @@ -103,11 +103,22 @@ | ||
| 103 | 103 | $builder = wp_ai_client_prompt( $prompt ); |
| 104 | 104 | if ( '' !== $system ) { |
| 105 | 105 | $builder = $builder->using_system_instruction( $system ); |
| 106 | 106 | } |
| 107 | - // Provider + model are chosen by the Core AI Client; OpenStation pins neither. | |
| 107 | + // Provider + model are chosen by the Core AI Client unless the | |
| 108 | + // model-config filter says otherwise. | |
| 108 | 109 | |
| 109 | - $json = $builder->as_json_response( openstation_ai_normalize_response_schema( $schema ) )->generate_text(); | |
| 110 | + $builder = $builder->as_json_response( openstation_ai_normalize_response_schema( $schema ) ); | |
| 111 | + $builder = openstation_ai_apply_model_config( | |
| 112 | + $builder, | |
| 113 | + array( | |
| 114 | + 'user_id' => (int) $user_id, | |
| 115 | + 'source' => 'ai-copilot/comment-analysis', | |
| 116 | + 'has_schema' => true, | |
| 117 | + ) | |
| 118 | + ); | |
| 119 | + | |
| 120 | + $json = $builder->generate_text(); | |
| 110 | 121 | if ( is_wp_error( $json ) ) { |
| 111 | 122 | return $json; |
| 112 | 123 | } |
| 113 | 124 | |