`GcsArtifactService` 类

java.lang.Object
com.google.adk.artifacts.GcsArtifactService
All Implemented Interfaces:
BaseArtifactService

public final class GcsArtifactService extends Object implements BaseArtifactService
这是一个使用 Google Cloud Storage (GCS) 实现的工件(artifact)服务。
  • 构造函数详细信息

    • GcsArtifactService

      public GcsArtifactService(String bucketName, com.google.cloud.storage.Storage storageClient)
      用于初始化 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)
      将某个“工件”(artifact)保存到 Google Cloud Storage (GCS) 并为其分配一个新的版本号。
      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)
      从 GCS 加载一个工件(artifact)。
      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)
      列出用户和会话对应的工件文件名。
      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)
      从 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)
      列出给定软件包(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)
      描述内容复制自接口文档: BaseArtifactService
      保存一个“artefact”(即某种数据或对象),并在文件数据(fileData)可用时将其一并返回。

      为了提高效率,实现类应该覆盖这个默认方法;因为默认方法会执行两次 I/O 操作(先保存数据,再读取数据)。

      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.