@getrouter/getrouter-cli 0.1.4 → 0.1.5
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/dist/bin.mjs +25 -19
- package/package.json +1 -1
- package/src/cmd/codex.ts +7 -14
- package/src/cmd/keys.ts +16 -7
- package/src/core/interactive/keys.ts +17 -4
- package/tests/cmd/codex.test.ts +5 -4
package/dist/bin.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { randomInt } from "node:crypto";
|
|
|
8
8
|
import prompts from "prompts";
|
|
9
9
|
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "0.1.
|
|
11
|
+
var version = "0.1.5";
|
|
12
12
|
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/generated/router/dashboard/v1/index.ts
|
|
@@ -616,8 +616,12 @@ const promptKeyName = async (initial) => {
|
|
|
616
616
|
message: "Key name",
|
|
617
617
|
initial: initial ?? ""
|
|
618
618
|
});
|
|
619
|
+
if (!("name" in response)) return { cancelled: true };
|
|
619
620
|
const value = typeof response.name === "string" ? response.name.trim() : "";
|
|
620
|
-
return
|
|
621
|
+
return {
|
|
622
|
+
cancelled: false,
|
|
623
|
+
name: value.length > 0 ? value : void 0
|
|
624
|
+
};
|
|
621
625
|
};
|
|
622
626
|
const promptKeyEnabled = async (initial) => {
|
|
623
627
|
const response = await prompts({
|
|
@@ -626,7 +630,11 @@ const promptKeyEnabled = async (initial) => {
|
|
|
626
630
|
message: "Enable this key?",
|
|
627
631
|
initial
|
|
628
632
|
});
|
|
629
|
-
|
|
633
|
+
if (!("enabled" in response)) return { cancelled: true };
|
|
634
|
+
return {
|
|
635
|
+
cancelled: false,
|
|
636
|
+
enabled: typeof response.enabled === "boolean" ? response.enabled : initial
|
|
637
|
+
};
|
|
630
638
|
};
|
|
631
639
|
const selectConsumer = async (consumerService) => {
|
|
632
640
|
const consumers = await fetchAllPages((pageToken) => consumerService.ListConsumers({
|
|
@@ -1112,18 +1120,10 @@ const registerCodexCommand = (program) => {
|
|
|
1112
1120
|
if (!apiKey) throw new Error("API key not found. Please create one or choose another.");
|
|
1113
1121
|
const reasoningValue = mapReasoningValue(reasoningId);
|
|
1114
1122
|
const keyName = selected.name?.trim() || "(unnamed)";
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
"Apply Codex configuration?",
|
|
1120
|
-
`Model: ${model}`,
|
|
1121
|
-
`Reasoning: ${formatReasoningLabel(reasoningId)} (${reasoningValue})`,
|
|
1122
|
-
"Provider: getrouter",
|
|
1123
|
-
`Key: ${keyName}`
|
|
1124
|
-
].join("\n"),
|
|
1125
|
-
initial: true
|
|
1126
|
-
})).confirm) return;
|
|
1123
|
+
console.log(`Model: ${model}`);
|
|
1124
|
+
console.log(`Reasoning: ${formatReasoningLabel(reasoningId)} (${reasoningValue})`);
|
|
1125
|
+
console.log("Provider: getrouter");
|
|
1126
|
+
console.log(`Key: ${keyName}`);
|
|
1127
1127
|
const codexDir = ensureCodexDir();
|
|
1128
1128
|
const configPath = path.join(codexDir, "config.toml");
|
|
1129
1129
|
const authPath = path.join(codexDir, "auth.json");
|
|
@@ -1243,10 +1243,12 @@ const resolveConsumerForDelete = async (consumerService, id) => {
|
|
|
1243
1243
|
};
|
|
1244
1244
|
const createConsumer = async (consumerService) => {
|
|
1245
1245
|
requireInteractiveForAction("create");
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1246
|
+
const nameResult = await promptKeyName();
|
|
1247
|
+
if (nameResult.cancelled) return;
|
|
1248
|
+
const enabledResult = await promptKeyEnabled(true);
|
|
1249
|
+
if (enabledResult.cancelled) return;
|
|
1248
1250
|
let consumer = await consumerService.CreateConsumer({});
|
|
1249
|
-
consumer = await updateConsumer(consumerService, consumer, name, enabled);
|
|
1251
|
+
consumer = await updateConsumer(consumerService, consumer, nameResult.name, enabledResult.enabled);
|
|
1250
1252
|
outputConsumerTable(consumer, true);
|
|
1251
1253
|
console.log("Please store this API key securely.");
|
|
1252
1254
|
};
|
|
@@ -1254,7 +1256,11 @@ const updateConsumerById = async (consumerService, id) => {
|
|
|
1254
1256
|
requireInteractiveForAction("update");
|
|
1255
1257
|
const selected = await resolveConsumerForUpdate(consumerService, id);
|
|
1256
1258
|
if (!selected?.id) return;
|
|
1257
|
-
|
|
1259
|
+
const nameResult = await promptKeyName(selected.name);
|
|
1260
|
+
if (nameResult.cancelled) return;
|
|
1261
|
+
const enabledResult = await promptKeyEnabled(selected.enabled ?? true);
|
|
1262
|
+
if (enabledResult.cancelled) return;
|
|
1263
|
+
outputConsumerTable(await updateConsumer(consumerService, selected, nameResult.name, enabledResult.enabled), false);
|
|
1258
1264
|
};
|
|
1259
1265
|
const deleteConsumerById = async (consumerService, id) => {
|
|
1260
1266
|
requireInteractiveForAction("delete");
|
package/package.json
CHANGED
package/src/cmd/codex.ts
CHANGED
|
@@ -2,7 +2,6 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import type { Command } from "commander";
|
|
5
|
-
import prompts from "prompts";
|
|
6
5
|
import { createApiClients } from "../core/api/client";
|
|
7
6
|
import {
|
|
8
7
|
getCodexModelChoices,
|
|
@@ -91,19 +90,13 @@ export const registerCodexCommand = (program: Command) => {
|
|
|
91
90
|
|
|
92
91
|
const reasoningValue = mapReasoningValue(reasoningId);
|
|
93
92
|
const keyName = selected.name?.trim() || "(unnamed)";
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"Provider: getrouter",
|
|
102
|
-
`Key: ${keyName}`,
|
|
103
|
-
].join("\n"),
|
|
104
|
-
initial: true,
|
|
105
|
-
});
|
|
106
|
-
if (!confirm.confirm) return;
|
|
93
|
+
|
|
94
|
+
console.log(`Model: ${model}`);
|
|
95
|
+
console.log(
|
|
96
|
+
`Reasoning: ${formatReasoningLabel(reasoningId)} (${reasoningValue})`,
|
|
97
|
+
);
|
|
98
|
+
console.log("Provider: getrouter");
|
|
99
|
+
console.log(`Key: ${keyName}`);
|
|
107
100
|
|
|
108
101
|
const codexDir = ensureCodexDir();
|
|
109
102
|
const configPath = path.join(codexDir, "config.toml");
|
package/src/cmd/keys.ts
CHANGED
|
@@ -132,10 +132,17 @@ const createConsumer = async (
|
|
|
132
132
|
consumerService: Pick<ConsumerService, "CreateConsumer" | "UpdateConsumer">,
|
|
133
133
|
) => {
|
|
134
134
|
requireInteractiveForAction("create");
|
|
135
|
-
const
|
|
136
|
-
|
|
135
|
+
const nameResult = await promptKeyName();
|
|
136
|
+
if (nameResult.cancelled) return;
|
|
137
|
+
const enabledResult = await promptKeyEnabled(true);
|
|
138
|
+
if (enabledResult.cancelled) return;
|
|
137
139
|
let consumer = await consumerService.CreateConsumer({});
|
|
138
|
-
consumer = await updateConsumer(
|
|
140
|
+
consumer = await updateConsumer(
|
|
141
|
+
consumerService,
|
|
142
|
+
consumer,
|
|
143
|
+
nameResult.name,
|
|
144
|
+
enabledResult.enabled,
|
|
145
|
+
);
|
|
139
146
|
outputConsumerTable(consumer, true);
|
|
140
147
|
console.log("Please store this API key securely.");
|
|
141
148
|
};
|
|
@@ -150,13 +157,15 @@ const updateConsumerById = async (
|
|
|
150
157
|
requireInteractiveForAction("update");
|
|
151
158
|
const selected = await resolveConsumerForUpdate(consumerService, id);
|
|
152
159
|
if (!selected?.id) return;
|
|
153
|
-
const
|
|
154
|
-
|
|
160
|
+
const nameResult = await promptKeyName(selected.name);
|
|
161
|
+
if (nameResult.cancelled) return;
|
|
162
|
+
const enabledResult = await promptKeyEnabled(selected.enabled ?? true);
|
|
163
|
+
if (enabledResult.cancelled) return;
|
|
155
164
|
const consumer = await updateConsumer(
|
|
156
165
|
consumerService,
|
|
157
166
|
selected,
|
|
158
|
-
name,
|
|
159
|
-
enabled,
|
|
167
|
+
nameResult.name,
|
|
168
|
+
enabledResult.enabled,
|
|
160
169
|
);
|
|
161
170
|
outputConsumerTable(consumer, false);
|
|
162
171
|
};
|
|
@@ -78,25 +78,38 @@ export const selectKeyAction = async (): Promise<KeyMenuAction> => {
|
|
|
78
78
|
|
|
79
79
|
export const promptKeyName = async (
|
|
80
80
|
initial?: string,
|
|
81
|
-
): Promise<
|
|
81
|
+
): Promise<
|
|
82
|
+
{ cancelled: true } | { cancelled: false; name: string | undefined }
|
|
83
|
+
> => {
|
|
82
84
|
const response = await prompts({
|
|
83
85
|
type: "text",
|
|
84
86
|
name: "name",
|
|
85
87
|
message: "Key name",
|
|
86
88
|
initial: initial ?? "",
|
|
87
89
|
});
|
|
90
|
+
if (!("name" in response)) {
|
|
91
|
+
return { cancelled: true };
|
|
92
|
+
}
|
|
88
93
|
const value = typeof response.name === "string" ? response.name.trim() : "";
|
|
89
|
-
return value.length > 0 ? value : undefined;
|
|
94
|
+
return { cancelled: false, name: value.length > 0 ? value : undefined };
|
|
90
95
|
};
|
|
91
96
|
|
|
92
|
-
export const promptKeyEnabled = async (
|
|
97
|
+
export const promptKeyEnabled = async (
|
|
98
|
+
initial: boolean,
|
|
99
|
+
): Promise<{ cancelled: true } | { cancelled: false; enabled: boolean }> => {
|
|
93
100
|
const response = await prompts({
|
|
94
101
|
type: "confirm",
|
|
95
102
|
name: "enabled",
|
|
96
103
|
message: "Enable this key?",
|
|
97
104
|
initial,
|
|
98
105
|
});
|
|
99
|
-
|
|
106
|
+
if (!("enabled" in response)) {
|
|
107
|
+
return { cancelled: true };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
cancelled: false,
|
|
111
|
+
enabled: typeof response.enabled === "boolean" ? response.enabled : initial,
|
|
112
|
+
};
|
|
100
113
|
};
|
|
101
114
|
|
|
102
115
|
export const selectConsumer = async (
|
package/tests/cmd/codex.test.ts
CHANGED
|
@@ -33,6 +33,7 @@ const originalEnv = Object.fromEntries(
|
|
|
33
33
|
|
|
34
34
|
afterEach(() => {
|
|
35
35
|
vi.unstubAllGlobals();
|
|
36
|
+
vi.clearAllMocks();
|
|
36
37
|
setStdinTTY(originalIsTTY);
|
|
37
38
|
prompts.inject([]);
|
|
38
39
|
for (const key of ENV_KEYS) {
|
|
@@ -70,7 +71,7 @@ describe("codex command", () => {
|
|
|
70
71
|
});
|
|
71
72
|
vi.stubGlobal("fetch", fetchMock);
|
|
72
73
|
|
|
73
|
-
prompts.inject(["gpt-5.2-codex", "extra_high", mockConsumer
|
|
74
|
+
prompts.inject(["gpt-5.2-codex", "extra_high", mockConsumer]);
|
|
74
75
|
(createApiClients as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
75
76
|
consumerService: {
|
|
76
77
|
ListConsumers: vi.fn().mockResolvedValue({
|
|
@@ -100,7 +101,7 @@ describe("codex command", () => {
|
|
|
100
101
|
setStdinTTY(true);
|
|
101
102
|
const dir = makeDir();
|
|
102
103
|
process.env.HOME = dir;
|
|
103
|
-
prompts.inject(["gpt-5.2-codex", "extra_high", mockConsumer
|
|
104
|
+
prompts.inject(["gpt-5.2-codex", "extra_high", mockConsumer]);
|
|
104
105
|
(createApiClients as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
105
106
|
consumerService: {
|
|
106
107
|
ListConsumers: vi.fn().mockResolvedValue({
|
|
@@ -162,7 +163,7 @@ describe("codex command", () => {
|
|
|
162
163
|
codexAuthPath(dir),
|
|
163
164
|
JSON.stringify({ OTHER: "keep", OPENAI_API_KEY: "old" }, null, 2),
|
|
164
165
|
);
|
|
165
|
-
prompts.inject(["gpt-5.2", "low", mockConsumer
|
|
166
|
+
prompts.inject(["gpt-5.2", "low", mockConsumer]);
|
|
166
167
|
(createApiClients as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
167
168
|
consumerService: {
|
|
168
169
|
ListConsumers: vi.fn().mockResolvedValue({
|
|
@@ -201,7 +202,7 @@ describe("codex command", () => {
|
|
|
201
202
|
setStdinTTY(true);
|
|
202
203
|
const dir = makeDir();
|
|
203
204
|
process.env.HOME = dir;
|
|
204
|
-
prompts.inject(["extra_high", mockConsumer
|
|
205
|
+
prompts.inject(["extra_high", mockConsumer]);
|
|
205
206
|
(createApiClients as unknown as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
206
207
|
consumerService: {
|
|
207
208
|
ListConsumers: vi.fn().mockResolvedValue({
|