dsh-plugin-image-workbench 0.0.0-stage → 1.1.5

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 (185) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +256 -0
  3. package/README.md +256 -2
  4. package/client.js +241 -0
  5. package/cordis.patch.yml +14 -0
  6. package/host.js +641 -0
  7. package/install.mjs +387 -0
  8. package/package.json +57 -4
  9. package/scripts/vendor-snapshot.py +154 -0
  10. package/server/access.py +26 -0
  11. package/server/app.py +1329 -0
  12. package/server/catalog.json +1 -0
  13. package/server/catalog.py +147 -0
  14. package/server/composer.py +391 -0
  15. package/server/drafts.py +158 -0
  16. package/server/history.py +575 -0
  17. package/server/imaging.py +172 -0
  18. package/server/pool.py +1335 -0
  19. package/server/pool_admin.py +921 -0
  20. package/server/pool_service.py +1073 -0
  21. package/server/requirements.txt +6 -0
  22. package/server/smoke_check.py +402 -0
  23. package/server/static/access.html +202 -0
  24. package/server/static/index.html +4725 -0
  25. package/vendor/chatgpt2api/README.md +13 -0
  26. package/vendor/chatgpt2api/SOURCE.json +11 -0
  27. package/vendor/chatgpt2api/runtime/uv.exe +0 -0
  28. package/vendor/chatgpt2api/source/.env.example +82 -0
  29. package/vendor/chatgpt2api/source/.python-version +1 -0
  30. package/vendor/chatgpt2api/source/LICENSE +21 -0
  31. package/vendor/chatgpt2api/source/README.md +391 -0
  32. package/vendor/chatgpt2api/source/VERSION +1 -0
  33. package/vendor/chatgpt2api/source/api/__init__.py +2 -0
  34. package/vendor/chatgpt2api/source/api/accounts.py +537 -0
  35. package/vendor/chatgpt2api/source/api/ai.py +217 -0
  36. package/vendor/chatgpt2api/source/api/app.py +62 -0
  37. package/vendor/chatgpt2api/source/api/errors.py +46 -0
  38. package/vendor/chatgpt2api/source/api/image_inputs.py +309 -0
  39. package/vendor/chatgpt2api/source/api/image_tasks.py +120 -0
  40. package/vendor/chatgpt2api/source/api/support.py +134 -0
  41. package/vendor/chatgpt2api/source/api/system.py +365 -0
  42. package/vendor/chatgpt2api/source/assets/atlascloud.svg +1 -0
  43. package/vendor/chatgpt2api/source/assets/ipwo.png +0 -0
  44. package/vendor/chatgpt2api/source/assets/kunrouai.svg +50 -0
  45. package/vendor/chatgpt2api/source/config.default.json +108 -0
  46. package/vendor/chatgpt2api/source/main.py +9 -0
  47. package/vendor/chatgpt2api/source/pyproject.toml +27 -0
  48. package/vendor/chatgpt2api/source/scripts/init_proxy_config.py +186 -0
  49. package/vendor/chatgpt2api/source/scripts/migrate_storage.py +163 -0
  50. package/vendor/chatgpt2api/source/scripts/privoxy-warp.conf +13 -0
  51. package/vendor/chatgpt2api/source/scripts/test_outlook_token_mailbox.py +385 -0
  52. package/vendor/chatgpt2api/source/scripts/test_storage.py +129 -0
  53. package/vendor/chatgpt2api/source/scripts/verify_oauth_refresh.py +92 -0
  54. package/vendor/chatgpt2api/source/services/__init__.py +0 -0
  55. package/vendor/chatgpt2api/source/services/account_service.py +1757 -0
  56. package/vendor/chatgpt2api/source/services/auth_service.py +253 -0
  57. package/vendor/chatgpt2api/source/services/backup_service.py +671 -0
  58. package/vendor/chatgpt2api/source/services/config.py +667 -0
  59. package/vendor/chatgpt2api/source/services/content_filter.py +242 -0
  60. package/vendor/chatgpt2api/source/services/cpa_service.py +315 -0
  61. package/vendor/chatgpt2api/source/services/editable_file_task_service.py +260 -0
  62. package/vendor/chatgpt2api/source/services/image_service.py +376 -0
  63. package/vendor/chatgpt2api/source/services/image_storage_service.py +405 -0
  64. package/vendor/chatgpt2api/source/services/image_tags_service.py +76 -0
  65. package/vendor/chatgpt2api/source/services/image_task_service.py +550 -0
  66. package/vendor/chatgpt2api/source/services/log_service.py +337 -0
  67. package/vendor/chatgpt2api/source/services/model_service.py +182 -0
  68. package/vendor/chatgpt2api/source/services/oauth_login_service.py +267 -0
  69. package/vendor/chatgpt2api/source/services/openai_backend_api.py +2763 -0
  70. package/vendor/chatgpt2api/source/services/openai_oauth.py +32 -0
  71. package/vendor/chatgpt2api/source/services/protocol/__init__.py +2 -0
  72. package/vendor/chatgpt2api/source/services/protocol/anthropic_v1_messages.py +307 -0
  73. package/vendor/chatgpt2api/source/services/protocol/chat_completion_cache.py +238 -0
  74. package/vendor/chatgpt2api/source/services/protocol/conversation.py +1644 -0
  75. package/vendor/chatgpt2api/source/services/protocol/error_response.py +124 -0
  76. package/vendor/chatgpt2api/source/services/protocol/openai_search.py +19 -0
  77. package/vendor/chatgpt2api/source/services/protocol/openai_v1_chat_complete.py +316 -0
  78. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_edit.py +86 -0
  79. package/vendor/chatgpt2api/source/services/protocol/openai_v1_image_generations.py +42 -0
  80. package/vendor/chatgpt2api/source/services/protocol/openai_v1_models.py +53 -0
  81. package/vendor/chatgpt2api/source/services/protocol/openai_v1_response.py +453 -0
  82. package/vendor/chatgpt2api/source/services/protocol/web_search_tool.py +160 -0
  83. package/vendor/chatgpt2api/source/services/proxy_service.py +648 -0
  84. package/vendor/chatgpt2api/source/services/storage/__init__.py +5 -0
  85. package/vendor/chatgpt2api/source/services/storage/base.py +38 -0
  86. package/vendor/chatgpt2api/source/services/storage/database_storage.py +194 -0
  87. package/vendor/chatgpt2api/source/services/storage/factory.py +104 -0
  88. package/vendor/chatgpt2api/source/services/storage/git_storage.py +183 -0
  89. package/vendor/chatgpt2api/source/services/storage/json_storage.py +95 -0
  90. package/vendor/chatgpt2api/source/services/sub2api_service.py +531 -0
  91. package/vendor/chatgpt2api/source/utils/__init__.py +0 -0
  92. package/vendor/chatgpt2api/source/utils/helper.py +469 -0
  93. package/vendor/chatgpt2api/source/utils/image_tokens.py +346 -0
  94. package/vendor/chatgpt2api/source/utils/log.py +110 -0
  95. package/vendor/chatgpt2api/source/utils/pkce.py +19 -0
  96. package/vendor/chatgpt2api/source/utils/pow.py +207 -0
  97. package/vendor/chatgpt2api/source/utils/sentinel.py +159 -0
  98. package/vendor/chatgpt2api/source/utils/turnstile.py +184 -0
  99. package/vendor/chatgpt2api/source/uv.lock +904 -0
  100. package/vendor/chatgpt2api/source/web/bun.lock +1501 -0
  101. package/vendor/chatgpt2api/source/web/components.json +24 -0
  102. package/vendor/chatgpt2api/source/web/eslint.config.mjs +17 -0
  103. package/vendor/chatgpt2api/source/web/next.config.ts +40 -0
  104. package/vendor/chatgpt2api/source/web/package.json +58 -0
  105. package/vendor/chatgpt2api/source/web/postcss.config.mjs +5 -0
  106. package/vendor/chatgpt2api/source/web/public/github.svg +1 -0
  107. package/vendor/chatgpt2api/source/web/public/next.svg +1 -0
  108. package/vendor/chatgpt2api/source/web/public/openai.svg +1 -0
  109. package/vendor/chatgpt2api/source/web/public/vercel.svg +1 -0
  110. package/vendor/chatgpt2api/source/web/src/app/accounts/components/account-import-dialog.tsx +925 -0
  111. package/vendor/chatgpt2api/source/web/src/app/accounts/page.tsx +1307 -0
  112. package/vendor/chatgpt2api/source/web/src/app/debug/components/chat-panel.tsx +224 -0
  113. package/vendor/chatgpt2api/source/web/src/app/debug/components/editable-file-panel.tsx +444 -0
  114. package/vendor/chatgpt2api/source/web/src/app/debug/components/ppt-panel.tsx +9 -0
  115. package/vendor/chatgpt2api/source/web/src/app/debug/components/psd-panel.tsx +9 -0
  116. package/vendor/chatgpt2api/source/web/src/app/debug/components/search-panel.tsx +172 -0
  117. package/vendor/chatgpt2api/source/web/src/app/debug/components/skill-panel.tsx +169 -0
  118. package/vendor/chatgpt2api/source/web/src/app/debug/components/types.ts +39 -0
  119. package/vendor/chatgpt2api/source/web/src/app/debug/page.tsx +59 -0
  120. package/vendor/chatgpt2api/source/web/src/app/favicon.ico +0 -0
  121. package/vendor/chatgpt2api/source/web/src/app/globals.css +231 -0
  122. package/vendor/chatgpt2api/source/web/src/app/image/components/image-composer.tsx +542 -0
  123. package/vendor/chatgpt2api/source/web/src/app/image/components/image-results.tsx +554 -0
  124. package/vendor/chatgpt2api/source/web/src/app/image/components/image-sidebar.tsx +176 -0
  125. package/vendor/chatgpt2api/source/web/src/app/image/page.tsx +1799 -0
  126. package/vendor/chatgpt2api/source/web/src/app/image-manager/page.tsx +732 -0
  127. package/vendor/chatgpt2api/source/web/src/app/layout.tsx +50 -0
  128. package/vendor/chatgpt2api/source/web/src/app/login/page.tsx +101 -0
  129. package/vendor/chatgpt2api/source/web/src/app/logs/page.tsx +356 -0
  130. package/vendor/chatgpt2api/source/web/src/app/page.tsx +30 -0
  131. package/vendor/chatgpt2api/source/web/src/app/settings/components/api-docs-card.tsx +341 -0
  132. package/vendor/chatgpt2api/source/web/src/app/settings/components/backup-settings-card.tsx +447 -0
  133. package/vendor/chatgpt2api/source/web/src/app/settings/components/base-url-card.tsx +71 -0
  134. package/vendor/chatgpt2api/source/web/src/app/settings/components/config-card.tsx +491 -0
  135. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pool-dialog.tsx +108 -0
  136. package/vendor/chatgpt2api/source/web/src/app/settings/components/cpa-pools-card.tsx +169 -0
  137. package/vendor/chatgpt2api/source/web/src/app/settings/components/import-browser-dialog.tsx +185 -0
  138. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-runtime-card.tsx +379 -0
  139. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings-card.tsx +127 -0
  140. package/vendor/chatgpt2api/source/web/src/app/settings/components/proxy-settings.tsx +200 -0
  141. package/vendor/chatgpt2api/source/web/src/app/settings/components/settings-header.tsx +12 -0
  142. package/vendor/chatgpt2api/source/web/src/app/settings/components/sub2api-connections.tsx +886 -0
  143. package/vendor/chatgpt2api/source/web/src/app/settings/components/third-party-apps-card.tsx +81 -0
  144. package/vendor/chatgpt2api/source/web/src/app/settings/components/user-keys-card.tsx +422 -0
  145. package/vendor/chatgpt2api/source/web/src/app/settings/page.tsx +135 -0
  146. package/vendor/chatgpt2api/source/web/src/app/settings/store.ts +1069 -0
  147. package/vendor/chatgpt2api/source/web/src/components/date-range-filter.tsx +49 -0
  148. package/vendor/chatgpt2api/source/web/src/components/header-actions.tsx +24 -0
  149. package/vendor/chatgpt2api/source/web/src/components/image-lightbox.tsx +434 -0
  150. package/vendor/chatgpt2api/source/web/src/components/image-thumbnail.tsx +46 -0
  151. package/vendor/chatgpt2api/source/web/src/components/theme-script.tsx +18 -0
  152. package/vendor/chatgpt2api/source/web/src/components/theme-toggle.tsx +14 -0
  153. package/vendor/chatgpt2api/source/web/src/components/top-nav.tsx +263 -0
  154. package/vendor/chatgpt2api/source/web/src/components/ui/animated-theme-toggler.tsx +256 -0
  155. package/vendor/chatgpt2api/source/web/src/components/ui/badge.tsx +41 -0
  156. package/vendor/chatgpt2api/source/web/src/components/ui/button.tsx +59 -0
  157. package/vendor/chatgpt2api/source/web/src/components/ui/calendar.tsx +46 -0
  158. package/vendor/chatgpt2api/source/web/src/components/ui/card.tsx +61 -0
  159. package/vendor/chatgpt2api/source/web/src/components/ui/checkbox.tsx +27 -0
  160. package/vendor/chatgpt2api/source/web/src/components/ui/dia-text-reveal.tsx +267 -0
  161. package/vendor/chatgpt2api/source/web/src/components/ui/dialog.tsx +132 -0
  162. package/vendor/chatgpt2api/source/web/src/components/ui/field.tsx +13 -0
  163. package/vendor/chatgpt2api/source/web/src/components/ui/input.tsx +19 -0
  164. package/vendor/chatgpt2api/source/web/src/components/ui/label.tsx +24 -0
  165. package/vendor/chatgpt2api/source/web/src/components/ui/morphing-text.tsx +149 -0
  166. package/vendor/chatgpt2api/source/web/src/components/ui/popover.tsx +38 -0
  167. package/vendor/chatgpt2api/source/web/src/components/ui/select.tsx +175 -0
  168. package/vendor/chatgpt2api/source/web/src/components/ui/sheet.tsx +143 -0
  169. package/vendor/chatgpt2api/source/web/src/components/ui/table.tsx +29 -0
  170. package/vendor/chatgpt2api/source/web/src/components/ui/tabs.tsx +91 -0
  171. package/vendor/chatgpt2api/source/web/src/components/ui/text-3d-flip.tsx +269 -0
  172. package/vendor/chatgpt2api/source/web/src/components/ui/textarea.tsx +18 -0
  173. package/vendor/chatgpt2api/source/web/src/components/version-release-dialog.tsx +127 -0
  174. package/vendor/chatgpt2api/source/web/src/constants/common-env.ts +6 -0
  175. package/vendor/chatgpt2api/source/web/src/hooks/use-version-check.ts +85 -0
  176. package/vendor/chatgpt2api/source/web/src/lib/api.ts +926 -0
  177. package/vendor/chatgpt2api/source/web/src/lib/auth-session.ts +26 -0
  178. package/vendor/chatgpt2api/source/web/src/lib/release.ts +25 -0
  179. package/vendor/chatgpt2api/source/web/src/lib/request.ts +93 -0
  180. package/vendor/chatgpt2api/source/web/src/lib/use-auth-guard.ts +89 -0
  181. package/vendor/chatgpt2api/source/web/src/lib/utils.ts +6 -0
  182. package/vendor/chatgpt2api/source/web/src/store/auth.ts +112 -0
  183. package/vendor/chatgpt2api/source/web/src/store/editable-file-history.ts +33 -0
  184. package/vendor/chatgpt2api/source/web/src/store/image-conversations.ts +318 -0
  185. package/vendor/chatgpt2api/source/web/tsconfig.json +42 -0
