@assistant-ui/react 0.3.5 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -8
- package/dist/edge.d.mts +9 -0
- package/dist/edge.d.ts +9 -0
- package/dist/edge.js +264 -0
- package/dist/edge.js.map +1 -0
- package/dist/edge.mjs +237 -0
- package/dist/edge.mjs.map +1 -0
- package/dist/index.d.mts +422 -60
- package/dist/index.d.ts +422 -60
- package/dist/index.js +1603 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1594 -76
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +859 -0
- package/dist/styles/index.css.map +1 -0
- package/dist/styles/index.d.ts +2 -0
- package/dist/styles/modal.css +143 -0
- package/dist/styles/modal.css.map +1 -0
- package/dist/styles/modal.d.ts +2 -0
- package/dist/styles/tailwindcss/base-components.css +53 -0
- package/dist/styles/tailwindcss/modal.css +29 -0
- package/dist/styles/tailwindcss/thread.css +159 -0
- package/dist/styles/themes/default.css +61 -0
- package/dist/tailwindcss/index.d.mts +15 -0
- package/dist/tailwindcss/index.d.ts +15 -0
- package/dist/tailwindcss/index.js +108 -0
- package/dist/tailwindcss/index.js.map +1 -0
- package/dist/tailwindcss/index.mjs +77 -0
- package/dist/tailwindcss/index.mjs.map +1 -0
- package/package.json +49 -6
package/README.md
CHANGED
@@ -2,15 +2,17 @@
|
|
2
2
|
<img src="https://raw.githubusercontent.com/Yonom/assistant-ui/main/.github/assets/header.svg" alt="assistant-ui Header" width="100%" />
|
3
3
|
</a>
|
4
4
|
|
5
|
-
|
5
|
+
<p align="center">
|
6
|
+
<a href="https://assistant-ui.com">Product</a> ·
|
7
|
+
<a href="https://assistant-ui.com/docs">Documentation</a> ·
|
8
|
+
<a href="https://assistant-ui.com/examples">Examples</a> ·
|
9
|
+
<a href="https://discord.gg/S9dwgCNEFs">Discord Community</a> ·
|
10
|
+
<a href="https://cal.com/simon-farshid/assistant-ui">Enterprise inquiry</a>
|
11
|
+
</p>
|
6
12
|
|
7
|
-
-
|
8
|
-
- [Website](https://assistant-ui.com/)
|
9
|
-
- [Demo](https://assistant-ui-rsc-example.vercel.app/)
|
13
|
+
**assistant-ui** is a set of React components for AI chat, with integrations Langchain, Vercel AI SDK, TailwindCSS, shadcn-ui, react-markdown, react-syntax-highlighter, React Hook Form and more!
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
- [Documentation](https://www.assistant-ui.com/docs/getting-started)
|
15
|
+
Wide model provider support (OpenAI, Anthropic, Mistral, Perplexity, AWS Bedrock, Azure, Google Gemini, Hugging Face, Fireworks, Cohere, Replicate, Ollama) out of the box and the ability to integrate custom APIs.
|
14
16
|
|
15
17
|
## Quick Start
|
16
18
|
|
@@ -23,7 +25,7 @@ npx assistant-ui@latest create my-app
|
|
23
25
|
cd my-app
|
24
26
|
```
|
25
27
|
|
26
|
-
Step 2: Update the `.env` file with your OpenAI API key.
|
28
|
+
Step 2: Update the `.env` file with your OpenAI API key.
|
27
29
|
|
28
30
|
Step 3: Run the app:
|
29
31
|
|
package/dist/edge.d.mts
ADDED
package/dist/edge.d.ts
ADDED
package/dist/edge.js
ADDED
@@ -0,0 +1,264 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
|
20
|
+
// src/edge.ts
|
21
|
+
var edge_exports = {};
|
22
|
+
__export(edge_exports, {
|
23
|
+
createEdgeRuntimeAPI: () => createEdgeRuntimeAPI
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(edge_exports);
|
26
|
+
|
27
|
+
// src/runtimes/edge/streams/assistantEncoderStream.ts
|
28
|
+
function assistantEncoderStream() {
|
29
|
+
const toolCalls = /* @__PURE__ */ new Set();
|
30
|
+
return new TransformStream({
|
31
|
+
transform(chunk, controller) {
|
32
|
+
const chunkType = chunk.type;
|
33
|
+
switch (chunkType) {
|
34
|
+
case "text-delta": {
|
35
|
+
controller.enqueue(
|
36
|
+
formatStreamPart(
|
37
|
+
"0" /* TextDelta */,
|
38
|
+
chunk.textDelta
|
39
|
+
)
|
40
|
+
);
|
41
|
+
break;
|
42
|
+
}
|
43
|
+
case "tool-call-delta": {
|
44
|
+
if (!toolCalls.has(chunk.toolCallId)) {
|
45
|
+
toolCalls.add(chunk.toolCallId);
|
46
|
+
controller.enqueue(
|
47
|
+
formatStreamPart("1" /* ToolCallBegin */, {
|
48
|
+
id: chunk.toolCallId,
|
49
|
+
name: chunk.toolName
|
50
|
+
})
|
51
|
+
);
|
52
|
+
}
|
53
|
+
controller.enqueue(
|
54
|
+
formatStreamPart(
|
55
|
+
"2" /* ToolCallArgsTextDelta */,
|
56
|
+
chunk.argsTextDelta
|
57
|
+
)
|
58
|
+
);
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
case "tool-call":
|
62
|
+
break;
|
63
|
+
case "finish": {
|
64
|
+
const { type, ...rest } = chunk;
|
65
|
+
controller.enqueue(
|
66
|
+
formatStreamPart(
|
67
|
+
"F" /* Finish */,
|
68
|
+
JSON.stringify(rest)
|
69
|
+
)
|
70
|
+
);
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
case "error": {
|
74
|
+
controller.enqueue(
|
75
|
+
formatStreamPart(
|
76
|
+
"E" /* Error */,
|
77
|
+
JSON.stringify(chunk.error)
|
78
|
+
)
|
79
|
+
);
|
80
|
+
break;
|
81
|
+
}
|
82
|
+
default: {
|
83
|
+
const unhandledType = chunkType;
|
84
|
+
throw new Error(`Unhandled chunk type: ${unhandledType}`);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
});
|
89
|
+
}
|
90
|
+
function formatStreamPart(code, value) {
|
91
|
+
return `${code}:${JSON.stringify(value)}
|
92
|
+
`;
|
93
|
+
}
|
94
|
+
|
95
|
+
// src/runtimes/edge/createEdgeRuntimeAPI.ts
|
96
|
+
var createEdgeRuntimeAPI = ({ model }) => {
|
97
|
+
const POST = async (request) => {
|
98
|
+
const { system, messages, tools } = await request.json();
|
99
|
+
const { stream } = await streamMessage({
|
100
|
+
model,
|
101
|
+
abortSignal: request.signal,
|
102
|
+
...system ? { system } : void 0,
|
103
|
+
messages,
|
104
|
+
tools
|
105
|
+
});
|
106
|
+
return new Response(stream, {
|
107
|
+
headers: {
|
108
|
+
contentType: "text/plain; charset=utf-8"
|
109
|
+
}
|
110
|
+
});
|
111
|
+
};
|
112
|
+
return { POST };
|
113
|
+
};
|
114
|
+
async function streamMessage({
|
115
|
+
model,
|
116
|
+
system,
|
117
|
+
messages,
|
118
|
+
tools,
|
119
|
+
toolChoice,
|
120
|
+
...options
|
121
|
+
}) {
|
122
|
+
const { stream, warnings, rawResponse } = await model.doStream({
|
123
|
+
inputFormat: "messages",
|
124
|
+
mode: {
|
125
|
+
type: "regular",
|
126
|
+
...tools ? { tools } : void 0,
|
127
|
+
...toolChoice ? { toolChoice } : void 0
|
128
|
+
},
|
129
|
+
prompt: convertToLanguageModelPrompt(system, messages),
|
130
|
+
...options
|
131
|
+
});
|
132
|
+
return {
|
133
|
+
stream: stream.pipeThrough(assistantEncoderStream()).pipeThrough(new TextEncoderStream()),
|
134
|
+
warnings,
|
135
|
+
rawResponse
|
136
|
+
};
|
137
|
+
}
|
138
|
+
function convertToLanguageModelPrompt(system, messages) {
|
139
|
+
const languageModelMessages = [];
|
140
|
+
if (system != null) {
|
141
|
+
languageModelMessages.push({ role: "system", content: system });
|
142
|
+
}
|
143
|
+
languageModelMessages.push(
|
144
|
+
...messages.flatMap(convertToLanguageModelMessage)
|
145
|
+
);
|
146
|
+
return languageModelMessages;
|
147
|
+
}
|
148
|
+
var assistantMessageSplitter = () => {
|
149
|
+
const stash = [];
|
150
|
+
let assistantMessage = {
|
151
|
+
role: "assistant",
|
152
|
+
content: []
|
153
|
+
};
|
154
|
+
let toolMessage = {
|
155
|
+
role: "tool",
|
156
|
+
content: []
|
157
|
+
};
|
158
|
+
return {
|
159
|
+
addTextContentPart: (part) => {
|
160
|
+
if (toolMessage.content.length > 0) {
|
161
|
+
stash.push(assistantMessage);
|
162
|
+
stash.push(toolMessage);
|
163
|
+
assistantMessage = {
|
164
|
+
role: "assistant",
|
165
|
+
content: []
|
166
|
+
};
|
167
|
+
toolMessage = {
|
168
|
+
role: "tool",
|
169
|
+
content: []
|
170
|
+
};
|
171
|
+
}
|
172
|
+
assistantMessage.content.push(part);
|
173
|
+
},
|
174
|
+
addToolCallPart: (part) => {
|
175
|
+
assistantMessage.content.push({
|
176
|
+
type: "tool-call",
|
177
|
+
toolCallId: part.toolCallId,
|
178
|
+
toolName: part.toolName,
|
179
|
+
args: part.args
|
180
|
+
});
|
181
|
+
if (part.result) {
|
182
|
+
toolMessage.content.push({
|
183
|
+
type: "tool-result",
|
184
|
+
toolCallId: part.toolCallId,
|
185
|
+
toolName: part.toolName,
|
186
|
+
result: part.result
|
187
|
+
// isError
|
188
|
+
});
|
189
|
+
}
|
190
|
+
},
|
191
|
+
getMessages: () => {
|
192
|
+
if (toolMessage.content.length > 0) {
|
193
|
+
return [...stash, assistantMessage, toolMessage];
|
194
|
+
}
|
195
|
+
return [...stash, assistantMessage];
|
196
|
+
}
|
197
|
+
};
|
198
|
+
};
|
199
|
+
function convertToLanguageModelMessage(message) {
|
200
|
+
const role = message.role;
|
201
|
+
switch (role) {
|
202
|
+
case "system": {
|
203
|
+
return [{ role: "system", content: message.content[0].text }];
|
204
|
+
}
|
205
|
+
case "user": {
|
206
|
+
const msg = {
|
207
|
+
role: "user",
|
208
|
+
content: message.content.map(
|
209
|
+
(part) => {
|
210
|
+
const type = part.type;
|
211
|
+
switch (type) {
|
212
|
+
case "text": {
|
213
|
+
return part;
|
214
|
+
}
|
215
|
+
case "image": {
|
216
|
+
return {
|
217
|
+
type: "image",
|
218
|
+
image: new URL(part.image)
|
219
|
+
};
|
220
|
+
}
|
221
|
+
default: {
|
222
|
+
const unhandledType = type;
|
223
|
+
throw new Error(
|
224
|
+
`Unspported content part type: ${unhandledType}`
|
225
|
+
);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
)
|
230
|
+
};
|
231
|
+
return [msg];
|
232
|
+
}
|
233
|
+
case "assistant": {
|
234
|
+
const splitter = assistantMessageSplitter();
|
235
|
+
for (const part of message.content) {
|
236
|
+
const type = part.type;
|
237
|
+
switch (type) {
|
238
|
+
case "text": {
|
239
|
+
splitter.addTextContentPart(part);
|
240
|
+
break;
|
241
|
+
}
|
242
|
+
case "tool-call": {
|
243
|
+
splitter.addToolCallPart(part);
|
244
|
+
break;
|
245
|
+
}
|
246
|
+
default: {
|
247
|
+
const _exhaustiveCheck = type;
|
248
|
+
throw new Error(`Unhandled content part type: ${_exhaustiveCheck}`);
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
return splitter.getMessages();
|
253
|
+
}
|
254
|
+
default: {
|
255
|
+
const unhandledRole = role;
|
256
|
+
throw new Error(`Unknown message role: ${unhandledRole}`);
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
// Annotate the CommonJS export names for ESM import in node:
|
261
|
+
0 && (module.exports = {
|
262
|
+
createEdgeRuntimeAPI
|
263
|
+
});
|
264
|
+
//# sourceMappingURL=edge.js.map
|
package/dist/edge.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/edge.ts","../src/runtimes/edge/streams/assistantEncoderStream.ts","../src/runtimes/edge/createEdgeRuntimeAPI.ts"],"sourcesContent":["export { createEdgeRuntimeAPI } from \"./runtimes/edge/createEdgeRuntimeAPI\";\n","import { AssistantStreamChunkType } from \"./AssistantStreamChunkType\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\n\nexport function assistantEncoderStream() {\n const toolCalls = new Set<string>();\n return new TransformStream<LanguageModelV1StreamPart, string>({\n transform(chunk, controller) {\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"text-delta\": {\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.TextDelta,\n chunk.textDelta,\n ),\n );\n break;\n }\n case \"tool-call-delta\": {\n if (!toolCalls.has(chunk.toolCallId)) {\n toolCalls.add(chunk.toolCallId);\n controller.enqueue(\n formatStreamPart(AssistantStreamChunkType.ToolCallBegin, {\n id: chunk.toolCallId,\n name: chunk.toolName,\n }),\n );\n }\n\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.ToolCallArgsTextDelta,\n chunk.argsTextDelta,\n ),\n );\n break;\n }\n\n // ignore\n case \"tool-call\":\n break;\n\n case \"finish\": {\n const { type, ...rest } = chunk;\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.Finish,\n JSON.stringify(rest),\n ),\n );\n break;\n }\n\n case \"error\": {\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.Error,\n JSON.stringify(chunk.error),\n ),\n );\n break;\n }\n default: {\n const unhandledType: never = chunkType;\n throw new Error(`Unhandled chunk type: ${unhandledType}`);\n }\n }\n },\n });\n}\n\nexport function formatStreamPart(\n code: AssistantStreamChunkType,\n value: any,\n): string {\n return `${code}:${JSON.stringify(value)}\\n`;\n}\n","import {\n LanguageModelV1,\n LanguageModelV1ToolChoice,\n LanguageModelV1FunctionTool,\n LanguageModelV1Message,\n LanguageModelV1Prompt,\n LanguageModelV1CallOptions,\n LanguageModelV1TextPart,\n LanguageModelV1CallWarning,\n LanguageModelV1ToolCallPart,\n LanguageModelV1ToolResultPart,\n LanguageModelV1ImagePart,\n} from \"@ai-sdk/provider\";\nimport {\n CoreThreadMessage,\n TextContentPart,\n ToolCallContentPart,\n} from \"../../types/AssistantTypes\";\nimport { assistantEncoderStream } from \"./streams/assistantEncoderStream\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\n\nexport const createEdgeRuntimeAPI = ({ model }: { model: LanguageModelV1 }) => {\n const POST = async (request: Request) => {\n const { system, messages, tools } =\n (await request.json()) as EdgeRuntimeRequestOptions;\n\n const { stream } = await streamMessage({\n model,\n abortSignal: request.signal,\n\n ...(system ? { system } : undefined),\n messages,\n tools,\n });\n\n return new Response(stream, {\n headers: {\n contentType: \"text/plain; charset=utf-8\",\n },\n });\n };\n return { POST };\n};\n\ntype StreamMessageResult = {\n stream: ReadableStream<Uint8Array>;\n warnings: LanguageModelV1CallWarning[] | undefined;\n rawResponse: unknown;\n};\n\nasync function streamMessage({\n model,\n system,\n messages,\n tools,\n toolChoice,\n ...options\n}: Omit<LanguageModelV1CallOptions, \"inputFormat\" | \"mode\" | \"prompt\"> & {\n model: LanguageModelV1;\n system?: string;\n messages: CoreThreadMessage[];\n tools?: LanguageModelV1FunctionTool[];\n toolChoice?: LanguageModelV1ToolChoice;\n}): Promise<StreamMessageResult> {\n const { stream, warnings, rawResponse } = await model.doStream({\n inputFormat: \"messages\",\n mode: {\n type: \"regular\",\n ...(tools ? { tools } : undefined),\n ...(toolChoice ? { toolChoice } : undefined),\n },\n prompt: convertToLanguageModelPrompt(system, messages),\n ...options,\n });\n\n return {\n stream: stream\n .pipeThrough(assistantEncoderStream())\n .pipeThrough(new TextEncoderStream()),\n warnings,\n rawResponse,\n };\n}\n\nexport function convertToLanguageModelPrompt(\n system: string | undefined,\n messages: CoreThreadMessage[],\n): LanguageModelV1Prompt {\n const languageModelMessages: LanguageModelV1Prompt = [];\n\n if (system != null) {\n languageModelMessages.push({ role: \"system\", content: system });\n }\n languageModelMessages.push(\n ...messages.flatMap(convertToLanguageModelMessage),\n );\n\n return languageModelMessages;\n}\n\nconst assistantMessageSplitter = () => {\n const stash: LanguageModelV1Message[] = [];\n let assistantMessage = {\n role: \"assistant\" as const,\n content: [] as (LanguageModelV1TextPart | LanguageModelV1ToolCallPart)[],\n };\n let toolMessage = {\n role: \"tool\" as const,\n content: [] as LanguageModelV1ToolResultPart[],\n };\n\n return {\n addTextContentPart: (part: TextContentPart) => {\n if (toolMessage.content.length > 0) {\n stash.push(assistantMessage);\n stash.push(toolMessage);\n\n assistantMessage = {\n role: \"assistant\" as const,\n content: [] as (\n | LanguageModelV1TextPart\n | LanguageModelV1ToolCallPart\n )[],\n };\n\n toolMessage = {\n role: \"tool\" as const,\n content: [] as LanguageModelV1ToolResultPart[],\n };\n }\n\n assistantMessage.content.push(part);\n },\n addToolCallPart: (part: ToolCallContentPart) => {\n assistantMessage.content.push({\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n args: part.args,\n });\n if (part.result) {\n toolMessage.content.push({\n type: \"tool-result\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n result: part.result,\n // isError\n });\n }\n },\n getMessages: () => {\n if (toolMessage.content.length > 0) {\n return [...stash, assistantMessage, toolMessage];\n }\n\n return [...stash, assistantMessage];\n },\n };\n};\n\nexport function convertToLanguageModelMessage(\n message: CoreThreadMessage,\n): LanguageModelV1Message[] {\n const role = message.role;\n switch (role) {\n case \"system\": {\n return [{ role: \"system\", content: message.content[0].text }];\n }\n\n case \"user\": {\n const msg: LanguageModelV1Message = {\n role: \"user\",\n content: message.content.map(\n (part): LanguageModelV1TextPart | LanguageModelV1ImagePart => {\n const type = part.type;\n switch (type) {\n case \"text\": {\n return part;\n }\n\n case \"image\": {\n return {\n type: \"image\",\n image: new URL(part.image),\n };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Unspported content part type: ${unhandledType}`,\n );\n }\n }\n },\n ),\n };\n return [msg];\n }\n\n case \"assistant\": {\n const splitter = assistantMessageSplitter();\n for (const part of message.content) {\n const type = part.type;\n switch (type) {\n case \"text\": {\n splitter.addTextContentPart(part);\n break;\n }\n case \"tool-call\": {\n splitter.addToolCallPart(part);\n break;\n }\n default: {\n const _exhaustiveCheck: never = type;\n throw new Error(`Unhandled content part type: ${_exhaustiveCheck}`);\n }\n }\n }\n return splitter.getMessages();\n }\n\n default: {\n const unhandledRole: never = role;\n throw new Error(`Unknown message role: ${unhandledRole}`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,yBAAyB;AACvC,QAAM,YAAY,oBAAI,IAAY;AAClC,SAAO,IAAI,gBAAmD;AAAA,IAC5D,UAAU,OAAO,YAAY;AAC3B,YAAM,YAAY,MAAM;AACxB,cAAQ,WAAW;AAAA,QACjB,KAAK,cAAc;AACjB,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,MAAM;AAAA,YACR;AAAA,UACF;AACA;AAAA,QACF;AAAA,QACA,KAAK,mBAAmB;AACtB,cAAI,CAAC,UAAU,IAAI,MAAM,UAAU,GAAG;AACpC,sBAAU,IAAI,MAAM,UAAU;AAC9B,uBAAW;AAAA,cACT,0CAAyD;AAAA,gBACvD,IAAI,MAAM;AAAA,gBACV,MAAM,MAAM;AAAA,cACd,CAAC;AAAA,YACH;AAAA,UACF;AAEA,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,MAAM;AAAA,YACR;AAAA,UACF;AACA;AAAA,QACF;AAAA,QAGA,KAAK;AACH;AAAA,QAEF,KAAK,UAAU;AACb,gBAAM,EAAE,MAAM,GAAG,KAAK,IAAI;AAC1B,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,KAAK,UAAU,IAAI;AAAA,YACrB;AAAA,UACF;AACA;AAAA,QACF;AAAA,QAEA,KAAK,SAAS;AACZ,q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Y;AAAA,IAC9B;AAAA,IAEA,SAAS;AACP,YAAM,gBAAuB;AAC7B,YAAM,IAAI,MAAM,yBAAyB,aAAa,EAAE;AAAA,IAC1D;AAAA,EACF;AACF;","names":[]}
|
package/dist/edge.mjs
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
// src/runtimes/edge/streams/assistantEncoderStream.ts
|
2
|
+
function assistantEncoderStream() {
|
3
|
+
const toolCalls = /* @__PURE__ */ new Set();
|
4
|
+
return new TransformStream({
|
5
|
+
transform(chunk, controller) {
|
6
|
+
const chunkType = chunk.type;
|
7
|
+
switch (chunkType) {
|
8
|
+
case "text-delta": {
|
9
|
+
controller.enqueue(
|
10
|
+
formatStreamPart(
|
11
|
+
"0" /* TextDelta */,
|
12
|
+
chunk.textDelta
|
13
|
+
)
|
14
|
+
);
|
15
|
+
break;
|
16
|
+
}
|
17
|
+
case "tool-call-delta": {
|
18
|
+
if (!toolCalls.has(chunk.toolCallId)) {
|
19
|
+
toolCalls.add(chunk.toolCallId);
|
20
|
+
controller.enqueue(
|
21
|
+
formatStreamPart("1" /* ToolCallBegin */, {
|
22
|
+
id: chunk.toolCallId,
|
23
|
+
name: chunk.toolName
|
24
|
+
})
|
25
|
+
);
|
26
|
+
}
|
27
|
+
controller.enqueue(
|
28
|
+
formatStreamPart(
|
29
|
+
"2" /* ToolCallArgsTextDelta */,
|
30
|
+
chunk.argsTextDelta
|
31
|
+
)
|
32
|
+
);
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
case "tool-call":
|
36
|
+
break;
|
37
|
+
case "finish": {
|
38
|
+
const { type, ...rest } = chunk;
|
39
|
+
controller.enqueue(
|
40
|
+
formatStreamPart(
|
41
|
+
"F" /* Finish */,
|
42
|
+
JSON.stringify(rest)
|
43
|
+
)
|
44
|
+
);
|
45
|
+
break;
|
46
|
+
}
|
47
|
+
case "error": {
|
48
|
+
controller.enqueue(
|
49
|
+
formatStreamPart(
|
50
|
+
"E" /* Error */,
|
51
|
+
JSON.stringify(chunk.error)
|
52
|
+
)
|
53
|
+
);
|
54
|
+
break;
|
55
|
+
}
|
56
|
+
default: {
|
57
|
+
const unhandledType = chunkType;
|
58
|
+
throw new Error(`Unhandled chunk type: ${unhandledType}`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
64
|
+
function formatStreamPart(code, value) {
|
65
|
+
return `${code}:${JSON.stringify(value)}
|
66
|
+
`;
|
67
|
+
}
|
68
|
+
|
69
|
+
// src/runtimes/edge/createEdgeRuntimeAPI.ts
|
70
|
+
var createEdgeRuntimeAPI = ({ model }) => {
|
71
|
+
const POST = async (request) => {
|
72
|
+
const { system, messages, tools } = await request.json();
|
73
|
+
const { stream } = await streamMessage({
|
74
|
+
model,
|
75
|
+
abortSignal: request.signal,
|
76
|
+
...system ? { system } : void 0,
|
77
|
+
messages,
|
78
|
+
tools
|
79
|
+
});
|
80
|
+
return new Response(stream, {
|
81
|
+
headers: {
|
82
|
+
contentType: "text/plain; charset=utf-8"
|
83
|
+
}
|
84
|
+
});
|
85
|
+
};
|
86
|
+
return { POST };
|
87
|
+
};
|
88
|
+
async function streamMessage({
|
89
|
+
model,
|
90
|
+
system,
|
91
|
+
messages,
|
92
|
+
tools,
|
93
|
+
toolChoice,
|
94
|
+
...options
|
95
|
+
}) {
|
96
|
+
const { stream, warnings, rawResponse } = await model.doStream({
|
97
|
+
inputFormat: "messages",
|
98
|
+
mode: {
|
99
|
+
type: "regular",
|
100
|
+
...tools ? { tools } : void 0,
|
101
|
+
...toolChoice ? { toolChoice } : void 0
|
102
|
+
},
|
103
|
+
prompt: convertToLanguageModelPrompt(system, messages),
|
104
|
+
...options
|
105
|
+
});
|
106
|
+
return {
|
107
|
+
stream: stream.pipeThrough(assistantEncoderStream()).pipeThrough(new TextEncoderStream()),
|
108
|
+
warnings,
|
109
|
+
rawResponse
|
110
|
+
};
|
111
|
+
}
|
112
|
+
function convertToLanguageModelPrompt(system, messages) {
|
113
|
+
const languageModelMessages = [];
|
114
|
+
if (system != null) {
|
115
|
+
languageModelMessages.push({ role: "system", content: system });
|
116
|
+
}
|
117
|
+
languageModelMessages.push(
|
118
|
+
...messages.flatMap(convertToLanguageModelMessage)
|
119
|
+
);
|
120
|
+
return languageModelMessages;
|
121
|
+
}
|
122
|
+
var assistantMessageSplitter = () => {
|
123
|
+
const stash = [];
|
124
|
+
let assistantMessage = {
|
125
|
+
role: "assistant",
|
126
|
+
content: []
|
127
|
+
};
|
128
|
+
let toolMessage = {
|
129
|
+
role: "tool",
|
130
|
+
content: []
|
131
|
+
};
|
132
|
+
return {
|
133
|
+
addTextContentPart: (part) => {
|
134
|
+
if (toolMessage.content.length > 0) {
|
135
|
+
stash.push(assistantMessage);
|
136
|
+
stash.push(toolMessage);
|
137
|
+
assistantMessage = {
|
138
|
+
role: "assistant",
|
139
|
+
content: []
|
140
|
+
};
|
141
|
+
toolMessage = {
|
142
|
+
role: "tool",
|
143
|
+
content: []
|
144
|
+
};
|
145
|
+
}
|
146
|
+
assistantMessage.content.push(part);
|
147
|
+
},
|
148
|
+
addToolCallPart: (part) => {
|
149
|
+
assistantMessage.content.push({
|
150
|
+
type: "tool-call",
|
151
|
+
toolCallId: part.toolCallId,
|
152
|
+
toolName: part.toolName,
|
153
|
+
args: part.args
|
154
|
+
});
|
155
|
+
if (part.result) {
|
156
|
+
toolMessage.content.push({
|
157
|
+
type: "tool-result",
|
158
|
+
toolCallId: part.toolCallId,
|
159
|
+
toolName: part.toolName,
|
160
|
+
result: part.result
|
161
|
+
// isError
|
162
|
+
});
|
163
|
+
}
|
164
|
+
},
|
165
|
+
getMessages: () => {
|
166
|
+
if (toolMessage.content.length > 0) {
|
167
|
+
return [...stash, assistantMessage, toolMessage];
|
168
|
+
}
|
169
|
+
return [...stash, assistantMessage];
|
170
|
+
}
|
171
|
+
};
|
172
|
+
};
|
173
|
+
function convertToLanguageModelMessage(message) {
|
174
|
+
const role = message.role;
|
175
|
+
switch (role) {
|
176
|
+
case "system": {
|
177
|
+
return [{ role: "system", content: message.content[0].text }];
|
178
|
+
}
|
179
|
+
case "user": {
|
180
|
+
const msg = {
|
181
|
+
role: "user",
|
182
|
+
content: message.content.map(
|
183
|
+
(part) => {
|
184
|
+
const type = part.type;
|
185
|
+
switch (type) {
|
186
|
+
case "text": {
|
187
|
+
return part;
|
188
|
+
}
|
189
|
+
case "image": {
|
190
|
+
return {
|
191
|
+
type: "image",
|
192
|
+
image: new URL(part.image)
|
193
|
+
};
|
194
|
+
}
|
195
|
+
default: {
|
196
|
+
const unhandledType = type;
|
197
|
+
throw new Error(
|
198
|
+
`Unspported content part type: ${unhandledType}`
|
199
|
+
);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
}
|
203
|
+
)
|
204
|
+
};
|
205
|
+
return [msg];
|
206
|
+
}
|
207
|
+
case "assistant": {
|
208
|
+
const splitter = assistantMessageSplitter();
|
209
|
+
for (const part of message.content) {
|
210
|
+
const type = part.type;
|
211
|
+
switch (type) {
|
212
|
+
case "text": {
|
213
|
+
splitter.addTextContentPart(part);
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
case "tool-call": {
|
217
|
+
splitter.addToolCallPart(part);
|
218
|
+
break;
|
219
|
+
}
|
220
|
+
default: {
|
221
|
+
const _exhaustiveCheck = type;
|
222
|
+
throw new Error(`Unhandled content part type: ${_exhaustiveCheck}`);
|
223
|
+
}
|
224
|
+
}
|
225
|
+
}
|
226
|
+
return splitter.getMessages();
|
227
|
+
}
|
228
|
+
default: {
|
229
|
+
const unhandledRole = role;
|
230
|
+
throw new Error(`Unknown message role: ${unhandledRole}`);
|
231
|
+
}
|
232
|
+
}
|
233
|
+
}
|
234
|
+
export {
|
235
|
+
createEdgeRuntimeAPI
|
236
|
+
};
|
237
|
+
//# sourceMappingURL=edge.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/runtimes/edge/streams/assistantEncoderStream.ts","../src/runtimes/edge/createEdgeRuntimeAPI.ts"],"sourcesContent":["import { AssistantStreamChunkType } from \"./AssistantStreamChunkType\";\nimport { LanguageModelV1StreamPart } from \"@ai-sdk/provider\";\n\nexport function assistantEncoderStream() {\n const toolCalls = new Set<string>();\n return new TransformStream<LanguageModelV1StreamPart, string>({\n transform(chunk, controller) {\n const chunkType = chunk.type;\n switch (chunkType) {\n case \"text-delta\": {\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.TextDelta,\n chunk.textDelta,\n ),\n );\n break;\n }\n case \"tool-call-delta\": {\n if (!toolCalls.has(chunk.toolCallId)) {\n toolCalls.add(chunk.toolCallId);\n controller.enqueue(\n formatStreamPart(AssistantStreamChunkType.ToolCallBegin, {\n id: chunk.toolCallId,\n name: chunk.toolName,\n }),\n );\n }\n\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.ToolCallArgsTextDelta,\n chunk.argsTextDelta,\n ),\n );\n break;\n }\n\n // ignore\n case \"tool-call\":\n break;\n\n case \"finish\": {\n const { type, ...rest } = chunk;\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.Finish,\n JSON.stringify(rest),\n ),\n );\n break;\n }\n\n case \"error\": {\n controller.enqueue(\n formatStreamPart(\n AssistantStreamChunkType.Error,\n JSON.stringify(chunk.error),\n ),\n );\n break;\n }\n default: {\n const unhandledType: never = chunkType;\n throw new Error(`Unhandled chunk type: ${unhandledType}`);\n }\n }\n },\n });\n}\n\nexport function formatStreamPart(\n code: AssistantStreamChunkType,\n value: any,\n): string {\n return `${code}:${JSON.stringify(value)}\\n`;\n}\n","import {\n LanguageModelV1,\n LanguageModelV1ToolChoice,\n LanguageModelV1FunctionTool,\n LanguageModelV1Message,\n LanguageModelV1Prompt,\n LanguageModelV1CallOptions,\n LanguageModelV1TextPart,\n LanguageModelV1CallWarning,\n LanguageModelV1ToolCallPart,\n LanguageModelV1ToolResultPart,\n LanguageModelV1ImagePart,\n} from \"@ai-sdk/provider\";\nimport {\n CoreThreadMessage,\n TextContentPart,\n ToolCallContentPart,\n} from \"../../types/AssistantTypes\";\nimport { assistantEncoderStream } from \"./streams/assistantEncoderStream\";\nimport { EdgeRuntimeRequestOptions } from \"./EdgeRuntimeRequestOptions\";\n\nexport const createEdgeRuntimeAPI = ({ model }: { model: LanguageModelV1 }) => {\n const POST = async (request: Request) => {\n const { system, messages, tools } =\n (await request.json()) as EdgeRuntimeRequestOptions;\n\n const { stream } = await streamMessage({\n model,\n abortSignal: request.signal,\n\n ...(system ? { system } : undefined),\n messages,\n tools,\n });\n\n return new Response(stream, {\n headers: {\n contentType: \"text/plain; charset=utf-8\",\n },\n });\n };\n return { POST };\n};\n\ntype StreamMessageResult = {\n stream: ReadableStream<Uint8Array>;\n warnings: LanguageModelV1CallWarning[] | undefined;\n rawResponse: unknown;\n};\n\nasync function streamMessage({\n model,\n system,\n messages,\n tools,\n toolChoice,\n ...options\n}: Omit<LanguageModelV1CallOptions, \"inputFormat\" | \"mode\" | \"prompt\"> & {\n model: LanguageModelV1;\n system?: string;\n messages: CoreThreadMessage[];\n tools?: LanguageModelV1FunctionTool[];\n toolChoice?: LanguageModelV1ToolChoice;\n}): Promise<StreamMessageResult> {\n const { stream, warnings, rawResponse } = await model.doStream({\n inputFormat: \"messages\",\n mode: {\n type: \"regular\",\n ...(tools ? { tools } : undefined),\n ...(toolChoice ? { toolChoice } : undefined),\n },\n prompt: convertToLanguageModelPrompt(system, messages),\n ...options,\n });\n\n return {\n stream: stream\n .pipeThrough(assistantEncoderStream())\n .pipeThrough(new TextEncoderStream()),\n warnings,\n rawResponse,\n };\n}\n\nexport function convertToLanguageModelPrompt(\n system: string | undefined,\n messages: CoreThreadMessage[],\n): LanguageModelV1Prompt {\n const languageModelMessages: LanguageModelV1Prompt = [];\n\n if (system != null) {\n languageModelMessages.push({ role: \"system\", content: system });\n }\n languageModelMessages.push(\n ...messages.flatMap(convertToLanguageModelMessage),\n );\n\n return languageModelMessages;\n}\n\nconst assistantMessageSplitter = () => {\n const stash: LanguageModelV1Message[] = [];\n let assistantMessage = {\n role: \"assistant\" as const,\n content: [] as (LanguageModelV1TextPart | LanguageModelV1ToolCallPart)[],\n };\n let toolMessage = {\n role: \"tool\" as const,\n content: [] as LanguageModelV1ToolResultPart[],\n };\n\n return {\n addTextContentPart: (part: TextContentPart) => {\n if (toolMessage.content.length > 0) {\n stash.push(assistantMessage);\n stash.push(toolMessage);\n\n assistantMessage = {\n role: \"assistant\" as const,\n content: [] as (\n | LanguageModelV1TextPart\n | LanguageModelV1ToolCallPart\n )[],\n };\n\n toolMessage = {\n role: \"tool\" as const,\n content: [] as LanguageModelV1ToolResultPart[],\n };\n }\n\n assistantMessage.content.push(part);\n },\n addToolCallPart: (part: ToolCallContentPart) => {\n assistantMessage.content.push({\n type: \"tool-call\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n args: part.args,\n });\n if (part.result) {\n toolMessage.content.push({\n type: \"tool-result\",\n toolCallId: part.toolCallId,\n toolName: part.toolName,\n result: part.result,\n // isError\n });\n }\n },\n getMessages: () => {\n if (toolMessage.content.length > 0) {\n return [...stash, assistantMessage, toolMessage];\n }\n\n return [...stash, assistantMessage];\n },\n };\n};\n\nexport function convertToLanguageModelMessage(\n message: CoreThreadMessage,\n): LanguageModelV1Message[] {\n const role = message.role;\n switch (role) {\n case \"system\": {\n return [{ role: \"system\", content: message.content[0].text }];\n }\n\n case \"user\": {\n const msg: LanguageModelV1Message = {\n role: \"user\",\n content: message.content.map(\n (part): LanguageModelV1TextPart | LanguageModelV1ImagePart => {\n const type = part.type;\n switch (type) {\n case \"text\": {\n return part;\n }\n\n case \"image\": {\n return {\n type: \"image\",\n image: new URL(part.image),\n };\n }\n\n default: {\n const unhandledType: never = type;\n throw new Error(\n `Unspported content part type: ${unhandledType}`,\n );\n }\n }\n },\n ),\n };\n return [msg];\n }\n\n case \"assistant\": {\n const splitter = assistantMessageSplitter();\n for (const part of message.content) {\n const type = part.type;\n switch (type) {\n case \"text\": {\n splitter.addTextContentPart(part);\n break;\n }\n case \"tool-call\": {\n splitter.addToolCallPart(part);\n break;\n }\n default: {\n const _exhaustiveCheck: never = type;\n throw new Error(`Unhandled content part type: ${_exhaustiveCheck}`);\n }\n }\n }\n return splitter.getMessages();\n }\n\n default: {\n const unhandledRole: never = role;\n throw new Error(`Unknown message role: ${unhandledRole}`);\n }\n }\n}\n"],"mappings":";AAGO,SAAS,yBAAyB;AACvC,QAAM,YAAY,oBAAI,IAAY;AAClC,SAAO,IAAI,gBAAmD;AAAA,IAC5D,UAAU,OAAO,YAAY;AAC3B,YAAM,YAAY,MAAM;AACxB,cAAQ,WAAW;AAAA,QACjB,KAAK,cAAc;AACjB,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,MAAM;AAAA,YACR;AAAA,UACF;AACA;AAAA,QACF;AAAA,QACA,KAAK,mBAAmB;AACtB,cAAI,CAAC,UAAU,IAAI,MAAM,UAAU,GAAG;AACpC,sBAAU,IAAI,MAAM,UAAU;AAC9B,uBAAW;AAAA,cACT,0CAAyD;AAAA,gBACvD,IAAI,MAAM;AAAA,gBACV,MAAM,MAAM;AAAA,cACd,CAAC;AAAA,YACH;AAAA,UACF;AAEA,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,MAAM;AAAA,YACR;AAAA,UACF;AACA;AAAA,QACF;AAAA,QAGA,KAAK;AACH;AAAA,QAEF,KAAK,UAAU;AACb,gBAAM,EAAE,MAAM,GAAG,KAAK,IAAI;AAC1B,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,KAAK,UAAU,IAAI;AAAA,YACrB;AAAA,UACF;AACA;AAAA,QACF;AAAA,QAEA,KAAK,SAAS;AACZ,qBAAW;AAAA,YACT;AAAA;AAAA,cAEE,KAAK,UAAU,MAAM,KAAK;AAAA,YAC5B;AAAA,UACF;AACA;AAAA,QACF;AAAA,QACA,SAAS;AACP,gBAAM,gBAAuB;AAC7B,gBAAM,IAAI,MAAM,yBAAyB,aAAa,EAAE;AAAA,QAC1D;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC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