trinity-config 1.1.0 → 1.1.1

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
@@ -50,7 +50,8 @@ npx -y trinity-config --type codex -k xh-你的key --model gpt-5.4
50
50
 
51
51
  - 配置后**所有模型调用走 Trinity 计费**。
52
52
  - 非交互模式必须同时提供 `--type` 与 `-k`。
53
- - Codex zcf 写入仍可能有已知限制,见设计文档。
53
+ - **Claude Code**:经 zcf 写入 `~/.claude/settings.json`
54
+ - **Codex CLI**:**直接** merge `~/.codex/config.toml` + `auth.json`(不调用 zcf;zcf cx 会重置为 ChatGPT 官方登录)
54
55
 
55
56
  ## License
56
57
 
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import pc from "picocolors";
5
5
 
6
6
  // src/constants.ts
7
7
  var PACKAGE_NAME = "trinity-config";
8
- var PACKAGE_VERSION = "1.1.0";
8
+ var PACKAGE_VERSION = "1.1.1";
9
9
  var TRINITY_BASE_URL = "https://api.trinitydesk.ai";
10
10
  var DEFAULT_CLAUDE_MODEL = "claude-sonnet-4-6";
11
11
  var DEFAULT_CLAUDE_FAST_MODEL = "claude-sonnet-4-6";
@@ -218,14 +218,9 @@ async function configureClaude(apiKey, baseUrl, claudeModel, verbose) {
218
218
  verbose
219
219
  });
220
220
  }
