builder.io 1.6.28 → 1.6.30

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,5 +1,6 @@
1
1
  import type { CodeGenTools, ContentMessageItemToolResult, ProjectFile } from "$/ai-utils";
2
2
  import type { DevToolsSys } from "../core";
3
+ import type { RunCommandCtx } from "./codegen";
3
4
  export interface LLMToolCalls {
4
5
  name: CodeGenTools;
5
6
  input: Record<string, any>;
@@ -10,10 +11,16 @@ export interface ToolResolution {
10
11
  isError: boolean;
11
12
  title?: string;
12
13
  }
13
- export declare function resolveToolCalls(sys: DevToolsSys, toolCalls: LLMToolCalls[]): Promise<{
14
- toolResults: ContentMessageItemToolResult[];
15
- projectFiles: ProjectFile[];
16
- }>;
14
+ export interface ProvidedToolContext {
15
+ commandCtx?: RunCommandCtx;
16
+ allowedCommands?: RegExp[];
17
+ }
18
+ export interface ToolContext extends ProvidedToolContext {
19
+ sys: DevToolsSys;
20
+ files: ProjectFile[];
21
+ signal: AbortSignal | undefined;
22
+ }
23
+ export declare function resolveToolCalls(toolContext: ToolContext, toolCalls: LLMToolCalls[]): Promise<ContentMessageItemToolResult[]>;
17
24
  interface RipgrepMatch {
18
25
  path: string;
19
26
  lineNumber: number;
@@ -1,72 +1,111 @@
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, GenerateCompletionState, 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;
6
+ import { type ProvidedToolContext } from "./code-tools";
7
+ import type { ChildProcessWithoutNullStreams } from "child_process";
8
+ export interface RunCommandCtx {
9
+ command: string;
10
+ getAllStdout: () => string;
11
+ getAllStderr: () => string;
12
+ getOutput: () => string;
13
+ pid: number | undefined;
14
+ process: ChildProcessWithoutNullStreams;
15
+ onStdout: (callback: (data: string) => void) => void;
16
+ onStderr: (callback: (data: string) => void) => void;
20
17
  }
21
- type State = "unknown" | "initial-with-url" | "initial-without-url" | "generating" | "success" | "abort" | "error";
22
18
  export interface SessionContext {
23
19
  sessionId: string;
24
- turns: Turn[];
20
+ turns: CodegenTurn[];
25
21
  selectedFilePaths: Map<string, number>;
26
22
  customInstructions: CustomInstruction[];
27
23
  userContext: UserContext;
28
24
  prettierConfig: prettier.Config | null;
29
- state: State;
25
+ state: GenerateCompletionState;
30
26
  }
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";
27
+ export interface CodeGenSessionOptionsBase {
28
+ sys: DevToolsSys;
29
+ credentials: Credentials;
30
+ args: CLIArgs;
31
+ position: string;
32
+ mode?: "quality" | "quality-v3" | "fast";
33
+ fusion?: boolean;
34
+ fusionRemote?: string;
35
+ fusionAutoInitGit?: boolean;
36
+ featureBranch?: string;
37
+ providedToolContext?: ProvidedToolContext;
40
38
  }
39
+ export interface CodeGenSessionOptionsSession extends CodeGenSessionOptionsBase {
40
+ sessionOrCompletionId?: string;
41
+ }
42
+ export interface CodeGenSessionOptionsInitialUrl extends CodeGenSessionOptionsBase {
43
+ initialUrl: string;
44
+ }
45
+ export type CodeGenSessionOptions = CodeGenSessionOptionsSession | CodeGenSessionOptionsInitialUrl;
46
+ export declare function createCodeSession(options: CodeGenSessionOptions): Promise<CodeGenSession>;
41
47
  export declare class CodeGenSession {
42
48
  #private;
43
- constructor(sys: DevToolsSys, credentials: Credentials, args: CLIArgs, position: string, initialUrl?: string, mode?: "quality" | "quality-v3" | "fast");
49
+ constructor(options: CodeGenSessionOptions);
50
+ initializeSession(): Promise<void>;
51
+ /**
52
+ * Get the current commit hash
53
+ */
54
+ getCurrentCommitHash(): Promise<string | undefined>;
55
+ /**
56
+ * Get the feature branch name
57
+ */
58
+ getFeatureBranch(): string | undefined;
59
+ /**
60
+ * Get the AI branch name
61
+ */
62
+ getAiBranch(): string | undefined;
63
+ /**
64
+ * Helper to run git commands
65
+ */
66
+ runGitCommand(command: string): Promise<string>;
67
+ /**
68
+ * Check if Fusion is enabled for this session
69
+ */
70
+ isFusionEnabled(): boolean;
44
71
  setDebug(debug: boolean): void;
45
72
  getAllFiles(): Promise<string[]>;
46
73
  isNextPage(): boolean;
47
- getSessionId(): Promise<string>;
74
+ getSessionId(): string;
48
75
  getSpaceId(): string | undefined;
49
- undoLastUserMessage(dryRun?: boolean): Promise<string[]>;
76
+ /**
77
+ * Core function to restore the codebase to a state that matches a predicate.
78
+ * This is the main function that handles both git-based and file-based restoration.
79
+ *
80
+ * @param predicate Function that takes a turn and its index and returns true if we should restore up to that turn
81
+ * @param dryRun If true, only simulate the restoration without making changes
82
+ * @returns Array of file paths that were changed
83
+ */
84
+ restore(location: "before" | "after", predicate: (turn: CodegenTurn | null, index: number) => boolean, dryRun?: boolean): Promise<string[] | null>;
85
+ restoreHEAD(): Promise<string[] | null>;
86
+ restoreAll(): Promise<string[] | null>;
87
+ restoreBeforeCompletionId(completionId: string): Promise<string[] | null>;
88
+ /**
89
+ * Undo all changes back to the last user message
90
+ */
91
+ undoLastUserMessage(dryRun?: boolean): Promise<string[] | null>;
50
92
  getLastCompletionId(): string | undefined;
51
- getCurrentState(): State;
52
- getLastTurn(): Turn | undefined;
93
+ getCurrentState(): GenerateCompletionState;
94
+ getLastTurn(): CodegenTurn | undefined;
53
95
  getNextUrl(): string | undefined;
54
96
  getNextMessage(): Promise<GenerateUserMessage>;
55
97
  sendFeedback(sentiment: "positive" | "negative" | "undo", message?: string, lastCompletionId?: string | undefined): Promise<void>;
56
98
  hasUndoChanges(): Promise<boolean>;
57
- isBusy(): boolean;
58
99
  sendMessage(message: GenerateUserMessage): void;
59
- isEventLoopRunning(): boolean;
60
- getTurns(): void;
61
- getSessionContext(): Promise<SessionContext>;
100
+ getTurns(): CodegenTurn[];
101
+ getSessionContext(): SessionContext;
62
102
  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>;
103
+ stopEventLoop(): Promise<void>;
104
+ close(): Promise<void>;
105
+ connectToEventLoop(shouldReplay: boolean, onStep: (step: GenerateCompletionStep) => void): () => void;
106
+ waitForEventLoop(): Promise<void>;
107
+ agentCompletion(userMessage: GenerateUserMessage, signal: AbortSignal | undefined, onStep: (step: GenerateCompletionStep) => Promise<void> | void): Promise<void>;
67
108
  }
68
- export declare const createSessionContext: (sys: DevToolsSys) => Promise<SessionContext>;
69
109
  export declare function transformStream(body: ReadableStream<Uint8Array> | null): AsyncGenerator<string, void, unknown>;
70
110
  export declare function getUserContext(sys: DevToolsSys): Promise<UserContext>;
71
111
  export declare function makeAsyncIterator<T>(): readonly [AsyncGenerator<T, void, void>, (event: T) => void, () => void];
72
- export {};
@@ -37,28 +37,8 @@ export interface CLIArgs {
37
37
  cwd?: string;
38
38
  /** Debug mode */
39
39
  debug?: boolean;
40
- /** Port number for the dev server */
41
- port?: number;
42
- /** Port number for the dev server (shorthand) */
43
- p?: number;
44
- /** Dev server command to execute */
45
- command?: string;
46
- /** Dev server command to execute (shorthand) */
47
- c?: string;
48
- /** Skip authentication for testing purposes */
49
- noAuth?: boolean;
50
- /** Skip authentication for testing purposes (flag form) */
51
- auth?: boolean;
52
- /** Use development server instead of production for launch command */
53
- dev?: boolean;
54
- /** Skip browser auto-open */
55
- noOpen?: boolean;
56
- /** Skip browser auto-open (flag form) */
57
- open?: boolean;
58
40
  /** Raw command line arguments */
59
41
  _: string[];
60
- /** Silent mode for launch command */
61
- silent?: boolean;
62
- /** Fusion project ID */
63
- projectId?: string;
42
+ /** Auto-initialize a git repository if none exists (for Fusion) */
43
+ fusionAutoInitGit?: boolean;
64
44
  }
@@ -0,0 +1,65 @@
1
+ import type { EnsureConfigResult } from "types";
2
+ export declare const GIT_APP_FOLDER = "code";
3
+ export declare const transformVolumePath: (volumePath?: string) => string;
4
+ export declare const navigateToVolumePath: (volumePath: string) => void;
5
+ export declare const navigateToGitAppFolder: () => void;
6
+ export type InstallOutcome = EnsureConfigResult["outcome"] | "install-failed";
7
+ export type InstallStatus = {
8
+ timestamp: string;
9
+ outcome: InstallOutcome;
10
+ packageManager: string;
11
+ buildTool: string;
12
+ rootDir: string;
13
+ error: string | undefined;
14
+ };
15
+ export type LaunchStatus = {
16
+ jsxPlugin?: Partial<InstallStatus>;
17
+ devTools?: {
18
+ version?: string;
19
+ };
20
+ stash?: {
21
+ completed?: boolean;
22
+ };
23
+ dependencies?: {
24
+ installed?: boolean;
25
+ error?: string | undefined;
26
+ };
27
+ gitRepo?: {
28
+ exists?: boolean;
29
+ configured?: boolean;
30
+ repo?: string | undefined;
31
+ branch?: string;
32
+ error?: string | undefined;
33
+ current?: string | undefined;
34
+ expected?: string | undefined;
35
+ };
36
+ gitUser?: {
37
+ configured?: boolean;
38
+ };
39
+ gitDirectory?: {
40
+ exists?: boolean;
41
+ creating?: boolean;
42
+ };
43
+ volumeDirectory?: {
44
+ exists?: boolean;
45
+ };
46
+ args?: {
47
+ repoFullName?: string;
48
+ branchName?: string;
49
+ volumePath?: string;
50
+ };
51
+ initialization?: {
52
+ started?: boolean;
53
+ timestamp?: string;
54
+ completed?: boolean;
55
+ success?: boolean;
56
+ error?: string;
57
+ };
58
+ };
59
+ export declare const updateStatus: <T extends keyof LaunchStatus>(key: T, value: Partial<LaunchStatus[T]>) => void;
60
+ /**
61
+ * This path is derived from the logs file path, which is set by `initializeLogging`.
62
+ * Therefore make sure that `initializeLogging` has been called before calling this function.
63
+ */
64
+ export declare const getBuilderStatusFilePath: () => string;
65
+ export declare const getConfigStatus: () => LaunchStatus;
@@ -1,7 +1,7 @@
1
1
  import type { DevToolsSys } from "@builder.io/dev-tools/core";
2
- import type { CLIArgs } from "../index";
3
- import type { EnsureConfigResult } from "types";
4
- export type InstallOutcome = EnsureConfigResult["outcome"] | "install-failed";
5
- export declare const installJsxPlugin: (sys: DevToolsSys, args: CLIArgs) => Promise<{
2
+ import { type InstallOutcome } from "./helpers";
3
+ export declare const installJsxPlugin: (sys: DevToolsSys) => Promise<{
4
+ timestamp: string;
6
5
  installOutcome: InstallOutcome;
6
+ error: string | undefined;
7
7
  }>;
@@ -0,0 +1,45 @@
1
+ import type { ChildProcessWithoutNullStreams } from "child_process";
2
+ /**
3
+ * Initialize logging by wrapping all console methods to write to logs file
4
+ */
5
+ export declare function initializeLogging({ goToParentTimes, }?: {
6
+ goToParentTimes?: number;
7
+ }): void;
8
+ /**
9
+ * Reset console methods to their original state
10
+ */
11
+ export declare function resetLogging(): void;
12
+ /**
13
+ * Capture and log child process output
14
+ */
15
+ export declare function setupChildProcessLogging(childProcess: ChildProcessWithoutNullStreams, prefix: string): void;
16
+ /**
17
+ * Display intro message with logging
18
+ */
19
+ export declare const intro: (message: string) => void;
20
+ /**
21
+ * Wrapped clack logging methods with file logging
22
+ */
23
+ export declare const log: {
24
+ info: (message: string) => void;
25
+ success: (message: string) => void;
26
+ error: (message: string) => void;
27
+ warn: (message: string) => void;
28
+ step: (message: string) => void;
29
+ message: (message?: string, { symbol }?: import("@clack/prompts").LogMessageOptions) => void;
30
+ warning: (message: string) => void;
31
+ };
32
+ /**
33
+ * Display outro message with logging
34
+ */
35
+ export declare const outro: (message: string) => void;
36
+ /**
37
+ * Reads logs with pagination
38
+ * @param nextToken Line number to start reading from (0-indexed)
39
+ * @param limit Number of lines to read
40
+ * @returns Object containing logs array and next token
41
+ */
42
+ export declare const readLogs: (nextToken?: number, limit?: number) => {
43
+ logs: string[];
44
+ nextToken: number | null;
45
+ };
@@ -0,0 +1,9 @@
1
+ import { type Express, type RequestHandler } from "express";
2
+ export declare const BUILDER_ENDPOINT_PREFIX = "/_builder.io";
3
+ export declare const BUILDER_API_ENDPOINT_PREFIX: string;
4
+ export declare const configureServer: (app: Express) => void;
5
+ export declare const serverAuthMiddleware: ({ validBuilderPrivateKey, authenticateProxy, }: {
6
+ validBuilderPrivateKey: string | undefined;
7
+ authenticateProxy: boolean;
8
+ }) => RequestHandler;
9
+ export declare const createLogAndConfigEndpoints: (app: Express) => void;
@@ -0,0 +1,13 @@
1
+ import type { DevToolsSys } from "@builder.io/dev-tools/core";
2
+ import type { CLIArgs } from "./index";
3
+ export interface InitArgs extends CLIArgs {
4
+ repoFullName?: string;
5
+ branchName?: string;
6
+ githubToken?: string;
7
+ installCommand?: string;
8
+ volumePath?: string;
9
+ }
10
+ export declare function runLaunchInitCommand({ args, sys, }: {
11
+ sys: DevToolsSys;
12
+ args: InitArgs;
13
+ }): Promise<number>;
@@ -1,7 +1,36 @@
1
1
  import type { DevToolsSys } from "@builder.io/dev-tools/core";
2
2
  import type { CLIArgs } from "./index";
3
+ /**
4
+ * Large random-ish port number that is unlikely to be used
5
+ */
3
6
  export declare const PROXY_PORT = 48752;
7
+ export interface LaunchArgs extends CLIArgs {
8
+ volumePath?: string;
9
+ /** Fusion project ID */
10
+ projectId?: string;
11
+ /** Silent mode for launch command */
12
+ silent?: boolean;
13
+ /** Port number for the dev server */
14
+ port?: number;
15
+ /** Port number for the dev server (shorthand) */
16
+ p?: number;
17
+ /** Dev server command to execute */
18
+ command?: string;
19
+ /** Dev server command to execute (shorthand) */
20
+ c?: string;
21
+ /** Use development server instead of production for launch command */
22
+ dev?: boolean;
23
+ /** Skip browser auto-open (flag form) */
24
+ open?: boolean;
25
+ /**
26
+ * Decides whether to skip authentication for the user's proxy server.
27
+ * Our own _builder.io/ endpoitns are always authenticated.
28
+ *
29
+ * @default false
30
+ */
31
+ authenticateProxy?: boolean;
32
+ }
4
33
  export declare function runLaunchCommand({ sys, args, }: {
5
34
  sys: DevToolsSys;
6
- args: CLIArgs;
7
- }): Promise<number>;
35
+ args: LaunchArgs;
36
+ }): Promise<undefined>;
@@ -0,0 +1,50 @@
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 RPCWebSocketServer(opts: ServerOptions): {
41
+ on: <EventKey extends keyof SocketEvents>(event: EventKey, cb: SocketEvents[EventKey]) => void;
42
+ event: (e: string) => void;
43
+ handleUpgrade: (req: IncomingMessage, socket: Duplex, upgradeHead: Buffer, callback?: (client: WebSocket, request: IncomingMessage) => void) => Promise<void>;
44
+ clients: () => Map<string, WebSocket>;
45
+ register: <T = any>(method: string, fn: RegisterFn<T>) => void;
46
+ emit: (name: string, ...params: any[]) => void;
47
+ notify: (name: string, socketId: string, ...params: any[]) => void;
48
+ close: () => Promise<unknown>;
49
+ };
50
+ export {};