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

Function handleAssistant

packages/ai-claude-code/src/stream/translate.ts:217–292  ·  view source on GitHub ↗
(
    message: SdkAssistantMessage,
  )

Source from the content-addressed store, hash-verified

215 }
216
217 function* handleAssistant(
218 message: SdkAssistantMessage,
219 ): Generator<StreamChunk> {
220 const alreadyStreamed =
221 message.message.id !== undefined &&
222 streamedMessageIds.has(message.message.id)
223
224 for (const block of message.message.content) {
225 if (block.type === 'text') {
226 if (alreadyStreamed) continue
227 const messageId = message.message.id ?? genId()
228 const text = (block as { text: string }).text
229 yield {
230 type: EventType.TEXT_MESSAGE_START,
231 messageId,
232 model,
233 timestamp: now(),
234 role: 'assistant',
235 }
236 yield {
237 type: EventType.TEXT_MESSAGE_CONTENT,
238 messageId,
239 model,
240 timestamp: now(),
241 delta: text,
242 content: text,
243 }
244 yield {
245 type: EventType.TEXT_MESSAGE_END,
246 messageId,
247 model,
248 timestamp: now(),
249 }
250 } else if (block.type === 'thinking') {
251 if (alreadyStreamed) continue
252 const reasoningId = genId()
253 const thinking = (block as { thinking: string }).thinking
254 yield {
255 type: EventType.REASONING_START,
256 messageId: reasoningId,
257 model,
258 timestamp: now(),
259 }
260 yield {
261 type: EventType.REASONING_MESSAGE_START,
262 messageId: reasoningId,
263 role: 'reasoning' as const,
264 model,
265 timestamp: now(),
266 }
267 yield {
268 type: EventType.REASONING_MESSAGE_CONTENT,
269 messageId: reasoningId,
270 delta: thinking,
271 model,
272 timestamp: now(),
273 }
274 yield {

Callers 1

translateSdkStreamFunction · 0.85

Calls 3

emitToolUseFunction · 0.85
hasMethod · 0.80
nowFunction · 0.70

Tested by

no test coverage detected