@kubb/studio 5.6.0 → 5.6.1
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 +80 -169
- package/dist/index.cjs +1466 -964
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +112 -406
- package/dist/index.js +1441 -947
- package/dist/index.js.map +1 -1
- package/dist/protocol-P0znFp9w.d.ts +626 -0
- package/dist/protocol.cjs +13 -13
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.ts +2 -628
- package/dist/protocol.js +12 -14
- package/dist/protocol.js.map +1 -1
- package/package.json +7 -12
- package/dist/configFile-dJtYeqX1.cjs +0 -567
- package/dist/configFile-dJtYeqX1.cjs.map +0 -1
- package/dist/configFile-zhp5DQIe.js +0 -566
- package/dist/configFile-zhp5DQIe.js.map +0 -1
- package/dist/resolveConfig-CjF6j-3y.cjs +0 -399
- package/dist/resolveConfig-CjF6j-3y.cjs.map +0 -1
- package/dist/resolveConfig-DOUv_Tid.js +0 -352
- package/dist/resolveConfig-DOUv_Tid.js.map +0 -1
- package/dist/rolldown-runtime-qbf5tadS.cjs +0 -38
- package/dist/snapshotPackage-BFjiRhGd.cjs +0 -177
- package/dist/snapshotPackage-BFjiRhGd.cjs.map +0 -1
- package/dist/snapshotPackage-BwZ8IJX-.js +0 -176
- package/dist/snapshotPackage-BwZ8IJX-.js.map +0 -1
- package/dist/url-DC87bYiU.cjs +0 -19
- package/dist/url-DC87bYiU.cjs.map +0 -1
- package/dist/url-DhFfJpxp.js +0 -14
- package/dist/url-DhFfJpxp.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,424 +1,126 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
-
import {
|
|
3
|
-
import { Storage } from "unstorage";
|
|
2
|
+
import { F as SnapshotUploadMetadata, a as AgentConnectInfo, k as PublishedSnapshot, o as AgentPermissions } from "./protocol-P0znFp9w.js";
|
|
4
3
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
5
|
-
//#region src/
|
|
4
|
+
//#region src/connect.d.ts
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
* revoked, or the agent it belonged to was deleted in the Studio UI. Hosts catch this to forget
|
|
9
|
-
* the stored credential and pair again.
|
|
6
|
+
* Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.
|
|
10
7
|
*/
|
|
11
8
|
export declare class InvalidAgentTokenError extends Error {
|
|
12
|
-
constructor(studioUrl: string
|
|
9
|
+
constructor(studioUrl: string);
|
|
13
10
|
}
|
|
14
11
|
/**
|
|
15
|
-
*
|
|
16
|
-
* agent is upgraded, so hosts stop instead of reconnecting.
|
|
12
|
+
* Studio closed with {@link AgentCloseCode.INCOMPATIBLE}. Only an upgrade helps.
|
|
17
13
|
*/
|
|
18
14
|
export declare class IncompatibleAgentError extends Error {
|
|
19
|
-
constructor(studioUrl
|
|
15
|
+
constructor({ studioUrl, detail }: {
|
|
16
|
+
studioUrl: string;
|
|
17
|
+
detail?: string;
|
|
18
|
+
});
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
* Status values returned by Studio's jobs API.
|
|
23
|
-
*/
|
|
24
|
-
type StudioJobStatus = 'queued' | 'running' | 'success' | 'failed' | 'canceled';
|
|
25
|
-
/** How a snapshot's files differ from an earlier snapshot of the same package, relative to `output.path`. */
|
|
26
|
-
type StudioSnapshotChanges = {
|
|
27
|
-
/** The snapshot these changes are measured against, `null` when there is none to compare with. */
|
|
28
|
-
base: {
|
|
29
|
-
id: string;
|
|
30
|
-
version: string | null;
|
|
31
|
-
/** The commit the base snapshot was built from, when reported. */
|
|
32
|
-
commit?: string;
|
|
33
|
-
createdAt: string;
|
|
34
|
-
} | null;
|
|
35
|
-
added: Array<string>;
|
|
36
|
-
changed: Array<string>;
|
|
37
|
-
removed: Array<string>;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* `StudioSnapshotChanges` against a pull request's base branch. `baseFound` tells apart the two
|
|
41
|
-
* reasons `base` can be `null`: `false` when no CI agent is registered for the branch yet (the
|
|
42
|
-
* workflow has never run there), `true` when that agent exists but has no snapshot of this package
|
|
43
|
-
* to compare with.
|
|
44
|
-
*/
|
|
45
|
-
type StudioBranchSnapshotChanges = StudioSnapshotChanges & {
|
|
46
|
-
baseFound: boolean;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Package view returned on a successful snapshot job from Studio.
|
|
50
|
-
*/
|
|
51
|
-
type StudioSnapshot = {
|
|
52
|
-
/**
|
|
53
|
-
* Immutable snapshot id.
|
|
54
|
-
*/
|
|
55
|
-
id: string;
|
|
56
|
-
/**
|
|
57
|
-
* npm package name, or `null` when Studio stored none.
|
|
58
|
-
*/
|
|
59
|
-
name: string | null;
|
|
60
|
-
/**
|
|
61
|
-
* npm package version, or `null` when Studio stored none.
|
|
62
|
-
*/
|
|
63
|
-
version: string | null;
|
|
64
|
-
/**
|
|
65
|
-
* Subresource integrity hash for the tarball, or `null` when unavailable.
|
|
66
|
-
*/
|
|
67
|
-
integrity: string | null;
|
|
68
|
-
/**
|
|
69
|
-
* Preferable download path, often the readable `/packages/{agentSlug}/{name}.tgz` form.
|
|
70
|
-
*/
|
|
71
|
-
url: string;
|
|
72
|
-
/**
|
|
73
|
-
* Stable download path keyed by snapshot id.
|
|
74
|
-
*/
|
|
75
|
-
snapshotIdUrl: string;
|
|
76
|
-
/**
|
|
77
|
-
* ISO timestamp after which Studio may delete the tarball.
|
|
78
|
-
*/
|
|
79
|
-
expiresAt: string;
|
|
80
|
-
/** What changed since the previous snapshot on the same agent. Absent when Studio or the agent predates it. */
|
|
81
|
-
changes?: StudioSnapshotChanges;
|
|
82
|
-
/** What differs from the latest snapshot of the CI agent `baseId` names. Absent without a base. */
|
|
83
|
-
branchChanges?: StudioBranchSnapshotChanges;
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Job record from `POST /api/jobs` and `GET /api/jobs/{id}`.
|
|
87
|
-
*/
|
|
88
|
-
type StudioJob = {
|
|
89
|
-
/**
|
|
90
|
-
* Job id returned by Studio when the job was queued.
|
|
91
|
-
*/
|
|
92
|
-
id: string;
|
|
93
|
-
/**
|
|
94
|
-
* Current status. Poll until `success`, `failed`, or `canceled`.
|
|
95
|
-
*/
|
|
96
|
-
status: StudioJobStatus;
|
|
97
|
-
/**
|
|
98
|
-
* Failure message when `status` is `failed`.
|
|
99
|
-
*/
|
|
100
|
-
error?: string;
|
|
101
|
-
/**
|
|
102
|
-
* Package view when a snapshot job finished successfully.
|
|
103
|
-
*/
|
|
104
|
-
snapshot?: StudioSnapshot;
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Queues a generation or snapshot job on Studio (`POST /api/jobs`).
|
|
108
|
-
*
|
|
109
|
-
* Returns as soon as Studio accepts the job (`202`). Poll with {@link waitForJob} until it finishes.
|
|
110
|
-
* Authenticates with the organization CI API key via `x-api-key`.
|
|
111
|
-
*
|
|
112
|
-
* A busy agent, a full queue, or a momentary lack of a live connection (409, 429, 503) retries with
|
|
113
|
-
* exponential backoff and jitter, honoring Studio's `Retry-After` header when it sends one, up to
|
|
114
|
-
* `timeoutMs`. Every other failure, including a missing agent (404), throws immediately.
|
|
115
|
-
*
|
|
116
|
-
* @example Snapshot job
|
|
117
|
-
* ```ts
|
|
118
|
-
* const job = await createJob({
|
|
119
|
-
* studioUrl: 'https://kubb.studio',
|
|
120
|
-
* token: process.env.KUBB_TOKEN!,
|
|
121
|
-
* type: 'snapshot',
|
|
122
|
-
* agentId: agent.id,
|
|
123
|
-
* name: '@kubb/demo',
|
|
124
|
-
* version: '1.0.0',
|
|
125
|
-
* })
|
|
126
|
-
* const finished = await waitForJob({ studioUrl, token, id: job.id })
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export declare function createJob({ studioUrl, token, type, agentId, name, version, commit, baseId, config, instanceId, timeoutMs, signal }: {
|
|
130
|
-
studioUrl: string;
|
|
131
|
-
token: string;
|
|
132
|
-
type: 'generation' | 'snapshot';
|
|
133
|
-
agentId: string;
|
|
134
|
-
name?: string;
|
|
135
|
-
version?: string;
|
|
136
|
-
/** The commit this snapshot is built from, so the next one can diff against it. */
|
|
137
|
-
commit?: string;
|
|
138
|
-
/** The `id` another CI agent's runs register under, such as the base branch's; this snapshot is also compared with its latest one. */
|
|
139
|
-
baseId?: string;
|
|
140
|
-
config?: Record<string, unknown>;
|
|
141
|
-
/**
|
|
142
|
-
* The agent process to run the job on, the `instanceId` its client connected with. A CI run passes
|
|
143
|
-
* its own, so an overlapping pipeline under the same CI agent never builds its checkout.
|
|
144
|
-
*/
|
|
145
|
-
instanceId?: string;
|
|
146
|
-
/**
|
|
147
|
-
* How long to keep retrying a busy or queue-full response before giving up, in milliseconds.
|
|
148
|
-
*
|
|
149
|
-
* @default 60000
|
|
150
|
-
*/
|
|
151
|
-
timeoutMs?: number;
|
|
152
|
-
signal?: AbortSignal;
|
|
153
|
-
}): Promise<StudioJob>;
|
|
154
|
-
/**
|
|
155
|
-
* Polls `GET /api/jobs/{id}` until the job reaches a terminal status, waiting
|
|
156
|
-
* {@link INITIAL_POLL_DELAY_MS} first and doubling up to {@link MAX_POLL_INTERVAL_MS} so a long
|
|
157
|
-
* job stays inside the API key's rate limit.
|
|
158
|
-
*
|
|
159
|
-
* A `failed` job resolves normally. Check `job.status` and `job.error`. Throws only when the
|
|
160
|
-
* deadline passes before Studio finishes.
|
|
161
|
-
*/
|
|
162
|
-
export declare function waitForJob({ studioUrl, token, id, timeoutMs, signal }: {
|
|
163
|
-
studioUrl: string;
|
|
164
|
-
token: string;
|
|
165
|
-
id: string;
|
|
166
|
-
/**
|
|
167
|
-
* How long to keep polling before throwing, in milliseconds.
|
|
168
|
-
*
|
|
169
|
-
* @default 60000
|
|
170
|
-
*/
|
|
171
|
-
timeoutMs?: number;
|
|
172
|
-
signal?: AbortSignal;
|
|
173
|
-
}): Promise<StudioJob>;
|
|
174
|
-
/**
|
|
175
|
-
* CI agent returned by {@link createAgent}. The token is issued only once, at creation or reuse.
|
|
176
|
-
*/
|
|
177
|
-
type StudioAgent = {
|
|
178
|
-
/**
|
|
179
|
-
* Agent id, passed to {@link createJob} as `agentId`.
|
|
180
|
-
*/
|
|
181
|
-
id: string;
|
|
182
|
-
/**
|
|
183
|
-
* Human-readable slug, used to build the readable snapshot URL and the agent's Studio page.
|
|
184
|
-
*/
|
|
185
|
-
slug: string;
|
|
186
|
-
/**
|
|
187
|
-
* Agent display name.
|
|
188
|
-
*/
|
|
189
|
-
name: string;
|
|
190
|
-
/**
|
|
191
|
-
* Bearer token for the WebSocket agent session. Mask it before logging.
|
|
192
|
-
*/
|
|
193
|
-
token: string;
|
|
194
|
-
};
|
|
195
|
-
/**
|
|
196
|
-
* Creates or reuses a CI agent (`POST /api/agents`), keyed by `(organization, machineToken)`.
|
|
197
|
-
* Authenticates via `x-api-key`. Reusing the same `machineToken` reuses the same agent instead of
|
|
198
|
-
* consuming a new one from the organization's agent limit.
|
|
199
|
-
*/
|
|
200
|
-
export declare function createAgent({ studioUrl, token, name, machineToken }: {
|
|
201
|
-
studioUrl: string;
|
|
202
|
-
token: string;
|
|
203
|
-
name: string;
|
|
204
|
-
machineToken: string;
|
|
205
|
-
}): Promise<StudioAgent>;
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/runtime/StudioSession.d.ts
|
|
208
|
-
type StudioSessionOptions = {
|
|
209
|
-
connector?: RpcConnector;
|
|
210
|
-
token: string;
|
|
211
|
-
studioUrl?: string;
|
|
212
|
-
configPath: string;
|
|
213
|
-
/**
|
|
214
|
-
* Loads the on-disk Kubb config. Injected so each host resolves config its own way: the Docker
|
|
215
|
-
* agent from an explicit `KUBB_AGENT_CONFIG` path, the CLI through the same discovery
|
|
216
|
-
* `kubb generate` uses.
|
|
217
|
-
*/
|
|
218
|
-
loadConfig: () => Promise<Config>;
|
|
219
|
-
/**
|
|
220
|
-
* The runtime's own version, reported to Studio next to the `kubb` version.
|
|
221
|
-
*/
|
|
222
|
-
version: string;
|
|
223
|
-
/**
|
|
224
|
-
* What Studio may do in this project, off unless the host grants it. A sandbox session narrows
|
|
225
|
-
* them further: it never writes to disk and never edits a config file, and it always generates
|
|
226
|
-
* from the spec Studio sends.
|
|
227
|
-
*/
|
|
228
|
-
permissions?: Partial<AgentPermissions>;
|
|
229
|
-
root?: string;
|
|
230
|
-
/**
|
|
231
|
-
* Maximum reconnect backoff in milliseconds.
|
|
232
|
-
*/
|
|
233
|
-
retryInterval?: number;
|
|
234
|
-
/**
|
|
235
|
-
* Milliseconds between keep-alive pings, clamped to `agentDefaults.maxHeartbeatIntervalMs`.
|
|
236
|
-
* Raise it to halve the traffic and database writes a long-lived agent costs, at the price of
|
|
237
|
-
* Studio taking that much longer to notice the agent has gone. Lower it in development to see
|
|
238
|
-
* connection state move immediately.
|
|
239
|
-
*/
|
|
240
|
-
heartbeatInterval?: number;
|
|
241
|
-
/**
|
|
242
|
-
* What this agent process can take on, reported to Studio at registration. Unset fields come from
|
|
243
|
-
* `KUBB_AGENT_MAX_CONCURRENT`.
|
|
244
|
-
*/
|
|
245
|
-
capacity?: Partial<AgentCapacity>;
|
|
246
|
-
/**
|
|
247
|
-
* Names this agent process to Studio, sent at registration and as {@link AGENT_INSTANCE_HEADER}
|
|
248
|
-
* on the socket. `runConnection` sets one per process, so a reconnect is the same instance and a
|
|
249
|
-
* restart is a new one. Not meant to be set directly by a host.
|
|
250
|
-
*/
|
|
251
|
-
instanceId?: string;
|
|
252
|
-
/**
|
|
253
|
-
* Aborting this disconnects the session and stops the reconnect loop. Hosts wire it to their own
|
|
254
|
-
* shutdown signal, usually `SIGINT` or `SIGTERM`.
|
|
255
|
-
*/
|
|
256
|
-
signal?: AbortSignal;
|
|
257
|
-
/**
|
|
258
|
-
* Installs listeners on the session's event emitter, which carries both the session events and
|
|
259
|
-
* the generations it runs. Left out, the runtime prints nothing, which is what a library should
|
|
260
|
-
* default to.
|
|
261
|
-
*/
|
|
262
|
-
installLogger?: (hooks: Hookable<KubbHooks>) => void | Promise<void>;
|
|
263
|
-
};
|
|
264
|
-
//#endregion
|
|
265
|
-
//#region src/runtime/client.d.ts
|
|
266
|
-
type ClientOptions = Omit<StudioSessionOptions, 'signal'> & {
|
|
267
|
-
/** Called once when a background reconnect rejects the credential. */
|
|
268
|
-
onAuthRequired?: (error: InvalidAgentTokenError) => void;
|
|
269
|
-
};
|
|
270
|
-
type Client = {
|
|
271
|
-
connect: () => Promise<void>;
|
|
272
|
-
disconnect: () => void;
|
|
273
|
-
};
|
|
274
|
-
/** Compatibility facade over the shared connection loop. */
|
|
275
|
-
export declare function createClient({ onAuthRequired, ...options }: ClientOptions): Client;
|
|
276
|
-
//#endregion
|
|
277
|
-
//#region src/operations/hooks.d.ts
|
|
278
|
-
type StudioConnectedContext = {
|
|
279
|
-
/**
|
|
280
|
-
* The Studio instance this session attached to.
|
|
281
|
-
*/
|
|
20
|
+
type StudioConnectedContext = AgentConnectInfo & {
|
|
282
21
|
url: string;
|
|
283
22
|
/**
|
|
284
|
-
*
|
|
23
|
+
* The Studio, runtime, and host versions, so a host can show a mismatch.
|
|
285
24
|
*/
|
|
286
25
|
versions: {
|
|
287
|
-
|
|
288
|
-
* The Studio instance's own version, when it sent one.
|
|
289
|
-
*/
|
|
290
|
-
studio?: string;
|
|
291
|
-
/**
|
|
292
|
-
* The version of the runtime that connected.
|
|
293
|
-
*/
|
|
26
|
+
studio: string;
|
|
294
27
|
kubb: string;
|
|
295
|
-
/**
|
|
296
|
-
* The version of the host itself, such as the `kubb` CLI or the agent image.
|
|
297
|
-
*/
|
|
298
28
|
agent: string;
|
|
299
29
|
};
|
|
300
|
-
/**
|
|
301
|
-
* This agent's slug, refreshed on every connect so a rename in Studio shows up without a
|
|
302
|
-
* re-pair. Absent when Studio predates the field.
|
|
303
|
-
*/
|
|
304
|
-
agentSlug?: string;
|
|
305
|
-
/**
|
|
306
|
-
* This agent's organization slug, absent for a sandbox or global agent, which has none, or when
|
|
307
|
-
* Studio predates the field.
|
|
308
|
-
*/
|
|
309
|
-
organizationSlug?: string;
|
|
310
30
|
};
|
|
311
|
-
/**
|
|
312
|
-
* Events a host emits about its Kubb Studio session, as opposed to a generation. `kubb:` stays
|
|
313
|
-
* reserved for generation lifecycle.
|
|
314
|
-
*/
|
|
315
31
|
declare global {
|
|
316
32
|
namespace Kubb {
|
|
317
33
|
interface KubbHooksRegistry {
|
|
318
34
|
/**
|
|
319
|
-
*
|
|
35
|
+
* Fired after each handshake, including reconnects.
|
|
320
36
|
*/
|
|
321
|
-
'studio:connecting': [ctx: {
|
|
322
|
-
url: string;
|
|
323
|
-
}];
|
|
324
37
|
'studio:connected': [ctx: StudioConnectedContext];
|
|
325
|
-
/**
|
|
326
|
-
* Fired once Studio confirms the `agent:connect` handshake was received and the session is
|
|
327
|
-
* fully registered. Distinct from `studio:connected`, which only means the socket is open.
|
|
328
|
-
*/
|
|
329
|
-
'studio:ready': [ctx: Record<string, never>];
|
|
330
|
-
/**
|
|
331
|
-
* Why Studio ended the session.
|
|
332
|
-
*/
|
|
333
38
|
'studio:disconnected': [ctx: {
|
|
39
|
+
code: number;
|
|
334
40
|
reason: string;
|
|
335
41
|
}];
|
|
336
|
-
/**
|
|
337
|
-
* Milliseconds until the next connection attempt.
|
|
338
|
-
*/
|
|
339
42
|
'studio:reconnecting': [ctx: {
|
|
340
43
|
delayMs: number;
|
|
341
44
|
}];
|
|
342
45
|
/**
|
|
343
|
-
*
|
|
46
|
+
* A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.
|
|
344
47
|
*/
|
|
345
|
-
'studio:command
|
|
346
|
-
command:
|
|
48
|
+
'studio:command': [ctx: {
|
|
49
|
+
command: 'generate' | 'saveConfig' | 'readFiles';
|
|
50
|
+
info: string;
|
|
347
51
|
}];
|
|
348
52
|
/**
|
|
349
|
-
*
|
|
350
|
-
* `applied 2/3 edits to kubb.config.ts`.
|
|
351
|
-
*/
|
|
352
|
-
'studio:command:end': [ctx: {
|
|
353
|
-
command: string;
|
|
354
|
-
info?: string;
|
|
355
|
-
}];
|
|
356
|
-
/**
|
|
357
|
-
* What was refused or ignored, and the missing permission if that is why, so the host can
|
|
358
|
-
* append its own remedy.
|
|
53
|
+
* A refused or ignored request, with the missing permission so the host can add a remedy.
|
|
359
54
|
*/
|
|
360
55
|
'studio:warn': [ctx: {
|
|
361
56
|
message: string;
|
|
362
57
|
permission?: keyof AgentPermissions;
|
|
363
58
|
}];
|
|
364
|
-
/**
|
|
365
|
-
* The failure, for the host's own output. One Studio needs to hear about goes over the
|
|
366
|
-
* socket through the `kubb:error` generation hook instead.
|
|
367
|
-
*/
|
|
368
59
|
'studio:error': [ctx: {
|
|
369
60
|
error: Error;
|
|
370
61
|
}];
|
|
371
62
|
}
|
|
372
63
|
}
|
|
373
64
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
* not whatever default the client would pick on its own.
|
|
379
|
-
*/
|
|
380
|
-
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
381
|
-
//#endregion
|
|
382
|
-
//#region src/operations/machine.d.ts
|
|
383
|
-
/**
|
|
384
|
-
* Installs the storage driver the runtime persists to. Call once, before connecting.
|
|
385
|
-
*/
|
|
386
|
-
export declare function setStorage(next: Storage): void;
|
|
387
|
-
/**
|
|
388
|
-
* A storage backed by files under `base`, so the machine secret and the last Studio config
|
|
389
|
-
* survive a restart. Repeated pairings of one machine depend on that secret staying put.
|
|
390
|
-
*/
|
|
391
|
-
export declare function createFileStorage(base: string): Storage;
|
|
392
|
-
/**
|
|
393
|
-
* Hashes a stable secret into the machine token Studio expects, so a host can derive one from its
|
|
394
|
-
* own identity without duplicating `getMachineToken`'s SHA-256 step.
|
|
395
|
-
*/
|
|
396
|
-
export declare function machineTokenFrom(secret: string): string;
|
|
397
|
-
//#endregion
|
|
398
|
-
//#region src/runtime/runConnection.d.ts
|
|
399
|
-
type ConnectionOutcome = 'shutdown' | 'stopped';
|
|
400
|
-
type TokenRejection<TCredentials> = {
|
|
401
|
-
error: InvalidAgentTokenError;
|
|
402
|
-
credentials: TCredentials;
|
|
403
|
-
/** Whether this credential already served a ready session. */
|
|
404
|
-
live: boolean;
|
|
405
|
-
};
|
|
406
|
-
type ConnectionOptions<TCredentials extends {
|
|
65
|
+
type ConnectAgentOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* The agent's bearer token, from {@link pairAgent}.
|
|
68
|
+
*/
|
|
407
69
|
token: string;
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
70
|
+
studioUrl?: string;
|
|
71
|
+
/**
|
|
72
|
+
* The config path shown in Studio, relative to `root` unless absolute.
|
|
73
|
+
*/
|
|
74
|
+
configPath: string;
|
|
75
|
+
/**
|
|
76
|
+
* Called for every handshake and every generation, so edits on disk show up.
|
|
77
|
+
*/
|
|
78
|
+
loadConfig: () => Promise<Config>;
|
|
79
|
+
/**
|
|
80
|
+
* The host's own version, reported to Studio next to the runtime's.
|
|
81
|
+
*/
|
|
82
|
+
version: string;
|
|
83
|
+
/**
|
|
84
|
+
* The project root generation runs against.
|
|
85
|
+
* @default process.cwd()
|
|
86
|
+
*/
|
|
87
|
+
root?: string;
|
|
88
|
+
/**
|
|
89
|
+
* What Studio may do in this project. Every permission is off unless granted.
|
|
90
|
+
*/
|
|
91
|
+
permissions?: Partial<AgentPermissions>;
|
|
92
|
+
/**
|
|
93
|
+
* Receives the `studio:*` hooks and the `kubb:*` hooks of every generation.
|
|
94
|
+
*/
|
|
95
|
+
hooks?: Hookable<KubbHooks>;
|
|
412
96
|
signal?: AbortSignal;
|
|
413
|
-
/**
|
|
414
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Longest wait between reconnect attempts, in milliseconds.
|
|
99
|
+
* @default 30000
|
|
100
|
+
*/
|
|
101
|
+
maxRetryDelay?: number;
|
|
102
|
+
/**
|
|
103
|
+
* Milliseconds between keep-alive pings, at most 60000.
|
|
104
|
+
* @default 30000
|
|
105
|
+
*/
|
|
106
|
+
heartbeatInterval?: number;
|
|
415
107
|
};
|
|
416
|
-
/**
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Connects this project to Kubb Studio and serves its commands until `signal` aborts. Reconnects
|
|
110
|
+
* with jittered backoff, and resolves when another process of the agent takes over. Rejects with
|
|
111
|
+
* {@link InvalidAgentTokenError} so the host can pair again, or {@link IncompatibleAgentError}.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const hooks = new Hookable<KubbHooks>()
|
|
116
|
+
* hooks.hook('studio:connected', ({ agentSlug }) => console.log(`Connected as ${agentSlug}`))
|
|
117
|
+
*
|
|
118
|
+
* await connectAgent({ token, configPath: 'kubb.config.ts', loadConfig, version: '1.0.0', hooks, signal })
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function connectAgent(options: ConnectAgentOptions): Promise<void>;
|
|
420
122
|
//#endregion
|
|
421
|
-
//#region src/
|
|
123
|
+
//#region src/pair.d.ts
|
|
422
124
|
/**
|
|
423
125
|
* RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.
|
|
424
126
|
* Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.
|
|
@@ -485,38 +187,15 @@ type StartPairingOptions = {
|
|
|
485
187
|
name: string;
|
|
486
188
|
hostname: string;
|
|
487
189
|
/**
|
|
488
|
-
*
|
|
190
|
+
* A stable secret the host keeps for this machine. Studio stores its hash against the agent, so
|
|
191
|
+
* the same machine pairing again rotates one agent's token instead of creating a second agent.
|
|
489
192
|
*/
|
|
490
|
-
|
|
491
|
-
};
|
|
492
|
-
/**
|
|
493
|
-
* Asks Studio for a pairing code. The machine token travels with the request and is stored against
|
|
494
|
-
* the code, so approval knows which machine it is pairing: the same machine pairing twice rotates
|
|
495
|
-
* one agent's token instead of creating a second agent.
|
|
496
|
-
*/
|
|
497
|
-
export declare function startPairing({ studioUrl, type, name, hostname, signal }: StartPairingOptions): Promise<PairingSession>;
|
|
498
|
-
type PollOptions = {
|
|
499
|
-
studioUrl?: string;
|
|
500
|
-
session: PairingSession;
|
|
193
|
+
machineId: string;
|
|
501
194
|
/**
|
|
502
|
-
* Aborting this
|
|
503
|
-
* lands between polls or during the wait for the next one.
|
|
195
|
+
* Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.
|
|
504
196
|
*/
|
|
505
197
|
signal?: AbortSignal;
|
|
506
|
-
/** Called when a poll could not reach Studio. Polling carries on. */
|
|
507
|
-
onRetry?: (error: Error) => void;
|
|
508
198
|
};
|
|
509
|
-
/**
|
|
510
|
-
* Polls until the user approves or denies, honoring the server's `slow_down` back-off.
|
|
511
|
-
*
|
|
512
|
-
* Studio's own endpoint is used rather than the auth layer's `/device/token`, because an approved
|
|
513
|
-
* Kubb pairing is worth an agent bearer token, not a user session.
|
|
514
|
-
*
|
|
515
|
-
* @throws {PairingExpiredError} when the code expires before anyone approves it.
|
|
516
|
-
* @throws {PairingDeniedError} when the pairing is denied in the browser.
|
|
517
|
-
* @throws {PairingCanceledError} when `signal` aborts.
|
|
518
|
-
*/
|
|
519
|
-
export declare function pollForPairingToken({ studioUrl, session, signal, onRetry }: PollOptions): Promise<PairingResult>;
|
|
520
199
|
type PairAgentOptions = StartPairingOptions & {
|
|
521
200
|
/** Shows the code to whoever approves it. Called again for each fresh code. */
|
|
522
201
|
onCode: (session: PairingSession, attempt: number) => void | Promise<void>;
|
|
@@ -533,18 +212,45 @@ type PairAgentOptions = StartPairingOptions & {
|
|
|
533
212
|
*/
|
|
534
213
|
export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }: PairAgentOptions): Promise<PairingResult>;
|
|
535
214
|
//#endregion
|
|
536
|
-
//#region src/
|
|
215
|
+
//#region src/snapshot.d.ts
|
|
216
|
+
type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDependencies'> & {
|
|
217
|
+
studioUrl?: string;
|
|
218
|
+
/**
|
|
219
|
+
* Organization CI API key, sent as `x-api-key`.
|
|
220
|
+
*/
|
|
221
|
+
apiKey: string;
|
|
222
|
+
/**
|
|
223
|
+
* The project's Kubb config. Like `kubb generate`, it writes to `output.path`, then runs the
|
|
224
|
+
* formatter, the linter, and `output.postGenerate`.
|
|
225
|
+
*/
|
|
226
|
+
config: Config;
|
|
227
|
+
hooks?: Hookable<KubbHooks>;
|
|
228
|
+
signal?: AbortSignal;
|
|
229
|
+
};
|
|
537
230
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
231
|
+
* Generates the project, packs it as an npm tarball, and publishes it to Studio in one
|
|
232
|
+
* `POST /api/snapshots` request.
|
|
540
233
|
*
|
|
541
234
|
* @example
|
|
542
235
|
* ```ts
|
|
543
|
-
* const
|
|
544
|
-
*
|
|
236
|
+
* const snapshot = await createSnapshot({
|
|
237
|
+
* apiKey: process.env.KUBB_TOKEN!,
|
|
238
|
+
* config,
|
|
239
|
+
* id: 'gh:123:pr-4',
|
|
240
|
+
* name: 'acme/api#4',
|
|
241
|
+
* packageName: '@acme/api',
|
|
242
|
+
* version: '1.0.0',
|
|
243
|
+
* })
|
|
244
|
+
* console.log(snapshot.url, snapshot.changes)
|
|
545
245
|
* ```
|
|
546
246
|
*/
|
|
547
|
-
export declare
|
|
247
|
+
export declare function createSnapshot({ studioUrl, apiKey, config, hooks, signal, ...metadata }: CreateSnapshotOptions): Promise<PublishedSnapshot>;
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/url.d.ts
|
|
250
|
+
/**
|
|
251
|
+
* Hosted Kubb Studio URL, used when a host passes none.
|
|
252
|
+
*/
|
|
253
|
+
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
548
254
|
//#endregion
|
|
549
|
-
export
|
|
255
|
+
export type { ConnectAgentOptions, StudioConnectedContext };
|
|
550
256
|
//# sourceMappingURL=index.d.ts.map
|