mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-08 07:17:39 +00:00
fix: stream opencode reasoning updates (#661)
Emit throttled ACP reasoning snapshots with stable stream ids so OpenCode reasoning updates render live without one row per token. Collapse matching reasoning snapshots in the web timeline and avoid stale session 404 redirects during refetch. Tests: targeted Vitest suite and bun typecheck. Co-authored-by: twshe <twshe@outlook.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { isSessionNotFoundError } from './useSession'
|
||||
|
||||
describe('isSessionNotFoundError', () => {
|
||||
it('matches hub 404 session responses', () => {
|
||||
expect(isSessionNotFoundError(new Error('HTTP 404 Not Found: {"error":"Session not found"}'))).toBe(true)
|
||||
})
|
||||
|
||||
it('does not match unrelated errors', () => {
|
||||
expect(isSessionNotFoundError(new Error('HTTP 500 Internal Server Error'))).toBe(false)
|
||||
expect(isSessionNotFoundError(null)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -3,10 +3,16 @@ import type { ApiClient } from '@/api/client'
|
||||
import type { Session } from '@/types/api'
|
||||
import { queryKeys } from '@/lib/query-keys'
|
||||
|
||||
export function isSessionNotFoundError(error: unknown): boolean {
|
||||
return error instanceof Error
|
||||
&& (error.message.includes('HTTP 404') || error.message.includes('Session not found'))
|
||||
}
|
||||
|
||||
export function useSession(api: ApiClient | null, sessionId: string | null): {
|
||||
session: Session | null
|
||||
isLoading: boolean
|
||||
error: string | null
|
||||
notFound: boolean
|
||||
refetch: () => Promise<unknown>
|
||||
} {
|
||||
const resolvedSessionId = sessionId ?? 'unknown'
|
||||
@@ -19,12 +25,19 @@ export function useSession(api: ApiClient | null, sessionId: string | null): {
|
||||
return await api.getSession(sessionId)
|
||||
},
|
||||
enabled: Boolean(api && sessionId),
|
||||
retry: (failureCount, error) => {
|
||||
if (isSessionNotFoundError(error)) {
|
||||
return false
|
||||
}
|
||||
return failureCount < 2
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
session: query.data?.session ?? null,
|
||||
isLoading: query.isLoading,
|
||||
error: query.error instanceof Error ? query.error.message : query.error ? 'Failed to load session' : null,
|
||||
notFound: isSessionNotFoundError(query.error) && !query.isFetching,
|
||||
refetch: query.refetch,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user