refactor(vibe): simplify durable session flow
Typecheck / typecheck (backend) (push) Has been cancelled
Typecheck / typecheck (workers) (push) Has been cancelled
Typecheck / typecheck (backend) (pull_request) Has been cancelled
Typecheck / typecheck (workers) (pull_request) Has been cancelled

This commit is contained in:
kami
2026-08-03 12:44:08 +04:00
parent 61a1373ca9
commit 9eba247a58
16 changed files with 191 additions and 520 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ describe('durable vibe service', () => {
await vibeService.next('session', 3);
expect(post).toHaveBeenCalledWith('/v2/vibe/sessions/session/next', { expectedPlanVersion: 3 });
expect(post).toHaveBeenCalledWith('/v2/vibe/sessions/session/advance', { expectedPlanVersion: 3 });
});
it('uses an explicit idempotency key to advance a served but unplayable item', async () => {
@@ -21,7 +21,7 @@ describe('durable vibe service', () => {
eventId: 'event', planVersionId: 'plan', ordinal: 4, trackId: 'track',
});
expect(post).toHaveBeenCalledWith('/v2/vibe/sessions/session/next', {
expect(post).toHaveBeenCalledWith('/v2/vibe/sessions/session/advance', {
expectedPlanVersion: 3,
unplayable: { eventId: 'event', planVersionId: 'plan', ordinal: 4, trackId: 'track' },
});
+2 -2
View File
@@ -71,7 +71,7 @@ export const vibeService = {
},
async next(sessionId: string, expectedPlanVersion: number): Promise<DurableVibeSessionResponse> {
const res = await api.post<DurableVibeSessionResponse>(`/v2/vibe/sessions/${sessionId}/next`, {
const res = await api.post<DurableVibeSessionResponse>(`/v2/vibe/sessions/${sessionId}/advance`, {
expectedPlanVersion,
});
return res.data;
@@ -82,7 +82,7 @@ export const vibeService = {
expectedPlanVersion: number,
unplayable: VibeUnplayableItemInput,
): Promise<DurableVibeSessionResponse> {
const res = await api.post<DurableVibeSessionResponse>(`/v2/vibe/sessions/${sessionId}/next`, {
const res = await api.post<DurableVibeSessionResponse>(`/v2/vibe/sessions/${sessionId}/advance`, {
expectedPlanVersion,
unplayable,
});
+1 -1
View File
@@ -202,7 +202,7 @@ function isSessionTerminalError(error: unknown): boolean {
export function vibeErrorMessage(error: unknown): string {
if (!axios.isAxiosError(error)) return 'Could not refresh this Vibe. Please try again.';
switch (error.response?.status) {
case 401: return 'Vibe needs a trusted local user identity. Set MUZICK_VIBE_USER_ID and try again.';
case 400: return 'Vibe needs a valid user identity.';
case 404: return 'This Vibe session is no longer available.';
case 409: return 'This Vibe session has already ended or was replaced.';
default: return 'Could not refresh this Vibe. Please try again.';
+2 -2
View File
@@ -75,8 +75,8 @@ export interface HealthResponse {
redis: 'ok' | 'error' | 'unknown';
}
// Active v2 recommendation session. The sessionId comes from
// POST /api/v2/vibe/start and identifies the Redis-stored plan.
// Active durable recommendation session. The sessionId comes from
// POST /api/v2/vibe/sessions and identifies its persisted plan.
export interface VibeSession {
sessionId: string;
seedTrackId: string | null;