@kubb/agent 4.29.1 → 4.31.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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +542 -380
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +3 -1
- package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
- package/.output/server/index.mjs +3 -1
- package/.output/server/index.mjs.map +1 -1
- package/.output/server/node_modules/@kubb/fabric-core/dist/chunk-BVHe6Par.js +22 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/{defaultParser-C1atU7yU.js → defaultParser-BD_N68Bo.js} +3 -2
- package/.output/server/node_modules/@kubb/fabric-core/dist/{getRelativePath-BcieQL5M.js → getRelativePath-C4Au07ON.js} +2 -1
- package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +8 -4
- package/.output/server/node_modules/@kubb/fabric-core/dist/{onProcessExit-CF200hsz.js → onProcessExit-CnZym153.js} +10 -3
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers/typescript.js +2 -1
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers.js +3 -2
- package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +3 -2
- package/.output/server/node_modules/@kubb/fabric-core/package.json +3 -2
- package/.output/server/node_modules/@kubb/react-fabric/dist/{chunk-Cnw5r_-A.js → chunk-DbZtQ4qb.js} +5 -1
- package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +4 -4
- package/.output/server/node_modules/@kubb/react-fabric/dist/{jsx-runtime-Dm7PKVbc.js → jsx-runtime-CZxrhUx8.js} +24 -5
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime.js +3 -3
- package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +3 -3
- package/.output/server/node_modules/@kubb/react-fabric/dist/{react-D652OKii.js → react-C2cYsofv.js} +87 -26
- package/.output/server/node_modules/@kubb/react-fabric/dist/{reactPlugin-BkDkx1cs.js → reactPlugin-DGKBWjiR.js} +1454 -317
- package/.output/server/node_modules/@kubb/react-fabric/package.json +4 -3
- package/.output/server/node_modules/@logtail/core/dist/cjs/base.js +339 -0
- package/.output/server/node_modules/@logtail/core/dist/cjs/index.js +9 -0
- package/.output/server/node_modules/@logtail/core/package.json +45 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/context.js +93 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/index.js +6 -0
- package/.output/server/node_modules/@logtail/node/dist/cjs/node.js +106 -0
- package/.output/server/node_modules/@logtail/node/package.json +53 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/batch.js +122 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/burstProtection.js +50 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/encode.js +12 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/index.js +41 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/queue.js +41 -0
- package/.output/server/node_modules/@logtail/tools/dist/cjs/throttle.js +67 -0
- package/.output/server/node_modules/@logtail/tools/package.json +39 -0
- package/.output/server/node_modules/@logtail/types/dist/cjs/types.js +21 -0
- package/.output/server/node_modules/@logtail/types/package.json +45 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/CachedKeyDecoder.js +63 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/DecodeError.js +18 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/Decoder.js +583 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/Encoder.js +408 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/ExtData.js +14 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/ExtensionCodec.js +72 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/decode.js +32 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/decodeAsync.js +44 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/encode.js +17 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/index.js +34 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/timestamp.js +104 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/int.js +34 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/prettyByte.js +8 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/stream.js +40 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/typedArrays.js +28 -0
- package/.output/server/node_modules/@msgpack/msgpack/dist/utils/utf8.js +167 -0
- package/.output/server/node_modules/@msgpack/msgpack/package.json +100 -0
- package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
- package/.output/server/node_modules/consola/dist/core.mjs +512 -0
- package/.output/server/node_modules/consola/dist/index.mjs +651 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
- package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
- package/.output/server/node_modules/consola/package.json +136 -0
- package/.output/server/node_modules/serialize-error/index.js +154 -0
- package/.output/server/node_modules/serialize-error/package.json +41 -0
- package/.output/server/node_modules/stack-trace/lib/stack-trace.js +136 -0
- package/.output/server/node_modules/stack-trace/package.json +21 -0
- package/.output/server/package.json +11 -3
- package/README.md +3 -3
- package/package.json +23 -18
|
@@ -6,14 +6,15 @@ import http, { Server as Server$2 } from 'node:http';
|
|
|
6
6
|
import https, { Server as Server$1 } from 'node:https';
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
8
|
import { Buffer as Buffer$1 } from 'node:buffer';
|
|
9
|
-
import fs$1, { promises, existsSync, readFileSync
|
|
9
|
+
import fs$1, { promises, existsSync, readFileSync } from 'node:fs';
|
|
10
10
|
import path$2, { resolve, dirname, relative, join, normalize } from 'node:path';
|
|
11
11
|
import anymatch from 'anymatch';
|
|
12
|
-
import { createHash } from 'node:crypto';
|
|
12
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
13
13
|
import process$1, { version as version$2 } from 'node:process';
|
|
14
|
+
import { Logtail } from '@logtail/node';
|
|
15
|
+
import { consola } from 'consola';
|
|
14
16
|
import { sortBy, mergeDeep, isPlainObject as isPlainObject$1, uniqueWith, isDeepEqual, isNumber, isFunction, difference } from 'remeda';
|
|
15
17
|
import { x } from 'tinyexec';
|
|
16
|
-
import os$1 from 'node:os';
|
|
17
18
|
import { styleText } from 'node:util';
|
|
18
19
|
import { access, rm, readFile as readFile$1, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
19
20
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
@@ -21,6 +22,7 @@ import mod, { createRequire } from 'node:module';
|
|
|
21
22
|
import { createFabric, createReactFabric, App, File, Function as Function$1, Const, FunctionParams, Type as Type$1, useApp } from '@kubb/react-fabric';
|
|
22
23
|
import { typescriptParser } from '@kubb/react-fabric/parsers';
|
|
23
24
|
import { fsPlugin } from '@kubb/react-fabric/plugins';
|
|
25
|
+
import os$1 from 'node:os';
|
|
24
26
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
25
27
|
import * as pkg from 'empathic/package';
|
|
26
28
|
import { coerce, satisfies } from 'semver';
|
|
@@ -4387,28 +4389,217 @@ function defineNitroPlugin(def) {
|
|
|
4387
4389
|
return def;
|
|
4388
4390
|
}
|
|
4389
4391
|
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
}
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4398
|
-
}
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4392
|
+
let logtail = null;
|
|
4393
|
+
function getLogtail() {
|
|
4394
|
+
if (logtail) {
|
|
4395
|
+
return logtail;
|
|
4396
|
+
}
|
|
4397
|
+
const token = process.env.OTLP_TOKEN;
|
|
4398
|
+
if (!token) {
|
|
4399
|
+
return null;
|
|
4400
|
+
}
|
|
4401
|
+
try {
|
|
4402
|
+
logtail = new Logtail(token, {
|
|
4403
|
+
endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT
|
|
4404
|
+
});
|
|
4405
|
+
return logtail;
|
|
4406
|
+
} catch {
|
|
4407
|
+
return null;
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
function toBetterStackContext(ctx) {
|
|
4411
|
+
if (!ctx) return void 0;
|
|
4412
|
+
const filtered = Object.fromEntries(Object.entries(ctx).filter(([, v]) => v !== void 0 && v !== null));
|
|
4413
|
+
return Object.keys(filtered).length ? filtered : void 0;
|
|
4414
|
+
}
|
|
4415
|
+
function sendToBetterStack(level, tag, message, ctx) {
|
|
4416
|
+
const client = getLogtail();
|
|
4417
|
+
if (!client) {
|
|
4418
|
+
return;
|
|
4406
4419
|
}
|
|
4420
|
+
try {
|
|
4421
|
+
const fullMessage = message !== void 0 ? `[${tag}] ${message}` : tag;
|
|
4422
|
+
const context = toBetterStackContext(ctx);
|
|
4423
|
+
if (level === "error") {
|
|
4424
|
+
client.error(fullMessage, context).then(() => client.flush());
|
|
4425
|
+
} else if (level === "warn") {
|
|
4426
|
+
client.warn(fullMessage, context).then(() => client.flush());
|
|
4427
|
+
} else {
|
|
4428
|
+
client.info(fullMessage, context).then(() => client.flush());
|
|
4429
|
+
}
|
|
4430
|
+
} catch (_e) {
|
|
4431
|
+
}
|
|
4432
|
+
}
|
|
4433
|
+
function log(level, tag, message, ctx) {
|
|
4434
|
+
const displayMessage = message !== void 0 ? `[${tag}] ${message}` : tag;
|
|
4435
|
+
consola[level](displayMessage);
|
|
4436
|
+
if (ctx) {
|
|
4437
|
+
const filtered = Object.fromEntries(Object.entries(ctx).filter(([, v]) => v !== void 0 && v !== null));
|
|
4438
|
+
if (Object.keys(filtered).length) {
|
|
4439
|
+
console.table(filtered);
|
|
4440
|
+
}
|
|
4441
|
+
}
|
|
4442
|
+
if (process.env.OTEL_EXPORTER_OTLP_ENDPOINT && process.env.OTLP_TOKEN) {
|
|
4443
|
+
sendToBetterStack(level, tag, message, ctx);
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
const logger = {
|
|
4447
|
+
info: (tag, message, ctx) => log("info", tag, message, ctx),
|
|
4448
|
+
success: (tag, message, ctx) => log("success", tag, message, ctx),
|
|
4449
|
+
warn: (tag, message, ctx) => log("warn", tag, message, ctx),
|
|
4450
|
+
error: (tag, message, ctx) => log("error", tag, message, ctx)
|
|
4407
4451
|
};
|
|
4408
4452
|
|
|
4409
4453
|
const _KZ9YuROWp70nNn4X1C4BxF_W0D7H9EWgBo03XvMd7w0 = defineNitroPlugin(() => {
|
|
4410
4454
|
});
|
|
4411
4455
|
|
|
4456
|
+
function maskedString(value, start = 8, end = 4) {
|
|
4457
|
+
if (value.length <= start + end) return value;
|
|
4458
|
+
return `${value.slice(0, start)}\u2026${value.slice(-end)}`;
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
const HEARTBEAT_INTERVAL_MS = 5 * 60 * 1e3;
|
|
4462
|
+
const _a2VEEUGb5K4b1gyM9hOmO1Xz0hUJSFuGyIT3cHsvE = defineNitroPlugin((nitro) => {
|
|
4463
|
+
const heartbeatUrl = process$1.env.KUBB_AGENT_HEARTBEAT_URL;
|
|
4464
|
+
if (!heartbeatUrl) {
|
|
4465
|
+
return;
|
|
4466
|
+
}
|
|
4467
|
+
const maskedUrl = maskedString(heartbeatUrl);
|
|
4468
|
+
const timer = setInterval(async () => {
|
|
4469
|
+
try {
|
|
4470
|
+
await $fetch(heartbeatUrl, { method: "GET" });
|
|
4471
|
+
logger.info(`Heartbeat sent to ${maskedUrl}`);
|
|
4472
|
+
} catch (error) {
|
|
4473
|
+
logger.warn(`Failed to send heartbeat to ${maskedUrl}`, error == null ? void 0 : error.message);
|
|
4474
|
+
}
|
|
4475
|
+
}, HEARTBEAT_INTERVAL_MS);
|
|
4476
|
+
nitro.hooks.hook("close", () => {
|
|
4477
|
+
clearInterval(timer);
|
|
4478
|
+
});
|
|
4479
|
+
});
|
|
4480
|
+
|
|
4481
|
+
function getStorage() {
|
|
4482
|
+
return useStorage("kubb");
|
|
4483
|
+
}
|
|
4484
|
+
function isSessionValid(session) {
|
|
4485
|
+
try {
|
|
4486
|
+
const expiresAt = new Date(session.expiresAt);
|
|
4487
|
+
const now = /* @__PURE__ */ new Date();
|
|
4488
|
+
return now.getTime() < expiresAt.getTime() - 6e4;
|
|
4489
|
+
} catch {
|
|
4490
|
+
return false;
|
|
4491
|
+
}
|
|
4492
|
+
}
|
|
4493
|
+
function getSessionKey(token) {
|
|
4494
|
+
return `sessions:${createHash("sha512").update(token).digest("hex")}`;
|
|
4495
|
+
}
|
|
4496
|
+
async function getCachedSession(sessionKey) {
|
|
4497
|
+
const storage = getStorage();
|
|
4498
|
+
const agentSession = await storage.getItem(sessionKey);
|
|
4499
|
+
if (!agentSession) {
|
|
4500
|
+
return null;
|
|
4501
|
+
}
|
|
4502
|
+
if (!isSessionValid(agentSession)) {
|
|
4503
|
+
return null;
|
|
4504
|
+
}
|
|
4505
|
+
return agentSession;
|
|
4506
|
+
}
|
|
4507
|
+
async function cacheSession({ sessionKey, session }) {
|
|
4508
|
+
const storage = getStorage();
|
|
4509
|
+
await storage.setItem(sessionKey, { ...session, storedAt: (/* @__PURE__ */ new Date()).toISOString(), configs: [] });
|
|
4510
|
+
}
|
|
4511
|
+
async function removeCachedSession(sessionKey) {
|
|
4512
|
+
const storage = getStorage();
|
|
4513
|
+
const maskedSessionKey = maskedString(sessionKey.replace("sessions:", ""));
|
|
4514
|
+
logger.info(`[${maskedSessionKey}] Removing expired agent session from cache...`);
|
|
4515
|
+
await storage.removeItem(sessionKey);
|
|
4516
|
+
logger.success(`[${maskedSessionKey}] Removed expired agent session from cache`);
|
|
4517
|
+
}
|
|
4518
|
+
async function saveStudioConfigToStorage({ sessionKey, config }) {
|
|
4519
|
+
const storage = getStorage();
|
|
4520
|
+
const agentSession = await getCachedSession(sessionKey);
|
|
4521
|
+
if (!agentSession) {
|
|
4522
|
+
throw new Error("No valid session found for retrieving previous configs");
|
|
4523
|
+
}
|
|
4524
|
+
await storage.setItem(sessionKey, { ...agentSession, configs: [...agentSession.configs, { config, storedAt: (/* @__PURE__ */ new Date()).toISOString() }] });
|
|
4525
|
+
}
|
|
4526
|
+
|
|
4527
|
+
function generateToken() {
|
|
4528
|
+
return randomBytes(32).toString("hex");
|
|
4529
|
+
}
|
|
4530
|
+
function generateMachineToken() {
|
|
4531
|
+
return process.env.KUBB_AGENT_SECRET ? process.env.KUBB_AGENT_SECRET : createHash("sha256").update(generateToken()).digest("hex");
|
|
4532
|
+
}
|
|
4533
|
+
|
|
4534
|
+
async function createAgentSession({ token, studioUrl, noCache, cacheKey }) {
|
|
4535
|
+
const machineToken = generateMachineToken();
|
|
4536
|
+
const sessionKey = cacheKey != null ? cacheKey : getSessionKey(token);
|
|
4537
|
+
const maskedSessionKey = maskedString(sessionKey.replace("sessions:", ""));
|
|
4538
|
+
const connectUrl = `${studioUrl}/api/agent/session/create`;
|
|
4539
|
+
const canCache = !noCache;
|
|
4540
|
+
if (canCache) {
|
|
4541
|
+
const cachedSession = await getCachedSession(sessionKey);
|
|
4542
|
+
if (cachedSession) {
|
|
4543
|
+
logger.success(`[${maskedSessionKey}] Using cached agent session`);
|
|
4544
|
+
return cachedSession;
|
|
4545
|
+
}
|
|
4546
|
+
await removeCachedSession(sessionKey);
|
|
4547
|
+
}
|
|
4548
|
+
try {
|
|
4549
|
+
logger.info(`[${maskedSessionKey}] Creating agent session with Studio...`);
|
|
4550
|
+
const data = await $fetch(connectUrl, {
|
|
4551
|
+
method: "POST",
|
|
4552
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
4553
|
+
body: { machineToken }
|
|
4554
|
+
});
|
|
4555
|
+
if (!data) {
|
|
4556
|
+
throw new Error("No data available for agent session");
|
|
4557
|
+
}
|
|
4558
|
+
if (canCache) {
|
|
4559
|
+
await cacheSession({ sessionKey, session: { ...data, storedAt: (/* @__PURE__ */ new Date()).toISOString(), configs: [] } });
|
|
4560
|
+
logger.success(`[${maskedSessionKey}] Saved agent session to cache`);
|
|
4561
|
+
}
|
|
4562
|
+
logger.info(`[${maskedSessionKey}] Created agent session with Studio`);
|
|
4563
|
+
return data;
|
|
4564
|
+
} catch (error) {
|
|
4565
|
+
throw new Error("Failed to get agent session from Kubb Studio", { cause: error });
|
|
4566
|
+
}
|
|
4567
|
+
}
|
|
4568
|
+
async function registerAgent({ token, studioUrl, poolSize }) {
|
|
4569
|
+
var _a, _b;
|
|
4570
|
+
const machineToken = generateMachineToken();
|
|
4571
|
+
const registerUrl = `${studioUrl}/api/agent/register`;
|
|
4572
|
+
try {
|
|
4573
|
+
logger.info("Registering agent with Studio...");
|
|
4574
|
+
await $fetch(registerUrl, {
|
|
4575
|
+
method: "POST",
|
|
4576
|
+
headers: {
|
|
4577
|
+
Authorization: `Bearer ${token}`
|
|
4578
|
+
},
|
|
4579
|
+
body: { machineToken, poolSize }
|
|
4580
|
+
});
|
|
4581
|
+
logger.success(`Agent registered with Studio with token ${maskedString(token)}`);
|
|
4582
|
+
} catch (error) {
|
|
4583
|
+
logger.error("Failed to register agent with Studio", (_b = (_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.message) != null ? _b : error == null ? void 0 : error.message);
|
|
4584
|
+
}
|
|
4585
|
+
}
|
|
4586
|
+
async function disconnect({ sessionId, token, studioUrl }) {
|
|
4587
|
+
const disconnectUrl = `${studioUrl}/api/agent/session/${sessionId}/disconnect`;
|
|
4588
|
+
const maskedSessionKey = maskedString(sessionId);
|
|
4589
|
+
try {
|
|
4590
|
+
logger.info(`[${maskedSessionKey}] Disconnecting from Studio...`);
|
|
4591
|
+
await $fetch(disconnectUrl, {
|
|
4592
|
+
method: "POST",
|
|
4593
|
+
headers: {
|
|
4594
|
+
Authorization: `Bearer ${token}`
|
|
4595
|
+
}
|
|
4596
|
+
});
|
|
4597
|
+
logger.success(`[${maskedSessionKey}] Disconnected from Studio`);
|
|
4598
|
+
} catch (error) {
|
|
4599
|
+
throw new Error("Failed to notify Studio of disconnection on exit", { cause: error });
|
|
4600
|
+
}
|
|
4601
|
+
}
|
|
4602
|
+
|
|
4412
4603
|
async function clean(path) {
|
|
4413
4604
|
return rm(path, {
|
|
4414
4605
|
recursive: true,
|
|
@@ -5882,116 +6073,16 @@ function tokenize(command) {
|
|
|
5882
6073
|
return args;
|
|
5883
6074
|
}
|
|
5884
6075
|
|
|
6076
|
+
var version = "4.31.1";
|
|
6077
|
+
|
|
5885
6078
|
function isCommandMessage(msg) {
|
|
5886
6079
|
return msg.type === "command";
|
|
5887
6080
|
}
|
|
5888
6081
|
function isPongMessage(msg) {
|
|
5889
6082
|
return msg.type === "pong";
|
|
5890
6083
|
}
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
return `sessions:${createHash("sha512").update(token).digest("hex")}`;
|
|
5894
|
-
}
|
|
5895
|
-
|
|
5896
|
-
function isSessionValid(session) {
|
|
5897
|
-
try {
|
|
5898
|
-
const expiresAt = new Date(session.expiresAt);
|
|
5899
|
-
const now = /* @__PURE__ */ new Date();
|
|
5900
|
-
return now.getTime() < expiresAt.getTime() - 6e4;
|
|
5901
|
-
} catch {
|
|
5902
|
-
return false;
|
|
5903
|
-
}
|
|
5904
|
-
}
|
|
5905
|
-
|
|
5906
|
-
function hashToken(input) {
|
|
5907
|
-
return createHash("sha256").update(input).digest("hex");
|
|
5908
|
-
}
|
|
5909
|
-
function generateMachineToken() {
|
|
5910
|
-
if (process.env.KUBB_STUDIO_SECRET) {
|
|
5911
|
-
return hashToken(process.env.KUBB_STUDIO_SECRET);
|
|
5912
|
-
}
|
|
5913
|
-
const interfaces = os$1.networkInterfaces();
|
|
5914
|
-
const macs = [];
|
|
5915
|
-
for (const name in interfaces) {
|
|
5916
|
-
for (const iface of interfaces[name]) {
|
|
5917
|
-
if (!iface.internal && iface.mac !== "00:00:00:00:00:00") {
|
|
5918
|
-
macs.push(iface.mac);
|
|
5919
|
-
}
|
|
5920
|
-
}
|
|
5921
|
-
}
|
|
5922
|
-
return hashToken(macs.join(",") + os$1.hostname());
|
|
5923
|
-
}
|
|
5924
|
-
|
|
5925
|
-
async function createAgentSession({ token, studioUrl, noCache }) {
|
|
5926
|
-
const storage = useStorage("kubb");
|
|
5927
|
-
if (!noCache) {
|
|
5928
|
-
const sessionKey = getSessionKey(token);
|
|
5929
|
-
const stored = await storage.getItem(sessionKey);
|
|
5930
|
-
if (stored && isSessionValid(stored)) {
|
|
5931
|
-
logger.success("Using cached agent session");
|
|
5932
|
-
return stored;
|
|
5933
|
-
}
|
|
5934
|
-
if (stored) {
|
|
5935
|
-
await storage.removeItem(sessionKey);
|
|
5936
|
-
}
|
|
5937
|
-
}
|
|
5938
|
-
const connectUrl = `${studioUrl}/api/agent/session/create`;
|
|
5939
|
-
try {
|
|
5940
|
-
const machineToken = generateMachineToken();
|
|
5941
|
-
const data = await $fetch(connectUrl, {
|
|
5942
|
-
method: "POST",
|
|
5943
|
-
headers: {
|
|
5944
|
-
Authorization: `Bearer ${token}`
|
|
5945
|
-
},
|
|
5946
|
-
body: { machineToken }
|
|
5947
|
-
});
|
|
5948
|
-
if (!data) {
|
|
5949
|
-
throw new Error("No data available for agent session");
|
|
5950
|
-
}
|
|
5951
|
-
if (!noCache) {
|
|
5952
|
-
const sessionKey = getSessionKey(token);
|
|
5953
|
-
await storage.setItem(sessionKey, {
|
|
5954
|
-
...data,
|
|
5955
|
-
storedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5956
|
-
});
|
|
5957
|
-
logger.success("Cached agent session");
|
|
5958
|
-
}
|
|
5959
|
-
logger.success("Agent session created");
|
|
5960
|
-
return data;
|
|
5961
|
-
} catch (error) {
|
|
5962
|
-
throw new Error("Failed to get agent session from Kubb Studio", { cause: error });
|
|
5963
|
-
}
|
|
5964
|
-
}
|
|
5965
|
-
async function registerAgent({ token, studioUrl }) {
|
|
5966
|
-
var _a, _b;
|
|
5967
|
-
const machineToken = generateMachineToken();
|
|
5968
|
-
const registerUrl = `${studioUrl}/api/agent/register`;
|
|
5969
|
-
try {
|
|
5970
|
-
await $fetch(registerUrl, {
|
|
5971
|
-
method: "POST",
|
|
5972
|
-
headers: {
|
|
5973
|
-
Authorization: `Bearer ${token}`
|
|
5974
|
-
},
|
|
5975
|
-
body: { machineToken }
|
|
5976
|
-
});
|
|
5977
|
-
logger.success("Agent registered with Studio");
|
|
5978
|
-
} catch (error) {
|
|
5979
|
-
logger.warn("Failed to register agent with Studio", (_b = (_a = error == null ? void 0 : error.cause) == null ? void 0 : _a.message) != null ? _b : error == null ? void 0 : error.message);
|
|
5980
|
-
}
|
|
5981
|
-
}
|
|
5982
|
-
async function disconnect({ sessionToken, token, studioUrl }) {
|
|
5983
|
-
try {
|
|
5984
|
-
const disconnectUrl = `${studioUrl}/api/agent/session/${sessionToken}/disconnect`;
|
|
5985
|
-
await $fetch(disconnectUrl, {
|
|
5986
|
-
method: "POST",
|
|
5987
|
-
headers: {
|
|
5988
|
-
Authorization: `Bearer ${token}`
|
|
5989
|
-
}
|
|
5990
|
-
});
|
|
5991
|
-
logger.success("Sent disconnect notification to Studio on exit");
|
|
5992
|
-
} catch (error) {
|
|
5993
|
-
throw new Error("Failed to notify Studio of disconnection on exit", { cause: error });
|
|
5994
|
-
}
|
|
6084
|
+
function isDisconnectMessage(msg) {
|
|
6085
|
+
return msg.type === "disconnect";
|
|
5995
6086
|
}
|
|
5996
6087
|
|
|
5997
6088
|
var __typeError$3 = (msg) => {
|
|
@@ -6027,7 +6118,7 @@ var BaseGenerator = (_a$3 = class {
|
|
|
6027
6118
|
function isInputPath(config) {
|
|
6028
6119
|
return typeof (config == null ? void 0 : config.input) === "object" && config.input !== null && "path" in config.input;
|
|
6029
6120
|
}
|
|
6030
|
-
var version$1 = "4.
|
|
6121
|
+
var version$1 = "4.31.1";
|
|
6031
6122
|
function getDiagnosticInfo() {
|
|
6032
6123
|
return {
|
|
6033
6124
|
nodeVersion: version$2,
|
|
@@ -6505,6 +6596,15 @@ async function getCosmiConfig(configPath) {
|
|
|
6505
6596
|
}
|
|
6506
6597
|
}
|
|
6507
6598
|
|
|
6599
|
+
async function loadConfig(resolvedConfigPath) {
|
|
6600
|
+
const result = await getCosmiConfig(resolvedConfigPath);
|
|
6601
|
+
const configs = await getConfigs(result.config, {});
|
|
6602
|
+
if (configs.length === 0) {
|
|
6603
|
+
throw new Error("No configs found");
|
|
6604
|
+
}
|
|
6605
|
+
return configs[0];
|
|
6606
|
+
}
|
|
6607
|
+
|
|
6508
6608
|
var __defProp$8 = Object.defineProperty;
|
|
6509
6609
|
var __name$5 = (target, value) => __defProp$8(target, "name", {
|
|
6510
6610
|
value,
|
|
@@ -11464,6 +11564,7 @@ async function buildOperations(operations, { config, fabric, plugin, generator,
|
|
|
11464
11564
|
})
|
|
11465
11565
|
}));
|
|
11466
11566
|
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
11567
|
+
fabricChild.unmount();
|
|
11467
11568
|
}
|
|
11468
11569
|
async function buildOperation(operation, { config, fabric, plugin, generator, Component }) {
|
|
11469
11570
|
if (!Component) return;
|
|
@@ -11484,6 +11585,7 @@ async function buildOperation(operation, { config, fabric, plugin, generator, Co
|
|
|
11484
11585
|
})
|
|
11485
11586
|
}));
|
|
11486
11587
|
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
11588
|
+
fabricChild.unmount();
|
|
11487
11589
|
}
|
|
11488
11590
|
async function buildSchema(schema, { config, fabric, plugin, Component, generator }) {
|
|
11489
11591
|
if (!Component) return;
|
|
@@ -11504,6 +11606,7 @@ async function buildSchema(schema, { config, fabric, plugin, Component, generato
|
|
|
11504
11606
|
})
|
|
11505
11607
|
}));
|
|
11506
11608
|
await fabric.context.fileManager.upsert(...fabricChild.files);
|
|
11609
|
+
fabricChild.unmount();
|
|
11507
11610
|
}
|
|
11508
11611
|
var SchemaGenerator = (_b = class extends BaseGenerator {
|
|
11509
11612
|
constructor() {
|
|
@@ -11781,6 +11884,16 @@ getRefAlias_fn = function(schemaObject, name) {
|
|
|
11781
11884
|
}
|
|
11782
11885
|
}];
|
|
11783
11886
|
}
|
|
11887
|
+
if ($ref.startsWith("#") && !$ref.startsWith("#/components/")) try {
|
|
11888
|
+
const inlineSchema = this.context.oas.get($ref);
|
|
11889
|
+
if (inlineSchema && !isReference(inlineSchema)) return this.parse({
|
|
11890
|
+
schema: inlineSchema,
|
|
11891
|
+
name,
|
|
11892
|
+
parentName: null,
|
|
11893
|
+
rootName: null
|
|
11894
|
+
});
|
|
11895
|
+
} catch {
|
|
11896
|
+
}
|
|
11784
11897
|
__privateMethod$1(this, _SchemaGenerator_instances, ensureNameMapping_fn).call(this);
|
|
11785
11898
|
const originalName = $ref.replace(/.+\//, "");
|
|
11786
11899
|
const resolvedName = __privateGet(this, _schemaNameMapping).get($ref) || originalName;
|
|
@@ -216221,10 +216334,10 @@ function QueryOptions$4({ name, clientName, dataReturnType, typeSchemas, paramsC
|
|
|
216221
216334
|
${enabledText}
|
|
216222
216335
|
queryKey,
|
|
216223
216336
|
queryFn: async ({ signal }) => {
|
|
216224
|
-
|
|
216225
|
-
|
|
216226
|
-
|
|
216227
|
-
|
|
216337
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
216338
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
216339
|
+
return name2;
|
|
216340
|
+
} })})
|
|
216228
216341
|
},
|
|
216229
216342
|
})
|
|
216230
216343
|
`
|
|
@@ -216513,12 +216626,12 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
|
|
|
216513
216626
|
${enabledText}
|
|
216514
216627
|
queryKey,
|
|
216515
216628
|
queryFn: async ({ signal, pageParam }) => {
|
|
216516
|
-
if (!config.signal) {
|
|
216517
|
-
config.signal = signal
|
|
216518
|
-
}
|
|
216519
216629
|
${infiniteOverrideParams}
|
|
216520
|
-
return ${clientName}(${clientParams.toCall()
|
|
216521
|
-
|
|
216630
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
216631
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
216632
|
+
return name2;
|
|
216633
|
+
} })})
|
|
216634
|
+
},
|
|
216522
216635
|
${queryOptions.join(",\n")}
|
|
216523
216636
|
})
|
|
216524
216637
|
`
|
|
@@ -216538,11 +216651,11 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
|
|
|
216538
216651
|
${enabledText}
|
|
216539
216652
|
queryKey,
|
|
216540
216653
|
queryFn: async ({ signal }) => {
|
|
216541
|
-
|
|
216542
|
-
|
|
216543
|
-
|
|
216544
|
-
|
|
216545
|
-
|
|
216654
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
216655
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
216656
|
+
return name2;
|
|
216657
|
+
} })})
|
|
216658
|
+
},
|
|
216546
216659
|
${queryOptions.join(",\n")}
|
|
216547
216660
|
})
|
|
216548
216661
|
`
|
|
@@ -217195,12 +217308,12 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
217195
217308
|
${enabledText}
|
|
217196
217309
|
queryKey,
|
|
217197
217310
|
queryFn: async ({ signal, pageParam }) => {
|
|
217198
|
-
if (!config.signal) {
|
|
217199
|
-
config.signal = signal
|
|
217200
|
-
}
|
|
217201
217311
|
${infiniteOverrideParams}
|
|
217202
|
-
return ${clientName}(${clientParams.toCall()
|
|
217203
|
-
|
|
217312
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
217313
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
217314
|
+
return name2;
|
|
217315
|
+
} })})
|
|
217316
|
+
},
|
|
217204
217317
|
${queryOptions.join(",\n")}
|
|
217205
217318
|
})
|
|
217206
217319
|
`
|
|
@@ -217220,13 +217333,13 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
217220
217333
|
${enabledText}
|
|
217221
217334
|
queryKey,
|
|
217222
217335
|
queryFn: async ({ signal }) => {
|
|
217223
|
-
|
|
217224
|
-
|
|
217225
|
-
|
|
217226
|
-
|
|
217227
|
-
|
|
217336
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
217337
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
217338
|
+
return name2;
|
|
217339
|
+
} })})
|
|
217340
|
+
},
|
|
217228
217341
|
${queryOptions.join(",\n")}
|
|
217229
|
-
|
|
217342
|
+
})
|
|
217230
217343
|
`
|
|
217231
217344
|
})
|
|
217232
217345
|
});
|
|
@@ -217747,7 +217860,7 @@ const infiniteQueryGenerator$1 = createReactGenerator({
|
|
|
217747
217860
|
path: zod.file.path
|
|
217748
217861
|
}),
|
|
217749
217862
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
217750
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
217863
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
217751
217864
|
name: "fetch",
|
|
217752
217865
|
path: options.client.importPath
|
|
217753
217866
|
}),
|
|
@@ -217766,7 +217879,7 @@ const infiniteQueryGenerator$1 = createReactGenerator({
|
|
|
217766
217879
|
isTypeOnly: true
|
|
217767
217880
|
})
|
|
217768
217881
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
217769
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
217882
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
217770
217883
|
name: ["fetch"],
|
|
217771
217884
|
root: query.file.path,
|
|
217772
217885
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -217973,7 +218086,7 @@ const mutationGenerator$4 = createReactGenerator({
|
|
|
217973
218086
|
path: zod.file.path
|
|
217974
218087
|
}),
|
|
217975
218088
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
217976
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218089
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
217977
218090
|
name: "fetch",
|
|
217978
218091
|
path: options.client.importPath
|
|
217979
218092
|
}),
|
|
@@ -217992,7 +218105,7 @@ const mutationGenerator$4 = createReactGenerator({
|
|
|
217992
218105
|
isTypeOnly: true
|
|
217993
218106
|
})
|
|
217994
218107
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
217995
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218108
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
217996
218109
|
name: ["fetch"],
|
|
217997
218110
|
root: mutation.file.path,
|
|
217998
218111
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -218183,7 +218296,7 @@ const queryGenerator$4 = createReactGenerator({
|
|
|
218183
218296
|
path: zod.file.path
|
|
218184
218297
|
}),
|
|
218185
218298
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218186
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218299
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218187
218300
|
name: "fetch",
|
|
218188
218301
|
path: options.client.importPath
|
|
218189
218302
|
}),
|
|
@@ -218202,7 +218315,7 @@ const queryGenerator$4 = createReactGenerator({
|
|
|
218202
218315
|
isTypeOnly: true
|
|
218203
218316
|
})
|
|
218204
218317
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218205
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218318
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218206
218319
|
name: ["fetch"],
|
|
218207
218320
|
root: query.file.path,
|
|
218208
218321
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -218405,7 +218518,7 @@ const suspenseInfiniteQueryGenerator = createReactGenerator({
|
|
|
218405
218518
|
path: zod.file.path
|
|
218406
218519
|
}),
|
|
218407
218520
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218408
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218521
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218409
218522
|
name: "fetch",
|
|
218410
218523
|
path: options.client.importPath
|
|
218411
218524
|
}),
|
|
@@ -218424,7 +218537,7 @@ const suspenseInfiniteQueryGenerator = createReactGenerator({
|
|
|
218424
218537
|
isTypeOnly: true
|
|
218425
218538
|
})
|
|
218426
218539
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218427
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218540
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218428
218541
|
name: ["fetch"],
|
|
218429
218542
|
root: query.file.path,
|
|
218430
218543
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -218639,7 +218752,7 @@ const suspenseQueryGenerator = createReactGenerator({
|
|
|
218639
218752
|
path: zod.file.path
|
|
218640
218753
|
}),
|
|
218641
218754
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218642
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218755
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218643
218756
|
name: "fetch",
|
|
218644
218757
|
path: options.client.importPath
|
|
218645
218758
|
}),
|
|
@@ -218658,7 +218771,7 @@ const suspenseQueryGenerator = createReactGenerator({
|
|
|
218658
218771
|
isTypeOnly: true
|
|
218659
218772
|
})
|
|
218660
218773
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
218661
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
218774
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
218662
218775
|
name: ["fetch"],
|
|
218663
218776
|
root: query.file.path,
|
|
218664
218777
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -219313,10 +219426,10 @@ function QueryOptions$3({ name, clientName, typeSchemas, paramsCasing, paramsTyp
|
|
|
219313
219426
|
${enabledText}
|
|
219314
219427
|
queryKey,
|
|
219315
219428
|
queryFn: async ({ signal }) => {
|
|
219316
|
-
|
|
219317
|
-
|
|
219318
|
-
|
|
219319
|
-
|
|
219429
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
219430
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
219431
|
+
return name2;
|
|
219432
|
+
} })})
|
|
219320
219433
|
},
|
|
219321
219434
|
})
|
|
219322
219435
|
`
|
|
@@ -219538,7 +219651,7 @@ const mutationGenerator$3 = createReactGenerator({
|
|
|
219538
219651
|
path: zod.file.path
|
|
219539
219652
|
}),
|
|
219540
219653
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
219541
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
219654
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
219542
219655
|
name: "fetch",
|
|
219543
219656
|
path: options.client.importPath
|
|
219544
219657
|
}),
|
|
@@ -219557,7 +219670,7 @@ const mutationGenerator$3 = createReactGenerator({
|
|
|
219557
219670
|
isTypeOnly: true
|
|
219558
219671
|
})
|
|
219559
219672
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
219560
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
219673
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
219561
219674
|
name: ["fetch"],
|
|
219562
219675
|
root: mutation.file.path,
|
|
219563
219676
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -219731,7 +219844,7 @@ const queryGenerator$3 = createReactGenerator({
|
|
|
219731
219844
|
path: zod.file.path
|
|
219732
219845
|
}),
|
|
219733
219846
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
219734
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
219847
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
219735
219848
|
name: "fetch",
|
|
219736
219849
|
path: options.client.importPath
|
|
219737
219850
|
}),
|
|
@@ -219750,7 +219863,7 @@ const queryGenerator$3 = createReactGenerator({
|
|
|
219750
219863
|
isTypeOnly: true
|
|
219751
219864
|
})
|
|
219752
219865
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
219753
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
219866
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
219754
219867
|
name: ["fetch"],
|
|
219755
219868
|
root: query.file.path,
|
|
219756
219869
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -220326,10 +220439,10 @@ function QueryOptions$2({ name, clientName, typeSchemas, paramsCasing, paramsTyp
|
|
|
220326
220439
|
${enabledText}
|
|
220327
220440
|
queryKey,
|
|
220328
220441
|
queryFn: async ({ signal }) => {
|
|
220329
|
-
|
|
220330
|
-
|
|
220331
|
-
|
|
220332
|
-
|
|
220442
|
+
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
220443
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
220444
|
+
return name2;
|
|
220445
|
+
} })})
|
|
220333
220446
|
},
|
|
220334
220447
|
})
|
|
220335
220448
|
`
|
|
@@ -220552,7 +220665,7 @@ const mutationGenerator$2 = createReactGenerator({
|
|
|
220552
220665
|
path: zod.file.path
|
|
220553
220666
|
}),
|
|
220554
220667
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
220555
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
220668
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
220556
220669
|
name: "fetch",
|
|
220557
220670
|
path: options.client.importPath
|
|
220558
220671
|
}),
|
|
@@ -220571,7 +220684,7 @@ const mutationGenerator$2 = createReactGenerator({
|
|
|
220571
220684
|
isTypeOnly: true
|
|
220572
220685
|
})
|
|
220573
220686
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
220574
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
220687
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
220575
220688
|
name: ["fetch"],
|
|
220576
220689
|
root: mutation.file.path,
|
|
220577
220690
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -220744,7 +220857,7 @@ const queryGenerator$2 = createReactGenerator({
|
|
|
220744
220857
|
path: zod.file.path
|
|
220745
220858
|
}),
|
|
220746
220859
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
220747
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
220860
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
220748
220861
|
name: "fetch",
|
|
220749
220862
|
path: options.client.importPath
|
|
220750
220863
|
}),
|
|
@@ -220763,7 +220876,7 @@ const queryGenerator$2 = createReactGenerator({
|
|
|
220763
220876
|
isTypeOnly: true
|
|
220764
220877
|
})
|
|
220765
220878
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
220766
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
220879
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
220767
220880
|
name: ["fetch"],
|
|
220768
220881
|
root: query.file.path,
|
|
220769
220882
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -221603,7 +221716,7 @@ const mutationGenerator$1 = createReactGenerator({
|
|
|
221603
221716
|
path: zod.file.path
|
|
221604
221717
|
}),
|
|
221605
221718
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
221606
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
221719
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
221607
221720
|
name: "fetch",
|
|
221608
221721
|
path: options.client.importPath
|
|
221609
221722
|
}),
|
|
@@ -221622,7 +221735,7 @@ const mutationGenerator$1 = createReactGenerator({
|
|
|
221622
221735
|
isTypeOnly: true
|
|
221623
221736
|
})
|
|
221624
221737
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
221625
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
221738
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
221626
221739
|
name: ["fetch"],
|
|
221627
221740
|
root: mutation.file.path,
|
|
221628
221741
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -221791,7 +221904,7 @@ const queryGenerator$1 = createReactGenerator({
|
|
|
221791
221904
|
path: zod.file.path
|
|
221792
221905
|
}),
|
|
221793
221906
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
221794
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
221907
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
221795
221908
|
name: "fetch",
|
|
221796
221909
|
path: options.client.importPath
|
|
221797
221910
|
}),
|
|
@@ -221810,7 +221923,7 @@ const queryGenerator$1 = createReactGenerator({
|
|
|
221810
221923
|
isTypeOnly: true
|
|
221811
221924
|
})
|
|
221812
221925
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
221813
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
221926
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
221814
221927
|
name: ["fetch"],
|
|
221815
221928
|
root: query.file.path,
|
|
221816
221929
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -222232,12 +222345,10 @@ function QueryOptions({ name, clientName, dataReturnType, typeSchemas, paramsCas
|
|
|
222232
222345
|
const queryKey = ${queryKeyName}(${queryKeyParams.toCall()})
|
|
222233
222346
|
return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
|
|
222234
222347
|
${enabledText}
|
|
222235
|
-
|
|
222236
|
-
|
|
222237
|
-
if (!config.signal) {
|
|
222238
|
-
config.signal = signal
|
|
222239
|
-
}
|
|
222348
|
+
queryKey,
|
|
222349
|
+
queryFn: async ({ signal }) => {
|
|
222240
222350
|
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
222351
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
222241
222352
|
return `toValue(${name2})`;
|
|
222242
222353
|
} })})
|
|
222243
222354
|
},
|
|
@@ -222547,11 +222658,9 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
222547
222658
|
${enabledText}
|
|
222548
222659
|
queryKey,
|
|
222549
222660
|
queryFn: async ({ signal, pageParam }) => {
|
|
222550
|
-
if (!config.signal) {
|
|
222551
|
-
config.signal = signal
|
|
222552
|
-
}
|
|
222553
222661
|
${infiniteOverrideParams}
|
|
222554
222662
|
return ${clientName}(${clientParams.toCall({ transformName(name2) {
|
|
222663
|
+
if (name2 === "config") return "{ ...config, signal: config.signal ?? signal }";
|
|
222555
222664
|
return `toValue(${name2})`;
|
|
222556
222665
|
} })})
|
|
222557
222666
|
},
|
|
@@ -222965,7 +223074,7 @@ const infiniteQueryGenerator = createReactGenerator({
|
|
|
222965
223074
|
path: zod.file.path
|
|
222966
223075
|
}),
|
|
222967
223076
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
222968
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223077
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
222969
223078
|
name: "fetch",
|
|
222970
223079
|
path: options.client.importPath
|
|
222971
223080
|
}),
|
|
@@ -222984,7 +223093,7 @@ const infiniteQueryGenerator = createReactGenerator({
|
|
|
222984
223093
|
isTypeOnly: true
|
|
222985
223094
|
})
|
|
222986
223095
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
222987
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223096
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
222988
223097
|
name: ["fetch"],
|
|
222989
223098
|
root: query.file.path,
|
|
222990
223099
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -223189,7 +223298,7 @@ const mutationGenerator = createReactGenerator({
|
|
|
223189
223298
|
path: zod.file.path
|
|
223190
223299
|
}),
|
|
223191
223300
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223192
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223301
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
223193
223302
|
name: "fetch",
|
|
223194
223303
|
path: options.client.importPath
|
|
223195
223304
|
}),
|
|
@@ -223208,7 +223317,7 @@ const mutationGenerator = createReactGenerator({
|
|
|
223208
223317
|
isTypeOnly: true
|
|
223209
223318
|
})
|
|
223210
223319
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223211
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223320
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
223212
223321
|
name: ["fetch"],
|
|
223213
223322
|
root: mutation.file.path,
|
|
223214
223323
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -223382,7 +223491,7 @@ const queryGenerator = createReactGenerator({
|
|
|
223382
223491
|
path: zod.file.path
|
|
223383
223492
|
}),
|
|
223384
223493
|
options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223385
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223494
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
223386
223495
|
name: "fetch",
|
|
223387
223496
|
path: options.client.importPath
|
|
223388
223497
|
}),
|
|
@@ -223401,7 +223510,7 @@ const queryGenerator = createReactGenerator({
|
|
|
223401
223510
|
isTypeOnly: true
|
|
223402
223511
|
})
|
|
223403
223512
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
223404
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
223513
|
+
!shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
|
|
223405
223514
|
name: ["fetch"],
|
|
223406
223515
|
root: query.file.path,
|
|
223407
223516
|
path: path$2.resolve(config.root, config.output.path, ".kubb/fetch.ts")
|
|
@@ -223690,20 +223799,41 @@ function resolvePlugins(plugins) {
|
|
|
223690
223799
|
});
|
|
223691
223800
|
}
|
|
223692
223801
|
|
|
223693
|
-
function
|
|
223694
|
-
|
|
223695
|
-
if (!
|
|
223696
|
-
|
|
223697
|
-
|
|
223698
|
-
|
|
223699
|
-
|
|
223700
|
-
|
|
223701
|
-
|
|
223702
|
-
|
|
223802
|
+
function mergePlugins(diskPlugins, studioPlugins) {
|
|
223803
|
+
if (!diskPlugins && !studioPlugins) return void 0;
|
|
223804
|
+
if (!studioPlugins) return diskPlugins;
|
|
223805
|
+
const resolvedStudio = resolvePlugins(studioPlugins);
|
|
223806
|
+
if (!diskPlugins) return resolvedStudio;
|
|
223807
|
+
const studioByName = new Map(resolvedStudio.map((p) => [p.name, p]));
|
|
223808
|
+
const diskNames = new Set(diskPlugins.map((p) => p.name));
|
|
223809
|
+
const mergedDisk = diskPlugins.map((diskPlugin) => {
|
|
223810
|
+
const studioPlugin = studioByName.get(diskPlugin.name);
|
|
223811
|
+
if (!studioPlugin) return diskPlugin;
|
|
223812
|
+
return { ...diskPlugin, options: mergeDeep(diskPlugin.options, studioPlugin.options) };
|
|
223813
|
+
});
|
|
223814
|
+
const studioOnly = resolvedStudio.filter((p) => !diskNames.has(p.name));
|
|
223815
|
+
return [...mergedDisk, ...studioOnly];
|
|
223703
223816
|
}
|
|
223704
|
-
|
|
223705
|
-
|
|
223706
|
-
|
|
223817
|
+
|
|
223818
|
+
function setupHookListener(events, root) {
|
|
223819
|
+
events.on("hook:start", async ({ id, command, args }) => {
|
|
223820
|
+
if (!id) {
|
|
223821
|
+
return;
|
|
223822
|
+
}
|
|
223823
|
+
const commandWithArgs = (args == null ? void 0 : args.length) ? `${command} ${args.join(" ")}` : command;
|
|
223824
|
+
try {
|
|
223825
|
+
const result = await x(command, [...args != null ? args : []], {
|
|
223826
|
+
nodeOptions: { cwd: root, detached: true },
|
|
223827
|
+
throwOnError: true
|
|
223828
|
+
});
|
|
223829
|
+
console.log(result.stdout.trimEnd());
|
|
223830
|
+
await events.emit("hook:end", { command, args, id, success: true, error: null });
|
|
223831
|
+
} catch (_err) {
|
|
223832
|
+
const errorMessage = new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
223833
|
+
await events.emit("hook:end", { command, args, id, success: false, error: errorMessage });
|
|
223834
|
+
await events.emit("error", errorMessage);
|
|
223835
|
+
}
|
|
223836
|
+
});
|
|
223707
223837
|
}
|
|
223708
223838
|
|
|
223709
223839
|
const WEBSOCKET_READY = 1;
|
|
@@ -223835,7 +223965,165 @@ function setupEventsStream(ws, events) {
|
|
|
223835
223965
|
});
|
|
223836
223966
|
}
|
|
223837
223967
|
|
|
223838
|
-
|
|
223968
|
+
async function connectToStudio(options) {
|
|
223969
|
+
var _a;
|
|
223970
|
+
const {
|
|
223971
|
+
token,
|
|
223972
|
+
studioUrl,
|
|
223973
|
+
configPath,
|
|
223974
|
+
resolvedConfigPath,
|
|
223975
|
+
noCache,
|
|
223976
|
+
allowAll,
|
|
223977
|
+
allowWrite,
|
|
223978
|
+
root,
|
|
223979
|
+
retryInterval,
|
|
223980
|
+
heartbeatInterval = 3e4,
|
|
223981
|
+
initialSession,
|
|
223982
|
+
sessionKey,
|
|
223983
|
+
nitro
|
|
223984
|
+
} = options;
|
|
223985
|
+
const events = new AsyncEventEmitter();
|
|
223986
|
+
const maskedSessionKey = maskedString(sessionKey.replace("sessions:", ""));
|
|
223987
|
+
async function removeSession() {
|
|
223988
|
+
if (!noCache) {
|
|
223989
|
+
await removeCachedSession(sessionKey);
|
|
223990
|
+
}
|
|
223991
|
+
}
|
|
223992
|
+
async function reconnect() {
|
|
223993
|
+
logger.info(`[${maskedSessionKey}] Retrying connection in ${formatMs(retryInterval)} to Kubb Studio ...`);
|
|
223994
|
+
await removeSession();
|
|
223995
|
+
setTimeout(() => connectToStudio({ ...options, initialSession: void 0 }), retryInterval);
|
|
223996
|
+
}
|
|
223997
|
+
try {
|
|
223998
|
+
setupHookListener(events, root);
|
|
223999
|
+
const { sessionId, wsUrl, isSandbox } = initialSession != null ? initialSession : await createAgentSession({ noCache, token, studioUrl, cacheKey: sessionKey });
|
|
224000
|
+
const ws = createWebsocket(wsUrl, { headers: { Authorization: `Bearer ${token}` } });
|
|
224001
|
+
const maskedWsUrl = maskedString(wsUrl);
|
|
224002
|
+
const effectiveAllowAll = isSandbox ? false : allowAll;
|
|
224003
|
+
const effectiveWrite = isSandbox ? false : allowWrite;
|
|
224004
|
+
let serverDisconnected = false;
|
|
224005
|
+
let heartbeatTimer;
|
|
224006
|
+
async function cleanup(reason = "cleanup") {
|
|
224007
|
+
try {
|
|
224008
|
+
clearInterval(heartbeatTimer);
|
|
224009
|
+
heartbeatTimer = void 0;
|
|
224010
|
+
events.removeAll();
|
|
224011
|
+
ws.close(1e3, reason);
|
|
224012
|
+
ws.removeEventListener("open", onOpen);
|
|
224013
|
+
ws.removeEventListener("close", onClose);
|
|
224014
|
+
ws.removeEventListener("error", onError);
|
|
224015
|
+
} catch (_error) {
|
|
224016
|
+
}
|
|
224017
|
+
}
|
|
224018
|
+
const onOpen = () => {
|
|
224019
|
+
logger.success(`[${maskedSessionKey}] Connected to Kubb Studio on "${maskedWsUrl}"`);
|
|
224020
|
+
};
|
|
224021
|
+
const onClose = async () => {
|
|
224022
|
+
if (serverDisconnected) {
|
|
224023
|
+
return;
|
|
224024
|
+
}
|
|
224025
|
+
serverDisconnected = true;
|
|
224026
|
+
await cleanup();
|
|
224027
|
+
await disconnect({ sessionId, studioUrl, token }).catch(() => {
|
|
224028
|
+
});
|
|
224029
|
+
await reconnect();
|
|
224030
|
+
};
|
|
224031
|
+
const onError = async () => {
|
|
224032
|
+
logger.error(`[${maskedSessionKey}] Failed to connect to Kubb Studio on "${maskedWsUrl}"`);
|
|
224033
|
+
await cleanup();
|
|
224034
|
+
await reconnect();
|
|
224035
|
+
};
|
|
224036
|
+
ws.addEventListener("open", onOpen);
|
|
224037
|
+
ws.addEventListener("close", onClose);
|
|
224038
|
+
ws.addEventListener("error", onError);
|
|
224039
|
+
nitro.hooks.hook("close", async () => {
|
|
224040
|
+
await cleanup();
|
|
224041
|
+
await disconnect({ sessionId, studioUrl, token }).catch(() => {
|
|
224042
|
+
});
|
|
224043
|
+
});
|
|
224044
|
+
heartbeatTimer = setInterval(() => sendAgentMessage(ws, { type: "ping" }), heartbeatInterval);
|
|
224045
|
+
setupEventsStream(ws, events);
|
|
224046
|
+
ws.addEventListener("message", async (message) => {
|
|
224047
|
+
var _a2, _b, _c;
|
|
224048
|
+
try {
|
|
224049
|
+
const data = JSON.parse(message.data);
|
|
224050
|
+
logger.info(`[${maskedSessionKey}] Received "${data.type}" from Studio`);
|
|
224051
|
+
if (isPongMessage(data)) {
|
|
224052
|
+
return;
|
|
224053
|
+
}
|
|
224054
|
+
if (isDisconnectMessage(data)) {
|
|
224055
|
+
logger.warn(`[${maskedSessionKey}] Agent session disconnected by Studio with reason: ${data.reason}`);
|
|
224056
|
+
if (data.reason === "revoked") {
|
|
224057
|
+
await cleanup(`session_${data.reason}`);
|
|
224058
|
+
await removeSession();
|
|
224059
|
+
return;
|
|
224060
|
+
}
|
|
224061
|
+
if (data.reason === "expired") {
|
|
224062
|
+
await cleanup();
|
|
224063
|
+
await reconnect();
|
|
224064
|
+
return;
|
|
224065
|
+
}
|
|
224066
|
+
return;
|
|
224067
|
+
}
|
|
224068
|
+
if (isCommandMessage(data)) {
|
|
224069
|
+
if (data.command === "generate") {
|
|
224070
|
+
const config = await loadConfig(resolvedConfigPath);
|
|
224071
|
+
const patch = data.payload;
|
|
224072
|
+
const plugins = mergePlugins(config.plugins, patch == null ? void 0 : patch.plugins);
|
|
224073
|
+
const inputOverride = isSandbox ? { data: (_a2 = patch == null ? void 0 : patch.input) != null ? _a2 : "" } : void 0;
|
|
224074
|
+
if (allowWrite && isSandbox) {
|
|
224075
|
+
logger.warn(`[${maskedSessionKey}] Agent is running in a sandbox environment, write will be disabled`);
|
|
224076
|
+
}
|
|
224077
|
+
if ((patch == null ? void 0 : patch.input) && !isSandbox) {
|
|
224078
|
+
logger.warn(`[${maskedSessionKey}] Input override via payload is only supported in sandbox mode and will be ignored`);
|
|
224079
|
+
}
|
|
224080
|
+
if (data.payload && effectiveWrite) {
|
|
224081
|
+
await saveStudioConfigToStorage({ sessionKey, config: data.payload }).catch((err) => {
|
|
224082
|
+
logger.warn(`[${maskedSessionKey}] Failed to save studio config: ${err == null ? void 0 : err.message}`);
|
|
224083
|
+
});
|
|
224084
|
+
}
|
|
224085
|
+
await generate({
|
|
224086
|
+
config: {
|
|
224087
|
+
...config,
|
|
224088
|
+
root,
|
|
224089
|
+
input: inputOverride != null ? inputOverride : config.input,
|
|
224090
|
+
output: { ...config.output, write: effectiveWrite },
|
|
224091
|
+
plugins
|
|
224092
|
+
},
|
|
224093
|
+
events
|
|
224094
|
+
});
|
|
224095
|
+
logger.success(`[${maskedSessionKey}] Completed "${data.type}" from Studio`);
|
|
224096
|
+
return;
|
|
224097
|
+
}
|
|
224098
|
+
if (data.command === "connect") {
|
|
224099
|
+
const config = await loadConfig(resolvedConfigPath);
|
|
224100
|
+
sendAgentMessage(ws, {
|
|
224101
|
+
type: "connected",
|
|
224102
|
+
payload: {
|
|
224103
|
+
version,
|
|
224104
|
+
configPath,
|
|
224105
|
+
permissions: { allowAll: effectiveAllowAll, allowWrite: effectiveWrite },
|
|
224106
|
+
config: {
|
|
224107
|
+
plugins: (_b = config.plugins) == null ? void 0 : _b.map((plugin) => ({
|
|
224108
|
+
name: `@kubb/${plugin.name}`,
|
|
224109
|
+
options: serializePluginOptions(plugin.options)
|
|
224110
|
+
}))
|
|
224111
|
+
}
|
|
224112
|
+
}
|
|
224113
|
+
});
|
|
224114
|
+
logger.success(`[${maskedSessionKey}] Completed "${data.type}" from Studio`);
|
|
224115
|
+
return;
|
|
224116
|
+
}
|
|
224117
|
+
}
|
|
224118
|
+
logger.warn(`[${maskedSessionKey}] Unknown message type from Kubb Studio: ${message.data}`);
|
|
224119
|
+
} catch (error) {
|
|
224120
|
+
logger.error(`[${maskedSessionKey}] [unhandledRejection] ${(_c = error == null ? void 0 : error.message) != null ? _c : error}`);
|
|
224121
|
+
}
|
|
224122
|
+
});
|
|
224123
|
+
} catch (error) {
|
|
224124
|
+
throw new Error(`[unhandledRejection] ${(_a = error == null ? void 0 : error.message) != null ? _a : error}`, { cause: error });
|
|
224125
|
+
}
|
|
224126
|
+
}
|
|
223839
224127
|
|
|
223840
224128
|
const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nitro) => {
|
|
223841
224129
|
const studioUrl = process$1.env.KUBB_STUDIO_URL || "https://studio.kubb.dev";
|
|
@@ -223843,196 +224131,70 @@ const _zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E = defineNitroPlugin(async (nit
|
|
|
223843
224131
|
const configPath = process$1.env.KUBB_AGENT_CONFIG || "kubb.config.ts";
|
|
223844
224132
|
const noCache = process$1.env.KUBB_AGENT_NO_CACHE === "true";
|
|
223845
224133
|
const retryInterval = process$1.env.KUBB_AGENT_RETRY_TIMEOUT ? Number.parseInt(process$1.env.KUBB_AGENT_RETRY_TIMEOUT, 10) : 3e4;
|
|
224134
|
+
const heartbeatInterval = process$1.env.KUBB_AGENT_HEARTBEAT_INTERVAL ? Number.parseInt(process$1.env.KUBB_AGENT_HEARTBEAT_INTERVAL, 10) : 3e4;
|
|
223846
224135
|
const root = process$1.env.KUBB_AGENT_ROOT || process$1.cwd();
|
|
223847
224136
|
const allowAll = process$1.env.KUBB_AGENT_ALLOW_ALL === "true";
|
|
223848
224137
|
const allowWrite = allowAll || process$1.env.KUBB_AGENT_ALLOW_WRITE === "true";
|
|
224138
|
+
const poolSize = process$1.env.KUBB_AGENT_POOL_SIZE ? Number.parseInt(process$1.env.KUBB_AGENT_POOL_SIZE, 10) : 1;
|
|
223849
224139
|
if (!token) {
|
|
223850
224140
|
logger.warn("KUBB_AGENT_TOKEN not set", "cannot authenticate with studio");
|
|
223851
224141
|
return null;
|
|
223852
224142
|
}
|
|
224143
|
+
if (!process$1.env.KUBB_AGENT_SECRET) {
|
|
224144
|
+
logger.warn("KUBB_AGENT_SECRET not set", "secret should be set");
|
|
224145
|
+
}
|
|
223853
224146
|
const resolvedConfigPath = path$2.isAbsolute(configPath) ? configPath : path$2.resolve(root, configPath);
|
|
223854
|
-
const events = new AsyncEventEmitter();
|
|
223855
224147
|
const storage = useStorage("kubb");
|
|
223856
|
-
|
|
223857
|
-
|
|
223858
|
-
|
|
223859
|
-
|
|
223860
|
-
|
|
223861
|
-
|
|
223862
|
-
|
|
223863
|
-
|
|
223864
|
-
|
|
223865
|
-
|
|
223866
|
-
|
|
223867
|
-
|
|
223868
|
-
|
|
223869
|
-
|
|
223870
|
-
|
|
223871
|
-
|
|
223872
|
-
|
|
223873
|
-
|
|
223874
|
-
|
|
223875
|
-
|
|
223876
|
-
|
|
223877
|
-
|
|
223878
|
-
|
|
223879
|
-
|
|
223880
|
-
|
|
223881
|
-
|
|
223882
|
-
|
|
223883
|
-
try {
|
|
223884
|
-
const result = await x(command, [...args != null ? args : []], {
|
|
223885
|
-
nodeOptions: { cwd: root, detached: true },
|
|
223886
|
-
throwOnError: true
|
|
223887
|
-
});
|
|
223888
|
-
console.log(result.stdout.trimEnd());
|
|
223889
|
-
await events.emit("hook:end", {
|
|
223890
|
-
command,
|
|
223891
|
-
args,
|
|
223892
|
-
id,
|
|
223893
|
-
success: true,
|
|
223894
|
-
error: null
|
|
223895
|
-
});
|
|
223896
|
-
} catch (_err) {
|
|
223897
|
-
const errorMessage = new Error(`Hook execute failed: ${commandWithArgs}`);
|
|
223898
|
-
await events.emit("hook:end", {
|
|
223899
|
-
command,
|
|
223900
|
-
args,
|
|
223901
|
-
id,
|
|
223902
|
-
success: false,
|
|
223903
|
-
error: errorMessage
|
|
223904
|
-
});
|
|
223905
|
-
await events.emit("error", errorMessage);
|
|
223906
|
-
}
|
|
223907
|
-
});
|
|
223908
|
-
const { sessionToken, wsUrl, isSandbox } = await createAgentSession({
|
|
223909
|
-
noCache,
|
|
223910
|
-
token,
|
|
223911
|
-
studioUrl
|
|
224148
|
+
const sessionKey = getSessionKey(token);
|
|
224149
|
+
const maskedSessionKey = maskedString(sessionKey.replace("sessions:", ""));
|
|
224150
|
+
try {
|
|
224151
|
+
await registerAgent({ token, studioUrl, poolSize });
|
|
224152
|
+
const baseOptions = {
|
|
224153
|
+
token,
|
|
224154
|
+
studioUrl,
|
|
224155
|
+
configPath,
|
|
224156
|
+
resolvedConfigPath,
|
|
224157
|
+
noCache,
|
|
224158
|
+
allowAll,
|
|
224159
|
+
allowWrite,
|
|
224160
|
+
root,
|
|
224161
|
+
retryInterval,
|
|
224162
|
+
heartbeatInterval,
|
|
224163
|
+
storage,
|
|
224164
|
+
sessionKey,
|
|
224165
|
+
nitro
|
|
224166
|
+
};
|
|
224167
|
+
logger.info(`[${maskedSessionKey}] Starting session pool of ${poolSize} connection(s)`);
|
|
224168
|
+
const sessions = /* @__PURE__ */ new Map();
|
|
224169
|
+
for (const index2 of Array.from({ length: poolSize }, (_, i) => i)) {
|
|
224170
|
+
const cacheKey = `${sessionKey}-${index2}`;
|
|
224171
|
+
const maskedSessionKey2 = maskedString(cacheKey);
|
|
224172
|
+
const session = await createAgentSession({ noCache, token, studioUrl, cacheKey }).catch((err) => {
|
|
224173
|
+
logger.warn(`[${maskedSessionKey2}] Failed to pre-create pool session:`, err == null ? void 0 : err.message);
|
|
224174
|
+
return null;
|
|
223912
224175
|
});
|
|
223913
|
-
|
|
223914
|
-
|
|
223915
|
-
|
|
223916
|
-
|
|
223917
|
-
|
|
223918
|
-
|
|
223919
|
-
|
|
223920
|
-
|
|
223921
|
-
|
|
223922
|
-
|
|
223923
|
-
|
|
223924
|
-
}
|
|
223925
|
-
};
|
|
223926
|
-
const onOpen = () => {
|
|
223927
|
-
logger.success(`Connected to Kubb Studio on "${wsUrl}"`);
|
|
223928
|
-
};
|
|
223929
|
-
const onClose = async () => {
|
|
223930
|
-
cleanup();
|
|
223931
|
-
logger.info("Disconnecting from Studio ...");
|
|
223932
|
-
if (sessionToken) {
|
|
223933
|
-
await disconnect({
|
|
223934
|
-
sessionToken,
|
|
223935
|
-
studioUrl,
|
|
223936
|
-
token
|
|
223937
|
-
}).catch(async () => {
|
|
223938
|
-
});
|
|
223939
|
-
await storage.removeItem(getSessionKey(token));
|
|
223940
|
-
await reconnectToStudio();
|
|
223941
|
-
}
|
|
223942
|
-
};
|
|
223943
|
-
const cleanup = () => {
|
|
223944
|
-
ws.removeEventListener("open", onOpen);
|
|
223945
|
-
ws.removeEventListener("close", onClose);
|
|
223946
|
-
ws.removeEventListener("error", onError);
|
|
223947
|
-
};
|
|
223948
|
-
ws.addEventListener("open", onOpen);
|
|
223949
|
-
ws.addEventListener("close", onClose);
|
|
223950
|
-
ws.addEventListener("error", onError);
|
|
223951
|
-
nitro.hooks.hook("close", onClose);
|
|
223952
|
-
setInterval(() => {
|
|
223953
|
-
sendAgentMessage(ws, {
|
|
223954
|
-
type: "ping"
|
|
223955
|
-
});
|
|
223956
|
-
}, 3e4);
|
|
223957
|
-
setupEventsStream(ws, events);
|
|
223958
|
-
ws.addEventListener("message", async (message) => {
|
|
223959
|
-
var _a, _b, _c, _d;
|
|
223960
|
-
try {
|
|
223961
|
-
const data = JSON.parse(message.data);
|
|
223962
|
-
if (isPongMessage(data)) {
|
|
223963
|
-
logger.info("Received pong from Studio");
|
|
223964
|
-
return;
|
|
223965
|
-
}
|
|
223966
|
-
if (isCommandMessage(data)) {
|
|
223967
|
-
if (data.command === "generate") {
|
|
223968
|
-
const config = await loadConfig();
|
|
223969
|
-
const studioConfig = readStudioConfig(resolvedConfigPath);
|
|
223970
|
-
const patch = (_a = data.payload) != null ? _a : studioConfig;
|
|
223971
|
-
const resolvedPlugins = (patch == null ? void 0 : patch.plugins) ? resolvePlugins(patch.plugins) : void 0;
|
|
223972
|
-
if (allowWrite && isSandbox) {
|
|
223973
|
-
logger.warn("Agent is running in a sandbox environment, write will be disabled");
|
|
223974
|
-
}
|
|
223975
|
-
if ((patch == null ? void 0 : patch.input) && !isSandbox) {
|
|
223976
|
-
logger.warn("Input override via payload is only supported in sandbox mode and will be ignored");
|
|
223977
|
-
}
|
|
223978
|
-
const inputOverride = isSandbox ? { data: (_b = patch.input) != null ? _b : "" } : void 0;
|
|
223979
|
-
await generate({
|
|
223980
|
-
config: {
|
|
223981
|
-
...config,
|
|
223982
|
-
input: inputOverride != null ? inputOverride : config.input,
|
|
223983
|
-
plugins: resolvedPlugins != null ? resolvedPlugins : config.plugins,
|
|
223984
|
-
root,
|
|
223985
|
-
output: {
|
|
223986
|
-
...config.output,
|
|
223987
|
-
write: isSandbox ? false : allowWrite
|
|
223988
|
-
}
|
|
223989
|
-
},
|
|
223990
|
-
events
|
|
223991
|
-
});
|
|
223992
|
-
if (allowWrite) {
|
|
223993
|
-
writeStudioConfig(resolvedConfigPath, data.payload);
|
|
223994
|
-
}
|
|
223995
|
-
logger.success("Generated command success");
|
|
223996
|
-
}
|
|
223997
|
-
if (data.command === "connect") {
|
|
223998
|
-
const config = await loadConfig();
|
|
223999
|
-
sendAgentMessage(ws, {
|
|
224000
|
-
type: "connected",
|
|
224001
|
-
payload: {
|
|
224002
|
-
version,
|
|
224003
|
-
configPath,
|
|
224004
|
-
permissions: {
|
|
224005
|
-
allowAll: isSandbox ? false : allowWrite,
|
|
224006
|
-
allowWrite: isSandbox ? false : allowWrite
|
|
224007
|
-
},
|
|
224008
|
-
config: {
|
|
224009
|
-
plugins: (_c = config.plugins) == null ? void 0 : _c.map((plugin) => ({
|
|
224010
|
-
name: `@kubb/${plugin.name}`,
|
|
224011
|
-
options: serializePluginOptions(plugin.options)
|
|
224012
|
-
}))
|
|
224013
|
-
}
|
|
224014
|
-
}
|
|
224015
|
-
});
|
|
224016
|
-
}
|
|
224017
|
-
return;
|
|
224018
|
-
}
|
|
224019
|
-
logger.warn(`Unknown message type from Kubb Studio: ${message.data}`);
|
|
224020
|
-
} catch (error) {
|
|
224021
|
-
logger.error(`[unhandledRejection] ${(_d = error == null ? void 0 : error.message) != null ? _d : error}`);
|
|
224022
|
-
}
|
|
224176
|
+
sessions.set(cacheKey, session);
|
|
224177
|
+
}
|
|
224178
|
+
let index = 0;
|
|
224179
|
+
for (const [cacheKey, session] of sessions) {
|
|
224180
|
+
index++;
|
|
224181
|
+
if (!session) {
|
|
224182
|
+
continue;
|
|
224183
|
+
}
|
|
224184
|
+
const maskedSessionKey2 = maskedString(session.sessionId);
|
|
224185
|
+
logger.info(`[${maskedSessionKey2}] Connecting session ${index}/${sessions.size}`);
|
|
224186
|
+
await connectToStudio({ ...baseOptions, initialSession: session, sessionKey: cacheKey }).catch((err) => {
|
|
224187
|
+
logger.warn(`[${maskedSessionKey2}] Session ${index} failed to connect:`, err == null ? void 0 : err.message);
|
|
224023
224188
|
});
|
|
224024
|
-
} catch (error) {
|
|
224025
|
-
await storage.removeItem(getSessionKey(token));
|
|
224026
|
-
logger.error(`Something went wrong ${error}`);
|
|
224027
|
-
await reconnectToStudio();
|
|
224028
224189
|
}
|
|
224190
|
+
} catch (error) {
|
|
224191
|
+
logger.error("Failed to connect to Kubb Studio\n", error == null ? void 0 : error.message);
|
|
224029
224192
|
}
|
|
224030
|
-
await registerAgent({ token, studioUrl });
|
|
224031
|
-
await connectToStudio();
|
|
224032
224193
|
});
|
|
224033
224194
|
|
|
224034
224195
|
const plugins = [
|
|
224035
224196
|
_KZ9YuROWp70nNn4X1C4BxF_W0D7H9EWgBo03XvMd7w0,
|
|
224197
|
+
_a2VEEUGb5K4b1gyM9hOmO1Xz0hUJSFuGyIT3cHsvE,
|
|
224036
224198
|
_zcw7I4pYH8OiCfaDcjy_x7I6IH1tLDQR3W_yRZgP6E
|
|
224037
224199
|
];
|
|
224038
224200
|
|