chain-module-sdk-rust/crates/chain-module-sdk/src/context.rs
flemming-it a4415ada7e
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 1s
feat(sdk)!: drop the #[fai_module] alias — #[chain_module] only
No module outside this workspace was ever published against the
alias (the system has no external users yet), so the pre-rename
name goes away instead of being maintained: one attribute, no
legacy surface. All internal doc references swept; echo example
description moves to the product name. 0.3.0.

Signed-off-by: flemming-it <sf@flemming.it>
2026-07-11 19:47:34 +02:00

33 lines
1.2 KiB
Rust

//! Invocation context passed to a module on every call.
//!
//! Mirrors the WIT `invocation-context` record. The
//! `#[chain_module]` macro builds this from the WIT-generated value
//! before handing it to user code.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Context {
pub invocation_id: String,
pub capability_namespace: String,
pub capability_name: String,
pub deadline_ms: u64,
}
impl Context {
/// Emit an ephemeral progress/stream event during this invocation
/// (WIT 1.1 `emit-event`). Delivered live to any client following
/// the flow (`SubmitStream`); it is **never** written to the audit
/// log. Use it for progress updates or token streaming.
///
/// `name` is a caller-defined label (e.g. `"progress"`, `"token"`);
/// `payload` is the event body. The host enforces per-invocation
/// size + rate limits — an over-limit event is dropped, never an
/// error. When the module runs outside a hub that supports it (or
/// in a unit test) `emit` is a silent no-op.
///
/// ```ignore
/// ctx.emit("progress", Payload::Text("50%".into()));
/// ```
pub fn emit(&self, name: &str, payload: crate::Payload) {
crate::emit(name, payload);
}
}