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

Function handleReasoningPart

packages/ai-opencode/src/stream/translate.ts:228–270  ·  view source on GitHub ↗
(
    part: Extract<OpencodePart, { type: 'reasoning' }>,
    delta: string | undefined,
  )

Source from the content-addressed store, hash-verified

226 }
227
228 function* handleReasoningPart(
229 part: Extract<OpencodePart, { type: 'reasoning' }>,
230 delta: string | undefined,
231 ): Generator<StreamChunk> {
232 yield* closeText()
233
234 const prev = textAccumulators.get(part.id) ?? ''
235 let deltaText: string
236 if (typeof delta === 'string' && delta !== '') {
237 deltaText = delta
238 textAccumulators.set(part.id, prev + delta)
239 } else {
240 const full = part.text
241 deltaText = full.startsWith(prev) ? full.slice(prev.length) : full
242 textAccumulators.set(part.id, full)
243 }
244 if (deltaText === '') return
245
246 if (openReasoningId !== part.id) {
247 yield* closeReasoning()
248 openReasoningId = part.id
249 yield {
250 type: EventType.REASONING_START,
251 messageId: part.id,
252 model,
253 timestamp: now(),
254 }
255 yield {
256 type: EventType.REASONING_MESSAGE_START,
257 messageId: part.id,
258 role: 'reasoning' as const,
259 model,
260 timestamp: now(),
261 }
262 }
263 yield {
264 type: EventType.REASONING_MESSAGE_CONTENT,
265 messageId: part.id,
266 delta: deltaText,
267 model,
268 timestamp: now(),
269 }
270 }
271
272 function* openToolCall(
273 part: Extract<OpencodePart, { type: 'tool' }>,

Callers 1

handleEventFunction · 0.85

Calls 5

closeTextFunction · 0.70
closeReasoningFunction · 0.70
nowFunction · 0.70
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected