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

Function fetcherToConnectionAdapter

packages/ai-client/src/connection-adapters.ts:963–995  ·  view source on GitHub ↗
(
  fetcher: ChatFetcher,
)

Source from the content-addressed store, hash-verified

961 * @internal
962 */
963export function fetcherToConnectionAdapter(
964 fetcher: ChatFetcher,
965): ConnectConnectionAdapter {
966 return {
967 async *connect(messages, data, abortSignal, runContext) {
968 if (!abortSignal) {
969 throw new Error(
970 'fetcherToConnectionAdapter requires an AbortSignal — the chat client always supplies one.',
971 )
972 }
973 if (!runContext) {
974 throw new Error(
975 'fetcherToConnectionAdapter requires a RunAgentInputContext — the chat client always supplies one.',
976 )
977 }
978 const uiMessages = messages as Array<UIMessage>
979 const result = await fetcher(
980 {
981 messages: uiMessages,
982 data,
983 threadId: runContext.threadId,
984 runId: runContext.runId,
985 },
986 { signal: abortSignal },
987 )
988 if (result instanceof Response) {
989 yield* responseToSSEChunks(result, abortSignal)
990 } else {
991 yield* abortableIterable(result, abortSignal)
992 }
993 },
994 }
995}
996
997/**
998 * Wrap an AsyncIterable so iteration aborts when `signal` fires. Without

Callers 1

resolveTransportFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected