文件Artifact服务(Service)

An ArtifactService that persists artifacts on the local filesystem.

The on-disk layout mirrors the other ADK file-backed artifact services so the same directory can be opened interchangeably across language ports. Each artifact version is a directory holding the raw payload (named after the artifact's basename) plus a metadata.json sidecar:

<baseDir>/users/<userId>/sessions/<sessionId>/artifacts/<artifactPath>/versions/<v>/<basename>
<baseDir>/users/<userId>/sessions/<sessionId>/artifacts/<artifactPath>/versions/<v>/metadata.json
<baseDir>/users/<userId>/artifacts/<artifactPath>/versions/<v>/<basename> # user-scoped

An artifact is user-scoped when the session id is null or the filename starts with user: (the prefix is stripped from the path and preserved in metadata). <artifactPath> is derived from the filename, so nested names such as images/photo.png create nested directories; absolute paths and names that traverse outside the storage scope (e.g. ../secret) are rejected.

Saving an artifact whose final path segment is metadata.json or whose scope-relative path contains a versions segment is rejected in any casing, including trailing dots or spaces. Existing artifacts with these names remain readable and deletable.

Versions are 0-based and increase monotonically. A version is published atomically by staging its payload and metadata in a temporary directory and renaming it into place, so concurrent readers only ever observe complete versions (payload and metadata together). Writes to the same artifact are additionally serialized by an in-process per-artifact lock; this does not coordinate across separate OS processes.

This impl lives in commonJvmAndroidMain because it only needs java.io.File, so the same code serves both Android and the JVM. On Android, prefer the fromContext factory (in the androidMain source set) which roots baseDir at the app-specific external files directory.

构造函数(Constructors)

Link copied to clipboard
constructor(baseDir: String)

类型

Link copied to clipboard
object Companion

函数

Link copied to clipboard
open suspend override fun deleteArtifact(sessionKey: SessionKey, filename: String)

删除一个工件(artifact)。

Link copied to clipboard
open suspend override fun listArtifactKeys(sessionKey: SessionKey): List<String>

列出当前会话中可见的文件名:包括会话自身生成的文件以及用户创建的文件。 user: ones.

Link copied to clipboard
open suspend override fun listVersions(sessionKey: SessionKey, filename: String): List<Int>

列出某个软件组件的所有版本(以修订版本号的形式表示)。

Link copied to clipboard
open suspend override fun loadArtifact(sessionKey: SessionKey, filename: String, version: Int? = null): Part?

获取一个工件(artifact)。

Link copied to clipboard
open suspend override fun saveAndReloadArtifact(sessionKey: SessionKey, filename: String, artifact: Part): Part

保存一个“artefact”(即某种数据或对象),并在文件数据(fileData)可用时将其一并返回。

Link copied to clipboard
open suspend override fun saveArtifact(sessionKey: SessionKey, filename: String, artifact: Part): Int

用于保存某个“文物”(即某个具有特殊价值或历史意义的物品)。