Add link session preparation flow

- wire front link resolve/prepare routes
- add orchestrator session command handling
- update admin dashboards and device/link logic
This commit is contained in:
user
2026-03-28 17:47:03 +02:00
parent 5da61ed853
commit 0a11be5006
20 changed files with 1099 additions and 175 deletions

View File

@@ -110,3 +110,41 @@ Update rule:
- Refactored `apps/main/src/lib/domains/{device,link,supported-app}` to remove local duplicate data type declarations and import canonical types from `@pkg/logic/domains/*/data`
- Updated device status validation in `device.remote.ts` to reuse `deviceStatusSchema` from logic instead of a duplicated local picklist
- Kept only derived UI helper types (`Pick`/`Omit`) where needed for presentation and transport-shape compatibility
### 15 — Fixed Links Table Not Refreshing After Create / Refresh Click
- Root cause: SvelteKit's `query()` caches `RemoteQuery` objects in an internal `query_map`; subsequent calls to `listLinksSQ()` returned the same stale cached Query
- Fix: in `LinkViewModel.fetchLinks()`, check `query.ready` and call `query.refresh()` on re-fetches to force a fresh server request; read `query.current` for the updated data
- This fixes both the post-create refresh and the manual Refresh button
### 16 — Front/Orchestrator Server Session Prep Flow
- Reworked `apps/front` into the current link/session server: added `GET /links/:token/resolve` and `POST /links/:token/prepare` to validate links, expose assigned device/app data, and call orchestrator server-side
- Implemented `apps/orchestrator` internal API with API-key auth, device list/detail routes, stubbed container `start|stop|restart` endpoints, and a real `POST /internal/sessions/prepare` flow
- Session prepare now allocates the device, runs ADB connect/force-stop/launch commands for the assigned package, and releases the device on failure while keeping it busy on success
- Hardened device allocation in `@pkg/logic` with an atomic `allocateIfAvailable` repository path so concurrent session-start attempts do not rely on a read-then-write race
### 17 — Orchestrator Domain Refactor
- Split `apps/orchestrator` into a thin composition entrypoint plus domain routers/services under `src/domains/{command,orchestrate}`
- Centralized shared Hono app helpers in `apps/orchestrator/src/core/utils.ts` for internal auth, flow context, request parsing, and JSON error shaping
- Kept the existing internal API contract intact while removing the previous monolithic `src/index.ts` implementation
### 18 — Front/Orchestrator Type Error Cleanup
- Fixed Hono response status typing in both `apps/front` and `apps/orchestrator` by normalizing numeric status values before `c.json(...)`
- Fixed orchestrator request-body narrowing in the orchestrate router so parsed payloads and error payloads are typed correctly
- Marked the legacy Bun prototype server in `apps/front/old.server.ts` as excluded from TypeScript checking so it no longer breaks the current Node/Hono apps
- Verified both `apps/orchestrator` and `apps/front` compile cleanly with `tsc --noEmit`
### 19 — Command/Orchestrate Responsibility Split
- Moved the low-level ADB executor and app-launch operations into `apps/orchestrator/src/domains/command/service.ts`
- Simplified `apps/orchestrator/src/domains/orchestrate/service.ts` so it now only coordinates device allocation, invokes command-domain execution, and handles release-on-failure
- Verified the reorganized orchestrator app still compiles cleanly with `tsc --noEmit`
### 20 — Front Domain Cleanup
- Split `apps/front` into a thin entrypoint, shared `src/core/utils.ts`, and a dedicated `src/domains/links/{router,service}.ts` flow
- Moved link resolve/prepare logic and orchestrator calling into the links domain service so `src/index.ts` only wires middleware and routes
- Verified the cleaned `apps/front` app compiles cleanly with `tsc --noEmit`