-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathconfig.js
More file actions
76 lines (67 loc) · 2.9 KB
/
Copy pathconfig.js
File metadata and controls
76 lines (67 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import dotenv from 'dotenv'
import { fileURLToPath } from 'node:url'
import path from 'node:path'
dotenv.config({
path: fileURLToPath(new URL('../.env', import.meta.url)),
quiet: true,
})
const port = process.env.PORT || 3001
const internalBaseUrl = (process.env.INTERNAL_BASE_URL || `http://localhost:${port}`).replace(
/\/+$/,
''
)
const toNumberOr = (value, fallback) => {
const n = Number.parseInt(value, 10)
return Number.isFinite(n) ? n : fallback
}
const repoRoot = fileURLToPath(new URL('..', import.meta.url))
export const config = {
port,
internalBaseUrl,
network: process.env.NETWORK || 'stellar:testnet',
facilitatorUrl: process.env.FACILITATOR_URL || 'https://www.x402.org/facilitator',
stellarRpcUrl: process.env.STELLAR_RPC_URL || 'https://soroban-testnet.stellar.org',
adminToken: process.env.ADMIN_TOKEN || '',
// Server wallet (receives payments)
serverAddress: process.env.SERVER_STELLAR_ADDRESS || '',
serverSecret: process.env.SERVER_STELLAR_SECRET || '',
// Orchestrator wallet (pays for sub-agent calls)
orchestratorAddress: process.env.ORCHESTRATOR_STELLAR_ADDRESS || '',
orchestratorSecret: process.env.ORCHESTRATOR_STELLAR_SECRET || '',
// Buyer wallet (demo user wallet)
buyerAddress: process.env.BUYER_STELLAR_ADDRESS || '',
buyerSecret: process.env.BUYER_STELLAR_SECRET || '',
// Anthropic
anthropicApiKey: process.env.ANTHROPIC_API_KEY || '',
anthropicRequestTimeoutMs: Math.max(
1000,
toNumberOr(process.env.ANTHROPIC_REQUEST_TIMEOUT_MS, 20000)
),
anthropicMaxRetries: Math.max(0, toNumberOr(process.env.ANTHROPIC_MAX_RETRIES, 2)),
anthropicRetryBaseDelayMs: Math.max(
100,
toNumberOr(process.env.ANTHROPIC_RETRY_BASE_DELAY_MS, 500)
),
logFormat: (process.env.LOG_FORMAT || 'json').toLowerCase() === 'pretty' ? 'pretty' : 'json',
// Rate limiting (defaults are intentionally permissive for demos)
rateLimit: {
// Default window in seconds and max requests per window
defaultWindowSec: Math.max(1, toNumberOr(process.env.RATE_LIMIT_DEFAULT_WINDOW_SEC, 60)),
defaultMax: Math.max(1, toNumberOr(process.env.RATE_LIMIT_DEFAULT_MAX, 60)),
// Stricter limits for /api/orchestrate
orchestrateWindowSec: Math.max(
1,
toNumberOr(process.env.RATE_LIMIT_ORCHESTRATE_WINDOW_SEC, 60)
),
orchestrateMax: Math.max(1, toNumberOr(process.env.RATE_LIMIT_ORCHESTRATE_MAX, 10)),
// Stricter limits for /api/config/apikey
apikeyWindowSec: Math.max(1, toNumberOr(process.env.RATE_LIMIT_APIKEY_WINDOW_SEC, 60)),
apikeyMax: Math.max(1, toNumberOr(process.env.RATE_LIMIT_APIKEY_MAX, 5)),
},
// Run history persistence
runHistoryStorage: process.env.RUN_HISTORY_STORAGE || 'file',
runHistoryFile: process.env.RUN_HISTORY_FILE
? path.resolve(process.env.RUN_HISTORY_FILE)
: path.join(repoRoot, 'data', 'run-history.json'),
runHistoryMaxRuns: Math.max(10, toNumberOr(process.env.RUN_HISTORY_MAX_RUNS, 200)),
}