@botconnector/bccli 0.1.0-beta.3 → 0.2.0-beta.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/bccli.js DELETED
@@ -1,173 +0,0 @@
1
- #!/usr/bin/env node
2
- // No postinstall/download step: npm installs exactly one of the
3
- // optionalDependencies platform packages (matched by "os"/"cpu" in each
4
- // package.json), and this launcher just execs whichever binary landed
5
- // in node_modules. If neither installed (unsupported platform, or npm
6
- // skipped optional deps), we say so clearly instead of failing silently.
7
-
8
- const fs = require("fs")
9
- const os = require("os")
10
- const path = require("path")
11
- const { spawnSync } = require("child_process")
12
-
13
- const PLATFORM_PACKAGES = {
14
- win32: { pkg: "bccli-win32-x64", binName: "bccli.exe" },
15
- linux: { pkg: "bccli-linux-x64", binName: "bccli" },
16
- }
17
-
18
- // Seed the BotConnector Gateway provider config on first run. BotConnector
19
- // keeps its own config under ~/.config/botconnector. The seed is copied once;
20
- // a narrow migration below only updates fields that exactly match our old
21
- // generated defaults, preserving user changes.
22
- function seedDefaultConfig() {
23
- try {
24
- const configDir = path.join(os.homedir(), ".config", "botconnector")
25
- const dest = path.join(configDir, "botconnector-cloud.jsonc")
26
- if (!fs.existsSync(dest)) {
27
- const src = path.join(__dirname, "..", "default-config", "botconnector-cloud.jsonc")
28
- if (fs.existsSync(src)) {
29
- fs.mkdirSync(configDir, { recursive: true })
30
- fs.copyFileSync(src, dest)
31
- }
32
- }
33
- return dest
34
- } catch {
35
- return undefined
36
- }
37
- }
38
-
39
- function migrateDefaultConfig() {
40
- try {
41
- const dest = path.join(os.homedir(), ".config", "botconnector", "botconnector-cloud.jsonc")
42
- if (!fs.existsSync(dest)) return
43
-
44
- const raw = fs.readFileSync(dest, "utf8")
45
- const config = JSON.parse(raw)
46
- const provider = config?.provider?.botconnector
47
- if (!provider || typeof provider !== "object") return
48
-
49
- let changed = false
50
- if (provider.name === "BotConnector Cloud") {
51
- provider.name = "BotConnector Gateway"
52
- changed = true
53
- }
54
-
55
- const options = provider.options
56
- if (
57
- options &&
58
- typeof options === "object" &&
59
- options.apiKey === "{env:BOTCONNECTOR_API_KEY}"
60
- ) {
61
- delete options.apiKey
62
- changed = true
63
- }
64
-
65
- if (!Array.isArray(provider.env)) {
66
- provider.env = ["BOTCONNECTOR_API_KEY"]
67
- changed = true
68
- } else if (!provider.env.includes("BOTCONNECTOR_API_KEY")) {
69
- provider.env.push("BOTCONNECTOR_API_KEY")
70
- changed = true
71
- }
72
-
73
- // BotConnector Gateway owns its model catalog. Remove any persisted model
74
- // snapshot from older releases so stale IDs can never override GET /v1/models.
75
- if (
76
- !provider.models ||
77
- typeof provider.models !== "object" ||
78
- Array.isArray(provider.models) ||
79
- Object.keys(provider.models).length > 0
80
- ) {
81
- provider.models = {}
82
- changed = true
83
- }
84
-
85
- // 0.1.8-0.1.11 injected an exact { edit: "ask", bash: "ask" }
86
- // permission block into generated configs. Remove only that proven legacy
87
- // shape so existing users regain upstream upstream engine defaults without
88
- // clobbering any custom permission policy.
89
- const permission = config.permission
90
- if (
91
- permission &&
92
- typeof permission === "object" &&
93
- !Array.isArray(permission) &&
94
- Object.keys(permission).length === 2 &&
95
- permission.edit === "ask" &&
96
- permission.bash === "ask"
97
- ) {
98
- delete config.permission
99
- changed = true
100
- }
101
-
102
- config.provider ??= {}
103
- if (!config.provider.ollama) {
104
- config.provider.ollama = {
105
- npm: "@ai-sdk/openai-compatible",
106
- name: "Ollama Local",
107
- options: { baseURL: "http://127.0.0.1:11434/v1" },
108
- models: {},
109
- }
110
- changed = true
111
- }
112
-
113
- if (changed) fs.writeFileSync(dest, JSON.stringify(config, null, 2) + "\n")
114
- } catch {
115
- // Never block the CLI for a best-effort migration. JSONC/user-customized
116
- // files that are not valid JSON are left untouched.
117
- }
118
- }
119
-
120
- function resolveBinary() {
121
- const entry = PLATFORM_PACKAGES[process.platform]
122
- if (!entry) {
123
- console.error(
124
- `bccli: unsupported platform "${process.platform}". Windows and Linux (x64) are the only prebuilt targets right now.`,
125
- )
126
- process.exit(1)
127
- }
128
- try {
129
- const pkgJsonPath = require.resolve(`${entry.pkg}/package.json`)
130
- return path.join(path.dirname(pkgJsonPath), entry.binName)
131
- } catch {
132
- console.error(
133
- `bccli: could not find ${entry.pkg} in node_modules.\n` +
134
- `This usually means optional dependencies were skipped during install.\n` +
135
- `Try: npm install bccli --include=optional`,
136
- )
137
- process.exit(1)
138
- }
139
- }
140
-
141
- const seededConfig = seedDefaultConfig()
142
- migrateDefaultConfig()
143
-
144
- const binPath = resolveBinary()
145
- const env = { ...process.env }
146
-
147
- // BotConnector owns config resolution. Legacy upstream engine config variables from
148
- // older installs must never silently override BotConnector's canonical config.
149
- delete env.OPENCODE_CONFIG
150
- delete env.OPENCODE_CONFIG_DIR
151
- delete env.OPENCODE_CONFIG_CONTENT
152
-
153
- if (!env.BOTCONNECTOR_CONFIG && seededConfig && fs.existsSync(seededConfig)) {
154
- env.BOTCONNECTOR_CONFIG = seededConfig
155
- }
156
-
157
- // Canonical BotConnector server envs. Legacy aliases are only an internal
158
- // compatibility bridge for the embedded runtime.
159
- if (env.BOTCONNECTOR_SERVER_USERNAME && !env.OPENCODE_SERVER_USERNAME) {
160
- env.OPENCODE_SERVER_USERNAME = env.BOTCONNECTOR_SERVER_USERNAME
161
- }
162
- if (env.BOTCONNECTOR_SERVER_PASSWORD && !env.OPENCODE_SERVER_PASSWORD) {
163
- env.OPENCODE_SERVER_PASSWORD = env.BOTCONNECTOR_SERVER_PASSWORD
164
- }
165
-
166
- const result = spawnSync(binPath, process.argv.slice(2), { stdio: "inherit", env })
167
-
168
- if (result.error) {
169
- console.error(`bccli: failed to launch ${binPath}: ${result.error.message}`)
170
- process.exit(1)
171
- }
172
-
173
- process.exit(result.status ?? 1)
@@ -1,21 +0,0 @@
1
- {
2
- "provider": {
3
- "botconnector": {
4
- "npm": "@ai-sdk/openai-compatible",
5
- "name": "BotConnector Gateway",
6
- "env": ["BOTCONNECTOR_API_KEY"],
7
- "options": {
8
- "baseURL": "https://api.botconnector.id/v1"
9
- },
10
- "models": {}
11
- },
12
- "ollama": {
13
- "npm": "@ai-sdk/openai-compatible",
14
- "name": "Ollama Local",
15
- "options": {
16
- "baseURL": "http://127.0.0.1:11434/v1"
17
- },
18
- "models": {}
19
- }
20
- }
21
- }