Commit Graph
1717 Commits
Author SHA1 Message Date
Luluandautofix-ci[bot] a40cbd67cf fix(stage-layouts): mount LoginDrawer in settings layout on mobile (#1675)
---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by-agent: Cursor <unknown@example.com>
2026-04-18 18:26:19 +08:00
github-actions[bot]andCrowdin Bot 2a444245ae chore(i18n): update translations (#1678)
This PR contains updated translations from Crowdin. Created from [GitHub
Actions](https://github.com/moeru-ai/airi/blob/main/.github/workflows/crowdin-cron-sync.yml).

You can review the source of translations
[here](https://crowdin.com/project/proj-airi)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-18 18:20:48 +08:00
Neko Ayaka 70495439ad refactor(core-agent,stage-ui): move spark-notify agent to core-agent 2026-04-17 16:18:42 +08:00
github-actions[bot]andCrowdin Bot 8d6905481b chore(i18n): update translations (#1672)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-17 15:09:06 +08:00
RainbowBird bef1598179 fix(stage-ui): refresh token concurrency 2026-04-17 02:59:14 +08:00
RainbowBird 8967bbe211 feat(server): add TTS support with per-character billing 2026-04-17 02:59:14 +08:00
Jensen Huang c14e9547d9 feat(stage-tamagotchi): improve updater cleanup lane and admin diagnostics 2026-04-16 22:58:10 +08:00
NJX 5187572c42 fix(stage-ui/inference): correctness and resilience fixes for browser-side inference infra (#1663)
## Summary

Addresses **Phase 1** of the inference infrastructure roadmap (#1661).
Six correctness and resilience issues fixed across adapters, workers,
and the unified protocol layer.

**Scope:** `packages/stage-ui/src/libs/inference/`,
`packages/stage-ui/src/libs/workers/`, `packages/stage-ui/src/workers/`

---

## Problems & Motivation

### 1. Kokoro Singleton cannot recover from terminal state

`getKokoroAdapter()` creates a singleton that is never reset. Once the
adapter reaches `terminated` or `error` (restarts exhausted), the
singleton is permanently dead -- users must refresh the page.

**Root cause:** `globalAdapter` is only re-created when `null`, never
checks the state of the existing instance. `scheduleRestart()` silently
returns when retries are exhausted, leaving state stuck at `'error'`
instead of transitioning to `'terminated'`.

**Fix:**
- `getKokoroAdapter()` now detects `terminated` / `error` states and
re-creates the adapter automatically
- `scheduleRestart()` in both Kokoro and Whisper adapters transitions to
`'terminated'` when max restarts are exhausted, making the dead state
detectable

### 2. `voices!` non-null assertion after nullable assignment

`kokoro.ts:275` assigns `voices = (response.metadata?.voices as Voices)
?? null` (can be null), but L288 returns `voices!` -- if the worker
returns unexpected metadata, callers receive `null` but the type system
promises `Voices`, causing downstream crashes.

**Fix:** Replaced with explicit null check + throw, routing into the
existing error recovery path.

### 3. Whisper Worker silently drops concurrent requests

The worker's `runInference()` has `if (processing) return` which
silently drops the request. The adapter's `waitForMessage()` never
receives a response, causing the Promise to hang for 120 seconds until
timeout.

**Root cause:** The bare boolean is safe in a single-threaded worker --
the real bug is the silent `return` with no error response.

**Fix:** Replaced with `sendError(requestId, ...)` so the adapter
receives an immediate rejection.

### 4. Whisper adapter leaks event listeners on worker restart

`ensureWorker()` attaches anonymous `message` and `error` listeners each
time a new Worker is created. `destroyWorker()` only calls
`worker.terminate()` without removing listeners. On restart paths
(`scheduleRestart -> ensureWorker`), old Worker listener closures may
prevent GC.

**Impact:** Whisper is most critical (2 listeners + restart logic).
Kokoro and Background Removal have the same pattern but lower risk.

**Fix:** All 3 adapters now store listener references and call
`removeEventListener` before `terminate()`. Whisper's
`terminateAdapter()` routes through `destroyWorker()` instead of direct
`worker.terminate()`.

### 5. Error classification is incomplete

`classifyError()` only matches 3 string patterns (OOM, DEVICE_LOST,
TIMEOUT). `LOAD_FAILED` and `INFERENCE_FAILED` are defined in the
`InferenceErrorCode` type but never produced. All workers hardcode
`recoverable: false`.

**Fix:**
- `classifyError(error, phase?)` gains a `phase` parameter: specific
patterns (OOM etc.) take priority, unmatched errors fall through to
`LOAD_FAILED` / `INFERENCE_FAILED` based on phase
- New `isRecoverable(code)` helper: TIMEOUT and DEVICE_LOST are
recoverable
- All 3 workers' `sendError()` updated to pass phase and use dynamic
recoverability

### 6. No dtype/device fallback chain

Kokoro Worker attempts model loading once with the requested dtype;
failure is terminal. Whisper Worker hardcodes `encoder_model: 'fp16'`
which crashes on devices that don't support it.

**Fix:**
- **Kokoro Worker:** New `DTYPE_FALLBACK` and `DEVICE_FALLBACK` maps.
Tries `fp16 -> fp32 -> q8 -> q4` on the same device, then `webgpu ->
wasm` device fallback. Reports `actualDtype` and `actualDevice` in
`ModelReadyResponse.metadata`
- **Whisper Worker:** Wraps fp16 encoder load in try-catch; falls back
to fp32

---

## State after changes

| Component | Before | After |
|-----------|--------|-------|
| Kokoro singleton | Returns dead instance forever after terminal error
| Auto-detects and re-creates |
| `voices` return | `voices!` can return null, lying to type system |
Explicit throw, enters error recovery path |
| Whisper Worker concurrency | Silent drop, Promise hangs 120s |
Immediate error response |
| Event listeners | Anonymous, never cleaned up | Stored references,
removeEventListener on destroy |
| Error classification | 4/6 codes reachable, recoverable hardcoded
false | 6/6 codes reachable, dynamic recoverability |
| dtype loading | Single attempt, failure is terminal | Progressive
fallback chain, reports actual config used |

---

## Files changed

| File | Changes |
|------|---------|
| `libs/inference/protocol.ts` | `classifyError` phase param, new
`isRecoverable` helper |
| `libs/inference/protocol.test.ts` | **New** -- 14 tests for
classification and recoverability |
| `libs/workers/worker.ts` | Silent drop fix, sendError phase, fp16
fallback |
| `workers/kokoro/worker.ts` | sendError phase, dtype/device fallback
chain |
| `workers/background-removal/worker.ts` | sendError phase |
| `libs/inference/adapters/whisper.ts` | Listener cleanup,
terminateAdapter uses destroyWorker, scheduleRestart terminal state |
| `libs/inference/adapters/kokoro.ts` | Singleton recovery, voices
assertion fix, listener cleanup, scheduleRestart terminal state |
| `libs/inference/adapters/kokoro.test.ts` | **New** -- 5 tests for
singleton and state transitions |
| `libs/inference/adapters/background-removal.ts` | Listener cleanup,
extracted destroyWorker |

## Test plan

- [x] `pnpm exec vitest run packages/stage-ui/src/libs/inference/` --
30/30 tests pass (protocol, kokoro adapter, GPU coordinator, load queue)
- [x] `pnpm -F @proj-airi/stage-ui typecheck` -- clean
- [x] `npx eslint` on all 9 changed files -- clean
- [x] Pre-commit hooks pass

Co-authored-by-agent: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:11:05 +08:00
Nashchenncandautofix-ci[bot] bf41655dbb feat(core-agent): extract pure runtime logic from stage-ui into core-agent (#1524)
Depends on #1487 

## Summary

- Introduce `packages/core-agent` — a new pure-runtime package that
extracts zero-Vue/Pinia algorithmic logic from `@proj-airi/stage-ui`,
following a "compatible facade + core sinking" strategy
- Migrate shared chat types, LLM streaming types, chat hook registry,
session message merge logic, context registry algorithm, and LLM service
utilities into `core-agent`
- `stage-ui` files are preserved as re-exports / thin wrappers — all
external imports, store IDs, and public APIs remain unchanged

## Motivation

`stage-ui` currently mixes pure agent runtime logic (algorithms, type
definitions, stateless utilities) with Vue/Pinia state management and
browser-specific adapters. This coupling makes it hard to:
- Test agent logic in isolation
- Reuse agent algorithms outside of Vue contexts (e.g., server-side,
CLI, other frameworks)
- Reason about the boundary between "what the agent does" vs "how the UI
manages state"

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by-agent: Unknown <unknown@example.com>
2026-04-16 16:09:22 +08:00
Octopus 11ac511dd9 feat(stage-ui,i18n): add MiniMax Speech TTS provider (#1594)
## Summary

- Add `minimax-speech` TTS provider using MiniMax's T2A v2 API
- Implement streaming SSE response with hex-encoded audio decoding (no
external dependency required)
- Include a curated static voice list (English and Mandarin voices)
- Add `speech-2.8-hd` (default) and `speech-2.8-turbo` model entries
- Support configurable base URL defaulting to `https://api.minimax.io`
- Add i18n translations for all 9 supported locales

Closes #1274

## Implementation Details

The provider uses a custom `fetch` interceptor within the
`SpeechProvider` interface to:
1. Parse the incoming OpenAI-style request (`input`, `voice`, `model`)
2. Call MiniMax's `/v1/t2a_v2` SSE streaming endpoint
3. Decode hex-encoded audio chunks from SSE events (skipping the summary
chunk with `status=2`)
4. Return a concatenated `audio/mpeg` response

## API Reference

- TTS: https://platform.minimax.io/docs/api-reference/speech-t2a-http
2026-04-16 16:07:30 +08:00
github-actions[bot]andCrowdin Bot b867980087 chore(i18n): update translations (#1669)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-16 15:59:40 +08:00
Makito 186a70fbc7 fix(stage-pages): replace with vueuse utilities 2026-04-16 01:35:14 +09:00
DrHuangMHT 9d5c9e9332 chore(deps): remove deprecated unplugin-vue-router (#1664) 2026-04-15 15:02:10 +08:00
akrlin e75b6618b3 fix(stage-ui,i18n) fix a bug when change language (#1666) 2026-04-15 14:47:26 +08:00
Neko Ayaka b9f88ef84f style: lint 2026-04-15 14:44:59 +08:00
Neko Ayaka f286464e03 chore(deps): bump dependencies 2026-04-15 14:44:59 +08:00
github-actions[bot]andCrowdin Bot fff6560e2d chore(i18n): update translations (#1665)
This PR contains updated translations from Crowdin. Created from [GitHub
Actions](https://github.com/moeru-ai/airi/blob/main/.github/workflows/crowdin-cron-sync.yml).

You can review the source of translations
[here](https://crowdin.com/project/proj-airi)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-15 11:15:08 +08:00
Neko Ayaka f7a9a7bf76 refactor(vishot-*,scenarios-*): better structure, better api, and markup components 2026-04-15 04:51:00 +08:00
Makito bcd89786a0 fix(stage-pages,stage-shared,stage-ui): auto fit IO tracer 2026-04-15 02:56:04 +09:00
Makito a620c2395b feat(stage-tamagotchi,i18n,stage-pages): localize IO Tracer title and update route metadata 2026-04-15 02:17:10 +09:00
Makito b0b48840ec feat(stage-tamagotchi,stage-pages): initialize IO trace viewer 2026-04-15 02:17:10 +09:00
Makito dbe85583bf feat(stage-pages,stage-shared,stage-ui): better OTel identifiers 2026-04-15 02:17:09 +09:00
Makito 7d544d03a1 feat(stage-shared,stage-ui): add store and integrations for IO tracer 2026-04-15 02:17:09 +09:00
0c3655ee8d refactor(inference): replace custom AsyncMutex with async-mutex package (#1660)
## Summary

Address maintainer feedback from #1622 ([@nekomeowww's
comment](https://github.com/moeru-ai/airi/pull/1622#discussion_r2342632282)).

The project already uses `async-mutex` in other packages
(`stage-tamagotchi`, `electron-screen-capture`), and it's in the
workspace catalog. This replaces the custom `AsyncMutex` implementation
with the shared dependency.

- Replace `AsyncMutex.run()` → `Mutex.runExclusive()`
- Replace `AsyncMutex.reset()` → `Mutex.cancel()`
- Remove `async-mutex.ts` and its unit tests
- Remove `AsyncMutex` from inference barrel exports
- Add `async-mutex` as direct dependency of `@proj-airi/stage-ui`

**Regarding `@moeru/eventa` suggestion**
([comment](https://github.com/moeru-ai/airi/pull/1622#discussion_r2342631692)):
The `waitForMessage` pattern is a thin request-response abstraction over
`postMessage`, where the worker is driven by `@huggingface/transformers`
internally. Eventa's transport-agnostic RPC is better suited for
bidirectional channels (Electron IPC, WebSocket) than for this one-way
"post and wait" pattern. No change for now.

## Test plan

- [x] `pnpm exec vitest run packages/stage-ui/src/libs/inference/` — 11
tests pass (4 removed with custom impl)
- [x] `pnpm -F @proj-airi/stage-ui typecheck` — no errors
- [x] `pnpm lint:fix` — no new errors in changed files

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-04-14 11:47:33 +08:00
github-actions[bot]andCrowdin Bot 803442f5d8 chore(i18n): update translations (#1659)
This PR contains updated translations from Crowdin. Created from [GitHub
Actions](https://github.com/moeru-ai/airi/blob/main/.github/workflows/crowdin-cron-sync.yml).

You can review the source of translations
[here](https://crowdin.com/project/proj-airi)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-14 10:07:31 +08:00
Makito 826861f9c9 feat(stage-layouts): add an optional disableBackButton to route metadata 2026-04-14 01:12:48 +09:00
147d077aa7 feat(inference): unify and optimize WebGPU inference pipeline (#1622)
## Problem

The WebGPU inference pipeline had several structural issues:

1. **No unified protocol** — Kokoro TTS, Whisper ASR, and Background
Removal workers each used their own ad-hoc message formats. Adding a new
model meant reinventing worker communication from scratch.
2. **Infrastructure existed but was disconnected** —
`GPUResourceCoordinator`, `LoadQueue`, `InferenceWorkerManager`, and
`protocol.ts` were all implemented but had zero consumers. The adapters
duplicated the same lifecycle/timeout/mutex patterns independently.
3. **Performance gaps** — Kokoro only offered fp32 on WebGPU (no fp16),
Whisper warm-up compiled shaders for 187.5s of dummy audio, audio
transfer went through unnecessary WAV blob encode/decode, and
`listVoices` reloaded the model every time.
4. **Silent failures** — Whisper worker's `generate()` had no try-catch;
errors were swallowed and the main thread waited until timeout.
5. **No graceful degradation** — Whisper and Background Removal workers
hardcoded `device: 'webgpu'` with no WASM fallback.
6. **No observability** — Only Kokoro had performance tracing. No
adapter reported status to `useInferenceStatus`. No cache management UI
existed.
7. **Dead code accumulation** — Old `KokoroWorkerManager` (232 lines),
legacy Whisper message types, and scattered duplicate constants.

## Changes

### Phase 0 — Critical Performance & Bugs
- Add `fp16-webgpu` dtype for Kokoro TTS (~2x inference speed on
supported GPUs)
- Fix Whisper warm-up tensor from `[1, 128, 3000]` → `[1, 128, 1]`
(minimal shader compilation)
- Fix Whisper worker silent error bug (add try-catch to `generate()` and
`load()`)

### Phase 1 — Data Transfer & Caching
- Switch Kokoro audio to Float32Array transferable (skip WAV blob encode
in worker, lightweight WAV encode on main thread)
- Cache `listVoices` results (skip redundant model reload when adapter
state is `ready`)
- Normalize progress reporting to 0-100 across all adapters,
differentiate `warmup` phase

### Phase 2 — Protocol Unification & Infrastructure
- Migrate all 3 workers + 3 adapters to unified `protocol.ts` message
types (`load-model`, `run-inference`, `model-ready`, `inference-result`,
`progress`, `error`)
- Wire `GPUResourceCoordinator` into all adapters (VRAM allocation
tracking, LRU ordering, memory pressure events)
- Wire `LoadQueue` into all adapters (priority-based sequential model
loading: TTS=10 > ASR=5 > BG_REMOVAL=1)
- Add `coordinator.ts` global singleton for GPU coordinator + load queue
- Add WebGPU detection + WASM fallback in Whisper and Background Removal
workers

### Phase 3 — Error Recovery & Observability
- Add restart logic with exponential backoff to Whisper adapter
(matching Kokoro's existing pattern)
- Integrate `classifyError()` (OOM / DEVICE_LOST / TIMEOUT
classification) in Whisper adapter
- Extend `defaultPerfTracer` to Whisper `transcribe()` and Background
Removal `processImage()`
- Wire `useInferenceStatus` into all 3 adapters (downloading → ready →
terminated lifecycle)

### Phase 4 — Tests
- Add unit tests for `AsyncMutex` (4 tests), `LoadQueue` (4 tests),
`GPUResourceCoordinator` (7 tests) — all 15 passing

### Phase 5 — Cleanup & Features
- Delete old `KokoroWorkerManager` (232 lines, zero consumers)
- Delete orphaned `libs/workers/types.ts` (old Whisper message types)
- Clean up `workers/kokoro/types.ts` (remove legacy message types, keep
domain types)
- Create centralized `constants.ts` (MODEL_IDS, MODEL_NAMES, TIMEOUTS,
MAX_RESTARTS)
- Remove hardcoded WebGPU check from background-removal devtools pages
(worker auto-detects)
- Add `useModelPreload` composable for generic idle-time preloading
- Add `useInferencePreload` composable that reads provider config and
preloads configured local models
- Wire preloading into both `stage-web` and `stage-tamagotchi` App.vue
(Kokoro TTS preloads 3s after init)
- Add `ModelCacheManager.vue` settings component (cache size display,
per-model status, clear cache)
- Document GPU Device isolation architecture in protocol.ts

## After This PR

- All inference workers speak the same protocol → adding a new model
adapter is straightforward
- GPU memory is tracked across all models with automatic pressure
warnings at 80%/95% of VRAM budget
- Models load sequentially via priority queue → no bandwidth/VRAM
contention
- Workers auto-detect WebGPU and fall back to WASM → works on browsers
without WebGPU
- Kokoro TTS preloads during idle time → "instant" first use for
configured users
- All adapters auto-restart on worker crashes (max 3 attempts,
exponential backoff)
- 15 unit tests cover core infrastructure (mutex, queue, coordinator)
- Zero dead code remains in the inference pipeline

## Test Plan

- [x] `pnpm exec vitest run packages/stage-ui/src/libs/inference/` — 15
tests pass
- [x] `pnpm -F @proj-airi/stage-ui exec tsc --noEmit` — no TypeScript
errors
- [x] `pnpm lint:fix` — no lint errors in changed files
- [ ] Manual: verify Kokoro TTS works with fp16-webgpu on a supported
browser
- [ ] Manual: verify Whisper ASR loads and transcribes correctly
- [ ] Manual: verify Background Removal works in devtools page
- [ ] Manual: verify preloading triggers in console (`[Preload] Loading
kokoro-...`)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-04-13 23:19:27 +08:00
Lulu 9bc2d718b6 fix(stage-ui): fit scroll visualizer metrics and scroller in fixed he… (#1632)
Co-authored-by-agent: Cursor <unknown@example.com>
2026-04-13 14:33:38 +08:00
Lulu bc94ba480b fix(stage-pages): allow clearing OpenAI-compatible speech model field (#1644) 2026-04-13 13:55:00 +08:00
github-actions[bot] 1ca3a72394 chore(i18n): update translations (#1650) 2026-04-13 13:54:14 +08:00
github-actions[bot]andCrowdin Bot 977a8e4f57 chore(i18n): update translations (#1641)
This PR contains updated translations from Crowdin. Created from [GitHub
Actions](https://github.com/moeru-ai/airi/blob/main/.github/workflows/crowdin-cron-sync.yml).

You can review the source of translations
[here](https://crowdin.com/project/proj-airi)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-12 17:03:13 +08:00
RainbowBird b7f9ff2749 chore(stage-ui): enhance flux package display and add recommended badge 2026-04-12 05:30:55 +08:00
RainbowBird 671517864a feat(flux): update transaction stats to use capacity from latest credit/initial transaction 2026-04-12 04:52:42 +08:00
RainbowBird 93888e6935 feat(server): use stripe product as flux pricing (#1640) 2026-04-12 04:32:42 +08:00
Makito bc5397b3f5 feat(stage-ui): add OTel deps and IO tracer helpers 2026-04-11 19:05:38 +09:00
Makito dd9cc0942b feat(stage-shared): add types for IO tracing 2026-04-11 18:25:19 +09:00
github-actions[bot]andCrowdin Bot 978009a13c chore(i18n): update translations (#1629)
This PR contains updated translations from Crowdin. Created from [GitHub
Actions](https://github.com/moeru-ai/airi/blob/main/.github/workflows/crowdin-cron-sync.yml).

You can review the source of translations
[here](https://crowdin.com/project/proj-airi)

Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-11 10:39:16 +08:00
Neko Ayaka b18158bce2 chore(computer-use-mcp): remove all hardcoded file path 2026-04-11 05:13:55 +08:00
Neko Ayaka 87f719272a fix(stage-layouts): prevent using :global(...) as they gets compiled into .dark without the children selector 2026-04-11 04:22:34 +08:00
Neko Ayaka 95eac8e41c chore(deps): bump dependencies 2026-04-11 04:00:49 +08:00
yewu 4da6fd3672 fix(stage-pages): persist default Kokoro model on first visit (#1624)
Co-authored-by-agent: Unknown <unknown@example.com>
2026-04-11 03:18:27 +08:00
Makito ccba8fbe65 fix(stage-ui): shrink icon size to better fit the button 2026-04-11 03:03:29 +09:00
Iro adcfcd9399 fix(stage-ui): resolve critical state and initialization issues (#1614) 2026-04-11 01:02:16 +08:00
Nashchennc 933ef01b10 test(stage-ui): add contract test (#1487) 2026-04-11 00:49:13 +08:00
LemonNeko c8a01e7a3b feat(stage-pocket): allow to set transparent background 2026-04-10 17:51:09 +08:00
Neko Ayaka fb3f54699b chore(18n): unified to use sign in / sign out 2026-04-10 16:25:11 +08:00
Neko Ayaka dd284f0f27 release: v0.9.0 2026-04-10 14:48:30 +08:00
github-actions[bot]andCrowdin Bot c05fd13545 chore(i18n): update translations (#1616)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-10 14:42:10 +08:00
Neko Ayaka 3962139b93 chore(stage-tamagotchi,ui): improved about page 2026-04-10 13:54:22 +08:00
github-actions[bot]andCrowdin Bot 558bd282b0 chore(i18n): update translations (#1613)
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
2026-04-10 11:14:38 +08:00