Skip to content

spark: fallback to WebSocket on X1 HTTP auth failure and improve SPARK_API_PASSWORD handling#5

Merged
FenjuFu merged 1 commit into
mainfrom
codex/resolve-issue
Mar 2, 2026
Merged

spark: fallback to WebSocket on X1 HTTP auth failure and improve SPARK_API_PASSWORD handling#5
FenjuFu merged 1 commit into
mainfrom
codex/resolve-issue

Conversation

@FenjuFu
Copy link
Copy Markdown
Owner

@FenjuFu FenjuFu commented Mar 2, 2026

Motivation

  • Ensure existing WebSocket v3.5 usage is not broken when X1 HTTP credentials are present but invalid by falling back automatically on auth failures.
  • Accept alternative environment variable and trim whitespace for SPARK_API_PASSWORD to avoid accidental misconfiguration.

Description

  • Normalize SPARK_API_PASSWORD to use process.env.SPARK_API_PASSWORD || process.env.IFLYTEK_SPARK_API_PASSWORD and apply .trim() to the value.
  • Add HttpErrorLike, getHttpStatus, and shouldFallbackToWs helpers to extract HTTP status and decide fallback conditions.
  • Make chatSparkX1Http attach a status and name to thrown errors when the HTTP response is not ok.
  • Update chatSpark to try the X1 HTTP path and on 401/403 automatically log a warning and fall back to chatSparkWs when WS credentials (APP_ID, API_KEY, API_SECRET) are available, otherwise rethrow the HTTP error.

Testing

  • Ran TypeScript build with tsc which completed successfully.
  • Ran the existing test suite with npm test and the tests passed successfully.

Codex Task

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
good-action-hub Ready Ready Preview, Comment Mar 2, 2026 3:18am

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 2, 2026

Deploy Preview for goodaction-hub ready!

Name Link
🔨 Latest commit 46b1dd2
🔍 Latest deploy log https://app.netlify.com/projects/goodaction-hub/deploys/69a5012b7120ed00085438be
😎 Deploy Preview https://deploy-preview-5--goodaction-hub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@FenjuFu FenjuFu merged commit c6d23ed into main Mar 2, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant