Commit Graph

755 Commits

Author SHA1 Message Date
admin 8afcc40b9c fix:社交登录重定向网址错误问题 2026-06-12 18:15:58 +08:00
admin c7b02ecfb6 refactor(auth): extract NextAuth config to shared lib module
Move the NextAuth v4 configuration from the route handler
(src/app/api/auth/[...nextauth]/route.ts) into a dedicated module
(src/lib/auth/auth.ts) to establish a single source of truth. The
route file now simply re-exports the handler from the shared
module, keeping provider setup, JWT/session callbacks, and
environment variable references in one reusable location.
2026-06-12 17:56:01 +08:00
admin dbc9a0cd13 refactor(auth): inline NextAuth v4 config and simplify AuthPlatform API
- Inline NextAuth v4 handler directly in `[...nextauth]/route.ts`, removing
  the `@/lib/auth/nextauth` abstraction layer
- Add Google/Facebook providers with JWT/session callbacks that expose
  `idToken` and `accessToken` on the session for backend exchange
- Refactor `AuthPlatform` from constructor-based to static methods
  (`googleSignIn()` / `facebookSignIn()`)
- Update `auth-machine.ts` and layout comment reference to match new structure
- Align with original Dart `nextauth-helpers.{googleLogin, facebookLogin}()`
  naming and keep persistence concerns (unstorage, backend, custom cookies)
  out of scope for this iteration
2026-06-12 17:20:56 +08:00
admin 1f83171067 chore: add logs directory to gitignore
Add logs/ to .gitignore to prevent log files from being tracked in version control.
2026-06-12 16:57:22 +08:00
admin 8ecdb85543 fix(hook): update post-receive script to handle build and start processes with logging 2026-06-12 16:47:19 +08:00
admin ea339bf621 fix:删除错误配置的代码 2026-06-12 16:43:29 +08:00
admin b36bb2c36b fix(user): make lastMessageAt nullable to handle new backend response 2026-06-12 16:28:33 +08:00
admin 7bc21c1864 chore(auth): add debug logging to guest login flow
Add console.log instrumentation across the guest login pipeline (auth-machine, authRepository, authApi) to trace request lifecycle and surface Zod parsing failures with detailed issue info. Useful for diagnosing lastMessageAt schema mismatches.
2026-06-12 16:21:21 +08:00
admin 4c9fd23b4f chore(release): update worktree paths to match new directory structure
Update WORKTREE_PATH in pre_release_web.sh and release_web.sh to reference the new frontend subdirectory location, aligning scripts with the current project folder structure.
2026-06-12 16:01:09 +08:00
admin a48a380cf7 fix(release): use absolute paths and add error handling in release scripts
- Add error handling to `cd` command to exit with a clear message if the worktree directory is missing
- Change relative `cp` source/destination paths to absolute paths prefixed with `$WORKTREE_PATH`, ensuring files are always read from and written to the intended worktree regardless of the current working directory
- Update inline comments to reflect the new absolute-path behavior in both `pre_release_web.sh` and `release_web.sh`
2026-06-12 15:59:52 +08:00
admin 0660b90809 fix:无法设置token的问题 2026-06-12 15:55:50 +08:00
admin 513b6ac116 fix:返回消息的时间戳错误问题 2026-06-12 15:19:50 +08:00
admin d76b048bb9 chore: move env examples to env-example/ and unify CDN env source
- Reorganize env example files into a dedicated env-example/ directory for clarity
- Update .gitignore to ignore env files (with examples now in env-example/)
- Unify CDN credentials (CF_ZONE_ID / CF_API_TOKEN) to be sourced from .env.local in both test and production deploys
- Update git_hooks/post-receive to copy production env example from new location
- Update deploy scripts (pre_release_web.sh, release_web.sh) to copy the appropriate env example into .env.local before building
- Update _deploy_lib.sh purge_cdn_cache to source from .env.local instead of .env
2026-06-12 15:05:37 +08:00
admin 05674264b8 chore(release): update worktree paths and remove obsolete comments
Update WORKTREE_PATH in release scripts to include "nextjs" prefix in directory names (cozsweet-nextjs-test and cozsweet-nextjs-main) and remove outdated comment blocks from both pre_release_web.sh and release_web.sh.
2026-06-12 14:42:43 +08:00
admin 4fa1ddf22f chore(hooks): copy env example to production env in post-receive
Add preparation step for production environment variables by copying
.env.production.example to .env.production before running build:start,
ensuring required environment variables are available on deployment.
2026-06-12 14:40:07 +08:00
admin c39a8f5f80 refactor(deploy): parameterize git remote in deploy scripts
Replace hardcoded GIT_REMOTE variable with a function parameter so the
shared deploy library can push to either the production or test remote
from the same script. Rename push_to_server to push_to_remote and update
both deploy_web.sh and deploy_web_test.sh to pass the appropriate remote.
2026-06-12 14:39:09 +08:00
admin e2abe03a33 chore: reorganize icons for environment-specific deployment
Move environment-specific icons into dedicated directories (icons/develop, icons/test, icons/production) and update release scripts to copy the appropriate icon set (favicon.ico, Icon-192.png, Icon-512.png) into public/ for each target environment. Update manifest.json to reference the new /images/icons/ path.
2026-06-12 14:33:37 +08:00
admin 64fad08c4a chore: update .gitignore to ignore all env files and retain example templates
Replace broad `.env*` ignore rule with explicit entries for real env files (`.env`, `.env.local`, `.env.development`, `.env.test`, `.env.production`) while preserving `.env.example` and adding exceptions for the new `.env.development.example`, `.env.test.example`, and `.env.production.example` templates.

