@builder.io/ai-utils 0.0.69 → 0.0.71

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/package.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.0.69",
3
+ "version": "0.0.71",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "main": "src/index.js",
7
+ "types": "src/index.d.ts",
8
8
  "exports": {
9
9
  ".": {
10
- "import": "./dist/index.js",
11
- "types": "./dist/index.d.ts"
10
+ "import": "./src/index.js",
11
+ "types": "./src/index.d.ts"
12
12
  }
13
13
  },
14
14
  "files": [
15
- "dist"
16
- ],
17
- "dependencies": {
18
- "@builder.io/sdk": "^2.2.4"
19
- }
15
+ "src"
16
+ ]
20
17
  }
@@ -1,5 +1,5 @@
1
1
  import type { BuilderContent, BuilderElement, Component } from "@builder.io/sdk";
2
- import type { Message, MessageParam } from "./messages.js";
2
+ import type { Message, MessageParam, Attachment } from "./messages.js";
3
3
  import type { BuilderModel } from "./events.js";
4
4
  export type BuilderContentData = BuilderContent["data"];
5
5
  export type { BuilderContent, BuilderElement, Component };
@@ -85,6 +85,7 @@ export interface CompletionOptions {
85
85
  * Defaults to `persist`
86
86
  */
87
87
  thread?: "persist" | "ephemeral";
88
+ attachments?: Attachment[];
88
89
  }
