> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nika.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# SDK type index

> Open engine projections, run lifecycle types, proof and error taxonomy.

## Run lifecycle

```ts theme={"system"}
interface NikaRun<Outputs extends Record<string, unknown> = Record<string, unknown>> {
  readonly id: NikaRunId
  readonly events: (options?: NikaEventsOptions) => AsyncIterable<NikaRunEvent<Outputs>>
  readonly result: () => Promise<NikaRunResult<Outputs>>
  readonly status: () => Promise<NikaRunStatus>      // resident-owned; native rejects (NikaCompatibilityError)
  readonly cancel: () => Promise<NikaCancelResult>   // idempotent; acceptance is not a result
  readonly artifacts: (options?: NikaArtifactsOptions) => Promise<NikaArtifactManifest>  // server only
  readonly downloadArtifact: (artifact: string | NikaArtifact, options?: NikaArtifactDownloadOptions) => Promise<NikaArtifactDownload>
  readonly readArtifact: (artifact: string | NikaArtifact, options?: NikaArtifactReadOptions) => Promise<Uint8Array>
  readonly done: Promise<NikaRunResult<Outputs>>     // compatibility alias of result()
}
```

The `Outputs` generic narrows `result().outputs` at compile time. It is a
type-level convenience only — nothing runtime-validates model output against
it. The workflow's `outputs:` block *exports* named values; it does not
validate them. Runtime shape enforcement comes from `infer.schema` (checked
when the model answers) or an explicit validator task (`nika:validate`) —
not from the export mapping, and never from a TypeScript generic.

`run.id` differs by transport: on HTTP it is the resident's **durable job
id** (the identity to store); on the native transport it is an ephemeral
correlation id of this SDK process — it appears in no journal, cannot be
recovered after the process ends, and `attachRun` refuses it. Resume a
native run through the engine's own trace instead.

```ts theme={"system"}
interface NikaRunResult<Outputs> {
  id: NikaRunId
  status: NikaRunStatus             // 'queued' | 'running' | 'paused' | 'succeeded' | 'failed' | 'interrupted' | 'cancelled' | …
  transport: 'native-process' | 'http'
  exitCode?: number                 // local engine exit code (0 · 1 · 3 · 4 · 130)
  outputs?: Outputs
  receipt?: NikaReceipt
  error?: NikaMachineError          // { code?, message?, task? }
  execution_id?: NikaExecutionId
  settlement?: NikaSettlement
  evidence?: NikaJournalEvidence    // HTTP only: { status: 'mirror_lost', reason }; no released engine writes it yet
  [key: string]: unknown
}

interface NikaSettlement {
  status?: NikaRunStatus
  cause?: 'normal' | 'human_gate' | 'task_failed' | 'output_contract' | 'budget' | 'operator' | 'refused' | (string & {})
  elapsed_ms?: number
  tasks?: NikaTaskTally             // total · ok · failed · recovered · skipped · cancelled · never_started
  spend?: {
    total_cost_usd?: number | null  // present only when a call metered real spend: never a made-up zero
    priced_calls?: number
    unpriced_calls?: number
    qualifier?: 'priced' | 'partially_priced' | 'unpriced' | 'unmetered' | (string & {})
  }
  error?: NikaMachineError
  [key: string]: unknown
}
```

`result()` has one failure law: it **rejects** on transport, protocol or
compatibility faults and on a broken observation
(`NikaObservationInterrupted`, which carries the cursor) — none of which say
the run failed; it may still be running. It **resolves** `status: 'failed'`
for an admitted workflow failure (result data, with the engine's
`error.code` when named), and `status: 'paused'` when a human gate holds the
run. Read `isNikaRunSucceeded(result)` before treating it as success.

## Events

```ts theme={"system"}
type NikaRunEventKind =
  | 'run.started' | 'task.scheduled' | 'task.started' | 'task.completed'
  | 'task.failed' | 'task.skipped' | 'task.cancelled' | 'task.cache_hit'
  | 'run.waiting' | 'run.settled' | 'run.interrupted'
  | 'run.sealed' | 'engine.event'

interface NikaRunEvent<Outputs> {
  readonly kind: NikaRunEventKind
  readonly transport: NikaTransportKind
  readonly status?: NikaRunStatus   // the engine's own state word, never renamed
  readonly sequence?: number        // HTTP only — persist for attachRun({ lastEventId })
  readonly task?: string            // the task a task.* frame named
  readonly error?: NikaMachineError
  readonly raw: NikaEvent<Outputs>  // the exact protocol frame the engine wrote
}
```

