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

Method probeReadWrite

packages/ai-sandbox-sprites/src/client.ts:474–512  ·  view source on GitHub ↗

Write a sentinel and read it back; throws unless the round-trip matches.

(
    name: string,
    path: string,
    marker: string,
    signal?: AbortSignal,
  )

Source from the content-addressed store, hash-verified

472
473 /** Write a sentinel and read it back; throws unless the round-trip matches. */
474 private async probeReadWrite(
475 name: string,
476 path: string,
477 marker: string,
478 signal?: AbortSignal,
479 ): Promise<void> {
480 const attemptSignal = signal
481 ? AbortSignal.any([signal, AbortSignal.timeout(8000)])
482 : AbortSignal.timeout(8000)
483 const writeUrl = this.spritePath(
484 name,
485 `/fs/write?path=${encodeURIComponent(path)}`,
486 )
487 const writeRes = await fetch(writeUrl, {
488 method: 'PUT',
489 headers: this.headers({ 'content-type': 'application/octet-stream' }),
490 body: new TextEncoder().encode(marker),
491 signal: attemptSignal,
492 })
493 await writeRes.body?.cancel()
494 if (!writeRes.ok) throw new Error(`probe write HTTP ${writeRes.status}`)
495
496 const readUrl = this.spritePath(
497 name,
498 `/fs/read?path=${encodeURIComponent(path)}`,
499 )
500 const readRes = await fetch(readUrl, {
501 method: 'GET',
502 headers: this.headers(),
503 signal: attemptSignal,
504 })
505 if (!readRes.ok) {
506 await readRes.body?.cancel()
507 throw new Error(`probe read HTTP ${readRes.status}`)
508 }
509 if ((await readRes.text()) !== marker) {
510 throw new Error('probe read mismatch')
511 }
512 }
513
514 private async deleteSentinel(name: string, path: string): Promise<void> {
515 const res = await fetch(

Callers 1

waitUntilReadyMethod · 0.95

Calls 5

spritePathMethod · 0.95
headersMethod · 0.95
cancelMethod · 0.65
textMethod · 0.65
fetchFunction · 0.50

Tested by

no test coverage detected