Files
wasmeld/wit/resident/package.wit
T

184 lines
5.9 KiB
Plaintext
Raw Normal View History

2026-07-30 07:40:02 +08:00
package wasmeld:resident@0.1.0;
/// Event/effect ABI for Components that remain active without monopolizing
/// their Actor thread. The Host owns timers, subscriptions, sockets, streams,
/// and all operating-system handles. A Component handles one bounded event and
/// returns effects before control goes back to the Runtime.
interface actor {
/// Opaque, nonzero identity allocated by the Host for one resident session.
///
/// IDs are scoped to one service revision and session. They are never OS
/// handles, must not be guessed, and become invalid after Host release.
2026-07-30 07:40:02 +08:00
type resource-id = u64;
/// One occurrence of a previously registered and armed timer.
2026-07-30 07:40:02 +08:00
record timer-fired {
timer-id: resource-id,
/// Driver monotonic deadline in nanoseconds, not wall-clock time.
2026-07-30 07:40:02 +08:00
scheduled-at-ns: u64,
}
/// A stream accepted by a previously registered TCP or Unix endpoint.
2026-07-30 07:40:02 +08:00
record stream-opened {
endpoint-id: resource-id,
stream-id: resource-id,
/// Driver-formatted peer address when the transport provides one.
2026-07-30 07:40:02 +08:00
peer: option<string>,
}
/// One bounded read chunk. Chunk boundaries are not message boundaries.
2026-07-30 07:40:02 +08:00
record stream-chunk {
stream-id: resource-id,
bytes: list<u8>,
}
/// Terminal reason reported by the Host driver.
2026-07-30 07:40:02 +08:00
enum close-reason {
/// The peer closed the transport normally.
2026-07-30 07:40:02 +08:00
peer-closed,
/// The platform or Component requested closure.
2026-07-30 07:40:02 +08:00
host-closed,
/// The configured inactivity deadline elapsed.
2026-07-30 07:40:02 +08:00
idle-timeout,
/// Protocol validation failed above the transport layer.
2026-07-30 07:40:02 +08:00
protocol-error,
/// The operating-system transport returned an error.
2026-07-30 07:40:02 +08:00
transport-error,
}
/// Final event for a stream identity.
2026-07-30 07:40:02 +08:00
record stream-closed {
stream-id: resource-id,
reason: close-reason,
}
/// One UDP datagram. A datagram is never split across events.
2026-07-30 07:40:02 +08:00
record datagram {
endpoint-id: resource-id,
peer: string,
bytes: list<u8>,
}
/// One delivery from a Host-owned broker or internal queue.
2026-07-30 07:40:02 +08:00
record message {
subscription-id: resource-id,
message-id: u64,
bytes: list<u8>,
}
/// Escape hatch for Host-owned event sources such as filesystem watchers,
/// serial devices, process signals, or platform-specific buses. `kind` and
/// `payload` are interpreted by the separately versioned Host capability
/// that created `source-id`.
record source-event {
source-id: resource-id,
kind: string,
payload: list<u8>,
}
variant event {
/// A registered timer reached its monotonic deadline.
2026-07-30 07:40:02 +08:00
timer(timer-fired),
/// A Host driver accepted a new stream.
2026-07-30 07:40:02 +08:00
stream-opened(stream-opened),
/// A stream produced one bounded read chunk.
2026-07-30 07:40:02 +08:00
stream-data(stream-chunk),
/// The driver can accept writes after previous backpressure.
2026-07-30 07:40:02 +08:00
stream-writable(resource-id),
/// The peer closed its write half; local writes may still be valid.
2026-07-30 07:40:02 +08:00
stream-half-closed(resource-id),
/// The stream is terminal and its identity will be released.
2026-07-30 07:40:02 +08:00
stream-closed(stream-closed),
/// A UDP endpoint received one datagram.
2026-07-30 07:40:02 +08:00
datagram(datagram),
/// A subscription delivered one message.
2026-07-30 07:40:02 +08:00
message(message),
/// A separately versioned extension source produced an event.
2026-07-30 07:40:02 +08:00
source(source-event),
/// The session is stopping. No later events will be delivered.
2026-07-30 07:40:02 +08:00
shutdown,
}
/// Request to enqueue bytes for a stream driver.
2026-07-30 07:40:02 +08:00
record stream-write {
stream-id: resource-id,
bytes: list<u8>,
}
/// Request to send one datagram through a registered UDP endpoint.
2026-07-30 07:40:02 +08:00
record datagram-send {
endpoint-id: resource-id,
peer: string,
bytes: list<u8>,
}
/// Request to arm or replace a registered timer schedule.
2026-07-30 07:40:02 +08:00
record timer-arm {
timer-id: resource-id,
/// Delay from operation application, in milliseconds.
2026-07-30 07:40:02 +08:00
delay-ms: u64,
/// Optional repeating interval in milliseconds.
2026-07-30 07:40:02 +08:00
interval-ms: option<u64>,
}
/// Request to acknowledge a previously delivered message.
2026-07-30 07:40:02 +08:00
record message-ack {
subscription-id: resource-id,
message-id: u64,
}
/// Driver-specific command for a separately versioned extension source.
2026-07-30 07:40:02 +08:00
record source-command {
source-id: resource-id,
command: string,
payload: list<u8>,
}
/// Host operations requested after handling one event.
///
/// Effects are declarations, not completed I/O. The Host validates the
/// entire returned list before applying any item, then the external driver
/// performs the operations in order.
2026-07-30 07:40:02 +08:00
variant effect {
/// Enqueue bytes for an open stream.
2026-07-30 07:40:02 +08:00
write-stream(stream-write),
/// Begin closing an open stream.
2026-07-30 07:40:02 +08:00
close-stream(resource-id),
/// Stop delivering new read data until resumed.
2026-07-30 07:40:02 +08:00
pause-stream(resource-id),
/// Resume delivery after a matching pause.
2026-07-30 07:40:02 +08:00
resume-stream(resource-id),
/// Send one UDP datagram.
2026-07-30 07:40:02 +08:00
send-datagram(datagram-send),
/// Arm or replace one timer.
2026-07-30 07:40:02 +08:00
arm-timer(timer-arm),
/// Disarm one timer; its identity remains registered.
2026-07-30 07:40:02 +08:00
cancel-timer(resource-id),
/// Acknowledge one broker or queue message.
2026-07-30 07:40:02 +08:00
acknowledge-message(message-ack),
/// Forward an extension-specific command.
2026-07-30 07:40:02 +08:00
source-command(source-command),
}
/// Expected Component failure while processing a resident event.
2026-07-30 07:40:02 +08:00
variant resident-error {
event-failed(string),
}
/// Handles exactly one serialized, bounded event.
///
/// This callback must not run an internal infinite loop or block on network
/// I/O. Update Component state, return requested effects, and let the Host
/// wait for the next external event. A trap faults the Actor; `event-failed`
/// reports an application error without changing the ABI.
2026-07-30 07:40:02 +08:00
handle-event: func(input: event) -> result<list<effect>, resident-error>;
}
/// Optional export world for Components that need long-lived Host-driven I/O.
///
/// A Component may compose this package with `wasmeld:service` and only the
/// capability packages it actually imports.
2026-07-30 07:40:02 +08:00
world resident-component {
export actor;
}