wired:core
Shared types and conventions used across all wired:* packages: math,
identifiers, errors, permissions, and time.
Units: lengths in meters, time in seconds, mass in kilograms, angles in
radians, forces in newtons. Coordinate space is right-handed (+Y up, -Z
forward). Rotations are unit quaternions. Colors are linear RGB with
straight (non-premultiplied) alpha, nominally 0..1 per channel. f64
timestamps are seconds on the local monotonic clock (not synchronized across
peers).
Errors: fallible calls return result<_, error>. Passing a dropped handle
or a handle from another script traps. All other failures return error.
Permissions: scripts run with the permissions granted locally to their
document's author. Unauthorized calls fail with permission. Resource
handles are checked on creation and remain valid until dropped.
Async results use pending-<noun> resources: poll returns none until
ready, then returns the same result on subsequent calls. Dropping cancels
the operation.
Streams use <noun>-subscription resources. drain(max) pops up to max
queued items, oldest first. Full queues drop the oldest item, and dropped
returns the cumulative drop count. Drain once per fixed-update.
Interface math
vec2
x: f32 | |
y: f32 |
vec3
x: f32 | |
y: f32 | |
z: f32 |
quat
Unit quaternion. Identity is { x: 0, y: 0, z: 0, w: 1 }.
x: f32 | |
y: f32 | |
z: f32 | |
w: f32 |
transform
Applied as scale, then rotation, then translation.
translation: vec3 | |
rotation: quat | |
scale: vec3 |
color
Linear RGB with straight alpha.
r: f32 | |
g: f32 | |
b: f32 | |
a: f32 |
ray
Half-line in world space. direction need not be normalized, but must be
non-zero.
origin: vec3 | |
direction: vec3 |
Interface ids
document-id
document-id = tuple<u64, u64, u64, u64>256-bit document ID as four little-endian u64 words (first word is bytes
0..8).
prim-id
prim-id = tuple<u64, u64>128-bit prim ID unique within its document, in the same word order as
document-id.
prim-ref
Reference to a specific prim within a document.
document: document-id | |
prim: prim-id |
did
did = stringDecentralized identifier (e.g. did:key:z6Mk...).
Interface error
permission
Host capability gated by the local peer's trust level for the document's author.
scene | Read the scene and write documents the script owns. |
create-document | Create new documents. |
commit | Commit edits durably to documents. |
event | Send and receive local script messages. |
input | Receive pointer input aimed at prims in writable documents. |
input-device | Read all local user input events and pointer states. |
local-agent | Read the local user's camera, avatar pose, and viewport. |
identity | Read the local user's DID. |
peer | Query document authors and physics holders. |
physics | Run raycasts and modify rigid-body state. |
portal | Open and pair portals. |
travel | Move the local user to another space. |
perception | Query nearby portals, agents, profiles, document metadata, and trust levels. |
rate
Refilling rate-limit bucket.
create-document | |
create-prim | |
emit | |
upload | Large property writes (meshes, colliders, images, shader graphs). |
portal |
limit
Hard resource ceiling; frees when existing resources are dropped.
documents | |
prims | |
handles | Live resource handles across all types. |
subscriptions | |
shared-memory | Bytes stored in the shared session layer. |
memory | Guest WebAssembly linear memory. |
error
invalid-argument(string) | Malformed or out-of-range argument, with a diagnostic message. |
not-found | Target does not exist or is not loaded locally. |
not-ready | Target exists but is not ready yet (e.g. an unspawned physics body). Retrying on a later tick may succeed. |
permission(permission) | Document author lacks the required permission on this peer. |
forbidden | Operation is disallowed on this target (e.g. writing an unowned document). |
rate-limited(rate) | Rate budget exhausted; retries may succeed once it refills. |
limit-reached(limit) | Resource ceiling reached; release existing resources before retrying. |
internal(string) | Internal host failure, with a diagnostic message. |
Interface time
utc-offset
utc-offset: func() -> s32Current local UTC offset in minutes (e.g. 60 for UTC+1, -300 for
UTC-5), including daylight saving time. May change between calls.
Source
/// Shared types and conventions used across all `wired:*` packages: math,
/// identifiers, errors, permissions, and time.
///
/// Units: lengths in meters, time in seconds, mass in kilograms, angles in
/// radians, forces in newtons. Coordinate space is right-handed (+Y up, -Z
/// forward). Rotations are unit quaternions. Colors are linear RGB with
/// straight (non-premultiplied) alpha, nominally 0..1 per channel. `f64`
/// timestamps are seconds on the local monotonic clock (not synchronized across
/// peers).
///
/// Errors: fallible calls return `result<_, error>`. Passing a dropped handle
/// or a handle from another script traps. All other failures return `error`.
///
/// Permissions: scripts run with the permissions granted locally to their
/// document's author. Unauthorized calls fail with `permission`. Resource
/// handles are checked on creation and remain valid until dropped.
///
/// Async results use `pending-<noun>` resources: `poll` returns `none` until
/// ready, then returns the same result on subsequent calls. Dropping cancels
/// the operation.
///
/// Streams use `<noun>-subscription` resources. `drain(max)` pops up to `max`
/// queued items, oldest first. Full queues drop the oldest item, and `dropped`
/// returns the cumulative drop count. Drain once per `fixed-update`.
package wired:core;
interface math {
record vec2 {
x: f32,
y: f32,
}
record vec3 {
x: f32,
y: f32,
z: f32,
}
/// Unit quaternion. Identity is `{ x: 0, y: 0, z: 0, w: 1 }`.
record quat {
x: f32,
y: f32,
z: f32,
w: f32,
}
/// Applied as scale, then rotation, then translation.
record transform {
translation: vec3,
rotation: quat,
scale: vec3,
}
/// Linear RGB with straight alpha.
record color {
r: f32,
g: f32,
b: f32,
a: f32,
}
/// Half-line in world space. `direction` need not be normalized, but must be
/// non-zero.
record ray {
origin: vec3,
direction: vec3,
}
}
interface ids {
/// 256-bit document ID as four little-endian `u64` words (first word is bytes
/// 0..8).
type document-id = tuple<u64, u64, u64, u64>;
/// 128-bit prim ID unique within its document, in the same word order as
/// `document-id`.
type prim-id = tuple<u64, u64>;
/// Reference to a specific prim within a document.
record prim-ref {
document: document-id,
prim: prim-id,
}
/// Decentralized identifier (e.g. `did:key:z6Mk...`).
type did = string;
}
interface error {
/// Host capability gated by the local peer's trust level for the document's
/// author.
enum permission {
/// Read the scene and write documents the script owns.
scene,
/// Create new documents.
create-document,
/// Commit edits durably to documents.
commit,
/// Send and receive local script messages.
event,
/// Receive pointer input aimed at prims in writable documents.
input,
/// Read all local user input events and pointer states.
input-device,
/// Read the local user's camera, avatar pose, and viewport.
local-agent,
/// Read the local user's DID.
identity,
/// Query document authors and physics holders.
peer,
/// Run raycasts and modify rigid-body state.
physics,
/// Open and pair portals.
portal,
/// Move the local user to another space.
travel,
/// Query nearby portals, agents, profiles, document metadata, and trust
/// levels.
perception,
}
/// Refilling rate-limit bucket.
enum rate {
create-document,
create-prim,
emit,
/// Large property writes (meshes, colliders, images, shader graphs).
upload,
portal,
}
/// Hard resource ceiling; frees when existing resources are dropped.
enum limit {
documents,
prims,
/// Live resource handles across all types.
handles,
subscriptions,
/// Bytes stored in the `shared` session layer.
shared-memory,
/// Guest WebAssembly linear memory.
memory,
}
variant error {
/// Malformed or out-of-range argument, with a diagnostic message.
invalid-argument(string),
/// Target does not exist or is not loaded locally.
not-found,
/// Target exists but is not ready yet (e.g. an unspawned physics body).
/// Retrying on a later tick may succeed.
not-ready,
/// Document author lacks the required permission on this peer.
permission(permission),
/// Operation is disallowed on this target (e.g. writing an unowned
/// document).
forbidden,
/// Rate budget exhausted; retries may succeed once it refills.
rate-limited(rate),
/// Resource ceiling reached; release existing resources before retrying.
limit-reached(limit),
/// Internal host failure, with a diagnostic message.
internal(string),
}
}
interface time {
/// Current local UTC offset in minutes (e.g. `60` for UTC+1, `-300` for
/// UTC-5), including daylight saving time. May change between calls.
utc-offset: func() -> s32;
}