Repository: onlook-dev/onlook
File: packages/code-provider/src/types.ts (TypeScript)

Code before:
    abstract runCommand(input: TerminalCommandInput): Promise<TerminalCommandOutput>;
    abstract runBackgroundCommand(
        input: TerminalBackgroundCommandInput,
    ): Promise<TerminalBackgroundCommandOutput>;
    abstract gitStatus(input: GitStatusInput): Promise<GitStatusOutput>;

    /**
     * Called in the backend as it may handle secrets.
     * Returns data for the frontend.
     * The data may be extended for each provider and must be serializable in JSON.
     */
    abstract createSession(input: CreateSessionInput): Promise<CreateSessionOutput>;

    /**
     * `Provider` is meant to be a singleton; this method is called when the first instance is created.
     * Use this to establish a connection or run operations that requires I/O.
     */
    abstract initialize(input: InitializeInput): Promise<InitializeOutput>;

    abstract setup(input: SetupInput): Promise<SetupOutput>;

    abstract reload(): Promise<boolean>;
    abstract reconnect(): Promise<void>;
    abstract ping(): Promise<boolean>;

    abstract createProject(input: CreateProjectInput): Promise<CreateProjectOutput>;
    abstract pauseProject(input: PauseProjectInput): Promise<PauseProjectOutput>;
    abstract stopProject(input: StopProjectInput): Promise<StopProjectOutput>;
    abstract listProjects(input: ListProjectsInput): Promise<ListProjectsOutput>;

    // this is called when the provider instance is no longer needed
    abstract destroy(): Promise<void>;
}

export abstract class ProviderFileWatcher {
    abstract start(input: WatchFilesInput): Promise<void>;
    abstract stop(): Promise<void>;
    abstract registerEventCallback(callback: (event: WatchEvent) => Promise<void>): void;
}

export type ProviderTerminalShellSize = {
    cols: number;
    rows: number;
};

/**
 * This is a wrapper around the terminal object from the code provider.
 * Inspired from @codesandbox/sdk/sessions/WebSocketSession/terminals.d.ts
 */
export abstract class ProviderTerminal {
    /**

Review comment (refactor):
@http-teapot fyi, I refactored create to be static (you also commented about this). 

Issue was: it was starting the template sandbox which was wasteful + added extra wait time.And in CSB case it was degrading the sandbox over time which caused it to corrupt after enough forks. 

Code after:
    abstract runCommand(input: TerminalCommandInput): Promise<TerminalCommandOutput>;
    abstract runBackgroundCommand(
        input: TerminalBackgroundCommandInput,
    ): Promise<TerminalBackgroundCommandOutput>;
    abstract gitStatus(input: GitStatusInput): Promise<GitStatusOutput>;

    /**
     * Called in the backend as it may handle secrets.
     * Returns data for the frontend.
     * The data may be extended for each provider and must be serializable in JSON.
     */
    abstract createSession(input: CreateSessionInput): Promise<CreateSessionOutput>;

    /**
     * `Provider` is meant to be a singleton; this method is called when the first instance is created.
     * Use this to establish a connection or run operations that requires I/O.
     */
    abstract initialize(input: InitializeInput): Promise<InitializeOutput>;

    abstract setup(input: SetupInput): Promise<SetupOutput>;

    abstract reload(): Promise<boolean>;
    abstract reconnect(): Promise<void>;
    abstract ping(): Promise<boolean>;

    static createProject(input: CreateProjectInput): Promise<CreateProjectOutput> {
        throw new Error('createProject must be implemented by subclass');
    }
    abstract pauseProject(input: PauseProjectInput): Promise<PauseProjectOutput>;
    abstract stopProject(input: StopProjectInput): Promise<StopProjectOutput>;
    abstract listProjects(input: ListProjectsInput): Promise<ListProjectsOutput>;

    // this is called when the provider instance is no longer needed
    abstract destroy(): Promise<void>;
}

export abstract class ProviderFileWatcher {
    abstract start(input: WatchFilesInput): Promise<void>;
    abstract stop(): Promise<void>;
    abstract registerEventCallback(callback: (event: WatchEvent) => Promise<void>): void;
}

export type ProviderTerminalShellSize = {
    cols: number;
    rows: number;
};

/**
 * This is a wrapper around the terminal object from the code provider.
 * Inspired from @codesandbox/sdk/sessions/WebSocketSession/terminals.d.ts
 */