@fish-under-sea/magpie-dragonapi 1.2.0 → 1.3.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.
- package/index.mjs +4 -30
- package/lib/catalog.mjs +4 -7
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -30,8 +30,6 @@ import { startService } from './lib/service.mjs'
|
|
|
30
30
|
const PROVIDER_ID = 'dragonapi'
|
|
31
31
|
/** 站点给这把钥匙起的名字前缀,便于用户在控制台认出来。 */
|
|
32
32
|
const KEY_NAME = 'Magpie'
|
|
33
|
-
/** 「优先走 Responses API」开关的 key(magpie 的 auth.options)。 */
|
|
34
|
-
const OPT_RESPONSES = 'responsesFirst'
|
|
35
33
|
|
|
36
34
|
/**
|
|
37
35
|
* 插件状态。全部放在闭包里,一个进程一份。
|
|
@@ -117,20 +115,7 @@ function makeContext(input, options) {
|
|
|
117
115
|
remember,
|
|
118
116
|
catalog,
|
|
119
117
|
status,
|
|
120
|
-
|
|
121
|
-
* preferResponses 读「走 Responses API」开关。
|
|
122
|
-
*
|
|
123
|
-
* 默认**开**:站点是 New API 部署,对话模型统一走 `/v1/responses`,
|
|
124
|
-
* 这样 magpie 的模型设置里才会出现 Responses 协议选项(协议选项是按
|
|
125
|
-
* 模型表里实际用到的协议归纳的)。关掉则退回 chat completions。
|
|
126
|
-
* 旧宿主不提供 option 时按默认(开)处理。
|
|
127
|
-
*/
|
|
128
|
-
preferResponses() {
|
|
129
|
-
try {
|
|
130
|
-
const v = input?.magpie?.option?.(PROVIDER_ID, OPT_RESPONSES)
|
|
131
|
-
return v === undefined || v === null ? true : v === true
|
|
132
|
-
} catch { return true }
|
|
133
|
-
},
|
|
118
|
+
|
|
134
119
|
noteModelsError: (why) => { state.lastModelsError = why },
|
|
135
120
|
}
|
|
136
121
|
}
|
|
@@ -213,18 +198,7 @@ export default async function dragonapi(input, options) {
|
|
|
213
198
|
|
|
214
199
|
auth: {
|
|
215
200
|
provider: PROVIDER_ID,
|
|
216
|
-
|
|
217
|
-
* options 是 magpie 自己的开关声明(OpenCode 不读)。用户在插件编辑器里
|
|
218
|
-
* 打开后,声明了 openai-response 的模型改用 Responses API。
|
|
219
|
-
*/
|
|
220
|
-
options: [
|
|
221
|
-
{
|
|
222
|
-
key: OPT_RESPONSES,
|
|
223
|
-
label: '走 Responses API',
|
|
224
|
-
description: '默认走 Responses API(模型设置里可看到 Responses 协议);关掉退回 chat completions。',
|
|
225
|
-
default: true,
|
|
226
|
-
},
|
|
227
|
-
],
|
|
201
|
+
|
|
228
202
|
get icon() {
|
|
229
203
|
// 站点图标(Ciallo 立绘):包内 png 编成 data URI。宿主只收 https 与
|
|
230
204
|
// data:image,联网抓会在断网时变成灰书页。
|
|
@@ -432,7 +406,7 @@ export default async function dragonapi(input, options) {
|
|
|
432
406
|
const st = await ctx.status.get({})
|
|
433
407
|
const cur = currencyOf(st)
|
|
434
408
|
const built = cat.env
|
|
435
|
-
? buildCatalog(cat.env, { cur, enabledGroups: [], site: ctx.site
|
|
409
|
+
? buildCatalog(cat.env, { cur, enabledGroups: [], site: ctx.site })
|
|
436
410
|
: { models: {}, rows: [], groups: [] }
|
|
437
411
|
|
|
438
412
|
// 保护 1:列表单调不减。站点偶发少给几个模型时用上一次实时表补齐,
|
|
@@ -580,7 +554,7 @@ async function authorizeKey(ctx, key) {
|
|
|
580
554
|
const cat = await ctx.catalog.get({})
|
|
581
555
|
const st = await ctx.status.get({})
|
|
582
556
|
const built = cat.env
|
|
583
|
-
? buildCatalog(cat.env, { cur: currencyOf(st), enabledGroups: [], site: ctx.site
|
|
557
|
+
? buildCatalog(cat.env, { cur: currencyOf(st), enabledGroups: [], site: ctx.site })
|
|
584
558
|
: { models: {} }
|
|
585
559
|
const known = new Set(Object.keys(built.models).map((id) => {
|
|
586
560
|
const cut = id.indexOf('/')
|
package/lib/catalog.mjs
CHANGED
|
@@ -30,16 +30,13 @@ export function npmOf(row, { preferResponses = false } = {}) {
|
|
|
30
30
|
// - 同时声明 openai + openai-response:默认 chat(兼容性最好);用户打开
|
|
31
31
|
// 「优先 Responses」后改走 Responses,此时编辑器里才会出现 Responses 选项,
|
|
32
32
|
// 可以再按模型单独改回 OpenAI。
|
|
33
|
-
const responses = ends.includes('openai-response')
|
|
34
|
-
const chat = ends.includes('openai')
|
|
35
33
|
// 生图/视频等非对话模型必须留在 openai-compatible:magpie 的 Images API
|
|
36
34
|
// 只认这个方言(PluginOpenAICompatible),换协议会直接画不出图。
|
|
37
35
|
if (kindOf(row) !== 'chat') return '@ai-sdk/openai-compatible'
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return '@ai-sdk/openai-compatible'
|
|
36
|
+
// 对话模型统一走 `@ai-sdk/openai`(Responses API)。原因:站点是 New API
|
|
37
|
+
// 部署,Responses 的 prompt cache 命中比 chat completions 高;而且 magpie
|
|
38
|
+
// 只有看到 `@ai-sdk/openai` 才会把 Responses 放进协议列表。
|
|
39
|
+
return '@ai-sdk/openai'
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
/** apiFor 按模型协议给 base URL:Anthropic 要根地址,Gemini 要 /v1beta。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fish-under-sea/magpie-dragonapi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "DragonAPI for magpie: a provider plugin whose models, groups and prices come from the site's public /api/pricing, with balance and per-call usage from an sk- key, plus a local page that lists the market (read-only), shows usage and can mint new keys for a group.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.mjs",
|