For AI agents: the complete documentation index is available at https://flow.jig.md/llms.txt, the full documentation bundle is available at https://flow.jig.md/llms-full.txt, and this page is available as Markdown at https://flow.jig.md/reference/sdk.md.
DocumentationReferencePrerelease

#SDK API

View Markdown

The SDK receives one invocation, exposes its context, and lets your method call host-bound dependencies. Use the same handler API for a directly launched Flow and a Flow called by another method.

LanguagePackageImport
TypeScript or JavaScript@jigging/flow@jigging/flow
Pythonjiggy-flowjiggy.flow

This page summarizes the current author interface. Run SDK/0 defines exact types and behavior, with Run/0 owning the wire protocol. For installation and a complete task, follow the build guides.

#Receive an invocation

TypeScript's handle(handler) returns a promise and receives an async handler:

import { handle } from "@jigging/flow";

await handle(async (run) => ({ outcome: "done", output: run.input }));

Python's handle(handler) creates and owns the event loop:

from jiggy.flow import RunContext, RunResult, handle


async def run(context: RunContext) -> RunResult:
    return {"outcome": "done", "output": context.input}


handle(run)

These illustrative echo handlers require a host exchange on stdin and stdout. Python's synchronous entrypoint belongs outside an already-running asyncio loop. The host supplies the context and qualifies the execution runtime.

#Invocation context

TypeScriptPythonContains
run.inputcontext.inputThe invocation's JSON/0 input.
run.settingscontext.settingsValidated implementation settings.
run.attachmentscontext.attachmentsAuthorized attachment paths and access modes, with artifact references on readonly views.
run.channelscontext.channelsEndpoints supplied for this invocation.
run.scratchcontext.scratchThe host-prepared scratch directory.
run.deadlineUnixMscontext.deadline_unix_msThe host-supplied finite deadline.
run.signalHandler task cancellationRoot cancellation.

Declarations name needed interfaces. The host supplies actual implementations, context, and authority. The SDK exposes the deadline, and the host enforces it.

#Call a dependency

Inside a handler, an illustrative call to a host-bound reviewer slot is:

const result = await run.call({
  operationId: "review:1",
  slot: "reviewer",
  input: run.input,
});

The equivalent Python call is:

result = await context.call(
    operation_id="review:1", slot="reviewer", input=context.input,
)

Declare the slot under uses in the package metadata. The host binds and authorizes its target before invocation. Your code supplies the operation identity according to Run/0 identity rules.

Optional call fields carry intent, channels, and attachments. Intent is advisory metadata. Explicit channel and attachment mappings carry the rights the host checks. See Run SDK/0 values and snapshots for optional-field and snapshot semantics.

#Results and errors

call returns a complete CallResult, including outcome, output, and optional held artifacts. Inspect the outcome before consuming its output. Declared domain outcomes remain data. Operational failures raise OperationError.

ValueUse
RunResultThe handler's outcome, JSON/0 output, and optional selected artifactResults.
CallResultA dependency's outcome, JSON/0 output, and optional held artifacts.
OperationError.codeMachine-readable failure classification.
OperationError.messageHuman-readable explanation.
OperationError.detailsOptional structured detail, represented by None when omitted in Python.

Branch on error codes rather than human messages. Invalid handler results become INVALID_RESULT. PROTOCOL_ERROR and CHANNEL_LOST are local-only classifications. See results and errors for the complete rules.

#Cancellation and owned work

TypeScript accepts a call-specific AbortSignal as run.call's second argument. Python uses ordinary task cancellation for an awaited call. Both cancel the local wait and send protocol cancellation when the request reached the wire.

Await owned calls before returning the handler result. The SDK settles outstanding requests and rejects abandoned live work. Cancellation neither proves remote work stopped nor reverses an external effect. The host owns enforcement and final settlement.

#Channels and artifacts

run.channel(...) or context.channel(...) requests a direct pair or isolated broadcast channel. The API exposes sender, receiver, and broadcast interfaces for sending, observing, subscribing, and closing. Read the channel projection for exact types and ownership.

Artifacts are opaque held references outside domain JSON. Forward selected references through artifactResults and explicit attachment mappings. Ordinary cleanup releases live rights automatically. Advanced early release uses release(...), when the host supports that operation. Read immutable artifact handoff before transferring or releasing references.

#Protocol output

After entry, the SDK routes ordinary console or print diagnostics to stderr. Keep import-time logging, raw stdout writes, and inherited child stdout off the protocol stream. For exact logging and completion semantics, use Run SDK/0.