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

Function useConnection

examples/ts-react-native-chat/src/App.tsx:81–95  ·  view source on GitHub ↗
(transport: TransportKey)

Source from the content-addressed store, hash-verified

79}
80
81function useConnection(transport: TransportKey): ConnectionAdapter {
82 return useMemo(() => {
83 const selected = transports.find((item) => item.key === transport)
84 const url = endpointUrl(selected?.endpoint ?? '/chat/http')
85
86 switch (transport) {
87 case 'fetch-http':
88 return fetchHttpStream(url)
89 case 'xhr-http':
90 return xhrHttpStream(url)
91 case 'xhr-sse':
92 return xhrServerSentEvents(url)
93 }
94 }, [transport])
95}
96
97function isRecord(value: unknown): value is Record<string, unknown> {
98 return typeof value === 'object' && value !== null && !Array.isArray(value)

Callers 1

AppFunction · 0.70

Calls 4

endpointUrlFunction · 0.85
fetchHttpStreamFunction · 0.85
xhrHttpStreamFunction · 0.85
xhrServerSentEventsFunction · 0.85

Tested by

no test coverage detected