@builder.io/dev-tools
Version:
Builder.io Visual CMS Devtools
127 lines (126 loc) • 7.15 kB
TypeScript
import type { DevToolsSys } from "../../core";
import { type Credentials } from "../credentials";
export { getCustomInstructions } from "./rules-discovery";
import type { CodeGenInputOptions, CodegenSetLastCompletion, CodegenTurn, GenerateCodeEvent, GenerateUserMessage, GetSessionTurnsResult, WorkspaceConfiguration, WorkspaceFolder, EnvironmentVariable, PushChangesArgs, PushChangesOptions, GenerateCompletionStepDevServerState, FusionConfig, GenerateCompletionStepGit } from "#ai-utils";
import type { SessionContext } from "../codegen";
import type { DevServerOrchestrator } from "../launch/dev-server-orchestrator";
export declare const DEFAULT_SOFT_MAX_COMPLETIONS = 100;
export declare const DEFAULT_HARD_MAX_COMPLETIONS = 200;
/**
* Merges and deduplicates items by name.
* Built-in items come first, discovered items can override them by name.
* @param builtIn - Built-in items
* @param discovered - Discovered items from project
* @returns Deduplicated array with discovered overriding built-in
*/
export declare function mergeByName<T extends {
name: string;
}>(builtIn: T[], discovered: T[]): T[];
export declare function getLastGoodTurn(sessionContext: SessionContext): CodegenTurn | undefined;
export declare function getLastUserTurn(sessionContext: SessionContext): CodegenTurn | undefined;
export declare function getLastApplyResultsTurn(sessionContext: SessionContext): CodegenTurn | undefined;
export declare function getLastOne<T>(array: T[]): T | undefined;
export declare function inPlaceRemovePendingTurns(turns: CodegenTurn[]): void;
export declare function restoreConsumedCredit(sys: DevToolsSys, credentials: Credentials, sessionId: string, restoreCredits: number): Promise<void>;
/**
* Analyzes the payload to identify what's making it large
*/
export declare function analyzePayloadBreakdown(body: CodeGenInputOptions, jsonString: string): Record<string, any>;
export declare function completionStream(sys: DevToolsSys, credentials: Credentials, body: CodeGenInputOptions, signal: AbortSignal, debug: boolean): AsyncGenerator<GenerateCodeEvent, void, unknown>;
export declare function codegenEndpoint(sys: DevToolsSys, credentials: Credentials, endpoint: string, body: Record<string, any>, debug: boolean): Promise<boolean>;
/**
* Makes a POST request to a codegen endpoint and returns parsed JSON.
* Returns undefined on failure (no retries, silent failure).
* Designed for non-critical requests like commit message generation.
*/
export declare function codegenPostJson<T>(credentials: Credentials, endpoint: string, body: Record<string, unknown>, options?: {
signal?: AbortSignal;
timeoutMs?: number;
debug: boolean;
}): Promise<T | undefined>;
export declare function setLastCompletionOfSession(sys: DevToolsSys, credentials: Credentials, data: CodegenSetLastCompletion, debug: boolean): Promise<boolean>;
export declare function getTurnsBySessionId(sys: DevToolsSys, credentials: Credentials, sessionId: string, linear: boolean, debug: boolean, completionIdCursor?: string, signal?: AbortSignal): Promise<GetSessionTurnsResult>;
export declare const parseCLIURL: (url: string | undefined) => {
id: undefined;
isInitial: boolean;
} | {
isInitial: boolean;
id: string;
};
export declare function getUserContext(sys: DevToolsSys, gitWorkingDirectory?: string): Promise<{
[x: string]: string | boolean | string[] | undefined;
client: string;
clientVersion: string;
nodeVersion: string;
systemPlatform: string;
frameworks: string[];
systemEOL: string;
systemArch: string;
systemShell?: string | undefined;
inGitRepo?: boolean | undefined;
}>;
export declare function makeAsyncIterator<T>(): readonly [AsyncGenerator<T, void, void>, (event: T) => void, () => void];
export declare function isAGENTSFile(filePath: string): boolean;
export declare function isBaseImportantFile(filePath: string, recommendedRootDir: string): boolean;
export declare function isImportantAgentFile(filePath: string, projectRootDir: string): boolean;
export declare function hasBuildError(text: string): boolean;
/**
* Loads a workspace configuration from a JSON file
* @param sys DevToolsSys instance
* @param workspaceFile Path to the workspace JSON file
* @returns The workspace configuration and working directory
*/
export declare function loadWorkspace(sys: DevToolsSys, workspaceFile: string): Promise<{
workspace: WorkspaceConfiguration;
workingDirectory: string;
}>;
export declare function mergeMessages(messages: GenerateUserMessage[]): GenerateUserMessage;
export declare function mergeUserMessages(currentMessage: GenerateUserMessage, newMessage: GenerateUserMessage): GenerateUserMessage;
export declare function keepAlive(): () => void;
export declare function parseAheadBehind(line: string): {
ahead: number;
behind: number;
};
export declare class BashError extends Error {
readonly code: number | string | undefined;
readonly stdout: string;
readonly stderr: string;
readonly command: string;
constructor(command: string, code: number | string | undefined, stdout: string, stderr: string, opts?: {
cause?: Error;
});
}
export declare class ParentBranchNotFoundError extends Error {
readonly branchName: string;
constructor(branchName: string, opts?: {
cause?: Error;
});
}
export declare function mergeEnvironmentVariables(envVariables: EnvironmentVariable[], extraEnvVariables: EnvironmentVariable[]): {
key: string;
value: string;
isSecret: boolean;
placeholder?: boolean | undefined;
explanation?: string | undefined;
}[];
export declare function processPushChangesArgs(opts: PushChangesArgs): PushChangesOptions;
export declare function getErrorMessage(err: unknown): string;
export declare function waitImmediate(): Promise<void>;
export declare function abortPromise<T extends Promise<any> | undefined>(promise: T, signal: AbortSignal | undefined): T;
export declare function waitRace(promise: Promise<any>, timeout: number): Promise<boolean>;
export declare function newAbortError(reason?: unknown): Error;
export declare function getDevServerStep(devServer: DevServerOrchestrator, fusionConfig: FusionConfig | undefined): GenerateCompletionStepDevServerState;
export declare function moveArrayElement<T>(arr: T[], old_index: number, new_index: number): T[];
export declare function canCollapseWorkspace(workspace: WorkspaceConfiguration | undefined): boolean;
export declare function computeRecommendedRootDir(workspace: WorkspaceConfiguration | undefined): string;
export { getEnvironmentVariablesPrompt } from "#vcp-common/codegen";
/**
* Converts a folder name to a per-repo GitHub token env var key.
* e.g. "code" → "GH_TOKEN_CODE", "ai-services" → "GH_TOKEN_AI_SERVICES"
*/
export declare function toGhTokenEnvKey(folderName: string): string;
export declare function generateGitStatusReminder(gitStatus: GenerateCompletionStepGit, gitEnabledFolders: WorkspaceFolder[], context: {
trigger: "session-start" | "sync-success" | "push-success" | "pull-success";
syncedBranches?: string[];
pushedToRemote?: boolean;
}): string;