@chad.dev/dsh-adclip 0.0.0-stage → 0.1.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.
Files changed (51) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +28 -2
  4. package/client.js +2256 -0
  5. package/cordis.patch.yml +10 -0
  6. package/engine/requirements.txt +9 -0
  7. package/engine/src/adclip/__init__.py +0 -0
  8. package/engine/src/adclip/api.py +704 -0
  9. package/engine/src/adclip/catalog.py +341 -0
  10. package/engine/src/adclip/image_params.py +45 -0
  11. package/engine/src/adclip/intents.py +209 -0
  12. package/engine/src/adclip/llm.py +142 -0
  13. package/engine/src/adclip/media/__init__.py +0 -0
  14. package/engine/src/adclip/media/asr.py +79 -0
  15. package/engine/src/adclip/media/ffmpeg.py +294 -0
  16. package/engine/src/adclip/media/stitch.py +124 -0
  17. package/engine/src/adclip/media/subtitles.py +45 -0
  18. package/engine/src/adclip/media/vision.py +105 -0
  19. package/engine/src/adclip/models.py +127 -0
  20. package/engine/src/adclip/params.py +158 -0
  21. package/engine/src/adclip/personas.py +60 -0
  22. package/engine/src/adclip/pipeline/__init__.py +0 -0
  23. package/engine/src/adclip/pipeline/analyze.py +133 -0
  24. package/engine/src/adclip/pipeline/generate.py +196 -0
  25. package/engine/src/adclip/pipeline/image_runner.py +146 -0
  26. package/engine/src/adclip/pipeline/persona.py +56 -0
  27. package/engine/src/adclip/pipeline/post.py +40 -0
  28. package/engine/src/adclip/pipeline/qa.py +44 -0
  29. package/engine/src/adclip/pipeline/replace.py +191 -0
  30. package/engine/src/adclip/pipeline/runner.py +138 -0
  31. package/engine/src/adclip/pipeline/script.py +226 -0
  32. package/engine/src/adclip/pipeline/segment.py +87 -0
  33. package/engine/src/adclip/providers/__init__.py +0 -0
  34. package/engine/src/adclip/providers/ark.py +122 -0
  35. package/engine/src/adclip/providers/ark_image.py +114 -0
  36. package/engine/src/adclip/providers/base.py +30 -0
  37. package/engine/src/adclip/providers/discovery.py +56 -0
  38. package/engine/src/adclip/providers/kling.py +101 -0
  39. package/engine/src/adclip/providers/minimax.py +155 -0
  40. package/engine/src/adclip/providers/minimax_image.py +89 -0
  41. package/engine/src/adclip/settings.py +109 -0
  42. package/engine/src/adclip/store.py +378 -0
  43. package/host/dsh.js +60 -0
  44. package/host/engine.js +265 -0
  45. package/host/proxy.js +142 -0
  46. package/host/supervisor.js +251 -0
  47. package/icon.svg +6 -0
  48. package/index.js +39 -0
  49. package/locale/en.json +12 -0
  50. package/locale/zh.json +12 -0
  51. package/package.json +47 -4
