@fish-under-sea/magpie-dragonapi 1.1.1 → 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 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,18 +115,7 @@ function makeContext(input, options) {
117
115
  remember,
118
116
  catalog,
119
117
  status,
120
- /**
121
- * preferResponses 读「优先走 Responses API」开关。
122
- *
123
- * 站点有些模型同时支持 chat 与 Responses;默认走 chat 兼容性最好,
124
- * 用户打开这个开关后,声明了 openai-response 的模型改用 Responses。
125
- */
126
- preferResponses() {
127
- try {
128
- const v = input?.magpie?.option?.(PROVIDER_ID, OPT_RESPONSES)
129
- return v === true
130
- } catch { return false }
131
- },
118
+
132
119
  noteModelsError: (why) => { state.lastModelsError = why },
133
120
  }
134
121
  }
@@ -211,18 +198,7 @@ export default async function dragonapi(input, options) {
211
198
 
212
199
  auth: {
213
200
  provider: PROVIDER_ID,
214
- /**
215
- * options 是 magpie 自己的开关声明(OpenCode 不读)。用户在插件编辑器里
216
- * 打开后,声明了 openai-response 的模型改用 Responses API。
217
- */
218
- options: [
219
- {
220
- key: OPT_RESPONSES,
221
- label: '优先 Responses API',
222
- description: '打开后 OpenAI 系模型改走 Responses API,模型设置里才会出现 Responses 协议选项;关掉走 chat completions。可再按模型单独改回 OpenAI。',
223
- default: false,
224
- },
225
- ],
201
+
226
202
  get icon() {
227
203
  // 站点图标(Ciallo 立绘):包内 png 编成 data URI。宿主只收 https 与
228
204
  // data:image,联网抓会在断网时变成灰书页。
@@ -430,7 +406,7 @@ export default async function dragonapi(input, options) {
430
406
  const st = await ctx.status.get({})
431
407
  const cur = currencyOf(st)
432
408
  const built = cat.env
433
- ? buildCatalog(cat.env, { cur, enabledGroups: [], site: ctx.site, preferResponses: ctx.preferResponses() })
409
+ ? buildCatalog(cat.env, { cur, enabledGroups: [], site: ctx.site })
434
410
  : { models: {}, rows: [], groups: [] }
435
411
 
436
412
  // 保护 1:列表单调不减。站点偶发少给几个模型时用上一次实时表补齐,
@@ -578,7 +554,7 @@ async function authorizeKey(ctx, key) {
578
554
  const cat = await ctx.catalog.get({})
579
555
  const st = await ctx.status.get({})
580
556
  const built = cat.env
581
- ? buildCatalog(cat.env, { cur: currencyOf(st), enabledGroups: [], site: ctx.site, preferResponses: ctx.preferResponses() })
557
+ ? buildCatalog(cat.env, { cur: currencyOf(st), enabledGroups: [], site: ctx.site })
582
558
  : { models: {} }
583
559
  const known = new Set(Object.keys(built.models).map((id) => {
584
560
  const cut = id.indexOf('/')
package/lib/catalog.mjs CHANGED
@@ -30,11 +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
- if (responses && (!chat || preferResponses)) return '@ai-sdk/openai'
36
- if (preferResponses && chat) return '@ai-sdk/openai'
37
- return '@ai-sdk/openai-compatible'
33
+ // 生图/视频等非对话模型必须留在 openai-compatible:magpie 的 Images API
34
+ // 只认这个方言(PluginOpenAICompatible),换协议会直接画不出图。
35
+ if (kindOf(row) !== 'chat') 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'
38
40
  }
39
41
 
40
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.1.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",