UNAVI Docs unavi.xyz
Build · Scripting API

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

record
x: f32
y: f32

vec3

record
x: f32
y: f32
z: f32

quat

record

Unit quaternion. Identity is { x: 0, y: 0, z: 0, w: 1 }.

x: f32
y: f32
z: f32
w: f32

transform

record

Applied as scale, then rotation, then translation.

translation: vec3
rotation: quat
scale: vec3

color

record

Linear RGB with straight alpha.

r: f32
g: f32
b: f32
a: f32

ray

record

Half-line in world space. direction need not be normalized, but must be non-zero.

origin: vec3
direction: vec3

Interface ids

document-id

typedocument-id = tuple<u64, u64, u64, u64>

256-bit document ID as four little-endian u64 words (first word is bytes 0..8).

prim-id

typeprim-id = tuple<u64, u64>

128-bit prim ID unique within its document, in the same word order as document-id.

prim-ref

record

Reference to a specific prim within a document.

document: document-id
prim: prim-id

did

typedid = string

Decentralized identifier (e.g. did:key:z6Mk...).

Interface error

permission

enum

Host capability gated by the local peer's trust level for the document's author.

sceneRead the scene and write documents the script owns.
create-documentCreate new documents.
commitCommit edits durably to documents.
eventSend and receive local script messages.
inputReceive pointer input aimed at prims in writable documents.
input-deviceRead all local user input events and pointer states.
local-agentRead the local user's camera, avatar pose, and viewport.
identityRead the local user's DID.
peerQuery document authors and physics holders.
physicsRun raycasts and modify rigid-body state.
portalOpen and pair portals.
travelMove the local user to another space.
perceptionQuery nearby portals, agents, profiles, document metadata, and trust levels.

rate

enum

Refilling rate-limit bucket.

create-document
create-prim
emit
uploadLarge property writes (meshes, colliders, images, shader graphs).
portal

limit

enum

Hard resource ceiling; frees when existing resources are dropped.

documents
prims
handlesLive resource handles across all types.
subscriptions
shared-memoryBytes stored in the shared session layer.
memoryGuest WebAssembly linear memory.

error

variant
invalid-argument(string)Malformed or out-of-range argument, with a diagnostic message.
not-foundTarget does not exist or is not loaded locally.
not-readyTarget 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.
forbiddenOperation 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

funcutc-offset: func() -> s32

Current 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;
}