@getrouter/getrouter-cli 0.1.5 → 0.1.7
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 +135 -42
- package/docs/plans/2026-01-02-getrouter-cli-auth-device-design.md +2 -2
- package/docs/plans/2026-01-02-getrouter-cli-auth-device-plan.md +1 -1
- package/docs/plans/2026-01-06-codex-uninstall-design.md +34 -0
- package/docs/plans/2026-01-06-codex-uninstall-plan.md +252 -0
- package/package.json +1 -1
- package/src/cmd/codex.ts +56 -4
- package/src/core/auth/device.ts +1 -1
- package/src/core/setup/codex.ts +84 -0
- package/src/generated/router/dashboard/v1/index.ts +643 -582
- package/tests/cmd/codex.test.ts +69 -0
package/src/core/setup/codex.ts
CHANGED
|
@@ -34,6 +34,8 @@ const providerValues = () => ({
|
|
|
34
34
|
|
|
35
35
|
const matchHeader = (line: string) => line.match(/^\s*\[([^\]]+)\]\s*$/);
|
|
36
36
|
const matchKey = (line: string) => line.match(/^\s*([A-Za-z0-9_.-]+)\s*=/);
|
|
37
|
+
const matchProviderValue = (line: string) =>
|
|
38
|
+
line.match(/^\s*model_provider\s*=\s*(['"]?)([^'"]+)\1\s*(?:#.*)?$/);
|
|
37
39
|
|
|
38
40
|
export const mergeCodexToml = (content: string, input: CodexConfigInput) => {
|
|
39
41
|
const lines = content.length ? content.split(/\r?\n/) : [];
|
|
@@ -131,3 +133,85 @@ export const mergeAuthJson = (
|
|
|
131
133
|
...data,
|
|
132
134
|
OPENAI_API_KEY: apiKey,
|
|
133
135
|
});
|
|
136
|
+
|
|
137
|
+
const stripGetrouterProviderSection = (lines: string[]) => {
|
|
138
|
+
const updated: string[] = [];
|
|
139
|
+
let skipSection = false;
|
|
140
|
+
|
|
141
|
+
for (const line of lines) {
|
|
142
|
+
const headerMatch = matchHeader(line);
|
|
143
|
+
if (headerMatch) {
|
|
144
|
+
const section = headerMatch[1]?.trim() ?? "";
|
|
145
|
+
if (section === PROVIDER_SECTION) {
|
|
146
|
+
skipSection = true;
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
skipSection = false;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (skipSection) continue;
|
|
153
|
+
updated.push(line);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return updated;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const stripRootKeys = (lines: string[]) => {
|
|
160
|
+
const updated: string[] = [];
|
|
161
|
+
let currentSection: string | null = null;
|
|
162
|
+
|
|
163
|
+
for (const line of lines) {
|
|
164
|
+
const headerMatch = matchHeader(line);
|
|
165
|
+
if (headerMatch) {
|
|
166
|
+
currentSection = headerMatch[1]?.trim() ?? null;
|
|
167
|
+
updated.push(line);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (currentSection === null) {
|
|
172
|
+
if (/^\s*model\s*=/.test(line)) continue;
|
|
173
|
+
if (/^\s*model_reasoning_effort\s*=/.test(line)) continue;
|
|
174
|
+
if (/^\s*model_provider\s*=/.test(line)) continue;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
updated.push(line);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return updated;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
export const removeCodexConfig = (content: string) => {
|
|
184
|
+
const lines = content.length ? content.split(/\r?\n/) : [];
|
|
185
|
+
let providerIsGetrouter = false;
|
|
186
|
+
let currentSection: string | null = null;
|
|
187
|
+
|
|
188
|
+
for (const line of lines) {
|
|
189
|
+
const headerMatch = matchHeader(line);
|
|
190
|
+
if (headerMatch) {
|
|
191
|
+
currentSection = headerMatch[1]?.trim() ?? null;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (currentSection !== null) continue;
|
|
196
|
+
|
|
197
|
+
const providerMatch = matchProviderValue(line);
|
|
198
|
+
const providerValue = providerMatch?.[2]?.trim();
|
|
199
|
+
if (providerValue?.toLowerCase() === CODEX_PROVIDER) {
|
|
200
|
+
providerIsGetrouter = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
let updated = stripGetrouterProviderSection(lines);
|
|
205
|
+
if (providerIsGetrouter) {
|
|
206
|
+
updated = stripRootKeys(updated);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const nextContent = updated.join("\n");
|
|
210
|
+
return { content: nextContent, changed: nextContent !== content };
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export const removeAuthJson = (data: Record<string, unknown>) => {
|
|
214
|
+
if (!("OPENAI_API_KEY" in data)) return { data, changed: false };
|
|
215
|
+
const { OPENAI_API_KEY: _ignored, ...rest } = data;
|
|
216
|
+
return { data: rest, changed: true };
|
|
217
|
+
};
|