package/client.js ADDED
@@ -0,0 +1,2256 @@
1
+ window.__ModuleLoader__.load({
2
+ id: '@chad.dev/dsh-adclip',
3
+ factory(require) {
4
+ const React = require('react')
5
+ const h = React.createElement
6
+ const { useState, useEffect, useRef, useCallback } = React
7
+
8
+ const boot = window.__ADPLUS_STUDIO__ || {}
9
+ const API = boot.base || '/adplus/api'
10
+ const MEDIA = boot.media || '/adplus/media'
11
+ let TOKEN = boot.token || ''
12
+
13
+ async function tokenReady() {
14
+ if (TOKEN) return TOKEN
15
+ try {
16
+ const res = await fetch('/adplus/health')
17
+ const data = await res.json()
18
+ if (data && data.token) TOKEN = data.token
19
+ } catch { /* the refreshed host injects the token instead */ }
20
+ return TOKEN
21
+ }
22
+
23
+ const CSS = `
24
+ .adp-root{height:100%;min-height:520px;display:flex;flex-direction:column;background:var(--dsw-alias-bg-base);color:var(--dsw-alias-label-primary);font:13px/1.5 -apple-system,BlinkMacSystemFont,"SF Pro Text","PingFang SC",sans-serif;font-variant-numeric:tabular-nums}
25
+ .adp-top{display:flex;align-items:center;gap:14px;padding:0 20px;height:54px;border-bottom:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);flex:0 0 auto}
26
+ .adp-brand{font-weight:750;letter-spacing:-.3px;font-size:15px;display:flex;align-items:baseline;gap:5px}
27
+ .adp-brand:after{content:"";width:5px;height:5px;border-radius:50%;background:#E5B45C;display:inline-block}
28
+ .adp-sub{color:var(--dsw-alias-label-secondary);font:10px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase}
29
+ .adp-tabs{display:flex;gap:2px;margin-left:10px;height:100%;align-items:stretch}
30
+ .adp-tab{border:0;background:transparent;color:var(--dsw-alias-label-secondary);padding:0 12px;cursor:pointer;font:inherit;position:relative;height:100%}
31
+ .adp-tab:hover{color:var(--dsw-alias-label-primary)}
32
+ .adp-tab.on{color:var(--dsw-alias-label-primary);font-weight:650}
33
+ .adp-tab.on:after{content:"";position:absolute;left:12px;right:12px;bottom:-1px;height:2px;background:#E5B45C;border-radius:2px 2px 0 0}
34
+ .adp-grow{flex:1 1 auto;min-width:0}
35
+ .adp-body{flex:1 1 auto;min-height:0;overflow:auto;padding:22px 24px 40px}
36
+ .adp-page{max-width:1120px;margin:0 auto}
37
+ .adp-page-head{display:flex;align-items:flex-end;justify-content:space-between;gap:18px;margin:2px 0 16px}
38
+ .adp-eyebrow{font:10px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.12em;text-transform:uppercase;color:#C99B54;margin-bottom:5px}
39
+ .adp-title{font-size:24px;line-height:1.12;font-weight:750;letter-spacing:-.5px;margin:0}
40
+ .adp-lede{color:var(--dsw-alias-label-secondary);font-size:12.5px;margin:6px 0 0;max-width:620px}
41
+ .adp-lede.adp-nowrap{max-width:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
42
+ .adp-page-meta{display:flex;align-items:center;gap:8px;color:var(--dsw-alias-label-secondary);font-size:11px;padding-bottom:2px}
43
+ .adp-panel{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:14px;overflow:hidden;box-shadow:0 1px 0 rgba(255,255,255,.03) inset}
44
+ .adp-panel-grid{display:grid;grid-template-columns:360px minmax(0,1fr)}
45
+ .adp-asset-col{padding:18px;border-right:1px solid var(--dsw-alias-border-l1);background:linear-gradient(180deg,var(--dsw-alias-bg-layer-2),var(--dsw-alias-bg-layer-1));min-width:0}
46
+ .adp-form-col{padding:18px 20px 0;min-width:0}
47
+ .adp-section-head{display:flex;align-items:center;gap:8px;margin:0 0 9px}
48
+ .adp-section-head:not(:first-child){margin-top:20px}
49
+ .adp-step{font:10px/1 ui-monospace,SFMono-Regular,Menlo,monospace;color:#C99B54;letter-spacing:.06em;border:1px solid rgba(229,180,92,.35);border-radius:4px;padding:3px 4px;background:rgba(229,180,92,.06)}
50
+ .adp-section-title{font-size:12.5px;font-weight:700;letter-spacing:.01em}
51
+ .adp-section-note{font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-left:auto}
52
+ .adp-label{display:flex;align-items:center;justify-content:space-between;gap:8px;font:10.5px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.05em;text-transform:uppercase;color:var(--dsw-alias-label-secondary);margin:0 0 5px}
53
+ .adp-label .count{font-weight:400;letter-spacing:0;text-transform:none;color:var(--dsw-alias-label-secondary);opacity:.8}
54
+ .adp-drop{position:relative;border:1px dashed var(--dsw-alias-border-l2);border-radius:11px;background:var(--dsw-alias-bg-layer-2);min-height:198px;display:flex;align-items:center;justify-content:center;cursor:pointer;overflow:hidden;transition:border-color .15s ease,background .15s ease}
55
+ .adp-drop:hover,.adp-drop.drag{border-color:#C99B54;background:color-mix(in srgb,var(--dsw-alias-bg-layer-2) 86%,#E5B45C 14%)}
56
+ .adp-drop video{width:100%;height:198px;object-fit:contain;display:block;background:#08090d}
57
+ .adp-drop .adp-drop-empty{display:flex;flex-direction:column;align-items:center;gap:5px;color:var(--dsw-alias-label-secondary);text-align:center;padding:16px}
58
+ .adp-drop .adp-drop-empty b{font-size:12.5px;color:var(--dsw-alias-label-primary);font-weight:600}
59
+ .adp-drop .adp-drop-empty span{font-size:10.5px;line-height:1.5}
60
+ .adp-drop .adp-drop-overlay{position:absolute;left:0;right:0;bottom:0;padding:8px 9px;background:linear-gradient(transparent,rgba(0,0,0,.72));color:#fff;font-size:10.5px;display:flex;align-items:center;justify-content:space-between;gap:8px}
61
+ .adp-drop .adp-remove{background:rgba(0,0,0,.45);color:#fff;border:0;border-radius:5px;width:20px;height:20px;cursor:pointer;line-height:18px;font-size:14px}
62
+ .adp-media-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px}
63
+ .adp-media{position:relative;aspect-ratio:1/1;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;overflow:hidden;background:var(--dsw-alias-bg-layer-2)}
64
+ .adp-media img{width:100%;height:100%;object-fit:cover;display:block}
65
+ .adp-media .adp-remove{position:absolute;top:3px;right:3px;width:18px;height:18px;border:0;border-radius:50%;background:rgba(0,0,0,.55);color:#fff;font-size:12px;line-height:18px;cursor:pointer;opacity:0;transition:opacity .15s ease}
66
+ .adp-media:hover .adp-remove{opacity:1}
67
+ .adp-media-add{aspect-ratio:1/1;border:1px dashed var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);display:flex;align-items:center;justify-content:center;flex-direction:column;gap:2px;cursor:pointer;font:10px/1.2 inherit}
68
+ .adp-media-add:hover{border-color:#C99B54;color:var(--dsw-alias-label-primary)}
69
+ .adp-media-add b{font-size:16px;font-weight:300}
70
+ .adp-form-col .adp-textarea{min-height:104px;resize:vertical;padding:10px 11px;line-height:1.55;font-size:12.5px}
71
+ .adp-brief{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-2);overflow:hidden;transition:border-color .15s ease,box-shadow .15s ease}
72
+ .adp-brief:focus-within{border-color:#C99B54;box-shadow:0 0 0 2px rgba(229,180,92,.13)}
73
+ .adp-brief-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:8px 11px;border-bottom:1px solid var(--dsw-alias-border-l1);font:10px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.06em;text-transform:uppercase;color:var(--dsw-alias-label-secondary)}
74
+ .adp-brief-head b{font-weight:600;color:var(--dsw-alias-label-primary);letter-spacing:.04em}
75
+ .adp-brief-input{display:block;width:100%;min-height:92px;max-height:190px;resize:vertical;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary);padding:10px 11px;font:12.5px/1.6 inherit;box-sizing:border-box}
76
+ .adp-brief-input::placeholder{color:var(--dsw-alias-label-secondary);opacity:.82}
77
+ .adp-brief-foot{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:7px 11px;border-top:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.4}
78
+ .adp-key{font:9.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;border:1px solid var(--dsw-alias-border-l1);border-radius:4px;padding:2px 5px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-1);white-space:nowrap}
79
+ .adp-hint{font-size:10.5px;color:var(--dsw-alias-label-secondary);line-height:1.5;margin:5px 0 0}
80
+ .adp-check{display:flex;align-items:center;gap:7px;color:var(--dsw-alias-label-secondary);font-size:11px;margin-top:10px;cursor:pointer}
81
+ .adp-check input{accent-color:#C99B54;width:13px;height:13px;margin:0}
82
+ .adp-field-grid{display:grid;gap:9px}
83
+ .adp-field-grid.g3{grid-template-columns:repeat(3,minmax(0,1fr))}
84
+ .adp-field-grid.g4{grid-template-columns:repeat(4,minmax(0,1fr))}
85
+ .adp-field-grid.g2{grid-template-columns:repeat(2,minmax(0,1fr))}
86
+ .adp-field{min-width:0}
87
+ .adp-field .adp-select{width:100%;height:31px;padding:0 8px;border-radius:7px;font-size:11.5px;background:var(--dsw-alias-bg-layer-2)}
88
+ .adp-field .adp-input{width:100%;height:31px;padding:0 8px;border-radius:7px;font-size:11.5px;background:var(--dsw-alias-bg-layer-2)}
89
+ .adp-field .adp-textarea{width:100%;background:var(--dsw-alias-bg-layer-2)}
90
+ .adp-field-label{font:10px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.04em;text-transform:uppercase;color:var(--dsw-alias-label-secondary);margin:0 0 4px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
91
+ .adp-actionbar{display:flex;align-items:center;gap:12px;margin:18px -20px 0;padding:13px 20px;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2)}
92
+ .adp-action-note{font-size:10.5px;color:var(--dsw-alias-label-secondary);line-height:1.45}
93
+ .adp-primary{border:0;border-radius:8px;background:var(--dsw-alias-label-primary);color:var(--dsw-alias-bg-base);padding:9px 16px;font:inherit;font-weight:700;font-size:12px;cursor:pointer;display:inline-flex;align-items:center;gap:8px;white-space:nowrap}
94
+ .adp-primary:hover{opacity:.88}
95
+ .adp-primary:focus-visible,.adp-btn:focus-visible,.adp-example:focus-visible,.adp-drop:focus-visible,.adp-media-add:focus-visible{outline:2px solid #C99B54;outline-offset:2px}
96
+ .adp-primary:disabled{opacity:.38;cursor:not-allowed}
97
+ .adp-primary .arrow{font-size:14px;line-height:1;font-weight:400}
98
+ .adp-card{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1);border-radius:12px;padding:14px}
99
+ .adp-row{display:flex;gap:10px;align-items:center;flex-wrap:wrap}
100
+ .adp-col{display:flex;flex-direction:column;gap:8px}
101
+ .adp-muted{color:var(--dsw-alias-label-secondary)}
102
+ .adp-faint{color:var(--dsw-alias-label-secondary);opacity:.75}
103
+ .adp-h1{font-size:18px;font-weight:700;letter-spacing:-.2px;margin:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
104
+ .adp-h2{font-size:12.5px;font-weight:700;margin:0}
105
+ .adp-small{font-size:11px}
106
+ .adp-btn{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:7px;padding:5px 9px;cursor:pointer;font:inherit;font-size:11.5px}
107
+ .adp-btn:hover{filter:brightness(1.08)}
108
+ .adp-btn.primary{background:var(--dsw-alias-label-primary);border-color:transparent;color:var(--dsw-alias-bg-base);font-weight:650}
109
+ .adp-btn.ghost{background:transparent}
110
+ .adp-btn.danger{color:var(--dsw-alias-state-error-primary)}
111
+ .adp-btn:disabled{opacity:.45;cursor:not-allowed}
112
+ .adp-input,.adp-select,.adp-textarea{border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:7px;padding:7px 8px;font:inherit;min-width:0;outline:none}
113
+ .adp-input:focus,.adp-select:focus,.adp-textarea:focus{border-color:#C99B54;box-shadow:0 0 0 2px rgba(229,180,92,.15)}
114
+ .adp-textarea{width:100%;min-height:90px;resize:vertical}
115
+ .adp-select{min-width:84px}
116
+ .adp-error{color:var(--dsw-alias-state-error-primary);font-size:11px;line-height:1.45;white-space:pre-wrap}
117
+ .adp-badge{font:10px/1.6 ui-monospace,SFMono-Regular,Menlo,monospace;border-radius:999px;padding:2px 7px;border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);letter-spacing:.02em}
118
+ .adp-caps{display:inline-flex;gap:4px;flex-wrap:wrap}
119
+ .adp-cap{font-size:10px;line-height:1.5;padding:0 5px;border-radius:4px;border:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2);white-space:nowrap}
120
+ .adp-badge.ok{color:var(--dsw-alias-state-success-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary) 55%,transparent)}
121
+ .adp-badge.warn{color:var(--dsw-alias-state-warn-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 55%,transparent)}
122
+ .adp-badge.bad{color:var(--dsw-alias-state-error-primary);border-color:color-mix(in srgb,var(--dsw-alias-state-error-primary) 55%,transparent)}
123
+ .adp-progress{height:6px;background:#26272d;border:1px solid rgba(255,255,255,.05);border-radius:999px;overflow:hidden;box-shadow:inset 0 1px 2px rgba(0,0,0,.35)}
124
+ .adp-progress i{display:block;height:100%;background:linear-gradient(90deg,#b8843e,#e2c08a);transition:width .3s ease}
125
+ .adp-video-wrap{display:flex;justify-content:center;align-items:center;background:#000;border-radius:9px;overflow:hidden;min-height:220px}
126
+ .adp-video{max-width:100%;max-height:520px;width:auto;background:#000;display:block}
127
+ .adp-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:10px}
128
+ .adp-task-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;align-items:start}
129
+ @media(max-width:980px){.adp-task-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
130
+ @media(max-width:640px){.adp-task-grid{grid-template-columns:1fr}}
131
+ .adp-run-card{position:relative;min-height:0;padding:12px 13px 12px;display:flex;flex-direction:column;gap:3px}
132
+ .adp-task-head{display:flex;align-items:flex-start;gap:7px;min-width:0}
133
+ .adp-task-check{margin-top:4px}
134
+ .adp-task-check-spacer{width:14px;height:14px;flex:0 0 auto;margin-top:4px}
135
+ .adp-task-title{flex:1;min-width:0;font-size:12.5px;font-weight:650;line-height:1.4;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;min-height:35px;overflow-wrap:anywhere}
136
+ .adp-task-title-input{height:28px;font-size:12px;min-width:0}
137
+ .adp-task-edit{flex:0 0 auto;width:23px;height:23px;margin-top:-2px}
138
+ .adp-task-save{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:0;border-radius:50%;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer}
139
+ .adp-task-save:hover{background:rgba(201,155,84,.14);color:#E2B96F}
140
+ .adp-task-save.ok{color:#C99B54}
141
+ .adp-task-scenario{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-left:21px;padding-right:56px;line-height:1.5}
142
+ .adp-task-time{line-height:1.5;padding-left:21px;padding-right:56px;font-variant-numeric:tabular-nums}
143
+ .adp-task-progress{margin:6px 0 0 21px}
144
+ .adp-status-stamp{position:absolute;right:14px;top:56px;width:44px;height:44px;aspect-ratio:1/1;min-width:44px;min-height:44px;display:flex;align-items:center;justify-content:center;text-align:center;font-family:Georgia,"Songti SC",serif;transform:rotate(-8deg);opacity:.62;pointer-events:none;mix-blend-mode:screen;border-radius:50%;z-index:2}
145
+ .adp-status-stamp .stamp-ring{position:absolute;inset:0;width:100%;height:100%;overflow:visible}
146
+ .adp-status-stamp b{position:relative;z-index:1;font-size:10px;line-height:1;letter-spacing:.1em;font-weight:700}
147
+ .adp-status-stamp.ok{color:#8FCB9B}.adp-status-stamp.bad{color:#E38B8B}.adp-status-stamp.warn{color:#D7B36A}.adp-status-stamp.muted{color:#8A8E99}
148
+ .adp-run-card.selected{border-color:#C99B54;box-shadow:0 0 0 1px #C99B54 inset}
149
+ .adp-task-check{accent-color:#C99B54;width:14px;height:14px;margin:0;cursor:pointer}
150
+ .adp-toolbar{display:flex;align-items:center;gap:8px;flex-wrap:wrap;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:9px 10px;margin:12px 0}
151
+ .adp-toolbar .adp-input,.adp-toolbar .adp-select,.adp-toolbar .adp-btn{height:32px;box-sizing:border-box;font-size:11px}
152
+ .adp-toolbar .adp-input,.adp-toolbar .adp-select{padding-top:0;padding-bottom:0}
153
+ .adp-toolbar .adp-select{padding-right:28px}
154
+ .adp-toolbar .adp-date-input{padding:0 8px}
155
+ .adp-toolbar .adp-btn{display:inline-flex;align-items:center;justify-content:center;padding:0 10px;line-height:1}
156
+ .adp-pager{display:flex;align-items:center;justify-content:center;gap:12px;margin:14px 0 0}
157
+ .adp-asset-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px;margin-top:12px}
158
+ .adp-asset-card{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:8px;min-width:0}
159
+ .adp-asset-card>img,.adp-asset-card>video{width:100%;height:110px;object-fit:cover;border-radius:7px;display:block;background:#0a0b10}
160
+ .adp-asset-card-body{display:flex;align-items:center;gap:6px;margin-top:6px;min-width:0}
161
+ .adp-asset-card-body>.adp-grow{display:block;flex:1 1 auto;width:0;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
162
+ .adp-asset-card-body .adp-icon-btn{width:28px;height:28px;flex:0 0 auto}
163
+ .adp-asset-meta-row{display:flex;align-items:center;justify-content:space-between;gap:6px;margin-top:4px;min-width:0;font-size:9.5px;line-height:1.4;color:var(--dsw-alias-label-tertiary)}
164
+ .adp-asset-kind{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
165
+ .adp-asset-time{flex:0 0 auto;white-space:nowrap;font-variant-numeric:tabular-nums;color:var(--dsw-alias-label-tertiary)}
166
+ .adp-run-card{border:1px solid var(--dsw-alias-border-l1);border-radius:9px;padding:10px;background:var(--dsw-alias-bg-layer-2);cursor:pointer}
167
+ .adp-run-card:hover{border-color:#C99B54}
168
+ .adp-sb{display:grid;grid-template-columns:repeat(auto-fill,minmax(190px,1fr));gap:9px}
169
+ .adp-sb-card{border:1px solid var(--dsw-alias-border-l1);border-radius:9px;overflow:hidden;background:var(--dsw-alias-bg-layer-2);cursor:pointer}
170
+ .adp-sb-card.on{border-color:#C99B54;box-shadow:0 0 0 1px #C99B54 inset}
171
+ .adp-sb-card img{width:100%;height:108px;object-fit:cover;display:block;background:#111}
172
+ .adp-sb-meta{padding:7px 8px;display:flex;flex-direction:column;gap:3px}
173
+ .adp-chat{display:flex;flex-direction:column;gap:8px;max-height:280px;overflow:auto;padding:2px}
174
+ .adp-msg{border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:8px 9px;background:var(--dsw-alias-bg-layer-2);font-size:11.5px;white-space:pre-wrap}
175
+ .adp-msg.user{background:var(--dsw-alias-bg-overlay)}
176
+ .adp-change{border-left:2px solid #C99B54;padding:5px 8px;background:var(--dsw-alias-bg-layer-2);border-radius:0 6px 6px 0;font-size:10.5px}
177
+ .adp-table{width:100%;border-collapse:collapse;font-size:11px}
178
+ .adp-table th,.adp-table td{text-align:left;padding:6px 7px;border-bottom:1px solid var(--dsw-alias-border-l1);vertical-align:top}
179
+ .adp-table th{color:var(--dsw-alias-label-secondary);font-weight:600}
180
+ .adp-crash{min-height:520px;display:flex;align-items:center;justify-content:center;padding:24px;background:var(--dsw-alias-bg-base)}
181
+ .adp-crash .box{max-width:640px;border:1px solid var(--dsw-alias-state-error-primary);border-radius:12px;padding:18px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font-size:12px;line-height:1.55;white-space:pre-wrap}
182
+ .adp-crash h3{margin:0 0 8px;font-size:14px;color:var(--dsw-alias-state-error-primary)}
183
+ .adp-create-tabs{display:flex;align-items:center;gap:4px;margin:14px 0 0;border-bottom:1px solid var(--dsw-alias-border-l1)}
184
+ .adp-create-tab{position:relative;border:0;background:transparent;color:var(--dsw-alias-label-secondary);padding:8px 12px;cursor:pointer;font:inherit;font-size:12px}
185
+ .adp-create-tab:hover{color:var(--dsw-alias-label-primary)}
186
+ .adp-create-tab.on{color:var(--dsw-alias-label-primary);font-weight:650}
187
+ .adp-create-tab.on:after{content:"";position:absolute;left:10px;right:10px;bottom:-1px;height:2px;background:#C99B54;border-radius:2px 2px 0 0}
188
+ .adp-create-tab:disabled{opacity:.38;cursor:not-allowed}
189
+ .adp-create-tab-note{font:9px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;color:#C99B54;margin-left:5px}
190
+ .adp-image-result{max-width:1120px;margin:0 auto;display:flex;flex-direction:column;gap:14px}
191
+ .adp-image-grid{display:grid;grid-template-columns:minmax(300px,1.1fr) minmax(280px,.9fr);gap:14px;align-items:start}
192
+ .adp-image-stage{min-height:420px;border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:radial-gradient(120% 100% at 50% 0%,#171a22 0%,#050608 70%);display:flex;align-items:center;justify-content:center;overflow:hidden;padding:12px}
193
+ .adp-image-stage img{max-width:100%;max-height:72vh;display:block;border-radius:7px;object-fit:contain}
194
+ .adp-image-prompt{font-size:11.5px;line-height:1.65;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--dsw-alias-label-primary);max-height:240px;overflow:auto}
195
+ @media(max-width:900px){.adp-image-grid{grid-template-columns:1fr}.adp-image-stage{min-height:260px}}
196
+ .adp-composer{border:1px solid var(--dsw-alias-border-l1);border-radius:14px;background:var(--dsw-alias-bg-layer-1);overflow:hidden;margin-top:14px}
197
+ .adp-composer:focus-within{border-color:#C99B54;box-shadow:0 0 0 2px rgba(229,180,92,.12)}
198
+ .adp-composer-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:11px 15px;border-bottom:1px solid var(--dsw-alias-border-l1);font:10px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase;color:var(--dsw-alias-label-secondary)}
199
+ .adp-composer-label{color:var(--dsw-alias-label-primary);font-weight:600}
200
+ .adp-composer-count{font-variant-numeric:tabular-nums;opacity:.8}
201
+ .adp-composer-input{display:block;width:100%;min-height:150px;max-height:300px;resize:vertical;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary);padding:14px 15px;font:13.5px/1.65 inherit;box-sizing:border-box}
202
+ .adp-composer-input::placeholder{color:var(--dsw-alias-label-secondary);opacity:.8}
203
+ .adp-attachments{display:flex;flex-wrap:wrap;gap:8px;padding:0 15px 12px}
204
+ .adp-attach{position:relative;width:68px;height:68px;border-radius:8px;overflow:hidden;border:1px solid var(--dsw-alias-border-l1);background:#0b0d12}
205
+ .adp-attach img,.adp-attach video{width:100%;height:100%;object-fit:cover;display:block}
206
+ .adp-attach-remove{position:absolute;top:3px;right:3px;width:17px;height:17px;border:0;border-radius:50%;background:rgba(0,0,0,.62);color:#fff;font-size:12px;line-height:17px;cursor:pointer}
207
+ .adp-attach-kind{position:absolute;left:4px;bottom:4px;border-radius:3px;padding:1px 4px;background:rgba(0,0,0,.62);color:#fff;font:8.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}
208
+ .adp-attach-add{width:68px;height:68px;border:1px dashed var(--dsw-alias-border-l2);border-radius:8px;background:transparent;color:var(--dsw-alias-label-secondary);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;cursor:pointer;font:10px/1.2 inherit}
209
+ .adp-attach-add:hover{border-color:#C99B54;color:var(--dsw-alias-label-primary)}
210
+ .adp-attach-add b{font-size:18px;font-weight:300}
211
+ .adp-detected{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:0 15px 10px;color:var(--dsw-alias-label-secondary);font-size:10px}
212
+ .adp-detected-chip{border:1px solid rgba(229,180,92,.35);border-radius:999px;padding:2px 7px;color:#C99B54;background:rgba(229,180,92,.06);font:10px/1.5 ui-monospace,SFMono-Regular,Menlo,monospace}
213
+ .adp-conflict{margin:0 15px 10px;padding:7px 9px;border:1px solid color-mix(in srgb,var(--dsw-alias-state-warn-primary) 45%,transparent);border-radius:7px;background:color-mix(in srgb,var(--dsw-alias-state-warn-primary) 8%,transparent);color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.45}
214
+ .adp-conflict b{color:var(--dsw-alias-state-warn-primary);font-weight:600;margin-right:6px}
215
+ .adp-composer-foot{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;padding:10px 15px;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2)}
216
+ .adp-text-model{display:inline-flex;align-items:center;gap:5px;min-width:0;max-width:260px}
217
+ .adp-text-model>span{font:9px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.05em;color:#C99B54;white-space:nowrap}
218
+ .adp-text-model .adp-select{height:32px;max-width:220px;font-size:11px;min-width:120px}
219
+ .adp-model-select{height:32px;min-width:180px;max-width:260px;font-size:11px}
220
+ .adp-ref-upload{position:relative;display:inline-flex;align-items:center;justify-content:center;height:32px;padding:0 10px;border:1px dashed var(--dsw-alias-border-l2);border-radius:7px;color:var(--dsw-alias-label-secondary);font-size:11.5px;cursor:pointer;overflow:hidden;max-width:260px}
221
+ .adp-ref-upload:hover{border-color:#C99B54;color:var(--dsw-alias-label-primary)}
222
+ .adp-ref-upload.has{border-style:solid;padding:0 6px 0 4px}
223
+ .adp-ref-chip{display:inline-flex;align-items:center;gap:6px;min-width:0}
224
+ .adp-ref-chip img{width:24px;height:24px;border-radius:4px;object-fit:cover;flex:0 0 auto}
225
+ .adp-ref-name{max-width:170px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
226
+
227
+ .adp-advanced-panel{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);padding:13px 15px;margin-top:10px}
228
+ .adp-settings-page .adp-section-head{margin-top:16px}
229
+ .adp-dsh-line{display:flex;align-items:center;justify-content:space-between;gap:10px;border:1px solid var(--dsw-alias-border-l1);border-radius:9px;background:var(--dsw-alias-bg-layer-1);padding:9px 11px}
230
+ .adp-provider-grid{display:flex;flex-direction:column;gap:11px;align-items:stretch}
231
+ .adp-provider-card{border:1px solid var(--dsw-alias-border-l1);border-radius:11px;background:var(--dsw-alias-bg-layer-1);padding:13px 14px;display:flex;flex-direction:column;gap:9px;min-width:0}
232
+ .adp-provider-card.configured{border-color:color-mix(in srgb,var(--dsw-alias-state-success-primary) 38%,var(--dsw-alias-border-l1))}
233
+ .adp-provider-head{display:flex;align-items:flex-start;justify-content:space-between;gap:10px}
234
+ .adp-provider-name{font-size:13px;font-weight:700;margin-bottom:2px}
235
+ .adp-keyrow{display:flex;gap:6px;align-items:center}
236
+ .adp-keyrow .adp-input{height:30px;font-size:11px}
237
+ .adp-remote-line{display:flex;align-items:center;gap:7px;flex-wrap:wrap;border:1px solid color-mix(in srgb,var(--dsw-alias-state-success-primary) 28%,var(--dsw-alias-border-l1));border-radius:7px;padding:5px 7px;background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 5%,transparent);font-size:10px;color:var(--dsw-alias-label-secondary);line-height:1.4}
238
+ .adp-remote-label{font:9px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.04em;color:var(--dsw-alias-state-success-primary);white-space:nowrap}
239
+ .adp-provider-models-title{font:9px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase;color:var(--dsw-alias-label-secondary);opacity:.8}
240
+ .adp-models-toggle{display:flex;align-items:center;gap:8px;width:100%;border:0;border-top:1px solid var(--dsw-alias-border-l1);background:transparent;color:var(--dsw-alias-label-primary);padding:9px 0 0;cursor:pointer;font:inherit;text-align:left}
241
+ .adp-models-toggle-title{font-size:11.5px;font-weight:650}
242
+ .adp-models-toggle-action{margin-left:auto;font:9.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;color:#C99B54;letter-spacing:.04em}
243
+ .adp-models-toggle:hover .adp-models-toggle-action{color:var(--dsw-alias-label-primary)}
244
+ .adp-model-summary{display:flex;flex-wrap:wrap;gap:5px}
245
+ .adp-model-summary-chip{border:1px solid var(--dsw-alias-border-l1);border-radius:999px;background:var(--dsw-alias-bg-layer-2);padding:3px 7px;font-size:10px;color:var(--dsw-alias-label-secondary)}
246
+ .adp-provider-models{display:flex;flex-direction:column;gap:5px;border-top:1px solid var(--dsw-alias-border-l1);padding-top:8px}
247
+ .adp-provider-model{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;padding:6px 0;border-bottom:1px solid color-mix(in srgb,var(--dsw-alias-border-l1) 55%,transparent)}
248
+ .adp-provider-model:last-child{border-bottom:0}
249
+ .adp-provider-model-name{font-size:11.5px;font-weight:600;margin-bottom:1px}
250
+ .adp-provider-model.off{opacity:.58}
251
+ .adp-model-enable{display:inline-flex;align-items:center;gap:4px;font-size:10px;color:var(--dsw-alias-label-secondary);cursor:pointer;white-space:nowrap}
252
+ .adp-model-enable input{accent-color:#C99B54;width:13px;height:13px;margin:0}
253
+ .adp-provider-model.on .adp-provider-model-name{color:var(--dsw-alias-label-primary)}
254
+ .adp-notice{border:1px solid color-mix(in srgb,var(--dsw-alias-state-success-primary) 42%,transparent);background:color-mix(in srgb,var(--dsw-alias-state-success-primary) 8%,transparent);border-radius:8px;padding:8px 10px;color:var(--dsw-alias-label-secondary);font-size:11px;margin-top:10px}
255
+ .adp-persona-inline{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-2);padding:11px 12px;display:flex;flex-direction:column;gap:9px}
256
+ .adp-persona-off{opacity:.45;pointer-events:none;user-select:none}
257
+ .adp-persona-source{display:flex;flex-direction:column;gap:4px}
258
+ .adp-persona-source .adp-select{width:100%;height:31px}
259
+ .adp-persona-status{display:flex;align-items:flex-start;gap:8px;flex-wrap:wrap;line-height:1.45}
260
+ .adp-persona-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;border-top:1px solid var(--dsw-alias-border-l1);padding-top:9px}
261
+ .adp-persona-actions .adp-hint{margin:0}
262
+ .adp-persona-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:10px}
263
+ .adp-empty-state{border:1px dashed var(--dsw-alias-border-l2);border-radius:12px;padding:20px;display:flex;flex-direction:column;align-items:flex-start;gap:7px;background:var(--dsw-alias-bg-layer-1)}
264
+ .adp-modal-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.56);z-index:90;display:flex;align-items:center;justify-content:center;padding:20px}
265
+ .adp-modal{width:min(720px,94vw);max-height:88vh;background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-border-l1);border-radius:14px;box-shadow:0 24px 80px rgba(0,0,0,.45);display:flex;flex-direction:column;overflow:hidden;animation:adp-modal-in .16s ease-out}
266
+ @keyframes adp-modal-in{from{opacity:.5;transform:translateY(8px) scale(.99)}to{opacity:1;transform:none}}
267
+ .adp-modal-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:16px 18px;border-bottom:1px solid var(--dsw-alias-border-l1)}
268
+ .adp-modal-body{padding:16px 18px;overflow:auto;display:flex;flex-direction:column;gap:16px}
269
+ .adp-modal-section{display:flex;flex-direction:column;gap:9px}
270
+ .adp-modal-section-title{font:10px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase;color:#C99B54}
271
+ .adp-modal-foot{display:flex;justify-content:flex-end;gap:8px;padding:13px 18px;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2)}
272
+ .adp-persona-modal{width:min(880px,94vw);max-height:90vh}
273
+ .adp-persona-modal .adp-modal-body{padding:20px 22px;gap:18px}
274
+ .adp-persona-modal .adp-modal-section{padding:14px 16px 16px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-2)}
275
+ .adp-persona-modal .adp-modal-section .adp-field-grid{gap:12px 14px}
276
+ .adp-persona-modal .adp-modal-section .adp-field-label{margin-bottom:6px}
277
+ .adp-persona-modal .adp-modal-section .adp-input,.adp-persona-modal .adp-modal-section .adp-select{height:35px;font-size:12.5px}
278
+ @media(max-width:620px){.adp-persona-modal{max-height:94vh;width:100%}.adp-persona-modal .adp-modal-body{padding:13px}.adp-persona-modal .adp-modal-section{padding:12px}.adp-persona-modal .adp-field-grid{grid-template-columns:1fr !important}}
279
+ .adp-personas{display:grid;grid-template-columns:minmax(250px,.72fr) minmax(0,1.28fr);gap:14px;align-items:start}
280
+ .adp-persona-list{display:flex;flex-direction:column;gap:8px;min-width:0}
281
+ .adp-persona-card{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:11px 12px;min-width:0}
282
+ .adp-persona-card.on{border-color:#C99B54;box-shadow:0 0 0 1px #C99B54 inset}
283
+ .adp-persona-card .adp-h2{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
284
+ @media(max-width:900px){.adp-personas{grid-template-columns:1fr}}
285
+ .adp-split{display:grid;grid-template-columns:minmax(0,1.35fr) minmax(280px,.65fr);gap:14px}
286
+ .adp-slots{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
287
+ .adp-slot{border:1px dashed var(--dsw-alias-border-l2);border-radius:9px;min-height:92px;display:flex;align-items:center;justify-content:center;cursor:pointer;background:var(--dsw-alias-bg-layer-2);overflow:hidden;position:relative}
288
+ .adp-slot img,.adp-slot video{width:100%;height:104px;object-fit:cover;display:block}
289
+ .adp-slot .fill{position:absolute;inset:0;display:flex;align-items:flex-end;justify-content:flex-start;padding:7px;background:linear-gradient(transparent 40%,rgba(0,0,0,.55));color:#fff;font-size:10px}
290
+ .adp-chips{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
291
+ .adp-chip{border:1px solid var(--dsw-alias-border-l1);border-radius:999px;padding:3px 9px;font-size:10.5px;color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-layer-2)}
292
+ .adp-asset-foot{margin-top:14px;padding-top:12px;border-top:1px solid var(--dsw-alias-border-l1);color:var(--dsw-alias-label-secondary);font-size:10.5px;line-height:1.6}
293
+ .adp-asset-foot b{display:block;color:var(--dsw-alias-label-primary);font-size:10.5px;margin-bottom:4px;font-weight:600}
294
+ .adp-examples{margin-top:18px}
295
+ .adp-example-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin-top:8px}
296
+ .adp-example{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);padding:11px;text-align:left;cursor:pointer;color:var(--dsw-alias-label-primary);font:inherit;display:flex;flex-direction:column;gap:6px;min-height:92px}
297
+ .adp-example:hover{border-color:#C99B54;background:var(--dsw-alias-bg-layer-2)}
298
+ .adp-example .tag{font:9.5px/1.2 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.06em;color:#C99B54;text-transform:uppercase}
299
+ .adp-example b{font-size:12px;font-weight:650}
300
+ .adp-example span{font-size:10.5px;color:var(--dsw-alias-label-secondary);line-height:1.45}
301
+ .adp-result{display:flex;flex-direction:column;gap:14px;max-width:1120px;margin:0 auto}
302
+ .adp-result-head{display:flex;align-items:center;gap:12px;min-height:38px}
303
+ .adp-back{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);border-radius:7px;padding:6px 9px;cursor:pointer;font:inherit;font-size:11.5px;white-space:nowrap}
304
+ .adp-back:hover{color:var(--dsw-alias-label-primary);border-color:#C99B54}
305
+ .adp-result-title{min-width:0;flex:1 1 auto}
306
+ .adp-result-badges{display:flex;align-items:center;gap:6px;flex:0 0 auto}
307
+ .adp-result-grid{display:grid;grid-template-columns:minmax(300px,380px) minmax(0,1fr);gap:14px;align-items:start}
308
+ .adp-stage{position:relative;height:420px;display:flex;align-items:center;justify-content:center;background:radial-gradient(120% 100% at 50% 0%,#171a22 0%,#050608 70%);border:1px solid var(--dsw-alias-border-l1);border-radius:12px;overflow:hidden}
309
+ .adp-stage-video{display:block;max-width:100%;max-height:100%;background:#000}
310
+ .adp-empty-stage{color:var(--dsw-alias-label-secondary);font-size:11px;text-align:center;padding:20px}
311
+ .adp-stage-progress{position:absolute;left:12px;right:12px;bottom:12px;padding:8px 9px;border-radius:7px;background:rgba(8,9,13,.82);backdrop-filter:blur(6px);display:flex;flex-direction:column;gap:5px;color:#fff;font-size:10px}
312
+ .adp-result-side{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}
313
+ .adp-side-block{padding:13px 15px;border-bottom:1px solid var(--dsw-alias-border-l1)}
314
+ .adp-side-block:last-child{border-bottom:0}
315
+ .adp-side-label{font:10px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase;color:var(--dsw-alias-label-secondary);margin-bottom:8px}
316
+ .adp-action-list{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:7px}
317
+ .adp-action{display:flex;align-items:center;justify-content:flex-start;gap:6px;min-width:0;overflow:hidden;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;padding:8px 9px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);cursor:pointer;font:inherit;font-size:11.5px;text-align:left;line-height:1.3}
318
+ .adp-action:hover{border-color:#C99B54;background:var(--dsw-alias-bg-layer-1)}
319
+ .adp-action:focus-visible,.adp-back:focus-visible,.adp-shot-edit:focus-visible,.adp-icon-btn:focus-visible{outline:2px solid #C99B54;outline-offset:2px}
320
+ .adp-action:disabled{opacity:.4;cursor:not-allowed}
321
+ .adp-action.danger{color:var(--dsw-alias-state-error-primary)}
322
+ .adp-action svg{flex:0 0 auto;color:#C99B54}
323
+ .adp-action span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
324
+ .adp-action.danger svg{color:var(--dsw-alias-state-error-primary)}
325
+ .adp-side-note{font-size:10.5px;line-height:1.55;color:var(--dsw-alias-label-secondary);margin-top:8px}
326
+ .adp-facts{display:grid;grid-template-columns:1fr 1fr;gap:8px 12px}
327
+ .adp-fact{display:flex;flex-direction:column;gap:2px;min-width:0}
328
+ .adp-fact span{font:9.5px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.04em;color:var(--dsw-alias-label-secondary);text-transform:uppercase}
329
+ .adp-fact b{font-size:11.5px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
330
+ .adp-qa{display:flex;align-items:center;gap:8px}
331
+ .adp-qa-note{font-size:10.5px;color:var(--dsw-alias-label-secondary);margin-top:6px;line-height:1.45}
332
+ .adp-inputs{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}
333
+ .adp-inputs-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 14px;border-bottom:1px solid var(--dsw-alias-border-l1)}
334
+ .adp-inputs-grid{display:grid;grid-template-columns:minmax(0,1.55fr) minmax(260px,.9fr);gap:0}
335
+ .adp-input-brief{position:relative;padding:13px 14px;min-width:0;border-right:1px solid var(--dsw-alias-border-l1)}
336
+ .adp-input-label{font:10px/1.3 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.08em;text-transform:uppercase;color:var(--dsw-alias-label-secondary);margin-bottom:7px}
337
+ .adp-brief-text{font-size:12px;line-height:1.65;white-space:pre-wrap;overflow-wrap:anywhere;color:var(--dsw-alias-label-primary)}
338
+ .adp-copy{position:absolute;right:12px;top:10px;display:inline-flex;align-items:center;gap:4px;border:1px solid var(--dsw-alias-border-l1);border-radius:6px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);padding:3px 6px;font:inherit;font-size:10px;cursor:pointer}
339
+ .adp-copy:hover{color:var(--dsw-alias-label-primary);border-color:#C99B54}
340
+ .adp-copy svg{color:#C99B54}
341
+ .adp-input-assets{display:flex;flex-direction:column;gap:9px;padding:13px 14px;min-width:0}
342
+ .adp-asset-line{display:flex;align-items:center;gap:8px;min-width:0}
343
+ .adp-asset-tag{font:9.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.03em;color:#C99B54;white-space:nowrap;flex:0 0 auto}
344
+ .adp-asset-name{font-size:11px;color:var(--dsw-alias-label-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
345
+ .adp-asset-thumbs{display:flex;gap:4px;flex-wrap:wrap}
346
+ .adp-asset-thumb{width:26px;height:26px;border-radius:4px;overflow:hidden;border:1px solid var(--dsw-alias-border-l1);background:#0a0b10;display:inline-block}
347
+ .adp-asset-thumb img{width:100%;height:100%;object-fit:cover;display:block}
348
+ .adp-storyboard{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}
349
+ .adp-storyboard-head{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 14px;border-bottom:1px solid var(--dsw-alias-border-l1)}
350
+ .adp-storyboard-meta{font-size:10.5px;color:var(--dsw-alias-label-secondary)}
351
+ .adp-shot{display:grid;grid-template-columns:72px minmax(0,1fr) auto;gap:12px;align-items:start;padding:11px 14px;border-bottom:1px solid var(--dsw-alias-border-l1)}
352
+ .adp-shot:last-child{border-bottom:0}
353
+ .adp-shot.open{background:var(--dsw-alias-bg-layer-2)}
354
+ .adp-shot-thumb{position:relative;width:72px;height:96px;border-radius:7px;overflow:hidden;background:#0a0b10;border:1px solid var(--dsw-alias-border-l1);flex:0 0 auto}
355
+ .adp-shot-thumb img{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block}
356
+ .adp-shot-placeholder{position:absolute;inset:0;background:linear-gradient(135deg,#1a1d26,#0b0d12)}
357
+ .adp-shot-index{position:absolute;left:4px;bottom:4px;border-radius:4px;padding:1px 4px;background:rgba(8,9,13,.72);color:#fff;font:9px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace}
358
+ .adp-shot-body{min-width:0;padding-top:1px}
359
+ .adp-shot-top{display:flex;align-items:baseline;gap:8px;min-width:0}
360
+ .adp-shot-top b{font-size:12.5px;font-weight:700}
361
+ .adp-shot-time{font:9.5px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--dsw-alias-label-secondary);white-space:nowrap}
362
+ .adp-shot-dialogue{font-size:12px;line-height:1.5;margin-top:5px;color:var(--dsw-alias-label-primary);overflow:hidden;text-overflow:ellipsis;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
363
+ .adp-shot-action{font-size:10.5px;line-height:1.45;color:var(--dsw-alias-label-secondary);margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
364
+ .adp-shot-edit{display:inline-flex;align-items:center;gap:4px;border:1px solid var(--dsw-alias-border-l1);border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);padding:4px 7px;font:inherit;font-size:10.5px;cursor:pointer;white-space:nowrap;margin-top:2px}
365
+ .adp-shot-edit:hover{color:var(--dsw-alias-label-primary);border-color:#C99B54}
366
+ .adp-shot-edit svg{color:#C99B54}
367
+ .adp-shot-editor{grid-column:1/-1;display:flex;flex-direction:column;gap:8px;border-top:1px solid var(--dsw-alias-border-l1);padding-top:10px;margin-top:1px}
368
+ .adp-shot-editor-head{font:10px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:.05em;text-transform:uppercase;color:#C99B54}
369
+ .adp-shot-chat-row .adp-input{height:32px}
370
+ .adp-empty-shots{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:16px 14px;color:var(--dsw-alias-label-secondary);font-size:11px}
371
+ .adp-result-error{border:1px solid color-mix(in srgb,var(--dsw-alias-state-error-primary) 45%,transparent);border-radius:8px;padding:9px 11px;background:color-mix(in srgb,var(--dsw-alias-state-error-primary) 8%,transparent)}
372
+ .adp-drawer-backdrop{position:fixed;inset:0;background:rgba(0,0,0,.52);z-index:80;display:flex;justify-content:flex-end}
373
+ .adp-drawer{width:min(380px,92vw);height:100%;background:var(--dsw-alias-bg-layer-1);border-left:1px solid var(--dsw-alias-border-l1);box-shadow:-18px 0 50px rgba(0,0,0,.35);display:flex;flex-direction:column;animation:adp-slide-in .18s ease-out}
374
+ @keyframes adp-slide-in{from{transform:translateX(18px);opacity:.6}to{transform:translateX(0);opacity:1}}
375
+ .adp-drawer-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px;padding:16px;border-bottom:1px solid var(--dsw-alias-border-l1)}
376
+ .adp-drawer-body{display:flex;flex-direction:column;gap:14px;padding:16px;overflow:auto}
377
+ .adp-drawer-body .adp-select{width:100%;height:34px}
378
+ .adp-drawer-foot{margin-top:auto;display:flex;justify-content:flex-end;gap:8px;padding:14px 16px;border-top:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-2)}
379
+ .adp-icon-btn{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border:0;border-radius:50%;background:transparent;color:var(--dsw-alias-label-secondary);cursor:pointer;transition:background .15s ease,color .15s ease,transform .15s ease}
380
+ .adp-icon-btn:hover{color:#E2B96F;background:rgba(201,155,84,.12);transform:translateY(-1px)}
381
+ @media(max-width:760px){.adp-example-grid{grid-template-columns:1fr}}
382
+ @media(hover:none){.adp-media .adp-remove{opacity:1}}
383
+ @media(max-width:980px){.adp-panel-grid{grid-template-columns:1fr}.adp-asset-col{border-right:0;border-bottom:1px solid var(--dsw-alias-border-l1)}.adp-title{font-size:21px}}
384
+ @media(max-width:980px){.adp-result-grid{grid-template-columns:1fr}.adp-stage{height:360px;max-width:420px;margin:0 auto;width:100%}}
385
+ @media(max-width:760px){.adp-inputs-grid{grid-template-columns:1fr}.adp-input-brief{border-right:0;border-bottom:1px solid var(--dsw-alias-border-l1)}}
386
+ .adp-select,.adp-field .adp-select,.adp-toolbar .adp-select,.adp-persona-modal .adp-modal-section .adp-select{appearance:none;-webkit-appearance:none;background-image:linear-gradient(45deg,transparent 50%,#A8ABB4 50%),linear-gradient(135deg,#A8ABB4 50%,transparent 50%);background-repeat:no-repeat;background-position:calc(100% - 14px) 50%,calc(100% - 9px) 50%;background-size:5px 5px;padding-right:28px}
387
+ .adp-date-input{width:124px;flex:0 0 auto}
388
+ .adp-upload-label{position:relative;overflow:hidden;cursor:pointer;display:inline-flex;align-items:center;justify-content:center}
389
+ @media(max-width:620px){.adp-modal-backdrop{padding:8px}.adp-modal{max-height:94vh;width:100%}.adp-modal-body{padding:13px}.adp-modal-foot{padding:12px}.adp-persona-grid{grid-template-columns:1fr}.adp-composer-input{min-height:120px;font-size:13px}.adp-composer-foot{align-items:stretch}.adp-composer-foot .adp-primary{width:100%;justify-content:center}.adp-model-select{min-width:0;flex:1 1 auto}.adp-text-model{max-width:none;flex:1 1 100%}.adp-text-model .adp-select{max-width:none;flex:1 1 auto}.adp-top{gap:8px;padding:0 12px}.adp-sub{display:none}.adp-tabs{margin-left:0}.adp-tab{padding:0 8px}.adp-body{padding:16px 12px 32px}.adp-page-head{display:block}.adp-page-meta{margin-top:8px}.adp-field-grid.g3,.adp-field-grid.g4{grid-template-columns:repeat(2,minmax(0,1fr))}.adp-actionbar{margin-left:-14px;margin-right:-14px;padding:12px 14px}.adp-form-col{padding:16px 14px 0}.adp-asset-col{padding:14px}.adp-slots{grid-template-columns:1fr 1fr}.adp-result-head{flex-wrap:wrap}.adp-result-badges{width:100%;justify-content:flex-start}.adp-stage{height:320px}.adp-shot{grid-template-columns:56px minmax(0,1fr) auto;gap:9px;padding:10px}.adp-shot-thumb{width:56px;height:76px}.adp-shot-edit span{display:none}.adp-facts{grid-template-columns:1fr 1fr}}
390
+ `
391
+ /** Supervisor state, available even while the engine is still being prepared. */
392
+ async function hostStatus() {
393
+ try {
394
+ const res = await fetch('/adplus/health', { headers: TOKEN ? { 'x-adplus-token': TOKEN } : {} })
395
+ if (!res.ok) return null
396
+ const data = await res.json()
397
+ return data.engine || null
398
+ } catch { return null }
399
+ }
400
+
401
+ async function restartEngineHost() {
402
+ const res = await fetch('/adplus/api/engine/restart', { method: 'POST', headers: TOKEN ? { 'x-adplus-token': TOKEN } : {} })
403
+ return res.ok
404
+ }
405
+
406
+ async function api(path, options) {
407
+ await tokenReady()
408
+ const opts = Object.assign({}, options || {})
409
+ const headers = Object.assign({ 'x-adplus-token': TOKEN }, opts.headers || {})
410
+ if (opts.body && typeof opts.body !== 'string' && !(opts.body instanceof Blob)) {
411
+ headers['content-type'] = 'application/json'
412
+ opts.body = JSON.stringify(opts.body)
413
+ }
414
+ const res = await fetch(API + path, Object.assign({}, opts, { headers }))
415
+ const text = await res.text()
416
+ let data = {}
417
+ try { data = text ? JSON.parse(text) : {} } catch { data = { raw: text } }
418
+ if (!res.ok) {
419
+ const message = (data.error && (data.error.message || data.error.code)) || data.detail || ('HTTP ' + res.status)
420
+ throw new Error(typeof message === 'string' ? message : JSON.stringify(message))
421
+ }
422
+ return data
423
+ }
424
+
425
+ function mediaUrl(path) {
426
+ if (!path) return ''
427
+ return MEDIA + '?path=' + encodeURIComponent(path) + '&token=' + encodeURIComponent(TOKEN)
428
+ }
429
+
430
+ function mediaUrlVersion(path, version) {
431
+ const url = mediaUrl(path)
432
+ if (!url) return ''
433
+ return url + (url.includes('?') ? '&' : '?') + 'v=' + encodeURIComponent(version || 1)
434
+ }
435
+
436
+ async function uploadFile(file, kind) {
437
+ await tokenReady()
438
+ const res = await fetch(API + '/assets/upload?kind=' + encodeURIComponent(kind) + '&name=' + encodeURIComponent(file.name || 'upload'), {
439
+ method: 'POST',
440
+ headers: { 'content-type': file.type || 'application/octet-stream', 'x-adplus-token': TOKEN },
441
+ body: file,
442
+ })
443
+ const data = await res.json()
444
+ if (!res.ok) throw new Error((data.error && data.error.message) || data.detail || '上传失败')
445
+ return Object.assign({}, data.asset, { deduplicated: Boolean(data.deduplicated) })
446
+ }
447
+
448
+ function fmt(seconds) {
449
+ const s = Number(seconds || 0)
450
+ if (!s) return '—'
451
+ return s < 60 ? s.toFixed(1) + 's' : Math.floor(s / 60) + 'm' + Math.round(s % 60) + 's'
452
+ }
453
+
454
+ function fmtAt(seconds) {
455
+ return Number(seconds || 0).toFixed(1) + 's'
456
+ }
457
+
458
+
459
+
460
+ function fmtDateTime(value) {
461
+ if (!value) return '—'
462
+ const date = new Date(value)
463
+ if (Number.isNaN(date.getTime())) return String(value)
464
+ return date.toLocaleString('zh-CN', { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
465
+ }
466
+
467
+ function fmtAssetDate(value) {
468
+ if (!value) return '—'
469
+ const date = new Date(value)
470
+ if (Number.isNaN(date.getTime())) return String(value)
471
+ const pad = (n) => String(n).padStart(2, '0')
472
+ return date.getFullYear() + '/' + pad(date.getMonth() + 1) + '/' + pad(date.getDate()) + ' ' + pad(date.getHours()) + ':' + pad(date.getMinutes())
473
+ }
474
+
475
+ function runDuration(run) {
476
+ if (!run || !run.created_at) return '—'
477
+ const start = new Date(run.created_at).getTime()
478
+ const end = run.finished_at ? new Date(run.finished_at).getTime() : Date.now()
479
+ if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) return '—'
480
+ const seconds = Math.round((end - start) / 1000)
481
+ return seconds < 60 ? seconds + 's' : Math.floor(seconds / 60) + 'm' + (seconds % 60) + 's'
482
+ }
483
+
484
+ async function downloadPost(path, body, filename) {
485
+ await tokenReady()
486
+ const res = await fetch(API + path, { method: 'POST', headers: { 'content-type': 'application/json', 'x-adplus-token': TOKEN }, body: JSON.stringify(body || {}) })
487
+ if (!res.ok) {
488
+ const text = await res.text()
489
+ let message = '导出失败'
490
+ try { const data = JSON.parse(text); message = data.detail || (data.error && data.error.message) || message } catch { /* noop */ }
491
+ throw new Error(message)
492
+ }
493
+ const blob = await res.blob()
494
+ const url = URL.createObjectURL(blob)
495
+ const a = document.createElement('a')
496
+ a.href = url
497
+ a.download = filename || 'adplus-export.zip'
498
+ a.click()
499
+ setTimeout(() => URL.revokeObjectURL(url), 1000)
500
+ }
501
+
502
+ function detectVideoParams(text) {
503
+ const source = String(text || '')
504
+ const aspect = (source.match(/(21:9|16:9|9:16|4:3|3:4|1:1)/) || [])[1] || (/竖屏/.test(source) ? '9:16' : /横屏/.test(source) ? '16:9' : /方屏|方形/.test(source) ? '1:1' : '')
505
+ const duration = Number((source.match(/(\d{1,2})\s*(?:秒|s|sec)(?!\w)/i) || [])[1] || 0)
506
+ const resolution = (source.match(/(1080p|720p|480p|2k)/i) || [])[1] || ''
507
+ const mode = /(精细|分段|分镜)/.test(source) ? 'fine' : ''
508
+ // Subtitles are a sidecar SRT switch. Judge the "off" phrasings first so
509
+ // "不要字幕" never reads as "字幕".
510
+ let subtitle = ''
511
+ if (/字幕/.test(source)) {
512
+ if (/(不要|不启用|不用|去掉|关闭|关掉|取消|别加|无)字幕|字幕(不要|关掉|关闭|去掉|不用)/.test(source)) subtitle = 'off'
513
+ else if (/(加|开|要|带|生成|启用)字幕|字幕(打开|开启)/.test(source)) subtitle = 'sidecar'
514
+ }
515
+ const vendor = /可灵|kling/i.test(source) ? 'kling'
516
+ : /seedance|方舟|ark/i.test(source) ? 'ark'
517
+ : /minimax|海螺|hailuo/i.test(source) ? 'minimax' : ''
518
+ return { aspect, duration: duration || 0, resolution: resolution ? resolution.toLowerCase().replace('2k', '1080p') : '', mode, subtitle, vendor }
519
+ }
520
+
521
+ /** First usable model from a vendor named in the brief, or '' when none. */
522
+ function modelForVendor(vendor, models) {
523
+ if (!vendor) return ''
524
+ const row = (models || []).find((m) => m.kind === 'video' && m.provider === vendor && m.available && m.enabled !== false)
525
+ return row ? row.id : ''
526
+ }
527
+
528
+ /** Default video model: first usable one, dialogue-capable first for remakes. */
529
+ function defaultModelId(models, needsDialogue) {
530
+ const rows = (models || []).filter((m) => m.kind === 'video' && m.available && m.enabled !== false && (m.capabilities || []).includes('text_to_video'))
531
+ const real = rows.filter((m) => m.provider !== 'synthetic')
532
+ const pool = real.length ? real : rows
533
+ const withAudio = needsDialogue ? pool.filter((m) => m.native_audio) : pool
534
+ const pick = (withAudio.length ? withAudio : pool)[0]
535
+ return pick ? pick.id : ''
536
+ }
537
+
538
+ /** How the subtitle setting reads in the UI. */
539
+ function subtitleLabel(value) {
540
+ return value === 'sidecar' ? 'SRT 旁挂' : '不启用'
541
+ }
542
+
543
+ async function parseIntentWithDsh(brief, textModel) {
544
+ try {
545
+ const data = await api('/dsh/chat', { method: 'POST', body: {
546
+ system: '你是广告视频参数解析器。只输出 JSON,不要解释,不要 markdown。字段:aspect(9:16|16:9|1:1|4:3|3:4|21:9 或 null)、duration(整数秒或 null)、resolution(480p|720p|1080p 或 null)、generation_mode(fast|fine 或 null)、subtitle(off|sidecar|null,是否交付 SRT 旁挂字幕)、model_vendor(kling|ark|minimax|null,用户点名的厂商)、stitch(布尔,用户是否想把附件视频拼接)、reason(一句话)。只按用户明确表达解析,不要猜。',
547
+ messages: [{ role: 'user', content: [{ type: 'text', text: String(brief || '').slice(0, 1000) }] }],
548
+ maxTokens: 500,
549
+ provider: textModel && textModel.provider,
550
+ model: textModel && textModel.model,
551
+ } })
552
+ const text = String((data.dsh && data.dsh.text) || '')
553
+ const start = text.indexOf('{')
554
+ const end = text.lastIndexOf('}')
555
+ if (start < 0 || end <= start) return null
556
+ const value = JSON.parse(text.slice(start, end + 1))
557
+ const aspects = ['9:16', '16:9', '1:1', '4:3', '3:4', '21:9']
558
+ const resolutions = ['480p', '720p', '1080p']
559
+ const duration = Number(value.duration)
560
+ const vendors = ['kling', 'ark', 'minimax']
561
+ return {
562
+ aspect: aspects.includes(value.aspect) ? value.aspect : '',
563
+ duration: Number.isFinite(duration) && duration >= 1 && duration <= 30 ? duration : 0,
564
+ resolution: resolutions.includes(String(value.resolution || '').toLowerCase()) ? String(value.resolution).toLowerCase() : '',
565
+ mode: value.generation_mode === 'fine' ? 'fine' : '',
566
+ subtitle: ['off', 'sidecar'].includes(value.subtitle) ? value.subtitle : '',
567
+ vendor: vendors.includes(String(value.model_vendor || '')) ? String(value.model_vendor) : '',
568
+ stitch: Boolean(value.stitch),
569
+ }
570
+ } catch (e) { return null }
571
+ }
572
+
573
+ function Badge({ status, children }) {
574
+ return h('span', { className: 'adp-badge ' + (status || '') }, children)
575
+ }
576
+
577
+ const CAPABILITY_LABELS = {
578
+ text_to_video: '文生视频', image_to_video: '图生视频', reference_to_video: '参考视频',
579
+ text_to_image: '文生图', image_to_image: '图生图',
580
+ }
581
+
582
+ /** One small chip per declared capability. */
583
+ function CapabilityChip({ capability }) {
584
+ return h('span', { className: 'adp-cap' }, CAPABILITY_LABELS[capability] || capability)
585
+ }
586
+
587
+ function CapabilityChips({ row }) {
588
+ const caps = (row && row.capabilities) || []
589
+ return h('span', { className: 'adp-caps' }, caps.map((cap) => h(CapabilityChip, { key: cap, capability: cap })))
590
+ }
591
+
592
+ /** Short label for the supervisor's bootstrap stage. */
593
+ function engineStageLabel(engine) {
594
+ const stage = engine && engine.boot && engine.boot.stage
595
+ if (stage === 'preparing') return '准备中'
596
+ if (stage === 'failed') return '不可用'
597
+ if (stage === 'stopped') return '已停止'
598
+ if (stage === 'disabled') return '已关闭'
599
+ return '离线'
600
+ }
601
+
602
+ function Icon(props) {
603
+ const size = props.size || 18
604
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': true },
605
+ h('rect', { x: 3, y: 4, width: 18, height: 16, rx: 3, stroke: 'currentColor', strokeWidth: 1.8 }),
606
+ h('path', { d: 'M10 9.2v5.6l4.8-2.8L10 9.2Z', fill: 'currentColor' }),
607
+ h('path', { d: 'M3 16.5l4.2-3.2 3.1 2.4 3-2.2 4.7 3.3', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round' })
608
+ )
609
+ }
610
+
611
+ function Glyph({ name, size = 14 }) {
612
+ const paths = {
613
+ back: 'M15 18l-6-6 6-6',
614
+ edit: 'M4 20h4l11-11a2.8 2.8 0 0 0-4-4L4 16v4Z M13.5 6.5l4 4',
615
+ refresh: 'M20 11a8 8 0 0 0-14-5 M4 4v6h6 M4 13a8 8 0 0 0 14 5 M20 20v-6h-6',
616
+ download: 'M12 3v12 M8 11l4 4 4-4 M4 21h16',
617
+ close: 'M6 6l12 12 M18 6L6 18',
618
+ check: 'M4 12.5l5 5L20 6.5',
619
+ play: 'M8 5l11 7-11 7V5Z',
620
+ spark: 'M12 3l1.7 5.3L19 10l-5.3 1.7L12 17l-1.7-5.3L5 10l5.3-1.7L12 3Z',
621
+ copy: 'M8 8h11v11H8V8Z M16 8V5H5v11h3',
622
+ folder: 'M3 7a2 2 0 0 1 2-2h5l2 2h7v10H3V7Z',
623
+ undo: 'M9 7H4v5 M4 12a8 8 0 1 0 2-5',
624
+ }
625
+ return h('svg', { width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.8, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true },
626
+ h('path', { d: paths[name] || paths.spark })
627
+ )
628
+ }
629
+
630
+ const DSH_MEDIA_MODEL = /(veo|seedance|happyhorse|gpt-image|nano-banana|(^|[-_.])wan(?:\d|[-_.])|image|video|t2v)/i
631
+
632
+ function dshTextModels(dsh) {
633
+ if (!dsh || !dsh.available) return []
634
+ const rows = []
635
+ for (const provider of dsh.providers || []) {
636
+ for (const model of provider.models || []) {
637
+ const id = String(model.id || '')
638
+ if (!id || DSH_MEDIA_MODEL.test(id)) continue
639
+ rows.push({
640
+ provider: provider.id,
641
+ providerName: provider.name || provider.id,
642
+ model: id,
643
+ name: model.name || id,
644
+ })
645
+ }
646
+ }
647
+ return rows
648
+ }
649
+
650
+ function defaultDshTextModel(dsh) {
651
+ const rows = dshTextModels(dsh)
652
+ if (!rows.length) return null
653
+ const selected = dsh && dsh.selection
654
+ if (selected && rows.some((row) => row.provider === selected.provider && row.model === selected.model)) {
655
+ return { provider: selected.provider, model: selected.model }
656
+ }
657
+ return { provider: rows[0].provider, model: rows[0].model }
658
+ }
659
+
660
+ function textModelKey(value) {
661
+ return value && value.provider && value.model ? value.provider + '|' + value.model : ''
662
+ }
663
+
664
+ function TextModelSelect({ dsh, value, onChange }) {
665
+ const rows = dshTextModels(dsh)
666
+ if (!rows.length) return null
667
+ const fallback = defaultDshTextModel(dsh)
668
+ const selected = value && rows.some((row) => row.provider === value.provider && row.model === value.model) ? value : fallback
669
+ const groups = new Map()
670
+ for (const row of rows) {
671
+ if (!groups.has(row.provider)) groups.set(row.provider, { name: row.providerName, rows: [] })
672
+ groups.get(row.provider).rows.push(row)
673
+ }
674
+ return h('label', { className: 'adp-text-model', title: 'DSH 文本模型(抽梗 / 脚本 / 润色)' },
675
+ h('span', null, '文本'),
676
+ h('select', {
677
+ className: 'adp-select',
678
+ value: textModelKey(selected),
679
+ onChange: (e) => {
680
+ const [provider, model] = String(e.currentTarget.value).split('|')
681
+ onChange({ provider, model })
682
+ },
683
+ }, Array.from(groups.entries()).map(([provider, group]) => h('optgroup', { key: provider, label: group.name },
684
+ group.rows.map((row) => h('option', { key: row.model, value: textModelKey(row) }, row.name))
685
+ )))
686
+ )
687
+ }
688
+
689
+ function UploadSlot({ label, asset, kind, onAsset }) {
690
+ const ref = useRef(null)
691
+ const [busy, setBusy] = useState(false)
692
+ const [err, setErr] = useState('')
693
+ const choose = () => ref.current && ref.current.click()
694
+ const onFile = async (event) => {
695
+ const file = event.currentTarget.files && event.currentTarget.files[0]
696
+ event.currentTarget.value = ''
697
+ if (!file) return
698
+ setBusy(true); setErr('')
699
+ try { onAsset(await uploadFile(file, kind)) } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
700
+ }
701
+ return h('div', { className: 'adp-col' },
702
+ h('div', { className: 'adp-small adp-muted' }, label),
703
+ h('div', { className: 'adp-slot', onClick: busy ? undefined : choose, title: asset ? '点击替换' : '点击上传' },
704
+ busy ? h('span', { className: 'adp-small adp-muted' }, '上传中…') : (
705
+ asset ? (asset.kind === 'image'
706
+ ? h('img', { src: mediaUrl(asset.path), alt: asset.name })
707
+ : h('video', { src: mediaUrl(asset.path), muted: true, playsInline: true }))
708
+ : h('span', { className: 'adp-small adp-muted' }, '+ ' + label)
709
+ ),
710
+ asset ? h('div', { className: 'fill' }, asset.name) : null
711
+ ),
712
+ err ? h('div', { className: 'adp-error' }, err) : null,
713
+ h('input', { ref, type: 'file', accept: kind === 'video' ? 'video/*' : 'image/*', onChange: onFile, style: { display: 'none' } })
714
+ )
715
+ }
716
+
717
+ function Select({ value, onChange, options, label }) {
718
+ return h('label', { className: 'adp-chip' },
719
+ label ? h('span', { className: 'adp-muted' }, label + ' ') : null,
720
+ h('select', { className: 'adp-select', value, onChange: (e) => onChange(e.currentTarget.value), style: { border: 0, background: 'transparent', padding: 0 } },
721
+ (options || []).map((opt) => h('option', { key: String(opt.value ?? opt), value: String(opt.value ?? opt) }, opt.label ?? String(opt)))
722
+ )
723
+ )
724
+ }
725
+
726
+ function Field({ label, hint, children, style }) {
727
+ return h('div', { className: 'adp-field', style },
728
+ label ? h('div', { className: 'adp-field-label' }, label) : null,
729
+ children,
730
+ hint ? h('div', { className: 'adp-hint' }, hint) : null
731
+ )
732
+ }
733
+
734
+ function FormSelect({ label, value, onChange, options }) {
735
+ return h(Field, { label },
736
+ h('select', { className: 'adp-select', value, onChange: (e) => onChange(e.currentTarget.value) },
737
+ (options || []).map((opt) => h('option', { key: String(opt.value ?? opt), value: String(opt.value ?? opt) }, opt.label ?? String(opt)))
738
+ )
739
+ )
740
+ }
741
+
742
+ function DropVideo({ asset, onAsset }) {
743
+ const input = useRef(null)
744
+ const [busy, setBusy] = useState(false)
745
+ const [drag, setDrag] = useState(false)
746
+ const [err, setErr] = useState('')
747
+ const choose = () => { if (!busy) input.current && input.current.click() }
748
+ const take = async (file) => {
749
+ if (!file) return
750
+ setBusy(true); setErr('')
751
+ try { onAsset(await uploadFile(file, 'video')) } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
752
+ }
753
+ return h('div', { className: 'adp-col' },
754
+ h('div', {
755
+ className: 'adp-drop' + (drag ? ' drag' : ''),
756
+ onClick: choose,
757
+ role: 'button',
758
+ tabIndex: 0,
759
+ onKeyDown: (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); choose() } },
760
+ onDragOver: (e) => { e.preventDefault(); setDrag(true) },
761
+ onDragLeave: () => setDrag(false),
762
+ onDrop: (e) => { e.preventDefault(); setDrag(false); take(e.dataTransfer.files && e.dataTransfer.files[0]) },
763
+ title: asset ? '点击替换参考视频' : '点击或拖入参考视频',
764
+ },
765
+ asset ? h('video', { src: mediaUrl(asset.path), muted: true, playsInline: true }) : h('div', { className: 'adp-drop-empty' },
766
+ h('b', null, busy ? '上传中…' : '拖入参考视频'),
767
+ h('span', null, '或点击选择 · mp4 / mov / webm · ≤30s')
768
+ ),
769
+ asset ? h('div', { className: 'adp-drop-overlay' },
770
+ h('span', { style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, asset.name),
771
+ h('button', { className: 'adp-remove', onClick: (e) => { e.stopPropagation(); onAsset(null) }, title: '移除' }, '×')
772
+ ) : null
773
+ ),
774
+ h('input', { ref: input, type: 'file', accept: 'video/*', style: { display: 'none' }, onChange: (e) => { take(e.currentTarget.files && e.currentTarget.files[0]); e.currentTarget.value = '' } }),
775
+ err ? h('div', { className: 'adp-error' }, err) : null
776
+ )
777
+ }
778
+
779
+ function MediaGrid({ assets, onAdd, onRemove, max = 9 }) {
780
+ const input = useRef(null)
781
+ const [busy, setBusy] = useState(false)
782
+ const [err, setErr] = useState('')
783
+ const add = async (files) => {
784
+ const list = Array.from(files || []).slice(0, Math.max(0, max - (assets || []).length))
785
+ if (!list.length) return
786
+ setBusy(true); setErr('')
787
+ try {
788
+ const out = []
789
+ for (const file of list) out.push(await uploadFile(file, 'image'))
790
+ onAdd(out)
791
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
792
+ }
793
+ return h('div', { className: 'adp-col' },
794
+ h('div', { className: 'adp-media-grid' },
795
+ (assets || []).map((asset) => h('div', { className: 'adp-media', key: asset.id, title: asset.name },
796
+ h('img', { src: mediaUrl(asset.path), alt: asset.name }),
797
+ h('button', { className: 'adp-remove', onClick: () => onRemove(asset.id), title: '移除' }, '×')
798
+ )),
799
+ (assets || []).length < max ? h('button', { className: 'adp-media-add', onClick: () => input.current && input.current.click(), disabled: busy, title: '添加商品图' },
800
+ h('b', null, busy ? '…' : '+'),
801
+ h('span', null, busy ? '上传中' : '添加')
802
+ ) : null
803
+ ),
804
+ h('input', { ref: input, type: 'file', accept: 'image/*', multiple: true, style: { display: 'none' }, onChange: (e) => { add(e.currentTarget.files); e.currentTarget.value = '' } }),
805
+ err ? h('div', { className: 'adp-error' }, err) : null
806
+ )
807
+ }
808
+
809
+ function PersonaFields({ value, onChange, columns = 4 }) {
810
+ const v = value || {}
811
+ const set = (key, val) => onChange(Object.assign({}, v, { [key]: val }))
812
+ return h('div', { className: 'adp-field-grid g' + columns },
813
+ h(FormSelect, { label: '性别', value: v.gender || 'any', onChange: (x) => set('gender', x), options: [{ value: 'any', label: '不限' }, { value: 'female', label: '女' }, { value: 'male', label: '男' }] }),
814
+ h(FormSelect, { label: '年龄', value: v.age || 'youth', onChange: (x) => set('age', x), options: [{ value: 'teenager', label: '18–24 青年感' }, { value: 'youth', label: '25–34 青年' }, { value: 'middle_aged', label: '35–54 中年' }, { value: 'senior', label: '55+ 老年' }] }),
815
+ h(FormSelect, { label: '体型', value: v.body_type || 'standard', onChange: (x) => set('body_type', x), options: [{ value: 'slim', label: '偏瘦' }, { value: 'standard', label: '标准' }, { value: 'athletic', label: '健硕' }, { value: 'chubby', label: '微胖' }] }),
816
+ h(FormSelect, { label: '族裔', value: v.ethnicity || 'asian', onChange: (x) => set('ethnicity', x), options: [{ value: 'asian', label: '亚洲' }, { value: 'caucasian', label: '欧美' }, { value: 'latino', label: '拉美' }, { value: 'african', label: '非洲' }, { value: 'middle_eastern', label: '中东' }, { value: 'any', label: '不限' }] })
817
+ )
818
+ }
819
+
820
+ function AdvancedRow({ value, onChange, models, needsDialogue }) {
821
+ const v = value || {}
822
+ const set = (key, val) => onChange(Object.assign({}, v, { [key]: val }))
823
+ const usableModels = (models || []).filter(m => m.available && m.enabled !== false)
824
+ const modelOptions = usableModels.map(m => ({ value: m.id, label: m.label }))
825
+ const currentModel = modelOptions.some(o => o.value === v.model) ? v.model : (modelOptions[0] ? modelOptions[0].value : '')
826
+ return h('div', { className: 'adp-col', style: { gap: 9 } },
827
+ h('div', { className: 'adp-field-grid g3' },
828
+ h(FormSelect, { label: '模式', value: v.generation_mode || 'fast', onChange: (x) => set('generation_mode', x), options: [{ value: 'fast', label: '快速 · 整条' }, { value: 'fine', label: '精细 · 分段' }] }),
829
+ h(FormSelect, { label: '时长(秒)', value: v.duration || 12, onChange: (x) => set('duration', Number(x)), options: [5, 8, 10, 12, 15, 30] }),
830
+ h(FormSelect, { label: '比例', value: v.aspect || '9:16', onChange: (x) => set('aspect', x), options: ['9:16', '16:9', '1:1', '4:3', '3:4', '21:9'] })
831
+ ),
832
+ h('div', { className: 'adp-field-grid g3' },
833
+ h(FormSelect, { label: '清晰度', value: v.resolution || '720p', onChange: (x) => set('resolution', x), options: ['480p', '720p', '1080p'] }),
834
+ h(FormSelect, { label: '模型', value: currentModel, onChange: (x) => set('model', x), options: modelOptions }),
835
+ h(FormSelect, { label: '字幕', value: v.subtitle || 'off', onChange: (x) => set('subtitle', x), options: [{ value: 'off', label: '不启用' }, { value: 'sidecar', label: 'SRT 旁挂' }] })
836
+ )
837
+ )
838
+ }
839
+
840
+ function StatusBadge({ status }) {
841
+ const cls = status === 'succeeded' ? 'ok' : status === 'failed' || status === 'canceled' ? 'bad' : status === 'running' || status === 'queued' ? 'warn' : ''
842
+ const label = { queued: '排队', running: '生成中', succeeded: '完成', failed: '失败', canceled: '已取消', interrupted: '中断' }[status] || status
843
+ return h(Badge, { status: cls }, label)
844
+ }
845
+
846
+ function RunCard({ run, onOpen }) {
847
+ return h('div', { className: 'adp-run-card', onClick: () => onOpen(run) },
848
+ h('div', { className: 'adp-row' }, h('div', { className: 'adp-h2 adp-grow' }, run.title || run.scenario), h(StatusBadge, { status: run.status })),
849
+ h('div', { className: 'adp-small adp-muted', style: { marginTop: 4 } }, run.scenario === 'text-to-image' ? ('文生图片 · ' + ((run.advanced && run.advanced.aspect) || '1:1') + ' · ' + ((run.advanced && run.advanced.area) || '2K')) : (run.scenario + ' · ' + ((run.advanced && run.advanced.duration) || 0) + 's · ' + ((run.advanced && run.advanced.aspect) || '9:16'))),
850
+ h('div', { className: 'adp-progress', style: { marginTop: 8 } }, h('i', { style: { width: Math.round((run.progress || 0) * 100) + '%' } })),
851
+ h('div', { className: 'adp-small adp-faint', style: { marginTop: 5 } }, run.step || '—', run.error ? ' · ' + String(run.error).slice(0, 80) : '')
852
+ )
853
+ }
854
+
855
+ async function downloadExport(runId) {
856
+ const res = await fetch(API + '/runs/' + runId + '/export', { headers: { 'x-adplus-token': TOKEN } })
857
+ if (!res.ok) throw new Error('导出失败')
858
+ const blob = await res.blob()
859
+ const url = URL.createObjectURL(blob)
860
+ const a = document.createElement('a')
861
+ a.href = url
862
+ a.download = runId + '.zip'
863
+ a.click()
864
+ setTimeout(() => URL.revokeObjectURL(url), 1000)
865
+ }
866
+
867
+ function ImageResultPanel({ run, onChanged, onBack }) {
868
+ const result = run.result || {}
869
+ const [busy, setBusy] = useState('')
870
+ const [err, setErr] = useState('')
871
+ const retry = async () => {
872
+ setBusy('retry'); setErr('')
873
+ try { const d = await api('/images/' + run.id + '/retry', { method: 'POST' }); onChanged && onChanged(d.run) } catch (e) { setErr(String(e.message || e)); } finally { setBusy('') }
874
+ }
875
+ const download = () => {
876
+ const url = mediaUrl(result.image)
877
+ if (!url) return
878
+ const a = document.createElement('a')
879
+ a.href = url
880
+ a.download = 'adplus-' + run.id + '.jpg'
881
+ a.click()
882
+ }
883
+ const copy = async () => { try { await navigator.clipboard.writeText(result.prompt || '') } catch (e) { setErr('复制失败:' + String(e.message || e)) } }
884
+ return h('div', { className: 'adp-image-result' },
885
+ h('div', { className: 'adp-result-head' },
886
+ h('button', { className: 'adp-back', onClick: onBack, title: '返回' }, h(Glyph, { name: 'back', size: 15 }), h('span', null, '返回')),
887
+ h('div', { className: 'adp-result-title' }, h('div', { className: 'adp-h1' }, run.title || '图片结果'), h('div', { className: 'adp-small adp-muted' }, '文生图片 · ' + (result.aspect || (run.advanced || {}).aspect || '1:1') + ' · ' + (result.area || (run.advanced || {}).area || '2K'))),
888
+ h('div', { className: 'adp-result-badges' }, h(StatusBadge, { status: run.status }), h(Badge, { status: 'ok' }, '图片'))
889
+ ),
890
+ run.error ? h('div', { className: 'adp-result-error' }, run.error) : null,
891
+ h('div', { className: 'adp-image-grid' },
892
+ h('div', { className: 'adp-image-stage' }, result.image ? h('img', { src: mediaUrl(result.image), alt: result.prompt || 'generated image' }) : h('div', { className: 'adp-empty-stage' }, run.status === 'running' ? '正在生成图片…' : '还没有图片')),
893
+ h('aside', { className: 'adp-result-side' },
894
+ h('div', { className: 'adp-side-block' },
895
+ h('div', { className: 'adp-side-label' }, '图片操作'),
896
+ h('div', { className: 'adp-action-list' },
897
+ h('button', { className: 'adp-action', onClick: retry, disabled: run.status === 'running' || busy === 'retry' }, h(Glyph, { name: 'refresh' }), h('span', null, busy === 'retry' ? '提交中…' : '再生成')),
898
+ h('button', { className: 'adp-action', onClick: download, disabled: !result.image }, h(Glyph, { name: 'download' }), h('span', null, '下载')),
899
+ h('button', { className: 'adp-action', onClick: copy, disabled: !result.prompt }, h(Glyph, { name: 'copy' }), h('span', null, '复制 prompt'))
900
+ )
901
+ ),
902
+ h('div', { className: 'adp-side-block' },
903
+ h('div', { className: 'adp-side-label' }, '图片信息'),
904
+ h('div', { className: 'adp-facts' },
905
+ h('div', { className: 'adp-fact' }, h('span', null, '模型'), h('b', null, result.native_model || result.model || '—')),
906
+ h('div', { className: 'adp-fact' }, h('span', null, '尺寸'), h('b', null, result.width && result.height ? result.width + '×' + result.height : (result.area || '—'))),
907
+ h('div', { className: 'adp-fact' }, h('span', null, '比例'), h('b', null, result.aspect || '—')),
908
+ h('div', { className: 'adp-fact' }, h('span', null, '资产'), h('b', null, result.asset_id || '—'))
909
+ )
910
+ ),
911
+ h('div', { className: 'adp-side-block' },
912
+ h('div', { className: 'adp-side-label' }, 'Prompt'),
913
+ h('div', { className: 'adp-image-prompt' }, result.prompt || (run.inputs && run.inputs.prompt) || '—')
914
+ ),
915
+ err ? h('div', { className: 'adp-result-error' }, err) : null
916
+ )
917
+ )
918
+ )
919
+ }
920
+
921
+ function ResultPanel({ run, onChanged, onBack, assets }) {
922
+ if (run.scenario === 'text-to-image') return h(ImageResultPanel, { run, onChanged, onBack })
923
+ return h(VideoResultPanel, { run, onChanged, onBack, assets })
924
+ }
925
+
926
+ function VideoResultPanel({ run, onChanged, onBack, assets }) {
927
+ const [storyboard, setStoryboard] = useState([])
928
+ const [selected, setSelected] = useState(null)
929
+ const [msg, setMsg] = useState('')
930
+ const [chat, setChat] = useState([])
931
+ const [changes, setChanges] = useState([])
932
+ const [busy, setBusy] = useState('')
933
+ const [err, setErr] = useState('')
934
+ const [editOpen, setEditOpen] = useState(false)
935
+ const adv = run.advanced || {}
936
+ const inputs = run.inputs || {}
937
+ const brief = String(inputs.brief || '').trim()
938
+ const refAsset = (assets || []).find((a) => a.id === inputs.reference_asset_id)
939
+ const productAssets = (inputs.product_asset_ids || []).map((id) => (assets || []).find((a) => a.id === id)).filter(Boolean)
940
+ const persona = adv.persona || {}
941
+ const [edit, setEdit] = useState({ aspect: adv.aspect || '9:16', resolution: adv.resolution || '720p', duration: adv.duration || 12 })
942
+ const result = run.result || {}
943
+ const video = result.video ? mediaUrlVersion(result.video, run.version) : ''
944
+ const qa = result.qa
945
+ const postOnly = changes.length > 0 && changes.every((c) => c.stage === 'post')
946
+ const running = run.status === 'running' || run.status === 'queued'
947
+ const editDirty = edit.aspect !== (adv.aspect || '9:16') || edit.resolution !== (adv.resolution || '720p') || Number(edit.duration) !== Number(adv.duration || 12)
948
+ const hasEdits = (run.segment_edits || []).length > 0
949
+
950
+ useEffect(() => {
951
+ setStoryboard([]); setSelected(null); setChat([]); setChanges([]); setBusy(''); setErr(''); setEditOpen(false)
952
+ setEdit({ aspect: adv.aspect || '9:16', resolution: adv.resolution || '720p', duration: adv.duration || 12 })
953
+ }, [run.id])
954
+
955
+ const loadSb = useCallback(async () => {
956
+ setBusy('sb'); setErr('')
957
+ try {
958
+ const data = await api('/runs/' + run.id + '/storyboard')
959
+ setStoryboard(data.segments || [])
960
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
961
+ }, [run.id])
962
+
963
+ useEffect(() => { if (run.status === 'succeeded') void loadSb() }, [run.status, loadSb])
964
+
965
+ const openEdit = () => {
966
+ setEdit({ aspect: adv.aspect || '9:16', resolution: adv.resolution || '720p', duration: adv.duration || 12 })
967
+ setEditOpen(true)
968
+ }
969
+
970
+ const applyEdit = async () => {
971
+ if (!editDirty) return
972
+ setBusy('edit'); setErr('')
973
+ try {
974
+ const list = []
975
+ if (edit.aspect !== (adv.aspect || '9:16')) list.push({ field: 'advanced.aspect', from: adv.aspect, to: edit.aspect, stage: 'generate', requires_regeneration: true, label: '比例' })
976
+ if (edit.resolution !== (adv.resolution || '720p')) list.push({ field: 'advanced.resolution', from: adv.resolution, to: edit.resolution, stage: 'generate', requires_regeneration: true, label: '清晰度' })
977
+ if (Number(edit.duration) !== Number(adv.duration || 12)) list.push({ field: 'advanced.duration', from: adv.duration, to: Number(edit.duration), stage: 'generate', requires_regeneration: true, label: '时长(秒)' })
978
+ const data = await api('/runs/' + run.id + '/derive', { method: 'POST', body: { changes: list } })
979
+ setEditOpen(false)
980
+ onChanged && onChanged(data.run)
981
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
982
+ }
983
+
984
+ const selectSegment = (seg) => {
985
+ if (selected && selected.id === seg.id) { setSelected(null); return }
986
+ setSelected(seg); setChat([]); setChanges([]); setMsg(''); setErr('')
987
+ }
988
+
989
+ const send = async () => {
990
+ if (!msg.trim() || !selected) return
991
+ const text = msg.trim(); setMsg(''); setChat((prev) => prev.concat([{ role: 'user', text }])); setBusy('chat'); setErr('')
992
+ try {
993
+ const data = await api('/assistant', { method: 'POST', body: {
994
+ message: text,
995
+ selected_segment_id: selected.id,
996
+ context: { advanced: adv, persona: adv.persona || {}, post: adv, brief: (run.inputs && run.inputs.brief) || '' },
997
+ } })
998
+ setChat((prev) => prev.concat([{ role: 'assistant', text: data.reply || '已整理变更。' }]))
999
+ setChanges(data.changes || [])
1000
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1001
+ }
1002
+
1003
+ const applyChanges = async () => {
1004
+ if (!changes.length) return
1005
+ setBusy('apply'); setErr('')
1006
+ try {
1007
+ const path = selected && !postOnly
1008
+ ? '/runs/' + run.id + '/segments/' + selected.id + '/replace'
1009
+ : '/runs/' + run.id + '/derive'
1010
+ const data = await api(path, { method: 'POST', body: { changes } })
1011
+ setChanges([]); setChat([])
1012
+ onChanged && onChanged(data.run)
1013
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1014
+ }
1015
+
1016
+ const retry = async () => {
1017
+ setBusy('retry'); setErr('')
1018
+ try { const d = await api('/runs/' + run.id + '/retry', { method: 'POST' }); onChanged && onChanged(d.run) } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1019
+ }
1020
+ const cancel = async () => {
1021
+ try { const d = await api('/runs/' + run.id + '/cancel', { method: 'POST' }); onChanged && onChanged(d.run) } catch (e) { setErr(String(e.message || e)) }
1022
+ }
1023
+ const rollback = async () => {
1024
+ setBusy('rollback'); setErr('')
1025
+ try { const d = await api('/runs/' + run.id + '/rollback', { method: 'POST' }); onChanged && onChanged(d.run) } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1026
+ }
1027
+ const download = async () => {
1028
+ setBusy('download'); setErr('')
1029
+ try { await downloadExport(run.id) } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1030
+ }
1031
+
1032
+ const aspectOptions = Array.from(new Set(['9:16', '16:9', '1:1', '4:3', '3:4', '21:9', adv.aspect].filter(Boolean)))
1033
+ const resolutionOptions = Array.from(new Set(['480p', '720p', '1080p', adv.resolution].filter(Boolean)))
1034
+ const durationOptions = Array.from(new Set([4, 5, 6, 8, 10, 12, 15, 30, Number(adv.duration || 12)])).sort((a, b) => a - b)
1035
+ const copyBrief = async () => {
1036
+ try { await navigator.clipboard.writeText(brief) } catch (e) { setErr('复制失败:' + String(e.message || e)) }
1037
+ }
1038
+
1039
+ const facts = [
1040
+ ['版本', 'v' + (run.version || 1)],
1041
+ ['画幅', adv.aspect || '9:16'],
1042
+ ['清晰度', adv.resolution || '720p'],
1043
+ ['时长', result.duration_s ? fmt(result.duration_s) : (adv.duration ? adv.duration + 's' : '—')],
1044
+ ['模型', result.model || adv.model || 'auto'],
1045
+ ]
1046
+ const qaPass = (qa && qa.summary && qa.summary.pass) || 0
1047
+ const qaTotal = (qa && qa.checks && qa.checks.length) || 0
1048
+
1049
+ return h('div', { className: 'adp-result' },
1050
+ h('div', { className: 'adp-result-head' },
1051
+ h('button', { className: 'adp-back', onClick: onBack, title: '返回' }, h(Glyph, { name: 'back', size: 15 }), h('span', null, '返回')),
1052
+ h('div', { className: 'adp-result-title' },
1053
+ h('div', { className: 'adp-h1' }, run.title || '成片'),
1054
+ h('div', { className: 'adp-small adp-muted' }, 'v' + (run.version || 1) + ' · ' + (adv.aspect || '9:16') + ' · ' + (adv.resolution || '720p') + (result.duration_s ? ' · ' + fmt(result.duration_s) : ''))
1055
+ ),
1056
+ h('div', { className: 'adp-result-badges' }, h(StatusBadge, { status: run.status }))
1057
+ ),
1058
+ run.error ? h('div', { className: 'adp-error' }, run.error) : null,
1059
+ h('div', { className: 'adp-result-grid' },
1060
+ h('div', { className: 'adp-stage' },
1061
+ video ? h('video', { className: 'adp-stage-video', src: video, controls: true, playsInline: true, poster: storyboard[0] && storyboard[0].thumbnail ? mediaUrlVersion(storyboard[0].thumbnail, run.version) : undefined }) : h('div', { className: 'adp-empty-stage' }, running ? '正在生成…' : '还没有可播放的成片'),
1062
+ running ? h('div', { className: 'adp-stage-progress' }, h('div', { className: 'adp-progress' }, h('i', { style: { width: Math.round((run.progress || 0) * 100) + '%' } })), h('span', null, '生成中 · ' + Math.round((run.progress || 0) * 100) + '%')) : null
1063
+ ),
1064
+ h('aside', { className: 'adp-result-side' },
1065
+ h('div', { className: 'adp-side-block' },
1066
+ h('div', { className: 'adp-side-label' }, '成片操作'),
1067
+ h('div', { className: 'adp-action-list' },
1068
+ h('button', { className: 'adp-action', onClick: openEdit, disabled: running || !video, title: '调整比例、清晰度或时长,生成新版本' }, h(Glyph, { name: 'edit' }), h('span', null, '修改参数')),
1069
+ h('button', { className: 'adp-action', onClick: retry, disabled: running || busy === 'retry', title: '保持当前参数,再生成一条' }, h(Glyph, { name: 'refresh' }), h('span', null, busy === 'retry' ? '提交中…' : '再生成')),
1070
+ h('button', { className: 'adp-action', onClick: download, disabled: !video || busy === 'download', title: '下载成片与字幕压缩包' }, h(Glyph, { name: 'download' }), h('span', null, busy === 'download' ? '打包中…' : '下载')),
1071
+ hasEdits ? h('button', { className: 'adp-action', onClick: rollback, disabled: running || busy === 'rollback', title: '回滚上一次分镜替换' }, h(Glyph, { name: 'undo' }), h('span', null, busy === 'rollback' ? '回滚中…' : '回滚上一镜')) : null,
1072
+ running ? h('button', { className: 'adp-action danger', onClick: cancel }, h(Glyph, { name: 'close' }), h('span', null, '取消生成')) : null
1073
+ ),
1074
+ h('div', { className: 'adp-side-note' }, '「再生成」保设置换一条;「修改参数」改设置生成新版本;单镜编辑只重做该镜并可直接回滚。')
1075
+ ),
1076
+ h('div', { className: 'adp-side-block' },
1077
+ h('div', { className: 'adp-side-label' }, '成片信息'),
1078
+ h('div', { className: 'adp-facts' }, facts.map((f) => h('div', { key: f[0], className: 'adp-fact' }, h('span', null, f[0]), h('b', null, f[1]))))
1079
+ ),
1080
+ qa ? h('div', { className: 'adp-side-block' },
1081
+ h('div', { className: 'adp-side-label' }, '质量检查'),
1082
+ h('div', { className: 'adp-qa' },
1083
+ h(Badge, { status: (qa.summary && qa.summary.fail) ? 'bad' : 'ok' }, qaPass + '/' + qaTotal),
1084
+ h('span', { className: 'adp-small adp-muted' }, (qa.summary && qa.summary.shippable) ? '可交付' : '需要复核')
1085
+ ),
1086
+ (qa.checks || []).filter((c) => c.status !== 'pass').map((c) => h('div', { key: c.id, className: 'adp-qa-note' }, c.label + ':' + c.status + (c.note ? ' · ' + c.note : '')))
1087
+ ) : null,
1088
+ result.post_notes && result.post_notes.length ? h('div', { className: 'adp-side-block' }, h('div', { className: 'adp-side-label' }, '后期说明'), h('div', { className: 'adp-side-note' }, result.post_notes.join(' · '))) : null
1089
+ )
1090
+ ),
1091
+ h('section', { className: 'adp-inputs' },
1092
+ h('div', { className: 'adp-inputs-head' },
1093
+ h('div', { className: 'adp-h2' }, '创作输入'),
1094
+ h('span', { className: 'adp-storyboard-meta' }, '保留原始需求,方便复现和追溯')
1095
+ ),
1096
+ h('div', { className: 'adp-inputs-grid' },
1097
+ h('div', { className: 'adp-input-brief' },
1098
+ h('div', { className: 'adp-input-label' }, '原始需求'),
1099
+ h('div', { className: 'adp-brief-text' }, brief || '未填写'),
1100
+ brief ? h('button', { className: 'adp-copy', onClick: copyBrief, title: '复制原始需求' }, h(Glyph, { name: 'copy' }), h('span', null, '复制')) : null
1101
+ ),
1102
+ h('div', { className: 'adp-input-assets' },
1103
+ h('div', { className: 'adp-input-label' }, '素材与人物'),
1104
+ refAsset ? h('div', { className: 'adp-asset-line' },
1105
+ h('span', { className: 'adp-asset-tag' }, '参考视频'),
1106
+ h('span', { className: 'adp-asset-name', title: refAsset.name }, refAsset.name || refAsset.id)
1107
+ ) : h('div', { className: 'adp-small adp-muted' }, '无参考视频'),
1108
+ productAssets.length ? h('div', { className: 'adp-asset-line' },
1109
+ h('span', { className: 'adp-asset-tag' }, '商品图'),
1110
+ h('div', { className: 'adp-asset-thumbs' }, productAssets.map((a) => h('span', { key: a.id, className: 'adp-asset-thumb', title: a.name }, h('img', { src: mediaUrl(a.path), alt: '' })))),
1111
+ h('span', { className: 'adp-small adp-muted' }, productAssets.length + ' 张')
1112
+ ) : h('div', { className: 'adp-small adp-muted' }, '无商品图'),
1113
+ h('div', { className: 'adp-asset-line' },
1114
+ h('span', { className: 'adp-asset-tag' }, '模特'),
1115
+ h('span', { className: 'adp-small adp-muted' }, [persona.gender, persona.age, persona.body_type, persona.ethnicity].filter(Boolean).join(' · ') || '未指定')
1116
+ )
1117
+ )
1118
+ )
1119
+ ),
1120
+ h('section', { className: 'adp-storyboard' },
1121
+ h('div', { className: 'adp-storyboard-head' },
1122
+ h('div', { className: 'adp-h2' }, '分镜'),
1123
+ h('span', { className: 'adp-storyboard-meta' }, storyboard.length ? storyboard.length + ' 段 · ' + (run.generation_mode === 'fine' ? '精细模式' : '快速模式') : (busy === 'sb' ? '读取中…' : '还没有分镜'))
1124
+ ),
1125
+ storyboard.length ? storyboard.map((seg) => h('div', { key: seg.id, className: 'adp-shot' + (selected && selected.id === seg.id ? ' open' : '') },
1126
+ h('div', { className: 'adp-shot-thumb' },
1127
+ h('div', { className: 'adp-shot-placeholder' }),
1128
+ seg.thumbnail ? h('img', { src: mediaUrlVersion(seg.thumbnail, run.version), alt: '', onError: (e) => { e.currentTarget.style.display = 'none' } }) : null,
1129
+ h('span', { className: 'adp-shot-index' }, '#' + (seg.index + 1))
1130
+ ),
1131
+ h('div', { className: 'adp-shot-body' },
1132
+ h('div', { className: 'adp-shot-top' },
1133
+ h('b', null, seg.function || '镜头'),
1134
+ h('span', { className: 'adp-shot-time' }, fmtAt(seg.start_s) + '–' + fmtAt(seg.end_s)),
1135
+ h('span', { className: 'adp-shot-time' }, fmtAt(seg.end_s - seg.start_s))
1136
+ ),
1137
+ h('div', { className: 'adp-shot-dialogue' }, seg.dialogue || '—'),
1138
+ seg.action ? h('div', { className: 'adp-shot-action' }, seg.action) : null
1139
+ ),
1140
+ h('button', { className: 'adp-shot-edit', onClick: () => selectSegment(seg), 'aria-expanded': selected && selected.id === seg.id, title: '编辑这一镜' }, h(Glyph, { name: 'edit' }), h('span', null, selected && selected.id === seg.id ? '收起' : '编辑')),
1141
+ selected && selected.id === seg.id ? h('div', { className: 'adp-shot-editor' },
1142
+ h('div', { className: 'adp-shot-editor-head' }, '分镜助手 · #' + (seg.index + 1) + ' · ' + fmtAt(seg.start_s) + '–' + fmtAt(seg.end_s)),
1143
+ chat.length ? h('div', { className: 'adp-chat' }, chat.map((m, i) => h('div', { key: i, className: 'adp-msg ' + (m.role === 'user' ? 'user' : '') }, m.text))) : h('div', { className: 'adp-small adp-muted' }, '直接说这一镜要改什么,例如:人物更近、把价格说出来、结尾加抢购动作。'),
1144
+ changes.length ? h('div', { className: 'adp-col' }, changes.map((c, i) => h('div', { key: i, className: 'adp-change' }, (c.label || c.field) + ':' + JSON.stringify(c.from) + ' → ' + JSON.stringify(c.to) + (c.stage === 'generate' ? ' · 需要重生成' : ' · 后期')))) : null,
1145
+ h('div', { className: 'adp-row adp-shot-chat-row' },
1146
+ h('input', { className: 'adp-input adp-grow', value: msg, placeholder: '这一镜改成…', onChange: (e) => setMsg(e.currentTarget.value), onKeyDown: (e) => { if (e.key === 'Enter') send() } }),
1147
+ h('button', { className: 'adp-btn primary', onClick: send, disabled: busy === 'chat' }, '发送'),
1148
+ changes.length ? h('button', { className: 'adp-btn', onClick: applyChanges, disabled: busy === 'apply' }, postOnly ? '只应用后期修改' : '应用到这一镜') : null
1149
+ )
1150
+ ) : null
1151
+ )) : h('div', { className: 'adp-empty-shots' },
1152
+ h('span', null, busy === 'sb' ? '正在读取分镜…' : '还没有分镜数据。'),
1153
+ !busy ? h('button', { className: 'adp-btn ghost', onClick: loadSb }, '重新读取') : null
1154
+ )
1155
+ ),
1156
+ err ? h('div', { className: 'adp-result-error' }, err) : null,
1157
+ editOpen ? h('div', { className: 'adp-drawer-backdrop', onClick: () => setEditOpen(false) },
1158
+ h('div', { className: 'adp-drawer', role: 'dialog', 'aria-modal': 'true', 'aria-label': '修改生成参数', onClick: (e) => e.stopPropagation() },
1159
+ h('div', { className: 'adp-drawer-head' },
1160
+ h('div', null, h('div', { className: 'adp-h2' }, '修改生成参数'), h('div', { className: 'adp-small adp-muted' }, '只改生成设置,生成一个新版本。')),
1161
+ h('button', { className: 'adp-icon-btn', onClick: () => setEditOpen(false), title: '关闭' }, h(Glyph, { name: 'close' }))
1162
+ ),
1163
+ h('div', { className: 'adp-drawer-body' },
1164
+ h(Field, { label: '比例' }, h('select', { className: 'adp-select', value: edit.aspect, onChange: (e) => setEdit(Object.assign({}, edit, { aspect: e.currentTarget.value })) }, aspectOptions.map((x) => h('option', { key: x, value: x }, x)))),
1165
+ h(Field, { label: '清晰度' }, h('select', { className: 'adp-select', value: edit.resolution, onChange: (e) => setEdit(Object.assign({}, edit, { resolution: e.currentTarget.value })) }, resolutionOptions.map((x) => h('option', { key: x, value: x }, x)))),
1166
+ h(Field, { label: '时长(秒)' }, h('select', { className: 'adp-select', value: edit.duration, onChange: (e) => setEdit(Object.assign({}, edit, { duration: Number(e.currentTarget.value) })) }, durationOptions.map((x) => h('option', { key: x, value: x }, x + 's')))),
1167
+ h('div', { className: 'adp-side-note' }, editDirty ? '参数已修改,应用后会生成新版本。' : '参数没有变化,按钮不可用。')
1168
+ ),
1169
+ h('div', { className: 'adp-drawer-foot' },
1170
+ h('button', { className: 'adp-btn ghost', onClick: () => setEditOpen(false) }, '取消'),
1171
+ h('button', { className: 'adp-btn primary', onClick: applyEdit, disabled: !editDirty || busy === 'edit', title: editDirty ? '应用修改并生成新版本' : '参数没有变化' }, busy === 'edit' ? '提交中…' : '应用并重生成')
1172
+ )
1173
+ )
1174
+ ) : null
1175
+ )
1176
+ }
1177
+
1178
+ function RecreateTab({ models, dsh, onStarted, personas, onRefreshPersonas }) {
1179
+ const [refAsset, setRefAsset] = useState(null)
1180
+ const [products, setProducts] = useState([])
1181
+ const [brief, setBrief] = useState('')
1182
+ const [textModel, setTextModel] = useState(null)
1183
+ const [advanced, setAdvanced] = useState({ generation_mode: 'fast', duration: 12, aspect: '9:16', resolution: '720p', model: '' })
1184
+ const [touched, setTouched] = useState({})
1185
+ const [detected, setDetected] = useState(() => Object.assign(detectVideoParams(''), { stitch: false }))
1186
+ const [persona, setPersona] = useState({ gender: 'any', age: 'youth', body_type: 'standard', ethnicity: 'asian' })
1187
+ const [personaEnabled, setPersonaEnabled] = useState(false)
1188
+ const [personaId, setPersonaId] = useState('')
1189
+ const [busy, setBusy] = useState(false)
1190
+ const [personaBusy, setPersonaBusy] = useState(false)
1191
+ const [polishBusy, setPolishBusy] = useState(false)
1192
+ const [err, setErr] = useState('')
1193
+ const usableModels = (models || []).filter((m) => m.available && m.enabled !== false)
1194
+ const hasRealModel = usableModels.length > 0
1195
+ const selectedModel = (models || []).find((m) => m.id === advanced.model)
1196
+ const imageOnly = Boolean(selectedModel && !(selectedModel.capabilities || []).includes('text_to_video'))
1197
+ useEffect(() => {
1198
+ setAdvanced((prev) => {
1199
+ const usable = (models || []).filter((m) => m.available && m.enabled !== false)
1200
+ if (prev.model && usable.some((m) => m.id === prev.model)) return prev
1201
+ const pick = defaultModelId(models, true)
1202
+ return pick ? Object.assign({}, prev, { model: pick }) : prev
1203
+ })
1204
+ }, [models])
1205
+ const selectedTextModel = textModel || defaultDshTextModel(dsh)
1206
+ const selectedPersona = (personas || []).find((p) => p.id === personaId)
1207
+ const dshReady = Boolean(dsh && dsh.available && (dsh.providers || []).length)
1208
+ useEffect(() => { setDetected(Object.assign(detectVideoParams(brief), { stitch: /(拼接|拼起来|拼成|接起来|接到一起|合并|组合|连起来|插入|顺序拼|前后拼)/.test(brief) })) }, [brief])
1209
+ const changeAdvanced = (next) => {
1210
+ const changed = {}
1211
+ for (const key of ['aspect', 'duration', 'resolution', 'generation_mode', 'subtitle']) {
1212
+ if (next[key] !== advanced[key]) changed[key] = true
1213
+ }
1214
+ if (Object.keys(changed).length) setTouched((prev) => Object.assign({}, prev, changed))
1215
+ setAdvanced(next)
1216
+ }
1217
+ // The brief wins: every parameter it names replaces the control value, and
1218
+ // the list below says exactly what will change before the run starts.
1219
+ const overrides = []
1220
+ if (detected.aspect && detected.aspect !== advanced.aspect) overrides.push('比例 ' + detected.aspect + '(控件 ' + advanced.aspect + ')')
1221
+ if (detected.duration && Number(detected.duration) !== Number(advanced.duration)) overrides.push('时长 ' + detected.duration + 's(控件 ' + advanced.duration + 's)')
1222
+ if (detected.resolution && detected.resolution !== advanced.resolution) overrides.push('清晰度 ' + detected.resolution + '(控件 ' + advanced.resolution + ')')
1223
+ if (detected.mode && detected.mode !== advanced.generation_mode) overrides.push('模式 精细(控件 快速)')
1224
+ if (detected.subtitle && detected.subtitle !== (advanced.subtitle || 'off')) overrides.push('字幕 ' + subtitleLabel(detected.subtitle) + '(控件 ' + subtitleLabel(advanced.subtitle) + ')')
1225
+ const savePersona = async () => {
1226
+ setPersonaBusy(true); setErr('')
1227
+ try {
1228
+ const created = await api('/personas', { method: 'POST', body: Object.assign({ name: '模特 ' + ((personas || []).length + 1), type: 'ai', consent: { confirmed: true, note: '运营创建' } }, persona) })
1229
+ setPersonaId(created.persona.id)
1230
+ onRefreshPersonas && await onRefreshPersonas()
1231
+ } catch (e) { setErr(String(e.message || e)) } finally { setPersonaBusy(false) }
1232
+ }
1233
+ const start = async () => {
1234
+ if (!refAsset) { setErr('请先上传参考视频'); return }
1235
+ if (imageOnly && !products.length) { setErr('当前模型是图生视频,请先上传至少一张商品图'); return }
1236
+ setBusy(true); setErr('')
1237
+ try {
1238
+ let smart = null
1239
+ try { smart = await parseIntentWithDsh(brief, selectedTextModel) } catch { smart = null }
1240
+ const next = Object.assign(detectVideoParams(brief))
1241
+ if (smart) {
1242
+ if (smart.aspect) next.aspect = smart.aspect
1243
+ if (smart.duration) next.duration = smart.duration
1244
+ if (smart.resolution) next.resolution = smart.resolution
1245
+ if (smart.mode) next.mode = smart.mode
1246
+ if (smart.subtitle) next.subtitle = smart.subtitle
1247
+ if (smart.vendor) next.vendor = smart.vendor
1248
+ }
1249
+ setDetected(next)
1250
+ const merged = Object.assign({}, advanced)
1251
+ if (next.aspect) merged.aspect = next.aspect
1252
+ if (next.duration) merged.duration = next.duration
1253
+ if (next.resolution) merged.resolution = next.resolution
1254
+ if (next.mode) merged.generation_mode = next.mode
1255
+ if (next.subtitle) merged.subtitle = next.subtitle
1256
+ const vendorModel = modelForVendor(next.vendor, models)
1257
+ if (vendorModel) merged.model = vendorModel
1258
+ if (selectedTextModel) merged.text_model = selectedTextModel
1259
+ const personaPayload = personaEnabled ? { persona, persona_map: personaId ? { A: personaId, B: personaId } : {} } : {}
1260
+ const data = await api('/runs', { method: 'POST', body: {
1261
+ scenario: 'viral-remake',
1262
+ inputs: { reference_asset_id: refAsset.id, product_asset_ids: products.map(p => p.id), brief },
1263
+ advanced: Object.assign({}, merged, personaPayload),
1264
+ } })
1265
+ onStarted(data.run)
1266
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
1267
+ }
1268
+ const polish = async () => {
1269
+ if (!brief.trim()) { setErr('先写一点需求,再让 DSH 模型润色'); return }
1270
+ setPolishBusy(true); setErr('')
1271
+ try {
1272
+ const data = await api('/dsh/chat', { method: 'POST', body: {
1273
+ system: '你是广告视频导演。把运营的需求改写成更清楚的中文创作要求,保留价格、卖点、产品和修改意图;只输出改写后的需求文本,不要解释,不要加引号。',
1274
+ messages: [{ role: 'user', content: [{ type: 'text', text: brief }] }],
1275
+ maxTokens: 600,
1276
+ provider: selectedTextModel && selectedTextModel.provider,
1277
+ model: selectedTextModel && selectedTextModel.model,
1278
+ } })
1279
+ const text = data.dsh && data.dsh.text
1280
+ if (text) setBrief(String(text).trim().slice(0, 2000))
1281
+ else setErr('DSH 模型没有返回文本')
1282
+ } catch (e) { setErr('DSH 模型暂不可用:' + String(e.message || e)) } finally { setPolishBusy(false) }
1283
+ }
1284
+ return h('div', { className: 'adp-page' },
1285
+ h('div', { className: 'adp-page-head' },
1286
+ h('div', null,
1287
+ h('div', { className: 'adp-eyebrow' }, 'SCENE 01 / VIRAL REMAKE'),
1288
+ h('h1', { className: 'adp-title' }, '爆款复刻'),
1289
+ h('p', { className: 'adp-lede' }, '把一条已验证的片子拆成结构和梗,换成你的商品、人物和台词。先给素材,再写要求,剩下的交给后台。')
1290
+ ),
1291
+ h('div', { className: 'adp-page-meta' },
1292
+ h(Badge, { status: hasRealModel ? 'ok' : 'bad' }, hasRealModel ? '模型已就绪' : '未配置模型'),
1293
+ h('span', null, '≤30s 参考片')
1294
+ )
1295
+ ),
1296
+ h('div', { className: 'adp-panel' },
1297
+ h('div', { className: 'adp-panel-grid' },
1298
+ h('section', { className: 'adp-asset-col' },
1299
+ h('div', { className: 'adp-section-head' },
1300
+ h('span', { className: 'adp-step' }, '01'),
1301
+ h('span', { className: 'adp-section-title' }, '素材'),
1302
+ h('span', { className: 'adp-section-note' }, '参考片决定结构')
1303
+ ),
1304
+ h('div', { className: 'adp-label' }, h('span', null, '参考视频'), h('span', { className: 'count' }, '必填')),
1305
+ h(DropVideo, { asset: refAsset, onAsset: setRefAsset }),
1306
+ h('div', { className: 'adp-label', style: { marginTop: 16 } },
1307
+ h('span', null, '商品图'),
1308
+ h('span', { className: 'count' }, (products.length || 0) + ' / 9')
1309
+ ),
1310
+ h(MediaGrid, { assets: products, onAdd: (list) => setProducts(prev => prev.concat(list).slice(0, 9)), onRemove: (id) => setProducts(prev => prev.filter(x => x.id !== id)) }),
1311
+ h('div', { className: 'adp-hint' }, '可上传多张:正面、包装、细节、使用场景。第一张会作为主商品参考。'),
1312
+ h('div', { className: 'adp-asset-foot' },
1313
+ h('b', null, '素材建议'),
1314
+ h('div', null, '参考片:一条完整片子,不要混剪。'),
1315
+ h('div', null, '商品图:正面 + 包装 + 细节;没有图也可以先用文字描述。')
1316
+ )
1317
+ ),
1318
+ h('section', { className: 'adp-form-col' },
1319
+ h('div', { className: 'adp-section-head' },
1320
+ h('span', { className: 'adp-step' }, '02'),
1321
+ h('span', { className: 'adp-section-title' }, '创作需求'),
1322
+ h('span', { className: 'adp-section-note' }, '不用写 prompt')
1323
+ ),
1324
+ h('div', { className: 'adp-brief' },
1325
+ h('div', { className: 'adp-brief-head' },
1326
+ h('b', null, '需求描述'),
1327
+ h('span', null, brief.length + ' / 2000')
1328
+ ),
1329
+ h('textarea', {
1330
+ className: 'adp-brief-input', value: brief, maxLength: 2000, rows: 4,
1331
+ placeholder: '例如:产品活动价 19.9,卖点是不油腻、追剧零食;保留原片的比价和抢购动作,台词更生活化。',
1332
+ onChange: (e) => setBrief(e.currentTarget.value),
1333
+ onKeyDown: (e) => { if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') { e.preventDefault(); start() } }
1334
+ }),
1335
+ h('div', { className: 'adp-brief-foot' },
1336
+ h('span', null, '写产品、卖点、价格、想保留/想改的地方。'),
1337
+ h('div', { className: 'adp-row', style: { gap: 8 } },
1338
+ h(TextModelSelect, { dsh, value: selectedTextModel, onChange: setTextModel }),
1339
+ dshReady ? h('button', { className: 'adp-btn', onClick: polish, disabled: polishBusy, title: '用 DSH 已配置模型润色需求' }, polishBusy ? '润色中…' : 'DSH 润色') : null,
1340
+ h('span', { className: 'adp-key' }, '⌘ ↵ 开始')
1341
+ )
1342
+ )
1343
+ ),
1344
+ h('div', { className: 'adp-section-head' },
1345
+ h('span', { className: 'adp-step' }, '03'),
1346
+ h('span', { className: 'adp-section-title' }, '生成设置')
1347
+ ),
1348
+ h(AdvancedRow, { value: advanced, onChange: changeAdvanced, models, needsDialogue: true }),
1349
+ imageOnly ? h('div', { className: 'adp-hint' }, '当前模型是图生视频:需要至少一张商品图;无原生音频。') : null,
1350
+ overrides.length ? h('div', { className: 'adp-conflict', style: { margin: '7px 0 0' } }, h('b', null, '描述优先'), overrides.join(';')) : null,
1351
+ h('div', { className: 'adp-section-head' },
1352
+ h('span', { className: 'adp-step' }, '04'),
1353
+ h('span', { className: 'adp-section-title' }, '模特'),
1354
+ h('span', { className: 'adp-section-note' }, '先定人,再定片')
1355
+ ),
1356
+ h('div', { className: 'adp-persona-inline' },
1357
+ h('label', { className: 'adp-check', style: { marginTop: 0 } },
1358
+ h('input', { type: 'checkbox', checked: personaEnabled, onChange: (e) => { const on = e.currentTarget.checked; setPersonaEnabled(on); if (!on) setPersonaId('') } }),
1359
+ '本次使用模特设定'
1360
+ ),
1361
+ h('div', { className: 'adp-persona-status' },
1362
+ h(Badge, { status: personaEnabled ? (personaId ? 'ok' : '') : '' }, personaEnabled ? (personaId ? '已选:' + (selectedPersona ? selectedPersona.name : '已保存模特') : '本次自定义') : '本次不使用模特'),
1363
+ h('span', { className: 'adp-small adp-muted' }, personaEnabled ? (personaId ? '下方字段已带入;修改任意字段会切换为本次自定义,不会改动已保存模特。' : '以下字段只影响本次生成,不会修改模特库。') : '原片没有人物、或不需要改人物时保持关闭;不会把模特写进生成要求。')
1364
+ ),
1365
+ h('div', { className: personaEnabled ? '' : 'adp-persona-off' },
1366
+ h('div', { className: 'adp-persona-source' },
1367
+ h('div', { className: 'adp-field-label' }, '已保存模特(可选)'),
1368
+ h('select', { className: 'adp-select', value: personaId, disabled: !personaEnabled, onChange: (e) => {
1369
+ const id = e.currentTarget.value
1370
+ setPersonaId(id)
1371
+ const found = (personas || []).find(p => p.id === id)
1372
+ if (found) { setPersona({ gender: found.gender || 'any', age: found.age || 'youth', body_type: found.body_type || 'standard', ethnicity: found.ethnicity || 'asian' }); setPersonaEnabled(true) }
1373
+ } },
1374
+ h('option', { value: '' }, '本次自定义'),
1375
+ (personas || []).map(p => h('option', { key: p.id, value: p.id }, p.name + ' · ' + (p.gender === 'female' ? '女' : p.gender === 'male' ? '男' : '不限') + ' · ' + (p.age || '')))
1376
+ )
1377
+ ),
1378
+ h(PersonaFields, { value: persona, onChange: (v) => { setPersonaId(''); setPersona(v) } })
1379
+ ),
1380
+ h('div', { className: 'adp-persona-actions' },
1381
+ h('button', { className: 'adp-btn ghost', onClick: savePersona, disabled: !personaEnabled || personaBusy }, personaBusy ? '保存中…' : (personaId ? '另存为副本' : '另存为模特')),
1382
+ h('span', { className: 'adp-hint' }, personaEnabled ? (personaId ? '不会覆盖当前选中的已保存模特' : '保存后可在模特库复用') : '关闭时不会影响原片人物或生成 prompt')
1383
+ )
1384
+ ),
1385
+ h('div', { className: 'adp-actionbar' },
1386
+ h('div', { className: 'adp-action-note' },
1387
+ !refAsset ? h('span', { style: { color: '#C99B54' } }, '先上传参考视频。') : (hasRealModel ? '将使用已配置的模型;生成通常需要几分钟。' : '还没有可用的视频模型,先去「设置」里配置厂商 key。'),
1388
+ h('br'),
1389
+ '开始后可在结果页看分镜、派生新版本或拼接。'
1390
+ ),
1391
+ h('div', { className: 'adp-grow' }),
1392
+ h('button', { className: 'adp-primary', onClick: start, disabled: busy || !refAsset },
1393
+ busy ? '正在启动…' : '开始复刻',
1394
+ h('span', { className: 'arrow' }, '→')
1395
+ )
1396
+ ),
1397
+ err ? h('div', { className: 'adp-error', style: { marginTop: 10 } }, err) : null
1398
+ )
1399
+ )
1400
+ ),
1401
+ h('div', { className: 'adp-examples' },
1402
+ h('div', { className: 'adp-section-head' },
1403
+ h('span', { className: 'adp-step' }, '05'),
1404
+ h('span', { className: 'adp-section-title' }, '示例'),
1405
+ h('span', { className: 'adp-section-note' }, '点一下套用需求')
1406
+ ),
1407
+ h('div', { className: 'adp-example-grid' },
1408
+ [
1409
+ { tag: 'PRICE', title: '价格反差', text: '先报高价,再翻活动价', brief: '保留原片的比价、贬损和抢购结构;产品活动价 19.9,卖点是不油腻、追剧零食,台词更生活化。' },
1410
+ { tag: 'TALK', title: '口播测评', text: '一个人讲三个卖点', brief: '一个人对着镜头讲三个卖点:口感、价格、使用场景;保留原片的节奏和结尾行动号召,不要夸张功效。' },
1411
+ { tag: 'UNBOX', title: '开箱展示', text: '手部特写 + 商品细节', brief: '用开箱动作展示包装、分量和细节;中近景为主,最后把商品举到镜头前,台词简短。' },
1412
+ ].map((ex) => h('button', { key: ex.tag, className: 'adp-example', onClick: () => setBrief(ex.brief) },
1413
+ h('span', { className: 'tag' }, ex.tag),
1414
+ h('b', null, ex.title),
1415
+ h('span', null, ex.text)
1416
+ ))
1417
+ )
1418
+ )
1419
+ )
1420
+ }
1421
+
1422
+ function TextTab({ models, dsh, imageModels, onStarted, assets, onRefreshAssets }) {
1423
+ const [brief, setBrief] = useState('')
1424
+ const [mode, setMode] = useState('video')
1425
+ const [textModel, setTextModel] = useState(null)
1426
+ const [files, setFiles] = useState([])
1427
+ const [advanced, setAdvanced] = useState({ generation_mode: 'fast', duration: 8, aspect: '9:16', resolution: '720p', model: '' })
1428
+ const [showAdvanced, setShowAdvanced] = useState(false)
1429
+ const [touched, setTouched] = useState({})
1430
+ const [busy, setBusy] = useState(false)
1431
+ const [err, setErr] = useState('')
1432
+ const input = useRef(null)
1433
+ const [detected, setDetected] = useState(() => Object.assign(detectVideoParams(''), { stitch: false }))
1434
+ useEffect(() => { setDetected(Object.assign(detectVideoParams(brief), { stitch: /(拼接|拼起来|拼成|接起来|接到一起|合并|组合|连起来|插入|顺序拼|前后拼)/.test(brief) })) }, [brief])
1435
+ const images = files.filter((f) => f.kind === 'image')
1436
+ const videos = files.filter((f) => f.kind === 'video')
1437
+ const selectedTextModel = textModel || defaultDshTextModel(dsh)
1438
+ const stitchIntent = Boolean(detected.stitch)
1439
+ const selectedModel = (models || []).find((m) => m.id === advanced.model)
1440
+ const imageOnly = Boolean(selectedModel && !(selectedModel.capabilities || []).includes('text_to_video'))
1441
+ useEffect(() => {
1442
+ setAdvanced((prev) => {
1443
+ const usable = (models || []).filter((m) => m.available && m.enabled !== false)
1444
+ if (prev.model && usable.some((m) => m.id === prev.model)) return prev
1445
+ const pick = defaultModelId(models, false)
1446
+ return pick ? Object.assign({}, prev, { model: pick }) : prev
1447
+ })
1448
+ }, [models])
1449
+ const modelOptions = (models || []).filter((m) => m.available && m.enabled !== false).map((m) => ({ value: m.id, label: m.label }))
1450
+ const currentModel = modelOptions.some((o) => o.value === advanced.model) ? advanced.model : (modelOptions[0] ? modelOptions[0].value : '')
1451
+ const detectedLabels = []
1452
+ if (detected.aspect) detectedLabels.push(detected.aspect)
1453
+ if (detected.duration) detectedLabels.push(detected.duration + 's')
1454
+ if (detected.resolution) detectedLabels.push(detected.resolution)
1455
+ if (detected.mode === 'fine') detectedLabels.push('精细')
1456
+ // The brief wins: every parameter it names replaces the control value, and
1457
+ // the list below says exactly what will change before the run starts.
1458
+ const overrides = []
1459
+ if (detected.aspect && detected.aspect !== advanced.aspect) overrides.push('比例 ' + detected.aspect + '(控件 ' + advanced.aspect + ')')
1460
+ if (detected.duration && Number(detected.duration) !== Number(advanced.duration)) overrides.push('时长 ' + detected.duration + 's(控件 ' + advanced.duration + 's)')
1461
+ if (detected.resolution && detected.resolution !== advanced.resolution) overrides.push('清晰度 ' + detected.resolution + '(控件 ' + advanced.resolution + ')')
1462
+ if (detected.mode && detected.mode !== advanced.generation_mode) overrides.push('模式 精细(控件 快速)')
1463
+ if (detected.subtitle && detected.subtitle !== (advanced.subtitle || 'off')) overrides.push('字幕 ' + subtitleLabel(detected.subtitle) + '(控件 ' + subtitleLabel(advanced.subtitle) + ')')
1464
+ const changeAdvanced = (patch) => {
1465
+ const next = Object.assign({}, advanced, patch)
1466
+ const changed = {}
1467
+ for (const key of ['aspect', 'duration', 'resolution', 'generation_mode', 'subtitle']) {
1468
+ if (next[key] !== advanced[key]) changed[key] = true
1469
+ }
1470
+ if (Object.keys(changed).length) setTouched((prev) => Object.assign({}, prev, changed))
1471
+ setAdvanced(next)
1472
+ }
1473
+
1474
+ const upload = async (event) => {
1475
+ const picked = Array.from(event.currentTarget.files || [])
1476
+ event.currentTarget.value = ''
1477
+ if (!picked.length) return
1478
+ setBusy(true); setErr('')
1479
+ try {
1480
+ const next = files.slice()
1481
+ for (const file of picked) {
1482
+ if (next.length >= 9) break
1483
+ const kind = file.type.startsWith('video') ? 'video' : 'image'
1484
+ next.push(await uploadFile(file, kind))
1485
+ }
1486
+ setFiles(next)
1487
+ onRefreshAssets && onRefreshAssets()
1488
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
1489
+ }
1490
+ const remove = (id) => setFiles((prev) => prev.filter((f) => f.id !== id))
1491
+ const start = async () => {
1492
+ if (!brief.trim()) { setErr('先描述你想生成或拼接什么'); return }
1493
+ setBusy(true); setErr('')
1494
+ try {
1495
+ let smart = null
1496
+ try { smart = await parseIntentWithDsh(brief, selectedTextModel) } catch { smart = null }
1497
+ const next = Object.assign(detectVideoParams(brief))
1498
+ if (smart) {
1499
+ if (smart.aspect) next.aspect = smart.aspect
1500
+ if (smart.duration) next.duration = smart.duration
1501
+ if (smart.resolution) next.resolution = smart.resolution
1502
+ if (smart.mode) next.mode = smart.mode
1503
+ if (smart.subtitle) next.subtitle = smart.subtitle
1504
+ if (smart.vendor) next.vendor = smart.vendor
1505
+ }
1506
+ next.stitch = Boolean((smart && smart.stitch) || detected.stitch || /(拼接|拼起来|拼成|接起来|接到一起|合并|组合|连起来|插入|顺序拼|前后拼)/.test(brief))
1507
+ setDetected(next)
1508
+ const merged = Object.assign({}, advanced)
1509
+ if (next.aspect) merged.aspect = next.aspect
1510
+ if (next.duration) merged.duration = next.duration
1511
+ if (next.resolution) merged.resolution = next.resolution
1512
+ if (next.mode) merged.generation_mode = next.mode
1513
+ if (next.subtitle) merged.subtitle = next.subtitle
1514
+ const vendorModel = modelForVendor(next.vendor, models)
1515
+ if (vendorModel) merged.model = vendorModel
1516
+ if (next.stitch) {
1517
+ if (videos.length < 2) { setErr('要拼接请至少上传两段视频'); return }
1518
+ const data = await api('/stitch', { method: 'POST', body: {
1519
+ clips: videos.map((v) => ({ asset_id: v.id, in_s: 0 })),
1520
+ output: { aspect: merged.aspect, resolution: merged.resolution },
1521
+ fit: 'blur_pad', transition: 'cut', audio: 'keep',
1522
+ } })
1523
+ onStarted(data.run); onRefreshAssets && onRefreshAssets()
1524
+ return
1525
+ }
1526
+ if (videos.length) { setErr('视频附件用于拼接;如果要生成新视频,请只保留图片附件,或用文字说明“拼接这些视频”'); return }
1527
+ if (imageOnly && !images.length) { setErr('当前模型是图生视频,请先上传一张参考图'); return }
1528
+ const data = await api('/runs', { method: 'POST', body: {
1529
+ scenario: 'text-to-video',
1530
+ inputs: { brief, reference_image_asset_id: images[0] ? images[0].id : null },
1531
+ advanced: merged,
1532
+ } })
1533
+ onStarted(data.run)
1534
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
1535
+ }
1536
+
1537
+ const imageAvailable = (imageModels || []).some((m) => m.available)
1538
+ const modeTabs = h('div', { className: 'adp-create-tabs' },
1539
+ h('button', { className: 'adp-create-tab' + (mode === 'video' ? ' on' : ''), onClick: () => setMode('video') }, '文生视频'),
1540
+ h('button', { className: 'adp-create-tab' + (mode === 'image' ? ' on' : ''), disabled: !imageAvailable, title: imageAvailable ? '用文字生成图片' : '先在设置里配置图片模型厂商 key', onClick: () => imageAvailable && setMode('image') }, '文生图片', !imageAvailable ? h('span', { className: 'adp-create-tab-note' }, '未配置图片模型') : null)
1541
+ )
1542
+ const pageHead = h('div', { className: 'adp-page-head' },
1543
+ h('div', null,
1544
+ h('div', { className: 'adp-eyebrow' }, 'FREE CREATE'),
1545
+ h('h1', { className: 'adp-title' }, '自由创作'),
1546
+ h('p', { className: 'adp-lede adp-nowrap', title: '文生视频出成片;文生图片出商品图。参数可直接写在描述里。' }, '文生视频出成片;文生图片出商品图。参数可直接写在描述里。')
1547
+ )
1548
+ )
1549
+ if (mode === 'image') {
1550
+ return h('div', { className: 'adp-page' }, pageHead, modeTabs, h(ImagePanel, { imageModels, onStarted, onRefreshAssets }))
1551
+ }
1552
+ return h('div', { className: 'adp-page' },
1553
+ pageHead,
1554
+ modeTabs,
1555
+ h('div', { className: 'adp-composer' },
1556
+ h('div', { className: 'adp-composer-head' },
1557
+ h('span', { className: 'adp-composer-label' }, '描述'),
1558
+ h('span', { className: 'adp-composer-count' }, brief.length + ' / 1000')
1559
+ ),
1560
+ h('textarea', {
1561
+ className: 'adp-composer-input',
1562
+ value: brief,
1563
+ maxLength: 1000,
1564
+ placeholder: '例如:竖屏 9:16,8 秒,一位 30 岁左右女性在明亮的厨房里展示一瓶饮料,中景,自然光;最后把产品举到镜头前。',
1565
+ onChange: (e) => setBrief(e.currentTarget.value),
1566
+ }),
1567
+ h('div', { className: 'adp-attachments' },
1568
+ files.map((file) => h('div', { key: file.id, className: 'adp-attach' },
1569
+ file.kind === 'image'
1570
+ ? h('img', { src: mediaUrl(file.path), alt: file.name })
1571
+ : h('video', { src: mediaUrl(file.path), muted: true, playsInline: true }),
1572
+ h('button', { className: 'adp-attach-remove', title: '移除', onClick: () => remove(file.id) }, '×'),
1573
+ h('span', { className: 'adp-attach-kind' }, file.kind === 'video' ? '视频' : '图片')
1574
+ )),
1575
+ h('button', { className: 'adp-attach-add', onClick: () => input.current && input.current.click(), title: '添加图片或视频' },
1576
+ h('b', null, '+'), h('span', null, '附件')
1577
+ ),
1578
+ h('input', { ref: input, type: 'file', accept: 'image/*,video/*', multiple: true, onChange: upload, style: { display: 'none' } })
1579
+ ),
1580
+ detectedLabels.length ? h('div', { className: 'adp-detected' }, h('span', null, '从描述识别'), detectedLabels.map((label) => h('span', { key: label, className: 'adp-detected-chip' }, label))) : null,
1581
+ overrides.length ? h('div', { className: 'adp-conflict' }, h('b', null, '描述优先'), overrides.join(';')) : null,
1582
+ h('div', { className: 'adp-composer-foot' },
1583
+ h('div', { className: 'adp-row' },
1584
+ h(TextModelSelect, { dsh, value: selectedTextModel, onChange: setTextModel }),
1585
+ h('select', { className: 'adp-select adp-model-select', value: currentModel, onChange: (e) => setAdvanced(Object.assign({}, advanced, { model: e.currentTarget.value })) },
1586
+ modelOptions.map((o) => h('option', { key: o.value, value: o.value }, o.label))
1587
+ ),
1588
+ h('button', { className: 'adp-btn ghost', onClick: () => setShowAdvanced((v) => !v) }, showAdvanced ? '收起参数' : '参数'),
1589
+ videos.length ? h('span', { className: 'adp-small adp-muted' }, videos.length + ' 段视频' + (stitchIntent ? ' · 将按顺序拼接' : ' · 说“拼接”才会拼接')) : null
1590
+ ),
1591
+ h('button', { className: 'adp-primary', onClick: start, disabled: busy },
1592
+ busy ? '提交中…' : (stitchIntent && videos.length >= 2 ? '拼接生成' : '生成'),
1593
+ h('span', { className: 'arrow' }, '→')
1594
+ )
1595
+ )
1596
+ ),
1597
+ showAdvanced ? h('div', { className: 'adp-advanced-panel' },
1598
+ h('div', { className: 'adp-section-head' }, h('span', { className: 'adp-section-title' }, '生成参数')),
1599
+ h(AdvancedRow, { value: advanced, onChange: (next) => changeAdvanced(next), models, needsDialogue: false }),
1600
+ imageOnly ? h('div', { className: 'adp-hint' }, '当前模型是图生视频:需要图片附件;它不生成原生音频。') : null
1601
+ ) : null,
1602
+ err ? h('div', { className: 'adp-error' }, err) : null
1603
+ )
1604
+ }
1605
+
1606
+ function ImagePanel({ imageModels, onStarted, onRefreshAssets }) {
1607
+ const available = (imageModels || []).filter((m) => m.available && (m.capabilities || []).includes('text_to_image'))
1608
+ const [prompt, setPrompt] = useState('')
1609
+ const [model, setModel] = useState(available[0] ? available[0].id : '')
1610
+ const [aspect, setAspect] = useState('1:1')
1611
+ const [area, setArea] = useState('2K')
1612
+ const [busy, setBusy] = useState(false)
1613
+ const [err, setErr] = useState('')
1614
+ const [refAsset, setRefAsset] = useState(null)
1615
+ const [refBusy, setRefBusy] = useState(false)
1616
+ const selected = available.find((m) => m.id === model) || available[0]
1617
+ const takesReference = Boolean(selected && (selected.capabilities || []).includes('image_to_image'))
1618
+ const uploadReference = async (event) => {
1619
+ const file = (event.currentTarget.files || [])[0]
1620
+ event.currentTarget.value = ''
1621
+ if (!file) return
1622
+ if (!file.type.startsWith('image/')) { setErr('参考图只支持图片文件'); return }
1623
+ setRefBusy(true); setErr('')
1624
+ try {
1625
+ const asset = await uploadFile(file, 'image')
1626
+ setRefAsset(asset)
1627
+ onRefreshAssets && await onRefreshAssets()
1628
+ } catch (e) { setErr(String(e.message || e)) } finally { setRefBusy(false) }
1629
+ }
1630
+ useEffect(() => {
1631
+ if (!selected && available.length) { setModel(available[0].id); setArea(available[0].default_area || '2K') }
1632
+ if (selected && selected.default_area && !(selected.areas || []).includes(area)) setArea(selected.default_area)
1633
+ }, [imageModels])
1634
+ const start = async () => {
1635
+ if (!prompt.trim()) { setErr('先描述你想生成的图片'); return }
1636
+ setBusy(true); setErr('')
1637
+ try {
1638
+ const data = await api('/images', { method: 'POST', body: { prompt: prompt.trim(), model: selected ? selected.id : '', aspect, area, reference_asset_id: takesReference && refAsset ? refAsset.id : '' } })
1639
+ onStarted(data.run)
1640
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
1641
+ }
1642
+ if (!available.length) {
1643
+ return h('div', { className: 'adp-card adp-col' }, h('div', { className: 'adp-h2' }, '暂无可用图片模型'), h('div', { className: 'adp-small adp-muted' }, '到「设置」里配置 MiniMax 或火山方舟的 key 后,图片模型会出现在这里。'))
1644
+ }
1645
+ return h('div', { className: 'adp-composer' },
1646
+ h('div', { className: 'adp-composer-head' }, h('span', { className: 'adp-composer-label' }, '描述图片'), h('span', { className: 'adp-composer-count' }, prompt.length + ' / 1000')),
1647
+ h('textarea', { className: 'adp-composer-input', value: prompt, maxLength: 1000, placeholder: '例如:一张 1:1 的商品主图,浅奶油色背景,鹰嘴豆包装居中,旁边散落几颗鹰嘴豆,柔和棚拍光,干净、有食欲。', onChange: (e) => setPrompt(e.currentTarget.value) }),
1648
+ h('div', { className: 'adp-composer-foot' },
1649
+ h('div', { className: 'adp-row' },
1650
+ h('select', { className: 'adp-select adp-model-select', value: selected ? selected.id : '', onChange: (e) => { const next = available.find((m) => m.id === e.currentTarget.value); setModel(e.currentTarget.value); if (next && next.default_area) setArea(next.default_area) } },
1651
+ available.map((m) => h('option', { key: m.id, value: m.id }, m.label))
1652
+ ),
1653
+ h('select', { className: 'adp-select', value: aspect, onChange: (e) => setAspect(e.currentTarget.value) }, (selected ? selected.aspects : ['1:1']).map((x) => h('option', { key: x, value: x }, x))),
1654
+ h('select', { className: 'adp-select', value: area, onChange: (e) => setArea(e.currentTarget.value) }, (selected ? selected.areas : ['2K']).map((x) => h('option', { key: x, value: x }, x))),
1655
+ takesReference ? h('label', { className: 'adp-ref-upload' + (refAsset ? ' has' : ''), title: '可选:上传一张参考图,按图生图生成' },
1656
+ refBusy ? h('span', null, '上传中…')
1657
+ : refAsset
1658
+ ? h('span', { className: 'adp-ref-chip' }, h('img', { src: mediaUrl(refAsset.path), alt: refAsset.name }), h('span', { className: 'adp-ref-name' }, refAsset.name))
1659
+ : h('span', null, '+ 参考图(可选)'),
1660
+ h('input', { type: 'file', accept: 'image/*', onChange: uploadReference, disabled: refBusy, style: { position: 'absolute', width: 1, height: 1, opacity: 0, clip: 'rect(0 0 0 0)', overflow: 'hidden' } })
1661
+ ) : null,
1662
+ refAsset && takesReference ? h('button', { className: 'adp-btn ghost', onClick: () => setRefAsset(null), title: '移除参考图' }, '移除') : null
1663
+ ),
1664
+ h('button', { className: 'adp-primary', onClick: start, disabled: busy }, busy ? '生成中…' : '生成图片', h('span', { className: 'arrow' }, '→'))
1665
+ ),
1666
+ err ? h('div', { className: 'adp-error', style: { padding: '0 15px 12px' } }, err) : null
1667
+ )
1668
+ }
1669
+
1670
+ function StitchBox({ assets, onStarted, onRefreshAssets }) {
1671
+ const videos = (assets || []).filter(a => a.kind === 'video')
1672
+ const [a, setA] = useState(''); const [b, setB] = useState(''); const [plan, setPlan] = useState(null); const [busy, setBusy] = useState(''); const [err, setErr] = useState('')
1673
+ const build = async () => {
1674
+ if (!a || !b) { setErr('请选择两个视频'); return }
1675
+ setBusy('plan'); setErr('')
1676
+ try { const data = await api('/stitch/plan', { method: 'POST', body: { clips: [{ asset_id: a, in_s: 0 }, { asset_id: b, in_s: 0 }], output: { aspect: '9:16', resolution: '720p' }, fit: 'blur_pad', transition: 'cut', audio: 'keep' } }); setPlan(data.plan) } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1677
+ }
1678
+ const apply = async () => {
1679
+ setBusy('apply'); setErr('')
1680
+ try { const data = await api('/stitch', { method: 'POST', body: { clips: [{ asset_id: a, in_s: 0 }, { asset_id: b, in_s: 0 }], output: { aspect: '9:16', resolution: '720p' }, fit: 'blur_pad', transition: 'cut', audio: 'keep' } }); setPlan(null); onStarted(data.run); onRefreshAssets && onRefreshAssets() } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1681
+ }
1682
+ return h('div', { className: 'adp-card adp-col', style: { marginTop: 4 } },
1683
+ h('div', { className: 'adp-h2' }, '拼接 / 插入'),
1684
+ h('div', { className: 'adp-small adp-muted' }, '两段顺序拼、长广告插中间;这里先做顺序拼接,计划卡确认后再执行。'),
1685
+ h('div', { className: 'adp-row' },
1686
+ h('select', { className: 'adp-select', value: a, onChange: (e) => setA(e.currentTarget.value) }, h('option', { value: '' }, '选择视频 A'), videos.map(v => h('option', { key: v.id, value: v.id }, v.name))),
1687
+ h('select', { className: 'adp-select', value: b, onChange: (e) => setB(e.currentTarget.value) }, h('option', { value: '' }, '选择视频 B'), videos.map(v => h('option', { key: v.id, value: v.id }, v.name))),
1688
+ h('button', { className: 'adp-btn', onClick: build, disabled: busy === 'plan' }, '生成计划'),
1689
+ plan ? h('button', { className: 'adp-btn primary', onClick: apply, disabled: busy === 'apply' }, '应用拼接') : null
1690
+ ),
1691
+ plan ? h('div', { className: 'adp-col' }, h('div', { className: 'adp-small adp-muted' }, '总时长 ' + fmt(plan.duration_s) + ' · ' + plan.width + '×' + plan.height), (plan.warnings || []).map((w, i) => h('div', { key: i, className: 'adp-error' }, w))) : null,
1692
+ err ? h('div', { className: 'adp-error' }, err) : null
1693
+ )
1694
+ }
1695
+
1696
+
1697
+ function assetMeta(a) {
1698
+ const kind = { image: '图片', video: '视频', audio: '音频' }[a.kind] || a.kind || '文件'
1699
+ const facts = [kind]
1700
+ if (a.duration_s) facts.push(fmt(a.duration_s))
1701
+ else if (a.width && a.height) facts.push(a.width + '×' + a.height)
1702
+ return facts.join(' · ')
1703
+ }
1704
+
1705
+ function statusStamp(status) {
1706
+ if (status === 'succeeded') return { label: '完成', tone: 'ok' }
1707
+ if (status === 'failed') return { label: '失败', tone: 'bad' }
1708
+ if (status === 'canceled') return { label: '取消', tone: 'muted' }
1709
+ if (status === 'running') return { label: '生成中', tone: 'warn' }
1710
+ return { label: '排队', tone: 'muted' }
1711
+ }
1712
+
1713
+ function TaskCard({ run, onOpen, selected, onSelect, onRenamed }) {
1714
+ const [renaming, setRenaming] = useState(false)
1715
+ const [title, setTitle] = useState(run.title || '')
1716
+ const [busy, setBusy] = useState(false)
1717
+ useEffect(() => { setTitle(run.title || '') }, [run.title])
1718
+ const canSelect = run.status === 'succeeded'
1719
+ const stamp = statusStamp(run.status)
1720
+ const save = async () => {
1721
+ setBusy(true)
1722
+ try {
1723
+ const data = await api('/runs/' + run.id, { method: 'PATCH', body: { title: title.trim() } })
1724
+ const next = data.run.title
1725
+ setTitle(next)
1726
+ setRenaming(false)
1727
+ onRenamed && onRenamed(run.id, next)
1728
+ } catch (e) { window.alert(String(e.message || e)) } finally { setBusy(false) }
1729
+ }
1730
+ return h('div', { className: 'adp-run-card' + (selected ? ' selected' : ''), onClick: () => { if (!renaming) onOpen(run) } },
1731
+ h('div', { className: 'adp-task-head' },
1732
+ canSelect ? h('input', { type: 'checkbox', className: 'adp-task-check', checked: selected, onClick: (e) => e.stopPropagation(), onChange: () => onSelect(run.id) }) : h('span', { className: 'adp-task-check-spacer' }),
1733
+ renaming
1734
+ ? h('input', { className: 'adp-input adp-grow adp-task-title-input', value: title, autoFocus: true, onClick: (e) => e.stopPropagation(), onChange: (e) => setTitle(e.currentTarget.value), onKeyDown: (e) => { if (e.key === 'Enter') save(); if (e.key === 'Escape') setRenaming(false) } })
1735
+ : h('div', { className: 'adp-task-title', title: run.title || run.scenario }, run.title || run.scenario),
1736
+ renaming
1737
+ ? h('div', { className: 'adp-row', style: { gap: 2 } },
1738
+ h('button', { className: 'adp-task-save ok', onClick: (e) => { e.stopPropagation(); save() }, disabled: busy, title: '保存名称' }, busy ? '…' : h(Glyph, { name: 'check', size: 14 })),
1739
+ h('button', { className: 'adp-task-save', onClick: (e) => { e.stopPropagation(); setRenaming(false) }, title: '取消' }, h(Glyph, { name: 'close', size: 13 }))
1740
+ )
1741
+ : h('button', { className: 'adp-icon-btn adp-task-edit', title: '重命名', onClick: (e) => { e.stopPropagation(); setRenaming(true) } }, h(Glyph, { name: 'edit', size: 13 }))
1742
+ ),
1743
+ h('div', { className: 'adp-small adp-muted adp-task-scenario' }, (run.scenario === 'text-to-image' ? '文生图片' : run.scenario) + ' · ' + ((run.advanced && run.advanced.model) || 'auto')),
1744
+ h('div', { className: 'adp-small adp-faint adp-task-time' }, '创建 ' + fmtDateTime(run.created_at)),
1745
+ h('div', { className: 'adp-small adp-faint adp-task-time' }, '完成 ' + (run.finished_at ? fmtDateTime(run.finished_at) : '—') + ' · 耗时 ' + runDuration(run)),
1746
+ h('div', { className: 'adp-progress adp-task-progress' }, h('i', { style: { width: Math.round((run.progress || 0) * 100) + '%' } })),
1747
+ h('div', { className: 'adp-status-stamp ' + stamp.tone, title: '状态:' + stamp.label, 'aria-label': '状态:' + stamp.label },
1748
+ h('svg', { className: 'stamp-ring', viewBox: '0 0 44 44', 'aria-hidden': true },
1749
+ h('circle', { cx: 22, cy: 22, r: 21, fill: 'none', stroke: 'currentColor', strokeWidth: 1 }),
1750
+ h('circle', { cx: 22, cy: 22, r: 17, fill: 'none', stroke: 'currentColor', strokeWidth: 1, strokeDasharray: '2 3', opacity: 0.65 })
1751
+ ),
1752
+ h('b', null, stamp.label)
1753
+ )
1754
+ )
1755
+ }
1756
+
1757
+ function AssetsTab({ onRefresh }) {
1758
+ const [page, setPage] = useState(1)
1759
+ const [pageSize, setPageSize] = useState(20)
1760
+ const [q, setQ] = useState('')
1761
+ const [kind, setKind] = useState('')
1762
+ const [dateFrom, setDateFrom] = useState('')
1763
+ const [dateTo, setDateTo] = useState('')
1764
+ const [data, setData] = useState({ assets: [], total: 0, has_more: false })
1765
+ const [loading, setLoading] = useState(false)
1766
+ const [busy, setBusy] = useState(false)
1767
+ const [err, setErr] = useState('')
1768
+ const [notice, setNotice] = useState('')
1769
+ const totalPages = Math.max(1, Math.ceil((data.total || 0) / pageSize))
1770
+ useEffect(() => { if (page > totalPages) setPage(totalPages) }, [page, totalPages])
1771
+ const load = useCallback(async () => {
1772
+ setLoading(true); setErr('')
1773
+ try {
1774
+ const params = new URLSearchParams({ offset: String((page - 1) * pageSize), limit: String(pageSize), q, kind, from: dateFrom, to: dateTo })
1775
+ const d = await api('/assets?' + params.toString())
1776
+ setData({ assets: d.assets || [], total: d.total || 0, has_more: Boolean(d.has_more) })
1777
+ } catch (e) { setErr(String(e.message || e)) } finally { setLoading(false) }
1778
+ }, [page, pageSize, q, kind, dateFrom, dateTo])
1779
+ useEffect(() => { void load() }, [load])
1780
+ useEffect(() => { const t = setTimeout(() => setPage(1), 250); return () => clearTimeout(t) }, [q, kind])
1781
+ const upload = async (event) => {
1782
+ const all = Array.from(event.currentTarget.files || [])
1783
+ event.currentTarget.value = ''
1784
+ const picked = all.filter((file) => file.type.startsWith('image/') || file.type.startsWith('video/'))
1785
+ if (!picked.length) {
1786
+ setErr('仅支持图片和视频素材')
1787
+ return
1788
+ }
1789
+ setBusy(true); setErr(''); setNotice(picked.length < all.length ? '已忽略非图片/视频文件' : '')
1790
+ try {
1791
+ let dup = 0
1792
+ for (const file of picked) {
1793
+ const asset = await uploadFile(file, file.type.startsWith('video') ? 'video' : 'image')
1794
+ if (asset.deduplicated) dup += 1
1795
+ }
1796
+ await onRefresh()
1797
+ await load()
1798
+ if (dup) setNotice('已存在相同 SHA-256 素材,未新增重复记录')
1799
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy(false) }
1800
+ }
1801
+ const reveal = async (path) => {
1802
+ setErr('')
1803
+ try { await api('/reveal', { method: 'POST', body: { path } }) } catch (e) { setErr('打开文件夹失败:' + String(e.message || e)) }
1804
+ }
1805
+ return h('div', { className: 'adp-page' },
1806
+ h('div', { className: 'adp-page-head' },
1807
+ h('div', null, h('div', { className: 'adp-eyebrow' }, 'ASSETS'), h('h1', { className: 'adp-title' }, '素材库'), h('p', { className: 'adp-lede' }, '相同文件按 SHA-256 去重;支持搜索、分页和在 Finder 中定位。')),
1808
+ h('div', { className: 'adp-row' },
1809
+ h('button', { className: 'adp-btn', onClick: () => reveal('assets') }, '打开素材文件夹'),
1810
+ h('label', { className: 'adp-btn primary adp-upload-label', title: '仅支持图片和视频' },
1811
+ busy ? '上传中…' : '上传素材',
1812
+ h('input', { type: 'file', accept: 'image/*,video/*', multiple: true, onChange: upload, disabled: busy, style: { position: 'absolute', width: 1, height: 1, opacity: 0, clip: 'rect(0 0 0 0)', overflow: 'hidden' } })
1813
+ )
1814
+ )
1815
+ ),
1816
+ h('div', { className: 'adp-toolbar' },
1817
+ h('input', { className: 'adp-input adp-grow', value: q, placeholder: '按名称搜索素材', onChange: (e) => { setQ(e.currentTarget.value); setPage(1) } }),
1818
+ h('select', { className: 'adp-select', value: kind, onChange: (e) => { setKind(e.currentTarget.value); setPage(1) } }, h('option', { value: '' }, '全部类型'), h('option', { value: 'image' }, '图片'), h('option', { value: 'video' }, '视频')),
1819
+ h('input', { className: 'adp-input adp-date-input', type: 'date', title: '开始日期', value: dateFrom, onChange: (e) => { setDateFrom(e.currentTarget.value); setPage(1) } }),
1820
+ h('span', { className: 'adp-small adp-muted' }, '至'),
1821
+ h('input', { className: 'adp-input adp-date-input', type: 'date', title: '结束日期', value: dateTo, onChange: (e) => { setDateTo(e.currentTarget.value); setPage(1) } }),
1822
+ h('select', { className: 'adp-select', value: pageSize, title: '每页数量', onChange: (e) => { setPageSize(Number(e.currentTarget.value)); setPage(1) } }, [20, 40, 80, 100, 200].map((n) => h('option', { key: n, value: n }, '每页 ' + n))),
1823
+ h('button', { className: 'adp-btn', onClick: load, disabled: loading }, loading ? '加载中…' : '刷新')
1824
+ ),
1825
+ notice ? h('div', { className: 'adp-notice' }, notice) : null,
1826
+ err ? h('div', { className: 'adp-error' }, err) : null,
1827
+ h('div', { className: 'adp-asset-grid' }, (data.assets || []).map((a) => h('div', { key: a.id, className: 'adp-asset-card' },
1828
+ a.kind === 'image' ? h('img', { src: mediaUrl(a.path), alt: a.name }) : h('video', { src: mediaUrl(a.path), muted: true, playsInline: true }),
1829
+ h('div', { className: 'adp-asset-card-body' },
1830
+ h('div', { className: 'adp-small adp-grow', title: a.name }, a.name),
1831
+ h('button', { className: 'adp-icon-btn', title: '在文件夹中显示', onClick: () => reveal(a.path) }, h(Glyph, { name: 'folder', size: 19 }))
1832
+ ),
1833
+ h('div', { className: 'adp-asset-meta-row' },
1834
+ h('span', { className: 'adp-asset-kind' }, assetMeta(a)),
1835
+ h('span', { className: 'adp-asset-time', title: fmtAssetDate(a.created_at) }, fmtAssetDate(a.created_at))
1836
+ )
1837
+ ))),
1838
+ !loading && !(data.assets || []).length ? h('div', { className: 'adp-empty-state' }, '没有匹配的素材') : null,
1839
+ h('div', { className: 'adp-pager' },
1840
+ h('button', { className: 'adp-btn', disabled: page <= 1 || loading, onClick: () => setPage((v) => Math.max(1, v - 1)) }, '上一页'),
1841
+ h('span', { className: 'adp-small adp-muted' }, '第 ' + page + ' / ' + totalPages + ' 页 · ' + (data.total || 0) + ' 个'),
1842
+ h('button', { className: 'adp-btn', disabled: page >= totalPages || loading, onClick: () => setPage((v) => v + 1) }, '下一页')
1843
+ )
1844
+ )
1845
+ }
1846
+
1847
+ function TasksTab({ onOpen }) {
1848
+ const [page, setPage] = useState(1)
1849
+ const [pageSize, setPageSize] = useState(20)
1850
+ const [q, setQ] = useState('')
1851
+ const [dateFrom, setDateFrom] = useState('')
1852
+ const [dateTo, setDateTo] = useState('')
1853
+ const [status, setStatus] = useState('')
1854
+ const [data, setData] = useState({ runs: [], total: 0, has_more: false })
1855
+ const [loading, setLoading] = useState(false)
1856
+ const [err, setErr] = useState('')
1857
+ const [notice, setNotice] = useState('')
1858
+ const [selectedIds, setSelectedIds] = useState([])
1859
+ const [busy, setBusy] = useState('')
1860
+ const totalPages = Math.max(1, Math.ceil((data.total || 0) / pageSize))
1861
+ useEffect(() => { if (page > totalPages) setPage(totalPages) }, [page, totalPages])
1862
+ const load = useCallback(async () => {
1863
+ setLoading(true); setErr('')
1864
+ try {
1865
+ const params = new URLSearchParams({ offset: String((page - 1) * pageSize), limit: String(pageSize), q, status, from: dateFrom, to: dateTo, sort: 'created_desc' })
1866
+ const d = await api('/runs?' + params.toString())
1867
+ setData({ runs: d.runs || [], total: d.total || 0, has_more: Boolean(d.has_more) })
1868
+ } catch (e) { setErr(String(e.message || e)) } finally { setLoading(false) }
1869
+ }, [page, pageSize, q, status, dateFrom, dateTo])
1870
+ useEffect(() => { void load() }, [load])
1871
+ useEffect(() => { const t = setTimeout(() => setPage(1), 250); return () => clearTimeout(t) }, [q])
1872
+ const select = (id) => setSelectedIds((prev) => prev.includes(id) ? prev.filter((x) => x !== id) : prev.concat(id))
1873
+ const pageSelectable = (data.runs || []).filter((r) => r.status === 'succeeded').map((r) => r.id)
1874
+ const pageAllSelected = pageSelectable.length > 0 && pageSelectable.every((id) => selectedIds.includes(id))
1875
+ const togglePage = () => {
1876
+ if (pageAllSelected) setSelectedIds((prev) => prev.filter((id) => !pageSelectable.includes(id)))
1877
+ else setSelectedIds((prev) => Array.from(new Set(prev.concat(pageSelectable))))
1878
+ }
1879
+ const clearAll = () => setSelectedIds([])
1880
+ const exportSelected = async () => {
1881
+ if (!selectedIds.length) { setErr('先选择已完成任务'); return }
1882
+ setBusy('export'); setErr(''); setNotice('')
1883
+ try { await downloadPost('/runs/export', { run_ids: selectedIds }, 'adplus-export.zip'); setNotice('已导出 ' + selectedIds.length + ' 个任务') } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1884
+ }
1885
+ const renamed = (id, title) => setData((prev) => Object.assign({}, prev, { runs: (prev.runs || []).map((r) => r.id === id ? Object.assign({}, r, { title }) : r) }))
1886
+ return h('div', { className: 'adp-page' },
1887
+ h('div', { className: 'adp-page-head' },
1888
+ h('div', null, h('div', { className: 'adp-eyebrow' }, 'TASKS'), h('h1', { className: 'adp-title' }, '任务'), h('p', { className: 'adp-lede' }, '运行历史;支持改名、按名称/时间搜索、分页和批量导出。')),
1889
+ h('div', { className: 'adp-row' },
1890
+ h('button', { className: 'adp-btn', onClick: load, disabled: loading }, loading ? '加载中…' : '刷新'),
1891
+ h('button', { className: 'adp-btn', onClick: togglePage, disabled: loading }, pageAllSelected ? '取消当前页' : '全选当前页'),
1892
+ selectedIds.length ? h('button', { className: 'adp-btn ghost', onClick: clearAll, disabled: !!busy }, '取消全部选择 (' + selectedIds.length + ')') : null,
1893
+ h('button', { className: 'adp-btn primary', onClick: exportSelected, disabled: !selectedIds.length || !!busy }, busy === 'export' ? '导出中…' : '导出选中 (' + selectedIds.length + ')')
1894
+ )
1895
+ ),
1896
+ h('div', { className: 'adp-toolbar' },
1897
+ h('input', { className: 'adp-input adp-grow', value: q, placeholder: '搜索任务名称 / ID', onChange: (e) => { setQ(e.currentTarget.value); setPage(1) } }),
1898
+ h('input', { className: 'adp-input', type: 'date', value: dateFrom, title: '开始日期', onChange: (e) => { setDateFrom(e.currentTarget.value); setPage(1) } }),
1899
+ h('span', { className: 'adp-small adp-muted' }, '至'),
1900
+ h('input', { className: 'adp-input', type: 'date', value: dateTo, title: '结束日期', onChange: (e) => { setDateTo(e.currentTarget.value); setPage(1) } }),
1901
+ h('select', { className: 'adp-select', value: status, onChange: (e) => { setStatus(e.currentTarget.value); setPage(1) } },
1902
+ h('option', { value: '' }, '全部状态'), h('option', { value: 'succeeded' }, '完成'), h('option', { value: 'running' }, '生成中'), h('option', { value: 'failed' }, '失败'), h('option', { value: 'canceled' }, '已取消')
1903
+ ),
1904
+ h('select', { className: 'adp-select', value: pageSize, title: '每页数量', onChange: (e) => { setPageSize(Number(e.currentTarget.value)); setPage(1) } },
1905
+ [20, 40, 80, 100, 200].map((n) => h('option', { key: n, value: n }, '每页 ' + n))
1906
+ )
1907
+ ),
1908
+ notice ? h('div', { className: 'adp-notice' }, notice) : null,
1909
+ err ? h('div', { className: 'adp-error' }, err) : null,
1910
+ h('div', { className: 'adp-task-grid' }, (data.runs || []).map((r) => h(TaskCard, { key: r.id, run: r, onOpen, selected: selectedIds.includes(r.id), onSelect: select, onRenamed: renamed }))),
1911
+ !loading && !(data.runs || []).length ? h('div', { className: 'adp-empty-state' }, '没有匹配的任务') : null,
1912
+ h('div', { className: 'adp-pager' },
1913
+ h('button', { className: 'adp-btn', disabled: page <= 1 || loading, onClick: () => setPage((v) => Math.max(1, v - 1)) }, '上一页'),
1914
+ h('span', { className: 'adp-small adp-muted' }, '第 ' + page + ' / ' + totalPages + ' 页 · ' + (data.total || 0) + ' 个任务'),
1915
+ h('button', { className: 'adp-btn', disabled: page >= totalPages || loading, onClick: () => setPage((v) => v + 1) }, '下一页')
1916
+ )
1917
+ )
1918
+ }
1919
+
1920
+ function PersonasTab({ personas, onRefresh }) {
1921
+ const empty = () => ({ name: '', type: 'ai', gender: 'any', age: 'youth', body_type: 'standard', ethnicity: 'asian', exact_age: '', height_cm: '', hair: '', outfit: '', temperament: '', voice_tone: '', role: 'both', consent: { confirmed: false, note: '' } })
1922
+ const [open, setOpen] = useState(false)
1923
+ const [form, setForm] = useState(empty)
1924
+ const [editingId, setEditingId] = useState('')
1925
+ const [busy, setBusy] = useState('')
1926
+ const [err, setErr] = useState('')
1927
+ const set = (key, value) => setForm((prev) => Object.assign({}, prev, { [key]: value }))
1928
+ const openNew = () => { setEditingId(''); setForm(empty()); setErr(''); setOpen(true) }
1929
+ const openEdit = (persona) => { setEditingId(persona.id); setForm(Object.assign(empty(), persona)); setErr(''); setOpen(true) }
1930
+ const close = () => { if (busy === 'save') return; setOpen(false); setEditingId(''); setErr('') }
1931
+ const save = async () => {
1932
+ setBusy('save'); setErr('')
1933
+ try {
1934
+ const payload = Object.assign({}, form)
1935
+ payload.name = String(payload.name || '').trim() || '未命名模特'
1936
+ if (payload.exact_age === '' || payload.exact_age == null) delete payload.exact_age
1937
+ if (payload.height_cm === '' || payload.height_cm == null) delete payload.height_cm
1938
+ if (payload.type === 'real' && !(payload.consent && payload.consent.confirmed)) throw new Error('真人模特必须勾选授权')
1939
+ await api(editingId ? '/personas/' + editingId : '/personas', { method: editingId ? 'PATCH' : 'POST', body: payload })
1940
+ await onRefresh(); close()
1941
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1942
+ }
1943
+ const remove = async (persona) => {
1944
+ if (!window.confirm('删除模特「' + persona.name + '」?')) return
1945
+ setBusy('remove:' + persona.id); setErr('')
1946
+ try { await api('/personas/' + persona.id, { method: 'DELETE' }); await onRefresh(); if (editingId === persona.id) close() } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
1947
+ }
1948
+ const summary = (p) => [p.gender, p.age, p.body_type, p.ethnicity].filter(Boolean).join(' · ')
1949
+ return h('div', { className: 'adp-page' },
1950
+ h('div', { className: 'adp-page-head' },
1951
+ h('div', null, h('div', { className: 'adp-eyebrow' }, 'CAST LIBRARY'), h('h1', { className: 'adp-title' }, '模特库'), h('p', { className: 'adp-lede' }, '把常用人物固定成可复用角色。性别、年龄、体型、族裔可组合;真人角色必须确认授权。')),
1952
+ h('button', { className: 'adp-btn primary', onClick: openNew }, '新建模特')
1953
+ ),
1954
+ h('div', { className: 'adp-persona-grid' },
1955
+ (personas || []).map((p) => h('div', { key: p.id, className: 'adp-persona-card' },
1956
+ h('div', { className: 'adp-row' }, h('div', { className: 'adp-h2 adp-grow' }, p.name || '未命名'), h(Badge, { status: p.type === 'real' ? (p.consent && p.consent.confirmed ? 'ok' : 'bad') : '' }, p.type === 'real' ? '真人' : p.type === 'group' ? '群像' : 'AI')),
1957
+ h('div', { className: 'adp-small adp-muted', style: { marginTop: 4 } }, summary(p) || '未设置'),
1958
+ h('div', { className: 'adp-small adp-faint', style: { marginTop: 3 } }, '角色:' + ({ both: '出镜+口播', A: '口播 A', B: '口播 B', group: '群像' }[p.role] || p.role || '—') + (p.used_in_runs && p.used_in_runs.length ? ' · 已用 ' + p.used_in_runs.length + ' 次' : '')),
1959
+ h('div', { className: 'adp-row', style: { marginTop: 10 } },
1960
+ h('button', { className: 'adp-btn', onClick: () => openEdit(p) }, '编辑'),
1961
+ h('button', { className: 'adp-btn danger', onClick: () => remove(p), disabled: busy === 'remove:' + p.id }, '删除')
1962
+ )
1963
+ )),
1964
+ !(personas || []).length ? h('div', { className: 'adp-empty-state' }, h('div', { className: 'adp-h2' }, '还没有模特'), h('div', { className: 'adp-small adp-muted' }, '新建一个角色,之后在爆款复刻里直接复用。'), h('button', { className: 'adp-btn primary', onClick: openNew }, '新建模特')) : null
1965
+ ),
1966
+ err && !open ? h('div', { className: 'adp-error', style: { marginTop: 12 } }, err) : null,
1967
+ open ? h('div', { className: 'adp-modal-backdrop', onClick: close },
1968
+ h('div', { className: 'adp-modal adp-persona-modal', role: 'dialog', 'aria-modal': 'true', 'aria-label': '编辑模特', onClick: (e) => e.stopPropagation() },
1969
+ h('div', { className: 'adp-modal-head' },
1970
+ h('div', null, h('div', { className: 'adp-h2' }, editingId ? '编辑模特' : '新建模特'), h('div', { className: 'adp-small adp-muted' }, '固定人物设定,复用到不同片子。')),
1971
+ h('button', { className: 'adp-icon-btn', onClick: close, title: '关闭' }, h(Glyph, { name: 'close' }))
1972
+ ),
1973
+ h('div', { className: 'adp-modal-body' },
1974
+ h('div', { className: 'adp-modal-section' },
1975
+ h('div', { className: 'adp-modal-section-title' }, '基础信息'),
1976
+ h('div', { className: 'adp-field-grid g2' },
1977
+ h(Field, { label: '名称', style: { gridColumn: '1 / -1' } }, h('input', { className: 'adp-input', value: form.name || '', placeholder: '例如:小美·追剧场景', onChange: (e) => set('name', e.currentTarget.value) })),
1978
+ h(FormSelect, { label: '类型', value: form.type || 'ai', onChange: (x) => set('type', x), options: [{ value: 'ai', label: 'AI 模特' }, { value: 'real', label: '真人(需授权)' }, { value: 'group', label: '群像' }] }),
1979
+ h(FormSelect, { label: '角色', value: form.role || 'both', onChange: (x) => set('role', x), options: [{ value: 'both', label: '出镜+口播' }, { value: 'A', label: '口播 A' }, { value: 'B', label: '口播 B' }, { value: 'group', label: '群像' }] })
1980
+ )
1981
+ ),
1982
+ h('div', { className: 'adp-modal-section' },
1983
+ h('div', { className: 'adp-modal-section-title' }, '人物特征'),
1984
+ h(PersonaFields, { value: form, onChange: (v) => setForm(Object.assign({}, form, v)), columns: 2 })
1985
+ ),
1986
+ h('div', { className: 'adp-modal-section' },
1987
+ h('div', { className: 'adp-modal-section-title' }, '细节'),
1988
+ h('div', { className: 'adp-field-grid g2' },
1989
+ h(Field, { label: '具体年龄', hint: '可选,精确控制人物年龄' }, h('input', { className: 'adp-input', type: 'number', value: form.exact_age || '', onChange: (e) => set('exact_age', e.currentTarget.value ? Number(e.currentTarget.value) : '') })),
1990
+ h(Field, { label: '身高 cm', hint: '可选,用于保持人物比例' }, h('input', { className: 'adp-input', type: 'number', value: form.height_cm || '', onChange: (e) => set('height_cm', e.currentTarget.value ? Number(e.currentTarget.value) : '') }))
1991
+ )
1992
+ ),
1993
+ h('div', { className: 'adp-modal-section' },
1994
+ h('div', { className: 'adp-modal-section-title' }, '风格与声线'),
1995
+ h('div', { className: 'adp-field-grid g2' },
1996
+ h(Field, { label: '发型' }, h('input', { className: 'adp-input', value: form.hair || '', placeholder: '例如:低马尾', onChange: (e) => set('hair', e.currentTarget.value) })),
1997
+ h(Field, { label: '服装' }, h('input', { className: 'adp-input', value: form.outfit || '', placeholder: '例如:米色针织衫', onChange: (e) => set('outfit', e.currentTarget.value) })),
1998
+ h(Field, { label: '气质' }, h('input', { className: 'adp-input', value: form.temperament || '', placeholder: '例如:松弛、生活化', onChange: (e) => set('temperament', e.currentTarget.value) })),
1999
+ h(Field, { label: '声线' }, h('input', { className: 'adp-input', value: form.voice_tone || '', placeholder: '例如:偏低、语速快', onChange: (e) => set('voice_tone', e.currentTarget.value) }))
2000
+ )
2001
+ ),
2002
+ form.type === 'real' ? h('label', { className: 'adp-check' }, h('input', { type: 'checkbox', checked: Boolean(form.consent && form.consent.confirmed), onChange: (e) => set('consent', { confirmed: e.currentTarget.checked, note: '模特库手动确认' }) }), '我确认已取得该真人的肖像/声音使用授权') : null,
2003
+ err ? h('div', { className: 'adp-error' }, err) : null
2004
+ ),
2005
+ h('div', { className: 'adp-modal-foot' },
2006
+ h('button', { className: 'adp-btn ghost', onClick: close }, '取消'),
2007
+ h('button', { className: 'adp-btn primary', onClick: save, disabled: busy === 'save' }, busy === 'save' ? '保存中…' : (editingId ? '保存修改' : '创建模特'))
2008
+ )
2009
+ )
2010
+ ) : null
2011
+ )
2012
+ }
2013
+
2014
+ function SettingsTab({ health, models, assets, onRefresh, engine }) {
2015
+ const [engineBusy, setEngineBusy] = useState(false)
2016
+ const [keys, setKeys] = useState([])
2017
+ const [values, setValues] = useState({})
2018
+ const [openModels, setOpenModels] = useState({})
2019
+ const [busy, setBusy] = useState('')
2020
+ const [err, setErr] = useState('')
2021
+ const [notice, setNotice] = useState('')
2022
+ const [refreshing, setRefreshing] = useState(false)
2023
+ useEffect(() => {
2024
+ api('/settings/keys').then((d) => setKeys(d.keys || [])).catch((e) => setErr(String(e.message || e)))
2025
+ }, [])
2026
+ const providers = [
2027
+ { id: 'minimax', name: 'MiniMax', key: 'MINIMAX_API_KEY', desc: 'H3 原生对白 / Hailuo 图生视频 / H3 Image' },
2028
+ { id: 'ark', name: '火山方舟', key: 'ARK_API_KEY', desc: 'Seedance 2.5 / 2.0 · Seedream 4.0' },
2029
+ { id: 'kling', name: 'Kling 可灵', key: 'KLING_API_KEY', desc: 'Kling v3 原生音频' },
2030
+ ]
2031
+ const statusFor = (name) => (keys || []).find((k) => k.name === name) || { present: false, masked: '' }
2032
+ const modelsFor = (provider) => (models || []).filter((m) => m.provider === provider)
2033
+ const save = async (name, override) => {
2034
+ const value = override === undefined ? (values[name] || '') : override
2035
+ setBusy(name); setErr(''); setNotice('')
2036
+ try {
2037
+ const data = await api('/settings/keys', { method: 'POST', body: { name, value } })
2038
+ setKeys(data.keys || [])
2039
+ setValues((prev) => Object.assign({}, prev, { [name]: '' }))
2040
+ setOpenModels((prev) => Object.assign({}, prev, { [name]: true }))
2041
+ await onRefresh()
2042
+ setNotice(value ? '已保存,已自动刷新该厂商模型' : '已清除该厂商 key,模型状态已刷新')
2043
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
2044
+ }
2045
+ const refresh = async () => {
2046
+ setRefreshing(true); setErr(''); setNotice('')
2047
+ try { await onRefresh(); setNotice('模型列表已刷新') } catch (e) { setErr(String(e.message || e)) } finally { setRefreshing(false) }
2048
+ }
2049
+ const otherModels = (models || []).filter((m) => !providers.some((p) => p.id === m.provider))
2050
+ const enabledModels = (models || []).filter((m) => m.enabled !== false).map((m) => m.id)
2051
+ const saveEnabled = async (ids, label) => {
2052
+ setBusy('models'); setErr(''); setNotice('')
2053
+ try {
2054
+ await api('/settings/models', { method: 'POST', body: { enabled: ids } })
2055
+ await onRefresh()
2056
+ setNotice(label || '模型启用状态已更新')
2057
+ } catch (e) { setErr(String(e.message || e)) } finally { setBusy('') }
2058
+ }
2059
+ const toggleModel = (model) => {
2060
+ const checked = model.enabled === false
2061
+ const next = checked ? enabledModels.concat(model.id) : enabledModels.filter((id) => id !== model.id)
2062
+ saveEnabled(next, (checked ? '已启用 ' : '已停用 ') + model.label)
2063
+ }
2064
+ const toggleProvider = (providerModels) => {
2065
+ const ids = providerModels.map((m) => m.id)
2066
+ const all = ids.every((id) => enabledModels.includes(id))
2067
+ const next = all ? enabledModels.filter((id) => !ids.includes(id)) : Array.from(new Set(enabledModels.concat(ids)))
2068
+ saveEnabled(next, all ? '已停用该厂商模型' : '已启用该厂商模型')
2069
+ }
2070
+ return h('div', { className: 'adp-page adp-settings-page' },
2071
+ h('div', { className: 'adp-page-head' },
2072
+ h('div', null,
2073
+ h('div', { className: 'adp-eyebrow' }, 'SETTINGS / MODELS'),
2074
+ h('h1', { className: 'adp-title' }, '设置与模型'),
2075
+ h('p', { className: 'adp-lede' }, '视频与图片模型;勾选后才会出现在生成页。文本模型由 DSH 提供,在创作页选择。')
2076
+ ),
2077
+ h('div', { className: 'adp-row' }, health ? h(Badge, { status: health.ok ? 'ok' : 'bad' }, health.ok ? '引擎在线' : '引擎离线') : null, h('button', { className: 'adp-btn', onClick: refresh, disabled: refreshing }, refreshing ? '刷新中…' : '刷新模型'), h('button', { className: 'adp-btn ghost', onClick: async () => { try { await api('/reveal', { method: 'POST', body: { path: '' } }) } catch (e) { setErr(String(e.message || e)) } } }, '打开数据文件夹'))
2078
+ ),
2079
+ health ? h('div', { className: 'adp-small adp-muted', style: { marginBottom: 14 } }, '服务:' + (health.service || '—') + ' · 数据:' + (health.data || '—') + ' · 运行:' + (health.runs ?? '—')) : null,
2080
+ h('div', { className: 'adp-card adp-col', style: { margin: '4px 0 8px' } },
2081
+ h('div', { className: 'adp-row' },
2082
+ h('div', { className: 'adp-h2 adp-grow' }, '引擎运行时'),
2083
+ engine
2084
+ ? h(Badge, { status: engine.ok ? 'ok' : ((engine.boot && engine.boot.stage === 'preparing') ? 'warn' : 'bad') }, engine.ok ? '在线' : engineStageLabel(engine))
2085
+ : h(Badge, null, '未连接')
2086
+ ),
2087
+ h('div', { className: 'adp-small adp-muted' }, engine ? (engine.detail || '—') : '尚未拿到 Host 状态'),
2088
+ engine && engine.ok ? h('div', { className: 'adp-small adp-faint', style: { marginTop: 3 } }, '端口 ' + (engine.port || '—') + ' · 解释器 ' + (engine.python || '—') + (engine.boot && engine.boot.source ? ' · ' + engine.boot.source : '')) : null,
2089
+ health && health.deps && health.deps.ok === false ? h('div', { className: 'adp-small adp-error', style: { marginTop: 4 } }, health.deps.hint) : null,
2090
+ h('div', { className: 'adp-row', style: { marginTop: 8 } },
2091
+ h('button', { className: 'adp-btn', disabled: engineBusy, onClick: async () => { setEngineBusy(true); setErr(''); try { await restartEngineHost(); setNotice('已请求重新启动引擎,状态会自动刷新') } catch (e) { setErr(String(e.message || e)) } finally { setEngineBusy(false) } } }, engineBusy ? '重启中…' : '重新启动引擎'),
2092
+ h('span', { className: 'adp-small adp-muted' }, '首次启动会在数据目录里准备 Python 依赖,约 1 分钟')
2093
+ )
2094
+ ),
2095
+ h('div', { className: 'adp-section-head', style: { marginTop: 20 } }, h('span', { className: 'adp-step' }, '01'), h('span', { className: 'adp-section-title' }, '视频服务商'), h('span', { className: 'adp-section-note' }, '勾选后才会出现在生成页')),
2096
+ h('div', { className: 'adp-provider-grid' }, providers.map((p) => {
2097
+ const st = statusFor(p.key)
2098
+ const providerModels = modelsFor(p.id)
2099
+ const enabledProviderModels = providerModels.filter((m) => m.enabled !== false)
2100
+ const openModelsForProvider = Boolean(openModels[p.key])
2101
+ return h('section', { key: p.id, className: 'adp-provider-card' + (st.present ? ' configured' : '') },
2102
+ h('div', { className: 'adp-provider-head' },
2103
+ h('div', null, h('div', { className: 'adp-provider-name' }, p.name), h('div', { className: 'adp-small adp-muted' }, p.desc)),
2104
+ h('div', { className: 'adp-row', style: { gap: 6 } },
2105
+ st.present ? h(Badge, { status: 'ok' }, '已配置') : h(Badge, null, '未配置'),
2106
+ providerModels.length ? h('button', { className: 'adp-btn ghost', disabled: busy === 'models', onClick: () => toggleProvider(providerModels), title: '切换该厂商全部模型' }, providerModels.every((m) => m.enabled !== false) ? '全不选' : '全选') : null
2107
+ )
2108
+ ),
2109
+ h('div', { className: 'adp-keyrow' },
2110
+ h('input', { className: 'adp-input adp-grow', type: 'password', value: values[p.key] || '', placeholder: st.present ? '输入新 key 可替换;留空保存会清除' : '粘贴 ' + p.key, onChange: (e) => { const value = e.currentTarget.value; setValues((prev) => Object.assign({}, prev, { [p.key]: value })) } }),
2111
+ h('button', { className: 'adp-btn primary', onClick: () => save(p.key), disabled: busy === p.key }, busy === p.key ? '保存中…' : '保存'),
2112
+ st.present ? h('button', { className: 'adp-btn ghost', onClick: () => save(p.key, ''), disabled: busy === p.key, title: '移除该厂商 key' }, '清除') : null
2113
+ ),
2114
+ st.present ? h('div', { className: 'adp-small adp-muted' }, '已配置:' + st.masked) : h('div', { className: 'adp-small adp-muted' }, '填入 key 后自动加载该厂商模型'),
2115
+ h('button', { className: 'adp-models-toggle', onClick: () => setOpenModels((prev) => Object.assign({}, prev, { [p.key]: !openModelsForProvider })) },
2116
+ h('span', { className: 'adp-models-toggle-title' }, '模型 ' + providerModels.length),
2117
+ h('span', { className: 'adp-small adp-muted' }, '已启用 ' + enabledProviderModels.length + ' / ' + providerModels.length),
2118
+ h('span', { className: 'adp-models-toggle-action' }, openModelsForProvider ? '收起' : '展开')
2119
+ ),
2120
+ !openModelsForProvider && enabledProviderModels.length ? h('div', { className: 'adp-model-summary' }, enabledProviderModels.map((m) => h('span', { key: m.id, className: 'adp-model-summary-chip' }, m.label))) : null,
2121
+ openModelsForProvider ? h('div', { className: 'adp-provider-models' },
2122
+ providerModels.length ? providerModels.map((m) => h('div', { key: m.id, className: 'adp-provider-model' + (m.available ? ' on' : '') + (m.enabled === false ? ' off' : '') },
2123
+ h('div', null, h('div', { className: 'adp-provider-model-name' }, m.label), h(CapabilityChips, { row: m })),
2124
+ h('div', { className: 'adp-row', style: { gap: 5 } }, m.available ? h(Badge, { status: 'ok' }, '可用') : h(Badge, { title: m.reason || '' }, '待 key'), m.native_audio ? h('span', { className: 'adp-small adp-muted' }, '原生对白') : null, h('label', { className: 'adp-model-enable' }, h('input', { type: 'checkbox', checked: m.enabled !== false, disabled: busy === 'models', onChange: () => toggleModel(m), title: '是否出现在生成页' }), '启用'))
2125
+ )) : h('div', { className: 'adp-small adp-muted' }, '该厂商暂无可展示模型;保存 key 后刷新。')
2126
+ ) : null
2127
+ )
2128
+ })),
2129
+ notice ? h('div', { className: 'adp-notice' }, notice) : null,
2130
+ err ? h('div', { className: 'adp-error', style: { marginTop: 10 } }, err) : null,
2131
+ h('div', { className: 'adp-section-head', style: { marginTop: 20 } }, h('span', { className: 'adp-step' }, '02'), h('span', { className: 'adp-section-title' }, '其他模型'), h('span', { className: 'adp-section-note' }, '未接入或可选通道')),
2132
+ h('table', { className: 'adp-table' }, h('thead', null, h('tr', null, h('th', null, '模型'), h('th', null, '能力'), h('th', null, '状态'), h('th', null, '启用'))), h('tbody', null, otherModels.map((m) => h('tr', { key: m.id }, h('td', null, m.label), h('td', null, h(CapabilityChips, { row: m })), h('td', null, h(Badge, { title: m.reason || '' }, '未接入')), h('td', null, h('label', { className: 'adp-model-enable' }, h('input', { type: 'checkbox', checked: m.enabled !== false, disabled: busy === 'models', onChange: () => toggleModel(m) }), '启用')))))),
2133
+ h('div', { className: 'adp-hint', style: { marginTop: 12 } }, '密钥只保存在本机数据目录的 settings.json(权限 0600);不会回显完整值。生产版应迁移到系统 Keychain。')
2134
+ )
2135
+ }
2136
+
2137
+ class AdClipBoundary extends React.Component {
2138
+ constructor(props) {
2139
+ super(props)
2140
+ this.state = { error: null }
2141
+ }
2142
+ static getDerivedStateFromError(error) {
2143
+ return { error: error }
2144
+ }
2145
+ componentDidCatch(error, info) {
2146
+ try { console.error('AdClip UI crashed', error, info) } catch { /* noop */ }
2147
+ }
2148
+ render() {
2149
+ if (this.state.error) {
2150
+ return h('div', { className: 'adp-root' },
2151
+ h('style', null, CSS),
2152
+ h('div', { className: 'adp-crash' },
2153
+ h('div', { className: 'box' },
2154
+ h('h3', null, 'AdClip UI 加载失败'),
2155
+ h('div', null, String(this.state.error && (this.state.error.stack || this.state.error.message || this.state.error))),
2156
+ h('div', { style: { marginTop: 12 } }, h('button', { className: 'adp-btn', onClick: () => location.reload() }, '重新加载'))
2157
+ )
2158
+ )
2159
+ )
2160
+ }
2161
+ return this.props.children
2162
+ }
2163
+ }
2164
+
2165
+ function App() {
2166
+ const [tab, setTab] = useState('recreate')
2167
+ const [health, setHealth] = useState(null)
2168
+ const [models, setModels] = useState([])
2169
+ const [dsh, setDsh] = useState(null)
2170
+ const [runs, setRuns] = useState([])
2171
+ const [assets, setAssets] = useState([])
2172
+ const [personas, setPersonas] = useState([])
2173
+ const [selected, setSelected] = useState(null)
2174
+ const [err, setErr] = useState('')
2175
+ const [engine, setEngine] = useState(null)
2176
+
2177
+ const refresh = useCallback(async () => {
2178
+ const state = await hostStatus()
2179
+ if (state) setEngine(state)
2180
+ if (state && !state.ok) return
2181
+ try {
2182
+ const [h, m, r, a, p, d] = await Promise.all([api('/health'), api('/models'), api('/runs?limit=20'), api('/assets?limit=60'), api('/personas'), api('/dsh/models').catch(() => ({ dsh: null }))])
2183
+ setHealth(h); setModels(m.models || []); setRuns(r.runs || []); setAssets(a.assets || []); setPersonas(p.personas || []); setDsh(d.dsh || null)
2184
+ setSelected(prev => prev ? (r.runs || []).find(x => x.id === prev.id) || prev : null)
2185
+ } catch (e) { setErr(String(e.message || e)) }
2186
+ }, [])
2187
+
2188
+ useEffect(() => { void refresh() }, [refresh])
2189
+ // The supervisor answers even while the engine is still being prepared,
2190
+ // which is exactly when the page needs to explain what is happening.
2191
+ useEffect(() => {
2192
+ let alive = true
2193
+ const load = async () => { const next = await hostStatus(); if (alive) setEngine(next) }
2194
+ void load()
2195
+ const timer = setInterval(load, 2500)
2196
+ return () => { alive = false; clearInterval(timer) }
2197
+ }, [])
2198
+ useEffect(() => {
2199
+ if (!selected || (selected.status !== 'running' && selected.status !== 'queued')) return
2200
+ const timer = setInterval(async () => {
2201
+ try { const d = await api('/runs/' + selected.id); setSelected(d.run); setRuns(prev => prev.map(x => x.id === d.run.id ? d.run : x)) } catch (e) { setErr(String(e.message || e)) }
2202
+ }, 2000)
2203
+ return () => clearInterval(timer)
2204
+ }, [selected && selected.id, selected && selected.status])
2205
+
2206
+ // One catalogue, two views: generation pages filter on kind + capability.
2207
+ const videoModels = (models || []).filter((m) => m.kind === 'video')
2208
+ const imageModels = (models || []).filter((m) => m.kind === 'image')
2209
+
2210
+ const openRun = (run) => { setSelected(run) }
2211
+ const started = (run) => { setSelected(run); void refresh() }
2212
+
2213
+ return h('div', { className: 'adp-root' },
2214
+ h('style', null, CSS),
2215
+ h('div', { className: 'adp-top' },
2216
+ h('div', { className: 'adp-brand' }, 'AdClip'),
2217
+ h('div', { className: 'adp-sub' }, 'AI AD VIDEO STUDIO'),
2218
+ h('div', { className: 'adp-tabs' },
2219
+ ['recreate', 'text', 'assets', 'personas', 'tasks', 'settings'].map(id => h('button', { key: id, className: 'adp-tab' + (tab === id ? ' on' : ''), onClick: () => { setTab(id); setSelected(null) } }, { recreate: '爆款复刻', text: '自由创作', assets: '素材', personas: '模特', tasks: '任务', settings: '设置' }[id]))
2220
+ ),
2221
+ h('div', { className: 'adp-grow' }),
2222
+ engine
2223
+ ? h(Badge, { status: engine.ok ? 'ok' : ((engine.boot && engine.boot.stage === 'preparing') ? 'warn' : 'bad') }, engine.ok ? '引擎在线' : '引擎' + engineStageLabel(engine))
2224
+ : (health ? h(Badge, { status: health.ok ? 'ok' : 'bad' }, health.ok ? '引擎在线' : '引擎离线') : h(Badge, null, '连接中…'))
2225
+ ),
2226
+ h('div', { className: 'adp-body' },
2227
+ h('div', { className: 'adp-wrap' },
2228
+ engine && !engine.ok && engine.boot && (engine.boot.stage === 'preparing' || engine.boot.stage === 'failed')
2229
+ ? h('div', { className: engine.boot.stage === 'failed' ? 'adp-error' : 'adp-notice', style: { marginBottom: 10 } },
2230
+ engine.boot.stage === 'preparing'
2231
+ ? '引擎准备中:' + (engine.boot.detail || '正在安装 Python 依赖')
2232
+ : '引擎不可用:' + (engine.boot.detail || '未知原因') + '(可到「设置」里点「重新启动引擎」)'
2233
+ )
2234
+ : null,
2235
+ err ? h('div', { className: 'adp-error' }, err) : null,
2236
+ selected ? h(ResultPanel, { run: selected, onChanged: started, onBack: () => setSelected(null), assets }) : null,
2237
+ h('div', { style: { display: (!selected && tab === 'recreate') ? 'block' : 'none' } }, h(RecreateTab, { models: videoModels, dsh, onStarted: started, personas, onRefreshPersonas: refresh })),
2238
+ h('div', { style: { display: (!selected && tab === 'text') ? 'block' : 'none' } }, h(TextTab, { models: videoModels, dsh, imageModels, onStarted: started, assets, onRefreshAssets: refresh })),
2239
+ !selected && tab === 'assets' ? h(AssetsTab, { onRefresh: refresh }) : null,
2240
+ !selected && tab === 'personas' ? h(PersonasTab, { personas, onRefresh: refresh }) : null,
2241
+ !selected && tab === 'tasks' ? h(TasksTab, { onOpen: openRun }) : null,
2242
+ !selected && tab === 'settings' ? h(SettingsTab, { health, models, assets, onRefresh: refresh, engine }) : null,
2243
+ )
2244
+ )
2245
+ )
2246
+ }
2247
+
2248
+ return {
2249
+ inject: ['slots'],
2250
+ apply(ctx) {
2251
+ ctx.slots.inject('main', () => ctx.slots.register({ name: 'main', key: 'adplus' }, () => h(AdClipBoundary, null, h(App))))
2252
+ ctx.slots.inject('sidebar.panellist', () => ctx.slots.register({ name: 'sidebar.panellist', id: 'adplus', order: 30, label: () => 'AdClip' }, Icon))
2253
+ },
2254
+ }
2255
+ },
2256
+ })