@heventure/model-provider-x 0.2.2 → 0.2.3

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 CHANGED
@@ -125,6 +125,9 @@ Proxy mode gives the broadest compatibility:
125
125
  - `/v1/chat/completions` and `/v1/completions` passthrough for OpenAI-compatible clients.
126
126
  - `/v1/messages` for Claude Code.
127
127
 
128
+ When proxy mode is selected interactively, the wizard confirms whether to reuse the current proxy token, generate a new one, or enter your own.
129
+ Non-interactive `--yes` runs keep the existing token or use the generated default.
130
+
128
131
  You can force either mode non-interactively:
129
132
 
130
133
  ```bash
package/dist/cli/index.js CHANGED
@@ -3,7 +3,7 @@ import { createInterface } from "node:readline/promises";
3
3
  import { stdin as input, stdout as output } from "node:process";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { readProxyStatus, startProxyProcess, stopProxyProcess } from "../core/proxy-process.js";
6
- import { getDefaultToolConfigPath, readToolConfig, upsertProviderProfile } from "../core/tool-config.js";
6
+ import { createProxyAuthToken, getDefaultToolConfigPath, readToolConfig, upsertProviderProfile, writeToolConfig } from "../core/tool-config.js";
7
7
  import { discoverOpenCodeConfigs, getDefaultConfigPath, writeProviderToConfig } from "../core/config.js";
8
8
  import { buildProviderConfig, detectProviderCapabilities, recommendProxyMode, validateAndFetchModels } from "../core/provider.js";
9
9
  import { startProxyServer } from "../proxy/server.js";
@@ -123,7 +123,7 @@ async function runSetup(command) {
123
123
  return;
124
124
  }
125
125
  if (target === "codex") {
126
- await writeCodexSetup(command, selection, useProxy);
126
+ await writeCodexSetup(rl, command, selection, useProxy);
127
127
  return;
128
128
  }
129
129
  await writeClaudeCodeSetup(rl, command, selection, useProxy);
@@ -174,6 +174,9 @@ async function collectProviderSelection(rl, command, providerInput) {
174
174
  };
175
175
  }
176
176
  async function writeOpenCodeSetup(rl, command, selection, useProxy, capabilities) {
177
+ if (useProxy) {
178
+ await ensureProxyAuthToken(rl, command, selection);
179
+ }
177
180
  const baseURL = useProxy ? `http://${selection.config.proxy.host}:${selection.config.proxy.port}/v1` : selection.upstreamBaseURL;
178
181
  const apiKey = useProxy ? selection.config.proxy.authToken : selection.apiKey;
179
182
  const opencodeApiType = await resolveOpenCodeApiType(rl, command, capabilities, useProxy);
@@ -208,6 +211,9 @@ async function writeOpenCodeSetup(rl, command, selection, useProxy, capabilities
208
211
  }
209
212
  }
210
213
  async function writeClaudeCodeSetup(rl, command, selection, useProxy) {
214
+ if (useProxy) {
215
+ await ensureProxyAuthToken(rl, command, selection);
216
+ }
211
217
  const proxyBaseURL = useProxy ? `http://${selection.config.proxy.host}:${selection.config.proxy.port}` : selection.upstreamBaseURL;
212
218
  const modelMapping = await resolveClaudeModelMapping(rl, command, selection);
213
219
  const result = await writeClaudeCodeSettings({
@@ -236,7 +242,10 @@ async function writeClaudeCodeSetup(rl, command, selection, useProxy) {
236
242
  output.write(`Started proxy: ${proxy.baseURL}\n`);
237
243
  }
238
244
  }
239
- async function writeCodexSetup(_command, selection, useProxy) {
245
+ async function writeCodexSetup(rl, command, selection, useProxy) {
246
+ if (useProxy) {
247
+ await ensureProxyAuthToken(rl, command, selection);
248
+ }
240
249
  const proxyBaseURL = useProxy
241
250
  ? `http://${selection.config.proxy.host}:${selection.config.proxy.port}/v1`
242
251
  : selection.upstreamBaseURL;
@@ -315,6 +324,48 @@ async function runProxyCommand(command) {
315
324
  process.once("SIGTERM", stop);
316
325
  });
317
326
  }
327
+ async function ensureProxyAuthToken(rl, command, selection) {
328
+ if (command.options.yes || !rl) {
329
+ return;
330
+ }
331
+ const current = selection.config.proxy.authToken;
332
+ const action = canUseTui()
333
+ ? await selectChoice("Proxy token", [
334
+ { label: "Use existing proxy token", value: "use", hint: tokenHint(current) },
335
+ { label: "Generate a new proxy token", value: "generate" },
336
+ { label: "Enter a proxy token", value: "input" }
337
+ ])
338
+ : await promptProxyTokenAction(rl, current);
339
+ if (action === "use") {
340
+ return;
341
+ }
342
+ const nextToken = action === "generate"
343
+ ? createProxyAuthToken()
344
+ : await requiredOption(rl, undefined, "Proxy token");
345
+ selection.config.proxy.authToken = nextToken;
346
+ await writeToolConfig(selection.toolConfigPath, selection.config);
347
+ }
348
+ async function promptProxyTokenAction(rl, current) {
349
+ output.write(`Proxy token found (${tokenHint(current)}).\n`);
350
+ const answer = await rl.question("Use existing, generate new, or enter your own? [use/generate/input] ");
351
+ const value = answer.trim().toLowerCase();
352
+ if (!value || value === "use" || value === "u") {
353
+ return "use";
354
+ }
355
+ if (value === "generate" || value === "g") {
356
+ return "generate";
357
+ }
358
+ if (value === "input" || value === "i" || value === "byok") {
359
+ return "input";
360
+ }
361
+ throw new Error(`Unknown proxy token action: ${answer}`);
362
+ }
363
+ function tokenHint(token) {
364
+ if (token.length <= 10) {
365
+ return token;
366
+ }
367
+ return `${token.slice(0, 8)}...${token.slice(-4)}`;
368
+ }
318
369
  async function requiredOption(rl, value, label) {
319
370
  const answer = value ?? (await rl.question(`${label}: `));
320
371
  if (!answer.trim()) {
@@ -40,10 +40,13 @@ function createDefaultToolConfig() {
40
40
  proxy: {
41
41
  host: "127.0.0.1",
42
42
  port: 4141,
43
- authToken: `mpx-${randomBytes(18).toString("base64url")}`
43
+ authToken: createProxyAuthToken()
44
44
  }
45
45
  };
46
46
  }
47
+ export function createProxyAuthToken() {
48
+ return `mpx-${randomBytes(18).toString("base64url")}`;
49
+ }
47
50
  function normalizeToolConfig(config) {
48
51
  const fallback = createDefaultToolConfig();
49
52
  const profiles = isRecord(config.profiles) ? config.profiles : {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heventure/model-provider-x",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "TUI configurator and local API proxy for wiring custom model providers into OpenCode and Claude Code.",
5
5
  "private": false,
6
6
  "license": "MIT",