`engine.event` is the preservation door: every frame this SDK version does
not name arrives there with its `raw` frame untouched; nothing is dropped,
and no lifecycle meaning is invented for it. Keep a `default` branch in
reducers; the set is additive. `run.sealed` names a `run_sealed` frame if an
engine streams one; engine 0.124.3 writes the seal to the run's record only,
so read `result.receipt.sealed` locally or `traceVerify(...).verdict`.

## Check and cancellation

`NikaCheckResult` is an open engine projection. A local check carries the
findings report, process `exitCode` and `verdicts`, typed `NikaCheckVerdicts`
(`valid` · `access_ready` · `capacity_fit` · `run_ready` · `blockers` ·
`network_tasks`): under `check({ access })` a pin the engine refuses keeps
`clean: true` with `verdicts.access_ready: false` and the refusal in
`verdicts.blockers`. `access_ready` judges the model routes only; from engine
0.124.1, `network_tasks` lists, sorted, the tasks whose own effects can still
reach the network (a fetch or webhook to a real host, an MCP tool, a paid
media call), which a `mock/echo` rehearsal does not stub. Each finding
(`NikaCheckFinding`) that names a part of the file carries `span`, a
`NikaSourceSpan` (`{ start, end }`): byte offsets into the workflow file,
`start` inclusive and `end` exclusive. From engine 0.124 a parse refusal
carries one too, and from 0.124.1 the offsets count a file's byte-order mark,
as the file is saved. A served-name HTTP check carries `clean: true` plus `status`, `snapshot_digest`,
`root` and `units`, or `clean: false` with a typed refusal in `error`; it does
not invent a local findings report or exit code.

`NikaCancelResult` describes action acceptance: `cancelled` (settled on the
reply), `already_settled`, or `cancellation_requested` — execution continues
toward its own settlement in the last case. Use `run.result()` for the
actual result, including success racing cancellation.

## Compile

```ts theme={"system"}
interface NikaCompileOutcome {
  compile_version: 1 | 2                    // 2 exactly when a provider call happened
  status: 'ready' | 'incomplete' | 'refused'
  ready: boolean                            // exactly status === 'ready'
  candidate: string | null                  // .nika source, proposed only when ready
  questions: NikaCompileQuestion[]
  diagnostics: NikaCompileDiagnostic[]
  requested_boundary: Record<string, unknown> | null
  requested_trigger?: NikaCompileTrigger | null
  check_preview: NikaCompilePreview | null  // scope 'sourceOnly', never admission
  provenance: NikaCompileProvenance
  replay_token?: string                     // HTTP only: a provider round the server kept
  written?: string | null                   // local engine only, with `output`
  // … and further HTTP or local-engine facts
}
```

A request is a create (`{ intent }`, or the intent as a bare string) or an
edit (`{ workflow, change }`, the accepted source plus the change), never
both. `incomplete` and `refused` are data: the SDK throws only on transport,
protocol, compatibility and engine-stamped failures. Under `incomplete`, a
non-null `candidate` is a preview, never a result to run or save.

## Artifacts

```ts theme={"system"}
interface NikaArtifactManifest {
  receipt: NikaReceipt              // the job's own, chain head included: the SDK checked it
  verdict: 'sealed' | 'anchored'    // the sealed journal's tier: any other word is refused
  max_artifact_bytes: number        // the server's download bound (256 MiB; no flag changes it)
  truncated: boolean                // more than the 1,024 listed entries exist
  artifacts: NikaArtifact[]         // in journal order; a file written twice appears once
  [key: string]: unknown
}

interface NikaArtifact {
  name: string                      // 'file/<path>' or 'agent_image/<n>.<ext>': a key, never a path
  kind: 'file' | 'agent_image' | (string & {})
  path?: string                     // a file's contained project path; absent for an agent image
  size: number                      // recorded bytes
  sha256: string                    // recorded SHA-256, 64 lowercase hex
  mime: string
  task?: string
  event_id: string
  [key: string]: unknown
}

interface NikaArtifactDownload {
  readonly name: string
  readonly size: number             // what the stream is proven against
  readonly sha256: string
  readonly mime: string
  readonly artifact?: NikaArtifact  // absent only for a name past a truncated manifest
  readonly stream: import('node:stream/web').ReadableStream<Uint8Array>  // closes only once proven
}

interface NikaArtifactsOptions { signal?: AbortSignal }
interface NikaArtifactDownloadOptions { signal?: AbortSignal }
interface NikaArtifactReadOptions extends NikaArtifactDownloadOptions {
  maxBytes?: number                 // default 16 MiB; a larger artifact is refused before its download
}
```

