Documentation
¶
Overview ¶
Package workspace manages workspace directories and the file operations exposed over the API.
A managed workspace is a directory directly under the store root, named by its ID. A host-directory attachment points at an existing project directory inside an allowed root (NATIVE_AGENT_ALLOWED_ROOTS); its record is stored under <root>/.attachments and removing the workspace removes only that record. Every path supplied by a client is resolved relative to the workspace directory; traversal and symbolic links are rejected so a request can never reach outside the workspace.
Index ¶
- Variables
- func MediaType(filePath string) string
- type Attachment
- type ConflictPolicy
- type Entry
- type Info
- type Store
- func (s *Store) AttachHostDirectory(path string) (Info, error)
- func (s *Store) Copy(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)
- func (s *Store) Create() (string, error)
- func (s *Store) CreateDirectory(id, requestedPath string, conflict ConflictPolicy) (Entry, error)
- func (s *Store) Delete(id, requestedPath string) error
- func (s *Store) Dir(id string) (string, error)
- func (s *Store) Health() error
- func (s *Store) Info(id string) (Info, error)
- func (s *Store) List(id string) ([]Entry, error)
- func (s *Store) Move(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)
- func (s *Store) Open(id, requestedPath string) (*os.File, Entry, error)
- func (s *Store) Protect(dirs ...string)
- func (s *Store) Remove(id string) error
- func (s *Store) Upload(id, requestedPath string, source io.Reader) (UploadedFile, error)
- func (s *Store) Workspaces() ([]Info, error)
- type Times
- type UploadedFile
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidID = errors.New("workspace id is invalid") ErrNotFound = errors.New("not found") ErrInvalidPath = errors.New("file path is invalid") ErrFileTooLarge = errors.New("file exceeds the configured upload limit") ErrTooManyEntries = errors.New("workspace contains too many entries") ErrIsDirectory = errors.New("target is a directory") ErrPathConflict = errors.New("destination already exists") ErrInvalidOperation = errors.New("file operation is invalid") // ErrAttachmentDisabled is returned when no allowed roots are configured. ErrAttachmentDisabled = errors.New("host-directory attachments need NATIVE_AGENT_ALLOWED_ROOTS") )
Sentinel errors returned by Store. Callers map them to API status codes with errors.Is.
Functions ¶
Types ¶
type Attachment ¶
type Attachment struct {
Path string `json:"path"`
State string `json:"state" enum:"ready,unavailable" doc:"unavailable: the directory is gone or no longer inside an allowed root."`
}
Attachment is the host directory backing an attached workspace.
type ConflictPolicy ¶
type ConflictPolicy string
ConflictPolicy defines what a file operation does when its destination exists.
const ( ConflictError ConflictPolicy = "error" ConflictReplace ConflictPolicy = "replace" )
type Entry ¶
type Entry struct {
Path string `json:"path"`
Directory bool `json:"directory"`
Size int64 `json:"size"`
MediaType string `json:"media_type,omitempty"`
Modified time.Time `json:"modified_at"`
}
Entry describes one file or directory inside a workspace.
type Info ¶
type Info struct {
ID string `json:"workspace_id"`
Storage string `json:"storage" enum:"managed,attachment" doc:"managed: a directory the gateway owns; attachment: a host directory."`
// Attachment is present when Storage is attachment.
Attachment *Attachment `json:"attachment,omitempty"`
Times Times `json:"times"`
}
Info describes a workspace.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store owns the workspace root directory.
func NewStore ¶
NewStore creates root (mode 0700) when missing and returns a Store backed by it. roots (may be nil) are the directories that can be attached as workspaces.
func (*Store) AttachHostDirectory ¶
AttachHostDirectory registers an existing directory inside an allowed root. Attaching the same directory again returns the existing workspace.
func (*Store) Copy ¶
func (s *Store) Copy(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)
Copy copies a regular file or directory tree. Symbolic links and special files are rejected.
func (*Store) CreateDirectory ¶
func (s *Store) CreateDirectory(id, requestedPath string, conflict ConflictPolicy) (Entry, error)
CreateDirectory creates one directory. Its parent must already exist.
func (*Store) Health ¶
Health verifies that the configured storage root is still an accessible directory.
func (*Store) List ¶
List returns every entry in the workspace sorted by path. Symbolic links are skipped.
func (*Store) Move ¶
func (s *Store) Move(id, sourcePath, destinationPath string, conflict ConflictPolicy) (Entry, error)
Move renames a regular file or directory inside one workspace.
func (*Store) Protect ¶
Protect adds directories that attachments must neither be inside nor contain. Call it before serving requests.
func (*Store) Remove ¶
Remove deletes a managed workspace with all of its contents, or only the record of an attached workspace (the project directory is never touched).
func (*Store) Upload ¶
Upload streams source into requestedPath atomically (temporary file + rename) and returns the stored file metadata together with its SHA-256 digest.
func (*Store) Workspaces ¶
Workspaces lists managed and attached workspaces.
type Times ¶
type Times struct {
CreatedAt time.Time `json:"created_at" doc:"When the workspace was created or attached."`
// LastUsedAt is the latest session activity in the workspace (a run starting, binding its
// conversation or finishing); absent before the first run.
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
}
Times are a workspace's timestamps.
type UploadedFile ¶
UploadedFile is the result of a successful upload.