MCPcopy
hub / github.com/TanStack/ai / createTextChunks

Function createTextChunks

packages/ai-client/tests/test-utils.ts:140–172  ·  view source on GitHub ↗
(
  text: string,
  messageId: string = 'msg-1',
  model: string = 'test',
)

Source from the content-addressed store, hash-verified

138 * Helper to create simple text content chunks (AG-UI format)
139 */
140export function createTextChunks(
141 text: string,
142 messageId: string = 'msg-1',
143 model: string = 'test',
144): Array<StreamChunk> {
145 const chunks: Array<StreamChunk> = []
146 let accumulated = ''
147 const runId = `run-${messageId}`
148 const threadId = `thread-${messageId}`
149
150 for (const chunk of text) {
151 accumulated += chunk
152 chunks.push({
153 type: 'TEXT_MESSAGE_CONTENT',
154 messageId,
155 model,
156 timestamp: Date.now(),
157 delta: chunk,
158 content: accumulated,
159 } as StreamChunk)
160 }
161
162 chunks.push({
163 type: 'RUN_FINISHED',
164 runId,
165 threadId,
166 model,
167 timestamp: Date.now(),
168 finishReason: 'stop',
169 } as StreamChunk)
170
171 return chunks
172}
173
174/**
175 * Helper to create custom event chunks

Callers 15

use-chat.test.tsFile · 0.90
use-chat.test.tsFile · 0.90
connectFunction · 0.90
devtools.test.tsFile · 0.90
use-chat.test.tsFile · 0.90
connectFunction · 0.90

Calls 2

nowMethod · 0.80
pushMethod · 0.45

Tested by 3

connectFunction · 0.72
connectFunction · 0.72
connectFunction · 0.72