dsh-lovart-mcp 0.17.1 → 0.17.3

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/lib/catalog.mjs CHANGED
@@ -112,15 +112,17 @@ export function switchBoard(models, disabled) {
112
112
 
113
113
  const byVendor = new Map()
114
114
  for (const model of Array.isArray(models) ? models : []) {
115
- const name = model?.name ?? model?.id
115
+ const name = model?.name ?? model?.model ?? model?.id
116
116
  if (typeof name !== 'string' || name === '') continue
117
117
  const vendor = modelVendor(name)
118
118
  if (!byVendor.has(vendor)) byVendor.set(vendor, [])
119
+ const membersOnly = model?.members_only === true || model?.membersOnly === true
120
+ const isDefault = model?.default === true
119
121
  byVendor.get(vendor).push({
120
122
  id: name,
121
123
  kind: 'model',
122
- label: model?.display_name ?? model?.displayName ?? name,
123
- detail: `${model?.kind ?? 'image'}${model?.members_only === true ? ' · 会员' : ''}${model?.default === true ? ' · 默认' : ''}`,
124
+ label: model?.display_name ?? model?.label ?? name,
125
+ detail: `${model?.kind ?? 'image'}${membersOnly ? ' · 会员' : ''}${isDefault ? ' · 默认' : ''}`,
124
126
  disabled: state.models.includes(name),
125
127
  })
126
128
  }
package/lib/index.js CHANGED
@@ -222,11 +222,38 @@ function importStateText(text) {
222
222
  return { ok: true, ...result }
223
223
  }
224
224
 
225
+ const catalogueCache = { at: 0, items: [] }
226
+
227
+ async function loadCatalogue({ accounts, mounted, credentials, logger }) {
228
+ if (catalogueCache.items.length > 0 && Date.now() - catalogueCache.at < 300_000) return catalogueCache.items
229
+ const account = accounts.find((entry) => mounted.has(entry.id)) ?? accounts[0]
230
+ if (account === undefined) return []
231
+ const access = await readValue(credentials, account.refs.access)
232
+ if (access === undefined) return []
233
+ const items = []
234
+ for (const kind of ['image', 'video']) {
235
+ try {
236
+ const page = await readModels(access, kind)
237
+ for (const model of page?.models ?? []) items.push({ ...model, kind: model?.kind ?? kind })
238
+ } catch (error) {
239
+ logger?.debug?.(`lovart-mcp: model catalogue (${kind}) — ${error instanceof Error ? error.message : String(error)}`)
240
+ }
241
+ }
242
+ if (items.length > 0) {
243
+ catalogueCache.at = Date.now()
244
+ catalogueCache.items = items
245
+ }
246
+ return items
247
+ }
248
+
225
249
  export async function apply(ctx, config = {}) {
226
250
  setProxy(config?.proxy)
227
251
  const accounts = normalizeAccounts(config?.accounts)
228
252
  /** Tools/models switched off from the panel; enforced here and in the proxy. */
229
253
  let disabled = normalizeDisabled(config?.disabled)
254
+ // Panel and tools both need the catalogue; keep the loader at apply scope so
255
+ // every closure below resolves it, whatever block it was written in.
256
+ const loadModelCatalogue = () => loadCatalogue({ accounts, mounted, credentials, logger })
230
257
  const credentials = ctx.credentials
231
258
  const logger = ctx.logger
232
259
  const disposers = []
@@ -535,26 +562,6 @@ export async function apply(ctx, config = {}) {
535
562
  return { disabled, saved }
536
563
  }
537
564
 
538
- let modelCache = { at: 0, items: [] }
539
- async function loadModelCatalogue() {
540
- if (modelCache.items.length > 0 && Date.now() - modelCache.at < 300_000) return modelCache.items
541
- const account = accounts.find((entry) => mounted.has(entry.id)) ?? accounts[0]
542
- if (account === undefined) return []
543
- const access = await readValue(credentials, account.refs.access)
544
- if (access === undefined) return []
545
- const items = []
546
- for (const kind of ['image', 'video']) {
547
- try {
548
- const page = await readModels(access, kind)
549
- for (const model of page?.models ?? []) items.push({ ...model, kind: model?.kind ?? kind })
550
- } catch (error) {
551
- logger?.debug?.(`lovart-mcp: model catalogue (${kind}) — ${error instanceof Error ? error.message : String(error)}`)
552
- }
553
- }
554
- if (items.length > 0) modelCache = { at: Date.now(), items }
555
- return items
556
- }
557
-
558
565
  disposers.push(ctx.tools.register(defineTool({
559
566
  name: 'lovart_switches',
560
567
  description: 'Show which Lovart capabilities and models are switched off, grouped by capability family and model vendor. Mirrors the panel section 模型与能力.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-lovart-mcp",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "type": "module",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {