api-switch-cc 0.2.2

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.
Files changed (3) hide show
  1. package/README.md +31 -0
  2. package/install.js +114 -0
  3. package/package.json +42 -0
package/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # api-switch-cc
2
+
3
+ > Claude Code 多模型代理 — 一键切换 DeepSeek、Qwen(通义千问)、GLM(智谱)、Moonshot(月之暗面)等国产大模型。协议自动转换,零配置即用。
4
+ > LLM API proxy for Claude Code — route to DeepSeek, Qwen, GLM, Moonshot and more with automatic protocol conversion.
5
+
6
+ ```
7
+ npm install -g api-switch-cc
8
+
9
+ api-switch provider add deepseek --key sk-xxx
10
+ api-switch use deepseek-chat
11
+ api-switch serve
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```bash
17
+ # Install globally
18
+ npm install -g api-switch-cc
19
+
20
+ # Or run directly
21
+ npx api-switch-cc provider add qwen --key sk-xxx
22
+ npx api-switch-cc serve
23
+ ```
24
+
25
+ See the [full documentation](https://github.com/hxz0727/API-Switch) on GitHub.
26
+
27
+ ## Supported platforms
28
+
29
+ - Linux (amd64, arm64)
30
+ - macOS (amd64, arm64)
31
+ - Windows (amd64)
package/install.js ADDED
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * API-Switch — binary downloader & launcher
5
+ *
6
+ * On postinstall, downloads the correct pre-built binary for the
7
+ * current platform from GitHub Releases and caches it locally.
8
+ *
9
+ * Usage: npx api-switch-cc <command>
10
+ * npm install -g api-switch-cc && api-switch serve
11
+ */
12
+
13
+ "use strict";
14
+
15
+ const { existsSync, mkdirSync, chmodSync, unlinkSync } = require("fs");
16
+ const { join } = require("path");
17
+ const { execSync } = require("child_process");
18
+
19
+ const PKG = require("./package.json");
20
+ // Download version — points to the GitHub release tag independent of npm version
21
+ const DOWNLOAD_VERSION = "v0.2.0";
22
+ const BASE = `https://github.com/hxz0727/API-Switch/releases/download/${DOWNLOAD_VERSION}`;
23
+ const BIN_DIR = join(__dirname, "bin");
24
+
25
+ // ── Platform detection ──────────────────────────────
26
+ function platform() {
27
+ const map = {
28
+ "darwin-x64": "darwin-amd64",
29
+ "darwin-arm64": "darwin-arm64",
30
+ "linux-x64": "linux-amd64",
31
+ "linux-arm64": "linux-arm64",
32
+ "win32-x64": "windows-amd64",
33
+ };
34
+ const key = `${process.platform}-${process.arch}`;
35
+ if (!map[key]) {
36
+ console.error(`Unsupported platform: ${process.platform} ${process.arch}`);
37
+ process.exit(1);
38
+ }
39
+ return map[key];
40
+ }
41
+
42
+ function binaryName() {
43
+ if (process.platform === "win32") return "api-switch.exe";
44
+ return "api-switch";
45
+ }
46
+
47
+ function archivedBinaryName() {
48
+ return `api-switch-${platform()}${process.platform === "win32" ? ".exe" : ""}`;
49
+ }
50
+
51
+ // ── Download & extract ──────────────────────────────
52
+ function install() {
53
+ const binName = binaryName();
54
+ const binPath = join(BIN_DIR, binName);
55
+
56
+ // Skip if binary exists and is fresh
57
+ if (existsSync(binPath)) {
58
+ return;
59
+ }
60
+
61
+ mkdirSync(BIN_DIR, { recursive: true });
62
+
63
+ const plat = platform();
64
+ const isWin = process.platform === "win32";
65
+ const archive = `api-switch-${plat}${isWin ? ".zip" : ".tar.gz"}`;
66
+ const url = `${BASE}/${archive}`;
67
+ const tmp = join(__dirname, `_${archive}`);
68
+
69
+ console.log(`Downloading api-switch v${DOWNLOAD_VERSION} for ${plat} ...`);
70
+
71
+ try {
72
+ // Download
73
+ execSync(`curl -sSL "${url}" -o "${tmp}"`, { stdio: "pipe" });
74
+
75
+ // Extract (archive contains binary named api-switch-<plat>)
76
+ const archiveBin = archivedBinaryName();
77
+ if (isWin) {
78
+ execSync(`unzip -o "${tmp}" "${archiveBin}" -d "${BIN_DIR}"`, { stdio: "pipe" });
79
+ } else {
80
+ execSync(`tar xzf "${tmp}" -C "${BIN_DIR}" "${archiveBin}"`, { stdio: "pipe" });
81
+ }
82
+
83
+ // Rename to simple binary name (e.g. api-switch-linux-amd64 → api-switch)
84
+ const extractedPath = join(BIN_DIR, archiveBin);
85
+ if (extractedPath !== binPath) {
86
+ execSync(`mv "${extractedPath}" "${binPath}"`, { stdio: "pipe" });
87
+ }
88
+
89
+ chmodSync(binPath, 0o755);
90
+ unlinkSync(tmp);
91
+
92
+ console.log(`Installed to ${binPath}`);
93
+ } catch (err) {
94
+ console.error(`Download failed: ${err.message}`);
95
+ console.log("Falling back to source build (requires Go)...");
96
+ execSync(
97
+ `cd ${join(__dirname, "..")} && go build -ldflags="-s -w" -o "${binPath}" ./cmd/api-switch/`,
98
+ { stdio: "inherit" }
99
+ );
100
+ }
101
+ }
102
+
103
+ // Run on postinstall
104
+ if (process.argv[2] === "postinstall") {
105
+ install();
106
+ process.exit(0);
107
+ }
108
+
109
+ // When run as CLI: execute the binary
110
+ const binPath = join(BIN_DIR, binaryName());
111
+ const result = require("child_process").spawnSync(binPath, process.argv.slice(2), {
112
+ stdio: "inherit",
113
+ });
114
+ process.exit(result.status ?? 1);
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "api-switch-cc",
3
+ "version": "0.2.2",
4
+ "description": "Claude Code 多模型代理 — 一键切换 DeepSeek、Qwen、GLM、Moonshot 等国产大模型,协议自动转换,零配置即用。LLM API proxy for Claude Code with DeepSeek, Qwen, Anthropic, OpenAI support.",
5
+ "bin": {
6
+ "api-switch": "bin/api-switch"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node install.js",
10
+ "postupdate": "node install.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/hxz0727/API-Switch.git"
15
+ },
16
+ "keywords": [
17
+ "claude",
18
+ "claude-code",
19
+ "llm",
20
+ "proxy",
21
+ "deepseek",
22
+ "qwen",
23
+ "moonshot",
24
+ "glm",
25
+ "openai",
26
+ "anthropic",
27
+ "api-gateway",
28
+ "ai-proxy",
29
+ "国产大模型",
30
+ "通义千问",
31
+ "智谱",
32
+ "月之暗面",
33
+ "deep-seek"
34
+ ],
35
+ "license": "MIT",
36
+ "bugs": {
37
+ "url": "https://github.com/hxz0727/API-Switch/issues"
38
+ },
39
+ "homepage": "https://github.com/hxz0727/API-Switch#readme",
40
+ "os": ["darwin", "linux", "win32"],
41
+ "cpu": ["x64", "arm64"]
42
+ }