feat(rustbridge): add streaming responses and robust large-payload/backpressure handling to RustBridge

This commit is contained in:
2026-02-11 00:12:56 +00:00
parent dcb88ef4b5
commit 5fb991ff51
11 changed files with 798 additions and 84 deletions

View File

@@ -39,4 +39,9 @@ export interface IRustBridgeOptions extends IBinaryLocatorOptions {
readyEventName?: string;
/** Optional logger instance */
logger?: IRustBridgeLogger;
/** Maximum message size in bytes (default: 50MB). Messages exceeding this are rejected. */
maxPayloadSize?: number;
/** Inactivity timeout for streaming commands in ms (default: same as requestTimeoutMs).
* Resets on each chunk received. */
streamTimeoutMs?: number;
}

View File

@@ -38,3 +38,25 @@ export interface ICommandDefinition<TParams = any, TResult = any> {
* Used to type-safe the bridge's sendCommand method.
*/
export type TCommandMap = Record<string, ICommandDefinition>;
/**
* Stream chunk message received from the Rust binary during a streaming command.
*/
export interface IManagementStreamChunk {
id: string;
stream: true;
data: any;
}
/**
* Extract keys from a command map whose definitions include a `chunk` field,
* indicating they support streaming responses.
*/
export type TStreamingCommandKeys<TCommands extends TCommandMap> = {
[K in keyof TCommands]: TCommands[K] extends { chunk: any } ? K : never;
}[keyof TCommands];
/**
* Extract the chunk type from a command definition that has a `chunk` field.
*/
export type TExtractChunk<TDef> = TDef extends { chunk: infer C } ? C : never;