@kubb/studio 5.3.16 → 5.3.18
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/README.md +29 -7
- package/dist/index.cjs +695 -542
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +68 -33
- package/dist/index.js +693 -543
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +20 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.ts +77 -40
- package/dist/protocol.js +19 -1
- package/dist/protocol.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
-
import { AgentApi, AgentPermissions, ConfigEdit, ConnectMessagePayload, GenerateInput, GenerateResult, GenerationEvent, GenerationEventPayloads, GenerationEventType, GenerationRun, PublishSnapshotInput, PublishSnapshotResult, RpcConnection, RpcConnector, StudioApi, generationEventTypes } from "./protocol.js";
|
|
3
|
-
import { Storage } from "unstorage";
|
|
2
|
+
import { AGENT_INSTANCE_HEADER, AgentApi, AgentCapacity, AgentCloseCode, AgentLoad, AgentPermissions, AgentRegisterInput, AgentRegisterResponse, ConfigEdit, ConnectMessagePayload, GenerateInput, GenerateResult, GenerationEvent, GenerationEventPayloads, GenerationEventType, GenerationRun, PublishSnapshotInput, PublishSnapshotResult, RpcClose, RpcConnection, RpcConnector, StudioApi, generationEventTypes } from "./protocol.js";
|
|
4
3
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
5
|
-
|
|
4
|
+
import { Storage } from "unstorage";
|
|
5
|
+
//#region src/operations/api.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Thrown when Studio rejects the agent token itself (401). Retrying cannot help: the token was
|
|
8
8
|
* revoked, or the agent it belonged to was deleted in the Studio UI. Hosts catch this to forget
|
|
@@ -11,13 +11,20 @@ import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
|
11
11
|
export declare class InvalidAgentTokenError extends Error {
|
|
12
12
|
constructor(studioUrl: string, options?: ErrorOptions);
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Thrown when Studio refuses this agent's protocol version (426). Retrying cannot help until the
|
|
16
|
+
* agent is upgraded, so hosts stop instead of reconnecting.
|
|
17
|
+
*/
|
|
18
|
+
export declare class IncompatibleAgentError extends Error {
|
|
19
|
+
constructor(studioUrl: string, detail?: string, options?: ErrorOptions);
|
|
20
|
+
}
|
|
14
21
|
/**
|
|
15
22
|
* Status values returned by Studio's jobs API.
|
|
16
23
|
*/
|
|
17
24
|
type StudioJobStatus = 'queued' | 'running' | 'success' | 'failed' | 'canceled';
|
|
18
|
-
/** How a snapshot's files differ from
|
|
25
|
+
/** How a snapshot's files differ from an earlier snapshot of the same package, relative to `output.path`. */
|
|
19
26
|
type StudioSnapshotChanges = {
|
|
20
|
-
/** The snapshot these changes are measured against, `null`
|
|
27
|
+
/** The snapshot these changes are measured against, `null` when there is none to compare with. */
|
|
21
28
|
base: {
|
|
22
29
|
id: string;
|
|
23
30
|
version: string | null;
|
|
@@ -61,8 +68,10 @@ type StudioSnapshot = {
|
|
|
61
68
|
* ISO timestamp after which Studio may delete the tarball.
|
|
62
69
|
*/
|
|
63
70
|
expiresAt: string;
|
|
64
|
-
/** What changed since the previous snapshot. Absent when Studio or the agent predates it. */
|
|
71
|
+
/** What changed since the previous snapshot on the same agent. Absent when Studio or the agent predates it. */
|
|
65
72
|
changes?: StudioSnapshotChanges;
|
|
73
|
+
/** What differs from the latest snapshot of the CI agent `baseId` names. Absent without a base. */
|
|
74
|
+
branchChanges?: StudioSnapshotChanges;
|
|
66
75
|
};
|
|
67
76
|
/**
|
|
68
77
|
* Job record from `POST /api/jobs` and `GET /api/jobs/{id}`.
|
|
@@ -91,6 +100,10 @@ type StudioJob = {
|
|
|
91
100
|
* Returns as soon as Studio accepts the job (`202`). Poll with {@link waitForJob} until it finishes.
|
|
92
101
|
* Authenticates with the organization CI API key via `x-api-key`.
|
|
93
102
|
*
|
|
103
|
+
* A busy agent, a full queue, or a momentary lack of a live connection (409, 429, 503) retries with
|
|
104
|
+
* exponential backoff and jitter, honoring Studio's `Retry-After` header when it sends one, up to
|
|
105
|
+
* `timeoutMs`. Every other failure, including a missing agent (404), throws immediately.
|
|
106
|
+
*
|
|
94
107
|
* @example Snapshot job
|
|
95
108
|
* ```ts
|
|
96
109
|
* const job = await createJob({
|
|
@@ -104,7 +117,7 @@ type StudioJob = {
|
|
|
104
117
|
* const finished = await waitForJob({ studioUrl, token, id: job.id })
|
|
105
118
|
* ```
|
|
106
119
|
*/
|
|
107
|
-
export declare function createJob({ studioUrl, token, type, agentId, name, version, commit, config }: {
|
|
120
|
+
export declare function createJob({ studioUrl, token, type, agentId, name, version, commit, baseId, config, instanceId, timeoutMs, signal }: {
|
|
108
121
|
studioUrl: string;
|
|
109
122
|
token: string;
|
|
110
123
|
type: 'generation' | 'snapshot';
|
|
@@ -113,7 +126,21 @@ export declare function createJob({ studioUrl, token, type, agentId, name, versi
|
|
|
113
126
|
version?: string;
|
|
114
127
|
/** The commit this snapshot is built from, so the next one can diff against it. */
|
|
115
128
|
commit?: string;
|
|
129
|
+
/** The `id` another CI agent's runs register under, such as the base branch's; this snapshot is also compared with its latest one. */
|
|
130
|
+
baseId?: string;
|
|
116
131
|
config?: Record<string, unknown>;
|
|
132
|
+
/**
|
|
133
|
+
* The agent process to run the job on, the `instanceId` its client connected with. A CI run passes
|
|
134
|
+
* its own, so an overlapping pipeline under the same CI agent never builds its checkout.
|
|
135
|
+
*/
|
|
136
|
+
instanceId?: string;
|
|
137
|
+
/**
|
|
138
|
+
* How long to keep retrying a busy or queue-full response before giving up, in milliseconds.
|
|
139
|
+
*
|
|
140
|
+
* @default 60000
|
|
141
|
+
*/
|
|
142
|
+
timeoutMs?: number;
|
|
143
|
+
signal?: AbortSignal;
|
|
117
144
|
}): Promise<StudioJob>;
|
|
118
145
|
/**
|
|
119
146
|
* Polls `GET /api/jobs/{id}` until the job reaches a terminal status, waiting
|
|
@@ -123,7 +150,7 @@ export declare function createJob({ studioUrl, token, type, agentId, name, versi
|
|
|
123
150
|
* A `failed` job resolves normally. Check `job.status` and `job.error`. Throws only when the
|
|
124
151
|
* deadline passes before Studio finishes.
|
|
125
152
|
*/
|
|
126
|
-
export declare function waitForJob({ studioUrl, token, id, timeoutMs }: {
|
|
153
|
+
export declare function waitForJob({ studioUrl, token, id, timeoutMs, signal }: {
|
|
127
154
|
studioUrl: string;
|
|
128
155
|
token: string;
|
|
129
156
|
id: string;
|
|
@@ -133,6 +160,7 @@ export declare function waitForJob({ studioUrl, token, id, timeoutMs }: {
|
|
|
133
160
|
* @default 60000
|
|
134
161
|
*/
|
|
135
162
|
timeoutMs?: number;
|
|
163
|
+
signal?: AbortSignal;
|
|
136
164
|
}): Promise<StudioJob>;
|
|
137
165
|
/**
|
|
138
166
|
* CI agent returned by {@link createAgent}. The token is issued only once, at creation or reuse.
|
|
@@ -167,7 +195,7 @@ export declare function createAgent({ studioUrl, token, name, machineToken }: {
|
|
|
167
195
|
machineToken: string;
|
|
168
196
|
}): Promise<StudioAgent>;
|
|
169
197
|
//#endregion
|
|
170
|
-
//#region src/StudioSession.d.ts
|
|
198
|
+
//#region src/runtime/StudioSession.d.ts
|
|
171
199
|
type StudioSessionOptions = {
|
|
172
200
|
connector?: RpcConnector;
|
|
173
201
|
token: string;
|
|
@@ -190,7 +218,14 @@ type StudioSessionOptions = {
|
|
|
190
218
|
*/
|
|
191
219
|
permissions?: Partial<AgentPermissions>;
|
|
192
220
|
root?: string;
|
|
221
|
+
/**
|
|
222
|
+
* Maximum reconnect backoff in milliseconds.
|
|
223
|
+
*/
|
|
193
224
|
retryInterval?: number;
|
|
225
|
+
/**
|
|
226
|
+
* Number of consecutive reconnect attempts that already failed.
|
|
227
|
+
*/
|
|
228
|
+
reconnectAttempt?: number;
|
|
194
229
|
/**
|
|
195
230
|
* Milliseconds between keep-alive pings, clamped to `agentDefaults.maxHeartbeatIntervalMs`.
|
|
196
231
|
* Raise it to halve the traffic and database writes a long-lived agent costs, at the price of
|
|
@@ -199,10 +234,16 @@ type StudioSessionOptions = {
|
|
|
199
234
|
*/
|
|
200
235
|
heartbeatInterval?: number;
|
|
201
236
|
/**
|
|
202
|
-
*
|
|
203
|
-
*
|
|
237
|
+
* What this agent process can take on, reported to Studio at registration. Unset fields come from
|
|
238
|
+
* `KUBB_AGENT_MAX_CONCURRENT`.
|
|
239
|
+
*/
|
|
240
|
+
capacity?: Partial<AgentCapacity>;
|
|
241
|
+
/**
|
|
242
|
+
* Names this agent process to Studio, sent at registration and as {@link AGENT_INSTANCE_HEADER}
|
|
243
|
+
* on the socket. `createClient` sets one per process, so a reconnect is the same instance and a
|
|
244
|
+
* restart is a new one. Not meant to be set directly by a host.
|
|
204
245
|
*/
|
|
205
|
-
|
|
246
|
+
instanceId?: string;
|
|
206
247
|
/**
|
|
207
248
|
* Aborting this disconnects the session and stops the reconnect loop. Hosts wire it to their own
|
|
208
249
|
* shutdown: Nitro's `close` hook, or `SIGINT`/`SIGTERM` in the CLI.
|
|
@@ -221,20 +262,14 @@ type StudioSessionOptions = {
|
|
|
221
262
|
* directly by a host.
|
|
222
263
|
*/
|
|
223
264
|
onTokenRejected?: (error: InvalidAgentTokenError) => void;
|
|
224
|
-
/**
|
|
225
|
-
* Sent as `studio:warn` once the host's logger is installed. `createClient` uses it to report a
|
|
226
|
-
* failed registration, which happens before any session has hooks to report through. Not meant
|
|
227
|
-
* to be set directly by a host, and dropped on reconnect so it is reported once.
|
|
228
|
-
*/
|
|
229
|
-
startupWarning?: string;
|
|
230
265
|
};
|
|
231
266
|
//#endregion
|
|
232
|
-
//#region src/client.d.ts
|
|
233
|
-
type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | '
|
|
267
|
+
//#region src/runtime/client.d.ts
|
|
268
|
+
type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | 'reconnectAttempt'> & {
|
|
234
269
|
/**
|
|
235
|
-
* Called once when
|
|
236
|
-
*
|
|
237
|
-
*
|
|
270
|
+
* Called once when the token is rejected during a background reconnect (401: revoked, or the
|
|
271
|
+
* agent was deleted). The client is already stopped by the time this fires, so a host only needs
|
|
272
|
+
* to get a replacement token and start a new client.
|
|
238
273
|
*
|
|
239
274
|
* Never fires for a startup rejection, which `connect()` reports by throwing, nor for an ordinary
|
|
240
275
|
* session expiry or revocation, both of which reconnect on their own.
|
|
@@ -243,12 +278,12 @@ type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | '
|
|
|
243
278
|
};
|
|
244
279
|
type Client = {
|
|
245
280
|
/**
|
|
246
|
-
* Registers with Studio and opens
|
|
247
|
-
*
|
|
281
|
+
* Registers with Studio and opens this process's one socket. Resolves once it is starting: the
|
|
282
|
+
* connection keeps running, and reconnects on its own, until `disconnect` is called.
|
|
248
283
|
*/
|
|
249
284
|
connect: () => Promise<void>;
|
|
250
285
|
/**
|
|
251
|
-
* Closes
|
|
286
|
+
* Closes the socket and stops reconnecting.
|
|
252
287
|
*/
|
|
253
288
|
disconnect: () => void;
|
|
254
289
|
};
|
|
@@ -267,7 +302,7 @@ type Client = {
|
|
|
267
302
|
*/
|
|
268
303
|
export declare function createClient({ onAuthRequired, ...options }: ClientOptions): Client;
|
|
269
304
|
//#endregion
|
|
270
|
-
//#region src/hooks.d.ts
|
|
305
|
+
//#region src/operations/hooks.d.ts
|
|
271
306
|
/**
|
|
272
307
|
* Events a host emits about its Kubb Studio session, as opposed to a generation. `kubb:` stays
|
|
273
308
|
* reserved for generation lifecycle.
|
|
@@ -373,14 +408,14 @@ declare global {
|
|
|
373
408
|
}
|
|
374
409
|
}
|
|
375
410
|
//#endregion
|
|
376
|
-
//#region src/constants.d.ts
|
|
411
|
+
//#region src/operations/constants.d.ts
|
|
377
412
|
/**
|
|
378
413
|
* Hosted Kubb Studio URL. Exported so credential stores can bind tokens to the resolved instance,
|
|
379
414
|
* not whatever default the client would pick on its own.
|
|
380
415
|
*/
|
|
381
416
|
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
382
417
|
//#endregion
|
|
383
|
-
//#region src/machine.d.ts
|
|
418
|
+
//#region src/operations/machine.d.ts
|
|
384
419
|
/**
|
|
385
420
|
* Installs the storage driver the runtime persists to. Call once, before connecting.
|
|
386
421
|
*/
|
|
@@ -396,7 +431,7 @@ export declare function createFileStorage(base: string): Storage;
|
|
|
396
431
|
*/
|
|
397
432
|
export declare function machineTokenFrom(secret: string): string;
|
|
398
433
|
//#endregion
|
|
399
|
-
//#region src/runConnection.d.ts
|
|
434
|
+
//#region src/runtime/runConnection.d.ts
|
|
400
435
|
/**
|
|
401
436
|
* Why a connection ended: the host asked it to stop through its `signal`, or the host declined to
|
|
402
437
|
* replace a rejected token.
|
|
@@ -464,7 +499,7 @@ export declare function runConnection<TCredentials extends {
|
|
|
464
499
|
token: string;
|
|
465
500
|
}>({ credentials, clientOptions, onTokenRejected, signal }: ConnectionOptions<TCredentials>): Promise<ConnectionOutcome>;
|
|
466
501
|
//#endregion
|
|
467
|
-
//#region src/pair.d.ts
|
|
502
|
+
//#region src/operations/pair.d.ts
|
|
468
503
|
/**
|
|
469
504
|
* RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.
|
|
470
505
|
* Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.
|
|
@@ -579,7 +614,7 @@ type PairAgentOptions = StartPairingOptions & {
|
|
|
579
614
|
*/
|
|
580
615
|
export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }: PairAgentOptions): Promise<PairingResult>;
|
|
581
616
|
//#endregion
|
|
582
|
-
//#region src/rpc.d.ts
|
|
617
|
+
//#region src/operations/rpc.d.ts
|
|
583
618
|
/**
|
|
584
619
|
* Opens an authenticated Cap'n Web session to Studio over a WebSocket. Rejects an unencrypted URL
|
|
585
620
|
* before opening the socket, so a bearer token never reaches a plaintext host.
|
|
@@ -592,5 +627,5 @@ export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }:
|
|
|
592
627
|
*/
|
|
593
628
|
export declare const connectWebSocketRpc: RpcConnector;
|
|
594
629
|
//#endregion
|
|
595
|
-
export { type AgentApi, type Client, type ClientOptions, type ConfigEdit, type ConnectMessagePayload, type ConnectionOptions, type GenerateInput, type GenerateResult, type GenerationEvent, type GenerationEventPayloads, type GenerationEventType, type GenerationRun, type PairingAgentType, type PairingResult, type PairingSession, type PublishSnapshotInput, type PublishSnapshotResult, type RpcConnection, type RpcConnector, type StudioAgent, type StudioApi, type StudioConnectedContext, type StudioJob, type StudioJobStatus, type StudioSnapshot, type StudioSnapshotChanges, generationEventTypes };
|
|
630
|
+
export { AGENT_INSTANCE_HEADER, type AgentApi, type AgentCapacity, AgentCloseCode, type AgentLoad, type AgentRegisterInput, type AgentRegisterResponse, type Client, type ClientOptions, type ConfigEdit, type ConnectMessagePayload, type ConnectionOptions, type GenerateInput, type GenerateResult, type GenerationEvent, type GenerationEventPayloads, type GenerationEventType, type GenerationRun, type PairingAgentType, type PairingResult, type PairingSession, type PublishSnapshotInput, type PublishSnapshotResult, type RpcClose, type RpcConnection, type RpcConnector, type StudioAgent, type StudioApi, type StudioConnectedContext, type StudioJob, type StudioJobStatus, type StudioSnapshot, type StudioSnapshotChanges, generationEventTypes };
|
|
596
631
|
//# sourceMappingURL=index.d.ts.map
|