A server's manifest is checked field by field: the `verdict` is `sealed` or
`anchored`, names are unique, sizes are byte counts, digests are SHA-256 and
a file's `path` is contained; any other key rides through. The `path` check
is lexical and POSIX, the server's own, so it does not make a path safe to
join under a local directory on every system: to write an artifact under
yours, resolve the joined path, check that it stays inside, and open it
exclusively (`wx`). The download stream errors with `NikaProtocolError` for
bytes that are not the recorded ones, `NikaOperationError` for a server
refusal on a retry (`artifact_changed`), and `NikaTransportError` for a
download that stayed incomplete or was aborted.
[Outputs and artifacts](https://docs.nika.sh/sdk/remote/artifacts.md) shows them in use.

## Access pins

```ts theme={"system"}
type NikaAccessPin =
  | 'local' | 'mock' | 'harness' | 'oauth' | 'api'
  | 'claude-code' | 'codex' | 'copilot' | 'gemini-cli'
  | 'grok-build' | 'kimi-code' | 'opencode' | 'qwen-code'
  | (string & {})
```

The words aid completion without closing the set: the engine, never the SDK,
judges a pin. `run({ access })` and `check({ access })` take one
([Configuration](https://docs.nika.sh/sdk/reference/configuration.md#access-pins)).

## Access contract and receipt

From 0.124.2. What a workflow file declares under `run.access` and
`run.reasoning`, and what one model call did with it:

```ts theme={"system"}
type NikaServiceTier = 'standard' | 'fast' | (string & {})

interface NikaAccessRequirement {
  via?: string
  protocol?: 'api' | 'acp' | (string & {})
  fallback?: 'none' | (string & {})
  service_tier?: NikaServiceTier
  effort?: string
  [key: string]: unknown
}

type NikaConfiguredSource =
  | 'session_config' | 'confirmed_selection' | 'accepted_request'
  | (string & {})

interface NikaSelectedValue {
  requested: string | null
  option: string | null
  transmitted: string | null
  configured: string | null
  configured_source: NikaConfiguredSource | null
  [key: string]: unknown
}

interface NikaAttestedValue {
  value: string | null
  evidence: 'unknown' | (string & {})
  [key: string]: unknown
}

interface NikaServiceTierEvidence {
  requested: NikaServiceTier | null
  option: string | null
  offered: string[] | null
  transmitted: string | null
  configured: string | null
  configured_source: NikaConfiguredSource | null
  turn: NikaAttestedValue
  effective: NikaAttestedValue
  [key: string]: unknown
}

interface NikaAccessSelection {
  schema: 'nika/access-selection@1' | (string & {})
  protocol: 'api' | 'acp' | (string & {}) | null
  model: NikaSelectedValue
  effort: NikaSelectedValue
  responder: {
    model: string | null
    evidence: 'api_response' | 'cli_reported' | 'unknown' | (string & {})
    [key: string]: unknown
  }
  service_tier?: NikaServiceTierEvidence
  changed_mid_turn?: string[]
  [key: string]: unknown
}
```

`null` means not applicable or not observed, never a copied value. A
`configured` value is what the route reported after the selection:
`session_config` when nothing was asked and the session stated its own,
`confirmed_selection` when a value was sent and read back,
`accepted_request` when the route took it without answering a configuration.
`changed_mid_turn` lists a model, an effort or a tier the route itself moved
during the turn. `readNikaAccessRequirement` and `readNikaAccessSelection`
return these from a task's terminal frame
([Run events](https://docs.nika.sh/sdk/runtime/events.md#read-the-access-contract-and-its-receipt)).

## Access offer

From 0.124.3. What `accessOffer()` returns: the sessions of a served
workflow's declared ACP route, read without a prompt
([Ask what a route offers](https://docs.nika.sh/sdk/operations/server-surfaces.md#ask-what-a-route-offers)):

```ts theme={"system"}
interface NikaAccessOfferListing {
  status: 'offered' | 'not_offered' | 'unobserved'
  option?: string
  offered?: string[]
  omitted?: number
  current?: string
  reason?: string
}

interface NikaAccessOfferRoute {
  via: string
  protocol: 'acp'
  profile: 'completion' | 'agent'
  tasks: string[]
  status: 'observed' | 'unavailable'
  observed_at: string
  fresh_until: string
  code?: string
  reason?: string
  adapter?: { name?: string; version?: string }
  model: {
    requested: string
    status?: 'confirmed' | 'session_default' | 'legacy_list' | 'not_offered' | 'not_confirmed'
    current?: string
    offered?: string[]
    omitted?: number
  }
  effort?: NikaAccessOfferListing
  service_tier?: NikaAccessOfferListing
}

interface NikaAccessOffer {
  schema: 'nika/access-offer@1'
  workflow: string
  status: 'read' | 'not_applicable'
  reason?: string
  declared?: NikaAccessRequirement
  prompts_sent: 0
  routes: NikaAccessOfferRoute[]
  routes_omitted: number
}

interface NikaAccessOfferOptions {
  signal?: AbortSignal
  timeoutMs?: number
}
```

The document is closed: the reader refuses an answer with a key or a word it
does not know, with `NikaProtocolError`. An observed row carries its
`model.status` and both listings. An unavailable row carries the `code` a run
would meet before its prompt.

## Proof

```ts theme={"system"}
type NikaReceipt = Readonly<Record<string, unknown>>

interface NikaTraceVerifyResult {
  verified: boolean
  verdict?: string   // local: 'verified' · 'invalid'
                     // nika serve: 'ok' · 'sealed' · 'anchored' · 'replayed' (hold)
                     //             'incomplete' · 'tampered' · 'broken' (do not) · 'unavailable'
                     //             refusals: 'unchained' · 'empty' · 'unreadable' · 'refused' · 'line-over-long' · 'unknown'
  reason?: string    // 'receipt_mismatch' · 'unsealed' · 'sealed' · 'trace_journal_unavailable' …
  trace_id?: string
  exitCode?: number
  output?: string
  [key: string]: unknown
}
```

Locally the verdict is `verified`, or `invalid` (`reason: 'receipt_mismatch'`
for an unsealed or edited record; no reason when the trace file cannot be
read). Over HTTP it is the CLI verifier's tier in lower case: `ok` means intact
but unsigned (`reason: 'unsealed'`), and `unavailable` means the server holds
no journal for the job. The published 0.124.3 declarations list the same
words, with the CLI verifier's refusal classes (`unchained` · `empty` ·
`unreadable` · `refused` · `line-over-long` · `unknown`), and over HTTP a
verdict that holds always carries its seal tier as `reason` (`sealed` or
`unsealed`). [Receipts](https://docs.nika.sh/sdk/runtime/receipts.md) has the measured table.

## Errors

```text theme={"system"}
NikaError
├── NikaConfigurationError
├── NikaEngineUnavailable        // no engine for this host (code NIKA_ENGINE_UNAVAILABLE, platform, arch)
├── NikaTransportError
│   ├── NikaProtocolError
│   └── NikaObservationInterrupted
├── NikaCompatibilityError
├── NikaOperationError
├── NikaEventBufferOverflowError
└── NikaRunOwnershipError
```

`NikaObservationInterrupted` means this client lost its observation of a run
that may still be running: an evidence state, never a settlement. Schedule
types (`NikaScheduleOptions`, `NikaScheduleStatus`, `NikaScheduleApplyResult`)
are exported for the revision-checked server schedule contract; their
engine-owned fields are additive.

> [accordion] Which published source this page describes
>
> > [!NOTE]
> >
> > These pages describe the published `@supernovae-st/nika@0.124.4`
> > [SDK release](https://github.com/supernovae-st/nika-client/tree/v0.124.4) and its matching
> > [bundled engine](https://github.com/supernovae-st/nika/releases/tag/v0.124.4). A newer engine
> > release or SDK main commit does not change an installed package. Use Node.js
> > 22 or newer, on macOS (arm64, x64) or Linux with glibc (x64, arm64); no
> > global Nika installation is required for local mode. Versioned transcripts,
> > recordings and measurements keep the release they were captured on;
> > selecting this package release does not re-run those examples.

> [card] [Published type declarations (v0.124.3)](https://github.com/supernovae-st/nika-client/tree/v0.124.4)
>
> Review the source of the published declarations.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.