@builder.io/ai-utils 0.3.1 → 0.3.3

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/messages.ts DELETED
@@ -1,240 +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
- }
17
-
18
- export interface ContentMessageItemImage {
19
- type: "image";
20
- source: ImageBase64Source | ImageUrlSource;
21
- cache?: boolean;
22
- }
23
-
24
- export interface ContentMessageItemDocument {
25
- type: "document";
26
- source: DocumentBase64Source | DocumentUrlSource;
27
- cache?: boolean;
28
- }
29
-
30
- export interface DocumentBase64Source {
31
- type: "base64";
32
- media_type: "application/pdf";
33
- data: string;
34
- }
35
-
36
- export interface DocumentUrlSource {
37
- type: "url";
38
- url: string;
39
- }
40
-
41
- export interface ContentMessageItemToolResult {
42
- type: "tool_result";
43
- tool_use_id: string;
44
- tool_name?: string;
45
- tool_input?: string;
46
- title?: string;
47
- content: string;
48
- is_error: boolean;
49
- cache?: boolean;
50
- }
51
-
52
- export interface ImageBase64Source {
53
- type: "base64";
54
- media_type: "image/webp" | "image/png" | "image/jpeg";
55
- data: string;
56
- }
57
-
58
- export interface ImageUrlSource {
59
- type: "url";
60
- url: string;
61
- }
62
-
63
- export interface ContentMessageItemThinking {
64
- type: "thinking";
65
- thinking: string;
66
- signature: string;
67
- }
68
-
69
- export interface ContentMessageItemRedactedThinking {
70
- type: "redacted_thinking";
71
- data: string;
72
- }
73
-
74
- export interface ContentMessageItemToolUse {
75
- type: "tool_use";
76
- id: string;
77
- input: unknown;
78
- completion?: string;
79
- name: string;
80
- }
81
-
82
- export type ContentMessageItem =
83
- | ContentMessageItemText
84
- | ContentMessageItemImage
85
- | ContentMessageItemDocument
86
- | ContentMessageItemThinking
87
- | ContentMessageItemRedactedThinking
88
- | ContentMessageItemToolUse
89
- | ContentMessageItemToolResult;
90
-
91
- export type ContentMessage = ContentMessageItem[];
92
-
93
- export interface SystemMessageParam {
94
- /**
95
- * The contents of the system message.
96
- */
97
- content: string | ContentMessageItemText[];
98
-
99
- // an id to track messages across a response including multiple retries
100
- responseId?: string;
101
-
102
- /**
103
- * The role of the messages author, in this case `system`.
104
- */
105
- role: "system";
106
-
107
- id?: string;
108
- }
109
-
110
- export interface UserMessageParam {
111
- /**
112
- * The contents of the user message.
113
- */
114
- content:
115
- | string
116
- | (
117
- | ContentMessageItemText
118
- | ContentMessageItemImage
119
- | ContentMessageItemDocument
120
- | ContentMessageItemToolResult
121
- )[];
122
-
123
- // an id to track messages across a response including multiple retries
124
- responseId?: string;
125
-
126
- /**
127
- * The role of the messages author, in this case `user`.
128
- */
129
- role: "user";
130
- id?: string;
131
- }
132
-
133
- export interface AssistantMessageParam {
134
- /**
135
- * The contents of the assistant message.
136
- */
137
- content: string | ContentMessageItem[];
138
- /**
139
- * The role of the messages author, in this case `assistant`.
140
- */
141
- role: "assistant";
142
-
143
- // an id to track messages across a response including multiple retries
144
- responseId?: string;
145
-
146
- /**
147
- * The function call name and arguments
148
- */
149
- action?: {
150
- /**
151
- * The specific function name
152
- */
153
- name: string;
154
- /** This is arbitrary JSON */
155
- arguments: any;
156
- };
157
- id?: string;
158
- skipDelta?: boolean;
159
- /**
160
- * A summary of the patches which the assistant has made.
161
- * Useful for genai.
162
- */
163
- patches?: ContentUpdatePatch[];
164
- state?: "error";
165
- }
166
-
167
- export interface SystemMessage extends SystemMessageParam {
168
- id: string;
169
- }
170
-
171
- export interface UserMessage extends UserMessageParam {
172
- id: string;
173
- }
174
-
175
- export interface AssistantMessage extends AssistantMessageParam {
176
- id: string;
177
- status?: "accepted" | "rejected" | "aborted";
178
- // Optional summary from the LLM that explains why it did
179
- summary?: string;
180
- }
181
-
182
- export interface AssistantActionMessage {
183
- /**
184
- * The role of the messages author, in this case `assistant`.
185
- */
186
- role: "assistant";
187
-
188
- id: string;
189
- }
190
-
191
- /**
192
- * Message DOES know the id of the message.
193
- * This message is after an id has been assigned
194
- * and is the output message.
195
- */
196
- export type Message = SystemMessage | UserMessage | AssistantMessage;
197
-
198
- export type GeneratingMessage = null | Partial<
199
- AssistantActionMessage | AssistantMessage
200
- >;
201
-
202
- export function getContentText(message: string | ContentMessage) {
203
- if (typeof message === "string") {
204
- return message;
205
- }
206
- return message
207
- .map((item) => (item.type === "text" ? item.text : ""))
208
- .join("");
209
- }
210
-
211
- export function getContentAttachments(message: string | ContentMessage) {
212
- if (typeof message === "string") {
213
- return [];
214
- }
215
- return message
216
- .filter((item) => item.type === "image")
217
- .map((item) => item.source);
218
- }
219
-
220
- export type Attachment = FileUpload | Template | URL;
221
-
222
- export interface URL {
223
- type: "url";
224
- value: string;
225
- }
226
-
227
- export interface FileUpload {
228
- type: "upload";
229
- contentType: string;
230
- name: string;
231
- dataUrl: string;
232
- size: number;
233
- id: string;
234
- }
235
-
236
- export interface Template {
237
- type: "template";
238
- name: string;
239
- id: number;
240
- }
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