@kubb/studio 5.4.0 → 5.4.2
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 +6 -3
- package/dist/index.cjs +187 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +12 -94
- package/dist/index.js +186 -237
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
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 { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
4
3
|
import { Storage } from "unstorage";
|
|
4
|
+
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
5
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
|
|
@@ -231,10 +231,6 @@ type StudioSessionOptions = {
|
|
|
231
231
|
* Maximum reconnect backoff in milliseconds.
|
|
232
232
|
*/
|
|
233
233
|
retryInterval?: number;
|
|
234
|
-
/**
|
|
235
|
-
* Number of consecutive reconnect attempts that already failed.
|
|
236
|
-
*/
|
|
237
|
-
reconnectAttempt?: number;
|
|
238
234
|
/**
|
|
239
235
|
* Milliseconds between keep-alive pings, clamped to `agentDefaults.maxHeartbeatIntervalMs`.
|
|
240
236
|
* Raise it to halve the traffic and database writes a long-lived agent costs, at the price of
|
|
@@ -249,13 +245,13 @@ type StudioSessionOptions = {
|
|
|
249
245
|
capacity?: Partial<AgentCapacity>;
|
|
250
246
|
/**
|
|
251
247
|
* Names this agent process to Studio, sent at registration and as {@link AGENT_INSTANCE_HEADER}
|
|
252
|
-
* on the socket. `
|
|
248
|
+
* on the socket. `runConnection` sets one per process, so a reconnect is the same instance and a
|
|
253
249
|
* restart is a new one. Not meant to be set directly by a host.
|
|
254
250
|
*/
|
|
255
251
|
instanceId?: string;
|
|
256
252
|
/**
|
|
257
253
|
* Aborting this disconnects the session and stops the reconnect loop. Hosts wire it to their own
|
|
258
|
-
* shutdown
|
|
254
|
+
* shutdown signal, usually `SIGINT` or `SIGTERM`.
|
|
259
255
|
*/
|
|
260
256
|
signal?: AbortSignal;
|
|
261
257
|
/**
|
|
@@ -264,51 +260,18 @@ type StudioSessionOptions = {
|
|
|
264
260
|
* default to.
|
|
265
261
|
*/
|
|
266
262
|
installLogger?: (hooks: Hookable<KubbHooks>) => void | Promise<void>;
|
|
267
|
-
/**
|
|
268
|
-
* Called when this session's background reconnect is rejected with an invalid token. Unlike
|
|
269
|
-
* `ClientOptions.onAuthRequired`, this fires once per session rather than once per pool:
|
|
270
|
-
* `createClient` wraps it into that deduped, pool-stopping callback. Not meant to be set
|
|
271
|
-
* directly by a host.
|
|
272
|
-
*/
|
|
273
|
-
onTokenRejected?: (error: InvalidAgentTokenError) => void;
|
|
274
263
|
};
|
|
275
264
|
//#endregion
|
|
276
265
|
//#region src/runtime/client.d.ts
|
|
277
|
-
type ClientOptions = Omit<StudioSessionOptions, 'signal'
|
|
278
|
-
/**
|
|
279
|
-
* Called once when the token is rejected during a background reconnect (401: revoked, or the
|
|
280
|
-
* agent was deleted). The client is already stopped by the time this fires, so a host only needs
|
|
281
|
-
* to get a replacement token and start a new client.
|
|
282
|
-
*
|
|
283
|
-
* Never fires for a startup rejection, which `connect()` reports by throwing, nor for an ordinary
|
|
284
|
-
* session expiry or revocation, both of which reconnect on their own.
|
|
285
|
-
*/
|
|
266
|
+
type ClientOptions = Omit<StudioSessionOptions, 'signal'> & {
|
|
267
|
+
/** Called once when a background reconnect rejects the credential. */
|
|
286
268
|
onAuthRequired?: (error: InvalidAgentTokenError) => void;
|
|
287
269
|
};
|
|
288
270
|
type Client = {
|
|
289
|
-
/**
|
|
290
|
-
* Registers with Studio and opens this process's one socket. Resolves once it is starting: the
|
|
291
|
-
* connection keeps running, and reconnects on its own, until `disconnect` is called.
|
|
292
|
-
*/
|
|
293
271
|
connect: () => Promise<void>;
|
|
294
|
-
/**
|
|
295
|
-
* Closes the socket and stops reconnecting.
|
|
296
|
-
*/
|
|
297
272
|
disconnect: () => void;
|
|
298
273
|
};
|
|
299
|
-
/**
|
|
300
|
-
* Creates the Kubb Studio client: the connection, the command loop, and the generation event
|
|
301
|
-
* stream shared by the `kubb studio` CLI command and the Docker agent.
|
|
302
|
-
*
|
|
303
|
-
* Every permission is off by default. A host that wants more grants it explicitly. The machine
|
|
304
|
-
* identity comes from the storage the host installed with `setStorage`, before connecting.
|
|
305
|
-
*
|
|
306
|
-
* @example
|
|
307
|
-
* ```ts
|
|
308
|
-
* const studio = createClient({ token, configPath, version, loadConfig: () => loadMyConfig() })
|
|
309
|
-
* await studio.connect()
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
274
|
+
/** Compatibility facade over the shared connection loop. */
|
|
312
275
|
export declare function createClient({ onAuthRequired, ...options }: ClientOptions): Client;
|
|
313
276
|
//#endregion
|
|
314
277
|
//#region src/operations/hooks.d.ts
|
|
@@ -441,72 +404,27 @@ export declare function createFileStorage(base: string): Storage;
|
|
|
441
404
|
export declare function machineTokenFrom(secret: string): string;
|
|
442
405
|
//#endregion
|
|
443
406
|
//#region src/runtime/runConnection.d.ts
|
|
444
|
-
/**
|
|
445
|
-
* Why a connection ended: the host asked it to stop through its `signal`, or the host declined to
|
|
446
|
-
* replace a rejected token.
|
|
447
|
-
*/
|
|
448
407
|
type ConnectionOutcome = 'shutdown' | 'stopped';
|
|
449
|
-
/**
|
|
450
|
-
* A rejected token, and whether it was already serving a live session when Studio rejected it.
|
|
451
|
-
*/
|
|
452
408
|
type TokenRejection<TCredentials> = {
|
|
453
409
|
error: InvalidAgentTokenError;
|
|
454
|
-
/**
|
|
455
|
-
* The credential Studio rejected, so a host can carry parts of it into the replacement.
|
|
456
|
-
*/
|
|
457
410
|
credentials: TCredentials;
|
|
458
|
-
/**
|
|
459
|
-
* `false` when the token was dead before a session ever opened, which is what `connect()` itself
|
|
460
|
-
* reports. `true` when a live pool's background reconnect was rejected, well after the session
|
|
461
|
-
* was up. Hosts treat the two differently: only the first has nothing to tear down.
|
|
462
|
-
*/
|
|
411
|
+
/** Whether this credential already served a ready session. */
|
|
463
412
|
live: boolean;
|
|
464
413
|
};
|
|
465
414
|
type ConnectionOptions<TCredentials extends {
|
|
466
415
|
token: string;
|
|
467
416
|
}> = {
|
|
468
|
-
/**
|
|
469
|
-
* The credential to open with. Only its token is read here, so a host keeps whatever else it
|
|
470
|
-
* stores alongside.
|
|
471
|
-
*/
|
|
472
417
|
credentials: TCredentials;
|
|
473
|
-
|
|
474
|
-
* Builds the client options for one attempt. Called again for every reconnect, so a host whose
|
|
475
|
-
* options depend on which agent approved, such as the permissions it granted, re-derives them
|
|
476
|
-
* rather than reusing the ones the rejected token was opened with.
|
|
477
|
-
*/
|
|
478
|
-
clientOptions: (credentials: TCredentials) => Omit<ClientOptions, 'token' | 'onAuthRequired'>;
|
|
479
|
-
/**
|
|
480
|
-
* Called when Studio rejects the token. Return the credential to reconnect with, or `null` to
|
|
481
|
-
* end the run. Throwing fails it, which is what a host does when it cannot pair again.
|
|
482
|
-
*/
|
|
418
|
+
clientOptions: (credentials: TCredentials) => Omit<StudioSessionOptions, 'token' | 'signal'>;
|
|
483
419
|
onTokenRejected: (rejection: TokenRejection<TCredentials>) => Promise<TCredentials | null>;
|
|
484
|
-
/**
|
|
485
|
-
* Aborting this disconnects and ends the run. Hosts wire it to their own shutdown: `SIGINT` in
|
|
486
|
-
* the CLI, Nitro's `close` hook in the Docker agent.
|
|
487
|
-
*/
|
|
488
420
|
signal?: AbortSignal;
|
|
421
|
+
/** Used by the client facade once startup succeeds or schedules its first retry. */
|
|
422
|
+
onStarted?: () => void;
|
|
489
423
|
};
|
|
490
|
-
/**
|
|
491
|
-
* Keeps a host connected to Studio across token changes: it opens a client, waits until the run
|
|
492
|
-
* ends or Studio rejects the token, and reconnects with whatever credential the host hands back.
|
|
493
|
-
*
|
|
494
|
-
* The host owns everything around that. Where credentials live, whether a rejected token may be
|
|
495
|
-
* replaced, and how any of it is reported are all decisions `onTokenRejected` makes.
|
|
496
|
-
*
|
|
497
|
-
* @example
|
|
498
|
-
* ```ts
|
|
499
|
-
* const outcome = await runConnection({
|
|
500
|
-
* credentials,
|
|
501
|
-
* clientOptions: () => ({ studioUrl, configPath, version, loadConfig }),
|
|
502
|
-
* signal: shutdown.signal,
|
|
503
|
-
* onTokenRejected: ({ error, live }) => pairAgain(error, live),
|
|
504
|
-
* })
|
|
505
|
-
* ```
|
|
506
|
-
*/
|
|
424
|
+
/** Runs the process's one connection loop, including retries and credential replacement. */
|
|
507
425
|
export declare function runConnection<TCredentials extends {
|
|
508
426
|
token: string;
|
|
509
|
-
}>({ credentials, clientOptions, onTokenRejected, signal }: ConnectionOptions<TCredentials>): Promise<ConnectionOutcome>;
|
|
427
|
+
}>({ credentials, clientOptions, onTokenRejected, signal, onStarted }: ConnectionOptions<TCredentials>): Promise<ConnectionOutcome>;
|
|
510
428
|
//#endregion
|
|
511
429
|
//#region src/operations/pair.d.ts
|
|
512
430
|
/**
|