import { Disposable, Emitter } from "@codesandbox/pitcher-common"; import type { client as clientProtocol, ClientSubscriptions, system as systemProtocol, PitcherRequest, PitcherPermissions, PitcherCapabilities } from "@codesandbox/pitcher-protocol"; import { States } from "class-states"; import { PitcherFeatureToVersionMap } from "../common/versions"; import type { IPitcherClient } from "../interface/IPitcherClient"; import type { ErrorEmitter, PitcherManagerResponse } from "../types"; import { PitcherMessageHandler } from "./PitcherMessageHandler"; import type { WebSocketClient } from "./WebSocketClient"; import { AiClient } from "./clients/AiClient"; import { ChannelClient } from "./clients/ChannelClient"; import { ClientClient } from "./clients/ClientClient"; import { CommandClient } from "./clients/CommandClient"; import { ContainerClient } from "./clients/ContainerClient"; import { FSClient } from "./clients/FSClient"; import { FileClient } from "./clients/FileClient"; import { GitClient } from "./clients/GitClient"; import { LanguageClient } from "./clients/LanguageClient"; import { NotificationClient } from "./clients/NotificationClient"; import { PortClient } from "./clients/PortClient"; import { SetupClient } from "./clients/SetupClient"; import { ShellClient } from "./clients/ShellClient"; import { SystemClient } from "./clients/SystemClient"; import { TaskClient } from "./clients/TaskClient"; export type PitcherInstanceRequest = (intanceId: string) => Promise; /** * These are the options passed by consuming client when initializing * a Pitcher Client */ export interface PitcherClientOpts { /** * Which instance to connect to */ instanceId: string; requestPitcherInstance: (instanceId: string) => Promise; subscriptions: ClientSubscriptions; appId: string; onFocusChange: (cb: (isFocused: boolean) => void) => () => void; seamlessFork?: boolean; } /** * These are the options passed to actuall instantitate an instance */ export type PitcherClientInstanceOpts = PitcherClientOpts & { messageHandler: PitcherMessageHandler; initialConnection: WebSocketClient; joinResult: clientProtocol.ClientJoinResult; hostResponse: PitcherManagerResponse; }; declare global { /** * @note Global variables must be annotated with `var`. * Using `let` or `const` will simply not work. */ var __CSB__SHOW_PITCHER_MESSAGES: boolean; } /** * This is the main object where clients consume Pitcher. It is instantiated with a connected connection * to Pitcher. This way you have a guarantee, also through typing, to be able to use its full API from the "get go". * * Its main state (connection state) is driven by the current connection, which can be changed out related to seamless branching. */ export declare class PitcherVMClient extends Disposable implements IPitcherClient { type: "vm"; instanceId: string; private connection; private appId; private subscriptions; private requestPitcherInstance; private lastFocusTimestamp; private onFocusChange; private onFocusChangeDisposer; private hostResponse; private joinResult; private currentRetryPromise?; private isFocused; sessionStartTime: number; get bootupType(): "RUNNING" | "CLEAN" | "RESUME" | "FORK"; state: States<{ state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } | { state: "CONNECTING"; } | { state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } | { state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } | { state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; }>; messageHandler: PitcherMessageHandler; onMessage: PitcherMessageHandler["onMessage"]; onMessageError: ErrorEmitter["event"]; onStateChange: { (state: T, listener: (state: ({ state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } extends infer T_1 ? T_1 extends { state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } ? T_1 extends { state: T; } ? T_1 : never : never : never) | ({ state: "CONNECTING"; } extends infer T_2 ? T_2 extends { state: "CONNECTING"; } ? T_2 extends { state: T; } ? T_2 : never : never : never) | ({ state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } extends infer T_3 ? T_3 extends { state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } ? T_3 extends { state: T; } ? T_3 : never : never : never) | ({ state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } extends infer T_4 ? T_4 extends { state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } ? T_4 extends { state: T; } ? T_4 : never : never : never) | ({ state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; } extends infer T_5 ? T_5 extends { state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; } ? T_5 extends { state: T; } ? T_5 : never : never : never), prevState: { state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } | { state: "CONNECTING"; } | { state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } | { state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } | { state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; }) => void): () => void; (listener: (state: { state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } | { state: "CONNECTING"; } | { state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } | { state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } | { state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; }, prevState: { state: "CONNECTED"; lastActivity: number; lastFocus: number; connectedAt: number; } | { state: "CONNECTING"; } | { state: "RECONNECTING"; attempt: number; wasFocused: boolean; lastActivity: number; disconnectReason: string; disconnectedAt: number; } | { state: "HIBERNATED"; wasFocused: boolean; disconnectedAt: number; } | { state: "DISCONNECTED"; reason: string; code: number; wasClean: boolean; wasFocused: boolean; disconnectedAt: number; }) => void): () => void; }; private onReconnectedEmitter; onReconnected: import("@codesandbox/pitcher-common").Event; onInstanceChangeRequired: Emitter["event"]; private onInstanceChangedEmitter; onInstanceChanged: import("@codesandbox/pitcher-common").Event<{ instanceId: string; }>; get currentClient(): clientProtocol.ClientJSON; get capabilities(): PitcherCapabilities; get permissions(): PitcherPermissions; get pitcherVersion(): string; get pitcherManagerVersion(): string; get pitcherProtocolVersion(): string; get workspacePath(): string; get userWorkspacePath(): string; get cluster(): string; get reconnectToken(): string; clients: { fs: FSClient; shell: ShellClient; port: PortClient; language: LanguageClient; client: ClientClient; file: FileClient; git: GitClient; setup: SetupClient; notification: NotificationClient; channel: ChannelClient; task: TaskClient; system: SystemClient; command: CommandClient; ai: AiClient; container: ContainerClient; }; constructor(opts: PitcherClientInstanceOpts); private subscribeConnection; private resolveCurrentConnection; reconnect(): Promise; private attemptReconnect; hasFeature(feature: T): boolean; revertSeamlessFork(): void; toggleSeamlessFork(value: boolean): void; changeInstance(instanceId: string): Promise; isUpToDate(): boolean; disconnect(): Promise; dispose(): void; } export declare function createInitialStatus(message?: string): systemProtocol.InitStatus; /** * We use an async initializer function to return a new instance of Pitcher Client. The reason * we do this is because the consumable API surface of PitcherClient makes no sense without the * initial connection. After that though, the connection can drop, reconnect and even be changed into * a completely different connection (seamless branching)... but still, the API surface exposed is consistent * and available. * * We also create each of the clients of PitcherClient in this async initializer as we also depend on certain * of those to async resolve before PitcherClient itself is ready to be consumed. */ export declare function initPitcherClient(opts: PitcherClientOpts, initStatusCb: (event: systemProtocol.InitStatus) => void, hostResponseCb?: (hostResponse: PitcherManagerResponse) => void): Promise; //# sourceMappingURL=index.d.ts.map