FileArtifactService

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.

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)

Types

Link copied to clipboard
object Companion

Functions

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

Deletes an artifact.

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

Lists the filenames of all artifacts within a session.

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

Lists all the versions (as revision IDs) of an artifact.

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

Gets an artifact.

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

Saves an artifact and returns it with fileData if available.

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

Saves an artifact.