@builder.io/ai-utils 0.0.74 → 0.0.75

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/fetch.ts DELETED
@@ -1,95 +0,0 @@
1
- export async function fetchJsonl<T>(
2
- input: string | URL,
3
- init: RequestInit,
4
- onData: (ev: T) => void,
5
- ) {
6
- return new Promise<Response>(async (resolve, reject) => {
7
- try {
8
- init = {
9
- ...init,
10
- headers: {
11
- accept: "application/jsonl",
12
- "content-type": "application/json",
13
- ...init.headers,
14
- },
15
- };
16
-
17
- const rsp = await (async () => {
18
- try {
19
- return await fetch(input, init);
20
- } catch (err) {
21
- reject(new NetworkError(`${input}, status: network failure`));
22
- }
23
- })();
24
-
25
- if (!rsp) {
26
- return;
27
- }
28
-
29
- if (!rsp.ok) {
30
- reject(new APIError(`${input}, status: ${rsp.status}`));
31
- return;
32
- }
33
-
34
- if (!rsp.body) {
35
- reject(new APIError(`${input}, missing body`));
36
- return;
37
- }
38
-
39
- const reader = rsp.body.getReader();
40
- const decoder = new TextDecoder();
41
- let data = "";
42
-
43
- const processStream = async () => {
44
- const { done, value } = await reader.read();
45
- data += decoder.decode(value, { stream: !done });
46
-
47
- if (!done) {
48
- let lines = data.split("\n");
49
- if (!done) {
50
- data = lines.pop() || "";
51
- }
52
-
53
- for (let line of lines) {
54
- if (line) {
55
- try {
56
- line = line.trim();
57
- if (line.startsWith("{") && line.endsWith("}")) {
58
- onData(JSON.parse(line));
59
- } else {
60
- reject(`Invalid JSONL line: ${line}`);
61
- return;
62
- }
63
- } catch (e) {
64
- console.error(`Failed to parse JSONL: ${line}`);
65
- reject(e);
66
- return;
67
- }
68
- }
69
- }
70
-
71
- await processStream();
72
- }
73
- };
74
-
75
- await processStream();
76
- resolve(rsp);
77
- } catch (e) {
78
- reject(e);
79
- }
80
- });
81
- }
82
-
83
- class NetworkError extends Error {
84
- constructor(message: string) {
85
- super(message);
86
- this.name = "NetworkError";
87
- }
88
- }
89
-
90
- class APIError extends Error {
91
- constructor(message: string) {
92
- super(message);
93
- this.name = "APIError";
94
- }
95
- }
package/src/mapping.ts DELETED
@@ -1,88 +0,0 @@
1
- import type { ESMImport } from "./codegen";
2
-
3
- export interface UserContext {
4
- client: string;
5
- clientVersion: string;
6
- nodeVersion: string;
7
- systemPlatform: string;
8
- frameworks: string[];
9
- systemEOL: string;
10
- systemArch: string;
11
- systemShell?: string;
12
- inGitRepo?: boolean;
13
- [key: string]: string | string[] | boolean | undefined;
14
- }
15
-
16
- export type ExportType = "default" | "named";
17
-
18
- /**
19
- * Gets the latest component mappings for a space
20
- */
21
- export interface FigmaMappingsData {
22
- id: string;
23
- figmaBuilderLinks: FigmaBuilderLink[];
24
- version?: number;
25
- createdDate?: string; // ISO string timestamp or unix timestamp
26
- local: boolean;
27
- userEmail?: string;
28
- remoteUrl?: string;
29
- }
30
-
31
- export interface FigmaBuilderLink {
32
- builderName: string;
33
- figmaName: string;
34
- figmaKey: string;
35
- figmaUrl?: string;
36
- inputMapper?: string;
37
- originalInputMapper?: string;
38
- exportType?: ExportType;
39
- importName?: string;
40
- importPath?: string;
41
- source: string;
42
- loc?: string;
43
- imports?: ESMImport[];
44
- }
45
-
46
- export interface FigmaMapperFile {
47
- filePath: string;
48
- content: string;
49
- }
50
-
51
- export interface PublishedMapping {
52
- figmaBuilderLinks: FigmaBuilderLink[];
53
- mapperFiles: FigmaMapperFile[];
54
-
55
- // Meta data
56
- remoteUrl?: string;
57
- defaultBranch?: string;
58
- currentBranch?: string;
59
- commit?: string;
60
- spaceKind?: string;
61
-
62
- userContext?: UserContext;
63
- }
64
-
65
- export interface FigmaComponentInfo {
66
- documentName: string;
67
- key: string;
68
- tree?: string;
69
- jsx?: string;
70
- type: string;
71
- name: string;
72
- exportJson?: any;
73
- inputs: FigmaComponentInput[];
74
- description: string;
75
- documentationLinks: string[];
76
- instanceId: string;
77
- }
78
-
79
- export interface FigmaComponentInput {
80
- id: string;
81
- name: string;
82
- value?: any;
83
- type: string;
84
- baseType: "text" | "variant" | "boolean" | "slot";
85
- variantOptions?: string[];
86
- isDefault: boolean;
87
- ref?: string;
88
- }
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
- }
File without changes