@builder.io/ai-utils 0.3.7 → 0.3.9

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