Appearance
EP-021 paid_article_ai_generate_consideration(有料記事 AI 考察生成)
概要
有料記事の編集画面から、指定した考察欄の下書きを ADM-028 で選んだ LLM(Claude Tool Use または Gemini Function Calling)で生成する。ハンドラは生成テキストを JSON で返す。post meta への自動保存はしない。
POST パラメータ
| フィールド | 必須 | 型・制約 | 説明 |
|---|---|---|---|
action | ○ | 文字列 | paid_article_ai_generate_consideration |
_wpnonce | ○ | 文字列 | paid_article_ai_generate_consideration で発行した nonce。nonce でも受け付ける |
post_id | ○ | 正整数 | 対象の paid_article 投稿 ID |
target_field | ○ | 許可リストの文字列 | 生成対象。例: paid_article_month_diff.comment_before |
target_field 許可リスト
| 形式 | 例 |
|---|---|
| HTML 固定セクション | paid_article_intro / paid_article_next_machine_comment |
| JSON 固定セクションの前後考察 | {meta_key}.comment_before / {meta_key}.comment_after |
| 可変セクション本文 | paid_article_section_vs_{instance_id}.content |
| 特定機種結果の前後考察 | paid_article_section_smr_{instance_id}.comment_before / .comment_after |
成功時 data
| 論理名 | 物理名 | 型 | 説明 |
|---|---|---|---|
| 本文 | content | string | 生成した考察 HTML または文章 |
失敗・ブロック(success: false の data に含み得るキー)
| 条件 | message の内容 |
|---|---|
| AJAX コンテキスト外・nonce 不正 | Messages::AUTH_FAILED |
post_id が不正、または投稿タイプが paid_article でない | PaidArticleAiGenerationAjaxCopy::INVALID_POST |
edit_post 権限なし | Messages::PERMISSION_DENIED |
target_field が許可リスト外 | PaidArticleAiGenerationServiceCopy::TARGET_FIELD_INVALID |
| 出力が max_tokens で途中切れ | PaidArticleAiGenerationServiceCopy::OUTPUT_TRUNCATED |
| API キー未設定・対象月未設定・指針未設定・応答切れ・形式不正・ループ上限 | 対応する PaidArticleAiGenerationServiceCopy の固定文言 |
| HTTP 429 / quota(Service 例外) | Messages::AI_LLM_CLAUDE_RATE_LIMITED / AI_LLM_GEMINI_RATE_LIMITED(応答から取れた待ち秒が 1〜120 なら「(約 N 秒後)」を付与。生レスポンスは出さない) |
| HTTP 401 / 403(Service 例外) | Messages::AI_LLM_CLAUDE_AUTH_FAILED / AI_LLM_GEMINI_AUTH_FAILED |
| HTTP タイムアウト・経過上限(Service 例外) | Messages::AI_LLM_CLAUDE_TIMEOUT / AI_LLM_GEMINI_TIMEOUT |
| 接続失敗(WP_Error、タイムアウト以外)(Service 例外) | Messages::AI_LLM_CLAUDE_CONNECTION_FAILED / AI_LLM_GEMINI_CONNECTION_FAILED |
| その他の HTTP 非 200(Service 例外) | Messages::AI_LLM_CLAUDE_HTTP_ERROR / AI_LLM_GEMINI_HTTP_ERROR(ステータスコードのみ。例: …(HTTP 500)。) |
| 上記以外の Service 例外 | PaidArticleAiGenerationAjaxCopy::NOTICE_GENERIC_ERROR(詳細は error_log) |
上流 API のレスポンス本文や WP_Error の生メッセージは画面・JSON に載せない(Issue #3866)。ArticleAiLlmClient は ArticleAiLlmHttpErrorMode::ClientSafe で固定文言だけを例外に入れ、PaidArticleAiGenerationAjaxHandler は ArticleAiLlmClientErrorFilter で許可した文言以外を汎用文言に置き換える。上流の詳細は ExternalApiErrorLogFormatter の要約(HTTP ステータス・短い要約・ハッシュ)で error_log に残す。
権限
- ログイン必須(
wp_ajax_のみ。noprivは付けない) - capability:
edit_post(対象post_id)
関連
- 全考察の一括生成は EP-022