Commit Graph
56 Commits
Author SHA1 Message Date
RainbowBird a3a401d79d feat(server): new metrics for auth
- Added a new ObservableGauge for distinct active users to track real active user count, mitigating session row inflation issues.
- Updated the Grafana dashboard to reflect changes, including the removal of redundant WS Connections panel and the addition of new metrics for active sessions and distinct users.
- Improved documentation for verification automation processes, outlining a structured approach to automate verification steps and maintain evidence of tests.
2026-05-15 18:54:05 +08:00
RainbowBird 3984677b01 feat(analytics): integrate PostHog for server-side event tracking
- Added a new PostHog client for capturing server-side business events such as Stripe webhooks and subscription state changes.
- Implemented various tracking functions for pricing funnel steps, character creation, and chat session starts.
- Enhanced the flux meter tests to handle partial charges and report unbilled flux correctly.
- Updated the CharacterDialog and Flux settings pages to track user interactions with analytics events.
- Introduced a mechanism to identify users on PostHog based on authentication state to ensure accurate funnel tracking.
- Added necessary dependencies for PostHog integration in the project.
2026-05-15 16:20:47 +08:00
Lulu 98b1b9c34f feat(server): env-based trusted origins for Capacitor dev (#1763)
## Description

Adds optional env **`ADDITIONAL_TRUSTED_ORIGINS`**: comma-separated
browser origins that are trusted for **CORS (`/api/*`)**, **Stripe
return URLs**, **Better Auth `trustedOrigins`**, and **dynamic web OIDC
redirect URIs**.

LAN / non-localhost Capacitor dev (e.g. Pocket + Vite on
`https://10.x:5273`) no longer relies on broad private-IP regex;
operators list exact origins in `.env.local` and restart the API server
after changes.

## Linked Issues

<!-- N/A -->

## Additional Context

Pocket iOS dev workflow: `cap`/`capacitor.config` often points at a LAN
HTTPS origin; without this allowlist the API rejects those
`Origin`/`Referer`/`redirect_uri` bases. Review can stay focused on
**`apps/server/src/libs/env.ts`**,
**`apps/server/src/utils/origin.ts`**, and wiring in **`app.ts`**,
**Stripe**, **auth routes**.
2026-05-14 16:17:13 +08:00
RainbowBird 272cdae03b feat(server/otel): restructure observability metrics and add active sessions gauge
- Moved RateLimitMetrics import path to a more centralized location.
- Introduced a new file for active sessions gauge to track user sessions in the database.
- Updated index.ts to include new metrics and ensure proper initialization of observability metrics.
- Modified various routes and services to utilize the new observability structure.
- Added smoke tests for HTTP and WebSocket metrics to ensure proper metric registration and functionality.
- Enhanced error handling for metrics reading failures to improve observability.
2026-05-12 23:10:13 +08:00
RainbowBird d24b22a561 refactor(server/otel): hono otel integrate 2026-05-11 12:01:57 +08:00
RainbowBird 21b180ced7 refactor(server/otel): enhance otel setup with improved SDK lifecycle management 2026-05-10 23:43:18 +08:00
RainbowBird 917450fdfb feat(server/otel): enhance observability with new metrics for email, rate limiting, and billing
- Added new metrics for email service including send, failures, and duration tracking.
- Introduced rate limit metrics to monitor blocked requests and improve abuse detection.
- Enhanced billing metrics to track credited and unbilled flux, as well as TTS character processing.
- Updated OpenAI and Stripe routes to utilize new metrics for better revenue tracking and rate limiting.
- Implemented a smoke test for OpenTelemetry metrics registration to ensure visibility at startup.
2026-05-08 23:35:38 +08:00
RainbowBird f8d1fa7a64 refactor(server): drop redis stream + worker role (#1792)
The Redis Stream `billing-events` + `worker` Railway role +
advisory-lock poller layered together didn't actually buy us reliability
— `debitFlux` swallowed XADD failures, leaving the door open to "balance
updated, ledger row never written". Collapse the whole thing back to:
`creditFlux` and `debitFlux` write `flux_transaction` ledger rows inline
within the same DB transaction that mutates `user_flux`, and `(user_id,
request_id)` remains the partial unique index that keeps retries safe.

Concrete changes:
- Inline ledger inserts in `BillingService.{debitFlux, creditFlux,
creditFluxFromStripeCheckout, creditFluxFromInvoice}`; drop `billingMq`
and `publishEvent` plumbing entirely.
- `routes/openai/v1` writes `llm_request_log` synchronously via the
existing `requestLogService`; the duplicate `llm-request-log.ts` service
module is removed.
- `bin/run-worker.ts`, `libs/mq/*`,
`services/billing/billing-events.ts`,
`services/billing/billing-consumer-handler.ts`, and matching tests are
deleted. CLI now exposes only `api`.
- `BILLING_EVENTS_*` env vars and the `DEFAULT_BILLING_EVENTS_STREAM`
helper are dropped; `docker-compose.yml` no longer ships a worker
service.
- `docs/ai-context/{workers-and-runtime, billing-architecture,
redis-boundaries-and-pubsub, data-model-and-state,
architecture-overview, README}.md`, `CLAUDE.md`, and the existing
verification docs are updated to describe the single-process synchronous
pipeline.

Tests: 29 files / 247 cases pass. Production deployments need to drop
the worker Railway service after this lands.
2026-05-08 21:14:01 +08:00
hahaqwq eba047328a revert(server): remove .well-known/assetlinks.json (revert #1772) (#1789) 2026-05-08 21:14:01 +08:00
RainbowBird 99956014fa feat(server): admin api (#1788) 2026-05-08 21:14:00 +08:00
RainbowBird d0e2b450cd feat(stage-ui): chat sync (#1775) 2026-05-08 21:14:00 +08:00
hahaqwqandRainbowBird ae8552695b feat(server): add .well-known/assetlinks.json for Android deeplinks (#1772)
Co-authored-by: RainbowBird <rbxin2003@outlook.com>
2026-05-08 21:14:00 +08:00
RainbowBird 6f0b7e0b9b feat(auth): delete account (#1756) 2026-04-28 20:53:00 +08:00
RainbowBirdandLiet Blue 172e4ce59c feat(auth): email login & profile (#1745)
Co-authored-by: Liet Blue <127093491+lietblue@users.noreply.github.com>
2026-04-28 00:07:38 +08:00
RainbowBird 8967bbe211 feat(server): add TTS support with per-character billing 2026-04-17 02:59:14 +08:00
RainbowBird 57533044f7 feat(server): add gateway and model configuration to environment variables 2026-04-17 02:59:14 +08:00
RainbowBird a11727020a feat(server/billing): implement debt ledger for TTS service using FluxMeter 2026-04-17 02:59:14 +08:00
RainbowBird 93888e6935 feat(server): use stripe product as flux pricing (#1640) 2026-04-12 04:32:42 +08:00
RainbowBird d782313464 feat(auth): jwt sign 2026-04-02 17:48:12 +08:00
RainbowBird 2eb30d6081 docs(auth): ai-context 2026-04-02 17:48:12 +08:00
RainbowBird f1fe161bc0 feat(auth): OIDC (#1531) 2026-04-02 04:24:04 +08:00
RainbowBird 33bf61f3f7 fix(server): no cache 2026-03-30 19:45:43 +08:00
RainbowBird bdb01d30f4 feat(auth): Bearer token handling and OAuth token extraction (#1501) 2026-03-28 20:27:47 +08:00
RainbowBird 4a85654d9b feat(server/otel): follow opentelemetry metrics sharded 2026-03-28 04:57:28 +08:00
RainbowBird 45bc5fef22 feat(server/otel): integrate OpenTelemetry logging and emit logs with context 2026-03-28 03:59:09 +08:00
RainbowBird 2f730ef93a feat(server): refactor flux auditing to transaction logging 2026-03-28 02:25:44 +08:00
RainbowBird 750e48ad95 refactor(server): redesign server routes structure 2026-03-28 02:25:44 +08:00
RainbowBird bf85158aa9 fix(server,stage-ui,i18n): address PR #1376 review comments 2026-03-28 02:25:44 +08:00
RainbowBird 8322c2c622 refactor(server): split mq libs, organize billing services structure 2026-03-28 02:25:44 +08:00
RainbowBird 0a2fefc304 refactor(server): rename tests folder 2026-03-28 02:25:44 +08:00
RainbowBird eab60d0bdb feat(server): reimplement message queue, drop outbox 2026-03-28 02:25:44 +08:00
RainbowBird 563d50fbee feat(server): retry when booting error 2026-03-28 02:25:44 +08:00
RainbowBird ef18772798 feat(server): message queue 2026-03-28 02:25:44 +08:00
RainbowBird 9b8d1f6ab7 feat(server): flux aduit (#1482) 2026-03-28 02:25:44 +08:00
RainbowBird 97cadd5f7a fix(stage-ui): update onboarding provider list and improve validation logic 2026-03-28 02:25:44 +08:00
RainbowBird 0f9ea751e5 feat(server): official provider router (#1117) 2026-03-28 02:25:44 +08:00
RainbowBird c78ac2ccf1 fix(server): collect metrics correctly 2026-03-28 02:25:44 +08:00
RainbowBird 3917af0250 refactor(server): organize order 2026-03-28 02:25:44 +08:00
RainbowBirdandClaude 963306944e feat(server): add OpenTelemetry observability stack (#1154)
Co-authored-by: Claude <noreply@anthropic.com>
2026-03-28 02:25:44 +08:00
RainbowBird 4e510bf5c2 feat(server): stripe service, more stripe table 2026-03-28 02:25:44 +08:00
RainbowBird 889a1e0800 feat(server): redis, config kv integration 2026-03-28 02:25:44 +08:00
RainbowBird fc51738209 feat(server): stripe integration and credits system (#1024) 2026-03-28 02:25:44 +08:00
RainbowBird 0732827a9e refactor(server): replace postgres-js to pg to support auto-instrumentation 2026-03-09 18:47:34 +08:00
RainbowBird 47d97320ef fix(server): collect metrics correctly 2026-03-06 04:14:04 +08:00
RainbowBird 284b100030 feat(server): add OpenTelemetry observability stack 2026-03-06 02:58:44 +08:00
RainbowBird 6c7aa855cf feat(server): log api error 2026-03-04 19:06:24 +08:00
RainbowBirdandSergei Kochanov 24eb86f682 fix(server): limited body size to 1MB
Co-authored-by: Sergei Kochanov <47022537+sergeykochanov@users.noreply.github.com>
2026-03-03 00:44:58 +08:00
RainbowBird 3c1fbdb654 refactor(server): move auth, db and env to libs 2026-03-02 16:55:16 +08:00
RainbowBird f787485b29 feat(server): health check route 2026-02-26 17:53:14 +08:00
RainbowBird ea05075550 feat(server): database migration 2026-02-26 15:01:06 +08:00