@antseed/cli 0.1.0 → 0.1.2
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/LICENSE +674 -0
- package/README.md +4 -2
- package/dist/cli/commands/dashboard.js +1 -1
- package/dist/cli/commands/dashboard.js.map +1 -1
- package/dist/cli/commands/seed.js +1 -1
- package/dist/cli/commands/seed.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/plugins/registry.js +4 -4
- package/dist/plugins/registry.js.map +1 -1
- package/dist/proxy/buyer-proxy.d.ts.map +1 -1
- package/dist/proxy/buyer-proxy.js +141 -27
- package/dist/proxy/buyer-proxy.js.map +1 -1
- package/package.json +19 -17
- package/.env.example +0 -15
- package/src/cli/commands/balance.ts +0 -77
- package/src/cli/commands/browse.ts +0 -113
- package/src/cli/commands/config.ts +0 -271
- package/src/cli/commands/connect.test.ts +0 -69
- package/src/cli/commands/connect.ts +0 -342
- package/src/cli/commands/dashboard.ts +0 -59
- package/src/cli/commands/deposit.ts +0 -61
- package/src/cli/commands/dev.ts +0 -107
- package/src/cli/commands/init.ts +0 -99
- package/src/cli/commands/plugin-create.test.ts +0 -60
- package/src/cli/commands/plugin-create.ts +0 -230
- package/src/cli/commands/plugin.test.ts +0 -55
- package/src/cli/commands/plugin.ts +0 -295
- package/src/cli/commands/profile.ts +0 -95
- package/src/cli/commands/seed.test.ts +0 -70
- package/src/cli/commands/seed.ts +0 -447
- package/src/cli/commands/status.ts +0 -73
- package/src/cli/commands/types.ts +0 -56
- package/src/cli/commands/withdraw.ts +0 -61
- package/src/cli/formatters.ts +0 -64
- package/src/cli/index.ts +0 -46
- package/src/cli/shutdown.ts +0 -38
- package/src/config/defaults.ts +0 -49
- package/src/config/effective.test.ts +0 -80
- package/src/config/effective.ts +0 -119
- package/src/config/loader.test.ts +0 -95
- package/src/config/loader.ts +0 -251
- package/src/config/types.ts +0 -139
- package/src/config/validation.ts +0 -78
- package/src/env/load-env.ts +0 -20
- package/src/plugins/loader.ts +0 -96
- package/src/plugins/manager.ts +0 -66
- package/src/plugins/registry.ts +0 -45
- package/src/proxy/buyer-proxy.ts +0 -604
- package/src/status/node-status.ts +0 -105
- package/tsconfig.json +0 -9
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import { getGlobalOptions } from './types.js';
|
|
5
|
-
import { loadConfig } from '../../config/loader.js';
|
|
6
|
-
import {
|
|
7
|
-
loadOrCreateIdentity,
|
|
8
|
-
BaseEscrowClient,
|
|
9
|
-
identityToEvmAddress,
|
|
10
|
-
} from '@antseed/node';
|
|
11
|
-
|
|
12
|
-
/** Format USDC base units (6 decimals) to human-readable string. */
|
|
13
|
-
function formatUsdc(baseUnits: bigint): string {
|
|
14
|
-
const whole = baseUnits / 1_000_000n;
|
|
15
|
-
const frac = baseUnits % 1_000_000n;
|
|
16
|
-
const fracStr = frac.toString().padStart(6, '0').replace(/0+$/, '') || '0';
|
|
17
|
-
return `${whole}.${fracStr}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function registerBalanceCommand(program: Command): void {
|
|
21
|
-
program
|
|
22
|
-
.command('balance')
|
|
23
|
-
.description('Show escrow balance for your wallet')
|
|
24
|
-
.option('--json', 'output as JSON', false)
|
|
25
|
-
.action(async (options) => {
|
|
26
|
-
const globalOpts = getGlobalOptions(program);
|
|
27
|
-
const config = await loadConfig(globalOpts.config);
|
|
28
|
-
|
|
29
|
-
const payments = config.payments;
|
|
30
|
-
if (!payments?.crypto) {
|
|
31
|
-
console.error(chalk.red('Error: No crypto payment configuration found.'));
|
|
32
|
-
console.error(chalk.dim('Configure payments.crypto in your config file or run: antseed init'));
|
|
33
|
-
process.exit(1);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const identity = await loadOrCreateIdentity(globalOpts.dataDir);
|
|
37
|
-
const address = identityToEvmAddress(identity);
|
|
38
|
-
|
|
39
|
-
const escrowClient = new BaseEscrowClient({
|
|
40
|
-
rpcUrl: payments.crypto.rpcUrl,
|
|
41
|
-
contractAddress: payments.crypto.escrowContractAddress,
|
|
42
|
-
usdcAddress: payments.crypto.usdcContractAddress,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const spinner = ora('Fetching balance...').start();
|
|
46
|
-
|
|
47
|
-
try {
|
|
48
|
-
const account = await escrowClient.getBuyerAccount(address);
|
|
49
|
-
const usdcBalance = await escrowClient.getUSDCBalance(address);
|
|
50
|
-
|
|
51
|
-
spinner.stop();
|
|
52
|
-
|
|
53
|
-
if (options.json) {
|
|
54
|
-
console.log(JSON.stringify({
|
|
55
|
-
address,
|
|
56
|
-
walletUSDC: formatUsdc(usdcBalance),
|
|
57
|
-
escrowDeposited: formatUsdc(account.deposited),
|
|
58
|
-
escrowCommitted: formatUsdc(account.committed),
|
|
59
|
-
escrowAvailable: formatUsdc(account.available),
|
|
60
|
-
}, null, 2));
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
console.log(chalk.bold('Wallet: ') + chalk.cyan(address));
|
|
65
|
-
console.log('');
|
|
66
|
-
console.log(chalk.bold('USDC Balance (wallet): ') + chalk.green(formatUsdc(usdcBalance) + ' USDC'));
|
|
67
|
-
console.log('');
|
|
68
|
-
console.log(chalk.bold('Escrow Account:'));
|
|
69
|
-
console.log(` Deposited: ${chalk.green(formatUsdc(account.deposited) + ' USDC')}`);
|
|
70
|
-
console.log(` Committed: ${chalk.yellow(formatUsdc(account.committed) + ' USDC')}`);
|
|
71
|
-
console.log(` Available: ${chalk.green(formatUsdc(account.available) + ' USDC')}`);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
spinner.fail(chalk.red(`Failed to fetch balance: ${(err as Error).message}`));
|
|
74
|
-
process.exit(1);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import ora from 'ora';
|
|
4
|
-
import Table from 'cli-table3';
|
|
5
|
-
import { getGlobalOptions } from './types.js';
|
|
6
|
-
import { loadConfig } from '../../config/loader.js';
|
|
7
|
-
import { AntseedNode } from '@antseed/node';
|
|
8
|
-
import { parseBootstrapList, toBootstrapConfig } from '@antseed/node/discovery';
|
|
9
|
-
|
|
10
|
-
function getReputationColor(reputation: number): (message: string) => string {
|
|
11
|
-
if (reputation >= 80) {
|
|
12
|
-
return chalk.green;
|
|
13
|
-
}
|
|
14
|
-
if (reputation >= 50) {
|
|
15
|
-
return chalk.yellow;
|
|
16
|
-
}
|
|
17
|
-
return chalk.red;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Register the `antseed browse` command on the Commander program.
|
|
22
|
-
* Discovers peers on the network and displays available models, prices, and reputation.
|
|
23
|
-
*/
|
|
24
|
-
export function registerBrowseCommand(program: Command): void {
|
|
25
|
-
program
|
|
26
|
-
.command('browse')
|
|
27
|
-
.description('Browse available models, prices, and reputation on the P2P network')
|
|
28
|
-
.option('-m, --model <model>', 'filter by model name')
|
|
29
|
-
.option('--json', 'output as JSON', false)
|
|
30
|
-
.action(async (options) => {
|
|
31
|
-
const globalOpts = getGlobalOptions(program);
|
|
32
|
-
const config = await loadConfig(globalOpts.config);
|
|
33
|
-
|
|
34
|
-
const bootstrapNodes = config.network.bootstrapNodes.length > 0
|
|
35
|
-
? toBootstrapConfig(parseBootstrapList(config.network.bootstrapNodes))
|
|
36
|
-
: undefined;
|
|
37
|
-
|
|
38
|
-
const spinner = ora('Discovering peers on the network...').start();
|
|
39
|
-
|
|
40
|
-
const node = new AntseedNode({
|
|
41
|
-
role: 'buyer',
|
|
42
|
-
bootstrapNodes,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
await node.start();
|
|
47
|
-
} catch (err) {
|
|
48
|
-
spinner.fail(chalk.red(`Failed to connect to network: ${(err as Error).message}`));
|
|
49
|
-
process.exit(1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
try {
|
|
53
|
-
const peers = await node.discoverPeers(options.model as string | undefined);
|
|
54
|
-
spinner.succeed(chalk.green(`Found ${peers.length} peer(s)`));
|
|
55
|
-
|
|
56
|
-
if (peers.length === 0) {
|
|
57
|
-
console.log(chalk.dim('No peers found. Try again later or check your bootstrap nodes.'));
|
|
58
|
-
await node.stop();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (options.json) {
|
|
63
|
-
console.log(JSON.stringify(peers, null, 2));
|
|
64
|
-
await node.stop();
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Display peers in a table
|
|
69
|
-
const table = new Table({
|
|
70
|
-
head: [
|
|
71
|
-
chalk.bold('Peer ID'),
|
|
72
|
-
chalk.bold('Providers'),
|
|
73
|
-
chalk.bold('Input $/1M'),
|
|
74
|
-
chalk.bold('Output $/1M'),
|
|
75
|
-
chalk.bold('Reputation'),
|
|
76
|
-
chalk.bold('Load'),
|
|
77
|
-
],
|
|
78
|
-
colWidths: [16, 18, 14, 14, 12, 10],
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
for (const peer of peers) {
|
|
82
|
-
const reputation = peer.reputationScore ?? 0;
|
|
83
|
-
const repLabel = `${reputation}%`;
|
|
84
|
-
const repColor = getReputationColor(reputation);
|
|
85
|
-
|
|
86
|
-
const load = peer.currentLoad !== undefined && peer.maxConcurrency !== undefined
|
|
87
|
-
? `${peer.currentLoad}/${peer.maxConcurrency}`
|
|
88
|
-
: chalk.dim('n/a');
|
|
89
|
-
|
|
90
|
-
table.push([
|
|
91
|
-
chalk.dim(peer.peerId.slice(0, 12) + '...'),
|
|
92
|
-
peer.providers.join(', '),
|
|
93
|
-
peer.defaultInputUsdPerMillion !== undefined
|
|
94
|
-
? `$${peer.defaultInputUsdPerMillion.toFixed(2)}`
|
|
95
|
-
: chalk.dim('n/a'),
|
|
96
|
-
peer.defaultOutputUsdPerMillion !== undefined
|
|
97
|
-
? `$${peer.defaultOutputUsdPerMillion.toFixed(2)}`
|
|
98
|
-
: chalk.dim('n/a'),
|
|
99
|
-
repColor(repLabel),
|
|
100
|
-
load,
|
|
101
|
-
]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
console.log('');
|
|
105
|
-
console.log(table.toString());
|
|
106
|
-
console.log('');
|
|
107
|
-
} catch (err) {
|
|
108
|
-
spinner.fail(chalk.red(`Discovery failed: ${(err as Error).message}`));
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
await node.stop();
|
|
112
|
-
});
|
|
113
|
-
}
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import { getGlobalOptions } from './types.js';
|
|
4
|
-
import { loadConfig, saveConfig } from '../../config/loader.js';
|
|
5
|
-
import type { AntseedConfig, ProviderConfig, ProviderType } from '../../config/types.js';
|
|
6
|
-
import { assertValidConfig } from '../../config/validation.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Register the `antseed config` command and its subcommands.
|
|
10
|
-
*/
|
|
11
|
-
export function registerConfigCommand(program: Command): void {
|
|
12
|
-
const configCmd = program
|
|
13
|
-
.command('config')
|
|
14
|
-
.description('Manage Antseed configuration');
|
|
15
|
-
|
|
16
|
-
// antseed config show
|
|
17
|
-
configCmd
|
|
18
|
-
.command('show')
|
|
19
|
-
.description('Display current configuration (credentials redacted)')
|
|
20
|
-
.action(async () => {
|
|
21
|
-
const globalOpts = getGlobalOptions(program);
|
|
22
|
-
const config = await loadConfig(globalOpts.config);
|
|
23
|
-
const redacted = redactConfig(config);
|
|
24
|
-
console.log(JSON.stringify(redacted, null, 2));
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// antseed config set <key> <value>
|
|
28
|
-
configCmd
|
|
29
|
-
.command('set <key> <value>')
|
|
30
|
-
.description('Set a configuration value (e.g., seller.reserveFloor 20)')
|
|
31
|
-
.action(async (key: string, value: string) => {
|
|
32
|
-
try {
|
|
33
|
-
const globalOpts = getGlobalOptions(program);
|
|
34
|
-
const config = await loadConfig(globalOpts.config);
|
|
35
|
-
const validKeys = getValidConfigKeys(config);
|
|
36
|
-
if (!validKeys.includes(key)) {
|
|
37
|
-
console.error(chalk.red(`Invalid config key: ${key}`));
|
|
38
|
-
console.error(chalk.dim(`Available keys: ${validKeys.join(', ')}`));
|
|
39
|
-
process.exitCode = 1;
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
setConfigValue(config as unknown as Record<string, unknown>, key, value);
|
|
43
|
-
assertValidConfig(config);
|
|
44
|
-
await saveConfig(globalOpts.config, config);
|
|
45
|
-
console.log(chalk.green(`Set ${key} = ${value}`));
|
|
46
|
-
} catch (err) {
|
|
47
|
-
console.error(chalk.red(`Error: ${(err as Error).message}`));
|
|
48
|
-
process.exitCode = 1;
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const sellerCmd = configCmd
|
|
53
|
-
.command('seller')
|
|
54
|
-
.description('Role-scoped seller configuration commands');
|
|
55
|
-
|
|
56
|
-
sellerCmd
|
|
57
|
-
.command('show')
|
|
58
|
-
.description('Display seller configuration')
|
|
59
|
-
.action(async () => {
|
|
60
|
-
const globalOpts = getGlobalOptions(program);
|
|
61
|
-
const config = await loadConfig(globalOpts.config);
|
|
62
|
-
console.log(JSON.stringify(config.seller, null, 2));
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
sellerCmd
|
|
66
|
-
.command('set <key> <value>')
|
|
67
|
-
.description('Set seller configuration value (e.g., pricing.defaults.inputUsdPerMillion 12)')
|
|
68
|
-
.action(async (key: string, value: string) => {
|
|
69
|
-
await setRoleScopedValue(program, 'seller', key, value);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
const buyerCmd = configCmd
|
|
73
|
-
.command('buyer')
|
|
74
|
-
.description('Role-scoped buyer configuration commands');
|
|
75
|
-
|
|
76
|
-
buyerCmd
|
|
77
|
-
.command('show')
|
|
78
|
-
.description('Display buyer configuration')
|
|
79
|
-
.action(async () => {
|
|
80
|
-
const globalOpts = getGlobalOptions(program);
|
|
81
|
-
const config = await loadConfig(globalOpts.config);
|
|
82
|
-
console.log(JSON.stringify(config.buyer, null, 2));
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
buyerCmd
|
|
86
|
-
.command('set <key> <value>')
|
|
87
|
-
.description('Set buyer configuration value (e.g., preferredProviders [\"anthropic\",\"openai\"])')
|
|
88
|
-
.action(async (key: string, value: string) => {
|
|
89
|
-
await setRoleScopedValue(program, 'buyer', key, value);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// antseed config add-provider
|
|
93
|
-
configCmd
|
|
94
|
-
.command('add-provider')
|
|
95
|
-
.description('Add a new provider credential')
|
|
96
|
-
.requiredOption('-t, --type <type>', 'provider type (anthropic, openai, google, moonshot)')
|
|
97
|
-
.requiredOption('-k, --key <key>', 'API key or auth token')
|
|
98
|
-
.option('-e, --endpoint <url>', 'custom API endpoint URL')
|
|
99
|
-
.action(async (options) => {
|
|
100
|
-
const knownTypes = ['anthropic', 'openai', 'google', 'moonshot'];
|
|
101
|
-
if (!knownTypes.includes(options.type as string)) {
|
|
102
|
-
console.error(chalk.red(`Unknown provider type: ${options.type as string}`));
|
|
103
|
-
console.error(chalk.dim(`Known types: ${knownTypes.join(', ')}`));
|
|
104
|
-
process.exitCode = 1;
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const globalOpts = getGlobalOptions(program);
|
|
108
|
-
const config = await loadConfig(globalOpts.config);
|
|
109
|
-
const provider = buildProviderConfig(
|
|
110
|
-
options.type as ProviderType,
|
|
111
|
-
options.key as string,
|
|
112
|
-
options.endpoint as string | undefined
|
|
113
|
-
);
|
|
114
|
-
config.providers.push(provider);
|
|
115
|
-
await saveConfig(globalOpts.config, config);
|
|
116
|
-
console.log(chalk.green(`Added ${options.type as string} provider`));
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
// antseed config remove-provider <type>
|
|
120
|
-
configCmd
|
|
121
|
-
.command('remove-provider <type>')
|
|
122
|
-
.description('Remove a provider credential by type')
|
|
123
|
-
.action(async (type: string) => {
|
|
124
|
-
const globalOpts = getGlobalOptions(program);
|
|
125
|
-
const config = await loadConfig(globalOpts.config);
|
|
126
|
-
const before = config.providers.length;
|
|
127
|
-
config.providers = config.providers.filter((p) => p.type !== type);
|
|
128
|
-
const removed = before - config.providers.length;
|
|
129
|
-
await saveConfig(globalOpts.config, config);
|
|
130
|
-
if (removed > 0) {
|
|
131
|
-
console.log(chalk.green(`Removed ${removed} ${type} provider(s)`));
|
|
132
|
-
} else {
|
|
133
|
-
console.log(chalk.yellow(`No ${type} provider found`));
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// antseed config init
|
|
138
|
-
configCmd
|
|
139
|
-
.command('init')
|
|
140
|
-
.description('Initialize a new config file with defaults')
|
|
141
|
-
.action(async () => {
|
|
142
|
-
const globalOpts = getGlobalOptions(program);
|
|
143
|
-
const { createDefaultConfig } = await import('../../config/defaults.js');
|
|
144
|
-
const config = createDefaultConfig();
|
|
145
|
-
await saveConfig(globalOpts.config, config);
|
|
146
|
-
console.log(chalk.green(`Config initialized at ${globalOpts.config}`));
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Redact sensitive fields (auth values) from config for display.
|
|
152
|
-
*/
|
|
153
|
-
export function redactConfig(config: AntseedConfig): Record<string, unknown> {
|
|
154
|
-
const clone = JSON.parse(JSON.stringify(config)) as Record<string, unknown>;
|
|
155
|
-
const providers = clone['providers'] as Array<Record<string, unknown>> | undefined;
|
|
156
|
-
for (const provider of providers ?? []) {
|
|
157
|
-
if (provider['authValue']) {
|
|
158
|
-
const val = provider['authValue'] as string;
|
|
159
|
-
provider['authValue'] = val.slice(0, 8) + '...' + val.slice(-4);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return clone;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Set a nested config value by dot-separated key path.
|
|
168
|
-
* @example setConfigValue(config, 'seller.reserveFloor', '20')
|
|
169
|
-
*/
|
|
170
|
-
export function setConfigValue(config: Record<string, unknown>, key: string, value: string): void {
|
|
171
|
-
const parts = key.split('.');
|
|
172
|
-
let current: Record<string, unknown> = config;
|
|
173
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
174
|
-
const part = parts[i]!;
|
|
175
|
-
if (typeof current[part] !== 'object' || current[part] === null) {
|
|
176
|
-
throw new Error(`Invalid config key: ${key}`);
|
|
177
|
-
}
|
|
178
|
-
current = current[part] as Record<string, unknown>;
|
|
179
|
-
}
|
|
180
|
-
const lastKey = parts[parts.length - 1]!;
|
|
181
|
-
const trimmed = value.trim();
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
(trimmed.startsWith('{') && trimmed.endsWith('}')) ||
|
|
185
|
-
(trimmed.startsWith('[') && trimmed.endsWith(']'))
|
|
186
|
-
) {
|
|
187
|
-
try {
|
|
188
|
-
current[lastKey] = JSON.parse(trimmed) as unknown;
|
|
189
|
-
return;
|
|
190
|
-
} catch {
|
|
191
|
-
throw new Error(`Invalid JSON value for ${key}`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Auto-parse numeric scalars
|
|
196
|
-
const numVal = Number(trimmed);
|
|
197
|
-
current[lastKey] = Number.isNaN(numVal) ? value : numVal;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function getValidConfigKeys(config: AntseedConfig, prefix = ''): string[] {
|
|
201
|
-
const keys: string[] = [];
|
|
202
|
-
for (const [k, v] of Object.entries(config)) {
|
|
203
|
-
if (k === 'providers' || k === 'plugins') continue;
|
|
204
|
-
const path = prefix ? `${prefix}.${k}` : k;
|
|
205
|
-
if (v && typeof v === 'object' && !Array.isArray(v)) {
|
|
206
|
-
keys.push(...getValidConfigKeys(v as unknown as AntseedConfig, path));
|
|
207
|
-
} else {
|
|
208
|
-
keys.push(path);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return keys;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async function setRoleScopedValue(
|
|
215
|
-
program: Command,
|
|
216
|
-
role: 'seller' | 'buyer',
|
|
217
|
-
key: string,
|
|
218
|
-
value: string,
|
|
219
|
-
): Promise<void> {
|
|
220
|
-
try {
|
|
221
|
-
const globalOpts = getGlobalOptions(program);
|
|
222
|
-
const config = await loadConfig(globalOpts.config);
|
|
223
|
-
const fullKey = `${role}.${key}`;
|
|
224
|
-
const validKeys = getValidConfigKeys(config);
|
|
225
|
-
if (!validKeys.includes(fullKey)) {
|
|
226
|
-
console.error(chalk.red(`Invalid ${role} config key: ${key}`));
|
|
227
|
-
const scopedKeys = validKeys
|
|
228
|
-
.filter((path) => path.startsWith(`${role}.`))
|
|
229
|
-
.map((path) => path.slice(role.length + 1));
|
|
230
|
-
console.error(chalk.dim(`Available ${role} keys: ${scopedKeys.join(', ')}`));
|
|
231
|
-
process.exitCode = 1;
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
setConfigValue(config as unknown as Record<string, unknown>, fullKey, value);
|
|
235
|
-
assertValidConfig(config);
|
|
236
|
-
await saveConfig(globalOpts.config, config);
|
|
237
|
-
console.log(chalk.green(`Set ${fullKey} = ${value}`));
|
|
238
|
-
} catch (err) {
|
|
239
|
-
console.error(chalk.red(`Error: ${(err as Error).message}`));
|
|
240
|
-
process.exitCode = 1;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Build a ProviderConfig with default endpoint and auth header for known providers.
|
|
246
|
-
*/
|
|
247
|
-
export function buildProviderConfig(
|
|
248
|
-
type: ProviderType,
|
|
249
|
-
authValue: string,
|
|
250
|
-
customEndpoint?: string
|
|
251
|
-
): ProviderConfig {
|
|
252
|
-
const defaults: Record<string, { endpoint: string; authHeaderName: string }> = {
|
|
253
|
-
anthropic: { endpoint: 'https://api.anthropic.com', authHeaderName: 'x-api-key' },
|
|
254
|
-
openai: { endpoint: 'https://api.openai.com', authHeaderName: 'Authorization' },
|
|
255
|
-
google: { endpoint: 'https://generativelanguage.googleapis.com', authHeaderName: 'x-goog-api-key' },
|
|
256
|
-
moonshot: { endpoint: 'https://api.moonshot.cn', authHeaderName: 'Authorization' },
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
const fallbackDefaults = {
|
|
260
|
-
endpoint: customEndpoint ?? '',
|
|
261
|
-
authHeaderName: 'Authorization',
|
|
262
|
-
};
|
|
263
|
-
const def = defaults[type] ?? fallbackDefaults;
|
|
264
|
-
|
|
265
|
-
return {
|
|
266
|
-
type,
|
|
267
|
-
endpoint: customEndpoint ?? def.endpoint,
|
|
268
|
-
authHeaderName: def.authHeaderName,
|
|
269
|
-
authValue,
|
|
270
|
-
};
|
|
271
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
import { createDefaultConfig } from '../../config/defaults.js';
|
|
4
|
-
import { resolveEffectiveBuyerConfig } from '../../config/effective.js';
|
|
5
|
-
import {
|
|
6
|
-
buildBuyerRuntimeOverridesFromFlags,
|
|
7
|
-
buildBuyerBootstrapEntries,
|
|
8
|
-
buildRouterRuntimeEnvFromBuyerConfig,
|
|
9
|
-
} from './connect.js';
|
|
10
|
-
|
|
11
|
-
test('connect runtime overrides are runtime-only and win over env/config', () => {
|
|
12
|
-
const config = createDefaultConfig();
|
|
13
|
-
config.buyer.proxyPort = 7777;
|
|
14
|
-
config.buyer.maxPricing.defaults.inputUsdPerMillion = 50;
|
|
15
|
-
config.buyer.maxPricing.defaults.outputUsdPerMillion = 60;
|
|
16
|
-
const beforeResolution = JSON.parse(JSON.stringify(config));
|
|
17
|
-
|
|
18
|
-
const env = {
|
|
19
|
-
ANTSEED_BUYER_MAX_INPUT_USD_PER_MILLION: '70',
|
|
20
|
-
ANTSEED_BUYER_MAX_OUTPUT_USD_PER_MILLION: '80',
|
|
21
|
-
} as NodeJS.ProcessEnv;
|
|
22
|
-
|
|
23
|
-
const overrides = buildBuyerRuntimeOverridesFromFlags({
|
|
24
|
-
port: 9000,
|
|
25
|
-
maxInputUsdPerMillion: 90,
|
|
26
|
-
maxOutputUsdPerMillion: 95,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const effective = resolveEffectiveBuyerConfig({
|
|
30
|
-
config,
|
|
31
|
-
env,
|
|
32
|
-
buyerOverrides: overrides,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
assert.equal(effective.proxyPort, 9000);
|
|
36
|
-
assert.equal(effective.maxPricing.defaults.inputUsdPerMillion, 90);
|
|
37
|
-
assert.equal(effective.maxPricing.defaults.outputUsdPerMillion, 95);
|
|
38
|
-
assert.deepEqual(config, beforeResolution);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('connect maps effective buyer config into router runtime env keys', () => {
|
|
42
|
-
const config = createDefaultConfig();
|
|
43
|
-
config.buyer.minPeerReputation = 72;
|
|
44
|
-
config.buyer.preferredProviders = ['anthropic', 'openai'];
|
|
45
|
-
config.buyer.maxPricing.defaults.inputUsdPerMillion = 21;
|
|
46
|
-
config.buyer.maxPricing.defaults.outputUsdPerMillion = 63;
|
|
47
|
-
|
|
48
|
-
const runtimeEnv = buildRouterRuntimeEnvFromBuyerConfig(config.buyer);
|
|
49
|
-
assert.equal(runtimeEnv['ANTSEED_MIN_REPUTATION'], '72');
|
|
50
|
-
assert.equal(runtimeEnv['ANTSEED_PREFERRED_PROVIDERS'], 'anthropic,openai');
|
|
51
|
-
|
|
52
|
-
const parsed = JSON.parse(runtimeEnv['ANTSEED_MAX_PRICING_JSON'] ?? '{}') as {
|
|
53
|
-
defaults?: { inputUsdPerMillion?: number; outputUsdPerMillion?: number };
|
|
54
|
-
};
|
|
55
|
-
assert.equal(parsed.defaults?.inputUsdPerMillion, 21);
|
|
56
|
-
assert.equal(parsed.defaults?.outputUsdPerMillion, 63);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('connect bootstrap entries use official nodes when config is empty and include local seeder first', () => {
|
|
60
|
-
const entries = buildBuyerBootstrapEntries([], 6881);
|
|
61
|
-
assert.equal(entries[0], '127.0.0.1:6881');
|
|
62
|
-
assert.ok(entries.length > 1);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test('connect bootstrap entries respect explicit configured nodes', () => {
|
|
66
|
-
const entries = buildBuyerBootstrapEntries(['10.0.0.2:6881'], 6889);
|
|
67
|
-
assert.equal(entries[0], '127.0.0.1:6889');
|
|
68
|
-
assert.deepEqual(entries.slice(1), ['10.0.0.2:6881']);
|
|
69
|
-
});
|