@builder.io/ai-utils 0.3.5 → 0.3.6

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Builder.io AI types and utilities
2
+
3
+ Shared types between AI systems, threads, servers, etc.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "Builder.io AI utils",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/codegen.ts ADDED
@@ -0,0 +1,558 @@
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 GetBuildOutputToolInput {}
95
+
96
+ export interface BashToolInput {
97
+ command?: string;
98
+ restart?: boolean;
99
+ }
100
+
101
+ export interface CodeGenToolMap {
102
+ view_path: ViewPathToolInput;
103
+ glob_search: GlobSearchToolInput;
104
+ grep_search: GrepSearchToolInput;
105
+ get_rule: GetRuleToolInput;
106
+ get_build_output: GetBuildOutputToolInput;
107
+ bash: BashToolInput;
108
+ }
109
+
110
+ export type CodeGenTools = keyof CodeGenToolMap;
111
+
112
+ export type CodeGenMode =
113
+ | "exact" // @deprecated
114
+ | "precise" // tries to match the design as close
115
+ | "precise_vision" // tries to match the design as close, also uses vision to match
116
+ | "creative" // adapts the design to some generic design language
117
+ | "creative_vision" // adapts the design to some generic design language, also uses vision to match
118
+ | "creative_only_vision"; // adapts the design to some generic design language, but only uses vision to match
119
+
120
+ export interface CodeGenInputOptions {
121
+ position: string;
122
+ eventName?: string;
123
+ sessionId: string;
124
+
125
+ codeGenMode?: "fast" | "quality" | "quality-v3";
126
+ url?: string;
127
+ diffActions?: boolean;
128
+ planningPrompt?: boolean;
129
+ customInstructions?: CustomInstruction[];
130
+ userPrompt?: string;
131
+ ephemeralUserPrompt?: string;
132
+ displayUserPrompt?: string;
133
+ files?: ProjectFile[];
134
+ rerankFiles?: number;
135
+ toolResults?: ContentMessageItemToolResult[];
136
+ attachments?: Attachment[];
137
+ beforeCommit?: string;
138
+
139
+ // Code options
140
+ builderContent?: BuilderContent;
141
+ framework?: CodeGenFramework;
142
+ styleLibrary?: CodeGenStyleLibrary;
143
+ typescript?: boolean;
144
+ userContext?: UserContext;
145
+
146
+ enabledTools?: CodeGenTools[];
147
+
148
+ // Options
149
+ maxTokens?: number;
150
+ maxPages?: number;
151
+ autoContinue?: number;
152
+ promptCaching?: boolean;
153
+ isAutoContinue?: boolean;
154
+ llmSuggestions?: boolean;
155
+ conclusionText?: boolean;
156
+
157
+ searchResponse?: any | null;
158
+
159
+ // Prettier options
160
+ prettierConfig?: PrettierOptions;
161
+
162
+ /** @deprecated */
163
+ history?: (UserMessageParam | AssistantMessageParam)[];
164
+ /** @deprecated */
165
+ prevId?: string;
166
+ /** @deprecated */
167
+ nextPage?: boolean;
168
+ /** @deprecated */
169
+ vcpId?: string;
170
+ }
171
+
172
+ export type Feature = "component-mapping";
173
+
174
+ export interface CodegenUsage {
175
+ total: number;
176
+ fast: number;
177
+ quality: number;
178
+ features: Feature[];
179
+ limits: {
180
+ aiGeneration: number;
181
+ aiGenerationContextWindow: number;
182
+ };
183
+ }
184
+
185
+ export interface PromptSuggestion {
186
+ type:
187
+ | "missing-imports"
188
+ | "lazy-code"
189
+ | "syntax-error"
190
+ | "llm-suggested"
191
+ | "diff-apply";
192
+
193
+ filePath?: string;
194
+ line?: number;
195
+ importance: "high" | "medium" | "low";
196
+ column?: number;
197
+ summary: string;
198
+ prompt: string;
199
+ }
200
+
201
+ export interface ActionItem {
202
+ type:
203
+ | "file"
204
+ | "text"
205
+ | "diff"
206
+ | "thinking"
207
+ | "tool"
208
+ | "suggestion"
209
+ | "tool_result";
210
+ id?: string;
211
+ content: string;
212
+ filePath?: string;
213
+ artifactTitle?: string;
214
+ actionTitle?: string;
215
+ synthetic?: boolean;
216
+ incomplete?: boolean;
217
+ suggestions?: PromptSuggestion[];
218
+ errors?: string[];
219
+ }
220
+
221
+ export interface RepoInfo {
222
+ remoteUrl: string;
223
+ defaultBranch: string;
224
+ currentBranch: string;
225
+ commit: string;
226
+ }
227
+
228
+ export interface CodebaseSearchOptions {
229
+ repoInfo?: RepoInfo;
230
+ query: string;
231
+ selectedFiles?: string[];
232
+ sessionId: string;
233
+ files?: string[];
234
+ packageJson?: string;
235
+ limit?: number;
236
+ includeContent?: boolean;
237
+ }
238
+
239
+ export interface CodebaseSearchResponse {
240
+ id: string;
241
+ relevantPaths: string[];
242
+ grepQueries: string[];
243
+ streamMeta: any;
244
+ ranked: RankedResult[];
245
+ }
246
+
247
+ export interface RankedResult {
248
+ index: number;
249
+ filePath: string;
250
+ startIndex: number;
251
+ endIndex: number;
252
+ score: number;
253
+ id: string;
254
+ content?: string;
255
+ }
256
+
257
+ export interface GenerateCompletionStepThinking {
258
+ type: "thinking";
259
+ }
260
+
261
+ export interface FileInfo {
262
+ filePath: string;
263
+ size: number;
264
+ }
265
+
266
+ export interface GenerateCompletionStepUserInput {
267
+ type: "user-input";
268
+ prompt: string;
269
+ files: FileInfo[];
270
+ }
271
+
272
+ export interface GenerateCompletionStepToolResult {
273
+ type: "agent-input";
274
+ toolResults: ContentMessageItemToolResult[];
275
+ }
276
+
277
+ export interface GenerateCompletionStepPlanning {
278
+ type: "planning";
279
+ content: string;
280
+ }
281
+
282
+ export interface GenerateCompletionStepUser {
283
+ type: "user";
284
+ displayPrompt: string | undefined;
285
+ id: string;
286
+ role: "user" | "agent";
287
+ }
288
+
289
+ export interface GenerateCompletionStepFile {
290
+ type: "file";
291
+ filePath: string;
292
+ content: string;
293
+ title: string;
294
+ id: string;
295
+ }
296
+
297
+ export interface GenerateCompletionStepDiff {
298
+ type: "diff";
299
+ filePath: string;
300
+ content: string;
301
+ title: string;
302
+ id: string;
303
+ }
304
+
305
+ export interface GenerateCompletionStepTool {
306
+ type: "tool";
307
+ name: string;
308
+ id: string;
309
+ content: string;
310
+ }
311
+
312
+ export interface GenerateCompletionStepText {
313
+ type: "text";
314
+ content: string;
315
+ }
316
+
317
+ export interface GenerateCompletionStepDone {
318
+ type: "done";
319
+ id: string;
320
+ applyResults: ApplyActionsResult[];
321
+ actions: ActionItem[];
322
+ usage: CodegenUsage | undefined;
323
+ url?: string;
324
+ stopReason: CompletionStopReason;
325
+ hasChanges: boolean;
326
+ }
327
+
328
+ export interface GenerateCompletionStepStart {
329
+ type: "start";
330
+ name: string;
331
+ id: string | undefined;
332
+ title: string;
333
+ content: string;
334
+ }
335
+
336
+ export interface GenerateCompletionStepDelta {
337
+ type: "delta";
338
+ name: string;
339
+ delta: string;
340
+ }
341
+
342
+ export interface GenerateCompletionStepError {
343
+ type: "error";
344
+ id?: string;
345
+ stopReason?: "error" | "limit";
346
+ metadata?: any;
347
+ message: string;
348
+ usage?: CodegenUsage;
349
+ }
350
+
351
+ export interface GenerateCompletionStepContinue {
352
+ type: "continue";
353
+ id: string;
354
+ url: string;
355
+ }
356
+
357
+ export interface GenerateCompletionStepWaitForInput {
358
+ type: "wait-for-input";
359
+ state: GenerateCompletionState;
360
+ }
361
+
362
+ export interface GenerateCompletionStepAbort {
363
+ type: "user-abort";
364
+ }
365
+
366
+ export interface GenerateCompletionStepRestore {
367
+ type: "restore";
368
+ location: "before" | "after";
369
+ files: string[];
370
+ lastCompletionId: string | undefined;
371
+ commitHash: string | undefined;
372
+ }
373
+
374
+ export type GenerateCompletionState =
375
+ | "unknown"
376
+ | "initial-with-url"
377
+ | "initial-without-url"
378
+ | "generating"
379
+ | "success"
380
+ | "abort"
381
+ | "error"
382
+ | "close";
383
+
384
+ export interface GenerateCompletionStepState {
385
+ type: "state";
386
+ previousState: GenerateCompletionState;
387
+ newState: GenerateCompletionState;
388
+ }
389
+
390
+ export interface GenerateCompletionStepClose {
391
+ type: "close";
392
+ }
393
+
394
+ export interface GenerateCompletionStepStdio {
395
+ type: "stdio";
396
+ stream: "stdout" | "stderr";
397
+ source: "run-command";
398
+ content: string;
399
+ }
400
+
401
+ export interface GenerateCompletionStepSession {
402
+ type: "session";
403
+ title: string | undefined;
404
+ beforeCommit: string | undefined;
405
+ createdUnixTime: number;
406
+ updatedUnixTime: number;
407
+ id: string;
408
+ hasChanges: boolean;
409
+ }
410
+
411
+ export type GenerateCompletionStep = { timestamp?: number } & (
412
+ | GenerateCompletionStepPlanning
413
+ | GenerateCompletionStepStart
414
+ | GenerateCompletionStepDelta
415
+ | GenerateCompletionStepUser
416
+ | GenerateCompletionStepFile
417
+ | GenerateCompletionStepDiff
418
+ | GenerateCompletionStepTool
419
+ | GenerateCompletionStepError
420
+ | GenerateCompletionStepContinue
421
+ | GenerateCompletionStepWaitForInput
422
+ | GenerateCompletionStepAbort
423
+ | GenerateCompletionStepDone
424
+ | GenerateCompletionStepUserInput
425
+ | GenerateCompletionStepText
426
+ | GenerateCompletionStepRestore
427
+ | GenerateCompletionStepState
428
+ | GenerateCompletionStepStdio
429
+ | GenerateCompletionStepSession
430
+ | GenerateCompletionStepToolResult
431
+ );
432
+
433
+ export interface ApplyActionsResult {
434
+ filePath: string;
435
+ addedLines: number;
436
+ removedLines: number;
437
+ action: "create" | "update" | "delete";
438
+ content?: string;
439
+ oldContent?: string;
440
+ }
441
+
442
+ export interface GenerateUserMessage {
443
+ userPrompt: string;
444
+ ephemeralUserPrompt?: string;
445
+ displayPrompt?: string;
446
+ files?: string[];
447
+ includeBaseFiles?: boolean;
448
+ skipSearch?: boolean;
449
+ attachments?: Attachment[];
450
+ }
451
+
452
+ export interface UserInput {
453
+ userMessage: GenerateUserMessage | undefined;
454
+ userPrompt: string;
455
+ attachments: Attachment[];
456
+ files: ProjectFile[];
457
+ searchResponse: CodebaseSearchResponse | null;
458
+ rerankFiles?: number;
459
+ mostRelevantFile: string | null;
460
+ toolResults: ContentMessageItemToolResult[];
461
+ role: "user" | "agent";
462
+ }
463
+
464
+ export interface CodegenTurn {
465
+ state: "running" | "done" | "error" | "aborted" | "reverted";
466
+ unixTime: number;
467
+ completionId: string;
468
+ title: string;
469
+ nextUrl: string | undefined;
470
+ role: "user" | "agent";
471
+ actions: ActionItem[];
472
+ sentiment: "positive" | "negative" | "undo" | undefined;
473
+ applyResults: ApplyActionsResult[];
474
+ userMessage: GenerateUserMessage | undefined;
475
+ beforeCommit: string | undefined;
476
+ afterCommit: string | undefined;
477
+ }
478
+
479
+ export interface GetSessionTurnsResult {
480
+ turns: CodegenTurn[];
481
+ sessionId: string;
482
+ initialUrl: string | undefined;
483
+ beforeCommit: string | undefined;
484
+ title: string | undefined;
485
+ createdUnixTime: number | undefined;
486
+ updatedUnixTime: number | undefined;
487
+ }
488
+
489
+ export interface CodegenFeedback {
490
+ id: string;
491
+ feedbackText?: string;
492
+ feedbackSentiment?: string;
493
+ framework?: string;
494
+ acceptedLines?: number;
495
+ afterCommit?: string;
496
+ }
497
+
498
+ export interface CodegenSetLastCompletion {
499
+ sessionId: string;
500
+ lastCompletionId: string | undefined;
501
+ }
502
+
503
+ export interface GenerateCodeEventDone {
504
+ type: "done";
505
+ unixTime: number;
506
+ stopReason: CompletionStopReason;
507
+ id: string;
508
+ actionTitle: string;
509
+ content?: string;
510
+ needsPagination: boolean;
511
+ actions?: ActionItem[];
512
+ suggestions: PromptSuggestion[];
513
+ usage?: CodegenUsage;
514
+ messageIndex: number;
515
+ sessionUsage: number;
516
+ nextUrl: string;
517
+ }
518
+
519
+ export interface GenerateCodeEventError {
520
+ type: "error";
521
+ stopReason: "error" | "limit";
522
+ id: string;
523
+ message: string;
524
+ usage?: CodegenUsage;
525
+ }
526
+ export interface GenerateCodeEventPagination {
527
+ type: "pagination";
528
+ pop: number;
529
+ page: number;
530
+ id: string;
531
+ }
532
+
533
+ export interface GenerateCodeEventContinue {
534
+ type: "continue";
535
+ id: string;
536
+ nextUrl: string;
537
+ }
538
+
539
+ export interface GenerateCodeEventDelta {
540
+ type: "delta";
541
+ content: string;
542
+ }
543
+
544
+ export interface GenerateCodeEventUser {
545
+ type: "user";
546
+ id: string;
547
+ displayPrompt: string | undefined;
548
+ role: "user" | "agent";
549
+ }
550
+
551
+ export type GenerateCodeEvent =
552
+ | ActionItem
553
+ | GenerateCodeEventDone
554
+ | GenerateCodeEventContinue
555
+ | GenerateCodeEventPagination
556
+ | GenerateCodeEventDelta
557
+ | GenerateCodeEventError
558
+ | GenerateCodeEventUser;