assistant-stream 0.0.20 → 0.0.22
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/ai-sdk.d.mts +20 -4
- package/dist/ai-sdk.d.ts +20 -4
- package/dist/ai-sdk.js +691 -42
- package/dist/ai-sdk.js.map +1 -1
- package/dist/ai-sdk.mjs +190 -44
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/assistant-stream-CEVTPU3I.d.mts +211 -0
- package/dist/assistant-stream-CEVTPU3I.d.ts +211 -0
- package/dist/chunk-DISBVUTK.mjs +932 -0
- package/dist/chunk-DISBVUTK.mjs.map +1 -0
- package/dist/index.d.mts +23 -103
- package/dist/index.d.ts +23 -103
- package/dist/index.js +1189 -490
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +417 -625
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/AssistantStream-dm_T4K6d.d.mts +0 -28
- package/dist/AssistantStream-dm_T4K6d.d.ts +0 -28
- package/dist/chunk-ZSSWV6GU.mjs +0 -11
- package/dist/chunk-ZSSWV6GU.mjs.map +0 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
|
|
2
|
+
type ReadonlyJSONObject = {
|
|
3
|
+
readonly [key: string]: ReadonlyJSONValue;
|
|
4
|
+
};
|
|
5
|
+
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
|
|
6
|
+
|
|
7
|
+
type PartInit = {
|
|
8
|
+
readonly type: "text" | "reasoning";
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "tool-call";
|
|
11
|
+
readonly toolCallId: string;
|
|
12
|
+
readonly toolName: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: "source";
|
|
15
|
+
readonly sourceType: "url";
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly title?: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "file";
|
|
21
|
+
readonly data: string;
|
|
22
|
+
readonly mimeType: string;
|
|
23
|
+
};
|
|
24
|
+
type AssistantStreamChunk = {
|
|
25
|
+
readonly path: readonly number[];
|
|
26
|
+
} & ({
|
|
27
|
+
readonly type: "part-start";
|
|
28
|
+
readonly part: PartInit;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "part-finish";
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "tool-call-args-text-finish";
|
|
33
|
+
} | {
|
|
34
|
+
readonly type: "text-delta";
|
|
35
|
+
readonly textDelta: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly type: "annotations";
|
|
38
|
+
readonly annotations: ReadonlyJSONValue[];
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "data";
|
|
41
|
+
readonly data: ReadonlyJSONValue[];
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "step-start";
|
|
44
|
+
readonly messageId: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "step-finish";
|
|
47
|
+
readonly finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
48
|
+
readonly usage: {
|
|
49
|
+
readonly promptTokens: number;
|
|
50
|
+
readonly completionTokens: number;
|
|
51
|
+
};
|
|
52
|
+
readonly isContinued: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "message-finish";
|
|
55
|
+
readonly finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
56
|
+
readonly usage: {
|
|
57
|
+
readonly promptTokens: number;
|
|
58
|
+
readonly completionTokens: number;
|
|
59
|
+
};
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: "result";
|
|
62
|
+
readonly result: ReadonlyJSONValue;
|
|
63
|
+
readonly isError: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "error";
|
|
66
|
+
readonly error: string;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
type AssistantStreamEncoder = ReadableWritablePair<Uint8Array, AssistantStreamChunk> & {
|
|
70
|
+
headers?: Headers;
|
|
71
|
+
};
|
|
72
|
+
type AssistantStream = ReadableStream<AssistantStreamChunk>;
|
|
73
|
+
declare const AssistantStream: {
|
|
74
|
+
toResponse(stream: AssistantStream, transformer: AssistantStreamEncoder): Response;
|
|
75
|
+
fromResponse(response: Response, transformer: ReadableWritablePair<AssistantStreamChunk, Uint8Array>): ReadableStream<AssistantStreamChunk>;
|
|
76
|
+
toByteStream(stream: AssistantStream, transformer: ReadableWritablePair<Uint8Array, AssistantStreamChunk>): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
77
|
+
fromByteStream(readable: ReadableStream<Uint8Array>, transformer: ReadableWritablePair<AssistantStreamChunk, Uint8Array>): ReadableStream<AssistantStreamChunk>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type TextStreamController = {
|
|
81
|
+
append(textDelta: string): void;
|
|
82
|
+
close(): void;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type ToolCallStreamController = {
|
|
86
|
+
argsText: TextStreamController;
|
|
87
|
+
setResult(result: ReadonlyJSONValue, isError?: boolean): void;
|
|
88
|
+
close(): void;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type TextStatus = {
|
|
92
|
+
type: "running";
|
|
93
|
+
} | {
|
|
94
|
+
type: "complete";
|
|
95
|
+
reason: "stop" | "unknown";
|
|
96
|
+
} | {
|
|
97
|
+
type: "incomplete";
|
|
98
|
+
reason: "cancelled" | "length" | "content-filter" | "other";
|
|
99
|
+
};
|
|
100
|
+
type TextPart = {
|
|
101
|
+
type: "text";
|
|
102
|
+
text: string;
|
|
103
|
+
status: TextStatus;
|
|
104
|
+
};
|
|
105
|
+
type ReasoningPart = {
|
|
106
|
+
type: "reasoning";
|
|
107
|
+
text: string;
|
|
108
|
+
status: TextStatus;
|
|
109
|
+
};
|
|
110
|
+
type ToolCallStatus = {
|
|
111
|
+
type: "running";
|
|
112
|
+
isArgsComplete: boolean;
|
|
113
|
+
} | {
|
|
114
|
+
type: "requires-action";
|
|
115
|
+
reason: "tool-call-result";
|
|
116
|
+
} | {
|
|
117
|
+
type: "complete";
|
|
118
|
+
reason: "stop" | "unknown";
|
|
119
|
+
} | {
|
|
120
|
+
type: "incomplete";
|
|
121
|
+
reason: "cancelled" | "length" | "content-filter" | "other";
|
|
122
|
+
};
|
|
123
|
+
type ToolCallPart = {
|
|
124
|
+
type: "tool-call";
|
|
125
|
+
state: "partial-call" | "call" | "result";
|
|
126
|
+
status: ToolCallStatus;
|
|
127
|
+
toolCallId: string;
|
|
128
|
+
toolName: string;
|
|
129
|
+
argsText: string;
|
|
130
|
+
args: ReadonlyJSONObject;
|
|
131
|
+
result?: ReadonlyJSONValue;
|
|
132
|
+
isError?: boolean;
|
|
133
|
+
};
|
|
134
|
+
type SourcePart = {
|
|
135
|
+
type: "source";
|
|
136
|
+
sourceType: "url";
|
|
137
|
+
id: string;
|
|
138
|
+
url: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
};
|
|
141
|
+
type FilePart = {
|
|
142
|
+
type: "file";
|
|
143
|
+
data: string;
|
|
144
|
+
mimeType: string;
|
|
145
|
+
};
|
|
146
|
+
type AssistantMessagePart = TextPart | ReasoningPart | ToolCallPart | SourcePart | FilePart;
|
|
147
|
+
type AssistantMessageStepUsage = {
|
|
148
|
+
promptTokens: number;
|
|
149
|
+
completionTokens: number;
|
|
150
|
+
};
|
|
151
|
+
type AssistantMessageStepMetadata = {
|
|
152
|
+
state: "started";
|
|
153
|
+
messageId: string;
|
|
154
|
+
} | {
|
|
155
|
+
state: "finished";
|
|
156
|
+
messageId: string;
|
|
157
|
+
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
158
|
+
usage?: AssistantMessageStepUsage;
|
|
159
|
+
isContinued: boolean;
|
|
160
|
+
};
|
|
161
|
+
type AssistantMessageStatus = {
|
|
162
|
+
type: "running";
|
|
163
|
+
} | {
|
|
164
|
+
type: "requires-action";
|
|
165
|
+
reason: "tool-calls";
|
|
166
|
+
} | {
|
|
167
|
+
type: "complete";
|
|
168
|
+
reason: "stop" | "unknown";
|
|
169
|
+
} | {
|
|
170
|
+
type: "incomplete";
|
|
171
|
+
reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
|
|
172
|
+
error?: ReadonlyJSONValue;
|
|
173
|
+
};
|
|
174
|
+
type AssistantMessage = {
|
|
175
|
+
role: "assistant";
|
|
176
|
+
status: AssistantMessageStatus;
|
|
177
|
+
parts: AssistantMessagePart[];
|
|
178
|
+
/**
|
|
179
|
+
* @deprecated Use `parts` instead.
|
|
180
|
+
*/
|
|
181
|
+
content: AssistantMessagePart[];
|
|
182
|
+
metadata: {
|
|
183
|
+
unstable_data: ReadonlyJSONValue[];
|
|
184
|
+
unstable_annotations: ReadonlyJSONValue[];
|
|
185
|
+
steps: AssistantMessageStepMetadata[];
|
|
186
|
+
custom: Record<string, unknown>;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
type AssistantStreamController = {
|
|
191
|
+
appendText(textDelta: string): void;
|
|
192
|
+
appendReasoning(reasoningDelta: string): void;
|
|
193
|
+
appendSource(options: SourcePart): void;
|
|
194
|
+
appendFile(options: FilePart): void;
|
|
195
|
+
addTextPart(): TextStreamController;
|
|
196
|
+
addToolCallPart(toolName: string): ToolCallStreamController;
|
|
197
|
+
addToolCallPart(options: {
|
|
198
|
+
toolCallId?: string;
|
|
199
|
+
toolName: string;
|
|
200
|
+
args?: ReadonlyJSONObject;
|
|
201
|
+
result?: ReadonlyJSONValue;
|
|
202
|
+
isError?: boolean;
|
|
203
|
+
}): ToolCallStreamController;
|
|
204
|
+
enqueue(chunk: AssistantStreamChunk): void;
|
|
205
|
+
merge(stream: AssistantStream): void;
|
|
206
|
+
close(): void;
|
|
207
|
+
};
|
|
208
|
+
declare function createAssistantStream(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): AssistantStream;
|
|
209
|
+
declare function createAssistantStreamResponse(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): Response;
|
|
210
|
+
|
|
211
|
+
export { AssistantStream as A, type ReadonlyJSONValue as R, type AssistantStreamChunk as a, type AssistantStreamController as b, type AssistantMessage as c, type AssistantStreamEncoder as d, createAssistantStream as e, createAssistantStreamResponse as f };
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
type ReadonlyJSONValue = null | string | number | boolean | ReadonlyJSONObject | ReadonlyJSONArray;
|
|
2
|
+
type ReadonlyJSONObject = {
|
|
3
|
+
readonly [key: string]: ReadonlyJSONValue;
|
|
4
|
+
};
|
|
5
|
+
type ReadonlyJSONArray = readonly ReadonlyJSONValue[];
|
|
6
|
+
|
|
7
|
+
type PartInit = {
|
|
8
|
+
readonly type: "text" | "reasoning";
|
|
9
|
+
} | {
|
|
10
|
+
readonly type: "tool-call";
|
|
11
|
+
readonly toolCallId: string;
|
|
12
|
+
readonly toolName: string;
|
|
13
|
+
} | {
|
|
14
|
+
readonly type: "source";
|
|
15
|
+
readonly sourceType: "url";
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly url: string;
|
|
18
|
+
readonly title?: string;
|
|
19
|
+
} | {
|
|
20
|
+
readonly type: "file";
|
|
21
|
+
readonly data: string;
|
|
22
|
+
readonly mimeType: string;
|
|
23
|
+
};
|
|
24
|
+
type AssistantStreamChunk = {
|
|
25
|
+
readonly path: readonly number[];
|
|
26
|
+
} & ({
|
|
27
|
+
readonly type: "part-start";
|
|
28
|
+
readonly part: PartInit;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "part-finish";
|
|
31
|
+
} | {
|
|
32
|
+
readonly type: "tool-call-args-text-finish";
|
|
33
|
+
} | {
|
|
34
|
+
readonly type: "text-delta";
|
|
35
|
+
readonly textDelta: string;
|
|
36
|
+
} | {
|
|
37
|
+
readonly type: "annotations";
|
|
38
|
+
readonly annotations: ReadonlyJSONValue[];
|
|
39
|
+
} | {
|
|
40
|
+
readonly type: "data";
|
|
41
|
+
readonly data: ReadonlyJSONValue[];
|
|
42
|
+
} | {
|
|
43
|
+
readonly type: "step-start";
|
|
44
|
+
readonly messageId: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "step-finish";
|
|
47
|
+
readonly finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
48
|
+
readonly usage: {
|
|
49
|
+
readonly promptTokens: number;
|
|
50
|
+
readonly completionTokens: number;
|
|
51
|
+
};
|
|
52
|
+
readonly isContinued: boolean;
|
|
53
|
+
} | {
|
|
54
|
+
readonly type: "message-finish";
|
|
55
|
+
readonly finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
56
|
+
readonly usage: {
|
|
57
|
+
readonly promptTokens: number;
|
|
58
|
+
readonly completionTokens: number;
|
|
59
|
+
};
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: "result";
|
|
62
|
+
readonly result: ReadonlyJSONValue;
|
|
63
|
+
readonly isError: boolean;
|
|
64
|
+
} | {
|
|
65
|
+
readonly type: "error";
|
|
66
|
+
readonly error: string;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
type AssistantStreamEncoder = ReadableWritablePair<Uint8Array, AssistantStreamChunk> & {
|
|
70
|
+
headers?: Headers;
|
|
71
|
+
};
|
|
72
|
+
type AssistantStream = ReadableStream<AssistantStreamChunk>;
|
|
73
|
+
declare const AssistantStream: {
|
|
74
|
+
toResponse(stream: AssistantStream, transformer: AssistantStreamEncoder): Response;
|
|
75
|
+
fromResponse(response: Response, transformer: ReadableWritablePair<AssistantStreamChunk, Uint8Array>): ReadableStream<AssistantStreamChunk>;
|
|
76
|
+
toByteStream(stream: AssistantStream, transformer: ReadableWritablePair<Uint8Array, AssistantStreamChunk>): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
77
|
+
fromByteStream(readable: ReadableStream<Uint8Array>, transformer: ReadableWritablePair<AssistantStreamChunk, Uint8Array>): ReadableStream<AssistantStreamChunk>;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
type TextStreamController = {
|
|
81
|
+
append(textDelta: string): void;
|
|
82
|
+
close(): void;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type ToolCallStreamController = {
|
|
86
|
+
argsText: TextStreamController;
|
|
87
|
+
setResult(result: ReadonlyJSONValue, isError?: boolean): void;
|
|
88
|
+
close(): void;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
type TextStatus = {
|
|
92
|
+
type: "running";
|
|
93
|
+
} | {
|
|
94
|
+
type: "complete";
|
|
95
|
+
reason: "stop" | "unknown";
|
|
96
|
+
} | {
|
|
97
|
+
type: "incomplete";
|
|
98
|
+
reason: "cancelled" | "length" | "content-filter" | "other";
|
|
99
|
+
};
|
|
100
|
+
type TextPart = {
|
|
101
|
+
type: "text";
|
|
102
|
+
text: string;
|
|
103
|
+
status: TextStatus;
|
|
104
|
+
};
|
|
105
|
+
type ReasoningPart = {
|
|
106
|
+
type: "reasoning";
|
|
107
|
+
text: string;
|
|
108
|
+
status: TextStatus;
|
|
109
|
+
};
|
|
110
|
+
type ToolCallStatus = {
|
|
111
|
+
type: "running";
|
|
112
|
+
isArgsComplete: boolean;
|
|
113
|
+
} | {
|
|
114
|
+
type: "requires-action";
|
|
115
|
+
reason: "tool-call-result";
|
|
116
|
+
} | {
|
|
117
|
+
type: "complete";
|
|
118
|
+
reason: "stop" | "unknown";
|
|
119
|
+
} | {
|
|
120
|
+
type: "incomplete";
|
|
121
|
+
reason: "cancelled" | "length" | "content-filter" | "other";
|
|
122
|
+
};
|
|
123
|
+
type ToolCallPart = {
|
|
124
|
+
type: "tool-call";
|
|
125
|
+
state: "partial-call" | "call" | "result";
|
|
126
|
+
status: ToolCallStatus;
|
|
127
|
+
toolCallId: string;
|
|
128
|
+
toolName: string;
|
|
129
|
+
argsText: string;
|
|
130
|
+
args: ReadonlyJSONObject;
|
|
131
|
+
result?: ReadonlyJSONValue;
|
|
132
|
+
isError?: boolean;
|
|
133
|
+
};
|
|
134
|
+
type SourcePart = {
|
|
135
|
+
type: "source";
|
|
136
|
+
sourceType: "url";
|
|
137
|
+
id: string;
|
|
138
|
+
url: string;
|
|
139
|
+
title?: string;
|
|
140
|
+
};
|
|
141
|
+
type FilePart = {
|
|
142
|
+
type: "file";
|
|
143
|
+
data: string;
|
|
144
|
+
mimeType: string;
|
|
145
|
+
};
|
|
146
|
+
type AssistantMessagePart = TextPart | ReasoningPart | ToolCallPart | SourcePart | FilePart;
|
|
147
|
+
type AssistantMessageStepUsage = {
|
|
148
|
+
promptTokens: number;
|
|
149
|
+
completionTokens: number;
|
|
150
|
+
};
|
|
151
|
+
type AssistantMessageStepMetadata = {
|
|
152
|
+
state: "started";
|
|
153
|
+
messageId: string;
|
|
154
|
+
} | {
|
|
155
|
+
state: "finished";
|
|
156
|
+
messageId: string;
|
|
157
|
+
finishReason: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other" | "unknown";
|
|
158
|
+
usage?: AssistantMessageStepUsage;
|
|
159
|
+
isContinued: boolean;
|
|
160
|
+
};
|
|
161
|
+
type AssistantMessageStatus = {
|
|
162
|
+
type: "running";
|
|
163
|
+
} | {
|
|
164
|
+
type: "requires-action";
|
|
165
|
+
reason: "tool-calls";
|
|
166
|
+
} | {
|
|
167
|
+
type: "complete";
|
|
168
|
+
reason: "stop" | "unknown";
|
|
169
|
+
} | {
|
|
170
|
+
type: "incomplete";
|
|
171
|
+
reason: "cancelled" | "tool-calls" | "length" | "content-filter" | "other" | "error";
|
|
172
|
+
error?: ReadonlyJSONValue;
|
|
173
|
+
};
|
|
174
|
+
type AssistantMessage = {
|
|
175
|
+
role: "assistant";
|
|
176
|
+
status: AssistantMessageStatus;
|
|
177
|
+
parts: AssistantMessagePart[];
|
|
178
|
+
/**
|
|
179
|
+
* @deprecated Use `parts` instead.
|
|
180
|
+
*/
|
|
181
|
+
content: AssistantMessagePart[];
|
|
182
|
+
metadata: {
|
|
183
|
+
unstable_data: ReadonlyJSONValue[];
|
|
184
|
+
unstable_annotations: ReadonlyJSONValue[];
|
|
185
|
+
steps: AssistantMessageStepMetadata[];
|
|
186
|
+
custom: Record<string, unknown>;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
type AssistantStreamController = {
|
|
191
|
+
appendText(textDelta: string): void;
|
|
192
|
+
appendReasoning(reasoningDelta: string): void;
|
|
193
|
+
appendSource(options: SourcePart): void;
|
|
194
|
+
appendFile(options: FilePart): void;
|
|
195
|
+
addTextPart(): TextStreamController;
|
|
196
|
+
addToolCallPart(toolName: string): ToolCallStreamController;
|
|
197
|
+
addToolCallPart(options: {
|
|
198
|
+
toolCallId?: string;
|
|
199
|
+
toolName: string;
|
|
200
|
+
args?: ReadonlyJSONObject;
|
|
201
|
+
result?: ReadonlyJSONValue;
|
|
202
|
+
isError?: boolean;
|
|
203
|
+
}): ToolCallStreamController;
|
|
204
|
+
enqueue(chunk: AssistantStreamChunk): void;
|
|
205
|
+
merge(stream: AssistantStream): void;
|
|
206
|
+
close(): void;
|
|
207
|
+
};
|
|
208
|
+
declare function createAssistantStream(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): AssistantStream;
|
|
209
|
+
declare function createAssistantStreamResponse(callback: (controller: AssistantStreamController) => PromiseLike<void> | void): Response;
|
|
210
|
+
|
|
211
|
+
export { AssistantStream as A, type ReadonlyJSONValue as R, type AssistantStreamChunk as a, type AssistantStreamController as b, type AssistantMessage as c, type AssistantStreamEncoder as d, createAssistantStream as e, createAssistantStreamResponse as f };
|