// Generated by openapi-moonbit — DO NOT EDIT
// Spec SHA-256: 7e574664c0f434e52021e12f313a3266fd3175fe2ecddde4c0e0930549c72ba2
///|
/// Operations in the `Worker` group. Implement this trait to mock or wrap `Client`.
pub(open) trait WorkerClient {
async fn get_workers_metadata(
self : Self,
component_id~ : @uuid.UUID,
filter? : Array[String],
cursor? : String,
count? : UInt64,
precise? : Bool,
) -> @model.WorkersMetadataResponse raise GolemError
async fn launch_new_worker(
self : Self,
component_id~ : @uuid.UUID,
body~ : @model.AgentCreationRequest,
) -> @model.WorkerCreationResponse raise GolemError
async fn get_worker_metadata(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.AgentMetadataDto raise GolemError
async fn delete_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.DeleteWorkerResponse raise GolemError
async fn complete_promise(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.CompleteParameters,
) -> Bool raise GolemError
async fn interrupt_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
recovery_immediately? : Bool,
) -> @model.InterruptResponse raise GolemError
async fn find_workers_metadata(
self : Self,
component_id~ : @uuid.UUID,
body~ : @model.WorkersMetadataRequest,
) -> @model.WorkersMetadataResponse raise GolemError
async fn resume_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.ResumeResponse raise GolemError
async fn update_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.UpdateWorkerRequest,
) -> @model.UpdateWorkerResponse raise GolemError
async fn get_oplog(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
count~ : UInt64,
from? : UInt64,
cursor? : @model.OplogCursor,
query? : String,
) -> @model.GetOplogResponse raise GolemError
async fn get_oplog_entry(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
oplog_index~ : UInt64,
component_revision? : UInt64,
) -> @model.PublicOplogEntryWithIndex raise GolemError
async fn get_files(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
file_name~ : String,
) -> @model.GetFilesResponse raise GolemError
async fn get_agent_wallet(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> Array[@model.StoredCard] raise GolemError
async fn get_file_content(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
file_name~ : String,
) -> Bytes raise GolemError
async fn activate_plugin(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
plugin_priority~ : Int32,
) -> @model.ActivatePluginResponse raise GolemError
async fn deactivate_plugin(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
plugin_priority~ : Int32,
) -> @model.DeactivatePluginResponse raise GolemError
async fn revert_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.RevertWorkerTarget,
) -> @model.RevertWorkerResponse raise GolemError
async fn fork_worker(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.ForkWorkerRequest,
) -> @model.ForkWorkerResponse raise GolemError
async fn cancel_invocation(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
idempotency_key~ : String,
) -> @model.CancelInvocationResponse raise GolemError
async fn worker_connect(
self : Self,
component_id~ : @uuid.UUID,
agent_name~ : String,
protocols? : Array[String],
) -> &@ws.WsConn raise GolemError
}
///|
/// Get metadata of multiple workers
/// ### Filters
///
/// | Property | Comparator | Description | Example |
/// |-------------|------------------------|--------------------------------|----------------------------------|
/// | name | StringFilterComparator | Name of worker | `name = worker-name` |
/// | version | FilterComparator | Version of worker | `version >= 0` |
/// | status | FilterComparator | Status of worker | `status = Running` |
/// | env.\[key\] | StringFilterComparator | Environment variable of worker | `env.var1 = value` |
/// | createdAt | FilterComparator | Creation time of worker | `createdAt > 2024-04-01T12:10:00Z` |
///
///
/// ### Comparators
///
/// - StringFilterComparator: `eq|equal|=|==`, `ne|notequal|!=`, `like`, `notlike`
/// - FilterComparator: `eq|equal|=|==`, `ne|notequal|!=`, `ge|greaterequal|>=`, `gt|greater|>`, `le|lessequal|<=`, `lt|less|<`
///
/// Returns metadata about an existing component workers:
/// - `workers` list of workers metadata
/// - `cursor` cursor for next request, if cursor is empty/null, there are no other values
///
/// `GET /v1/components/{component_id}/workers` (`get_workers_metadata`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_workers_metadata(
self : Client[T],
component_id~ : @uuid.UUID,
filter? : Array[String],
cursor? : String,
count? : UInt64,
precise? : Bool,
) -> @model.WorkersMetadataResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
match filter {
Option::Some(__qv) => {
let _ = __qb.add_array(
"filter",
__qv,
style=@encoding.QueryStyle::Form,
explode=true,
)
}
Option::None => ()
}
match cursor {
Option::Some(__qv) => {
let _ = __qb.add_scalar("cursor", __qv)
}
Option::None => ()
}
match count {
Option::Some(__qv) => {
let _ = __qb.add_scalar("count", @encoding.format_uint64(__qv))
}
Option::None => ()
}
match precise {
Option::Some(__qv) => {
let _ = __qb.add_scalar("precise", @encoding.format_bool(__qv))
}
Option::None => ()
}
let __req = self.prepare_request(
http_method="GET",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.WorkersMetadataResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Launch a new worker.
/// Creates a new worker. The worker initially is in `Idle`` status, waiting to be invoked.
///
/// The parameters in the request are the following:
/// - `name` is the name of the created worker. This has to be unique, but only for a given component
/// - `args` is a list of strings which appear as command line arguments for the worker
/// - `env` is a list of key-value pairs (represented by arrays) which appear as environment variables for the worker
///
/// `POST /v1/components/{component_id}/workers` (`launch_new_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn launch_new_worker(
self : Client[T],
component_id~ : @uuid.UUID,
body~ : @model.AgentCreationRequest,
) -> @model.WorkerCreationResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.WorkerCreationResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get metadata of a worker
/// Returns metadata about an existing worker:
/// - `workerId` is a combination of the used component and the worker's user specified name
/// - `accountId` the account the worker is created by
/// - `args` is the provided command line arguments passed to the worker
/// - `env` is the provided map of environment variables passed to the worker
/// - `componentVersion` is the version of the component used by the worker
/// - `retryCount` is the number of retries the worker did in case of a failure
/// - `status` is the worker's current status, one of the following:
/// - `Running` if the worker is currently executing
/// - `Idle` if the worker is waiting for an invocation
/// - `Suspended` if the worker was running but is now waiting to be resumed by an event (such as end of a sleep, a promise, etc)
/// - `Interrupted` if the worker was interrupted by the user
/// - `Retrying` if the worker failed, and an automatic retry was scheduled for it
/// - `Failed` if the worker failed and there are no more retries scheduled for it
/// - `Exited` if the worker explicitly exited using the exit WASI function
///
/// `GET /v1/components/{component_id}/workers/{agent_name}` (`get_worker_metadata`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_worker_metadata(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.AgentMetadataDto raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}", __path_params,
)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.AgentMetadataDto)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Delete a worker
/// Interrupts and deletes an existing worker.
///
/// `DELETE /v1/components/{component_id}/workers/{agent_name}` (`delete_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn delete_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.DeleteWorkerResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}", __path_params,
)
let __req = self.prepare_request(http_method="DELETE", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Complete a promise
/// Completes a promise with a given custom array of bytes.
/// The promise must be previously created from within the worker, and it's identifier (a combination of a worker identifier and an oplogIdx ) must be sent out to an external caller so it can use this endpoint to mark the promise completed.
/// The data field is sent back to the worker, and it has no predefined meaning.
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/complete` (`complete_promise`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn complete_promise(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.CompleteParameters,
) -> Bool raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/complete", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 => self.decode_json_response(__resp, __r => __r.read_bool())
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Interrupt a worker
/// Interrupts the execution of a worker.
/// The worker's status will be Interrupted unless the recover-immediately parameter was used, in which case it remains as it was.
/// An interrupted worker can be still used, and it is going to be automatically resumed the first time it is used.
/// For example in case of a new invocation, the previously interrupted invocation is continued before the new one gets processed.
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/interrupt` (`interrupt_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn interrupt_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
recovery_immediately? : Bool,
) -> @model.InterruptResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/interrupt", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
match recovery_immediately {
Option::Some(__qv) => {
let _ = __qb.add_scalar(
"recovery-immediately",
@encoding.format_bool(__qv),
)
}
Option::None => ()
}
let __req = self.prepare_request(
http_method="POST",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Advanced search for workers
/// ### Filter types
/// | Type | Comparator | Description | Example |
/// |-----------|------------------------|--------------------------------|-----------------------------------------------------------------------------------------------|
/// | Name | StringFilterComparator | Name of worker | `{ "type": "Name", "comparator": "Equal", "value": "worker-name" }` |
/// | Version | FilterComparator | Version of worker | `{ "type": "Version", "comparator": "GreaterEqual", "value": 0 }` |
/// | Status | FilterComparator | Status of worker | `{ "type": "Status", "comparator": "Equal", "value": "Running" }` |
/// | Env | StringFilterComparator | Environment variable of worker | `{ "type": "Env", "name": "var1", "comparator": "Equal", "value": "value" }` |
/// | CreatedAt | FilterComparator | Creation time of worker | `{ "type": "CreatedAt", "comparator": "Greater", "value": "2024-04-01T12:10:00Z" }` |
/// | And | | And filter combinator | `{ "type": "And", "filters": [ ... ] }` |
/// | Or | | Or filter combinator | `{ "type": "Or", "filters": [ ... ] }` |
/// | Not | | Negates the specified filter | `{ "type": "Not", "filter": { "type": "Version", "comparator": "GreaterEqual", "value": 0 } }`|
///
/// ### Comparators
/// - StringFilterComparator: `Equal`, `NotEqual`, `Like`, `NotLike`
/// - FilterComparator: `Equal`, `NotEqual`, `GreaterEqual`, `Greater`, `LessEqual`, `Less`
///
/// Returns metadata about an existing component workers:
/// - `workers` list of workers metadata
/// - `cursor` cursor for next request, if cursor is empty/null, there are no other values
///
/// `POST /v1/components/{component_id}/workers/find` (`find_workers_metadata`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn find_workers_metadata(
self : Client[T],
component_id~ : @uuid.UUID,
body~ : @model.WorkersMetadataRequest,
) -> @model.WorkersMetadataResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/find", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.WorkersMetadataResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Resume a worker
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/resume` (`resume_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn resume_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> @model.ResumeResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/resume", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Update a worker
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/update` (`update_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn update_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.UpdateWorkerRequest,
) -> @model.UpdateWorkerResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/update", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.UpdateWorkerResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get the oplog of a worker
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/oplog` (`get_oplog`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_oplog(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
count~ : UInt64,
from? : UInt64,
cursor? : @model.OplogCursor,
query? : String,
) -> @model.GetOplogResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/oplog", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
match from {
Option::Some(__qv) => {
let _ = __qb.add_scalar("from", @encoding.format_uint64(__qv))
}
Option::None => ()
}
let _ = __qb.add_scalar("count", @encoding.format_uint64(count))
match cursor {
Option::Some(__qv) => {
let __pairs : Array[(String, String)] = []
__pairs.push(
("nextOplogIndex", @encoding.format_uint64(__qv.next_oplog_index)),
)
__pairs.push(
(
"currentComponentRevision",
@encoding.format_uint64(__qv.current_component_revision),
),
)
let _ = __qb.add_object(
"cursor",
__pairs,
style=@encoding.QueryStyle::Form,
explode=true,
)
}
Option::None => ()
}
match query {
Option::Some(__qv) => {
let _ = __qb.add_scalar("query", __qv)
}
Option::None => ()
}
let __req = self.prepare_request(
http_method="GET",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.GetOplogResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get one oplog entry of a worker
/// Oplog pages omit entries whose encoded form is larger than a server limit, and describe
/// them by their type, timestamp, size and component revision. This endpoint returns such an
/// entry in full. Pass the component revision of the description to save the server from
/// scanning the oplog for it.
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/oplog/{oplog_index}` (`get_oplog_entry`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_oplog_entry(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
oplog_index~ : UInt64,
component_revision? : UInt64,
) -> @model.PublicOplogEntryWithIndex raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
__path_params.push(("oplog_index", @encoding.format_uint64(oplog_index)))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/oplog/{oplog_index}", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
match component_revision {
Option::Some(__qv) => {
let _ = __qb.add_scalar(
"component_revision",
@encoding.format_uint64(__qv),
)
}
Option::None => ()
}
let __req = self.prepare_request(
http_method="GET",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.PublicOplogEntryWithIndex)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// List files in a worker
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/files/{file_name}` (`get_files`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_files(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
file_name~ : String,
) -> @model.GetFilesResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
__path_params.push(("file_name", file_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/files/{file_name}", __path_params,
)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.GetFilesResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get the wallet (active permission cards) of a worker.
/// Activates the worker if it is not already active.
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/wallet` (`get_agent_wallet`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_agent_wallet(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
) -> Array[@model.StoredCard] raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/wallet", __path_params,
)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
__r
.read_array()
.map(__el_0 => {
(
@cjson.FromJson::from_json(__el_0.raw(), __el_0.context()) :
@model.StoredCard)
})
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Get contents of a file in a worker
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/file-contents/{file_name}` (`get_file_content`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn get_file_content(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
file_name~ : String,
) -> Bytes raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
__path_params.push(("file_name", file_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/file-contents/{file_name}",
__path_params,
)
let __req = self.prepare_request(http_method="GET", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 => __resp.body()
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Activate a plugin
/// The plugin must be one of the installed plugins for the worker's current component version.
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/activate-plugin` (`activate_plugin`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn activate_plugin(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
plugin_priority~ : Int32,
) -> @model.ActivatePluginResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/activate-plugin", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
let _ = __qb.add_scalar(
"plugin-priority",
@encoding.format_int32(plugin_priority),
)
let __req = self.prepare_request(
http_method="POST",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Deactivate a plugin
/// The plugin must be one of the installed plugins for the worker's current component version.
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/deactivate-plugin` (`deactivate_plugin`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn deactivate_plugin(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
plugin_priority~ : Int32,
) -> @model.DeactivatePluginResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/deactivate-plugin", __path_params,
)
let __qb = @encoding.QueryBuilder::new()
let _ = __qb.add_scalar(
"plugin-priority",
@encoding.format_int32(plugin_priority),
)
let __req = self.prepare_request(
http_method="POST",
path=__path,
query=__qb.build(),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Revert a worker
/// Reverts a worker by undoing either the last few invocations or the last few recorded oplog entries.
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/revert` (`revert_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn revert_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.RevertWorkerTarget,
) -> @model.RevertWorkerResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/revert", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Fork a worker
/// Fork a worker by creating a new worker with the oplog up to the provided index
///
/// `POST /v1/components/{component_id}/workers/{agent_name}/fork` (`fork_worker`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn fork_worker(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
body~ : @model.ForkWorkerRequest,
) -> @model.ForkWorkerResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/fork", __path_params,
)
let __req = self.prepare_request(http_method="POST", path=__path)
let _ = __req.with_body(
content_type="application/json",
body=@runtime.utf8_encode(body.to_json().stringify()),
)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
if __resp.body().is_empty() {
@cjson.Json::null()
} else {
let __b = __resp.text()
@rjson.parse_json(__b) catch {
e => {
let __err = GolemError::Decode(
status=__resp.status(),
message=e.to_string(),
body=__b,
)
raise __err
}
}
}
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Cancels a pending invocation if it has not started yet
/// The invocation to be cancelled is identified by the idempotency key passed to the invoke API.
///
/// `DELETE /v1/components/{component_id}/workers/{agent_name}/invocations/{idempotency_key}` (`cancel_invocation`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn cancel_invocation(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
idempotency_key~ : String,
) -> @model.CancelInvocationResponse raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
__path_params.push(("idempotency_key", idempotency_key))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/invocations/{idempotency_key}",
__path_params,
)
let __req = self.prepare_request(http_method="DELETE", path=__path)
let __resp = self.send_request(__req)
match __resp.status() {
200 =>
self.decode_json_response(__resp, __r => {
(
@cjson.FromJson::from_json(__r.raw(), __r.context()) :
@model.CancelInvocationResponse)
})
_ => raise self.api_error_from_response(__resp)
}
}
///|
/// Connect to a worker using a websocket and stream events
///
/// `GET /v1/components/{component_id}/workers/{agent_name}/connect` (`worker_connect`).
pub impl[T : @runtime.Transport] WorkerClient for Client[T] with fn worker_connect(
self : Client[T],
component_id~ : @uuid.UUID,
agent_name~ : String,
protocols? : Array[String],
) -> &@ws.WsConn raise GolemError {
let __path_params : Array[(String, String)] = []
__path_params.push(("component_id", component_id.to_string()))
__path_params.push(("agent_name", agent_name))
let __path = self.expand_op_path(
"/v1/components/{component_id}/workers/{agent_name}/connect", __path_params,
)
let __req = self.prepare_request(
http_method="GET",
path=__path,
apply_auth=false,
)
let __dialer = match self.ws_dialer {
Option::Some(d) => d
Option::None => {
let __err = GolemError::InvalidParam(
name="ws_dialer",
message="WebSocket operation requires a WebSocketDialer",
)
raise __err
}
}
let __ws_url = http_url_to_ws(__req.url())
let __protocols = protocols.unwrap_or([])
__dialer.dial(url=__ws_url, headers=__req.headers(), protocols=__protocols) catch {
e => {
let __err = GolemError::WebSocket(e)
raise __err
}
}
}
///|
pub extend Client with WorkerClient::{
get_workers_metadata,
launch_new_worker,
get_worker_metadata,
delete_worker,
complete_promise,
interrupt_worker,
find_workers_metadata,
resume_worker,
update_worker,
get_oplog,
get_oplog_entry,
get_files,
get_agent_wallet,
get_file_content,
activate_plugin,
deactivate_plugin,
revert_worker,
fork_worker,
cancel_invocation,
worker_connect,
}