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

@ -13,10 +13,13 @@ use std::path::PathBuf;
use sha2::{Digest, Sha256};
/// Identical to FROZEN_WIT_SHA256 in
/// fai/platform :: crates/fai_runtime/tests/wit_freeze.rs.
/// fai/chain :: crates/chain_runtime/tests/wit_freeze.rs.
/// Update both repos in lockstep, never one alone.
/// 2026-07-05 — WIT 1.0.0 → 1.1.0 (additive: host.emit-event). The SDK
/// wit/world.wit is now byte-identical to the platform's, so the two
/// frozen hashes match exactly.
const PLATFORM_FROZEN_WIT_SHA256: &str =
"6f4e2266a4264832a16fe5a3704622cd978b290b90f3300c3ed236d98b689b5f";
"2ba9d6c61c4c77d081679603a9389aef663429ec80f9c386cf9b1ca9d353bf6f";
fn world_wit_path() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))