@certalis/agent-smith 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -12
- package/dist/bin.js +1649 -315
- package/dist/client-launcher.js +2473 -0
- package/dist/dashboard/chunk-re8nxxzq.css +1 -0
- package/dist/dashboard/chunk-v15gev12.js +111 -0
- package/dist/dashboard/{chunk-rnbsj0t8.js.map → chunk-v15gev12.js.map} +11 -8
- package/dist/dashboard/index.html +1 -1
- package/dist/dashboard/manifest.json +3 -3
- package/dist/edge.js +12 -1
- package/dist/https.js +16 -3
- package/dist/pool-status.js +170 -0
- package/dist/pool.js +1124 -275
- package/dist/post-processor.worker.js +255 -32
- package/dist/server.js +1123 -274
- package/package.json +1 -1
- package/dist/dashboard/chunk-r6qvhv5e.css +0 -1
- package/dist/dashboard/chunk-rnbsj0t8.js +0 -111
|
@@ -841,7 +841,6 @@ function isRequestStreamEvent(value) {
|
|
|
841
841
|
var init_request_events2 = __esm(() => {
|
|
842
842
|
init_request();
|
|
843
843
|
});
|
|
844
|
-
|
|
845
844
|
// ../../packages/types/src/stats.ts
|
|
846
845
|
function isTimeRange(value) {
|
|
847
846
|
return TIME_RANGES.includes(value);
|
|
@@ -1314,6 +1313,129 @@ var init_paths = __esm(() => {
|
|
|
1314
1313
|
init_paths_common();
|
|
1315
1314
|
});
|
|
1316
1315
|
|
|
1316
|
+
// ../../packages/config/src/window-warmup.ts
|
|
1317
|
+
function isLocalTimes(value) {
|
|
1318
|
+
return Array.isArray(value) && value.length > 0 && value.length <= MAX_TIMES && value.every((time) => typeof time === "string" && LOCAL_TIME.test(time));
|
|
1319
|
+
}
|
|
1320
|
+
function isTimeZone(value) {
|
|
1321
|
+
if (typeof value !== "string" || value.length === 0 || value.length > 64) {
|
|
1322
|
+
return false;
|
|
1323
|
+
}
|
|
1324
|
+
try {
|
|
1325
|
+
new Intl.DateTimeFormat("en-US", { timeZone: value });
|
|
1326
|
+
return true;
|
|
1327
|
+
} catch {
|
|
1328
|
+
return false;
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
function sanitizeWindowWarmup(value) {
|
|
1332
|
+
if (!isRecord(value))
|
|
1333
|
+
return;
|
|
1334
|
+
const result = {};
|
|
1335
|
+
if (typeof value.enabled === "boolean")
|
|
1336
|
+
result.enabled = value.enabled;
|
|
1337
|
+
if (isLocalTimes(value.times))
|
|
1338
|
+
result.times = [...new Set(value.times)];
|
|
1339
|
+
if (isTimeZone(value.time_zone))
|
|
1340
|
+
result.time_zone = value.time_zone;
|
|
1341
|
+
if (typeof value.weekdays_only === "boolean") {
|
|
1342
|
+
result.weekdays_only = value.weekdays_only;
|
|
1343
|
+
}
|
|
1344
|
+
if (typeof value.model === "string" && MODEL_NAME.test(value.model)) {
|
|
1345
|
+
result.model = value.model;
|
|
1346
|
+
}
|
|
1347
|
+
return Object.keys(value).every((key) => (key in result)) ? result : undefined;
|
|
1348
|
+
}
|
|
1349
|
+
function windowWarmupConfig(file) {
|
|
1350
|
+
return {
|
|
1351
|
+
enabled: file?.enabled ?? WINDOW_WARMUP_DEFAULTS.enabled,
|
|
1352
|
+
times: [...file?.times ?? WINDOW_WARMUP_DEFAULTS.times],
|
|
1353
|
+
timeZone: file?.time_zone ?? WINDOW_WARMUP_DEFAULTS.timeZone,
|
|
1354
|
+
weekdaysOnly: file?.weekdays_only ?? WINDOW_WARMUP_DEFAULTS.weekdaysOnly,
|
|
1355
|
+
model: file?.model ?? WINDOW_WARMUP_DEFAULTS.model
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
function windowWarmupFileConfig(config) {
|
|
1359
|
+
return {
|
|
1360
|
+
enabled: config.enabled,
|
|
1361
|
+
times: [...config.times],
|
|
1362
|
+
time_zone: config.timeZone,
|
|
1363
|
+
weekdays_only: config.weekdaysOnly,
|
|
1364
|
+
...config.model && { model: config.model }
|
|
1365
|
+
};
|
|
1366
|
+
}
|
|
1367
|
+
function wallClockFormat(timeZone) {
|
|
1368
|
+
let format = wallClockFormats.get(timeZone);
|
|
1369
|
+
if (!format) {
|
|
1370
|
+
format = new Intl.DateTimeFormat("en-US", {
|
|
1371
|
+
timeZone,
|
|
1372
|
+
hourCycle: "h23",
|
|
1373
|
+
year: "numeric",
|
|
1374
|
+
month: "numeric",
|
|
1375
|
+
day: "numeric",
|
|
1376
|
+
hour: "numeric",
|
|
1377
|
+
minute: "numeric",
|
|
1378
|
+
second: "numeric"
|
|
1379
|
+
});
|
|
1380
|
+
wallClockFormats.set(timeZone, format);
|
|
1381
|
+
}
|
|
1382
|
+
return format;
|
|
1383
|
+
}
|
|
1384
|
+
function wallClock(at, timeZone) {
|
|
1385
|
+
const parts = wallClockFormat(timeZone).formatToParts(at);
|
|
1386
|
+
const part = (type) => Number(parts.find((entry) => entry.type === type)?.value);
|
|
1387
|
+
return {
|
|
1388
|
+
year: part("year"),
|
|
1389
|
+
month: part("month"),
|
|
1390
|
+
day: part("day"),
|
|
1391
|
+
hour: part("hour") % 24,
|
|
1392
|
+
minute: part("minute"),
|
|
1393
|
+
second: part("second")
|
|
1394
|
+
};
|
|
1395
|
+
}
|
|
1396
|
+
function zoneOffsetMs(at, timeZone) {
|
|
1397
|
+
const wall = wallClock(at, timeZone);
|
|
1398
|
+
return Date.UTC(wall.year, wall.month - 1, wall.day, wall.hour, wall.minute, wall.second) - Math.floor(at / 1000) * 1000;
|
|
1399
|
+
}
|
|
1400
|
+
function zonedInstant(wall, timeZone) {
|
|
1401
|
+
return wall - zoneOffsetMs(wall - zoneOffsetMs(wall, timeZone), timeZone);
|
|
1402
|
+
}
|
|
1403
|
+
function nextWindowWarmupAt(routing, after) {
|
|
1404
|
+
const warmup = routing.windowWarmup;
|
|
1405
|
+
if (!routing.enabled || !warmup.enabled)
|
|
1406
|
+
return null;
|
|
1407
|
+
const today = wallClock(after, warmup.timeZone);
|
|
1408
|
+
for (let offset = 0;offset < 8; offset++) {
|
|
1409
|
+
const day = Date.UTC(today.year, today.month - 1, today.day + offset);
|
|
1410
|
+
const weekday = new Date(day).getUTCDay();
|
|
1411
|
+
if (warmup.weekdaysOnly && (weekday === SATURDAY || weekday === SUNDAY)) {
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
const instants = warmup.times.map((time) => {
|
|
1415
|
+
const [hour = 0, minute = 0] = time.split(":").map(Number);
|
|
1416
|
+
return zonedInstant(day + hour * TIME_CONSTANTS.HOUR + minute * TIME_CONSTANTS.MINUTE, warmup.timeZone);
|
|
1417
|
+
}).filter((at) => at > after);
|
|
1418
|
+
if (instants.length > 0)
|
|
1419
|
+
return Math.min(...instants);
|
|
1420
|
+
}
|
|
1421
|
+
return null;
|
|
1422
|
+
}
|
|
1423
|
+
var WINDOW_WARMUP_DEFAULTS, LOCAL_TIME, MODEL_NAME, MAX_TIMES = 24, SATURDAY = 6, SUNDAY = 0, wallClockFormats;
|
|
1424
|
+
var init_window_warmup = __esm(() => {
|
|
1425
|
+
init_src2();
|
|
1426
|
+
init_src();
|
|
1427
|
+
WINDOW_WARMUP_DEFAULTS = {
|
|
1428
|
+
enabled: false,
|
|
1429
|
+
times: ["06:00"],
|
|
1430
|
+
timeZone: "Europe/Paris",
|
|
1431
|
+
weekdaysOnly: true,
|
|
1432
|
+
model: null
|
|
1433
|
+
};
|
|
1434
|
+
LOCAL_TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
1435
|
+
MODEL_NAME = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,99}$/;
|
|
1436
|
+
wallClockFormats = new Map;
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1317
1439
|
// ../../packages/config/src/index.ts
|
|
1318
1440
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
1319
1441
|
import {
|
|
@@ -1340,10 +1462,20 @@ function normalizeEnrollmentEmail(value) {
|
|
|
1340
1462
|
const email = value.trim().toLowerCase();
|
|
1341
1463
|
return email.length <= 254 && patterns.email.test(email) ? email : undefined;
|
|
1342
1464
|
}
|
|
1465
|
+
function normalizeEnrollmentRule(value) {
|
|
1466
|
+
const rule = normalizeEnrollmentEmail(value);
|
|
1467
|
+
if (!rule?.includes("*"))
|
|
1468
|
+
return rule;
|
|
1469
|
+
if (!rule.startsWith("*@"))
|
|
1470
|
+
return;
|
|
1471
|
+
const labels = rule.slice(2).split(".");
|
|
1472
|
+
const label = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
1473
|
+
return labels.length >= 2 && labels.every((part) => label.test(part)) ? rule : undefined;
|
|
1474
|
+
}
|
|
1343
1475
|
function sanitizeEnrollmentEmails(value) {
|
|
1344
1476
|
if (!Array.isArray(value))
|
|
1345
1477
|
return;
|
|
1346
|
-
const emails = value.map(
|
|
1478
|
+
const emails = value.map(normalizeEnrollmentRule).filter((email) => email !== undefined);
|
|
1347
1479
|
return [...new Set(emails)].slice(0, MAX_ENROLLMENT_EMAILS);
|
|
1348
1480
|
}
|
|
1349
1481
|
function sanitizeConfigData(value) {
|
|
@@ -1488,6 +1620,12 @@ function sanitizeClientRouting(value) {
|
|
|
1488
1620
|
if (typeof value.proxy_key_file === "string" && (value.proxy_key_file.startsWith("/") || value.proxy_key_file.startsWith("~/")) && value.proxy_key_file.length <= 1024) {
|
|
1489
1621
|
client.proxy_key_file = value.proxy_key_file;
|
|
1490
1622
|
}
|
|
1623
|
+
if (typeof value.keep_claude_login === "boolean") {
|
|
1624
|
+
client.keep_claude_login = value.keep_claude_login;
|
|
1625
|
+
}
|
|
1626
|
+
if (typeof value.pool_ssh_host === "string" && POOL_SSH_HOST_PATTERN.test(value.pool_ssh_host)) {
|
|
1627
|
+
client.pool_ssh_host = value.pool_ssh_host;
|
|
1628
|
+
}
|
|
1491
1629
|
return Object.keys(client).length > 0 ? client : undefined;
|
|
1492
1630
|
}
|
|
1493
1631
|
function sanitizeProviderModels(value) {
|
|
@@ -1555,12 +1693,25 @@ function sanitizeTeamRouting(value) {
|
|
|
1555
1693
|
if (typeof value.distribution_enabled === "boolean") {
|
|
1556
1694
|
result.distribution_enabled = value.distribution_enabled;
|
|
1557
1695
|
}
|
|
1696
|
+
if (typeof value.prefer_expiring_quota === "boolean") {
|
|
1697
|
+
result.prefer_expiring_quota = value.prefer_expiring_quota;
|
|
1698
|
+
}
|
|
1558
1699
|
if (Array.isArray(value.allowlisted_account_uuids) && value.allowlisted_account_uuids.every((entry) => typeof entry === "string" && entry.length > 0 && entry.length <= 200)) {
|
|
1559
1700
|
result.allowlisted_account_uuids = [...value.allowlisted_account_uuids];
|
|
1560
1701
|
}
|
|
1561
1702
|
if (isFiniteNumber(value.max_usage) && value.max_usage > 0 && value.max_usage <= 0.9) {
|
|
1562
1703
|
result.max_usage = value.max_usage;
|
|
1563
1704
|
}
|
|
1705
|
+
if (isFiniteNumber(value.weekly_max_usage) && value.weekly_max_usage > 0 && value.weekly_max_usage <= 0.95) {
|
|
1706
|
+
result.weekly_max_usage = value.weekly_max_usage;
|
|
1707
|
+
}
|
|
1708
|
+
if (isRecord(value.weekly_max_usage_by_email)) {
|
|
1709
|
+
const entries = Object.entries(value.weekly_max_usage_by_email);
|
|
1710
|
+
const normalized = entries.map(([email, cap]) => [normalizeEnrollmentEmail(email), cap]);
|
|
1711
|
+
if (normalized.every(([email, cap]) => email !== undefined && isFiniteNumber(cap) && cap > 0 && cap <= 0.95) && new Set(normalized.map(([email]) => email)).size === entries.length) {
|
|
1712
|
+
result.weekly_max_usage_by_email = Object.fromEntries(normalized);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1564
1715
|
if (isNonNegativeFiniteNumber(value.admission_cap)) {
|
|
1565
1716
|
result.admission_cap = Math.floor(value.admission_cap);
|
|
1566
1717
|
}
|
|
@@ -1576,16 +1727,42 @@ function sanitizeTeamRouting(value) {
|
|
|
1576
1727
|
if (isNonNegativeFiniteNumber(value.quota_probe_seconds)) {
|
|
1577
1728
|
result.quota_probe_seconds = Math.min(Math.floor(value.quota_probe_seconds), 7 * 24 * 60 * 60);
|
|
1578
1729
|
}
|
|
1730
|
+
const windowWarmup = sanitizeWindowWarmup(value.window_warmup);
|
|
1731
|
+
if (windowWarmup)
|
|
1732
|
+
result.window_warmup = windowWarmup;
|
|
1579
1733
|
return result;
|
|
1580
1734
|
}
|
|
1581
|
-
|
|
1735
|
+
function readClientRouting(configPath = resolveConfigPath()) {
|
|
1736
|
+
let data;
|
|
1737
|
+
try {
|
|
1738
|
+
data = JSON.parse(readFileSync(configPath, "utf8"));
|
|
1739
|
+
} catch {
|
|
1740
|
+
throw new Error("Agent Smith client config could not be read");
|
|
1741
|
+
}
|
|
1742
|
+
if (!isRecord(data) || data.client !== undefined && !isRecord(data.client) || isRecord(data.client) && data.client.enabled !== undefined && typeof data.client.enabled !== "boolean") {
|
|
1743
|
+
throw new Error("Agent Smith client config is invalid");
|
|
1744
|
+
}
|
|
1745
|
+
return clientRouting(sanitizeClientRouting(data.client));
|
|
1746
|
+
}
|
|
1747
|
+
function clientRouting(client) {
|
|
1748
|
+
return {
|
|
1749
|
+
enabled: client?.enabled === true,
|
|
1750
|
+
...client?.base_url && { baseUrl: client.base_url },
|
|
1751
|
+
...client?.proxy_key_file && { proxyKeyFile: client.proxy_key_file },
|
|
1752
|
+
...client?.keep_claude_login === true && { keepClaudeLogin: true },
|
|
1753
|
+
...client?.pool_ssh_host && { poolSshHost: client.pool_ssh_host }
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, POOL_SSH_HOST_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, MAX_ALERT_VALUE_LENGTH = 512, Config;
|
|
1582
1757
|
var init_src4 = __esm(() => {
|
|
1583
1758
|
init_src2();
|
|
1584
1759
|
init_src3();
|
|
1585
1760
|
init_src();
|
|
1586
1761
|
init_paths();
|
|
1762
|
+
init_window_warmup();
|
|
1587
1763
|
init_paths();
|
|
1588
1764
|
init_paths_common();
|
|
1765
|
+
init_window_warmup();
|
|
1589
1766
|
log2 = new Logger("Config");
|
|
1590
1767
|
PROVIDER_STRATEGIES = [
|
|
1591
1768
|
"anthropic-api",
|
|
@@ -1601,16 +1778,21 @@ var init_src4 = __esm(() => {
|
|
|
1601
1778
|
];
|
|
1602
1779
|
BUILTIN_PROVIDER_CONFIG_BY_NAME = new Map(BUILTIN_PROVIDER_CONFIGS.map((provider) => [provider.name, provider]));
|
|
1603
1780
|
PROVIDER_NAME_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
1781
|
+
POOL_SSH_HOST_PATTERN = /^\w[\w.-]{0,127}(@\w[\w.-]{0,127})?$/;
|
|
1604
1782
|
TEAM_ROUTING_DEFAULTS = {
|
|
1605
1783
|
enabled: false,
|
|
1606
1784
|
distributionEnabled: true,
|
|
1785
|
+
preferExpiringQuota: false,
|
|
1607
1786
|
allowlistedAccountUuids: [],
|
|
1608
1787
|
maxUsage: 0.9,
|
|
1788
|
+
weeklyMaxUsage: 0.95,
|
|
1789
|
+
weeklyMaxUsageByEmail: {},
|
|
1609
1790
|
admissionCap: 5,
|
|
1610
1791
|
admissionQueueLimit: 25,
|
|
1611
1792
|
admissionWaitMs: 30000,
|
|
1612
1793
|
holdSeconds: 0,
|
|
1613
|
-
quotaProbeSeconds: 0
|
|
1794
|
+
quotaProbeSeconds: 0,
|
|
1795
|
+
windowWarmup: WINDOW_WARMUP_DEFAULTS
|
|
1614
1796
|
};
|
|
1615
1797
|
Config = class Config extends EventEmitter3 {
|
|
1616
1798
|
configPath;
|
|
@@ -1716,17 +1898,20 @@ var init_src4 = __esm(() => {
|
|
|
1716
1898
|
if (fromEnv) {
|
|
1717
1899
|
const n = parseInt(fromEnv, 10);
|
|
1718
1900
|
if (!Number.isNaN(n))
|
|
1719
|
-
return this.clamp(n,
|
|
1901
|
+
return this.clamp(n, 0, 365);
|
|
1720
1902
|
}
|
|
1721
1903
|
const fromFile = this.data.data_retention_days;
|
|
1722
1904
|
if (typeof fromFile === "number")
|
|
1723
|
-
return this.clamp(fromFile,
|
|
1905
|
+
return this.clamp(fromFile, 0, 365);
|
|
1724
1906
|
return 7;
|
|
1725
1907
|
}
|
|
1726
1908
|
setDataRetentionDays(days) {
|
|
1727
|
-
const clamped = this.clamp(days,
|
|
1909
|
+
const clamped = this.clamp(days, 0, 365);
|
|
1728
1910
|
this.set("data_retention_days", clamped);
|
|
1729
1911
|
}
|
|
1912
|
+
storesRequestPayloads() {
|
|
1913
|
+
return this.getDataRetentionDays() > 0;
|
|
1914
|
+
}
|
|
1730
1915
|
getRequestRetentionDays() {
|
|
1731
1916
|
const fromEnv = process.env.AGENT_SMITH_REQUEST_RETENTION_DAYS;
|
|
1732
1917
|
if (fromEnv) {
|
|
@@ -1757,15 +1942,19 @@ var init_src4 = __esm(() => {
|
|
|
1757
1942
|
return {
|
|
1758
1943
|
enabled: file?.enabled ?? TEAM_ROUTING_DEFAULTS.enabled,
|
|
1759
1944
|
distributionEnabled: file?.distribution_enabled ?? TEAM_ROUTING_DEFAULTS.distributionEnabled,
|
|
1945
|
+
preferExpiringQuota: file?.prefer_expiring_quota ?? TEAM_ROUTING_DEFAULTS.preferExpiringQuota,
|
|
1760
1946
|
allowlistedAccountUuids: [
|
|
1761
1947
|
...file?.allowlisted_account_uuids ?? TEAM_ROUTING_DEFAULTS.allowlistedAccountUuids
|
|
1762
1948
|
],
|
|
1763
1949
|
maxUsage: file?.max_usage ?? TEAM_ROUTING_DEFAULTS.maxUsage,
|
|
1950
|
+
weeklyMaxUsage: file?.weekly_max_usage ?? TEAM_ROUTING_DEFAULTS.weeklyMaxUsage,
|
|
1951
|
+
weeklyMaxUsageByEmail: { ...file?.weekly_max_usage_by_email },
|
|
1764
1952
|
admissionCap: file?.admission_cap ?? TEAM_ROUTING_DEFAULTS.admissionCap,
|
|
1765
1953
|
admissionQueueLimit: file?.admission_queue_limit ?? TEAM_ROUTING_DEFAULTS.admissionQueueLimit,
|
|
1766
1954
|
admissionWaitMs: file?.admission_wait_ms ?? TEAM_ROUTING_DEFAULTS.admissionWaitMs,
|
|
1767
1955
|
holdSeconds: file?.hold_seconds ?? TEAM_ROUTING_DEFAULTS.holdSeconds,
|
|
1768
|
-
quotaProbeSeconds: file?.quota_probe_seconds ?? TEAM_ROUTING_DEFAULTS.quotaProbeSeconds
|
|
1956
|
+
quotaProbeSeconds: file?.quota_probe_seconds ?? TEAM_ROUTING_DEFAULTS.quotaProbeSeconds,
|
|
1957
|
+
windowWarmup: windowWarmupConfig(file?.window_warmup)
|
|
1769
1958
|
};
|
|
1770
1959
|
}
|
|
1771
1960
|
getAlerts() {
|
|
@@ -1780,14 +1969,10 @@ var init_src4 = __esm(() => {
|
|
|
1780
1969
|
};
|
|
1781
1970
|
}
|
|
1782
1971
|
getClientRouting() {
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
...client?.proxy_key_file && {
|
|
1788
|
-
proxyKeyFile: client.proxy_key_file
|
|
1789
|
-
}
|
|
1790
|
-
};
|
|
1972
|
+
return clientRouting(this.data.client);
|
|
1973
|
+
}
|
|
1974
|
+
setClientRoutingEnabled(enabled) {
|
|
1975
|
+
this.persistStrictly("client", { ...this.data.client, enabled });
|
|
1791
1976
|
}
|
|
1792
1977
|
getBlockWhenAllFull() {
|
|
1793
1978
|
return this.data.block_when_all_full !== false;
|
|
@@ -1828,13 +2013,17 @@ var init_src4 = __esm(() => {
|
|
|
1828
2013
|
const allowed = new Set([
|
|
1829
2014
|
"enabled",
|
|
1830
2015
|
"distribution_enabled",
|
|
2016
|
+
"prefer_expiring_quota",
|
|
1831
2017
|
"allowlisted_account_uuids",
|
|
1832
2018
|
"max_usage",
|
|
2019
|
+
"weekly_max_usage",
|
|
2020
|
+
"weekly_max_usage_by_email",
|
|
1833
2021
|
"admission_cap",
|
|
1834
2022
|
"admission_queue_limit",
|
|
1835
2023
|
"admission_wait_ms",
|
|
1836
2024
|
"hold_seconds",
|
|
1837
|
-
"quota_probe_seconds"
|
|
2025
|
+
"quota_probe_seconds",
|
|
2026
|
+
"window_warmup"
|
|
1838
2027
|
]);
|
|
1839
2028
|
if (Object.keys(value).some((key) => !allowed.has(key))) {
|
|
1840
2029
|
throw new Error("team routing configuration contains an unknown field");
|
|
@@ -1849,13 +2038,12 @@ var init_src4 = __esm(() => {
|
|
|
1849
2038
|
}
|
|
1850
2039
|
}
|
|
1851
2040
|
const oldValue = this.data.team_routing;
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
});
|
|
2041
|
+
if (!("weekly_max_usage_by_email" in value) && oldValue?.weekly_max_usage_by_email) {
|
|
2042
|
+
sanitized.weekly_max_usage_by_email = {
|
|
2043
|
+
...oldValue.weekly_max_usage_by_email
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
this.persistStrictly("team_routing", sanitized);
|
|
1859
2047
|
}
|
|
1860
2048
|
allowAccountUuid(accountUuid) {
|
|
1861
2049
|
const current = this.getTeamRouting().allowlistedAccountUuids;
|
|
@@ -1878,10 +2066,18 @@ var init_src4 = __esm(() => {
|
|
|
1878
2066
|
getEnrollmentEmails() {
|
|
1879
2067
|
return [...this.data.enrollment_emails ?? []];
|
|
1880
2068
|
}
|
|
2069
|
+
isEnrollmentEmailAllowed(value) {
|
|
2070
|
+
const email = normalizeEnrollmentEmail(value);
|
|
2071
|
+
if (!email || email.includes("*"))
|
|
2072
|
+
return false;
|
|
2073
|
+
const rules = this.data.enrollment_emails ?? [];
|
|
2074
|
+
const domainRule = `*${email.slice(email.indexOf("@"))}`;
|
|
2075
|
+
return rules.includes(email) || rules.includes(domainRule);
|
|
2076
|
+
}
|
|
1881
2077
|
setEnrollmentEmails(emails) {
|
|
1882
|
-
const normalized = emails.map(
|
|
2078
|
+
const normalized = emails.map(normalizeEnrollmentRule);
|
|
1883
2079
|
if (normalized.some((email) => email === undefined)) {
|
|
1884
|
-
throw new ValidationError("Invalid enrollment email", "enrollment_emails");
|
|
2080
|
+
throw new ValidationError("Invalid enrollment email or exact-domain rule (use *@example.com)", "enrollment_emails");
|
|
1885
2081
|
}
|
|
1886
2082
|
const unique = [...new Set(normalized)];
|
|
1887
2083
|
if (unique.length > MAX_ENROLLMENT_EMAILS) {
|
|
@@ -1911,6 +2107,7 @@ var init_src4 = __esm(() => {
|
|
|
1911
2107
|
},
|
|
1912
2108
|
sessionDurationMs: TIME_CONSTANTS.SESSION_DURATION_DEFAULT,
|
|
1913
2109
|
port: NETWORK.DEFAULT_PORT,
|
|
2110
|
+
storeRequestPayloads: this.storesRequestPayloads(),
|
|
1914
2111
|
teamRouting: this.getTeamRouting()
|
|
1915
2112
|
};
|
|
1916
2113
|
if (process.env.AGENT_SMITH_CLIENT_ID) {
|
|
@@ -2434,7 +2631,7 @@ function backfillRequestLinkageColumns(db) {
|
|
|
2434
2631
|
FROM requests r
|
|
2435
2632
|
LEFT JOIN request_payloads rp ON rp.id = r.id
|
|
2436
2633
|
ORDER BY r.timestamp ASC
|
|
2437
|
-
`).
|
|
2634
|
+
`).iterate();
|
|
2438
2635
|
const responseToChain = new Map;
|
|
2439
2636
|
let updatedRows = 0;
|
|
2440
2637
|
const updateStmt = db.prepare(`
|
|
@@ -3592,7 +3789,7 @@ var init_request_repository = __esm(() => {
|
|
|
3592
3789
|
}
|
|
3593
3790
|
save(data) {
|
|
3594
3791
|
const { usage, timings } = data;
|
|
3595
|
-
const payloadJson = data.payload === undefined ? undefined : JSON.stringify(data.payload);
|
|
3792
|
+
const payloadJson = data.payload === undefined || data.storePayload === false ? undefined : JSON.stringify(data.payload);
|
|
3596
3793
|
const linkage = requestLinkageFromPayload(data.payload);
|
|
3597
3794
|
const responseChainId = this.resolveResponseChainId(linkage.previousResponseId, linkage.responseId, data.id);
|
|
3598
3795
|
this.db.run("BEGIN");
|
|
@@ -3972,7 +4169,11 @@ var init_request_repository = __esm(() => {
|
|
|
3972
4169
|
return this.runWithChanges(`DELETE FROM request_payloads WHERE id NOT IN (SELECT id FROM requests)`);
|
|
3973
4170
|
}
|
|
3974
4171
|
deletePayloadsOlderThan(cutoffTs) {
|
|
3975
|
-
return this.runWithChanges(`DELETE FROM request_payloads
|
|
4172
|
+
return this.runWithChanges(`DELETE FROM request_payloads
|
|
4173
|
+
WHERE EXISTS (
|
|
4174
|
+
SELECT 1 FROM requests r
|
|
4175
|
+
WHERE r.id = request_payloads.id AND r.timestamp < ?
|
|
4176
|
+
)`, [cutoffTs]);
|
|
3976
4177
|
}
|
|
3977
4178
|
};
|
|
3978
4179
|
});
|
|
@@ -4099,11 +4300,16 @@ var init_strategy_repository = __esm(() => {
|
|
|
4099
4300
|
|
|
4100
4301
|
// ../../packages/database/src/database-operations.ts
|
|
4101
4302
|
import { Database } from "bun:sqlite";
|
|
4102
|
-
import { mkdirSync as mkdirSync3 } from "fs";
|
|
4303
|
+
import { mkdirSync as mkdirSync3, statfsSync } from "fs";
|
|
4103
4304
|
import { dirname as dirname2 } from "path";
|
|
4305
|
+
function freeDiskBytes(directory) {
|
|
4306
|
+
const { bavail, bsize } = statfsSync(directory);
|
|
4307
|
+
return bavail * bsize;
|
|
4308
|
+
}
|
|
4104
4309
|
|
|
4105
4310
|
class DatabaseOperations {
|
|
4106
4311
|
db;
|
|
4312
|
+
dbPath;
|
|
4107
4313
|
runtime;
|
|
4108
4314
|
closed = false;
|
|
4109
4315
|
accounts;
|
|
@@ -4115,6 +4321,7 @@ class DatabaseOperations {
|
|
|
4115
4321
|
stats;
|
|
4116
4322
|
constructor(dbPath) {
|
|
4117
4323
|
const resolvedPath = dbPath ?? resolveDbPath();
|
|
4324
|
+
this.dbPath = resolvedPath;
|
|
4118
4325
|
const dir = dirname2(resolvedPath);
|
|
4119
4326
|
mkdirSync3(dir, { recursive: true });
|
|
4120
4327
|
this.db = new Database(resolvedPath, { create: true });
|
|
@@ -4247,6 +4454,7 @@ class DatabaseOperations {
|
|
|
4247
4454
|
usage,
|
|
4248
4455
|
timestamp: options?.timestamp,
|
|
4249
4456
|
payload: options?.payload,
|
|
4457
|
+
storePayload: options?.storePayload,
|
|
4250
4458
|
timings: options?.timings
|
|
4251
4459
|
});
|
|
4252
4460
|
}
|
|
@@ -4331,7 +4539,7 @@ class DatabaseOperations {
|
|
|
4331
4539
|
return;
|
|
4332
4540
|
}
|
|
4333
4541
|
this.closed = true;
|
|
4334
|
-
this.
|
|
4542
|
+
this.checkpointWal();
|
|
4335
4543
|
this.db.close();
|
|
4336
4544
|
}
|
|
4337
4545
|
dispose() {
|
|
@@ -4341,9 +4549,23 @@ class DatabaseOperations {
|
|
|
4341
4549
|
this.db.exec("PRAGMA optimize");
|
|
4342
4550
|
this.db.exec("PRAGMA wal_checkpoint(PASSIVE)");
|
|
4343
4551
|
}
|
|
4344
|
-
|
|
4552
|
+
checkpointWal() {
|
|
4345
4553
|
this.db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
|
|
4554
|
+
}
|
|
4555
|
+
compact(freeBytes = freeDiskBytes(dirname2(this.dbPath))) {
|
|
4556
|
+
this.checkpointWal();
|
|
4557
|
+
const requiredBytes = 2 * this.liveDataBytes();
|
|
4558
|
+
if (freeBytes < requiredBytes) {
|
|
4559
|
+
return { vacuumed: false, freeBytes, requiredBytes };
|
|
4560
|
+
}
|
|
4346
4561
|
this.db.exec("VACUUM");
|
|
4562
|
+
this.checkpointWal();
|
|
4563
|
+
return { vacuumed: true, freeBytes, requiredBytes };
|
|
4564
|
+
}
|
|
4565
|
+
liveDataBytes() {
|
|
4566
|
+
const row = this.db.query(`SELECT (page_count - freelist_count) * page_size AS bytes
|
|
4567
|
+
FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size()`).get();
|
|
4568
|
+
return row.bytes;
|
|
4347
4569
|
}
|
|
4348
4570
|
getStatsRepository() {
|
|
4349
4571
|
return this.stats;
|
|
@@ -4960,6 +5182,7 @@ async function handleEnd(msg) {
|
|
|
4960
5182
|
} : undefined, {
|
|
4961
5183
|
timestamp: startMessage.timestamp,
|
|
4962
5184
|
payload,
|
|
5185
|
+
storePayload: startMessage.storePayload,
|
|
4963
5186
|
timings
|
|
4964
5187
|
}));
|
|
4965
5188
|
if (state.usage.model && startMessage.accountId !== null) {
|