{"version":3,"file":"session.cjs","names":["toSandboxSnapshot","Command","params: RunCommandParams","command","CommandFinished","consumeReadable","Snapshot"],"sources":["../src/session.ts"],"sourcesContent":["import { type SessionMetaData, type SandboxRouteData, type SandboxMetaData, type SnapshotMetadata, WebixApiClient } from \"./api-client/index.js\";\nimport type { WebixHostOptions } from \"./webix/host.js\";\nimport type { Writable } from \"stream\";\nimport { Command, CommandFinished } from \"./command.js\";\nimport { Snapshot } from \"./snapshot.js\";\nimport { consumeReadable } from \"./utils/consume-readable.js\";\nimport type {\n  NetworkPolicy,\n  NetworkPolicyRule,\n  NetworkTransformer,\n} from \"./network-policy.js\";\nimport { toSandboxSnapshot, type SandboxSnapshot } from \"./utils/sandbox-snapshot.js\";\n\nexport type { NetworkPolicy, NetworkPolicyRule, NetworkTransformer };\n\n/**\n * Serialized representation of a Session.\n */\nexport interface SerializedSession {\n  session: SandboxSnapshot;\n  routes: SandboxRouteData[];\n}\n\n/** @inline */\nexport interface RunCommandParams {\n  /**\n   * The command to execute\n   */\n  cmd: string;\n  /**\n   * Arguments to pass to the command\n   */\n  args?: string[];\n  /**\n   * Working directory to execute the command in\n   */\n  cwd?: string;\n  /**\n   * Environment variables to set for this command\n   */\n  env?: Record<string, string>;\n  /**\n   * If true, execute this command with root privileges. Defaults to false.\n   */\n  sudo?: boolean;\n  /**\n   * If true, the command will return without waiting for `exitCode`\n   */\n  detached?: boolean;\n  /**\n   * A `Writable` stream where `stdout` from the command will be piped\n   */\n  stdout?: Writable;\n  /**\n   * A `Writable` stream where `stderr` from the command will be piped\n   */\n  stderr?: Writable;\n  /**\n   * An AbortSignal to cancel the command execution\n   */\n  signal?: AbortSignal;\n}\n\n/**\n * A Session represents a running VM instance within a {@link Sandbox}.\n *\n * Obtain a session via {@link Sandbox.currentSession}.\n */\nexport class Session {\n  private _client: WebixApiClient | null = null;\n\n  /**\n   * Return the in-browser sandbox client. The client is bound to a live Blink\n   * host at creation time; a Session detached from its host (e.g. after a\n   * structured-clone round-trip) cannot rebuild one and reports so.\n   * @internal\n   */\n  private async ensureClient(): Promise<WebixApiClient> {\n    if (this._client) return this._client;\n    throw new Error(\n      \"Session is not attached to a live in-browser sandbox host.\",\n    );\n  }\n\n  /**\n   * Routes from ports to subdomains.\n   * @hidden\n   */\n  public readonly routes: SandboxRouteData[];\n\n  /**\n   * Internal metadata about the current session.\n   */\n  private session: SandboxSnapshot;\n\n  private get client(): WebixApiClient {\n    if (!this._client) throw new Error(\"API client not initialized\");\n    return this._client;\n  }\n\n  /** @internal */\n  get _sessionSnapshot(): SandboxSnapshot {\n    return this.session;\n  }\n\n  /**\n   * Unique ID of this session.\n   */\n  public get sessionId(): string {\n    return this.session.id;\n  }\n\n  public get interactivePort(): number | undefined {\n    return this.session.interactivePort ?? undefined;\n  }\n\n  /**\n   * The status of this session.\n   */\n  public get status(): SessionMetaData[\"status\"] {\n    return this.session.status;\n  }\n\n  /**\n   * The creation date of this session.\n   */\n  public get createdAt(): Date {\n    return new Date(this.session.createdAt);\n  }\n\n  /**\n   * The timeout of this session in milliseconds.\n   */\n  public get timeout(): number {\n    return this.session.timeout;\n  }\n\n  /**\n   * The network policy of this session.\n   */\n  public get networkPolicy(): NetworkPolicy | undefined {\n    return this.session.networkPolicy;\n  }\n\n  /**\n   * If the session was created from a snapshot, the ID of that snapshot.\n   */\n  public get sourceSnapshotId(): string | undefined {\n    return this.session.sourceSnapshotId;\n  }\n\n  /**\n   * Memory allocated to this session in MB.\n   */\n  public get memory(): number {\n    return this.session.memory;\n  }\n\n  /**\n   * Number of vCPUs allocated to this session.\n   */\n  public get vcpus(): number {\n    return this.session.vcpus;\n  }\n\n  /**\n   * The region where this session is hosted.\n   */\n  public get region(): string {\n    return this.session.region;\n  }\n\n  /**\n   * Runtime identifier (e.g. \"node24\", \"python3.13\").\n   */\n  public get runtime(): string {\n    return this.session.runtime;\n  }\n\n  /**\n   * The working directory of this session.\n   */\n  public get cwd(): string {\n    return this.session.cwd;\n  }\n\n  /**\n   * When this session was requested.\n   */\n  public get requestedAt(): Date {\n    return new Date(this.session.requestedAt);\n  }\n\n  /**\n   * When this session started running.\n   */\n  public get startedAt(): Date | undefined {\n    return this.session.startedAt != null\n      ? new Date(this.session.startedAt)\n      : undefined;\n  }\n\n  /**\n   * When this session was requested to stop.\n   */\n  public get requestedStopAt(): Date | undefined {\n    return this.session.requestedStopAt != null\n      ? new Date(this.session.requestedStopAt)\n      : undefined;\n  }\n\n  /**\n   * When this session was stopped.\n   */\n  public get stoppedAt(): Date | undefined {\n    return this.session.stoppedAt != null\n      ? new Date(this.session.stoppedAt)\n      : undefined;\n  }\n\n  /**\n   * When this session was aborted.\n   */\n  public get abortedAt(): Date | undefined {\n    return this.session.abortedAt != null\n      ? new Date(this.session.abortedAt)\n      : undefined;\n  }\n\n  /**\n   * The wall-clock duration of this session in milliseconds.\n   */\n  public get duration(): number | undefined {\n    return this.session.duration;\n  }\n\n  /**\n   * When a snapshot was requested for this session.\n   */\n  public get snapshottedAt(): Date | undefined {\n    return this.session.snapshottedAt != null\n      ? new Date(this.session.snapshottedAt)\n      : undefined;\n  }\n\n  /**\n   * When this session was last updated.\n   */\n  public get updatedAt(): Date {\n    return new Date(this.session.updatedAt);\n  }\n\n  /**\n   * The amount of active CPU used by the session. Only reported once the VM is\n   * stopped.\n   */\n  public get activeCpuUsageMs(): number | undefined {\n    return this.session.activeCpuDurationMs;\n  }\n\n  /**\n   * The amount of network data used by the session. Only reported once the VM\n   * is stopped.\n   */\n  public get networkTransfer():\n    | { ingress: number; egress: number }\n    | undefined {\n    return this.session.networkTransfer;\n  }\n\n  constructor(params: {\n    client: WebixApiClient;\n    routes: SandboxRouteData[];\n    session: SessionMetaData;\n  } | {\n    /** @internal – used to reconstruct from a metadata snapshot (no live host) */\n    routes: SandboxRouteData[];\n    snapshot: SandboxSnapshot;\n  }) {\n    this.routes = params.routes;\n    if (\"snapshot\" in params) {\n      this.session = params.snapshot;\n    } else {\n      this._client = params.client;\n      this.session = toSandboxSnapshot(params.session);\n    }\n  }\n\n  /** @internal */\n  updateRoutes(routes: SandboxRouteData[]): void {\n    (this as { routes: SandboxRouteData[] }).routes = routes;\n  }\n\n  /**\n   * Get a previously run command by its ID.\n   *\n   * @param cmdId - ID of the command to retrieve\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A {@link Command} instance representing the command\n   */\n  async getCommand(\n    cmdId: string,\n    opts?: { signal?: AbortSignal },\n  ): Promise<Command> {\n    \"use step\";\n    const client = await this.ensureClient();\n    const command = await client.getCommand({\n      sessionId: this.session.id,\n      cmdId,\n      signal: opts?.signal,\n    });\n\n    return new Command({\n      client,\n      sessionId: this.session.id,\n      cmd: command.json.command,\n    });\n  }\n\n  /**\n   * Start executing a command in this session.\n   *\n   * @param command - The command to execute.\n   * @param args - Arguments to pass to the command.\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the command execution.\n   * @returns A {@link CommandFinished} result once execution is done.\n   */\n  async runCommand(\n    command: string,\n    args?: string[],\n    opts?: { signal?: AbortSignal },\n  ): Promise<CommandFinished>;\n\n  /**\n   * Start executing a command in detached mode.\n   *\n   * @param params - The command parameters.\n   * @returns A {@link Command} instance for the running command.\n   */\n  async runCommand(\n    params: RunCommandParams & { detached: true },\n  ): Promise<Command>;\n\n  /**\n   * Start executing a command in this session.\n   *\n   * @param params - The command parameters.\n   * @returns A {@link CommandFinished} result once execution is done.\n   */\n  async runCommand(params: RunCommandParams): Promise<CommandFinished>;\n\n  async runCommand(\n    commandOrParams: string | RunCommandParams,\n    args?: string[],\n    opts?: { signal?: AbortSignal },\n  ): Promise<Command | CommandFinished> {\n    \"use step\";\n    const client = await this.ensureClient();\n    const params: RunCommandParams =\n      typeof commandOrParams === \"string\"\n        ? { cmd: commandOrParams, args, signal: opts?.signal }\n        : commandOrParams;\n    const wait = params.detached ? false : true;\n    const pipeLogs = async (command: Command): Promise<void> => {\n      if (!params.stdout && !params.stderr) {\n        return;\n      }\n\n      try {\n        for await (const log of command.logs({ signal: params.signal })) {\n          if (log.stream === \"stdout\") {\n            params.stdout?.write(log.data);\n          } else if (log.stream === \"stderr\") {\n            params.stderr?.write(log.data);\n          }\n        }\n      } catch (err) {\n        if (params.signal?.aborted) {\n          return;\n        }\n        throw err;\n      }\n    };\n\n    if (wait) {\n      const commandStream = await client.runCommand({\n        sessionId: this.session.id,\n        command: params.cmd,\n        args: params.args ?? [],\n        cwd: params.cwd,\n        env: params.env ?? {},\n        sudo: params.sudo ?? false,\n        wait: true,\n        signal: params.signal,\n      });\n\n      const command = new Command({\n        client,\n        sessionId: this.session.id,\n        cmd: commandStream.command,\n      });\n\n      const [finished] = await Promise.all([\n        commandStream.finished,\n        pipeLogs(command),\n      ]);\n      return new CommandFinished({\n        client,\n        sessionId: this.session.id,\n        cmd: finished,\n        exitCode: finished.exitCode ?? 0,\n      });\n    }\n\n    const commandResponse = await client.runCommand({\n      sessionId: this.session.id,\n      command: params.cmd,\n      args: params.args ?? [],\n      cwd: params.cwd,\n      env: params.env ?? {},\n      sudo: params.sudo ?? false,\n      signal: params.signal,\n    });\n\n    const command = new Command({\n      client,\n      sessionId: this.session.id,\n      cmd: commandResponse.json.command,\n    });\n\n    void pipeLogs(command).catch((err) => {\n      if (params.signal?.aborted) {\n        return;\n      }\n      (params.stderr ?? params.stdout)?.emit(\"error\", err);\n    });\n\n    return command;\n  }\n\n  /**\n   * Create a directory in the filesystem of this session.\n   *\n   * @param path - Path of the directory to create\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   */\n  async mkDir(path: string, opts?: { signal?: AbortSignal }): Promise<void> {\n    \"use step\";\n    const client = await this.ensureClient();\n    await client.mkDir({\n      sessionId: this.session.id,\n      path: path,\n      signal: opts?.signal,\n    });\n  }\n\n  /**\n   * Read a file from the filesystem of this session as a stream.\n   *\n   * @param file - File to read, with path and optional cwd\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves to a ReadableStream containing the file contents, or null if file not found\n   */\n  async readFile(\n    file: { path: string; cwd?: string },\n    opts?: { signal?: AbortSignal },\n  ): Promise<ReadableStream | null> {\n    const client = await this.ensureClient();\n    return client.readFile({\n      sessionId: this.session.id,\n      path: file.path,\n      cwd: file.cwd,\n      signal: opts?.signal,\n    });\n  }\n\n  /**\n   * Read a file from the filesystem of this session as a Buffer.\n   *\n   * @param file - File to read, with path and optional cwd\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves to the file contents as a Buffer, or null if file not found\n   */\n  async readFileToBuffer(\n    file: { path: string; cwd?: string },\n    opts?: { signal?: AbortSignal },\n  ): Promise<Uint8Array | null> {\n    const client = await this.ensureClient();\n    const stream = await client.readFile({\n      sessionId: this.session.id,\n      path: file.path,\n      cwd: file.cwd,\n      signal: opts?.signal,\n    });\n\n    if (stream === null) {\n      return null;\n    }\n\n    return consumeReadable(stream);\n  }\n\n  /**\n   * Download a file from the session to the local filesystem.\n   *\n   * @param src - Source file on the session, with path and optional cwd\n   * @param dst - Destination file on the local machine, with path and optional cwd\n   * @param opts - Optional parameters.\n   * @param opts.mkdirRecursive - If true, create parent directories for the destination if they don't exist.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns The absolute path to the written file, or null if the source file was not found\n   */\n  async downloadFile(\n    src: { path: string; cwd?: string },\n    dst: { path: string; cwd?: string },\n    opts?: { mkdirRecursive?: boolean; signal?: AbortSignal },\n  ): Promise<string | null> {\n    \"use step\";\n    const client = await this.ensureClient();\n    if (!src?.path) {\n      throw new Error(\"downloadFile: source path is required\");\n    }\n\n    if (!dst?.path) {\n      throw new Error(\"downloadFile: destination path is required\");\n    }\n\n    const stream = await client.readFile({\n      sessionId: this.session.id,\n      path: src.path,\n      cwd: src.cwd,\n      signal: opts?.signal,\n    });\n\n    if (stream === null) {\n      return null;\n    }\n\n    // downloadFile writes to the local filesystem and is Node-only; its Node\n    // builtins are imported dynamically AND bundler-ignored so they never enter\n    // (or break) a browser bundle (Next/Turbopack/vite).\n    const { pipeline } = await import(/* webpackIgnore: true */ /* @vite-ignore */ \"stream/promises\");\n    const { createWriteStream } = await import(/* webpackIgnore: true */ /* @vite-ignore */ \"fs\");\n    const { mkdir } = await import(/* webpackIgnore: true */ /* @vite-ignore */ \"fs/promises\");\n    const { dirname, resolve } = await import(/* webpackIgnore: true */ /* @vite-ignore */ \"path\");\n    const { Readable } = await import(/* webpackIgnore: true */ /* @vite-ignore */ \"stream\");\n\n    const dstPath = resolve(dst.cwd ?? \"\", dst.path);\n    if (opts?.mkdirRecursive) {\n      await mkdir(dirname(dstPath), { recursive: true });\n    }\n    await pipeline(\n      Readable.fromWeb(stream as import(\"stream/web\").ReadableStream),\n      createWriteStream(dstPath),\n      { signal: opts?.signal },\n    );\n    return dstPath;\n  }\n\n  /**\n   * Write files to the filesystem of this session.\n   * Defaults to writing to /vercel/sandbox unless an absolute path is specified.\n   * Writes files using the `vercel-sandbox` user.\n   *\n   * @param files - Array of files with path and stream/buffer contents\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves when the files are written\n   */\n  async writeFiles(\n    files: { path: string; content: string | Uint8Array; mode?: number }[],\n    opts?: { signal?: AbortSignal },\n  ): Promise<void> {\n    const client = await this.ensureClient();\n    await client.writeFiles({\n      sessionId: this.session.id,\n      cwd: this.session.cwd,\n      extractDir: \"/\",\n      files: files,\n      signal: opts?.signal,\n    });\n  }\n\n  /**\n   * Get the public domain of a port of this session.\n   *\n   * @param p - Port number to resolve\n   * @returns A full domain (e.g. `https://subdomain.vercel.run`)\n   * @throws If the port has no associated route\n   */\n  domain(p: number): string {\n    const route = this.routes.find(({ port }) => port == p);\n    if (route) {\n      return `https://${route.subdomain}.vercel.run`;\n    } else {\n      throw new Error(`No route for port ${p}`);\n    }\n  }\n\n  /**\n   * Stop this session.\n   *\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns The final session state and optional sandbox metadata.\n   */\n  async stop(opts?: {\n    signal?: AbortSignal;\n  }): Promise<{ session: SandboxSnapshot; sandbox?: SandboxMetaData; snapshot?: SnapshotMetadata }> {\n    \"use step\";\n    const client = await this.ensureClient();\n    const response = await client.stopSession({\n      sessionId: this.session.id,\n      signal: opts?.signal,\n    });\n    this.session = toSandboxSnapshot(response.json.session);\n    return { session: this.session, sandbox: response.json.sandbox, snapshot: response.json.snapshot };\n  }\n\n  /**\n   * Update the current session's settings.\n   *\n   * @param params - Fields to update.\n   * @param params.networkPolicy - The new network policy to apply.\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   *\n   * @example\n   * // Restrict to specific domains\n   * await session.update({\n   *   networkPolicy: {\n   *     allow: [\"*.npmjs.org\", \"github.com\"],\n   *   }\n   * });\n   *\n   * @example\n   * // Inject credentials with per-domain transformers\n   * await session.update({\n   *   networkPolicy: {\n   *     allow: {\n   *       \"ai-gateway.vercel.sh\": [{\n   *         transform: [{\n   *           headers: { authorization: \"Bearer ...\" }\n   *         }]\n   *       }],\n   *       \"*\": []\n   *     }\n   *   }\n   * });\n   *\n   * @example\n   * // Deny all network access\n   * await session.update({ networkPolicy: \"deny-all\" });\n   */\n  async update(\n    params: {\n      networkPolicy?: NetworkPolicy;\n    },\n    opts?: { signal?: AbortSignal },\n  ): Promise<void> {\n    \"use step\";\n    if (params.networkPolicy !== undefined) {\n      const client = await this.ensureClient();\n      const response = await client.updateNetworkPolicy({\n        sessionId: this.session.id,\n        networkPolicy: params.networkPolicy,\n        signal: opts?.signal,\n      });\n\n      // Update the internal session with the new network policy\n      this.session = toSandboxSnapshot(response.json.session);\n    }\n  }\n\n  /**\n   * Extend the timeout of the session by the specified duration.\n   *\n   * This allows you to extend the lifetime of a session up until the maximum\n   * execution timeout for your plan.\n   *\n   * @param duration - The duration in milliseconds to extend the timeout by\n   * @param opts - Optional parameters.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves when the timeout is extended\n   *\n   * @example\n   * const sandbox = await Sandbox.create({ timeout: ms('10m') });\n   * const session = sandbox.currentSession();\n   * // Extends timeout by 5 minutes, to a total of 15 minutes.\n   * await session.extendTimeout(ms('5m'));\n   */\n  async extendTimeout(\n    duration: number,\n    opts?: { signal?: AbortSignal },\n  ): Promise<void> {\n    \"use step\";\n    const client = await this.ensureClient();\n    const response = await client.extendTimeout({\n      sessionId: this.session.id,\n      duration,\n      signal: opts?.signal,\n    });\n\n    // Update the internal sandbox metadata with the new timeout value\n    this.session = toSandboxSnapshot(response.json.session);\n  }\n\n  /**\n   * Create a snapshot from this currently running session. New sandboxes can\n   * then be created from this snapshot using {@link Sandbox.create}.\n   *\n   * Note: this session will be stopped as part of the snapshot creation process.\n   *\n   * @param opts - Optional parameters.\n   * @param opts.expiration - Optional expiration time in milliseconds. Use 0 for no expiration at all.\n   * @param opts.signal - An AbortSignal to cancel the operation.\n   * @returns A promise that resolves to the Snapshot instance\n   */\n  async snapshot(opts?: {\n    expiration?: number;\n    signal?: AbortSignal;\n  }): Promise<Snapshot> {\n    \"use step\";\n    const client = await this.ensureClient();\n    const response = await client.createSnapshot({\n      sessionId: this.session.id,\n      expiration: opts?.expiration,\n      signal: opts?.signal,\n    });\n\n    this.session = toSandboxSnapshot(response.json.session);\n\n    return new Snapshot({\n      client,\n      snapshot: response.json.snapshot,\n    });\n  }\n}\n"],"mappings":";;;;;;;;;;;AAoEA,IAAa,UAAb,MAAqB;;;;;;;CASnB,MAAc,eAAwC;AACpD,MAAI,KAAK,QAAS,QAAO,KAAK;AAC9B,QAAM,IAAI,MACR,6DACD;;CAcH,IAAY,SAAyB;AACnC,MAAI,CAAC,KAAK,QAAS,OAAM,IAAI,MAAM,6BAA6B;AAChE,SAAO,KAAK;;;CAId,IAAI,mBAAoC;AACtC,SAAO,KAAK;;;;;CAMd,IAAW,YAAoB;AAC7B,SAAO,KAAK,QAAQ;;CAGtB,IAAW,k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