feat(sdk): Context::emit for WIT 1.1 host.emit-event (T1)
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 1s
Some checks failed
CI / Linux x86_64 (Forgejo) (push) Failing after 1s
Brings the module SDK to WIT 1.1 in lockstep with the platform and
exposes the new host.emit-event as an ergonomic ctx.emit(name,
payload). Modules emit ephemeral progress/stream events (progress,
token streaming) delivered live to a following client and never
persisted.
- wit/world.wit → 1.1.0 (host.emit-event + use types.{payload}).
- host.rs: an emit hook (thread-local fn pointer; guest is
single-threaded). The #[fai_module] expansion installs a closure
reaching the real WIT emit-event import at the start of each
invocation; Context::emit calls through it. Outside a hub (unit
tests) it is a silent no-op.
- examples/progress: reference module emitting progress + token events;
builds clean for wasm32-wasip2, proving the ergonomics end-to-end.
The SDK keeps shielding module authors: emit is the whole surface, no
wit_bindgen in sight.
Signed-off-by: flemming-it <sf@flemming.it>
This commit is contained in:
parent
98e98e9371
commit
f32dc820b9
9 changed files with 568 additions and 5 deletions
|
|
@ -11,3 +11,23 @@ pub struct Context {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue