@builder.io/ai-utils 0.0.74 → 0.0.76
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 +1 -1
- package/src/codegen.d.ts +92 -0
- package/src/codegen.js +1 -0
- package/src/completion.d.ts +153 -0
- package/src/completion.js +1 -0
- package/src/events.d.ts +369 -0
- package/src/events.js +1 -0
- package/src/{index.ts → index.d.ts} +0 -4
- package/src/index.js +6 -0
- package/src/mapping.d.ts +86 -0
- package/src/mapping.js +1 -0
- package/src/messages.d.ts +144 -0
- package/src/messages.js +16 -0
- package/src/settings.d.ts +23 -0
- package/src/settings.js +31 -0
- package/README.md +0 -3
- package/src/codegen.ts +0 -111
- package/src/complete-json.ts +0 -55
- package/src/completion.ts +0 -173
- package/src/events.ts +0 -539
- package/src/fetch.ts +0 -95
- package/src/mapping.ts +0 -88
- package/src/messages.ts +0 -190
- package/src/settings.ts +0 -63
- package/src/thread.ts +0 -28
- package/src/vcp.ts +0 -32
package/src/messages.ts
DELETED
|
@@ -1,190 +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: ImageSource;
|
|
21
|
-
cache?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ImageSource {
|
|
25
|
-
type: "base64";
|
|
26
|
-
media_type: "image/webp" | "image/png" | "image/jpeg";
|
|
27
|
-
data: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface ContentMessageItemThinking {
|
|
31
|
-
type: "thinking";
|
|
32
|
-
thinking: string;
|
|
33
|
-
signature: string;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface ContentMessageItemRedactedThinking {
|
|
37
|
-
type: "redacted_thinking";
|
|
38
|
-
data: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface ContentMessageItemToolUse {
|
|
42
|
-
type: "tool_use";
|
|
43
|
-
id: string;
|
|
44
|
-
input: unknown;
|
|
45
|
-
name: string;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export type ContentMessageItem =
|
|
49
|
-
| ContentMessageItemText
|
|
50
|
-
| ContentMessageItemImage
|
|
51
|
-
| ContentMessageItemThinking
|
|
52
|
-
| ContentMessageItemRedactedThinking
|
|
53
|
-
| ContentMessageItemToolUse;
|
|
54
|
-
|
|
55
|
-
export type ContentMessage = ContentMessageItem[];
|
|
56
|
-
|
|
57
|
-
export interface SystemMessageParam {
|
|
58
|
-
/**
|
|
59
|
-
* The contents of the system message.
|
|
60
|
-
*/
|
|
61
|
-
content: string | ContentMessageItemText[];
|
|
62
|
-
|
|
63
|
-
// an id to track messages across a response including multiple retries
|
|
64
|
-
responseId?: string;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* The role of the messages author, in this case `system`.
|
|
68
|
-
*/
|
|
69
|
-
role: "system";
|
|
70
|
-
|
|
71
|
-
id?: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export interface UserMessageParam {
|
|
75
|
-
/**
|
|
76
|
-
* The contents of the user message.
|
|
77
|
-
*/
|
|
78
|
-
content: string | (ContentMessageItemText | ContentMessageItemImage)[];
|
|
79
|
-
|
|
80
|
-
// an id to track messages across a response including multiple retries
|
|
81
|
-
responseId?: string;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The role of the messages author, in this case `user`.
|
|
85
|
-
*/
|
|
86
|
-
role: "user";
|
|
87
|
-
id?: string;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface AssistantMessageParam {
|
|
91
|
-
/**
|
|
92
|
-
* The contents of the assistant message.
|
|
93
|
-
*/
|
|
94
|
-
content: string | ContentMessageItem[];
|
|
95
|
-
/**
|
|
96
|
-
* The role of the messages author, in this case `assistant`.
|
|
97
|
-
*/
|
|
98
|
-
role: "assistant";
|
|
99
|
-
|
|
100
|
-
// an id to track messages across a response including multiple retries
|
|
101
|
-
responseId?: string;
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* The function call name and arguments
|
|
105
|
-
*/
|
|
106
|
-
action?: {
|
|
107
|
-
/**
|
|
108
|
-
* The specific function name
|
|
109
|
-
*/
|
|
110
|
-
name: string;
|
|
111
|
-
/** This is arbitrary JSON */
|
|
112
|
-
arguments: any;
|
|
113
|
-
};
|
|
114
|
-
id?: string;
|
|
115
|
-
skipDelta?: boolean;
|
|
116
|
-
/**
|
|
117
|
-
* A summary of the patches which the assistant has made.
|
|
118
|
-
* Useful for genai.
|
|
119
|
-
*/
|
|
120
|
-
patches?: ContentUpdatePatch[];
|
|
121
|
-
state?: "error";
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface SystemMessage extends SystemMessageParam {
|
|
125
|
-
id: string;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface UserMessage extends UserMessageParam {
|
|
129
|
-
id: string;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export interface AssistantMessage extends AssistantMessageParam {
|
|
133
|
-
id: string;
|
|
134
|
-
status?: "accepted" | "rejected" | "aborted";
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface AssistantActionMessage {
|
|
138
|
-
/**
|
|
139
|
-
* The role of the messages author, in this case `assistant`.
|
|
140
|
-
*/
|
|
141
|
-
role: "assistant";
|
|
142
|
-
|
|
143
|
-
id: string;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Message DOES know the id of the message.
|
|
148
|
-
* This message is after an id has been assigned
|
|
149
|
-
* and is the output message.
|
|
150
|
-
*/
|
|
151
|
-
export type Message = SystemMessage | UserMessage | AssistantMessage;
|
|
152
|
-
|
|
153
|
-
export type GeneratingMessage = null | Partial<
|
|
154
|
-
AssistantActionMessage | AssistantMessage
|
|
155
|
-
>;
|
|
156
|
-
|
|
157
|
-
export function getContentText(message: string | ContentMessage) {
|
|
158
|
-
if (typeof message === "string") {
|
|
159
|
-
return message;
|
|
160
|
-
}
|
|
161
|
-
return message
|
|
162
|
-
.map((item) => (item.type === "text" ? item.text : ""))
|
|
163
|
-
.join("");
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function getContentAttachments(message: string | ContentMessage) {
|
|
167
|
-
if (typeof message === "string") {
|
|
168
|
-
return [];
|
|
169
|
-
}
|
|
170
|
-
return message
|
|
171
|
-
.filter((item) => item.type === "image")
|
|
172
|
-
.map((item) => item.source);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export type Attachment = FileUpload | Template;
|
|
176
|
-
|
|
177
|
-
export interface FileUpload {
|
|
178
|
-
type: "upload";
|
|
179
|
-
contentType: string;
|
|
180
|
-
name: string;
|
|
181
|
-
dataUrl: string;
|
|
182
|
-
size: number;
|
|
183
|
-
id: string;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export interface Template {
|
|
187
|
-
type: "template";
|
|
188
|
-
name: string;
|
|
189
|
-
id: number;
|
|
190
|
-
}
|
package/src/settings.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export interface AssistantSettings {
|
|
2
|
-
assistantType?: string;
|
|
3
|
-
viewId?: string;
|
|
4
|
-
cssOverrides?: string;
|
|
5
|
-
messagePlaceholder: string;
|
|
6
|
-
showPrompt?: boolean;
|
|
7
|
-
theme?: "dark" | "light";
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface IframeSettings extends Partial<AssistantSettings> {
|
|
11
|
-
local?: boolean;
|
|
12
|
-
/**
|
|
13
|
-
* The URL of the assistant.
|
|
14
|
-
*/
|
|
15
|
-
baseUrl?: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type AssistantSettingsKeys = keyof AssistantSettings;
|
|
19
|
-
|
|
20
|
-
const urlParamSettings: AssistantSettingsKeys[] = [
|
|
21
|
-
"assistantType",
|
|
22
|
-
"showPrompt",
|
|
23
|
-
"theme",
|
|
24
|
-
"viewId",
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
export function getAssistantUrl(opts: IframeSettings = {}) {
|
|
28
|
-
const url = new URL(
|
|
29
|
-
opts.baseUrl ??
|
|
30
|
-
(opts.local ? "http://localhost:7242" : "https://assistant.builder.io"),
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
urlParamSettings.forEach((key) => {
|
|
34
|
-
const value = opts[key];
|
|
35
|
-
if (typeof value === "string" || typeof value === "boolean") {
|
|
36
|
-
url.searchParams.set(key, String(value));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return url.href;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function parseAssistantUrlSettings(url: string) {
|
|
44
|
-
const parsed = new URL(url);
|
|
45
|
-
const settings: Record<string, string | boolean> = {};
|
|
46
|
-
|
|
47
|
-
urlParamSettings.forEach((key) => {
|
|
48
|
-
const value = parsed.searchParams.get(key);
|
|
49
|
-
if (value === "true" || value === "false") {
|
|
50
|
-
settings[key] = value === "true";
|
|
51
|
-
} else if (value) {
|
|
52
|
-
settings[key] = value;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
return settings as Partial<AssistantSettings>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface BuilderEditorAuth {
|
|
60
|
-
spaceId: string;
|
|
61
|
-
userId: string;
|
|
62
|
-
authToken: string;
|
|
63
|
-
}
|
package/src/thread.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { Message } from "./messages.js";
|
|
2
|
-
|
|
3
|
-
export interface Thread {
|
|
4
|
-
/**
|
|
5
|
-
* The unique LOCAL identifier of the thread.
|
|
6
|
-
*/
|
|
7
|
-
id: string;
|
|
8
|
-
/**
|
|
9
|
-
* The unique OPENAI identifier of the thread. This is only
|
|
10
|
-
* set after openai creates the thread.
|
|
11
|
-
*/
|
|
12
|
-
threadId?: string;
|
|
13
|
-
platformId?: string;
|
|
14
|
-
title?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The type of assistant that the thread is associated with.
|
|
17
|
-
* For example, "content-editor" or "docs".
|
|
18
|
-
*/
|
|
19
|
-
assistantType?: string;
|
|
20
|
-
/**
|
|
21
|
-
* The unique identifier of the view that the thread is associated with.
|
|
22
|
-
* For example, the "content-editor" assistant would use the
|
|
23
|
-
* builder content id as the viewId.
|
|
24
|
-
*/
|
|
25
|
-
viewId?: string;
|
|
26
|
-
created: number;
|
|
27
|
-
messages: Message[];
|
|
28
|
-
}
|
package/src/vcp.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ESMImport } from "./codegen";
|
|
2
|
-
|
|
3
|
-
export interface BuilderComponentInfo {
|
|
4
|
-
name: string;
|
|
5
|
-
inputs?: BuilderComponentInput[];
|
|
6
|
-
path: string;
|
|
7
|
-
imports: { [key: string]: string | undefined };
|
|
8
|
-
esmImports?: ESMImport[];
|
|
9
|
-
options?: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface BuilderComponentInput {
|
|
13
|
-
name: string;
|
|
14
|
-
type: string;
|
|
15
|
-
value: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface BuilderComponentSlot {
|
|
19
|
-
figmaId: string;
|
|
20
|
-
builderName: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface JSXNode {
|
|
24
|
-
"@type": "jsx";
|
|
25
|
-
name: string;
|
|
26
|
-
props: Record<string, any>;
|
|
27
|
-
tagName?: string;
|
|
28
|
-
includeAirLayoutStyles?: boolean;
|
|
29
|
-
path?: string;
|
|
30
|
-
imports?: { [key: string]: string | undefined };
|
|
31
|
-
esmImports?: ESMImport[];
|
|
32
|
-
}
|