@kubb/studio 5.3.16 → 5.3.17

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,7 +1,7 @@
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";
4
+ import { Storage } from "unstorage";
5
5
  //#region src/api.d.ts
6
6
  /**
7
7
  * Thrown when Studio rejects the agent token itself (401). Retrying cannot help: the token was
@@ -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 the previous one of the same package and agent, relative to `output.path`. */
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` for the first one. */
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, timeoutMs, signal }: {
108
121
  studioUrl: string;
109
122
  token: string;
110
123
  type: 'generation' | 'snapshot';
@@ -113,7 +126,16 @@ 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
+ * How long to keep retrying a busy or queue-full response before giving up, in milliseconds.
134
+ *
135
+ * @default 60000
136
+ */
137
+ timeoutMs?: number;
138
+ signal?: AbortSignal;
117
139
  }): Promise<StudioJob>;
118
140
  /**
119
141
  * Polls `GET /api/jobs/{id}` until the job reaches a terminal status, waiting
@@ -123,7 +145,7 @@ export declare function createJob({ studioUrl, token, type, agentId, name, versi
123
145
  * A `failed` job resolves normally. Check `job.status` and `job.error`. Throws only when the
124
146
  * deadline passes before Studio finishes.
125
147
  */
126
- export declare function waitForJob({ studioUrl, token, id, timeoutMs }: {
148
+ export declare function waitForJob({ studioUrl, token, id, timeoutMs, signal }: {
127
149
  studioUrl: string;
128
150
  token: string;
129
151
  id: string;
@@ -133,6 +155,7 @@ export declare function waitForJob({ studioUrl, token, id, timeoutMs }: {
133
155
  * @default 60000
134
156
  */
135
157
  timeoutMs?: number;
158
+ signal?: AbortSignal;
136
159
  }): Promise<StudioJob>;
137
160
  /**
138
161
  * CI agent returned by {@link createAgent}. The token is issued only once, at creation or reuse.
@@ -190,7 +213,14 @@ type StudioSessionOptions = {
190
213
  */
191
214
  permissions?: Partial<AgentPermissions>;
192
215
  root?: string;
216
+ /**
217
+ * Maximum reconnect backoff in milliseconds.
218
+ */
193
219
  retryInterval?: number;
220
+ /**
221
+ * Number of consecutive reconnect attempts that already failed.
222
+ */
223
+ reconnectAttempt?: number;
194
224
  /**
195
225
  * Milliseconds between keep-alive pings, clamped to `agentDefaults.maxHeartbeatIntervalMs`.
196
226
  * Raise it to halve the traffic and database writes a long-lived agent costs, at the price of
@@ -199,10 +229,16 @@ type StudioSessionOptions = {
199
229
  */
200
230
  heartbeatInterval?: number;
201
231
  /**
202
- * Number of pool sessions this agent serves. Read by `createClient`, which opens one
203
- * session per slot, and reported to Studio at registration.
232
+ * What this agent process can take on, reported to Studio at registration. Unset fields come from
233
+ * `KUBB_AGENT_MAX_CONCURRENT` and `KUBB_AGENT_MEMORY_BUDGET_MB`.
234
+ */
235
+ capacity?: Partial<AgentCapacity>;
236
+ /**
237
+ * Names this agent process to Studio, sent at registration and as {@link AGENT_INSTANCE_HEADER}
238
+ * on the socket. `createClient` sets one per process, so a reconnect is the same instance and a
239
+ * restart is a new one. Not meant to be set directly by a host.
204
240
  */
205
- poolSize?: number;
241
+ instanceId?: string;
206
242
  /**
207
243
  * Aborting this disconnects the session and stops the reconnect loop. Hosts wire it to their own
208
244
  * shutdown: Nitro's `close` hook, or `SIGINT`/`SIGTERM` in the CLI.
@@ -221,20 +257,14 @@ type StudioSessionOptions = {
221
257
  * directly by a host.
222
258
  */
223
259
  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
260
  };
231
261
  //#endregion
232
262
  //#region src/client.d.ts
233
- type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | 'startupWarning'> & {
263
+ type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | 'instanceId' | 'reconnectAttempt'> & {
234
264
  /**
235
- * Called once when a live pool's token is rejected during background reconnect (401: revoked, or
236
- * the agent was deleted). The whole pool is already stopped by the time this fires, so a host
237
- * only needs to get a replacement token and start a new client.
265
+ * Called once when the token is rejected during a background reconnect (401: revoked, or the
266
+ * agent was deleted). The client is already stopped by the time this fires, so a host only needs
267
+ * to get a replacement token and start a new client.
238
268
  *
239
269
  * Never fires for a startup rejection, which `connect()` reports by throwing, nor for an ordinary
240
270
  * session expiry or revocation, both of which reconnect on their own.
@@ -243,12 +273,12 @@ type ClientOptions = Omit<StudioSessionOptions, 'signal' | 'onTokenRejected' | '
243
273
  };
244
274
  type Client = {
245
275
  /**
246
- * Registers with Studio and opens the session pool. Resolves once the pool is starting: the
247
- * sessions keep running, and reconnect on their own, until `disconnect` is called.
276
+ * Registers with Studio and opens this process's one socket. Resolves once it is starting: the
277
+ * connection keeps running, and reconnects on its own, until `disconnect` is called.
248
278
  */
249
279
  connect: () => Promise<void>;
250
280
  /**
251
- * Closes every session and stops reconnecting.
281
+ * Closes the socket and stops reconnecting.
252
282
  */
253
283
  disconnect: () => void;
254
284
  };
@@ -592,5 +622,5 @@ export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }:
592
622
  */
593
623
  export declare const connectWebSocketRpc: RpcConnector;
594
624
  //#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 };
625
+ 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
626
  //# sourceMappingURL=index.d.ts.map