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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +4 -0
  3. package/README.md +28 -2
  4. package/client.js +2256 -0
  5. package/cordis.patch.yml +10 -0
  6. package/engine/requirements.txt +9 -0
  7. package/engine/src/adclip/__init__.py +0 -0
  8. package/engine/src/adclip/api.py +704 -0
  9. package/engine/src/adclip/catalog.py +341 -0
  10. package/engine/src/adclip/image_params.py +45 -0
  11. package/engine/src/adclip/intents.py +209 -0
  12. package/engine/src/adclip/llm.py +142 -0
  13. package/engine/src/adclip/media/__init__.py +0 -0
  14. package/engine/src/adclip/media/asr.py +79 -0
  15. package/engine/src/adclip/media/ffmpeg.py +294 -0
  16. package/engine/src/adclip/media/stitch.py +124 -0
  17. package/engine/src/adclip/media/subtitles.py +45 -0
  18. package/engine/src/adclip/media/vision.py +105 -0
  19. package/engine/src/adclip/models.py +127 -0
  20. package/engine/src/adclip/params.py +158 -0
  21. package/engine/src/adclip/personas.py +60 -0
  22. package/engine/src/adclip/pipeline/__init__.py +0 -0
  23. package/engine/src/adclip/pipeline/analyze.py +133 -0
  24. package/engine/src/adclip/pipeline/generate.py +196 -0
  25. package/engine/src/adclip/pipeline/image_runner.py +146 -0
  26. package/engine/src/adclip/pipeline/persona.py +56 -0
  27. package/engine/src/adclip/pipeline/post.py +40 -0
  28. package/engine/src/adclip/pipeline/qa.py +44 -0
  29. package/engine/src/adclip/pipeline/replace.py +191 -0
  30. package/engine/src/adclip/pipeline/runner.py +138 -0
  31. package/engine/src/adclip/pipeline/script.py +226 -0
  32. package/engine/src/adclip/pipeline/segment.py +87 -0
  33. package/engine/src/adclip/providers/__init__.py +0 -0
  34. package/engine/src/adclip/providers/ark.py +122 -0
  35. package/engine/src/adclip/providers/ark_image.py +114 -0
  36. package/engine/src/adclip/providers/base.py +30 -0
  37. package/engine/src/adclip/providers/discovery.py +56 -0
  38. package/engine/src/adclip/providers/kling.py +101 -0
  39. package/engine/src/adclip/providers/minimax.py +155 -0
  40. package/engine/src/adclip/providers/minimax_image.py +89 -0
  41. package/engine/src/adclip/settings.py +109 -0
  42. package/engine/src/adclip/store.py +378 -0
  43. package/host/dsh.js +60 -0
  44. package/host/engine.js +265 -0
  45. package/host/proxy.js +142 -0
  46. package/host/supervisor.js +251 -0
  47. package/icon.svg +6 -0
  48. package/index.js +39 -0
  49. package/locale/en.json +12 -0
  50. package/locale/zh.json +12 -0
  51. package/package.json +47 -4
