dsh-lovart-mcp 0.12.4 → 0.13.1
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/README.md +12 -2
- package/client.js +114 -0
- package/cordis.patch.yml +4 -0
- package/lib/catalog.mjs +175 -0
- package/lib/index.js +105 -0
- package/lib/panel.mjs +24 -1
- package/lib/proxy.mjs +28 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ dsh plugin install dsh-lovart-mcp
|
|
|
17
17
|
3. 浏览器会打开 Lovart 授权页,选择你的账号并点「允许」。
|
|
18
18
|
4. 回到对话就能用了。
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
需要再加账号时,在面板的「新增账号」里填一个 id(例如 `c`)点 **添加账号**,再点新卡片上的 **登录**,用另一个 Lovart 号重复上面的授权。不用的号在卡片上点 **移除** 即可(会清掉本机令牌)。
|
|
21
21
|
|
|
22
22
|
## 使用
|
|
23
23
|
|
|
@@ -31,13 +31,23 @@ dsh plugin install dsh-lovart-mcp
|
|
|
31
31
|
| 改图、放大、抠图、分层、上传、查任务、管项目 | `lovart_tool` |
|
|
32
32
|
| 看账号状态与余额 | 面板,或 `lovart_status` |
|
|
33
33
|
| 看项目、模型权限、任务与素材记录 | `lovart_account` |
|
|
34
|
-
| 添加 / 移除账号 | `lovart_add_account` / `lovart_remove_account` |
|
|
34
|
+
| 添加 / 移除账号 | 面板的「新增账号」与卡片上的「移除」,或 `lovart_add_account` / `lovart_remove_account` |
|
|
35
35
|
| 设置代理 | `lovart_set_proxy` |
|
|
36
|
+
| 开关模型与能力 | 面板的「模型与能力」,或 `lovart_switch` / `lovart_switches` |
|
|
36
37
|
| 导出 / 导入登录 | 面板按钮,或 `lovart_export_credential` / `lovart_import_credential` |
|
|
37
38
|
| 导出 / 导入任务与素材记录 | 面板按钮,或 `lovart_export_state` / `lovart_import_state` |
|
|
38
39
|
|
|
39
40
|
提交生成前会先给出积分报价,确认后才执行。
|
|
40
41
|
|
|
42
|
+
## 模型与能力
|
|
43
|
+
|
|
44
|
+
面板底部有一块「模型与能力」:能力按生成、编辑、素材、项目、任务、模型目录、账户、评估分组,模型按厂商(openai、vertex、seedance……)分组。
|
|
45
|
+
|
|
46
|
+
- 点组里的名字 = 单独开关这一项
|
|
47
|
+
- 点「关闭整组」= 一次关掉整组
|
|
48
|
+
|
|
49
|
+
关掉的能力会从 DSH 的工具列表里消失(连 `mcp__lovart-a__*` 这样的原始工具也没有了),关掉的模型不能用于生成。所有开关都写进插件配置,重启后保留。也可以用 `lovart_switch` 切换、`lovart_switches` 查看当前状态。
|
|
50
|
+
|
|
41
51
|
## 网络
|
|
42
52
|
|
|
43
53
|
连不上 Lovart 时,在面板的「代理」填 HTTP 代理地址并保存,或:
|
package/client.js
CHANGED
|
@@ -409,6 +409,119 @@ window.__ModuleLoader__.load({
|
|
|
409
409
|
)
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
function SwitchBoardBox() {
|
|
413
|
+
const [board, setBoard] = React.useState(null)
|
|
414
|
+
const [busyId, setBusyId] = React.useState('')
|
|
415
|
+
const [error, setError] = React.useState('')
|
|
416
|
+
React.useEffect(() => {
|
|
417
|
+
let alive = true
|
|
418
|
+
fetch(`${API}/switches`, { headers: { accept: 'application/json' } })
|
|
419
|
+
.then((response) => response.json())
|
|
420
|
+
.then((body) => { if (alive) setBoard(body) })
|
|
421
|
+
.catch((failure) => { if (alive) setError(String((failure && failure.message) || failure)) })
|
|
422
|
+
return () => { alive = false }
|
|
423
|
+
}, [])
|
|
424
|
+
const toggle = async (payload) => {
|
|
425
|
+
const key = payload.groupId || payload.id || ''
|
|
426
|
+
setBusyId(key)
|
|
427
|
+
try {
|
|
428
|
+
const response = await fetch(`${API}/switches`, {
|
|
429
|
+
method: 'POST',
|
|
430
|
+
headers: { 'content-type': 'application/json' },
|
|
431
|
+
body: JSON.stringify(payload),
|
|
432
|
+
})
|
|
433
|
+
const body = await response.json().catch(() => ({}))
|
|
434
|
+
if (!response.ok) {
|
|
435
|
+
setError(body.error || `切换失败(${response.status})`)
|
|
436
|
+
return
|
|
437
|
+
}
|
|
438
|
+
setError('')
|
|
439
|
+
if (body.board) setBoard(body.board)
|
|
440
|
+
else if (body.board === undefined) setBoard((current) => current)
|
|
441
|
+
} catch (failure) {
|
|
442
|
+
setError(String((failure && failure.message) || failure))
|
|
443
|
+
} finally {
|
|
444
|
+
setBusyId('')
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
if (board === null) {
|
|
448
|
+
return h('div', { style: { fontSize: '12px', opacity: 0.6 } }, error || '模型与能力加载中…')
|
|
449
|
+
}
|
|
450
|
+
const chip = (item) => h('button', {
|
|
451
|
+
key: `${item.kind}:${item.id}`,
|
|
452
|
+
type: 'button',
|
|
453
|
+
title: item.detail || item.label,
|
|
454
|
+
disabled: busyId !== '' && busyId !== item.id,
|
|
455
|
+
onClick: () => toggle({ id: item.id, kind: item.kind }),
|
|
456
|
+
style: {
|
|
457
|
+
font: 'inherit',
|
|
458
|
+
fontSize: '11px',
|
|
459
|
+
lineHeight: '18px',
|
|
460
|
+
padding: '1px 7px',
|
|
461
|
+
borderRadius: '999px',
|
|
462
|
+
cursor: 'pointer',
|
|
463
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
464
|
+
background: item.disabled ? 'rgba(127,127,127,.10)' : 'transparent',
|
|
465
|
+
color: item.disabled ? 'var(--dsw-alias-text-secondary, #888)' : 'inherit',
|
|
466
|
+
textDecoration: item.disabled ? 'line-through' : 'none',
|
|
467
|
+
opacity: busyId === item.id ? 0.5 : 1,
|
|
468
|
+
},
|
|
469
|
+
}, item.label)
|
|
470
|
+
const groupRow = (group) => h('div', {
|
|
471
|
+
key: group.id,
|
|
472
|
+
style: { display: 'flex', flexDirection: 'column', gap: '4px', padding: '6px 0' },
|
|
473
|
+
},
|
|
474
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: '8px' } },
|
|
475
|
+
h('button', {
|
|
476
|
+
type: 'button',
|
|
477
|
+
disabled: busyId !== '' && busyId !== group.id,
|
|
478
|
+
onClick: () => toggle({ groupId: group.id }),
|
|
479
|
+
style: {
|
|
480
|
+
font: 'inherit',
|
|
481
|
+
fontSize: '11px',
|
|
482
|
+
lineHeight: '18px',
|
|
483
|
+
padding: '1px 8px',
|
|
484
|
+
borderRadius: '6px',
|
|
485
|
+
cursor: 'pointer',
|
|
486
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
487
|
+
background: group.disabled ? 'rgba(127,127,127,.10)' : 'transparent',
|
|
488
|
+
color: 'inherit',
|
|
489
|
+
},
|
|
490
|
+
}, group.disabled ? `启用「${group.label}」整组` : `关闭「${group.label}」整组`),
|
|
491
|
+
h('span', { style: { fontSize: '11px', opacity: 0.55 } },
|
|
492
|
+
`${group.kind === 'tool' ? '能力' : '模型'} · ${group.items.length} 项`),
|
|
493
|
+
),
|
|
494
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '5px' } }, group.items.map(chip)),
|
|
495
|
+
)
|
|
496
|
+
const toolGroups = board.groups.filter((group) => group.kind === 'tool')
|
|
497
|
+
const modelGroups = board.groups.filter((group) => group.kind === 'model')
|
|
498
|
+
return h('div', {
|
|
499
|
+
style: {
|
|
500
|
+
display: 'flex',
|
|
501
|
+
flexDirection: 'column',
|
|
502
|
+
gap: '4px',
|
|
503
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
504
|
+
borderRadius: '10px',
|
|
505
|
+
padding: '10px 12px',
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
h('div', { style: { fontSize: '13px', fontWeight: 600 } }, '模型与能力'),
|
|
509
|
+
h('div', { style: { fontSize: '11px', opacity: 0.65 } },
|
|
510
|
+
'点名字可单独开关,点「关闭整组」可一次关掉一组。关闭后对应的 MCP 工具会从 DSH 里消失,模型也不能被用于生成。'),
|
|
511
|
+
error ? note(error, 'danger') : null,
|
|
512
|
+
h('div', { style: { display: 'flex', gap: '16px', flexWrap: 'wrap', fontSize: '11px', opacity: 0.6 } },
|
|
513
|
+
h('span', null, `能力 ${board.totals.tools} 项 · 已关 ${board.totals.disabledItems}`),
|
|
514
|
+
h('span', null, `模型 ${board.totals.models} 项 · 组 ${board.totals.disabledGroups}`),
|
|
515
|
+
),
|
|
516
|
+
h('div', { style: { fontSize: '12px', fontWeight: 600, marginTop: '4px' } }, '能力'),
|
|
517
|
+
toolGroups.map(groupRow),
|
|
518
|
+
h('div', { style: { fontSize: '12px', fontWeight: 600, marginTop: '4px' } }, '模型'),
|
|
519
|
+
modelGroups.length === 0
|
|
520
|
+
? h('div', { style: { fontSize: '11px', opacity: 0.6 } }, '先登录一个账号,模型列表才能拉取。')
|
|
521
|
+
: modelGroups.map(groupRow),
|
|
522
|
+
)
|
|
523
|
+
}
|
|
524
|
+
|
|
412
525
|
function Panel() {
|
|
413
526
|
const { data, busy, action, load, login, addAccount, removeAccount, exportAccount, importBundle, exportState, importStateText, saveProxy } = useStatus()
|
|
414
527
|
const [proxyDraft, setProxyDraft] = React.useState(null)
|
|
@@ -454,6 +567,7 @@ window.__ModuleLoader__.load({
|
|
|
454
567
|
})),
|
|
455
568
|
),
|
|
456
569
|
h(AddAccountBox, { onAdd: addAccount, busy }),
|
|
570
|
+
h(SwitchBoardBox, null),
|
|
457
571
|
action && action.kind === 'add'
|
|
458
572
|
? note(`已新增账号 ${action.id}(${action.label})${action.saved ? ',并写入插件配置' : ',仅本次会话有效'}。点上面的「登录」去授权。`)
|
|
459
573
|
: null,
|
package/cordis.patch.yml
CHANGED
package/lib/catalog.mjs
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability catalog: which Lovart MCP tools the plugin offers, how they group,
|
|
3
|
+
* and how model ids group by vendor. Used by the panel (to render switches), by
|
|
4
|
+
* the plugin tools (to refuse disabled calls) and by the stdio proxy (to hide
|
|
5
|
+
* disabled tools from DSH entirely).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export const TOOL_GROUPS = [
|
|
9
|
+
{ id: 'generation', label: '生成', tools: ['generate_image', 'generate_video'] },
|
|
10
|
+
{ id: 'editing', label: '编辑', tools: ['edit_image', 'separate_layers', 'vectorize', 'upscale', 'remove_video_background'] },
|
|
11
|
+
{ id: 'assets', label: '素材', tools: ['upload_asset'] },
|
|
12
|
+
{ id: 'projects', label: '项目', tools: ['create_project', 'rename_project', 'list_projects'] },
|
|
13
|
+
{ id: 'tasks', label: '任务', tools: ['get_task', 'get_task_status', 'cancel_task'] },
|
|
14
|
+
{ id: 'models', label: '模型目录', tools: ['list_models', 'describe_model'] },
|
|
15
|
+
{ id: 'account', label: '账户', tools: ['get_credits'] },
|
|
16
|
+
{ id: 'ranking', label: '评估', tools: ['rank_candidates_with_jev'] },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
export const TOOL_LABELS = {
|
|
20
|
+
generate_image: '生成图片',
|
|
21
|
+
generate_video: '生成视频',
|
|
22
|
+
edit_image: '编辑图片',
|
|
23
|
+
separate_layers: '拆分层',
|
|
24
|
+
vectorize: '矢量化',
|
|
25
|
+
upscale: '放大',
|
|
26
|
+
remove_video_background: '视频去背',
|
|
27
|
+
upload_asset: '上传素材',
|
|
28
|
+
create_project: '新建项目',
|
|
29
|
+
rename_project: '重命名项目',
|
|
30
|
+
list_projects: '项目列表',
|
|
31
|
+
get_task: '任务详情',
|
|
32
|
+
get_task_status: '任务状态',
|
|
33
|
+
cancel_task: '取消任务',
|
|
34
|
+
list_models: '模型列表',
|
|
35
|
+
describe_model: '模型参数',
|
|
36
|
+
get_credits: '积分余额',
|
|
37
|
+
rank_candidates_with_jev: '候选评分',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Empty switch state. */
|
|
41
|
+
export function emptyDisabled() {
|
|
42
|
+
return { tools: [], models: [], groups: [] }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Normalise whatever the config holds into the three-array shape. */
|
|
46
|
+
export function normalizeDisabled(raw) {
|
|
47
|
+
const source = raw !== null && typeof raw === 'object' ? raw : {}
|
|
48
|
+
const list = (value) => (Array.isArray(value) ? value.filter((item) => typeof item === 'string' && item !== '') : [])
|
|
49
|
+
return {
|
|
50
|
+
tools: Array.from(new Set(list(source.tools))),
|
|
51
|
+
models: Array.from(new Set(list(source.models))),
|
|
52
|
+
groups: Array.from(new Set(list(source.groups))),
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function groupOfTool(name) {
|
|
57
|
+
const group = TOOL_GROUPS.find((entry) => entry.tools.includes(name))
|
|
58
|
+
return group?.id ?? null
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** True when the tool itself or its whole group is switched off. */
|
|
62
|
+
export function isToolDisabled(name, disabled) {
|
|
63
|
+
const state = normalizeDisabled(disabled)
|
|
64
|
+
if (state.tools.includes(name)) return true
|
|
65
|
+
const group = groupOfTool(name)
|
|
66
|
+
return group !== null && state.groups.includes(`tool:${group}`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function modelVendor(name) {
|
|
70
|
+
const text = typeof name === 'string' ? name : ''
|
|
71
|
+
const slash = text.indexOf('/')
|
|
72
|
+
return slash > 0 ? text.slice(0, slash) : 'other'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** True when the model itself or its whole vendor group is switched off. */
|
|
76
|
+
export function isModelDisabled(name, disabled) {
|
|
77
|
+
const state = normalizeDisabled(disabled)
|
|
78
|
+
if (state.models.includes(name)) return true
|
|
79
|
+
return state.groups.includes(`model:${modelVendor(name)}`)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function filterToolList(tools, disabled) {
|
|
83
|
+
if (!Array.isArray(tools)) return tools
|
|
84
|
+
return tools.filter((tool) => !isToolDisabled(tool?.name, disabled))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Flat list of every tool switched off, groups expanded. */
|
|
88
|
+
export function expandToolNames(disabled) {
|
|
89
|
+
const state = normalizeDisabled(disabled)
|
|
90
|
+
const names = new Set(state.tools)
|
|
91
|
+
for (const group of TOOL_GROUPS) {
|
|
92
|
+
if (state.groups.includes(`tool:${group.id}`)) for (const tool of group.tools) names.add(tool)
|
|
93
|
+
}
|
|
94
|
+
return Array.from(names)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Panel payload: switch groups plus every individual entry. */
|
|
98
|
+
export function switchBoard(models, disabled) {
|
|
99
|
+
const state = normalizeDisabled(disabled)
|
|
100
|
+
const toolGroups = TOOL_GROUPS.map((group) => ({
|
|
101
|
+
id: `tool:${group.id}`,
|
|
102
|
+
kind: 'tool',
|
|
103
|
+
label: group.label,
|
|
104
|
+
disabled: state.groups.includes(`tool:${group.id}`),
|
|
105
|
+
items: group.tools.map((name) => ({
|
|
106
|
+
id: name,
|
|
107
|
+
kind: 'tool',
|
|
108
|
+
label: TOOL_LABELS[name] ?? name,
|
|
109
|
+
disabled: state.tools.includes(name),
|
|
110
|
+
})),
|
|
111
|
+
}))
|
|
112
|
+
|
|
113
|
+
const byVendor = new Map()
|
|
114
|
+
for (const model of Array.isArray(models) ? models : []) {
|
|
115
|
+
const name = model?.name ?? model?.id
|
|
116
|
+
if (typeof name !== 'string' || name === '') continue
|
|
117
|
+
const vendor = modelVendor(name)
|
|
118
|
+
if (!byVendor.has(vendor)) byVendor.set(vendor, [])
|
|
119
|
+
byVendor.get(vendor).push({
|
|
120
|
+
id: name,
|
|
121
|
+
kind: 'model',
|
|
122
|
+
label: model?.display_name ?? model?.displayName ?? name,
|
|
123
|
+
detail: `${model?.kind ?? 'image'}${model?.members_only === true ? ' · 会员' : ''}${model?.default === true ? ' · 默认' : ''}`,
|
|
124
|
+
disabled: state.models.includes(name),
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
const modelGroups = Array.from(byVendor.entries())
|
|
128
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
129
|
+
.map(([vendor, items]) => ({
|
|
130
|
+
id: `model:${vendor}`,
|
|
131
|
+
kind: 'model',
|
|
132
|
+
label: vendor,
|
|
133
|
+
disabled: state.groups.includes(`model:${vendor}`),
|
|
134
|
+
items: items.sort((a, b) => a.id.localeCompare(b.id)),
|
|
135
|
+
}))
|
|
136
|
+
|
|
137
|
+
const groupCount = [...toolGroups, ...modelGroups].filter((group) => group.disabled).length
|
|
138
|
+
return {
|
|
139
|
+
disabled: state,
|
|
140
|
+
groups: [...toolGroups, ...modelGroups],
|
|
141
|
+
totals: {
|
|
142
|
+
tools: toolGroups.reduce((sum, group) => sum + group.items.length, 0),
|
|
143
|
+
models: modelGroups.reduce((sum, group) => sum + group.items.length, 0),
|
|
144
|
+
disabledGroups: groupCount,
|
|
145
|
+
disabledItems:
|
|
146
|
+
state.tools.length +
|
|
147
|
+
state.models.length +
|
|
148
|
+
toolGroups.filter((group) => group.disabled).reduce((sum, group) => sum + group.items.length, 0) +
|
|
149
|
+
modelGroups.filter((group) => group.disabled).reduce((sum, group) => sum + group.items.length, 0),
|
|
150
|
+
},
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Dispatch a single toggle against the stored state. A group toggle clears the
|
|
156
|
+
* per-item flags inside it so the two levels cannot contradict each other.
|
|
157
|
+
*/
|
|
158
|
+
export function applyToggle(disabled, { id, kind, groupId } = {}) {
|
|
159
|
+
const state = normalizeDisabled(disabled)
|
|
160
|
+
if (typeof groupId === 'string' && groupId !== '') {
|
|
161
|
+
const isGroup = groupId.startsWith('tool:') || groupId.startsWith('model:')
|
|
162
|
+
const exists = state.groups.includes(groupId)
|
|
163
|
+
state.groups = exists ? state.groups.filter((item) => item !== groupId) : [...state.groups, groupId]
|
|
164
|
+
if (exists === false) {
|
|
165
|
+
const prefix = groupId.startsWith('tool:') ? 'tools' : 'models'
|
|
166
|
+
state[prefix] = state[prefix].filter((item) => (prefix === 'tools' ? `tool:${groupOfTool(item)}` : `model:${modelVendor(item)}`) !== groupId)
|
|
167
|
+
}
|
|
168
|
+
return isGroup ? state : state
|
|
169
|
+
}
|
|
170
|
+
if (typeof id !== 'string' || id === '') return state
|
|
171
|
+
const bucket = kind === 'model' ? 'models' : 'tools'
|
|
172
|
+
const exists = state[bucket].includes(id)
|
|
173
|
+
state[bucket] = exists ? state[bucket].filter((item) => item !== id) : [...state[bucket], id]
|
|
174
|
+
return state
|
|
175
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -31,6 +31,7 @@ import { applyTaskStatus, listAssets, listTasks, loadLedger, recordAsset, record
|
|
|
31
31
|
import { buildState, mergeState, parseState } from './state.mjs'
|
|
32
32
|
import { CONFIRM_THRESHOLD_CREDITS, FREE_TOOLS, catalog, quote, quoteExtra } from './pricing.mjs'
|
|
33
33
|
import { createBundlePayload, newKey, open as openBundle, seal } from './vault.mjs'
|
|
34
|
+
import { TOOL_GROUPS, applyToggle, expandToolNames, isModelDisabled, isToolDisabled, normalizeDisabled, switchBoard } from './catalog.mjs'
|
|
34
35
|
|
|
35
36
|
export const name = 'lovart-mcp'
|
|
36
37
|
export const inject = ['tools', 'credentials', 'mcpManager']
|
|
@@ -223,6 +224,8 @@ function importStateText(text) {
|
|
|
223
224
|
export async function apply(ctx, config = {}) {
|
|
224
225
|
setProxy(config?.proxy)
|
|
225
226
|
const accounts = normalizeAccounts(config?.accounts)
|
|
227
|
+
/** Tools/models switched off from the panel; enforced here and in the proxy. */
|
|
228
|
+
let disabled = normalizeDisabled(config?.disabled)
|
|
226
229
|
const credentials = ctx.credentials
|
|
227
230
|
const logger = ctx.logger
|
|
228
231
|
const disposers = []
|
|
@@ -267,6 +270,7 @@ export async function apply(ctx, config = {}) {
|
|
|
267
270
|
env: {
|
|
268
271
|
LOVART_TOKEN: access,
|
|
269
272
|
LOVART_MCP_URL: MCP_URL,
|
|
273
|
+
LOVART_DISABLED_TOOLS: expandToolNames(disabled).join(','),
|
|
270
274
|
...(resolveProxy() === '' ? {} : { LOVART_PROXY: resolveProxy() }),
|
|
271
275
|
},
|
|
272
276
|
toolCallTimeoutMs: 180000,
|
|
@@ -505,6 +509,90 @@ export async function apply(ctx, config = {}) {
|
|
|
505
509
|
}
|
|
506
510
|
}
|
|
507
511
|
|
|
512
|
+
async function persistDisabled() {
|
|
513
|
+
const editor = ctx.get?.('configEditor')
|
|
514
|
+
const entry = await entryForAccounts()
|
|
515
|
+
if (editor === undefined || entry === undefined) return false
|
|
516
|
+
try {
|
|
517
|
+
await editor.edit(entry, (current) => ({ ...(current ?? {}), disabled }))
|
|
518
|
+
return true
|
|
519
|
+
} catch (error) {
|
|
520
|
+
logger?.warn?.(`lovart-mcp: could not persist switches — ${error instanceof Error ? error.message : String(error)}`)
|
|
521
|
+
return false
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Save the switch board and remount every account: the proxy receives the
|
|
527
|
+
* disabled list through its env, so the raw `mcp__lovart-*__*` tools really
|
|
528
|
+
* disappear instead of merely being refused by the plugin wrappers.
|
|
529
|
+
*/
|
|
530
|
+
async function setDisabledState(next) {
|
|
531
|
+
disabled = normalizeDisabled(next)
|
|
532
|
+
const saved = await persistDisabled()
|
|
533
|
+
for (const account of accounts) void mountAccount(account)
|
|
534
|
+
return { disabled, saved }
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
let modelCache = { at: 0, items: [] }
|
|
538
|
+
async function loadModelCatalogue() {
|
|
539
|
+
if (modelCache.items.length > 0 && Date.now() - modelCache.at < 300_000) return modelCache.items
|
|
540
|
+
const account = accounts.find((entry) => mounted.has(entry.id)) ?? accounts[0]
|
|
541
|
+
if (account === undefined) return []
|
|
542
|
+
const access = await readValue(credentials, account.refs.access)
|
|
543
|
+
if (access === undefined) return []
|
|
544
|
+
const items = []
|
|
545
|
+
for (const kind of ['image', 'video']) {
|
|
546
|
+
try {
|
|
547
|
+
const page = await readModels(access, kind)
|
|
548
|
+
for (const model of page?.models ?? []) items.push({ ...model, kind: model?.kind ?? kind })
|
|
549
|
+
} catch (error) {
|
|
550
|
+
logger?.debug?.(`lovart-mcp: model catalogue (${kind}) — ${error instanceof Error ? error.message : String(error)}`)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
if (items.length > 0) modelCache = { at: Date.now(), items }
|
|
554
|
+
return items
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
disposers.push(ctx.tools.register(defineTool({
|
|
558
|
+
name: 'lovart_switches',
|
|
559
|
+
description: 'Show which Lovart capabilities and models are switched off, grouped by capability family and model vendor. Mirrors the panel section 模型与能力.',
|
|
560
|
+
parameters: {},
|
|
561
|
+
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] },
|
|
562
|
+
async execute() {
|
|
563
|
+
const models = await loadModelCatalogue()
|
|
564
|
+
const board = switchBoard(models, disabled)
|
|
565
|
+
const rows = board.groups.map((group) => ({
|
|
566
|
+
id: group.id,
|
|
567
|
+
label: group.label,
|
|
568
|
+
disabled: group.disabled,
|
|
569
|
+
items: group.items.map((item) => ({ id: item.id, label: item.label, disabled: item.disabled })),
|
|
570
|
+
}))
|
|
571
|
+
return JSON.stringify({ disabled: board.disabled, totals: board.totals, groups: rows }, null, 2)
|
|
572
|
+
},
|
|
573
|
+
})))
|
|
574
|
+
|
|
575
|
+
disposers.push(ctx.tools.register(defineTool({
|
|
576
|
+
name: 'lovart_switch',
|
|
577
|
+
description: 'Switch a Lovart capability group, capability, model group or model on or off. Use "tool:editing" / "model:vertex" for whole groups, or a tool name such as "upscale" / a model id such as "openai/gpt-image-2" for a single item. Disabled capabilities disappear from DSH and disabled models cannot be used for generation.',
|
|
578
|
+
parameters: {
|
|
579
|
+
target: { type: 'string', description: 'Group id ("tool:editing", "model:vertex"), tool name ("upscale") or model id ("openai/gpt-image-2").' },
|
|
580
|
+
},
|
|
581
|
+
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] },
|
|
582
|
+
async execute(args) {
|
|
583
|
+
const target = String(args.target ?? '').trim()
|
|
584
|
+
if (target === '') return 'target is required, for example target:"tool:editing" or target:"upscale"'
|
|
585
|
+
let next
|
|
586
|
+
if (target.startsWith('tool:') || target.startsWith('model:')) {
|
|
587
|
+
next = applyToggle(disabled, { groupId: target })
|
|
588
|
+
} else {
|
|
589
|
+
next = applyToggle(disabled, { id: target, kind: target.includes('/') ? 'model' : 'tool' })
|
|
590
|
+
}
|
|
591
|
+
const result = await setDisabledState(next)
|
|
592
|
+
return JSON.stringify({ ok: true, saved: result.saved, disabled: result.disabled }, null, 2)
|
|
593
|
+
},
|
|
594
|
+
})))
|
|
595
|
+
|
|
508
596
|
disposers.push(ctx.tools.register(defineTool({
|
|
509
597
|
name: 'lovart_set_proxy',
|
|
510
598
|
description: 'Route all Lovart traffic (OAuth token calls and MCP) through an HTTP proxy, or clear it. Node fetch ignores HTTPS_PROXY, so this is the supported switch behind a firewall. Persists the value into the plugin config and remounts every account.',
|
|
@@ -723,6 +811,9 @@ export async function apply(ctx, config = {}) {
|
|
|
723
811
|
const access = await readValue(credentials, account.refs.access)
|
|
724
812
|
if (access === undefined) return `lovart-${account.id} is not authorized. Run lovart_login(account: "${account.id}") first.`
|
|
725
813
|
const kind = typeof args.kind === 'string' && args.kind === 'video' ? 'video' : 'image'
|
|
814
|
+
if (isToolDisabled(kind === 'video' ? 'generate_video' : 'generate_image', disabled)) {
|
|
815
|
+
return `generate_${kind} is switched off in the Lovart panel (模型与能力). Turn it back on to generate.`
|
|
816
|
+
}
|
|
726
817
|
const priced = quote({
|
|
727
818
|
kind,
|
|
728
819
|
model: typeof args.model === 'string' ? args.model : undefined,
|
|
@@ -730,6 +821,9 @@ export async function apply(ctx, config = {}) {
|
|
|
730
821
|
duration: typeof args.duration === 'string' ? args.duration : undefined,
|
|
731
822
|
count: typeof args.count === 'string' ? args.count : 1,
|
|
732
823
|
})
|
|
824
|
+
if (isModelDisabled(priced.model, disabled)) {
|
|
825
|
+
return `Model ${priced.model} is switched off in the Lovart panel (模型与能力). Pick another model or turn it back on.`
|
|
826
|
+
}
|
|
733
827
|
if (priced.needsConfirmation && String(args.confirm_credits ?? '').toLowerCase() !== 'true') {
|
|
734
828
|
return JSON.stringify({
|
|
735
829
|
status: 'needs_confirmation',
|
|
@@ -927,6 +1021,9 @@ export async function apply(ctx, config = {}) {
|
|
|
927
1021
|
async execute(args) {
|
|
928
1022
|
const tool = String(args.tool ?? '').trim()
|
|
929
1023
|
if (!tool) return 'tool is required, for example tool:"get_task_status"'
|
|
1024
|
+
if (isToolDisabled(tool, disabled)) {
|
|
1025
|
+
return `${tool} is switched off in the Lovart panel (模型与能力). Turn it back on to call it.`
|
|
1026
|
+
}
|
|
930
1027
|
const wanted = String(args.account ?? accounts[0]?.id ?? '').trim()
|
|
931
1028
|
const target = accounts.find((item) => item.id === wanted) ?? accounts[0]
|
|
932
1029
|
if (!target) return 'No Lovart account configured. Run lovart_add_account first.'
|
|
@@ -1120,6 +1217,14 @@ export async function apply(ctx, config = {}) {
|
|
|
1120
1217
|
for (const account of accounts) await mountAccount(account)
|
|
1121
1218
|
return saved
|
|
1122
1219
|
},
|
|
1220
|
+
loadModels: () => loadModelCatalogue(),
|
|
1221
|
+
switchBoard: (models) => switchBoard(models, disabled),
|
|
1222
|
+
toggleSwitch: async ({ id, kind, groupId } = {}) => {
|
|
1223
|
+
const next = applyToggle(disabled, { id, kind, groupId })
|
|
1224
|
+
const result = await setDisabledState(next)
|
|
1225
|
+
const models = await loadModelCatalogue()
|
|
1226
|
+
return { ...result, board: switchBoard(models, result.disabled) }
|
|
1227
|
+
},
|
|
1123
1228
|
})
|
|
1124
1229
|
if (typeof disposePanel === 'function') disposers.push(disposePanel)
|
|
1125
1230
|
} catch (error) {
|
package/lib/panel.mjs
CHANGED
|
@@ -73,7 +73,7 @@ function readBody(req, limitBytes = 200_000) {
|
|
|
73
73
|
})
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
export function registerPanel(ctx, { accounts, credentials, login, addAccount, removeAccount, exportAccount, importAccount, exportState, importState, getProxy, setProxyValue }) {
|
|
76
|
+
export function registerPanel(ctx, { accounts, credentials, login, addAccount, removeAccount, exportAccount, importAccount, exportState, importState, getProxy, setProxyValue, loadModels, switchBoard, toggleSwitch }) {
|
|
77
77
|
const server = ctx.get?.('webServer')
|
|
78
78
|
if (server === undefined || typeof server.register !== 'function') return undefined
|
|
79
79
|
const connection = ctx.get?.('connection')
|
|
@@ -191,6 +191,29 @@ export function registerPanel(ctx, { accounts, credentials, login, addAccount, r
|
|
|
191
191
|
return writeJson(res, 404, { error: String(error instanceof Error ? error.message : error).slice(0, 300) })
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
+
if (route === 'switches' && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
195
|
+
if (typeof switchBoard !== 'function') return writeJson(res, 501, { error: 'switches are not available' })
|
|
196
|
+
const models = typeof loadModels === 'function' ? await loadModels() : []
|
|
197
|
+
return writeJson(res, 200, switchBoard(models))
|
|
198
|
+
}
|
|
199
|
+
if (route === 'switches' && req.method === 'POST') {
|
|
200
|
+
if (typeof toggleSwitch !== 'function') return writeJson(res, 501, { error: 'switches are not available' })
|
|
201
|
+
let body
|
|
202
|
+
try {
|
|
203
|
+
body = JSON.parse(await readBody(req))
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return writeJson(res, 400, { error: String(error instanceof Error ? error.message : error).slice(0, 200) })
|
|
206
|
+
}
|
|
207
|
+
const groupId = typeof body?.groupId === 'string' && body.groupId !== '' ? body.groupId : undefined
|
|
208
|
+
const id = typeof body?.id === 'string' && body.id !== '' ? body.id : undefined
|
|
209
|
+
if (groupId === undefined && id === undefined) return writeJson(res, 400, { error: 'id or groupId is required' })
|
|
210
|
+
try {
|
|
211
|
+
const result = await toggleSwitch({ id, kind: body?.kind, groupId })
|
|
212
|
+
return writeJson(res, 200, { ok: true, saved: result.saved, board: result.board })
|
|
213
|
+
} catch (error) {
|
|
214
|
+
return writeJson(res, 500, { error: String(error instanceof Error ? error.message : error).slice(0, 300) })
|
|
215
|
+
}
|
|
216
|
+
}
|
|
194
217
|
if (route === 'export' && req.method === 'POST') {
|
|
195
218
|
if (typeof exportAccount !== 'function') return writeJson(res, 501, { error: 'export is not available' })
|
|
196
219
|
const id = url.searchParams.get('account')
|
package/lib/proxy.mjs
CHANGED
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
const MCP_URL = process.env.LOVART_MCP_URL ?? 'https://lgw.lovart.ai/v1/openapi/mcp/widgets'
|
|
7
7
|
const TOKEN = process.env.LOVART_TOKEN ?? ''
|
|
8
8
|
const { httpRequest } = await import('./net.mjs')
|
|
9
|
+
const { filterToolList, isToolDisabled } = await import('./catalog.mjs')
|
|
10
|
+
|
|
11
|
+
// Tools switched off from the panel. The proxy hides them from tools/list and
|
|
12
|
+
// refuses tools/call, so the raw mcp__lovart-*__* tools really disappear.
|
|
13
|
+
const DISABLED = (process.env.LOVART_DISABLED_TOOLS ?? '')
|
|
14
|
+
.split(',')
|
|
15
|
+
.map((item) => item.trim())
|
|
16
|
+
.filter((item) => item !== '')
|
|
17
|
+
const switched = { tools: DISABLED, models: [], groups: [] }
|
|
9
18
|
|
|
10
19
|
if (TOKEN === '') {
|
|
11
20
|
process.stderr.write('lovart proxy: LOVART_TOKEN is missing\n')
|
|
@@ -26,14 +35,23 @@ function remember(message) {
|
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
|
|
38
|
+
function sanitize(message) {
|
|
39
|
+
if (message === null || typeof message !== 'object') return message
|
|
40
|
+
const tools = message.result?.tools
|
|
41
|
+
if (!Array.isArray(tools)) return message
|
|
42
|
+
const kept = filterToolList(tools, switched)
|
|
43
|
+
if (kept.length === tools.length) return message
|
|
44
|
+
return { ...message, result: { ...message.result, tools: kept } }
|
|
45
|
+
}
|
|
46
|
+
|
|
29
47
|
function emit(parsed) {
|
|
30
48
|
if (Array.isArray(parsed)) {
|
|
31
|
-
for (const item of parsed) if (item !== null && typeof item === 'object') { remember(item); write(item) }
|
|
49
|
+
for (const item of parsed) if (item !== null && typeof item === 'object') { remember(item); write(sanitize(item)) }
|
|
32
50
|
return
|
|
33
51
|
}
|
|
34
52
|
if (parsed === null || typeof parsed !== 'object') return
|
|
35
53
|
remember(parsed)
|
|
36
|
-
if (parsed.id !== undefined || parsed.method !== undefined || parsed.error !== undefined) write(parsed)
|
|
54
|
+
if (parsed.id !== undefined || parsed.method !== undefined || parsed.error !== undefined) write(sanitize(parsed))
|
|
37
55
|
}
|
|
38
56
|
|
|
39
57
|
async function forward(message) {
|
|
@@ -109,6 +127,14 @@ process.stdin.on('data', (chunk) => {
|
|
|
109
127
|
continue
|
|
110
128
|
}
|
|
111
129
|
sequence += 1
|
|
130
|
+
if (message?.method === 'tools/call' && isToolDisabled(message?.params?.name, switched)) {
|
|
131
|
+
write({
|
|
132
|
+
jsonrpc: '2.0',
|
|
133
|
+
id: message.id ?? null,
|
|
134
|
+
error: { code: -32601, message: `lovart proxy: tool "${message.params?.name}" is disabled in the plugin panel` },
|
|
135
|
+
})
|
|
136
|
+
continue
|
|
137
|
+
}
|
|
112
138
|
void forward(message).catch((error) => {
|
|
113
139
|
if (message?.id === undefined || message?.id === null) return
|
|
114
140
|
write({
|