@kubb/studio 0.0.0-canary-20260903193839
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/LICENSE +21 -0
- package/README.md +136 -0
- package/dist/configFile-DjzP1_Ln.cjs +575 -0
- package/dist/configFile-DjzP1_Ln.cjs.map +1 -0
- package/dist/configFile-ZnV5tPon.js +574 -0
- package/dist/configFile-ZnV5tPon.js.map +1 -0
- package/dist/index-BVn89Nw2.d.ts +562 -0
- package/dist/index.cjs +1330 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +274 -0
- package/dist/index.js +1319 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +42 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.ts +2 -0
- package/dist/protocol.js +37 -0
- package/dist/protocol.js.map +1 -0
- package/dist/resolveConfig-B9oGiNMi.js +179 -0
- package/dist/resolveConfig-B9oGiNMi.js.map +1 -0
- package/dist/resolveConfig-Ci-BVhN_.cjs +202 -0
- package/dist/resolveConfig-Ci-BVhN_.cjs.map +1 -0
- package/dist/rolldown-runtime-CRm0XQPb.js +9 -0
- package/dist/rolldown-runtime-qbf5tadS.cjs +38 -0
- package/package.json +86 -0
|
@@ -0,0 +1,562 @@
|
|
|
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
|
+
}];
|
|
250
|
+
'kubb:generation:summary': [ctx: {
|
|
251
|
+
duration: number;
|
|
252
|
+
fileCount: number;
|
|
253
|
+
failedPlugins: number;
|
|
254
|
+
status: 'success' | 'failed';
|
|
255
|
+
}];
|
|
256
|
+
'kubb:lifecycle:start': [];
|
|
257
|
+
'kubb:lifecycle:end': [];
|
|
258
|
+
'kubb:format:start': [];
|
|
259
|
+
'kubb:format:end': [];
|
|
260
|
+
'kubb:lint:start': [];
|
|
261
|
+
'kubb:lint:end': [];
|
|
262
|
+
'kubb:hooks:start': [];
|
|
263
|
+
'kubb:hooks:end': [];
|
|
264
|
+
'kubb:hook:start': [ctx: {
|
|
265
|
+
id?: string;
|
|
266
|
+
command: string;
|
|
267
|
+
args?: Array<string>;
|
|
268
|
+
}];
|
|
269
|
+
'kubb:hook:line': [ctx: {
|
|
270
|
+
id: string;
|
|
271
|
+
line: string;
|
|
272
|
+
}];
|
|
273
|
+
'kubb:hook:end': [ctx: {
|
|
274
|
+
id?: string;
|
|
275
|
+
command: string;
|
|
276
|
+
args?: Array<string>;
|
|
277
|
+
success: boolean;
|
|
278
|
+
error?: {
|
|
279
|
+
message: string;
|
|
280
|
+
stack?: string;
|
|
281
|
+
};
|
|
282
|
+
}];
|
|
283
|
+
};
|
|
284
|
+
type KubbHook = keyof KubbHooks$1;
|
|
285
|
+
/**
|
|
286
|
+
* Run a generation with the given config. `payload` is the merged config Studio wants generated.
|
|
287
|
+
*/
|
|
288
|
+
type StudioGenerateMessage = {
|
|
289
|
+
type: 'studio:generate';
|
|
290
|
+
payload: JSONKubbConfig;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Ask the agent to send a fresh `agent:connect` payload. Permissions are fixed when the host starts
|
|
294
|
+
* the agent; this message only triggers another read of disk config and saved Studio state.
|
|
295
|
+
*/
|
|
296
|
+
type StudioConnectMessage = {
|
|
297
|
+
type: 'studio:connect';
|
|
298
|
+
/**
|
|
299
|
+
* Version of the Studio instance asking, which refreshes what the agent picked up when the
|
|
300
|
+
* session was created. Absent when Studio predates the field.
|
|
301
|
+
*/
|
|
302
|
+
version?: string;
|
|
303
|
+
};
|
|
304
|
+
/**
|
|
305
|
+
* Change plugin options in the user's `kubb.config.ts`. Applied only when the agent was granted
|
|
306
|
+
* `allowConfigEdit`; otherwise every edit comes back refused.
|
|
307
|
+
*/
|
|
308
|
+
type StudioSaveMessage = {
|
|
309
|
+
type: 'studio:save';
|
|
310
|
+
edits: Array<ConfigEdit>;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* Anything Studio asks the agent to do. Each command is its own `type`, so a handler switches once
|
|
314
|
+
* instead of reading a `type` and then a nested `command` field.
|
|
315
|
+
*/
|
|
316
|
+
type CommandMessage = StudioGenerateMessage | StudioConnectMessage | StudioSaveMessage;
|
|
317
|
+
/**
|
|
318
|
+
* The command names, for a host that needs the list rather than the union.
|
|
319
|
+
*/
|
|
320
|
+
declare const commandTypes: readonly ["studio:generate", "studio:connect", "studio:save"];
|
|
321
|
+
/**
|
|
322
|
+
* Identifies the host running the Kubb runtime. Local to the runtime rather than part of the wire:
|
|
323
|
+
* it picks which remedy a refused-input warning suggests, since the Docker agent and the CLI grant
|
|
324
|
+
* `allowInput` different ways.
|
|
325
|
+
*/
|
|
326
|
+
type ClientInfo = {
|
|
327
|
+
/**
|
|
328
|
+
* `cli` for a `kubb studio` connection from a developer's machine, `docker` for the agent image.
|
|
329
|
+
*/
|
|
330
|
+
kind: 'cli' | 'docker';
|
|
331
|
+
};
|
|
332
|
+
/**
|
|
333
|
+
* Payload of the `agent:connect` handshake, sent when the agent attaches to a session. Carries only
|
|
334
|
+
* what Studio renders, with everything about the config under one key.
|
|
335
|
+
*/
|
|
336
|
+
type ConnectMessagePayload = {
|
|
337
|
+
/**
|
|
338
|
+
* Always sent, so a mismatch is visible on both sides: Studio badges the connection with these
|
|
339
|
+
* and the host prints them.
|
|
340
|
+
*/
|
|
341
|
+
versions: {
|
|
342
|
+
/**
|
|
343
|
+
* The version of the `@kubb/studio` runtime the agent runs.
|
|
344
|
+
*/
|
|
345
|
+
kubb: string;
|
|
346
|
+
/**
|
|
347
|
+
* The version of the host itself (the `kubb.agent` package or the `kubb` CLI).
|
|
348
|
+
*/
|
|
349
|
+
agent: string;
|
|
350
|
+
};
|
|
351
|
+
/**
|
|
352
|
+
* The agent's project root (`KUBB_AGENT_ROOT`, or the working directory when unset). This is the
|
|
353
|
+
* workspace that generation runs against.
|
|
354
|
+
*/
|
|
355
|
+
root: string;
|
|
356
|
+
/**
|
|
357
|
+
* The baseline every generation starts from.
|
|
358
|
+
*/
|
|
359
|
+
config: {
|
|
360
|
+
/**
|
|
361
|
+
* The config path as configured (`KUBB_AGENT_CONFIG`), relative to `root` unless absolute.
|
|
362
|
+
*/
|
|
363
|
+
path: string;
|
|
364
|
+
/**
|
|
365
|
+
* What the agent read out of the config file itself, so Studio can render the plugin editor
|
|
366
|
+
* against the real file. Absent when the agent could not read it, or was not granted
|
|
367
|
+
* `allowConfigEdit`.
|
|
368
|
+
*/
|
|
369
|
+
file?: ConfigFileView;
|
|
370
|
+
/**
|
|
371
|
+
* Plugins the config registers, with their serialized options.
|
|
372
|
+
*/
|
|
373
|
+
plugins?: Array<{
|
|
374
|
+
name: string;
|
|
375
|
+
options?: object;
|
|
376
|
+
}>;
|
|
377
|
+
};
|
|
378
|
+
permissions: {
|
|
379
|
+
/**
|
|
380
|
+
* Whether the agent writes generated files to disk. False for a sandbox agent. For a local
|
|
381
|
+
* agent it mirrors the agent's `KUBB_AGENT_ALLOW_WRITE`.
|
|
382
|
+
*/
|
|
383
|
+
allowWrite: boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Whether the agent will accept and generate from an OpenAPI spec supplied by Studio.
|
|
386
|
+
* Always true for a sandbox agent; otherwise it mirrors the agent's own opt-in. Studio reads
|
|
387
|
+
* this to decide whether to send `input`.
|
|
388
|
+
*/
|
|
389
|
+
allowInput: boolean;
|
|
390
|
+
/**
|
|
391
|
+
* Whether the agent runs the formatter, the linter, and `output.postGenerate` as child
|
|
392
|
+
* processes after a generation. Always true for the Docker agent, where the image bounds what
|
|
393
|
+
* can run. The CLI runs in the user's own project and defaults it off.
|
|
394
|
+
*/
|
|
395
|
+
allowExec: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Whether the agent may change plugin options in the user's `kubb.config.ts`. Separate from
|
|
398
|
+
* `allowWrite`, which covers generated output: this one edits a hand-authored source file.
|
|
399
|
+
*/
|
|
400
|
+
allowConfigEdit: boolean;
|
|
401
|
+
};
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Agent → Studio handshake. Sent when the WebSocket opens and again after a `connect` command.
|
|
405
|
+
* Carries the on-disk config baseline, granted permissions, and paths Studio needs to render the editor.
|
|
406
|
+
*/
|
|
407
|
+
type AgentConnectMessage = {
|
|
408
|
+
type: 'agent:connect';
|
|
409
|
+
payload: ConnectMessagePayload;
|
|
410
|
+
};
|
|
411
|
+
/**
|
|
412
|
+
* Reply to a `save` command: what the agent did to the file on disk.
|
|
413
|
+
*/
|
|
414
|
+
type AgentSaveMessage = {
|
|
415
|
+
type: 'agent:save';
|
|
416
|
+
payload: {
|
|
417
|
+
/**
|
|
418
|
+
* Per-edit result, in the order the edits were sent.
|
|
419
|
+
*/
|
|
420
|
+
outcomes: Array<ConfigEditOutcome>;
|
|
421
|
+
/**
|
|
422
|
+
* Whether the file on disk changed. False when every edit was refused, and when the applied
|
|
423
|
+
* edits produced the text the file already had.
|
|
424
|
+
*/
|
|
425
|
+
changed: boolean;
|
|
426
|
+
/**
|
|
427
|
+
* The config file as it now stands, so Studio can re-render without a round trip. Absent when
|
|
428
|
+
* nothing was written. Named to match `config.file` in the connect payload.
|
|
429
|
+
*/
|
|
430
|
+
file?: ConfigFileView;
|
|
431
|
+
};
|
|
432
|
+
};
|
|
433
|
+
/**
|
|
434
|
+
* Failure notice from Studio for something that breaks outside a generation, such as a malformed
|
|
435
|
+
* command. The agent's own failures travel as an `agent:data` message carrying a `kubb:error`
|
|
436
|
+
* payload, which keeps them ordered against the generation events around them.
|
|
437
|
+
*/
|
|
438
|
+
type StudioErrorMessage = {
|
|
439
|
+
type: 'studio:error';
|
|
440
|
+
message: string;
|
|
441
|
+
};
|
|
442
|
+
/**
|
|
443
|
+
* Heartbeat sent by the Agent to Studio so the connection is not treated as idle.
|
|
444
|
+
*/
|
|
445
|
+
type AgentPingMessage = {
|
|
446
|
+
type: 'agent:ping';
|
|
447
|
+
};
|
|
448
|
+
/**
|
|
449
|
+
* Studio's reply to an `agent:ping`, confirming the connection is still alive.
|
|
450
|
+
*/
|
|
451
|
+
type StudioPingMessage = {
|
|
452
|
+
type: 'studio:ping';
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* Disconnect message sent from Studio to Agent when the session is expired or revoked.
|
|
456
|
+
* The agent should close the connection without reconnecting.
|
|
457
|
+
*/
|
|
458
|
+
type StudioDisconnectMessage = {
|
|
459
|
+
type: 'studio:disconnect';
|
|
460
|
+
reason: 'expired' | 'revoked';
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* The agent going away, so Studio marks the session offline instead of waiting out the heartbeat
|
|
464
|
+
* window. The mirror of {@link StudioDisconnectMessage}.
|
|
465
|
+
*
|
|
466
|
+
* Only sent for a shutdown. An expired or revoked session was Studio's own decision, so echoing it
|
|
467
|
+
* back says nothing new.
|
|
468
|
+
*/
|
|
469
|
+
type AgentDisconnectMessage = {
|
|
470
|
+
type: 'agent:disconnect';
|
|
471
|
+
reason: 'shutdown';
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Payload of an `agent:data` message: a single Kubb generation event forwarded to Studio in real time.
|
|
475
|
+
* Generic over the hook name so `data` is typed to that hook's context tuple.
|
|
476
|
+
*/
|
|
477
|
+
type DataMessagePayload<T extends KubbHook = KubbHook> = {
|
|
478
|
+
/**
|
|
479
|
+
* The Kubb hook this event is for (e.g. `kubb:plugin:start`).
|
|
480
|
+
*/
|
|
481
|
+
type: T;
|
|
482
|
+
/**
|
|
483
|
+
* The hook's context tuple, matching `KubbHooks[type]`.
|
|
484
|
+
*/
|
|
485
|
+
data: KubbHooks$1[T];
|
|
486
|
+
/**
|
|
487
|
+
* When the agent emitted the event, epoch milliseconds.
|
|
488
|
+
*/
|
|
489
|
+
timestamp: number;
|
|
490
|
+
/**
|
|
491
|
+
* Monotonic per-connection counter stamped in the order the agent emits events. Studio orders the
|
|
492
|
+
* event log by this, since `timestamp` has millisecond resolution and a full generation fires
|
|
493
|
+
* dozens of events per tick, and the relay can deliver them out of order.
|
|
494
|
+
*/
|
|
495
|
+
seq: number;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Envelope for a single generation event streamed from Agent to Studio. Wraps a
|
|
499
|
+
* {@link DataMessagePayload} so both sides can switch on `type: 'agent:data'`.
|
|
500
|
+
*/
|
|
501
|
+
type DataMessage<T extends KubbHook = KubbHook> = {
|
|
502
|
+
type: 'agent:data';
|
|
503
|
+
payload: DataMessagePayload<T>;
|
|
504
|
+
};
|
|
505
|
+
/**
|
|
506
|
+
* Response returned by the Studio `/api/agent/sessions` endpoint.
|
|
507
|
+
*/
|
|
508
|
+
type AgentConnectResponse = {
|
|
509
|
+
/**
|
|
510
|
+
* WebSocket URL the agent opens to reach the session, with the session token embedded.
|
|
511
|
+
*/
|
|
512
|
+
wsUrl: string;
|
|
513
|
+
/**
|
|
514
|
+
* When the session expires and the wsUrl stops working (ISO 8601).
|
|
515
|
+
*/
|
|
516
|
+
expiresAt: string;
|
|
517
|
+
/**
|
|
518
|
+
* When the session was revoked (ISO 8601), or null while it is still valid.
|
|
519
|
+
*/
|
|
520
|
+
revokedAt: string | null;
|
|
521
|
+
/**
|
|
522
|
+
* Opaque session token, also embedded in `wsUrl`. Store it to revoke the session later.
|
|
523
|
+
*/
|
|
524
|
+
sessionId: string;
|
|
525
|
+
/**
|
|
526
|
+
* Short readable identifier for this connection, used in logs (e.g. brave-otter).
|
|
527
|
+
*/
|
|
528
|
+
slug: string | null;
|
|
529
|
+
/**
|
|
530
|
+
* Whether this session belongs to a shared sandbox agent rather than an owned one.
|
|
531
|
+
*/
|
|
532
|
+
isSandbox: boolean;
|
|
533
|
+
/**
|
|
534
|
+
* The Studio instance's own version. Reported here rather than only on `studio:connect`, so the
|
|
535
|
+
* agent knows it before it announces itself and can name both sides from the first connect.
|
|
536
|
+
* Absent when Studio predates the field.
|
|
537
|
+
*/
|
|
538
|
+
version?: string;
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Every message that can cross the agent WebSocket, in either direction. Narrow it with the
|
|
542
|
+
* `is*Message` guards below before reading a variant's fields.
|
|
543
|
+
*/
|
|
544
|
+
type AgentMessage = CommandMessage | DataMessage | AgentConnectMessage | AgentSaveMessage | AgentPingMessage | AgentDisconnectMessage | StudioErrorMessage | StudioPingMessage | StudioDisconnectMessage;
|
|
545
|
+
declare function isCommandMessage(msg: AgentMessage): msg is CommandMessage;
|
|
546
|
+
/**
|
|
547
|
+
* Type guard to narrow a data message to a specific event type.
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```ts
|
|
551
|
+
* if (isDataMessage(msg, 'kubb:plugin:start')) {
|
|
552
|
+
* // msg.payload.data is now typed as [ctx: { plugin: { name: string } }]
|
|
553
|
+
* const pluginName = msg.payload.data[0].plugin.name
|
|
554
|
+
* }
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
declare function isDataMessage<T extends KubbHook>(msg: AgentMessage, type?: T): msg is DataMessage<T>;
|
|
558
|
+
declare function isStudioPingMessage(msg: AgentMessage): msg is StudioPingMessage;
|
|
559
|
+
declare function isDisconnectMessage(msg: AgentMessage): msg is StudioDisconnectMessage;
|
|
560
|
+
//#endregion
|
|
561
|
+
export { isDataMessage as A, StudioDisconnectMessage as C, StudioSaveMessage as D, StudioPingMessage as E, isStudioPingMessage as M, commandTypes as O, StudioConnectMessage as S, StudioGenerateMessage as T, JSONKubbConfig as _, AgentPingMessage as a, OptionValue as b, CommandMessage as c, ConfigFileView as d, ConfigRef as f, DataMessagePayload as g, DataMessage as h, AgentMessage as i, isDisconnectMessage as j, isCommandMessage as k, ConfigEdit as l, ConnectMessagePayload as m, AgentConnectResponse as n, AgentSaveMessage as o, ConfigView as p, AgentDisconnectMessage as r, ClientInfo as s, AgentConnectMessage as t, ConfigEditOutcome as u, KubbHook as v, StudioErrorMessage as w, PluginView as x, KubbHooks$1 as y };
|
|
562
|
+
//# sourceMappingURL=index-BVn89Nw2.d.ts.map
|