@builder.io/ai-utils 0.0.75 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.0.75",
3
+ "version": "0.0.76",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/codegen.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { UserMessageParam } from "./messages";
1
+ import type { ContentMessageItemToolResult, UserMessageParam } from "./messages";
2
2
  import type { BuilderContent } from "./completion";
3
3
  import type { Options as PrettierOptions } from "prettier";
4
4
  import type { UserContext } from "./mapping";
@@ -23,13 +23,15 @@ export interface CustomInstruction {
23
23
  }
24
24
  export type CodeGenFramework = "react" | "html" | "mitosis" | "react-native" | "angular" | "vue" | "svelte" | "qwik" | "solid" | "marko" | "swiftui" | "jetpack-compose" | "flutter";
25
25
  export type CodeGenStyleLibrary = "tailwind" | "tailwind-precise" | "emotion" | "styled-components" | "styled-jsx" | "react-native" | undefined;
26
- export type CodeGenStopReason = "error" | "max_tokens" | "end" | "limit";
26
+ export type CompletionStopReason = "max_tokens" | "stop_sequence" | "tool_use" | "end_turn" | "content_filter" | null;
27
+ export type CodeGenStopReason = "error" | "limit" | CompletionStopReason;
28
+ export type CodeGenTools = "view_file_content";
27
29
  export type CodeGenMode = "exact" | "precise" | "precise_vision" | "creative" | "creative_vision" | "creative_only_vision";
