@certalis/agent-smith 0.1.4 → 0.1.6
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 +58 -6
- package/dist/bin.js +492 -118
- package/dist/post-processor.worker.js +128 -18
- package/dist/server.js +408 -92
- package/package.json +1 -1
|
@@ -1315,11 +1315,13 @@ var init_paths = __esm(() => {
|
|
|
1315
1315
|
// ../../packages/config/src/index.ts
|
|
1316
1316
|
import { EventEmitter as EventEmitter3 } from "events";
|
|
1317
1317
|
import {
|
|
1318
|
+
chmodSync,
|
|
1318
1319
|
existsSync as existsSync2,
|
|
1319
1320
|
mkdirSync as mkdirSync2,
|
|
1320
1321
|
readFileSync,
|
|
1321
1322
|
renameSync,
|
|
1322
1323
|
rmSync,
|
|
1324
|
+
statSync as statSync2,
|
|
1323
1325
|
writeFileSync
|
|
1324
1326
|
} from "fs";
|
|
1325
1327
|
import { dirname } from "path";
|
|
@@ -1372,6 +1374,18 @@ function sanitizeConfigData(value) {
|
|
|
1372
1374
|
sanitized.provider_pools = providerPools;
|
|
1373
1375
|
continue;
|
|
1374
1376
|
}
|
|
1377
|
+
if (key === "client") {
|
|
1378
|
+
const client = sanitizeClientRouting(entry);
|
|
1379
|
+
if (client)
|
|
1380
|
+
sanitized.client = client;
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
if (key === "alerts") {
|
|
1384
|
+
const alerts = sanitizeAlerts(entry);
|
|
1385
|
+
if (alerts)
|
|
1386
|
+
sanitized.alerts = alerts;
|
|
1387
|
+
continue;
|
|
1388
|
+
}
|
|
1375
1389
|
if (typeof entry === "string" || typeof entry === "boolean" || isFiniteNumber(entry)) {
|
|
1376
1390
|
sanitized[key] = entry;
|
|
1377
1391
|
}
|
|
@@ -1402,6 +1416,46 @@ function sanitizeConfigData(value) {
|
|
|
1402
1416
|
}
|
|
1403
1417
|
return sanitized;
|
|
1404
1418
|
}
|
|
1419
|
+
function filledText(value) {
|
|
1420
|
+
if (typeof value !== "string")
|
|
1421
|
+
return;
|
|
1422
|
+
const text = value.trim();
|
|
1423
|
+
return text.length > 0 && text.length <= MAX_ALERT_VALUE_LENGTH ? text : undefined;
|
|
1424
|
+
}
|
|
1425
|
+
function sanitizeHttpsUrl(value) {
|
|
1426
|
+
const text = filledText(value);
|
|
1427
|
+
if (!text)
|
|
1428
|
+
return;
|
|
1429
|
+
try {
|
|
1430
|
+
return new URL(text).protocol === "https:" ? text : undefined;
|
|
1431
|
+
} catch {
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
}
|
|
1435
|
+
function sanitizeAlerts(value) {
|
|
1436
|
+
if (!isRecord(value))
|
|
1437
|
+
return;
|
|
1438
|
+
const alerts = {};
|
|
1439
|
+
const slackWebhookUrl = sanitizeHttpsUrl(value.slack_webhook_url);
|
|
1440
|
+
if (slackWebhookUrl)
|
|
1441
|
+
alerts.slack_webhook_url = slackWebhookUrl;
|
|
1442
|
+
const slackBotToken = filledText(value.slack_bot_token);
|
|
1443
|
+
if (slackBotToken)
|
|
1444
|
+
alerts.slack_bot_token = slackBotToken;
|
|
1445
|
+
const slackChannel = filledText(value.slack_channel);
|
|
1446
|
+
if (slackChannel)
|
|
1447
|
+
alerts.slack_channel = slackChannel;
|
|
1448
|
+
const email = normalizeEnrollmentEmail(value.email);
|
|
1449
|
+
if (email)
|
|
1450
|
+
alerts.email = email;
|
|
1451
|
+
const emailFrom = filledText(value.email_from);
|
|
1452
|
+
if (emailFrom)
|
|
1453
|
+
alerts.email_from = emailFrom;
|
|
1454
|
+
const resendApiKey = filledText(value.resend_api_key);
|
|
1455
|
+
if (resendApiKey)
|
|
1456
|
+
alerts.resend_api_key = resendApiKey;
|
|
1457
|
+
return alerts;
|
|
1458
|
+
}
|
|
1405
1459
|
function isProviderStrategy(value) {
|
|
1406
1460
|
return typeof value === "string" && PROVIDER_STRATEGIES.includes(value);
|
|
1407
1461
|
}
|
|
@@ -1415,6 +1469,23 @@ function sanitizeProviderBaseUrl(value) {
|
|
|
1415
1469
|
return;
|
|
1416
1470
|
}
|
|
1417
1471
|
}
|
|
1472
|
+
function sanitizeClientRouting(value) {
|
|
1473
|
+
if (!isRecord(value))
|
|
1474
|
+
return;
|
|
1475
|
+
const client = {};
|
|
1476
|
+
if (typeof value.base_url === "string") {
|
|
1477
|
+
try {
|
|
1478
|
+
const url = new URL(value.base_url);
|
|
1479
|
+
if ((url.protocol === "http:" || url.protocol === "https:") && url.pathname === "/" && url.search === "" && url.hash === "" && url.username === "" && url.password === "") {
|
|
1480
|
+
client.base_url = url.origin;
|
|
1481
|
+
}
|
|
1482
|
+
} catch {}
|
|
1483
|
+
}
|
|
1484
|
+
if (typeof value.proxy_key_file === "string" && (value.proxy_key_file.startsWith("/") || value.proxy_key_file.startsWith("~/")) && value.proxy_key_file.length <= 1024) {
|
|
1485
|
+
client.proxy_key_file = value.proxy_key_file;
|
|
1486
|
+
}
|
|
1487
|
+
return Object.keys(client).length > 0 ? client : undefined;
|
|
1488
|
+
}
|
|
1418
1489
|
function sanitizeProviderModels(value) {
|
|
1419
1490
|
if (!isRecord(value))
|
|
1420
1491
|
return;
|
|
@@ -1503,7 +1574,7 @@ function sanitizeTeamRouting(value) {
|
|
|
1503
1574
|
}
|
|
1504
1575
|
return result;
|
|
1505
1576
|
}
|
|
1506
|
-
var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, Config;
|
|
1577
|
+
var log2, PROVIDER_STRATEGIES, BUILTIN_PROVIDER_CONFIGS, BUILTIN_PROVIDER_CONFIG_BY_NAME, PROVIDER_NAME_PATTERN, TEAM_ROUTING_DEFAULTS, MAX_ENROLLMENT_EMAILS = 200, MAX_ALERT_VALUE_LENGTH = 512, Config;
|
|
1507
1578
|
var init_src4 = __esm(() => {
|
|
1508
1579
|
init_src2();
|
|
1509
1580
|
init_src3();
|
|
@@ -1550,17 +1621,30 @@ var init_src4 = __esm(() => {
|
|
|
1550
1621
|
try {
|
|
1551
1622
|
const content = readFileSync(this.configPath, "utf8");
|
|
1552
1623
|
this.data = sanitizeConfigData(JSON.parse(content));
|
|
1553
|
-
if ("default_agent_model" in this.data) {
|
|
1554
|
-
delete this.data.default_agent_model;
|
|
1555
|
-
this.saveConfig();
|
|
1556
|
-
}
|
|
1557
1624
|
} catch (error) {
|
|
1558
1625
|
log2.error(`Failed to parse config file: ${error}`);
|
|
1559
1626
|
this.data = {};
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
try {
|
|
1630
|
+
chmodSync(this.configPath, 384);
|
|
1631
|
+
} catch {
|
|
1632
|
+
let ownerOnly = false;
|
|
1633
|
+
try {
|
|
1634
|
+
ownerOnly = (statSync2(this.configPath).mode & 63) === 0;
|
|
1635
|
+
} catch {}
|
|
1636
|
+
if (!ownerOnly) {
|
|
1637
|
+
throw new Error("Config file must be owner-only");
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
if ("default_agent_model" in this.data) {
|
|
1641
|
+
delete this.data.default_agent_model;
|
|
1642
|
+
this.saveConfig();
|
|
1560
1643
|
}
|
|
1561
1644
|
} else {
|
|
1562
1645
|
const dir = dirname(this.configPath);
|
|
1563
|
-
mkdirSync2(dir, { recursive: true });
|
|
1646
|
+
mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
1647
|
+
chmodSync(dir, 448);
|
|
1564
1648
|
this.data = {
|
|
1565
1649
|
lb_strategy: DEFAULT_STRATEGY
|
|
1566
1650
|
};
|
|
@@ -1569,12 +1653,23 @@ var init_src4 = __esm(() => {
|
|
|
1569
1653
|
}
|
|
1570
1654
|
saveConfig() {
|
|
1571
1655
|
try {
|
|
1572
|
-
|
|
1573
|
-
writeFileSync(this.configPath, content, "utf8");
|
|
1656
|
+
this.writePrivately(this.data);
|
|
1574
1657
|
} catch (error) {
|
|
1575
1658
|
log2.error(`Failed to save config file: ${error}`);
|
|
1576
1659
|
}
|
|
1577
1660
|
}
|
|
1661
|
+
writePrivately(data) {
|
|
1662
|
+
const temporary = `${this.configPath}.${crypto.randomUUID()}.tmp`;
|
|
1663
|
+
try {
|
|
1664
|
+
writeFileSync(temporary, JSON.stringify(data, null, 2), {
|
|
1665
|
+
mode: 384,
|
|
1666
|
+
flag: "wx"
|
|
1667
|
+
});
|
|
1668
|
+
renameSync(temporary, this.configPath);
|
|
1669
|
+
} finally {
|
|
1670
|
+
rmSync(temporary, { force: true });
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1578
1673
|
get(key, defaultValue) {
|
|
1579
1674
|
const value = this.data[key];
|
|
1580
1675
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
@@ -1669,6 +1764,29 @@ var init_src4 = __esm(() => {
|
|
|
1669
1764
|
quotaProbeSeconds: file?.quota_probe_seconds ?? TEAM_ROUTING_DEFAULTS.quotaProbeSeconds
|
|
1670
1765
|
};
|
|
1671
1766
|
}
|
|
1767
|
+
getAlerts() {
|
|
1768
|
+
const file = this.data.alerts;
|
|
1769
|
+
return {
|
|
1770
|
+
slackWebhookUrl: file?.slack_webhook_url ?? null,
|
|
1771
|
+
slackBotToken: file?.slack_bot_token ?? null,
|
|
1772
|
+
slackChannel: file?.slack_channel ?? null,
|
|
1773
|
+
email: file?.email ?? null,
|
|
1774
|
+
emailFrom: file?.email_from ?? null,
|
|
1775
|
+
resendApiKey: file?.resend_api_key ?? null
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
getClientRouting() {
|
|
1779
|
+
const client = this.data.client;
|
|
1780
|
+
return {
|
|
1781
|
+
...client?.base_url && { baseUrl: client.base_url },
|
|
1782
|
+
...client?.proxy_key_file && {
|
|
1783
|
+
proxyKeyFile: client.proxy_key_file
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
}
|
|
1787
|
+
getBlockWhenAllFull() {
|
|
1788
|
+
return this.data.block_when_all_full !== false;
|
|
1789
|
+
}
|
|
1672
1790
|
getProviderConfig(name) {
|
|
1673
1791
|
const builtin = BUILTIN_PROVIDER_CONFIG_BY_NAME.get(name);
|
|
1674
1792
|
const configured = this.data.providers?.[name];
|
|
@@ -1769,22 +1887,14 @@ var init_src4 = __esm(() => {
|
|
|
1769
1887
|
}
|
|
1770
1888
|
persistStrictly(key, value) {
|
|
1771
1889
|
const next = { ...this.data, [key]: value };
|
|
1772
|
-
|
|
1773
|
-
try {
|
|
1774
|
-
writeFileSync(temporary, JSON.stringify(next, null, 2), {
|
|
1775
|
-
mode: 384,
|
|
1776
|
-
flag: "wx"
|
|
1777
|
-
});
|
|
1778
|
-
renameSync(temporary, this.configPath);
|
|
1779
|
-
} finally {
|
|
1780
|
-
rmSync(temporary, { force: true });
|
|
1781
|
-
}
|
|
1890
|
+
this.writePrivately(next);
|
|
1782
1891
|
const oldValue = this.data[key];
|
|
1783
1892
|
this.data = next;
|
|
1784
1893
|
this.emit("change", { key, oldValue, newValue: value });
|
|
1785
1894
|
}
|
|
1786
1895
|
getRuntime() {
|
|
1787
1896
|
const defaults = {
|
|
1897
|
+
blockWhenAllFull: this.getBlockWhenAllFull(),
|
|
1788
1898
|
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
1789
1899
|
maxBodyBytes: 64 * 1024 * 1024,
|
|
1790
1900
|
quotaThreshold: 0.98,
|