221
- async function configureCodex(apiKey, codexBaseUrl, codexModel, verbose) {
222
- await runZcfInit({
223
- codeType: "cx",
224
- apiKey,
225
- baseUrl: codexBaseUrl,
226
- primaryModel: codexModel,
227
- verbose
228
- });
221
+ async function configureCodex(apiKey, codexBaseUrl, codexModel, _verbose) {
222
+ const { configureCodexDirect } = await import("./merge-codex-config-GC7ZDP7R.js");
223
+ return configureCodexDirect(apiKey, codexBaseUrl, codexModel);
229
224
  }
230
225
  function resolveBaseUrls(baseUrl) {
231
226
  const root = (baseUrl ?? TRINITY_BASE_URL).replace(/\/+$/, "");
@@ -427,8 +422,10 @@ async function run() {
427
422
  } else {
428
423
  spinner2.start("\u914D\u7F6E Codex CLI\u2026");
429
424
  try {
430
- await configureCodex(apiKey, apiBaseUrl, model, opts.verbose);
431
- spinner2.stop("Codex \u914D\u7F6E\u5DF2\u5199\u5165 ~/.codex/");
425
+ const backupDir = await configureCodex(apiKey, apiBaseUrl, model, opts.verbose);
426
+ const backupHint = backupDir ? `
427
+ \u5907\u4EFD: ${backupDir}` : "";
428
+ spinner2.stop(`Codex \u914D\u7F6E\u5DF2\u5199\u5165 ~/.codex/config.toml \u4E0E auth.json${backupHint}`);
432
429
  } catch (error) {
433
430
  spinner2.stop(pc.red("Codex \u914D\u7F6E\u5931\u8D25"));
434
431
  console.error(formatZcfError(error));
@@ -0,0 +1,107 @@
1
+ // src/merge-codex-config.ts
2
+ import fs from "fs";
3
+ import os from "os";
4
+ import path from "path";
5
+ import { parse, stringify } from "smol-toml";
6
+ var TRINITY_CODEX_PROVIDER = "trinity";
7
+ var TRINITY_CODEX_TEMP_ENV_KEY = "TRINITY_API_KEY";
8
+ function codexHome() {
9
+ return process.env.CODEX_HOME?.trim() || path.join(os.homedir(), ".codex");
10
+ }
11
+ function codexConfigPath() {
12
+ return path.join(codexHome(), "config.toml");
13
+ }
14
+ function codexAuthPath() {
15
+ return path.join(codexHome(), "auth.json");
16
+ }
17
+ function timestampLabel() {
18
+ const now = /* @__PURE__ */ new Date();
19
+ const pad = (n) => String(n).padStart(2, "0");
20
+ return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}`;
21
+ }
22
+ function backupCodexFiles() {
23
+ const home = codexHome();
24
+ const configPath = codexConfigPath();
25
+ const authPath = codexAuthPath();
26
+ if (!fs.existsSync(configPath) && !fs.existsSync(authPath)) {
27
+ return null;
28
+ }
29
+ const backupDir = path.join(home, "backup", `trinity-config-${timestampLabel()}`);
30
+ fs.mkdirSync(backupDir, { recursive: true });
31
+ for (const src of [configPath, authPath]) {
32
+ if (fs.existsSync(src)) {
33
+ fs.copyFileSync(src, path.join(backupDir, path.basename(src)));
34
+ }
35
+ }
36
+ return backupDir;
37
+ }
38
+ function readCodexConfigDoc() {
39
+ const configPath = codexConfigPath();
40
+ if (!fs.existsSync(configPath)) {
41
+ return {};
42
+ }
43
+ const raw = fs.readFileSync(configPath, "utf8");
44
+ if (!raw.trim()) {
45
+ return {};
46
+ }
47
+ try {
48
+ return parse(raw);
49
+ } catch {
50
+ throw new Error(`\u65E0\u6CD5\u89E3\u6790 ${configPath}\uFF0C\u8BF7\u68C0\u67E5 TOML \u8BED\u6CD5\u540E\u91CD\u8BD5\u3002`);
51
+ }
52
+ }
53
+ function buildTrinityProvider(baseUrl) {
54
+ return {
55
+ name: "Trinity API",
56
+ base_url: baseUrl.replace(/\/+$/, ""),
57
+ wire_api: "responses",
58
+ temp_env_key: TRINITY_CODEX_TEMP_ENV_KEY,
59
+ requires_openai_auth: false
60
+ };
61
+ }
62
+ function mergeCodexConfig(model, baseUrl) {
63
+ const configPath = codexConfigPath();
64
+ const doc = readCodexConfigDoc();
65
+ doc.model = model;
66
+ doc.model_provider = TRINITY_CODEX_PROVIDER;
67
+ doc.disable_response_storage = true;
68
+ const providers = doc.model_providers && typeof doc.model_providers === "object" ? { ...doc.model_providers } : {};
69
+ providers[TRINITY_CODEX_PROVIDER] = buildTrinityProvider(baseUrl);
70
+ doc.model_providers = providers;
71
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
72
+ fs.writeFileSync(configPath, `${stringify(doc)}
73
+ `, "utf8");
74
+ }
75
+ function mergeCodexAuth(apiKey) {
76
+ const authPath = codexAuthPath();
77
+ let auth = {};
78
+ if (fs.existsSync(authPath)) {
79
+ try {
80
+ auth = JSON.parse(fs.readFileSync(authPath, "utf8"));
81
+ } catch {
82
+ auth = {};
83
+ }
84
+ }
85
+ auth[TRINITY_CODEX_TEMP_ENV_KEY] = apiKey;
86
+ auth.OPENAI_API_KEY = apiKey;
87
+ fs.mkdirSync(path.dirname(authPath), { recursive: true });
88
+ fs.writeFileSync(authPath, `${JSON.stringify(auth, null, 2)}
89
+ `, "utf8");
90
+ }
91
+ function configureCodexDirect(apiKey, codexBaseUrl, model) {
92
+ const backupDir = backupCodexFiles();
93
+ mergeCodexConfig(model, codexBaseUrl);
94
+ mergeCodexAuth(apiKey);
95
+ return backupDir;
96
+ }
97
+ export {
98
+ TRINITY_CODEX_PROVIDER,
99
+ TRINITY_CODEX_TEMP_ENV_KEY,
100
+ backupCodexFiles,
101
+ codexAuthPath,
102
+ codexConfigPath,
103
+ codexHome,
104
+ configureCodexDirect,
105
+ mergeCodexAuth,
106
+ mergeCodexConfig
107
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trinity-config",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "一键把 Trinity API 接入 Claude Code 与 Codex CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -42,7 +42,8 @@
42
42
  "dependencies": {
43
43
  "@clack/prompts": "^0.11.0",
44
44
  "execa": "^9.5.2",
45
- "picocolors": "^1.1.1"
45
+ "picocolors": "^1.1.1",
46
+ "smol-toml": "^1.3.1"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@types/node": "^22.10.0",