@kubb/studio 5.2.5 → 5.2.6

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.
@@ -1,579 +0,0 @@
1
- import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
2
- import { Config } from "@kubb/core";
3
- //#region src/protocol/index.d.ts
4
- /**
5
- * JSON-serializable Kubb config exchanged over the WebSocket. A live `kubb/kit` config holds
6
- * functions and class instances that cannot survive JSON, so both sides pass this flattened shape
7
- * and rebuild the real config from it.
8
- */
9
- type JSONKubbConfig = {
10
- /**
11
- * Plugins with their serialized options. `name` is the package name (e.g. `@kubb/plugin-ts`)
12
- * and `options` is an opaque blob the agent forwards unchanged to the plugin factory. An entry
13
- * with `disabled: true` is dropped even when the disk config's `plugins` array still lists it.
14
- */
15
- plugins?: Array<{
16
- name: string;
17
- options?: object;
18
- disabled?: boolean;
19
- }>;
20
- /**
21
- * Raw OpenAPI / Swagger spec content (YAML or JSON string).
22
- * Always honored for a 'sandbox' agent. For a non-sandbox agent it is honored only when the
23
- * agent opts in with `KUBB_AGENT_ALLOW_INPUT`; otherwise the spec is read from disk and this is ignored.
24
- */
25
- input?: string;
26
- /**
27
- * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options
28
- * and re-applied through the same adapter factory, since an adapter instance's functions
29
- * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.
30
- */
31
- adapter?: object;
32
- };
33
- /**
34
- * Which `defineConfig(...)` entry an edit targets, for a config file that exports an array.
35
- *
36
- * A number selects by position, a string matches the entry's `name`. Omitted targets the only
37
- * entry, or the first one when the file exports an array.
38
- */
39
- type ConfigRef = string | number;
40
- /**
41
- * A value the agent can read out of a plugin option in `kubb.config.ts` and round-trip through JSON.
42
- */
43
- type OptionValue = string | number | boolean | null | Array<OptionValue> | {
44
- [key: string]: OptionValue;
45
- };
46
- /**
47
- * One change to a plugin's options in the user's `kubb.config.ts`.
48
- *
49
- * `plugin` is the package name (`@kubb/plugin-ts`), the same identity used in {@link JSONKubbConfig}.
50
- * The agent applies these to the file with an AST patch, so only the targeted values are rewritten.
51
- *
52
- * Declared here rather than in `configFile.ts` because this is the wire contract, and the patcher
53
- * imports it from here. Type-only, so nothing pulls `magicast` into this entry point.
54
- */
55
- type ConfigEdit =
56
- /**
57
- * Write a literal option value. `path` walks nested objects, so `['enum', 'type']` targets
58
- * `pluginTs({ enum: { type } })`.
59
- */
60
- {
61
- operation: 'set';
62
- config?: ConfigRef;
63
- plugin: string;
64
- path: Array<string>;
65
- value: unknown;
66
- } |
67
- /**
68
- * Drop an option so the plugin falls back to its default.
69
- */
70
- {
71
- operation: 'remove';
72
- config?: ConfigRef;
73
- plugin: string;
74
- path: Array<string>;
75
- } |
76
- /**
77
- * Add a plugin factory call and its import to the `plugins` array.
78
- */
79
- {
80
- operation: 'add-plugin';
81
- config?: ConfigRef;
82
- plugin: string;
83
- importName?: string;
84
- options?: Record<string, unknown>;
85
- } |
86
- /**
87
- * Comment the plugin call out, keeping its options in the file so enabling it again restores them.
88
- */
89
- {
90
- operation: 'disable-plugin';
91
- config?: ConfigRef;
92
- plugin: string;
93
- } |
94
- /**
95
- * Uncomment a plugin call a previous `disable-plugin` commented out.
96
- */
97
- {
98
- operation: 'enable-plugin';
99
- config?: ConfigRef;
100
- plugin: string;
101
- };
102
- /**
103
- * A plugin factory call the agent found in the `plugins` array of a `defineConfig(...)`.
104
- */
105
- type PluginView = {
106
- /**
107
- * Local identifier of the factory in the file, e.g. `pluginTs`. This is the alias when the plugin
108
- * was imported under one.
109
- */
110
- importName: string;
111
- /**
112
- * Module the factory is imported from, e.g. `@kubb/plugin-ts`.
113
- */
114
- packageName: string;
115
- /**
116
- * Top-level option keys, each flagged with whether the agent may write it and, when it can, the
117
- * value found in the file. An option marked `literal: false` holds a function or a reference the
118
- * agent will not overwrite, so Studio shows the control disabled rather than hiding it, and
119
- * `value` is absent since there is nothing safe to display as the current value.
120
- */
121
- options: Record<string, {
122
- literal: boolean;
123
- value?: OptionValue;
124
- }>;
125
- /**
126
- * Set when the plugin call is commented out in the file. Its options stay on disk but are not
127
- * readable, so `options` is empty until it is enabled again.
128
- */
129
- disabled?: true;
130
- };
131
- /**
132
- * One `defineConfig(...)` entry. A config file that exports a single object has exactly one.
133
- */
134
- type ConfigView = {
135
- /**
136
- * The entry's `name`, when it sets one. Studio labels the config picker with it.
137
- */
138
- name?: string;
139
- /**
140
- * Each plugin call in the entry, with its top-level option keys.
141
- */
142
- plugins: Array<PluginView>;
143
- };
144
- /**
145
- * What the agent found in the user's config file, so Studio knows which controls it may offer.
146
- * Absent when the agent could not read the file at all.
147
- */
148
- type ConfigFileView = {
149
- managed: true;
150
- /**
151
- * One entry per config the file exports, in source order. Every {@link ConfigEdit} names
152
- * which of these it targets through its `config` field.
153
- */
154
- configs: Array<ConfigView>;
155
- } | {
156
- managed: false;
157
- /**
158
- * Why the file is outside what the agent edits, for example a default export that is not a
159
- * `defineConfig(...)` call. Studio shows this and offers no property-level controls.
160
- */
161
- reason: string;
162
- };
163
- /**
164
- * Outcome of a single {@link ConfigEdit}, returned in a {@link ConfigSavedMessage}.
165
- */
166
- type ConfigEditOutcome = {
167
- edit: ConfigEdit;
168
- applied: boolean;
169
- /**
170
- * Why the edit was refused, absent when it was applied.
171
- */
172
- reason?: string;
173
- };
174
- /**
175
- * Typed events sent by the Kubb agent to Studio over WebSocket.
176
- * Mirrors the single-context-object tuple style of {@link KubbHooks} in `kubb/kit`,
177
- * using JSON-serializable shapes (e.g. `sources` as a `Record` instead of `Map`,
178
- * `error` as `{ message; stack? }` instead of `Error`).
179
- */
180
- type KubbHooks$1 = {
181
- 'kubb:plugin:start': [ctx: {
182
- plugin: {
183
- name: string;
184
- };
185
- }];
186
- 'kubb:plugin:end': [ctx: {
187
- plugin: {
188
- name: string;
189
- };
190
- duration: number;
191
- success: boolean;
192
- }];
193
- 'kubb:build:start': [ctx: {
194
- config: {
195
- name?: string;
196
- };
197
- adapter: {
198
- name: string;
199
- };
200
- }];
201
- 'kubb:build:end': [ctx: {
202
- files: Array<{
203
- path: string;
204
- name: string;
205
- }>;
206
- outputDir: string;
207
- }];
208
- 'kubb:files:processing:start': [ctx: {
209
- total: number;
210
- }];
211
- 'kubb:files:processing:update': [ctx: {
212
- files: Array<{
213
- file: string;
214
- processed: number;
215
- total: number;
216
- percentage: number;
217
- }>;
218
- }];
219
- 'kubb:files:processing:end': [ctx: {
220
- total: number;
221
- }];
222
- 'kubb:info': [ctx: {
223
- message: string;
224
- info?: string;
225
- }];
226
- 'kubb:success': [ctx: {
227
- message: string;
228
- info?: string;
229
- }];
230
- 'kubb:warn': [ctx: {
231
- message: string;
232
- info?: string;
233
- }];
234
- 'kubb:error': [ctx: {
235
- message: string;
236
- stack?: string;
237
- }];
238
- 'kubb:debug': [ctx: {
239
- logs: Array<string>;
240
- fileName?: string;
241
- }];
242
- 'kubb:generation:start': [ctx: {
243
- name?: string;
244
- plugins: number;
245
- }];
246
- 'kubb:generation:end': [ctx: {
247
- config: Config;
248
- storage: Record<string, string>;
249
- peerDependencies: Record<string, string>;
250
- missingDependencies: Array<string>;
251
- }];
252
- 'kubb:generation:summary': [ctx: {
253
- duration: number;
254
- fileCount: number;
255
- failedPlugins: number;
256
- status: 'success' | 'failed';
257
- }];
258
- 'kubb:lifecycle:start': [];
259
- 'kubb:lifecycle:end': [];
260
- 'kubb:format:start': [];
261
- 'kubb:format:end': [];
262
- 'kubb:lint:start': [];
263
- 'kubb:lint:end': [];
264
- 'kubb:hooks:start': [];
265
- 'kubb:hooks:end': [];
266
- 'kubb:hook:start': [ctx: {
267
- id?: string;
268
- command: string;
269
- args?: Array<string>;
270
- }];
271
- 'kubb:hook:line': [ctx: {
272
- id: string;
273
- line: string;
274
- }];
275
- 'kubb:hook:end': [ctx: {
276
- id?: string;
277
- command: string;
278
- args?: Array<string>;
279
- success: boolean;
280
- error?: {
281
- message: string;
282
- stack?: string;
283
- };
284
- }];
285
- };
286
- type KubbHook = keyof KubbHooks$1;
287
- /**
288
- * Run a generation with the given config. `payload` is the merged config Studio wants generated.
289
- */
290
- type StudioGenerateMessage = {
291
- type: 'studio:generate';
292
- payload: JSONKubbConfig;
293
- };
294
- /**
295
- * Ask the agent to send a fresh `agent:connect` payload. Permissions are fixed when the host starts
296
- * the agent; this message only triggers another read of disk config and saved Studio state.
297
- */
298
- type StudioConnectMessage = {
299
- type: 'studio:connect';
300
- /**
301
- * Version of the Studio instance asking, which refreshes what the agent picked up when the
302
- * session was created. Absent when Studio predates the field.
303
- */
304
- version?: string;
305
- };
306
- /**
307
- * Change plugin options in the user's `kubb.config.ts`. Applied only when the agent was granted
308
- * `allowConfigEdit`; otherwise every edit comes back refused.
309
- */
310
- type StudioSaveMessage = {
311
- type: 'studio:save';
312
- edits: Array<ConfigEdit>;
313
- };
314
- /**
315
- * Anything Studio asks the agent to do. Each command is its own `type`, so a handler switches once
316
- * instead of reading a `type` and then a nested `command` field.
317
- */
318
- type CommandMessage = StudioGenerateMessage | StudioConnectMessage | StudioSaveMessage;
319
- /**
320
- * The command names, for a host that needs the list rather than the union.
321
- */
322
- declare const commandTypes: readonly ["studio:generate", "studio:connect", "studio:save"];
323
- /**
324
- * Identifies the host running the Kubb runtime. Local to the runtime rather than part of the wire:
325
- * it picks which remedy a refused-input warning suggests, since the Docker agent and the CLI grant
326
- * `allowInput` different ways.
327
- */
328
- type ClientInfo = {
329
- /**
330
- * `cli` for a `kubb studio` connection from a developer's machine, `docker` for the agent image,
331
- * `ci` for a client embedded directly in an automated pipeline (no `kubb studio` process).
332
- */
333
- kind: 'cli' | 'docker' | 'ci';
334
- };
335
- /**
336
- * Payload of the `agent:connect` handshake, sent when the agent attaches to a session. Carries only
337
- * what Studio renders, with everything about the config under one key.
338
- */
339
- type ConnectMessagePayload = {
340
- /**
341
- * Always sent, so a mismatch is visible on both sides: Studio badges the connection with these
342
- * and the host prints them.
343
- */
344
- versions: {
345
- /**
346
- * The version of the `@kubb/studio` runtime the agent runs.
347
- */
348
- kubb: string;
349
- /**
350
- * The version of the host itself (the `kubb.agent` package or the `kubb` CLI).
351
- */
352
- agent: string;
353
- };
354
- /**
355
- * The agent's project root (`KUBB_AGENT_ROOT`, or the working directory when unset). This is the
356
- * workspace that generation runs against.
357
- */
358
- root: string;
359
- /**
360
- * The baseline every generation starts from.
361
- */
362
- config: {
363
- /**
364
- * The config path as configured (`KUBB_AGENT_CONFIG`), relative to `root` unless absolute.
365
- */
366
- path: string;
367
- /**
368
- * What the agent read out of the config file itself, so Studio can render the plugin editor
369
- * against the real file. Absent when the agent could not read it, or was not granted
370
- * `allowConfigEdit`.
371
- */
372
- file?: ConfigFileView;
373
- /**
374
- * Plugins the config registers, with their serialized options.
375
- */
376
- plugins?: Array<{
377
- name: string;
378
- options?: object;
379
- }>;
380
- };
381
- permissions: AgentPermissions;
382
- };
383
- /**
384
- * What an agent may do in the project it serves. Every one is off unless the host granted it, and
385
- * a sandbox session narrows them further.
386
- */
387
- type AgentPermissions = {
388
- /**
389
- * Whether the agent writes generated files to disk. False for a sandbox agent. For a local
390
- * agent it mirrors the agent's `KUBB_AGENT_ALLOW_WRITE`.
391
- */
392
- allowWrite: boolean;
393
- /**
394
- * Whether the agent will accept and generate from an OpenAPI spec supplied by Studio.
395
- * Always true for a sandbox agent, otherwise it mirrors the agent's own opt-in. Studio reads
396
- * this to decide whether to send `input`.
397
- */
398
- allowInput: boolean;
399
- /**
400
- * Whether the agent runs the formatter, the linter, and `output.postGenerate` as child
401
- * processes after a generation. Always true for the Docker agent, where the image bounds what
402
- * can run. The CLI runs in the user's own project and defaults it off.
403
- */
404
- allowExec: boolean;
405
- /**
406
- * Whether the agent may change plugin options in the user's `kubb.config.ts`. Separate from
407
- * `allowWrite`, which covers generated output: this one edits a hand-authored source file.
408
- */
409
- allowConfigEdit: boolean;
410
- };
411
- /**
412
- * Agent → Studio handshake. Sent when the WebSocket opens and again after a `connect` command.
413
- * Carries the on-disk config baseline, granted permissions, and paths Studio needs to render the editor.
414
- */
415
- type AgentConnectMessage = {
416
- type: 'agent:connect';
417
- payload: ConnectMessagePayload;
418
- };
419
- /**
420
- * Reply to a `save` command: what the agent did to the file on disk.
421
- */
422
- type AgentSaveMessage = {
423
- type: 'agent:save';
424
- payload: {
425
- /**
426
- * Per-edit result, in the order the edits were sent.
427
- */
428
- outcomes: Array<ConfigEditOutcome>;
429
- /**
430
- * Whether the file on disk changed. False when every edit was refused, and when the applied
431
- * edits produced the text the file already had.
432
- */
433
- changed: boolean;
434
- /**
435
- * The config file as it now stands, so Studio can re-render without a round trip. Absent when
436
- * nothing was written. Named to match `config.file` in the connect payload.
437
- */
438
- file?: ConfigFileView;
439
- };
440
- };
441
- /**
442
- * Failure notice from Studio for something that breaks outside a generation, such as a malformed
443
- * command. The agent's own failures travel as an `agent:data` message carrying a `kubb:error`
444
- * payload, which keeps them ordered against the generation events around them.
445
- */
446
- type StudioErrorMessage = {
447
- type: 'studio:error';
448
- message: string;
449
- };
450
- /**
451
- * Heartbeat sent by the Agent to Studio so the connection is not treated as idle.
452
- */
453
- type AgentPingMessage = {
454
- type: 'agent:ping';
455
- };
456
- /**
457
- * Studio's reply to an `agent:ping`, confirming the connection is still alive.
458
- */
459
- type StudioPingMessage = {
460
- type: 'studio:ping';
461
- };
462
- /**
463
- * Studio's acknowledgement that an `agent:connect` handshake was received and the session is
464
- * fully registered: the connection now counts as available for job dispatch. Distinct from the
465
- * socket merely being open, which is not yet the same thing.
466
- */
467
- type StudioReadyMessage = {
468
- type: 'studio:ready';
469
- };
470
- /**
471
- * Disconnect message sent from Studio to Agent when the session is expired or revoked.
472
- * The agent should close the connection without reconnecting.
473
- */
474
- type StudioDisconnectMessage = {
475
- type: 'studio:disconnect';
476
- reason: 'expired' | 'revoked';
477
- };
478
- /**
479
- * The agent going away, so Studio marks the session offline instead of waiting out the heartbeat
480
- * window. The mirror of {@link StudioDisconnectMessage}.
481
- *
482
- * Only sent for a shutdown. An expired or revoked session was Studio's own decision, so echoing it
483
- * back says nothing new.
484
- */
485
- type AgentDisconnectMessage = {
486
- type: 'agent:disconnect';
487
- reason: 'shutdown';
488
- };
489
- /**
490
- * Payload of an `agent:data` message: a single Kubb generation event forwarded to Studio in real time.
491
- * Generic over the hook name so `data` is typed to that hook's context tuple.
492
- */
493
- type DataMessagePayload<T extends KubbHook = KubbHook> = {
494
- /**
495
- * The Kubb hook this event is for (e.g. `kubb:plugin:start`).
496
- */
497
- type: T;
498
- /**
499
- * The hook's context tuple, matching `KubbHooks[type]`.
500
- */
501
- data: KubbHooks$1[T];
502
- /**
503
- * When the agent emitted the event, epoch milliseconds.
504
- */
505
- timestamp: number;
506
- /**
507
- * Monotonic per-connection counter stamped in the order the agent emits events. Studio orders the
508
- * event log by this, since `timestamp` has millisecond resolution and a full generation fires
509
- * dozens of events per tick, and the relay can deliver them out of order.
510
- */
511
- seq: number;
512
- };
513
- /**
514
- * Envelope for a single generation event streamed from Agent to Studio. Wraps a
515
- * {@link DataMessagePayload} so both sides can switch on `type: 'agent:data'`.
516
- */
517
- type DataMessage<T extends KubbHook = KubbHook> = {
518
- type: 'agent:data';
519
- payload: DataMessagePayload<T>;
520
- };
521
- /**
522
- * Response returned by the Studio `/api/agent/sessions` endpoint.
523
- */
524
- type AgentConnectResponse = {
525
- /**
526
- * WebSocket URL the agent opens to reach the session, with the session token embedded.
527
- */
528
- wsUrl: string;
529
- /**
530
- * When the session expires and the wsUrl stops working (ISO 8601).
531
- */
532
- expiresAt: string;
533
- /**
534
- * When the session was revoked (ISO 8601), or null while it is still valid.
535
- */
536
- revokedAt: string | null;
537
- /**
538
- * Opaque session token, also embedded in `wsUrl`. Store it to revoke the session later.
539
- */
540
- sessionId: string;
541
- /**
542
- * Short readable identifier for this connection, used in logs (e.g. brave-otter).
543
- */
544
- slug: string | null;
545
- /**
546
- * Whether this session belongs to a shared sandbox agent rather than an owned one.
547
- */
548
- isSandbox: boolean;
549
- /**
550
- * The Studio instance's own version. Reported here rather than only on `studio:connect`, so the
551
- * agent knows it before it announces itself and can name both sides from the first connect.
552
- * Absent when Studio predates the field.
553
- */
554
- version?: string;
555
- };
556
- /**
557
- * Every message that can cross the agent WebSocket, in either direction. Narrow it with the
558
- * `is*Message` guards below before reading a variant's fields.
559
- */
560
- type AgentMessage = CommandMessage | DataMessage | AgentConnectMessage | AgentSaveMessage | AgentPingMessage | AgentDisconnectMessage | StudioErrorMessage | StudioPingMessage | StudioReadyMessage | StudioDisconnectMessage;
561
- declare function isCommandMessage(msg: AgentMessage): msg is CommandMessage;
562
- /**
563
- * Type guard to narrow a data message to a specific event type.
564
- *
565
- * @example
566
- * ```ts
567
- * if (isDataMessage(msg, 'kubb:plugin:start')) {
568
- * // msg.payload.data is now typed as [ctx: { plugin: { name: string } }]
569
- * const pluginName = msg.payload.data[0].plugin.name
570
- * }
571
- * ```
572
- */
573
- declare function isDataMessage<T extends KubbHook>(msg: AgentMessage, type?: T): msg is DataMessage<T>;
574
- declare function isStudioPingMessage(msg: AgentMessage): msg is StudioPingMessage;
575
- declare function isStudioReadyMessage(msg: AgentMessage): msg is StudioReadyMessage;
576
- declare function isDisconnectMessage(msg: AgentMessage): msg is StudioDisconnectMessage;
577
- //#endregion
578
- export { commandTypes as A, StudioConnectMessage as C, StudioPingMessage as D, StudioGenerateMessage as E, isStudioReadyMessage as F, isDataMessage as M, isDisconnectMessage as N, StudioReadyMessage as O, isStudioPingMessage as P, PluginView as S, StudioErrorMessage as T, DataMessagePayload as _, AgentPermissions as a, KubbHooks$1 as b, ClientInfo as c, ConfigEditOutcome as d, ConfigFileView as f, DataMessage as g, ConnectMessagePayload as h, AgentMessage as i, isCommandMessage as j, StudioSaveMessage as k, CommandMessage as l, ConfigView as m, AgentConnectResponse as n, AgentPingMessage as o, ConfigRef as p, AgentDisconnectMessage as r, AgentSaveMessage as s, AgentConnectMessage as t, ConfigEdit as u, JSONKubbConfig as v, StudioDisconnectMessage as w, OptionValue as x, KubbHook as y };
579
- //# sourceMappingURL=index-Dq2uq38g.d.ts.map