@builder.io/ai-utils 0.3.0 → 0.3.2

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/codegen.ts DELETED
@@ -1,517 +0,0 @@
1
- import type {
2
- Attachment,
3
- ContentMessageItemToolResult,
4
- UserMessageParam,
5
- } from "./messages";
6
-
7
- import type { BuilderContent } from "./completion";
8
-
9
- import type { Options as PrettierOptions } from "prettier";
10
- import type { UserContext } from "./mapping";
11
- import type { AssistantMessageParam } from "./messages";
12
-
13
- // Define the import type as a union of literal types.
14
- export type ImportType = "named" | "default";
15
-
16
- // Define an interface for the import descriptor.
17
- export interface ESMImport {
18
- importName: string; // e.g. "Button"
19
- importPath: string; // e.g. "path"
20
- importType: ImportType; // Either 'named' or 'default'
21
- }
22
-
23
- export interface ProjectFile {
24
- filePath: string;
25
- content?: string;
26
- importance?: number;
27
- dropReason?: string;
28
- wasIncluded?: boolean;
29
- }
30
-
31
- export interface CustomInstruction {
32
- id: string;
33
- name: string;
34
- content: string;
35
- type?: "always" | "agent-mode" | string;
36
- glob?: string;
37
- description?: string;
38
- }
39
-
40
- export type CodeGenFramework =
41
- | "react"
42
- | "html"
43
- | "mitosis"
44
- | "react-native"
45
- | "angular"
46
- | "vue"
47
- | "svelte"
48
- | "qwik"
49
- | "solid"
50
- | "marko"
51
- | "swiftui"
52
- | "jetpack-compose"
53
- | "flutter";
54
-
55
- export type CodeGenStyleLibrary =
56
- | "tailwind"
57
- | "tailwind-precise"
58
- | "emotion"
59
- | "styled-components"
60
- | "styled-jsx"
61
- | "react-native"
62
- | undefined;
63
-
64
- export type CompletionStopReason =
65
- | "max_tokens"
66
- | "stop_sequence"
67
- | "tool_use"
68
- | "end_turn"
69
- | "content_filter"
70
- | null;
71
-
72
- export interface ViewPathToolInput {
73
- filePath: string;
74
- viewRange?: [number, number];
75
- }
76
-
77
- export interface GlobSearchToolInput {
78
- pattern: string;
79
- }
80
-
81
- export interface GrepSearchToolInput {
82
- query: string;
83
- includeGlob?: string;
84
- excludeGlob?: string;
85
- }
86
-
87
- export interface GetRuleToolInput {
88
- name: string;
89
- type?: "always" | "agent-mode" | string;
90
- glob?: string;
91
- description?: string;
92
- }
93
-
94
- export interface CodeGenToolMap {
95
- view_path: ViewPathToolInput;
96
- glob_search: GlobSearchToolInput;
97
- grep_search: GrepSearchToolInput;
98
- get_rule: GetRuleToolInput;
99
- }
100
-
101
- export type CodeGenTools = keyof CodeGenToolMap;
102
-
103
- export type CodeGenMode =
104
- | "exact" // @deprecated
105
- | "precise" // tries to match the design as close
106
- | "precise_vision" // tries to match the design as close, also uses vision to match
107
- | "creative" // adapts the design to some generic design language
108
- | "creative_vision" // adapts the design to some generic design language, also uses vision to match
109
- | "creative_only_vision"; // adapts the design to some generic design language, but only uses vision to match
110
-
111
- export interface CodeGenInputOptions {
112
- position: string;
113
- eventName?: string;
114
- sessionId: string;
115
-
116
- codeGenMode?: "fast" | "quality" | "quality-v3";
117
- url?: string;
118
- diffActions?: boolean;
119
- planningPrompt?: boolean;
120
- customInstructions?: CustomInstruction[];
121
- userPrompt?: string;
122
- displayUserPrompt?: string;
123
- files?: ProjectFile[];
124
- rerankFiles?: number;
125
- toolResults?: ContentMessageItemToolResult[];
126
- attachments?: Attachment[];
127
- beforeCommit?: string;
128
-
129
- // Code options
130
- builderContent?: BuilderContent;
131
- framework?: CodeGenFramework;
132
- styleLibrary?: CodeGenStyleLibrary;
133
- typescript?: boolean;
134
- userContext?: UserContext;
135
-
136
- enabledTools?: CodeGenTools[];
137
-
138
- // Options
139
- maxTokens?: number;
140
- maxPages?: number;
141
- autoContinue?: number;
142
- promptCaching?: boolean;
143
- isAutoContinue?: boolean;
144
- llmSuggestions?: boolean;
145
- conclusionText?: boolean;
146
-
147
- searchResponse?: any | null;
148
-
149
- // Prettier options
150
- prettierConfig?: PrettierOptions;
151
-
152
- /** @deprecated */
153
- history?: (UserMessageParam | AssistantMessageParam)[];
154
- /** @deprecated */
155
- prevId?: string;
156
- /** @deprecated */
157
- nextPage?: boolean;
158
- /** @deprecated */
159
- vcpId?: string;
160
- }
161
-
162
- export type Feature = "component-mapping";
163
-
164
- export interface CodegenUsage {
165
- total: number;
166
- fast: number;
167
- quality: number;
168
- features: Feature[];
169
- limits: {
170
- aiGeneration: number;
171
- aiGenerationContextWindow: number;
172
- };
173
- }
174
-
175
- export interface PromptSuggestion {
176
- type:
177
- | "missing-imports"
178
- | "lazy-code"
179
- | "syntax-error"
180
- | "llm-suggested"
181
- | "diff-apply";
182
-
183
- filePath?: string;
184
- line?: number;
185
- importance: "high" | "medium" | "low";
186
- column?: number;
187
- summary: string;
188
- prompt: string;
189
- }
190
-
191
- export interface ActionItem {
192
- type:
193
- | "file"
194
- | "text"
195
- | "diff"
196
- | "thinking"
197
- | "tool"
198
- | "suggestion"
199
- | "tool_result";
200
- id?: string;
201
- content: string;
202
- filePath?: string;
203
- artifactTitle?: string;
204
- actionTitle?: string;
205
- synthetic?: boolean;
206
- incomplete?: boolean;
207
- suggestions?: PromptSuggestion[];
208
- errors?: string[];
209
- }
210
-
211
- export interface RepoInfo {
212
- remoteUrl: string;
213
- defaultBranch: string;
214
- currentBranch: string;
215
- commit: string;
216
- }
217
-
218
- export interface CodebaseSearchOptions {
219
- repoInfo?: RepoInfo;
220
- query: string;
221
- selectedFiles?: string[];
222
- sessionId: string;
223
- files?: string[];
224
- packageJson?: string;
225
- limit?: number;
226
- includeContent?: boolean;
227
- }
228
-
229
- export interface CodebaseSearchResponse {
230
- id: string;
231
- relevantPaths: string[];
232
- grepQueries: string[];
233
- streamMeta: any;
234
- ranked: RankedResult[];
235
- }
236
-
237
- export interface RankedResult {
238
- index: number;
239
- filePath: string;
240
- startIndex: number;
241
- endIndex: number;
242
- score: number;
243
- id: string;
244
- content?: string;
245
- }
246
-
247
- export interface GenerateCompletionStepThinking {
248
- type: "thinking";
249
- }
250
-
251
- export interface FileInfo {
252
- filePath: string;
253
- size: number;
254
- }
255
-
256
- export interface GenerateCompletionStepUserInput {
257
- type: "user-input";
258
- prompt: string;
259
- files: FileInfo[];
260
- }
261
-
262
- export interface GenerateCompletionStepToolResult {
263
- type: "agent-input";
264
- toolResults: ContentMessageItemToolResult[];
265
- }
266
-
267
- export interface GenerateCompletionStepPlanning {
268
- type: "planning";
269
- content: string;
270
- }
271
-
272
- export interface GenerateCompletionStepUser {
273
- type: "user";
274
- displayPrompt: string | undefined;
275
- id: string;
276
- role: "user" | "agent";
277
- }
278
-
279
- export interface GenerateCompletionStepFile {
280
- type: "file";
281
- filePath: string;
282
- content: string;
283
- title: string;
284
- id: string;
285
- }
286
-
287
- export interface GenerateCompletionStepDiff {
288
- type: "diff";
289
- filePath: string;
290
- content: string;
291
- title: string;
292
- id: string;
293
- }
294
-
295
- export interface GenerateCompletionStepTool {
296
- type: "tool";
297
- name: string;
298
- id: string;
299
- content: string;
300
- }
301
-
302
- export interface GenerateCompletionStepText {
303
- type: "text";
304
- content: string;
305
- }
306
-
307
- export interface GenerateCompletionStepDone {
308
- type: "done";
309
- id: string;
310
- applyResults: ApplyActionsResult[];
311
- actions: ActionItem[];
312
- usage: CodegenUsage | undefined;
313
- url?: string;
314
- stopReason: CompletionStopReason;
315
- }
316
-
317
- export interface GenerateCompletionStepStart {
318
- type: "start";
319
- name: string;
320
- id: string | undefined;
321
- title: string;
322
- content: string;
323
- }
324
-
325
- export interface GenerateCompletionStepDelta {
326
- type: "delta";
327
- name: string;
328
- delta: string;
329
- }
330
-
331
- export interface GenerateCompletionStepError {
332
- type: "error";
333
- id?: string;
334
- stopReason?: "error" | "limit";
335
- metadata?: any;
336
- message: string;
337
- usage?: CodegenUsage;
338
- }
339
-
340
- export interface GenerateCompletionStepContinue {
341
- type: "continue";
342
- id: string;
343
- url: string;
344
- }
345
-
346
- export interface GenerateCompletionStepWaitForInput {
347
- type: "wait-for-input";
348
- state: GenerateCompletionState;
349
- }
350
-
351
- export interface GenerateCompletionStepAbort {
352
- type: "user-abort";
353
- }
354
-
355
- export interface GenerateCompletionStepRestore {
356
- type: "restore";
357
- location: "before" | "after";
358
- files: string[];
359
- lastCompletionId: string | undefined;
360
- commitHash: string | undefined;
361
- }
362
-
363
- export type GenerateCompletionState =
364
- | "unknown"
365
- | "initial-with-url"
366
- | "initial-without-url"
367
- | "generating"
368
- | "success"
369
- | "abort"
370
- | "error"
371
- | "close";
372
-
373
- export interface GenerateCompletionStepState {
374
- type: "state";
375
- previousState: GenerateCompletionState;
376
- newState: GenerateCompletionState;
377
- }
378
-
379
- export interface GenerateCompletionStepClose {
380
- type: "close";
381
- }
382
-
383
- export type GenerateCompletionStep = { timestamp?: number } & (
384
- | GenerateCompletionStepPlanning
385
- | GenerateCompletionStepStart
386
- | GenerateCompletionStepDelta
387
- | GenerateCompletionStepUser
388
- | GenerateCompletionStepFile
389
- | GenerateCompletionStepDiff
390
- | GenerateCompletionStepTool
391
- | GenerateCompletionStepError
392
- | GenerateCompletionStepContinue
393
- | GenerateCompletionStepWaitForInput
394
- | GenerateCompletionStepAbort
395
- | GenerateCompletionStepDone
396
- | GenerateCompletionStepUserInput
397
- | GenerateCompletionStepText
398
- | GenerateCompletionStepRestore
399
- | GenerateCompletionStepState
400
- | GenerateCompletionStepToolResult
401
- );
402
-
403
- export interface ApplyActionsResult {
404
- filePath: string;
405
- addedLines: number;
406
- removedLines: number;
407
- action: "create" | "update" | "delete";
408
- content?: string;
409
- oldContent?: string;
410
- }
411
-
412
- export interface GenerateUserMessage {
413
- userPrompt: string;
414
- displayPrompt?: string;
415
- files?: string[];
416
- includeBaseFiles?: boolean;
417
- skipSearch?: boolean;
418
- attachments?: Attachment[];
419
- }
420
-
421
- export interface UserInput {
422
- userMessage: GenerateUserMessage | undefined;
423
- userPrompt: string;
424
- attachments: Attachment[];
425
- files: ProjectFile[];
426
- searchResponse: CodebaseSearchResponse | null;
427
- rerankFiles?: number;
428
- mostRelevantFile: string | null;
429
- toolResults: ContentMessageItemToolResult[];
430
- role: "user" | "agent";
431
- }
432
-
433
- export interface CodegenTurn {
434
- state: "running" | "done" | "error" | "aborted" | "reverted";
435
- unixTime: number;
436
- completionId: string;
437
- title: string;
438
- nextUrl: string | undefined;
439
- role: "user" | "agent";
440
- actions: ActionItem[];
441
- sentiment: "positive" | "negative" | "undo" | undefined;
442
- applyResults: ApplyActionsResult[];
443
- userMessage: GenerateUserMessage | undefined;
444
- beforeCommit: string | undefined;
445
- afterCommit: string | undefined;
446
- }
447
-
448
- export interface CodegenFeedback {
449
- id: string;
450
- feedbackText?: string;
451
- feedbackSentiment?: string;
452
- framework?: string;
453
- acceptedLines?: number;
454
- afterCommit?: string;
455
- }
456
-
457
- export interface CodegenSetLastCompletion {
458
- sessionId: string;
459
- lastCompletionId: string | undefined;
460
- }
461
-
462
- export interface GenerateCodeEventDone {
463
- type: "done";
464
- unixTime: number;
465
- stopReason: CompletionStopReason;
466
- id: string;
467
- actionTitle: string;
468
- content?: string;
469
- needsPagination: boolean;
470
- actions?: ActionItem[];
471
- suggestions: PromptSuggestion[];
472
- usage?: CodegenUsage;
473
- messageIndex: number;
474
- sessionUsage: number;
475
- nextUrl: string;
476
- }
477
-
478
- export interface GenerateCodeEventError {
479
- type: "error";
480
- stopReason: "error" | "limit";
481
- id: string;
482
- message: string;
483
- usage?: CodegenUsage;
484
- }
485
- export interface GenerateCodeEventPagination {
486
- type: "pagination";
487
- pop: number;
488
- page: number;
489
- id: string;
490
- }
491
-
492
- export interface GenerateCodeEventContinue {
493
- type: "continue";
494
- id: string;
495
- nextUrl: string;
496
- }
497
-
498
- export interface GenerateCodeEventDelta {
499
- type: "delta";
500
- content: string;
501
- }
502
-
503
- export interface GenerateCodeEventUser {
504
- type: "user";
505
- id: string;
506
- displayPrompt: string | undefined;
507
- role: "user" | "agent";
508
- }
509
-
510
- export type GenerateCodeEvent =
511
- | ActionItem
512
- | GenerateCodeEventDone
513
- | GenerateCodeEventContinue
514
- | GenerateCodeEventPagination
515
- | GenerateCodeEventDelta
516
- | GenerateCodeEventError
517
- | GenerateCodeEventUser;
package/src/completion.ts DELETED
@@ -1,174 +0,0 @@
1
- import type {
2
- BuilderContent,
3
- BuilderElement,
4
- Component,
5
- } from "@builder.io/sdk";
6
- import type { Message, MessageParam, Attachment } from "./messages.js";
7
- import type { BuilderModel } from "./events.js";
8
-
9
- export type { BuilderContent, BuilderElement, Component };
10
-
11
- export interface CompletionOptions {
12
- /**
13
- * How this assistant is being used. For example, "content-editor"
14
- * is used when the assistant is being used in the Builder.io content editor.
15
- */
16
- assistantType?: string;
17
-
18
- /**
19
- * LLM Model identifier to lookup which sdk and model to use.
20
- * If not provided the default model will be used.
21
- * Note: This is not the Builder.io data model.
22
- */
23
- modelId?: string;
24
-
25
- /**
26
- * The unique LOCAL identifier of the thread to submit the user message to.
27
- * This is used to identify the thread with our own id (openai assistant id is different)
28
- */
29
- id: string;
30
-
31
- /**
32
- * The unique OPENAI assistant id of the thread to submit the user message to.
33
- * If the assistantThreadId is not provided, a new thread will be created.
34
- */
35
- assistantThreadId?: string;
36
-
37
- /**
38
- * The message history of the conversation, user prompt then assistant response.
39
- * The messages are ordered from oldest to newest. The last message in the array
40
- * is the message that the user has just sent.
41
- */
42
- messages: (MessageParam | Message)[];
43
-
44
- /**
45
- * Which platform (framework) the the user has choosen to get help with.
46
- */
47
- platformId?: string;
48
-
49
- /**
50
- * The user id of the user sending the message.
51
- * This is used to track the user's progress in the conversation.
52
- * User id is stored in localStorage for this domain, its not the builder user id.
53
- */
54
- userId: string;
55
-
56
- /**
57
- * The state of the builder editor.
58
- */
59
- builderState?: BuilderEditorState;
60
-
61
- /**
62
- * Additional console logs
63
- */
64
- debug?: boolean;
65
-
66
- /**
67
- * Date.now() timestamp of when the assistant was started.
68
- * This is used to calculate the time taken between all events.
69
- */
70
- startMs?: number;
71
- /**
72
- * If events should be streamed back throughout the process.
73
- *
74
- * Setting to `false` will skip any intermediate processing and emitting
75
- * events while collecting LLM deltas, but will only emit the final result.
76
- *
77
- * Defaults to `true`.
78
- */
79
- stream?: boolean;
80
- /**
81
- * Provide a system prompt id to lookup a pre-defined system prompt
82
- * text sent to the LLM. Must be a pre-defined system prompt id!
83
- */
84
- systemPromptIds?: {
85
- "content-edit"?: string;
86
- };
87
- /**
88
- * Option on how this call should handle the conversation thread.
89
- *
90
- * `persist`:
91
- * - When there is no CompletionOptions `id`, it'll create a new thread id
92
- * - When given an existing `id`, it'll look up the past thread messages and prefix the messages
93
- *
94
- * `ephemeral`:
95
- * - Creates a new conversation each time, ignoring any existing thread history
96
- * - Will not save the conversation for future use
97
- *
98
- * Defaults to `persist`
99
- */
100
- thread?: "persist" | "ephemeral";
101
-
102
- attachments?: Attachment[];
103
- }
104
-
105
- export interface BuilderEditorState {
106
- /**
107
- * The active locale of the builder editor.
108
- */
109
- activeLocale?: string;
110
- /**
111
- * The locale of the provided builder content.
112
- */
113
- contentLocale?: string;
114
- /**
115
- * Top level Builder content. The data.blocks array contains the BuilderElement.
116
- */
117
- content?: BuilderContent;
118
- /**
119
- * Builder custom components.
120
- */
121
- components?: Component[];
122
- /**
123
- * Builder design tokens.
124
- */
125
- designTokens?: Record<string, string>;
126
- /**
127
- * Builder model. (not the LLM model)
128
- */
129
- model?: BuilderModel;
130
- /**
131
- * Other models in the Builder account
132
- */
133
- otherModels?: BuilderModel[];
134
- /**
135
- * The URL that the Builder content preview is pointing to.
136
- */
137
- previewUrl?: string;
138
- /**
139
- * Selected ids in the builder.
140
- */
141
- selectedIds?: string[];
142
- /**
143
- * Builder space id.
144
- */
145
- spaceId?: string;
146
- /**
147
- * Builder user id.
148
- */
149
- userId?: string;
150
- /**
151
- * Email of the user in the builder.
152
- */
153
- userEmail?: string;
154
- /**
155
- * User's jobs
156
- */
157
- userJobs?: string[];
158
- /**
159
- * Builder session id.
160
- */
161
- sessionId?: string;
162
- /**
163
- * Custom instructions that could be add into the prompt.
164
- */
165
- customInstructions?: Record<string, string>;
166
-
167
- // A URL to use as design inspiration when generating content
168
- styleInspirationURL?: string;
169
-
170
- /**
171
- * All targeting attributes of the content.
172
- */
173
- allTargetingAttributes?: Record<string, any>;
174
- }