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