@gengjiawen/os-init 1.1.0 → 1.2.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/bin/bin.js +24 -1
- package/build/index.d.ts +7 -0
- package/build/index.js +102 -0
- package/libs/index.ts +48 -0
- package/package.json +1 -1
package/bin/bin.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const { Command } = require('commander')
|
|
4
|
-
const { writeConfig, installDeps } = require('../build')
|
|
4
|
+
const { writeConfig, installDeps, writeCodexConfig, installCodexDeps } = require('../build')
|
|
5
5
|
|
|
6
6
|
const program = new Command()
|
|
7
7
|
|
|
@@ -24,6 +24,29 @@ program
|
|
|
24
24
|
console.error('Failed to complete setup:', err.message)
|
|
25
25
|
process.exit(1)
|
|
26
26
|
}
|
|
27
|
+
console.log('use `ccr code` in terminal to start building')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
program
|
|
31
|
+
.command('set-codex')
|
|
32
|
+
.description('setup codex cli config and auth')
|
|
33
|
+
.argument('<apiKey>', 'API key to set for Codex')
|
|
34
|
+
.action(async (apiKey) => {
|
|
35
|
+
if (!apiKey || String(apiKey).trim().length === 0) {
|
|
36
|
+
console.error('Missing required argument: <apiKey>')
|
|
37
|
+
program.help({ error: true })
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const { configPath, authPath } = writeCodexConfig(apiKey)
|
|
42
|
+
console.log(`Codex config written to: ${configPath}`)
|
|
43
|
+
console.log(`Codex auth written to: ${authPath}`)
|
|
44
|
+
await installCodexDeps()
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error('Failed to setup Codex:', err.message)
|
|
47
|
+
process.exit(1)
|
|
48
|
+
}
|
|
49
|
+
console.log('Codex is ready. use `codex` in terminal to start building')
|
|
27
50
|
})
|
|
28
51
|
|
|
29
52
|
program.parse(process.argv)
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function writeConfig(apiKey: string): string;
|
|
2
|
+
export declare function installDeps(): Promise<void>;
|
|
3
|
+
export declare function writeCodexConfig(apiKey: string): {
|
|
4
|
+
configPath: string;
|
|
5
|
+
authPath: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function installCodexDeps(): Promise<void>;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeConfig = writeConfig;
|
|
4
|
+
exports.installDeps = installDeps;
|
|
5
|
+
exports.writeCodexConfig = writeCodexConfig;
|
|
6
|
+
exports.installCodexDeps = installCodexDeps;
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
const path = require("path");
|
|
9
|
+
const os = require("os");
|
|
10
|
+
const execa_1 = require("execa");
|
|
11
|
+
function getDefaultConfigDir() {
|
|
12
|
+
return path.join(os.homedir(), '.claude-code-router');
|
|
13
|
+
}
|
|
14
|
+
function ensureDir(dirPath) {
|
|
15
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
16
|
+
}
|
|
17
|
+
const DEFAULT_TEMPLATE = `{
|
|
18
|
+
"Providers": [
|
|
19
|
+
{
|
|
20
|
+
"name": "jw",
|
|
21
|
+
"api_base_url": "https://ai.gengjiawen.com/api/openai/v1/chat/completions",
|
|
22
|
+
"api_key": "API_KEY_PLACEHOLDER",
|
|
23
|
+
"models": ["code", "free", "free-thinking"],
|
|
24
|
+
"transformer": {
|
|
25
|
+
"use": ["openrouter"]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"Router": {
|
|
30
|
+
"default": "jw,code",
|
|
31
|
+
"background": "jw,code",
|
|
32
|
+
"think": "jw,code",
|
|
33
|
+
"longContext": "jw,code"
|
|
34
|
+
}
|
|
35
|
+
}`;
|
|
36
|
+
function writeConfig(apiKey) {
|
|
37
|
+
const configDir = getDefaultConfigDir();
|
|
38
|
+
const configPath = path.join(configDir, 'config.json');
|
|
39
|
+
ensureDir(configDir);
|
|
40
|
+
const content = DEFAULT_TEMPLATE.replace('API_KEY_PLACEHOLDER', apiKey);
|
|
41
|
+
fs.writeFileSync(configPath, content);
|
|
42
|
+
return configPath;
|
|
43
|
+
}
|
|
44
|
+
async function commandExists(command) {
|
|
45
|
+
try {
|
|
46
|
+
const { failed } = await (0, execa_1.execa)(command, ['--version'], { stdio: 'ignore', reject: false });
|
|
47
|
+
return !failed;
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async function installDeps() {
|
|
54
|
+
const packages = ['@anthropic-ai/claude-code', '@musistudio/claude-code-router'];
|
|
55
|
+
const usePnpm = await commandExists('pnpm');
|
|
56
|
+
if (usePnpm) {
|
|
57
|
+
console.log('pnpm detected. Installing dependencies with pnpm...');
|
|
58
|
+
await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' });
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.log('pnpm not found. Falling back to npm...');
|
|
62
|
+
await (0, execa_1.execa)('npm', ['install', '-g', ...packages], { stdio: 'inherit' });
|
|
63
|
+
}
|
|
64
|
+
console.log('Dependencies installed successfully.');
|
|
65
|
+
}
|
|
66
|
+
function getCodexConfigDir() {
|
|
67
|
+
return path.join(os.homedir(), '.codex');
|
|
68
|
+
}
|
|
69
|
+
const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
|
|
70
|
+
model = "gpt-5"
|
|
71
|
+
model_reasoning_effort = "high"
|
|
72
|
+
disable_response_storage = true
|
|
73
|
+
preferred_auth_method = "apikey"
|
|
74
|
+
|
|
75
|
+
[model_providers.jw]
|
|
76
|
+
name = "jw"
|
|
77
|
+
base_url = "https://ai.gengjiawen.com/api/openai"
|
|
78
|
+
wire_api = "responses"
|
|
79
|
+
`;
|
|
80
|
+
function writeCodexConfig(apiKey) {
|
|
81
|
+
const configDir = getCodexConfigDir();
|
|
82
|
+
ensureDir(configDir);
|
|
83
|
+
const configPath = path.join(configDir, 'config.toml');
|
|
84
|
+
fs.writeFileSync(configPath, CODEX_CONFIG_TOML_TEMPLATE);
|
|
85
|
+
const authPath = path.join(configDir, 'auth.json');
|
|
86
|
+
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2);
|
|
87
|
+
fs.writeFileSync(authPath, authContent);
|
|
88
|
+
return { configPath, authPath };
|
|
89
|
+
}
|
|
90
|
+
async function installCodexDeps() {
|
|
91
|
+
const packages = ['@openai/codex'];
|
|
92
|
+
const usePnpm = await commandExists('pnpm');
|
|
93
|
+
if (usePnpm) {
|
|
94
|
+
console.log('pnpm detected. Installing Codex dependency with pnpm...');
|
|
95
|
+
await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' });
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
console.log('pnpm not found. Falling back to npm...');
|
|
99
|
+
await (0, execa_1.execa)('npm', ['install', '-g', ...packages], { stdio: 'inherit' });
|
|
100
|
+
}
|
|
101
|
+
console.log('Codex dependency installed successfully.');
|
|
102
|
+
}
|
package/libs/index.ts
CHANGED
|
@@ -72,3 +72,51 @@ export async function installDeps(): Promise<void> {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
|
|
75
|
+
/** Return Codex configuration directory path */
|
|
76
|
+
function getCodexConfigDir(): string {
|
|
77
|
+
return path.join(os.homedir(), '.codex')
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Template for Codex config.toml */
|
|
81
|
+
const CODEX_CONFIG_TOML_TEMPLATE = `model_provider = "jw"
|
|
82
|
+
model = "gpt-5"
|
|
83
|
+
model_reasoning_effort = "high"
|
|
84
|
+
disable_response_storage = true
|
|
85
|
+
preferred_auth_method = "apikey"
|
|
86
|
+
|
|
87
|
+
[model_providers.jw]
|
|
88
|
+
name = "jw"
|
|
89
|
+
base_url = "https://ai.gengjiawen.com/api/openai"
|
|
90
|
+
wire_api = "responses"
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
/** Write Codex config.toml and auth.json */
|
|
94
|
+
export function writeCodexConfig(apiKey: string): { configPath: string; authPath: string } {
|
|
95
|
+
const configDir = getCodexConfigDir()
|
|
96
|
+
ensureDir(configDir)
|
|
97
|
+
|
|
98
|
+
const configPath = path.join(configDir, 'config.toml')
|
|
99
|
+
fs.writeFileSync(configPath, CODEX_CONFIG_TOML_TEMPLATE)
|
|
100
|
+
|
|
101
|
+
const authPath = path.join(configDir, 'auth.json')
|
|
102
|
+
const authContent = JSON.stringify({ OPENAI_API_KEY: apiKey }, null, 2)
|
|
103
|
+
fs.writeFileSync(authPath, authContent)
|
|
104
|
+
|
|
105
|
+
return { configPath, authPath }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Install Codex dependency */
|
|
109
|
+
export async function installCodexDeps(): Promise<void> {
|
|
110
|
+
const packages = ['@openai/codex']
|
|
111
|
+
const usePnpm = await commandExists('pnpm')
|
|
112
|
+
|
|
113
|
+
if (usePnpm) {
|
|
114
|
+
console.log('pnpm detected. Installing Codex dependency with pnpm...')
|
|
115
|
+
await execa('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' })
|
|
116
|
+
} else {
|
|
117
|
+
console.log('pnpm not found. Falling back to npm...')
|
|
118
|
+
await execa('npm', ['install', '-g', ...packages], { stdio: 'inherit' })
|
|
119
|
+
}
|
|
120
|
+
console.log('Codex dependency installed successfully.')
|
|
121
|
+
}
|
|
122
|
+
|