@supernovae-st/nika-client 0.63.0
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 +661 -0
- package/README.md +263 -0
- package/dist/index.cjs +675 -0
- package/dist/index.d.cts +274 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +639 -0
- package/package.json +44 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
interface NikaLogger {
|
|
2
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
3
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
4
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
}
|
|
7
|
+
interface NikaConfig {
|
|
8
|
+
/** URL of nika serve (e.g. http://localhost:3000) */
|
|
9
|
+
url: string;
|
|
10
|
+
/** Bearer token for authentication */
|
|
11
|
+
token: string;
|
|
12
|
+
/** Global HTTP request timeout in ms. Default: 30_000 */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Retries on 429/5xx. Default: 2 */
|
|
15
|
+
retries?: number;
|
|
16
|
+
/** Initial polling interval in ms. Default: 2_000 */
|
|
17
|
+
pollInterval?: number;
|
|
18
|
+
/** Max polling timeout in ms. Default: 300_000 (5 min) */
|
|
19
|
+
pollTimeout?: number;
|
|
20
|
+
/** Backoff multiplier for polling. Default: 1.5 */
|
|
21
|
+
pollBackoff?: number;
|
|
22
|
+
/** Max concurrent HTTP requests to nika serve. Default: 24 */
|
|
23
|
+
concurrency?: number;
|
|
24
|
+
/** Custom fetch function. Default: globalThis.fetch */
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
/** Logger for request/response tracing. Default: silent */
|
|
27
|
+
logger?: NikaLogger;
|
|
28
|
+
}
|
|
29
|
+
interface RunRequest {
|
|
30
|
+
workflow: string;
|
|
31
|
+
inputs?: Record<string, unknown>;
|
|
32
|
+
resume_from?: string;
|
|
33
|
+
}
|
|
34
|
+
/** POST /v1/run response */
|
|
35
|
+
interface RunResponse {
|
|
36
|
+
job_id: string;
|
|
37
|
+
status: string;
|
|
38
|
+
}
|
|
39
|
+
interface RunOptions {
|
|
40
|
+
resumeFrom?: string;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
type JobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
44
|
+
/** GET /v1/status/{id} response */
|
|
45
|
+
interface NikaJob {
|
|
46
|
+
job_id: string;
|
|
47
|
+
status: JobStatus;
|
|
48
|
+
workflow: string;
|
|
49
|
+
created_at: string;
|
|
50
|
+
started_at?: string;
|
|
51
|
+
completed_at?: string;
|
|
52
|
+
exit_code?: number;
|
|
53
|
+
output?: string;
|
|
54
|
+
}
|
|
55
|
+
interface CancelResponse {
|
|
56
|
+
job_id: string;
|
|
57
|
+
status: string;
|
|
58
|
+
message?: string;
|
|
59
|
+
}
|
|
60
|
+
interface NikaArtifact {
|
|
61
|
+
name: string;
|
|
62
|
+
size: number;
|
|
63
|
+
format: string;
|
|
64
|
+
content_type: string;
|
|
65
|
+
checksum?: string;
|
|
66
|
+
}
|
|
67
|
+
/** GET /v1/jobs/{id}/artifacts response */
|
|
68
|
+
interface ArtifactsResponse {
|
|
69
|
+
job_id: string;
|
|
70
|
+
count: number;
|
|
71
|
+
artifacts: NikaArtifact[];
|
|
72
|
+
}
|
|
73
|
+
/** GET /health response */
|
|
74
|
+
interface NikaHealth {
|
|
75
|
+
status: 'ok';
|
|
76
|
+
version: string;
|
|
77
|
+
service: string;
|
|
78
|
+
}
|
|
79
|
+
interface WorkflowInfo {
|
|
80
|
+
name: string;
|
|
81
|
+
size: number;
|
|
82
|
+
}
|
|
83
|
+
/** GET /v1/workflows response */
|
|
84
|
+
interface ListWorkflowsResponse {
|
|
85
|
+
workflows: WorkflowInfo[];
|
|
86
|
+
count: number;
|
|
87
|
+
/** Whether more results exist (present when `limit` is set). */
|
|
88
|
+
has_more?: boolean;
|
|
89
|
+
}
|
|
90
|
+
type NikaEvent = {
|
|
91
|
+
type: 'started';
|
|
92
|
+
job_id: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'task_start';
|
|
95
|
+
job_id: string;
|
|
96
|
+
task_id: string;
|
|
97
|
+
verb: string;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'task_complete';
|
|
100
|
+
job_id: string;
|
|
101
|
+
task_id: string;
|
|
102
|
+
duration_ms: number;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'task_failed';
|
|
105
|
+
job_id: string;
|
|
106
|
+
task_id: string;
|
|
107
|
+
error: string;
|
|
108
|
+
duration_ms: number;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'artifact_written';
|
|
111
|
+
job_id: string;
|
|
112
|
+
task_id: string;
|
|
113
|
+
path: string;
|
|
114
|
+
size: number;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'completed';
|
|
117
|
+
job_id: string;
|
|
118
|
+
output: string | null;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'failed';
|
|
121
|
+
job_id: string;
|
|
122
|
+
error: string | null;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'cancelled';
|
|
125
|
+
job_id: string;
|
|
126
|
+
};
|
|
127
|
+
type NikaEventType = NikaEvent['type'];
|
|
128
|
+
interface StreamOptions {
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
/** Max ms without any event before treating connection as dead. Default: 60_000 */
|
|
131
|
+
idleTimeout?: number;
|
|
132
|
+
/** Max reconnection attempts on stream drop. Default: 3 */
|
|
133
|
+
maxReconnects?: number;
|
|
134
|
+
/** Initial reconnect delay in ms (multiplied by attempt). Default: 1000 */
|
|
135
|
+
reconnectDelay?: number;
|
|
136
|
+
}
|
|
137
|
+
interface PollOptions {
|
|
138
|
+
interval: number;
|
|
139
|
+
timeout: number;
|
|
140
|
+
backoff: number;
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class ApiClient {
|
|
145
|
+
readonly url: string;
|
|
146
|
+
readonly timeout: number;
|
|
147
|
+
readonly retries: number;
|
|
148
|
+
readonly logger?: NikaLogger;
|
|
149
|
+
private readonly token;
|
|
150
|
+
private readonly _fetch;
|
|
151
|
+
private readonly semaphore;
|
|
152
|
+
constructor(url: string, token: string, timeout: number, retries: number, fetchFn: typeof globalThis.fetch, concurrency: number, logger?: NikaLogger);
|
|
153
|
+
request(path: string, init?: RequestInit): Promise<Response>;
|
|
154
|
+
private _request;
|
|
155
|
+
json<T>(path: string, init?: RequestInit): Promise<T>;
|
|
156
|
+
connectSSE(path: string, signal?: AbortSignal, extraHeaders?: Record<string, string>): Promise<Response>;
|
|
157
|
+
fetchHealth(): Promise<Response>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface JobsPollConfig {
|
|
161
|
+
pollInterval: number;
|
|
162
|
+
pollTimeout: number;
|
|
163
|
+
pollBackoff: number;
|
|
164
|
+
}
|
|
165
|
+
declare class Jobs {
|
|
166
|
+
private readonly api;
|
|
167
|
+
private readonly poll;
|
|
168
|
+
constructor(api: ApiClient, poll: JobsPollConfig);
|
|
169
|
+
/** Submit a workflow and return immediately with job ID. */
|
|
170
|
+
submit(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<RunResponse>;
|
|
171
|
+
/** Get current job status. */
|
|
172
|
+
status(jobId: string): Promise<NikaJob>;
|
|
173
|
+
/** Cancel a running job. */
|
|
174
|
+
cancel(jobId: string): Promise<CancelResponse>;
|
|
175
|
+
/** Run a workflow and wait for completion (polling). */
|
|
176
|
+
run(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<NikaJob>;
|
|
177
|
+
/** Stream job events via SSE (AsyncIterable). */
|
|
178
|
+
stream(jobId: string, options?: StreamOptions): AsyncIterable<NikaEvent>;
|
|
179
|
+
/** List artifacts for a job. */
|
|
180
|
+
artifacts(jobId: string): Promise<NikaArtifact[]>;
|
|
181
|
+
/** Download a specific artifact as string. */
|
|
182
|
+
artifact(jobId: string, name: string): Promise<string>;
|
|
183
|
+
/** Download a specific artifact as parsed JSON. */
|
|
184
|
+
artifactJson<T = unknown>(jobId: string, name: string): Promise<T>;
|
|
185
|
+
/** Download a specific artifact as raw bytes. */
|
|
186
|
+
artifactBinary(jobId: string, name: string): Promise<Uint8Array>;
|
|
187
|
+
/** Stream an artifact as a ReadableStream (for large files). */
|
|
188
|
+
artifactStream(jobId: string, name: string): Promise<ReadableStream<Uint8Array>>;
|
|
189
|
+
/** Run workflow, wait, and collect all non-binary artifacts into a map. */
|
|
190
|
+
runAndCollect(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<Record<string, unknown>>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface ListPageOptions {
|
|
194
|
+
/** Max workflows to return per page. */
|
|
195
|
+
limit?: number;
|
|
196
|
+
/** Cursor: return workflows after this name (from previous page's last item). */
|
|
197
|
+
after?: string;
|
|
198
|
+
}
|
|
199
|
+
declare class Workflows {
|
|
200
|
+
private readonly api;
|
|
201
|
+
constructor(api: ApiClient);
|
|
202
|
+
/**
|
|
203
|
+
* List all workflows. Auto-paginates if server supports it.
|
|
204
|
+
* For large lists, use `listPage()` for manual pagination.
|
|
205
|
+
*/
|
|
206
|
+
list(): Promise<WorkflowInfo[]>;
|
|
207
|
+
/** List a single page of workflows (manual pagination). */
|
|
208
|
+
listPage(options?: ListPageOptions): Promise<ListWorkflowsResponse>;
|
|
209
|
+
/** Reload workflows from disk and return the refreshed list. */
|
|
210
|
+
reload(): Promise<WorkflowInfo[]>;
|
|
211
|
+
/** Get the raw YAML source of a workflow. */
|
|
212
|
+
source(name: string): Promise<string>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Verify nika serve webhook signatures (Stripe-style HMAC-SHA256).
|
|
217
|
+
*
|
|
218
|
+
* Signature header format: "t=<unix_timestamp>,v1=<hmac_sha256_hex>"
|
|
219
|
+
* Signed payload: "<timestamp>.<body>"
|
|
220
|
+
*/
|
|
221
|
+
declare function verifyWebhookSignature(payload: string, signatureHeader: string, secret: string, tolerance?: number): Promise<boolean>;
|
|
222
|
+
|
|
223
|
+
/** Base error for all SDK errors. Catch this to handle any nika-client error. */
|
|
224
|
+
declare class NikaError extends Error {
|
|
225
|
+
constructor(message: string);
|
|
226
|
+
}
|
|
227
|
+
/** HTTP error from nika serve (non-2xx response). */
|
|
228
|
+
declare class NikaAPIError extends NikaError {
|
|
229
|
+
readonly status: number;
|
|
230
|
+
readonly body: string;
|
|
231
|
+
readonly requestId?: string;
|
|
232
|
+
constructor(message: string, status: number, body: string, requestId?: string);
|
|
233
|
+
}
|
|
234
|
+
/** Network or connection error (DNS, TCP reset, refused). */
|
|
235
|
+
declare class NikaConnectionError extends NikaError {
|
|
236
|
+
readonly cause?: Error;
|
|
237
|
+
constructor(message: string, cause?: Error);
|
|
238
|
+
}
|
|
239
|
+
/** Request or poll timeout exceeded. */
|
|
240
|
+
declare class NikaTimeoutError extends NikaError {
|
|
241
|
+
constructor(message: string);
|
|
242
|
+
}
|
|
243
|
+
/** Job terminated with status 'failed'. */
|
|
244
|
+
declare class NikaJobError extends NikaError {
|
|
245
|
+
readonly job: NikaJob;
|
|
246
|
+
readonly exitCode: number | undefined;
|
|
247
|
+
constructor(job: NikaJob);
|
|
248
|
+
}
|
|
249
|
+
/** Job was cancelled. Extends NikaJobError — catch NikaJobError to get both. */
|
|
250
|
+
declare class NikaJobCancelledError extends NikaJobError {
|
|
251
|
+
constructor(job: NikaJob);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class Nika {
|
|
255
|
+
/** Job operations: submit, status, cancel, run, stream, artifacts. */
|
|
256
|
+
readonly jobs: Jobs;
|
|
257
|
+
/** Workflow operations: list, reload. */
|
|
258
|
+
readonly workflows: Workflows;
|
|
259
|
+
private readonly api;
|
|
260
|
+
constructor(config: NikaConfig);
|
|
261
|
+
/** Health check (no auth required, uses timeout). */
|
|
262
|
+
health(): Promise<NikaHealth>;
|
|
263
|
+
/**
|
|
264
|
+
* Verify a webhook signature from nika serve.
|
|
265
|
+
*
|
|
266
|
+
* @param payload — raw request body string
|
|
267
|
+
* @param signature — value of X-Nika-Signature header
|
|
268
|
+
* @param secret — shared webhook secret (NIKA_WEBHOOK_SECRET)
|
|
269
|
+
* @param tolerance — max age in seconds (default: 300)
|
|
270
|
+
*/
|
|
271
|
+
static verifyWebhook: typeof verifyWebhookSignature;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { type ArtifactsResponse, type CancelResponse, type JobStatus, Jobs, type ListPageOptions, type ListWorkflowsResponse, Nika, NikaAPIError, type NikaArtifact, type NikaConfig, NikaConnectionError, NikaError, type NikaEvent, type NikaEventType, type NikaHealth, type NikaJob, NikaJobCancelledError, NikaJobError, type NikaLogger, NikaTimeoutError, type PollOptions, type RunOptions, type RunRequest, type RunResponse, type StreamOptions, type WorkflowInfo, Workflows, verifyWebhookSignature };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
interface NikaLogger {
|
|
2
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
3
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
4
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
5
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
6
|
+
}
|
|
7
|
+
interface NikaConfig {
|
|
8
|
+
/** URL of nika serve (e.g. http://localhost:3000) */
|
|
9
|
+
url: string;
|
|
10
|
+
/** Bearer token for authentication */
|
|
11
|
+
token: string;
|
|
12
|
+
/** Global HTTP request timeout in ms. Default: 30_000 */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Retries on 429/5xx. Default: 2 */
|
|
15
|
+
retries?: number;
|
|
16
|
+
/** Initial polling interval in ms. Default: 2_000 */
|
|
17
|
+
pollInterval?: number;
|
|
18
|
+
/** Max polling timeout in ms. Default: 300_000 (5 min) */
|
|
19
|
+
pollTimeout?: number;
|
|
20
|
+
/** Backoff multiplier for polling. Default: 1.5 */
|
|
21
|
+
pollBackoff?: number;
|
|
22
|
+
/** Max concurrent HTTP requests to nika serve. Default: 24 */
|
|
23
|
+
concurrency?: number;
|
|
24
|
+
/** Custom fetch function. Default: globalThis.fetch */
|
|
25
|
+
fetch?: typeof globalThis.fetch;
|
|
26
|
+
/** Logger for request/response tracing. Default: silent */
|
|
27
|
+
logger?: NikaLogger;
|
|
28
|
+
}
|
|
29
|
+
interface RunRequest {
|
|
30
|
+
workflow: string;
|
|
31
|
+
inputs?: Record<string, unknown>;
|
|
32
|
+
resume_from?: string;
|
|
33
|
+
}
|
|
34
|
+
/** POST /v1/run response */
|
|
35
|
+
interface RunResponse {
|
|
36
|
+
job_id: string;
|
|
37
|
+
status: string;
|
|
38
|
+
}
|
|
39
|
+
interface RunOptions {
|
|
40
|
+
resumeFrom?: string;
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
type JobStatus = 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
44
|
+
/** GET /v1/status/{id} response */
|
|
45
|
+
interface NikaJob {
|
|
46
|
+
job_id: string;
|
|
47
|
+
status: JobStatus;
|
|
48
|
+
workflow: string;
|
|
49
|
+
created_at: string;
|
|
50
|
+
started_at?: string;
|
|
51
|
+
completed_at?: string;
|
|
52
|
+
exit_code?: number;
|
|
53
|
+
output?: string;
|
|
54
|
+
}
|
|
55
|
+
interface CancelResponse {
|
|
56
|
+
job_id: string;
|
|
57
|
+
status: string;
|
|
58
|
+
message?: string;
|
|
59
|
+
}
|
|
60
|
+
interface NikaArtifact {
|
|
61
|
+
name: string;
|
|
62
|
+
size: number;
|
|
63
|
+
format: string;
|
|
64
|
+
content_type: string;
|
|
65
|
+
checksum?: string;
|
|
66
|
+
}
|
|
67
|
+
/** GET /v1/jobs/{id}/artifacts response */
|
|
68
|
+
interface ArtifactsResponse {
|
|
69
|
+
job_id: string;
|
|
70
|
+
count: number;
|
|
71
|
+
artifacts: NikaArtifact[];
|
|
72
|
+
}
|
|
73
|
+
/** GET /health response */
|
|
74
|
+
interface NikaHealth {
|
|
75
|
+
status: 'ok';
|
|
76
|
+
version: string;
|
|
77
|
+
service: string;
|
|
78
|
+
}
|
|
79
|
+
interface WorkflowInfo {
|
|
80
|
+
name: string;
|
|
81
|
+
size: number;
|
|
82
|
+
}
|
|
83
|
+
/** GET /v1/workflows response */
|
|
84
|
+
interface ListWorkflowsResponse {
|
|
85
|
+
workflows: WorkflowInfo[];
|
|
86
|
+
count: number;
|
|
87
|
+
/** Whether more results exist (present when `limit` is set). */
|
|
88
|
+
has_more?: boolean;
|
|
89
|
+
}
|
|
90
|
+
type NikaEvent = {
|
|
91
|
+
type: 'started';
|
|
92
|
+
job_id: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: 'task_start';
|
|
95
|
+
job_id: string;
|
|
96
|
+
task_id: string;
|
|
97
|
+
verb: string;
|
|
98
|
+
} | {
|
|
99
|
+
type: 'task_complete';
|
|
100
|
+
job_id: string;
|
|
101
|
+
task_id: string;
|
|
102
|
+
duration_ms: number;
|
|
103
|
+
} | {
|
|
104
|
+
type: 'task_failed';
|
|
105
|
+
job_id: string;
|
|
106
|
+
task_id: string;
|
|
107
|
+
error: string;
|
|
108
|
+
duration_ms: number;
|
|
109
|
+
} | {
|
|
110
|
+
type: 'artifact_written';
|
|
111
|
+
job_id: string;
|
|
112
|
+
task_id: string;
|
|
113
|
+
path: string;
|
|
114
|
+
size: number;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'completed';
|
|
117
|
+
job_id: string;
|
|
118
|
+
output: string | null;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'failed';
|
|
121
|
+
job_id: string;
|
|
122
|
+
error: string | null;
|
|
123
|
+
} | {
|
|
124
|
+
type: 'cancelled';
|
|
125
|
+
job_id: string;
|
|
126
|
+
};
|
|
127
|
+
type NikaEventType = NikaEvent['type'];
|
|
128
|
+
interface StreamOptions {
|
|
129
|
+
signal?: AbortSignal;
|
|
130
|
+
/** Max ms without any event before treating connection as dead. Default: 60_000 */
|
|
131
|
+
idleTimeout?: number;
|
|
132
|
+
/** Max reconnection attempts on stream drop. Default: 3 */
|
|
133
|
+
maxReconnects?: number;
|
|
134
|
+
/** Initial reconnect delay in ms (multiplied by attempt). Default: 1000 */
|
|
135
|
+
reconnectDelay?: number;
|
|
136
|
+
}
|
|
137
|
+
interface PollOptions {
|
|
138
|
+
interval: number;
|
|
139
|
+
timeout: number;
|
|
140
|
+
backoff: number;
|
|
141
|
+
signal?: AbortSignal;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
declare class ApiClient {
|
|
145
|
+
readonly url: string;
|
|
146
|
+
readonly timeout: number;
|
|
147
|
+
readonly retries: number;
|
|
148
|
+
readonly logger?: NikaLogger;
|
|
149
|
+
private readonly token;
|
|
150
|
+
private readonly _fetch;
|
|
151
|
+
private readonly semaphore;
|
|
152
|
+
constructor(url: string, token: string, timeout: number, retries: number, fetchFn: typeof globalThis.fetch, concurrency: number, logger?: NikaLogger);
|
|
153
|
+
request(path: string, init?: RequestInit): Promise<Response>;
|
|
154
|
+
private _request;
|
|
155
|
+
json<T>(path: string, init?: RequestInit): Promise<T>;
|
|
156
|
+
connectSSE(path: string, signal?: AbortSignal, extraHeaders?: Record<string, string>): Promise<Response>;
|
|
157
|
+
fetchHealth(): Promise<Response>;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface JobsPollConfig {
|
|
161
|
+
pollInterval: number;
|
|
162
|
+
pollTimeout: number;
|
|
163
|
+
pollBackoff: number;
|
|
164
|
+
}
|
|
165
|
+
declare class Jobs {
|
|
166
|
+
private readonly api;
|
|
167
|
+
private readonly poll;
|
|
168
|
+
constructor(api: ApiClient, poll: JobsPollConfig);
|
|
169
|
+
/** Submit a workflow and return immediately with job ID. */
|
|
170
|
+
submit(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<RunResponse>;
|
|
171
|
+
/** Get current job status. */
|
|
172
|
+
status(jobId: string): Promise<NikaJob>;
|
|
173
|
+
/** Cancel a running job. */
|
|
174
|
+
cancel(jobId: string): Promise<CancelResponse>;
|
|
175
|
+
/** Run a workflow and wait for completion (polling). */
|
|
176
|
+
run(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<NikaJob>;
|
|
177
|
+
/** Stream job events via SSE (AsyncIterable). */
|
|
178
|
+
stream(jobId: string, options?: StreamOptions): AsyncIterable<NikaEvent>;
|
|
179
|
+
/** List artifacts for a job. */
|
|
180
|
+
artifacts(jobId: string): Promise<NikaArtifact[]>;
|
|
181
|
+
/** Download a specific artifact as string. */
|
|
182
|
+
artifact(jobId: string, name: string): Promise<string>;
|
|
183
|
+
/** Download a specific artifact as parsed JSON. */
|
|
184
|
+
artifactJson<T = unknown>(jobId: string, name: string): Promise<T>;
|
|
185
|
+
/** Download a specific artifact as raw bytes. */
|
|
186
|
+
artifactBinary(jobId: string, name: string): Promise<Uint8Array>;
|
|
187
|
+
/** Stream an artifact as a ReadableStream (for large files). */
|
|
188
|
+
artifactStream(jobId: string, name: string): Promise<ReadableStream<Uint8Array>>;
|
|
189
|
+
/** Run workflow, wait, and collect all non-binary artifacts into a map. */
|
|
190
|
+
runAndCollect(workflow: string, inputs?: Record<string, unknown>, options?: RunOptions): Promise<Record<string, unknown>>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
interface ListPageOptions {
|
|
194
|
+
/** Max workflows to return per page. */
|
|
195
|
+
limit?: number;
|
|
196
|
+
/** Cursor: return workflows after this name (from previous page's last item). */
|
|
197
|
+
after?: string;
|
|
198
|
+
}
|
|
199
|
+
declare class Workflows {
|
|
200
|
+
private readonly api;
|
|
201
|
+
constructor(api: ApiClient);
|
|
202
|
+
/**
|
|
203
|
+
* List all workflows. Auto-paginates if server supports it.
|
|
204
|
+
* For large lists, use `listPage()` for manual pagination.
|
|
205
|
+
*/
|
|
206
|
+
list(): Promise<WorkflowInfo[]>;
|
|
207
|
+
/** List a single page of workflows (manual pagination). */
|
|
208
|
+
listPage(options?: ListPageOptions): Promise<ListWorkflowsResponse>;
|
|
209
|
+
/** Reload workflows from disk and return the refreshed list. */
|
|
210
|
+
reload(): Promise<WorkflowInfo[]>;
|
|
211
|
+
/** Get the raw YAML source of a workflow. */
|
|
212
|
+
source(name: string): Promise<string>;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Verify nika serve webhook signatures (Stripe-style HMAC-SHA256).
|
|
217
|
+
*
|
|
218
|
+
* Signature header format: "t=<unix_timestamp>,v1=<hmac_sha256_hex>"
|
|
219
|
+
* Signed payload: "<timestamp>.<body>"
|
|
220
|
+
*/
|
|
221
|
+
declare function verifyWebhookSignature(payload: string, signatureHeader: string, secret: string, tolerance?: number): Promise<boolean>;
|
|
222
|
+
|
|
223
|
+
/** Base error for all SDK errors. Catch this to handle any nika-client error. */
|
|
224
|
+
declare class NikaError extends Error {
|
|
225
|
+
constructor(message: string);
|
|
226
|
+
}
|
|
227
|
+
/** HTTP error from nika serve (non-2xx response). */
|
|
228
|
+
declare class NikaAPIError extends NikaError {
|
|
229
|
+
readonly status: number;
|
|
230
|
+
readonly body: string;
|
|
231
|
+
readonly requestId?: string;
|
|
232
|
+
constructor(message: string, status: number, body: string, requestId?: string);
|
|
233
|
+
}
|
|
234
|
+
/** Network or connection error (DNS, TCP reset, refused). */
|
|
235
|
+
declare class NikaConnectionError extends NikaError {
|
|
236
|
+
readonly cause?: Error;
|
|
237
|
+
constructor(message: string, cause?: Error);
|
|
238
|
+
}
|
|
239
|
+
/** Request or poll timeout exceeded. */
|
|
240
|
+
declare class NikaTimeoutError extends NikaError {
|
|
241
|
+
constructor(message: string);
|
|
242
|
+
}
|
|
243
|
+
/** Job terminated with status 'failed'. */
|
|
244
|
+
declare class NikaJobError extends NikaError {
|
|
245
|
+
readonly job: NikaJob;
|
|
246
|
+
readonly exitCode: number | undefined;
|
|
247
|
+
constructor(job: NikaJob);
|
|
248
|
+
}
|
|
249
|
+
/** Job was cancelled. Extends NikaJobError — catch NikaJobError to get both. */
|
|
250
|
+
declare class NikaJobCancelledError extends NikaJobError {
|
|
251
|
+
constructor(job: NikaJob);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
declare class Nika {
|
|
255
|
+
/** Job operations: submit, status, cancel, run, stream, artifacts. */
|
|
256
|
+
readonly jobs: Jobs;
|
|
257
|
+
/** Workflow operations: list, reload. */
|
|
258
|
+
readonly workflows: Workflows;
|
|
259
|
+
private readonly api;
|
|
260
|
+
constructor(config: NikaConfig);
|
|
261
|
+
/** Health check (no auth required, uses timeout). */
|
|
262
|
+
health(): Promise<NikaHealth>;
|
|
263
|
+
/**
|
|
264
|
+
* Verify a webhook signature from nika serve.
|
|
265
|
+
*
|
|
266
|
+
* @param payload — raw request body string
|
|
267
|
+
* @param signature — value of X-Nika-Signature header
|
|
268
|
+
* @param secret — shared webhook secret (NIKA_WEBHOOK_SECRET)
|
|
269
|
+
* @param tolerance — max age in seconds (default: 300)
|
|
270
|
+
*/
|
|
271
|
+
static verifyWebhook: typeof verifyWebhookSignature;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export { type ArtifactsResponse, type CancelResponse, type JobStatus, Jobs, type ListPageOptions, type ListWorkflowsResponse, Nika, NikaAPIError, type NikaArtifact, type NikaConfig, NikaConnectionError, NikaError, type NikaEvent, type NikaEventType, type NikaHealth, type NikaJob, NikaJobCancelledError, NikaJobError, type NikaLogger, NikaTimeoutError, type PollOptions, type RunOptions, type RunRequest, type RunResponse, type StreamOptions, type WorkflowInfo, Workflows, verifyWebhookSignature };
|