feat(sdk): Context::emit for WIT 1.1 host.emit-event (T1)
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:
flemming-it 2026-07-05 19:22:53 +02:00
parent 98e98e9371
commit f32dc820b9
9 changed files with 568 additions and 5 deletions

View file

@ -95,6 +95,13 @@ pub fn fai_module(_attrs: TokenStream, input: TokenStream) -> TokenStream {
let sdk_inputs =
::chain_module_sdk::Inputs::__from_pairs(sdk_pairs);
// Wire Context::emit to the real WIT host import
// for the duration of this invocation (WIT 1.1).
::chain_module_sdk::__set_emit_hook(|name, payload| {
let wit = sdk_payload_to_wit(payload);
chain::platform::host::emit_event(name, &wit);
});
match super::#user_fn_name(sdk_ctx, sdk_inputs) {
Ok(outputs) => {
let pairs = outputs.__into_pairs();