builder.io 1.6.28 → 1.6.29

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.
@@ -1,71 +1,99 @@
1
1
  import type { DevToolsSys } from "../types";
2
2
  import type { CLIArgs } from "./index";
3
3
  import { type Credentials } from "./credentials";
4
- import { type Checkpoint } from "./incremental-tsc";
5
- import type { ApplyActionsResult, Attachment, CodebaseSearchResponse, ContentMessageItemToolResult, CustomInstruction, GenerateCompletionStep, GenerateUserMessage, ProjectFile, UserContext } from "$/ai-utils";
4
+ import type { CodegenTurn, CustomInstruction, GenerateCompletionStep, GenerateUserMessage, UserContext } from "$/ai-utils";
6
5
  import prettier from "prettier";
7
- interface Turn {
8
- completionId: string;
9
- nextUrl: string | undefined;
10
- originalFiles: {
11
- path: string;
12
- content: Uint8Array | null;
13
- }[];
14
- isUserMessage: boolean;
15
- toolResults: ContentMessageItemToolResult[];
16
- sentiment?: "positive" | "negative" | "undo";
17
- applyResults: ApplyActionsResult[];
18
- projectFiles: ProjectFile[];
19
- userInput: UserInput;
20
- }
21
6
  type State = "unknown" | "initial-with-url" | "initial-without-url" | "generating" | "success" | "abort" | "error";
22
7
  export interface SessionContext {
23
8
  sessionId: string;
24
- turns: Turn[];
9
+ turns: CodegenTurn[];
25
10
  selectedFilePaths: Map<string, number>;
26
11
  customInstructions: CustomInstruction[];
27
12
  userContext: UserContext;
28
13
  prettierConfig: prettier.Config | null;
29
14
  state: State;
30
15
  }
