@wwkit/llmproxy 1.0.1 → 1.0.3
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/package.json +4 -4
- package/src/set.js +20 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wwkit/llmproxy",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"author": "bluesliu <langcai163@163.com>",
|
|
5
5
|
"description": "Generic OpenAI-compatible proxy for multiple LLM providers (codearts, ...). Pluggable via config.json5.",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"json5": "^2.2.3",
|
|
23
23
|
"undici": "^8.10.1",
|
|
24
|
-
"@wwkit/cft": "1.0.
|
|
25
|
-
"@wwkit/shared": "1.0.
|
|
24
|
+
"@wwkit/cft": "1.0.4",
|
|
25
|
+
"@wwkit/shared": "1.0.4"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
"login": "node bin/index.js login",
|
|
39
39
|
"dev": "node src/server.js",
|
|
40
40
|
"test": "node --test",
|
|
41
|
-
"release": "
|
|
41
|
+
"release": "node ../../packages/shared/bin/release-pkg.js"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/src/set.js
CHANGED
|
@@ -8,10 +8,15 @@ import { config, getProviderIds, getProviderConfig } from './config.js'
|
|
|
8
8
|
const SUPPORTED_TARGETS = ['opencode']
|
|
9
9
|
const OPENCODE_PATH = path.join(os.homedir(), '.config/opencode/opencode.jsonc')
|
|
10
10
|
|
|
11
|
+
// opencode 不支持 provider 名含 /,统一替换为 -
|
|
12
|
+
function sanitizeProviderId(id) {
|
|
13
|
+
return id.replace(/\//g, '-')
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
function buildOpencodeEntry(providerId, providerConfig) {
|
|
12
17
|
return {
|
|
13
18
|
npm: "@ai-sdk/openai-compatible",
|
|
14
|
-
name: providerId,
|
|
19
|
+
name: sanitizeProviderId(providerId),
|
|
15
20
|
options: {
|
|
16
21
|
baseURL: `http://127.0.0.1:${config.port}/${providerId}/v1`,
|
|
17
22
|
apiKey: config.proxyApiKey || "noapikey",
|
|
@@ -60,20 +65,21 @@ export async function setProviderToTarget(providerId, target, { dryRun = false }
|
|
|
60
65
|
process.exit(1)
|
|
61
66
|
}
|
|
62
67
|
|
|
63
|
-
// 生成所有 provider
|
|
64
|
-
const entries =
|
|
68
|
+
// 生成所有 provider 条目(key 已 sanitize,baseURL 保留原始 id 的 /)
|
|
69
|
+
const entries = []
|
|
65
70
|
for (const id of providerIds) {
|
|
66
71
|
const providerConfig = getProviderConfig(id)
|
|
67
72
|
if (!providerConfig) {
|
|
68
73
|
console.error(`未知 provider: ${id},跳过`)
|
|
69
74
|
continue
|
|
70
75
|
}
|
|
71
|
-
|
|
76
|
+
const key = sanitizeProviderId(id)
|
|
77
|
+
entries.push({ id, key, entry: buildOpencodeEntry(id, providerConfig) })
|
|
72
78
|
}
|
|
73
79
|
|
|
74
80
|
// dry-run 模式:只打印配置
|
|
75
81
|
if (dryRun) {
|
|
76
|
-
console.log(JSON.stringify(entries, null, 2))
|
|
82
|
+
console.log(JSON.stringify(Object.fromEntries(entries.map(e => [e.key, e.entry])), null, 2))
|
|
77
83
|
return
|
|
78
84
|
}
|
|
79
85
|
|
|
@@ -84,15 +90,15 @@ export async function setProviderToTarget(providerId, target, { dryRun = false }
|
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
let added = 0, updated = 0
|
|
87
|
-
for (const
|
|
88
|
-
if (opencodeConfig.provider[
|
|
89
|
-
console.log(`更新: ${id}`)
|
|
93
|
+
for (const { id, key, entry } of entries) {
|
|
94
|
+
if (opencodeConfig.provider[key]) {
|
|
95
|
+
console.log(`更新: ${id}${key !== id ? ` → ${key}` : ''}`)
|
|
90
96
|
updated++
|
|
91
97
|
} else {
|
|
92
|
-
console.log(`新增: ${id}`)
|
|
98
|
+
console.log(`新增: ${id}${key !== id ? ` → ${key}` : ''}`)
|
|
93
99
|
added++
|
|
94
100
|
}
|
|
95
|
-
opencodeConfig.provider[
|
|
101
|
+
opencodeConfig.provider[key] = entry
|
|
96
102
|
}
|
|
97
103
|
|
|
98
104
|
saveOpencodeConfig(opencodeConfig)
|
|
@@ -118,13 +124,14 @@ export async function removeProviderFromTarget(providerId, target, { dryRun = fa
|
|
|
118
124
|
// 确定要删除的 provider 列表
|
|
119
125
|
let providerIds
|
|
120
126
|
if (providerId) {
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
const key = sanitizeProviderId(providerId)
|
|
128
|
+
if (!opencodeConfig.provider[key]) {
|
|
129
|
+
console.error(`opencode 中不存在 provider: ${providerId}${key !== providerId ? ` (key: ${key})` : ''}`)
|
|
123
130
|
const available = Object.keys(opencodeConfig.provider)
|
|
124
131
|
console.error(`可用: ${available.join(', ')}`)
|
|
125
132
|
process.exit(1)
|
|
126
133
|
}
|
|
127
|
-
providerIds = [
|
|
134
|
+
providerIds = [key]
|
|
128
135
|
} else {
|
|
129
136
|
providerIds = Object.keys(opencodeConfig.provider)
|
|
130
137
|
}
|