@supernovae-st/nika 0.71.0 → 0.118.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +562 -30
- package/dist/bin/nika.js +407 -0
- package/dist/index.cjs +2889 -0
- package/dist/index.d.cts +593 -0
- package/dist/index.d.ts +593 -0
- package/dist/index.js +2838 -0
- package/docs/architecture.md +85 -0
- package/docs/http-api.md +87 -0
- package/docs/migrating-to-0.116.md +147 -0
- package/docs/testing.md +156 -0
- package/openapi.json +1 -0
- package/package.json +76 -24
- package/bin.js +0 -49
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
interface NikaSharedConfig {
|
|
2
|
+
/** Bound for each event subscriber. Default: 256 events. */
|
|
3
|
+
eventBufferSize?: number;
|
|
4
|
+
/** Bound for buffered diagnostics and one machine frame. Default: 64 KiB. */
|
|
5
|
+
machineBufferBytes?: number;
|
|
6
|
+
}
|
|
7
|
+
/** The default configuration drives a native `nika` process. */
|
|
8
|
+
interface NikaLocalConfig extends NikaSharedConfig {
|
|
9
|
+
/** Working directory used by the native process transport. */
|
|
10
|
+
cwd?: string;
|
|
11
|
+
/** Binary resolution: this value, then NIKA_BIN, then the host payload package. */
|
|
12
|
+
bin?: string;
|
|
13
|
+
url?: never;
|
|
14
|
+
token?: never;
|
|
15
|
+
allowInsecureHttp?: never;
|
|
16
|
+
requestTimeout?: never;
|
|
17
|
+
fetch?: never;
|
|
18
|
+
}
|
|
19
|
+
/** Supplying a URL selects the authenticated HTTP transport. */
|
|
20
|
+
interface NikaRemoteConfig extends NikaSharedConfig {
|
|
21
|
+
/** A `nika serve --bind` base URL. */
|
|
22
|
+
url: string;
|
|
23
|
+
/** Bearer token matching the server's `--token-file`. */
|
|
24
|
+
token: string;
|
|
25
|
+
/** Plain HTTP is refused unless this is explicitly true. */
|
|
26
|
+
allowInsecureHttp?: boolean;
|
|
27
|
+
/** Bound for HTTP admission. Default: 30 seconds. */
|
|
28
|
+
requestTimeout?: number;
|
|
29
|
+
/** Fetch implementation used by the HTTP transport. */
|
|
30
|
+
fetch?: typeof globalThis.fetch;
|
|
31
|
+
/** Working directory used while capturing the immutable snapshot locally. */
|
|
32
|
+
cwd?: string;
|
|
33
|
+
/** Local engine used to capture the immutable snapshot before HTTP admission. */
|
|
34
|
+
bin?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Public configuration for the one Nika client surface. */
|
|
37
|
+
type NikaConfig = NikaLocalConfig | NikaRemoteConfig;
|
|
38
|
+
type NikaTransportKind = 'native-process' | 'http';
|
|
39
|
+
/**
|
|
40
|
+
* Brand carrier for engine-issued identities. The SDK brands an identity
|
|
41
|
+
* only where the engine (or its durable record) issues it; it never invents
|
|
42
|
+
* one itself.
|
|
43
|
+
*/
|
|
44
|
+
declare const NikaIdentityBrand: unique symbol;
|
|
45
|
+
interface NikaIdentity<Name extends string> {
|
|
46
|
+
readonly [NikaIdentityBrand]: Name;
|
|
47
|
+
}
|
|
48
|
+
/** A run identity issued by `run()` or `attachRun()`. Assignable to `string`. */
|
|
49
|
+
type NikaRunId = string & NikaIdentity<'NikaRunId'>;
|
|
50
|
+
/** An engine execution identity carried by terminal settlements and receipts. */
|
|
51
|
+
type NikaExecutionId = string & NikaIdentity<'NikaExecutionId'>;
|
|
52
|
+
/** A durable `nika serve` job identity accepted by `attachRun()`. */
|
|
53
|
+
type NikaJobId = string & NikaIdentity<'NikaJobId'>;
|
|
54
|
+
/** Machine vocabulary is additive. Known words aid completion without closing the set. */
|
|
55
|
+
type NikaRunStatus = 'queued' | 'running' | 'paused' | 'succeeded' | 'failed' | 'interrupted' | 'cancelled' | (string & {});
|
|
56
|
+
/** A machine check report. Unknown engine fields deliberately ride through. */
|
|
57
|
+
interface NikaCheckResult {
|
|
58
|
+
report_version?: number;
|
|
59
|
+
clean?: boolean;
|
|
60
|
+
exitCode?: number;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
/** Fields every engine event can carry, whether its kind is known or not. */
|
|
64
|
+
interface NikaEventFields {
|
|
65
|
+
status?: NikaRunStatus;
|
|
66
|
+
sequence?: number;
|
|
67
|
+
receipt?: NikaReceipt;
|
|
68
|
+
outputs?: Record<string, unknown>;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
/** The workflow graph started executing. */
|
|
72
|
+
interface NikaWorkflowStartedEvent extends NikaEventFields {
|
|
73
|
+
kind: 'workflow_started';
|
|
74
|
+
}
|
|
75
|
+
/** A task was scheduled for execution. */
|
|
76
|
+
interface NikaTaskScheduledEvent extends NikaEventFields {
|
|
77
|
+
kind: 'task_scheduled';
|
|
78
|
+
}
|
|
79
|
+
/** A task started executing. */
|
|
80
|
+
interface NikaTaskStartedEvent extends NikaEventFields {
|
|
81
|
+
kind: 'task_started';
|
|
82
|
+
}
|
|
83
|
+
/** A task settled. Per-task payloads ride the open fields. */
|
|
84
|
+
interface NikaTaskCompletedEvent extends NikaEventFields {
|
|
85
|
+
kind: 'task_completed';
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The workflow graph settled. This is the terminal frame of a native-process
|
|
89
|
+
* run and carries the run's outputs, receipt, and final status together.
|
|
90
|
+
*/
|
|
91
|
+
interface NikaWorkflowCompletedEvent<Outputs extends Record<string, unknown> = Record<string, unknown>> extends NikaEventFields {
|
|
92
|
+
kind: 'workflow_completed';
|
|
93
|
+
status?: NikaRunStatus;
|
|
94
|
+
outputs?: Outputs;
|
|
95
|
+
receipt?: NikaReceipt;
|
|
96
|
+
}
|
|
97
|
+
/** The workflow graph failed. */
|
|
98
|
+
interface NikaWorkflowFailedEvent extends NikaEventFields {
|
|
99
|
+
kind: 'workflow_failed';
|
|
100
|
+
error?: NikaMachineError;
|
|
101
|
+
}
|
|
102
|
+
/** The workflow graph was interrupted before settling. */
|
|
103
|
+
interface NikaWorkflowInterruptedEvent extends NikaEventFields {
|
|
104
|
+
kind: 'workflow_interrupted';
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The terminal settlement frame of a native engine process: the one frame
|
|
108
|
+
* that carries the run's outputs, receipt, and final status together. Its
|
|
109
|
+
* HTTP peer is `execution.settled`; one guard narrows both.
|
|
110
|
+
*/
|
|
111
|
+
interface NikaRunSettledEvent<Outputs extends Record<string, unknown> = Record<string, unknown>> extends NikaEventFields {
|
|
112
|
+
kind: 'run_settled';
|
|
113
|
+
status?: NikaRunStatus;
|
|
114
|
+
/** Why the run settled this way (engine 0.118+ · flattened on this frame). */
|
|
115
|
+
cause?: NikaRunCause;
|
|
116
|
+
elapsed_ms?: number;
|
|
117
|
+
tasks?: NikaTaskTally;
|
|
118
|
+
spend?: NikaSpend;
|
|
119
|
+
outputs?: Outputs;
|
|
120
|
+
receipt?: NikaReceipt;
|
|
121
|
+
/**
|
|
122
|
+
* The cause of a `failed` settlement (engine 0.117+): the first failed
|
|
123
|
+
* task's code, message and task id. Absent on a succeeded or paused run,
|
|
124
|
+
* and on engines that only name the cause on their `task_failed` frame.
|
|
125
|
+
*/
|
|
126
|
+
error?: NikaMachineError;
|
|
127
|
+
}
|
|
128
|
+
/** The run's trace chain was sealed. */
|
|
129
|
+
interface NikaRunSealedEvent extends NikaEventFields {
|
|
130
|
+
kind: 'run_sealed';
|
|
131
|
+
receipt?: NikaReceipt;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The HTTP transport admitted the execution and it is running. This is the
|
|
135
|
+
* first lifecycle frame `nika serve --bind` streams for a durable job.
|
|
136
|
+
*/
|
|
137
|
+
interface NikaExecutionStartedEvent extends NikaEventFields {
|
|
138
|
+
kind: 'execution.started';
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The terminal settlement frame of the HTTP transport, and the peer of
|
|
142
|
+
* `run_settled`: the one frame that carries the run's outputs, receipt, and
|
|
143
|
+
* final status together.
|
|
144
|
+
*/
|
|
145
|
+
interface NikaExecutionSettledEvent<Outputs extends Record<string, unknown> = Record<string, unknown>> extends NikaEventFields {
|
|
146
|
+
kind: 'execution.settled';
|
|
147
|
+
status?: NikaRunStatus;
|
|
148
|
+
outputs?: Outputs;
|
|
149
|
+
receipt?: NikaReceipt;
|
|
150
|
+
/** The settlement the resident nests whole on this frame (engine 0.118+ · ADR-128). */
|
|
151
|
+
settlement?: NikaSettlement;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The resident cancelled the execution: a queued job cancelled before it was
|
|
155
|
+
* claimed, or a running one whose owner settled the request as a
|
|
156
|
+
* cancellation. It carries the settlement when the runtime built one.
|
|
157
|
+
*/
|
|
158
|
+
interface NikaExecutionCancelledEvent extends NikaEventFields {
|
|
159
|
+
kind: 'execution.cancelled';
|
|
160
|
+
settlement?: NikaSettlement;
|
|
161
|
+
}
|
|
162
|
+
/** The server refused the execution. */
|
|
163
|
+
interface NikaExecutionRefusedEvent extends NikaEventFields {
|
|
164
|
+
kind: 'execution.refused';
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* The execution was interrupted before settling. A resident that restarts
|
|
168
|
+
* marks an orphaned running job with either word, so both are one variant.
|
|
169
|
+
*/
|
|
170
|
+
interface NikaExecutionInterruptedEvent extends NikaEventFields {
|
|
171
|
+
kind: 'execution.interrupted' | 'interrupted';
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Forward-compatibility variant: any kind this SDK version does not know
|
|
175
|
+
* yet stays representable, so the event union is intentionally
|
|
176
|
+
* non-exhaustive.
|
|
177
|
+
*/
|
|
178
|
+
interface NikaUnknownEvent extends NikaEventFields {
|
|
179
|
+
kind?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* One engine-owned run event, from either transport: the native process emits
|
|
183
|
+
* the `workflow_*` / `task_*` / `run_*` kinds, `nika serve` emits the
|
|
184
|
+
* `execution.*` kinds. Known kinds discriminate on `kind`; unknown kinds fall
|
|
185
|
+
* back to `NikaUnknownEvent`. Future fields stay open on every variant.
|
|
186
|
+
* `Outputs` types the terminal frames' outputs and defaults to the transport
|
|
187
|
+
* shape, so untyped callers see no change.
|
|
188
|
+
*/
|
|
189
|
+
type NikaEvent<Outputs extends Record<string, unknown> = Record<string, unknown>> = NikaWorkflowStartedEvent | NikaTaskScheduledEvent | NikaTaskStartedEvent | NikaTaskCompletedEvent | NikaWorkflowCompletedEvent<Outputs> | NikaWorkflowFailedEvent | NikaWorkflowInterruptedEvent | NikaRunSettledEvent<Outputs> | NikaRunSealedEvent | NikaExecutionStartedEvent | NikaExecutionSettledEvent<Outputs> | NikaExecutionCancelledEvent | NikaExecutionRefusedEvent | NikaExecutionInterruptedEvent | NikaUnknownEvent;
|
|
190
|
+
/**
|
|
191
|
+
* Engine-issued proof material. The SDK transports it but never constructs,
|
|
192
|
+
* reads a workflow to enrich it, or verifies its claims itself.
|
|
193
|
+
*/
|
|
194
|
+
type NikaReceipt = Readonly<Record<string, unknown>>;
|
|
195
|
+
interface NikaMachineError {
|
|
196
|
+
code?: string;
|
|
197
|
+
message?: string;
|
|
198
|
+
/** The task that failed, when a native `task_failed` frame named it. */
|
|
199
|
+
task?: string;
|
|
200
|
+
[key: string]: unknown;
|
|
201
|
+
}
|
|
202
|
+
/** Why a run settled the way it did (engine 0.118+ · ADR-128). */
|
|
203
|
+
type NikaRunCause = 'normal' | 'human_gate' | 'task_failed' | 'output_contract' | 'budget' | 'operator' | 'refused' | (string & {});
|
|
204
|
+
/**
|
|
205
|
+
* How much of the spend is priced (engine 0.118+): `unmetered` = no metered
|
|
206
|
+
* call · `unpriced` = a local or subscription seat, never free · `partially_priced`
|
|
207
|
+
* · `priced`.
|
|
208
|
+
*/
|
|
209
|
+
type NikaCostQualifier = 'priced' | 'partially_priced' | 'unpriced' | 'unmetered' | (string & {});
|
|
210
|
+
/** How the run's tasks ended (engine 0.118+): `recovered` is a tally, never a state. */
|
|
211
|
+
interface NikaTaskTally {
|
|
212
|
+
total?: number;
|
|
213
|
+
ok?: number;
|
|
214
|
+
failed?: number;
|
|
215
|
+
recovered?: number;
|
|
216
|
+
skipped?: number;
|
|
217
|
+
cancelled?: number;
|
|
218
|
+
never_started?: number;
|
|
219
|
+
[key: string]: unknown;
|
|
220
|
+
}
|
|
221
|
+
/** What the run spent and how much of it is priced (engine 0.118+). */
|
|
222
|
+
interface NikaSpend {
|
|
223
|
+
/** Present only when at least one call metered real spend; unknown cost is never zero. */
|
|
224
|
+
total_cost_usd?: number | null;
|
|
225
|
+
priced_calls?: number;
|
|
226
|
+
unpriced_calls?: number;
|
|
227
|
+
qualifier?: NikaCostQualifier;
|
|
228
|
+
pricing_as_of?: string | null;
|
|
229
|
+
/** Spend per pricing source, when the engine broke it down. */
|
|
230
|
+
by_source?: Record<string, number>;
|
|
231
|
+
[key: string]: unknown;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* The run's settlement as the engine built it once (ADR-128): the state's
|
|
235
|
+
* cause, the task tally, the spend and its qualifier, the elapsed time.
|
|
236
|
+
* Absent on engines before 0.118; never derived from an exit code.
|
|
237
|
+
*/
|
|
238
|
+
interface NikaSettlement {
|
|
239
|
+
/**
|
|
240
|
+
* The state word the settlement itself carries (`succeeded` · `failed` ·
|
|
241
|
+
* `paused` · `cancelled`) on the resident's nested projection; the native
|
|
242
|
+
* `run_settled` frame states it on the frame instead.
|
|
243
|
+
*/
|
|
244
|
+
status?: NikaRunStatus;
|
|
245
|
+
cause?: NikaRunCause;
|
|
246
|
+
elapsed_ms?: number;
|
|
247
|
+
tasks?: NikaTaskTally;
|
|
248
|
+
spend?: NikaSpend;
|
|
249
|
+
/** The failure named on a `failed` settlement: code, message and the task, when one failed. */
|
|
250
|
+
error?: NikaMachineError;
|
|
251
|
+
[key: string]: unknown;
|
|
252
|
+
}
|
|
253
|
+
/** The only terminal value for a run. */
|
|
254
|
+
interface NikaRunResult<Outputs extends Record<string, unknown> = Record<string, unknown>> {
|
|
255
|
+
id: NikaRunId;
|
|
256
|
+
status: NikaRunStatus;
|
|
257
|
+
transport: NikaTransportKind;
|
|
258
|
+
exitCode?: number;
|
|
259
|
+
outputs?: Outputs;
|
|
260
|
+
receipt?: NikaReceipt;
|
|
261
|
+
error?: NikaMachineError;
|
|
262
|
+
/** Engine execution identity, when the transport surface reports one. */
|
|
263
|
+
execution_id?: NikaExecutionId;
|
|
264
|
+
/** The settlement's cause, tally and spend (engine 0.118+), when the terminal frame carried them. */
|
|
265
|
+
settlement?: NikaSettlement;
|
|
266
|
+
[key: string]: unknown;
|
|
267
|
+
}
|
|
268
|
+
/** A run identity plus its one terminal settlement. */
|
|
269
|
+
interface NikaRun<Outputs extends Record<string, unknown> = Record<string, unknown>> {
|
|
270
|
+
readonly id: NikaRunId;
|
|
271
|
+
readonly done: Promise<NikaRunResult<Outputs>>;
|
|
272
|
+
}
|
|
273
|
+
interface NikaCancelResult {
|
|
274
|
+
runId: NikaRunId;
|
|
275
|
+
accepted: boolean;
|
|
276
|
+
/**
|
|
277
|
+
* `cancelled`: the job settled cancelled on the cancel reply itself.
|
|
278
|
+
* `already_settled`: the run had already ended, nothing was cancelled.
|
|
279
|
+
* `cancellation_requested`: the request was accepted while the execution
|
|
280
|
+
* owner had not settled yet (a native SIGTERM, or the resident's 202); the
|
|
281
|
+
* run then settles on its own terminal, read from `run.done`, which may be
|
|
282
|
+
* `cancelled`, `succeeded`, `failed`, or `interrupted` once the resident's
|
|
283
|
+
* grace expired. Open to the engine's future words.
|
|
284
|
+
*/
|
|
285
|
+
status: 'cancelled' | 'already_settled' | 'cancellation_requested' | (string & {});
|
|
286
|
+
transport: NikaTransportKind;
|
|
287
|
+
[key: string]: unknown;
|
|
288
|
+
}
|
|
289
|
+
/** Server-owned metadata for one contained resident workflow. */
|
|
290
|
+
interface NikaWorkflowMetadata {
|
|
291
|
+
workflow: string;
|
|
292
|
+
[key: string]: unknown;
|
|
293
|
+
}
|
|
294
|
+
interface NikaTraceVerifyResult {
|
|
295
|
+
verified: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Engine-owned trace verdict. The native path answers `verified` or
|
|
298
|
+
* `invalid`; the resident's door answers `unavailable` while it has no
|
|
299
|
+
* trace-journal authority (engine 0.118), and will speak the CLI's tiers
|
|
300
|
+
* (`OK` · `SEALED` · `ANCHORED` · `REPLAYED` hold · `INCOMPLETE` ·
|
|
301
|
+
* `TAMPERED` do not) once it does. Open to additive future vocabulary.
|
|
302
|
+
*/
|
|
303
|
+
verdict?: 'verified' | 'invalid' | 'unavailable' | 'OK' | 'SEALED' | 'ANCHORED' | 'REPLAYED' | 'INCOMPLETE' | 'TAMPERED' | (string & {});
|
|
304
|
+
/** Engine-owned explanation for a negative or unavailable verdict; a verdict that holds carries none. */
|
|
305
|
+
reason?: 'trace_invalid' | 'receipt_mismatch' | 'run_not_terminal' | 'trace_journal_unavailable' | (string & {});
|
|
306
|
+
trace_id?: string;
|
|
307
|
+
exitCode?: number;
|
|
308
|
+
output?: string;
|
|
309
|
+
[key: string]: unknown;
|
|
310
|
+
}
|
|
311
|
+
interface NikaCheckOptions {
|
|
312
|
+
model?: string;
|
|
313
|
+
nativeStrict?: boolean;
|
|
314
|
+
/** Stops only this check request/process. */
|
|
315
|
+
signal?: AbortSignal;
|
|
316
|
+
}
|
|
317
|
+
interface NikaRunOptions {
|
|
318
|
+
vars?: Record<string, string | number | boolean>;
|
|
319
|
+
model?: string;
|
|
320
|
+
maxCostUsd?: number;
|
|
321
|
+
/** Retained for HTTP admission deduplication. */
|
|
322
|
+
idempotencyKey?: string;
|
|
323
|
+
}
|
|
324
|
+
/** Resume observation of an already-admitted durable HTTP job. */
|
|
325
|
+
interface NikaAttachRunOptions {
|
|
326
|
+
/** Last SSE sequence durably consumed by the caller. Default: 0. */
|
|
327
|
+
lastEventId?: number;
|
|
328
|
+
}
|
|
329
|
+
interface NikaEventsOptions {
|
|
330
|
+
/** Stops this subscriber view. It never cancels the run. */
|
|
331
|
+
signal?: AbortSignal;
|
|
332
|
+
/** Per-view queue bound, capped by the client eventBufferSize. */
|
|
333
|
+
bufferSize?: number;
|
|
334
|
+
}
|
|
335
|
+
interface NikaTraceVerifyOptions {
|
|
336
|
+
/** Stops only the verification request/process. */
|
|
337
|
+
signal?: AbortSignal;
|
|
338
|
+
}
|
|
339
|
+
/** The SDK operations whose engine refusal can be returned as a typed error. */
|
|
340
|
+
type NikaOperation = 'check' | 'run' | 'attachRun' | 'status' | 'cancel' | 'listWorkflows' | 'workflow' | 'traceVerify' | 'schedule' | 'scheduleStatus';
|
|
341
|
+
/** One engine-owned schedule finding. The vocabulary remains additive. */
|
|
342
|
+
interface NikaScheduleFinding {
|
|
343
|
+
code: string;
|
|
344
|
+
detail: string;
|
|
345
|
+
[key: string]: unknown;
|
|
346
|
+
}
|
|
347
|
+
/** Findings carried by the one operation-error taxonomy. */
|
|
348
|
+
type NikaOperationFinding = NikaScheduleFinding;
|
|
349
|
+
type NikaScheduleWhen = {
|
|
350
|
+
kind: 'once';
|
|
351
|
+
at: string;
|
|
352
|
+
} | {
|
|
353
|
+
kind: 'cadence';
|
|
354
|
+
expression: string;
|
|
355
|
+
};
|
|
356
|
+
/** Exact declarative input accepted by PUT /v1/schedules/{id}. */
|
|
357
|
+
interface NikaScheduleOptions {
|
|
358
|
+
/** Stable path identity for the resident schedule. */
|
|
359
|
+
id: string;
|
|
360
|
+
when: NikaScheduleWhen;
|
|
361
|
+
maxCostUsd: number;
|
|
362
|
+
missed: 'catch-up' | 'catch-up-once' | 'skip';
|
|
363
|
+
maxLatenessSeconds?: number;
|
|
364
|
+
overlap?: 'skip' | 'queue' | 'replace';
|
|
365
|
+
afterSkip?: 'next_slot' | 'on_completion';
|
|
366
|
+
jitter?: 'hash';
|
|
367
|
+
tolerance?: string;
|
|
368
|
+
active?: boolean;
|
|
369
|
+
pauseReason?: string;
|
|
370
|
+
/** ISO calendar date (`YYYY-MM-DD`) required when active is false. */
|
|
371
|
+
pauseUntil?: string;
|
|
372
|
+
/** Exact prior revision for an update. Omit for create-if-absent. */
|
|
373
|
+
revision?: string;
|
|
374
|
+
}
|
|
375
|
+
type NikaScheduleMissed = 'catch-up' | 'catch-up-once' | 'skip' | (string & {});
|
|
376
|
+
type NikaScheduleOverlap = 'skip' | 'queue' | 'replace' | (string & {});
|
|
377
|
+
type NikaScheduleAfterSkip = 'next_slot' | 'on_completion' | (string & {});
|
|
378
|
+
/** The engine-normalized schedule definition; the SDK never normalizes it. */
|
|
379
|
+
interface NikaScheduleDefinition {
|
|
380
|
+
id: string;
|
|
381
|
+
workflow: string;
|
|
382
|
+
when: NikaScheduleWhen | {
|
|
383
|
+
kind: string;
|
|
384
|
+
[key: string]: unknown;
|
|
385
|
+
};
|
|
386
|
+
maxCostUsd: number;
|
|
387
|
+
missed: NikaScheduleMissed;
|
|
388
|
+
maxLatenessSeconds: number | null;
|
|
389
|
+
overlap: NikaScheduleOverlap;
|
|
390
|
+
afterSkip: NikaScheduleAfterSkip;
|
|
391
|
+
jitter: 'hash' | (string & {}) | null;
|
|
392
|
+
tolerance: string | null;
|
|
393
|
+
active: boolean;
|
|
394
|
+
pauseReason: string | null;
|
|
395
|
+
pauseUntil: string | null;
|
|
396
|
+
[key: string]: unknown;
|
|
397
|
+
}
|
|
398
|
+
interface NikaScheduleSlot {
|
|
399
|
+
slotId: string;
|
|
400
|
+
scheduledFor: string;
|
|
401
|
+
requestedCivil: string | null;
|
|
402
|
+
shift: 'exact' | 'advanced_first_valid' | 'folded_first' | (string & {});
|
|
403
|
+
[key: string]: unknown;
|
|
404
|
+
}
|
|
405
|
+
type NikaScheduleDue = {
|
|
406
|
+
kind: 'scheduled';
|
|
407
|
+
slot: NikaScheduleSlot;
|
|
408
|
+
} | {
|
|
409
|
+
kind: 'catch_up';
|
|
410
|
+
slot: NikaScheduleSlot;
|
|
411
|
+
missedSlots: number;
|
|
412
|
+
} | {
|
|
413
|
+
kind: 'skipped_missed';
|
|
414
|
+
slot: NikaScheduleSlot;
|
|
415
|
+
missedSlots: number;
|
|
416
|
+
} | {
|
|
417
|
+
kind: 'skipped_too_late';
|
|
418
|
+
slot: NikaScheduleSlot;
|
|
419
|
+
latenessSeconds: number;
|
|
420
|
+
maximumSeconds: number;
|
|
421
|
+
} | {
|
|
422
|
+
kind: 'paused';
|
|
423
|
+
reason: string | null;
|
|
424
|
+
pauseUntil: string | null;
|
|
425
|
+
} | {
|
|
426
|
+
kind: 'once_consumed';
|
|
427
|
+
slotId: string;
|
|
428
|
+
scheduledFor: string;
|
|
429
|
+
} | {
|
|
430
|
+
kind: 'not_due';
|
|
431
|
+
} | {
|
|
432
|
+
kind: string & {};
|
|
433
|
+
[key: string]: unknown;
|
|
434
|
+
};
|
|
435
|
+
interface NikaSchedulePause {
|
|
436
|
+
reason: string | null;
|
|
437
|
+
until: string | null;
|
|
438
|
+
}
|
|
439
|
+
interface NikaScheduleClaim {
|
|
440
|
+
runId: string;
|
|
441
|
+
executionId: string;
|
|
442
|
+
traceId: string;
|
|
443
|
+
generation: string;
|
|
444
|
+
[key: string]: unknown;
|
|
445
|
+
}
|
|
446
|
+
interface NikaScheduleLastDecision {
|
|
447
|
+
action: 'claimed' | 'skipped' | (string & {});
|
|
448
|
+
decision: 'scheduled' | 'catch_up' | (string & {});
|
|
449
|
+
revision: string;
|
|
450
|
+
slotId: string;
|
|
451
|
+
scheduledFor: string;
|
|
452
|
+
decidedAt: string;
|
|
453
|
+
reason: string | null;
|
|
454
|
+
claim: NikaScheduleClaim | null;
|
|
455
|
+
[key: string]: unknown;
|
|
456
|
+
}
|
|
457
|
+
/** Fresh engine planning facts. The SDK transports them without interpretation. */
|
|
458
|
+
interface NikaScheduleStatus {
|
|
459
|
+
definition: NikaScheduleDefinition;
|
|
460
|
+
origin: 'api' | (string & {});
|
|
461
|
+
revision: string;
|
|
462
|
+
active: boolean;
|
|
463
|
+
pause: NikaSchedulePause | null;
|
|
464
|
+
due?: NikaScheduleDue;
|
|
465
|
+
finding?: NikaScheduleFinding;
|
|
466
|
+
next: NikaScheduleSlot[];
|
|
467
|
+
earliestWakeHint: string | null;
|
|
468
|
+
lastDecision: NikaScheduleLastDecision | null;
|
|
469
|
+
[key: string]: unknown;
|
|
470
|
+
}
|
|
471
|
+
/** Durable apply acknowledgement. It does not wait for a scheduled fire. */
|
|
472
|
+
interface NikaScheduleApplyResult {
|
|
473
|
+
applied: true;
|
|
474
|
+
changed: boolean;
|
|
475
|
+
status: NikaScheduleStatus;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
declare class NikaError extends Error {
|
|
479
|
+
constructor(message: string, options?: ErrorOptions);
|
|
480
|
+
}
|
|
481
|
+
declare class NikaConfigurationError extends NikaError {
|
|
482
|
+
constructor(message: string);
|
|
483
|
+
}
|
|
484
|
+
declare class NikaTransportError extends NikaError {
|
|
485
|
+
readonly transport: NikaTransportKind;
|
|
486
|
+
constructor(transport: NikaTransportKind, message: string, options?: ErrorOptions);
|
|
487
|
+
}
|
|
488
|
+
/** A typed engine/adapter capability gap, not a workflow failure. */
|
|
489
|
+
declare class NikaCompatibilityError extends NikaError {
|
|
490
|
+
readonly capability: string;
|
|
491
|
+
readonly transport: NikaTransportKind;
|
|
492
|
+
constructor(capability: string, transport: NikaTransportKind, message: string);
|
|
493
|
+
}
|
|
494
|
+
declare class NikaProtocolError extends NikaTransportError {
|
|
495
|
+
constructor(transport: NikaTransportKind, message: string, options?: ErrorOptions);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Observation broke before terminal settlement and the final durable read
|
|
499
|
+
* stayed non-terminal. The cursor feeds attachRun(id, { lastEventId }).
|
|
500
|
+
*/
|
|
501
|
+
declare class NikaObservationInterrupted extends NikaTransportError {
|
|
502
|
+
readonly runId: string;
|
|
503
|
+
readonly lastSequence: number;
|
|
504
|
+
readonly attempts: number;
|
|
505
|
+
constructor(transport: NikaTransportKind, runId: string, lastSequence: number, attempts: number);
|
|
506
|
+
}
|
|
507
|
+
/** One taxonomy for engine refusals returned by an SDK operation. */
|
|
508
|
+
declare class NikaOperationError extends NikaError {
|
|
509
|
+
readonly operation: NikaOperation;
|
|
510
|
+
readonly code: string;
|
|
511
|
+
readonly transport: NikaTransportKind;
|
|
512
|
+
readonly status: number;
|
|
513
|
+
readonly findings?: readonly NikaOperationFinding[];
|
|
514
|
+
readonly currentRevision?: string | null;
|
|
515
|
+
readonly machineCode?: string;
|
|
516
|
+
constructor(operation: NikaOperation, transport: NikaTransportKind, code: string, message: string, details: {
|
|
517
|
+
status: number;
|
|
518
|
+
findings?: readonly NikaOperationFinding[];
|
|
519
|
+
currentRevision?: string | null;
|
|
520
|
+
machineCode?: string;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
declare class NikaEventBufferOverflowError extends NikaError {
|
|
524
|
+
readonly runId: string;
|
|
525
|
+
readonly limit: number;
|
|
526
|
+
constructor(runId: string, limit: number);
|
|
527
|
+
}
|
|
528
|
+
declare class NikaRunOwnershipError extends NikaError {
|
|
529
|
+
constructor();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** The local engine could not be resolved without an implicit PATH lookup. */
|
|
533
|
+
declare class NikaEngineUnavailable extends NikaError {
|
|
534
|
+
readonly code = "NIKA_ENGINE_UNAVAILABLE";
|
|
535
|
+
readonly platform: string;
|
|
536
|
+
readonly arch: string;
|
|
537
|
+
readonly packageName?: string;
|
|
538
|
+
constructor(platform: string, arch: string, packageName?: string);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Narrows any run event to the terminal settlement frame, which carries the
|
|
543
|
+
* run's status, outputs, and receipt together. Both transports have one: the
|
|
544
|
+
* native process emits `run_settled`, `nika serve` emits `execution.settled`.
|
|
545
|
+
* Kind equality alone cannot exclude the forward-compatibility variant; this
|
|
546
|
+
* guard can.
|
|
547
|
+
*/
|
|
548
|
+
declare function isNikaRunSettledEvent<Outputs extends Record<string, unknown> = Record<string, unknown>>(event: NikaEvent<Outputs>): event is NikaRunSettledEvent<Outputs> | NikaExecutionSettledEvent<Outputs>;
|
|
549
|
+
/**
|
|
550
|
+
* Narrows any run event to a terminal one by the status the engine reported,
|
|
551
|
+
* not by its kind, so it holds on either transport and across kinds this SDK
|
|
552
|
+
* version does not know yet. It therefore also covers the frames that end a
|
|
553
|
+
* run without settling outputs: `execution.cancelled`, `execution.refused`,
|
|
554
|
+
* `interrupted`, `workflow_failed` and `workflow_cancelled` (the engine's
|
|
555
|
+
* four run terminals are `workflow_completed` · `workflow_failed` ·
|
|
556
|
+
* `workflow_paused` · `workflow_cancelled` · ADR-128).
|
|
557
|
+
*/
|
|
558
|
+
declare function isNikaTerminalEvent<Outputs extends Record<string, unknown> = Record<string, unknown>>(event: NikaEvent<Outputs>): event is NikaEvent<Outputs> & {
|
|
559
|
+
status: 'succeeded' | 'failed' | 'interrupted' | 'cancelled';
|
|
560
|
+
};
|
|
561
|
+
/** Narrows any run event to the frame that sealed the run's trace chain. */
|
|
562
|
+
declare function isNikaRunSealedEvent<Outputs extends Record<string, unknown> = Record<string, unknown>>(event: NikaEvent<Outputs>): event is NikaRunSealedEvent;
|
|
563
|
+
|
|
564
|
+
/** One client surface for a local engine process or a live nika serve URL. */
|
|
565
|
+
declare class Nika {
|
|
566
|
+
readonly transportKind: NikaTransportKind;
|
|
567
|
+
private readonly transport;
|
|
568
|
+
private readonly sessions;
|
|
569
|
+
private readonly eventBufferSize;
|
|
570
|
+
constructor(config?: NikaConfig);
|
|
571
|
+
check(workflow: string, options?: NikaCheckOptions): Promise<NikaCheckResult>;
|
|
572
|
+
/**
|
|
573
|
+
* `Outputs` is the caller's projection of the engine-emitted outputs map;
|
|
574
|
+
* the SDK transports outputs without validating their shape.
|
|
575
|
+
*/
|
|
576
|
+
run<Outputs extends Record<string, unknown> = Record<string, unknown>>(workflow: string, options?: NikaRunOptions): Promise<NikaRun<Outputs>>;
|
|
577
|
+
/** Reattach this client process to an already-admitted durable HTTP job. */
|
|
578
|
+
attachRun<Outputs extends Record<string, unknown> = Record<string, unknown>>(id: string, options?: NikaAttachRunOptions): Promise<NikaRun<Outputs>>;
|
|
579
|
+
/** List contained workflow names from a resident HTTP authority. */
|
|
580
|
+
listWorkflows(): Promise<readonly string[]>;
|
|
581
|
+
/** Read path-free metadata for one contained workflow. */
|
|
582
|
+
workflow(name: string): Promise<NikaWorkflowMetadata>;
|
|
583
|
+
events<Outputs extends Record<string, unknown> = Record<string, unknown>>(run: NikaRun<Outputs>, options?: NikaEventsOptions): AsyncIterable<NikaEvent<Outputs>>;
|
|
584
|
+
cancel(run: NikaRun): Promise<NikaCancelResult>;
|
|
585
|
+
/** Read the current durable status without waiting for terminal settlement. */
|
|
586
|
+
status(run: NikaRun): Promise<NikaRunStatus>;
|
|
587
|
+
schedule(workflow: string, options: NikaScheduleOptions): Promise<NikaScheduleApplyResult>;
|
|
588
|
+
scheduleStatus(id: string): Promise<NikaScheduleStatus>;
|
|
589
|
+
traceVerify(receipt: NikaReceipt, options?: NikaTraceVerifyOptions): Promise<NikaTraceVerifyResult>;
|
|
590
|
+
private session;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
export { Nika, type NikaAttachRunOptions, type NikaCancelResult, type NikaCheckOptions, type NikaCheckResult, NikaCompatibilityError, type NikaConfig, NikaConfigurationError, type NikaCostQualifier, NikaEngineUnavailable, NikaError, type NikaEvent, NikaEventBufferOverflowError, type NikaEventsOptions, type NikaExecutionCancelledEvent, type NikaExecutionId, type NikaExecutionInterruptedEvent, type NikaExecutionRefusedEvent, type NikaExecutionSettledEvent, type NikaExecutionStartedEvent, type NikaJobId, type NikaLocalConfig, type NikaMachineError, NikaObservationInterrupted, type NikaOperation, NikaOperationError, type NikaOperationFinding, NikaProtocolError, type NikaReceipt, type NikaRemoteConfig, type NikaRun, type NikaRunCause, type NikaRunId, type NikaRunOptions, NikaRunOwnershipError, type NikaRunResult, type NikaRunSealedEvent, type NikaRunSettledEvent, type NikaRunStatus, type NikaScheduleAfterSkip, type NikaScheduleApplyResult, type NikaScheduleClaim, type NikaScheduleDefinition, type NikaScheduleDue, type NikaScheduleFinding, type NikaScheduleLastDecision, type NikaScheduleMissed, type NikaScheduleOptions, type NikaScheduleOverlap, type NikaSchedulePause, type NikaScheduleSlot, type NikaScheduleStatus, type NikaScheduleWhen, type NikaSettlement, type NikaSpend, type NikaTaskCompletedEvent, type NikaTaskScheduledEvent, type NikaTaskStartedEvent, type NikaTaskTally, type NikaTraceVerifyOptions, type NikaTraceVerifyResult, NikaTransportError, type NikaTransportKind, type NikaUnknownEvent, type NikaWorkflowCompletedEvent, type NikaWorkflowFailedEvent, type NikaWorkflowInterruptedEvent, type NikaWorkflowMetadata, type NikaWorkflowStartedEvent, isNikaRunSealedEvent, isNikaRunSettledEvent, isNikaTerminalEvent };
|