@kubb/studio 5.18.8 → 5.19.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.
- package/README.md +2 -1
- package/dist/index.cjs +142 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +142 -88
- package/dist/index.js.map +1 -1
- package/dist/{protocol-f2YAAGLi.d.cts → protocol-BFIUEXLA.d.cts} +11 -4
- package/dist/{protocol-f2YAAGLi.d.ts → protocol-BFIUEXLA.d.ts} +11 -4
- package/dist/{protocol-B4wWGPon.cjs → protocol-CmX5XTPc.cjs} +2 -1
- package/dist/{protocol-B4wWGPon.cjs.map → protocol-CmX5XTPc.cjs.map} +1 -1
- package/dist/{protocol-B6oWLc7W.js → protocol-xk8P0Zhv.js} +2 -1
- package/dist/{protocol-B6oWLc7W.js.map → protocol-xk8P0Zhv.js.map} +1 -1
- package/dist/protocol.cjs +1 -1
- package/dist/protocol.d.cts +2 -2
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +1 -1
- package/package.json +4 -4
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { K as editConfig, V as SnapshotUploadMetadata, a as AgentConnectInfo, c as AgentPermissions, k as PublishedSnapshot, l as AgentType, q as editConfigFile, s as AgentPermission } from "./protocol-BFIUEXLA.cjs";
|
|
2
2
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
3
3
|
/**
|
|
4
4
|
* Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.
|
|
@@ -96,6 +96,12 @@ type ConnectAgentOptions = {
|
|
|
96
96
|
* What Studio may do in this project. Every permission is off unless granted.
|
|
97
97
|
*/
|
|
98
98
|
permissions?: Partial<AgentPermissions>;
|
|
99
|
+
/**
|
|
100
|
+
* The kind of agent the host runs. A `'sandbox'` or `'global'` agent is shared, and lets Studio read what it generated.
|
|
101
|
+
* Studio's own `sandbox` and `managed` flags only take permissions away.
|
|
102
|
+
* @default 'user'
|
|
103
|
+
*/
|
|
104
|
+
agentType?: AgentType;
|
|
99
105
|
/** The CLI entry `installExtension` runs `kubb add` with. Found through the project's `kubb` or `@kubb/cli` dependency when omitted. */
|
|
100
106
|
kubbBin?: string;
|
|
101
107
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { K as editConfig, V as SnapshotUploadMetadata, a as AgentConnectInfo, c as AgentPermissions, k as PublishedSnapshot, l as AgentType, q as editConfigFile, s as AgentPermission } from "./protocol-BFIUEXLA.js";
|
|
2
2
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
3
3
|
/**
|
|
4
4
|
* Studio closed with {@link AgentCloseCode.UNAUTHORIZED}. Hosts forget the token and pair again.
|
|
@@ -96,6 +96,12 @@ type ConnectAgentOptions = {
|
|
|
96
96
|
* What Studio may do in this project. Every permission is off unless granted.
|
|
97
97
|
*/
|
|
98
98
|
permissions?: Partial<AgentPermissions>;
|
|
99
|
+
/**
|
|
100
|
+
* The kind of agent the host runs. A `'sandbox'` or `'global'` agent is shared, and lets Studio read what it generated.
|
|
101
|
+
* Studio's own `sandbox` and `managed` flags only take permissions away.
|
|
102
|
+
* @default 'user'
|
|
103
|
+
*/
|
|
104
|
+
agentType?: AgentType;
|
|
99
105
|
/** The CLI entry `installExtension` runs `kubb add` with. Found through the project's `kubb` or `@kubb/cli` dependency when omitted. */
|
|
100
106
|
kubbBin?: string;
|
|
101
107
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as AgentPermission, c as MAX_SNAPSHOT_BYTES, d as extensionKinds, i as AgentMessage, l as generationEventTypes, n as AGENT_SOCKET_PATH, r as AgentCloseCode, t as AGENT_INSTANCE_HEADER, u as ConfigEditOperation } from "./protocol-
|
|
1
|
+
import { a as AgentPermission, c as MAX_SNAPSHOT_BYTES, d as extensionKinds, i as AgentMessage, l as generationEventTypes, n as AGENT_SOCKET_PATH, r as AgentCloseCode, t as AGENT_INSTANCE_HEADER, u as ConfigEditOperation } from "./protocol-xk8P0Zhv.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { createHash, hash, randomUUID } from "node:crypto";
|
|
4
4
|
import { existsSync, readFile, writeFile } from "node:fs";
|
|
@@ -22,6 +22,63 @@ import net from "node:net";
|
|
|
22
22
|
import { Readable, Transform } from "node:stream";
|
|
23
23
|
import { ofetch } from "ofetch";
|
|
24
24
|
import { gzipSync } from "node:zlib";
|
|
25
|
+
// ../../internals/utils/src/promise.ts
|
|
26
|
+
/**
|
|
27
|
+
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
28
|
+
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
29
|
+
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
33
|
+
*/
|
|
34
|
+
function memo(store, key, compute) {
|
|
35
|
+
const cached = store.get(key);
|
|
36
|
+
if (cached !== void 0 || store.has(key)) return cached;
|
|
37
|
+
const value = compute();
|
|
38
|
+
store.set(key, value);
|
|
39
|
+
return value;
|
|
40
|
+
}
|
|
41
|
+
function createStore({ weak, max } = {}) {
|
|
42
|
+
if (weak) return /* @__PURE__ */ new WeakMap();
|
|
43
|
+
const entry = /* @__PURE__ */ new Map();
|
|
44
|
+
if (max === void 0) return entry;
|
|
45
|
+
const set = (key, value) => {
|
|
46
|
+
if (entry.size >= max) entry.clear();
|
|
47
|
+
entry.set(key, value);
|
|
48
|
+
};
|
|
49
|
+
if (max !== 1) return {
|
|
50
|
+
has: (key) => entry.has(key),
|
|
51
|
+
get: (key) => entry.get(key),
|
|
52
|
+
set
|
|
53
|
+
};
|
|
54
|
+
const touch = (key) => {
|
|
55
|
+
if (!entry.has(key)) return false;
|
|
56
|
+
set(key, entry.get(key));
|
|
57
|
+
return true;
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
has: touch,
|
|
61
|
+
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
62
|
+
set
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
memo.create = createStore;
|
|
66
|
+
/**
|
|
67
|
+
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
68
|
+
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
async function inParallel({ items, limit, run }) {
|
|
76
|
+
const queue = items.entries();
|
|
77
|
+
const worker = async () => {
|
|
78
|
+
for (const [index, item] of queue) await run(item, index);
|
|
79
|
+
};
|
|
80
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
81
|
+
}
|
|
25
82
|
// ../../internals/utils/src/casing.ts
|
|
26
83
|
/**
|
|
27
84
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -36,16 +93,10 @@ function convert(text, pascal) {
|
|
|
36
93
|
return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
|
|
37
94
|
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
38
95
|
}
|
|
39
|
-
const cache =
|
|
40
|
-
const cacheLimit = 1e5;
|
|
96
|
+
const cache = memo.create({ max: 1e5 });
|
|
41
97
|
function toCamelOrPascal(text, pascal) {
|
|
42
98
|
const key = `${pascal ? "P" : "c"}${text}`;
|
|
43
|
-
|
|
44
|
-
if (cached !== void 0) return cached;
|
|
45
|
-
const result = convert(text, pascal);
|
|
46
|
-
if (cache.size >= cacheLimit) cache.clear();
|
|
47
|
-
cache.set(key, result);
|
|
48
|
-
return result;
|
|
99
|
+
return memo(cache, key, () => convert(text, pascal));
|
|
49
100
|
}
|
|
50
101
|
/**
|
|
51
102
|
* Converts `text` to camelCase.
|
|
@@ -171,60 +222,8 @@ function isPathInside(path, parent) {
|
|
|
171
222
|
const rel = relative(resolvedParent, resolvedPath);
|
|
172
223
|
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
173
224
|
}
|
|
174
|
-
// ../../internals/utils/src/promise.ts
|
|
175
|
-
/**
|
|
176
|
-
* Returns the value cached under `key` in `store`, computing and storing it on the first call.
|
|
177
|
-
* Pass a `WeakMap` for object keys, so an entry goes away with its key, or a `Map` for primitive
|
|
178
|
-
* keys. A cached `null` or `undefined` counts as a hit, so `compute` runs once per key.
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* `const refs = memo(refCache, node, () => collectRefs(node))`
|
|
182
|
-
*/
|
|
183
|
-
function memo(store, key, compute) {
|
|
184
|
-
const cached = store.get(key);
|
|
185
|
-
if (cached !== void 0 || store.has(key)) return cached;
|
|
186
|
-
const value = compute();
|
|
187
|
-
store.set(key, value);
|
|
188
|
-
return value;
|
|
189
|
-
}
|
|
190
|
-
function createStore({ type }) {
|
|
191
|
-
if (type === "weak") return /* @__PURE__ */ new WeakMap();
|
|
192
|
-
const entry = /* @__PURE__ */ new Map();
|
|
193
|
-
if (type === "map") return entry;
|
|
194
|
-
const set = (key, value) => {
|
|
195
|
-
entry.clear();
|
|
196
|
-
entry.set(key, value);
|
|
197
|
-
};
|
|
198
|
-
const touch = (key) => {
|
|
199
|
-
if (!entry.has(key)) return false;
|
|
200
|
-
set(key, entry.get(key));
|
|
201
|
-
return true;
|
|
202
|
-
};
|
|
203
|
-
return {
|
|
204
|
-
has: touch,
|
|
205
|
-
get: (key) => touch(key) ? entry.get(key) : void 0,
|
|
206
|
-
set
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
memo.create = createStore;
|
|
210
|
-
/**
|
|
211
|
-
* Runs `run` over every item with at most `limit` in flight. Workers share one iterator, so each
|
|
212
|
-
* takes the next item the moment it frees up instead of waiting for a batch to drain.
|
|
213
|
-
*
|
|
214
|
-
* @example
|
|
215
|
-
* ```ts
|
|
216
|
-
* await inParallel({ items: files, limit: 50, run: (file) => storage.writeItem(file.path, file.source) })
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
async function inParallel({ items, limit, run }) {
|
|
220
|
-
const queue = items.entries();
|
|
221
|
-
const worker = async () => {
|
|
222
|
-
for (const [index, item] of queue) await run(item, index);
|
|
223
|
-
};
|
|
224
|
-
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => worker()));
|
|
225
|
-
}
|
|
226
225
|
// package.json
|
|
227
|
-
var version = "5.
|
|
226
|
+
var version = "5.19.1";
|
|
228
227
|
// ../../internals/shared/src/constants.ts
|
|
229
228
|
/**
|
|
230
229
|
* Extensions `kubb` ships at its own version, so they count as installed without being a direct
|
|
@@ -361,6 +360,22 @@ function isOutputValue({ key, value }) {
|
|
|
361
360
|
function pickOutput(output) {
|
|
362
361
|
return Object.fromEntries(Object.entries(output).filter(([key]) => isOutputKey(key)));
|
|
363
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* Returns the first `output.path` in `value`, at any depth (`override` entries included), that is
|
|
365
|
+
* absolute or climbs out of the folder it resolves against.
|
|
366
|
+
*/
|
|
367
|
+
function findEscapingOutputPath(value) {
|
|
368
|
+
if (!Array.isArray(value) && !isPlainObject(value)) return void 0;
|
|
369
|
+
const output = isPlainObject(value) ? value.output : void 0;
|
|
370
|
+
if (isPlainObject(output) && typeof output.path === "string") {
|
|
371
|
+
const normalized = path.posix.normalize(output.path.replaceAll("\\", "/"));
|
|
372
|
+
if (path.posix.isAbsolute(normalized) || /^[a-z]:/i.test(output.path) || normalized === ".." || normalized.startsWith("../")) return output.path;
|
|
373
|
+
}
|
|
374
|
+
for (const entry of Object.values(value)) {
|
|
375
|
+
const found = findEscapingOutputPath(entry);
|
|
376
|
+
if (found !== void 0) return found;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
364
379
|
// ../../internals/shared/src/configFile/text.ts
|
|
365
380
|
/**
|
|
366
381
|
* A valid JavaScript identifier, so an import name can only ever print as `import { name } from`,
|
|
@@ -456,13 +471,15 @@ function isNonEmptyString(value) {
|
|
|
456
471
|
}
|
|
457
472
|
/** Edits cross the wire, so their shape is checked before anything reads them. */
|
|
458
473
|
function validateEdit(edit) {
|
|
459
|
-
const { operation, plugin, config, path, kind, input } = typeof edit === "object" && edit !== null ? edit : {};
|
|
474
|
+
const { operation, plugin, config, path, kind, input, value, options } = typeof edit === "object" && edit !== null ? edit : {};
|
|
460
475
|
if (typeof operation !== "string" || !OPERATIONS.has(operation)) return `unknown operation ${JSON.stringify(operation)}`;
|
|
461
476
|
if (config !== void 0 && typeof config !== "string" && !Number.isSafeInteger(config)) return "config must name an entry or give its index";
|
|
462
477
|
if (operation === ConfigEditOperation.SET_INPUT) return typeof input === "string" && input.trim() !== "" ? void 0 : "the edit names no input";
|
|
463
478
|
const isOption = OPTION_OPERATIONS.has(operation);
|
|
464
479
|
const isOutput = OUTPUT_OPERATIONS.has(operation);
|
|
465
480
|
if (!isOutput && !isNonEmptyString(plugin)) return "the edit names no plugin";
|
|
481
|
+
const escaping = findEscapingOutputPath(operation === ConfigEditOperation.SET_OPTION && Array.isArray(path) ? path.reduceRight((inner, key) => ({ [String(key)]: inner }), value) : options);
|
|
482
|
+
if (escaping !== void 0) return `output.path ${JSON.stringify(escaping)} resolves outside the output folder`;
|
|
466
483
|
if (kind !== void 0) {
|
|
467
484
|
if (typeof kind !== "string" || !KINDS.has(kind)) return `unknown kind ${JSON.stringify(kind)}`;
|
|
468
485
|
const takesKind = operation === ConfigEditOperation.ADD_PLUGIN || operation === ConfigEditOperation.REMOVE_EXTENSION;
|
|
@@ -964,14 +981,14 @@ function addPlugin({ source, parsed, config, edit, quote, extensions }) {
|
|
|
964
981
|
if (array ? array.type !== nodeTypes.arrayExpression : !isParser) return { reason: `${key} is not an array literal` };
|
|
965
982
|
const defaults = isParser && !array ? DEFAULT_PARSERS.filter((parser) => parser.importName !== importName) : [];
|
|
966
983
|
const imports = getImports(parsed.program);
|
|
967
|
-
const missing =
|
|
984
|
+
const missing = memo.create();
|
|
968
985
|
for (const item of [...defaults, {
|
|
969
986
|
importName,
|
|
970
987
|
packageName: edit.plugin
|
|
971
988
|
}]) {
|
|
972
989
|
const from = imports.get(item.importName)?.from;
|
|
973
990
|
if (from && from !== item.packageName) return { reason: `${item.importName} is already imported from ${from}` };
|
|
974
|
-
if (!from) missing
|
|
991
|
+
if (!from) memo(missing, item.packageName, () => []).push(item.importName);
|
|
975
992
|
}
|
|
976
993
|
const call = `${importName}(${Object.keys(options).length ? printValue(options, quote) : ""})`;
|
|
977
994
|
const next = array?.type === nodeTypes.arrayExpression ? appendItem(source, array, call) : appendItem(source, config, `parsers: [${[...defaults.map((parser) => `${parser.importName}()`), call].join(", ")}]`);
|
|
@@ -1121,13 +1138,13 @@ function applyEdit({ source, edit, extensions }) {
|
|
|
1121
1138
|
function editConfig({ source, edits, extensions = /* @__PURE__ */ new Map() }) {
|
|
1122
1139
|
let current = source;
|
|
1123
1140
|
const outcomes = edits.map((edit) => {
|
|
1124
|
-
const invalid = validateEdit(edit);
|
|
1125
|
-
if (invalid) return {
|
|
1126
|
-
edit,
|
|
1127
|
-
applied: false,
|
|
1128
|
-
reason: invalid
|
|
1129
|
-
};
|
|
1130
1141
|
try {
|
|
1142
|
+
const invalid = validateEdit(edit);
|
|
1143
|
+
if (invalid) return {
|
|
1144
|
+
edit,
|
|
1145
|
+
applied: false,
|
|
1146
|
+
reason: invalid
|
|
1147
|
+
};
|
|
1131
1148
|
const result = applyEdit({
|
|
1132
1149
|
source: current,
|
|
1133
1150
|
edit,
|
|
@@ -1364,7 +1381,7 @@ function generationFailure(diagnostics) {
|
|
|
1364
1381
|
* Runs one generation and returns the files it produced. The formatter, the linter, and
|
|
1365
1382
|
* `output.postGenerate` only run with `allowExec`. Throws when any plugin reports an error.
|
|
1366
1383
|
*/
|
|
1367
|
-
async function generate({ config, hooks, signal, allowExec }) {
|
|
1384
|
+
async function generate({ config, hooks, signal, allowExec, fileRefs }) {
|
|
1368
1385
|
const output = allowExec ? config.output : {
|
|
1369
1386
|
...config.output,
|
|
1370
1387
|
format: false,
|
|
@@ -1376,7 +1393,8 @@ async function generate({ config, hooks, signal, allowExec }) {
|
|
|
1376
1393
|
output
|
|
1377
1394
|
}, {
|
|
1378
1395
|
hooks,
|
|
1379
|
-
signal
|
|
1396
|
+
signal,
|
|
1397
|
+
fileRefs
|
|
1380
1398
|
});
|
|
1381
1399
|
const result = await kubb.generate();
|
|
1382
1400
|
if (!result.success) throw generationFailure(result.diagnostics);
|
|
@@ -1759,7 +1777,7 @@ const NO_BODY = /* @__PURE__ */ new Set([
|
|
|
1759
1777
|
304
|
|
1760
1778
|
]);
|
|
1761
1779
|
function notPublic(host) {
|
|
1762
|
-
return /* @__PURE__ */ new Error(`${host} is not a public address, so
|
|
1780
|
+
return /* @__PURE__ */ new Error(`${host} is not a public address, so this agent does not fetch from it`);
|
|
1763
1781
|
}
|
|
1764
1782
|
function createLookup(blocked) {
|
|
1765
1783
|
return (hostname, options, callback) => {
|
|
@@ -1811,8 +1829,8 @@ function request({ url, blocked, signal }) {
|
|
|
1811
1829
|
*/
|
|
1812
1830
|
function createPublicFetch(blocked) {
|
|
1813
1831
|
const publicFetch = async (input, init) => {
|
|
1814
|
-
if (typeof input !== "string" && !(input instanceof URL)) throw new TypeError("
|
|
1815
|
-
if (init?.method && init.method.toUpperCase() !== "GET") throw new TypeError("
|
|
1832
|
+
if (typeof input !== "string" && !(input instanceof URL)) throw new TypeError("This agent fetches by URL only");
|
|
1833
|
+
if (init?.method && init.method.toUpperCase() !== "GET") throw new TypeError("This agent only sends GET requests");
|
|
1816
1834
|
let url = new URL(input);
|
|
1817
1835
|
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
|
1818
1836
|
const response = await request({
|
|
@@ -1831,7 +1849,7 @@ function createPublicFetch(blocked) {
|
|
|
1831
1849
|
}
|
|
1832
1850
|
/**
|
|
1833
1851
|
* Runs `run` with the global `fetch` limited to public addresses, then puts the original back.
|
|
1834
|
-
* A managed agent runs one job at a time, so nothing else shares the window.
|
|
1852
|
+
* A sandbox or managed agent runs one job at a time, so nothing else shares the window.
|
|
1835
1853
|
*/
|
|
1836
1854
|
async function withPublicFetch(run) {
|
|
1837
1855
|
const original = globalThis.fetch;
|
|
@@ -2104,6 +2122,18 @@ function assertOutputPaths({ plugins, diskPlugins, root, outputPath }) {
|
|
|
2104
2122
|
}
|
|
2105
2123
|
}
|
|
2106
2124
|
/**
|
|
2125
|
+
* The folders a `$ref` may read local files from on each kind of agent. Studio may have sent the
|
|
2126
|
+
* spec, so a shared agent gets none, and a managed agent only the git checkout it made itself. A
|
|
2127
|
+
* project agent gets its `root` and the folder of the file `input` in its own config. `undefined`
|
|
2128
|
+
* means no limit, which only `allowFileRefs` grants.
|
|
2129
|
+
*/
|
|
2130
|
+
function resolveFileRefs({ agentType, allowFileRefs, root, input, checkoutDir }) {
|
|
2131
|
+
if (agentType === "sandbox" || agentType === "global") return [];
|
|
2132
|
+
if (agentType === "managed") return checkoutDir ? [checkoutDir] : [];
|
|
2133
|
+
if (allowFileRefs) return void 0;
|
|
2134
|
+
return typeof input === "string" && getInputKind(input) === "file" ? [root, path.dirname(path.resolve(root, input))] : [root];
|
|
2135
|
+
}
|
|
2136
|
+
/**
|
|
2107
2137
|
* Re-invokes the factory behind a disk adapter or parser with Studio's options merged over its own.
|
|
2108
2138
|
* An instance carries live functions (`parse`, `print`, ...) that cannot survive JSON, so Studio's
|
|
2109
2139
|
* options are a patch, not a replacement, and the factory is found from the disk instance itself: the
|
|
@@ -2195,6 +2225,7 @@ function secureUrl({ studioUrl, path, socket = false }) {
|
|
|
2195
2225
|
}
|
|
2196
2226
|
// src/connect.ts
|
|
2197
2227
|
const HEARTBEAT_INTERVAL_MS = 3e4;
|
|
2228
|
+
const SHARED_AGENT_TYPES = /* @__PURE__ */ new Set(["sandbox", "global"]);
|
|
2198
2229
|
const MAX_HEARTBEAT_INTERVAL_MS = 6e4;
|
|
2199
2230
|
const PING_TIMEOUT_MS = 1e4;
|
|
2200
2231
|
const OPEN_TIMEOUT_MS = 5e3;
|
|
@@ -2320,14 +2351,25 @@ var Agent = class extends RpcTarget {
|
|
|
2320
2351
|
this.#session = session;
|
|
2321
2352
|
}
|
|
2322
2353
|
get #sandbox() {
|
|
2323
|
-
return this.#session.info?.sandbox === true;
|
|
2354
|
+
return SHARED_AGENT_TYPES.has(this.#options.agentType) || this.#session.info?.sandbox === true;
|
|
2324
2355
|
}
|
|
2325
2356
|
get #managed() {
|
|
2326
|
-
return this.#session.info?.managed === true;
|
|
2357
|
+
return this.#options.agentType === "managed" || this.#session.info?.managed === true;
|
|
2358
|
+
}
|
|
2359
|
+
get #agentType() {
|
|
2360
|
+
if (this.#sandbox) return "sandbox";
|
|
2361
|
+
if (this.#managed) return "managed";
|
|
2362
|
+
return this.#options.agentType;
|
|
2327
2363
|
}
|
|
2328
2364
|
get #permissions() {
|
|
2329
|
-
const { permissions } = this.#options;
|
|
2330
|
-
|
|
2365
|
+
const { permissions, agentType } = this.#options;
|
|
2366
|
+
const sandbox = SHARED_AGENT_TYPES.has(agentType);
|
|
2367
|
+
if (this.#managed) return {
|
|
2368
|
+
...permissions,
|
|
2369
|
+
allowFileRefs: false
|
|
2370
|
+
};
|
|
2371
|
+
if (!this.#sandbox) return permissions;
|
|
2372
|
+
return {
|
|
2331
2373
|
...permissions,
|
|
2332
2374
|
allowWrite: false,
|
|
2333
2375
|
allowConfigEdit: false,
|
|
@@ -2335,9 +2377,10 @@ var Agent = class extends RpcTarget {
|
|
|
2335
2377
|
allowUpdate: false,
|
|
2336
2378
|
allowRemove: false,
|
|
2337
2379
|
allowSaveInput: false,
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2380
|
+
allowFileRefs: false,
|
|
2381
|
+
allowRead: sandbox || permissions.allowRead,
|
|
2382
|
+
allowReadAst: sandbox || permissions.allowReadAst
|
|
2383
|
+
};
|
|
2341
2384
|
}
|
|
2342
2385
|
get #generations() {
|
|
2343
2386
|
this.#store ??= createGenerationStore({
|
|
@@ -2559,7 +2602,8 @@ var Agent = class extends RpcTarget {
|
|
|
2559
2602
|
});
|
|
2560
2603
|
const activePlugins = plugins ?? config.plugins;
|
|
2561
2604
|
if (patch?.input && !this.#sandbox && !this.#managed) await emit(this.#options.hooks, "kubb:warn", { message: "Ignored the spec from Studio: generating from a Studio spec is only available to a sandbox or managed agent" });
|
|
2562
|
-
const
|
|
2605
|
+
const managedInput = this.#managed ? studioInput ?? config.input : void 0;
|
|
2606
|
+
const checkout = typeof managedInput === "string" && getInputKind(managedInput) === "git" ? await checkoutGitInput(managedInput, signal, {
|
|
2563
2607
|
publicOnly: true,
|
|
2564
2608
|
authorization: input.gitAuth?.authorization
|
|
2565
2609
|
}).catch((error) => this.#refuse({
|
|
@@ -2585,9 +2629,16 @@ var Agent = class extends RpcTarget {
|
|
|
2585
2629
|
},
|
|
2586
2630
|
hooks: this.#options.hooks,
|
|
2587
2631
|
signal,
|
|
2588
|
-
allowExec: this.#permissions.allowWrite && this.#permissions.allowExec
|
|
2632
|
+
allowExec: this.#permissions.allowWrite && this.#permissions.allowExec,
|
|
2633
|
+
fileRefs: resolveFileRefs({
|
|
2634
|
+
agentType: this.#agentType,
|
|
2635
|
+
allowFileRefs: this.#permissions.allowFileRefs,
|
|
2636
|
+
root: this.#options.root,
|
|
2637
|
+
input: config.input,
|
|
2638
|
+
checkoutDir: checkout?.dir
|
|
2639
|
+
})
|
|
2589
2640
|
});
|
|
2590
|
-
const files = await (this.#managed ? withPublicFetch(run) : run()).catch(async (error) => {
|
|
2641
|
+
const files = await (this.#sandbox || this.#managed ? withPublicFetch(run) : run()).catch(async (error) => {
|
|
2591
2642
|
await this.#generations.drop(jobId);
|
|
2592
2643
|
await this.#logCommand("generate", getErrorMessage(error), input.requestedBy, true);
|
|
2593
2644
|
throw error;
|
|
@@ -2682,7 +2733,7 @@ var Agent = class extends RpcTarget {
|
|
|
2682
2733
|
/**
|
|
2683
2734
|
* Readies a `set-input` edit for the config file: a document is pointed at `openapi.yaml` (`openapi.json`
|
|
2684
2735
|
* for JSON) in the project, one file per config entry, for `saveConfig` to write once the edit applies.
|
|
2685
|
-
* A managed agent refuses a file path, as in a generation.
|
|
2736
|
+
* A managed agent refuses a file path, as in a generation. Every agent refuses a file path outside the project.
|
|
2686
2737
|
*/
|
|
2687
2738
|
async #keepInput(edit) {
|
|
2688
2739
|
if (edit?.operation !== ConfigEditOperation.SET_INPUT || typeof edit.input !== "string" || !edit.input.trim()) return edit;
|
|
@@ -2695,6 +2746,7 @@ var Agent = class extends RpcTarget {
|
|
|
2695
2746
|
}
|
|
2696
2747
|
const kind = getInputKind(edit.input);
|
|
2697
2748
|
if (this.#managed && !MANAGED_INPUT_KINDS.has(kind)) return { reason: AgentMessage.MANAGED_INPUT_KIND };
|
|
2749
|
+
if ((kind === "file" || kind === "url" && !/^https?:/i.test(edit.input)) && !isPathInside(path.resolve(this.#options.root, edit.input), this.#options.root)) return { reason: "the input is a file outside the project" };
|
|
2698
2750
|
if (kind !== "inline") return edit;
|
|
2699
2751
|
const fileName = `openapi${edit.config === void 0 || edit.config === 0 ? "" : `-${String(edit.config).replace(/[^\w.-]/g, "-")}`}.${isJson(edit.input) ? "json" : "yaml"}`;
|
|
2700
2752
|
return {
|
|
@@ -3105,6 +3157,7 @@ async function runAgent({ options, openRpc }) {
|
|
|
3105
3157
|
...options,
|
|
3106
3158
|
studioUrl: options.studioUrl ?? "https://kubb.studio",
|
|
3107
3159
|
root,
|
|
3160
|
+
agentType: options.agentType ?? "user",
|
|
3108
3161
|
configFile: path.resolve(root, options.configPath),
|
|
3109
3162
|
permissions: {
|
|
3110
3163
|
allowWrite: false,
|
|
@@ -3113,6 +3166,7 @@ async function runAgent({ options, openRpc }) {
|
|
|
3113
3166
|
allowUpdate: false,
|
|
3114
3167
|
allowRemove: false,
|
|
3115
3168
|
allowSaveInput: false,
|
|
3169
|
+
allowFileRefs: false,
|
|
3116
3170
|
allowExec: false,
|
|
3117
3171
|
allowRead: false,
|
|
3118
3172
|
allowReadAst: false,
|