@kubb/studio 5.12.8 → 5.13.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.
@@ -1,70 +1,22 @@
1
1
  import { ExtensionKind, ExtensionManifest } from "@kubb/core";
2
2
  import { InputNode } from "@kubb/ast";
3
- //#region src/protocol.d.ts
4
- /**
5
- * JSON-serializable Kubb config exchanged over RPC. 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), never a file path.
22
- * Required by a 'sandbox' agent, which has no disk config of its own and refuses anything else.
23
- * A 'managed' agent also takes a URL or a `git+<repo>#<ref>:<path>` input, and falls back to its disk config without one.
24
- * Any other agent always reads its spec from disk, so this is ignored with a `kubb:warn`.
25
- */
26
- input?: string;
27
- /**
28
- * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options
29
- * and re-applied through the same adapter factory, since an adapter instance's functions
30
- * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.
31
- */
32
- adapter?: object;
33
- /**
34
- * Parser option overrides from Studio, matched to the disk config's parsers by `name` and
35
- * re-applied through each parser's factory, the same way `adapter` is.
36
- */
37
- parsers?: Array<{
38
- name: string;
39
- options?: object;
40
- }>;
41
- /** Root `output` overrides for `barrel`, `format`, `lint`, `clean`, and `defaultBanner`. Other members are ignored. */
42
- output?: object;
43
- /**
44
- * Which `defineConfig(...)` entry to generate from. Omitted runs the first one.
45
- */
46
- config?: ConfigRef;
47
- };
48
- /**
49
- * Which `defineConfig(...)` entry an edit targets, for a config file that exports an array.
50
- *
51
- * A number selects by position, a string matches the entry's `name`. Omitted targets the only
52
- * entry, or the first one when the file exports an array.
53
- */
3
+ //#region ../../internals/shared/src/configFile/types.d.ts
4
+ /** Which `defineConfig(...)` entry an edit targets: its index or `name`, the first entry when omitted. */
54
5
  type ConfigRef = string | number;
55
- /**
56
- * A value the agent can read out of a plugin option in `kubb.config.ts` and round-trip through JSON.
57
- */
6
+ /** A literal option value that survives a JSON round trip. */
58
7
  type OptionValue = string | number | boolean | null | Array<OptionValue> | {
59
8
  [key: string]: OptionValue;
60
9
  };
