/** Represents an array item within a `Node` output chunk, specifies the field is an array containing this `item` at the `index`. **/ type ChunkArrayItem = { object: "array.item"; index: number; item: T; }; /** Helper types for producing the "Chunk" types used in the `NodeDelta` messages */ type ChunkizeObject = T extends object ? { [P in keyof T]: ChunkizeAny } : T; type ChunkizeArray = T extends (infer U)[] ? ChunkArrayItem> : ChunkArrayItem; type ChunkizeAny = T extends (infer U)[] ? ChunkizeArray : T extends object ? ChunkizeObject : T; /** Stream message that contains the completed `Node` output */ type NodeResult = { object: "node.result"; nodeId: string; data: T; }; /** Stream message that contains a chunk of the `Node` output */ type NodeDelta = { object: "node.delta"; nodeId: string; data: ChunkizeAny; }; /** Stream message when an error happened during a `Node` run. */ export type NodeError = { object: "node.error"; nodeId: string; data: { type: string; message: string; }; }; /** Stream message that contains the completed "Graph" output */ export type GraphResult = { object: "graph.result"; data: T; }; export type NodeMessage = NodeResult | NodeDelta | NodeError; export type SSEMessage = NodeMessage | GraphResult;