feat: improve streaming and startup responsiveness

This commit is contained in:
mesalogo
2026-08-15 18:06:03 +08:00
parent ed8d1791b1
commit f27dd37f42
13 changed files with 1795 additions and 885 deletions
+61
View File
@@ -0,0 +1,61 @@
export type StartupPrerequisiteDependencies<ConfiguredRuntime> = {
prepareDeepSeekHome: () => Promise<void>
initializeKnowledgeAndGateway: () => Promise<void>
hydrateConfiguredRuntime: () => Promise<ConfiguredRuntime>
initializeAssistant: () => void
}
function startObserved<T>(operation: () => Promise<T>): Promise<T> {
let started: Promise<T>
try {
started = Promise.resolve(operation())
} catch (error) {
started = Promise.reject(error)
}
void started.catch(() => undefined)
return started
}
export async function runStartupPrerequisites<ConfiguredRuntime>(
dependencies: StartupPrerequisiteDependencies<ConfiguredRuntime>
): Promise<ConfiguredRuntime> {
const deepSeekHomeReady = startObserved(
dependencies.prepareDeepSeekHome
)
const knowledgeAndGatewayReady = startObserved(
dependencies.initializeKnowledgeAndGateway
)
const configuredRuntimeReady = startObserved(
dependencies.hydrateConfiguredRuntime
)
let assistantInitializationFailed = false
let assistantInitializationError: unknown
try {
dependencies.initializeAssistant()
} catch (error) {
assistantInitializationFailed = true
assistantInitializationError = error
}
const [deepSeekHome, knowledgeAndGateway, configuredRuntime] =
await Promise.allSettled([
deepSeekHomeReady,
knowledgeAndGatewayReady,
configuredRuntimeReady
] as const)
if (assistantInitializationFailed) {
throw assistantInitializationError
}
if (deepSeekHome.status === 'rejected') {
throw deepSeekHome.reason
}
if (knowledgeAndGateway.status === 'rejected') {
throw knowledgeAndGateway.reason
}
if (configuredRuntime.status === 'rejected') {
throw configuredRuntime.reason
}
return configuredRuntime.value
}