#[cfg(test)]
test_r::enable!();
pub use uuid::Uuid;
pub use wasip3;
#[doc(hidden)]
#[cfg(feature = "export_golem_agentic")]
pub fn __link_golem_component_exports() {
#[cfg(target_arch = "wasm32")]
agentic::exports::raw::link();
}
#[macro_export]
#[cfg(feature = "export_golem_agentic")]
macro_rules! export_golem_component {
() => {
$crate::ctor::__support::ctor_parse!(
#[ctor]
fn __golem_link_component_exports() {
$crate::__link_golem_component_exports();
}
);
};
}
pub use golem_schema;
pub use golem_schema::schema;
pub use golem_schema::schema::wit::direct::{FromWire, IntoWire, WireSchema};
pub use golem_schema::schema::{
FromSchema, IntoSchema, IntoTypedSchemaValue, Quantity, QuantityUnit, Schema,
SchemaFingerprintError, SchemaFingerprintV1, SchemaGraph, SchemaType, SchemaValue,
TypedSchemaValue, schema_fingerprint_v1,
};
#[cfg(feature = "macro")]
pub use golem_schema::schema::{FromWire, IntoWire, WireSchema};
pub use golem_schema::{AgentId, CardId, ComponentId, EnvironmentId, PromiseId};
pub fn encode_schema_graph(
graph: &SchemaGraph,
) -> Result<schema::wit::wire::SchemaGraph, schema::wit::EncodeError> {
schema::wit::encode_graph(graph)
}
pub fn decode_schema_graph(
graph: &schema::wit::wire::SchemaGraph,
) -> Result<SchemaGraph, schema::wit::DecodeError> {
schema::wit::decode_graph(graph)
}
pub fn encode_schema_value(
value: &SchemaValue,
) -> Result<schema::wit::wire::SchemaValueTree, schema::wit::EncodeError> {
schema::wit::encode_value(value)
}
pub async fn encode_schema_value_async(
value: &SchemaValue,
) -> Result<schema::wit::wire::SchemaValueTree, schema::wit::EncodeError> {
schema::wit::encode_value_async(value).await
}
pub fn decode_schema_value(
value: schema::wit::wire::SchemaValueTree,
) -> Result<SchemaValue, schema::wit::DecodeError> {
schema::wit::decode_value(value)
}
pub fn encode_typed_schema_value(
value: &TypedSchemaValue,
) -> Result<schema::wit::wire::TypedSchemaValue, schema::wit::EncodeError> {
schema::wit::encode_typed(value)
}
pub async fn encode_typed_schema_value_async(
value: &TypedSchemaValue,
) -> Result<schema::wit::wire::TypedSchemaValue, schema::wit::EncodeError> {
schema::wit::encode_typed_async(value).await
}
pub fn decode_typed_schema_value(
value: &schema::wit::wire::TypedSchemaValue,
) -> Result<TypedSchemaValue, schema::wit::DecodeError> {
schema::wit::decode_typed(value)
}
pub fn encode_typed_schema_value_owned(
value: TypedSchemaValue,
) -> Result<schema::wit::wire::TypedSchemaValue, schema::wit::EncodeError> {
schema::wit::encode_typed_owned(value)
}
pub fn decode_typed_schema_value_owned(
value: schema::wit::wire::TypedSchemaValue,
) -> Result<TypedSchemaValue, schema::wit::DecodeError> {
schema::wit::decode_typed_owned(value)
}
pub type ScheduledTime = wasip3::clocks::system_clock::Instant;
mod wasi_clocks_compat {
pub mod system_clock {
pub use wasip3::clocks::system_clock::Instant;
}
pub mod types {
pub use wasip3::clocks::types::Duration;
}
}
mod raw_bindings {
use wit_bindgen::generate;
generate!({
path: "wit",
world: "golem-rust",
generate_all,
generate_unused_types: true,
pub_export_macro: true,
with: {
"golem:core/types@2.0.0": golem_schema::schema::wit::wire,
"golem:tool/common@0.1.0": golem_schema::schema::tool::wit::wire,
"wasi:clocks/system-clock@0.3.0": crate::wasi_clocks_compat::system_clock,
"wasi:clocks/types@0.3.0": crate::wasi_clocks_compat::types,
}
});
}
pub use crate::raw_bindings::wit_stream;
pub mod bindings {
pub use crate::raw_bindings::wasi;
pub mod golem {
pub mod api {
pub(crate) use crate::raw_bindings::golem::api::host;
pub use crate::raw_bindings::golem::api::{context, oplog, retry};
}
pub mod durability {
pub(crate) use crate::raw_bindings::golem::durability::durability;
}
pub mod quota {
pub(crate) use crate::raw_bindings::golem::quota::types;
}
pub mod secrets {
pub use crate::raw_bindings::golem::secrets::{reveal, types};
}
pub mod agent {
pub use crate::raw_bindings::golem::agent::{common, durable_streams, host};
}
pub mod permissions {
pub use crate::raw_bindings::golem::permissions::{
derive, inspect, kernel_introspection, revoke, types, wallet,
};
}
pub mod tool {
pub use crate::raw_bindings::golem::tool::{host, streams};
pub use crate::schema::tool::wit::wire as common;
}
pub use crate::raw_bindings::golem::{rdbms, websocket};
}
}
#[cfg(feature = "export_load_snapshot")]
pub mod load_snapshot {
use wit_bindgen::generate;
generate!({
path: "wit",
world: "golem-rust-load-snapshot",
async: ["export:golem:api/load-snapshot@1.5.0#load"],
generate_all,
generate_unused_types: true,
pub_export_macro: true,
with: {
"golem:core/types@2.0.0": golem_schema::schema::wit::wire,
"golem:tool/common@0.1.0": golem_schema::schema::tool::wit::wire,
"wasi:clocks/system-clock@0.3.0": crate::wasi_clocks_compat::system_clock,
"wasi:clocks/types@0.3.0": crate::wasi_clocks_compat::types,
"golem:api/host@1.5.0": crate::bindings::golem::api::host,
"golem:tool/host@0.1.0": crate::bindings::golem::tool::host,
"golem:api/retry@1.5.0": crate::bindings::golem::api::retry,
"golem:api/oplog@1.5.0": crate::bindings::golem::api::oplog,
"golem:api/context@1.5.0": crate::bindings::golem::api::context,
"golem:durability/durability@1.6.0": crate::bindings::golem::durability::durability,
"golem:quota/types@1.5.0": crate::bindings::golem::quota::types,
"golem:secrets/types@0.1.0": crate::bindings::golem::secrets::types,
"golem:secrets/reveal@0.1.0": crate::bindings::golem::secrets::reveal,
"golem:rdbms/mysql@1.5.0": crate::bindings::golem::rdbms::mysql,
"golem:rdbms/postgres@1.5.0": crate::bindings::golem::rdbms::postgres,
"golem:rdbms/types@1.5.0": crate::bindings::golem::rdbms::types,
"wasi:blobstore/blobstore": crate::bindings::wasi::blobstore::blobstore,
"wasi:blobstore/container": crate::bindings::wasi::blobstore::container,
"wasi:blobstore/types": crate::bindings::wasi::blobstore::types,
"wasi:keyvalue/eventual-batch@0.1.0": crate::bindings::wasi::keyvalue::eventual_batch,
"wasi:keyvalue/eventual@0.1.0": crate::bindings::wasi::keyvalue::eventual,
"wasi:keyvalue/types@0.1.0": crate::bindings::wasi::keyvalue::types,
"wasi:keyvalue/wasi-keyvalue-error@0.1.0": crate::bindings::wasi::keyvalue::wasi_keyvalue_error,
"wasi:logging/logging": crate::bindings::wasi::logging::logging,
}
});
pub use __export_golem_rust_load_snapshot_impl as export_load_snapshot;
}
#[cfg(feature = "export_save_snapshot")]
pub mod save_snapshot {
use wit_bindgen::generate;
generate!({
path: "wit",
world: "golem-rust-save-snapshot",
async: ["export:golem:api/save-snapshot@1.5.0#save"],
generate_all,
generate_unused_types: true,
pub_export_macro: true,
with: {
"golem:core/types@2.0.0": golem_schema::schema::wit::wire,
"golem:tool/common@0.1.0": golem_schema::schema::tool::wit::wire,
"wasi:clocks/system-clock@0.3.0": crate::wasi_clocks_compat::system_clock,
"wasi:clocks/types@0.3.0": crate::wasi_clocks_compat::types,
"golem:api/host@1.5.0": crate::bindings::golem::api::host,
"golem:tool/host@0.1.0": crate::bindings::golem::tool::host,
"golem:api/retry@1.5.0": crate::bindings::golem::api::retry,
"golem:api/oplog@1.5.0": crate::bindings::golem::api::oplog,
"golem:api/context@1.5.0": crate::bindings::golem::api::context,
"golem:durability/durability@1.6.0": crate::bindings::golem::durability::durability,
"golem:quota/types@1.5.0": crate::bindings::golem::quota::types,
"golem:secrets/types@0.1.0": crate::bindings::golem::secrets::types,
"golem:secrets/reveal@0.1.0": crate::bindings::golem::secrets::reveal,
"golem:rdbms/mysql@1.5.0": crate::bindings::golem::rdbms::mysql,
"golem:rdbms/postgres@1.5.0": crate::bindings::golem::rdbms::postgres,
"golem:rdbms/types@1.5.0": crate::bindings::golem::rdbms::types,
"wasi:blobstore/blobstore": crate::bindings::wasi::blobstore::blobstore,
"wasi:blobstore/container": crate::bindings::wasi::blobstore::container,
"wasi:blobstore/types": crate::bindings::wasi::blobstore::types,
"wasi:keyvalue/eventual-batch@0.1.0": crate::bindings::wasi::keyvalue::eventual_batch,
"wasi:keyvalue/eventual@0.1.0": crate::bindings::wasi::keyvalue::eventual,
"wasi:keyvalue/types@0.1.0": crate::bindings::wasi::keyvalue::types,
"wasi:keyvalue/wasi-keyvalue-error@0.1.0": crate::bindings::wasi::keyvalue::wasi_keyvalue_error,
"wasi:logging/logging": crate::bindings::wasi::logging::logging,
}
});
pub use __export_golem_rust_save_snapshot_impl as export_save_snapshot;
}
#[cfg(feature = "export_golem_agentic")]
pub mod golem_agentic {
use wit_bindgen::generate;
generate!({
path: "wit",
world: "golem-agentic",
async: [
"export:golem:agent/guest@2.0.0#initialize",
"export:golem:agent/guest@2.0.0#invoke",
"export:golem:tool/guest@0.1.0#invoke",
"export:golem:tool/tool-middleware-guest@0.1.0#invoke-tool-middleware",
],
generate_all,
generate_unused_types: true,
pub_export_macro: true,
with: {
"golem:core/types@2.0.0": golem_schema::schema::wit::wire,
"golem:tool/common@0.1.0": golem_schema::schema::tool::wit::wire,
"wasi:clocks/system-clock@0.3.0": crate::wasi_clocks_compat::system_clock,
"wasi:clocks/types@0.3.0": crate::wasi_clocks_compat::types,
"golem:api/host@1.5.0": crate::bindings::golem::api::host,
"golem:api/retry@1.5.0": crate::bindings::golem::api::retry,
"golem:api/oplog@1.5.0": crate::bindings::golem::api::oplog,
"golem:api/context@1.5.0": crate::bindings::golem::api::context,
"golem:durability/durability@1.6.0": crate::bindings::golem::durability::durability,
"golem:quota/types@1.5.0": crate::bindings::golem::quota::types,
"golem:secrets/types@0.1.0": crate::bindings::golem::secrets::types,
"golem:secrets/reveal@0.1.0": crate::bindings::golem::secrets::reveal,
"golem:rdbms/mysql@1.5.0": crate::bindings::golem::rdbms::mysql,
"golem:rdbms/postgres@1.5.0": crate::bindings::golem::rdbms::postgres,
"golem:rdbms/types@1.5.0": crate::bindings::golem::rdbms::types,
"wasi:blobstore/blobstore": crate::bindings::wasi::blobstore::blobstore,
"wasi:blobstore/container": crate::bindings::wasi::blobstore::container,
"wasi:blobstore/types": crate::bindings::wasi::blobstore::types,
"wasi:keyvalue/eventual-batch@0.1.0": crate::bindings::wasi::keyvalue::eventual_batch,
"wasi:keyvalue/eventual@0.1.0": crate::bindings::wasi::keyvalue::eventual,
"wasi:keyvalue/types@0.1.0": crate::bindings::wasi::keyvalue::types,
"wasi:keyvalue/wasi-keyvalue-error@0.1.0": crate::bindings::wasi::keyvalue::wasi_keyvalue_error,
"wasi:logging/logging": crate::bindings::wasi::logging::logging,
"wasi:config/store@0.2.0-draft": crate::bindings::wasi::config::store,
}
});
pub use __export_golem_agentic_impl as export_golem_agentic;
}
#[cfg(feature = "export_golem_agentic")]
pub(crate) use golem_agentic::golem::tool::underlying as tool_underlying_bindings;
#[cfg(feature = "export_golem_agentic")]
pub use ctor;
#[cfg(feature = "export_golem_agentic")]
pub use async_trait;
#[cfg(feature = "export_golem_agentic")]
pub use serde;
#[cfg(feature = "export_golem_agentic")]
pub use serde_json;
#[cfg(feature = "export_oplog_processor")]
pub mod oplog_processor {
use wit_bindgen::generate;
pub mod host {
pub use crate::raw_bindings::golem::api::host::AgentMetadata;
}
generate!({
path: "wit",
world: "golem-rust-oplog-processor",
generate_all,
generate_unused_types: true,
pub_export_macro: true,
with: {
"golem:core/types@2.0.0": golem_schema::schema::wit::wire,
"golem:tool/common@0.1.0": golem_schema::schema::tool::wit::wire,
"wasi:clocks/system-clock@0.3.0": crate::wasi_clocks_compat::system_clock,
"wasi:clocks/types@0.3.0": crate::wasi_clocks_compat::types,
"golem:api/host@1.5.0": crate::bindings::golem::api::host,
"golem:tool/host@0.1.0": crate::bindings::golem::tool::host,
"golem:api/retry@1.5.0": crate::bindings::golem::api::retry,
"golem:api/oplog@1.5.0": crate::bindings::golem::api::oplog,
"golem:api/context@1.5.0": crate::bindings::golem::api::context,
"golem:durability/durability@1.6.0": crate::bindings::golem::durability::durability,
"golem:quota/types@1.5.0": crate::bindings::golem::quota::types,
"golem:secrets/types@0.1.0": crate::bindings::golem::secrets::types,
"golem:secrets/reveal@0.1.0": crate::bindings::golem::secrets::reveal,
"golem:rdbms/mysql@1.5.0": crate::bindings::golem::rdbms::mysql,
"golem:rdbms/postgres@1.5.0": crate::bindings::golem::rdbms::postgres,
"golem:rdbms/types@1.5.0": crate::bindings::golem::rdbms::types,
"wasi:blobstore/blobstore": crate::bindings::wasi::blobstore::blobstore,
"wasi:blobstore/container": crate::bindings::wasi::blobstore::container,
"wasi:blobstore/types": crate::bindings::wasi::blobstore::types,
"wasi:keyvalue/eventual-batch@0.1.0": crate::bindings::wasi::keyvalue::eventual_batch,
"wasi:keyvalue/eventual@0.1.0": crate::bindings::wasi::keyvalue::eventual,
"wasi:keyvalue/types@0.1.0": crate::bindings::wasi::keyvalue::types,
"wasi:keyvalue/wasi-keyvalue-error@0.1.0": crate::bindings::wasi::keyvalue::wasi_keyvalue_error,
"wasi:logging/logging": crate::bindings::wasi::logging::logging,
}
});
pub use __export_golem_rust_oplog_processor_impl as export_oplog_processor;
}
#[cfg(feature = "export_golem_agentic")]
pub mod agentic;
#[cfg(feature = "export_golem_agentic")]
pub use agentic::reflection::*;
#[cfg(feature = "durability")]
pub mod durability;
#[cfg(feature = "json")]
mod json;
#[cfg(feature = "json")]
pub use json::*;
#[cfg(feature = "json")]
pub mod durable_streams;
mod checkpoint;
pub mod quota;
pub mod secrets;
pub mod tool;
mod transaction;
use std::future::Future;
use bindings::golem::api::host::{
self as host_api, get_idempotence_mode, mark_begin_operation, mark_end_operation,
set_idempotence_mode,
};
pub type OplogIndex = u64;
pub mod websocket;
pub use checkpoint::*;
pub use quota::*;
pub use secrets::*;
pub mod retry;
pub use transaction::*;
pub use websocket::{WebSocketCloseInfo, WebSocketError, WebSocketMessage, WebsocketConnection};
#[cfg(feature = "macro")]
pub use golem_rust_macro::*;
fn schema_uuid_to_wire(value: Uuid) -> schema::wit::wire::Uuid {
let (high_bits, low_bits) = value.as_u64_pair();
schema::wit::wire::Uuid {
high_bits,
low_bits,
}
}
fn wire_uuid_to_schema(value: schema::wit::wire::Uuid) -> Uuid {
Uuid::from_u64_pair(value.high_bits, value.low_bits)
}
fn schema_component_id_to_wire(value: ComponentId) -> schema::wit::wire::ComponentId {
schema::wit::wire::ComponentId {
uuid: schema_uuid_to_wire(value.uuid),
}
}
fn wire_component_id_to_schema(value: schema::wit::wire::ComponentId) -> ComponentId {
ComponentId {
uuid: wire_uuid_to_schema(value.uuid),
}
}
fn schema_agent_id_to_wire(value: AgentId) -> schema::wit::wire::AgentId {
schema::wit::wire::AgentId {
component_id: schema_component_id_to_wire(value.component_id),
agent_id: value.agent_id,
}
}
fn wire_agent_id_to_schema(value: schema::wit::wire::AgentId) -> AgentId {
AgentId {
component_id: wire_component_id_to_schema(value.component_id),
agent_id: value.agent_id,
}
}
fn schema_promise_id_to_wire(value: &PromiseId) -> schema::wit::wire::PromiseId {
schema::wit::wire::PromiseId {
agent_id: schema_agent_id_to_wire(value.agent_id.clone()),
oplog_idx: value.oplog_idx,
}
}
fn wire_promise_id_to_schema(value: schema::wit::wire::PromiseId) -> PromiseId {
PromiseId {
agent_id: wire_agent_id_to_schema(value.agent_id),
oplog_idx: value.oplog_idx,
}
}
fn schema_environment_id_to_host(value: EnvironmentId) -> host_api::EnvironmentId {
host_api::EnvironmentId {
uuid: schema_uuid_to_wire(value.uuid),
}
}
fn host_environment_id_to_schema(value: host_api::EnvironmentId) -> EnvironmentId {
EnvironmentId {
uuid: wire_uuid_to_schema(value.uuid),
}
}
#[derive(
Clone, Copy, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema,
)]
pub enum UpdateMode {
Automatic,
SnapshotBased,
}
impl From<host_api::UpdateMode> for UpdateMode {
fn from(value: host_api::UpdateMode) -> Self {
match value {
host_api::UpdateMode::Automatic => Self::Automatic,
host_api::UpdateMode::SnapshotBased => Self::SnapshotBased,
}
}
}
impl From<UpdateMode> for host_api::UpdateMode {
fn from(value: UpdateMode) -> Self {
match value {
UpdateMode::Automatic => Self::Automatic,
UpdateMode::SnapshotBased => Self::SnapshotBased,
}
}
}
#[derive(
Clone, Copy, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema,
)]
pub enum FilterComparator {
Equal,
NotEqual,
GreaterEqual,
Greater,
LessEqual,
Less,
}
impl From<host_api::FilterComparator> for FilterComparator {
fn from(value: host_api::FilterComparator) -> Self {
match value {
host_api::FilterComparator::Equal => Self::Equal,
host_api::FilterComparator::NotEqual => Self::NotEqual,
host_api::FilterComparator::GreaterEqual => Self::GreaterEqual,
host_api::FilterComparator::Greater => Self::Greater,
host_api::FilterComparator::LessEqual => Self::LessEqual,
host_api::FilterComparator::Less => Self::Less,
}
}
}
impl From<FilterComparator> for host_api::FilterComparator {
fn from(value: FilterComparator) -> Self {
match value {
FilterComparator::Equal => Self::Equal,
FilterComparator::NotEqual => Self::NotEqual,
FilterComparator::GreaterEqual => Self::GreaterEqual,
FilterComparator::Greater => Self::Greater,
FilterComparator::LessEqual => Self::LessEqual,
FilterComparator::Less => Self::Less,
}
}
}
#[derive(
Clone, Copy, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema,
)]
pub enum StringFilterComparator {
Equal,
NotEqual,
Like,
NotLike,
StartsWith,
}
impl From<host_api::StringFilterComparator> for StringFilterComparator {
fn from(value: host_api::StringFilterComparator) -> Self {
match value {
host_api::StringFilterComparator::Equal => Self::Equal,
host_api::StringFilterComparator::NotEqual => Self::NotEqual,
host_api::StringFilterComparator::Like => Self::Like,
host_api::StringFilterComparator::NotLike => Self::NotLike,
host_api::StringFilterComparator::StartsWith => Self::StartsWith,
}
}
}
impl From<StringFilterComparator> for host_api::StringFilterComparator {
fn from(value: StringFilterComparator) -> Self {
match value {
StringFilterComparator::Equal => Self::Equal,
StringFilterComparator::NotEqual => Self::NotEqual,
StringFilterComparator::Like => Self::Like,
StringFilterComparator::NotLike => Self::NotLike,
StringFilterComparator::StartsWith => Self::StartsWith,
}
}
}
#[derive(
Clone, Copy, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema,
)]
pub enum AgentStatus {
Running,
Idle,
Suspended,
Interrupted,
Retrying,
Failed,
Exited,
}
impl From<host_api::AgentStatus> for AgentStatus {
fn from(value: host_api::AgentStatus) -> Self {
match value {
host_api::AgentStatus::Running => Self::Running,
host_api::AgentStatus::Idle => Self::Idle,
host_api::AgentStatus::Suspended => Self::Suspended,
host_api::AgentStatus::Interrupted => Self::Interrupted,
host_api::AgentStatus::Retrying => Self::Retrying,
host_api::AgentStatus::Failed => Self::Failed,
host_api::AgentStatus::Exited => Self::Exited,
}
}
}
impl From<AgentStatus> for host_api::AgentStatus {
fn from(value: AgentStatus) -> Self {
match value {
AgentStatus::Running => Self::Running,
AgentStatus::Idle => Self::Idle,
AgentStatus::Suspended => Self::Suspended,
AgentStatus::Interrupted => Self::Interrupted,
AgentStatus::Retrying => Self::Retrying,
AgentStatus::Failed => Self::Failed,
AgentStatus::Exited => Self::Exited,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentNameFilter {
pub comparator: StringFilterComparator,
pub value: String,
}
impl From<host_api::AgentNameFilter> for AgentNameFilter {
fn from(value: host_api::AgentNameFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
impl From<AgentNameFilter> for host_api::AgentNameFilter {
fn from(value: AgentNameFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentStatusFilter {
pub comparator: FilterComparator,
pub value: AgentStatus,
}
impl From<host_api::AgentStatusFilter> for AgentStatusFilter {
fn from(value: host_api::AgentStatusFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: Into::into(value.value),
}
}
}
impl From<AgentStatusFilter> for host_api::AgentStatusFilter {
fn from(value: AgentStatusFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: Into::into(value.value),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentVersionFilter {
pub comparator: FilterComparator,
pub value: u64,
}
impl From<host_api::AgentVersionFilter> for AgentVersionFilter {
fn from(value: host_api::AgentVersionFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
impl From<AgentVersionFilter> for host_api::AgentVersionFilter {
fn from(value: AgentVersionFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentCreatedAtFilter {
pub comparator: FilterComparator,
pub value: u64,
}
impl From<host_api::AgentCreatedAtFilter> for AgentCreatedAtFilter {
fn from(value: host_api::AgentCreatedAtFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
impl From<AgentCreatedAtFilter> for host_api::AgentCreatedAtFilter {
fn from(value: AgentCreatedAtFilter) -> Self {
Self {
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentEnvFilter {
pub name: String,
pub comparator: StringFilterComparator,
pub value: String,
}
impl From<host_api::AgentEnvFilter> for AgentEnvFilter {
fn from(value: host_api::AgentEnvFilter) -> Self {
Self {
name: value.name,
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
impl From<AgentEnvFilter> for host_api::AgentEnvFilter {
fn from(value: AgentEnvFilter) -> Self {
Self {
name: value.name,
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentConfigVarsFilter {
pub name: String,
pub comparator: StringFilterComparator,
pub value: String,
}
impl From<host_api::AgentConfigVarsFilter> for AgentConfigVarsFilter {
fn from(value: host_api::AgentConfigVarsFilter) -> Self {
Self {
name: value.name,
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
impl From<AgentConfigVarsFilter> for host_api::AgentConfigVarsFilter {
fn from(value: AgentConfigVarsFilter) -> Self {
Self {
name: value.name,
comparator: Into::into(value.comparator),
value: value.value,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub enum AgentPropertyFilter {
Name(AgentNameFilter),
Status(AgentStatusFilter),
Version(AgentVersionFilter),
CreatedAt(AgentCreatedAtFilter),
Env(AgentEnvFilter),
Config(AgentConfigVarsFilter),
}
impl From<host_api::AgentPropertyFilter> for AgentPropertyFilter {
fn from(value: host_api::AgentPropertyFilter) -> Self {
match value {
host_api::AgentPropertyFilter::Name(value) => Self::Name(Into::into(value)),
host_api::AgentPropertyFilter::Status(value) => Self::Status(Into::into(value)),
host_api::AgentPropertyFilter::Version(value) => Self::Version(Into::into(value)),
host_api::AgentPropertyFilter::CreatedAt(value) => Self::CreatedAt(Into::into(value)),
host_api::AgentPropertyFilter::Env(value) => Self::Env(Into::into(value)),
host_api::AgentPropertyFilter::Config(value) => Self::Config(Into::into(value)),
}
}
}
impl From<AgentPropertyFilter> for host_api::AgentPropertyFilter {
fn from(value: AgentPropertyFilter) -> Self {
match value {
AgentPropertyFilter::Name(value) => Self::Name(Into::into(value)),
AgentPropertyFilter::Status(value) => Self::Status(Into::into(value)),
AgentPropertyFilter::Version(value) => Self::Version(Into::into(value)),
AgentPropertyFilter::CreatedAt(value) => Self::CreatedAt(Into::into(value)),
AgentPropertyFilter::Env(value) => Self::Env(Into::into(value)),
AgentPropertyFilter::Config(value) => Self::Config(Into::into(value)),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentAllFilter {
pub filters: Vec<AgentPropertyFilter>,
}
impl From<host_api::AgentAllFilter> for AgentAllFilter {
fn from(value: host_api::AgentAllFilter) -> Self {
Self {
filters: value.filters.into_iter().map(Into::into).collect(),
}
}
}
impl From<AgentAllFilter> for host_api::AgentAllFilter {
fn from(value: AgentAllFilter) -> Self {
Self {
filters: value.filters.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentAnyFilter {
pub filters: Vec<AgentAllFilter>,
}
impl From<host_api::AgentAnyFilter> for AgentAnyFilter {
fn from(value: host_api::AgentAnyFilter) -> Self {
Self {
filters: value.filters.into_iter().map(Into::into).collect(),
}
}
}
impl From<AgentAnyFilter> for host_api::AgentAnyFilter {
fn from(value: AgentAnyFilter) -> Self {
Self {
filters: value.filters.into_iter().map(Into::into).collect(),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct AgentMetadata {
pub agent_id: AgentId,
pub args: Vec<String>,
pub env: Vec<(String, String)>,
pub config: Vec<(String, String)>,
pub status: AgentStatus,
pub component_revision: u64,
pub retry_count: u64,
pub environment_id: EnvironmentId,
}
impl From<host_api::AgentMetadata> for AgentMetadata {
fn from(value: host_api::AgentMetadata) -> Self {
Self {
agent_id: wire_agent_id_to_schema(value.agent_id),
args: value.args,
env: value.env,
config: value.config,
status: Into::into(value.status),
component_revision: value.component_revision,
retry_count: value.retry_count,
environment_id: host_environment_id_to_schema(value.environment_id),
}
}
}
impl From<AgentMetadata> for host_api::AgentMetadata {
fn from(value: AgentMetadata) -> Self {
Self {
agent_id: schema_agent_id_to_wire(value.agent_id),
args: value.args,
env: value.env,
config: value.config,
status: Into::into(value.status),
component_revision: value.component_revision,
retry_count: value.retry_count,
environment_id: schema_environment_id_to_host(value.environment_id),
}
}
}
pub struct GetAgents {
raw: host_api::GetAgents,
}
pub use host_api::AgentOperationError;
impl GetAgents {
pub fn new(component_id: ComponentId, filter: Option<&AgentAnyFilter>, precise: bool) -> Self {
let raw_filter = filter.cloned().map(host_api::AgentAnyFilter::from);
Self {
raw: host_api::GetAgents::new(
schema_component_id_to_wire(component_id),
raw_filter.as_ref(),
precise,
),
}
}
pub fn get_next(&self) -> Result<Option<Vec<AgentMetadata>>, AgentOperationError> {
self.raw
.get_next()
.map(|values| values.map(|values| values.into_iter().map(Into::into).collect()))
}
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub struct ForkDetails {
pub forked_phantom_id: Uuid,
}
#[derive(Clone, Debug, Eq, PartialEq, IntoSchema, FromSchema, IntoWire, FromWire, WireSchema)]
pub enum ForkResult {
Original(ForkDetails),
Forked(ForkDetails),
}
impl From<host_api::ForkResult> for ForkResult {
fn from(value: host_api::ForkResult) -> Self {
match value {
host_api::ForkResult::Original(details) => Self::Original(ForkDetails {
forked_phantom_id: wire_uuid_to_schema(details.forked_phantom_id),
}),
host_api::ForkResult::Forked(details) => Self::Forked(ForkDetails {
forked_phantom_id: wire_uuid_to_schema(details.forked_phantom_id),
}),
}
}
}
pub struct PromiseResult {
raw: host_api::GetPromiseResult,
}
impl PromiseResult {
pub async fn get(&self) -> Vec<u8> {
self.raw.get().await
}
}
pub fn create_promise() -> PromiseId {
wire_promise_id_to_schema(host_api::create_promise())
}
pub fn get_promise(promise_id: &PromiseId) -> PromiseResult {
PromiseResult {
raw: host_api::get_promise(&schema_promise_id_to_wire(promise_id)),
}
}
pub fn complete_promise(promise_id: &PromiseId, data: &[u8]) -> bool {
host_api::complete_promise(&schema_promise_id_to_wire(promise_id), data)
}
pub fn get_oplog_index() -> OplogIndex {
host_api::get_oplog_index()
}
pub fn set_oplog_index(oplog_idx: OplogIndex) {
host_api::set_oplog_index(oplog_idx)
}
pub fn oplog_commit(replicas: u8) {
host_api::oplog_commit(replicas)
}
pub fn get_self_metadata() -> Result<AgentMetadata, AgentOperationError> {
host_api::get_self_metadata().map(Into::into)
}
pub fn get_agent_metadata(agent_id: &AgentId) -> Option<AgentMetadata> {
host_api::get_agent_metadata(&schema_agent_id_to_wire(agent_id.clone())).map(Into::into)
}
pub fn update_agent(
agent_id: &AgentId,
target_revision: u64,
mode: UpdateMode,
) -> Result<(), AgentOperationError> {
host_api::update_agent(
&schema_agent_id_to_wire(agent_id.clone()),
target_revision,
Into::into(mode),
)
}
pub fn resolve_component_id(component_reference: &str) -> Option<ComponentId> {
host_api::resolve_component_id(component_reference).map(wire_component_id_to_schema)
}
pub fn resolve_agent_id(component_reference: &str, agent_name: &str) -> Option<AgentId> {
host_api::resolve_agent_id(component_reference, agent_name).map(wire_agent_id_to_schema)
}
pub fn resolve_agent_id_strict(component_reference: &str, agent_name: &str) -> Option<AgentId> {
host_api::resolve_agent_id_strict(component_reference, agent_name).map(wire_agent_id_to_schema)
}
pub fn fork() -> Result<ForkResult, AgentOperationError> {
host_api::fork().map(Into::into)
}
pub fn blocking_await_promise(promise_id: &PromiseId) -> Vec<u8> {
let promise = get_promise(promise_id);
wit_bindgen::block_on(async move { promise.get().await })
}
pub async fn await_promise(promise_id: &PromiseId) -> Vec<u8> {
let promise = get_promise(promise_id);
promise.get().await
}
pub struct IdempotenceModeGuard {
original: bool,
}
impl Drop for IdempotenceModeGuard {
fn drop(&mut self) {
set_idempotence_mode(self.original);
}
}
#[must_use]
pub fn use_idempotence_mode(mode: bool) -> IdempotenceModeGuard {
let original = get_idempotence_mode();
set_idempotence_mode(mode);
IdempotenceModeGuard { original }
}
pub fn with_idempotence_mode<R>(mode: bool, f: impl FnOnce() -> R) -> R {
let _guard = use_idempotence_mode(mode);
f()
}
pub async fn with_idempotence_mode_async<R, F: Future<Output = R>>(
mode: bool,
f: impl FnOnce() -> F,
) -> R {
let _guard = use_idempotence_mode(mode);
f().await
}
pub fn generate_idempotency_key() -> uuid::Uuid {
Into::into(host_api::generate_idempotency_key())
}
pub struct AtomicOperationGuard {
begin: OplogIndex,
}
impl Drop for AtomicOperationGuard {
fn drop(&mut self) {
if !std::thread::panicking() {
mark_end_operation(self.begin);
}
}
}
#[must_use]
pub fn mark_atomic_operation() -> AtomicOperationGuard {
let begin = mark_begin_operation();
AtomicOperationGuard { begin }
}
pub fn atomically<T>(f: impl FnOnce() -> T) -> T {
let _guard = mark_atomic_operation();
f()
}
pub async fn atomically_async<T, F: Future<Output = T>>(f: impl FnOnce() -> F) -> T {
let _guard = mark_atomic_operation();
f().await
}
pub fn atomically_result<T, E>(f: impl FnOnce() -> Result<T, E>) -> Result<T, E>
where
E: core::fmt::Display,
{
let guard = mark_atomic_operation();
match f() {
Ok(v) => Ok(v),
Err(e) => {
core::mem::forget(guard);
host_api::trap(&format!("atomic block failed: {e}"));
unreachable!("trap host call must not return")
}
}
}
pub async fn atomically_result_async<T, E, F>(f: impl FnOnce() -> F) -> Result<T, E>
where
E: core::fmt::Display,
F: Future<Output = Result<T, E>>,
{
let guard = mark_atomic_operation();
match f().await {
Ok(v) => Ok(v),
Err(e) => {
core::mem::forget(guard);
host_api::trap(&format!("atomic block failed: {e}"));
unreachable!("trap host call must not return")
}
}
}