Add environment-specific example files to document required variables for development, test, and production setups, including API base URLs, WebSocket endpoints, API timeouts, Auth.js secret, OAuth credentials (Google, Facebook), and Cloudflare CDN configuration.
2026-06-12 14:24:56 +08:00
admin cac3ecd5de chore: add .env.example template and clean up deploy messages
Introduce a tracked .env.example file documenting all required environment
variables (app env, API/WebSocket base URLs, timeouts, Google/Facebook OAuth
credentials, Cloudflare CDN zone/token). Update .gitignore to allow this
file despite the blanket .env* ignore rule. Also simplify the push
success/failure output in scripts/deploy/_deploy_lib.sh by removing
verbose troubleshooting hints.
2026-06-12 14:13:20 +08:00
admin c4fa692528 feat: add git post-receive hook for auto build and start
Adds a `git_hooks/post-receive` script that runs `pnpm run build:start`
(equivalent to `next build && next start`) automatically after a push is
received, enabling deployment on `receive.denyCurrentBranch=updateInstead`
configured repos (e.g., production/test servers).

Updates the README with a new "Git Hooks" section explaining:

- How to enable the hooks locally via `git config core.hooksPath git_hooks`
- That `core.hooksPath` is a local config and must be set per clone
- That `post-receive` fires on the receiving (push target) machine, not
  the local dev machine
