dsh-lovart-mcp 0.9.2 → 0.12.2
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/LICENSE +21 -0
- package/README.md +36 -100
- package/assets/icon-256.png +0 -0
- package/assets/icon.png +0 -0
- package/client.js +268 -9
- package/lib/account-data.mjs +128 -0
- package/lib/index.js +197 -2
- package/lib/ledger.mjs +120 -0
- package/lib/mcp-call.mjs +1 -0
- package/lib/panel.mjs +119 -2
- package/lib/state.mjs +128 -0
- package/package.json +4 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bitfancy56
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,122 +1,58 @@
|
|
|
1
1
|
# dsh-lovart-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在 DeepSeek Harness 里使用 Lovart:登录一次,就能在对话中生成图片和视频。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 安装
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
2. **挂载**:每个已授权账号挂成一个 MCP 服务器,工具命名空间 `mcp__lovart-<id>__*`(18 个 Lovart 工具)。
|
|
9
|
-
3. **刷新**:每 60 秒检查一次,到期前 3 分钟用 refresh token 换新并重挂,凭据不变、工具名不变。
|
|
7
|
+
在 DSH 的插件页搜索 `dsh-lovart-mcp` 安装,或者:
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Lovart 网关对 MCP 的 `GET`(SSE 下行)返回 **400**,而 DSH 使用的 MCP SDK 只接受 405 作为「无 SSE」的正常响应,其它状态一律判定连接失败并无限重连。
|
|
14
|
-
所以插件为每个账号起一个 `lib/proxy.mjs` 子进程(stdio ↔ 一次一发 HTTP POST),绕开 SSE GET。
|
|
15
|
-
|
|
16
|
-
## 配置
|
|
17
|
-
|
|
18
|
-
bundle 自带 `cordis.patch.yml`:
|
|
19
|
-
|
|
20
|
-
```yaml
|
|
21
|
-
- insert:
|
|
22
|
-
- id: lovart-mcp
|
|
23
|
-
name: dsh-lovart-mcp
|
|
24
|
-
config:
|
|
25
|
-
accounts:
|
|
26
|
-
- id: a
|
|
27
|
-
label: Lovart A
|
|
28
|
-
- id: b
|
|
29
|
-
label: Lovart B
|
|
9
|
+
```bash
|
|
10
|
+
dsh plugin install dsh-lovart-mcp
|
|
30
11
|
```
|
|
31
12
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## 使用
|
|
35
|
-
|
|
36
|
-
- `lovart_login(account: "a")` → 返回授权 URL;在浏览器打开并用对应 Lovart 账号点「允许」(15 分钟内有效)。
|
|
37
|
-
- `lovart_status()` → 各账号是否已授权、令牌剩余时间。
|
|
38
|
-
- `lovart_diagnose()` → 各 MCP 实例的连接状态与工具数。
|
|
39
|
-
- `lovart_logout(account: "a")`(或 `all`)→ 删除该账号凭据并卸载实例。
|
|
40
|
-
|
|
41
|
-
## 多账号隔离
|
|
42
|
-
|
|
43
|
-
- 每个账号独立凭据:`LOVART_<ID>_ACCESS` / `_REFRESH` / `_EXPIRES`。
|
|
44
|
-
- 每个账号独立 MCP 实例与工具命名空间,可同时调用:`mcp__lovart-a__generate_image`、`mcp__lovart-b__get_credits`。
|
|
45
|
-
- 生成会消耗**对应账号**的积分;不确定余额时先 `get_credits`。
|
|
46
|
-
|
|
47
|
-
## 安全边界
|
|
48
|
-
|
|
49
|
-
- 只用公开预注册客户端 `codex-lovart`(无 client secret,`token_endpoint_auth_methods_supported: none`)。
|
|
50
|
-
- 不读取浏览器 Cookie / session token,不把令牌写进 config 或聊天。
|
|
51
|
-
- 凭据存于 DSH credentials;`lovart_logout` 可随时清除。
|
|
52
|
-
|
|
53
|
-
## 成本策略(Relax 优先)
|
|
54
|
-
|
|
55
|
-
- `lovart_catalog()` → 模型、分辨率、积分单价与 Relax 窗口一览。
|
|
56
|
-
- `lovart_quote()` → 不生成,只估算:积分、按套餐折算的美元、是否有 Relax 慢速无限通道、是否需要确认。
|
|
57
|
-
- `lovart_generate()` → 带成本闸门的生成:
|
|
58
|
-
- 默认走 **Relax 模型**(`vertex/nano-banana-2`,1K,8 积分)并用最小够用分辨率;
|
|
59
|
-
- 没有 Relax 通道的模型、估算 ≥ 50 积分、或积分未公开时,先返回 `status: "needs_confirmation"`,明确写出积分与美元,需显式 `confirm_credits: "true"` 才提交;
|
|
60
|
-
- 提交后返回 `quotedCredits` 与实际 `result`(task/project),便于事后核对扣费。
|
|
13
|
+
## 登录
|
|
61
14
|
|
|
62
|
-
|
|
15
|
+
1. 打开插件页里的 **dsh-lovart-mcp**,会看到账号面板。
|
|
16
|
+
2. 在账号卡片上点 **登录**。
|
|
17
|
+
3. 浏览器会打开 Lovart 授权页,选择你的账号并点「允许」。
|
|
18
|
+
4. 回到对话就能用了。
|
|
63
19
|
|
|
64
|
-
|
|
20
|
+
需要再加账号时,在面板或对话里说「加一个 lovart-b」,然后用另一个 Lovart 号重复上面的登录。
|
|
65
21
|
|
|
66
|
-
|
|
67
|
-
- 令牌过期依赖 refresh token;若 Lovart 撤销刷新,需要重新 `lovart_login`。
|
|
68
|
-
- `lovart_status` 只显示剩余秒数,从不显示令牌本身。
|
|
69
|
-
- 积分价格表里 `openai/gpt-image-2` 2K = 12 积分是本地实测;其余为 Lovart 公布的每输出积分,未公开的保持 `null`(强制确认),不做猜测。
|
|
70
|
-
- MCP 接口不暴露 Relax 开关:插件只能优先选择 Relax 模型与低分辨率,实际是否走慢速队列由 Lovart 侧决定。
|
|
71
|
-
|
|
72
|
-
## 凭据导出 / 导入(迁移自己的登录)
|
|
73
|
-
|
|
74
|
-
- `lovart_export_credential(account: "a")` → 在 `~/.lovart-exports/` 写出两个文件:`lovart-a-<时间>.cred.json`(AES-256-GCM + scrypt 加密)与 `lovart-a-<时间>.key`(一次性密钥)。工具只返回路径,**从不打印令牌或密钥**。
|
|
75
|
-
- `lovart_import_credential(bundle: "...", key_file: "...")` → 解密后写入 `LOVART_<ID>_ACCESS/_REFRESH/_EXPIRES` 并挂载 `lovart-<id>`;目标账号需先 `lovart_add_account`。
|
|
76
|
-
- 两个文件分开渠道传输;两端同时刷新会互相顶掉刷新令牌,只保留一边使用更稳。
|
|
77
|
-
- **合规提醒**:Lovart 条款禁止账号共享与转售。这个功能用于把自己的登录搬到自己的另一台机器;把账号交给别人使用有封号风险。
|
|
78
|
-
|
|
79
|
-
## 发布到插件市场
|
|
80
|
-
|
|
81
|
-
1. `npm publish`(包名 `dsh-lovart-mcp`,需要 npm 账号与 token)。
|
|
82
|
-
2. GitHub 仓库必须声明 `dsh.bundle` 清单、带 `dsh-plugin` topic,且仓库创建满 1 天。
|
|
83
|
-
3. 到 [awesome-dsh-plugin](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin) 提 PR,新增一个 `data/plugins/<owner>__<repo>.yml`(category 取值以该仓库的 contributing.md 为准):
|
|
22
|
+
## 使用
|
|
84
23
|
|
|
85
|
-
|
|
86
|
-
url: https://github.com/<owner>/<repo>
|
|
87
|
-
name: <owner>/<repo>
|
|
88
|
-
category: tools
|
|
89
|
-
description:
|
|
90
|
-
en: Lovart MCP over native OAuth for DSH with per-account servers and credit quoting.
|
|
91
|
-
zh: 为 DSH 提供 Lovart MCP 原生 OAuth 多账号接入,并在生成前报价。
|
|
92
|
-
```
|
|
24
|
+
直接说需求即可,例如「用 lovart-a 生成一张 1K 的插画」。对应工具名是 `mcp__lovart-a__generate_image`。
|
|
93
25
|
|
|
94
|
-
|
|
26
|
+
| 想做的事 | 工具 |
|
|
27
|
+
|---|---|
|
|
28
|
+
| 生成图片或视频 | `lovart_generate` |
|
|
29
|
+
| 先看会用多少积分 | `lovart_quote` |
|
|
30
|
+
| 查支持的模型 | `lovart_catalog` |
|
|
31
|
+
| 改图、放大、抠图、分层、上传、查任务、管项目 | `lovart_tool` |
|
|
32
|
+
| 看账号状态与余额 | 面板,或 `lovart_status` |
|
|
33
|
+
| 看项目、模型权限、任务与素材记录 | `lovart_account` |
|
|
34
|
+
| 添加 / 移除账号 | `lovart_add_account` / `lovart_remove_account` |
|
|
35
|
+
| 设置代理 | `lovart_set_proxy` |
|
|
36
|
+
| 导出 / 导入登录 | 面板按钮,或 `lovart_export_credential` / `lovart_import_credential` |
|
|
37
|
+
| 导出 / 导入任务与素材记录 | 面板按钮,或 `lovart_export_state` / `lovart_import_state` |
|
|
95
38
|
|
|
96
|
-
|
|
39
|
+
提交生成前会先给出积分报价,确认后才执行。
|
|
97
40
|
|
|
98
|
-
|
|
41
|
+
## 网络
|
|
99
42
|
|
|
100
|
-
|
|
43
|
+
连不上 Lovart 时,在面板的「代理」填 HTTP 代理地址并保存,或:
|
|
101
44
|
|
|
102
45
|
```
|
|
103
|
-
lovart_set_proxy(
|
|
46
|
+
lovart_set_proxy("http://127.0.0.1:7890")
|
|
104
47
|
```
|
|
105
48
|
|
|
106
|
-
|
|
49
|
+
留空即恢复直连。
|
|
107
50
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
代理只影响 Lovart 相关流量(OAuth 令牌请求、MCP 调用、stdio 子进程),不影响 DSH 其他插件。
|
|
111
|
-
|
|
112
|
-
## 任意工具直通
|
|
113
|
-
|
|
114
|
-
`lovart_tool(tool, args, account)` 可以直接调用任意 Lovart MCP 工具,把参数作为 JSON 传入:
|
|
115
|
-
|
|
116
|
-
```
|
|
117
|
-
lovart_tool(tool: "get_task_status", args: "{\"task_ids\":[\"...\"]}")
|
|
118
|
-
lovart_tool(tool: "upscale", args: "{\"media\":\"https://...\"}", account: "b")
|
|
119
|
-
```
|
|
51
|
+
## 安全
|
|
120
52
|
|
|
121
|
-
|
|
53
|
+
- 插件不显示、不打印令牌,登录信息存在 DSH 凭据里。
|
|
54
|
+
- 登录全程在浏览器完成,插件不需要你的密码或验证码。
|
|
55
|
+
- 导出的凭据包等于该账号的控制权,只给自己、分开渠道传输,用完及时删除。
|
|
56
|
+
- 任务与素材记录里只有任务 ID、状态和产物链接,不含令牌,可以随便传。
|
|
122
57
|
|
|
58
|
+
开发与实现说明见仓库里的 `DEVELOPING.md`。
|
|
Binary file
|
package/assets/icon.png
ADDED
|
Binary file
|
package/client.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Lovart account panel for the DSH Web GUI.
|
|
2
|
-
// Reads only the plugin's same-origin
|
|
2
|
+
// Reads only the plugin's same-origin JSON routes; no tokens are ever shown.
|
|
3
3
|
window.__ModuleLoader__.load({
|
|
4
4
|
id: 'dsh-lovart-mcp',
|
|
5
5
|
factory(require) {
|
|
@@ -41,9 +41,19 @@ window.__ModuleLoader__.load({
|
|
|
41
41
|
},
|
|
42
42
|
}, label)
|
|
43
43
|
|
|
44
|
+
const note = (text, tone) => h('div', {
|
|
45
|
+
style: {
|
|
46
|
+
fontSize: '11px',
|
|
47
|
+
lineHeight: '17px',
|
|
48
|
+
wordBreak: 'break-all',
|
|
49
|
+
color: tone === 'danger' ? 'var(--dsw-alias-text-danger, #e03131)' : 'var(--dsw-alias-text-secondary, #888)',
|
|
50
|
+
},
|
|
51
|
+
}, text)
|
|
52
|
+
|
|
44
53
|
function useStatus() {
|
|
45
54
|
const [data, setData] = React.useState({ loading: true, accounts: [] })
|
|
46
55
|
const [busy, setBusy] = React.useState('')
|
|
56
|
+
const [action, setAction] = React.useState(null)
|
|
47
57
|
const load = React.useCallback(async () => {
|
|
48
58
|
try {
|
|
49
59
|
const response = await fetch(`${API}/status`, { headers: { accept: 'application/json' } })
|
|
@@ -54,24 +64,120 @@ window.__ModuleLoader__.load({
|
|
|
54
64
|
}
|
|
55
65
|
}, [])
|
|
56
66
|
React.useEffect(() => { void load() }, [load])
|
|
67
|
+
const fail = (message) => setData((current) => ({ ...current, error: message }))
|
|
57
68
|
const login = async (id) => {
|
|
58
69
|
setBusy(id)
|
|
59
70
|
try {
|
|
60
71
|
const response = await fetch(`${API}/login?account=${encodeURIComponent(id)}`, { method: 'POST' })
|
|
61
72
|
if (!response.ok) {
|
|
62
73
|
const body = await response.json().catch(() => ({}))
|
|
63
|
-
|
|
74
|
+
fail(body.error || `login failed (${response.status})`)
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
fail(String((error && error.message) || error))
|
|
78
|
+
} finally {
|
|
79
|
+
setBusy('')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const exportAccount = async (id) => {
|
|
83
|
+
setBusy(`export:${id}`)
|
|
84
|
+
try {
|
|
85
|
+
const response = await fetch(`${API}/export?account=${encodeURIComponent(id)}`, { method: 'POST' })
|
|
86
|
+
const body = await response.json().catch(() => ({}))
|
|
87
|
+
if (!response.ok) {
|
|
88
|
+
fail(body.error || `export failed (${response.status})`)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
setAction({ kind: 'export', account: id, bundle: body.bundle, key: body.key_file })
|
|
92
|
+
} catch (error) {
|
|
93
|
+
fail(String((error && error.message) || error))
|
|
94
|
+
} finally {
|
|
95
|
+
setBusy('')
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const importBundle = async ({ accountId, bundleText, keyText }) => {
|
|
99
|
+
setBusy('import')
|
|
100
|
+
try {
|
|
101
|
+
const response = await fetch(`${API}/import`, {
|
|
102
|
+
method: 'POST',
|
|
103
|
+
headers: { 'content-type': 'application/json' },
|
|
104
|
+
body: JSON.stringify({ account: accountId || undefined, bundle: bundleText, key: keyText }),
|
|
105
|
+
})
|
|
106
|
+
const body = await response.json().catch(() => ({}))
|
|
107
|
+
if (!response.ok) {
|
|
108
|
+
fail(body.error || `import failed (${response.status})`)
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
setAction({ kind: 'import', account: body.account, server: body.server })
|
|
112
|
+
await load()
|
|
113
|
+
} catch (error) {
|
|
114
|
+
fail(String((error && error.message) || error))
|
|
115
|
+
} finally {
|
|
116
|
+
setBusy('')
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const exportState = async () => {
|
|
120
|
+
setBusy('state-export')
|
|
121
|
+
try {
|
|
122
|
+
const response = await fetch(`${API}/state/export`, { method: 'POST' })
|
|
123
|
+
const body = await response.json().catch(() => ({}))
|
|
124
|
+
if (!response.ok) {
|
|
125
|
+
fail(body.error || `export failed (${response.status})`)
|
|
126
|
+
return
|
|
127
|
+
}
|
|
128
|
+
setAction({ kind: 'state-export', path: body.path, counts: body.counts })
|
|
129
|
+
} catch (error) {
|
|
130
|
+
fail(String((error && error.message) || error))
|
|
131
|
+
} finally {
|
|
132
|
+
setBusy('')
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const importStateText = async (text) => {
|
|
136
|
+
setBusy('state-import')
|
|
137
|
+
try {
|
|
138
|
+
const response = await fetch(`${API}/state/import`, {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: { 'content-type': 'application/json' },
|
|
141
|
+
body: JSON.stringify({ text }),
|
|
142
|
+
})
|
|
143
|
+
const body = await response.json().catch(() => ({}))
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
fail(body.error || `import failed (${response.status})`)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
setAction({ kind: 'state-import', result: body })
|
|
149
|
+
await load()
|
|
150
|
+
} catch (error) {
|
|
151
|
+
fail(String((error && error.message) || error))
|
|
152
|
+
} finally {
|
|
153
|
+
setBusy('')
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const saveProxy = async (value) => {
|
|
157
|
+
setBusy('proxy')
|
|
158
|
+
try {
|
|
159
|
+
const response = await fetch(`${API}/proxy`, {
|
|
160
|
+
method: 'POST',
|
|
161
|
+
headers: { 'content-type': 'application/json' },
|
|
162
|
+
body: JSON.stringify({ proxy: value }),
|
|
163
|
+
})
|
|
164
|
+
const body = await response.json().catch(() => ({}))
|
|
165
|
+
if (!response.ok) {
|
|
166
|
+
fail(body.error || `proxy failed (${response.status})`)
|
|
167
|
+
return
|
|
64
168
|
}
|
|
169
|
+
setAction({ kind: 'proxy', proxy: body.proxy })
|
|
170
|
+
await load()
|
|
65
171
|
} catch (error) {
|
|
66
|
-
|
|
172
|
+
fail(String((error && error.message) || error))
|
|
67
173
|
} finally {
|
|
68
174
|
setBusy('')
|
|
69
175
|
}
|
|
70
176
|
}
|
|
71
|
-
return { data, busy, load, login }
|
|
177
|
+
return { data, busy, action, load, login, exportAccount, importBundle, exportState, importStateText, saveProxy }
|
|
72
178
|
}
|
|
73
179
|
|
|
74
|
-
function AccountCard({ account, busy, onLogin }) {
|
|
180
|
+
function AccountCard({ account, busy, onLogin, onExport }) {
|
|
75
181
|
const days = typeof account.expiresInSeconds === 'number' ? Math.round(account.expiresInSeconds / 86400) : undefined
|
|
76
182
|
return h('div', { style: cardStyle },
|
|
77
183
|
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' } },
|
|
@@ -88,15 +194,117 @@ window.__ModuleLoader__.load({
|
|
|
88
194
|
days !== undefined ? ` · 令牌 ${days} 天` : '',
|
|
89
195
|
account.connection ? ` · ${account.connection}` : '',
|
|
90
196
|
),
|
|
197
|
+
h('div', { style: { fontSize: '11px', opacity: 0.6 } },
|
|
198
|
+
typeof account.projectCount === 'number' ? `项目 ${account.projectCount}` : '项目 —',
|
|
199
|
+
typeof account.taskCount === 'number' ? ` · 本地记录任务 ${account.taskCount}` : '',
|
|
200
|
+
),
|
|
91
201
|
account.error ? h('div', { style: { fontSize: '11px', color: 'var(--dsw-alias-text-danger, #e03131)' } }, account.error) : null,
|
|
92
|
-
h('div', { style: { display: 'flex', gap: '8px', marginTop: '2px' } },
|
|
93
|
-
button(busy ? '正在打开…' : account.authorized ? '重新登录' : '登录', () => onLogin(account.id), !account.authorized),
|
|
202
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', marginTop: '2px' } },
|
|
203
|
+
button(busy === account.id ? '正在打开…' : account.authorized ? '重新登录' : '登录', () => onLogin(account.id), !account.authorized),
|
|
204
|
+
account.authorized ? button(busy === `export:${account.id}` ? '导出中…' : '导出登录', () => onExport(account.id)) : null,
|
|
205
|
+
),
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function ImportBox({ onImport, busy }) {
|
|
210
|
+
const bundleRef = React.useRef(null)
|
|
211
|
+
const keyRef = React.useRef(null)
|
|
212
|
+
const accountRef = React.useRef(null)
|
|
213
|
+
const [message, setMessage] = React.useState('')
|
|
214
|
+
const submit = async () => {
|
|
215
|
+
const bundleFile = bundleRef.current && bundleRef.current.files ? bundleRef.current.files[0] : undefined
|
|
216
|
+
const keyFile = keyRef.current && keyRef.current.files ? keyRef.current.files[0] : undefined
|
|
217
|
+
if (!bundleFile || !keyFile) {
|
|
218
|
+
setMessage('请选择凭据包和密钥文件。')
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
setMessage('导入中…')
|
|
222
|
+
const accountId = accountRef.current ? String(accountRef.current.value || '').trim() : ''
|
|
223
|
+
await onImport({
|
|
224
|
+
accountId,
|
|
225
|
+
bundleText: await bundleFile.text(),
|
|
226
|
+
keyText: await keyFile.text(),
|
|
227
|
+
})
|
|
228
|
+
setMessage('')
|
|
229
|
+
}
|
|
230
|
+
const inputStyle = {
|
|
231
|
+
fontSize: '11px',
|
|
232
|
+
color: 'var(--dsw-alias-text-secondary, #888)',
|
|
233
|
+
}
|
|
234
|
+
return h('div', {
|
|
235
|
+
style: {
|
|
236
|
+
border: '1px dashed var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
237
|
+
borderRadius: '10px',
|
|
238
|
+
padding: '10px 12px',
|
|
239
|
+
display: 'flex',
|
|
240
|
+
flexDirection: 'column',
|
|
241
|
+
gap: '8px',
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
h('div', { style: { fontSize: '12px', fontWeight: 600 } }, '导入另一台机器的登录'),
|
|
245
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '10px', alignItems: 'center' } },
|
|
246
|
+
h('label', { style: inputStyle }, '凭据包 ', h('input', { type: 'file', ref: bundleRef, accept: '.json' })),
|
|
247
|
+
h('label', { style: inputStyle }, '密钥文件 ', h('input', { type: 'file', ref: keyRef })),
|
|
248
|
+
h('input', {
|
|
249
|
+
ref: accountRef,
|
|
250
|
+
placeholder: '导入到账号(可留空)',
|
|
251
|
+
style: {
|
|
252
|
+
fontSize: '11px',
|
|
253
|
+
padding: '4px 8px',
|
|
254
|
+
borderRadius: '6px',
|
|
255
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
256
|
+
background: 'transparent',
|
|
257
|
+
color: 'inherit',
|
|
258
|
+
width: '150px',
|
|
259
|
+
},
|
|
260
|
+
}),
|
|
261
|
+
button(busy === 'import' ? '导入中…' : '导入', submit),
|
|
262
|
+
),
|
|
263
|
+
message ? note(message) : null,
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function StateBox({ onExport, onImport, busy }) {
|
|
268
|
+
const fileRef = React.useRef(null)
|
|
269
|
+
const [message, setMessage] = React.useState('')
|
|
270
|
+
const submit = async () => {
|
|
271
|
+
const file = fileRef.current && fileRef.current.files ? fileRef.current.files[0] : undefined
|
|
272
|
+
if (!file) {
|
|
273
|
+
setMessage('请选择记录文件。')
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
setMessage('导入中…')
|
|
277
|
+
await onImport(await file.text())
|
|
278
|
+
setMessage('')
|
|
279
|
+
}
|
|
280
|
+
return h('div', {
|
|
281
|
+
style: {
|
|
282
|
+
border: '1px dashed var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
283
|
+
borderRadius: '10px',
|
|
284
|
+
padding: '10px 12px',
|
|
285
|
+
display: 'flex',
|
|
286
|
+
flexDirection: 'column',
|
|
287
|
+
gap: '8px',
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
h('div', { style: { fontSize: '12px', fontWeight: 600 } }, '任务与素材记录'),
|
|
291
|
+
h('div', { style: { fontSize: '11px', opacity: 0.6 } }, '只包含任务 ID、状态、产物链接和上传记录,不含任何令牌。'),
|
|
292
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '10px', alignItems: 'center' } },
|
|
293
|
+
button(busy === 'state-export' ? '导出中…' : '导出全部记录', () => onExport()),
|
|
294
|
+
h('label', { style: { fontSize: '11px', color: 'var(--dsw-alias-text-secondary, #888)' } },
|
|
295
|
+
'选择记录文件 ',
|
|
296
|
+
h('input', { type: 'file', ref: fileRef, accept: '.json' }),
|
|
297
|
+
),
|
|
298
|
+
button(busy === 'state-import' ? '导入中…' : '导入记录', submit),
|
|
94
299
|
),
|
|
300
|
+
message ? note(message) : null,
|
|
95
301
|
)
|
|
96
302
|
}
|
|
97
303
|
|
|
98
304
|
function Panel() {
|
|
99
|
-
const { data, busy, load, login } = useStatus()
|
|
305
|
+
const { data, busy, action, load, login, exportAccount, importBundle, exportState, importStateText, saveProxy } = useStatus()
|
|
306
|
+
const [proxyDraft, setProxyDraft] = React.useState(null)
|
|
307
|
+
const shownProxy = proxyDraft ?? data.proxy ?? ''
|
|
100
308
|
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px', padding: '4px 0 12px' } },
|
|
101
309
|
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px' } },
|
|
102
310
|
h('div', null,
|
|
@@ -105,12 +313,63 @@ window.__ModuleLoader__.load({
|
|
|
105
313
|
),
|
|
106
314
|
button(data.loading ? '刷新中…' : '刷新', () => load()),
|
|
107
315
|
),
|
|
316
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '8px', alignItems: 'center' } },
|
|
317
|
+
h('span', { style: { fontSize: '11px', opacity: 0.65 } }, '代理'),
|
|
318
|
+
h('input', {
|
|
319
|
+
value: shownProxy,
|
|
320
|
+
placeholder: 'http://127.0.0.1:7890(留空直连)',
|
|
321
|
+
onChange: (event) => setProxyDraft(event.target.value),
|
|
322
|
+
style: {
|
|
323
|
+
fontSize: '11px',
|
|
324
|
+
padding: '4px 8px',
|
|
325
|
+
borderRadius: '6px',
|
|
326
|
+
border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
|
|
327
|
+
background: 'transparent',
|
|
328
|
+
color: 'inherit',
|
|
329
|
+
width: '240px',
|
|
330
|
+
},
|
|
331
|
+
}),
|
|
332
|
+
button(busy === 'proxy' ? '保存中…' : '保存', () => saveProxy(shownProxy)),
|
|
333
|
+
h('span', { style: { fontSize: '11px', opacity: 0.55 } }, '只影响 Lovart 流量'),
|
|
334
|
+
),
|
|
108
335
|
data.error ? h('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-text-danger, #e03131)' } }, data.error) : null,
|
|
109
336
|
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '10px' } },
|
|
110
337
|
data.accounts.length === 0 && !data.loading
|
|
111
338
|
? h('div', { style: { fontSize: '12px', opacity: 0.6 } }, '还没有配置账号。用 lovart_add_account 添加。')
|
|
112
|
-
: data.accounts.map((account) => h(AccountCard, {
|
|
339
|
+
: data.accounts.map((account) => h(AccountCard, {
|
|
340
|
+
key: account.id,
|
|
341
|
+
account,
|
|
342
|
+
busy,
|
|
343
|
+
onLogin: login,
|
|
344
|
+
onExport: exportAccount,
|
|
345
|
+
})),
|
|
113
346
|
),
|
|
347
|
+
action && action.kind === 'proxy'
|
|
348
|
+
? note(action.proxy ? `代理已设为 ${action.proxy},所有 Lovart 请求将走它。` : '代理已清除,改为直连。')
|
|
349
|
+
: null,
|
|
350
|
+
action && action.kind === 'export'
|
|
351
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
352
|
+
note(`已导出账号 ${action.account}:`),
|
|
353
|
+
note(action.bundle),
|
|
354
|
+
note(action.key),
|
|
355
|
+
note('两个文件请分开渠道传输;导入后原机器与这台不要同时刷新登录。'),
|
|
356
|
+
)
|
|
357
|
+
: null,
|
|
358
|
+
action && action.kind === 'import'
|
|
359
|
+
? note(`已导入账号 ${action.account},服务 ${action.server} 已挂载。`)
|
|
360
|
+
: null,
|
|
361
|
+
action && action.kind === 'state-export'
|
|
362
|
+
? h('div', { style: { display: 'flex', flexDirection: 'column', gap: '4px' } },
|
|
363
|
+
note('记录已导出:'),
|
|
364
|
+
note(action.path),
|
|
365
|
+
note(`任务 ${action.counts?.tasks ?? 0} 条 · 素材 ${action.counts?.assets ?? 0} 条`),
|
|
366
|
+
)
|
|
367
|
+
: null,
|
|
368
|
+
action && action.kind === 'state-import'
|
|
369
|
+
? note(`已合并记录:新增任务 ${action.result?.addedTasks ?? 0}、更新 ${action.result?.updatedTasks ?? 0}、新增素材 ${action.result?.addedAssets ?? 0}。`)
|
|
370
|
+
: null,
|
|
371
|
+
h(ImportBox, { onImport: importBundle, busy }),
|
|
372
|
+
h(StateBox, { onExport: exportState, onImport: importStateText, busy }),
|
|
114
373
|
)
|
|
115
374
|
}
|
|
116
375
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Organized reads of what a Lovart account exposes over MCP.
|
|
3
|
+
*
|
|
4
|
+
* Lovart answers list_projects with a rendered card and puts the real rows in
|
|
5
|
+
* `_meta['lovart/ui']`, so the raw envelope is what carries project names,
|
|
6
|
+
* covers and image counts. credits/models/tasks come from their own tools.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { callTool } from './mcp-call.mjs'
|
|
10
|
+
|
|
11
|
+
const UI_META = 'lovart/ui'
|
|
12
|
+
|
|
13
|
+
const cleanCover = (url) => (typeof url === 'string' && url !== '' && !url.includes('{{') ? url : null)
|
|
14
|
+
|
|
15
|
+
export function pickProjects(raw, fallbackTotal = 0) {
|
|
16
|
+
const ui = raw?._meta?.[UI_META]
|
|
17
|
+
const rows = Array.isArray(ui?.projects) ? ui.projects : []
|
|
18
|
+
return {
|
|
19
|
+
total: Number(ui?.total ?? fallbackTotal ?? rows.length),
|
|
20
|
+
projects: rows.map((row) => {
|
|
21
|
+
const rawCover = row.cover_url ?? row.coverUrl ?? null
|
|
22
|
+
return {
|
|
23
|
+
id: row.project_id ?? row.projectId ?? '',
|
|
24
|
+
name: row.name ?? '',
|
|
25
|
+
updatedAt: row.updated_at ?? row.updatedAt ?? null,
|
|
26
|
+
imageCount: typeof row.image_count === 'number' ? row.image_count : row.imageCount ?? null,
|
|
27
|
+
editUrl: row.edit_url ?? row.editUrl ?? null,
|
|
28
|
+
coverUrl: cleanCover(rawCover),
|
|
29
|
+
hasCover: typeof rawCover === 'string' && rawCover !== '',
|
|
30
|
+
}
|
|
31
|
+
}),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function summarizeModels(payload, kindHint = '') {
|
|
36
|
+
const models = Array.isArray(payload?.models) ? payload.models : []
|
|
37
|
+
const kind = kindHint || payload?.kind || models[0]?.kind || ''
|
|
38
|
+
const rows = models.map((model) => ({
|
|
39
|
+
model: model.name ?? model.model ?? model.id ?? '',
|
|
40
|
+
label: model.display_name ?? model.label ?? model.name ?? '',
|
|
41
|
+
description: typeof model.description === 'string' ? model.description.slice(0, 140) : null,
|
|
42
|
+
default: model.default === true,
|
|
43
|
+
membersOnly: model.members_only === true || model.membersOnly === true,
|
|
44
|
+
kind: model.kind ?? kind,
|
|
45
|
+
}))
|
|
46
|
+
const byKind = kind === 'image' ? payload?.default_image_model : kind === 'video' ? payload?.default_video_model : undefined
|
|
47
|
+
return {
|
|
48
|
+
kind,
|
|
49
|
+
defaultModel: byKind ?? payload?.default_model ?? payload?.defaultModel ?? rows.find((row) => row.default)?.model ?? null,
|
|
50
|
+
total: rows.length,
|
|
51
|
+
membersOnly: rows.filter((row) => row.membersOnly).length,
|
|
52
|
+
models: rows,
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function summarizeCredits(payload) {
|
|
57
|
+
if (payload === null || typeof payload !== 'object') return null
|
|
58
|
+
return {
|
|
59
|
+
credits: typeof payload.credits === 'number' ? payload.credits : null,
|
|
60
|
+
member: payload.member === true,
|
|
61
|
+
concurrencyLimit: typeof payload.concurrency_limit === 'number' ? payload.concurrency_limit : payload.concurrencyLimit ?? null,
|
|
62
|
+
homeUrl: payload.home_url ?? payload.homeUrl ?? null,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function extractTaskHandles(result) {
|
|
67
|
+
if (result === null || typeof result !== 'object') return { taskIds: [], projectId: null, status: null, artifacts: [] }
|
|
68
|
+
const deep = result.result && typeof result.result === 'object' ? result.result : result
|
|
69
|
+
const ids = []
|
|
70
|
+
for (const candidate of [deep.task_ids, deep.taskIds, deep.task_id, deep.taskId]) {
|
|
71
|
+
if (Array.isArray(candidate)) ids.push(...candidate.filter((id) => typeof id === 'string' && id.length > 0))
|
|
72
|
+
else if (typeof candidate === 'string' && candidate.length > 0) ids.push(candidate)
|
|
73
|
+
}
|
|
74
|
+
const artifacts = []
|
|
75
|
+
for (const candidate of [deep.artifacts, deep.artifact]) {
|
|
76
|
+
if (Array.isArray(candidate)) artifacts.push(...candidate)
|
|
77
|
+
else if (candidate && typeof candidate === 'object') artifacts.push(candidate)
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
taskIds: [...new Set(ids)],
|
|
81
|
+
projectId: deep.project_id ?? deep.projectId ?? null,
|
|
82
|
+
status: typeof deep.status === 'string' ? deep.status : null,
|
|
83
|
+
artifacts: artifacts.filter((item) => item && typeof item === 'object'),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function summarizeTask(payload) {
|
|
88
|
+
if (payload === null || typeof payload !== 'object') return null
|
|
89
|
+
const task = payload.task && typeof payload.task === 'object' ? payload.task : payload
|
|
90
|
+
return {
|
|
91
|
+
taskId: task.task_id ?? task.taskId ?? null,
|
|
92
|
+
status: task.status ?? null,
|
|
93
|
+
tool: task.tool ?? null,
|
|
94
|
+
model: task.model ?? null,
|
|
95
|
+
progress: typeof task.progress === 'number' ? task.progress : null,
|
|
96
|
+
durationMs: typeof task.duration_ms === 'number' ? task.duration_ms : task.durationMs ?? null,
|
|
97
|
+
error: typeof task.error === 'string' ? task.error : null,
|
|
98
|
+
artifacts: (Array.isArray(task.artifacts) ? task.artifacts : task.artifact ? [task.artifact] : []).map((item) => ({
|
|
99
|
+
url: item?.url ?? null,
|
|
100
|
+
format: item?.format ?? null,
|
|
101
|
+
width: item?.width ?? null,
|
|
102
|
+
height: item?.height ?? null,
|
|
103
|
+
})),
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function readCredits(token, options = {}) {
|
|
108
|
+
const payload = await callTool(token, 'get_credits', {}, { timeoutMs: options.timeoutMs ?? 20000 })
|
|
109
|
+
return summarizeCredits(payload)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export async function readProjects(token, { limit = 12 } = {}) {
|
|
113
|
+
const raw = await callTool(token, 'list_projects', { limit }, { raw: true, timeoutMs: 60000 })
|
|
114
|
+
const fallback = raw?.structuredContent?.total ?? 0
|
|
115
|
+
return pickProjects(raw, fallback)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function readModels(token, kind = 'image') {
|
|
119
|
+
const payload = await callTool(token, 'list_models', { kind }, { timeoutMs: 60000 })
|
|
120
|
+
return summarizeModels(payload, kind)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function readTasks(token, taskIds, options = {}) {
|
|
124
|
+
if (!Array.isArray(taskIds) || taskIds.length === 0) return []
|
|
125
|
+
const payload = await callTool(token, 'get_task_status', { task_ids: taskIds }, { timeoutMs: options.timeoutMs ?? 60000 })
|
|
126
|
+
const rows = Array.isArray(payload) ? payload : Array.isArray(payload?.tasks) ? payload.tasks : [payload]
|
|
127
|
+
return rows.map(summarizeTask).filter((row) => row !== null)
|
|
128
|
+
}
|