@q253595422/dsh-imagegen-video 1.13.0 → 1.14.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,47 @@ Attribution for third-party code is in [NOTICE](./NOTICE).
5
5
 
6
6
  ## Releases
7
7
 
8
+ ### 1.14.0 — draw it in code, render it here
9
+
10
+ - **A second renderer, chosen per task.** The canvas composer now carries a
11
+ *Rendering* select: **Model** (the historical path, unchanged and still the
12
+ default) or **Code**. The choice belongs to the task being submitted — it is
13
+ not a setting, not a global switch, and nothing is written to disk, so the
14
+ next generation on the same canvas can use the other one.
15
+ - **No image or video provider involved.** In code mode the drawing program is
16
+ written by the conversation model DSH already has (`ctx.agentDefaultModel`,
17
+ mounted through the host's `agents` and `agentPresets` services) — not the
18
+ plugin's prompt-enhancement endpoint — and rendered on this machine. One
19
+ headless turn, no tools, no vendor SDK, no second credential.
20
+ - **Rendered, not prompted.** The returned JavaScript runs in a `node:vm`
21
+ context with a drawing API and no `require`, `process` or filesystem; each
22
+ frame is RGBA pixels handed to ffmpeg, or encoded straight to PNG. Nothing
23
+ leaves the machine, so a code render costs no image/video quota.
24
+ - **Same pipeline, same slots.** A code result is submitted through the same
25
+ `GenerateRequest` / `VideoGenerateRequest` (an extra `renderer: 'code'`),
26
+ lands in the same `images/` and `videos/` directories and the same history
27
+ stores, and is therefore stitchable, timeline-cuttable, transitionable,
28
+ favouritable and re-framable exactly like a model result. Resolution,
29
+ aspect and duration come from the same composer controls; frames =
30
+ duration × 30 fps.
31
+ - **Failures are named and recoverable.** `code-prompt-empty`,
32
+ `code-prompt-too-long`, `code-no-chat-model`, `code-chat-failed`,
33
+ `code-not-code`, `code-syntax`, `code-runtime`, `render-timeout`,
34
+ `render-no-ffmpeg`, `render-cancelled`, `render-encoder-died`,
35
+ `render-encoder-failed`, `render-empty`. The node shows the host's own
36
+ message plus a hint to switch back to Model and retry; a missing ffmpeg is
37
+ warned about in the composer *before* submitting (`POST /code/probe`).
38
+ - **A non-code answer still produces something.** If the model replies with
39
+ prose instead of a program, the render falls back to a built-in title card
40
+ and the task is marked `degraded` with the reason — a wasted render is worse
41
+ than a plain one.
42
+ - **Retry replays the program.** The generated source is kept on the task, so
43
+ retrying a failed *render* does not ask the model again; generating again
44
+ does.
45
+ - **No new dependency.** `node:vm`, hand-written PNG encoding and the existing
46
+ `locateFfmpeg()` / `clip-compose.ts` path — ffmpeg remains the only external
47
+ tool, needed for code videos only.
48
+
8
49
  ### 1.13.0 — the video is directed before it is rendered
9
50
 
10
51
  - **A planning step before every render.** With the studio's new *Plan first*
package/README.md CHANGED
@@ -87,6 +87,7 @@ dsh plugin --profile web add ./q253595422-dsh-imagegen-video-1.7.8.tgz
87
87
  | **电商套图** | 从商品参考图生成主图、卖点图、场景图等成套素材。 |
88
88
  | **文生图 / 图生图** | 使用兼容的生图渠道生成、编辑并比较图片。 |
89
89
  | **生视频** | 文生视频、图生视频、首尾帧与多参考图;按协议族适配异步渲染与轮询。 |
90
+ | **代码生成** | 让 DSH 里已有的对话模型写绘图程序,本机渲染成视频或图片;不调生图/生视频模型,每个任务单独选。 |
90
91
  | **对话与 Agent** | 在 DSH 对话中生成图片、继续编辑,并把结果带回会话。 |
91
92
  | **画廊与历史** | 图片与视频同列管理,支持模板与标签;在不同设备上接续创作。 |
92
93
 
@@ -193,6 +194,40 @@ dsh plugin --profile web add ./q253595422-dsh-imagegen-video-1.7.8.tgz
193
194
 
194
195
  </details>
195
196
 
197
+ #### 代码生成路径(不调生图/生视频模型)
198
+
199
+ 画布合成栏里有一个「生成方式」下拉,两个选项:**模型生成**(默认,就是上面那整条链路)和**代码生成**。它**按任务选**,不写进设置、不做全局开关;同一个画布上这一张用模型、下一张用代码都行。
200
+
201
+ 选「代码生成」时:
202
+
203
+ - **谁来画**:用 **DSH 里已经接入的对话模型**——就是你在对话面板里选中的那个模型,不是插件设置里的「提示词增强模型」,插件也不新增任何模型或密钥配置。宿主把这个请求当成一次无头对话:系统提示里给绘图 API 与约束,用户消息就是你的描述,模型返回一段 JavaScript 绘图程序。
204
+ - **谁来渲染**:本机 `node:vm` 沙箱逐帧执行这段程序,拿到 RGBA 像素后交给 ffmpeg 编码(视频)或直接写成 PNG(图片)。全过程不产生任何网络请求,也不消耗生图/生视频额度。沙箱里没有 `require`、没有 `process`、没有文件系统,只有一套绘图方法(矩形、圆、路径、渐变、文字等)。
205
+ - **参数照旧**:分辨率、比例、时长仍按合成栏选的档位生效(`480P`/`720P`/`1080P` × 比例,30fps),视频帧数 = 时长 × 30。同一套档位,代码路径不另立一套。
206
+ - **产物对等**:视频落进同一个 `videos/` 目录、同一条视频历史(条目带 `renderer: 'code'`),因此预览、下载、收藏、取尾帧、多选拼接、时间线裁剪与转场、工作流执行器全部照常;图片落进同一个 `images/` 与图片历史,可以继续做标注、海报编辑、当参考图。
207
+ - **模型会「答非所问」时降级**:如果模型返回的不是代码(比如直接回了一段说明),会改用内置标题卡渲染,任务标记 `degraded` 并记录原因——**照样出图/出片**,不会白跑一趟。真正无法继续的情况(语法错、运行时抛错、超时、缺 ffmpeg)才失败。
208
+ - **重试不重复问模型**:第一次生成的绘图程序存在任务里,重试会沿用它;想换一版再重新生成。
209
+
210
+ 失败语义(错误码会直接显示在节点上,并附一行「可在上方「生成方式」里切回模型生成后重试」):
211
+
212
+ | 错误码 | 含义 | 怎么办 |
213
+ | --- | --- | --- |
214
+ | `code-prompt-empty` | 描述为空 | 写一句画面描述(代码路径靠这句话绘图,不会自己编) |
215
+ | `code-prompt-too-long` | 描述超过 4000 字符 | 压缩到核心画面与文案 |
216
+ | `code-no-chat-model` | DSH 里没有选中的对话模型 | 在对话面板选一个模型,或切回模型生成 |
217
+ | `code-chat-failed` | 对话模型调用失败(鉴权、网络、上游报错) | 看节点上的原始原因;换模型或切回模型生成 |
218
+ | `code-not-code` / `code-syntax` | 模型返回的不是可执行代码,或代码编译不过 | 重试(会重新问模型),或切回模型生成 |
219
+ | `code-runtime` | 代码逐帧执行时抛错(报文里带第几帧) | 同上 |
220
+ | `render-timeout` | 整次渲染超过 120 秒 | 缩短时长或降分辨率后重试 |
221
+ | `render-no-ffmpeg` | 本机找不到 ffmpeg,无法编码视频 | `brew install ffmpeg`,或在设置里填 `FFMPEG_PATH`;图片不需要 ffmpeg |
222
+ | `render-cancelled` | 用户取消 | 重新提交即可 |
223
+ | `render-encoder-died` / `render-encoder-failed` | ffmpeg 进程异常退出 | 重试;持续失败请查 ffmpeg 是否可用 |
224
+
225
+ 缺 ffmpeg 在**提交前**就会提示(合成栏下方一行黄色说明),不会等渲染到一半才报。
226
+
227
+ 依赖只有 ffmpeg(视频路径;图片路径零依赖)。不引入任何新框架或原生模块。
228
+
229
+ </details>
230
+
196
231
  #### 多模型对比
197
232
 
198
233
  同一提示词可提交给多个模型并列查看结果,便于快速挑选风格与质量。
@@ -0,0 +1,51 @@
1
+ # v1.14.0 — 代码生成:对话模型写程序,本机渲染成片
2
+
3
+ 一句话概括:画布合成栏多了一个「生成方式」选项。选「代码生成」后,DSH 里已经在用的对话模型写一段绘图程序,本机把它渲染成视频或图片——**不需要任何生图或生视频模型**。「模型生成」原样保留,仍是默认值,两条路每个任务各选一次。
4
+
5
+ ## 为什么
6
+
7
+ 生图和生视频都受两件事约束:要有额度,要等上游。而有些画面——标题卡、数据动图、几何转场、确定性的图表动画——用代码直接画出来更快、更准、更便宜,也更容易复现。DSH 里本来就有对话模型,缺的只是「让它写程序、由本机执行」这一段。
8
+
9
+ ## 做了什么
10
+
11
+ - **每任务选择,不做全局开关**:入口在现有合成栏里(`生成方式` 下拉),状态只活在当前画布,不写设置、不落盘。选「代码生成」时该分支的模型选择器隐藏,比例 / 分辨率 / 时长保留——它们照常决定输出。
12
+ - **走宿主已有的模型,不新增配置**:`ctx.inject(['skills','agents'])` 拿到宿主的 `agents` 与 `agentPresets`,用 `ctx.agentDefaultModel` 的当前选择组一次无头回合:系统提示放绘图 API 与约束,用户消息就是那句描述,回合结束读最后一条助手文本。**不是**插件设置里的「提示词增强模型」,也不需要新密钥。没选模型时报 `code-no-chat-model`。
13
+ - **沙箱执行**:`node:vm` + `Object.create(null)` 上下文,2 秒编译超时 + 整次渲染 deadline(默认 120 秒)。上下文里没有 `require` / `process` / `fs`,只有一套固定的绘图方法(矩形、圆、路径、渐变、文字、图像的像素级操作)。生成源码上限 60000 字符。
14
+ - **渲染**:逐帧得到 RGBA 缓冲,视频写进 ffmpeg 的 stdin 编成 MP4(`libx264` + `yuv420p`,可直接播放,也能被 `clip-compose.ts` 拼接);图片用自写的 PNG 编码(IHDR/IDAT/IEND + CRC32 + `zlib.deflateSync`)直接落盘,零原生依赖。
15
+ - **产物对等**:不新开队列,不新开存储。请求只多一个 `renderer: 'code'`,其余照旧走 `GenerationRequest` / `VideoGenerateRequest`,因此占位节点、轮询、取消、重试、历史、画廊、取尾帧、多选拼接、时间线裁剪与转场、工作流执行器**全部直接复用**。视频条目与图片条目都带 `renderer: 'code'` 与 `renderSource`。
16
+ - **唯一的额外路由是只读的**:`POST /api/dsh-imagegen/code/probe` 回答「会渲染成多大、多少帧、本机有没有 ffmpeg」,不调模型、不渲染。故意**没有** `code/render`——两条生产入口迟早会让占位/取消/重试各写一遍并漂移。
17
+ - **降级而不是死路**:模型回了一段散文而不是代码时,改用内置标题卡渲染,任务标 `degraded` 并记原因;`code-not-code` 只用于拿不到可执行内容的情况。
18
+
19
+ ## 失败语义
20
+
21
+ 节点上直接显示宿主原文,并在下方补一行「可在上方「生成方式」里切回模型生成后重试」。
22
+
23
+ | 错误码 | 触发条件 |
24
+ | --- | --- |
25
+ | `code-prompt-empty` / `code-prompt-too-long` | 描述为空 / 超过 4000 字符(路由边界拦,不调模型) |
26
+ | `code-no-chat-model` | DSH 里没有选中的对话模型,或 `agents` 服务不可用 |
27
+ | `code-chat-failed` | 回合失败(鉴权、网络、上游报错),报文带宿主持久化的失败原因 |
28
+ | `code-not-code` / `code-syntax` | 模型没给出可执行代码 / 代码编译不过 |
29
+ | `code-runtime` | 逐帧执行抛错,报文标明第几帧 |
30
+ | `render-timeout` | 超过 120 秒 |
31
+ | `render-no-ffmpeg` | 找不到 ffmpeg(含 `FFMPEG_PATH` 候选),提示安装方式 |
32
+ | `render-cancelled` | 用户取消 |
33
+ | `render-encoder-died` / `render-encoder-failed` / `render-empty` | ffmpeg 异常退出 / 无输出 |
34
+
35
+ 缺 ffmpeg 会在**提交前**预警(`code/probe`),且只影响视频——图片路径不需要 ffmpeg。
36
+
37
+ ## 重试
38
+
39
+ 生成出的绘图程序存在任务上。重试一次**渲染失败**的任务会沿用同一份源码,不再问模型;想换一版就重新生成。
40
+
41
+ ## 验证
42
+
43
+ - `pnpm run typecheck`、`pnpm run build`、`pnpm test` 全绿。
44
+ - `node scripts/smoke-code-render.mjs`:13 项,含真实 ffmpeg 出片(ffprobe 复核 1280×720 / 30fps / ~3s)、真实 PNG(校验签名与 `1080x1080`)、代码片段进入 `createClipComposer()` 拼接出带 `ftyp` 的 MP4,以及宿主 seam 的正常与三类失败(无 `agents`、无模型、回合 `turn/end` 为 error)。
45
+ - `scripts/smoke.mjs` 里补了画布交互用例:默认「模型生成」、切到「代码生成」后模型选择器消失而比例/分辨率/时长保留、提交体带 `renderer: 'code'` 且 `model` / `channelId` 为空、占位节点带 `renderer`、失败节点显示错误码与切回提示、切回后模型选择器回来。
46
+
47
+ ## 依赖与边界
48
+
49
+ - 新增依赖:**无**。ffmpeg 仍是唯一外部工具,仅视频路径需要。
50
+ - 代码路径不参与导演规划:代码本身就是规划。
51
+ - 代码渲染是 CPU 任务,视频队列并发为 1,与模型渲染串行;`MAX_PIXELS` 限 4096²。