artifacts.go

Overview

The artifacts.go file defines the ArtifactsAPIController, which implements HTTP handlers to provide a RESTful API for managing artifacts associated with user-agent interaction sessions. Artifacts represent files or blobs stored and versioned within a session context, enabling persistence and retrieval of data generated or consumed by agents.

This controller exposes endpoints to:

It acts as an intermediary between HTTP clients and the underlying artifact storage service, handling request validation, parameter parsing, error handling, and encoding JSON responses.

The file is part of the controllers package and integrates with:


Types and Functions

ArtifactsAPIController

type ArtifactsAPIController struct {
	artifactService artifact.Service
}

Description:
This struct is the main controller type for artifact-related REST API endpoints. It holds a reference to an artifact.Service implementation, which provides the core artifact management functions such as listing, loading, and deleting artifacts.

Usage:
Instantiate with NewArtifactsAPIController by injecting an artifact.Service to enable API handlers to delegate artifact operations.


NewArtifactsAPIController

func NewArtifactsAPIController(artifactService artifact.Service) *ArtifactsAPIController

Description:
Creates a new ArtifactsAPIController instance with the provided artifact service.

Parameters:

Returns:

Example:

svc := artifact.NewInMemoryService()
controller := NewArtifactsAPIController(svc)

ListArtifactsHandler

func (c *ArtifactsAPIController) ListArtifactsHandler(rw http.ResponseWriter, req *http.Request)

Description:
HTTP handler that lists artifact filenames within a specified session.

Request Parameters:

Behavior:

Response:

Example:
GET /api/sessions/{app_name}/{user_id}/{session_id}/artifacts


LoadArtifactHandler

func (c *ArtifactsAPIController) LoadArtifactHandler(rw http.ResponseWriter, req *http.Request)

Description:
HTTP handler to load the content of a specific artifact by name for a session. Supports optional version parameter via query string.

Request Parameters:

Behavior:

Response:

Example:
GET /api/sessions/{app_name}/{user_id}/{session_id}/artifacts/{artifact_name}?version=2


LoadArtifactVersionHandler

func (c *ArtifactsAPIController) LoadArtifactVersionHandler(rw http.ResponseWriter, req *http.Request)

Description:
HTTP handler that loads a specific version of an artifact by name from a session. The version is specified as a path variable.

Request Parameters:

Behavior:

Response:

Example:
GET /api/sessions/{app_name}/{user_id}/{session_id}/artifacts/{artifact_name}/versions/{version}


DeleteArtifactHandler

func (c *ArtifactsAPIController) DeleteArtifactHandler(rw http.ResponseWriter, req *http.Request)

Description:
HTTP handler that deletes an artifact from a session.

Request Parameters:

Behavior:

Response:

Example:
DELETE /api/sessions/{app_name}/{user_id}/{session_id}/artifacts/{artifact_name}


Implementation Details and Algorithms


Interaction with Other System Components


Usage Examples

List Artifacts in a Session

GET /api/sessions/myapp/user123/session456/artifacts

Response:

[
  "output.json",
  "log.txt",
  "result.csv"
]

Load Artifact Content (Latest Version)

GET /api/sessions/myapp/user123/session456/artifacts/output.json

Response:

{
  "data": "base64-encoded-content",
  "size": 1024,
  "version": 5
}

Load Specific Artifact Version

GET /api/sessions/myapp/user123/session456/artifacts/output.json/versions/3

Response:

{
  "data": "base64-encoded-content",
  "size": 900,
  "version": 3
}

Delete an Artifact

DELETE /api/sessions/myapp/user123/session456/artifacts/log.txt

Response:

null

Diagram: ArtifactsAPIController Structure and Handler Relationships

classDiagram
class ArtifactsAPIController {
-artifactService: artifact.Service
+ListArtifactsHandler()
+LoadArtifactHandler()
+LoadArtifactVersionHandler()
+DeleteArtifactHandler()
}

References