@fish-under-sea/magpie-dragonapi 1.2.0 → 1.4.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 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, preferResponses: ctx.preferResponses() })
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, preferResponses: ctx.preferResponses() })
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,18 +30,33 @@ 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
- // 只声明 openai-response 的模型没有别的路,直接走 Responses;同时支持 chat
39
- // 时看开关:默认开(让协议表里有 Responses 可选),关掉就退回 chat。
40
- if (responses && (!chat || preferResponses)) return '@ai-sdk/openai'
41
- if (preferResponses && chat) return '@ai-sdk/openai'
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
 
42
+ /**
43
+ * alsoNpms 是这个模型**除主协议外**站点还声明支持的协议,交给 magpie 的
44
+ * `also` 字段。magpie 据此在「模型设置」的协议切换里给出可选项,并按客户端
45
+ * 实际发来的协议原样转发(Open Design 的 amr-link 就是这么做的)。
46
+ *
47
+ * 只列 OpenCode 侧真正有对应 SDK 的协议:chat / responses / anthropic。
48
+ * 不列 `@ai-sdk/google`——它会让 magpie 认为该模型还能走 Gemini 协议,
49
+ * 而插件供应商的 Gemini 位是 Code Assist(见 magpie 的 pluginProtocol)。
50
+ */
51
+ export function alsoNpms(row, primary) {
52
+ const ends = Array.isArray(row?.supported_endpoint_types) ? row.supported_endpoint_types.map(String) : []
53
+ const out = []
54
+ const add = (npm) => { if (npm !== primary && !out.includes(npm)) out.push(npm) }
55
+ if (ends.includes('openai')) add('@ai-sdk/openai-compatible') // Chat Completions
56
+ if (ends.includes('openai') || ends.includes('openai-response')) add('@ai-sdk/openai') // Responses
57
+ if (ends.includes('anthropic')) add('@ai-sdk/anthropic')
58
+ return out
59
+ }
45
60
  /** apiFor 按模型协议给 base URL:Anthropic 要根地址,Gemini 要 /v1beta。 */
46
61
  function apiFor(row, site, opts = {}) {
47
62
  const base = String(site || '').replace(/\/+$/, '')
@@ -167,10 +182,12 @@ export function buildCatalog(env, { cur, enabledGroups = [], site, preferRespons
167
182
  })
168
183
 
169
184
  const { url: apiUrl, npm } = apiFor(row, site, { preferResponses })
185
+ const also = kindOf(row) === 'chat' ? alsoNpms(row, npm) : []
170
186
  models[id] = {
171
187
  id,
172
188
  name: `${name} · ${group}${ratio > 0 ? ` ×${round(ratio)}` : ''}`,
173
189
  api: { id: name, url: apiUrl, npm },
190
+ ...(also.length ? { also } : {}),
174
191
  limit: {
175
192
  context: Number(row?.context_window) > 0 ? Number(row.context_window) : 0,
176
193
  output: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fish-under-sea/magpie-dragonapi",
3
- "version": "1.2.0",
3
+ "version": "1.4.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",