@tanstack/ai-client 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/chat-client.d.ts +1 -1
- package/dist/esm/chat-client.js +1 -1
- package/dist/esm/chat-client.js.map +1 -1
- package/dist/esm/connection-adapters.d.ts +21 -1
- package/dist/esm/connection-adapters.js +262 -68
- package/dist/esm/connection-adapters.js.map +1 -1
- package/dist/esm/devtools-noop.d.ts +1 -1
- package/dist/esm/devtools-noop.js.map +1 -1
- package/dist/esm/devtools.d.ts +1 -1
- package/dist/esm/devtools.js +1 -1
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/events.d.ts +1 -1
- package/dist/esm/events.js.map +1 -1
- package/dist/esm/generation-client.js.map +1 -1
- package/dist/esm/generation-types.d.ts +1 -1
- package/dist/esm/generation-types.js.map +1 -1
- package/dist/esm/index.d.ts +5 -4
- package/dist/esm/index.js +7 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/realtime-client.d.ts +1 -1
- package/dist/esm/realtime-client.js +1 -1
- package/dist/esm/realtime-client.js.map +1 -1
- package/dist/esm/realtime-types.d.ts +1 -1
- package/dist/esm/response-stream.d.ts +7 -0
- package/dist/esm/response-stream.js +32 -0
- package/dist/esm/response-stream.js.map +1 -0
- package/dist/esm/sse-parser.d.ts +1 -1
- package/dist/esm/sse-parser.js +5 -6
- package/dist/esm/sse-parser.js.map +1 -1
- package/dist/esm/sse-utils.d.ts +1 -0
- package/dist/esm/sse-utils.js +11 -0
- package/dist/esm/sse-utils.js.map +1 -0
- package/dist/esm/tool-types.d.ts +1 -1
- package/dist/esm/types.d.ts +2 -2
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/video-generation-client.js.map +1 -1
- package/package.json +3 -3
- package/src/chat-client.ts +2 -2
- package/src/connection-adapters.ts +360 -68
- package/src/devtools-noop.ts +1 -1
- package/src/devtools.ts +2 -2
- package/src/events.ts +1 -1
- package/src/generation-client.ts +1 -1
- package/src/generation-types.ts +1 -1
- package/src/index.ts +7 -3
- package/src/realtime-client.ts +2 -2
- package/src/realtime-types.ts +1 -1
- package/src/response-stream.ts +42 -0
- package/src/sse-parser.ts +9 -7
- package/src/sse-utils.ts +8 -0
- package/src/tool-types.ts +1 -1
- package/src/types.ts +2 -2
- package/src/video-generation-client.ts +1 -1
package/src/events.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
aiEventClient,
|
|
3
3
|
createAIDevtoolsEventEnvelope,
|
|
4
4
|
} from '@tanstack/ai-event-client'
|
|
5
|
-
import type { ContentPart } from '@tanstack/ai'
|
|
5
|
+
import type { ContentPart } from '@tanstack/ai/client'
|
|
6
6
|
import type { UIMessage } from './types'
|
|
7
7
|
|
|
8
8
|
export interface ChatClientRunEventContext {
|
package/src/generation-client.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GENERATION_EVENTS } from './generation-types'
|
|
2
2
|
import { createNoOpGenerationDevtoolsBridge } from './devtools-noop'
|
|
3
3
|
import { parseSSEResponse } from './sse-parser'
|
|
4
|
-
import type { StreamChunk } from '@tanstack/ai'
|
|
4
|
+
import type { StreamChunk } from '@tanstack/ai/client'
|
|
5
5
|
import type {
|
|
6
6
|
ConnectConnectionAdapter,
|
|
7
7
|
RunAgentInputContext,
|
package/src/generation-types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type {
|
|
|
43
43
|
VideoGenerateInput,
|
|
44
44
|
} from './generation-types'
|
|
45
45
|
export { GENERATION_EVENTS } from './generation-types'
|
|
46
|
+
export { UnsupportedResponseStreamError } from './response-stream'
|
|
46
47
|
export { clientTools, createChatClientOptions } from './types'
|
|
47
48
|
export {
|
|
48
49
|
createAIDevtoolsGenerationPreview,
|
|
@@ -58,7 +59,7 @@ export type {
|
|
|
58
59
|
ExtractToolInput,
|
|
59
60
|
ExtractToolOutput,
|
|
60
61
|
} from './tool-types'
|
|
61
|
-
export type { AnyClientTool } from '@tanstack/ai'
|
|
62
|
+
export type { AnyClientTool } from '@tanstack/ai/client'
|
|
62
63
|
export type {
|
|
63
64
|
RealtimeAdapter,
|
|
64
65
|
RealtimeConnection,
|
|
@@ -69,6 +70,8 @@ export type {
|
|
|
69
70
|
export {
|
|
70
71
|
fetchServerSentEvents,
|
|
71
72
|
fetchHttpStream,
|
|
73
|
+
xhrServerSentEvents,
|
|
74
|
+
xhrHttpStream,
|
|
72
75
|
stream,
|
|
73
76
|
rpcStream,
|
|
74
77
|
StreamTruncatedError,
|
|
@@ -77,6 +80,7 @@ export {
|
|
|
77
80
|
type FetchConnectionOptions,
|
|
78
81
|
type RunAgentInputContext,
|
|
79
82
|
type SubscribeConnectionAdapter,
|
|
83
|
+
type XhrConnectionOptions,
|
|
80
84
|
} from './connection-adapters'
|
|
81
85
|
|
|
82
86
|
// Re-export message converters from @tanstack/ai
|
|
@@ -87,7 +91,7 @@ export {
|
|
|
87
91
|
convertMessagesToModelMessages,
|
|
88
92
|
normalizeToUIMessage,
|
|
89
93
|
generateMessageId,
|
|
90
|
-
} from '@tanstack/ai'
|
|
94
|
+
} from '@tanstack/ai/client'
|
|
91
95
|
|
|
92
96
|
// Re-export stream processing from @tanstack/ai (shared implementation)
|
|
93
97
|
export {
|
|
@@ -110,4 +114,4 @@ export {
|
|
|
110
114
|
type ChunkRecording,
|
|
111
115
|
type ProcessorResult,
|
|
112
116
|
type ProcessorState,
|
|
113
|
-
} from '@tanstack/ai'
|
|
117
|
+
} from '@tanstack/ai/client'
|
package/src/realtime-client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { convertSchemaToJsonSchema } from '@tanstack/ai'
|
|
1
|
+
import { convertSchemaToJsonSchema } from '@tanstack/ai/client'
|
|
2
2
|
import type {
|
|
3
3
|
AnyClientTool,
|
|
4
4
|
AudioVisualization,
|
|
@@ -6,7 +6,7 @@ import type {
|
|
|
6
6
|
RealtimeMode,
|
|
7
7
|
RealtimeStatus,
|
|
8
8
|
RealtimeToken,
|
|
9
|
-
} from '@tanstack/ai'
|
|
9
|
+
} from '@tanstack/ai/client'
|
|
10
10
|
import type {
|
|
11
11
|
RealtimeClientOptions,
|
|
12
12
|
RealtimeClientState,
|
package/src/realtime-types.ts
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type MissingResponseStreamFeature =
|
|
2
|
+
| 'TextDecoder'
|
|
3
|
+
| 'Response.body'
|
|
4
|
+
| 'Response.body.getReader'
|
|
5
|
+
|
|
6
|
+
export class UnsupportedResponseStreamError extends Error {
|
|
7
|
+
readonly missingFeature: MissingResponseStreamFeature
|
|
8
|
+
|
|
9
|
+
constructor(missingFeature: MissingResponseStreamFeature) {
|
|
10
|
+
super(createUnsupportedResponseStreamMessage(missingFeature))
|
|
11
|
+
this.name = 'UnsupportedResponseStreamError'
|
|
12
|
+
this.missingFeature = missingFeature
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function createUnsupportedResponseStreamMessage(
|
|
17
|
+
missingFeature: MissingResponseStreamFeature,
|
|
18
|
+
): string {
|
|
19
|
+
return `Streaming fetch responses are not supported in this runtime because ${missingFeature} is unavailable. React Native users need a compatible fetch/stream/TextDecoder polyfill, or should use a fetch, XHR, or custom transport that can deliver streaming chunks.`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getResponseStreamReader(
|
|
23
|
+
response: Response,
|
|
24
|
+
): ReadableStreamDefaultReader<Uint8Array> {
|
|
25
|
+
if (!response.body) {
|
|
26
|
+
throw new UnsupportedResponseStreamError('Response.body')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof response.body.getReader !== 'function') {
|
|
30
|
+
throw new UnsupportedResponseStreamError('Response.body.getReader')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return response.body.getReader()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createResponseStreamTextDecoder(): TextDecoder {
|
|
37
|
+
if (typeof globalThis.TextDecoder !== 'function') {
|
|
38
|
+
throw new UnsupportedResponseStreamError('TextDecoder')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new globalThis.TextDecoder()
|
|
42
|
+
}
|
package/src/sse-parser.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
createResponseStreamTextDecoder,
|
|
3
|
+
getResponseStreamReader,
|
|
4
|
+
} from './response-stream'
|
|
5
|
+
import { parseSseDataLine } from './sse-utils'
|
|
6
|
+
import type { StreamChunk } from '@tanstack/ai/client'
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Read lines from a stream (newline-delimited)
|
|
@@ -8,7 +13,7 @@ async function* readStreamLines(
|
|
|
8
13
|
abortSignal?: AbortSignal,
|
|
9
14
|
): AsyncGenerator<string> {
|
|
10
15
|
try {
|
|
11
|
-
const decoder =
|
|
16
|
+
const decoder = createResponseStreamTextDecoder()
|
|
12
17
|
let buffer = ''
|
|
13
18
|
|
|
14
19
|
while (!abortSignal?.aborted) {
|
|
@@ -51,13 +56,10 @@ export async function* parseSSEResponse(
|
|
|
51
56
|
)
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
const reader = response
|
|
55
|
-
if (!reader) {
|
|
56
|
-
throw new Error('Response body is not readable')
|
|
57
|
-
}
|
|
59
|
+
const reader = getResponseStreamReader(response)
|
|
58
60
|
|
|
59
61
|
for await (const line of readStreamLines(reader, abortSignal)) {
|
|
60
|
-
const data =
|
|
62
|
+
const data = parseSseDataLine(line)
|
|
61
63
|
|
|
62
64
|
if (data === '[DONE]') {
|
|
63
65
|
console.warn(
|
package/src/sse-utils.ts
ADDED
package/src/tool-types.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -11,12 +11,12 @@ import type {
|
|
|
11
11
|
StreamChunk,
|
|
12
12
|
StructuredOutputPart,
|
|
13
13
|
VideoPart,
|
|
14
|
-
} from '@tanstack/ai'
|
|
14
|
+
} from '@tanstack/ai/client'
|
|
15
15
|
import type { ConnectionAdapter } from './connection-adapters'
|
|
16
16
|
import type { AIDevtoolsClientMetadata } from './devtools'
|
|
17
17
|
import type { ChatDevtoolsBridgeFactory } from './devtools-noop'
|
|
18
18
|
|
|
19
|
-
export type { StructuredOutputPart } from '@tanstack/ai'
|
|
19
|
+
export type { StructuredOutputPart } from '@tanstack/ai/client'
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* `messages` is the full UIMessage history (not a delta). `data` is the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GENERATION_EVENTS } from './generation-types'
|
|
2
2
|
import { createNoOpVideoDevtoolsBridge } from './devtools-noop'
|
|
3
3
|
import { parseSSEResponse } from './sse-parser'
|
|
4
|
-
import type { StreamChunk } from '@tanstack/ai'
|
|
4
|
+
import type { StreamChunk } from '@tanstack/ai/client'
|
|
5
5
|
import type {
|
|
6
6
|
ConnectConnectionAdapter,
|
|
7
7
|
RunAgentInputContext,
|