magpie-plugin-codez 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +66 -2
- package/codez.js +168 -0
- package/index.js +6 -0
- package/package.json +30 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zwenooo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# codez
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
把 [CodeZ](https://codezsy.com) 加成 magpie 的供应商,用 API 密钥登录。
|
|
4
|
+
|
|
5
|
+
- 模型列表来自每把密钥自己的 `/v1/models`:一把密钥属于 CodeZ 的一个分组,
|
|
6
|
+
只列这个分组能用的模型。多把密钥(比如 gpt 分组、国模分组、gemini 分组)
|
|
7
|
+
都登录在同一个 CodeZ 供应商下,请求会发给列着这个模型的那把。
|
|
8
|
+
- 每个模型走哪个接口(和 zwenooo/magpie fork 的 CodeZ 预设一样):
|
|
9
|
+
- GPT、Codex、o 系列走 Responses。CodeZ 原生支持,它的模型列表里却只标了
|
|
10
|
+
`openai`(Chat);
|
|
11
|
+
- Claude 走 Messages;
|
|
12
|
+
- 其他模型走 Chat completions。
|
|
13
|
+
|
|
14
|
+
CodeZ 列表里标出的其他接口写进 `also`:客户端用那些接口发来的请求原样转发,
|
|
15
|
+
不做翻译。
|
|
16
|
+
- 用量:CodeZ 不通过 API 公开密钥的额度(`quota_details_hidden`),所以只检查
|
|
17
|
+
密钥是否可用。余额去 codezsy.com 看。
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
在 magpie 的插件页搜索 CodeZ 安装(npm 包 `magpie-plugin-codez`),或者:
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
magpie plugin add magpie-plugin-codez
|
|
25
|
+
magpie plugin login codez # 粘贴 API 密钥;每把密钥登录一次
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
也可以直接从 GitHub 装:`magpie plugin add github:zwenooo/magpie-codez`。
|
|
29
|
+
|
|
30
|
+
密钥在 <https://codezsy.com/console/token>。
|
|
31
|
+
|
|
32
|
+
## 和手动加的 CodeZ 供应商并存
|
|
33
|
+
|
|
34
|
+
如果 magpie 里已经有一个 id 为 `codez` 的供应商(fork 的 CodeZ 预设,或者手动
|
|
35
|
+
加的中转站),插件的供应商会叫 `codez-plugin`,两者互不影响。把旧的删掉之后,
|
|
36
|
+
插件的供应商就叫 `codez`,模型名仍是 `codez/<模型>`,原来按这个名字挑的模型
|
|
37
|
+
还能对上。
|
|
38
|
+
|
|
39
|
+
## 注意
|
|
40
|
+
|
|
41
|
+
- 模型的上下文长度和价格 CodeZ 的列表里没有,插件不填(显示为未知)。
|
|
42
|
+
- 一个供应商超过 24 个模型、又没有挑选时,magpie 只先放出前 24 个。用
|
|
43
|
+
`magpie provider models codez +<模型>` 或在供应商页里挑。
|
|
44
|
+
|
|
45
|
+
## 开发
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
bun test
|
|
49
|
+
magpie plugin add <本文件夹>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 版本
|
|
53
|
+
|
|
54
|
+
从 npm 装的跟着 npm 上的 `latest`。从 GitHub 装(不带 `#…`)的跟着 `main`,有新提交时
|
|
55
|
+
magpie 提示更新;要固定某个版本,用 `github:zwenooo/magpie-codez#v<版本>`。
|
|
56
|
+
|
|
57
|
+
发布新版本:改好、提交后,把 `package.json` 的 version 提上去,提交,再
|
|
58
|
+
`git tag v<版本> && git push origin main v<版本>`,最后 `npm publish`。npm 和 tag 的版本
|
|
59
|
+
要一致。
|
|
60
|
+
|
|
61
|
+
这个插件原先在 [zwenooo/magpie-plugins](https://github.com/zwenooo/magpie-home)(现已改名为 magpie-home)
|
|
62
|
+
的 `packages/codez` 里(最后一版是 tag `codez-v0.1.0`),2026-11-25 拆成了独立仓库。
|
|
63
|
+
那边还有 skill 和这些插件的来龙去脉(`docs/roadmap.md`)。
|
|
64
|
+
|
|
65
|
+
## 许可
|
|
66
|
+
|
|
67
|
+
MIT
|
package/codez.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// CodeZ (codezsy.com) as a provider in magpie, signed in with an API key.
|
|
2
|
+
//
|
|
3
|
+
// CodeZ is a new-api relay at https://api.codezsy.com. One key reaches the
|
|
4
|
+
// models of its group: GET /v1/models lists them, each with the APIs CodeZ
|
|
5
|
+
// says it serves it on (supported_endpoint_types: "openai" is chat
|
|
6
|
+
// completions, "openai-response" the Responses API, "anthropic" Messages).
|
|
7
|
+
//
|
|
8
|
+
// Which API a model is asked on, as the zwenooo/magpie fork's CodeZ preset
|
|
9
|
+
// did: an OpenAI model (gpt-…, codex…, o1…) on Responses, which CodeZ
|
|
10
|
+
// serves natively (and turns a chat request for one into), though its list
|
|
11
|
+
// says only "openai" for them; a Claude model on Messages; every other on
|
|
12
|
+
// chat completions. The other APIs a model is served on go in `also`, so a
|
|
13
|
+
// client's request on one of them is relayed as it was sent.
|
|
14
|
+
|
|
15
|
+
export const ID = "codez"
|
|
16
|
+
export const BASE = "https://api.codezsy.com/v1"
|
|
17
|
+
export const SITE = "https://codezsy.com"
|
|
18
|
+
export const KEYS = "https://codezsy.com/console/token"
|
|
19
|
+
|
|
20
|
+
const CHAT = "@ai-sdk/openai-compatible"
|
|
21
|
+
const RESPONSES = "@ai-sdk/openai"
|
|
22
|
+
const MESSAGES = "@ai-sdk/anthropic"
|
|
23
|
+
|
|
24
|
+
// the AI SDK package of each API CodeZ names
|
|
25
|
+
const BY_TYPE = { openai: CHAT, "openai-response": RESPONSES, anthropic: MESSAGES }
|
|
26
|
+
|
|
27
|
+
function last(id) {
|
|
28
|
+
return id.slice(id.lastIndexOf("/") + 1).toLowerCase()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// openAIModel is magpie's (internal/provider/provider.go openAIModel).
|
|
32
|
+
export function openAIModel(id) {
|
|
33
|
+
const m = last(id)
|
|
34
|
+
return m.startsWith("gpt-") || m.startsWith("codex") || (m.length > 1 && m[0] === "o" && m[1] >= "0" && m[1] <= "9")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function claudeModel(id) {
|
|
38
|
+
return last(id).startsWith("claude")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// apisOf is the API a model is asked on, then the others it is served on.
|
|
42
|
+
export function apisOf(id, types) {
|
|
43
|
+
const own = openAIModel(id) ? RESPONSES : claudeModel(id) ? MESSAGES : CHAT
|
|
44
|
+
const also = [CHAT]
|
|
45
|
+
for (const t of Array.isArray(types) ? types : []) {
|
|
46
|
+
const npm = BY_TYPE[t]
|
|
47
|
+
if (npm && !also.includes(npm)) also.push(npm)
|
|
48
|
+
}
|
|
49
|
+
return { npm: own, also: also.filter((x) => x !== own) }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Image input for the families known to read images; any other model is
|
|
53
|
+
// sent text only, so it is never sent what it can't read.
|
|
54
|
+
export function readsImages(id) {
|
|
55
|
+
const m = last(id)
|
|
56
|
+
return claudeModel(id) || openAIModel(id) || m.startsWith("gemini")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// row is a model as OpenCode's provider list has it, the shape magpie's
|
|
60
|
+
// plugin host reads from a models hook. Its name is its id, as CodeZ's
|
|
61
|
+
// console shows it.
|
|
62
|
+
export function row(id, types) {
|
|
63
|
+
const { npm, also } = apisOf(id, types)
|
|
64
|
+
const image = readsImages(id)
|
|
65
|
+
return {
|
|
66
|
+
id,
|
|
67
|
+
name: id,
|
|
68
|
+
api: { id, url: BASE, npm },
|
|
69
|
+
status: "active",
|
|
70
|
+
headers: {},
|
|
71
|
+
options: {},
|
|
72
|
+
limit: { context: 0, output: 0 },
|
|
73
|
+
capabilities: {
|
|
74
|
+
temperature: true,
|
|
75
|
+
reasoning: true,
|
|
76
|
+
attachment: image,
|
|
77
|
+
toolcall: true,
|
|
78
|
+
input: { text: true, image },
|
|
79
|
+
output: { text: true },
|
|
80
|
+
},
|
|
81
|
+
variants: {},
|
|
82
|
+
...(also.length ? { also } : {}),
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// rowsOf is the model list of CodeZ's /v1/models answer, null when the
|
|
87
|
+
// answer is no list.
|
|
88
|
+
export function rowsOf(body) {
|
|
89
|
+
if (!Array.isArray(body?.data)) return null
|
|
90
|
+
const out = {}
|
|
91
|
+
for (const m of body.data) {
|
|
92
|
+
if (typeof m?.id !== "string" || !m.id) return null
|
|
93
|
+
out[m.id] = row(m.id, m.supported_endpoint_types)
|
|
94
|
+
}
|
|
95
|
+
return out
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function listModels(fetchImpl, key, signal) {
|
|
99
|
+
return fetchImpl(`${BASE}/models`, {
|
|
100
|
+
headers: { authorization: `Bearer ${key}`, accept: "application/json" },
|
|
101
|
+
signal: signal ?? AbortSignal.timeout(15000),
|
|
102
|
+
redirect: "error",
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const refused = (status) => `CodeZ refused this key (HTTP ${status}): check it at ${KEYS}, then sign in again`
|
|
107
|
+
|
|
108
|
+
export function createPlugin({ fetchImpl = globalThis.fetch } = {}) {
|
|
109
|
+
return {
|
|
110
|
+
config: async (cfg) => {
|
|
111
|
+
cfg.provider ??= {}
|
|
112
|
+
// ??= keeps a provider the user set up in plugins.json
|
|
113
|
+
cfg.provider[ID] ??= { name: "CodeZ", npm: CHAT, api: BASE, models: {} }
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
auth: {
|
|
117
|
+
provider: ID,
|
|
118
|
+
methods: [{ type: "api", label: "CodeZ API key", placeholder: "sk-…" }],
|
|
119
|
+
// magpie puts the key on each request in the way its API takes it
|
|
120
|
+
// (Authorization: Bearer, or x-api-key on Messages); CodeZ takes both
|
|
121
|
+
async loader(getAuth) {
|
|
122
|
+
const auth = await getAuth()
|
|
123
|
+
if (auth?.type !== "api" || !auth.key) return {}
|
|
124
|
+
return { baseURL: BASE, apiKey: auth.key }
|
|
125
|
+
},
|
|
126
|
+
// CodeZ hides a key's quota from its API (quota_details_hidden), so
|
|
127
|
+
// this only checks the key and says where its balance is
|
|
128
|
+
async usage(getAuth) {
|
|
129
|
+
const auth = await getAuth()
|
|
130
|
+
if (auth?.type !== "api" || !auth.key) return {}
|
|
131
|
+
let res
|
|
132
|
+
try {
|
|
133
|
+
res = await listModels(fetchImpl, auth.key)
|
|
134
|
+
} catch (e) {
|
|
135
|
+
return { error: `CodeZ unreachable: ${e?.cause?.code || e?.message || "network error"}`, windows: [] }
|
|
136
|
+
}
|
|
137
|
+
if (res.status === 401 || res.status === 403) return { error: refused(res.status), signIn: "expired", windows: [] }
|
|
138
|
+
if (!res.ok) return { error: `CodeZ answered HTTP ${res.status}`, windows: [] }
|
|
139
|
+
return { plan: `Pay as you go · balance at ${SITE}`, windows: [] }
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
provider: {
|
|
144
|
+
id: ID,
|
|
145
|
+
// each key's own models: a key belongs to one group
|
|
146
|
+
async models(provider, { auth, signal } = {}) {
|
|
147
|
+
if (auth?.type !== "api" || !auth.key) return provider.models
|
|
148
|
+
let res
|
|
149
|
+
try {
|
|
150
|
+
res = await listModels(fetchImpl, auth.key, signal)
|
|
151
|
+
} catch {
|
|
152
|
+
return provider.models // unreachable: the list it had stays
|
|
153
|
+
}
|
|
154
|
+
if (res.status === 401 || res.status === 403) throw Object.assign(new Error(refused(res.status)), { signIn: "expired" })
|
|
155
|
+
if (!res.ok) return provider.models
|
|
156
|
+
let body
|
|
157
|
+
try {
|
|
158
|
+
body = await res.json()
|
|
159
|
+
} catch {
|
|
160
|
+
throw new Error("CodeZ sent no model list")
|
|
161
|
+
}
|
|
162
|
+
const rows = rowsOf(body)
|
|
163
|
+
if (!rows) throw new Error("CodeZ sent no model list")
|
|
164
|
+
return rows
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
}
|
package/index.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "magpie-plugin-codez",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "CodeZ (codezsy.com) as a magpie provider with your API key: each key's models, GPT on Responses, Claude on Messages, the rest on chat completions",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"magpie",
|
|
7
|
+
"magpie-plugin",
|
|
8
|
+
"codez",
|
|
9
|
+
"provider",
|
|
10
|
+
"new-api"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"files": [
|
|
15
|
+
"index.js",
|
|
16
|
+
"codez.js",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/zwenooo/magpie-codez#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/zwenooo/magpie-codez/issues"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/zwenooo/magpie-codez.git"
|
|
28
|
+
},
|
|
29
|
+
"magpie": {
|
|
30
|
+
"icon": "https://codezsy.com/logo.png"
|
|
31
|
+
}
|
|
32
|
+
}
|