Payloads service¶
consortium.server.services.payloads_service
¶
PayloadsService(events_service, repository_service, agent_templates_service)
¶
repository_directory_path = repository_service.repository_directory_path
instance-attribute
¶
load_repository_metadata()
¶
save_repository_metadata()
¶
reserve_resource_id()
¶
Generates and reserves a resource ID to be claimed later during payload creation.
Reservations are required when the caller needs to know the resource ID before
the payload file or directory has been created (e.g., to name the file after the
ID). The reserved ID must be provided as resource_id to create_payload_file
or create_payload_directory.
Returns:
| Type | Description |
|---|---|
UUID
|
The reserved resource ID. |
create_payload_file(agent_template_id, build_parameters, content, payload_data=None, resource_id=None, name=None, description='')
async
¶
Creates a file-based payload and associates it with an agent template.
Build parameters are validated against the agent template before creating the
resource. If resource_id is provided it must have been previously reserved via
reserve_resource_id. Emits a PAYLOAD_CREATED event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_template_id
|
str | UUID
|
The ID of the agent template to associate with the payload. |
required |
build_parameters
|
dict[str, Any]
|
Parameters used to build the agent generator from the template (validated against the template). |
required |
content
|
str | bytes | TextIO | BinaryIO
|
The file content to write to the repository. |
required |
payload_data
|
dict[str, Any] | None
|
Arbitrary metadata attached to the
payload. When |
None
|
resource_id
|
str | UUID | None
|
A previously reserved ID to assign to
this payload. When |
None
|
name
|
str | None
|
A human-readable name for the payload file. When |
None
|
description
|
str
|
An optional description for the payload. |
''
|
Returns:
| Type | Description |
|---|---|
Payload
|
The created payload. |
Raises:
| Type | Description |
|---|---|
AgentTemplateIDNotFoundError
|
If no agent template with the given ID exists. |
MissingRequiredAgentTemplateOptionError
|
If a required option is absent
from |
AgentTemplateOptionNotFoundError
|
If |
AgentTemplateOptionValueValidationError
|
If an option value in
|
AgentTemplateValidatingFunctionError
|
If the agent template's validating function rejects the resolved options. |
ResourceIDReservationNotFoundError
|
If |
RepositoryResourceFileSystemError
|
If the file cannot be written to disk. |
RepositoryMetadataFileSystemError
|
If the payload metadata cannot be written to disk after the file is written. |
UnicodeDecodeError
|
If |
add_payload_file(agent_template_id, build_parameters, path, payload_data=None, resource_id=None, name=None, description='', copy=False)
async
¶
Registers an existing file on disk as a file-based payload.
Unlike create_payload_file, no new file is written. The file at path
is moved (or copied when copy=True) into the repository. Build parameters
are validated against the agent template before registration. If resource_id
is provided it must have been previously reserved via reserve_resource_id.
Emits a PAYLOAD_CREATED event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_template_id
|
str | UUID
|
The ID of the agent template to associate with the payload. |
required |
build_parameters
|
dict[str, Any]
|
Parameters used to build the agent generator from the template (validated against the template). |
required |
path
|
Path | str
|
Path to the existing file to register. |
required |
payload_data
|
dict[str, Any] | None
|
Arbitrary metadata attached to
the payload. When |
None
|
resource_id
|
str | UUID | None
|
A previously reserved ID to
assign to this payload. When |
None
|
name
|
str | None
|
A human-readable name for the payload file. When
|
None
|
description
|
str
|
An optional description for the payload. |
''
|
copy
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Payload
|
The registered payload. |
Raises:
| Type | Description |
|---|---|
AgentTemplateIDNotFoundError
|
If no agent template with the given ID exists. |
MissingRequiredAgentTemplateOptionError
|
If a required option is absent
from |
AgentTemplateOptionNotFoundError
|
If |
AgentTemplateOptionValueValidationError
|
If an option value in
|
AgentTemplateValidatingFunctionError
|
If the agent template's validating function rejects the resolved options. |
ResourceIDReservationNotFoundError
|
If |
RepositoryResourceFileSystemError
|
If no file exists at |
RepositoryMetadataFileSystemError
|
If the payload metadata cannot be written to disk afterwards. |
create_payload_directory(agent_template_id, build_parameters, content, payload_data=None, resource_id=None, archive_file_format='zip', name=None, description='')
async
¶
Creates a directory-based payload by extracting an archive and associating it with an agent template.
Build parameters are validated against the agent template before creating the
resource. If resource_id is provided it must have been previously reserved via
reserve_resource_id. Emits a PAYLOAD_CREATED event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_template_id
|
str | UUID
|
The ID of the agent template to associate with the payload. |
required |
build_parameters
|
dict[str, Any]
|
Parameters used to build the agent generator from the template (validated against the template). |
required |
content
|
bytes | BinaryIO
|
The archive content to extract into the repository directory. |
required |
payload_data
|
dict[str, Any] | None
|
Arbitrary metadata attached to the
payload. When |
None
|
resource_id
|
str | UUID | None
|
A previously reserved ID to assign to
this payload. When |
None
|
archive_file_format
|
Literal['zip', 'tar', 'gztar', 'bztar', 'xztar']
|
The
format of the archive to extract. Defaults to |
'zip'
|
name
|
str | None
|
A human-readable name for the payload directory. When
|
None
|
description
|
str
|
An optional description for the payload. |
''
|
Returns:
| Type | Description |
|---|---|
Payload
|
The created payload. |
Raises:
| Type | Description |
|---|---|
AgentTemplateIDNotFoundError
|
If no agent template with the given ID exists. |
MissingRequiredAgentTemplateOptionError
|
If a required option is absent
from |
AgentTemplateOptionNotFoundError
|
If |
AgentTemplateOptionValueValidationError
|
If an option value in
|
AgentTemplateValidatingFunctionError
|
If the agent template's validating function rejects the resolved options. |
ResourceIDReservationNotFoundError
|
If |
InvalidRepositoryDirectoryArchiveFileFormatError
|
If |
RepositoryResourceFileSystemError
|
If the directory cannot be created or the archive cannot be unpacked into it. |
RepositoryMetadataFileSystemError
|
If the payload metadata cannot be written to disk after the directory is created. |
add_payload_directory(agent_template_id, build_parameters, path, payload_data=None, resource_id=None, name=None, description='', copy=False)
async
¶
Registers an existing directory on disk as a directory-based payload.
Unlike create_payload_directory, no archive is extracted and no new
directory is created. The directory at path is moved (or copied when
copy=True) into the repository. Build parameters are validated against
the agent template before registration. If resource_id is provided it
must have been previously reserved via reserve_resource_id. Emits a
PAYLOAD_CREATED event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_template_id
|
str | UUID
|
The ID of the agent template to associate with the payload. |
required |
build_parameters
|
dict[str, Any]
|
Parameters used to build the agent generator from the template (validated against the template). |
required |
path
|
Path | str
|
Path to the existing directory to register. |
required |
payload_data
|
dict[str, Any] | None
|
Arbitrary metadata attached to
the payload. When |
None
|
resource_id
|
str | UUID | None
|
A previously reserved ID to
assign to this payload. When |
None
|
name
|
str | None
|
A human-readable name for the payload directory.
When |
None
|
description
|
str
|
An optional description for the payload. |
''
|
copy
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Payload
|
The registered payload. |
Raises:
| Type | Description |
|---|---|
AgentTemplateIDNotFoundError
|
If no agent template with the given ID exists. |
MissingRequiredAgentTemplateOptionError
|
If a required option is absent
from |
AgentTemplateOptionNotFoundError
|
If |
AgentTemplateOptionValueValidationError
|
If an option value in
|
AgentTemplateValidatingFunctionError
|
If the agent template's validating function rejects the resolved options. |
ResourceIDReservationNotFoundError
|
If |
RepositoryResourceFileSystemError
|
If no directory exists at |
RepositoryMetadataFileSystemError
|
If the payload metadata cannot be written to disk afterwards. |
update_payload_by_resource_id(resource_id, name=None, description=None, agent_template_id=None, build_parameters=None, payload_data=None)
async
¶
Updates a payload's mutable metadata.
name and description are updated in place when provided. The payload's stored
data is only rebuilt when agent_template_id is passed, mirroring the parameters
of the payload creation methods: the agent template is resolved and the supplied
build_parameters are validated against it exactly as they would be on creation
before the new metadata is recorded. When agent_template_id is omitted the
existing data is left untouched. Emits a PAYLOAD_UPDATED event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
str | UUID
|
The ID of the payload to update. |
required |
name
|
str | None
|
A new human-readable name for the payload. When |
None
|
description
|
str | None
|
A new description for the payload. When |
None
|
agent_template_id
|
str | UUID | None
|
When provided, rebuilds the payload's |
None
|
build_parameters
|
dict[str, Any] | None
|
Parameters used to build the agent generator from the
template (validated against the template). Only used, and defaulted to an
empty mapping, when |
None
|
payload_data
|
dict[str, Any] | None
|
Arbitrary metadata attached to the payload. Only used when
|
None
|
Returns:
| Type | Description |
|---|---|
Payload
|
The updated payload. |
Raises:
| Type | Description |
|---|---|
ResourceNotFoundError
|
If no payload with the given ID exists. |
RepositoryMetadataFileSystemError
|
If the updated metadata cannot be written to disk. |
AgentTemplateIDNotFoundError
|
If |
MissingRequiredAgentTemplateOptionError
|
If |
AgentTemplateOptionNotFoundError
|
If |
AgentTemplateOptionValueValidationError
|
If |
AgentTemplateValidatingFunctionError
|
If |
delete_payload_by_resource_id(resource_id)
async
¶
Deletes a payload from disk and the repository.
A payload is "just" a repository resource whose data field carries the payload
metadata, so deleting the resource removes the payload in full. The payload's JSON
is snapshotted before removal so it can be carried on the emitted PAYLOAD_DELETED
event, then the resource is deleted from disk and deregistered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resource_id
|
str | UUID
|
The ID of the payload to delete. |
required |
A payload whose file or directory is already missing from the repository directory is deleted successfully: the record is deregistered and the event is still emitted.
Raises:
| Type | Description |
|---|---|
ResourceNotFoundError
|
If no payload with the given ID exists. |
RepositoryResourceFileSystemError
|
If the payload's file or directory exists on disk but cannot be deleted. |
RepositoryMetadataFileSystemError
|
If the metadata file cannot be written to disk after deletion. |