Find a file
RainbowBird b2fd492af0
Some checks are pending
CI / Detect changes (push) Waiting to run
CI / Lint (push) Blocked by required conditions
CI / Build Test (stage-web) (push) Blocked by required conditions
CI / Build Test (stage-tamagotchi) (push) Blocked by required conditions
CI / Build Test (ui-playgrounds) (push) Blocked by required conditions
CI / Build Test (stage-tamagotchi-godot) (push) Blocked by required conditions
CI / Unit Test (others) (push) Blocked by required conditions
CI / Unit Test (api-server-1) (push) Blocked by required conditions
CI / Unit Test (api-server-2) (push) Blocked by required conditions
CI / Unit Test (stage-tamagotchi) (push) Blocked by required conditions
CI / Unit Test (stage-ui-1) (push) Blocked by required conditions
CI / Unit Test (stage-ui-2) (push) Blocked by required conditions
CI / Unit Test (push) Blocked by required conditions
CI / Type Check (others) (push) Blocked by required conditions
CI / Type Check (desktop) (push) Blocked by required conditions
CI / Type Check (web) (push) Blocked by required conditions
CI / Type Check (push) Blocked by required conditions
CI / Check Provenance (push) Blocked by required conditions
Cloudflare Pages (Auth UI) / Deploy - ui-server-auth (push) Waiting to run
Cloudflare Workers / Build - docs (push) Waiting to run
Cloudflare Workers / Deploy - stage-web (push) Blocked by required conditions
Release Tamagotchi / Plan Updates (push) Waiting to run
Release Tamagotchi / Build (push) Blocked by required conditions
Release Tamagotchi / Build-1 (push) Blocked by required conditions
Release Tamagotchi / Build-2 (push) Blocked by required conditions
Release Tamagotchi / Build-3 (push) Blocked by required conditions
Release Tamagotchi / Build-4 (push) Blocked by required conditions
Release Tamagotchi / Publish Bundle (push) Blocked by required conditions
Release Tamagotchi / Promote Canary to Stable (push) Blocked by required conditions
Release Tamagotchi / Publish GitCode Release Mirror (push) Blocked by required conditions
Release Tamagotchi / Publish Distribution (push) Blocked by required conditions
Release Tamagotchi / Publish Distribution-1 (push) Blocked by required conditions
Release Tamagotchi / Publish Distribution-2 (push) Blocked by required conditions
Release Tamagotchi / Publish Distribution-3 (push) Blocked by required conditions
E2E Test - Tamagotchi (Linux) / X11 window render (Xvfb) (push) Waiting to run
E2E Test - Tamagotchi (Linux) / Wayland window render (weston headless) (push) Waiting to run
feat(server): support cookie sessions in api-server and cookie-only session-jwt in auth-server (#3657)
## Summary

This is **PR 1 of 4** for migrating Web authentication to a same-origin
BFF with Better Auth `HttpOnly` session cookies and moving Electron
token management to the main process.

This PR adds two strictly additive backend boundaries without changing
any existing Bearer JWT or OIDC flows:

1. **`server/apps/auth`**:
- Adds private `GET /internal/auth/session` (outside `/api/auth/*` rate
limiting and blocked at the public edge by `/internal/* -> 404`) so
`server/apps/api` can resolve Better Auth session cookies over
`AUTH_SERVER_INTERNAL_URL` without importing Better Auth or holding
`BETTER_AUTH_SECRET`.
- Adds cookie-only `POST /api/auth/session-jwt` to mint a 5-minute
stateless JWT (using Better Auth's `auth.api.signJWT` and existing JWKS
key set, matching `iss`, `aud`, `sub`, and `sid`) for Bearer-only
upstreams such as `cloud.airi.build`.
2. **`server/apps/api`**:
- Extends `resolveRequestAuth` to resolve `better-auth.session_token`
(and `__Secure-better-auth.session_token`) cookies via
`AUTH_SERVER_INTERNAL_URL/internal/auth/session` when no `Authorization:
Bearer` header is present.
- Enforces CSRF origin checks on cookie-authenticated mutations and
CSWSH trusted-origin checks on cookie-authenticated WebSocket upgrades
(`/ws/chat`, `/ws/v2/chat`, `/api/v1/audio/speech/ws`).
- Supports pre-authenticated `/ws/v2/chat` upgrades on open while
preserving anonymous upgrade + `chat:authenticate` for native clients.
3. **ADR**: Adds
`server/docs/ai/adr/2026-12-02-cookie-session-and-session-jwt-boundary.md`.

This PR is independent and based on `origin/main` (`4554c786a`).

## Change map

| Module | Before | After | Description |
| --- | --- | --- | --- |
| Auth routes (`server/apps/auth/src/routes.ts`, `auth.ts`) | Only
public `/api/auth/*` routes and OIDC token exchange exist. | Adds
private `GET /internal/auth/session` and cookie-only `POST
/api/auth/session-jwt` backed by `auth.api.signJWT`. | Keeps Better Auth
and its secret inside `server/apps/auth` while enabling same-origin
cookie BFFs. |
| API request auth (`server/apps/api/src/libs/request-auth.ts`,
`middlewares/auth.ts`, `audio-transcription-stream/route.ts`) | Accepts
`Authorization: Bearer` JWTs only. | Keeps Bearer priority, adds
internal cookie session resolution with CSRF/CSWSH origin validation and
ban re-checks. | Enables cookie-authenticated HTTP and streaming ASR
requests without duplicating Better Auth in `api-server`. |
| API WebSocket auth (`server/apps/api/src/app.ts`, `libs/ws-auth.ts`,
`routes/chat-ws/v2/index.ts`) | `/ws/chat` and `/api/v1/audio/speech/ws`
require `?token=`. `/ws/v2/chat` always requires `chat:authenticate`. |
Accepts trusted-origin session cookies on upgrade and pre-authenticates
`/ws/v2/chat` on open while keeping `?token=` and `chat:authenticate`
unchanged. | Removes browser URL query tokens when Web moves behind a
same-origin BFF. |

## Architecture and behavior

```mermaid
sequenceDiagram
  participant B as Browser / Web BFF
  participant API as server/apps/api
  participant AUTH as server/apps/auth
  participant DB as PostgreSQL

  B->>API: HTTP / WS upgrade with Cookie + trusted Origin
  API->>API: Validate CSRF / CSWSH origin rules
  API->>AUTH: GET /internal/auth/session (Cookie only)
  AUTH->>DB: Verify active session and ban state
  AUTH-->>API: 200 { userId, sessionId, expiresAt, ... }
  API->>DB: Load user row and re-check ban state
  API-->>B: Authenticated response or pre-authenticated WS peer
```

## Boundaries and risks

| Invariant or boundary | Failure mode | Protection | Evidence or gap |
| --- | --- | --- | --- |
| Better Auth isolation | `api-server` leaks `BETTER_AUTH_SECRET` or
imports Better Auth | Cookie validation stays in `auth-server` behind
private `GET /internal/auth/session` | Covered by
`routes-cookie-session.test.ts` and `request-auth.test.ts` |
| Public edge isolation for `/internal/auth/session` | Public caller
reaches internal route | Edge proxy blocks `/internal/*` with `404`
(same contract as `api-server`'s `/internal/auth/*`) | Existing Caddy
edge rule in `server/dev/caddy/Caddyfile`; Railway edge config not
modified in this PR |
| Cookie-only isolation on `/session-jwt` and `/internal/auth/session` |
Bearer JWT tries to mint new JWTs or resolve internal session |
`copyCookieHeaderOnly` strips `Authorization` before calling
`auth.api.getSession` | Covered by `routes-cookie-session.test.ts` |
| CSRF on cookie mutations and `/session-jwt` | Cross-site form or
script triggers state-changing call | Rejects `Sec-Fetch-Site:
cross-site` and untrusted `Origin` / `Referer` headers | Covered by
`routes-cookie-session.test.ts` and `request-auth.test.ts` |
| CSWSH on cookie WebSocket upgrades | Cross-site page opens WS using
browser cookie | `requireTrustedOriginForCookie: true` requires a
present, trusted `Origin` header | Covered by `request-auth.test.ts` |
| Transient internal auth failure on WS upgrade | Temporary 5xx closes
WS as permanent 4001 | `resolveCookieSession` throws on non-401
failures; WS upgrades close with retryable `1011`
(`createRetryableWsEvents`) | Covered by `request-auth.test.ts` |
| Existing Bearer / OIDC clients | Regression on Electron, Capacitor, or
current Web | Bearer path runs first and never invokes cookie lookup |
Covered by existing `request-auth.test.ts` and
`routes-oidc-token-auth.test.ts` |

## Verification

### Static checks

```text
pnpm exec eslint server/docs/ai/adr/2026-12-02-cookie-session-and-session-jwt-boundary.md server/apps/auth/src/auth.ts server/apps/auth/src/routes.ts server/apps/auth/src/tests/routes-cookie-session.test.ts server/apps/api/src/app.ts server/apps/api/src/middlewares/auth.ts server/apps/api/src/libs/request-auth.ts server/apps/api/src/libs/ws-auth.ts server/apps/api/src/libs/tests/request-auth.test.ts server/apps/api/src/routes/audio-transcription-stream/route.ts server/apps/api/src/routes/chat-ws/v2/index.ts server/apps/api/src/routes/chat-ws/v2/index.test.ts
# Passed (0 errors)

pnpm -F @proj-airi/auth-server typecheck
pnpm -F @proj-airi/api-server typecheck
# Passed (0 errors)
```

### Focused tests

```text
pnpm -F @proj-airi/auth-server exec vitest run src/tests/routes-cookie-session.test.ts src/tests/routes-oidc-token-auth.test.ts
# Passed: 2 files, 13 tests (plus 196 existing auth-server tests passed on the preceding full run)

pnpm -F @proj-airi/api-server exec vitest run src/libs/tests/request-auth.test.ts src/libs/tests/ws-auth.test.ts src/routes/chat-ws/v2/ src/routes/audio-transcription-stream/route.test.ts
# Passed: 7 files, 33 tests
```

### Not verified locally

- Full monorepo `pnpm typecheck` and `pnpm test:run` (left for GitHub
Actions CI).
- Live Railway private-network (`AUTH_SERVER_INTERNAL_URL`) deployment
verification (verified after merge).
2026-12-02 07:52:44 +00:00
.agents/skills docs(agents): merge the font rules into a visual design skill (#3617) 2026-11-26 02:45:11 +08:00
.claude feat(skills): add symlink to agent skills directory 2026-10-03 20:58:18 +08:00
.cursor/commands
.gemini chore: disable gemini review 2026-05-16 17:27:26 +08:00
.github feat(i18n,stage-tamagotchi): find missing keys behind translation helpers (#3636) 2026-11-29 16:36:18 +07:00
.vscode fix(repo): stop VS Code Java extensions from scanning node_modules (#3057) 2026-10-21 18:29:44 +08:00
.x18n feat(i18n,stage-tamagotchi): find missing keys behind translation helpers (#3636) 2026-11-29 16:36:18 +07:00
.zed
apps feat(core-agent): measure context tokens on the provider request (#3580) 2026-12-01 18:14:54 +00:00
bucket
deploy/openpanel feat(analytics): send product events to OpenPanel and PostHog in parallel (#3454) 2026-11-15 03:13:12 +08:00
docs feat(stage-tamagotchi,stage-ui,ui,i18n): add swipe back and right-click menus to the chat views (#3631) 2026-11-28 09:33:20 +00:00
engines/stage-tamagotchi-godot release: v0.15.4 2026-11-13 03:53:10 +07:00
evals docs(evals): add datasets, results, and conclusion to the formula speech eval (#3061) 2026-10-21 23:15:39 +08:00
integrations feat(photon-bot,stage-ui): add Photon iMessage integration and settings page (#3558) 2026-11-23 01:22:47 +00:00
nix chore(nix): update pnpmDeps hash (#3652) 2026-12-01 13:20:38 +00:00
packages fix(stage-ui): prevent client auth refresh races and spurious logouts (#3654) 2026-12-02 07:05:05 +00:00
patches fix(core-agent,stage-ui): send voice audio over Responses to OpenRouter (#3385) 2026-11-04 10:47:44 +00:00
plugins fix(web-extension): read the playing video on YouTube Shorts (#3463) 2026-11-20 10:41:40 +08:00
scripts chore: remove retired agent research from the product tree (#3612) 2026-11-24 17:33:29 +00:00
server feat(server): support cookie sessions in api-server and cookie-only session-jwt in auth-server (#3657) 2026-12-02 07:52:44 +00:00
services/computer-use-mcp fix(computer-use-mcp): keep unfinished dispatches unconfirmed (#3578) 2026-12-02 02:09:43 +08:00
.dockerignore ci: reduce CI time without removing checks (#3330) 2026-11-02 17:52:33 +08:00
.editorconfig chore(repo): remove obsolete files and configuration (#3055) 2026-10-21 17:19:03 +08:00
.gitattributes
.gitignore Revert "fix(model-driver-mediapipe): load MediaPipe assets at runtime instead of on install (#3366)" 2026-11-09 20:13:53 +08:00
.prototools chore(ci): added Godot vscode extension recommendation, and .prototools for managing dotnet versions 2026-04-23 02:19:44 +08:00
.tool-versions fix(security): update runtimes for CVE-2026-111497 (#3184) 2026-10-28 20:45:56 +08:00
AGENTS.md docs(agents): merge the font rules into a visual design skill (#3617) 2026-11-26 02:45:11 +08:00
alint.config.ts Revert "style: lint" 2026-08-26 20:13:10 +08:00
bump.config.ts Revert "style: lint" 2026-08-26 20:13:10 +08:00
CLAUDE.md
crowdin.yml
cspell.config.yaml feat(stage-tamagotchi): update with ergosphere-it, and publish each push to a dev channel (#3126) 2026-10-26 23:55:16 +08:00
default.nix
DESIGN.md docs(agents): merge the font rules into a visual design skill (#3617) 2026-11-26 02:45:11 +08:00
eslint-suppressions.json refactor(telegram-bot): remove explicit any types (#3561) 2026-11-22 22:51:37 +09:00
eslint.config.ts feat(computer-use-mcp,stage-tamagotchi): init and use AUV Wayland backend (#3629) 2026-12-01 01:09:04 +08:00
flake.lock feat(nix/server-runtime): init (#3538) 2026-11-19 22:16:08 +08:00
flake.nix feat(nix/server-runtime): init (#3538) 2026-11-19 22:16:08 +08:00
knip.json
LICENSE
package.json feat(i18n,stage-tamagotchi): find missing keys behind translation helpers (#3636) 2026-11-29 16:36:18 +07:00
pnpm-lock.yaml feat(auth): upgrade Better Auth to ^1.7.28 and enable refresh token reuse window (#3648) 2026-12-01 13:12:15 +00:00
pnpm-workspace.yaml feat(auth): upgrade Better Auth to ^1.7.28 and enable refresh token reuse window (#3648) 2026-12-01 13:12:15 +00:00
README.md feat(photon-bot,stage-ui): add Photon iMessage integration and settings page (#3558) 2026-11-23 01:22:47 +00:00
renovate.json chore(deps): add Renovate configuration (#3646) 2026-11-30 18:14:49 +00:00
skills-lock.json chore(.agents/skills): update existing skills 2026-08-05 20:46:16 +08:00
sponsorkit.config.js chore(docs): move the documentation site to moeru-ai/airi-docs (#2924) 2026-10-12 14:30:33 +08:00
tsconfig.json chore(pocket): exclude build and public folder in tsconfig 2026-05-04 19:47:38 +08:00
turbo.json ci: reduce CI time without removing checks (#3330) 2026-11-02 17:52:33 +08:00
uno.config.ts fix(stage-ui): use the Capacitor icon for subscriptions (#3624) 2026-11-27 16:37:51 +08:00
vite-env.d.ts feat(api,stage-ui): add the Capacitor, a subscription store of Flux (#2813) 2026-10-11 01:18:20 +08:00
vitest.config.ts test: run workspace tests through Turbo (#3048) 2026-10-21 20:44:37 +08:00
x18n.config.ts feat(i18n,stage-tamagotchi): find missing keys behind translation helpers (#3636) 2026-11-29 16:36:18 +07:00

Project AIRI

Re-creating Neuro-sama, a soul container of AI waifu / virtual characters to bring them into our world.

[Join Discord Server] [Try it] [简体中文] [日本語] [Русский] [Tiếng Việt] [Français] [한국어]

AIRI - A container of cyber living souls, re-creation of Neuro-sama | Product Hunt moeru-ai%2Fairi | Trendshift AIRI - #1 repository of the week across all languages | Trendshift

Heavily inspired by Neuro-sama

Tip

On Windows, you can also install AIRI with winget:

winget install MoeruAI.AIRI

Or install AIRI with Scoop:

scoop bucket add airi https://github.com/moeru-ai/airi
scoop install airi/airi

On macOS, you can install AIRI with Homebrew Cask without adding a custom tap:

brew install --cask airi

Warning

Attention: We do not have any officially minted cryptocurrency or token associated with this project. Please check the information and proceed with caution.

Note

We've got a whole dedicated organization @proj-airi for all the sub-projects born from Project AIRI. Check it out!

RAG, memory system, embedded database, icons, Live2D utilities, and more!

Tip

You can translate AIRI on Crowdin, or open a pull request that changes packages/i18n/src/locales/. Both ways update the same translations.

Do not submit a translation that is the same as the English text. Review rejects it. A string without a translation shows the English text.

Crowdin | Agile localization for tech companies

Have you dreamed about having a cyber living being (cyber waifu, digital pet) or digital companion that could play with and talk to you?

With the power of modern large language models like ChatGPT and famous Claude, asking a virtual being to roleplay and chat with us is already easy enough for everyone. Platforms like Character.ai (a.k.a. c.ai) and JanitorAI as well as local playgrounds like SillyTavern are already good-enough solutions for a chat based or visual adventure game like experience.

But, what about the abilities to play games? And see what you are coding at? Chatting while playing games, watching videos, and is capable of doing many other things.

Perhaps you know Neuro-sama already. She is currently the best virtual streamer capable of playing games, chatting, and interacting with you and the participants. Some also call this kind of being "digital human." Sadly, as it's not open sourced, you cannot interact with her after her live streams go offline.

Therefore, this project, AIRI, offers another possibility here: let you own your digital life, cyber living, easily, anywhere, anytime.

Recent DevLogs & Stories

What's So Special About This Project?

Unlike the other AI driven VTuber open source projects, アイリ was built with support of many Web technologies such as WebGPU, WebAudio, Web Workers, WebAssembly, WebSocket, etc. from the first day.

Tip

Worrying about the performance drop since we are using Web related technologies?

Don't worry, while the Web browser version is meant to give an insight into how much we can push and do inside browsers and webviews, we will never fully rely on this. The desktop version of AIRI is capable of using native NVIDIA CUDA and Apple Metal by default (thanks to HuggingFace & the beloved candle project), without any complex dependency management. Considering the tradeoff, it is partially powered by Web technologies for graphics, layouts, animations, and the WIP plugin system for everyone to integrate things.

This means that アイリ is capable of running on modern browsers and devices and even on mobile devices (already done with PWA support). This brings a lot of possibilities for us (the developers) to build and extend the power of アイリ VTuber to the next level, while still leaving the flexibility for users to enable features that require TCP connections or other non-Web technologies such as connecting to a Discord voice channel or playing Minecraft and Factorio with friends.

Note

We are still in the early stage of development where we are seeking out talented developers to join us and help us to make アイリ a reality.

It's ok if you are not familiar with Vue.js, TypeScript, and devtools required for this project, you can join us as an artist, designer, or even help us to launch our first live stream.

Even if you are a big fan of React, Svelte or even Solid, we welcome you. You can open a sub-directory to add features that you want to see in アイリ, or would like to experiment with.

Fields (and related projects) that we are looking for:

  • Live2D modeller
  • VRM modeller
  • VRChat avatar designer
  • Computer Vision
  • Reinforcement Learning
  • Speech Recognition
  • Speech Synthesis
  • ONNX Runtime
  • Transformers.js
  • vLLM
  • WebGPU
  • Three.js
  • WebXR (checkout the another project we have under the @moeru-ai organization)

If you are interested, why not introduce yourself here? Would like to join part of us to build AIRI?

Current Progress & Roadmap

Capable of

  • Brain
  • Ears
    • Audio input from browser
    • Audio input from Discord
    • Client side speech recognition
    • Client side talking detection
  • Mouth
    • Multi-provider voice synthesis, including ElevenLabs, Microsoft/Azure Speech, OpenAI-compatible TTS, Alibaba Cloud Model Studio, and local Kokoro TTS
  • Body
    • VRM support
      • Control VRM model
    • VRM model animations
      • Auto blink
      • Auto look at
      • Idle eye movement
    • Live2D support
      • Control Live2D model
    • Live2D model animations
      • Auto blink
      • Auto look at
      • Idle eye movement

Development

For detailed instructions to develop this project, follow CONTRIBUTING.md

Note

By default, pnpm dev will start the development server for the Stage Web (browser version). If you would like to try developing the desktop version, please make sure you read CONTRIBUTING.md to setup the environment correctly.

pnpm i
pnpm dev

Stage Web (Browser Version at airi.moeru.ai)

pnpm dev

Stage Tamagotchi (Desktop Version)

pnpm dev:tamagotchi

A Nix package for Tamagotchi is included. To run airi with Nix, first make sure to enable flakes, then run:

nix run github:moeru-ai/airi

NixOS

Electron requires shared libraries that aren't in standard paths on NixOS. Use the FHS shell defined in flake.nix:

nix develop .#fhs
pnpm dev:tamagotchi

Stage Pocket (Mobile Version)

Start the development server for the capacitor:

pnpm dev:pocket:ios --target "<DEVICE_ID_OR_SIMULATOR_NAME>"
# Or
CAPACITOR_DEVICE_ID_IOS="<DEVICE_ID_OR_SIMULATOR_NAME>" pnpm dev:pocket:ios

Quote the target: simulator names such as iPhone 16 Pro contain spaces.

You can see the list of available devices and simulators by running pnpm -F @proj-airi/stage-pocket exec cap run ios --list. @capacitor/cli is declared in apps/stage-pocket, so cap does not resolve from the repository root.

If you need to connect server channel on pocket in wireless mode, you need to start tamagotchi as root:

sudo pnpm dev:tamagotchi

Then enable secure websocket in tamagotchi settings/connections.

Documentation Site

The documentation site lives in moeru-ai/airi-docs.

Publish

Run bumpp to update the monorepo version:

npx bumpp --no-commit --no-tag

Support of LLM API Providers (powered by xsai)

Sub-projects Born from This Project

flowchart LR
  subgraph Apps[Stage applications]
    Web[stage-web]
    Desktop[stage-tamagotchi]
    Pocket[stage-pocket\nexperimental]
  end

  subgraph Shared[Shared product packages]
    StageUI[stage-ui]
    Domain[core-agent\ncore-character]
    Audio[pipelines-audio]
    Renderers[stage-ui-live2d\nstage-ui-three and renderers]
    SDK[server-sdk\nserver-shared]
  end

  subgraph Channel[Desktop server channel]
    Runtime[server-runtime]
  end

  subgraph Integrations[Source-configured integrations]
    Discord[discord-bot]
    Minecraft[minecraft-bot]
    Other[Telegram, Factorio, MCP, and others]
  end

  subgraph Hosted[Hosted backend]
    Edge[Caddy]
    API[api-server]
    Auth[auth-server]
    Database[(PostgreSQL)]
    Cache[(Redis)]
  end

  Web --> StageUI
  Desktop --> StageUI
  Pocket --> StageUI
  StageUI --> Domain
  StageUI --> Audio
  StageUI --> Renderers
  StageUI --> SDK
  Desktop --> Runtime
  SDK <-->|server channel| Runtime
  Discord --> SDK
  Minecraft --> SDK
  Other -. optional .-> SDK
  Edge --> API
  Edge --> Auth
  API --> Database
  API --> Cache
  Auth --> Database
  Auth --> Cache

Similar Projects

Open sourced ones

Non-open-sourced ones

Project Status

Repobeats analytics image

Acknowledgements

Supporters

Thank you for supporting Project AIRI through OpenCollective, Patreon, and Ko-fi.

Project AIRI supporters

Special Thanks

Special thanks to all contributors for their contributions to Project AIRI ❤️

Star History

Star History Chart