@builder.io/ai-utils 0.0.75 → 0.1.0
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 +65 -4
- package/src/completion.d.ts +1 -1
- package/src/events.d.ts +2 -81
- package/src/index.d.ts +0 -4
- package/src/index.js +0 -4
- package/src/mapping.d.ts +9 -0
- package/src/messages.d.ts +24 -6
- package/src/settings.d.ts +0 -3
- package/src/settings.js +0 -1
- package/src/complete-json.d.ts +0 -4
- package/src/complete-json.js +0 -52
- package/src/fetch.d.ts +0 -1
- package/src/fetch.js +0 -83
- package/src/thread.d.ts +0 -27
- package/src/thread.js +0 -1
- package/src/vcp.d.ts +0 -32
- package/src/vcp.js +0 -1
package/package.json
CHANGED
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,35 @@ 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
|
|
26
|
+
export type CompletionStopReason = "max_tokens" | "stop_sequence" | "tool_use" | "end_turn" | "content_filter" | null;
|
|
27
|
+
export type CodeGenStopReason = "error" | "limit" | CompletionStopReason;
|
|
28
|
+
export interface ViewPathToolInput {
|
|
29
|
+
filePath: string;
|
|
30
|
+
}
|
|
31
|
+
export interface GlobSearchToolInput {
|
|
32
|
+
pattern: string;
|
|
33
|
+
}
|
|
34
|
+
export interface GrepSearchToolInput {
|
|
35
|
+
query: string;
|
|
36
|
+
includeGlob?: string;
|
|
37
|
+
excludeGlob?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface AskUserToolInput {
|
|
40
|
+
question: string;
|
|
41
|
+
}
|
|
42
|
+
export interface CodeGenToolMap {
|
|
43
|
+
view_path: ViewPathToolInput;
|
|
44
|
+
glob_search: GlobSearchToolInput;
|
|
45
|
+
grep_search: GrepSearchToolInput;
|
|
46
|
+
ask_user: AskUserToolInput;
|
|
47
|
+
}
|
|
48
|
+
export type CodeGenTools = keyof CodeGenToolMap;
|
|
27
49
|
export type CodeGenMode = "exact" | "precise" | "precise_vision" | "creative" | "creative_vision" | "creative_only_vision";
|
|
28
50
|
export interface CodeGenInputOptions {
|
|
29
51
|
position: string;
|
|
30
52
|
eventName?: string;
|
|
31
53
|
sessionId: string;
|
|
32
|
-
codeGenMode?: "fast" | "quality-
|
|
54
|
+
codeGenMode?: "fast" | "quality" | "quality-v3";
|
|
33
55
|
url?: string;
|
|
34
56
|
diffActions?: boolean;
|
|
35
57
|
planningPrompt?: boolean;
|
|
@@ -37,18 +59,19 @@ export interface CodeGenInputOptions {
|
|
|
37
59
|
userPrompt?: string;
|
|
38
60
|
files?: ProjectFile[];
|
|
39
61
|
rerankFiles?: number;
|
|
62
|
+
toolResults?: ContentMessageItemToolResult[];
|
|
40
63
|
builderContent?: BuilderContent;
|
|
41
64
|
framework?: CodeGenFramework;
|
|
42
65
|
styleLibrary?: CodeGenStyleLibrary;
|
|
43
66
|
typescript?: boolean;
|
|
44
67
|
userContext?: UserContext;
|
|
68
|
+
enabledTools?: CodeGenTools[];
|
|
45
69
|
maxTokens?: number;
|
|
46
70
|
maxPages?: number;
|
|
47
71
|
autoContinue?: number;
|
|
48
72
|
promptCaching?: boolean;
|
|
49
73
|
isAutoContinue?: boolean;
|
|
50
74
|
llmSuggestions?: boolean;
|
|
51
|
-
requestActions?: boolean;
|
|
52
75
|
conclusionText?: boolean;
|
|
53
76
|
searchResponse?: any | null;
|
|
54
77
|
prettierConfig?: PrettierOptions;
|
|
@@ -61,3 +84,41 @@ export interface CodeGenInputOptions {
|
|
|
61
84
|
/** @deprecated */
|
|
62
85
|
vcpId?: string;
|
|
63
86
|
}
|
|
87
|
+
export type Feature = "component-mapping";
|
|
88
|
+
export interface CodegenUsage {
|
|
89
|
+
total: number;
|
|
90
|
+
fast: number;
|
|
91
|
+
quality: number;
|
|
92
|
+
features: Feature[];
|
|
93
|
+
limits: {
|
|
94
|
+
aiGeneration: number;
|
|
95
|
+
aiGenerationContextWindow: number;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export interface PromptSuggestion {
|
|
99
|
+
type: "missing-imports" | "lazy-code" | "syntax-error" | "llm-suggested" | "diff-apply";
|
|
100
|
+
filePath?: string;
|
|
101
|
+
line?: number;
|
|
102
|
+
importance: "high" | "medium" | "low";
|
|
103
|
+
column?: number;
|
|
104
|
+
summary: string;
|
|
105
|
+
prompt: string;
|
|
106
|
+
}
|
|
107
|
+
export interface ActionItem {
|
|
108
|
+
type: "file" | "text" | "delta" | "done" | "diff" | "thinking" | "user" | "tool" | "suggestion" | "continue";
|
|
109
|
+
id?: string;
|
|
110
|
+
content: string;
|
|
111
|
+
filePath?: string;
|
|
112
|
+
artifactTitle?: string;
|
|
113
|
+
actionTitle?: string;
|
|
114
|
+
synthetic?: boolean;
|
|
115
|
+
incomplete?: boolean;
|
|
116
|
+
nextUrl?: string;
|
|
117
|
+
actions?: ActionItem[];
|
|
118
|
+
stopReason?: CodeGenStopReason;
|
|
119
|
+
suggestions?: PromptSuggestion[];
|
|
120
|
+
messageIndex?: number;
|
|
121
|
+
usage?: CodegenUsage;
|
|
122
|
+
errors?: string[];
|
|
123
|
+
sessionUsage?: number;
|
|
124
|
+
}
|
package/src/completion.d.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -147,6 +146,7 @@ export interface BuilderEditorState {
|
|
|
147
146
|
* Custom instructions that could be add into the prompt.
|
|
148
147
|
*/
|
|
149
148
|
customInstructions?: Record<string, string>;
|
|
149
|
+
styleInspirationURL?: string;
|
|
150
150
|
/**
|
|
151
151
|
* All targeting attributes of the content.
|
|
152
152
|
*/
|
package/src/events.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { BuilderContent, BuilderElement } from "@builder.io/sdk";
|
|
|
2
2
|
import type { AssistantMessage } from "./messages.js";
|
|
3
3
|
import type { AssistantSettings } from "./settings.js";
|
|
4
4
|
export type BuilderAssistantEventHandler = (ev: BuilderAssistantEvent) => void;
|
|
5
|
-
export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent |
|
|
5
|
+
export type BuilderAssistantEvent = AssistantCompletionResultEvent | AssistantErrorEvent | AssistantStreamErrorEvent | AppCloseEvent | AppMessagesClickEvent | AppMessagesGenerationEvent | AppMessageEditCustomInstructionsEvent | AppPromptAbortEvent | AppPromptFocusEvent | AppReadyEvent | AppSettingsSetEvent | AppThreadNewEvent | AssistantStatsEvent | AssistantThemeEvent | BuilderEditorAuthEvent | BuilderEditorStateEvent | ContentUpdateEvent | ContentApplySnapshotEvent | ModelUndoEvent | ModelRedoEvent | ResultEvent | ThreadCreatedEvent | ThreadMessageCompletedEvent | ThreadMessageCreatedEvent | ThreadMessageDeltaEvent | ThreadMessageFeedbackEvent | ThreadRunStepCreatedEvent | ThreadRunStepDeltaEvent | AppAcceptChangeEvent | AppAcceptRejectEvent | AssistantTrackEvent | AssistantEditorAuthMessage | AppAttachmentTemplateEvent | ThreadMessageRetryEvent;
|
|
6
6
|
export interface AssistantCompletionResultEvent {
|
|
7
7
|
type: "assistant.result";
|
|
8
8
|
data: {
|
|
@@ -78,18 +78,9 @@ export interface AppPromptAbortEvent {
|
|
|
78
78
|
export interface AppPromptFocusEvent {
|
|
79
79
|
type: "assistant.app.prompt.focus";
|
|
80
80
|
}
|
|
81
|
-
export interface AppPromptTextEvent {
|
|
82
|
-
type: "assistant.app.prompt.text";
|
|
83
|
-
data: {
|
|
84
|
-
text: string;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
81
|
export interface AppReadyEvent {
|
|
88
82
|
type: "assistant.app.ready";
|
|
89
83
|
}
|
|
90
|
-
export interface AppSettingsResetEvent {
|
|
91
|
-
type: "assistant.app.settings.reset";
|
|
92
|
-
}
|
|
93
84
|
export interface AppSettingsSetEvent {
|
|
94
85
|
type: "assistant.app.settings.set";
|
|
95
86
|
data: Partial<AssistantSettings>;
|
|
@@ -140,7 +131,7 @@ export interface ContentUpdateEvent {
|
|
|
140
131
|
type: "assistant.content.update";
|
|
141
132
|
data: ContentUpdatePatch[];
|
|
142
133
|
}
|
|
143
|
-
export type ContentUpdatePatch =
|
|
134
|
+
export type ContentUpdatePatch = ContentTsUpdateComponentPatch;
|
|
144
135
|
interface ContentPatchBase {
|
|
145
136
|
id: string;
|
|
146
137
|
nodeId?: string;
|
|
@@ -161,48 +152,6 @@ interface ContentPatchBase {
|
|
|
161
152
|
export interface ContentTsUpdateComponentPatch extends ContentPatchBase {
|
|
162
153
|
type: "update_component";
|
|
163
154
|
}
|
|
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
155
|
export interface AssistantStatsEvent {
|
|
207
156
|
type: "assistant.stats";
|
|
208
157
|
data: AssistantStats;
|
|
@@ -295,23 +244,12 @@ export interface AssistantStats {
|
|
|
295
244
|
*/
|
|
296
245
|
cacheCreatedTokens?: number;
|
|
297
246
|
}
|
|
298
|
-
export interface ModelCreateEvent {
|
|
299
|
-
type: "assistant.model.create";
|
|
300
|
-
data: BuilderModel;
|
|
301
|
-
}
|
|
302
|
-
export interface ModelUpdateEvent {
|
|
303
|
-
type: "assistant.model.update";
|
|
304
|
-
data: ModelUpdate;
|
|
305
|
-
}
|
|
306
247
|
export interface ModelUndoEvent {
|
|
307
248
|
type: "assistant.model.undo";
|
|
308
249
|
}
|
|
309
250
|
export interface ModelRedoEvent {
|
|
310
251
|
type: "assistant.model.redo";
|
|
311
252
|
}
|
|
312
|
-
export interface ModelUpdate {
|
|
313
|
-
patches: ModelPatch[];
|
|
314
|
-
}
|
|
315
253
|
export interface BuilderModel {
|
|
316
254
|
name?: string;
|
|
317
255
|
friendlyName?: string;
|
|
@@ -324,11 +262,6 @@ export interface BuilderModelField {
|
|
|
324
262
|
type?: string;
|
|
325
263
|
description?: string;
|
|
326
264
|
}
|
|
327
|
-
export type ModelPatch = {
|
|
328
|
-
op: "add" | "remove" | "replace";
|
|
329
|
-
path: string;
|
|
330
|
-
value?: any;
|
|
331
|
-
};
|
|
332
265
|
export interface ThreadMessageFeedbackEvent {
|
|
333
266
|
type: "assistant.thread.message.feedback";
|
|
334
267
|
data: CompletionResponseFeedback;
|
|
@@ -383,18 +316,6 @@ export interface ThreadMessageCompleted extends AssistantMessage {
|
|
|
383
316
|
threadId: string;
|
|
384
317
|
commitId?: string;
|
|
385
318
|
}
|
|
386
|
-
export interface ThreadRunRequiresActionEvent {
|
|
387
|
-
type: "assistant.thread.run.requires_action";
|
|
388
|
-
data: ThreadRunRequiredAction;
|
|
389
|
-
}
|
|
390
|
-
export interface ThreadRunRequiredAction {
|
|
391
|
-
platformId: string;
|
|
392
|
-
threadId: string;
|
|
393
|
-
action: {
|
|
394
|
-
name: string;
|
|
395
|
-
arguments: string;
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
319
|
export interface ThreadRunStepDeltaEvent {
|
|
399
320
|
type: "assistant.thread.run.step.delta";
|
|
400
321
|
data: ThreadMessageStepDelta;
|
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,27 @@ export interface ContentMessageItemText {
|
|
|
11
11
|
}
|
|
12
12
|
export interface ContentMessageItemImage {
|
|
13
13
|
type: "image";
|
|
14
|
-
source:
|
|
14
|
+
source: ImageBase64Source | ImageUrlSource;
|
|
15
15
|
cache?: boolean;
|
|
16
16
|
}
|
|
17
|
-
export interface
|
|
17
|
+
export interface ContentMessageItemToolResult {
|
|
18
|
+
type: "tool_result";
|
|
19
|
+
tool_use_id: string;
|
|
20
|
+
tool_name?: string;
|
|
21
|
+
tool_input?: string;
|
|
22
|
+
content: string;
|
|
23
|
+
is_error: boolean;
|
|
24
|
+
cache?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface ImageBase64Source {
|
|
18
27
|
type: "base64";
|
|
19
28
|
media_type: "image/webp" | "image/png" | "image/jpeg";
|
|
20
29
|
data: string;
|
|
21
30
|
}
|
|
31
|
+
export interface ImageUrlSource {
|
|
32
|
+
type: "url";
|
|
33
|
+
url: string;
|
|
34
|
+
}
|
|
22
35
|
export interface ContentMessageItemThinking {
|
|
23
36
|
type: "thinking";
|
|
24
37
|
thinking: string;
|
|
@@ -32,9 +45,10 @@ export interface ContentMessageItemToolUse {
|
|
|
32
45
|
type: "tool_use";
|
|
33
46
|
id: string;
|
|
34
47
|
input: unknown;
|
|
48
|
+
completion?: string;
|
|
35
49
|
name: string;
|
|
36
50
|
}
|
|
37
|
-
export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse;
|
|
51
|
+
export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult;
|
|
38
52
|
export type ContentMessage = ContentMessageItem[];
|
|
39
53
|
export interface SystemMessageParam {
|
|
40
54
|
/**
|
|
@@ -52,7 +66,7 @@ export interface UserMessageParam {
|
|
|
52
66
|
/**
|
|
53
67
|
* The contents of the user message.
|
|
54
68
|
*/
|
|
55
|
-
content: string | (ContentMessageItemText | ContentMessageItemImage)[];
|
|
69
|
+
content: string | (ContentMessageItemText | ContentMessageItemImage | ContentMessageItemToolResult)[];
|
|
56
70
|
responseId?: string;
|
|
57
71
|
/**
|
|
58
72
|
* The role of the messages author, in this case `user`.
|
|
@@ -115,8 +129,12 @@ export interface AssistantActionMessage {
|
|
|
115
129
|
export type Message = SystemMessage | UserMessage | AssistantMessage;
|
|
116
130
|
export type GeneratingMessage = null | Partial<AssistantActionMessage | AssistantMessage>;
|
|
117
131
|
export declare function getContentText(message: string | ContentMessage): string;
|
|
118
|
-
export declare function getContentAttachments(message: string | ContentMessage):
|
|
119
|
-
export type Attachment = FileUpload | Template;
|
|
132
|
+
export declare function getContentAttachments(message: string | ContentMessage): (ImageBase64Source | ImageUrlSource)[];
|
|
133
|
+
export type Attachment = FileUpload | Template | URL;
|
|
134
|
+
export interface URL {
|
|
135
|
+
type: "url";
|
|
136
|
+
value: string;
|
|
137
|
+
}
|
|
120
138
|
export interface FileUpload {
|
|
121
139
|
type: "upload";
|
|
122
140
|
contentType: string;
|
package/src/settings.d.ts
CHANGED
package/src/settings.js
CHANGED
package/src/complete-json.d.ts
DELETED
package/src/complete-json.js
DELETED
|
@@ -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 {};
|