An operation is the unit of compute in DXOS. It is a typed action that you define once. Whoever needs it runs it: a
person through the UI, an agent as a tool, or a trigger. A trigger is an object that starts an operation on a schedule
or an event.
A definition is the value that Operation.make builds from metadata and two schemas:
The metadata, meta, holds the key, a name, a description and an icon. The key is a DXN, such as
com.example.operation.stashedLink.markRead, and it names the operation everywhere it runs. The description is
what an agent reads when it decides whether to call the operation.
The input and output schemas are Effect schemas. Their field descriptions tell people and agents what to pass.
A definition can also list the ECHO types it uses, so the types are known where it runs remotely, and the
services its handler needs.
Creates a new Operation definition.
Applies default executionMode of 'async' if not specified.
The returned type preserves the literal types of props (including services).
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
Field definitions are discovered from own enumerable string and symbol
properties of fields. Non-enumerable and inherited definitions are ignored.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Declared fields on the input may be non-enumerable or inherited and are copied
to own properties in the output. The __proto__ field is accepted only when
it is an own property.
Parsing does not guarantee that output keys retain their input order.
Use when you need to model the return value of a function, RPC, or endpoint
whose result is intentionally ignored.
Details
Runtime parsing accepts any present value and discards it, producing
undefined. The public decoded and encoded TypeScript representation remains
void, so typed construction, decoding, and encoding APIs are still modeled
as void.
@stability ― stable
@category ― models
@since ― 3.10.0
@see ― Undefined for a schema that matches only the exact undefined value.
@stability ― stable
@category ― schemas
@since ― 3.10.0
Void,
27
});
28
MarkRead has no handler yet. Its one input field, link, is a reference to the link, not the link itself, and its
output is Schema.Void, so a caller gets nothing back.
Provides a way to write effectful code using generator functions, simplifying
control flow and error handling.
When to use
Use when you want to write effectful code that looks and behaves like
synchronous code, while still handling asynchronous tasks, errors, and complex
control flow such as loops and conditions.
Generator functions work similarly to async/await but keep errors,
requirements, and interruption in the Effect type. You can yield* values
from effects and return the final result at the end.
Perform mutations on an echo object within a controlled context.
All mutations within the callback are batched and trigger a single notification
when the callback completes. Direct mutations outside of Obj.update will throw
an error for echo objects.
This function also works with nested objects within echo objects (e.g., Template structs)
that are reactive at runtime.
@param ― obj - The echo object to mutate. Use Relation.update for relations.
@param ― callback - The callback that performs mutations on the object.
@example
const person = Obj.make(Person, { name: 'John', age: 25 });
handler is the MarkRead definition with its handler attached. The handler can call Database.resolve because the
definition lists Database.Service. It then sets read to true inside Obj.update.
The definition and the handler are separate values, so a package can publish the definition for others to call
without shipping how it runs.
Operation.lazyHandler names the module that holds the handler. Use it when the code should load only on the first
call.
A handler set is a group of handlers that a runtime loads together. A PLEX plugin contributes one through a
capability. See PLEX’s Operations.
The operation registry holds each definition as an ECHO object, so agents and the MCP server can search the
operations a space offers. A definition whose metadata sets skipRegistry is left out of it.
One definition serves every caller. A button, the command palette, an agent and a trigger invoke the same key with
the same input.
Errors are typed. A handler fails with tagged errors that the caller catches by tag. If you invoke a key that no
handler set serves, the call fails with NoHandlerError.
A handler can stop early when its run is cancelled. It reads the run’s AbortSignal from Cancellation.signal in
@dxos/compute, and hands the signal to work that can stop, such as a fetch.
The runtime that runs the operation fires the signal. In the app, it fires when the
process is terminated, and the runtime then interrupts the handler. On EDGE, it
fires when the client asks to cancel the run, and the handler is not interrupted.
If the runtime provides no cancellation, the signal never fires.
An operation can invoke other operations. The call is linked to the caller’s process,
so the trace shows which call started it.
When you deploy an operation to EDGE, EDGE assigns it a deployment id. A client can invoke it there by that id or by
its key.
Input and output must be serializable, because a call may cross to a browser worker or to EDGE. Pass ECHO objects
by reference.
A handler gets only the services its definition declares and the ones every process has. It does not get the UI.
An operation that sets skipRegistry is not in the operation registry, so agents and the MCP server cannot find it.
Use it for an operation that only makes sense in the UI.