MCPcopy Index your code
hub / github.com/TanStack/ai / chunk

Function chunk

packages/ai/tests/stream-processor.test.ts:25–33  ·  view source on GitHub ↗

Create a typed StreamChunk by event type. Narrows the return to the * matching variant via `Extract`.

(
  type: T,
  fields?: Record<string, unknown>,
)

Source from the content-addressed store, hash-verified

23/** Create a typed StreamChunk by event type. Narrows the return to the
24 * matching variant via `Extract`. */
25function chunk<T extends StreamChunk['type']>(
26 type: T,
27 fields?: Record<string, unknown>,
28): Extract<StreamChunk, { type: T }> {
29 return { type, timestamp: Date.now(), ...fields } as Extract<
30 StreamChunk,
31 { type: T }
32 >
33}
34
35/** Create an async iterable from a list of chunks. */
36async function* streamOf(

Callers 1

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected