@builder.io/ai-utils 0.3.22 → 0.4.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/README.md +3 -0
- package/package.json +1 -1
- package/src/codegen.ts +725 -0
- package/src/completion.ts +174 -0
- package/src/events.ts +488 -0
- package/src/mapping.ts +98 -0
- package/src/messages.ts +393 -0
- package/src/settings.ts +59 -0
- package/src/codegen.d.ts +0 -534
- package/src/codegen.js +0 -1
- package/src/completion.d.ts +0 -154
- package/src/completion.js +0 -1
- package/src/events.d.ts +0 -378
- package/src/events.js +0 -1
- package/src/index.js +0 -6
- package/src/mapping.d.ts +0 -86
- package/src/mapping.js +0 -1
- package/src/messages.d.ts +0 -261
- package/src/messages.js +0 -16
- package/src/settings.d.ts +0 -20
- package/src/settings.js +0 -30
- /package/src/{index.d.ts → index.ts} +0 -0
package/src/messages.d.ts
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import type { ContentUpdatePatch } from "./events.js";
|
|
2
|
-
/**
|
|
3
|
-
* Message param does not know the id of the message.
|
|
4
|
-
* This is an input message.
|
|
5
|
-
*/
|
|
6
|
-
export type MessageParam = SystemMessageParam | UserMessageParam | AssistantMessageParam;
|
|
7
|
-
export interface ContentMessageItemText {
|
|
8
|
-
type: "text";
|
|
9
|
-
text: string;
|
|
10
|
-
cache?: boolean;
|
|
11
|
-
citations?: TextCitationParam[] | null;
|
|
12
|
-
ephemeral?: boolean;
|
|
13
|
-
}
|
|
14
|
-
export interface ContentMessageItemImage {
|
|
15
|
-
type: "image";
|
|
16
|
-
source: ImageBase64Source | ImageUrlSource;
|
|
17
|
-
cache?: boolean;
|
|
18
|
-
ephemeral?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface ContentMessageItemDocument {
|
|
21
|
-
type: "document";
|
|
22
|
-
source: DocumentBase64Source | DocumentUrlSource;
|
|
23
|
-
cache?: boolean;
|
|
24
|
-
ephemeral?: boolean;
|
|
25
|
-
}
|
|
26
|
-
export interface DocumentBase64Source {
|
|
27
|
-
type: "base64";
|
|
28
|
-
media_type: "application/pdf";
|
|
29
|
-
data: string;
|
|
30
|
-
}
|
|
31
|
-
export interface DocumentUrlSource {
|
|
32
|
-
type: "url";
|
|
33
|
-
url: string;
|
|
34
|
-
}
|
|
35
|
-
export interface ContentMessageItemToolResult {
|
|
36
|
-
type: "tool_result";
|
|
37
|
-
tool_use_id: string;
|
|
38
|
-
tool_name?: string;
|
|
39
|
-
tool_input?: string;
|
|
40
|
-
title?: string;
|
|
41
|
-
content: string | (ContentMessageItemText | ContentMessageItemImage)[];
|
|
42
|
-
is_error?: boolean;
|
|
43
|
-
cache?: boolean;
|
|
44
|
-
ephemeral?: boolean;
|
|
45
|
-
}
|
|
46
|
-
export interface ImageBase64Source {
|
|
47
|
-
type: "base64";
|
|
48
|
-
media_type: "image/webp" | "image/png" | "image/jpeg" | "image/gif";
|
|
49
|
-
data: string;
|
|
50
|
-
}
|
|
51
|
-
export interface ImageUrlSource {
|
|
52
|
-
type: "url";
|
|
53
|
-
url: string;
|
|
54
|
-
}
|
|
55
|
-
export interface ContentMessageItemThinking {
|
|
56
|
-
type: "thinking";
|
|
57
|
-
thinking: string;
|
|
58
|
-
signature: string;
|
|
59
|
-
}
|
|
60
|
-
export interface ContentMessageItemRedactedThinking {
|
|
61
|
-
type: "redacted_thinking";
|
|
62
|
-
data: string;
|
|
63
|
-
}
|
|
64
|
-
export interface ContentMessageItemToolUse {
|
|
65
|
-
type: "tool_use";
|
|
66
|
-
id: string;
|
|
67
|
-
input: unknown;
|
|
68
|
-
completion?: string;
|
|
69
|
-
name: string;
|
|
70
|
-
}
|
|
71
|
-
export interface CitationCharLocationParam {
|
|
72
|
-
cited_text: string;
|
|
73
|
-
document_index: number;
|
|
74
|
-
document_title: string | null;
|
|
75
|
-
end_char_index: number;
|
|
76
|
-
start_char_index: number;
|
|
77
|
-
type: "char_location";
|
|
78
|
-
}
|
|
79
|
-
export interface CitationContentBlockLocationParam {
|
|
80
|
-
cited_text: string;
|
|
81
|
-
document_index: number;
|
|
82
|
-
document_title: string | null;
|
|
83
|
-
end_block_index: number;
|
|
84
|
-
start_block_index: number;
|
|
85
|
-
type: "content_block_location";
|
|
86
|
-
}
|
|
87
|
-
export interface CitationPageLocationParam {
|
|
88
|
-
cited_text: string;
|
|
89
|
-
document_index: number;
|
|
90
|
-
document_title: string | null;
|
|
91
|
-
end_page_number: number;
|
|
92
|
-
start_page_number: number;
|
|
93
|
-
type: "page_location";
|
|
94
|
-
}
|
|
95
|
-
export interface CitationWebSearchResultLocationParam {
|
|
96
|
-
cited_text: string;
|
|
97
|
-
encrypted_index: string;
|
|
98
|
-
title: string | null;
|
|
99
|
-
type: "web_search_result_location";
|
|
100
|
-
url: string;
|
|
101
|
-
}
|
|
102
|
-
export type TextCitationParam = CitationCharLocationParam | CitationPageLocationParam | CitationContentBlockLocationParam | CitationWebSearchResultLocationParam;
|
|
103
|
-
export interface ServerToolUseContent {
|
|
104
|
-
type: "web_search_result";
|
|
105
|
-
title: string;
|
|
106
|
-
url: string;
|
|
107
|
-
page_age: string | null;
|
|
108
|
-
encrypted_content: string;
|
|
109
|
-
}
|
|
110
|
-
export interface ServerToolUseContentError {
|
|
111
|
-
error_code: "invalid_tool_input" | "unavailable" | "max_uses_exceeded" | "too_many_requests" | "query_too_long";
|
|
112
|
-
type: "web_search_tool_result_error";
|
|
113
|
-
}
|
|
114
|
-
export type ServerToolUseContentUnion = ServerToolUseContent[] | ServerToolUseContentError;
|
|
115
|
-
export interface ContentMessageItemServerToolUse {
|
|
116
|
-
type: "server_tool_use";
|
|
117
|
-
id: string;
|
|
118
|
-
name: "web_search" | "code_execution";
|
|
119
|
-
input: unknown;
|
|
120
|
-
completion?: string;
|
|
121
|
-
content?: any;
|
|
122
|
-
cache?: boolean;
|
|
123
|
-
}
|
|
124
|
-
export interface MCPServerURLDefinition {
|
|
125
|
-
name: string;
|
|
126
|
-
type: "url";
|
|
127
|
-
url: string;
|
|
128
|
-
authorization_token?: string | null;
|
|
129
|
-
tool_configuration?: MCPServerToolConfiguration | null;
|
|
130
|
-
}
|
|
131
|
-
export interface MCPServerToolConfiguration {
|
|
132
|
-
allowed_tools?: Array<string> | null;
|
|
133
|
-
enabled?: boolean | null;
|
|
134
|
-
}
|
|
135
|
-
export interface ContentMessageItemWebSearchToolResult {
|
|
136
|
-
content: ServerToolUseContent[] | ServerToolUseContentError;
|
|
137
|
-
tool_use_id: string;
|
|
138
|
-
type: "web_search_tool_result";
|
|
139
|
-
cache?: boolean;
|
|
140
|
-
}
|
|
141
|
-
export interface ContentMessageItemMCPToolUse {
|
|
142
|
-
type: "mcp_tool_use";
|
|
143
|
-
id: string;
|
|
144
|
-
name: string;
|
|
145
|
-
input: unknown;
|
|
146
|
-
server_name: string;
|
|
147
|
-
cache?: boolean;
|
|
148
|
-
}
|
|
149
|
-
export interface ContentMessageItemContainerUpload {
|
|
150
|
-
type: "container_upload";
|
|
151
|
-
file_id: string;
|
|
152
|
-
}
|
|
153
|
-
export interface ContentMessageItemMCPToolResult {
|
|
154
|
-
type: "mcp_tool_result";
|
|
155
|
-
tool_use_id: string;
|
|
156
|
-
content: string | ContentMessageItemText[];
|
|
157
|
-
is_error: boolean;
|
|
158
|
-
cache?: boolean;
|
|
159
|
-
}
|
|
160
|
-
export interface ContentMessageItemCodeExecutionToolResult {
|
|
161
|
-
type: "code_execution_tool_result";
|
|
162
|
-
tool_use_id: string;
|
|
163
|
-
content: any;
|
|
164
|
-
cache?: boolean;
|
|
165
|
-
}
|
|
166
|
-
export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult | ContentMessageItemWebSearchToolResult | ContentMessageItemServerToolUse | ContentMessageItemMCPToolUse | ContentMessageItemMCPToolResult | ContentMessageItemContainerUpload | ContentMessageItemCodeExecutionToolResult;
|
|
167
|
-
export type ContentMessage = ContentMessageItem[];
|
|
168
|
-
export interface SystemMessageParam {
|
|
169
|
-
/**
|
|
170
|
-
* The contents of the system message.
|
|
171
|
-
*/
|
|
172
|
-
content: string | ContentMessageItemText[];
|
|
173
|
-
responseId?: string;
|
|
174
|
-
/**
|
|
175
|
-
* The role of the messages author, in this case `system`.
|
|
176
|
-
*/
|
|
177
|
-
role: "system";
|
|
178
|
-
id?: string;
|
|
179
|
-
}
|
|
180
|
-
export interface UserMessageParam {
|
|
181
|
-
/**
|
|
182
|
-
* The contents of the user message.
|
|
183
|
-
*/
|
|
184
|
-
content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemToolResult)[];
|
|
185
|
-
responseId?: string;
|
|
186
|
-
/**
|
|
187
|
-
* The role of the messages author, in this case `user`.
|
|
188
|
-
*/
|
|
189
|
-
role: "user";
|
|
190
|
-
id?: string;
|
|
191
|
-
}
|
|
192
|
-
export type AssistantMessageAction = "new-chat";
|
|
193
|
-
export interface AssistantMessageParam {
|
|
194
|
-
/**
|
|
195
|
-
* The contents of the assistant message.
|
|
196
|
-
*/
|
|
197
|
-
content: string | ContentMessageItem[];
|
|
198
|
-
/**
|
|
199
|
-
* The role of the messages author, in this case `assistant`.
|
|
200
|
-
*/
|
|
201
|
-
role: "assistant";
|
|
202
|
-
responseId?: string;
|
|
203
|
-
id?: string;
|
|
204
|
-
skipDelta?: boolean;
|
|
205
|
-
/**
|
|
206
|
-
* A summary of the patches which the assistant has made.
|
|
207
|
-
* Useful for genai.
|
|
208
|
-
*/
|
|
209
|
-
patches?: ContentUpdatePatch[];
|
|
210
|
-
state?: "error";
|
|
211
|
-
/**
|
|
212
|
-
* Any actions associated with the error such as a "new chat" button.
|
|
213
|
-
* typically used when there is an error.
|
|
214
|
-
*/
|
|
215
|
-
actions?: AssistantMessageAction[];
|
|
216
|
-
}
|
|
217
|
-
export interface SystemMessage extends SystemMessageParam {
|
|
218
|
-
id: string;
|
|
219
|
-
}
|
|
220
|
-
export interface UserMessage extends UserMessageParam {
|
|
221
|
-
id: string;
|
|
222
|
-
}
|
|
223
|
-
export interface AssistantMessage extends AssistantMessageParam {
|
|
224
|
-
id: string;
|
|
225
|
-
status?: "accepted" | "rejected" | "aborted";
|
|
226
|
-
summary?: string;
|
|
227
|
-
}
|
|
228
|
-
export interface AssistantActionMessage {
|
|
229
|
-
/**
|
|
230
|
-
* The role of the messages author, in this case `assistant`.
|
|
231
|
-
*/
|
|
232
|
-
role: "assistant";
|
|
233
|
-
id: string;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Message DOES know the id of the message.
|
|
237
|
-
* This message is after an id has been assigned
|
|
238
|
-
* and is the output message.
|
|
239
|
-
*/
|
|
240
|
-
export type Message = SystemMessage | UserMessage | AssistantMessage;
|
|
241
|
-
export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
|
|
242
|
-
export declare function getContentText(message: string | ContentMessage): string;
|
|
243
|
-
export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
|
|
244
|
-
export type Attachment = FileUpload | Template | URL;
|
|
245
|
-
export interface URL {
|
|
246
|
-
type: "url";
|
|
247
|
-
value: string;
|
|
248
|
-
}
|
|
249
|
-
export interface FileUpload {
|
|
250
|
-
type: "upload";
|
|
251
|
-
contentType: string;
|
|
252
|
-
name: string;
|
|
253
|
-
dataUrl: string;
|
|
254
|
-
size: number;
|
|
255
|
-
id: string;
|
|
256
|
-
}
|
|
257
|
-
export interface Template {
|
|
258
|
-
type: "template";
|
|
259
|
-
name: string;
|
|
260
|
-
id: number;
|
|
261
|
-
}
|
package/src/messages.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function getContentText(message) {
|
|
2
|
-
if (typeof message === "string") {
|
|
3
|
-
return message;
|
|
4
|
-
}
|
|
5
|
-
return message
|
|
6
|
-
.map((item) => (item.type === "text" ? item.text : ""))
|
|
7
|
-
.join("");
|
|
8
|
-
}
|
|
9
|
-
export function getContentAttachments(message) {
|
|
10
|
-
if (typeof message === "string") {
|
|
11
|
-
return [];
|
|
12
|
-
}
|
|
13
|
-
return message
|
|
14
|
-
.filter((item) => item.type === "image")
|
|
15
|
-
.map((item) => item.source);
|
|
16
|
-
}
|
package/src/settings.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export interface AssistantSettings {
|
|
2
|
-
assistantType?: string;
|
|
3
|
-
viewId?: string;
|
|
4
|
-
theme?: "dark" | "light";
|
|
5
|
-
}
|
|
6
|
-
interface IframeSettings extends Partial<AssistantSettings> {
|
|
7
|
-
local?: boolean;
|
|
8
|
-
/**
|
|
9
|
-
* The URL of the assistant.
|
|
10
|
-
*/
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
}
|
|
13
|
-
export declare function getAssistantUrl(opts?: IframeSettings): string;
|
|
14
|
-
export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
|
|
15
|
-
export interface BuilderEditorAuth {
|
|
16
|
-
spaceId: string;
|
|
17
|
-
userId: string;
|
|
18
|
-
authToken: string;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/src/settings.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const urlParamSettings = [
|
|
2
|
-
"assistantType",
|
|
3
|
-
"theme",
|
|
4
|
-
"viewId",
|
|
5
|
-
];
|
|
6
|
-
export function getAssistantUrl(opts = {}) {
|
|
7
|
-
var _a;
|
|
8
|
-
const url = new URL((_a = opts.baseUrl) !== null && _a !== void 0 ? _a : (opts.local ? "http://localhost:7242" : "https://assistant.builder.io"));
|
|
9
|
-
urlParamSettings.forEach((key) => {
|
|
10
|
-
const value = opts[key];
|
|
11
|
-
if (typeof value === "string" || typeof value === "boolean") {
|
|
12
|
-
url.searchParams.set(key, String(value));
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
return url.href;
|
|
16
|
-
}
|
|
17
|
-
export function parseAssistantUrlSettings(url) {
|
|
18
|
-
const parsed = new URL(url);
|
|
19
|
-
const settings = {};
|
|
20
|
-
urlParamSettings.forEach((key) => {
|
|
21
|
-
const value = parsed.searchParams.get(key);
|
|
22
|
-
if (value === "true" || value === "false") {
|
|
23
|
-
settings[key] = value === "true";
|
|
24
|
-
}
|
|
25
|
-
else if (value) {
|
|
26
|
-
settings[key] = value;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
return settings;
|
|
30
|
-
}
|
|
File without changes
|