@certalis/agent-smith 0.1.8 → 0.1.10
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 +20 -10
- package/dist/bin.js +158 -144
- package/dist/dashboard/{chunk-h03pp3xg.js → chunk-rnbsj0t8.js} +6 -6
- package/dist/dashboard/{chunk-h03pp3xg.js.map → chunk-rnbsj0t8.js.map} +58 -58
- package/dist/dashboard/index.html +3 -3
- package/dist/dashboard/manifest.json +2 -2
- package/dist/edge.js +9 -2
- package/dist/https.js +420 -0
- package/dist/pool.js +12445 -0
- package/dist/post-processor.worker.js +34 -31
- package/dist/server.js +50 -43
- package/package.json +10 -10
|
@@ -334,13 +334,13 @@ class PriceCatalogue {
|
|
|
334
334
|
return PriceCatalogue.instance;
|
|
335
335
|
}
|
|
336
336
|
getCacheDir() {
|
|
337
|
-
return join(tmpdir(), "
|
|
337
|
+
return join(tmpdir(), "agent-smith");
|
|
338
338
|
}
|
|
339
339
|
getCachePath() {
|
|
340
340
|
return join(this.getCacheDir(), "models.dev.json");
|
|
341
341
|
}
|
|
342
342
|
getCacheDurationMs() {
|
|
343
|
-
const hours = Number(process.env.
|
|
343
|
+
const hours = Number(process.env.AGENT_SMITH_PRICING_REFRESH_HOURS) || 24;
|
|
344
344
|
return hours * TIME_CONSTANTS.HOUR;
|
|
345
345
|
}
|
|
346
346
|
async ensureCacheDir() {
|
|
@@ -1087,7 +1087,7 @@ class LogFileWriter {
|
|
|
1087
1087
|
stream = null;
|
|
1088
1088
|
maxFileSize = BUFFER_SIZES.LOG_FILE_MAX_SIZE;
|
|
1089
1089
|
constructor() {
|
|
1090
|
-
this.logDir = join2(tmpdir2(), "
|
|
1090
|
+
this.logDir = join2(tmpdir2(), "agent-smith-logs");
|
|
1091
1091
|
if (!existsSync(this.logDir)) {
|
|
1092
1092
|
mkdirSync(this.logDir, { recursive: true });
|
|
1093
1093
|
}
|
|
@@ -1173,11 +1173,11 @@ class Logger {
|
|
|
1173
1173
|
constructor(prefix = "", level = 1 /* INFO */, options = {}) {
|
|
1174
1174
|
this.prefix = prefix;
|
|
1175
1175
|
this.level = this.getLogLevelFromEnv() || level;
|
|
1176
|
-
this.format = process.env.
|
|
1177
|
-
this.silentConsole = options.silentConsole ?? !(process.env.
|
|
1176
|
+
this.format = process.env.AGENT_SMITH_LOG_FORMAT || "pretty";
|
|
1177
|
+
this.silentConsole = options.silentConsole ?? !(process.env.AGENT_SMITH_DEBUG === "1" || this.level === 0 /* DEBUG */);
|
|
1178
1178
|
}
|
|
1179
1179
|
getLogLevelFromEnv() {
|
|
1180
|
-
const envLevel = process.env.
|
|
1180
|
+
const envLevel = process.env.AGENT_SMITH_LOG_LEVEL?.toUpperCase();
|
|
1181
1181
|
if (envLevel && envLevel in LogLevel) {
|
|
1182
1182
|
return LogLevel[envLevel];
|
|
1183
1183
|
}
|
|
@@ -1254,7 +1254,7 @@ class Logger {
|
|
|
1254
1254
|
}
|
|
1255
1255
|
setLevel(level) {
|
|
1256
1256
|
this.level = level;
|
|
1257
|
-
this.silentConsole = !(process.env.
|
|
1257
|
+
this.silentConsole = !(process.env.AGENT_SMITH_DEBUG === "1" || this.level === 0 /* DEBUG */);
|
|
1258
1258
|
}
|
|
1259
1259
|
getLevel() {
|
|
1260
1260
|
return this.level;
|
|
@@ -1289,11 +1289,11 @@ import { platform } from "process";
|
|
|
1289
1289
|
function getPlatformConfigDir() {
|
|
1290
1290
|
if (platform === "win32") {
|
|
1291
1291
|
const baseDir = process.env.LOCALAPPDATA ?? process.env.APPDATA ?? join3(homedir(), "AppData", "Local");
|
|
1292
|
-
return join3(baseDir, "
|
|
1292
|
+
return join3(baseDir, "agent-smith");
|
|
1293
1293
|
} else {
|
|
1294
1294
|
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
1295
1295
|
const baseDir = xdgConfig ?? join3(homedir(), ".config");
|
|
1296
|
-
return join3(baseDir, "
|
|
1296
|
+
return join3(baseDir, "agent-smith");
|
|
1297
1297
|
}
|
|
1298
1298
|
}
|
|
1299
1299
|
var init_paths_common = () => {};
|
|
@@ -1301,12 +1301,12 @@ var init_paths_common = () => {};
|
|
|
1301
1301
|
// ../../packages/config/src/paths.ts
|
|
1302
1302
|
import { join as join4 } from "path";
|
|
1303
1303
|
function resolveConfigPath() {
|
|
1304
|
-
const explicitPath = process.env.
|
|
1304
|
+
const explicitPath = process.env.AGENT_SMITH_CONFIG_PATH;
|
|
1305
1305
|
if (explicitPath) {
|
|
1306
1306
|
return explicitPath;
|
|
1307
1307
|
}
|
|
1308
1308
|
const configDir = getPlatformConfigDir();
|
|
1309
|
-
return join4(configDir, "
|
|
1309
|
+
return join4(configDir, "agent-smith.json");
|
|
1310
1310
|
}
|
|
1311
1311
|
var init_paths = __esm(() => {
|
|
1312
1312
|
init_paths_common();
|
|
@@ -1473,6 +1473,8 @@ function sanitizeClientRouting(value) {
|
|
|
1473
1473
|
if (!isRecord(value))
|
|
1474
1474
|
return;
|
|
1475
1475
|
const client = {};
|
|
1476
|
+
if (typeof value.enabled === "boolean")
|
|
1477
|
+
client.enabled = value.enabled;
|
|
1476
1478
|
if (typeof value.base_url === "string") {
|
|
1477
1479
|
try {
|
|
1478
1480
|
const url = new URL(value.base_url);
|
|
@@ -1688,7 +1690,7 @@ var init_src4 = __esm(() => {
|
|
|
1688
1690
|
this.emit("change", { key, oldValue, newValue: value });
|
|
1689
1691
|
}
|
|
1690
1692
|
getStrategy() {
|
|
1691
|
-
const envStrategy = process.env.
|
|
1693
|
+
const envStrategy = process.env.AGENT_SMITH_LB_STRATEGY;
|
|
1692
1694
|
if (envStrategy && isValidStrategy(envStrategy)) {
|
|
1693
1695
|
return envStrategy;
|
|
1694
1696
|
}
|
|
@@ -1708,7 +1710,7 @@ var init_src4 = __esm(() => {
|
|
|
1708
1710
|
return Math.max(min, Math.min(max, n));
|
|
1709
1711
|
}
|
|
1710
1712
|
getDataRetentionDays() {
|
|
1711
|
-
const fromEnv = process.env.
|
|
1713
|
+
const fromEnv = process.env.AGENT_SMITH_DATA_RETENTION_DAYS;
|
|
1712
1714
|
if (fromEnv) {
|
|
1713
1715
|
const n = parseInt(fromEnv, 10);
|
|
1714
1716
|
if (!Number.isNaN(n))
|
|
@@ -1724,7 +1726,7 @@ var init_src4 = __esm(() => {
|
|
|
1724
1726
|
this.set("data_retention_days", clamped);
|
|
1725
1727
|
}
|
|
1726
1728
|
getRequestRetentionDays() {
|
|
1727
|
-
const fromEnv = process.env.
|
|
1729
|
+
const fromEnv = process.env.AGENT_SMITH_REQUEST_RETENTION_DAYS;
|
|
1728
1730
|
if (fromEnv) {
|
|
1729
1731
|
const n = parseInt(fromEnv, 10);
|
|
1730
1732
|
if (!Number.isNaN(n))
|
|
@@ -1778,6 +1780,7 @@ var init_src4 = __esm(() => {
|
|
|
1778
1780
|
getClientRouting() {
|
|
1779
1781
|
const client = this.data.client;
|
|
1780
1782
|
return {
|
|
1783
|
+
enabled: client?.enabled === true,
|
|
1781
1784
|
...client?.base_url && { baseUrl: client.base_url },
|
|
1782
1785
|
...client?.proxy_key_file && {
|
|
1783
1786
|
proxyKeyFile: client.proxy_key_file
|
|
@@ -1908,34 +1911,34 @@ var init_src4 = __esm(() => {
|
|
|
1908
1911
|
port: NETWORK.DEFAULT_PORT,
|
|
1909
1912
|
teamRouting: this.getTeamRouting()
|
|
1910
1913
|
};
|
|
1911
|
-
if (process.env.
|
|
1912
|
-
defaults.clientId = process.env.
|
|
1914
|
+
if (process.env.AGENT_SMITH_CLIENT_ID) {
|
|
1915
|
+
defaults.clientId = process.env.AGENT_SMITH_CLIENT_ID;
|
|
1913
1916
|
}
|
|
1914
|
-
const retryAttempts = parseNumber(process.env.
|
|
1917
|
+
const retryAttempts = parseNumber(process.env.AGENT_SMITH_RETRY_ATTEMPTS);
|
|
1915
1918
|
if (retryAttempts !== undefined) {
|
|
1916
1919
|
defaults.retry.attempts = retryAttempts;
|
|
1917
1920
|
}
|
|
1918
|
-
const maxBodyBytes = parseNumber(process.env.
|
|
1921
|
+
const maxBodyBytes = parseNumber(process.env.AGENT_SMITH_MAX_BODY_BYTES);
|
|
1919
1922
|
if (maxBodyBytes !== undefined) {
|
|
1920
1923
|
defaults.maxBodyBytes = maxBodyBytes;
|
|
1921
1924
|
}
|
|
1922
|
-
const quotaThreshold = parseNumber(process.env.
|
|
1925
|
+
const quotaThreshold = parseNumber(process.env.AGENT_SMITH_QUOTA_THRESHOLD);
|
|
1923
1926
|
if (quotaThreshold !== undefined && quotaThreshold > 0 && quotaThreshold <= 1) {
|
|
1924
1927
|
defaults.quotaThreshold = quotaThreshold;
|
|
1925
1928
|
}
|
|
1926
|
-
const retryDelayMs = parseNumber(process.env.
|
|
1929
|
+
const retryDelayMs = parseNumber(process.env.AGENT_SMITH_RETRY_DELAY_MS);
|
|
1927
1930
|
if (retryDelayMs !== undefined) {
|
|
1928
1931
|
defaults.retry.delayMs = retryDelayMs;
|
|
1929
1932
|
}
|
|
1930
|
-
const retryBackoff = parseNumber(process.env.
|
|
1933
|
+
const retryBackoff = parseNumber(process.env.AGENT_SMITH_RETRY_BACKOFF);
|
|
1931
1934
|
if (retryBackoff !== undefined) {
|
|
1932
1935
|
defaults.retry.backoff = retryBackoff;
|
|
1933
1936
|
}
|
|
1934
|
-
const requestScopedRetryDelayMs = parseNumber(process.env.
|
|
1937
|
+
const requestScopedRetryDelayMs = parseNumber(process.env.AGENT_SMITH_REQUEST_SCOPED_429_RETRY_DELAY_MS);
|
|
1935
1938
|
if (requestScopedRetryDelayMs !== undefined) {
|
|
1936
1939
|
defaults.requestScopedRetryDelayMs = requestScopedRetryDelayMs;
|
|
1937
1940
|
}
|
|
1938
|
-
const sessionDurationMs = parseNumber(process.env.
|
|
1941
|
+
const sessionDurationMs = parseNumber(process.env.AGENT_SMITH_SESSION_DURATION_MS);
|
|
1939
1942
|
if (sessionDurationMs !== undefined) {
|
|
1940
1943
|
defaults.sessionDurationMs = sessionDurationMs;
|
|
1941
1944
|
}
|
|
@@ -1978,12 +1981,12 @@ var init_src4 = __esm(() => {
|
|
|
1978
1981
|
// ../../packages/database/src/paths.ts
|
|
1979
1982
|
import { join as join5 } from "path";
|
|
1980
1983
|
function resolveDbPath() {
|
|
1981
|
-
const explicitPath = process.env.
|
|
1984
|
+
const explicitPath = process.env.AGENT_SMITH_DB_PATH;
|
|
1982
1985
|
if (explicitPath) {
|
|
1983
1986
|
return explicitPath;
|
|
1984
1987
|
}
|
|
1985
1988
|
const configDir = getPlatformConfigDir();
|
|
1986
|
-
return join5(configDir, "
|
|
1989
|
+
return join5(configDir, "agent-smith.db");
|
|
1987
1990
|
}
|
|
1988
1991
|
var init_paths2 = __esm(() => {
|
|
1989
1992
|
init_src4();
|
|
@@ -4556,12 +4559,12 @@ var tokenEncoder = get_encoding("cl100k_base");
|
|
|
4556
4559
|
var streamDecoder = new TextDecoder("utf-8", { fatal: false });
|
|
4557
4560
|
var dbOps = new DatabaseOperations;
|
|
4558
4561
|
var asyncWriter = new AsyncDbWriter;
|
|
4559
|
-
var MAX_BUFFER_SIZE = Number(process.env.
|
|
4560
|
-
var TIMEOUT_MS = Number(process.env.
|
|
4561
|
-
var MAX_PAYLOAD_BYTES = Number(process.env.
|
|
4562
|
-
var MAX_TRACKED_REQUESTS = Number(process.env.
|
|
4563
|
-
var TOKEN_CURVE_SAMPLE_EVERY = Math.max(1, Number(process.env.
|
|
4564
|
-
var TOKEN_CURVE_MAX_SAMPLES = Math.max(1, Number(process.env.
|
|
4562
|
+
var MAX_BUFFER_SIZE = Number(process.env.AGENT_SMITH_STREAM_USAGE_BUFFER_KB || BUFFER_SIZES.STREAM_USAGE_BUFFER_KB) * 1024;
|
|
4563
|
+
var TIMEOUT_MS = Number(process.env.AGENT_SMITH_STREAM_TIMEOUT_MS || TIME_CONSTANTS.STREAM_TIMEOUT_DEFAULT);
|
|
4564
|
+
var MAX_PAYLOAD_BYTES = Number(process.env.AGENT_SMITH_MAX_PAYLOAD_BYTES || 0) || 2 * 1024 * 1024;
|
|
4565
|
+
var MAX_TRACKED_REQUESTS = Number(process.env.AGENT_SMITH_MAX_TRACKED_REQUESTS || 0) || 100;
|
|
4566
|
+
var TOKEN_CURVE_SAMPLE_EVERY = Math.max(1, Number(process.env.AGENT_SMITH_TOKEN_CURVE_SAMPLE_EVERY || 10) || 10);
|
|
4567
|
+
var TOKEN_CURVE_MAX_SAMPLES = Math.max(1, Number(process.env.AGENT_SMITH_TOKEN_CURVE_MAX_SAMPLES || 200) || 200);
|
|
4565
4568
|
var RESPONSES_TERMINAL_EVENTS = new Set([
|
|
4566
4569
|
"response.completed",
|
|
4567
4570
|
"response.failed",
|
package/dist/server.js
CHANGED
|
@@ -334,13 +334,13 @@ class PriceCatalogue {
|
|
|
334
334
|
return PriceCatalogue.instance;
|
|
335
335
|
}
|
|
336
336
|
getCacheDir() {
|
|
337
|
-
return join2(tmpdir(), "
|
|
337
|
+
return join2(tmpdir(), "agent-smith");
|
|
338
338
|
}
|
|
339
339
|
getCachePath() {
|
|
340
340
|
return join2(this.getCacheDir(), "models.dev.json");
|
|
341
341
|
}
|
|
342
342
|
getCacheDurationMs() {
|
|
343
|
-
const hours = Number(process.env.
|
|
343
|
+
const hours = Number(process.env.AGENT_SMITH_PRICING_REFRESH_HOURS) || 24;
|
|
344
344
|
return hours * TIME_CONSTANTS.HOUR;
|
|
345
345
|
}
|
|
346
346
|
async ensureCacheDir() {
|
|
@@ -1158,7 +1158,7 @@ class LogFileWriter {
|
|
|
1158
1158
|
stream = null;
|
|
1159
1159
|
maxFileSize = BUFFER_SIZES.LOG_FILE_MAX_SIZE;
|
|
1160
1160
|
constructor() {
|
|
1161
|
-
this.logDir = join3(tmpdir2(), "
|
|
1161
|
+
this.logDir = join3(tmpdir2(), "agent-smith-logs");
|
|
1162
1162
|
if (!existsSync(this.logDir)) {
|
|
1163
1163
|
mkdirSync(this.logDir, { recursive: true });
|
|
1164
1164
|
}
|
|
@@ -1244,11 +1244,11 @@ class Logger {
|
|
|
1244
1244
|
constructor(prefix = "", level = 1 /* INFO */, options = {}) {
|
|
1245
1245
|
this.prefix = prefix;
|
|
1246
1246
|
this.level = this.getLogLevelFromEnv() || level;
|
|
1247
|
-
this.format = process.env.
|
|
1248
|
-
this.silentConsole = options.silentConsole ?? !(process.env.
|
|
1247
|
+
this.format = process.env.AGENT_SMITH_LOG_FORMAT || "pretty";
|
|
1248
|
+
this.silentConsole = options.silentConsole ?? !(process.env.AGENT_SMITH_DEBUG === "1" || this.level === 0 /* DEBUG */);
|
|
1249
1249
|
}
|
|
1250
1250
|
getLogLevelFromEnv() {
|
|
1251
|
-
const envLevel = process.env.
|
|
1251
|
+
const envLevel = process.env.AGENT_SMITH_LOG_LEVEL?.toUpperCase();
|
|
1252
1252
|
if (envLevel && envLevel in LogLevel) {
|
|
1253
1253
|
return LogLevel[envLevel];
|
|
1254
1254
|
}
|
|
@@ -1325,7 +1325,7 @@ class Logger {
|
|
|
1325
1325
|
}
|
|
1326
1326
|
setLevel(level) {
|
|
1327
1327
|
this.level = level;
|
|
1328
|
-
this.silentConsole = !(process.env.
|
|
1328
|
+
this.silentConsole = !(process.env.AGENT_SMITH_DEBUG === "1" || this.level === 0 /* DEBUG */);
|
|
1329
1329
|
}
|
|
1330
1330
|
getLevel() {
|
|
1331
1331
|
return this.level;
|
|
@@ -1459,7 +1459,8 @@ var init_base = __esm(() => {
|
|
|
1459
1459
|
TRANSPORT_HEADERS_TO_DELETE = [
|
|
1460
1460
|
"host",
|
|
1461
1461
|
"accept-encoding",
|
|
1462
|
-
"content-encoding"
|
|
1462
|
+
"content-encoding",
|
|
1463
|
+
"transfer-encoding"
|
|
1463
1464
|
];
|
|
1464
1465
|
CLIENT_CREDENTIAL_HEADERS_TO_DELETE = [
|
|
1465
1466
|
"api-key",
|
|
@@ -3296,7 +3297,7 @@ function createAuthCallbackHandler(dbOps, config, providerRegistry) {
|
|
|
3296
3297
|
sessionId: authSession.id,
|
|
3297
3298
|
code
|
|
3298
3299
|
});
|
|
3299
|
-
return htmlPage(200, "Account connected", "Your OAuth account has been connected successfully. You can close this window and return to
|
|
3300
|
+
return htmlPage(200, "Account connected", "Your OAuth account has been connected successfully. You can close this window and return to agent-smith.");
|
|
3300
3301
|
} catch (error) {
|
|
3301
3302
|
dbOps.deleteAuthSession(authSession.id);
|
|
3302
3303
|
return htmlPage(400, "Authorization failed", escapeHtml(error instanceof Error ? error.message : "Failed to complete OAuth flow."));
|
|
@@ -3808,11 +3809,11 @@ import { platform } from "process";
|
|
|
3808
3809
|
function getPlatformConfigDir() {
|
|
3809
3810
|
if (platform === "win32") {
|
|
3810
3811
|
const baseDir = process.env.LOCALAPPDATA ?? process.env.APPDATA ?? join4(homedir(), "AppData", "Local");
|
|
3811
|
-
return join4(baseDir, "
|
|
3812
|
+
return join4(baseDir, "agent-smith");
|
|
3812
3813
|
} else {
|
|
3813
3814
|
const xdgConfig = process.env.XDG_CONFIG_HOME;
|
|
3814
3815
|
const baseDir = xdgConfig ?? join4(homedir(), ".config");
|
|
3815
|
-
return join4(baseDir, "
|
|
3816
|
+
return join4(baseDir, "agent-smith");
|
|
3816
3817
|
}
|
|
3817
3818
|
}
|
|
3818
3819
|
var init_paths_common = () => {};
|
|
@@ -3820,12 +3821,12 @@ var init_paths_common = () => {};
|
|
|
3820
3821
|
// ../../packages/config/src/paths.ts
|
|
3821
3822
|
import { join as join5 } from "path";
|
|
3822
3823
|
function resolveConfigPath() {
|
|
3823
|
-
const explicitPath = process.env.
|
|
3824
|
+
const explicitPath = process.env.AGENT_SMITH_CONFIG_PATH;
|
|
3824
3825
|
if (explicitPath) {
|
|
3825
3826
|
return explicitPath;
|
|
3826
3827
|
}
|
|
3827
3828
|
const configDir = getPlatformConfigDir();
|
|
3828
|
-
return join5(configDir, "
|
|
3829
|
+
return join5(configDir, "agent-smith.json");
|
|
3829
3830
|
}
|
|
3830
3831
|
var init_paths = __esm(() => {
|
|
3831
3832
|
init_paths_common();
|
|
@@ -3992,6 +3993,8 @@ function sanitizeClientRouting(value) {
|
|
|
3992
3993
|
if (!isRecord(value))
|
|
3993
3994
|
return;
|
|
3994
3995
|
const client2 = {};
|
|
3996
|
+
if (typeof value.enabled === "boolean")
|
|
3997
|
+
client2.enabled = value.enabled;
|
|
3995
3998
|
if (typeof value.base_url === "string") {
|
|
3996
3999
|
try {
|
|
3997
4000
|
const url = new URL(value.base_url);
|
|
@@ -4207,7 +4210,7 @@ var init_src7 = __esm(() => {
|
|
|
4207
4210
|
this.emit("change", { key, oldValue, newValue: value });
|
|
4208
4211
|
}
|
|
4209
4212
|
getStrategy() {
|
|
4210
|
-
const envStrategy = process.env.
|
|
4213
|
+
const envStrategy = process.env.AGENT_SMITH_LB_STRATEGY;
|
|
4211
4214
|
if (envStrategy && isValidStrategy(envStrategy)) {
|
|
4212
4215
|
return envStrategy;
|
|
4213
4216
|
}
|
|
@@ -4227,7 +4230,7 @@ var init_src7 = __esm(() => {
|
|
|
4227
4230
|
return Math.max(min, Math.min(max, n));
|
|
4228
4231
|
}
|
|
4229
4232
|
getDataRetentionDays() {
|
|
4230
|
-
const fromEnv = process.env.
|
|
4233
|
+
const fromEnv = process.env.AGENT_SMITH_DATA_RETENTION_DAYS;
|
|
4231
4234
|
if (fromEnv) {
|
|
4232
4235
|
const n = parseInt(fromEnv, 10);
|
|
4233
4236
|
if (!Number.isNaN(n))
|
|
@@ -4243,7 +4246,7 @@ var init_src7 = __esm(() => {
|
|
|
4243
4246
|
this.set("data_retention_days", clamped);
|
|
4244
4247
|
}
|
|
4245
4248
|
getRequestRetentionDays() {
|
|
4246
|
-
const fromEnv = process.env.
|
|
4249
|
+
const fromEnv = process.env.AGENT_SMITH_REQUEST_RETENTION_DAYS;
|
|
4247
4250
|
if (fromEnv) {
|
|
4248
4251
|
const n = parseInt(fromEnv, 10);
|
|
4249
4252
|
if (!Number.isNaN(n))
|
|
@@ -4297,6 +4300,7 @@ var init_src7 = __esm(() => {
|
|
|
4297
4300
|
getClientRouting() {
|
|
4298
4301
|
const client2 = this.data.client;
|
|
4299
4302
|
return {
|
|
4303
|
+
enabled: client2?.enabled === true,
|
|
4300
4304
|
...client2?.base_url && { baseUrl: client2.base_url },
|
|
4301
4305
|
...client2?.proxy_key_file && {
|
|
4302
4306
|
proxyKeyFile: client2.proxy_key_file
|
|
@@ -4427,34 +4431,34 @@ var init_src7 = __esm(() => {
|
|
|
4427
4431
|
port: NETWORK.DEFAULT_PORT,
|
|
4428
4432
|
teamRouting: this.getTeamRouting()
|
|
4429
4433
|
};
|
|
4430
|
-
if (process.env.
|
|
4431
|
-
defaults.clientId = process.env.
|
|
4434
|
+
if (process.env.AGENT_SMITH_CLIENT_ID) {
|
|
4435
|
+
defaults.clientId = process.env.AGENT_SMITH_CLIENT_ID;
|
|
4432
4436
|
}
|
|
4433
|
-
const retryAttempts = parseNumber(process.env.
|
|
4437
|
+
const retryAttempts = parseNumber(process.env.AGENT_SMITH_RETRY_ATTEMPTS);
|
|
4434
4438
|
if (retryAttempts !== undefined) {
|
|
4435
4439
|
defaults.retry.attempts = retryAttempts;
|
|
4436
4440
|
}
|
|
4437
|
-
const maxBodyBytes = parseNumber(process.env.
|
|
4441
|
+
const maxBodyBytes = parseNumber(process.env.AGENT_SMITH_MAX_BODY_BYTES);
|
|
4438
4442
|
if (maxBodyBytes !== undefined) {
|
|
4439
4443
|
defaults.maxBodyBytes = maxBodyBytes;
|
|
4440
4444
|
}
|
|
4441
|
-
const quotaThreshold = parseNumber(process.env.
|
|
4445
|
+
const quotaThreshold = parseNumber(process.env.AGENT_SMITH_QUOTA_THRESHOLD);
|
|
4442
4446
|
if (quotaThreshold !== undefined && quotaThreshold > 0 && quotaThreshold <= 1) {
|
|
4443
4447
|
defaults.quotaThreshold = quotaThreshold;
|
|
4444
4448
|
}
|
|
4445
|
-
const retryDelayMs = parseNumber(process.env.
|
|
4449
|
+
const retryDelayMs = parseNumber(process.env.AGENT_SMITH_RETRY_DELAY_MS);
|
|
4446
4450
|
if (retryDelayMs !== undefined) {
|
|
4447
4451
|
defaults.retry.delayMs = retryDelayMs;
|
|
4448
4452
|
}
|
|
4449
|
-
const retryBackoff = parseNumber(process.env.
|
|
4453
|
+
const retryBackoff = parseNumber(process.env.AGENT_SMITH_RETRY_BACKOFF);
|
|
4450
4454
|
if (retryBackoff !== undefined) {
|
|
4451
4455
|
defaults.retry.backoff = retryBackoff;
|
|
4452
4456
|
}
|
|
4453
|
-
const requestScopedRetryDelayMs = parseNumber(process.env.
|
|
4457
|
+
const requestScopedRetryDelayMs = parseNumber(process.env.AGENT_SMITH_REQUEST_SCOPED_429_RETRY_DELAY_MS);
|
|
4454
4458
|
if (requestScopedRetryDelayMs !== undefined) {
|
|
4455
4459
|
defaults.requestScopedRetryDelayMs = requestScopedRetryDelayMs;
|
|
4456
4460
|
}
|
|
4457
|
-
const sessionDurationMs = parseNumber(process.env.
|
|
4461
|
+
const sessionDurationMs = parseNumber(process.env.AGENT_SMITH_SESSION_DURATION_MS);
|
|
4458
4462
|
if (sessionDurationMs !== undefined) {
|
|
4459
4463
|
defaults.sessionDurationMs = sessionDurationMs;
|
|
4460
4464
|
}
|
|
@@ -4497,12 +4501,12 @@ var init_src7 = __esm(() => {
|
|
|
4497
4501
|
// ../../packages/database/src/paths.ts
|
|
4498
4502
|
import { join as join6 } from "path";
|
|
4499
4503
|
function resolveDbPath() {
|
|
4500
|
-
const explicitPath = process.env.
|
|
4504
|
+
const explicitPath = process.env.AGENT_SMITH_DB_PATH;
|
|
4501
4505
|
if (explicitPath) {
|
|
4502
4506
|
return explicitPath;
|
|
4503
4507
|
}
|
|
4504
4508
|
const configDir = getPlatformConfigDir();
|
|
4505
|
-
return join6(configDir, "
|
|
4509
|
+
return join6(configDir, "agent-smith.db");
|
|
4506
4510
|
}
|
|
4507
4511
|
var init_paths2 = __esm(() => {
|
|
4508
4512
|
init_src7();
|
|
@@ -8644,11 +8648,12 @@ async function prepareRequestBody(req, maxBodyBytes = DEFAULT_MAX_BODY_BYTES) {
|
|
|
8644
8648
|
}
|
|
8645
8649
|
};
|
|
8646
8650
|
}
|
|
8647
|
-
async function makeProxyRequest(targetUrl, method, headers3, createBodyStream, hasBody) {
|
|
8651
|
+
async function makeProxyRequest(targetUrl, method, headers3, createBodyStream, hasBody, signal) {
|
|
8648
8652
|
return fetch(targetUrl, {
|
|
8649
8653
|
method,
|
|
8650
8654
|
headers: headers3,
|
|
8651
8655
|
body: createBodyStream(),
|
|
8656
|
+
signal,
|
|
8652
8657
|
...hasBody ? { duplex: "half" } : {}
|
|
8653
8658
|
});
|
|
8654
8659
|
}
|
|
@@ -9672,7 +9677,7 @@ function createUpstreamSender(input) {
|
|
|
9672
9677
|
const requestAccount = token === input.account.access_token ? input.account : { ...input.account, access_token: token };
|
|
9673
9678
|
const headers3 = input.ctx.provider.prepareHeaders(input.req.headers, requestAccount);
|
|
9674
9679
|
const upstreamRequestStartedAt = Date.now();
|
|
9675
|
-
const response = await makeProxyRequest(targetUrl, input.req.method, headers3, () => input.createBodyStream(input.requestBody), !!input.req.body);
|
|
9680
|
+
const response = await makeProxyRequest(targetUrl, input.req.method, headers3, () => input.createBodyStream(input.requestBody), !!input.req.body, input.req.signal);
|
|
9676
9681
|
return {
|
|
9677
9682
|
response,
|
|
9678
9683
|
responseHeadersReceivedAt: Date.now(),
|
|
@@ -9796,6 +9801,7 @@ async function proxyWithAccount(req, url, account2, requestMeta, requestBodyBuff
|
|
|
9796
9801
|
const upstream = await sendAuthorizedRequest(input, createUpstreamSender(input));
|
|
9797
9802
|
return isProxyAttempt(upstream) ? upstream : await classifyUpstreamResponse(input, upstream);
|
|
9798
9803
|
} catch (err) {
|
|
9804
|
+
req.signal.throwIfAborted();
|
|
9799
9805
|
handleProxyError(err, account2, log20);
|
|
9800
9806
|
return err instanceof TokenRefreshError ? { kind: "failed" } : { kind: "transport-failure" };
|
|
9801
9807
|
}
|
|
@@ -9868,6 +9874,7 @@ function quotaExhaustionResponse(resetAt2) {
|
|
|
9868
9874
|
});
|
|
9869
9875
|
}
|
|
9870
9876
|
async function attemptAccount(request2, account2, failoverAttempts) {
|
|
9877
|
+
request2.req.signal.throwIfAborted();
|
|
9871
9878
|
const admission = request2.ctx.teamAdmission;
|
|
9872
9879
|
let permit;
|
|
9873
9880
|
try {
|
|
@@ -10423,7 +10430,7 @@ function createDefaultLogger() {
|
|
|
10423
10430
|
};
|
|
10424
10431
|
}
|
|
10425
10432
|
function resolveUsageWorkerEntrypoint() {
|
|
10426
|
-
const configuredPath = process.env.
|
|
10433
|
+
const configuredPath = process.env.AGENT_SMITH_USAGE_WORKER_PATH?.trim();
|
|
10427
10434
|
if (!configuredPath) {
|
|
10428
10435
|
return new URL("./post-processor.worker.ts", import.meta.url).href;
|
|
10429
10436
|
}
|
|
@@ -10761,8 +10768,8 @@ var DEFAULT_READY_TIMEOUT_MS, DEFAULT_ACK_TIMEOUT_MS, DEFAULT_SHUTDOWN_DELAY_MS
|
|
|
10761
10768
|
var init_usage_worker = __esm(() => {
|
|
10762
10769
|
init_src2();
|
|
10763
10770
|
init_src();
|
|
10764
|
-
DEFAULT_READY_TIMEOUT_MS = Number(process.env.
|
|
10765
|
-
DEFAULT_ACK_TIMEOUT_MS = Number(process.env.
|
|
10771
|
+
DEFAULT_READY_TIMEOUT_MS = Number(process.env.AGENT_SMITH_USAGE_WORKER_READY_TIMEOUT_MS || TIME_CONSTANTS.RETRY_DELAY_DEFAULT * 5);
|
|
10772
|
+
DEFAULT_ACK_TIMEOUT_MS = Number(process.env.AGENT_SMITH_USAGE_WORKER_ACK_TIMEOUT_MS || TIME_CONSTANTS.RETRY_DELAY_DEFAULT * 5);
|
|
10766
10773
|
});
|
|
10767
10774
|
|
|
10768
10775
|
// ../../packages/proxy/src/proxy.ts
|
|
@@ -11747,13 +11754,13 @@ function configuredKey(value) {
|
|
|
11747
11754
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
11748
11755
|
}
|
|
11749
11756
|
function createExposureConfig(config) {
|
|
11750
|
-
const configuredHost = configuredKey(process.env.
|
|
11751
|
-
const configuredTrustLoopback = process.env.
|
|
11757
|
+
const configuredHost = configuredKey(process.env.AGENT_SMITH_HOST) ?? configuredKey(config.get("host"));
|
|
11758
|
+
const configuredTrustLoopback = process.env.AGENT_SMITH_TRUST_LOOPBACK;
|
|
11752
11759
|
return {
|
|
11753
|
-
adminKey: configuredKey(process.env.
|
|
11760
|
+
adminKey: configuredKey(process.env.AGENT_SMITH_ADMIN_KEY),
|
|
11754
11761
|
bindHost: configuredHost ?? "127.0.0.1",
|
|
11755
|
-
proxyKey: configuredKey(process.env.
|
|
11756
|
-
clientKeysFile: configuredKey(process.env.
|
|
11762
|
+
proxyKey: configuredKey(process.env.AGENT_SMITH_PROXY_KEY),
|
|
11763
|
+
clientKeysFile: configuredKey(process.env.AGENT_SMITH_CLIENT_KEYS_FILE),
|
|
11757
11764
|
trustLoopback: configuredTrustLoopback === undefined ? config.get("trust_loopback") !== false : configuredTrustLoopback !== "false"
|
|
11758
11765
|
};
|
|
11759
11766
|
}
|
|
@@ -11921,7 +11928,7 @@ function bootstrapRuntime(port, serverLog) {
|
|
|
11921
11928
|
container.registerInstance(SERVICE_KEYS.PricingLogger, pricingLogger);
|
|
11922
11929
|
setPricingLogger(pricingLogger);
|
|
11923
11930
|
const apiRouter = new APIRouter({
|
|
11924
|
-
enrollmentOrigin: process.env.
|
|
11931
|
+
enrollmentOrigin: process.env.AGENT_SMITH_ENROLLMENT_ORIGIN,
|
|
11925
11932
|
config,
|
|
11926
11933
|
dbOps,
|
|
11927
11934
|
providerRegistry,
|
|
@@ -12076,7 +12083,7 @@ function serveDashboardRoute(url) {
|
|
|
12076
12083
|
}
|
|
12077
12084
|
return null;
|
|
12078
12085
|
}
|
|
12079
|
-
var DASHBOARD_MANIFEST_EXPORT = "@
|
|
12086
|
+
var DASHBOARD_MANIFEST_EXPORT = "@agent-smith/web/manifest.json", DASHBOARD_DIST_DIR_ENV = "AGENT_SMITH_DASHBOARD_DIST_DIR", DASHBOARD_MANIFEST_PATH_ENV = "AGENT_SMITH_DASHBOARD_MANIFEST_PATH", dashboardAssets = null;
|
|
12080
12087
|
var init_dashboard_assets = __esm(() => {
|
|
12081
12088
|
init_src2();
|
|
12082
12089
|
});
|
|
@@ -12101,7 +12108,7 @@ var init_oauth_token = __esm(() => {
|
|
|
12101
12108
|
"host",
|
|
12102
12109
|
"content-length",
|
|
12103
12110
|
"x-api-key",
|
|
12104
|
-
"x-
|
|
12111
|
+
"x-agent-smith-scenario-client-id"
|
|
12105
12112
|
];
|
|
12106
12113
|
});
|
|
12107
12114
|
|
|
@@ -12196,7 +12203,7 @@ function createStartupBanner(options) {
|
|
|
12196
12203
|
const dashboardUrl = withDashboard ? `http://localhost:${port}` : "disabled";
|
|
12197
12204
|
const supportedProviders = providers2.join(", ");
|
|
12198
12205
|
return `
|
|
12199
|
-
\uD83C\uDFAF
|
|
12206
|
+
\uD83C\uDFAF Agent Smith Server v${version}
|
|
12200
12207
|
\uD83C\uDF10 Port: ${port}
|
|
12201
12208
|
\uD83D\uDCCA Dashboard: ${dashboardUrl}
|
|
12202
12209
|
\uD83D\uDD17 Management API: http://localhost:${port}/api
|
|
@@ -12421,8 +12428,8 @@ var init_src11 = __esm(() => {
|
|
|
12421
12428
|
|
|
12422
12429
|
// src/bundled-assets.ts
|
|
12423
12430
|
import { join } from "path";
|
|
12424
|
-
process.env.
|
|
12425
|
-
process.env.
|
|
12431
|
+
process.env.AGENT_SMITH_DASHBOARD_DIST_DIR ??= join(import.meta.dir, "dashboard");
|
|
12432
|
+
process.env.AGENT_SMITH_USAGE_WORKER_PATH ??= join(import.meta.dir, "post-processor.worker.js");
|
|
12426
12433
|
|
|
12427
12434
|
// src/server.ts
|
|
12428
12435
|
init_src11();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@certalis/agent-smith",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "PROOF OF CONCEPT for ideation only: an experimental local proxy and provider pool for Claude Code and Codex",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Certalis",
|
|
@@ -37,15 +37,15 @@
|
|
|
37
37
|
"react": "^19.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
40
|
+
"@agent-smith/config": "workspace:*",
|
|
41
|
+
"@agent-smith/core": "workspace:*",
|
|
42
|
+
"@agent-smith/database": "workspace:*",
|
|
43
|
+
"@agent-smith/logger": "workspace:*",
|
|
44
|
+
"@agent-smith/oauth-flow": "workspace:*",
|
|
45
|
+
"@agent-smith/providers": "workspace:*",
|
|
46
|
+
"@agent-smith/runtime-server": "workspace:*",
|
|
47
|
+
"@agent-smith/types": "workspace:*",
|
|
48
|
+
"@agent-smith/ui": "workspace:*",
|
|
49
49
|
"@types/react": "^19.0.0",
|
|
50
50
|
"@types/node": "^20.0.0"
|
|
51
51
|
},
|