89
90
  export interface BuilderEditorState {
90
91
  /**
@@ -158,4 +159,5 @@ export interface BuilderEditorState {
158
159
  export type BuiderEditorState = BuilderEditorState;
159
160
  export type OnPromptSubmit = (opts: {
160
161
  prompt?: string;
162
+ attachments: Attachment[];
161
163
  }) => void;
@@ -1,15 +1,15 @@
1
1
  import type { BuilderContent, BuilderElement } from "@builder.io/sdk";
2
- import type { Thread } from "./thread.js";
3
2
  import type { AssistantMessage } from "./messages.js";
4
- import { AssistantSettings } from "./settings.js";
3
+ import type { AssistantSettings } from "./settings.js";
5
4
  export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
6
- export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptTextEvent | AppReadyEvent | AppSettingsResetEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | BuilderEditorAuthEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelCreateEvent | ModelUpdateEvent | ModelUndoEvent | ModelRedoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageCompletedEvent | ThreadMessageCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageFeedbackEvent | ThreadRunRequiresActionEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent | AppAcceptChangeEvent | AppAcceptRejectEvent | AssistantTrackEvent | AssistantEditorAuthMessage;
5
+ export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppPromptTextEvent | AppReadyEvent | AppSettingsResetEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | BuilderEditorAuthEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelCreateEvent | ModelUpdateEvent | ModelUndoEvent | ModelRedoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageCompletedEvent | ThreadMessageCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageFeedbackEvent | ThreadRunRequiresActionEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent | AppAcceptChangeEvent | AppAcceptRejectEvent | AssistantTrackEvent | AssistantEditorAuthMessage | AppAttachmentTemplateEvent;
7
6
  export interface AssistantCompletionResultEvent {
8
7
  type: "assistant.result";
9
8
  data: {
10
9
  content?: BuilderContent;
11
10
  stats?: AssistantStats;
12
11
  };
12
+ resolveId?: string;
13
13
  }
14
14
  export interface AssistantError {
15
15
  message: string;
@@ -45,6 +45,13 @@ export interface AppAcceptRejectEvent {
45
45
  export interface AppMessageEditCustomInstructionsEvent {
46
46
  type: "assistant.app.messages.editCustomInstructions";
47
47
  }
48
+ export interface AppAttachmentTemplateEvent {
49
+ type: "assistant.app.attachment.template";
50
+ data: {
51
+ id: number;
52
+ name: string;
53
+ };
54
+ }
48
55
  export interface AppMessagesGenerationEvent {
49
56
  type: "assistant.app.messages.generation";
50
57
  data: {
@@ -127,27 +134,15 @@ export interface ContentUpdateEvent {
127
134
  type: "assistant.content.update";
128
135
  data: ContentUpdatePatch[];
129
136
  }
130
- export type ContentUpdatePatch = ContentTsCodePatch | ContentInsertBeforePatch | ContentInsertAfterPatch | ContentPropsUpdatePatch | ContentSetChildrenPatch | ContentStyleUpdatePatch | ContentDeletePatch | ContentSetStorePatch | ContentSetMountPatch | ContentMovePatch | ContentMoveAfterPatch | ContentMoveBeforePatch | ContentSetTagNamePatch;
131
- export interface NodeData {
132
- /**
133
- * When dealing with some builder nodes that contain virtual children like Columns, and PersonalizationContainer,
134
- * we need to store the virtual child index so we can properly add nodes inside one of the children if needed.
135
- */
136
- virtualChildIndex?: number;
137
- }
137
+ export type ContentUpdatePatch = ContentTsCodePatch | ContentInsertBeforePatch | ContentInsertAfterPatch | ContentPropsUpdatePatch | ContentSetChildrenPatch | ContentStyleUpdatePatch | ContentDeletePatch | ContentSetStorePatch | ContentSetMountPatch | ContentMovePatch | ContentMoveAfterPatch | ContentMoveBeforePatch | ContentSetTagNamePatch | ContentTsUpdateComponentPatch;
138
138
  interface ContentPatchBase {
139
139
  id: string;
140
+ nodeId?: string;
140
141
  builderId?: string;
141
142
  description?: string;
142
- index: number;
143
143
  value: string;
144
144
  displayValue?: string;
145
145
  ts: number;
146
- /**
147
- * Any additional data about the patch. For example, this payload could contain the
148
- * column index to update when dealing with a Columns component.
149
- */
150
- data?: NodeData;
151
146
  /**
152
147
  * A change value is considered incomplete until we also parsed it's closing xml tag.
153
148
  */
@@ -277,10 +272,22 @@ export interface AssistantStats {
277
272
  * Output tokens
278
273
  */
279
274
  outputTokens?: number;
275
+ /**
276
+ * Output tokens
277
+ */
278
+ completionCost?: number;
280
279
  /**
281
280
  * Number of streamed snapshots
282
281
  */
283
282
  streamedSnapshots?: number;
283
+ /**
284
+ * Number of cached input tokens
285
+ */
286
+ cacheInputTokens?: number;
287
+ /**
288
+ * Number of cached created tokens
289
+ */
290
+ cacheCreatedTokens?: number;
284
291
  }
285
292
  export interface ModelCreateEvent {
286
293
  type: "assistant.model.create";
@@ -318,25 +325,19 @@ export type ModelPatch = {
318
325
  };
319
326
  export interface ThreadMessageFeedbackEvent {
320
327
  type: "assistant.thread.message.feedback";
321
- data: ThreadMessageFeedback;
328
+ data: CompletionResponseFeedback;
322
329
  }
323
- export interface ThreadMessageFeedback {
324
- /**
325
- * Same as "id" of message
326
- */
327
- messageId: string;
330
+ export interface CompletionResponseFeedback {
328
331
  userId: string;
329
- commitId?: string;
330
- frontendDomain: string | undefined;
332
+ builderUserId?: string;
333
+ builderEmail?: string;
334
+ responseId?: string;
335
+ frontendUrl: string | undefined;
331
336
  frontendCommitId: string | undefined;
332
337
  backendDomain?: string;
333
338
  backendCommitId: string | undefined;
334
339
  feedbackText: string;
335
- thread: Thread;
336
- platformId: string;
337
340
  sentiment?: "positive" | "negative";
338
- builderUserId?: string;
339
- builderEmail?: string;
340
341
  }
341
342
  export interface ThreadCreatedEvent {
342
343
  type: "assistant.thread.created";
@@ -353,6 +354,7 @@ export interface ThreadMessageCreatedEvent {
353
354
  }
354
355
  export interface ThreadMessageCreated {
355
356
  id: string;
357
+ responseId: string;
356
358
  threadId: string;
357
359
  }
358
360
  export interface ThreadMessageDeltaEvent {
@@ -1,14 +1,47 @@
1
- import { ContentUpdatePatch } from "./events.js";
1
+ import type { ContentUpdatePatch } from "./events.js";
2
2
  /**
3
3
  * Message param does not know the id of the message.
4
4
  * This is an input message.
5
5
  */
6
6
  export type MessageParam = SystemMessageParam | UserMessageParam | AssistantMessageParam;
7
+ export interface ContentMessageItemText {
8
+ type: "text";
9
+ text: string;
10
+ cache?: boolean;
11
+ }
12
+ export interface ContentMessageItemImage {
13
+ type: "image";
14
+ source: ImageSource;
15
+ cache?: boolean;
16
+ }
17
+ export interface ImageSource {
18
+ type: "base64";
19
+ media_type: "image/webp" | "image/png" | "image/jpeg";
20
+ data: string;
21
+ }
22
+ export interface ContentMessageItemThinking {
23
+ type: "thinking";
24
+ thinking: string;
25
+ signature: string;
26
+ }
27
+ export interface ContentMessageItemRedactedThinking {
28
+ type: "redacted_thinking";
29
+ data: string;
30
+ }
31
+ export interface ContentMessageItemToolUse {
32
+ type: "tool_use";
33
+ id: string;
34
+ input: unknown;
35
+ name: string;
36
+ }
37
+ export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse;
38
+ export type ContentMessage = ContentMessageItem[];
7
39
  export interface SystemMessageParam {
8
40
  /**
9
41
  * The contents of the system message.
10
42
  */
11
- content: string;
43
+ content: string | ContentMessageItemText[];
44
+ responseId?: string;
12
45
  /**
13
46
  * The role of the messages author, in this case `system`.
14
47
  */
@@ -19,7 +52,8 @@ export interface UserMessageParam {
19
52
  /**
20
53
  * The contents of the user message.
21
54
  */
22
- content: string;
55
+ content: string | (ContentMessageItemText | ContentMessageItemImage)[];
56
+ responseId?: string;
23
57
  /**
24
58
  * The role of the messages author, in this case `user`.
25
59
  */
@@ -30,11 +64,12 @@ export interface AssistantMessageParam {
30
64
  /**
31
65
  * The contents of the assistant message.
32
66
  */
33
- content?: string;
67
+ content: string | (ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemText | ContentMessageItemToolUse)[];
34
68
  /**
35
69
  * The role of the messages author, in this case `assistant`.
36
70
  */
37
71
  role: "assistant";
72
+ responseId?: string;
38
73
  /**
39
74
  * The function call name and arguments
40
75
  */
@@ -47,6 +82,7 @@ export interface AssistantMessageParam {
47
82
  arguments: any;
48
83
  };
49
84
  id?: string;
85
+ skipDelta?: boolean;
50
86
  /**
51
87
  * A summary of the patches which the assistant has made.
52
88
  * Useful for genai.
@@ -62,7 +98,7 @@ export interface UserMessage extends UserMessageParam {
62
98
  }
63
99
  export interface AssistantMessage extends AssistantMessageParam {
64
100
  id: string;
65
- status?: "accepted" | "rejected";
101
+ status?: "accepted" | "rejected" | "aborted";
66
102
  }
67
103
  export interface AssistantActionMessage {
68
104
  /**
@@ -78,3 +114,10 @@ export interface AssistantActionMessage {
78
114
  */
79
115
  export type Message = SystemMessage | UserMessage | AssistantMessage;
80
116
  export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
117
+ export declare function getContentText(message: string | ContentMessage): string;
118
+ export type Attachment = Template;
119
+ export interface Template {
120
+ type: "template";
121
+ name: string;
122
+ id: number;
123
+ }
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,32 @@
1
+ export interface AssistantSettings {
2
+ assistantType?: string;
3
+ viewId?: string;
4
+ cssOverrides?: string;
5
+ headingText: string;
6
+ headingTitle?: string;
7
+ suggestedPrompts?: SuggestedPrompt[];
8
+ messagePlaceholder: string;
9
+ requestAuth?: boolean;
10
+ requestState?: boolean;
11
+ showPrompt?: boolean;
12
+ theme?: "dark" | "light";
13
+ }
14
+ export interface SuggestedPrompt {
15
+ text: string;
16
+ type: "modify" | "interactivity" | "data";
17
+ }
18
+ interface IframeSettings extends Partial<AssistantSettings> {
19
+ local?: boolean;
20
+ /**
21
+ * The URL of the assistant.
22
+ */
23
+ baseUrl?: string;
24
+ }
25
+ export declare function getAssistantUrl(opts?: IframeSettings): string;
26
+ export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
27
+ export interface BuilderEditorAuth {
28
+ spaceId: string;
29
+ userId: string;
30
+ authToken: string;
31
+ }
32
+ export {};
@@ -1,22 +1,14 @@
1
1
  const urlParamSettings = [
2
2
  "assistantType",
3
- "hideFrameworkPicker",
4
- "hideHeader",
5
- "showAiCanMakeMistakes",
6
- "showCloseButton",
7
- "showHeaderButton",
8
3
  "showPrompt",
9
- "showSparklesInInputBar",
10
- "showUndoButton",
11
4
  "requestAuth",
12
5
  "requestState",
13
6
  "theme",
14
- "transparentBackground",
15
7
  "viewId",
16
8
  ];
17
9
  export function getAssistantUrl(opts = {}) {
18
- var _a;
19
- const url = new URL((_a = opts.baseUrl) !== null && _a !== void 0 ? _a : (opts.local ? "http://localhost:7242" : "https://assistant.builder.io"));
10
+ const url = new URL(opts.baseUrl ??
11
+ (opts.local ? "http://localhost:7242" : "https://assistant.builder.io"));
20
12
  urlParamSettings.forEach((key) => {
21
13
  const value = opts[key];
22
14
  if (typeof value === "string" || typeof value === "boolean") {
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Builder.io AI types and utilities
2
-
3
- Shared types between AI systems, threads, servers, etc.
package/dist/messages.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,65 +0,0 @@
1
- export interface AssistantSettings {
2
- assistantType?: string;
3
- viewId?: string;
4
- cssOverrides?: string;
5
- headingText: string;
6
- headingTitle?: string;
7
- headingImage?: string;
8
- suggestedPrompts?: SuggestedPrompt[];
9
- hideNewChatIfNoMessages?: boolean;
10
- hideFrameworkPicker?: boolean;
11
- hideHeader?: boolean;
12
- messagePlaceholder: string;
13
- requestAuth?: boolean;
14
- requestState?: boolean;
15
- showAiCanMakeMistakes?: boolean;
16
- showCloseButton?: boolean;
17
- showHeaderButton?: boolean;
18
- showPrompt?: boolean;
19
- showSparklesInInputBar?: boolean;
20
- /**
21
- * Show the undo button under the assistant's message.
22
- */
23
- showUndoButton?: boolean;
24
- suggestedItems: Snippet[];
25
- theme?: "dark" | "light";
26
- transparentBackground?: boolean;
27
- }
28
- export interface SuggestedPrompt {
29
- text: string;
30
- type: "modify" | "interactivity" | "data";
31
- }
32
- export interface Snippet {
33
- /**
34
- * The text that will be displayed in the chat snippet button.
35
- */
36
- text: string;
37
- /**
38
- * The icon that will be displayed in the chat snippet button.
39
- */
40
- icon?: string;
41
- /**
42
- * The color of the icon that will be displayed in the chat snippet button.
43
- */
44
- iconColor?: string;
45
- /**
46
- * The prompt text that will be sent to the assistant when the user clicks the chat snippet button.
47
- * This prompt is also what's added to the chat conversation from the user.
48
- */
49
- prompt?: string;
50
- }
51
- interface IframeSettings extends Partial<AssistantSettings> {
52
- local?: boolean;
53
- /**
54
- * The URL of the assistant.
55
- */
56
- baseUrl?: string;
57
- }
58
- export declare function getAssistantUrl(opts?: IframeSettings): string;
59
- export declare function parseAssistantUrlSettings(url: string): Partial<AssistantSettings>;
60
- export interface BuilderEditorAuth {
61
- spaceId: string;
62
- userId: string;
63
- authToken: string;
64
- }
65
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes