# Class GcsArtifactService

java.lang.Object
com.google.adk.artifacts.GcsArtifactService

All Implemented Interfaces:
  `BaseArtifactService`

public final class GcsArtifactService extends Object implements BaseArtifactService
An artifact service implementation using Google Cloud Storage (GCS).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GcsArtifactService(String bucketName, com.google.cloud.storage.Storage storageClient)`
  Initializes the GcsArtifactService.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `io.reactivex.rxjava3.core.Completable`
  `deleteArtifact(String appName, String userId, String sessionId, String filename)`
  Deletes all versions of the specified artifact from GCS.
  `io.reactivex.rxjava3.core.Single<ListArtifactsResponse>`
  `listArtifactKeys(String appName, String userId, String sessionId)`
  Lists artifact filenames for a user and session.
  `io.reactivex.rxjava3.core.Single<com.google.common.collect.ImmutableList<Integer>>`
  `listVersions(String appName, String userId, String sessionId, String filename)`
  Lists all available versions for a given artifact.
  `io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part>`
  `loadArtifact(String appName, String userId, String sessionId, String filename, @Nullable Integer version)`
  Loads an artifact from GCS.
  `io.reactivex.rxjava3.core.Single<com.google.genai.types.Part>`
  `saveAndReloadArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)`
  Saves an artifact and returns it with fileData if available.
  `io.reactivex.rxjava3.core.Single<Integer>`
  `saveArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)`
  Saves an artifact to GCS and assigns a new version.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface BaseArtifactService

  `deleteArtifact, listArtifactKeys, listVersions, loadArtifact, loadArtifact, loadArtifact, loadArtifact, saveAndReloadArtifact, saveArtifact`
  Modifier and Type
  Method
  Description
  `default io.reactivex.rxjava3.core.Completable`
  `deleteArtifact(SessionKey sessionKey, String filename)`
  `default io.reactivex.rxjava3.core.Single<ListArtifactsResponse>`
  `listArtifactKeys(SessionKey sessionKey)`
  `default io.reactivex.rxjava3.core.Single<com.google.common.collect.ImmutableList<Integer>>`
  `listVersions(SessionKey sessionKey, String filename)`
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part>`
  `loadArtifact(SessionKey sessionKey, String filename)`
  Loads the latest version of an artifact from the service.
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part>`
  `loadArtifact(SessionKey sessionKey, String filename, int version)`
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part>`
  `loadArtifact(String appName, String userId, String sessionId, String filename)`
  Loads the latest version of an artifact from the service.
  `default io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part>`
  `loadArtifact(String appName, String userId, String sessionId, String filename, int version)`
  Loads a specific version of an artifact from the service.
  `default io.reactivex.rxjava3.core.Single<com.google.genai.types.Part>`
  `saveAndReloadArtifact(SessionKey sessionKey, String filename, com.google.genai.types.Part artifact)`
  Saves an artifact and returns it with fileData if available.
  `default io.reactivex.rxjava3.core.Single<Integer>`
  `saveArtifact(SessionKey sessionKey, String filename, com.google.genai.types.Part artifact)`
  Saves an artifact.

- ## Constructor Details

  - ### GcsArtifactService

    public GcsArtifactService(String bucketName, com.google.cloud.storage.Storage storageClient)
    Initializes the GcsArtifactService.
    Parameters:
      `bucketName` - The name of the GCS bucket to use.
      `storageClient` - The GCS storage client instance.

- ## Method Details

  - ### saveArtifact

    public io.reactivex.rxjava3.core.Single<Integer> saveArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)
    Saves an artifact to GCS and assigns a new version.
    Specified by:
      `saveArtifact` in interface `BaseArtifactService`
    Parameters:
      `appName` - Application name.
      `userId` - User ID.
      `sessionId` - Session ID.
      `filename` - Artifact filename.
      `artifact` - Artifact content to save.
    Returns:
      Single with assigned version number.

  - ### loadArtifact

    public io.reactivex.rxjava3.core.Maybe<com.google.genai.types.Part> loadArtifact(String appName, String userId, String sessionId, String filename, @Nullable Integer version)
    Loads an artifact from GCS.
    Specified by:
      `loadArtifact` in interface `BaseArtifactService`
    Parameters:
      `appName` - Application name.
      `userId` - User ID.
      `sessionId` - Session ID.
      `filename` - Artifact filename.
      `version` - Optional version to load. Loads latest if empty.
    Returns:
      Maybe with loaded artifact, or empty if not found.

  - ### listArtifactKeys

    public io.reactivex.rxjava3.core.Single<ListArtifactsResponse> listArtifactKeys(String appName, String userId, String sessionId)
    Lists artifact filenames for a user and session.
    Specified by:
      `listArtifactKeys` in interface `BaseArtifactService`
    Parameters:
      `appName` - Application name.
      `userId` - User ID.
      `sessionId` - Session ID.
    Returns:
      Single with sorted list of artifact filenames.

  - ### deleteArtifact

    public io.reactivex.rxjava3.core.Completable deleteArtifact(String appName, String userId, String sessionId, String filename)
    Deletes all versions of the specified artifact from GCS.
    Specified by:
      `deleteArtifact` in interface `BaseArtifactService`
    Parameters:
      `appName` - Application name.
      `userId` - User ID.
      `sessionId` - Session ID.
      `filename` - Artifact filename.
    Returns:
      Completable indicating operation completion.

  - ### listVersions

    public io.reactivex.rxjava3.core.Single<com.google.common.collect.ImmutableList<Integer>> listVersions(String appName, String userId, String sessionId, String filename)
    Lists all available versions for a given artifact.
    Specified by:
      `listVersions` in interface `BaseArtifactService`
    Parameters:
      `appName` - Application name.
      `userId` - User ID.
      `sessionId` - Session ID.
      `filename` - Artifact filename.
    Returns:
      Single with sorted list of version numbers.

  - ### saveAndReloadArtifact

    public io.reactivex.rxjava3.core.Single<com.google.genai.types.Part> saveAndReloadArtifact(String appName, String userId, String sessionId, String filename, com.google.genai.types.Part artifact)
    Description copied from interface: `BaseArtifactService`
    Saves an artifact and returns it with fileData if available.

    Implementations should override this default method for efficiency, as the default performs two I/O operations (save then load).

    Specified by:
      `saveAndReloadArtifact` in interface `BaseArtifactService`
    Parameters:
      `appName` - the app name
      `userId` - the user ID
      `sessionId` - the session ID
      `filename` - the filename
      `artifact` - the artifact to save
    Returns:
      the saved artifact with fileData if available.