dsh-lovart-mcp 0.0.0-stage → 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 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,3 +1,58 @@
1
- # Temporary Holding Version
1
+ # dsh-lovart-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 在 DeepSeek Harness 里使用 Lovart:登录一次,就能在对话中生成图片和视频。
4
+
5
+ ## 安装
6
+
7
+ 在 DSH 的插件页搜索 `dsh-lovart-mcp` 安装,或者:
8
+
9
+ ```bash
10
+ dsh plugin install dsh-lovart-mcp
11
+ ```
12
+
13
+ ## 登录
14
+
15
+ 1. 打开插件页里的 **dsh-lovart-mcp**,会看到账号面板。
16
+ 2. 在账号卡片上点 **登录**。
17
+ 3. 浏览器会打开 Lovart 授权页,选择你的账号并点「允许」。
18
+ 4. 回到对话就能用了。
19
+
20
+ 需要再加账号时,在面板或对话里说「加一个 lovart-b」,然后用另一个 Lovart 号重复上面的登录。
21
+
22
+ ## 使用
23
+
24
+ 直接说需求即可,例如「用 lovart-a 生成一张 1K 的插画」。对应工具名是 `mcp__lovart-a__generate_image`。
25
+
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` |
38
+
39
+ 提交生成前会先给出积分报价,确认后才执行。
40
+
41
+ ## 网络
42
+
43
+ 连不上 Lovart 时,在面板的「代理」填 HTTP 代理地址并保存,或:
44
+
45
+ ```
46
+ lovart_set_proxy("http://127.0.0.1:7890")
47
+ ```
48
+
49
+ 留空即恢复直连。
50
+
51
+ ## 安全
52
+
53
+ - 插件不显示、不打印令牌,登录信息存在 DSH 凭据里。
54
+ - 登录全程在浏览器完成,插件不需要你的密码或验证码。
55
+ - 导出的凭据包等于该账号的控制权,只给自己、分开渠道传输,用完及时删除。
56
+ - 任务与素材记录里只有任务 ID、状态和产物链接,不含令牌,可以随便传。
57
+
58
+ 开发与实现说明见仓库里的 `DEVELOPING.md`。
Binary file
Binary file
package/client.js ADDED
@@ -0,0 +1,388 @@
1
+ // Lovart account panel for the DSH Web GUI.
2
+ // Reads only the plugin's same-origin JSON routes; no tokens are ever shown.
3
+ window.__ModuleLoader__.load({
4
+ id: 'dsh-lovart-mcp',
5
+ factory(require) {
6
+ const React = require('react')
7
+ const h = React.createElement
8
+ const API = '/lovart-panel/api'
9
+
10
+ const cardStyle = {
11
+ border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.25))',
12
+ borderRadius: '10px',
13
+ padding: '12px 14px',
14
+ display: 'flex',
15
+ flexDirection: 'column',
16
+ gap: '8px',
17
+ minWidth: '210px',
18
+ background: 'var(--dsw-alias-bg-elevated, transparent)',
19
+ }
20
+ const pill = (text, tone) => h('span', {
21
+ style: {
22
+ fontSize: '11px',
23
+ lineHeight: '18px',
24
+ padding: '0 8px',
25
+ borderRadius: '999px',
26
+ color: tone === 'ok' ? 'var(--dsw-alias-text-success, #2f9e44)' : tone === 'warn' ? 'var(--dsw-alias-text-warning, #e8590c)' : 'var(--dsw-alias-text-secondary, #888)',
27
+ background: tone === 'ok' ? 'var(--dsw-alias-bg-success-subtle, rgba(47,158,68,.12))' : tone === 'warn' ? 'var(--dsw-alias-bg-warning-subtle, rgba(232,89,12,.12))' : 'var(--dsw-alias-bg-subtle, rgba(127,127,127,.12))',
28
+ },
29
+ }, text)
30
+
31
+ const button = (label, onClick, primary) => h('button', {
32
+ onClick,
33
+ style: {
34
+ cursor: 'pointer',
35
+ border: '1px solid var(--dsw-alias-border-subtle, rgba(127,127,127,.3))',
36
+ borderRadius: '8px',
37
+ padding: '4px 12px',
38
+ fontSize: '12px',
39
+ background: primary ? 'var(--dsw-alias-bg-accent, #3b6cf6)' : 'transparent',
40
+ color: primary ? '#fff' : 'var(--dsw-alias-text-primary, inherit)',
41
+ },
42
+ }, label)
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
+
53
+ function useStatus() {
54
+ const [data, setData] = React.useState({ loading: true, accounts: [] })
55
+ const [busy, setBusy] = React.useState('')
56
+ const [action, setAction] = React.useState(null)
57
+ const load = React.useCallback(async () => {
58
+ try {
59
+ const response = await fetch(`${API}/status`, { headers: { accept: 'application/json' } })
60
+ const body = await response.json()
61
+ setData({ loading: false, ...body })
62
+ } catch (error) {
63
+ setData({ loading: false, accounts: [], error: String((error && error.message) || error) })
64
+ }
65
+ }, [])
66
+ React.useEffect(() => { void load() }, [load])
67
+ const fail = (message) => setData((current) => ({ ...current, error: message }))
68
+ const login = async (id) => {
69
+ setBusy(id)
70
+ try {
71
+ const response = await fetch(`${API}/login?account=${encodeURIComponent(id)}`, { method: 'POST' })
72
+ if (!response.ok) {
73
+ const body = await response.json().catch(() => ({}))
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
168
+ }
169
+ setAction({ kind: 'proxy', proxy: body.proxy })
170
+ await load()
171
+ } catch (error) {
172
+ fail(String((error && error.message) || error))
173
+ } finally {
174
+ setBusy('')
175
+ }
176
+ }
177
+ return { data, busy, action, load, login, exportAccount, importBundle, exportState, importStateText, saveProxy }
178
+ }
179
+
180
+ function AccountCard({ account, busy, onLogin, onExport }) {
181
+ const days = typeof account.expiresInSeconds === 'number' ? Math.round(account.expiresInSeconds / 86400) : undefined
182
+ return h('div', { style: cardStyle },
183
+ h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '8px' } },
184
+ h('strong', { style: { fontSize: '13px' } }, account.label || account.id),
185
+ account.authorized ? pill('已登录', 'ok') : pill('未登录', 'warn'),
186
+ ),
187
+ h('div', { style: { fontSize: '11px', opacity: 0.65 } }, `${account.server} · ${account.id}`),
188
+ h('div', { style: { fontSize: '20px', fontWeight: 600 } },
189
+ typeof account.credits === 'number' ? account.credits.toLocaleString() : '—',
190
+ h('span', { style: { fontSize: '11px', fontWeight: 400, opacity: 0.6, marginLeft: '6px' } }, '积分'),
191
+ ),
192
+ h('div', { style: { fontSize: '11px', opacity: 0.7 } },
193
+ account.member ? '会员' : '非会员',
194
+ days !== undefined ? ` · 令牌 ${days} 天` : '',
195
+ account.connection ? ` · ${account.connection}` : '',
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
+ ),
201
+ account.error ? h('div', { style: { fontSize: '11px', color: 'var(--dsw-alias-text-danger, #e03131)' } }, account.error) : null,
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),
299
+ ),
300
+ message ? note(message) : null,
301
+ )
302
+ }
303
+
304
+ function Panel() {
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 ?? ''
308
+ return h('div', { style: { display: 'flex', flexDirection: 'column', gap: '12px', padding: '4px 0 12px' } },
309
+ h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: '12px' } },
310
+ h('div', null,
311
+ h('div', { style: { fontSize: '13px', fontWeight: 600 } }, 'Lovart 账号'),
312
+ h('div', { style: { fontSize: '11px', opacity: 0.65 } }, '登录会打开系统默认浏览器,请在那个页面选择要授权的 Lovart 账号并点「允许」。'),
313
+ ),
314
+ button(data.loading ? '刷新中…' : '刷新', () => load()),
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
+ ),
335
+ data.error ? h('div', { style: { fontSize: '12px', color: 'var(--dsw-alias-text-danger, #e03131)' } }, data.error) : null,
336
+ h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: '10px' } },
337
+ data.accounts.length === 0 && !data.loading
338
+ ? h('div', { style: { fontSize: '12px', opacity: 0.6 } }, '还没有配置账号。用 lovart_add_account 添加。')
339
+ : data.accounts.map((account) => h(AccountCard, {
340
+ key: account.id,
341
+ account,
342
+ busy,
343
+ onLogin: login,
344
+ onExport: exportAccount,
345
+ })),
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 }),
373
+ )
374
+ }
375
+
376
+ return {
377
+ inject: ['slots'],
378
+ apply(ctx) {
379
+ ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
380
+ name: 'plugins.bundle.config',
381
+ id: 'lovart-accounts',
382
+ key: 'dsh-lovart-mcp',
383
+ order: 10,
384
+ }, Panel))
385
+ },
386
+ }
387
+ },
388
+ })
@@ -0,0 +1,10 @@
1
+ - insert:
2
+ - id: lovart-mcp
3
+ name: dsh-lovart-mcp
4
+ config:
5
+ proxy: ''
6
+ accounts:
7
+ - id: a
8
+ label: Lovart A
9
+ - id: b
10
+ label: Lovart B
@@ -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
+ }