31
- export interface UserInput {
32
- userPrompt: string;
33
- attachments: Attachment[];
34
- sentiment: "positive" | "negative" | "undo";
35
- files: ProjectFile[];
36
- searchResponse: CodebaseSearchResponse | null;
37
- rerankFiles?: number;
38
- mostRelevantFile: string | null;
39
- role: "user" | "agent";
16
+ export interface CodeGenSessionOptionsBase {
17
+ sys: DevToolsSys;
18
+ credentials: Credentials;
19
+ args: CLIArgs;
20
+ position: string;
21
+ mode?: "quality" | "quality-v3" | "fast";
22
+ fusion?: boolean;
23
+ fusionRemote?: string;
24
+ fusionAutoInitGit?: boolean;
25
+ featureBranch?: string;
26
+ }
27
+ export interface CodeGenSessionOptionsSession extends CodeGenSessionOptionsBase {
28
+ sessionOrCompletionId?: string;
29
+ }
30
+ export interface CodeGenSessionOptionsInitialUrl extends CodeGenSessionOptionsBase {
31
+ initialUrl: string;
40
32
  }
33
+ export type CodeGenSessionOptions = CodeGenSessionOptionsSession | CodeGenSessionOptionsInitialUrl;
34
+ export declare function createCodeSession(options: CodeGenSessionOptions): Promise<CodeGenSession>;
41
35
  export declare class CodeGenSession {
42
36
  #private;
43
- constructor(sys: DevToolsSys, credentials: Credentials, args: CLIArgs, position: string, initialUrl?: string, mode?: "quality" | "quality-v3" | "fast");
37
+ constructor(options: CodeGenSessionOptions);
38
+ initializeSession(): Promise<void>;
39
+ /**
40
+ * Get the current commit hash
41
+ */
42
+ getCurrentCommitHash(): Promise<string | undefined>;
43
+ /**
44
+ * Get the feature branch name
45
+ */
46
+ getFeatureBranch(): string | undefined;
47
+ /**
48
+ * Get the AI branch name
49
+ */
50
+ getAiBranch(): string | undefined;
51
+ /**
52
+ * Helper to run git commands
53
+ */
54
+ runGitCommand(command: string): Promise<string>;
55
+ /**
56
+ * Check if Fusion is enabled for this session
57
+ */
58
+ isFusionEnabled(): boolean;
44
59
  setDebug(debug: boolean): void;
45
60
  getAllFiles(): Promise<string[]>;
46
61
  isNextPage(): boolean;
47
- getSessionId(): Promise<string>;
62
+ getSessionId(): string;
48
63
  getSpaceId(): string | undefined;
49
- undoLastUserMessage(dryRun?: boolean): Promise<string[]>;
64
+ /**
65
+ * Core function to restore the codebase to a state that matches a predicate.
66
+ * This is the main function that handles both git-based and file-based restoration.
67
+ *
68
+ * @param predicate Function that takes a turn and its index and returns true if we should restore up to that turn
69
+ * @param dryRun If true, only simulate the restoration without making changes
70
+ * @returns Array of file paths that were changed
71
+ */
72
+ restore(location: "before" | "after", predicate: (turn: CodegenTurn | null, index: number) => boolean, dryRun?: boolean): Promise<string[] | null>;
73
+ restoreHEAD(): Promise<string[] | null>;
74
+ restoreAll(): Promise<string[] | null>;
75
+ restoreBeforeCompletionId(completionId: string): Promise<string[] | null>;
76
+ /**
77
+ * Undo all changes back to the last user message
78
+ */
79
+ undoLastUserMessage(dryRun?: boolean): Promise<string[] | null>;
50
80
  getLastCompletionId(): string | undefined;
51
81
  getCurrentState(): State;
52
- getLastTurn(): Turn | undefined;
82
+ getLastTurn(): CodegenTurn | undefined;
53
83
  getNextUrl(): string | undefined;
54
84
  getNextMessage(): Promise<GenerateUserMessage>;
55
85
  sendFeedback(sentiment: "positive" | "negative" | "undo", message?: string, lastCompletionId?: string | undefined): Promise<void>;
56
86
  hasUndoChanges(): Promise<boolean>;
57
87
  isBusy(): boolean;
58
88
  sendMessage(message: GenerateUserMessage): void;
59
- isEventLoopRunning(): boolean;
60
- getTurns(): void;
61
- getSessionContext(): Promise<SessionContext>;
89
+ getTurns(): CodegenTurn[];
90
+ getSessionContext(): SessionContext;
62
91
  abort(): void;
63
- stopEventLoop(): void;
64
- startEventLoop(onStep: (step: GenerateCompletionStep) => void): Promise<void>;
65
- agentCompletion(userMessage: GenerateUserMessage, baselineCheckpoint: Checkpoint, signal: AbortSignal | undefined, onStep: (step: GenerateCompletionStep) => Promise<void> | void): Promise<Checkpoint>;
66
- getUserInput(userMessage: GenerateUserMessage, signal: AbortSignal | undefined): Promise<UserInput>;
92
+ stopEventLoop(): Promise<void>;
93
+ connectToEventLoop(shouldReplay: boolean, onStep: (step: GenerateCompletionStep) => void): () => void;
94
+ waitForEventLoop(): Promise<void>;
95
+ agentCompletion(userMessage: GenerateUserMessage, signal: AbortSignal | undefined, onStep: (step: GenerateCompletionStep) => Promise<void> | void): Promise<void>;
67
96
  }
68
- export declare const createSessionContext: (sys: DevToolsSys) => Promise<SessionContext>;
69
97
  export declare function transformStream(body: ReadableStream<Uint8Array> | null): AsyncGenerator<string, void, unknown>;
70
98
  export declare function getUserContext(sys: DevToolsSys): Promise<UserContext>;
71
99
  export declare function makeAsyncIterator<T>(): readonly [AsyncGenerator<T, void, void>, (event: T) => void, () => void];
@@ -61,4 +61,14 @@ export interface CLIArgs {
61
61
  silent?: boolean;
62
62
  /** Fusion project ID */
63
63
  projectId?: string;
64
+ /** Enable Fusion side-car branch workflow */
65
+ fusion?: boolean;
66
+ /** Remote URL for Fusion side-car branch storage */
67
+ fusionRemote?: string;
68
+ /** Auto-commit changes when session ends (for Fusion) */
69
+ fusionAutoCommit?: boolean;
70
+ /** Auto-initialize a git repository if none exists (for Fusion) */
71
+ fusionAutoInitGit?: boolean;
72
+ /** Push changes to origin after squash merge (for Fusion) */
73
+ fusionPushToOrigin?: boolean;
64
74
  }
@@ -0,0 +1,56 @@
1
+ import type { Duplex } from "node:stream";
2
+ import type { IncomingMessage } from "node:http";
3
+ export type SocketRequest = {
4
+ id: number;
5
+ jsonrpc: string;
6
+ method: string;
7
+ params: any;
8
+ };
9
+ export type SocketResponse<T = any> = {
10
+ id?: number | null;
11
+ jsonrpc: string;
12
+ result?: T;
13
+ notification?: string;
14
+ params?: any;
15
+ error?: {
16
+ code: number;
17
+ message: string;
18
+ data?: any;
19
+ };
20
+ };
21
+ export type SocketSendOptions = {
22
+ timeout?: number;
23
+ };
24
+ export type SocketQueue = {
25
+ type: "request" | "notification";
26
+ result?: SocketResponse["result"];
27
+ error?: SocketResponse["error"];
28
+ };
29
+ import type { ServerOptions } from "ws";
30
+ import type { WebSocket } from "ws";
31
+ type RegisterFn<T = any> = (params: T, socketId: string) => Promise<any> | any;
32
+ type SocketEvents = {
33
+ listening: () => Promise<void> | void;
34
+ connection: (socket: WebSocket, socketId: string) => Promise<void> | void;
35
+ disconnection: (socketId: string) => Promise<void> | void;
36
+ error: (error: Error) => Promise<void> | void;
37
+ "socket-error": (socketId: string, error: Error) => Promise<void> | void;
38
+ close: () => Promise<void> | void;
39
+ };
40
+ export declare function Server(opts: ServerOptions): {
41
+ on: <EventKey extends keyof SocketEvents>(event: EventKey, cb: SocketEvents[EventKey]) => void;
42
+ of: (ns: string) => {
43
+ emit: (name: string, ...params: any[]) => void;
44
+ clients: () => Map<string, WebSocket>;
45
+ register: <T = any>(method: string, fn: RegisterFn<T>) => void;
46
+ event: (name: string) => void;
47
+ };
48
+ event: (e: string) => void;
49
+ handleUpgrade: (req: IncomingMessage, socket: Duplex, upgradeHead: Buffer, callback?: (client: WebSocket, request: IncomingMessage) => void) => Promise<void>;
50
+ clients: () => Map<string, WebSocket>;
51
+ register: <T = any>(method: string, fn: RegisterFn<T>) => void;
52
+ emit: (name: string, ...params: any[]) => void;
53
+ notify: (name: string, socketId: string, ...params: any[]) => void;
54
+ close: () => Promise<unknown>;
55
+ };
56
+ export {};