fix: session persistence + h3 readability + outline error messages
Session issues fixed: - Removed auto-draft-only gate for showing unassigned sessions on new posts (now shows on any post that has no linked sessions) - Auto-link unassigned session to current post when user opens it - Added beforeunload/pagehide flush to persist messages before page close (prevents data loss from 700ms debounce not firing) - Added warning log when session loads with 0 messages for debugging UI fix: - Override WP editor h3 shrinkage (11px/uppercase → 15px/normal/white) - Fix h2/h4-h6 headings in response content for dark theme readability Outline error messages: - Separate empty response from parse failure with distinct actionable messages - Show model name + token count on empty response for debugging - Reassure user that parse failures are usually one-time issues
This commit is contained in:
@@ -2296,13 +2296,25 @@ Keep sections focused and actionable. Include H2 headings only. For technical ar
|
||||
// Debug: log the raw response
|
||||
wpaw_debug_log( 'Plan generation raw response length: ' . strlen( $content ) );
|
||||
|
||||
if ( empty( trim( (string) $content ) ) ) {
|
||||
$model_used = $response['model'] ?? 'unknown';
|
||||
return new WP_Error(
|
||||
'empty_response',
|
||||
sprintf(
|
||||
__( 'The AI model (%s) returned an empty response. Try a different planning model or simplify your topic.', 'wp-agentic-writer' ),
|
||||
$model_used
|
||||
),
|
||||
array( 'status' => 500 )
|
||||
);
|
||||
}
|
||||
|
||||
if ( null === $plan_json ) {
|
||||
wpaw_debug_log( 'extract_plan_from_response returned null. Content preview: ' . substr( $content, 0, 500 ) );
|
||||
return new WP_Error(
|
||||
'invalid_json',
|
||||
sprintf(
|
||||
/* translators: %s: model output preview */
|
||||
__( 'The model responded, but the outline format could not be parsed. Preview: %s', 'wp-agentic-writer' ),
|
||||
__( 'The AI responded but the outline couldn\'t be parsed as JSON. Try again — this is usually a one-time formatting issue. Preview: %s', 'wp-agentic-writer' ),
|
||||
$this->build_model_output_preview( $content )
|
||||
),
|
||||
array( 'status' => 500 )
|
||||
@@ -2904,6 +2916,25 @@ Keep sections focused and actionable. Include H2 headings only. For technical ar
|
||||
|
||||
$content = $response['content'];
|
||||
wpaw_debug_log( 'stream_generatePlan content length: ' . strlen( $content ) );
|
||||
|
||||
// Handle empty response gracefully
|
||||
if ( empty( trim( (string) $content ) ) ) {
|
||||
$model_used = $response['model'] ?? 'unknown';
|
||||
$input_tokens = $response['input_tokens'] ?? 0;
|
||||
echo "data: " . wp_json_encode(
|
||||
array(
|
||||
'type' => 'error',
|
||||
'message' => sprintf(
|
||||
'The AI model (%s) returned an empty response. This usually means the model couldn\'t process the request. Try: 1) Use a different planning model in Settings, 2) Simplify your topic, or 3) Try again. (Tokens sent: %d)',
|
||||
$model_used,
|
||||
$input_tokens
|
||||
),
|
||||
)
|
||||
) . "\n\n";
|
||||
flush();
|
||||
exit;
|
||||
}
|
||||
|
||||
$plan_json = $this->extract_plan_from_response( $content, $topic );
|
||||
|
||||
if ( null === $plan_json ) {
|
||||
@@ -2912,7 +2943,7 @@ Keep sections focused and actionable. Include H2 headings only. For technical ar
|
||||
echo "data: " . wp_json_encode(
|
||||
array(
|
||||
'type' => 'error',
|
||||
'message' => 'The model responded, but the outline format could not be parsed. Preview: ' . $preview,
|
||||
'message' => 'The AI responded but the outline couldn\'t be parsed as JSON. This sometimes happens when the model adds extra text. Trying again usually fixes this. Preview: ' . $preview,
|
||||
)
|
||||
) . "\n\n";
|
||||
flush();
|
||||
|
||||
Reference in New Issue
Block a user