@chad.dev/dsh-adclip 0.0.0-stage → 0.1.0

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