MCPcopy
hub / github.com/codeaashu/claude-code / withStreamingVCR

Function withStreamingVCR

src/services/vcr.ts:349–380  ·  view source on GitHub ↗
(
  messages: Message[],
  f: () => AsyncGenerator<
    StreamEvent | AssistantMessage | SystemAPIErrorMessage,
    void
  >,
)

Source from the content-addressed store, hash-verified

347}
348
349export async function* withStreamingVCR(
350 messages: Message[],
351 f: () => AsyncGenerator<
352 StreamEvent | AssistantMessage | SystemAPIErrorMessage,
353 void
354 >,
355): AsyncGenerator<
356 StreamEvent | AssistantMessage | SystemAPIErrorMessage,
357 void
358> {
359 if (!shouldUseVCR()) {
360 return yield* f()
361 }
362
363 // Compute and yield messages
364 const buffer: (StreamEvent | AssistantMessage | SystemAPIErrorMessage)[] = []
365
366 // Record messages (or fetch from cache)
367 const cachedBuffer = await withVCR(messages, async () => {
368 for await (const message of f()) {
369 buffer.push(message)
370 }
371 return buffer
372 })
373
374 if (cachedBuffer.length > 0) {
375 yield* cachedBuffer
376 return
377 }
378
379 yield* buffer
380}
381
382export async function withTokenCountVCR(
383 messages: unknown[],

Callers 2

queryModelWithStreamingFunction · 0.85

Calls 4

shouldUseVCRFunction · 0.85
withVCRFunction · 0.85
fFunction · 0.50
pushMethod · 0.45

Tested by

no test coverage detected