xiaodcs-copilot-api-edge 2.3.9-edge.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/LICENSE +21 -0
- package/README.md +888 -0
- package/README.zh-CN.md +940 -0
- package/dist/auth-BiVetBYt.js +446 -0
- package/dist/auth-Bu4MXadr.js +2 -0
- package/dist/config-SytZjLq8.js +544 -0
- package/dist/debug-BFadhEB4.js +90 -0
- package/dist/electron-fetch-BRX-ug5E.js +20 -0
- package/dist/fast-path-BoMnZCVC.js +9 -0
- package/dist/main.js +49 -0
- package/dist/mcp-fpSlKZxK.js +14 -0
- package/dist/mcp-server-BeNu_Edl.js +25 -0
- package/dist/mcp-server-DQ4r-fAy.js +2 -0
- package/dist/models-YMUf33c-.js +88 -0
- package/dist/server-CFQmvoAJ.js +11710 -0
- package/dist/start-FFVCi8su.js +528 -0
- package/dist/tls-Aq1Dd8E2.js +14 -0
- package/dist/token-D9svRIYW.js +1950 -0
- package/dist/tool-search-Ds1vbmGG.js +114 -0
- package/package.json +96 -0
- package/pages/index.html +2257 -0
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { F as ensurePaths, N as setConfiguredApiKeys, P as PATHS, a as normalizeProviderBaseUrl, c as setProviderConfig, n as getRawProviderConfig, r as isSupportedProviderType, y as SUPPORTED_PROVIDER_TYPES } from "./config-SytZjLq8.js";
|
|
2
|
+
import { A as getConfiguredApiKeys, K as state, M as loginCodex, a as setupGitHubToken, n as persistCodexCredentials } from "./token-D9svRIYW.js";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
import consola from "consola";
|
|
5
|
+
//#region src/lib/quick-providers.ts
|
|
6
|
+
const QUICK_PROVIDER_CONFIGS = {
|
|
7
|
+
"opencode-go": {
|
|
8
|
+
type: "openai-compatible",
|
|
9
|
+
baseUrl: "https://opencode.ai/zen/go",
|
|
10
|
+
pricingCurrency: "USD",
|
|
11
|
+
editableType: false
|
|
12
|
+
},
|
|
13
|
+
kimi: {
|
|
14
|
+
type: "openai-compatible",
|
|
15
|
+
baseUrl: "https://api.kimi.com/coding",
|
|
16
|
+
pricingCurrency: "USD",
|
|
17
|
+
editableType: true
|
|
18
|
+
},
|
|
19
|
+
deepseek: {
|
|
20
|
+
type: "anthropic",
|
|
21
|
+
baseUrl: "https://api.deepseek.com/anthropic",
|
|
22
|
+
pricingCurrency: "CNY",
|
|
23
|
+
editableType: true
|
|
24
|
+
},
|
|
25
|
+
dashscope: {
|
|
26
|
+
type: "openai-compatible",
|
|
27
|
+
baseUrl: "https://dashscope.aliyuncs.com/compatible-mode",
|
|
28
|
+
pricingCurrency: "CNY",
|
|
29
|
+
editableType: true
|
|
30
|
+
},
|
|
31
|
+
openrouter: {
|
|
32
|
+
type: "anthropic",
|
|
33
|
+
baseUrl: "https://openrouter.ai/api",
|
|
34
|
+
pricingCurrency: "USD",
|
|
35
|
+
editableType: false
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/auth.ts
|
|
40
|
+
const authArgs = {
|
|
41
|
+
provider: {
|
|
42
|
+
type: "string",
|
|
43
|
+
description: "Provider to log in with or configure (copilot, codex, opencode-go, kimi, deepseek, dashscope, openrouter, custom)"
|
|
44
|
+
},
|
|
45
|
+
verbose: {
|
|
46
|
+
alias: "v",
|
|
47
|
+
type: "boolean",
|
|
48
|
+
default: false,
|
|
49
|
+
description: "Enable verbose logging"
|
|
50
|
+
},
|
|
51
|
+
"show-token": {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
default: false,
|
|
54
|
+
description: "Show provider access token on auth"
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const BUILTIN_PROVIDER_NAMES = ["copilot", "codex"];
|
|
58
|
+
const QUICK_PROVIDER_NAMES = Object.keys(QUICK_PROVIDER_CONFIGS);
|
|
59
|
+
const AUTH_PROVIDER_NAMES = [
|
|
60
|
+
...BUILTIN_PROVIDER_NAMES,
|
|
61
|
+
...QUICK_PROVIDER_NAMES,
|
|
62
|
+
"custom"
|
|
63
|
+
];
|
|
64
|
+
const CUSTOM_PROVIDER_AUTH_TYPE_OPTION = "__default__";
|
|
65
|
+
const QUICK_PROVIDER_DEFAULT_TYPE_OPTION = "__default__";
|
|
66
|
+
const CUSTOM_PROVIDER_AUTH_TYPES = ["x-api-key", "authorization"];
|
|
67
|
+
const AUTH_PROVIDER_LABELS = {
|
|
68
|
+
copilot: "GitHub Copilot",
|
|
69
|
+
codex: "OpenAI Codex",
|
|
70
|
+
"opencode-go": "OpenCode Go",
|
|
71
|
+
kimi: "Kimi",
|
|
72
|
+
deepseek: "DeepSeek",
|
|
73
|
+
dashscope: "DashScope",
|
|
74
|
+
openrouter: "OpenRouter",
|
|
75
|
+
custom: "Custom provider"
|
|
76
|
+
};
|
|
77
|
+
function isAuthProviderName(providerName) {
|
|
78
|
+
return AUTH_PROVIDER_NAMES.includes(providerName);
|
|
79
|
+
}
|
|
80
|
+
function isCustomProviderAuthType(value) {
|
|
81
|
+
return CUSTOM_PROVIDER_AUTH_TYPES.includes(value);
|
|
82
|
+
}
|
|
83
|
+
function isQuickProviderName(providerName) {
|
|
84
|
+
return QUICK_PROVIDER_NAMES.includes(providerName);
|
|
85
|
+
}
|
|
86
|
+
async function resolveProviderSelection(providerArg) {
|
|
87
|
+
const availableProviders = [...AUTH_PROVIDER_NAMES];
|
|
88
|
+
if (providerArg !== void 0) {
|
|
89
|
+
const providerName = providerArg.trim();
|
|
90
|
+
if (!isAuthProviderName(providerName)) throw new Error(`Unknown provider '${providerArg}'. Expected one of: ${availableProviders.join(", ")}`);
|
|
91
|
+
return providerName;
|
|
92
|
+
}
|
|
93
|
+
if (availableProviders.length === 1) return availableProviders[0];
|
|
94
|
+
const provider = await consola.prompt("Select a provider to log in with", {
|
|
95
|
+
type: "select",
|
|
96
|
+
options: availableProviders.map((providerName) => ({
|
|
97
|
+
label: `${AUTH_PROVIDER_LABELS[providerName]} (${providerName})`,
|
|
98
|
+
value: providerName
|
|
99
|
+
}))
|
|
100
|
+
});
|
|
101
|
+
if (!provider || !isAuthProviderName(provider)) throw new Error("No provider selected");
|
|
102
|
+
return provider;
|
|
103
|
+
}
|
|
104
|
+
function assertCustomProviderName(providerName) {
|
|
105
|
+
if (!providerName) throw new Error("Provider name must be a non-empty string");
|
|
106
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9_-]*$/u.test(providerName)) throw new Error("Provider name must start with a letter or number and contain only letters, numbers, underscores, or hyphens");
|
|
107
|
+
if (providerName === "copilot" || providerName === "codex") throw new Error(`Provider name '${providerName}' is reserved for a builtin provider`);
|
|
108
|
+
}
|
|
109
|
+
async function promptRequiredText(message, fieldName) {
|
|
110
|
+
const value = await consola.prompt(message, { type: "text" });
|
|
111
|
+
const normalizedValue = typeof value === "string" ? value.trim() : "";
|
|
112
|
+
if (!normalizedValue) throw new Error(`${fieldName} must be a non-empty string`);
|
|
113
|
+
return normalizedValue;
|
|
114
|
+
}
|
|
115
|
+
function canUseMaskedPrompt() {
|
|
116
|
+
return Boolean(process.stdin.isTTY && process.stdout.isTTY && typeof process.stdin.setRawMode === "function");
|
|
117
|
+
}
|
|
118
|
+
async function promptMaskedText(message) {
|
|
119
|
+
if (!canUseMaskedPrompt()) {
|
|
120
|
+
const value = await consola.prompt(message, { type: "text" });
|
|
121
|
+
return typeof value === "string" ? value : "";
|
|
122
|
+
}
|
|
123
|
+
return await new Promise((resolve, reject) => {
|
|
124
|
+
let value = "";
|
|
125
|
+
const rawModeWasEnabled = process.stdin.isRaw === true;
|
|
126
|
+
function cleanup() {
|
|
127
|
+
process.stdin.off("data", onData);
|
|
128
|
+
process.stdin.setRawMode(rawModeWasEnabled);
|
|
129
|
+
process.stdin.pause();
|
|
130
|
+
}
|
|
131
|
+
function finish() {
|
|
132
|
+
cleanup();
|
|
133
|
+
process.stdout.write("\n");
|
|
134
|
+
resolve(value);
|
|
135
|
+
}
|
|
136
|
+
function cancel() {
|
|
137
|
+
cleanup();
|
|
138
|
+
process.stdout.write("\n");
|
|
139
|
+
reject(/* @__PURE__ */ new Error("Prompt cancelled"));
|
|
140
|
+
}
|
|
141
|
+
function onData(chunk) {
|
|
142
|
+
const input = chunk.toString("utf8");
|
|
143
|
+
if (input.startsWith("\x1B")) return;
|
|
144
|
+
for (const char of input) {
|
|
145
|
+
if (char === "") {
|
|
146
|
+
cancel();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (char === "\r" || char === "\n") {
|
|
150
|
+
finish();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (char === "\b" || char === "") {
|
|
154
|
+
if (value.length > 0) {
|
|
155
|
+
value = value.slice(0, -1);
|
|
156
|
+
process.stdout.write("\b \b");
|
|
157
|
+
}
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (char >= " ") {
|
|
161
|
+
value += char;
|
|
162
|
+
process.stdout.write("*");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
process.stdout.write(`${message}: `);
|
|
167
|
+
process.stdin.setRawMode(true);
|
|
168
|
+
process.stdin.resume();
|
|
169
|
+
process.stdin.on("data", onData);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
async function promptRequiredSecret(message, fieldName) {
|
|
173
|
+
const normalizedValue = (await promptMaskedText(message)).trim();
|
|
174
|
+
if (!normalizedValue) throw new Error(`${fieldName} must be a non-empty string`);
|
|
175
|
+
return normalizedValue;
|
|
176
|
+
}
|
|
177
|
+
async function promptCustomProviderName() {
|
|
178
|
+
const providerName = await promptRequiredText("Enter provider name", "Provider name");
|
|
179
|
+
assertCustomProviderName(providerName);
|
|
180
|
+
return providerName;
|
|
181
|
+
}
|
|
182
|
+
async function promptCustomProviderType() {
|
|
183
|
+
const providerType = await consola.prompt("Select provider type", {
|
|
184
|
+
type: "select",
|
|
185
|
+
options: SUPPORTED_PROVIDER_TYPES.map((type) => ({
|
|
186
|
+
label: type,
|
|
187
|
+
value: type
|
|
188
|
+
}))
|
|
189
|
+
});
|
|
190
|
+
if (typeof providerType !== "string" || !isSupportedProviderType(providerType)) throw new Error("No provider type selected");
|
|
191
|
+
return providerType;
|
|
192
|
+
}
|
|
193
|
+
async function promptQuickProviderType(defaultType) {
|
|
194
|
+
const providerType = await consola.prompt(`Select provider type (default: ${defaultType})`, {
|
|
195
|
+
type: "select",
|
|
196
|
+
options: [{
|
|
197
|
+
label: `Default (${defaultType})`,
|
|
198
|
+
value: QUICK_PROVIDER_DEFAULT_TYPE_OPTION
|
|
199
|
+
}, ...SUPPORTED_PROVIDER_TYPES.map((type) => ({
|
|
200
|
+
label: type,
|
|
201
|
+
value: type
|
|
202
|
+
}))]
|
|
203
|
+
});
|
|
204
|
+
if (providerType === QUICK_PROVIDER_DEFAULT_TYPE_OPTION) return defaultType;
|
|
205
|
+
if (typeof providerType === "string" && isSupportedProviderType(providerType)) return providerType;
|
|
206
|
+
throw new Error("No provider type selected");
|
|
207
|
+
}
|
|
208
|
+
function getDefaultProviderAuthType(providerType) {
|
|
209
|
+
return providerType === "anthropic" ? "x-api-key" : "authorization";
|
|
210
|
+
}
|
|
211
|
+
async function promptCustomProviderAuthType(providerType) {
|
|
212
|
+
const defaultAuthType = getDefaultProviderAuthType(providerType);
|
|
213
|
+
const authType = await consola.prompt("Select provider auth type", {
|
|
214
|
+
type: "select",
|
|
215
|
+
options: [{
|
|
216
|
+
label: `Default (${defaultAuthType})`,
|
|
217
|
+
value: CUSTOM_PROVIDER_AUTH_TYPE_OPTION
|
|
218
|
+
}, ...CUSTOM_PROVIDER_AUTH_TYPES.map((value) => ({
|
|
219
|
+
label: value,
|
|
220
|
+
value
|
|
221
|
+
}))]
|
|
222
|
+
});
|
|
223
|
+
if (authType === CUSTOM_PROVIDER_AUTH_TYPE_OPTION) return;
|
|
224
|
+
if (typeof authType === "string" && isCustomProviderAuthType(authType)) return authType;
|
|
225
|
+
throw new Error("No provider auth type selected");
|
|
226
|
+
}
|
|
227
|
+
async function promptQuickProviderBaseUrl(defaultBaseUrl) {
|
|
228
|
+
const value = await consola.prompt(`Enter provider baseUrl (default: ${defaultBaseUrl})`, {
|
|
229
|
+
type: "text",
|
|
230
|
+
default: defaultBaseUrl,
|
|
231
|
+
initial: defaultBaseUrl
|
|
232
|
+
});
|
|
233
|
+
const baseUrl = normalizeProviderBaseUrl(typeof value === "string" && value.trim() ? value : defaultBaseUrl);
|
|
234
|
+
if (!baseUrl) throw new Error("baseUrl must be a non-empty string");
|
|
235
|
+
return baseUrl;
|
|
236
|
+
}
|
|
237
|
+
function buildCustomProviderConfig(existingProviderConfig, options) {
|
|
238
|
+
return {
|
|
239
|
+
type: options.type,
|
|
240
|
+
enabled: true,
|
|
241
|
+
baseUrl: options.baseUrl,
|
|
242
|
+
apiKey: options.apiKey,
|
|
243
|
+
...options.authType ? { authType: options.authType } : {},
|
|
244
|
+
pricingCurrency: options.pricingCurrency ?? existingProviderConfig.pricingCurrency,
|
|
245
|
+
...existingProviderConfig.models ? { models: existingProviderConfig.models } : {}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
async function configureCustomProvider() {
|
|
249
|
+
const providerName = await promptCustomProviderName();
|
|
250
|
+
const type = await promptCustomProviderType();
|
|
251
|
+
const baseUrl = normalizeProviderBaseUrl(await promptRequiredText("Enter provider baseUrl", "baseUrl"));
|
|
252
|
+
if (!baseUrl) throw new Error("baseUrl must be a non-empty string");
|
|
253
|
+
const apiKey = await promptRequiredSecret("Enter provider apiKey", "apiKey");
|
|
254
|
+
const authType = await promptCustomProviderAuthType(type);
|
|
255
|
+
setProviderConfig(providerName, buildCustomProviderConfig(getRawProviderConfig(providerName) ?? {}, {
|
|
256
|
+
apiKey,
|
|
257
|
+
authType,
|
|
258
|
+
baseUrl,
|
|
259
|
+
type
|
|
260
|
+
}));
|
|
261
|
+
consola.success(`Custom provider '${providerName}' written to ${PATHS.CONFIG_PATH}`);
|
|
262
|
+
}
|
|
263
|
+
async function configureQuickProvider(providerName) {
|
|
264
|
+
const defaultProviderConfig = QUICK_PROVIDER_CONFIGS[providerName];
|
|
265
|
+
const apiKey = await promptRequiredSecret(`Enter ${providerName} apiKey`, "apiKey");
|
|
266
|
+
const type = defaultProviderConfig.editableType ? await promptQuickProviderType(defaultProviderConfig.type) : defaultProviderConfig.type;
|
|
267
|
+
const baseUrl = await promptQuickProviderBaseUrl(defaultProviderConfig.baseUrl);
|
|
268
|
+
setProviderConfig(providerName, buildCustomProviderConfig(getRawProviderConfig(providerName) ?? {}, {
|
|
269
|
+
apiKey,
|
|
270
|
+
baseUrl,
|
|
271
|
+
pricingCurrency: defaultProviderConfig.pricingCurrency,
|
|
272
|
+
type
|
|
273
|
+
}));
|
|
274
|
+
consola.success(`${AUTH_PROVIDER_LABELS[providerName]} provider '${providerName}' written to ${PATHS.CONFIG_PATH}`);
|
|
275
|
+
}
|
|
276
|
+
async function loginWithCodex() {
|
|
277
|
+
await persistCodexCredentials(await loginCodex({
|
|
278
|
+
onAuth(info) {
|
|
279
|
+
consola.info("Open the following URL to authenticate with Codex:");
|
|
280
|
+
consola.log(info.url);
|
|
281
|
+
if (info.instructions) consola.info(info.instructions);
|
|
282
|
+
},
|
|
283
|
+
onPrompt(message) {
|
|
284
|
+
return consola.prompt(message, { type: "text" });
|
|
285
|
+
},
|
|
286
|
+
onProgress(message) {
|
|
287
|
+
consola.debug(message);
|
|
288
|
+
}
|
|
289
|
+
}), { enableProvider: true });
|
|
290
|
+
consola.success(`Codex provider config written to ${PATHS.CONFIG_PATH} and credentials written to ${PATHS.CODEX_CREDENTIAL_PATH}`);
|
|
291
|
+
}
|
|
292
|
+
async function loginWithProvider(provider) {
|
|
293
|
+
if (provider === "copilot") {
|
|
294
|
+
await setupGitHubToken({ force: true });
|
|
295
|
+
consola.success("GitHub token written to", PATHS.GITHUB_TOKEN_PATH);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (provider === "codex") {
|
|
299
|
+
await loginWithCodex();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (isQuickProviderName(provider)) {
|
|
303
|
+
await configureQuickProvider(provider);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
await configureCustomProvider();
|
|
307
|
+
}
|
|
308
|
+
async function runProviderSetup() {
|
|
309
|
+
const provider = await resolveProviderSelection(void 0);
|
|
310
|
+
consola.info(`Logging in with ${AUTH_PROVIDER_LABELS[provider]}`);
|
|
311
|
+
await loginWithProvider(provider);
|
|
312
|
+
}
|
|
313
|
+
async function runAuthLogin(options) {
|
|
314
|
+
(await import("./tls-Aq1Dd8E2.js")).enableSystemCACompat();
|
|
315
|
+
if (options.verbose) {
|
|
316
|
+
consola.level = 5;
|
|
317
|
+
consola.info("Verbose logging enabled");
|
|
318
|
+
}
|
|
319
|
+
state.showToken = options.showToken;
|
|
320
|
+
await ensurePaths();
|
|
321
|
+
const provider = await resolveProviderSelection(options.provider);
|
|
322
|
+
consola.info(`Logging in with ${AUTH_PROVIDER_LABELS[provider]}`);
|
|
323
|
+
await loginWithProvider(provider);
|
|
324
|
+
}
|
|
325
|
+
const authKeysArgs = {
|
|
326
|
+
add: {
|
|
327
|
+
alias: "a",
|
|
328
|
+
type: "string",
|
|
329
|
+
description: "Add an API key for gateway authentication"
|
|
330
|
+
},
|
|
331
|
+
remove: {
|
|
332
|
+
alias: "r",
|
|
333
|
+
type: "string",
|
|
334
|
+
description: "Remove an API key"
|
|
335
|
+
},
|
|
336
|
+
list: {
|
|
337
|
+
alias: "l",
|
|
338
|
+
type: "boolean",
|
|
339
|
+
default: false,
|
|
340
|
+
description: "List configured API keys"
|
|
341
|
+
},
|
|
342
|
+
clear: {
|
|
343
|
+
type: "boolean",
|
|
344
|
+
default: false,
|
|
345
|
+
description: "Remove all configured API keys"
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
function normalizeAuthKeyValue(value) {
|
|
349
|
+
const normalizedKey = value.trim();
|
|
350
|
+
if (!normalizedKey) throw new Error("API key must be a non-empty string");
|
|
351
|
+
return normalizedKey;
|
|
352
|
+
}
|
|
353
|
+
async function runAuthKeys(options) {
|
|
354
|
+
(await import("./tls-Aq1Dd8E2.js")).enableSystemCACompat();
|
|
355
|
+
await ensurePaths();
|
|
356
|
+
const operations = [
|
|
357
|
+
...options.add !== void 0 ? ["add"] : [],
|
|
358
|
+
...options.remove !== void 0 ? ["remove"] : [],
|
|
359
|
+
...options.list ? ["list"] : [],
|
|
360
|
+
...options.clear ? ["clear"] : []
|
|
361
|
+
];
|
|
362
|
+
if (operations.length > 1) throw new Error("Use only one of --add, --remove, --list, or --clear per invocation");
|
|
363
|
+
const operation = operations[0] ?? "list";
|
|
364
|
+
if (operation === "add") {
|
|
365
|
+
const apiKey = normalizeAuthKeyValue(options.add ?? "");
|
|
366
|
+
const currentKeys = getConfiguredApiKeys();
|
|
367
|
+
if (currentKeys.includes(apiKey)) {
|
|
368
|
+
consola.info(`API key already configured. ${currentKeys.length} API key(s) configured.`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const storedKeys = setConfiguredApiKeys([...currentKeys, apiKey]);
|
|
372
|
+
consola.success(`API key added to ${PATHS.CONFIG_PATH}. ${storedKeys.length} API key(s) configured.`);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (operation === "remove") {
|
|
376
|
+
const apiKey = normalizeAuthKeyValue(options.remove ?? "");
|
|
377
|
+
const currentKeys = getConfiguredApiKeys();
|
|
378
|
+
if (!currentKeys.includes(apiKey)) {
|
|
379
|
+
consola.info(`API key not found. ${currentKeys.length} API key(s) configured.`);
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const storedKeys = setConfiguredApiKeys(currentKeys.filter((key) => key !== apiKey));
|
|
383
|
+
consola.success(`API key removed from ${PATHS.CONFIG_PATH}. ${storedKeys.length} API key(s) configured.`);
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
if (operation === "clear") {
|
|
387
|
+
setConfiguredApiKeys([]);
|
|
388
|
+
consola.success(`Removed all API keys from ${PATHS.CONFIG_PATH}.`);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const currentKeys = getConfiguredApiKeys();
|
|
392
|
+
if (currentKeys.length === 0) {
|
|
393
|
+
consola.info("No API keys configured. Run `npx copilot-api auth keys --add <key>` to add one.");
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
consola.info("Configured API keys:");
|
|
397
|
+
for (const key of currentKeys) consola.info(`- ${key}`);
|
|
398
|
+
}
|
|
399
|
+
const auth = defineCommand({
|
|
400
|
+
meta: {
|
|
401
|
+
name: "auth",
|
|
402
|
+
description: "Run authentication flows without running the server"
|
|
403
|
+
},
|
|
404
|
+
args: authArgs,
|
|
405
|
+
subCommands: {
|
|
406
|
+
login: defineCommand({
|
|
407
|
+
meta: {
|
|
408
|
+
name: "login",
|
|
409
|
+
description: "Authenticate or configure a provider without running the server"
|
|
410
|
+
},
|
|
411
|
+
args: authArgs,
|
|
412
|
+
run({ args }) {
|
|
413
|
+
return runAuthLogin({
|
|
414
|
+
provider: args.provider,
|
|
415
|
+
verbose: args.verbose,
|
|
416
|
+
showToken: args["show-token"]
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
}),
|
|
420
|
+
keys: defineCommand({
|
|
421
|
+
meta: {
|
|
422
|
+
name: "keys",
|
|
423
|
+
description: "Manage gateway API keys (auth.apiKeys) in the config"
|
|
424
|
+
},
|
|
425
|
+
args: authKeysArgs,
|
|
426
|
+
run({ args }) {
|
|
427
|
+
return runAuthKeys({
|
|
428
|
+
add: args.add,
|
|
429
|
+
remove: args.remove,
|
|
430
|
+
list: args.list,
|
|
431
|
+
clear: args.clear
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
})
|
|
435
|
+
},
|
|
436
|
+
run({ args }) {
|
|
437
|
+
if ((args._[0] ?? "").trim()) return;
|
|
438
|
+
return runAuthLogin({
|
|
439
|
+
provider: args.provider,
|
|
440
|
+
verbose: args.verbose,
|
|
441
|
+
showToken: args["show-token"]
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
});
|
|
445
|
+
//#endregion
|
|
446
|
+
export { runProviderSetup as i, runAuthKeys as n, runAuthLogin as r, auth as t };
|