@kubb/agent 4.27.4 → 4.28.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.
Files changed (26) hide show
  1. package/.output/nitro.json +1 -1
  2. package/.output/server/chunks/nitro/nitro.mjs +278 -140
  3. package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
  4. package/.output/server/chunks/routes/api/health.get.mjs +5 -0
  5. package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
  6. package/.output/server/index.mjs +6 -1
  7. package/.output/server/index.mjs.map +1 -1
  8. package/.output/server/node_modules/anymatch/index.js +104 -0
  9. package/.output/server/node_modules/anymatch/package.json +48 -0
  10. package/.output/server/node_modules/chokidar/handler.js +632 -0
  11. package/.output/server/node_modules/chokidar/index.js +822 -0
  12. package/.output/server/node_modules/chokidar/package.json +63 -0
  13. package/.output/server/node_modules/normalize-path/index.js +35 -0
  14. package/.output/server/node_modules/normalize-path/package.json +77 -0
  15. package/.output/server/node_modules/picomatch/index.js +3 -0
  16. package/.output/server/node_modules/picomatch/lib/constants.js +179 -0
  17. package/.output/server/node_modules/picomatch/lib/parse.js +1091 -0
  18. package/.output/server/node_modules/picomatch/lib/picomatch.js +342 -0
  19. package/.output/server/node_modules/picomatch/lib/scan.js +391 -0
  20. package/.output/server/node_modules/picomatch/lib/utils.js +64 -0
  21. package/.output/server/node_modules/picomatch/package.json +81 -0
  22. package/.output/server/node_modules/readdirp/index.js +272 -0
  23. package/.output/server/node_modules/readdirp/package.json +66 -0
  24. package/.output/server/package.json +6 -1
  25. package/README.md +98 -42
  26. package/package.json +16 -23
@@ -1,10 +1,15 @@
1
- import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};import http, { Server as Server$2 } from 'node:http';
1
+ import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};import urlNode from 'node:url'
2
+ import pathNode from 'node:path'
3
+ const __filename = urlNode.fileURLToPath(globalThis._importMeta_.url)
4
+ const __dirname = pathNode.dirname(__filename)
5
+ import http, { Server as Server$2 } from 'node:http';
2
6
  import https, { Server as Server$1 } from 'node:https';
3
7
  import { EventEmitter } from 'node:events';
4
8
  import { Buffer as Buffer$1 } from 'node:buffer';