@@ -0,0 +1,341 @@
1
+ """One catalogue for every model the plugin can drive.
2
+
3
+ Each row declares what it is (`kind`), what it can do (`capabilities`), what it
4
+ costs to be usable (`requires`), and how it is parameterised. Generation pages
5
+ filter on `capabilities`; nothing in the UI or the pipeline matches model ids.
6
+
7
+ Capability vocabulary (fixed):
8
+ video: text_to_video, image_to_video, reference_to_video
9
+ image: text_to_image, image_to_image
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import os
14
+ import time
15
+ from typing import Any
16
+
17
+ from . import settings
18
+
19
+ VIDEO_CAPABILITIES = ("text_to_video", "image_to_video", "reference_to_video")
20
+ IMAGE_CAPABILITIES = ("text_to_image", "image_to_image")
21
+
22
+ VIDEO_ROWS: list[dict[str, Any]] = [
23
+ {
24
+ "id": "ark.seedance-2.5",
25
+ "kind": "video",
26
+ "provider": "ark",
27
+ "model": "doubao-seedance-2-5-260628",
28
+ "label": "Seedance 2.5(火山方舟)",
29
+ "capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
30
+ "native_audio": True,
31
+ "durations": [4, 5, 8, 10, 12, 15, 30],
32
+ "resolutions": ["480p", "720p"],
33
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
34
+ "max_duration_s": 30,
35
+ "requires": ["ARK_API_KEY"],
36
+ "adapter_ready": True,
37
+ "tags": ["中文对白首选", "原生音频"],
38
+ "reason": "未配置 ARK_API_KEY",
39
+ },
40
+ {
41
+ "id": "ark.seedance-2.0",
42
+ "kind": "video",
43
+ "provider": "ark",
44
+ "model": "doubao-seedance-2-0-260128",
45
+ "label": "Seedance 2.0(火山方舟)",
46
+ "capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
47
+ "native_audio": True,
48
+ "durations": [4, 5, 8, 10, 12, 15],
49
+ "resolutions": ["480p", "720p", "1080p"],
50
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
51
+ "max_duration_s": 15,
52
+ "requires": ["ARK_API_KEY"],
53
+ "adapter_ready": True,
54
+ "tags": ["原生音频", "中文"],
55
+ "reason": "未配置 ARK_API_KEY",
56
+ },
57
+ {
58
+ "id": "ark.seedance-2.0-mini",
59
+ "kind": "video",
60
+ "provider": "ark",
61
+ "model": "doubao-seedance-2-0-mini-260615",
62
+ "label": "Seedance 2.0 Mini(火山方舟)",
63
+ "capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
64
+ "native_audio": True,
65
+ "durations": [4, 5, 8, 10, 12, 15],
66
+ "resolutions": ["480p", "720p", "1080p"],
67
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
68
+ "max_duration_s": 15,
69
+ "requires": ["ARK_API_KEY"],
70
+ "adapter_ready": True,
71
+ "tags": ["Mini", "原生音频", "已实测"],
72
+ "reason": "未配置 ARK_API_KEY",
73
+ },
74
+ {
75
+ "id": "ark.seedance-2.0-fast",
76
+ "kind": "video",
77
+ "provider": "ark",
78
+ "model": "doubao-seedance-2-0-fast-260128",
79
+ "label": "Seedance 2.0 Fast(火山方舟)",
80
+ "capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
81
+ "native_audio": True,
82
+ "durations": [4, 5, 8, 10, 12, 15],
83
+ "resolutions": ["480p", "720p", "1080p"],
84
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
85
+ "max_duration_s": 15,
86
+ "requires": ["ARK_API_KEY"],
87
+ "adapter_ready": True,
88
+ "tags": ["Fast", "原生音频", "已实测"],
89
+ "reason": "未配置 ARK_API_KEY",
90
+ },
91
+ {
92
+ "id": "kling.v3",
93
+ "kind": "video",
94
+ "provider": "kling",
95
+ "model": "kling-v3",
96
+ "label": "Kling v3(可灵)",
97
+ "capabilities": ["text_to_video", "image_to_video", "reference_to_video"],
98
+ "native_audio": True,
99
+ "durations": [3, 5, 8, 10, 12, 15],
100
+ "resolutions": ["720p", "1080p"],
101
+ "aspects": ["9:16", "16:9", "1:1"],
102
+ "max_duration_s": 15,
103
+ "requires": ["KLING_API_KEY"],
104
+ "adapter_ready": True,
105
+ "tags": ["1080p 候选", "原生音频"],
106
+ "reason": "未配置 KLING_API_KEY",
107
+ },
108
+ {
109
+ "id": "minimax.hailuo-2.3-fast",
110
+ "kind": "video",
111
+ "provider": "minimax",
112
+ "model": "MiniMax-Hailuo-2.3-Fast",
113
+ "label": "MiniMax Hailuo 2.3 Fast(图生视频)",
114
+ "capabilities": ["image_to_video"],
115
+ "native_audio": False,
116
+ "durations": [6, 10],
117
+ "resolutions": ["768P", "1080P"],
118
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
119
+ "max_duration_s": 10,
120
+ "requires": ["MINIMAX_API_KEY"],
121
+ "adapter_ready": True,
122
+ "tags": ["图生视频已验证", "无原生音频"],
123
+ "reason": "未配置 MINIMAX_API_KEY",
124
+ },
125
+ {
126
+ "id": "minimax.h3",
127
+ "kind": "video",
128
+ "provider": "minimax",
129
+ "model": "MiniMax-H3",
130
+ "label": "MiniMax H3(2K · 原生对白)",
131
+ "capabilities": ["text_to_video", "image_to_video"],
132
+ "native_audio": True,
133
+ "durations": [4, 5, 6, 8, 10, 12, 15],
134
+ "resolutions": ["2K"],
135
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
136
+ "max_duration_s": 15,
137
+ "requires": ["MINIMAX_API_KEY"],
138
+ "adapter_ready": True,
139
+ "tags": ["2K", "中文原生对白已验证"],
140
+ "reason": "未配置 MINIMAX_API_KEY",
141
+ },
142
+ {
143
+ "id": "volcengine.jimeng-3.0",
144
+ "kind": "video",
145
+ "provider": "volcengine",
146
+ "model": "jimeng_ti2v_v30_pro",
147
+ "label": "火山引擎即梦 3.0 Pro",
148
+ "capabilities": ["text_to_video", "image_to_video"],
149
+ "native_audio": False,
150
+ "durations": [5, 10],
151
+ "resolutions": ["720p", "1080p"],
152
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
153
+ "max_duration_s": 10,
154
+ "requires": ["VOLC_ACCESSKEY", "VOLC_SECRETKEY"],
155
+ "adapter_ready": False,
156
+ "tags": ["无原生对白"],
157
+ "reason": "适配器未接入",
158
+ },
159
+ {
160
+ "id": "veo.3.1",
161
+ "kind": "video",
162
+ "provider": "fal",
163
+ "model": "veo-3.1-generate-001",
164
+ "label": "Veo 3.1(可选)",
165
+ "capabilities": ["text_to_video", "image_to_video"],
166
+ "native_audio": True,
167
+ "durations": [8],
168
+ "resolutions": ["720p", "1080p"],
169
+ "aspects": ["9:16", "16:9"],
170
+ "max_duration_s": 8,
171
+ "requires": ["FAL_KEY"],
172
+ "adapter_ready": False,
173
+ "tags": ["海外", "原生音频"],
174
+ "reason": "适配器未接入",
175
+ },
176
+ {
177
+ "id": "sora.2",
178
+ "kind": "video",
179
+ "provider": "fal",
180
+ "model": "sora-2",
181
+ "label": "Sora 2(可选)",
182
+ "capabilities": ["text_to_video", "image_to_video"],
183
+ "native_audio": True,
184
+ "durations": [10, 15],
185
+ "resolutions": ["720p"],
186
+ "aspects": ["9:16", "16:9"],
187
+ "max_duration_s": 15,
188
+ "requires": ["FAL_KEY", "OPENAI_API_KEY"],
189
+ "adapter_ready": False,
190
+ "tags": ["海外", "原生音频"],
191
+ "reason": "适配器未接入",
192
+ },
193
+ ]
194
+
195
+ IMAGE_ROWS: list[dict[str, Any]] = [
196
+ {
197
+ "id": "minimax.h3-image",
198
+ "kind": "image",
199
+ "provider": "minimax",
200
+ "model": "MiniMax-H3-Image",
201
+ "label": "MiniMax H3 Image",
202
+ "capabilities": ["text_to_image"],
203
+ "aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
204
+ "areas": ["1K", "2K", "4K"],
205
+ "default_area": "2K",
206
+ "requires": ["MINIMAX_API_KEY"],
207
+ "adapter_ready": True,
208
+ "tags": ["文生图"],
209
+ "reason": "未配置 MINIMAX_API_KEY",
210
+ },
211
+ {
212
+ "id": "minimax.h3-image-highspeed",
213
+ "kind": "image",
214
+ "provider": "minimax",
215
+ "model": "MiniMax-H3-Image-Highspeed",
216
+ "label": "MiniMax H3 Image Highspeed",
217
+ "capabilities": ["text_to_image"],
218
+ "aspects": ["1:1", "3:4", "4:3", "9:16", "16:9"],
219
+ "areas": ["1K", "2K", "4K"],
220
+ "default_area": "2K",
221
+ "requires": ["MINIMAX_API_KEY"],
222
+ "adapter_ready": True,
223
+ "tags": ["文生图", "快速"],
224
+ "reason": "未配置 MINIMAX_API_KEY",
225
+ },
226
+ {
227
+ "id": "ark.seedream-4.0",
228
+ "kind": "image",
229
+ "provider": "ark",
230
+ "model": "doubao-seedream-4-0-20260415",
231
+ "label": "Doubao-Seedream 4.0(火山方舟)",
232
+ "capabilities": ["text_to_image", "image_to_image"],
233
+ "aspects": ["1:1", "4:3", "3:4", "16:9", "9:16"],
234
+ "areas": ["1K", "2K", "4K"],
235
+ "default_area": "2K",
236
+ "requires": ["ARK_API_KEY"],
237
+ "adapter_ready": True,
238
+ "tags": ["4K", "参考图生图已验证", "中文提示"],
239
+ "reason": "未配置 ARK_API_KEY",
240
+ },
241
+ ]
242
+
243
+ TEST_ROW: dict[str, Any] = {
244
+ "id": "test.synthetic",
245
+ "kind": "video",
246
+ "provider": "synthetic",
247
+ "model": "synthetic",
248
+ "label": "Synthetic(测试)",
249
+ "capabilities": list(VIDEO_CAPABILITIES),
250
+ "native_audio": True,
251
+ "durations": [4, 5, 6, 8, 10, 12, 15, 30],
252
+ "resolutions": ["480p", "720p", "1080p"],
253
+ "aspects": ["9:16", "16:9", "1:1", "4:3", "3:4", "21:9"],
254
+ "max_duration_s": 30,
255
+ "requires": [],
256
+ "adapter_ready": True,
257
+ "tags": ["测试"],
258
+ "reason": "",
259
+ }
260
+
261
+
262
+ def test_mode() -> bool:
263
+ return os.environ.get("ADCLIP_TEST_MODE", "").strip() == "1"
264
+
265
+
266
+ def base_rows() -> list[dict[str, Any]]:
267
+ rows = [*VIDEO_ROWS, *IMAGE_ROWS]
268
+ if test_mode():
269
+ rows.append(TEST_ROW)
270
+ return rows
271
+
272
+
273
+ def evaluate(row: dict[str, Any], enabled_ids: list[str] | None = None, kind_has_ids: dict[str, bool] | None = None) -> dict[str, Any]:
274
+ """Live view of one row: keys present, usable, enabled, short reason.
275
+
276
+ `enabled_ids` is the saved preference list; `None` means "no preference file
277
+ yet". A kind with no saved ids at all stays enabled, so a prefs file written
278
+ before that kind existed does not hide it.
279
+ """
280
+ item = dict(row)
281
+ item.setdefault("capabilities", [])
282
+ if item["kind"] == "video":
283
+ item["modes"] = list(item["capabilities"])
284
+ requires = [str(name) for name in item.get("requires") or []]
285
+ item["key_present"] = all(bool(os.environ.get(name, "").strip()) for name in requires)
286
+ item["available"] = bool(item.get("adapter_ready", True)) and (not requires or item["key_present"])
287
+ if not item.get("adapter_ready", True):
288
+ item["reason"] = "适配器未接入"
289
+ elif requires and not item["key_present"]:
290
+ item["reason"] = "未配置 " + " / ".join(requires)
291
+ else:
292
+ item["reason"] = str(item.get("reason") or "")
293
+ if enabled_ids is None:
294
+ item["enabled"] = True
295
+ elif kind_has_ids is not None and not kind_has_ids.get(item["kind"], False):
296
+ item["enabled"] = True
297
+ else:
298
+ item["enabled"] = item["id"] in enabled_ids
299
+ item["checked_at"] = time.strftime("%Y-%m-%dT%H:%M:%S%z")
300
+ return item
301
+
302
+
303
+ def rows() -> list[dict[str, Any]]:
304
+ """Every model with live availability and enablement."""
305
+ enabled_ids = settings.enabled_models()
306
+ base = base_rows()
307
+ kind_has_ids = {
308
+ kind: any(row["id"] in (enabled_ids or []) for row in base if row["kind"] == kind)
309
+ for kind in {row["kind"] for row in base}
310
+ }
311
+ return [evaluate(row, enabled_ids, kind_has_ids) for row in base]
312
+
313
+
314
+ def for_kind(kind: str) -> list[dict[str, Any]]:
315
+ return [row for row in rows() if row["kind"] == kind]
316
+
317
+
318
+ def get(model_id: str) -> dict[str, Any] | None:
319
+ for row in rows():
320
+ if row["id"] == model_id:
321
+ return row
322
+ return None
323
+
324
+
325
+ def with_capability(capability: str, *, kind: str = "", usable: bool = False) -> list[dict[str, Any]]:
326
+ rows_ = [row for row in rows() if capability in row["capabilities"]]
327
+ if kind:
328
+ rows_ = [row for row in rows_ if row["kind"] == kind]
329
+ if usable:
330
+ rows_ = [row for row in rows_ if row["available"] and row["enabled"]]
331
+ return rows_
332
+
333
+
334
+ def default_model(kind: str, capability: str = "") -> str:
335
+ for row in rows():
336
+ if row["kind"] != kind or not row["available"] or not row["enabled"]:
337
+ continue
338
+ if capability and capability not in row["capabilities"]:
339
+ continue
340
+ return row["id"]
341
+ return ""
@@ -0,0 +1,45 @@
1
+ """Image-model view over the shared catalogue.
2
+
3
+ Image rows live in `catalog.py` next to the video rows; this module keeps the
4
+ image-shaped helpers the image pipeline imports.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ from typing import Any
9
+
10
+ from . import catalog as model_catalog
11
+
12
+
13
+ def catalog_rows() -> list[dict[str, Any]]:
14
+ return model_catalog.for_kind("image")
15
+
16
+
17
+ def catalog() -> list[dict[str, Any]]:
18
+ return model_catalog.for_kind("image")
19
+
20
+
21
+ def get_model(model_id: str) -> dict[str, Any] | None:
22
+ row = model_catalog.get(model_id)
23
+ return row if row and row["kind"] == "image" else None
24
+
25
+
26
+ def default_model() -> str:
27
+ return model_catalog.default_model("image", "text_to_image")
28
+
29
+
30
+ def size_for(area: str, aspect: str) -> str:
31
+ """Pixel size for providers that take explicit dimensions, not presets.
32
+
33
+ The short edge follows the area (1K/2K/4K); the other edge keeps the aspect
34
+ ratio and lands on a multiple of 16, which every image API we target accepts.
35
+ """
36
+ short = {"1K": 1024, "2K": 2048, "4K": 4096}.get(str(area).upper(), 2048)
37
+ ratios = {"1:1": (1, 1), "4:3": (4, 3), "3:4": (3, 4), "16:9": (16, 9), "9:16": (9, 16)}
38
+ width_units, height_units = ratios.get(aspect, (1, 1))
39
+ if width_units >= height_units:
40
+ width = short
41
+ height = round(short * height_units / width_units / 16) * 16
42
+ else:
43
+ height = short
44
+ width = round(short * width_units / height_units / 16) * 16
45
+ return f"{max(16, width)}x{max(16, height)}"
@@ -0,0 +1,209 @@
1
+ """Rule-first assistant changes.
2
+
3
+ The assistant is deliberately a form copilot: it returns changes, never starts
4
+ a run. The common phrases from the operator playbook are handled here.
5
+ """
6
+ from __future__ import annotations
7
+
8
+ import re
9
+ from typing import Any
10
+
11
+ from . import catalog
12
+ from .models import AssistantRequest
13
+
14
+
15
+ def _change(field: str, old: Any, new: Any, stage: str, label: str) -> dict[str, Any]:
16
+ return {
17
+ "field": field,
18
+ "from": old,
19
+ "to": new,
20
+ "stage": stage,
21
+ "requires_regeneration": stage == "generate",
22
+ "label": label,
23
+ }
24
+
25
+
26
+ def analyze(req: AssistantRequest) -> dict[str, Any]:
27
+ text = req.message.strip()
28
+ context = req.context or {}
29
+ advanced = dict(context.get("advanced") or {})
30
+ persona = dict(context.get("persona") or {})
31
+ post = dict(context.get("post") or {})
32
+ changes: list[dict[str, Any]] = []
33
+ questions: list[str] = []
34
+ actions: list[str] = []
35
+
36
+ # aspect
37
+ aspect = None
38
+ if re.search(r"横屏|16\s*[::]\s*9", text):
39
+ aspect = "16:9"
40
+ elif re.search(r"竖屏|9\s*[::]\s*16", text):
41
+ aspect = "9:16"
42
+ elif re.search(r"方形|1\s*[::]\s*1", text):
43
+ aspect = "1:1"
44
+ if aspect and aspect != advanced.get("aspect"):
45
+ changes.append(_change("advanced.aspect", advanced.get("aspect"), aspect, "generate", "比例"))
46
+ advanced["aspect"] = aspect
47
+
48
+ # resolution
49
+ resolution = None
50
+ if re.search(r"1080|高清", text):
51
+ resolution = "1080p"
52
+ elif re.search(r"720|标清", text):
53
+ resolution = "720p"
54
+ elif re.search(r"480|草稿", text):
55
+ resolution = "480p"
56
+ if resolution and resolution != advanced.get("resolution"):
57
+ changes.append(_change("advanced.resolution", advanced.get("resolution"), resolution, "generate", "清晰度"))
58
+ advanced["resolution"] = resolution
59
+
60
+ # duration
61
+ match = re.search(r"(\d+(?:\.\d+)?)\s*(?:秒|s|S)", text)
62
+ if match:
63
+ duration = int(round(float(match.group(1))))
64
+ duration = max(1, min(30, duration))
65
+ if duration != advanced.get("duration"):
66
+ changes.append(_change("advanced.duration", advanced.get("duration"), duration, "generate", "时长"))
67
+ advanced["duration"] = duration
68
+
69
+ # model: a vendor keyword selects that vendor's first usable model, never a
70
+ # hardcoded id, so new models from the same provider are picked up.
71
+ vendor = None
72
+ if re.search(r"可灵|kling", text, re.I):
73
+ vendor = "kling"
74
+ elif re.search(r"seedance|方舟|ark", text, re.I):
75
+ vendor = "ark"
76
+ elif re.search(r"minimax|海螺|hailuo", text, re.I):
77
+ vendor = "minimax"
78
+ if vendor:
79
+ candidate = next((row for row in catalog.rows()
80
+ if row["kind"] == "video" and row["provider"] == vendor
81
+ and row.get("available") and row.get("enabled")), None)
82
+ if candidate is not None:
83
+ changes.append(_change("advanced.model", advanced.get("model"), candidate["id"], "generate", "模型"))
84
+
85
+ # generation mode
86
+ if re.search(r"精细|逐镜|分段", text):
87
+ changes.append(_change("advanced.generation_mode", advanced.get("generation_mode"), "fine", "generate", "生成模式"))
88
+ elif re.search(r"快速|整条", text):
89
+ changes.append(_change("advanced.generation_mode", advanced.get("generation_mode"), "fast", "generate", "生成模式"))
90
+
91
+ # persona gender
92
+ gender = None
93
+ if re.search(r"换成女性|女性|女生|女主", text):
94
+ gender = "female"
95
+ elif re.search(r"换成男性|男性|男生|男主", text):
96
+ gender = "male"
97
+ if gender and gender != persona.get("gender"):
98
+ changes.append(_change("persona.gender", persona.get("gender"), gender, "generate", "模特性别"))
99
+ persona["gender"] = gender
100
+
101
+ # persona age
102
+ age = None
103
+ if re.search(r"年龄大|老一点|成熟", text):
104
+ age = {"teenager": "youth", "youth": "middle_aged", "middle_aged": "senior", "senior": "senior"}.get(persona.get("age") or "youth")
105
+ elif re.search(r"年轻|年龄小|小几岁", text):
106
+ age = {"teenager": "teenager", "youth": "teenager", "middle_aged": "youth", "senior": "middle_aged"}.get(persona.get("age") or "youth")
107
+ if age and age != persona.get("age"):
108
+ changes.append(_change("persona.age", persona.get("age"), age, "generate", "模特年龄"))
109
+ persona["age"] = age
110
+
111
+ # persona body
112
+ body = None
113
+ if re.search(r"壮|健硕|肌肉", text):
114
+ body = "athletic"
115
+ elif re.search(r"瘦|纤细", text):
116
+ body = "slim"
117
+ elif re.search(r"微胖|丰满", text):
118
+ body = "chubby"
119
+ elif re.search(r"标准|匀称", text):
120
+ body = "standard"
121
+ if body and body != persona.get("body_type"):
122
+ changes.append(_change("persona.body_type", persona.get("body_type"), body, "generate", "模特体型"))
123
+ persona["body_type"] = body
124
+
125
+ # persona ethnicity
126
+ ethnicity = None
127
+ if re.search(r"欧美|白人|caucasian", text, re.I):
128
+ ethnicity = "caucasian"
129
+ elif re.search(r"亚洲|asian", text, re.I):
130
+ ethnicity = "asian"
131
+ elif re.search(r"拉美|latino", text, re.I):
132
+ ethnicity = "latino"
133
+ elif re.search(r"非洲|african", text, re.I):
134
+ ethnicity = "african"
135
+ elif re.search(r"中东|middle", text, re.I):
136
+ ethnicity = "middle_eastern"
137
+ if ethnicity and ethnicity != persona.get("ethnicity"):
138
+ changes.append(_change("persona.ethnicity", persona.get("ethnicity"), ethnicity, "generate", "模特族裔"))
139
+ persona["ethnicity"] = ethnicity
140
+
141
+ # post-only: subtitle delivery is a switch, so judge on/off before the size words
142
+ subtitle_toggled = False
143
+ current_subtitle = str(advanced.get("subtitle") or "off")
144
+ if re.search(r"字幕", text) and re.search(r"关闭|关掉|不要|不用|去掉|取消|不启用|别加|无字幕", text):
145
+ subtitle_toggled = True
146
+ if current_subtitle != "off":
147
+ changes.append(_change("post.subtitle", current_subtitle, "off", "post", "字幕"))
148
+ advanced["subtitle"] = "off"
149
+ elif re.search(r"字幕", text) and re.search(r"开启|打开|加上|加个|要字幕|带字幕|加字幕|启用", text):
150
+ subtitle_toggled = True
151
+ if current_subtitle != "sidecar":
152
+ changes.append(_change("post.subtitle", current_subtitle, "sidecar", "post", "字幕"))
153
+ advanced["subtitle"] = "sidecar"
154
+ if not subtitle_toggled and re.search(r"字幕", text) and re.search(r"大|放大", text):
155
+ size = int(post.get("subtitle_size") or 32) + 4
156
+ changes.append(_change("post.subtitle_size", post.get("subtitle_size"), size, "post", "字幕字号"))
157
+ post["subtitle_size"] = size
158
+ if not subtitle_toggled and re.search(r"字幕", text) and re.search(r"小", text):
159
+ size = max(16, int(post.get("subtitle_size") or 32) - 4)
160
+ changes.append(_change("post.subtitle_size", post.get("subtitle_size"), size, "post", "字幕字号"))
161
+ post["subtitle_size"] = size
162
+ if re.search(r"轻音乐|背景音乐|音乐", text):
163
+ changes.append(_change("post.music", post.get("music", "off"), "light", "post", "音乐"))
164
+ post["music"] = "light"
165
+ if re.search(r"文件.*(小|太大)|码率|体积", text):
166
+ changes.append(_change("post.export_bitrate", post.get("export_bitrate", "8M"), "4M", "post", "导出码率"))
167
+ post["export_bitrate"] = "4M"
168
+
169
+ # stitch intent
170
+ stitch_words = re.search(r"拼|合并|接起来|插入|中间加|加个广告|串起来", text)
171
+ if stitch_words:
172
+ actions.append("stitch")
173
+ questions.append("请选择至少两个视频片段,或在素材库里勾选后再打开拼接计划。")
174
+
175
+ # reroll / revert
176
+ if re.search(r"再来一条|换一条|重生成一条", text):
177
+ actions.append("retry")
178
+ if re.search(r"上一版|回退|恢复", text):
179
+ actions.append("version")
180
+
181
+ # price / product text -> brief changes
182
+ price = re.search(r"价格.*?(\d+(?:\.\d+)?)|(\d+(?:\.\d+)?)\s*(?:块|元|块九|\.9)", text)
183
+ if price and re.search(r"价格|活动价|原价", text):
184
+ value = price.group(1) or price.group(2)
185
+ changes.append(_change("inputs.brief", context.get("brief"), f"价格调整为 {value},其余结构不变", "generate", "价格台词"))
186
+ actions.append("needs_brief_merge")
187
+
188
+ requires_regen = any(c["stage"] == "generate" for c in changes)
189
+ post_only = bool(changes) and not requires_regen
190
+ if not changes and not questions and actions:
191
+ reply = {"retry": "好,按同参数再生成一条。", "version": "可以切换到上一版。", "stitch": "请选择片段后打开拼接计划。"}.get(actions[0], "我整理成一个动作了,请确认。")
192
+ elif not changes and not questions:
193
+ reply = "我理解为你想调整这条片子。请说具体一点:改台词、换商品/模特、改比例/清晰度、拼接,或只改字幕/音乐。"
194
+ questions.append("你想改内容、画面,还是只改后期?")
195
+ elif post_only:
196
+ reply = "这些是后期修改,不用重生成。"
197
+ elif stitch_words:
198
+ reply = "这需要走拼接计划:选择片段、插入点、转场和音频后,再应用拼接。"
199
+ else:
200
+ reply = "我整理成变更卡了。生成参数变化需要重生成整条或选中分镜;请确认后应用。"
201
+ return {
202
+ "reply": reply,
203
+ "changes": changes,
204
+ "questions": questions,
205
+ "actions": actions,
206
+ "requires_regeneration": requires_regen,
207
+ "post_only": post_only,
208
+ "context_patch": {"advanced": advanced, "persona": persona, "post": post},
209
+ }