@builder.io/ai-utils 0.3.23 → 0.4.1

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/src/mapping.ts DELETED
@@ -1,98 +0,0 @@
1
- import type { ESMImport } from "./codegen";
2
-
3
- export interface RawFigmaJson {
4
- documents: any[];
5
- document?: any;
6
- components?: Record<string, any>;
7
- styles?: Record<string, any>;
8
- componentSets?: Record<string, any>;
9
- schemaVersion?: number;
10
- }
11
-
12
- export interface UserContext {
13
- client: string;
14
- clientVersion: string;
15
- nodeVersion: string;
16
- systemPlatform: string;
17
- frameworks: string[];
18
- systemEOL: string;
19
- systemArch: string;
20
- systemShell?: string;
21
- inGitRepo?: boolean;
22
- [key: string]: string | string[] | boolean | undefined;
23
- }
24
-
25
- export type ExportType = "default" | "named";
26
-
27
- /**
28
- * Gets the latest component mappings for a space
29
- */
30
- export interface FigmaMappingsData {
31
- id: string;
32
- figmaBuilderLinks: FigmaBuilderLink[];
33
- framework: string;
34
- version?: number;
35
- createdDate?: string; // ISO string timestamp or unix timestamp
36
- local: boolean;
37
- userEmail?: string;
38
- remoteUrl?: string;
39
- }
40
-
41
- export interface FigmaBuilderLink {
42
- builderName: string;
43
- figmaName: string;
44
- figmaKey: string;
45
- figmaUrl?: string;
46
- inputMapper?: string;
47
- originalInputMapper?: string;
48
- exportType?: ExportType;
49
- importName?: string;
50
- importPath?: string;
51
- source: string;
52
- loc?: string;
53
- imports?: ESMImport[];
54
- }
55
-
56
- export interface FigmaMapperFile {
57
- filePath: string;
58
- content: string;
59
- }
60
-
61
- export interface PublishedMapping {
62
- figmaBuilderLinks: FigmaBuilderLink[];
63
- mapperFiles: FigmaMapperFile[];
64
-
65
- // Meta data
66
- remoteUrl?: string;
67
- defaultBranch?: string;
68
- currentBranch?: string;
69
- commit?: string;
70
- spaceKind?: string;
71
-
72
- userContext?: UserContext;
73
- }
74
-
75
- export interface FigmaComponentInfo {
76
- documentName: string;
77
- key: string;
78
- tree?: string;
79
- jsx?: string;
80
- type: string;
81
- name: string;
82
- exportJson?: any;
83
- inputs: FigmaComponentInput[];
84
- description: string;
85
- documentationLinks: string[];
86
- instanceId: string;
87
- }
88
-
89
- export interface FigmaComponentInput {
90
- id: string;
91
- name: string;
92
- value?: any;
93
- type: string;
94
- baseType: "text" | "variant" | "boolean" | "slot";
95
- variantOptions?: string[];
96
- isDefault: boolean;
97
- ref?: string;
98
- }
package/src/messages.ts DELETED
@@ -1,393 +0,0 @@
1
- import type { ContentUpdatePatch } from "./events.js";
2
-
3
- /**
4
- * Message param does not know the id of the message.
5
- * This is an input message.
6
- */
7
- export type MessageParam =
8
- | SystemMessageParam
9
- | UserMessageParam
10
- | AssistantMessageParam;
11
-
12
- export interface ContentMessageItemText {
13
- type: "text";
14
- text: string;
15
- cache?: boolean;
16
- citations?: TextCitationParam[] | null;
17
- ephemeral?: boolean;
18
- }
19
-
20
- export interface ContentMessageItemImage {
21
- type: "image";
22
- source: ImageBase64Source | ImageUrlSource;
23
- cache?: boolean;
24
- ephemeral?: boolean;
25
- }
26
-
27
- export interface ContentMessageItemDocument {
28
- type: "document";
29
- source: DocumentBase64Source | DocumentUrlSource;
30
- cache?: boolean;
31
- ephemeral?: boolean;
32
- }
33
-
34
- export interface DocumentBase64Source {
35
- type: "base64";
36
- media_type: "application/pdf";
37
- data: string;
38
- }
39
-
40
- export interface DocumentUrlSource {
41
- type: "url";
42
- url: string;
43
- }
44
-
45
- export interface ContentMessageItemToolResult {
46
- type: "tool_result";
47
- tool_use_id: string;
48
- tool_name?: string;
49
- tool_input?: string;
50
- title?: string;
51
- content: string | (ContentMessageItemText | ContentMessageItemImage)[];
52
- is_error?: boolean;
53
- cache?: boolean;
54
- ephemeral?: boolean;
55
- }
56
-
57
- export interface ImageBase64Source {
58
- type: "base64";
59
- media_type: "image/webp" | "image/png" | "image/jpeg" | "image/gif";
60
- data: string;
61
- }
62
-
63
- export interface ImageUrlSource {
64
- type: "url";
65
- url: string;
66
- }
67
-
68
- export interface ContentMessageItemThinking {
69
- type: "thinking";
70
- thinking: string;
71
- signature: string;
72
- }
73
-
74
- export interface ContentMessageItemRedactedThinking {
75
- type: "redacted_thinking";
76
- data: string;
77
- }
78
-
79
- export interface ContentMessageItemToolUse {
80
- type: "tool_use";
81
- id: string;
82
- input: unknown;
83
- completion?: string;
84
- name: string;
85
- }
86
-
87
- export interface CitationCharLocationParam {
88
- cited_text: string;
89
-
90
- document_index: number;
91
-
92
- document_title: string | null;
93
-
94
- end_char_index: number;
95
-
96
- start_char_index: number;
97
-
98
- type: "char_location";
99
- }
100
-
101
- export interface CitationContentBlockLocationParam {
102
- cited_text: string;
103
-
104
- document_index: number;
105
-
106
- document_title: string | null;
107
-
108
- end_block_index: number;
109
-
110
- start_block_index: number;
111
-
112
- type: "content_block_location";
113
- }
114
-
115
- export interface CitationPageLocationParam {
116
- cited_text: string;
117
-
118
- document_index: number;
119
-
120
- document_title: string | null;
121
-
122
- end_page_number: number;
123
-
124
- start_page_number: number;
125
-
126
- type: "page_location";
127
- }
128
-
129
- export interface CitationWebSearchResultLocationParam {
130
- cited_text: string;
131
-
132
- encrypted_index: string;
133
-
134
- title: string | null;
135
-
136
- type: "web_search_result_location";
137
-
138
- url: string;
139
- }
140
-
141
- export type TextCitationParam =
142
- | CitationCharLocationParam
143
- | CitationPageLocationParam
144
- | CitationContentBlockLocationParam
145
- | CitationWebSearchResultLocationParam;
146
-
147
- export interface ServerToolUseContent {
148
- type: "web_search_result";
149
- title: string;
150
- url: string;
151
- page_age: string | null;
152
- encrypted_content: string;
153
- }
154
-
155
- export interface ServerToolUseContentError {
156
- error_code:
157
- | "invalid_tool_input"
158
- | "unavailable"
159
- | "max_uses_exceeded"
160
- | "too_many_requests"
161
- | "query_too_long";
162
-
163
- type: "web_search_tool_result_error";
164
- }
165
-
166
- export type ServerToolUseContentUnion =
167
- | ServerToolUseContent[]
168
- | ServerToolUseContentError;
169
-
170
- export interface ContentMessageItemServerToolUse {
171
- type: "server_tool_use";
172
- id: string;
173
- name: "web_search" | "code_execution";
174
- input: unknown;
175
- completion?: string;
176
- content?: any;
177
- cache?: boolean;
178
- }
179
-
180
- export interface MCPServerURLDefinition {
181
- name: string;
182
-
183
- type: "url";
184
-
185
- url: string;
186
-
187
- authorization_token?: string | null;
188
-
189
- tool_configuration?: MCPServerToolConfiguration | null;
190
- }
191
-
192
- export interface MCPServerToolConfiguration {
193
- allowed_tools?: Array<string> | null;
194
-
195
- enabled?: boolean | null;
196
- }
197
-
198
- export interface ContentMessageItemWebSearchToolResult {
199
- content: ServerToolUseContent[] | ServerToolUseContentError;
200
- tool_use_id: string;
201
- type: "web_search_tool_result";
202
- cache?: boolean;
203
- }
204
-
205
- export interface ContentMessageItemMCPToolUse {
206
- type: "mcp_tool_use";
207
- id: string;
208
- name: string;
209
- input: unknown;
210
- server_name: string;
211
- cache?: boolean;
212
- }
213
-
214
- export interface ContentMessageItemContainerUpload {
215
- type: "container_upload";
216
- file_id: string;
217
- }
218
-
219
- export interface ContentMessageItemMCPToolResult {
220
- type: "mcp_tool_result";
221
- tool_use_id: string;
222
- content: string | ContentMessageItemText[];
223
- is_error: boolean;
224
- cache?: boolean;
225
- }
226
-
227
- export interface ContentMessageItemCodeExecutionToolResult {
228
- type: "code_execution_tool_result";
229
- tool_use_id: string;
230
- content: any;
231
- cache?: boolean;
232
- }
233
-
234
- export type ContentMessageItem =
235
- | ContentMessageItemText
236
- | ContentMessageItemImage
237
- | ContentMessageItemDocument
238
- | ContentMessageItemThinking
239
- | ContentMessageItemRedactedThinking
240
- | ContentMessageItemToolUse
241
- | ContentMessageItemToolResult
242
- | ContentMessageItemWebSearchToolResult
243
- | ContentMessageItemServerToolUse
244
- | ContentMessageItemMCPToolUse
245
- | ContentMessageItemMCPToolResult
246
- | ContentMessageItemContainerUpload
247
- | ContentMessageItemCodeExecutionToolResult;
248
-
249
- export type ContentMessage = ContentMessageItem[];
250
-
251
- export interface SystemMessageParam {
252
- /**
253
- * The contents of the system message.
254
- */
255
- content: string | ContentMessageItemText[];
256
-
257
- // an id to track messages across a response including multiple retries
258
- responseId?: string;
259
-
260
- /**
261
- * The role of the messages author, in this case `system`.
262
- */
263
- role: "system";
264
-
265
- id?: string;
266
- }
267
-
268
- export interface UserMessageParam {
269
- /**
270
- * The contents of the user message.
271
- */
272
- content:
273
- | string
274
- | (
275
- | ContentMessageItemText
276
- | ContentMessageItemImage
277
- | ContentMessageItemDocument
278
- | ContentMessageItemToolResult
279
- )[];
280
-
281
- // an id to track messages across a response including multiple retries
282
- responseId?: string;
283
-
284
- /**
285
- * The role of the messages author, in this case `user`.
286
- */
287
- role: "user";
288
- id?: string;
289
- }
290
-
291
- export type AssistantMessageAction = "new-chat";
292
-
293
- export interface AssistantMessageParam {
294
- /**
295
- * The contents of the assistant message.
296
- */
297
- content: string | ContentMessageItem[];
298
- /**
299
- * The role of the messages author, in this case `assistant`.
300
- */
301
- role: "assistant";
302
-
303
- // an id to track messages across a response including multiple retries
304
- responseId?: string;
305
- id?: string;
306
- skipDelta?: boolean;
307
- /**
308
- * A summary of the patches which the assistant has made.
309
- * Useful for genai.
310
- */
311
- patches?: ContentUpdatePatch[];
312
- state?: "error";
313
- /**
314
- * Any actions associated with the error such as a "new chat" button.
315
- * typically used when there is an error.
316
- */
317
- actions?: AssistantMessageAction[];
318
- }
319
-
320
- export interface SystemMessage extends SystemMessageParam {
321
- id: string;
322
- }
323
-
324
- export interface UserMessage extends UserMessageParam {
325
- id: string;
326
- }
327
-
328
- export interface AssistantMessage extends AssistantMessageParam {
329
- id: string;
330
- status?: "accepted" | "rejected" | "aborted";
331
- // Optional summary from the LLM that explains why it did
332
- summary?: string;
333
- }
334
-
335
- export interface AssistantActionMessage {
336
- /**
337
- * The role of the messages author, in this case `assistant`.
338
- */
339
- role: "assistant";
340
-
341
- id: string;
342
- }
343
-
344
- /**
345
- * Message DOES know the id of the message.
346
- * This message is after an id has been assigned
347
- * and is the output message.
348
- */
349
- export type Message = SystemMessage | UserMessage | AssistantMessage;
350
-
351
- export type GeneratingMessage = null | Partial<
352
- AssistantActionMessage | AssistantMessage
353
- >;
354
-
355
- export function getContentText(message: string | ContentMessage) {
356
- if (typeof message === "string") {
357
- return message;
358
- }
359
- return message
360
- .map((item) => (item.type === "text" ? item.text : ""))
361
- .join("");
362
- }
363
-
364
- export function getContentAttachments(message: string | ContentMessage) {
365
- if (typeof message === "string") {
366
- return [];
367
- }
368
- return message
369
- .filter((item) => item.type === "image")
370
- .map((item) => item.source);
371
- }
372
-
373
- export type Attachment = FileUpload | Template | URL;
374
-
375
- export interface URL {
376
- type: "url";
377
- value: string;
378
- }
379
-
380
- export interface FileUpload {
381
- type: "upload";
382
- contentType: string;
383
- name: string;
384
- dataUrl: string;
385
- size: number;
386
- id: string;
387
- }
388
-
389
- export interface Template {
390
- type: "template";
391
- name: string;
392
- id: number;
393
- }
package/src/settings.ts DELETED
@@ -1,59 +0,0 @@
1
- export interface AssistantSettings {
2
- assistantType?: string;
3
- viewId?: string;
4
- theme?: "dark" | "light";
5
- }
6
-
7
- interface IframeSettings extends Partial<AssistantSettings> {
8
- local?: boolean;
9
- /**
10
- * The URL of the assistant.
11
- */
12
- baseUrl?: string;
13
- }
14
-
15
- type AssistantSettingsKeys = keyof AssistantSettings;
16
-
17
- const urlParamSettings: AssistantSettingsKeys[] = [
18
- "assistantType",
19
- "theme",
20
- "viewId",
21
- ];
22
-
23
- export function getAssistantUrl(opts: IframeSettings = {}) {
24
- const url = new URL(
25
- opts.baseUrl ??
26
- (opts.local ? "http://localhost:7242" : "https://assistant.builder.io"),
27
- );
28
-
29
- urlParamSettings.forEach((key) => {
30
- const value = opts[key];
31
- if (typeof value === "string" || typeof value === "boolean") {
32
- url.searchParams.set(key, String(value));
33
- }
34
- });
35
-
36
- return url.href;
37
- }
38
-
39
- export function parseAssistantUrlSettings(url: string) {
40
- const parsed = new URL(url);
41
- const settings: Record<string, string | boolean> = {};
42
-
43
- urlParamSettings.forEach((key) => {
44
- const value = parsed.searchParams.get(key);
45
- if (value === "true" || value === "false") {
46
- settings[key] = value === "true";
47
- } else if (value) {
48
- settings[key] = value;
49
- }
50
- });
51
-
52
- return settings as Partial<AssistantSettings>;
53
- }
54
-
55
- export interface BuilderEditorAuth {
56
- spaceId: string;
57
- userId: string;
58
- authToken: string;
59
- }
File without changes