Skip to content

feat: pnpm migration, English logs, local temp chat mode - #161

Open
shabahmd wants to merge 4 commits into
Rfym21:mainfrom
shabahmd:feat/pnpm-migration-and-english-logs
Open

feat: pnpm migration, English logs, local temp chat mode#161
shabahmd wants to merge 4 commits into
Rfym21:mainfrom
shabahmd:feat/pnpm-migration-and-english-logs

Conversation

@shabahmd

@shabahmd shabahmd commented Aug 25, 2026

Copy link
Copy Markdown

Changes

Package Manager: npm → pnpm

  • Switched from npm to pnpm (v11.22.0) with packageManager field
  • Added pnpm-workspace.yaml (root + public workspace)
  • Replaced package-lock.json with pnpm-lock.yaml
  • Removed PM2 dependency (ecosystem.config.js, PM2_INSTANCES, PM2_MAX_MEMORY)
  • Updated README-en.md deployment instructions

Local/Temporary Chat Mode — single source of truth (551dff6)

  • New resolveChatMode() helper (src/utils/chat-helpers.js): the only chat_mode decision point — explicit client 'normal' wins over the flag, then 'local' request or ENABLE_TEMP_CHATS=true, else 'normal'
  • Both entry points resolve through it: OpenAI middleware and Anthropic buildInternalRequest (previously hardcoded 'normal')
  • generateChatID() now creates upstream chats with the resolved mode (chats/new payload), and both upstream requests use referer /c/local in temp mode — matching real browser traffic
  • Previously enabling ENABLE_TEMP_CHATS had no effect: a persistent chat was always created first with hardcoded 'normal'

Fix Anthropic /v1/messages upstream WAF/captcha rejections (551dff6)

  • The Anthropic path sent a non-browser-shaped body (missing version/timestamp, skeletal messages, extra session_id/id) → Alibaba risk control fingerprinted it as a bot → HTTP 200 with FAIL_SYS_USER_VALIDATE / RGV587
  • New shared buildFeChatMessage() factory emits the full FE 0.2.81 message shape; used by both middleware and Anthropic builder (no duplicated message literals)
  • Anthropic body now aligned: single FE-shaped message (history already folded by parserMessages), version: '2.1', top-level timestamp; removed write-only session_id/id/top-level sub_chat_type

Dynamic default model (551dff6)

  • Model selection is fully dynamic: /v1/models derives from the live upstream list (+ capability suffixes); request models are alias-matched against it
  • Removed stale hardcode: omitted model now resolves to the first upstream t2t-capable model instead of literal qwen3-coder-plus (absent from today's list)

Chinese → English Log Translation

  • Translated all logger/console/throw/res strings across 29 source files
  • Chinese JSDoc comments preserved
  • 0 remaining Chinese strings in active code paths

Files Changed

  • 29+7 source files updated across 3 commits
  • pnpm-lock.yaml, pnpm-workspace.yaml, public/pnpm-lock.yaml added
  • README-en.md updated with pnpm instructions, PM2 removed, temp chat mode documented
  • .env.example: documents ENABLE_TEMP_CHATS

Testing

  • Full suite: 68/68 pass (node --test --test-force-exit tests/*.test.js)
  • New tests: resolveChatMode precedence, middleware stamping, FE message-shape guard
  • Verified end-to-end on live server:
    • /v1/chat/completions: no field → local, explicit local ✓, explicit normal opt-out ✓
    • /v1/messages: default, local, and normal all return completions (previously deterministic WAF failure)
    • Models: qwen3.8-max, qwen3.7-max, qwen3.6-plus each resolve to distinct upstream models; omitted model resolves dynamically

shabahmd and others added 2 commits August 26, 2026 03:46
- Switch package manager from npm to pnpm (v11), add pnpm-workspace.yaml
- Add enableTempChats config + local chat_mode support in middleware and request util
- Translate all logger/console/throw/res Chinese strings to English across 29 files
- Remove PM2, package-lock.json from gitignore; add pnpm-lock.yaml
- Build frontend successfully with pnpm

Co-authored-by: ByNara <admin@bynara.id>
Model: agnes-2.0-flash
- Remove PM2 references, replace npm with pnpm
- Add ENABLE_TEMP_CHATS config option documentation
- Update project structure (pnpm-workspace.yaml, no ecosystem.config.js)
- Clean up stale references

Co-authored-by: ByNara <admin@bynara.id>
Model: agnes-2.0-flash
@shabahmd

Copy link
Copy Markdown
Author

Well, I prefer my rice boiled, not cooked.

@shabahmd

Copy link
Copy Markdown
Author

Also, I did not know much about PM2, I can re-add them into a new pull request if server hosting is required.

shabahmd and others added 2 commits August 26, 2026 06:38
…stream payloads

- resolveChatMode(): one decision point (explicit 'normal' > 'local'/ENABLE_TEMP_CHATS > default),
  used by both OpenAI middleware and Anthropic builder
- generateChatID creates upstream chats with the resolved chat_mode; /c/local referer in temp mode
- buildFeChatMessage(): shared FE 0.2.81 message factory; Anthropic path now sends a full-shape
  single message (+version/timestamp, -session_id/-id), fixing upstream WAF/captcha rejections
  (FAIL_SYS_USER_VALIDATE/RGV587) on /v1/messages
- parserModel: omitted model now resolves dynamically from the upstream t2t list instead of
  hardcoded qwen3-coder-plus
- ENABLE_TEMP_CHATS documented in env example; npm test uses --test-force-exit
- tests: chat_mode precedence, middleware stamping, FE shape guard

Co-authored-by: ByNara <admin@bynara.id>
Model: agnes-2.0-flash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant