@builder.io/ai-utils 0.3.5 → 0.3.7

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/events.d.ts DELETED
@@ -1,369 +0,0 @@
1
- import type { BuilderContent, BuilderElement } from "@builder.io/sdk";
2
- import type { AssistantMessage } from "./messages.js";
3
- import type { AssistantSettings } from "./settings.js";
4
- export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
5
- export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptSubmitEvent | AppReadyEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | AssistantThemeEvent | BuilderEditorAuthEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelUndoEvent | ModelRedoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageCompletedEvent | ThreadMessageCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageFeedbackEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent | AppAcceptChangeEvent | AppAcceptRejectEvent | AssistantTrackEvent | AssistantEditorAuthMessage | AppAttachmentTemplateEvent | ThreadMessageRetryEvent | AppFigmaImportEvent | AppWebImportEvent | AppAiTemplatesEvent | AssistantContentInitialEvent | ThreadMessageSummaryEvent | AssistantHeartbeatEvent | ShowUpgradeDialogEvent;
6
- export interface AssistantCompletionResultEvent {
7
- type: "assistant.result";
8
- data: {
9
- content?: BuilderContent;
10
- stats?: AssistantStats;
11
- };
12
- resolveId?: string;
13
- }
14
- export interface AssistantError {
15
- message: string;
16
- status?: number;
17
- }
18
- export interface AssistantErrorEvent {
19
- type: "assistant.error";
20
- data: AssistantError;
21
- }
22
- export interface AssistantStreamErrorEvent {
23
- type: "assistant.stream.error";
24
- data: AssistantError;
25
- }
26
- export interface AppFigmaImportEvent {
27
- type: "assistant.app.figmaImport";
28
- }
29
- export interface AppWebImportEvent {
30
- type: "assistant.app.webImport";
31
- }
32
- export interface AppAiTemplatesEvent {
33
- type: "assistant.app.aiTemplates";
34
- }
35
- export interface AssistantTrackEvent {
36
- type: "assistant.track";
37
- data: {
38
- name: string;
39
- properties: Record<string, any>;
40
- };
41
- }
42
- export interface AssistantThemeEvent {
43
- type: "assistant.app.theme.update";
44
- data: {
45
- theme: string;
46
- };
47
- }
48
- export interface AppCloseEvent {
49
- type: "assistant.app.close";
50
- }
51
- export interface AppMessagesClickEvent {
52
- type: "assistant.app.messages.click";
53
- }
54
- export interface ShowUpgradeDialogEvent {
55
- type: "assistant.app.showUpgradeDialog";
56
- }
57
- export interface AppAcceptChangeEvent {
58
- type: "assistant.app.change.accept";
59
- }
60
- export interface AppAcceptRejectEvent {
61
- type: "assistant.app.change.reject";
62
- }
63
- export interface AppMessageEditCustomInstructionsEvent {
64
- type: "assistant.app.messages.editCustomInstructions";
65
- }
66
- export interface AppAttachmentTemplateEvent {
67
- type: "assistant.app.attachment.template";
68
- data: {
69
- id: number;
70
- name: string;
71
- };
72
- }
73
- export interface AppMessagesGenerationEvent {
74
- type: "assistant.app.messages.generation";
75
- data: {
76
- state: GenerationState;
77
- };
78
- }
79
- /**
80
- * idle: no messages are being generated or queued to be generated
81
- *
82
- * queued: messages have been sent to the LLM, but no response has been received yet
83
- *
84
- * generating: messages are actively being generated and streaming back to the UI
85
- */
86
- export type GenerationState = "idle" | "queued" | "generating";
87
- export interface AppPromptAbortEvent {
88
- type: "assistant.app.prompt.abort";
89
- }
90
- export interface AppPromptFocusEvent {
91
- type: "assistant.app.prompt.focus";
92
- }
93
- export interface AppPromptSubmitEvent {
94
- type: "assistant.app.prompt.submit";
95
- data: {
96
- prompt: string;
97
- attachments: any[];
98
- };
99
- }
100
- export interface AppReadyEvent {
101
- type: "assistant.app.ready";
102
- }
103
- export interface AppSettingsSetEvent {
104
- type: "assistant.app.settings.set";
105
- data: Partial<AssistantSettings>;
106
- }
107
- export interface AppThreadNewEvent {
108
- type: "assistant.app.thread.new";
109
- }
110
- export interface AssistantEditorAuthMessage {
111
- type: "assistant.editor.auth.update";
112
- }
113
- export interface BuilderEditorAuthEvent extends AwaitResultEvent {
114
- type: "assistant.editor.auth";
115
- }
116
- export interface BuilderEditorStateEvent extends AwaitResultEvent {
117
- type: "assistant.editor.state";
118
- }
119
- export interface AwaitResultEvent {
120
- resolveId?: string;
121
- }
122
- export interface ResultEvent {
123
- type: "assistant.result";
124
- resolveId: string;
125
- data: any;
126
- }
127
- export interface ContentCreatePatch {
128
- parentId: string;
129
- insertBeforeId: string;
130
- element: BuilderElement;
131
- }
132
- export interface ContentApplySnapshot {
133
- /**
134
- * The id of the BuilderContent to apply the snapshot to
135
- */
136
- id: string;
137
- /**
138
- * Each snapshot can be either a full BuilderContent or individual BuilderElements.
139
- * Order matters, as the snapshots will be applied in the order they are listed.
140
- * The builder app will handle the logic of applying the snapshots in the correct order
141
- * and to the right content/elements.
142
- */
143
- snapshots: (BuilderElement | BuilderContent)[];
144
- }
145
- export interface ContentApplySnapshotEvent {
146
- type: "assistant.content.applysnapshot";
147
- data: ContentApplySnapshot;
148
- }
149
- export interface ContentUpdateEvent {
150
- type: "assistant.content.update";
151
- data: ContentUpdatePatch[];
152
- }
153
- export type ContentUpdatePatch = ContentTsUpdateComponentPatch;
154
- interface ContentPatchBase {
155
- id: string;
156
- nodeId?: string;
157
- builderId?: string;
158
- description?: string;
159
- value: string;
160
- displayValue?: string;
161
- ts: number;
162
- /**
163
- * A change value is considered incomplete until we also parsed it's closing xml tag.
164
- */
165
- incomplete?: boolean;
166
- /**
167
- * If there was an error applying the patch, this will contain the error message.
168
- */
169
- error?: string;
170
- }
171
- export interface ContentTsUpdateComponentPatch extends ContentPatchBase {
172
- type: "update_component";
173
- }
174
- export interface AssistantStatsEvent {
175
- type: "assistant.stats";
176
- data: AssistantStats;
177
- }
178
- export interface AssistantStats {
179
- /**
180
- * The unique id of the thread (not the openai threadId)
181
- */
182
- threadId: string;
183
- /**
184
- * The unique id of the completion, which is a combination of the user's prompt and assistant's response.
185
- */
186
- completionId: string;
187
- /**
188
- * The model id used to generate this completion.
189
- */
190
- modelId: string;
191
- /**
192
- * The assistant's response message.
193
- */
194
- assistantMessage: string;
195
- /**
196
- * The assistant's summary of what it did. This appears after assistantMessage
197
- * as well as any changes it made.
198
- */
199
- assistantSummary: string;
200
- /**
201
- * The user's prompt message.
202
- */
203
- userMessage: string;
204
- /**
205
- * The index within the thread the assistant message is.
206
- * For a first assistant message, the index will be 1 (the user message is index 0).
207
- * For a second assistant message, the index will be 3 (the user message is index 2), and so on.
208
- */
209
- assistantMessageIndex: number;
210
- /**
211
- * The timestamp (Date.now()) of when the user first submitted their prompt.
212
- */
213
- userPromptMs: number;
214
- /**
215
- * The timestamp of the first assistant chunk in the response.
216
- */
217
- firstChunkMs: number;
218
- /**
219
- * The timestamp of the last assistant chunk in the response.
220
- */
221
- lastChunkMs: number;
222
- /**
223
- * The total number of chunks in the assistant's streamed response.
224
- */
225
- chunkCount: number;
226
- /**
227
- * The total number of characters in the generated prompt sent to the LLM.
228
- */
229
- promptLength: number;
230
- /**
231
- * The total number of characters in the assistant's response.
232
- */
233
- completionLength: number;
234
- /**
235
- * If the user provided custom instructions for the prompt.
236
- */
237
- hasCustomInstructions: boolean;
238
- /**
239
- * The deployed version.
240
- */
241
- version: string;
242
- /**
243
- * Error message if there was one.
244
- */
245
- errorMessage?: string;
246
- /**
247
- * Input tokens
248
- */
249
- inputTokens?: number;
250
- /**
251
- * Output tokens
252
- */
253
- outputTokens?: number;
254
- /**
255
- * Output tokens
256
- */
257
- completionCost?: number;
258
- /**
259
- * Number of streamed snapshots
260
- */
261
- streamedSnapshots?: number;
262
- /**
263
- * Number of cached input tokens
264
- */
265
- cacheInputTokens?: number;
266
- /**
267
- * Number of cached created tokens
268
- */
269
- cacheCreatedTokens?: number;
270
- }
271
- export interface ModelUndoEvent {
272
- type: "assistant.model.undo";
273
- }
274
- export interface ModelRedoEvent {
275
- type: "assistant.model.redo";
276
- }
277
- export interface BuilderModel {
278
- name?: string;
279
- friendlyName?: string;
280
- description?: string;
281
- type?: string;
282
- fields?: BuilderModelField[];
283
- }
284
- export interface BuilderModelField {
285
- name?: string;
286
- type?: string;
287
- description?: string;
288
- }
289
- export interface ThreadMessageFeedbackEvent {
290
- type: "assistant.thread.message.feedback";
291
- data: CompletionResponseFeedback;
292
- }
293
- export interface CompletionResponseFeedback {
294
- userId: string;
295
- builderUserId?: string;
296
- builderEmail?: string;
297
- responseId?: string;
298
- frontendUrl: string | undefined;
299
- frontendCommitId: string | undefined;
300
- backendDomain?: string;
301
- backendCommitId: string | undefined;
302
- feedbackText: string;
303
- sentiment?: "positive" | "negative";
304
- }
305
- export interface ThreadCreatedEvent {
306
- type: "assistant.thread.created";
307
- data: ThreadCreated;
308
- }
309
- export interface ThreadCreated {
310
- platformId: string;
311
- threadId: string;
312
- vectorStoreId: string;
313
- }
314
- export interface ThreadMessageCreatedEvent {
315
- type: "assistant.thread.message.created";
316
- data: ThreadMessageCreated;
317
- }
318
- export interface ThreadMessageCreated {
319
- id: string;
320
- responseId: string;
321
- threadId: string;
322
- }
323
- export interface ThreadMessageDeltaEvent {
324
- type: "assistant.thread.message.delta";
325
- data: ThreadMessageDelta;
326
- }
327
- export interface AssistantHeartbeatEvent {
328
- type: "assistant.heartbeat";
329
- }
330
- export interface ThreadMessageDelta {
331
- id: string;
332
- text: string;
333
- }
334
- export interface ThreadMessageCompletedEvent {
335
- type: "assistant.thread.message.completed";
336
- data: ThreadMessageCompleted;
337
- }
338
- export interface ThreadMessageRetryEvent {
339
- type: "assistant.thread.message.retry";
340
- }
341
- export interface ThreadMessageSummaryEvent {
342
- type: "assistant.thread.message.summary.delta";
343
- data: ThreadMessageDelta;
344
- }
345
- export interface ThreadMessageCompleted extends AssistantMessage {
346
- platformId: string;
347
- threadId: string;
348
- commitId?: string;
349
- }
350
- export interface ThreadRunStepDeltaEvent {
351
- type: "assistant.thread.run.step.delta";
352
- data: ThreadMessageStepDelta;
353
- }
354
- export interface ThreadMessageStepDelta {
355
- delta: any;
356
- }
357
- export interface ThreadRunStepCreatedEvent {
358
- type: "assistant.thread.run.step.created";
359
- }
360
- export type DeepPartial<T> = T extends object ? {
361
- [P in keyof T]?: DeepPartial<T[P]>;
362
- } : T;
363
- export interface AssistantContentInitialEvent {
364
- type: "assistant.content.initial";
365
- data: {
366
- code: string;
367
- };
368
- }
369
- export {};
package/src/events.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- export * from "./completion.js";
2
- export * from "./events.js";
3
- export * from "./messages.js";
4
- export * from "./settings.js";
5
- export * from "./mapping.js";
6
- export * from "./codegen.js";
package/src/mapping.d.ts DELETED
@@ -1,86 +0,0 @@
1
- import type { ESMImport } from "./codegen";
2
- export interface RawFigmaJson {
3
- documents: any[];
4
- document?: any;
5
- components?: Record<string, any>;
6
- styles?: Record<string, any>;
7
- componentSets?: Record<string, any>;
8
- schemaVersion?: number;
9
- }
10
- export interface UserContext {
11
- client: string;
12
- clientVersion: string;
13
- nodeVersion: string;
14
- systemPlatform: string;
15
- frameworks: string[];
16
- systemEOL: string;
17
- systemArch: string;
18
- systemShell?: string;
19
- inGitRepo?: boolean;
20
- [key: string]: string | string[] | boolean | undefined;
21
- }
22
- export type ExportType = "default" | "named";
23
- /**
24
- * Gets the latest component mappings for a space
25
- */
26
- export interface FigmaMappingsData {
27
- id: string;
28
- figmaBuilderLinks: FigmaBuilderLink[];
29
- framework: string;
30
- version?: number;
31
- createdDate?: string;
32
- local: boolean;
33
- userEmail?: string;
34
- remoteUrl?: string;
35
- }
36
- export interface FigmaBuilderLink {
37
- builderName: string;
38
- figmaName: string;
39
- figmaKey: string;
40
- figmaUrl?: string;
41
- inputMapper?: string;
42
- originalInputMapper?: string;
43
- exportType?: ExportType;
44
- importName?: string;
45
- importPath?: string;
46
- source: string;
47
- loc?: string;
48
- imports?: ESMImport[];
49
- }
50
- export interface FigmaMapperFile {
51
- filePath: string;
52
- content: string;
53
- }
54
- export interface PublishedMapping {
55
- figmaBuilderLinks: FigmaBuilderLink[];
56
- mapperFiles: FigmaMapperFile[];
57
- remoteUrl?: string;
58
- defaultBranch?: string;
59
- currentBranch?: string;
60
- commit?: string;
61
- spaceKind?: string;
62
- userContext?: UserContext;
63
- }
64
- export interface FigmaComponentInfo {
65
- documentName: string;
66
- key: string;
67
- tree?: string;
68
- jsx?: string;
69
- type: string;
70
- name: string;
71
- exportJson?: any;
72
- inputs: FigmaComponentInput[];
73
- description: string;
74
- documentationLinks: string[];
75
- instanceId: string;
76
- }
77
- export interface FigmaComponentInput {
78
- id: string;
79
- name: string;
80
- value?: any;
81
- type: string;
82
- baseType: "text" | "variant" | "boolean" | "slot";
83
- variantOptions?: string[];
84
- isDefault: boolean;
85
- ref?: string;
86
- }
package/src/mapping.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/src/messages.d.ts DELETED
@@ -1,170 +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
- ephemeral?: boolean;
12
- }
13
- export interface ContentMessageItemImage {
14
- type: "image";
15
- source: ImageBase64Source | ImageUrlSource;
16
- cache?: boolean;
17
- ephemeral?: boolean;
18
- }
19
- export interface ContentMessageItemDocument {
20
- type: "document";
21
- source: DocumentBase64Source | DocumentUrlSource;
22
- cache?: boolean;
23
- ephemeral?: boolean;
24
- }
25
- export interface DocumentBase64Source {
26
- type: "base64";
27
- media_type: "application/pdf";
28
- data: string;
29
- }
30
- export interface DocumentUrlSource {
31
- type: "url";
32
- url: string;
33
- }
34
- export interface ContentMessageItemToolResult {
35
- type: "tool_result";
36
- tool_use_id: string;
37
- tool_name?: string;
38
- tool_input?: string;
39
- title?: string;
40
- content: string;
41
- is_error: boolean;
42
- cache?: boolean;
43
- ephemeral?: boolean;
44
- }
45
- export interface ImageBase64Source {
46
- type: "base64";
47
- media_type: "image/webp" | "image/png" | "image/jpeg";
48
- data: string;
49
- }
50
- export interface ImageUrlSource {
51
- type: "url";
52
- url: string;
53
- }
54
- export interface ContentMessageItemThinking {
55
- type: "thinking";
56
- thinking: string;
57
- signature: string;
58
- }
59
- export interface ContentMessageItemRedactedThinking {
60
- type: "redacted_thinking";
61
- data: string;
62
- }
63
- export interface ContentMessageItemToolUse {
64
- type: "tool_use";
65
- id: string;
66
- input: unknown;
67
- completion?: string;
68
- name: string;
69
- }
70
- export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult;
71
- export type ContentMessage = ContentMessageItem[];
72
- export interface SystemMessageParam {
73
- /**
74
- * The contents of the system message.
75
- */
76
- content: string | ContentMessageItemText[];
77
- responseId?: string;
78
- /**
79
- * The role of the messages author, in this case `system`.
80
- */
81
- role: "system";
82
- id?: string;
83
- }
84
- export interface UserMessageParam {
85
- /**
86
- * The contents of the user message.
87
- */
88
- content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemDocument | ContentMessageItemToolResult)[];
89
- responseId?: string;
90
- /**
91
- * The role of the messages author, in this case `user`.
92
- */
93
- role: "user";
94
- id?: string;
95
- }
96
- export interface AssistantMessageParam {
97
- /**
98
- * The contents of the assistant message.
99
- */
100
- content: string | ContentMessageItem[];
101
- /**
102
- * The role of the messages author, in this case `assistant`.
103
- */
104
- role: "assistant";
105
- responseId?: string;
106
- /**
107
- * The function call name and arguments
108
- */
109
- action?: {
110
- /**
111
- * The specific function name
112
- */
113
- name: string;
114
- /** This is arbitrary JSON */
115
- arguments: any;
116
- };
117
- id?: string;
118
- skipDelta?: boolean;
119
- /**
120
- * A summary of the patches which the assistant has made.
121
- * Useful for genai.
122
- */
123
- patches?: ContentUpdatePatch[];
124
- state?: "error";
125
- }
126
- export interface SystemMessage extends SystemMessageParam {
127
- id: string;
128
- }
129
- export interface UserMessage extends UserMessageParam {
130
- id: string;
131
- }
132
- export interface AssistantMessage extends AssistantMessageParam {
133
- id: string;
134
- status?: "accepted" | "rejected" | "aborted";
135
- summary?: string;
136
- }
137
- export interface AssistantActionMessage {
138
- /**
139
- * The role of the messages author, in this case `assistant`.
140
- */
141
- role: "assistant";
142
- id: string;
143
- }
144
- /**
145
- * Message DOES know the id of the message.
146
- * This message is after an id has been assigned
147
- * and is the output message.
148
- */
149
- export type Message = SystemMessage | UserMessage | AssistantMessage;
150
- export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
151
- export declare function getContentText(message: string | ContentMessage): string;
152
- export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
153
- export type Attachment = FileUpload | Template | URL;
154
- export interface URL {
155
- type: "url";
156
- value: string;
157
- }
158
- export interface FileUpload {
159
- type: "upload";
160
- contentType: string;
161
- name: string;
162
- dataUrl: string;
163
- size: number;
164
- id: string;
165
- }
166
- export interface Template {
167
- type: "template";
168
- name: string;
169
- id: number;
170
- }
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