package/client.js ADDED
@@ -0,0 +1,241 @@
1
+ /**
2
+ * DSH Client 插件:把 127.0.0.1:8092 的生图工作台嵌进侧栏面板。
3
+ * 页面本体是 image-local/static/index.html,浏览器直连与插件内看到的是同一个工作台。
4
+ * 号池是工作台自带的进程,所以侧栏只注册这一个面板,不再有独立号池入口。
5
+ */
6
+ window.__ModuleLoader__.load({
7
+ id: 'dsh-plugin-image-workbench',
8
+ factory(require) {
9
+ const { createElement: h, useState, useEffect, useCallback } = require('react');
10
+ const PANEL = 'image-workbench';
11
+ const STATUS_API = '/api/image-workbench.status';
12
+ const CSS = `
13
+ .iw-root{display:flex;flex-direction:column;height:100%;min-height:0;width:100%;background:#e7eaee;color:#1c1e21;font:14px/1.5 "PingFang SC","Microsoft YaHei",system-ui,sans-serif;box-sizing:border-box}
14
+ .iw-root *{box-sizing:border-box}
15
+ .iw-bar{display:flex;align-items:center;justify-content:flex-start;gap:12px;flex:none;padding:10px 18px;background:#fff;border-bottom:1px solid #dee3e9;flex-wrap:wrap}
16
+ .iw-title{display:flex;align-items:center;gap:10px;font-size:14px;font-weight:600;color:#0a1317;flex-wrap:wrap}
17
+ .iw-title small{font-weight:400;color:#8595a4;font-size:12px}
18
+ .iw-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-left:auto}
19
+ .iw-btn{border:1px solid #d7dde5;background:#fff;color:#1c1e21;border-radius:7px;padding:5px 11px;font-size:12px;cursor:pointer;text-decoration:none;font-family:inherit;line-height:1.5}
20
+ .iw-btn:hover{border-color:#0064e0;color:#0064e0}
21
+ .iw-btn.primary{background:#0064e0;border-color:#0064e0;color:#fff}
22
+ .iw-btn.primary:hover{background:#0053bb;color:#fff}
23
+ .iw-btn:disabled{opacity:.5;cursor:default}
24
+ .iw-chip{display:inline-flex;align-items:center;gap:6px;border-radius:99px;padding:3px 10px;font-size:11px;background:#eef1f5;color:#5d6c7b}
25
+ .iw-chip.on{background:#e6f6ec;color:#1d7a3c}
26
+ .iw-chip.off{background:#fff0ed;color:#b3402f}
27
+ .iw-chip.warn{background:#fff5e2;color:#9a6700}
28
+ .iw-dot{width:7px;height:7px;border-radius:50%;background:currentColor}
29
+ .iw-frame{flex:1;min-height:0;width:100%;border:0;background:#e7eaee;display:block}
30
+ .iw-empty{flex:1;min-height:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;padding:32px;text-align:center;color:#5d6c7b}
31
+ .iw-empty h2{margin:0;font-size:18px;color:#1c1e21}
32
+ .iw-empty p{margin:0;max-width:560px;font-size:13px;line-height:1.8}
33
+ .iw-empty code{background:#dfe4ea;padding:2px 6px;border-radius:4px;font-size:12px}
34
+ .iw-error{margin:8px 18px 0;padding:9px 12px;border-radius:7px;background:#fff3ef;border:1px solid #f3cfc4;color:#a13c28;font-size:12px;flex:none}
35
+ .iw-empty .iw-why{margin:0;max-width:560px;padding:9px 12px;border-radius:7px;background:#fff3ef;
36
+ border:1px solid #f3cfc4;color:#a13c28;font-size:12.5px;line-height:1.7;text-align:left}
37
+ .iw-empty .iw-why .iw-tail{margin:6px 0 0;padding:8px;max-height:150px;overflow:auto;background:#fff;
38
+ border:1px solid #f0d8d1;border-radius:5px;color:#6b3a30;font-size:11.5px;line-height:1.55;
39
+ white-space:pre-wrap;word-break:break-all;font-family:ui-monospace,Consolas,monospace}
40
+ .iw-note{flex:0 1 auto;min-width:0;max-width:min(420px,38vw);padding:4px 10px;border-radius:7px;
41
+ font-size:12px;line-height:1.55;background:#eef4ff;border:1px solid #cddffb;color:#1b4d8f;
42
+ white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
43
+ .iw-note.bad{background:#fff3ef;border-color:#f3cfc4;color:#a13c28}
44
+ /* 窄一点先把次要的自述说明收起来,优先保证提示条和按钮不换行 */
45
+ @media(max-width:1180px){.iw-title small{display:none}}
46
+ @media(max-width:820px){.iw-bar{padding:8px 12px}}
47
+ `;
48
+
49
+ function Button(label, onClick, opts = {}) {
50
+ return h('button', { type: 'button', className: 'iw-btn' + (opts.primary ? ' primary' : ''), onClick, disabled: !!opts.disabled, ...(opts.extra || {}) }, label);
51
+ }
52
+
53
+ function Workbench() {
54
+ const [status, setStatus] = useState(null);
55
+ const [error, setError] = useState('');
56
+ const [notice, setNotice] = useState(null);
57
+ const [busy, setBusy] = useState('');
58
+ const [nonce, setNonce] = useState(0);
59
+
60
+ const call = useCallback(async (action) => {
61
+ setBusy(action || '刷新');
62
+ setError('');
63
+ try {
64
+ const response = action
65
+ ? await fetch(STATUS_API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ action }) })
66
+ : await fetch(STATUS_API, { cache: 'no-store' });
67
+ if (!response.ok) throw new Error('宿主接口返回 HTTP ' + response.status);
68
+ const data = await response.json();
69
+ setStatus(data);
70
+ if (data.running && action === 'start') setNonce(n => n + 1);
71
+ if (!data.running && action === 'start') setError('后端仍未就绪,可查看日志:' + (data.log || '~/.dsh/image-workbench/backend.log'));
72
+
73
+ // 每个动作都要能看见结果:以前点了像没反应,就是因为什么都不回显
74
+ // 文案压短,完整信息放 hint(渲染成 title),否则窄一点就把按钮挤到第二行
75
+ if (action === 'open') {
76
+ const done = data.lastAction || {};
77
+ setNotice(done.ok
78
+ ? { ok: true, text: '已用系统浏览器打开', hint: '已在系统默认浏览器打开 ' + (data.url || '') }
79
+ : { ok: false, text: '打开浏览器失败', hint: '原因:' + (done.error || '未知') + '。也可以手动访问 ' + (data.url || '') });
80
+ } else if (action === 'refresh') {
81
+ setNotice(data.running
82
+ ? { ok: true, text: '后端正常 · 端口 ' + (data.port || 8092), hint: '已检查:工作台后端在跑,端口正常响应' }
83
+ : { ok: false, text: '端口 ' + (data.port || 8092) + ' 无响应', hint: '已检查:后端没在跑,点「启动后端」' });
84
+ }
85
+ } catch (e) {
86
+ setError(e.message || '状态查询失败');
87
+ } finally {
88
+ setBusy('');
89
+ }
90
+ }, []);
91
+
92
+ // 提示条自动消失,避免一直占着页面顶部
93
+ useEffect(() => {
94
+ if (!notice) return undefined;
95
+ const timer = setTimeout(() => setNotice(null), notice.ok ? 6000 : 10000);
96
+ return () => clearTimeout(timer);
97
+ }, [notice]);
98
+
99
+ const copyUrl = useCallback(async () => {
100
+ const url = status?.url || 'http://127.0.0.1:8092/';
101
+ try {
102
+ await navigator.clipboard.writeText(url);
103
+ setNotice({ ok: true, text: '地址已复制', hint: '已复制到剪贴板,可直接粘到浏览器打开:' + url });
104
+ } catch {
105
+ setNotice({ ok: false, text: '复制失败', hint: '复制被环境拦下了,手动复制这个地址:' + url });
106
+ }
107
+ }, [status]);
108
+
109
+ // 不做定时轮询:iframe 一旦重载,正在编辑的工程会被打断。
110
+ useEffect(() => { call(); }, [call]);
111
+
112
+ // 后端没起来时(首次装环境、刚被拉起)轻量轮询,起来就自动切成 iframe。
113
+ // 只在没有 iframe 的时候轮询,所以不会打断正在编辑的内容;最多盯 2 分钟。
114
+ useEffect(() => {
115
+ if (Boolean(status?.running)) return undefined;
116
+ let tick = 0;
117
+ const timer = setInterval(() => {
118
+ tick += 1;
119
+ if (tick > 40) { clearInterval(timer); return; }
120
+ void call();
121
+ }, 3000);
122
+ return () => clearInterval(timer);
123
+ }, [status?.running, call]);
124
+
125
+ // 后端起不来时,把真实原因复制出来,不用让用户去翻日志文件
126
+ const copyDiag = useCallback(async () => {
127
+ const d = {
128
+ time: new Date().toISOString(),
129
+ running: status?.running, port: status?.port,
130
+ serverDir: status?.serverDir, python: status?.python,
131
+ venv: status?.venv, lastError: status?.lastError,
132
+ watchdog: status?.watchdog, log: status?.log,
133
+ };
134
+ try {
135
+ await navigator.clipboard.writeText(JSON.stringify(d, null, 2));
136
+ setNotice({ ok: true, text: '诊断信息已复制', hint: '已复制到剪贴板,可直接发给作者' });
137
+ } catch {
138
+ setNotice({ ok: false, text: '复制失败', hint: JSON.stringify(d) });
139
+ }
140
+ }, [status]);
141
+
142
+ const running = Boolean(status?.running);
143
+ const appUrl = status?.url || 'http://127.0.0.1:8092/';
144
+ const guard = status?.watchdog;
145
+ const guardText = !status ? '检查中'
146
+ : !guard ? '守护未加载 · 需重启 DSH'
147
+ : !guard.enabled ? '守护已关闭'
148
+ : '守护已开' + (guard.restarts ? ' · 已自动拉起 ' + guard.restarts + ' 次' : '')
149
+ + (guard.consecutiveFailures ? ' · 拉起失败 ' + guard.consecutiveFailures + ' 次' : '');
150
+ const guardClass = !status ? '' : !guard ? 'warn' : guard.enabled && !guard.consecutiveFailures ? 'on' : 'off';
151
+ // 号池是工作台自带的第二个进程,状态由后端上报;不再有独立号池插件
152
+ const bp = status?.pool;
153
+ const poolText = !status ? '' : !bp ? '内置号池读取中'
154
+ : bp.online ? `内置号池 ${bp.active}/${bp.total} · 剩 ${bp.quota} 次`
155
+ : '内置号池未就绪';
156
+ const poolClass = !bp ? 'warn' : bp.online ? 'on' : 'off';
157
+
158
+ return h('div', { className: 'iw-root' },
159
+ h('style', null, CSS),
160
+ h('header', { className: 'iw-bar' },
161
+ h('div', { className: 'iw-title' },
162
+ 'Bluxe手绘工坊 · 生图工作台',
163
+ h('small', null, '号池运行时随插件自带 · 可独立运行'),
164
+ h('span', { className: 'iw-chip ' + guardClass, title: '后端端口掉线时由 DSH 宿主自动拉起;修改插件后需重启 DSH 才会加载新代码' },
165
+ h('span', { className: 'iw-dot' }), guardText),
166
+ h('span', { className: 'iw-chip ' + poolClass, title: '号池服务端代码与 uv 随插件自带,全新机器首次启动自动初始化虚拟环境;由工作台后端自己启动与守护,不需要任何第三方号池插件' },
167
+ h('span', { className: 'iw-dot' }), poolText)),
168
+ // 提示放在标题右侧、按钮左侧这条空档里,不额外占一行高度
169
+ notice && h('div', { className: 'iw-note' + (notice.ok ? '' : ' bad'), role: 'status', title: notice.hint || notice.text }, notice.text),
170
+ h('div', { className: 'iw-actions' },
171
+ Button(busy === 'refresh' ? '检查中…' : '刷新状态', () => call('refresh'), { disabled: !!busy }),
172
+ // 只有在没跑的时候才给「启动后端」,跑着的时候这个按钮点了也没意义
173
+ !running && Button(busy === 'start' ? '启动中…' : '启动后端', () => call('start'), { disabled: !!busy, primary: true }),
174
+ Button(busy === 'open' ? '正在打开…' : '用系统浏览器打开', () => call('open'), { disabled: !!busy }),
175
+ // 原来的「新窗口打开」是 <a target="_blank">,DSH 里既开不了新窗口又会静默失败,换成复制地址
176
+ Button('复制地址', copyUrl))),
177
+ error && h('div', { className: 'iw-error', role: 'alert' }, error),
178
+ running
179
+ ? h('iframe', {
180
+ key: 'frame-' + nonce,
181
+ className: 'iw-frame',
182
+ src: appUrl + (appUrl.includes('?') ? '&' : '?') + 'dsh=' + nonce,
183
+ title: '生图工作台(图文 / 摄影)',
184
+ allow: 'clipboard-read; clipboard-write; fullscreen',
185
+ })
186
+ : h('div', { className: 'iw-empty' },
187
+ h('h2', null, status ? '工作台后端未运行' : '正在连接工作台'),
188
+ h('p', null,
189
+ '插件会自动拉起本机 image-local 工作台(uvicorn,端口 ',
190
+ h('code', null, String(status?.port || 8092)),
191
+ ')。若这里一直是空白,请确认 DSH 已重启加载插件,或点「用系统浏览器打开」直接访问。'),
192
+ status?.serverDir && h('p', null, '后端目录:', h('code', null, status.serverDir)),
193
+ // 初始化中 / 失败原因:以前这里只说「未运行」,用户完全看不出卡在哪一步
194
+ !status ? null
195
+ : (status.venv?.message || status.lastError)
196
+ ? h('div', { className: 'iw-why' },
197
+ h('div', null, '原因:' + (status.venv?.message || status.lastError)),
198
+ status.backendTail
199
+ ? h('pre', { className: 'iw-tail' }, status.backendTail)
200
+ : null)
201
+ : (status.venv?.tried && !status.venv?.ready)
202
+ ? h('p', null, '正在初始化运行环境(首次启动约 1 分钟),装好后这里会自动刷新。')
203
+ : null,
204
+ h('div', { style: { display: 'flex', gap: '8px', flexWrap: 'wrap' } },
205
+ Button(busy ? '正在处理' : '立即启动并重试', () => call('start'), { primary: true, disabled: !!busy }),
206
+ Button('复制诊断信息', copyDiag),
207
+ status?.venv?.log && h('span', {
208
+ style: { fontSize: '12px', color: '#6b7280', alignSelf: 'center' },
209
+ title: status.venv.log,
210
+ }, '日志:' + status.venv.log)),
211
+ ),
212
+ );
213
+ }
214
+
215
+ function HeaderIcon({ size = 20 }) {
216
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, 'aria-hidden': true },
217
+ h('rect', { x: 3, y: 3, width: 18, height: 18, rx: 2 }),
218
+ h('circle', { cx: 9, cy: 9, r: 2.2 }),
219
+ h('path', { d: 'M21 15l-5-5L5 21' }));
220
+ }
221
+
222
+ function apply(ctx) {
223
+ const slots = ctx?.slots;
224
+ if (!slots?.inject) return;
225
+ const register = () => {
226
+ const disposers = [];
227
+ disposers.push(slots.inject('sidebar.panellist', () => slots.register(
228
+ { name: 'sidebar.panellist', id: PANEL, order: 73, label: () => 'Bluxe手绘工坊 · 生图工作台' },
229
+ HeaderIcon)));
230
+ disposers.push(slots.inject('main', () => slots.register(
231
+ { name: 'main', key: PANEL },
232
+ Workbench)));
233
+ return () => { for (const fn of disposers.reverse()) if (typeof fn === 'function') fn(); };
234
+ };
235
+ if (typeof ctx.effect === 'function') ctx.effect(register, 'image-workbench: panel registrations');
236
+ else register();
237
+ }
238
+
239
+ return { name: PANEL, inject: ['slots'], apply };
240
+ },
241
+ });
@@ -0,0 +1,14 @@
1
+ # DSH profile patch: register the workbench as a loader entry.
2
+ # All paths are resolved at runtime by host.js; no absolute paths are stored here.
3
+ # The DSH host manages the workbench backend on port 8092 only.
4
+ # The account-pool process on port 38651 is managed by server/pool_service.py.
5
+ - insert:
6
+ - id: image-workbench
7
+ name: dsh-plugin-image-workbench
8
+ config:
9
+ port: 8092
10
+ poolPort: 38651
11
+ autoStart: true
12
+ # 宿主侧守护:探测失败时自动重启后端,不重载面板。设为 false 并重启 DSH 可关闭。
13
+ watchdog: true
14
+ watchdogIntervalMs: 15000