示例工程 18-streaming-ui
18-streaming-ui/app/shared/ipc.ts
export const CH = {
start: "stream:start",
cancel: "stream:cancel",
port: "stream:port",
} as const;
export type StreamOptions = {
chunks: number;
intervalMs: number;
shuffle: boolean;
from: number;
};
export type StreamMessage =
| { type: "chunk"; seq: number; token: string; at: number }
| { type: "done"; total: number; lastSeq: number }
| { type: "cancelled"; sent: number };
export type StartResult =
| { ok: true; streamId: string; from: number; to: number }
| { ok: false; code: string };
export type Api = {
start(options: StreamOptions): Promise<StartResult>;
cancel(): Promise<{ ok: boolean }>;
onStream(cb: (message: StreamMessage) => void): () => void;
};