@hxz0727/api-switch-cc 0.1.0

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 +30 -0
  2. package/install.js +114 -0
  3. package/package.json +32 -0
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @hxz0727/api-switch-cc
2
+
3
+ > LLM API proxy for Claude Code — route to DeepSeek, Qwen, GLM, and more.
4
+
5
+ ```
6
+ npm install -g @hxz0727/api-switch-cc
7
+
8
+ api-switch provider add deepseek --key sk-xxx
9
+ api-switch use deepseek-chat
10
+ api-switch serve
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```bash
16
+ # Install globally
17
+ npm install -g @hxz0727/api-switch-cc
18
+
19
+ # Or run directly
20
+ npx @hxz0727/api-switch-cc provider add qwen --key sk-xxx
21
+ npx @hxz0727/api-switch-cc serve
22
+ ```
23
+
24
+ See the [full documentation](https://github.com/hxz0727/API-Switch) on GitHub.
25
+
26
+ ## Supported platforms
27
+
28
+ - Linux (amd64, arm64)
29
+ - macOS (amd64, arm64)
30
+ - 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 = "v1.1.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,32 @@
1
+ {
2
+ "name": "@hxz0727/api-switch-cc",
3
+ "version": "0.1.0",
4
+ "description": "LLM API proxy for Claude Code — route to DeepSeek, Qwen, GLM, and more",
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
+ "openai"
24
+ ],
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/hxz0727/API-Switch/issues"
28
+ },
29
+ "homepage": "https://github.com/hxz0727/API-Switch#readme",
30
+ "os": ["darwin", "linux", "win32"],
31
+ "cpu": ["x64", "arm64"]
32
+ }