61
- /**
62
- * The kinds of {@link ConfigEdit}, one per `operation`.
63
- */
10
+ declare const extensionKinds: {
11
+ readonly plugin: 'plugin';
12
+ readonly adapter: 'adapter';
13
+ readonly parser: 'parser';
14
+ };
64
15
  declare const ConfigEditOperation: {
65
- readonly SET: 'set';
66
- readonly REMOVE: 'remove';
16
+ readonly SET_OPTION: 'set-option';
17
+ readonly REMOVE_OPTION: 'remove-option';
67
18
  readonly ADD_PLUGIN: 'add-plugin';
19
+ readonly REMOVE_EXTENSION: 'remove-extension';
68
20
  readonly DISABLE_PLUGIN: 'disable-plugin';
69
21
  readonly ENABLE_PLUGIN: 'enable-plugin';
70
22
  readonly SET_INPUT: 'set-input';
@@ -73,177 +25,170 @@ declare const ConfigEditOperation: {
73
25
  };
74
26
  type ConfigEditOperation = (typeof ConfigEditOperation)[keyof typeof ConfigEditOperation];
75
27
  /**
76
- * One change to a plugin's options in the user's `kubb.config.ts`.
77
- *
78
- * `plugin` is the package name (`@kubb/plugin-ts`), the same identity used in {@link JSONKubbConfig}.
79
- * The agent applies these to the file with an AST patch, so only the targeted values are rewritten.
80
- *
81
- * Declared here rather than in `configFile.ts` because this is the wire contract, and the patcher
82
- * imports it from here. Type-only, so nothing pulls `magicast` into this entry point.
28
+ * One change to `kubb.config.ts`. `plugin` is the package name, and `kind` picks the `plugins` entry
29
+ * (default), the `adapter`, or a `parsers` entry. `path` walks nested option objects.
83
30
  */
84
- type ConfigEdit =
85
- /**
86
- * Write a literal option value. `path` walks nested objects, so `['enum', 'type']` targets
87
- * `pluginTs({ enum: { type } })`. `kind` names which factory call `plugin` is: one in `plugins`
88
- * when left out, the config's `adapter`, or one in `parsers`.
89
- */
90
- {
91
- operation: typeof ConfigEditOperation.SET;
31
+ type ConfigEdit = {
32
+ operation: typeof ConfigEditOperation.SET_OPTION;
92
33
  config?: ConfigRef;
93
34
  kind?: ExtensionKind;
94
35
  plugin: string;
95
36
  path: Array<string>;
96
37
  value: unknown;
97
- } |
98
- /**
99
- * Drop an option so the extension falls back to its default. `kind` as for `set`.
100
- */
101
- {
102
- operation: typeof ConfigEditOperation.REMOVE;
38
+ } | {
39
+ operation: typeof ConfigEditOperation.REMOVE_OPTION;
103
40
  config?: ConfigRef;
104
41
  kind?: ExtensionKind;
105
42
  plugin: string;
106
43
  path: Array<string>;
107
44
  } |
108
- /**
109
- * Add a plugin factory call and its import to the `plugins` array.
110
- */
45
+ /** With `kind: 'parser'`, adds to `parsers`. A config without `parsers` gets the defaults written next to it, so they keep running. */
111
46
  {
112
47
  operation: typeof ConfigEditOperation.ADD_PLUGIN;
113
48
  config?: ConfigRef;
49
+ kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser;
114
50
  plugin: string;
115
51
  options?: Record<string, unknown>;
116
52
  } |
117
- /**
118
- * Comment the plugin call out, keeping its options in the file so enabling it again restores them.
119
- */
53
+ /** Deletes every call of a plugin, or a parser with `kind: 'parser'`, a disabled block included, and the imports nothing else uses. */
120
54
  {
55
+ operation: typeof ConfigEditOperation.REMOVE_EXTENSION;
56
+ config?: ConfigRef;
57
+ kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser;
58
+ plugin: string;
59
+ } | {
121
60
  operation: typeof ConfigEditOperation.DISABLE_PLUGIN;
122
61
  config?: ConfigRef;
123
62
  plugin: string;
124
- } |
125
- /**
126
- * Uncomment a plugin call a previous `disable-plugin` commented out.
127
- */
128
- {
63
+ } | {
129
64
  operation: typeof ConfigEditOperation.ENABLE_PLUGIN;
130
65
  config?: ConfigRef;
131
66
  plugin: string;
132
- } |
133
- /**
134
- * Point the config's `input` at a spec. The agent writes a document to `openapi.yaml` (or
135
- * `openapi.json`, and `openapi-<entry>` for a later entry) in its project and points `input` there.
136
- * Refused without `allowSaveInput`, and a managed agent takes only a document, a URL, or a `git+` file.
137
- */
138
- {
67
+ } | {
139
68
  operation: typeof ConfigEditOperation.SET_INPUT;
140
69
  config?: ConfigRef;
141
70
  input: string;
142
- } |
143
- /** Write a literal inside the root `output` object, for the members `JSONKubbConfig.output` takes. */
144
- {
71
+ } | {
145
72
  operation: typeof ConfigEditOperation.SET_OUTPUT;
146
73
  config?: ConfigRef;
147
74
  path: Array<string>;
148
75
  value: unknown;
149
- } |
150
- /** Drop a member of the root `output` object that `set-output` may write. */
151
- {
76
+ } | {
152
77
  operation: typeof ConfigEditOperation.REMOVE_OUTPUT;
153
78
  config?: ConfigRef;
154
79
  path: Array<string>;
155
80
  };
156
- /** The top-level keys of an object in the config file, as {@link PluginView.options} describes. */
81
+ /** Option keys, each with whether Studio may write it. `locked` lists the code paths inside a partly literal object. */
157
82
  type OptionsView = Record<string, {
158
83
  literal: boolean;
159
84
  value?: OptionValue;
160
85
  locked?: Array<Array<string>>;
161
86
  }>;
162
- /**
163
- * A factory call the agent found in a `defineConfig(...)`: a plugin in `plugins`, the `adapter`, or
164
- * a parser in `parsers`.
165
- */
87
+ /** A factory call in `plugins`, `adapter`, or `parsers`. `importName` is the local name, alias included. */
166
88
  type PluginView = {
167
- /**
168
- * Local identifier of the factory in the file, e.g. `pluginTs`. This is the alias when the plugin
169
- * was imported under one.
170
- */
171
89
  importName: string;
172
- /**
173
- * Module the factory is imported from, e.g. `@kubb/plugin-ts`.
174
- */
175
90
  packageName: string;
176
- /**
177
- * Top-level option keys, each flagged with whether the agent may write it and, when it can, the
178
- * value found in the file. An option marked `literal: false` holds a function or a reference the
179
- * agent will not overwrite, so Studio shows the control disabled rather than hiding it, and
180
- * `value` is absent since there is nothing safe to display as the current value.
181
- *
182
- * An object option that holds code in only some members, such as
183
- * `output: { path: './gen', banner: () => '' }`, also carries `value` with its literal members
184
- * and `locked` with the paths of the members that are code, relative to the option
185
- * (`[['banner']]`). A `set` at any deeper path outside `locked` succeeds, so Studio can edit
186
- * `output.path` there.
187
- */
188
91
  options: OptionsView;
189
- /**
190
- * Set when the plugin call is commented out in the file. Its options stay on disk but are not
191
- * readable, so `options` is empty until it is enabled again.
192
- */
92
+ /** The call is commented out by `disable-plugin`. */
193
93
  disabled?: true;
194
94
  };
195
- /**
196
- * One `defineConfig(...)` entry. A config file that exports a single object has exactly one.
197
- */
198
95
  type ConfigView = {
199
- /**
200
- * The entry's `name`, when it sets one. Studio labels the config picker with it.
201
- */
202
96
  name?: string;
203
- /**
204
- * Each plugin call in the entry, with its top-level option keys.
205
- */
206
97
  plugins: Array<PluginView>;
207
- /**
208
- * The `adapter` call, when the entry sets one through an imported factory.
209
- */
210
98
  adapter?: PluginView;
211
- /**
212
- * The parser calls in `parsers`, when the entry lists any through imported factories.
213
- */
214
99
  parsers?: Array<PluginView>;
215
- /** The root `output` members Studio may set. Absent when `output` is not an object literal. */
100
+ /** The root `output` members Studio may set, absent when `output` is not an object literal. */
216
101
  output?: OptionsView;
217
102
  };
218
- /**
219
- * What the agent found in the user's config file, so Studio knows which controls it may offer.
220
- * Absent when the agent could not read the file at all.
221
- */
103
+ /** The config file as Studio may edit it, or why it cannot. */
222
104
  type ConfigFileView = {
223
105
  managed: true;
224
- /**
225
- * One entry per config the file exports, in source order. Every {@link ConfigEdit} names
226
- * which of these it targets through its `config` field.
227
- */
228
106
  configs: Array<ConfigView>;
229
107
  } | {
230
108
  managed: false;
231
- /**
232
- * Why the file is outside what the agent edits, for example a default export that is not a
233
- * `defineConfig(...)` call. Studio shows this and offers no property-level controls.
234
- */
235
109
  reason: string;
236
110
  };
237
- /**
238
- * Outcome of a single {@link ConfigEdit}, returned in a {@link SaveResult}.
239
- */
240
111
  type ConfigEditOutcome = {
241
112
  edit: ConfigEdit;
242
113
  applied: boolean;
114
+ reason?: string;
115
+ };
116
+ type ExtensionEntry = {
117
+ package: string;
118
+ version: string;
119
+ manifest: ExtensionManifest;
120
+ /** Ships with `kubb` at its version, so updating `kubb` updates it and `kubb update` cannot. */
121
+ bundled?: true;
122
+ };
123
+ /** Installed extensions by package name, the only ones Studio may import besides `@kubb/plugin-*`. */
124
+ type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>;
125
+ //#endregion
126
+ //#region ../../internals/shared/src/configFile/configFile.d.ts
127
+ /** Applies edits in place, touching only the text each targets. A refused edit is reported and the rest still run. */
128
+ declare function editConfig({ source, edits, extensions }: {
129
+ source: string;
130
+ edits: Array<ConfigEdit>;
131
+ extensions?: InstalledExtensions;
132
+ }): {
133
+ source: string;
134
+ outcomes: Array<ConfigEditOutcome>;
135
+ changed: boolean;
136
+ };
137
+ /** Applies `edits` to `filePath`, writing only when something changed. */
138
+ declare function editConfigFile({ filePath, edits, extensions }: {
139
+ filePath: string;
140
+ edits: Array<ConfigEdit>;
141
+ extensions?: InstalledExtensions;
142
+ }): Promise<{
143
+ source: string;
144
+ outcomes: Array<ConfigEditOutcome>;
145
+ changed: boolean;
146
+ }>;
147
+ //#endregion
148
+ //#region src/protocol.d.ts
149
+ /**
150
+ * JSON-serializable Kubb config exchanged over RPC. A live `kubb/kit` config holds
151
+ * functions and class instances that cannot survive JSON, so both sides pass this flattened shape
152
+ * and rebuild the real config from it.
153
+ */
154
+ type JSONKubbConfig = {
243
155
  /**
244
- * Why the edit was refused, absent when it was applied.
156
+ * Plugins with their serialized options. `name` is the package name (e.g. `@kubb/plugin-ts`)
157
+ * and `options` is an opaque blob the agent forwards unchanged to the plugin factory. An entry
158
+ * with `disabled: true` is dropped even when the disk config's `plugins` array still lists it.
245
159
  */
246
- reason?: string;
160
+ plugins?: Array<{
161
+ name: string;
162
+ options?: object;
163
+ disabled?: boolean;
164
+ }>;
165
+ /**
166
+ * Raw OpenAPI / Swagger spec content (YAML or JSON string), never a file path.
167
+ * Required by a 'sandbox' agent, which has no disk config of its own and refuses anything else.
168
+ * A 'managed' agent also takes a URL or a `git+<repo>#<ref>:<path>` input, and falls back to its disk config without one.
169
+ * Any other agent always reads its spec from disk, so this is ignored with a `kubb:warn`.
170
+ */
171
+ input?: string;
172
+ /**
173
+ * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options
174
+ * and re-applied through the same adapter factory, since an adapter instance's functions
175
+ * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.
176
+ */
177
+ adapter?: object;
178
+ /**
179
+ * Parser option overrides from Studio, matched to the disk config's parsers by `name` and
180
+ * re-applied through each parser's factory, the same way `adapter` is.
181
+ */
182
+ parsers?: Array<{
183
+ name: string;
184
+ options?: object;
185
+ }>;
186
+ /** Root `output` overrides for `barrel`, `format`, `lint`, `clean`, and `defaultBanner`. Other members are ignored. */
187
+ output?: object;
188
+ /**
189
+ * Which `defineConfig(...)` entry to generate from. Omitted runs the first one.
190
+ */
191
+ config?: ConfigRef;
247
192
  };
248
193
  /**
249
194
  * The public, JSON-safe subset of Kubb lifecycle hooks. The core registry remains extensible;
@@ -455,6 +400,16 @@ type UpdateExtensionsResult = {
455
400
  updated: boolean;
456
401
  reason?: string;
457
402
  };
403
+ /** Asks the agent to run `kubb remove <id> --yes`. `requestedBy` as for {@link GenerateInput}. */
404
+ type RemoveExtensionInput = {
405
+ id: string;
406
+ requestedBy?: string;
407
+ };
408
+ /** `removed` is false when the agent refused or `kubb remove` failed, with `reason` saying why. */
409
+ type RemoveExtensionResult = {
410
+ removed: boolean;
411
+ reason?: string;
412
+ };
458
413
  /**
459
414
  * Reads an immutable output set kept on disk, from a generation or the initial connection.
460
415
  */
@@ -613,6 +568,8 @@ type AgentApi = {
613
568
  installExtension: (input: InstallExtensionInput) => Promise<InstallExtensionResult>;
614
569
  /** Refused without `allowUpdate`. Installs packages only, so `kubb.config.ts` stays as it is. */
615
570
  updateExtensions: (input: UpdateExtensionsInput) => Promise<UpdateExtensionsResult>;
571
+ /** Refused without `allowRemove` and `allowConfigEdit`. An agent from before `removeExtension` rejects the call. */
572
+ removeExtension: (input: RemoveExtensionInput) => Promise<RemoveExtensionResult>;
616
573
  readFiles: (input: ReadFilesInput) => Promise<ReadFilesResult>;
617
574
  /**
618
575
  * Refused unless the agent was granted `allowRead`, like {@link AgentApi.readFiles}.
@@ -733,14 +690,6 @@ type ConfigEntryView = {
733
690
  options?: object;
734
691
  }>;
735
692
  };
736
- /** An installed extension package and the manifest it ships. */
737
- type ExtensionEntry = {
738
- package: string;
739
- version: string;
740
- manifest: ExtensionManifest;
741
- };
742
- /** Installed extension packages by package name, the only ones Studio may import besides `@kubb/plugin-*`. */
743
- type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>;
744
693
  /**
745
694
  * What an agent may do in the project it serves. Every one is off unless the host granted it, and
746
695
  * a sandbox narrows them further.
@@ -764,6 +713,8 @@ type AgentPermissions = {
764
713
  allowInstall: boolean;
765
714
  /** Whether the agent may run `kubb update` in the project, which installs newer extension versions and leaves `kubb.config.ts` alone. */
766
715
  allowUpdate: boolean;
716
+ /** Whether the agent may run `kubb remove` in the project, which edits `kubb.config.ts` and uninstalls packages. Needs `allowConfigEdit` as well. */
717
+ allowRemove: boolean;
767
718
  /** Whether the agent may keep the spec Studio sends: a document in `openapi.yaml` and `input` in `kubb.config.ts`. Needs `allowConfigEdit` as well. */
768
719
  allowSaveInput: boolean;
769
720
  /**
@@ -787,6 +738,7 @@ declare const AgentPermission: {
787
738
  readonly CONFIG_EDIT: 'allowConfigEdit';
788
739
  readonly INSTALL: 'allowInstall';
789
740
  readonly UPDATE: 'allowUpdate';
741
+ readonly REMOVE: 'allowRemove';
790
742
  readonly SAVE_INPUT: 'allowSaveInput';
791
743
  readonly EXEC: 'allowExec';
792
744
  };
@@ -879,5 +831,5 @@ type PublishedSnapshot = {
879
831
  branchChanges?: BranchSnapshotChanges;
880
832
  };
881
833
  //#endregion
882
- export { generationEventTypes as $, InstallExtensionResult as A, ReadDiffInput as B, GenerateInput as C, GenerationEventType as D, GenerationEventPayloads as E, MAX_SNAPSHOT_BYTES as F, ReadInputResult as G, ReadFilesInput as H, OptionValue as I, SnapshotChanges as J, SaveConfigInput as K, OptionsView as L, JSONKubbConfig as M, MAX_FILES_PER_REQUEST as N, GenerationRun as O, MAX_PAGE_LINES as P, UpdateExtensionsResult as Q, PluginView as R, FilePage as S, GenerationEvent as T, ReadFilesResult as U, ReadDiffResult as V, ReadInputInput as W, StudioApi as X, SnapshotUploadMetadata as Y, UpdateExtensionsInput as Z, ConnectMessagePayload as _, AgentConnectInfo as a, DiskOutput as b, AgentPermissions as c, ConfigEditOperation as d, ConfigEditOutcome as f, ConfigView as g, ConfigRef as h, AgentCloseCode as i, InstalledExtensions as j, InstallExtensionInput as k, BranchSnapshotChanges as l, ConfigFileView as m, AGENT_SOCKET_PATH as n, AgentMessage as o, ConfigEntryView as p, SaveResult as q, AgentApi as r, AgentPermission as s, AGENT_INSTANCE_HEADER as t, ConfigEdit as u, DiffHunk as v, GenerateResult as w, ExtensionEntry as x, DiffStats as y, PublishedSnapshot as z };
883
- //# sourceMappingURL=protocol-C4loKcxw.d.cts.map
834
+ export { ExtensionEntry as $, ReadDiffResult as A, SnapshotUploadMetadata as B, InstallExtensionResult as C, MAX_SNAPSHOT_BYTES as D, MAX_PAGE_LINES as E, RemoveExtensionInput as F, editConfig as G, UpdateExtensionsInput as H, RemoveExtensionResult as I, ConfigEditOperation as J, editConfigFile as K, SaveConfigInput as L, ReadFilesResult as M, ReadInputInput as N, PublishedSnapshot as O, ReadInputResult as P, ConfigView as Q, SaveResult as R, InstallExtensionInput as S, MAX_FILES_PER_REQUEST as T, UpdateExtensionsResult as U, StudioApi as V, generationEventTypes as W, ConfigFileView as X, ConfigEditOutcome as Y, ConfigRef as Z, GenerateResult as _, AgentConnectInfo as a, GenerationEventType as b, AgentPermissions as c, ConnectMessagePayload as d, InstalledExtensions as et, DiffHunk as f, GenerateInput as g, FilePage as h, AgentCloseCode as i, ReadFilesInput as j, ReadDiffInput as k, BranchSnapshotChanges as l, DiskOutput as m, AGENT_SOCKET_PATH as n, OptionsView as nt, AgentMessage as o, DiffStats as p, ConfigEdit as q, AgentApi as r, PluginView as rt, AgentPermission as s, AGENT_INSTANCE_HEADER as t, OptionValue as tt, ConfigEntryView as u, GenerationEvent as v, JSONKubbConfig as w, GenerationRun as x, GenerationEventPayloads as y, SnapshotChanges as z };
835
+ //# sourceMappingURL=protocol-DQTwqmNO.d.ts.map
@@ -0,0 +1,118 @@
1
+ //#region ../../internals/shared/src/configFile/types.ts
2
+ const extensionKinds = {
3
+ plugin: "plugin",
4
+ adapter: "adapter",
5
+ parser: "parser"
6
+ };
7
+ const ConfigEditOperation = {
8
+ SET_OPTION: "set-option",
9
+ REMOVE_OPTION: "remove-option",
10
+ ADD_PLUGIN: "add-plugin",
11
+ REMOVE_EXTENSION: "remove-extension",
12
+ DISABLE_PLUGIN: "disable-plugin",
13
+ ENABLE_PLUGIN: "enable-plugin",
14
+ SET_INPUT: "set-input",
15
+ SET_OUTPUT: "set-output",
16
+ REMOVE_OUTPUT: "remove-output"
17
+ };
18
+ //#endregion
19
+ //#region src/protocol.ts
20
+ /**
21
+ * The public, JSON-safe subset of Kubb lifecycle hooks. The core registry remains extensible;
22
+ * adding a core hook does not publish it to Studio until it is listed here and projected below.
23
+ */
24
+ const generationEventTypes = [
25
+ "kubb:plugin:start",
26
+ "kubb:plugin:end",
27
+ "kubb:build:start",
28
+ "kubb:build:end",
29
+ "kubb:files:processing:start",
30
+ "kubb:files:processing:update",
31
+ "kubb:files:processing:end",
32
+ "kubb:info",
33
+ "kubb:success",
34
+ "kubb:warn",
35
+ "kubb:error",
36
+ "kubb:diagnostic",
37
+ "kubb:generation:start",
38
+ "kubb:generation:end",
39
+ "kubb:generation:summary",
40
+ "kubb:lifecycle:start",
41
+ "kubb:lifecycle:end",
42
+ "kubb:format:start",
43
+ "kubb:format:end",
44
+ "kubb:lint:start",
45
+ "kubb:lint:end",
46
+ "kubb:hooks:start",
47
+ "kubb:hooks:end",
48
+ "kubb:hook:start",
49
+ "kubb:hook:line",
50
+ "kubb:hook:end"
51
+ ];
52
+ /**
53
+ * Why the agent refuses a request. Studio matches on these to answer with the right status.
54
+ */
55
+ const AgentMessage = {
56
+ GENERATION_IN_PROGRESS: "A generation is already in progress, please wait for it to finish",
57
+ INSTALL_IN_PROGRESS: "An extension install or update is running, please wait for it to finish",
58
+ SAVE_IN_PROGRESS: "The config is being saved, please wait for it to finish",
59
+ SANDBOX_INPUT_ONLY: "A sandbox agent generates only from the OpenAPI document content Studio sends, not from a file path or URL",
60
+ MANAGED_INPUT_KIND: "A managed agent generates from the OpenAPI document content, a URL, or a git file that Studio sends, not from a file path",
61
+ CONFIG_ENTRY_NOT_FOUND: "The config file has no entry at that position or with that name",
62
+ JOB_REQUIRED: "The request must name a job",
63
+ FILE_REQUEST_INVALID: "The request must name an output set and carry paths",
64
+ TOO_MANY_FILES: "Too many paths were requested at once",
65
+ INVALID_PAGE: "The requested file page is invalid",
66
+ DIFF_REQUEST_INVALID: "The request must name a job, a base, and a path",
67
+ HASHES_ONLY: "This agent kept only the hashes of that job",
68
+ /**
69
+ * A read for a job whose files the agent no longer keeps.
70
+ */
71
+ GENERATION_GONE: "The files of this generation are no longer kept on the agent, run the generation again",
72
+ READ_NOT_ALLOWED: "The agent was not granted permission to read generated files",
73
+ /**
74
+ * Reading the parsed spec is its own permission.
75
+ */
76
+ READ_AST_NOT_ALLOWED: "The agent was not granted permission to read the parsed spec",
77
+ NO_INPUT: "This job kept no API input"
78
+ };
79
+ /**
80
+ * Close codes Studio sends when it ends an agent socket on purpose. `UNAUTHORIZED` means the token
81
+ * was refused, so pair again. `SUPERSEDED` and `INCOMPATIBLE` mean stop. Any other code, `1011`
82
+ * included, is an ordinary drop and the agent reconnects.
83
+ */
84
+ const AgentCloseCode = {
85
+ UNAUTHORIZED: 4001,
86
+ SUPERSEDED: 4002,
87
+ INCOMPATIBLE: 4003
88
+ };
89
+ const AGENT_SOCKET_PATH = "/api/agent/socket";
90
+ /**
91
+ * Optional header naming the process a socket belongs to, for agents that run several processes.
92
+ */
93
+ const AGENT_INSTANCE_HEADER = "x-kubb-instance-id";
94
+ /**
95
+ * How many files a single `readFiles` request may ask for at once.
96
+ */
97
+ const MAX_FILES_PER_REQUEST = 50;
98
+ /** Most lines one page may ask for. */
99
+ const MAX_PAGE_LINES = 2e3;
100
+ const MAX_SNAPSHOT_BYTES = 52428800;
101
+ /**
102
+ * The keys of {@link AgentPermissions}, such as the permission a refused request names.
103
+ */
104
+ const AgentPermission = {
105
+ READ: "allowRead",
106
+ READ_AST: "allowReadAst",
107
+ WRITE: "allowWrite",
108
+ CONFIG_EDIT: "allowConfigEdit",
109
+ INSTALL: "allowInstall",
110
+ UPDATE: "allowUpdate",
111
+ REMOVE: "allowRemove",
112
+ SAVE_INPUT: "allowSaveInput",
113
+ EXEC: "allowExec"
114
+ };
115
+ //#endregion
116
+ export { AgentPermission as a, MAX_SNAPSHOT_BYTES as c, extensionKinds as d, AgentMessage as i, generationEventTypes as l, AGENT_SOCKET_PATH as n, MAX_FILES_PER_REQUEST as o, AgentCloseCode as r, MAX_PAGE_LINES as s, AGENT_INSTANCE_HEADER as t, ConfigEditOperation as u };
117
+
118
+ //# sourceMappingURL=protocol-DQnAN8NE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol-DQnAN8NE.js","names":[],"sources":["../../../internals/shared/src/configFile/types.ts","../src/protocol.ts"],"sourcesContent":["import type { ExtensionKind, ExtensionManifest } from '@kubb/core'\n\n/** Which `defineConfig(...)` entry an edit targets: its index or `name`, the first entry when omitted. */\nexport type ConfigRef = string | number\n\n/** A literal option value that survives a JSON round trip. */\nexport type OptionValue = string | number | boolean | null | Array<OptionValue> | { [key: string]: OptionValue }\n\nexport const extensionKinds = { plugin: 'plugin', adapter: 'adapter', parser: 'parser' } as const satisfies Record<string, ExtensionKind>\n\nexport const ConfigEditOperation = {\n SET_OPTION: 'set-option',\n REMOVE_OPTION: 'remove-option',\n ADD_PLUGIN: 'add-plugin',\n REMOVE_EXTENSION: 'remove-extension',\n DISABLE_PLUGIN: 'disable-plugin',\n ENABLE_PLUGIN: 'enable-plugin',\n SET_INPUT: 'set-input',\n SET_OUTPUT: 'set-output',\n REMOVE_OUTPUT: 'remove-output',\n} as const\nexport type ConfigEditOperation = (typeof ConfigEditOperation)[keyof typeof ConfigEditOperation]\n\n/**\n * One change to `kubb.config.ts`. `plugin` is the package name, and `kind` picks the `plugins` entry\n * (default), the `adapter`, or a `parsers` entry. `path` walks nested option objects.\n */\nexport type ConfigEdit =\n | { operation: typeof ConfigEditOperation.SET_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OPTION; config?: ConfigRef; kind?: ExtensionKind; plugin: string; path: Array<string> }\n /** With `kind: 'parser'`, adds to `parsers`. A config without `parsers` gets the defaults written next to it, so they keep running. */\n | {\n operation: typeof ConfigEditOperation.ADD_PLUGIN\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n options?: Record<string, unknown>\n }\n /** Deletes every call of a plugin, or a parser with `kind: 'parser'`, a disabled block included, and the imports nothing else uses. */\n | {\n operation: typeof ConfigEditOperation.REMOVE_EXTENSION\n config?: ConfigRef\n kind?: typeof extensionKinds.plugin | typeof extensionKinds.parser\n plugin: string\n }\n | { operation: typeof ConfigEditOperation.DISABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.ENABLE_PLUGIN; config?: ConfigRef; plugin: string }\n | { operation: typeof ConfigEditOperation.SET_INPUT; config?: ConfigRef; input: string }\n | { operation: typeof ConfigEditOperation.SET_OUTPUT; config?: ConfigRef; path: Array<string>; value: unknown }\n | { operation: typeof ConfigEditOperation.REMOVE_OUTPUT; config?: ConfigRef; path: Array<string> }\n\n/** Option keys, each with whether Studio may write it. `locked` lists the code paths inside a partly literal object. */\nexport type OptionsView = Record<string, { literal: boolean; value?: OptionValue; locked?: Array<Array<string>> }>\n\n/** A factory call in `plugins`, `adapter`, or `parsers`. `importName` is the local name, alias included. */\nexport type PluginView = {\n importName: string\n packageName: string\n options: OptionsView\n /** The call is commented out by `disable-plugin`. */\n disabled?: true\n}\n\nexport type ConfigView = {\n name?: string\n plugins: Array<PluginView>\n adapter?: PluginView\n parsers?: Array<PluginView>\n /** The root `output` members Studio may set, absent when `output` is not an object literal. */\n output?: OptionsView\n}\n\n/** The config file as Studio may edit it, or why it cannot. */\nexport type ConfigFileView = { managed: true; configs: Array<ConfigView> } | { managed: false; reason: string }\n\nexport type ConfigEditOutcome = {\n edit: ConfigEdit\n applied: boolean\n reason?: string\n}\n\nexport type ExtensionEntry = {\n package: string\n version: string\n manifest: ExtensionManifest\n /** Ships with `kubb` at its version, so updating `kubb` updates it and `kubb update` cannot. */\n bundled?: true\n}\n\n/** Installed extensions by package name, the only ones Studio may import besides `@kubb/plugin-*`. */\nexport type InstalledExtensions = ReadonlyMap<string, ExtensionEntry>\n","import type { InputNode } from '@kubb/ast'\nimport type { KubbHooks } from '@kubb/core'\nimport type { ConfigEdit, ConfigEditOutcome, ConfigFileView, ConfigRef, ExtensionEntry } from '@internals/shared'\n\nexport {\n ConfigEditOperation,\n type ConfigEdit,\n type ConfigEditOutcome,\n type ConfigFileView,\n type ConfigRef,\n type ConfigView,\n type ExtensionEntry,\n type InstalledExtensions,\n type OptionsView,\n type OptionValue,\n type PluginView,\n} from '@internals/shared'\n\n/**\n * JSON-serializable Kubb config exchanged over RPC. A live `kubb/kit` config holds\n * functions and class instances that cannot survive JSON, so both sides pass this flattened shape\n * and rebuild the real config from it.\n */\nexport type JSONKubbConfig = {\n /**\n * Plugins with their serialized options. `name` is the package name (e.g. `@kubb/plugin-ts`)\n * and `options` is an opaque blob the agent forwards unchanged to the plugin factory. An entry\n * with `disabled: true` is dropped even when the disk config's `plugins` array still lists it.\n */\n plugins?: Array<{\n name: string\n options?: object\n disabled?: boolean\n }>\n /**\n * Raw OpenAPI / Swagger spec content (YAML or JSON string), never a file path.\n * Required by a 'sandbox' agent, which has no disk config of its own and refuses anything else.\n * A 'managed' agent also takes a URL or a `git+<repo>#<ref>:<path>` input, and falls back to its disk config without one.\n * Any other agent always reads its spec from disk, so this is ignored with a `kubb:warn`.\n */\n input?: string\n /**\n * Adapter option overrides sent from Studio UI. Merged into the disk config's adapter options\n * and re-applied through the same adapter factory, since an adapter instance's functions\n * (`parse`, `getImports`, ...) can't survive JSON serialization over the WebSocket.\n */\n adapter?: object\n /**\n * Parser option overrides from Studio, matched to the disk config's parsers by `name` and\n * re-applied through each parser's factory, the same way `adapter` is.\n */\n parsers?: Array<{\n name: string\n options?: object\n }>\n /** Root `output` overrides for `barrel`, `format`, `lint`, `clean`, and `defaultBanner`. Other members are ignored. */\n output?: object\n /**\n * Which `defineConfig(...)` entry to generate from. Omitted runs the first one.\n */\n config?: ConfigRef\n}\n\n/**\n * The public, JSON-safe subset of Kubb lifecycle hooks. The core registry remains extensible;\n * adding a core hook does not publish it to Studio until it is listed here and projected below.\n */\nexport const generationEventTypes = [\n 'kubb:plugin:start',\n 'kubb:plugin:end',\n 'kubb:build:start',\n 'kubb:build:end',\n 'kubb:files:processing:start',\n 'kubb:files:processing:update',\n 'kubb:files:processing:end',\n 'kubb:info',\n 'kubb:success',\n 'kubb:warn',\n 'kubb:error',\n 'kubb:diagnostic',\n 'kubb:generation:start',\n 'kubb:generation:end',\n 'kubb:generation:summary',\n 'kubb:lifecycle:start',\n 'kubb:lifecycle:end',\n 'kubb:format:start',\n 'kubb:format:end',\n 'kubb:lint:start',\n 'kubb:lint:end',\n 'kubb:hooks:start',\n 'kubb:hooks:end',\n 'kubb:hook:start',\n 'kubb:hook:line',\n 'kubb:hook:end',\n] as const satisfies ReadonlyArray<keyof KubbHooks>\n\n/**\n * One of the lifecycle hooks {@link generationEventTypes} publishes.\n */\nexport type GenerationEventType = (typeof generationEventTypes)[number]\n\n/**\n * The JSON-safe payload each published event carries. These are flattened on purpose: a core hook\n * context holds live objects (a `Config`, a `Storage`) that cannot cross the wire.\n */\nexport type GenerationEventPayloads = {\n 'kubb:plugin:start': [ctx: { plugin: { name: string } }]\n 'kubb:plugin:end': [ctx: { plugin: { name: string }; duration: number; success: boolean }]\n 'kubb:build:start': [ctx: { config: { name?: string }; adapter: { name: string } }]\n 'kubb:build:end': [ctx: { files: Array<{ path: string; name: string }>; outputDir: string }]\n 'kubb:files:processing:start': [ctx: { total: number }]\n 'kubb:files:processing:update': [\n ctx: {\n files: Array<{\n file: string\n processed: number\n total: number\n percentage: number\n }>\n },\n ]\n 'kubb:files:processing:end': [ctx: { total: number }]\n 'kubb:info': [ctx: { message: string; info?: string }]\n 'kubb:success': [ctx: { message: string; info?: string }]\n 'kubb:warn': [ctx: { message: string; info?: string }]\n 'kubb:error': [ctx: { message: string; stack?: string }]\n 'kubb:diagnostic': [\n ctx: {\n code: string\n message: string\n severity: string\n location?: { kind: string; pointer?: string; ref?: string }\n help?: string\n plugin?: string\n stack?: string\n },\n ]\n 'kubb:generation:start': [ctx: { name?: string; plugins: number }]\n /**\n * A run finished. See `kubb:build:end` for files, `kubb:generation:summary` for the count, and\n * `readFiles` for contents.\n */\n 'kubb:generation:end': []\n 'kubb:generation:summary': [ctx: { duration: number; fileCount: number; failedPlugins: number; status: 'success' | 'failed' }]\n 'kubb:lifecycle:start': []\n 'kubb:lifecycle:end': []\n 'kubb:format:start': []\n 'kubb:format:end': []\n 'kubb:lint:start': []\n 'kubb:lint:end': []\n 'kubb:hooks:start': []\n 'kubb:hooks:end': []\n 'kubb:hook:start': [ctx: { id?: string; command: string; args?: Array<string> }]\n 'kubb:hook:line': [ctx: { id: string; line: string }]\n 'kubb:hook:end': [\n ctx: {\n id?: string\n command: string\n args?: Array<string>\n success: boolean\n error?: { message: string; stack?: string }\n },\n ]\n}\n\n/**\n * Versioned envelope around one lifecycle event. Cap'n Web streams preserve the order the agent\n * emitted them in, so the receiver replays a run by reading the stream straight through.\n */\nexport type GenerationEvent = {\n [Type in GenerationEventType]: { type: Type; data: GenerationEventPayloads[Type] }\n}[GenerationEventType] & {\n version: 1\n jobId: string\n timestamp: number\n}\n\n/**\n * Asks the agent to run one generation. `jobId` tags every event the run emits so a caller\n * watching several runs can tell them apart. `requestedBy` names the Studio user in the agent's\n * command log, and Studio leaves it out for a shared agent.\n */\nexport type GenerateInput = {\n jobId: string\n config: JSONKubbConfig\n /**\n * Display name of the Studio user who asked for the run, shown in the agent's job log.\n */\n requestedBy?: string\n /**\n * A short-lived `Authorization` header value that a managed agent sends with the git fetch of a `git+` input, to its origin only.\n */\n gitAuth?: { authorization: string }\n}\n\n/**\n * What a finished run produced.\n */\nexport type GenerateResult = {\n status: 'success' | 'failed'\n /**\n * Paths of the generated files, relative to the output directory.\n */\n files: Array<string>\n fileCount: number\n /**\n * Content fingerprint per file in `files`, to tell changed files apart without reading them.\n */\n hashes: Record<string, string>\n}\n\n/**\n * Asks the agent to apply a batch of edits to the config file on disk. `requestedBy` as for {@link GenerateInput}.\n */\nexport type SaveConfigInput = {\n edits: Array<ConfigEdit>\n /**\n * Display name of the Studio user who asked for the save, shown in the agent's job log.\n */\n requestedBy?: string\n}\n\n/**\n * Per-edit outcomes. `changed` is false when every edit was a no-op, so a caller can skip reloading.\n */\nexport type SaveResult = { outcomes: Array<ConfigEditOutcome>; changed: boolean }\n\n/** Asks the agent to run `kubb add <id>`: `owner/slug`, or a bare `slug` for an official extension. `requestedBy` as for {@link GenerateInput}. */\nexport type InstallExtensionInput = { id: string; requestedBy?: string }\n\n/** `installed` is false when the agent refused or `kubb add` failed, with `reason` saying why. */\nexport type InstallExtensionResult = { installed: boolean; reason?: string }\n\n/** Asks the agent to run `kubb update [ids] --yes`. Empty `ids` updates every installed extension the registry lists. */\nexport type UpdateExtensionsInput = { ids?: Array<string>; requestedBy?: string }\n\n/** `updated` is false when the agent refused or `kubb update` failed, with `reason` saying why. */\nexport type UpdateExtensionsResult = { updated: boolean; reason?: string }\n\n/** Asks the agent to run `kubb remove <id> --yes`. `requestedBy` as for {@link GenerateInput}. */\nexport type RemoveExtensionInput = { id: string; requestedBy?: string }\n\n/** `removed` is false when the agent refused or `kubb remove` failed, with `reason` saying why. */\nexport type RemoveExtensionResult = { removed: boolean; reason?: string }\n\n/**\n * Reads an immutable output set kept on disk, from a generation or the initial connection.\n */\nexport type ReadFilesInput = {\n jobId: string\n paths: Array<string>\n cursor?: number\n limit?: number\n}\n\n/**\n * Where a paged read stands for one file: the cursor of the next page, `null` after the last one.\n */\nexport type FilePage = { nextCursor: number | null; totalLines: number }\n\n/**\n * What a file read returns. `pages` is set only for a paged read.\n */\nexport type ReadFilesResult = { files: Record<string, string>; pages?: Record<string, FilePage> }\n\n/**\n * Asks for one page of a file's line diff between two kept sets, so a large file never leaves the agent whole.\n * `jobId`'s `output` is the newer side, `base` the older one. `cursor` and `limit` page the patch lines.\n */\nexport type ReadDiffInput = { jobId: string; path: string; base: { jobId: string }; cursor?: number; limit: number }\n\n/**\n * One hunk of a diff page, with its `@@` header. Pages hold whole hunks, and only a hunk longer than a page is\n * split: its parts keep `index` and the header.\n */\nexport type DiffHunk = { index: number; oldStart: number; oldLines: number; newStart: number; newLines: number; lines: Array<string> }\n\n/**\n * The size of the whole diff, sent with every page, so a viewer can summarize it before reading every page.\n */\nexport type DiffStats = {\n additions: number\n deletions: number\n hunks: number\n /**\n * Patch lines in all hunks, the range `cursor` pages through.\n */\n lines: number\n /**\n * True when part of the diff ran out of time and shows as one block that replaces those lines.\n */\n coarse: boolean\n}\n\n/**\n * One page of a diff. `hasBase` is false, and the page empty, when the base set does not hold the path.\n */\nexport type ReadDiffResult = { hunks: Array<DiffHunk>; nextCursor: number | null; hasBase: boolean; stats: DiffStats }\n\n/**\n * Asks for the Kubb AST one job parsed its spec into. A job the agent no longer keeps fails with {@link AgentMessage.GENERATION_GONE}.\n */\nexport type ReadInputInput = { jobId: string }\n\n/**\n * The job's `InputNode`, as JSON. A ref schema names its target, which `input.schemas` holds, without a copy.\n */\nexport type ReadInputResult = { input: InputNode }\n\n/**\n * Why the agent refuses a request. Studio matches on these to answer with the right status.\n */\nexport const AgentMessage = {\n GENERATION_IN_PROGRESS: 'A generation is already in progress, please wait for it to finish',\n INSTALL_IN_PROGRESS: 'An extension install or update is running, please wait for it to finish',\n SAVE_IN_PROGRESS: 'The config is being saved, please wait for it to finish',\n SANDBOX_INPUT_ONLY: 'A sandbox agent generates only from the OpenAPI document content Studio sends, not from a file path or URL',\n MANAGED_INPUT_KIND: 'A managed agent generates from the OpenAPI document content, a URL, or a git file that Studio sends, not from a file path',\n CONFIG_ENTRY_NOT_FOUND: 'The config file has no entry at that position or with that name',\n JOB_REQUIRED: 'The request must name a job',\n FILE_REQUEST_INVALID: 'The request must name an output set and carry paths',\n TOO_MANY_FILES: 'Too many paths were requested at once',\n INVALID_PAGE: 'The requested file page is invalid',\n DIFF_REQUEST_INVALID: 'The request must name a job, a base, and a path',\n HASHES_ONLY: 'This agent kept only the hashes of that job',\n /**\n * A read for a job whose files the agent no longer keeps.\n */\n GENERATION_GONE: 'The files of this generation are no longer kept on the agent, run the generation again',\n READ_NOT_ALLOWED: 'The agent was not granted permission to read generated files',\n /**\n * Reading the parsed spec is its own permission.\n */\n READ_AST_NOT_ALLOWED: 'The agent was not granted permission to read the parsed spec',\n NO_INPUT: 'This job kept no API input',\n} as const\nexport type AgentMessage = (typeof AgentMessage)[keyof typeof AgentMessage]\n\n/**\n * A generation in flight. Cap'n Web keeps the three calls pointed at the same run, so a caller can\n * read `events()` while `result()` is still pending and `cancel()` stops it early.\n */\nexport type GenerationRun = {\n events: () => Promise<ReadableStream<GenerationEvent>>\n result: () => Promise<GenerateResult>\n cancel: () => Promise<void>\n}\n\n/**\n * What Studio knows about the agent on the other end of a socket. Studio passes it with every\n * {@link AgentApi.connect} call, so it stays the authority on whether the agent is a sandbox.\n */\nexport type AgentConnectInfo = {\n /**\n * A shared `sandbox` or `global` agent. It keeps generations on temporary disk, runs each job in a\n * temporary root, and generates from the spec Studio sends without editing a project or its config.\n */\n sandbox: boolean\n /**\n * A `managed` agent Studio hosts for the organization. It has no project spec on disk, so it\n * may generate from a spec Studio sends: the content, a URL, or a git file.\n */\n managed?: boolean\n agentSlug: string\n /**\n * Absent for a sandbox or global agent, which belongs to no organization.\n */\n organizationSlug?: string\n studioVersion: string\n}\n\n/**\n * Operations Studio invokes on an agent over its socket.\n */\nexport type AgentApi = {\n /**\n * The first call on every socket, and again whenever Studio needs the current config.\n */\n connect: (info: AgentConnectInfo) => Promise<ConnectMessagePayload>\n startGeneration: (input: GenerateInput) => GenerationRun\n saveConfig: (input: SaveConfigInput) => Promise<SaveResult>\n /** Refused without `allowInstall` and `allowConfigEdit`. An agent from before `installExtension` rejects the call. */\n installExtension: (input: InstallExtensionInput) => Promise<InstallExtensionResult>\n /** Refused without `allowUpdate`. Installs packages only, so `kubb.config.ts` stays as it is. */\n updateExtensions: (input: UpdateExtensionsInput) => Promise<UpdateExtensionsResult>\n /** Refused without `allowRemove` and `allowConfigEdit`. An agent from before `removeExtension` rejects the call. */\n removeExtension: (input: RemoveExtensionInput) => Promise<RemoveExtensionResult>\n readFiles: (input: ReadFilesInput) => Promise<ReadFilesResult>\n /**\n * Refused unless the agent was granted `allowRead`, like {@link AgentApi.readFiles}.\n */\n readInput: (input: ReadInputInput) => Promise<ReadInputResult>\n /**\n * Refused unless the agent was granted `allowRead`, like {@link AgentApi.readFiles}.\n */\n readDiff: (input: ReadDiffInput) => Promise<ReadDiffResult>\n}\n\n/**\n * Operations an agent invokes on Studio over its socket.\n */\nexport type StudioApi = {\n /**\n * Keeps the connection alive. A ping that does not settle in time makes the agent reconnect.\n */\n ping: () => Promise<void>\n}\n\n/**\n * Close codes Studio sends when it ends an agent socket on purpose. `UNAUTHORIZED` means the token\n * was refused, so pair again. `SUPERSEDED` and `INCOMPATIBLE` mean stop. Any other code, `1011`\n * included, is an ordinary drop and the agent reconnects.\n */\nexport const AgentCloseCode = {\n UNAUTHORIZED: 4001,\n SUPERSEDED: 4002,\n INCOMPATIBLE: 4003,\n} as const\n\nexport const AGENT_SOCKET_PATH = '/api/agent/socket'\n\n/**\n * Optional header naming the process a socket belongs to, for agents that run several processes.\n */\nexport const AGENT_INSTANCE_HEADER = 'x-kubb-instance-id'\n\n/**\n * How many files a single `readFiles` request may ask for at once.\n */\nexport const MAX_FILES_PER_REQUEST = 50\n\n/** Most lines one page may ask for. */\nexport const MAX_PAGE_LINES = 2000\n\nexport const MAX_SNAPSHOT_BYTES = 50 * 1024 * 1024\n\n/**\n * Connection payload returned by {@link AgentApi.connect}. Carries only what Studio renders, with\n * everything about the config under one key.\n */\nexport type ConnectMessagePayload = {\n /**\n * Always sent, so a mismatch is visible on both sides: Studio badges the connection with these\n * and the host prints them.\n */\n versions: {\n /**\n * The version of the `@kubb/studio` runtime the agent runs.\n */\n kubb: string\n /**\n * The version of the host itself (the `kubb.agent` package or the `kubb` CLI).\n */\n agent: string\n }\n /**\n * The agent's project root. This is the workspace that generation runs against.\n */\n root: string\n /**\n * The baseline every generation starts from.\n */\n config: {\n /**\n * The config path as the host gave it, relative to `root` unless absolute.\n */\n path: string\n /**\n * What the agent read out of the config file itself, so Studio can render the plugin editor\n * against the real file. Absent when the agent could not read it, or was not granted\n * `allowConfigEdit`.\n */\n file?: ConfigFileView\n /** Installed packages that ship a `kubb-extension.json`, including plugins the config does not use yet. */\n extensions?: Array<ExtensionEntry>\n /** Every entry the config exports, in source order. */\n configs: Array<ConfigEntryView>\n }\n permissions: AgentPermissions\n}\n\nexport type DiskOutput = {\n jobId: string\n files: Array<string>\n hashes: Record<string, string>\n}\n\n/**\n * One `defineConfig(...)` entry as the agent runs it. Every option is a JSON copy: anything JSON cannot\n * hold, such as a function, is left out. A plugin defined in the project keeps its own `name`.\n */\nexport type ConfigEntryView = {\n name?: string\n /** The input file path or URL, without credentials. Omitted for an inline or parsed document. */\n input?: string\n /** The output directory as the entry gives it, relative to the project root unless absolute. */\n output: string\n /** The root `output` members Studio may set, as a JSON copy. */\n outputOptions?: object\n /**\n * The output directory's current file list, readable through `readFiles` without generating.\n * Absent for a sandbox or when the host has not granted `allowRead`.\n */\n disk?: DiskOutput\n plugins: Array<{\n name: string\n options?: object\n }>\n adapter?: {\n name: string\n options?: object\n }\n parsers: Array<{\n name: string\n options?: object\n }>\n}\n\n/**\n * What an agent may do in the project it serves. Every one is off unless the host granted it, and\n * a sandbox narrows them further.\n */\nexport type AgentPermissions = {\n /**\n * Whether the agent writes generated files to disk. Always false for a sandbox.\n */\n allowWrite: boolean\n /**\n * Whether the agent runs the formatter, the linter, and `output.postGenerate` as child\n * processes after a generation.\n */\n allowExec: boolean\n /**\n * Whether the agent may change plugin options in the user's `kubb.config.ts`. Separate from\n * `allowWrite`, which covers generated output: this one edits a hand-authored source file.\n */\n allowConfigEdit: boolean\n /** Whether the agent may run `kubb add` in the project, which also edits `kubb.config.ts`. Needs `allowConfigEdit` as well. */\n allowInstall: boolean\n /** Whether the agent may run `kubb update` in the project, which installs newer extension versions and leaves `kubb.config.ts` alone. */\n allowUpdate: boolean\n /** Whether the agent may run `kubb remove` in the project, which edits `kubb.config.ts` and uninstalls packages. Needs `allowConfigEdit` as well. */\n allowRemove: boolean\n /** Whether the agent may keep the spec Studio sends: a document in `openapi.yaml` and `input` in `kubb.config.ts`. Needs `allowConfigEdit` as well. */\n allowSaveInput: boolean\n /**\n * Whether the agent shares existing output on connect and hands back file source through\n * `readFiles`. A sandbox always permits reads of its generated files.\n */\n allowRead: boolean\n /**\n * Whether the agent hands back the parsed spec (the Kubb AST) in response to `readInput`.\n * Separate from `allowRead`, which covers generated files. Always true for a sandbox.\n */\n allowReadAst: boolean\n}\n\n/**\n * The keys of {@link AgentPermissions}, such as the permission a refused request names.\n */\nexport const AgentPermission = {\n READ: 'allowRead',\n READ_AST: 'allowReadAst',\n WRITE: 'allowWrite',\n CONFIG_EDIT: 'allowConfigEdit',\n INSTALL: 'allowInstall',\n UPDATE: 'allowUpdate',\n REMOVE: 'allowRemove',\n SAVE_INPUT: 'allowSaveInput',\n EXEC: 'allowExec',\n} as const satisfies Record<string, keyof AgentPermissions>\nexport type AgentPermission = (typeof AgentPermission)[keyof typeof AgentPermission]\n\n/**\n * Metadata part of `POST /api/snapshots`. The `tarball` part carries the packed package.\n */\nexport type SnapshotUploadMetadata = {\n /**\n * Stable CI identity, such as `gh:<repoId>:<pr>`. Snapshots with the same `id` share one CI agent.\n */\n id: string\n name: string\n packageName: string\n version: string\n /**\n * The commit the snapshot is built from, so the next one can name it as its base.\n */\n commit?: string\n /**\n * The `id` of another CI agent, such as the base branch's, to also compare with.\n */\n baseId?: string\n /**\n * Content fingerprint per generated file, keyed by path relative to the project root.\n */\n hashes: Record<string, string>\n peerDependencies: Record<string, string>\n}\n\n/**\n * How a snapshot's files differ from an earlier snapshot of the same package.\n */\nexport type SnapshotChanges = {\n /**\n * The snapshot these changes are measured against, `null` when there is none to compare with.\n */\n base: { id: string; version: string | null; commit?: string; createdAt: string; number?: number } | null\n added: Array<string>\n changed: Array<string>\n removed: Array<string>\n}\n\n/**\n * {@link SnapshotChanges} against another CI agent. `baseFound` is `false` when Studio has no CI\n * agent with that id yet, and `true` when it has one without a snapshot of this package.\n */\nexport type BranchSnapshotChanges = SnapshotChanges & { baseFound: boolean }\n\n/**\n * Response body of `POST /api/snapshots`: `{ snapshot: PublishedSnapshot }`.\n */\nexport type PublishedSnapshot = {\n id: string\n name: string | null\n version: string | null\n integrity: string | null\n agent: { id: string; name: string; slug: string | null }\n /**\n * Readable download path, often `/packages/{agentSlug}/{name}.tgz`.\n */\n url: string\n snapshotIdUrl: string\n /**\n * Studio page of this snapshot, such as `/kubb-labs/petstore/182`. Absent from a Studio that does not send it.\n */\n webUrl?: string\n /**\n * The snapshot's sequence number on its CI agent, shown as `#182`. Absent from a Studio that does not send it.\n */\n number?: number\n createdAt: string\n expiresAt: string\n /**\n * What changed since the previous snapshot of this package on the same CI agent.\n */\n changes?: SnapshotChanges\n /**\n * What differs from the latest snapshot of the CI agent `baseId` names. Absent without a base.\n */\n branchChanges?: BranchSnapshotChanges\n}\n"],"mappings":";AAQA,MAAa,iBAAiB;CAAE,QAAQ;CAAU,SAAS;CAAW,QAAQ;AAAS;AAEvF,MAAa,sBAAsB;CACjC,YAAY;CACZ,eAAe;CACf,YAAY;CACZ,kBAAkB;CAClB,gBAAgB;CAChB,eAAe;CACf,WAAW;CACX,YAAY;CACZ,eAAe;AACjB;;;;;;;AC+CA,MAAa,uBAAuB;CAClC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;AA0NA,MAAa,eAAe;CAC1B,wBAAwB;CACxB,qBAAqB;CACrB,kBAAkB;CAClB,oBAAoB;CACpB,oBAAoB;CACpB,wBAAwB;CACxB,cAAc;CACd,sBAAsB;CACtB,gBAAgB;CAChB,cAAc;CACd,sBAAsB;CACtB,aAAa;;;;CAIb,iBAAiB;CACjB,kBAAkB;;;;CAIlB,sBAAsB;CACtB,UAAU;AACZ;;;;;;AA8EA,MAAa,iBAAiB;CAC5B,cAAc;CACd,YAAY;CACZ,cAAc;AAChB;AAEA,MAAa,oBAAoB;;;;AAKjC,MAAa,wBAAwB;;;;AAKrC,MAAa,wBAAwB;;AAGrC,MAAa,iBAAiB;AAE9B,MAAa,qBAAqB;;;;AA8HlC,MAAa,kBAAkB;CAC7B,MAAM;CACN,UAAU;CACV,OAAO;CACP,aAAa;CACb,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,YAAY;CACZ,MAAM;AACR"}