Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

API

codeMode(options)

Makes an instance. Do this once, at startup.

codeMode({
  capabilities,      // required, see below
  tracer,            // optional, defaults to the global OpenTelemetry tracer
  capture,           // optional, payload settings
});

Bad capabilities throw here, at startup, rather than later on a request.

capabilities

FieldType
observes_crossings"all" | "some" | "none"required
unmediated_egressbooleanrequired
crossing_edge"invocation" | "dispatch"required unless observes_crossings is "none"
attestedstring[]what your server observed, default []
attested_attributesstring[]your keys you measured, needs host_attributes
relayed_attributesstring[]your keys a target reported, needs host_attributes
declaredobjectwhat your keys mean

capture

FieldDefault
valuesfalsewrite program text, arguments and results
cap8192bytes written per value
programCap32768bytes written for the program
measure1048576bytes read to compute the real size and hash

execution.run(options, body)

Starts a run, calls body, closes the run. Returns whatever body returns, and follows a promise if it returns one. A throw is recorded as failed and rethrown unchanged.

observed.execution.run({ program, tool: "execute" }, (execution) => { … });
Option
programthe submitted text, required
toolthe name of your code-mode tool
idyour own run id; one is generated if you don’t pass one
languagea hint like "javascript", leave it out rather than guess
kind"server" (default) or "local"
parentthe caller’s context from your propagator, never from the sandbox
sessionId, conversationId, toolCallIdcorrelation ids
attributesyour own attributes
endread a failure envelope, see the wrappers

execution.start(options)

Same options, but you close it yourself. Use it when your handler shape doesn’t suit a callback.

Execution handle

instrument(fn, options?)wrap a bridge function, one call becomes one span
crossing.start(options)open a call by hand
complete(options?)close the run as completed
fail(cause, options?)close it as failed
end(options)close it with any disposition
spanthe underlying OpenTelemetry span
contextthe run’s context, for bridges served in another task

Closing twice is a no-op, so the first close wins.

instrument(fn, options?)

Returns a wrapped function with the same name, arity and behaviour. It forwards this, rethrows the exact error, and follows a returned promise.

Option
targeta string, or a function of the arguments; defaults to the first argument
inputa function of the arguments; defaults to everything after the target
endturn the bridge’s answer into an outcome
toolType"function", "extension" or "datastore"
attributesyour own attributes

If one of these options throws, you lose that field and not the call. The call still runs and the span is still recorded.

Crossing handle

output(value?, options?)settled with a result
error(cause, options?)settled with an error
end(options)settled with any outcome
spanthe underlying span

Options take dispatched, errorType, message, endTime and attributes. A call you never settle is closed as abandoned when the run ends.

logTracer(write | options)

A tracer that writes flat records to a function instead of exporting spans. See using your logger.

Errors

Bad configuration throws at startup: TypeError for a wrong type, RangeError for a value outside a fixed set.

On the request path, nothing throws. A value that can’t be serialized is recorded as redacted, a broken option costs that field, a logger that throws costs that record. Observability should never break the thing it’s watching.