28
30
  export interface CodeGenInputOptions {
29
31
  position: string;
30
32
  eventName?: string;
31
33
  sessionId: string;
32
- codeGenMode?: "fast" | "quality-v2";
34
+ codeGenMode?: "fast" | "quality-v2" | "agent";
33
35
  url?: string;
34
36
  diffActions?: boolean;
35
37
  planningPrompt?: boolean;
@@ -37,18 +39,19 @@ export interface CodeGenInputOptions {
37
39
  userPrompt?: string;
38
40
  files?: ProjectFile[];
39
41
  rerankFiles?: number;
42
+ toolResults?: ContentMessageItemToolResult[];
40
43
  builderContent?: BuilderContent;
41
44
  framework?: CodeGenFramework;
42
45
  styleLibrary?: CodeGenStyleLibrary;
43
46
  typescript?: boolean;
44
47
  userContext?: UserContext;
48
+ enabledTools?: CodeGenTools[];
45
49
  maxTokens?: number;
46
50
  maxPages?: number;
47
51
  autoContinue?: number;
48
52
  promptCaching?: boolean;
49
53
  isAutoContinue?: boolean;
50
54
  llmSuggestions?: boolean;
51
- requestActions?: boolean;
52
55
  conclusionText?: boolean;
53
56
  searchResponse?: any | null;
54
57
  prettierConfig?: PrettierOptions;
@@ -61,3 +64,29 @@ export interface CodeGenInputOptions {
61
64
  /** @deprecated */
62
65
  vcpId?: string;
63
66
  }
67
+ export type Feature = "component-mapping";
68
+ export interface CodegenUsage {
69
+ total: number;
70
+ fast: number;
71
+ quality: number;
72
+ features: Feature[];
73
+ limits: {
74
+ aiGeneration: number;
75
+ aiGenerationContextWindow: number;
76
+ };
77
+ }
78
+ export interface ActionItem {
79
+ type: "file" | "text" | "delta" | "done" | "diff" | "thinking" | "user" | "tool" | "suggestion" | "continue";
80
+ id?: string;
81
+ content: string;
82
+ filePath?: string;
83
+ artifactTitle?: string;
84
+ actionTitle?: string;
85
+ synthetic?: boolean;
86
+ incomplete?: boolean;
87
+ nextUrl?: string;
88
+ actions?: ActionItem[];
89
+ stopReason?: CodeGenStopReason;
90
+ usage?: CodegenUsage;
91
+ errors?: string[];
92
+ }
@@ -1,7 +1,6 @@
1
1
  import type { BuilderContent, BuilderElement, Component } from "@builder.io/sdk";
2
2
  import type { Message, MessageParam, Attachment } from "./messages.js";
3
3
  import type { BuilderModel } from "./events.js";
4
- export type BuilderContentData = BuilderContent["data"];
5
4
  export type { BuilderContent, BuilderElement, Component };
6
5
  export interface CompletionOptions {
7
6
  /**
package/src/events.d.ts CHANGED
@@ -140,7 +140,7 @@ export interface ContentUpdateEvent {
140
140
  type: "assistant.content.update";
141
141
  data: ContentUpdatePatch[];
142
142
  }
143
- export type ContentUpdatePatch = ContentTsCodePatch | ContentInsertBeforePatch | ContentInsertAfterPatch | ContentPropsUpdatePatch | ContentSetChildrenPatch | ContentStyleUpdatePatch | ContentDeletePatch | ContentSetStorePatch | ContentSetMountPatch | ContentMovePatch | ContentMoveAfterPatch | ContentMoveBeforePatch | ContentSetTagNamePatch | ContentTsUpdateComponentPatch;
143
+ export type ContentUpdatePatch = ContentTsUpdateComponentPatch;
144
144
  interface ContentPatchBase {
145
145
  id: string;
146
146
  nodeId?: string;
@@ -161,48 +161,6 @@ interface ContentPatchBase {
161
161
  export interface ContentTsUpdateComponentPatch extends ContentPatchBase {
162
162
  type: "update_component";
163
163
  }
164
- export interface ContentTsCodePatch extends ContentPatchBase {
165
- type: "ts_code";
166
- }
167
- export interface ContentSetTagNamePatch extends ContentPatchBase {
168
- type: "set_tag_name";
169
- }
170
- export interface ContentInsertBeforePatch extends ContentPatchBase {
171
- type: "insert_before";
172
- snapshotBuilderId?: string;
173
- }
174
- export interface ContentInsertAfterPatch extends ContentPatchBase {
175
- type: "insert_after";
176
- snapshotBuilderId?: string;
177
- }
178
- export interface ContentPropsUpdatePatch extends ContentPatchBase {
179
- type: "props";
180
- }
181
- export interface ContentStyleUpdatePatch extends ContentPatchBase {
182
- type: "style";
183
- }
184
- export interface ContentSetChildrenPatch extends ContentPatchBase {
185
- type: "children";
186
- snapshotBuilderId?: string;
187
- }
188
- export interface ContentDeletePatch extends ContentPatchBase {
189
- type: "delete";
190
- }
191
- export interface ContentSetStorePatch extends ContentPatchBase {
192
- type: "store";
193
- }
194
- export interface ContentSetMountPatch extends ContentPatchBase {
195
- type: "mount";
196
- }
197
- export interface ContentMovePatch extends ContentPatchBase {
198
- type: "move";
199
- }
200
- export interface ContentMoveAfterPatch extends ContentPatchBase {
201
- type: "move_after";
202
- }
203
- export interface ContentMoveBeforePatch extends ContentPatchBase {
204
- type: "move_before";
205
- }
206
164
  export interface AssistantStatsEvent {
207
165
  type: "assistant.stats";
208
166
  data: AssistantStats;
package/src/index.d.ts CHANGED
@@ -1,10 +1,6 @@
1
- export * from "./complete-json.js";
2
1
  export * from "./completion.js";
3
2
  export * from "./events.js";
4
- export * from "./fetch.js";
5
3
  export * from "./messages.js";
6
4
  export * from "./settings.js";
7
- export * from "./thread.js";
8
5
  export * from "./mapping.js";
9
6
  export * from "./codegen.js";
10
- export * from "./vcp.js";
package/src/index.js CHANGED
@@ -1,10 +1,6 @@
1
- export * from "./complete-json.js";
2
1
  export * from "./completion.js";
3
2
  export * from "./events.js";
4
- export * from "./fetch.js";
5
3
  export * from "./messages.js";
6
4
  export * from "./settings.js";
7
- export * from "./thread.js";
8
5
  export * from "./mapping.js";
9
6
  export * from "./codegen.js";
10
- export * from "./vcp.js";
package/src/mapping.d.ts CHANGED
@@ -1,4 +1,12 @@
1
1
  import type { ESMImport } from "./codegen";
2
+ export interface RawFigmaJson {
3
+ documents: any[];
4
+ document?: any;
5
+ components?: Record<string, any>;
6
+ styles?: Record<string, any>;
7
+ componentSets?: Record<string, any>;
8
+ schemaVersion?: number;
9
+ }
2
10
  export interface UserContext {
3
11
  client: string;
4
12
  clientVersion: string;
@@ -18,6 +26,7 @@ export type ExportType = "default" | "named";
18
26
  export interface FigmaMappingsData {
19
27
  id: string;
20
28
  figmaBuilderLinks: FigmaBuilderLink[];
29
+ framework: string;
21
30
  version?: number;
22
31
  createdDate?: string;
23
32
  local: boolean;
package/src/messages.d.ts CHANGED
@@ -11,14 +11,25 @@ export interface ContentMessageItemText {
11
11
  }
12
12
  export interface ContentMessageItemImage {
13
13
  type: "image";
14
- source: ImageSource;
14
+ source: ImageBase64Source | ImageUrlSource;
15
15
  cache?: boolean;
16
16
  }
17
- export interface ImageSource {
17
+ export interface ContentMessageItemToolResult {
18
+ type: "tool_result";
19
+ tool_use_id: string;
20
+ content: string;
21
+ is_error: boolean;
22
+ cache?: boolean;
23
+ }
24
+ export interface ImageBase64Source {
18
25
  type: "base64";
19
26
  media_type: "image/webp" | "image/png" | "image/jpeg";
20
27
  data: string;
21
28
  }
29
+ export interface ImageUrlSource {
30
+ type: "url";
31
+ url: string;
32
+ }
22
33
  export interface ContentMessageItemThinking {
23
34
  type: "thinking";
24
35
  thinking: string;
@@ -32,9 +43,10 @@ export interface ContentMessageItemToolUse {
32
43
  type: "tool_use";
33
44
  id: string;
34
45
  input: unknown;
46
+ completion?: string;
35
47
  name: string;
36
48
  }
37
- export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse;
49
+ export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult;
38
50
  export type ContentMessage = ContentMessageItem[];
39
51
  export interface SystemMessageParam {
40
52
  /**
@@ -52,7 +64,7 @@ export interface UserMessageParam {
52
64
  /**
53
65
  * The contents of the user message.
54
66
  */
55
- content: string | (ContentMessageItemText | ContentMessageItemImage)[];
67
+ content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemToolResult)[];
56
68
  responseId?: string;
57
69
  /**
58
70
  * The role of the messages author, in this case `user`.
@@ -115,7 +127,7 @@ export interface AssistantActionMessage {
115
127
  export type Message = SystemMessage | UserMessage | AssistantMessage;
116
128
  export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
117
129
  export declare function getContentText(message: string | ContentMessage): string;
118
- export declare function getContentAttachments(message: string | ContentMessage): ImageSource[];
130
+ export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
119
131
  export type Attachment = FileUpload | Template;
120
132
  export interface FileUpload {
121
133
  type: "upload";
@@ -1,4 +0,0 @@
1
- /**
2
- * Complete a partial JSON string with the necessary closing brackets and braces
3
- */
4
- export declare function completeJson(input: string): string;
@@ -1,52 +0,0 @@
1
- /**
2
- * Complete a partial JSON string with the necessary closing brackets and braces
3
- */
4
- export function completeJson(input) {
5
- const stack = [];
6
- let isInString = false;
7
- let lastQuote = "";
8
- // Scan the string to determine the necessary closures
9
- for (const char of input) {
10
- switch (char) {
11
- case '"':
12
- case "'":
13
- if (isInString && char === lastQuote) {
14
- // Check for escaping
15
- if (input.charAt(input.indexOf(char) - 1) !== "\\") {
16
- isInString = false;
17
- }
18
- }
19
- else if (!isInString) {
20
- isInString = true;
21
- lastQuote = char;
22
- }
23
- break;
24
- case "{":
25
- case "[":
26
- if (!isInString) {
27
- stack.push(char === "{" ? "}" : "]");
28
- }
29
- break;
30
- case "}":
31
- case "]":
32
- if (!isInString) {
33
- if (stack.length > 0 && stack[stack.length - 1] === char) {
34
- stack.pop();
35
- }
36
- }
37
- break;
38
- default:
39
- break;
40
- }
41
- }
42
- // Close any unclosed string
43
- if (isInString) {
44
- input += lastQuote;
45
- }
46
- // Close all remaining open brackets and braces
47
- while (stack.length > 0) {
48
- const charToClose = stack.pop();
49
- input += charToClose;
50
- }
51
- return input;
52
- }
package/src/fetch.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function fetchJsonl<T>(input: string | URL, init: RequestInit, onData: (ev: T) => void): Promise<Response>;
package/src/fetch.js DELETED
@@ -1,83 +0,0 @@
1
- export async function fetchJsonl(input, init, onData) {
2
- return new Promise(async (resolve, reject) => {
3
- try {
4
- init = {
5
- ...init,
6
- headers: {
7
- accept: "application/jsonl",
8
- "content-type": "application/json",
9
- ...init.headers,
10
- },
11
- };
12
- const rsp = await (async () => {
13
- try {
14
- return await fetch(input, init);
15
- }
16
- catch (err) {
17
- reject(new NetworkError(`${input}, status: network failure`));
18
- }
19
- })();
20
- if (!rsp) {
21
- return;
22
- }
23
- if (!rsp.ok) {
24
- reject(new APIError(`${input}, status: ${rsp.status}`));
25
- return;
26
- }
27
- if (!rsp.body) {
28
- reject(new APIError(`${input}, missing body`));
29
- return;
30
- }
31
- const reader = rsp.body.getReader();
32
- const decoder = new TextDecoder();
33
- let data = "";
34
- const processStream = async () => {
35
- const { done, value } = await reader.read();
36
- data += decoder.decode(value, { stream: !done });
37
- if (!done) {
38
- let lines = data.split("\n");
39
- if (!done) {
40
- data = lines.pop() || "";
41
- }
42
- for (let line of lines) {
43
- if (line) {
44
- try {
45
- line = line.trim();
46
- if (line.startsWith("{") && line.endsWith("}")) {
47
- onData(JSON.parse(line));
48
- }
49
- else {
50
- reject(`Invalid JSONL line: ${line}`);
51
- return;
52
- }
53
- }
54
- catch (e) {
55
- console.error(`Failed to parse JSONL: ${line}`);
56
- reject(e);
57
- return;
58
- }
59
- }
60
- }
61
- await processStream();
62
- }
63
- };
64
- await processStream();
65
- resolve(rsp);
66
- }
67
- catch (e) {
68
- reject(e);
69
- }
70
- });
71
- }
72
- class NetworkError extends Error {
73
- constructor(message) {
74
- super(message);
75
- this.name = "NetworkError";
76
- }
77
- }
78
- class APIError extends Error {
79
- constructor(message) {
80
- super(message);
81
- this.name = "APIError";
82
- }
83
- }
package/src/thread.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import type { Message } from "./messages.js";
2
- export interface Thread {
3
- /**
4
- * The unique LOCAL identifier of the thread.
5
- */
6
- id: string;
7
- /**
8
- * The unique OPENAI identifier of the thread. This is only
9
- * set after openai creates the thread.
10
- */
11
- threadId?: string;
12
- platformId?: string;
13
- title?: string;
14
- /**
15
- * The type of assistant that the thread is associated with.
16
- * For example, "content-editor" or "docs".
17
- */
18
- assistantType?: string;
19
- /**
20
- * The unique identifier of the view that the thread is associated with.
21
- * For example, the "content-editor" assistant would use the
22
- * builder content id as the viewId.
23
- */
24
- viewId?: string;
25
- created: number;
26
- messages: Message[];
27
- }
package/src/thread.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/src/vcp.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import type { ESMImport } from "./codegen";
2
- export interface BuilderComponentInfo {
3
- name: string;
4
- inputs?: BuilderComponentInput[];
5
- path: string;
6
- imports: {
7
- [key: string]: string | undefined;
8
- };
9
- esmImports?: ESMImport[];
10
- options?: any;
11
- }
12
- export interface BuilderComponentInput {
13
- name: string;
14
- type: string;
15
- value: any;
16
- }
17
- export interface BuilderComponentSlot {
18
- figmaId: string;
19
- builderName: string;
20
- }
21
- export interface JSXNode {
22
- "@type": "jsx";
23
- name: string;
24
- props: Record<string, any>;
25
- tagName?: string;
26
- includeAirLayoutStyles?: boolean;
27
- path?: string;
28
- imports?: {
29
- [key: string]: string | undefined;
30
- };
31
- esmImports?: ESMImport[];
32
- }
package/src/vcp.js DELETED
@@ -1 +0,0 @@
1
- export {};