Import packages/plugin/src/tui-event-source.ts
This commit is contained in:
parent
73f57b221c
commit
6170eb01e5
|
|
@ -0,0 +1,27 @@
|
|||
import type { LocalTypertGateway } from './typert-gateway-contract.js'
|
||||
|
||||
/** Check the public Gateway stream before a terminal Host becomes available. */
|
||||
export async function assertRemoteEventSource(gateway: LocalTypertGateway): Promise<void> {
|
||||
const peerGateway = gateway.createPeer?.()
|
||||
if (peerGateway?.peer === undefined) {
|
||||
await peerGateway?.dispose?.()
|
||||
throw new Error('dsh-TUI Remote requires an official owner Peer for Remote events.')
|
||||
}
|
||||
const signal = AbortSignal.timeout(5_000)
|
||||
let iterator: AsyncIterator<unknown> | undefined
|
||||
try {
|
||||
const source = await peerGateway.open('$events', { args: {} }, signal)
|
||||
iterator = source[Symbol.asyncIterator]()
|
||||
const first = await iterator.next()
|
||||
const value = first.value
|
||||
if (first.done || typeof value !== 'object' || value === null
|
||||
|| !('type' in value) || value.type !== 'ready') {
|
||||
throw new Error('The Host Remote event source did not send a ready frame.')
|
||||
}
|
||||
} catch {
|
||||
throw new Error('dsh-TUI Remote needs @deepseek-ai/dsh-api-remotes and its Host API packages.')
|
||||
} finally {
|
||||
await iterator?.return?.().catch(() => undefined)
|
||||
await peerGateway.dispose?.()
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue