swixter 0.1.5 → 0.1.6
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/cli/index.js +73 -33
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -13999,7 +13999,7 @@ var CONFIG_VERSION = "2.0.0", EXPORT_VERSION = "1.0.0";
|
|
|
13999
13999
|
var init_versions2 = () => {};
|
|
14000
14000
|
|
|
14001
14001
|
// src/constants/meta.ts
|
|
14002
|
-
var APP_VERSION = "0.1.
|
|
14002
|
+
var APP_VERSION = "0.1.6";
|
|
14003
14003
|
var init_meta = () => {};
|
|
14004
14004
|
|
|
14005
14005
|
// src/constants/install.ts
|
|
@@ -18915,7 +18915,7 @@ var init_env_key_helper = __esm(() => {
|
|
|
18915
18915
|
});
|
|
18916
18916
|
|
|
18917
18917
|
// src/adapters/codex.ts
|
|
18918
|
-
import { mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4 } from "node:fs/promises";
|
|
18918
|
+
import { mkdir as mkdir4, readFile as readFile4, writeFile as writeFile4, unlink } from "node:fs/promises";
|
|
18919
18919
|
import { existsSync as existsSync4 } from "node:fs";
|
|
18920
18920
|
import { homedir as homedir2 } from "node:os";
|
|
18921
18921
|
import { join as join3, dirname as dirname4 } from "node:path";
|
|
@@ -18923,8 +18923,10 @@ import { join as join3, dirname as dirname4 } from "node:path";
|
|
|
18923
18923
|
class CodexAdapter {
|
|
18924
18924
|
name = "codex";
|
|
18925
18925
|
configPath;
|
|
18926
|
+
authPath;
|
|
18926
18927
|
constructor() {
|
|
18927
18928
|
this.configPath = join3(homedir2(), ".codex", "config.toml");
|
|
18929
|
+
this.authPath = join3(homedir2(), ".codex", "auth.json");
|
|
18928
18930
|
}
|
|
18929
18931
|
async apply(profile) {
|
|
18930
18932
|
try {
|
|
@@ -18962,6 +18964,7 @@ class CodexAdapter {
|
|
|
18962
18964
|
config2.model_provider = providerName;
|
|
18963
18965
|
const tomlContent = stringify(config2);
|
|
18964
18966
|
await writeFile4(this.configPath, tomlContent, "utf-8");
|
|
18967
|
+
await this.writeAuthJson(profile);
|
|
18965
18968
|
} catch (error46) {
|
|
18966
18969
|
throw new Error(`Failed to apply Codex configuration: ${error46 instanceof Error ? error46.message : String(error46)}`);
|
|
18967
18970
|
}
|
|
@@ -18984,6 +18987,22 @@ class CodexAdapter {
|
|
|
18984
18987
|
if (!config2.model_providers || !config2.model_providers[providerName]) {
|
|
18985
18988
|
return false;
|
|
18986
18989
|
}
|
|
18990
|
+
if (profile.apiKey) {
|
|
18991
|
+
const envKey = await getEnvKey(profile);
|
|
18992
|
+
if (existsSync4(this.authPath)) {
|
|
18993
|
+
try {
|
|
18994
|
+
const authContent = await readFile4(this.authPath, "utf-8");
|
|
18995
|
+
const auth = JSON.parse(authContent);
|
|
18996
|
+
if (auth[envKey] !== profile.apiKey) {
|
|
18997
|
+
return false;
|
|
18998
|
+
}
|
|
18999
|
+
} catch {
|
|
19000
|
+
return false;
|
|
19001
|
+
}
|
|
19002
|
+
} else {
|
|
19003
|
+
return false;
|
|
19004
|
+
}
|
|
19005
|
+
}
|
|
18987
19006
|
return true;
|
|
18988
19007
|
} catch (error46) {
|
|
18989
19008
|
return false;
|
|
@@ -18994,7 +19013,8 @@ class CodexAdapter {
|
|
|
18994
19013
|
const providerTable = {
|
|
18995
19014
|
name: preset.displayName,
|
|
18996
19015
|
base_url: profile.baseURL || baseUrl,
|
|
18997
|
-
wire_api:
|
|
19016
|
+
wire_api: "responses",
|
|
19017
|
+
requires_openai_auth: true
|
|
18998
19018
|
};
|
|
18999
19019
|
providerTable.env_key = await getEnvKey(profile);
|
|
19000
19020
|
if (preset.headers) {
|
|
@@ -19017,6 +19037,31 @@ class CodexAdapter {
|
|
|
19017
19037
|
}
|
|
19018
19038
|
return profileTable;
|
|
19019
19039
|
}
|
|
19040
|
+
async writeAuthJson(profile) {
|
|
19041
|
+
const envKey = await getEnvKey(profile);
|
|
19042
|
+
let auth = {};
|
|
19043
|
+
if (existsSync4(this.authPath)) {
|
|
19044
|
+
try {
|
|
19045
|
+
const content = await readFile4(this.authPath, "utf-8");
|
|
19046
|
+
const parsed = JSON.parse(content);
|
|
19047
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
19048
|
+
auth = parsed;
|
|
19049
|
+
}
|
|
19050
|
+
} catch {
|
|
19051
|
+
auth = {};
|
|
19052
|
+
}
|
|
19053
|
+
}
|
|
19054
|
+
if (profile.apiKey) {
|
|
19055
|
+
auth[envKey] = profile.apiKey;
|
|
19056
|
+
} else {
|
|
19057
|
+
delete auth[envKey];
|
|
19058
|
+
}
|
|
19059
|
+
if (Object.keys(auth).length > 0) {
|
|
19060
|
+
await writeFile4(this.authPath, JSON.stringify(auth, null, 2), "utf-8");
|
|
19061
|
+
} else if (existsSync4(this.authPath)) {
|
|
19062
|
+
await unlink(this.authPath);
|
|
19063
|
+
}
|
|
19064
|
+
}
|
|
19020
19065
|
async getEnvExportCommands(profile) {
|
|
19021
19066
|
const commands = await getEnvExportCommands(profile);
|
|
19022
19067
|
const modelValue = getOpenAIModel(profile);
|
|
@@ -19035,7 +19080,9 @@ class CodexAdapter {
|
|
|
19035
19080
|
const providerKey = `swixter-${profileName}`;
|
|
19036
19081
|
const profileKey = `swixter-${profileName}`;
|
|
19037
19082
|
let modified = false;
|
|
19083
|
+
let envKeyToRemove;
|
|
19038
19084
|
if (config2.model_providers && config2.model_providers[providerKey]) {
|
|
19085
|
+
envKeyToRemove = config2.model_providers[providerKey].env_key;
|
|
19039
19086
|
delete config2.model_providers[providerKey];
|
|
19040
19087
|
modified = true;
|
|
19041
19088
|
}
|
|
@@ -19052,6 +19099,14 @@ class CodexAdapter {
|
|
|
19052
19099
|
const tomlContent = stringify(config2);
|
|
19053
19100
|
await writeFile4(this.configPath, tomlContent, "utf-8");
|
|
19054
19101
|
}
|
|
19102
|
+
if (envKeyToRemove && existsSync4(this.authPath)) {
|
|
19103
|
+
try {
|
|
19104
|
+
const authContent = await readFile4(this.authPath, "utf-8");
|
|
19105
|
+
const auth = JSON.parse(authContent);
|
|
19106
|
+
delete auth[envKeyToRemove];
|
|
19107
|
+
await writeFile4(this.authPath, JSON.stringify(auth, null, 2), "utf-8");
|
|
19108
|
+
} catch {}
|
|
19109
|
+
}
|
|
19055
19110
|
} catch (error46) {
|
|
19056
19111
|
console.warn(`Failed to remove profile from Codex config: ${error46}`);
|
|
19057
19112
|
}
|
|
@@ -26529,7 +26584,7 @@ var init_client = __esm(() => {
|
|
|
26529
26584
|
|
|
26530
26585
|
// src/auth/token.ts
|
|
26531
26586
|
import { existsSync as existsSync13 } from "node:fs";
|
|
26532
|
-
import { readFile as readFile10, writeFile as writeFile9, unlink as
|
|
26587
|
+
import { readFile as readFile10, writeFile as writeFile9, unlink as unlink4 } from "node:fs/promises";
|
|
26533
26588
|
import { join as join11 } from "node:path";
|
|
26534
26589
|
function getAuthFilePath() {
|
|
26535
26590
|
return join11(getConfigDir("swixter"), AUTH_FILE);
|
|
@@ -26552,7 +26607,7 @@ async function saveAuthState(state) {
|
|
|
26552
26607
|
async function clearAuthState() {
|
|
26553
26608
|
const authPath = getAuthFilePath();
|
|
26554
26609
|
if (existsSync13(authPath)) {
|
|
26555
|
-
await
|
|
26610
|
+
await unlink4(authPath);
|
|
26556
26611
|
}
|
|
26557
26612
|
}
|
|
26558
26613
|
function isExpired(expiresAt) {
|
|
@@ -28655,8 +28710,8 @@ async function cmdCreateInteractive3() {
|
|
|
28655
28710
|
console.log();
|
|
28656
28711
|
console.log(import_picocolors10.default.bold(import_picocolors10.default.cyan(PROMPTS.createProfile(CODER_CONFIG3.displayName))));
|
|
28657
28712
|
console.log();
|
|
28658
|
-
const {
|
|
28659
|
-
const presets = await
|
|
28713
|
+
const { getAllPresets: getAllPresets2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
|
|
28714
|
+
const presets = await getAllPresets2();
|
|
28660
28715
|
const name = await he({
|
|
28661
28716
|
message: PROMPTS.configName,
|
|
28662
28717
|
placeholder: DEFAULT_PLACEHOLDERS.configName,
|
|
@@ -28824,12 +28879,6 @@ async function cmdCreateQuiet3(params) {
|
|
|
28824
28879
|
console.log(import_picocolors10.default.dim("Run 'swixter providers' to see all supported providers"));
|
|
28825
28880
|
process.exit(1);
|
|
28826
28881
|
}
|
|
28827
|
-
if (preset.wire_api !== "chat") {
|
|
28828
|
-
console.log(import_picocolors10.default.red(`Error: Provider "${preset.displayName}" is not compatible with ${CODER_CONFIG3.displayName}`));
|
|
28829
|
-
console.log(import_picocolors10.default.dim(`${CODER_CONFIG3.displayName} only supports OpenAI-compatible providers (chat API).`));
|
|
28830
|
-
console.log(import_picocolors10.default.dim("Use 'ollama' or 'custom' provider instead."));
|
|
28831
|
-
process.exit(1);
|
|
28832
|
-
}
|
|
28833
28882
|
if (params.provider !== "ollama" && !params["api-key"]) {
|
|
28834
28883
|
console.log(import_picocolors10.default.red("Error: This provider requires --api-key parameter"));
|
|
28835
28884
|
process.exit(1);
|
|
@@ -28993,8 +29042,8 @@ async function cmdEdit3(profileName) {
|
|
|
28993
29042
|
console.log();
|
|
28994
29043
|
console.log(import_picocolors10.default.bold(import_picocolors10.default.cyan(`Edit profile: ${profileName}`)));
|
|
28995
29044
|
console.log();
|
|
28996
|
-
const {
|
|
28997
|
-
const presets = await
|
|
29045
|
+
const { getAllPresets: getAllPresets2 } = await Promise.resolve().then(() => (init_presets(), exports_presets));
|
|
29046
|
+
const presets = await getAllPresets2();
|
|
28998
29047
|
const currentPreset = await getPresetByIdAsync(profile.providerId);
|
|
28999
29048
|
const shouldChangeProvider = await ye({
|
|
29000
29049
|
message: `Change provider? Current: ${currentPreset?.displayName}`,
|
|
@@ -29184,19 +29233,10 @@ async function cmdApply3() {
|
|
|
29184
29233
|
console.log(` Provider: ${import_picocolors10.default.yellow(preset?.displayName)}`);
|
|
29185
29234
|
console.log(` Config file: ${import_picocolors10.default.dim(adapter.configPath)}`);
|
|
29186
29235
|
console.log();
|
|
29187
|
-
|
|
29188
|
-
|
|
29189
|
-
|
|
29190
|
-
|
|
29191
|
-
console.log();
|
|
29192
|
-
envCommands.forEach((cmd) => {
|
|
29193
|
-
console.log(` ${import_picocolors10.default.green(cmd)}`);
|
|
29194
|
-
});
|
|
29195
|
-
console.log();
|
|
29196
|
-
console.log(import_picocolors10.default.dim(`Then run: ${import_picocolors10.default.cyan("codex")}`));
|
|
29197
|
-
console.log();
|
|
29198
|
-
}
|
|
29199
|
-
}
|
|
29236
|
+
console.log(import_picocolors10.default.bold("Run Codex now: ") + import_picocolors10.default.cyan("codex"));
|
|
29237
|
+
console.log();
|
|
29238
|
+
console.log(import_picocolors10.default.dim("Environment variables are automatically managed via auth.json."));
|
|
29239
|
+
console.log();
|
|
29200
29240
|
} else {
|
|
29201
29241
|
console.log(import_picocolors10.default.yellow("⚠ Profile written, but verification failed"));
|
|
29202
29242
|
console.log(import_picocolors10.default.dim("Please check config file format"));
|
|
@@ -30112,7 +30152,7 @@ init_versions2();
|
|
|
30112
30152
|
init_paths();
|
|
30113
30153
|
init_export();
|
|
30114
30154
|
import { existsSync as existsSync9, statSync as statSync2 } from "node:fs";
|
|
30115
|
-
import { readFile as readFile8, writeFile as writeFile7, unlink } from "node:fs/promises";
|
|
30155
|
+
import { readFile as readFile8, writeFile as writeFile7, unlink as unlink2 } from "node:fs/promises";
|
|
30116
30156
|
import { join as join8 } from "node:path";
|
|
30117
30157
|
async function getVersion(req, res) {
|
|
30118
30158
|
sendJson(res, {
|
|
@@ -30175,7 +30215,7 @@ async function exportConfigFile(req, res) {
|
|
|
30175
30215
|
res.end(content);
|
|
30176
30216
|
} finally {
|
|
30177
30217
|
try {
|
|
30178
|
-
await
|
|
30218
|
+
await unlink2(tempPath);
|
|
30179
30219
|
} catch {}
|
|
30180
30220
|
}
|
|
30181
30221
|
} catch (error46) {
|
|
@@ -30197,7 +30237,7 @@ async function importConfigFile(req, res) {
|
|
|
30197
30237
|
sendJson(res, { success: true, ...result });
|
|
30198
30238
|
} finally {
|
|
30199
30239
|
try {
|
|
30200
|
-
await
|
|
30240
|
+
await unlink2(tempPath);
|
|
30201
30241
|
} catch {}
|
|
30202
30242
|
}
|
|
30203
30243
|
} catch (error46) {
|
|
@@ -30546,7 +30586,7 @@ async function startServer(portArg, options) {
|
|
|
30546
30586
|
// src/utils/daemon.ts
|
|
30547
30587
|
init_paths();
|
|
30548
30588
|
import { existsSync as existsSync12 } from "node:fs";
|
|
30549
|
-
import { readFile as readFile9, writeFile as writeFile8, unlink as
|
|
30589
|
+
import { readFile as readFile9, writeFile as writeFile8, unlink as unlink3 } from "node:fs/promises";
|
|
30550
30590
|
import { join as join10 } from "node:path";
|
|
30551
30591
|
function getPidFilePath() {
|
|
30552
30592
|
return join10(getConfigDir("swixter"), "ui.pid");
|
|
@@ -30573,7 +30613,7 @@ async function writePidFile(pid, port) {
|
|
|
30573
30613
|
async function removePidFile() {
|
|
30574
30614
|
const path = getPidFilePath();
|
|
30575
30615
|
if (existsSync12(path)) {
|
|
30576
|
-
await
|
|
30616
|
+
await unlink3(path).catch(() => {});
|
|
30577
30617
|
}
|
|
30578
30618
|
}
|
|
30579
30619
|
function isProcessAlive2(pid) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swixter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "CLI tool for managing AI coding assistant configurations - easily switch between providers (Claude Code, Codex, Continue) with Anthropic, Ollama, or custom APIs",
|
|
5
5
|
"main": "dist/cli/index.js",
|
|
6
6
|
"module": "dist/cli/index.js",
|