2026-06-12 14:06:41 +08:00
admin d64ad0f130 refactor(chat): extract ai disclosure into dedicated banner component
- Move AiDisclosure and EmptyState logic into a new AiDisclosureBanner component
- Remove isGuest prop from ChatArea as it's no longer needed there
- Update styling with explicit color values for better visibility
2026-06-12 12:12:13 +08:00
admin 57992bffac chore(chat): clean up legacy state machine and fix bubble alignment
- Remove redundant `loadingMoreHistory` and `ready` states from chat machine, consolidating history loading flow
- Add `align-self: flex-start` to chat row container for proper alignment
- Clean up commented-out margin rules in text bubble styles
- Update deploy script GIT_REMOTE from "server" to "test"
2026-06-12 11:59:34 +08:00
admin a9938b8dae refactor(chat): wire sendMessageHttpActor for HTTP message sending and update response handling 2026-06-12 11:45:46 +08:00
admin 38f060bbd8 refactor(chat): extract XState actors into chat-machine.actors.ts
- Split chat state machine actors (chatInit, sendMessageHttp, loadMoreHistory, chatWebSocket) into a dedicated module
- Add comprehensive console logging across the chat state machine for full trace debugging
- Comment out margin on text bubble CSS for layout adjustment
- Add debug logging to chat input bar send handler
- Clean up redundant comments in auth-screen component
2026-06-12 11:20:19 +08:00
admin 6394c8ba7b refactor(chat): remove legacy screen visibility events and use absolute state refs
- Remove ChatScreenVisible and ChatScreenInvisible events from chat state machine
- Remove legacy ChatInit event handler
- Migrate state transitions to use absolute references (#chat.guestSession, #chat.userSession, #chat.idle)
- Adjust legal text wording for Cozsweet privacy agreement
2026-06-11 19:10:01 +08:00
admin 1b13e4fa19 fix(auth): add inline auto styles to logo Image to silence dimension warning
Next.js Image scans only inline style for 'auto' to determine whether
sizing is fully delegated to CSS. The .logo class already sets
height: var(--auth-logo-height) and width: auto, but the inline auto
hint is required to suppress the width/height-modified warning.

Applies to both auth-facebook-panel and auth-email-panel where the same
login logo is rendered.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 18:59:45 +08:00
admin bdc607c6c5 fix(auth): update legal text and center icon+label in auth buttons
- Update auth-legal-text copy to "I agree to the Cozsweet Privacy
  Agreement and Terms of User", keeping the two external links.
- Center the Facebook icon and "Login with Facebook" label as a group
  inside the main Facebook button (change .facebookLabel flex).
- Apply the same centering to the shared AuthSocialButton .label rule
  so the Email and Facebook entries in the "Other Sign-in Options"
  bottom sheet also render icon+text centered.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 18:58:12 +08:00
admin d55694a73e refactor(chat): move WebSocket lifecycle into chat machine via fromCallback actor
- chat-screen no longer manages WebSocket directly; it now dispatches three
  auth lifecycle events (ChatGuestLogin, ChatNonGuestLogin, ChatLogout)
  derived from auth.loginStatus
- chat-machine internally owns the WebSocket long-lived actor via
  fromCallback, completing the previously deferred migration scope
- removed ChatWebSocket import, getWsToken helper, and direct WS
  effect from chat-screen; renamed dispatchInitialLoad to
  dispatchAuthLifecycle to reflect the new responsibility
- decouples auth from chat machine via event-driven boundary: machine
  stays unaware of loginStatus, guest semantics live at the dispatch
  layer (guest → skip WS, non-guest → connect with token)
2026-06-11 18:57:11 +08:00
admin 4b356f58f2 refactor(chat): remove unused ChatScreenVisible and ChatScreenInvisible events
The screen-lifecycle events were dead code: the transitions in chat-machine
(idle <-> ready) had no caller behavior tied to them, and the dispatches
in chat-screen.tsx were the only senders. Drop the union members, both
state transitions, and the mount-effect dispatches.

The idle state remains declared as initial but is no longer reachable
at runtime; can be refactored in a follow-up.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 18:39:50 +08:00
admin ed4ccddae3 refactor(chat): decouple chat state from auth and gate quota alerts to guests
- Remove ChatAuthStatusChanged dispatch from auth login flow; chat screen now subscribes directly to auth state machine (loginStatus) to derive isGuest and drive WS lifecycle
- Gate quota-exceeded and warning dialogs to guests only (non-guests have no message limit)
- Dispatch ChatLoadMoreHistory for non-guest initial load vs ChatInit for guests
- Fix AppConstants import path from @/core/constants/app_constants to @/core/app_constants
- Add defensive isGuest checks in quota effects to prevent non-guest quota triggers
2026-06-11 18:31:08 +08:00
kanban e3d069e49f fix(chat): remove 75% cap on text bubble and add outer margin
TextBubble now fills the available half-row width instead of being
capped at 75%. Add 16px margin on the avatar-side edge (margin-left
for AI, margin-right for user) so short messages still feel airy
and long messages are no longer artificially clipped.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 18:25:47 +08:00
admin 0ffc961e00 refactor(core): consolidate core files under src/core directory
Move breakpoints, fonts, and app_constants into the core directory for better organization:
- Move src/lib/breakpoints.ts to src/core/breakpoints.ts
- Move src/lib/fonts.ts to src/core/fonts.ts
- Move src/core/constants/app_constants.ts to src/core/app_constants.ts and clean up outdated comments
2026-06-11 18:16:08 +08:00
admin e68aa09395 fix(chat): improve text bubble layout to fill width and prevent overflow 2026-06-11 17:25:54 +08:00
admin be6abaacd8 fix(auth): short-circuit guestLoginActor when local guestToken exists
Skip /auth/guest round-trip on splash Skip when localStorage already
holds a valid guestToken. Avoids redundant API call (and the
fingerprintjs deviceId probe) every time the user reopens splash.

Trade-off: a server-revoked token still resolves "guest" until the
first protected API call returns 401, which the HTTP layer handles.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 17:12:24 +08:00
Claude d205025a11 fix(splash): left-align bottom text on splash screen 2026-06-11 17:06:47 +08:00
admin 982d9ba790 refactor(data): add I*Repository interfaces and depend on them in stores
为 /src/data/repositories/ 下每个仓库类增加对应的接口契约,
接口文件存放在独立的 interfaces/ 子目录中。

改动:
- 新建 4 个接口文件 (iauth_repository / ichat_repository /
  imetrics_repository / iuser_repository),纯 type-only,方法签名
  与实现类完全一致
- 4 个实现类加 implements I{Name}Repository 子句,编译器自动校验契约
- 3 个 stores 文件 (auth / chat / user state machines) 改为依赖接口
  类型:通过 `const xxxRepo: I{Name}Repository = xxxRepository` 局部别名,
  actor 内部调用全部走别名
- barrelsby.json 加入 interfaces/ 目录,让自动 barrel 能覆盖
- Auto-regenerated repositories/index.ts 与 interfaces/index.ts

参照 storage 层已有的 IAuthStorage / IChatStorage / IUserStorage 模式。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 17:02:49 +08:00
admin 1151a9a61b fix:splash 界面重定向界面问题 2026-06-11 17:00:04 +08:00
admin e3d549d660 fix:splash 界面重定向界面问题 2026-06-11 16:06:36 +08:00
admin a6bc6941d4 refactor(splash): convert Skip to explicit guest login flow
- Splash Skip button now dispatches `AuthGuestLoginSubmitted` instead of
  direct routing, keeping guest auth under the state machine
- Update PWA install dialog copy ("Add to Home Screen") and drop favicon
  entry from manifest icons
- Add debug logging and routing sequence docs to splash-button
2026-06-11 15:58:48 +08:00
admin e557f084c4 feat: add PWA icons (192x192 and 512x512) to web manifest
Include new splash icons in public/manifest.json to support Progressive Web App installation and display across various device resolutions.
2026-06-11 15:18:25 +08:00
admin 2f4d414412 feat(utils): add structured error logging to Result.wrap
Integrate the Logger into `Result.wrap` so that caught exceptions are
recorded with stack trace, error type, and a `component: "Result"`
tag before being wrapped into a `Result<T>`. Errors are first
normalized via `toError` to preserve `.stack`, `.code`, and `.status`
fields, then logged through the standard pipeline (dev console in
development, JSON pipeline in production). Callers continue to receive
a `Result<T>` — re-throwing remains opt-in via `Result.unwrap`.
2026-06-11 14:58:54 +08:00
admin d189a18f03 chore(deps): add pino logger dependency
Add pino v10.3.1 to project dependencies for structured logging support, along with its transitive dependencies (pino-abstract-transport, pino-std-serializers, quick-format-unescaped, atomic-sleep, etc.).
2026-06-11 14:23:30 +08:00
admin 2b6d3924fd fix(chat): right-align user message row for proper mirror layout
Add align-self: flex-end to .bubbleRowUser so the user message row
sizes to its content and pins to the right edge of the chat area.
Combined with the existing flex-end cross-axis alignment, this places
the user avatar at the right edge with the bubble to its left,
producing a proper left-to-right AI / right-to-left user mirror.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 14:03:46 +08:00
admin 674df49e24 style(sidebar): align /sidebar screen with Flutter original
Match the Dart lib/ui/sidebar/sidebar_screen.dart + profile_view.dart
exactly:
- White inner shell with 24px padding
- Back button row (arrow icon + "Back" text, no "Profile" header)
- Single "Other" section with one "Log out" row
- Drop profile card, Account/Data/Session sections, and Sign-in CTA

Match Flutter row visuals in the shared SettingsSection:
- Gray (#f5f5f5) rounded row pill on a white card
- 20px chevron, 1px rgba(61,49,74,0.5) divider
- Destructive color #ff6b6b, 14px/600 black section title

Add tokens: --color-settings-card-background, --color-settings-row-background,
--color-settings-divider, --color-chevron-icon, --color-destructive.

Wire the BlocConsumer listener equivalent: on currentUser transitioning to
null, dispatch ChatAuthStatusChanged + AuthReset and router.replace("/chat").

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 14:02:52 +08:00
admin 2475cb3e45 feat(auth): add startup auth status check with device id fallback
Add AuthStatusChecker mounted in RootProviders to dispatch AuthStatusCheckSubmitted on mount. The new checkAuthStatusActor retrieves the device id, checks for an existing login or guest token, and falls back to a guest login API call when neither is present. Wires the new event/actor through the auth machine to enable automatic session restoration and guest-mode bootstrap.
2026-06-11 13:23:29 +08:00
admin 7c89f1b39d fix(chat): align message bubble and avatar in the same row
Change flex-direction from column to row on .bubbleRowAi and
.bubbleRowUser so the avatar and message content render side-by-side
as the JSX and JSDoc already intend.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-11 13:00:32 +08:00
admin 0c63b7dee4 feat(auth): sync OAuth provider tokens to backend via NextAuth session
Wire the Google/Facebook OAuth callback flow end-to-end so the provider's id_token (Google) and access_token (Facebook) captured by NextAuth are forwarded to the backend in exchange for business tokens:

- Extend the NextAuth config with jwt/session callbacks that surface `account.id_token` / `account.access_token` to the client during first sign-in
- Add an `OAuthSessionSync` bridge mounted inside `RootProviders` that listens to `useSession()` and dispatches new `AuthGoogleSyncSubmitted` / `AuthFacebookSyncSubmitted` events
- Add corresponding actors in the auth XState machine that call `authRepository.googleLogin` / `facebookLogin`, persisting the backend's `LoginResponse` through the existing repository path

This keeps all authentication orchestrated by the auth state machine while preserving NextAuth's OAuth redirect UX.
2026-06-11 12:59:23 +08:00
admin b50191ed50 refactor(auth): rename loginType to loginStatus and update related logic 2026-06-11 12:04:48 +08:00
admin 72941d9c9f style(pwa-install-dialog): redesign dialog to match Dart spec
Update the PWA install dialog styling and content to align with the
original Dart design, including a white background with large 40px
radius, 86x86 PNG icon, gradient primary button, and dynamic app title
sourced from AppConstants.
2026-06-11 11:29:52 +08:00
admin 39ef78e9ea refactor(sidebar): move SidebarPage/BottomNavItem enums to sidebar-state
Move the `SidebarPage` and `BottomNavItem` enum definitions from
`sidebar-machine.ts` to `sidebar-state.ts` to avoid a circular
dependency between the two modules. Since both enums are tightly
coupled to the state shape (they define the value sets of
`currentPage` and `selectedBottomNavItem`), they now live alongside
the state itself.

- Move enum declarations and types from `sidebar-machine.ts` to
  `sidebar-state.ts`
- Update `sidebar-events.ts` import path to reference `sidebar-state`
- Keep `sidebar-machine.ts` re-exporting `SidebarState` and
  `initialState` to preserve its public API
2026-06-11 10:35:57 +08:00