archondev 0.1.0 → 1.2.0
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 +84 -51
- package/dist/auth-2QIFQZTL.js +12 -0
- package/dist/bug-DXLBBW3U.js +10 -0
- package/dist/{chunk-R6IMTNKV.js → chunk-2CFO5GVH.js} +0 -35
- package/dist/chunk-A7QU6JC6.js +119 -0
- package/dist/chunk-CAYCSBNX.js +202 -0
- package/dist/chunk-EDP55FCI.js +485 -0
- package/dist/chunk-I4ZVNLNO.js +4648 -0
- package/dist/chunk-IMZN36GC.js +159 -0
- package/dist/chunk-JBKFAD4M.js +650 -0
- package/dist/chunk-MOZHC2GX.js +351 -0
- package/dist/chunk-PK3OQVBG.js +91 -0
- package/dist/chunk-QGM4M3NI.js +37 -0
- package/dist/chunk-SMR7JQK6.js +399 -0
- package/dist/chunk-UDBFDXJI.js +696 -0
- package/dist/chunk-UG2ZZ7CM.js +737 -0
- package/dist/chunk-VKM3HAHW.js +832 -0
- package/dist/chunk-WCCBJSNI.js +62 -0
- package/dist/code-review-FSTYDHNG.js +16 -0
- package/dist/execute-LYID2ODD.js +13 -0
- package/dist/index.js +1250 -7206
- package/dist/keys-EL3FUM5O.js +15 -0
- package/dist/list-VXMVEIL5.js +13 -0
- package/dist/{parser-D6PBQUJH.js → parser-M4DI7A24.js} +2 -1
- package/dist/plan-7VSFESVD.js +16 -0
- package/dist/preferences-PL2ON5VY.js +17 -0
- package/dist/review-3R6QXAXQ.js +27 -0
- package/package.json +21 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KeyValidator,
|
|
3
|
+
keyManager
|
|
4
|
+
} from "./chunk-SMR7JQK6.js";
|
|
5
|
+
import {
|
|
6
|
+
loadConfig,
|
|
7
|
+
saveConfig
|
|
8
|
+
} from "./chunk-WCCBJSNI.js";
|
|
9
|
+
|
|
10
|
+
// src/cli/keys.ts
|
|
11
|
+
import chalk from "chalk";
|
|
12
|
+
import ora from "ora";
|
|
13
|
+
import { createInterface } from "readline";
|
|
14
|
+
var VALID_PROVIDERS = ["anthropic", "openai", "google"];
|
|
15
|
+
function isValidProvider(provider) {
|
|
16
|
+
return VALID_PROVIDERS.includes(provider);
|
|
17
|
+
}
|
|
18
|
+
async function promptForKey(provider) {
|
|
19
|
+
const rl = createInterface({
|
|
20
|
+
input: process.stdin,
|
|
21
|
+
output: process.stdout
|
|
22
|
+
});
|
|
23
|
+
return new Promise((resolve) => {
|
|
24
|
+
const providerName = provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
25
|
+
rl.question(`Enter your ${providerName} API key: `, (answer) => {
|
|
26
|
+
rl.close();
|
|
27
|
+
resolve(answer.trim());
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function addKey(provider, options = {}) {
|
|
32
|
+
if (!isValidProvider(provider)) {
|
|
33
|
+
console.error(chalk.red(`Invalid provider: ${provider}`));
|
|
34
|
+
console.log(chalk.dim(`Valid providers: ${VALID_PROVIDERS.join(", ")}`));
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
const label = options.label ?? "default";
|
|
38
|
+
const apiKey = await promptForKey(provider);
|
|
39
|
+
if (!apiKey) {
|
|
40
|
+
console.error(chalk.red("API key cannot be empty"));
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
const spinner = ora("Validating API key...").start();
|
|
44
|
+
const validator = new KeyValidator();
|
|
45
|
+
const validationResult = await validator.validateKey(provider, apiKey);
|
|
46
|
+
if (!validationResult.valid) {
|
|
47
|
+
spinner.fail(chalk.red(`API key validation failed: ${validationResult.error}`));
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
spinner.text = "Encrypting and storing API key...";
|
|
51
|
+
const result = await keyManager.addKey(provider, apiKey, label);
|
|
52
|
+
if (!result.success) {
|
|
53
|
+
spinner.fail(chalk.red(`Failed to store key: ${result.error}`));
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const config = await loadConfig();
|
|
57
|
+
if (config.tier === "FREE") {
|
|
58
|
+
await saveConfig({ ...config, tier: "BYOK" });
|
|
59
|
+
spinner.succeed(chalk.green(`API key for ${provider} (${label}) added successfully!`));
|
|
60
|
+
console.log(chalk.blue("Your tier has been upgraded to BYOK (Bring Your Own Key)"));
|
|
61
|
+
console.log(chalk.dim("You now have access to all models and unlimited atoms."));
|
|
62
|
+
} else {
|
|
63
|
+
spinner.succeed(chalk.green(`API key for ${provider} (${label}) added successfully!`));
|
|
64
|
+
}
|
|
65
|
+
const adversarialStatus = await keyManager.getAdversarialStatus();
|
|
66
|
+
if (adversarialStatus.enabled) {
|
|
67
|
+
console.log(chalk.green(`\u2713 ${adversarialStatus.message}`));
|
|
68
|
+
} else {
|
|
69
|
+
console.log(chalk.yellow(`\u25CB ${adversarialStatus.message}`));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
async function listKeys() {
|
|
73
|
+
const spinner = ora("Loading configured keys...").start();
|
|
74
|
+
const keys = await keyManager.listKeys();
|
|
75
|
+
spinner.stop();
|
|
76
|
+
if (keys.length === 0) {
|
|
77
|
+
console.log(chalk.yellow("No API keys configured"));
|
|
78
|
+
console.log(chalk.dim("Run `archon keys add <provider>` to add a key"));
|
|
79
|
+
console.log(chalk.dim(`Available providers: ${VALID_PROVIDERS.join(", ")}`));
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
console.log(chalk.green("Configured API keys:"));
|
|
83
|
+
console.log();
|
|
84
|
+
const byProvider = {};
|
|
85
|
+
for (const key of keys) {
|
|
86
|
+
if (!byProvider[key.provider]) {
|
|
87
|
+
byProvider[key.provider] = [];
|
|
88
|
+
}
|
|
89
|
+
byProvider[key.provider]?.push(key);
|
|
90
|
+
}
|
|
91
|
+
for (const [provider, providerKeys] of Object.entries(byProvider)) {
|
|
92
|
+
console.log(chalk.blue(` ${provider.toUpperCase()}`));
|
|
93
|
+
for (const key of providerKeys ?? []) {
|
|
94
|
+
const addedDate = new Date(key.createdAt).toLocaleDateString();
|
|
95
|
+
const primaryBadge = key.isPrimary ? chalk.green(" [primary]") : "";
|
|
96
|
+
console.log(` \u2022 ${key.label}${primaryBadge} ${chalk.dim(`(added ${addedDate})`)}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
console.log();
|
|
100
|
+
const adversarialStatus = await keyManager.getAdversarialStatus();
|
|
101
|
+
if (adversarialStatus.enabled) {
|
|
102
|
+
console.log(chalk.green(`\u2713 ${adversarialStatus.message}`));
|
|
103
|
+
} else {
|
|
104
|
+
console.log(chalk.yellow(`\u25CB ${adversarialStatus.message}`));
|
|
105
|
+
}
|
|
106
|
+
console.log();
|
|
107
|
+
console.log(chalk.dim("Note: API keys are stored locally with encryption"));
|
|
108
|
+
}
|
|
109
|
+
async function removeKey(provider, options = {}) {
|
|
110
|
+
if (!isValidProvider(provider)) {
|
|
111
|
+
console.error(chalk.red(`Invalid provider: ${provider}`));
|
|
112
|
+
console.log(chalk.dim(`Valid providers: ${VALID_PROVIDERS.join(", ")}`));
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
const label = options.label;
|
|
116
|
+
const labelMsg = label ? ` (${label})` : "";
|
|
117
|
+
const spinner = ora(`Removing API key for ${provider}${labelMsg}...`).start();
|
|
118
|
+
const result = await keyManager.removeKey(provider, label);
|
|
119
|
+
if (!result.success) {
|
|
120
|
+
spinner.fail(chalk.red(result.error ?? "Failed to remove key"));
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const hasRemainingKeys = await keyManager.hasAnyKey();
|
|
124
|
+
if (!hasRemainingKeys) {
|
|
125
|
+
const config = await loadConfig();
|
|
126
|
+
if (config.tier === "BYOK") {
|
|
127
|
+
await saveConfig({ ...config, tier: "FREE" });
|
|
128
|
+
spinner.succeed(chalk.green(`API key for ${provider}${labelMsg} removed`));
|
|
129
|
+
console.log(chalk.yellow("No API keys remaining. Tier reverted to FREE."));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
spinner.succeed(chalk.green(`API key for ${provider}${labelMsg} removed`));
|
|
134
|
+
const adversarialStatus = await keyManager.getAdversarialStatus();
|
|
135
|
+
if (!adversarialStatus.enabled && adversarialStatus.providerCount > 0) {
|
|
136
|
+
console.log(chalk.yellow(`\u25CB ${adversarialStatus.message}`));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
async function setPrimaryKey(provider, label) {
|
|
140
|
+
if (!isValidProvider(provider)) {
|
|
141
|
+
console.error(chalk.red(`Invalid provider: ${provider}`));
|
|
142
|
+
console.log(chalk.dim(`Valid providers: ${VALID_PROVIDERS.join(", ")}`));
|
|
143
|
+
process.exit(1);
|
|
144
|
+
}
|
|
145
|
+
const spinner = ora(`Setting primary key for ${provider} to "${label}"...`).start();
|
|
146
|
+
const result = await keyManager.setPrimary(provider, label);
|
|
147
|
+
if (!result.success) {
|
|
148
|
+
spinner.fail(chalk.red(result.error ?? "Failed to set primary key"));
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
spinner.succeed(chalk.green(`Primary key for ${provider} set to "${label}"`));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export {
|
|
155
|
+
addKey,
|
|
156
|
+
listKeys,
|
|
157
|
+
removeKey,
|
|
158
|
+
setPrimaryKey
|
|
159
|
+
};
|