@kubb/studio 5.10.1 → 5.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.cjs +417 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +260 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +419 -44
- package/dist/index.js.map +1 -1
- package/dist/protocol-CrMJymjT.d.cts +778 -0
- package/dist/{protocol-C1PwN9fa.d.ts → protocol-CrMJymjT.d.ts} +96 -12
- package/dist/protocol.cjs +34 -10
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.cts +2 -0
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +32 -7
- package/dist/protocol.js.map +1 -1
- package/package.json +28 -10
- package/dist/rolldown-runtime-CRm0XQPb.js +0 -9
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { D as InstalledExtensions, P as PublishedSnapshot, W as SnapshotUploadMetadata, a as AgentConnectInfo, c as AgentPermissions, d as ConfigEditOutcome, s as AgentPermission, u as ConfigEdit } from "./protocol-CrMJymjT.cjs";
|
|
2
|
+
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
3
|
+
//#region src/connect.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InvalidAgentTokenError extends Error {
|
|
8
|
+
constructor(studioUrl: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Studio closed with {@link AgentCloseCode.INCOMPATIBLE}. Only an upgrade helps.
|
|
12
|
+
*/
|
|
13
|
+
export declare class IncompatibleAgentError extends Error {
|
|
14
|
+
constructor({ studioUrl, detail }: {
|
|
15
|
+
studioUrl: string;
|
|
16
|
+
detail?: string;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
type StudioConnectedContext = AgentConnectInfo & {
|
|
20
|
+
url: string;
|
|
21
|
+
/**
|
|
22
|
+
* The Studio, runtime, and host versions, so a host can show a mismatch.
|
|
23
|
+
*/
|
|
24
|
+
versions: {
|
|
25
|
+
studio: string;
|
|
26
|
+
kubb: string;
|
|
27
|
+
agent: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
declare global {
|
|
31
|
+
namespace Kubb {
|
|
32
|
+
interface KubbHooksRegistry {
|
|
33
|
+
/**
|
|
34
|
+
* Fired after each handshake, including reconnects.
|
|
35
|
+
*/
|
|
36
|
+
'studio:connected': [ctx: StudioConnectedContext];
|
|
37
|
+
'studio:disconnected': [ctx: {
|
|
38
|
+
code: number;
|
|
39
|
+
reason: string;
|
|
40
|
+
}];
|
|
41
|
+
'studio:reconnecting': [ctx: {
|
|
42
|
+
delayMs: number;
|
|
43
|
+
}];
|
|
44
|
+
/**
|
|
45
|
+
* A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.
|
|
46
|
+
*/
|
|
47
|
+
'studio:command': [ctx: {
|
|
48
|
+
command: 'generate' | 'saveConfig' | 'readFiles' | 'readInput' | 'readDiff';
|
|
49
|
+
info: string;
|
|
50
|
+
}];
|
|
51
|
+
/**
|
|
52
|
+
* A refused or ignored request, with the missing permission so the host can add a remedy.
|
|
53
|
+
*/
|
|
54
|
+
'studio:warn': [ctx: {
|
|
55
|
+
message: string;
|
|
56
|
+
permission?: AgentPermission;
|
|
57
|
+
}];
|
|
58
|
+
'studio:error': [ctx: {
|
|
59
|
+
error: Error;
|
|
60
|
+
}];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
type ConnectAgentOptions = {
|
|
65
|
+
/**
|
|
66
|
+
* The agent's bearer token, from {@link pairAgent}.
|
|
67
|
+
*/
|
|
68
|
+
token: string;
|
|
69
|
+
studioUrl?: string;
|
|
70
|
+
/**
|
|
71
|
+
* The config path shown in Studio, relative to `root` unless absolute.
|
|
72
|
+
*/
|
|
73
|
+
configPath: string;
|
|
74
|
+
/**
|
|
75
|
+
* Called for every handshake and every generation, so edits on disk show up.
|
|
76
|
+
*/
|
|
77
|
+
loadConfig: () => Promise<Config>;
|
|
78
|
+
/**
|
|
79
|
+
* The host's own version, reported to Studio next to the runtime's.
|
|
80
|
+
*/
|
|
81
|
+
version: string;
|
|
82
|
+
/**
|
|
83
|
+
* The project root generation runs against.
|
|
84
|
+
* @default process.cwd()
|
|
85
|
+
*/
|
|
86
|
+
root?: string;
|
|
87
|
+
/**
|
|
88
|
+
* What Studio may do in this project. Every permission is off unless granted.
|
|
89
|
+
*/
|
|
90
|
+
permissions?: Partial<AgentPermissions>;
|
|
91
|
+
/**
|
|
92
|
+
* Receives the `studio:*` hooks and the `kubb:*` hooks of every generation.
|
|
93
|
+
*/
|
|
94
|
+
hooks?: Hookable<KubbHooks>;
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
/**
|
|
97
|
+
* Longest wait between reconnect attempts, in milliseconds.
|
|
98
|
+
* @default 30000
|
|
99
|
+
*/
|
|
100
|
+
maxRetryDelay?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Milliseconds between keep-alive pings, at most 60000.
|
|
103
|
+
* @default 30000
|
|
104
|
+
*/
|
|
105
|
+
heartbeatInterval?: number;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Connects this project to Kubb Studio and serves its commands until `signal` aborts. Reconnects
|
|
109
|
+
* with jittered backoff, and resolves when another process of the agent takes over. Rejects with
|
|
110
|
+
* {@link InvalidAgentTokenError} so the host can pair again, or {@link IncompatibleAgentError}.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const hooks = new Hookable<KubbHooks>()
|
|
115
|
+
* hooks.hook('studio:connected', ({ agentSlug }) => console.log(`Connected as ${agentSlug}`))
|
|
116
|
+
*
|
|
117
|
+
* await connectAgent({ token, configPath: 'kubb.config.ts', loadConfig, version: '1.0.0', hooks, signal })
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function connectAgent(options: ConnectAgentOptions): Promise<void>;
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/pair.d.ts
|
|
123
|
+
/**
|
|
124
|
+
* RFC 8628 device-authorization response from Studio's `/api/auth/device/code` endpoint.
|
|
125
|
+
* Field names match the RFC; the CLI polls with `device_code` and shows `user_code` to the user.
|
|
126
|
+
*/
|
|
127
|
+
type PairingSession = {
|
|
128
|
+
device_code: string;
|
|
129
|
+
user_code: string;
|
|
130
|
+
verification_uri: string;
|
|
131
|
+
verification_uri_complete: string;
|
|
132
|
+
expires_in: number;
|
|
133
|
+
interval: number;
|
|
134
|
+
};
|
|
135
|
+
type PairingResult = {
|
|
136
|
+
/**
|
|
137
|
+
* Bearer token for this machine. Write credentials with mode 0600 and never log the value.
|
|
138
|
+
*/
|
|
139
|
+
token: string;
|
|
140
|
+
agent: {
|
|
141
|
+
/**
|
|
142
|
+
* Stable agent id in Studio.
|
|
143
|
+
*/
|
|
144
|
+
id: string;
|
|
145
|
+
/**
|
|
146
|
+
* Short slug used in logs and the UI (for example `brave-otter`).
|
|
147
|
+
*/
|
|
148
|
+
slug: string;
|
|
149
|
+
/**
|
|
150
|
+
* Display name chosen at pairing time.
|
|
151
|
+
*/
|
|
152
|
+
name: string;
|
|
153
|
+
/**
|
|
154
|
+
* This agent's organization slug, absent for a sandbox or global agent, which has none.
|
|
155
|
+
*/
|
|
156
|
+
organizationSlug?: string;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* What this machine registers as. Any member may approve `cli` (`kubb studio`); only an admin may
|
|
161
|
+
* approve `user` and `sandbox` (the Docker image). A `ci` agent never pairs.
|
|
162
|
+
*/
|
|
163
|
+
type PairingAgentType = 'cli' | 'user' | 'sandbox';
|
|
164
|
+
/**
|
|
165
|
+
* Thrown when a caller aborts `startPairing` or `pollForPairingToken` through their `signal`, such
|
|
166
|
+
* as a `kubb studio` shutdown mid-pairing. Distinct from a denial or an expired code, so a host can
|
|
167
|
+
* exit quietly instead of reporting a pairing failure.
|
|
168
|
+
*/
|
|
169
|
+
export declare class PairingCanceledError extends Error {
|
|
170
|
+
constructor();
|
|
171
|
+
}
|
|
172
|
+
/** Thrown when the code expired unapproved. A fresh code can still succeed. */
|
|
173
|
+
export declare class PairingExpiredError extends Error {
|
|
174
|
+
constructor(message?: string);
|
|
175
|
+
}
|
|
176
|
+
/** Thrown when the pairing was denied in the browser, including by the organization's agent limit. */
|
|
177
|
+
export declare class PairingDeniedError extends Error {
|
|
178
|
+
constructor(message?: string);
|
|
179
|
+
}
|
|
180
|
+
type StartPairingOptions = {
|
|
181
|
+
studioUrl?: string;
|
|
182
|
+
type: PairingAgentType;
|
|
183
|
+
/**
|
|
184
|
+
* Display name for the agent, usually the project or machine name.
|
|
185
|
+
*/
|
|
186
|
+
name: string;
|
|
187
|
+
hostname: string;
|
|
188
|
+
/**
|
|
189
|
+
* A stable secret the host keeps for this machine. Studio stores its hash against the agent, so
|
|
190
|
+
* the same machine pairing again rotates one agent's token instead of creating a second agent.
|
|
191
|
+
*/
|
|
192
|
+
machineId: string;
|
|
193
|
+
/**
|
|
194
|
+
* Aborting this cancels the request in flight and rejects with {@link PairingCanceledError}.
|
|
195
|
+
*/
|
|
196
|
+
signal?: AbortSignal;
|
|
197
|
+
};
|
|
198
|
+
type PairAgentOptions = StartPairingOptions & {
|
|
199
|
+
/** Shows the code to whoever approves it. Called again for each fresh code. */
|
|
200
|
+
onCode: (session: PairingSession, attempt: number) => void | Promise<void>;
|
|
201
|
+
/** Called when a poll could not reach Studio. Polling carries on. */
|
|
202
|
+
onRetry?: (error: Error) => void;
|
|
203
|
+
/**
|
|
204
|
+
* Codes to ask for in total when one expires unapproved. A denial or abort ends it at once.
|
|
205
|
+
* @default 1
|
|
206
|
+
*/
|
|
207
|
+
maxAttempts?: number;
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* Pairs this machine with Studio: asks for a code, hands it to the host to show, and waits for approval.
|
|
211
|
+
*/
|
|
212
|
+
export declare function pairAgent({ onCode, onRetry, maxAttempts, ...options }: PairAgentOptions): Promise<PairingResult>;
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/snapshot.d.ts
|
|
215
|
+
type CreateSnapshotOptions = Omit<SnapshotUploadMetadata, 'hashes' | 'peerDependencies'> & {
|
|
216
|
+
studioUrl?: string;
|
|
217
|
+
/**
|
|
218
|
+
* Organization CI API key, sent as `x-api-key`.
|
|
219
|
+
*/
|
|
220
|
+
apiKey: string;
|
|
221
|
+
/**
|
|
222
|
+
* The project's Kubb config, generated like `kubb generate`: formatter, linter, and `output.postGenerate` included.
|
|
223
|
+
*/
|
|
224
|
+
config: Config;
|
|
225
|
+
hooks?: Hookable<KubbHooks>;
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Generates the project, packs it as an npm tarball, and publishes it to Studio in one `POST /api/snapshots` request.
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```ts
|
|
233
|
+
* const { url } = await createSnapshot({ apiKey: process.env.KUBB_TOKEN!, config, id: 'gh:123:pr-4', name: 'acme/api#4', packageName: '@acme/api', version: '1.0.0' })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
export declare function createSnapshot({ studioUrl, apiKey, config, hooks, signal, ...metadata }: CreateSnapshotOptions): Promise<PublishedSnapshot>;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/url.d.ts
|
|
239
|
+
/**
|
|
240
|
+
* Hosted Kubb Studio URL, used when a host passes none.
|
|
241
|
+
*/
|
|
242
|
+
export declare const defaultStudioUrl = "https://kubb.studio";
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/configFile.d.ts
|
|
245
|
+
/**
|
|
246
|
+
* Applies `edits` to the config file at `filePath`, writing it only when something changed.
|
|
247
|
+
* `add-plugin` accepts `@kubb/plugin-*` packages and the plugins in `extensions`.
|
|
248
|
+
*/
|
|
249
|
+
export declare function writeConfigEdits({ filePath, edits, extensions }: {
|
|
250
|
+
filePath: string;
|
|
251
|
+
edits: Array<ConfigEdit>;
|
|
252
|
+
extensions?: InstalledExtensions;
|
|
253
|
+
}): Promise<{
|
|
254
|
+
source: string;
|
|
255
|
+
outcomes: Array<ConfigEditOutcome>;
|
|
256
|
+
changed: boolean;
|
|
257
|
+
}>;
|
|
258
|
+
//#endregion
|
|
259
|
+
export type { ConnectAgentOptions, StudioConnectedContext };
|
|
260
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { H as SnapshotUploadMetadata, M as PublishedSnapshot, a as AgentConnectInfo, c as ConfigEdit, l as ConfigEditOutcome, o as AgentPermissions, w as InstalledExtensions } from "./protocol-C1PwN9fa.js";
|
|
1
|
+
import { D as InstalledExtensions, P as PublishedSnapshot, W as SnapshotUploadMetadata, a as AgentConnectInfo, c as AgentPermissions, d as ConfigEditOutcome, s as AgentPermission, u as ConfigEdit } from "./protocol-CrMJymjT.js";
|
|
3
2
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
4
3
|
//#region src/connect.d.ts
|
|
5
4
|
/**
|
|
@@ -46,7 +45,7 @@ declare global {
|
|
|
46
45
|
* A finished command and what it did, such as `applied 2/3 edits to kubb.config.ts`.
|
|
47
46
|
*/
|
|
48
47
|
'studio:command': [ctx: {
|
|
49
|
-
command: 'generate' | 'saveConfig' | 'readFiles' | 'readInput';
|
|
48
|
+
command: 'generate' | 'saveConfig' | 'readFiles' | 'readInput' | 'readDiff';
|
|
50
49
|
info: string;
|
|
51
50
|
}];
|
|
52
51
|
/**
|
|
@@ -54,7 +53,7 @@ declare global {
|
|
|
54
53
|
*/
|
|
55
54
|
'studio:warn': [ctx: {
|
|
56
55
|
message: string;
|
|
57
|
-
permission?:
|
|
56
|
+
permission?: AgentPermission;
|
|
58
57
|
}];
|
|
59
58
|
'studio:error': [ctx: {
|
|
60
59
|
error: Error;
|