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

Function xhrHttpStream

packages/ai-client/src/connection-adapters.ts:895–923  ·  view source on GitHub ↗
(
  url: string | (() => string),
  options: XhrConnectionOptionsResolver = {},
)

Source from the content-addressed store, hash-verified

893 * Create an XMLHttpRequest-backed newline-delimited JSON stream adapter.
894 */
895export function xhrHttpStream(
896 url: string | (() => string),
897 options: XhrConnectionOptionsResolver = {},
898): ConnectConnectionAdapter {
899 return {
900 async *connect(messages, data, abortSignal, runContext) {
901 const resolvedUrl = typeof url === 'function' ? url() : url
902 const resolvedOptions = await resolveXhrConnectionOptions(options)
903 const signal = abortSignal || resolvedOptions.signal
904 const request = createConfiguredXhrRequest(
905 resolvedUrl,
906 resolvedOptions,
907 messages,
908 data,
909 runContext,
910 )
911 const lines = readXhrLines(request.xhr, signal)
912 if (signal?.aborted) {
913 await lines.next()
914 return
915 }
916 request.xhr.send(request.body)
917
918 for await (const line of lines) {
919 yield JSON.parse(line) as StreamChunk
920 }
921 },
922 }
923}
924
925/**
926 * Create a direct stream connection adapter (for server functions or direct streams)

Callers 3

useConnectionFunction · 0.85
useConnectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected