@fish-under-sea/magpie-dragonapi 1.3.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.
Files changed (2) hide show
  1. package/lib/catalog.mjs +20 -0
  2. package/package.json +1 -1
package/lib/catalog.mjs CHANGED
@@ -39,6 +39,24 @@ export function npmOf(row, { preferResponses = false } = {}) {
39
39
  return '@ai-sdk/openai'
40
40
  }
41
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
+ }
42
60
  /** apiFor 按模型协议给 base URL:Anthropic 要根地址,Gemini 要 /v1beta。 */
43
61
  function apiFor(row, site, opts = {}) {
44
62
  const base = String(site || '').replace(/\/+$/, '')
@@ -164,10 +182,12 @@ export function buildCatalog(env, { cur, enabledGroups = [], site, preferRespons
164
182
  })
165
183
 
166
184
  const { url: apiUrl, npm } = apiFor(row, site, { preferResponses })
185
+ const also = kindOf(row) === 'chat' ? alsoNpms(row, npm) : []
167
186
  models[id] = {
168
187
  id,
169
188
  name: `${name} · ${group}${ratio > 0 ? ` ×${round(ratio)}` : ''}`,
170
189
  api: { id: name, url: apiUrl, npm },
190
+ ...(also.length ? { also } : {}),
171
191
  limit: {
172
192
  context: Number(row?.context_window) > 0 ? Number(row.context_window) : 0,
173
193
  output: 0,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fish-under-sea/magpie-dragonapi",
3
- "version": "1.3.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",