@assistant-ui/react 0.5.30 → 0.5.32
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/EdgeRuntimeRequestOptions-BD0mpoF6.d.mts +412 -0
- package/dist/EdgeRuntimeRequestOptions-BD0mpoF6.d.ts +412 -0
- package/dist/edge.d.mts +261 -3
- package/dist/edge.d.ts +261 -3
- package/dist/edge.js +98 -101
- package/dist/edge.js.map +1 -1
- package/dist/edge.mjs +96 -100
- package/dist/edge.mjs.map +1 -1
- package/dist/index.d.mts +54 -283
- package/dist/index.d.ts +54 -283
- package/dist/index.js +2785 -2722
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2827 -2764
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/AssistantTypes-Bo5YKjhV.d.mts +0 -162
- package/dist/AssistantTypes-Bo5YKjhV.d.ts +0 -162
package/dist/edge.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { LanguageModelV1LogProbs, LanguageModelV1, LanguageModelV1ToolChoice } from '@ai-sdk/provider';
|
2
|
-
import { z } from 'zod';
|
3
2
|
import { JSONSchema7 } from 'json-schema';
|
3
|
+
import { z } from 'zod';
|
4
4
|
|
5
5
|
type TextContentPart = {
|
6
6
|
type: "text";
|
@@ -42,6 +42,255 @@ type CoreAssistantMessage = {
|
|
42
42
|
};
|
43
43
|
type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage;
|
44
44
|
|
45
|
+
declare const EdgeRuntimeRequestOptionsSchema: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<{
|
46
|
+
system: z.ZodOptional<z.ZodString>;
|
47
|
+
messages: z.ZodArray<z.ZodDiscriminatedUnion<"role", [z.ZodObject<{
|
48
|
+
role: z.ZodLiteral<"system">;
|
49
|
+
content: z.ZodTuple<[z.ZodObject<{
|
50
|
+
type: z.ZodLiteral<"text">;
|
51
|
+
text: z.ZodString;
|
52
|
+
}, "strip", z.ZodTypeAny, {
|
53
|
+
text: string;
|
54
|
+
type: "text";
|
55
|
+
}, {
|
56
|
+
text: string;
|
57
|
+
type: "text";
|
58
|
+
}>], null>;
|
59
|
+
}, "strip", z.ZodTypeAny, {
|
60
|
+
role: "system";
|
61
|
+
content: [{
|
62
|
+
text: string;
|
63
|
+
type: "text";
|
64
|
+
}];
|
65
|
+
}, {
|
66
|
+
role: "system";
|
67
|
+
content: [{
|
68
|
+
text: string;
|
69
|
+
type: "text";
|
70
|
+
}];
|
71
|
+
}>, z.ZodObject<{
|
72
|
+
role: z.ZodLiteral<"user">;
|
73
|
+
content: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
74
|
+
type: z.ZodLiteral<"text">;
|
75
|
+
text: z.ZodString;
|
76
|
+
}, "strip", z.ZodTypeAny, {
|
77
|
+
text: string;
|
78
|
+
type: "text";
|
79
|
+
}, {
|
80
|
+
text: string;
|
81
|
+
type: "text";
|
82
|
+
}>, z.ZodObject<{
|
83
|
+
type: z.ZodLiteral<"image">;
|
84
|
+
image: z.ZodString;
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
86
|
+
image: string;
|
87
|
+
type: "image";
|
88
|
+
}, {
|
89
|
+
image: string;
|
90
|
+
type: "image";
|
91
|
+
}>]>, "many">;
|
92
|
+
}, "strip", z.ZodTypeAny, {
|
93
|
+
role: "user";
|
94
|
+
content: ({
|
95
|
+
text: string;
|
96
|
+
type: "text";
|
97
|
+
} | {
|
98
|
+
image: string;
|
99
|
+
type: "image";
|
100
|
+
})[];
|
101
|
+
}, {
|
102
|
+
role: "user";
|
103
|
+
content: ({
|
104
|
+
text: string;
|
105
|
+
type: "text";
|
106
|
+
} | {
|
107
|
+
image: string;
|
108
|
+
type: "image";
|
109
|
+
})[];
|
110
|
+
}>, z.ZodObject<{
|
111
|
+
role: z.ZodLiteral<"assistant">;
|
112
|
+
content: z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
113
|
+
type: z.ZodLiteral<"text">;
|
114
|
+
text: z.ZodString;
|
115
|
+
}, "strip", z.ZodTypeAny, {
|
116
|
+
text: string;
|
117
|
+
type: "text";
|
118
|
+
}, {
|
119
|
+
text: string;
|
120
|
+
type: "text";
|
121
|
+
}>, z.ZodObject<{
|
122
|
+
type: z.ZodLiteral<"tool-call">;
|
123
|
+
toolCallId: z.ZodString;
|
124
|
+
toolName: z.ZodString;
|
125
|
+
args: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
126
|
+
result: z.ZodOptional<z.ZodUnknown>;
|
127
|
+
isError: z.ZodOptional<z.ZodBoolean>;
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
129
|
+
type: "tool-call";
|
130
|
+
toolCallId: string;
|
131
|
+
toolName: string;
|
132
|
+
args: Record<string, unknown>;
|
133
|
+
isError?: boolean | undefined;
|
134
|
+
result?: unknown;
|
135
|
+
}, {
|
136
|
+
type: "tool-call";
|
137
|
+
toolCallId: string;
|
138
|
+
toolName: string;
|
139
|
+
args: Record<string, unknown>;
|
140
|
+
isError?: boolean | undefined;
|
141
|
+
result?: unknown;
|
142
|
+
}>]>, "many">;
|
143
|
+
}, "strip", z.ZodTypeAny, {
|
144
|
+
role: "assistant";
|
145
|
+
content: ({
|
146
|
+
text: string;
|
147
|
+
type: "text";
|
148
|
+
} | {
|
149
|
+
type: "tool-call";
|
150
|
+
toolCallId: string;
|
151
|
+
toolName: string;
|
152
|
+
args: Record<string, unknown>;
|
153
|
+
isError?: boolean | undefined;
|
154
|
+
result?: unknown;
|
155
|
+
})[];
|
156
|
+
}, {
|
157
|
+
role: "assistant";
|
158
|
+
content: ({
|
159
|
+
text: string;
|
160
|
+
type: "text";
|
161
|
+
} | {
|
162
|
+
type: "tool-call";
|
163
|
+
toolCallId: string;
|
164
|
+
toolName: string;
|
165
|
+
args: Record<string, unknown>;
|
166
|
+
isError?: boolean | undefined;
|
167
|
+
result?: unknown;
|
168
|
+
})[];
|
169
|
+
}>]>, "many">;
|
170
|
+
tools: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
171
|
+
type: z.ZodLiteral<"function">;
|
172
|
+
name: z.ZodString;
|
173
|
+
description: z.ZodOptional<z.ZodString>;
|
174
|
+
parameters: z.ZodType<JSONSchema7, z.ZodTypeDef, JSONSchema7>;
|
175
|
+
}, "strip", z.ZodTypeAny, {
|
176
|
+
type: "function";
|
177
|
+
name: string;
|
178
|
+
parameters: JSONSchema7;
|
179
|
+
description?: string | undefined;
|
180
|
+
}, {
|
181
|
+
type: "function";
|
182
|
+
name: string;
|
183
|
+
parameters: JSONSchema7;
|
184
|
+
description?: string | undefined;
|
185
|
+
}>, "many">>;
|
186
|
+
}, {
|
187
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
188
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
189
|
+
topP: z.ZodOptional<z.ZodNumber>;
|
190
|
+
presencePenalty: z.ZodOptional<z.ZodNumber>;
|
191
|
+
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
192
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
193
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodOptional<z.ZodString>>>;
|
194
|
+
}>, {
|
195
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
196
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
197
|
+
modelName: z.ZodOptional<z.ZodString>;
|
198
|
+
}>, "strip", z.ZodTypeAny, {
|
199
|
+
messages: ({
|
200
|
+
role: "user";
|
201
|
+
content: ({
|
202
|
+
text: string;
|
203
|
+
type: "text";
|
204
|
+
} | {
|
205
|
+
image: string;
|
206
|
+
type: "image";
|
207
|
+
})[];
|
208
|
+
} | {
|
209
|
+
role: "assistant";
|
210
|
+
content: ({
|
211
|
+
text: string;
|
212
|
+
type: "text";
|
213
|
+
} | {
|
214
|
+
type: "tool-call";
|
215
|
+
toolCallId: string;
|
216
|
+
toolName: string;
|
217
|
+
args: Record<string, unknown>;
|
218
|
+
isError?: boolean | undefined;
|
219
|
+
result?: unknown;
|
220
|
+
})[];
|
221
|
+
} | {
|
222
|
+
role: "system";
|
223
|
+
content: [{
|
224
|
+
text: string;
|
225
|
+
type: "text";
|
226
|
+
}];
|
227
|
+
})[];
|
228
|
+
system?: string | undefined;
|
229
|
+
maxTokens?: number | undefined;
|
230
|
+
temperature?: number | undefined;
|
231
|
+
topP?: number | undefined;
|
232
|
+
presencePenalty?: number | undefined;
|
233
|
+
frequencyPenalty?: number | undefined;
|
234
|
+
seed?: number | undefined;
|
235
|
+
headers?: Record<string, string | undefined> | undefined;
|
236
|
+
apiKey?: string | undefined;
|
237
|
+
baseUrl?: string | undefined;
|
238
|
+
modelName?: string | undefined;
|
239
|
+
tools?: {
|
240
|
+
type: "function";
|
241
|
+
name: string;
|
242
|
+
parameters: JSONSchema7;
|
243
|
+
description?: string | undefined;
|
244
|
+
}[] | undefined;
|
245
|
+
}, {
|
246
|
+
messages: ({
|
247
|
+
role: "user";
|
248
|
+
content: ({
|
249
|
+
text: string;
|
250
|
+
type: "text";
|
251
|
+
} | {
|
252
|
+
image: string;
|
253
|
+
type: "image";
|
254
|
+
})[];
|
255
|
+
} | {
|
256
|
+
role: "assistant";
|
257
|
+
content: ({
|
258
|
+
text: string;
|
259
|
+
type: "text";
|
260
|
+
} | {
|
261
|
+
type: "tool-call";
|
262
|
+
toolCallId: string;
|
263
|
+
toolName: string;
|
264
|
+
args: Record<string, unknown>;
|
265
|
+
isError?: boolean | undefined;
|
266
|
+
result?: unknown;
|
267
|
+
})[];
|
268
|
+
} | {
|
269
|
+
role: "system";
|
270
|
+
content: [{
|
271
|
+
text: string;
|
272
|
+
type: "text";
|
273
|
+
}];
|
274
|
+
})[];
|
275
|
+
system?: string | undefined;
|
276
|
+
maxTokens?: number | undefined;
|
277
|
+
temperature?: number | undefined;
|
278
|
+
topP?: number | undefined;
|
279
|
+
presencePenalty?: number | undefined;
|
280
|
+
frequencyPenalty?: number | undefined;
|
281
|
+
seed?: number | undefined;
|
282
|
+
headers?: Record<string, string | undefined> | undefined;
|
283
|
+
apiKey?: string | undefined;
|
284
|
+
baseUrl?: string | undefined;
|
285
|
+
modelName?: string | undefined;
|
286
|
+
tools?: {
|
287
|
+
type: "function";
|
288
|
+
name: string;
|
289
|
+
parameters: JSONSchema7;
|
290
|
+
description?: string | undefined;
|
291
|
+
}[] | undefined;
|
292
|
+
}>;
|
293
|
+
|
45
294
|
declare const LanguageModelV1CallSettingsSchema: z.ZodObject<{
|
46
295
|
maxTokens: z.ZodOptional<z.ZodNumber>;
|
47
296
|
temperature: z.ZodOptional<z.ZodNumber>;
|
@@ -103,8 +352,17 @@ type CreateEdgeRuntimeAPIOptions = LanguageModelV1CallSettings & {
|
|
103
352
|
toolChoice?: LanguageModelV1ToolChoice;
|
104
353
|
onFinish?: (result: FinishResult) => void;
|
105
354
|
};
|
106
|
-
|
355
|
+
type GetEdgeRuntimeStreamOptions = {
|
356
|
+
abortSignal: AbortSignal;
|
357
|
+
requestData: z.infer<typeof EdgeRuntimeRequestOptionsSchema>;
|
358
|
+
options: CreateEdgeRuntimeAPIOptions;
|
359
|
+
};
|
360
|
+
declare namespace getEdgeRuntimeResponse {
|
361
|
+
export type { GetEdgeRuntimeStreamOptions as Options };
|
362
|
+
}
|
363
|
+
declare const getEdgeRuntimeResponse: (options: getEdgeRuntimeResponse.Options) => Promise<Response>;
|
364
|
+
declare const createEdgeRuntimeAPI: (options: CreateEdgeRuntimeAPIOptions) => {
|
107
365
|
POST: (request: Request) => Promise<Response>;
|
108
366
|
};
|
109
367
|
|
110
|
-
export { createEdgeRuntimeAPI };
|
368
|
+
export { createEdgeRuntimeAPI, getEdgeRuntimeResponse };
|
package/dist/edge.js
CHANGED
@@ -30,7 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
30
30
|
// src/edge.ts
|
31
31
|
var edge_exports = {};
|
32
32
|
__export(edge_exports, {
|
33
|
-
createEdgeRuntimeAPI: () => createEdgeRuntimeAPI
|
33
|
+
createEdgeRuntimeAPI: () => createEdgeRuntimeAPI,
|
34
|
+
getEdgeRuntimeResponse: () => getEdgeRuntimeResponse
|
34
35
|
});
|
35
36
|
module.exports = __toCommonJS(edge_exports);
|
36
37
|
|
@@ -963,117 +964,112 @@ var voidStream = () => {
|
|
963
964
|
}
|
964
965
|
});
|
965
966
|
};
|
966
|
-
var
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
967
|
+
var getEdgeRuntimeStream = async ({
|
968
|
+
abortSignal,
|
969
|
+
requestData: unsafeRequest,
|
970
|
+
options: {
|
971
|
+
model: modelOrCreator,
|
972
|
+
system: serverSystem,
|
973
|
+
tools: serverTools = {},
|
974
|
+
toolChoice,
|
975
|
+
onFinish,
|
976
|
+
...unsafeSettings
|
977
|
+
}
|
973
978
|
}) => {
|
974
979
|
const settings = LanguageModelV1CallSettingsSchema.parse(unsafeSettings);
|
975
980
|
const lmServerTools = toLanguageModelTools(serverTools);
|
976
981
|
const hasServerTools = Object.values(serverTools).some((v) => !!v.execute);
|
977
|
-
const
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
);
|
996
|
-
}
|
982
|
+
const {
|
983
|
+
system: clientSystem,
|
984
|
+
tools: clientTools = [],
|
985
|
+
messages,
|
986
|
+
apiKey,
|
987
|
+
baseUrl,
|
988
|
+
modelName,
|
989
|
+
...callSettings
|
990
|
+
} = EdgeRuntimeRequestOptionsSchema.parse(unsafeRequest);
|
991
|
+
const systemMessages = [];
|
992
|
+
if (serverSystem) systemMessages.push(serverSystem);
|
993
|
+
if (clientSystem) systemMessages.push(clientSystem);
|
994
|
+
const system = systemMessages.join("\n\n");
|
995
|
+
for (const clientTool of clientTools) {
|
996
|
+
if (serverTools?.[clientTool.name]) {
|
997
|
+
throw new Error(
|
998
|
+
`Tool ${clientTool.name} was defined in both the client and server tools. This is not allowed.`
|
999
|
+
);
|
997
1000
|
}
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1001
|
+
}
|
1002
|
+
let model;
|
1003
|
+
model = typeof modelOrCreator === "function" ? await modelOrCreator({ apiKey, baseUrl, modelName }) : modelOrCreator;
|
1004
|
+
let stream;
|
1005
|
+
const streamResult = await streamMessage({
|
1006
|
+
...settings,
|
1007
|
+
...callSettings,
|
1008
|
+
model,
|
1009
|
+
abortSignal,
|
1010
|
+
...!!system ? { system } : void 0,
|
1011
|
+
messages,
|
1012
|
+
tools: lmServerTools.concat(clientTools),
|
1013
|
+
...toolChoice ? { toolChoice } : void 0
|
1014
|
+
});
|
1015
|
+
stream = streamResult.stream;
|
1016
|
+
const canExecuteTools = hasServerTools && toolChoice?.type !== "none";
|
1017
|
+
if (canExecuteTools) {
|
1018
|
+
stream = stream.pipeThrough(toolResultStream(serverTools, abortSignal));
|
1019
|
+
}
|
1020
|
+
if (canExecuteTools || onFinish) {
|
1021
|
+
const tees = stream.tee();
|
1022
|
+
stream = tees[0];
|
1023
|
+
let serverStream = tees[1];
|
1024
|
+
if (onFinish) {
|
1025
|
+
let lastChunk;
|
1026
|
+
serverStream = serverStream.pipeThrough(runResultStream()).pipeThrough(
|
1027
|
+
new TransformStream({
|
1028
|
+
transform(chunk) {
|
1029
|
+
lastChunk = chunk;
|
1030
|
+
},
|
1031
|
+
flush() {
|
1032
|
+
if (!lastChunk?.status || lastChunk.status.type === "running")
|
1033
|
+
return;
|
1034
|
+
const resultingMessages = [
|
1035
|
+
...messages,
|
1036
|
+
toCoreMessage({
|
1037
|
+
role: "assistant",
|
1038
|
+
content: lastChunk.content
|
1039
|
+
})
|
1040
|
+
];
|
1041
|
+
onFinish({
|
1042
|
+
messages: resultingMessages,
|
1043
|
+
roundtrips: lastChunk.roundtrips
|
1044
|
+
});
|
1011
1045
|
}
|
1012
|
-
}
|
1046
|
+
})
|
1013
1047
|
);
|
1014
1048
|
}
|
1015
|
-
|
1016
|
-
|
1017
|
-
...settings,
|
1018
|
-
...callSettings,
|
1019
|
-
model,
|
1020
|
-
abortSignal: request.signal,
|
1021
|
-
...!!system ? { system } : void 0,
|
1022
|
-
messages,
|
1023
|
-
tools: lmServerTools.concat(clientTools),
|
1024
|
-
...toolChoice ? { toolChoice } : void 0
|
1049
|
+
serverStream.pipeTo(voidStream()).catch((e) => {
|
1050
|
+
console.error("Server stream processing error:", e);
|
1025
1051
|
});
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
let serverStream = tees[1];
|
1037
|
-
if (onFinish) {
|
1038
|
-
let lastChunk;
|
1039
|
-
serverStream = serverStream.pipeThrough(runResultStream()).pipeThrough(
|
1040
|
-
new TransformStream({
|
1041
|
-
transform(chunk) {
|
1042
|
-
lastChunk = chunk;
|
1043
|
-
},
|
1044
|
-
flush() {
|
1045
|
-
if (!lastChunk?.status || lastChunk.status.type === "running")
|
1046
|
-
return;
|
1047
|
-
const resultingMessages = [
|
1048
|
-
...messages,
|
1049
|
-
toCoreMessage({
|
1050
|
-
role: "assistant",
|
1051
|
-
content: lastChunk.content
|
1052
|
-
})
|
1053
|
-
];
|
1054
|
-
onFinish({
|
1055
|
-
messages: resultingMessages,
|
1056
|
-
roundtrips: lastChunk.roundtrips
|
1057
|
-
});
|
1058
|
-
}
|
1059
|
-
})
|
1060
|
-
);
|
1052
|
+
}
|
1053
|
+
return stream;
|
1054
|
+
};
|
1055
|
+
var getEdgeRuntimeResponse = async (options) => {
|
1056
|
+
const stream = await getEdgeRuntimeStream(options);
|
1057
|
+
return new Response(
|
1058
|
+
stream.pipeThrough(assistantEncoderStream()).pipeThrough(streamPartEncoderStream()),
|
1059
|
+
{
|
1060
|
+
headers: {
|
1061
|
+
"Content-Type": "text/plain; charset=utf-8"
|
1061
1062
|
}
|
1062
|
-
serverStream.pipeTo(voidStream()).catch((e) => {
|
1063
|
-
console.error("Server stream processing error:", e);
|
1064
|
-
});
|
1065
1063
|
}
|
1066
|
-
|
1067
|
-
stream.pipeThrough(assistantEncoderStream()).pipeThrough(streamPartEncoderStream()),
|
1068
|
-
{
|
1069
|
-
headers: {
|
1070
|
-
contentType: "text/plain; charset=utf-8"
|
1071
|
-
}
|
1072
|
-
}
|
1073
|
-
);
|
1074
|
-
};
|
1075
|
-
return { POST };
|
1064
|
+
);
|
1076
1065
|
};
|
1066
|
+
var createEdgeRuntimeAPI = (options) => ({
|
1067
|
+
POST: async (request) => getEdgeRuntimeResponse({
|
1068
|
+
abortSignal: request.signal,
|
1069
|
+
requestData: await request.json(),
|
1070
|
+
options
|
1071
|
+
})
|
1072
|
+
});
|
1077
1073
|
async function streamMessage({
|
1078
1074
|
model,
|
1079
1075
|
system,
|
@@ -1103,6 +1099,7 @@ function convertToLanguageModelPrompt(system, messages) {
|
|
1103
1099
|
}
|
1104
1100
|
// Annotate the CommonJS export names for ESM import in node:
|
1105
1101
|
0 && (module.exports = {
|
1106
|
-
createEdgeRuntimeAPI
|
1102
|
+
createEdgeRuntimeAPI,
|
1103
|
+
getEdgeRuntimeResponse
|
1107
1104
|
});
|
1108
1105
|
//# sourceMappingURL=edge.js.map
|