5
- import fs$2, { promises, existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
6
- import path$2, { resolve, dirname, join, relative, normalize } from 'node:path';
7
- import nodeCrypto, { createHash } from 'node:crypto';
9
+ import fs$2, { promises, existsSync, readFileSync, writeFileSync } from 'node:fs';
10
+ import path$2, { resolve, dirname, relative, join, normalize } from 'node:path';
11
+ import anymatch from 'anymatch';
12
+ import { createHash, randomBytes } from 'node:crypto';
8
13
  import process$1, { version as version$2 } from 'node:process';
9
14
  import { orderBy } from 'natural-orderby';
10
15
  import { merge as merge$1, mergeDeep, isPlainObject as isPlainObject$1, uniqueWith, isDeepEqual, isNumber, isFunction, difference } from 'remeda';
@@ -2597,11 +2602,11 @@ function defineDriver$1(factory) {
2597
2602
  return factory;
2598
2603
  }
2599
2604
 
2600
- const DRIVER_NAME$1 = "memory";
2605
+ const DRIVER_NAME$2 = "memory";
2601
2606
  const memory = defineDriver$1(() => {
2602
2607
  const data = /* @__PURE__ */ new Map();
2603
2608
  return {
2604
- name: DRIVER_NAME$1,
2609
+ name: DRIVER_NAME$2,
2605
2610
  getInstance: () => data,
2606
2611
  hasItem(key) {
2607
2612
  return data.has(key);
@@ -3150,6 +3155,118 @@ async function rmRecursive(dir) {
3150
3155
  );
3151
3156
  }
3152
3157
 
3158
+ const PATH_TRAVERSE_RE$1 = /\.\.:|\.\.$/;
3159
+ const DRIVER_NAME$1 = "fs";
3160
+ const unstorage_47drivers_47fs = defineDriver((userOptions = {}) => {
3161
+ if (!userOptions.base) {
3162
+ throw createRequiredError(DRIVER_NAME$1, "base");
3163
+ }
3164
+ const base = resolve(userOptions.base);
3165
+ const ignore = anymatch(
3166
+ userOptions.ignore || ["**/node_modules/**", "**/.git/**"]
3167
+ );
3168
+ const r = (key) => {
3169
+ if (PATH_TRAVERSE_RE$1.test(key)) {
3170
+ throw createError(
3171
+ DRIVER_NAME$1,
3172
+ `Invalid key: ${JSON.stringify(key)}. It should not contain .. segments`
3173
+ );
3174
+ }
3175
+ const resolved = join(base, key.replace(/:/g, "/"));
3176
+ return resolved;
3177
+ };
3178
+ let _watcher;
3179
+ const _unwatch = async () => {
3180
+ if (_watcher) {
3181
+ await _watcher.close();
3182
+ _watcher = void 0;
3183
+ }
3184
+ };
3185
+ return {
3186
+ name: DRIVER_NAME$1,
3187
+ options: userOptions,
3188
+ flags: {
3189
+ maxDepth: true
3190
+ },
3191
+ hasItem(key) {
3192
+ return existsSync(r(key));
3193
+ },
3194
+ getItem(key) {
3195
+ return readFile(r(key), "utf8");
3196
+ },
3197
+ getItemRaw(key) {
3198
+ return readFile(r(key));
3199
+ },
3200
+ async getMeta(key) {
3201
+ const { atime, mtime, size, birthtime, ctime } = await promises.stat(r(key)).catch(() => ({}));
3202
+ return { atime, mtime, size, birthtime, ctime };
3203
+ },
3204
+ setItem(key, value) {
3205
+ if (userOptions.readOnly) {
3206
+ return;
3207
+ }
3208
+ return writeFile(r(key), value, "utf8");
3209
+ },
3210
+ setItemRaw(key, value) {
3211
+ if (userOptions.readOnly) {
3212
+ return;
3213
+ }
3214
+ return writeFile(r(key), value);
3215
+ },
3216
+ removeItem(key) {
3217
+ if (userOptions.readOnly) {
3218
+ return;
3219
+ }
3220
+ return unlink(r(key));
3221
+ },
3222
+ getKeys(_base, topts) {
3223
+ return readdirRecursive(r("."), ignore, topts?.maxDepth);
3224
+ },
3225
+ async clear() {
3226
+ if (userOptions.readOnly || userOptions.noClear) {
3227
+ return;
3228
+ }
3229
+ await rmRecursive(r("."));
3230
+ },
3231
+ async dispose() {
3232
+ if (_watcher) {
3233
+ await _watcher.close();
3234
+ }
3235
+ },
3236
+ async watch(callback) {
3237
+ if (_watcher) {
3238
+ return _unwatch;
3239
+ }
3240
+ const { watch } = await import('chokidar');
3241
+ await new Promise((resolve2, reject) => {
3242
+ const watchOptions = {
3243
+ ignoreInitial: true,
3244
+ ...userOptions.watchOptions
3245
+ };
3246
+ if (!watchOptions.ignored) {
3247
+ watchOptions.ignored = [];
3248
+ } else if (Array.isArray(watchOptions.ignored)) {
3249
+ watchOptions.ignored = [...watchOptions.ignored];
3250
+ } else {
3251
+ watchOptions.ignored = [watchOptions.ignored];
3252
+ }
3253
+ watchOptions.ignored.push(ignore);
3254
+ _watcher = watch(base, watchOptions).on("ready", () => {
3255
+ resolve2();
3256
+ }).on("error", reject).on("all", (eventName, path) => {
3257
+ path = relative(base, path);
3258
+ if (eventName === "change" || eventName === "add") {
3259
+ callback("update", path);
3260
+ } else if (eventName === "unlink") {
3261
+ callback("remove", path);
3262
+ }
3263
+ });
3264
+ });
3265
+ return _unwatch;
3266
+ }
3267
+ };
3268
+ });
3269
+
3153
3270
  const PATH_TRAVERSE_RE = /\.\.:|\.\.$/;
3154
3271
  const DRIVER_NAME = "fs-lite";
3155
3272
  const unstorage_47drivers_47fs_45lite = defineDriver((opts = {}) => {
@@ -3220,6 +3337,7 @@ const storage = createStorage({});
3220
3337
 
3221
3338
  storage.mount('/assets', assets);
3222
3339
 
3340
+ storage.mount('kubb', unstorage_47drivers_47fs({"driver":"fs","base":"./.kubb/cache"}));
3223
3341
  storage.mount('data', unstorage_47drivers_47fs_45lite({"driver":"fsLite","base":"./.data/kv"}));
3224
3342
 
3225
3343
  function useStorage(base = "") {
@@ -5891,25 +6009,14 @@ function serializePluginOptions(options) {
5891
6009
  function isCommandMessage(msg) {
5892
6010
  return msg.type === "command";
5893
6011
  }
5894
-
5895
- const CONFIG_DIR = path$2.join(os$1.homedir(), ".kubb");
5896
- const CONFIG_FILE = path$2.join(CONFIG_DIR, "config.json");
5897
- function loadAgentConfig() {
5898
- try {
5899
- const content = readFileSync(CONFIG_FILE, "utf-8");
5900
- return JSON.parse(content);
5901
- } catch (_error) {
5902
- return { sessions: {} };
5903
- }
6012
+ function isPongMessage(msg) {
6013
+ return msg.type === "pong";
5904
6014
  }
5905
- function saveAgentConfig(config) {
5906
- try {
5907
- mkdirSync(CONFIG_DIR, { recursive: true });
5908
- writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8");
5909
- } catch (_error) {
5910
- logger.warn("Failed to save agent config");
5911
- }
6015
+
6016
+ function getSessionKey(token) {
6017
+ return `sessions:${createHash("sha512").update(token).digest("hex")}`;
5912
6018
  }
6019
+
5913
6020
  function isSessionValid(session) {
5914
6021
  try {
5915
6022
  const expiresAt = new Date(session.expiresAt);
@@ -5919,60 +6026,17 @@ function isSessionValid(session) {
5919
6026
  return false;
5920
6027
  }
5921
6028
  }
5922
- function getCachedSession(agentToken) {
5923
- var _a;
5924
- try {
5925
- const config = loadAgentConfig();
5926
- const sessionKey = hashAgentToken(agentToken);
5927
- const session = (_a = config.sessions) == null ? void 0 : _a[sessionKey];
5928
- if (!session) {
5929
- return null;
5930
- }
5931
- if (!isSessionValid(session)) {
5932
- deleteCachedSession(agentToken);
5933
- return null;
5934
- }
5935
- return session;
5936
- } catch (_error) {
5937
- logger.warn("Failed to get cached session");
5938
- return null;
5939
- }
6029
+
6030
+ function generateToken() {
6031
+ return randomBytes(32).toString("hex");
5940
6032
  }
5941
- function cacheSession(agentToken, session) {
5942
- try {
5943
- const config = loadAgentConfig();
5944
- const sessionKey = hashAgentToken(agentToken);
5945
- if (!config.sessions) {
5946
- config.sessions = {};
5947
- }
5948
- config.sessions[sessionKey] = {
5949
- ...session,
5950
- storedAt: (/* @__PURE__ */ new Date()).toISOString()
5951
- };
5952
- saveAgentConfig(config);
5953
- logger.success("Cached agent session");
5954
- } catch (_error) {
5955
- logger.warn("Failed to cache session");
5956
- }
6033
+ function generateSecureToken(id = generateToken()) {
6034
+ return createHash("sha256").update(id).digest("hex");
5957
6035
  }
5958
- function deleteCachedSession(agentToken) {
5959
- var _a;
5960
- try {
5961
- const config = loadAgentConfig();
5962
- const sessionKey = hashAgentToken(agentToken);
5963
- if ((_a = config.sessions) == null ? void 0 : _a[sessionKey]) {
5964
- delete config.sessions[sessionKey];
5965
- saveAgentConfig(config);
5966
- }
5967
- } catch (_error) {
5968
- logger.warn("Failed to delete cached session");
6036
+ function generateMachineToken() {
6037
+ if (process.env.KUBB_AGENT_SECRET) {
6038
+ return generateSecureToken(process.env.KUBB_AGENT_SECRET);
5969
6039
  }
5970
- }
5971
- function hashAgentToken(token) {
5972
- return createHash("sha512").update(token).digest("hex");
5973
- }
5974
-
5975
- function getMachineId() {
5976
6040
  const interfaces = os$1.networkInterfaces();
5977
6041
  const macs = [];
5978
6042
  for (const name in interfaces) {
@@ -5984,30 +6048,43 @@ function getMachineId() {
5984
6048
  }
5985
6049
  const hostname = os$1.hostname();
5986
6050
  const rawId = macs.join(",") + hostname;
5987
- return nodeCrypto.createHash("sha256").update(rawId).digest("hex");
6051
+ return generateSecureToken(rawId);
5988
6052
  }
5989
6053
 
5990
6054
  async function createAgentSession({ token, studioUrl, noCache }) {
5991
- const cachedSession = !noCache ? getCachedSession(token) : null;
5992
- if (cachedSession) {
5993
- logger.success("Using cached agent session");
5994
- return cachedSession;
6055
+ const storage = useStorage("kubb");
6056
+ if (!noCache) {
6057
+ const sessionKey = getSessionKey(token);
6058
+ const stored = await storage.getItem(sessionKey);
6059
+ if (stored && isSessionValid(stored)) {
6060
+ logger.success("Using cached agent session");
6061
+ return stored;
6062
+ }
6063
+ if (stored) {
6064
+ await storage.removeItem(sessionKey);
6065
+ }
5995
6066
  }
5996
6067
  const connectUrl = `${studioUrl}/api/agent/session/create`;
5997
6068
  try {
6069
+ const machineToken = generateMachineToken();
5998
6070
  const data = await $fetch(connectUrl, {
5999
6071
  method: "POST",
6000
6072
  headers: {
6001
6073
  Authorization: `Bearer ${token}`
6002
6074
  },
6003
- body: { machineId: getMachineId() }
6075
+ body: { machineToken }
6004
6076
  });
6005
- if (data && !noCache) {
6006
- cacheSession(token, data);
6007
- }
6008
6077
  if (!data) {
6009
6078
  throw new Error("No data available for agent session");
6010
6079
  }
6080
+ if (!noCache) {
6081
+ const sessionKey = getSessionKey(token);
6082
+ await storage.setItem(sessionKey, {
6083
+ ...data,
6084
+ storedAt: (/* @__PURE__ */ new Date()).toISOString()
6085
+ });
6086
+ logger.success("Cached agent session");
6087
+ }
6011
6088
  logger.success("Agent session created");
6012
6089
  return data;
6013
6090
  } catch (error) {
@@ -6016,7 +6093,7 @@ async function createAgentSession({ token, studioUrl, noCache }) {
6016
6093
  }
6017
6094
  async function registerAgent({ token, studioUrl }) {
6018
6095
  var _a, _b;
6019
- const machineId = getMachineId();
6096
+ const machineToken = generateMachineToken();
6020
6097
  const registerUrl = `${studioUrl}/api/agent/register`;
6021
6098
  try {
6022
6099
  await $fetch(registerUrl, {
@@ -6024,7 +6101,7 @@ async function registerAgent({ token, studioUrl }) {
6024
6101
  headers: {
6025
6102
  Authorization: `Bearer ${token}`
6026
6103
  },
6027
- body: { machineId }
6104
+ body: { machineToken }
6028
6105
  });
6029
6106
  logger.success("Agent registered with Studio");
6030
6107
  } catch (error) {
@@ -6079,7 +6156,7 @@ var BaseGenerator = (_a$3 = class {
6079
6156
  function isInputPath(config) {
6080
6157
  return typeof (config == null ? void 0 : config.input) === "object" && config.input !== null && "path" in config.input;
6081
6158
  }
6082
- var version$1 = "4.27.4";
6159
+ var version$1 = "4.28.1";
6083
6160
  function getDiagnosticInfo() {
6084
6161
  return {
6085
6162
  nodeVersion: version$2,
@@ -12419,9 +12496,13 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
12419
12496
  }
12420
12497
  }, ...baseItems];
12421
12498
  }
12499
+ if (schemaObject.type === "string" && schemaObject.contentMediaType === "application/octet-stream") {
12500
+ baseItems.unshift({ keyword: schemaKeywords.blob });
12501
+ return baseItems;
12502
+ }
12422
12503
  if (schemaObject.format) {
12423
12504
  if (schemaObject.type === "integer" && schemaObject.format === "int64") {
12424
- baseItems.unshift({ keyword: schemaKeywords.bigint });
12505
+ baseItems.unshift({ keyword: options.integerType === "number" ? schemaKeywords.integer : schemaKeywords.bigint });
12425
12506
  return baseItems;
12426
12507
  }
12427
12508
  if (schemaObject.type === "integer" && schemaObject.format === "int32") {
@@ -12634,6 +12715,27 @@ parseSchemaObject_fn = function({ schema: _schemaObject, name, parentName, rootN
12634
12715
  }));
12635
12716
  return (await Promise.all(writeTasks)).flat();
12636
12717
  }, _b);
12718
+ function getRequestBody(operationSchema) {
12719
+ var _a2, _b2;
12720
+ const requestBody = (_b2 = (_a2 = operationSchema == null ? void 0 : operationSchema.operation) == null ? void 0 : _a2.schema) == null ? void 0 : _b2.requestBody;
12721
+ if (!requestBody || "$ref" in requestBody) return;
12722
+ return requestBody;
12723
+ }
12724
+ function isRequestBodyRequired(operationSchema) {
12725
+ const requestBody = getRequestBody(operationSchema);
12726
+ return !!requestBody && requestBody.required === true;
12727
+ }
12728
+ function withRequiredRequestBodySchema(operationSchema) {
12729
+ if (!operationSchema || !isRequestBodyRequired(operationSchema)) return operationSchema;
12730
+ if (Array.isArray(operationSchema.schema.required) && operationSchema.schema.required.length > 0) return operationSchema;
12731
+ return {
12732
+ ...operationSchema,
12733
+ schema: {
12734
+ ...operationSchema.schema,
12735
+ required: ["__kubb_required_request_body__"]
12736
+ }
12737
+ };
12738
+ }
12637
12739
 
12638
12740
  function getDefaultBanner({ title, description, version, config }) {
12639
12741
  try {
@@ -13377,6 +13479,18 @@ var OperationGenerator = (_a = class extends BaseGenerator {
13377
13479
  var _a3, _b2;
13378
13480
  return ((_a3 = item.statusCode) == null ? void 0 : _a3.toString().startsWith("4")) || ((_b2 = item.statusCode) == null ? void 0 : _b2.toString().startsWith("5"));
13379
13481
  });
13482
+ const request = withRequiredRequestBodySchema(requestSchema ? {
13483
+ name: this.context.UNSTABLE_NAMING ? resolveName(transformers_default.pascalCase(`${operationId} RequestData`)) : resolveName(transformers_default.pascalCase(`${operationId} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
13484
+ description: (_a2 = operation.schema.requestBody) == null ? void 0 : _a2.description,
13485
+ operation,
13486
+ operationName,
13487
+ schema: requestSchema,
13488
+ keys: resolveKeys(requestSchema),
13489
+ keysToOmit: (_b = resolveKeys(requestSchema)) == null ? void 0 : _b.filter((key) => {
13490
+ var _a3, _b2;
13491
+ return (_b2 = (_a3 = requestSchema.properties) == null ? void 0 : _a3[key]) == null ? void 0 : _b2.readOnly;
13492
+ })
13493
+ } : void 0);
13380
13494
  return {
13381
13495
  pathParams: pathParamsSchema ? {
13382
13496
  name: resolveName(transformers_default.pascalCase(`${operationId} PathParams`)),
@@ -13399,18 +13513,7 @@ var OperationGenerator = (_a = class extends BaseGenerator {
13399
13513
  schema: headerParamsSchema,
13400
13514
  keys: resolveKeys(headerParamsSchema)
13401
13515
  } : void 0,
13402
- request: requestSchema ? {
13403
- name: this.context.UNSTABLE_NAMING ? resolveName(transformers_default.pascalCase(`${operationId} RequestData`)) : resolveName(transformers_default.pascalCase(`${operationId} ${operation.method === "get" ? "queryRequest" : "mutationRequest"}`)),
13404
- description: (_a2 = operation.schema.requestBody) == null ? void 0 : _a2.description,
13405
- operation,
13406
- operationName,
13407
- schema: requestSchema,
13408
- keys: resolveKeys(requestSchema),
13409
- keysToOmit: (_b = resolveKeys(requestSchema)) == null ? void 0 : _b.filter((key) => {
13410
- var _a3, _b2;
13411
- return (_b2 = (_a3 = requestSchema.properties) == null ? void 0 : _a3[key]) == null ? void 0 : _b2.readOnly;
13412
- })
13413
- } : void 0,
13516
+ request,
13414
13517
  response: {
13415
13518
  name: this.context.UNSTABLE_NAMING ? resolveName(transformers_default.pascalCase(`${operationId} ResponseData`)) : resolveName(transformers_default.pascalCase(`${operationId} ${operation.method === "get" ? "queryResponse" : "mutationResponse"}`)),
13416
13519
  operation,
@@ -213376,13 +213479,14 @@ const pluginTs = definePlugin((options) => {
213376
213479
  const { output = {
213377
213480
  path: "types",
213378
213481
  barrelType: "named"
213379
- }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers: transformers$1 = {}, mapper = {}, paramsCasing, generators = [typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
213482
+ }, group, exclude = [], include, override = [], enumType = "asConst", enumKeyCasing = "none", enumSuffix = "enum", dateType = "string", integerType = "bigint", unknownType = "any", optionalType = "questionToken", arrayType = "array", emptySchemaType = unknownType, syntaxType = "type", transformers: transformers$1 = {}, mapper = {}, paramsCasing, generators = [typeGenerator].filter(Boolean), contentType, UNSTABLE_NAMING } = options;
213380
213483
  return {
213381
213484
  name: pluginTsName,
213382
213485
  options: {
213383
213486
  output,
213384
213487
  transformers: transformers$1,
213385
213488
  dateType,
213489
+ integerType,
213386
213490
  optionalType,
213387
213491
  arrayType,
213388
213492
  enumType,
@@ -216383,7 +216487,9 @@ function QueryOptions$4({ name, clientName, dataReturnType, typeSchemas, paramsC
216383
216487
  ${enabledText}
216384
216488
  queryKey,
216385
216489
  queryFn: async ({ signal }) => {
216386
- config.signal = signal
216490
+ if (!config.signal) {
216491
+ config.signal = signal
216492
+ }
216387
216493
  return ${clientName}(${clientParams.toCall({})})
216388
216494
  },
216389
216495
  })
@@ -216673,7 +216779,9 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
216673
216779
  ${enabledText}
216674
216780
  queryKey,
216675
216781
  queryFn: async ({ signal, pageParam }) => {
216676
- config.signal = signal
216782
+ if (!config.signal) {
216783
+ config.signal = signal
216784
+ }
216677
216785
  ${infiniteOverrideParams}
216678
216786
  return ${clientName}(${clientParams.toCall()})
216679
216787
  },
@@ -216696,7 +216804,9 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
216696
216804
  ${enabledText}
216697
216805
  queryKey,
216698
216806
  queryFn: async ({ signal }) => {
216699
- config.signal = signal
216807
+ if (!config.signal) {
216808
+ config.signal = signal
216809
+ }
216700
216810
  return ${clientName}(${clientParams.toCall()})
216701
216811
  },
216702
216812
  ${queryOptions.join(",\n")}
@@ -217351,7 +217461,9 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
217351
217461
  ${enabledText}
217352
217462
  queryKey,
217353
217463
  queryFn: async ({ signal, pageParam }) => {
217354
- config.signal = signal
217464
+ if (!config.signal) {
217465
+ config.signal = signal
217466
+ }
217355
217467
  ${infiniteOverrideParams}
217356
217468
  return ${clientName}(${clientParams.toCall()})
217357
217469
  },
@@ -217374,7 +217486,9 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
217374
217486
  ${enabledText}
217375
217487
  queryKey,
217376
217488
  queryFn: async ({ signal }) => {
217377
- config.signal = signal
217489
+ if (!config.signal) {
217490
+ config.signal = signal
217491
+ }
217378
217492
  return ${clientName}(${clientParams.toCall()})
217379
217493
  },
217380
217494
  ${queryOptions.join(",\n")}
@@ -219465,7 +219579,9 @@ function QueryOptions$3({ name, clientName, typeSchemas, paramsCasing, paramsTyp
219465
219579
  ${enabledText}
219466
219580
  queryKey,
219467
219581
  queryFn: async ({ signal }) => {
219468
- config.signal = signal
219582
+ if (!config.signal) {
219583
+ config.signal = signal
219584
+ }
219469
219585
  return ${clientName}(${clientParams.toCall()})
219470
219586
  },
219471
219587
  })
@@ -220476,7 +220592,9 @@ function QueryOptions$2({ name, clientName, typeSchemas, paramsCasing, paramsTyp
220476
220592
  ${enabledText}
220477
220593
  queryKey,
220478
220594
  queryFn: async ({ signal }) => {
220479
- config.signal = signal
220595
+ if (!config.signal) {
220596
+ config.signal = signal
220597
+ }
220480
220598
  return ${clientName}(${clientParams.toCall()})
220481
220599
  },
220482
220600
  })
@@ -222382,7 +222500,9 @@ function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCas
222382
222500
  ${enabledText}
222383
222501
  queryKey,
222384
222502
  queryFn: async ({ signal }) => {
222385
- config.signal = signal
222503
+ if (!config.signal) {
222504
+ config.signal = signal
222505
+ }
222386
222506
  return ${clientName}(${clientParams.toCall({ transformName(name$1) {
222387
222507
  return `toValue(${name$1})`;
222388
222508
  } })})
@@ -222693,7 +222813,9 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
222693
222813
  ${enabledText}
222694
222814
  queryKey,
222695
222815
  queryFn: async ({ signal, pageParam }) => {
222696
- config.signal = signal
222816
+ if (!config.signal) {
222817
+ config.signal = signal
222818
+ }
222697
222819
  ${infiniteOverrideParams}
222698
222820
  return ${clientName}(${clientParams.toCall({ transformName(name$1) {
222699
222821
  return `toValue(${name$1})`;
@@ -223808,25 +223930,25 @@ const pluginVueQuery = definePlugin((options) => {
223808
223930
  };
223809
223931
  });
223810
223932
 
223811
- const pluginRegistry = {
223812
- "@kubb/plugin-client": pluginClient,
223813
- "@kubb/plugin-cypress": pluginCypress,
223814
- "@kubb/plugin-faker": pluginFaker,
223815
- "@kubb/plugin-mcp": pluginMcp,
223816
- "@kubb/plugin-msw": pluginMsw,
223817
- "@kubb/plugin-oas": pluginOas,
223818
- "@kubb/plugin-react-query": pluginReactQuery,
223819
- "@kubb/plugin-redoc": pluginRedoc,
223820
- "@kubb/plugin-solid-query": pluginSolidQuery,
223821
- "@kubb/plugin-svelte-query": pluginSvelteQuery,
223822
- "@kubb/plugin-swr": pluginSwr,
223823
- "@kubb/plugin-ts": pluginTs,
223824
- "@kubb/plugin-vue-query": pluginVueQuery,
223825
- "@kubb/plugin-zod": pluginZod
223826
- };
223933
+ const pluginRegistry = /* @__PURE__ */ new Map([
223934
+ ["@kubb/plugin-client", pluginClient],
223935
+ ["@kubb/plugin-cypress", pluginCypress],
223936
+ ["@kubb/plugin-faker", pluginFaker],
223937
+ ["@kubb/plugin-mcp", pluginMcp],
223938
+ ["@kubb/plugin-msw", pluginMsw],
223939
+ ["@kubb/plugin-oas", pluginOas],
223940
+ ["@kubb/plugin-react-query", pluginReactQuery],
223941
+ ["@kubb/plugin-redoc", pluginRedoc],
223942
+ ["@kubb/plugin-solid-query", pluginSolidQuery],
223943
+ ["@kubb/plugin-svelte-query", pluginSvelteQuery],
223944
+ ["@kubb/plugin-swr", pluginSwr],
223945
+ ["@kubb/plugin-ts", pluginTs],
223946
+ ["@kubb/plugin-vue-query", pluginVueQuery],
223947
+ ["@kubb/plugin-zod", pluginZod]
223948
+ ]);
223827
223949
  function resolvePlugins(plugins) {
223828
223950
  return plugins.map(({ name, options }) => {
223829
- const factory = pluginRegistry[name];
223951
+ const factory = pluginRegistry.get(name);
223830
223952
  if (typeof factory !== "function") {
223831
223953
  throw new Error(`Plugin "${name}" is not supported. Supported plugins: ${Object.keys(pluginRegistry).join(", ")}`);
223832
223954
  }
@@ -223979,7 +224101,7 @@ function setupEventsStream(ws, events) {
223979
224101
  });
223980
224102
  }
223981
224103
 
223982
- var version = "4.27.4";
224104
+ var version = "4.28.1";
223983
224105
 
223984
224106
  const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nitro) => {
223985
224107
  const studioUrl = process$1.env.KUBB_STUDIO_URL || "https://studio.kubb.dev";
@@ -223996,6 +224118,7 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
223996
224118
  }
223997
224119
  const resolvedConfigPath = path$2.isAbsolute(configPath) ? configPath : path$2.resolve(root, configPath);
223998
224120
  const events = new AsyncEventEmitter();
224121
+ const storage = useStorage("kubb");
223999
224122
  async function loadConfig() {
224000
224123
  const result = await getCosmiConfig(resolvedConfigPath);
224001
224124
  const configs = await getConfigs(result.config, {});
@@ -224048,7 +224171,7 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224048
224171
  }
224049
224172
  async function connectToStudio() {
224050
224173
  try {
224051
- const { sessionToken, wsUrl } = await createAgentSession({
224174
+ const { sessionToken, wsUrl, isSandbox } = await createAgentSession({
224052
224175
  noCache,
224053
224176
  token,
224054
224177
  studioUrl
@@ -224057,10 +224180,13 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224057
224180
  const onError = async () => {
224058
224181
  cleanup();
224059
224182
  logger.error(`Failed to connect to Kubb Studio on "${wsUrl}"`);
224060
- const cachedSession = !noCache ? getCachedSession(token) : null;
224061
- if (cachedSession) {
224062
- deleteCachedSession(token);
224063
- await reconnectToStudio();
224183
+ if (!noCache) {
224184
+ const sessionKey = getSessionKey(token);
224185
+ const stored = await storage.getItem(sessionKey);
224186
+ if (stored && isSessionValid(stored)) {
224187
+ await storage.removeItem(sessionKey);
224188
+ await reconnectToStudio();
224189
+ }
224064
224190
  }
224065
224191
  };
224066
224192
  const onOpen = () => {
@@ -224075,7 +224201,7 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224075
224201
  studioUrl,
224076
224202
  token
224077
224203
  }).catch(async () => {
224078
- deleteCachedSession(token);
224204
+ await storage.removeItem(getSessionKey(token));
224079
224205
  await reconnectToStudio();
224080
224206
  });
224081
224207
  }
@@ -224096,23 +224222,35 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224096
224222
  }, 3e4);
224097
224223
  setupEventsStream(ws, events);
224098
224224
  ws.addEventListener("message", async (message) => {
224099
- var _a, _b, _c;
224225
+ var _a, _b, _c, _d;
224100
224226
  try {
224101
224227
  const data = JSON.parse(message.data);
224228
+ if (isPongMessage(data)) {
224229
+ logger.info("Received pong from Studio");
224230
+ return;
224231
+ }
224102
224232
  if (isCommandMessage(data)) {
224103
224233
  if (data.command === "generate") {
224104
224234
  const config = await loadConfig();
224105
224235
  const studioConfig = readStudioConfig(resolvedConfigPath);
224106
224236
  const patch = (_a = data.payload) != null ? _a : studioConfig;
224107
224237
  const resolvedPlugins = (patch == null ? void 0 : patch.plugins) ? resolvePlugins(patch.plugins) : void 0;
224238
+ if (allowWrite && isSandbox) {
224239
+ logger.warn("Agent is running in a sandbox environment, write will be disabled");
224240
+ }
224241
+ if ((patch == null ? void 0 : patch.input) && !isSandbox) {
224242
+ logger.warn("Input override via payload is only supported in sandbox mode and will be ignored");
224243
+ }
224244
+ const inputOverride = isSandbox ? { data: (_b = patch.input) != null ? _b : "" } : void 0;
224108
224245
  await generate({
224109
224246
  config: {
224110
224247
  ...config,
224248
+ input: inputOverride != null ? inputOverride : config.input,
224111
224249
  plugins: resolvedPlugins != null ? resolvedPlugins : config.plugins,
224112
224250
  root,
224113
224251
  output: {
224114
224252
  ...config.output,
224115
- write: allowWrite
224253
+ write: isSandbox ? false : allowWrite
224116
224254
  }
224117
224255
  },
224118
224256
  events
@@ -224130,11 +224268,11 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224130
224268
  version,
224131
224269
  configPath,
224132
224270
  permissions: {
224133
- allowAll,
224134
- allowWrite
224271
+ allowAll: isSandbox ? false : allowWrite,
224272
+ allowWrite: isSandbox ? false : allowWrite
224135
224273
  },
224136
224274
  config: {
224137
- plugins: (_b = config.plugins) == null ? void 0 : _b.map((plugin) => ({
224275
+ plugins: (_c = config.plugins) == null ? void 0 : _c.map((plugin) => ({
224138
224276
  name: `@kubb/${plugin.name}`,
224139
224277
  options: serializePluginOptions(plugin.options)
224140
224278
  }))
@@ -224146,11 +224284,11 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
224146
224284
  }
224147
224285
  logger.warn(`Unknown message type from Kubb Studio: ${message.data}`);
224148
224286
  } catch (error) {
224149
- logger.error(`[unhandledRejection] ${(_c = error == null ? void 0 : error.message) != null ? _c : error}`);
224287
+ logger.error(`[unhandledRejection] ${(_d = error == null ? void 0 : error.message) != null ? _d : error}`);
224150
224288
  }
224151
224289
  });
224152
224290
  } catch (error) {
224153
- deleteCachedSession(token);
224291
+ await storage.removeItem(getSessionKey(token));
224154
224292
  logger.error(`Something went wrong ${error}`);
224155
224293
  await reconnectToStudio();
224156
224294
  }