@kubb/studio 5.5.6 → 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/dist/index.d.ts CHANGED
@@ -1,432 +1,126 @@
1
1
  import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
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";
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/operations/api.d.ts
4
+ //#region src/connect.d.ts
6
5
  /**
7
- * Thrown when Studio rejects the agent token itself (401). Retrying cannot help: the token was
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, options?: ErrorOptions);
9
+ constructor(studioUrl: string);
13
10
  }
14
11
  /**
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.
12
+ * Studio closed with {@link AgentCloseCode.INCOMPATIBLE}. Only an upgrade helps.
17
13
  */
18
14
  export declare class IncompatibleAgentError extends Error {
19
- constructor(studioUrl: string, detail?: string, options?: ErrorOptions);
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
- */
20
+ type StudioConnectedContext = AgentConnectInfo & {
71
21
  url: string;
72
22
  /**
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`.
23
+ * The Studio, runtime, and host versions, so a host can show a mismatch.
99
24
  */
100
- error?: string;
101
- /**
102
- * Package view when a snapshot job finished successfully.
103
- */
104
- snapshot?: StudioSnapshot;
25
+ versions: {
26
+ studio: string;
27
+ kubb: string;
28
+ agent: string;
29
+ };
105
30
  };
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;
31
+ declare global {
32
+ namespace Kubb {
33
+ interface KubbHooksRegistry {
34
+ /**
35
+ * Fired after each handshake, including reconnects.
36
+ */
37
+ 'studio:connected': [ctx: StudioConnectedContext];
38
+ 'studio:disconnected': [ctx: {
39
+ code: number;
40
+ reason: string;
41
+ }];
42
+ 'studio:reconnecting': [ctx: {
43
+ delayMs: number;
44
+ }];
45
+ /**
46
+ * A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.
47
+ */
48
+ 'studio:command': [ctx: {
49
+ command: 'generate' | 'saveConfig' | 'readFiles';
50
+ info: string;
51
+ }];
52
+ /**
53
+ * A refused or ignored request, with the missing permission so the host can add a remedy.
54
+ */
55
+ 'studio:warn': [ctx: {
56
+ message: string;
57
+ permission?: keyof AgentPermissions;
58
+ }];
59
+ 'studio:error': [ctx: {
60
+ error: Error;
61
+ }];
62
+ }
63
+ }
64
+ }
65
+ type ConnectAgentOptions = {
146
66
  /**
147
- * How long to keep retrying a busy or queue-full response before giving up, in milliseconds.
148
- *
149
- * @default 60000
67
+ * The agent's bearer token, from {@link pairAgent}.
150
68
  */
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
69
  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;
70
+ studioUrl?: string;
190
71
  /**
191
- * Bearer token for the WebSocket agent session. Mask it before logging.
72
+ * The config path shown in Studio, relative to `root` unless absolute.
192
73
  */
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
74
  configPath: string;
213
75
  /**
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.
76
+ * Called for every handshake and every generation, so edits on disk show up.
217
77
  */
218
78
  loadConfig: () => Promise<Config>;
219
79
  /**
220
- * The runtime's own version, reported to Studio next to the `kubb` version.
80
+ * The host's own version, reported to Studio next to the runtime's.
221
81
  */
222
82
  version: string;
223
83
  /**
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.
84
+ * The project root generation runs against.
85
+ * @default process.cwd()
227
86
  */
228
- permissions?: Partial<AgentPermissions>;
229
87
  root?: string;
230
88
  /**
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.
89
+ * What Studio may do in this project. Every permission is off unless granted.
239
90
  */
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;
91
+ permissions?: Partial<AgentPermissions>;
252
92
  /**
253
- * Aborting this disconnects the session and stops the reconnect loop. Hosts wire it to their own
254
- * shutdown signal, usually `SIGINT` or `SIGTERM`.
93
+ * Receives the `studio:*` hooks and the `kubb:*` hooks of every generation.
255
94
  */
95
+ hooks?: Hookable<KubbHooks>;
256
96
  signal?: AbortSignal;
257
97
  /**
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
- /**
279
- * Events a host emits about its Kubb Studio session, as opposed to a generation. `kubb:` stays
280
- * reserved for generation lifecycle.
281
- */
282
- type StudioConnectingContext = {
283
- /**
284
- * The Studio instance this session is opening against.
285
- */
286
- url: string;
287
- };
288
- type StudioConnectedContext = {
289
- /**
290
- * The Studio instance this session attached to.
291
- */
292
- url: string;
293
- /**
294
- * Both sides of the connection, so a host can print them and make a mismatch visible.
295
- */
296
- versions: {
297
- /**
298
- * The Studio instance's own version, when it sent one.
299
- */
300
- studio?: string;
301
- /**
302
- * The version of the runtime that connected.
303
- */
304
- kubb: string;
305
- /**
306
- * The version of the host itself, such as the `kubb` CLI or the agent image.
307
- */
308
- agent: string;
309
- };
310
- /**
311
- * This agent's slug, refreshed on every connect so a rename in Studio shows up without a
312
- * re-pair. Absent when Studio predates the field.
313
- */
314
- agentSlug?: string;
315
- /**
316
- * This agent's organization slug, absent for a sandbox or global agent, which has none, or when
317
- * Studio predates the field.
98
+ * Longest wait between reconnect attempts, in milliseconds.
99
+ * @default 30000
318
100
  */
319
- organizationSlug?: string;
320
- };
321
- /**
322
- * Fired once Studio confirms the `agent:connect` handshake was received and the session is fully
323
- * registered. Distinct from `studio:connected`, which only means the socket is open.
324
- */
325
- type StudioReadyContext = Record<string, never>;
326
- type StudioDisconnectedContext = {
327
- /**
328
- * Why Studio ended the session.
329
- */
330
- reason: string;
331
- };
332
- type StudioReconnectingContext = {
333
- /** Milliseconds until the next connection attempt. */
334
- delayMs: number;
335
- };
336
- type StudioCommandStartContext = {
337
- /**
338
- * The command Studio sent, without its `studio:` prefix: `generate`, `connect` or `save`.
339
- */
340
- command: string;
341
- };
342
- type StudioCommandEndContext = {
343
- /**
344
- * The command that finished, without its `studio:` prefix.
345
- */
346
- command: string;
101
+ maxRetryDelay?: number;
347
102
  /**
348
- * What the command did, when there is something to report: `applied 2/3 edits to kubb.config.ts`.
103
+ * Milliseconds between keep-alive pings, at most 60000.
104
+ * @default 30000
349
105
  */
350
- info?: string;
351
- };
352
- type StudioWarnContext = {
353
- /**
354
- * What was refused or ignored.
355
- */
356
- message: string;
357
- /** The missing permission, if that is why, so the host can append its own remedy. */
358
- permission?: keyof AgentPermissions;
359
- };
360
- type StudioErrorContext = {
361
- /**
362
- * The failure, for the host's own output. One Studio needs to hear about goes over the socket
363
- * through the `kubb:error` generation hook instead.
364
- */
365
- error: Error;
106
+ heartbeatInterval?: number;
366
107
  };
367
- declare global {
368
- namespace Kubb {
369
- interface KubbHooksRegistry {
370
- 'studio:connecting': [ctx: StudioConnectingContext];
371
- 'studio:connected': [ctx: StudioConnectedContext];
372
- 'studio:ready': [ctx: StudioReadyContext];
373
- 'studio:disconnected': [ctx: StudioDisconnectedContext];
374
- 'studio:reconnecting': [ctx: StudioReconnectingContext];
375
- 'studio:command:start': [ctx: StudioCommandStartContext];
376
- 'studio:command:end': [ctx: StudioCommandEndContext];
377
- 'studio:warn': [ctx: StudioWarnContext];
378
- 'studio:error': [ctx: StudioErrorContext];
379
- }
380
- }
381
- }
382
- //#endregion
383
- //#region src/operations/constants.d.ts
384
- /**
385
- * Hosted Kubb Studio URL. Exported so credential stores can bind tokens to the resolved instance,
386
- * not whatever default the client would pick on its own.
387
- */
388
- export declare const defaultStudioUrl = "https://kubb.studio";
389
- //#endregion
390
- //#region src/operations/machine.d.ts
391
- /**
392
- * Installs the storage driver the runtime persists to. Call once, before connecting.
393
- */
394
- export declare function setStorage(next: Storage): void;
395
108
  /**
396
- * A storage backed by files under `base`, so the machine secret and the last Studio config
397
- * survive a restart. Repeated pairings of one machine depend on that secret staying put.
398
- */
399
- export declare function createFileStorage(base: string): Storage;
400
- /**
401
- * Hashes a stable secret into the machine token Studio expects, so a host can derive one from its
402
- * own identity without duplicating `getMachineToken`'s SHA-256 step.
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
+ * ```
403
120
  */
404
- export declare function machineTokenFrom(secret: string): string;
405
- //#endregion
406
- //#region src/runtime/runConnection.d.ts
407
- type ConnectionOutcome = 'shutdown' | 'stopped';
408
- type TokenRejection<TCredentials> = {
409
- error: InvalidAgentTokenError;
410
- credentials: TCredentials;
411
- /** Whether this credential already served a ready session. */
412
- live: boolean;
413
- };
414
- type ConnectionOptions<TCredentials extends {
415
- token: string;
416
- }> = {
417
- credentials: TCredentials;
418
- clientOptions: (credentials: TCredentials) => Omit<StudioSessionOptions, 'token' | 'signal'>;
419
- onTokenRejected: (rejection: TokenRejection<TCredentials>) => Promise<TCredentials | null>;
420
- signal?: AbortSignal;
421
- /** Used by the client facade once startup succeeds or schedules its first retry. */
422
- onStarted?: () => void;
423
- };
424
- /** Runs the process's one connection loop, including retries and credential replacement. */
425
- export declare function runConnection<TCredentials extends {
426
- token: string;
427
- }>({ credentials, clientOptions, onTokenRejected, signal, onStarted }: ConnectionOptions<TCredentials>): Promise<ConnectionOutcome>;
121
+ export declare function connectAgent(options: ConnectAgentOptions): Promise<void>;
428
122
  //#endregion
429
- //#region src/operations/pair.d.ts
123
+ //#region src/pair.d.ts
430
124
  /**
431
125
  * RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.
432
126
  * Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.
@@ -493,38 +187,15 @@ type StartPairingOptions = {
493
187
  name: string;
494
188
  hostname: string;
495
189
  /**
496
- * Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.
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.
497
192
  */
498
- signal?: AbortSignal;
499
- };
500
- /**
501
- * Asks Studio for a pairing code. The machine token travels with the request and is stored against
502
- * the code, so approval knows which machine it is pairing: the same machine pairing twice rotates
503
- * one agent's token instead of creating a second agent.
504
- */
505
- export declare function startPairing({ studioUrl, type, name, hostname, signal }: StartPairingOptions): Promise<PairingSession>;
506
- type PollOptions = {
507
- studioUrl?: string;
508
- session: PairingSession;
193
+ machineId: string;
509
194
  /**
510
- * Aborting this stops polling and rejects with {@link PairingCanceledError}, whether the abort
511
- * lands between polls or during the wait for the next one.
195
+ * Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.
512
196
  */
513
197
  signal?: AbortSignal;
514
- /** Called when a poll could not reach Studio. Polling carries on. */
515
- onRetry?: (error: Error) => void;
516
198
  };
517
- /**
518
- * Polls until the user approves or denies, honoring the server's `slow_down` back-off.
519
- *
520
- * Studio's own endpoint is used rather than the auth layer's `/device/token`, because an approved
521
- * Kubb pairing is worth an agent bearer token, not a user session.
522
- *
523
- * @throws {PairingExpiredError} when the code expires before anyone approves it.
524
- * @throws {PairingDeniedError} when the pairing is denied in the browser.
525
- * @throws {PairingCanceledError} when `signal` aborts.
526
- */
527
- export declare function pollForPairingToken({ studioUrl, session, signal, onRetry }: PollOptions): Promise<PairingResult>;
528
199
  type PairAgentOptions = StartPairingOptions & {
529
200
  /** Shows the code to whoever approves it. Called again for each fresh code. */
530
201
  onCode: (session: PairingSession, attempt: number) => void | Promise<void>;
@@ -541,18 +212,45 @@ type PairAgentOptions = StartPairingOptions & {
541
212
  */
542
213
  export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }: PairAgentOptions): Promise<PairingResult>;
543
214
  //#endregion
544
- //#region src/operations/rpc.d.ts
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
+ };
545
230
  /**
546
- * Opens an authenticated Cap'n Web session to Studio over a WebSocket. Rejects an unencrypted URL
547
- * before opening the socket, so a bearer token never reaches a plaintext host.
231
+ * Generates the project, packs it as an npm tarball, and publishes it to Studio in one
232
+ * `POST /api/snapshots` request.
548
233
  *
549
234
  * @example
550
235
  * ```ts
551
- * const rpc = await connectWebSocketRpc({ url: 'wss://studio.kubb.dev/s/1', token, local: session })
552
- * await rpc.studio.ping()
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)
553
245
  * ```
554
246
  */
555
- export declare const connectWebSocketRpc: RpcConnector;
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";
556
254
  //#endregion
557
- 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 StudioBranchSnapshotChanges, type StudioConnectedContext, type StudioJob, type StudioJobStatus, type StudioSnapshot, type StudioSnapshotChanges, generationEventTypes };
255
+ export type { ConnectAgentOptions, StudioConnectedContext };
558
256
  //# sourceMappingURL=index.d.ts.map