dsh-game-material-master 0.7.0 → 0.9.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/lib/tools.js CHANGED
@@ -33,12 +33,13 @@ import { listSequenceJobs, readSequenceJob, listSequenceTasks } from "./seqgen.j
33
33
  import { listRigJobs, readRigJob, rigSnapshot } from "./riggen.js";
34
34
  import { listTileProjects, readTileProject, tileSnapshot } from "./tilegen.js";
35
35
  import { listMapProjects, mapSnapshot, readMapProject } from "./mapgen.js";
36
- import { MAP_STAGES } from "./links.js";
36
+ import { listMusicJobs, musicSnapshot, readMusicJob } from "./musicgen.js";
37
+ import { listSfxJobs, readSfxJob, sfxNextActions, sfxSnapshot } from "./sfxgen.js";
37
38
  import { TOOL_METHODS } from "./wire.js";
38
- import { PANEL_KEY, STUDIO_MODULES, buildOpenLink, originForLinks } from "./links.js";
39
+ import { MUSIC_STAGES, MAP_STAGES, SFX_STAGES, PANEL_KEY, STUDIO_MODULES, assetBasePath, buildOpenLink, originForLinks } from "./links.js";
39
40
  import { loadConfig } from "./config.js";
40
41
  /**
41
- * 五个模块的 key 与界面里的模块 key 完全一致。
42
+ * 八个模块的 key 与界面里的模块 key 完全一致。
42
43
  *
43
44
  * 真源是 `links.ts` 的 `STUDIO_MODULES`(配置层的 `hiddenModules` 也按它收敛),
44
45
  * 这里只是换个短名字。
@@ -51,7 +52,9 @@ export const MODULE_LABELS = {
51
52
  sequence: "序列帧生成",
52
53
  rig: "骨骼动画生成",
53
54
  tile: "45°地图地块生成",
54
- map: "地图编辑器(导入 tileset)"
55
+ map: "地图编辑器(导入 tileset)",
56
+ music: "音乐生成编辑",
57
+ sfx: "音效生成"
55
58
  };
56
59
  /**
57
60
  * 远程方法 → 它属于哪个模块。
@@ -182,6 +185,8 @@ export const METHOD_MODULE = {
182
185
  deleteMapProject: "map",
183
186
  importMapTileset: "map",
184
187
  importSampleTileset: "map",
188
+ composeMapAsset: "map",
189
+ recomposeMapTileset: "map",
185
190
  saveMapTileset: "map",
186
191
  removeMapTileset: "map",
187
192
  saveMapDoc: "map",
@@ -194,7 +199,46 @@ export const METHOD_MODULE = {
194
199
  runMapExport: "map",
195
200
  cancelMapJob: "map",
196
201
  setMapApproved: "map",
197
- revealMapProject: "map"
202
+ revealMapProject: "map",
203
+ // 模块七 音乐生成编辑
204
+ getMusicGuide: "music",
205
+ getMusicScoreGuide: "music",
206
+ saveMusicScorePlan: "music",
207
+ runMusicScore: "music",
208
+ submitMusicScoreToSuno: "music",
209
+ listMusicJobs: "music",
210
+ createMusicJob: "music",
211
+ getMusicJob: "music",
212
+ saveMusicJob: "music",
213
+ deleteMusicJob: "music",
214
+ setMusicApproved: "music",
215
+ revealMusicJob: "music",
216
+ runMusicGeneration: "music",
217
+ cancelMusicGeneration: "music",
218
+ refreshMusicJob: "music",
219
+ getMusicWav: "music",
220
+ getMusicLrc: "music",
221
+ listMusicHistory: "music",
222
+ listMusicStemInstruments: "music",
223
+ runMusicTool: "music",
224
+ musicPeaks: "music",
225
+ renderMusicEdit: "music",
226
+ saveMusicVersion: "music",
227
+ deleteMusicVersion: "music",
228
+ exportMusic: "music",
229
+ // 模块八 音效生成
230
+ listSfxJobs: "sfx",
231
+ createSfxJob: "sfx",
232
+ getSfxJob: "sfx",
233
+ saveSfxJob: "sfx",
234
+ deleteSfxJob: "sfx",
235
+ uploadSfxRef: "sfx",
236
+ removeSfxRef: "sfx",
237
+ runSfxGeneration: "sfx",
238
+ cancelSfxGeneration: "sfx",
239
+ setSfxApproved: "sfx",
240
+ revealSfxJob: "sfx",
241
+ exportSfx: "sfx"
198
242
  };
199
243
  /**
200
244
  * 不隶属于任何模块的方法:配置类 + 跨模块的审核模式
@@ -206,6 +250,10 @@ export const SHARED_TOOL_METHODS = new Set([
206
250
  "testArk",
207
251
  "testCustomImage",
208
252
  "testMinimax",
253
+ "testComfy",
254
+ "testMusic",
255
+ "testMusicScore",
256
+ "testSfx",
209
257
  "setReviewMode"
210
258
  ]);
211
259
  /**
@@ -257,7 +305,7 @@ const clampInt = (value, fallback, min, max) => {
257
305
  function moduleOf(value) {
258
306
  return typeof value === "string" && MODULES.includes(value) ? value : undefined;
259
307
  }
260
- /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t… / m…)。 */
308
+ /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t… / m… / a… / f…)。 */
261
309
  export function moduleForId(id) {
262
310
  if (/^p[a-z0-9]+$/.test(id))
263
311
  return "sprite";
@@ -271,6 +319,10 @@ export function moduleForId(id) {
271
319
  return "tile";
272
320
  if (/^m[a-z0-9]+$/.test(id))
273
321
  return "map";
322
+ if (/^a[a-z0-9]+$/.test(id))
323
+ return "music";
324
+ if (/^f[a-z0-9]+$/.test(id))
325
+ return "sfx";
274
326
  return undefined;
275
327
  }
276
328
  /** 产物相对路径 → 浏览器可直接打开的绝对 URL。 */
@@ -347,7 +399,7 @@ function cellsOf(nodes, assetBase, pick) {
347
399
  });
348
400
  }
349
401
  function spriteSnapshot(project) {
350
- const assetBase = `${ROUTE_PREFIX}/assets/${project.id}/`;
402
+ const assetBase = assetBasePath(`${ROUTE_PREFIX}/assets/${project.id}/`);
351
403
  // 「还有没有活在跑」= 节点状态 + 宿主的后台任务表。只看节点不行:批量任务是
352
404
  // 一个方向一个方向开工的(抽帧并发只有 2),任务刚登记时八个方向可能都还不是
353
405
  // running,只看节点会让 game_material_wait 立刻返回 settled=true,
@@ -444,7 +496,7 @@ function spriteSnapshot(project) {
444
496
  };
445
497
  }
446
498
  function imageSnapshot(job) {
447
- const assetBase = `${ROUTE_PREFIX}/image-assets/${job.id}/`;
499
+ const assetBase = assetBasePath(`${ROUTE_PREFIX}/image-assets/${job.id}/`);
448
500
  const items = (job.items ?? []).map((item) => ({
449
501
  index: item.index,
450
502
  status: item.status,
@@ -477,7 +529,7 @@ function imageSnapshot(job) {
477
529
  };
478
530
  }
479
531
  function sequenceSnapshot(job) {
480
- const assetBase = `${ROUTE_PREFIX}/sequence-assets/${job.id}/`;
532
+ const assetBase = assetBasePath(`${ROUTE_PREFIX}/sequence-assets/${job.id}/`);
481
533
  const steps = [
482
534
  { step: "video", title: "① 生成视频", status: job.video?.status, approved: job.video?.approved === true, url: assetUrl(assetBase, job.video?.file), error: job.video?.error },
483
535
  { step: "frames", title: "② 抽帧 + 抠像", status: job.frames?.status, approved: job.frames?.approved === true, files: (job.frames?.files ?? []).map((file) => assetUrl(assetBase, file)), keyed: (job.frames?.keyed ?? []).map((file) => assetUrl(assetBase, file)), stale: job.frames?.stale === true, error: job.frames?.error },
@@ -536,6 +588,18 @@ async function snapshotOf(module, id) {
536
588
  throw new Error(`找不到地图项目:${id}`);
537
589
  return mapSnapshot(project, originForLinks());
538
590
  }
591
+ if (module === "music") {
592
+ const job = await readMusicJob(id);
593
+ if (job === undefined)
594
+ throw new Error(`找不到音乐任务:${id}`);
595
+ return musicSnapshot(job, originForLinks());
596
+ }
597
+ if (module === "sfx") {
598
+ const job = await readSfxJob(id);
599
+ if (job === undefined)
600
+ throw new Error(`找不到音效任务:${id}`);
601
+ return sfxSnapshot(job, originForLinks());
602
+ }
539
603
  const job = await readRigJob(id);
540
604
  if (job === undefined)
541
605
  throw new Error(`找不到骨骼动画任务:${id}`);
@@ -563,13 +627,88 @@ function openInfo(intent, hint) {
563
627
  return { panel: PANEL_KEY, openUrl: buildOpenLink(intent), openHint: hint };
564
628
  }
565
629
  /**
566
- * 从一次远程调用的入参里推断该打开哪个界面。
630
+ * 音乐方法对应的界面阶段:生成 / 编辑 / 导出。
631
+ *
632
+ * 深链接少一个 stage 也能打开任务,但「从对话里点回来看的是哪一步」会丢失;
633
+ * 这里按方法名自动补,省得每个工具调用都自己传。
634
+ */
635
+ function musicStageOf(method) {
636
+ if (method === "exportMusic")
637
+ return "export";
638
+ if (method === "renderMusicEdit" || method === "saveMusicVersion" || method === "deleteMusicVersion" || method === "musicPeaks")
639
+ return "edit";
640
+ if (method === "getMusicScoreGuide" || method === "saveMusicScorePlan" || method === "runMusicScore")
641
+ return "compose";
642
+ if (method === "runMusicGeneration" ||
643
+ method === "submitMusicScoreToSuno" ||
644
+ method === "getMusicWav" ||
645
+ method === "getMusicLrc" ||
646
+ method === "refreshMusicJob" ||
647
+ method === "cancelMusicGeneration" ||
648
+ method === "getMusicJob") {
649
+ return "generate";
650
+ }
651
+ return undefined;
652
+ }
653
+ /** 音效方法对应的界面阶段:生成 / 导出。 */
654
+ function sfxStageOf(method) {
655
+ if (method === "exportSfx")
656
+ return "export";
657
+ if (method === "setSfxApproved" || method === "revealSfxJob" || method === "deleteSfxJob")
658
+ return undefined;
659
+ return "generate";
660
+ }
661
+ /**
662
+ * 从一次远程调用的入参(和已经拿到的返回值)里推断该打开哪个界面。
567
663
  * 推断不出来(例如 listProjects)就不给链接,免得把用户带到一个空页面上。
664
+ *
665
+ * `value` 只有少数方法用得上:链接里要带的**产物路径**是算出来的,不在入参里。
568
666
  */
569
- function intentFromCall(method, payload) {
667
+ function intentFromCall(method, payload, value) {
570
668
  const projectId = asString(payload.projectId);
571
669
  const jobId = asString(payload.jobId);
572
670
  const stage = typeof payload.stage === "string" ? payload.stage : undefined;
671
+ /**
672
+ * `composeMapAsset` 是「AI 生成素材」那条链路的终点:它整理出来的图**还不是素材**
673
+ * —— 素材属性在「新增素材」那一刻定死,所以要用户自己点一次「确定」。
674
+ * 链接因此带上 `dialog=add&asset=<相对路径>&frames=<帧数>&shape=<形态>`:
675
+ * 点开落在地图编辑器、素材窗口展开、「新增素材」已经打开并**按形态**预填好
676
+ * (少了 `shape` 的话拼块 / 整格会被预选成「普通」,导入出来的块全是碎的,而且不报错)。
677
+ */
678
+ if (method === "composeMapAsset") {
679
+ const file = typeof value?.file === "string" ? value.file : "";
680
+ const frames = typeof value?.frameCount === "number" ? value.frameCount : undefined;
681
+ const shape = typeof value?.shape === "string" ? value.shape : undefined;
682
+ /**
683
+ * 素材图是**每格几倍分辨率**:`composeMapAsset` 会先留到 4 倍(保留细节),
684
+ * 「新增素材」据此知道导入时还要按用户选的清晰度缩到格子上 —— 链接里少这个数,
685
+ * 界面就会把 4 倍图切成 16 倍的碎块(而且不报错)。
686
+ */
687
+ const scale = typeof value?.scale === "number" && value.scale > 1 ? value.scale : undefined;
688
+ /**
689
+ * 整图:占几格也要带上(`shape=stamp` 时「新增素材」按它预填)。
690
+ * 少了它只能退回默认 3×3,图与占格对不上会被拉伸 —— 而且这种拉伸不报错。
691
+ */
692
+ const stamp = value?.stamp;
693
+ const cols = typeof stamp?.cols === "number" ? stamp.cols : undefined;
694
+ const rows = typeof stamp?.rows === "number" ? stamp.rows : undefined;
695
+ /** 整理时已经抠过绿幕 → 回链带 `keyed=1`,界面就不会再抠第二遍。 */
696
+ const keyed = typeof value?.keyed === "number" && value.keyed > 0 ? 1 : undefined;
697
+ if (projectId === "")
698
+ return { module: "map" };
699
+ return {
700
+ module: "map",
701
+ jobId: projectId,
702
+ stage: "assets",
703
+ ...(file === "" ? {} : { dialog: "add", asset: file }),
704
+ ...(frames === undefined ? {} : { frames }),
705
+ ...(shape === undefined ? {} : { shape }),
706
+ ...(scale === undefined ? {} : { scale }),
707
+ ...(cols === undefined ? {} : { cols }),
708
+ ...(rows === undefined ? {} : { rows }),
709
+ ...(keyed === undefined ? {} : { keyed })
710
+ };
711
+ }
573
712
  /**
574
713
  * ⚠️ **先按方法名认模块,再看字段名。**
575
714
  *
@@ -582,7 +721,27 @@ function intentFromCall(method, payload) {
582
721
  const owner = METHOD_MODULE[method];
583
722
  if (owner !== undefined && owner !== "sprite") {
584
723
  const targetId = projectId !== "" ? projectId : jobId;
585
- return targetId === "" ? { module: owner } : { module: owner, jobId: targetId, stage };
724
+ const autoStage = owner === "music"
725
+ ? method === "getMusicJob" && value?.workflow === "compose"
726
+ ? "compose"
727
+ : musicStageOf(method)
728
+ : owner === "sfx"
729
+ ? sfxStageOf(method)
730
+ : undefined;
731
+ const effectiveStage = stage ?? autoStage;
732
+ const scoreId = typeof value?.scoreId === "string" && value.scoreId !== "" ? value.scoreId : undefined;
733
+ return targetId === ""
734
+ ? { module: owner }
735
+ : {
736
+ module: owner,
737
+ jobId: targetId,
738
+ ...(effectiveStage === undefined ? {} : { stage: effectiveStage }),
739
+ ...(owner === "music" && scoreId !== undefined ? { scoreId } : {})
740
+ };
741
+ }
742
+ // 两个导入入口都是「素材」这一步:链接直接展开素材窗口,省得用户自己找。
743
+ if (method === "importMapTileset" && projectId !== "") {
744
+ return { module: "map", jobId: projectId, stage: "assets" };
586
745
  }
587
746
  if (projectId !== "") {
588
747
  const framePick = method === "prepareFramePick" || method === "setFramePick" || method === "setFramePicks" || method === "resetFramePicks";
@@ -598,6 +757,10 @@ function intentFromCall(method, payload) {
598
757
  return { module: "tile" };
599
758
  if (method.startsWith("listMapProject") || method.startsWith("createMapProject"))
600
759
  return { module: "map" };
760
+ if (method.startsWith("listMusicJob") || method.startsWith("createMusicJob"))
761
+ return { module: "music" };
762
+ if (method.startsWith("listSfxJob") || method.startsWith("createSfxJob"))
763
+ return { module: "sfx" };
601
764
  if (method.startsWith("listImageJob") || method.startsWith("createImageJob"))
602
765
  return { module: "image" };
603
766
  if (method.startsWith("listSequenceJob") || method.startsWith("createSequenceJob"))
@@ -610,9 +773,9 @@ function intentFromCall(method, payload) {
610
773
  /** `game_material_call` 的描述:把每个远程方法的用途与入参写清楚。 */
611
774
  const CALL_DESCRIPTION = [
612
775
  "调用「游戏素材大师」插件的任意远程方法——插件界面上的每个功能都能在这里调用。",
613
- "配置:getConfig() / saveConfig(payload: 任意配置字段,如 arkApiKey、arkModel、imageProvider(ark|custom)、customProtocol(openai|comfyui|sdwebui)、customBaseUrl、customModel、customWorkflow、minimaxModel、cellWidth…) / testArk() / testCustomImage() / testMinimax()",
776
+ "配置:getConfig() / saveConfig(payload: 任意配置字段,如 arkApiKey、arkModel、imageProvider(ark|custom)、customProtocol(openai|comfyui|sdwebui)、customBaseUrl、customModel、customWorkflow、minimaxModel、sfxApiKey、sfxModel、sfxBaseUrl、cellWidth…) / testArk() / testCustomImage() / testMinimax() / testComfy() / testSfx()",
614
777
  " ★ 生图后端有两种:`ark`(火山方舟 Seedream,默认)与 `custom`(用户自己的服务,协议可选 openai / comfyui / sdwebui)。",
615
- " 换后端只改 imageProvider 一个字段,八方向图 / 图片生成 / 骨骼动画 / 地图地块全都跟着走;图生视频始终只走 MiniMax。",
778
+ " 换后端只改 imageProvider 一个字段,八方向图 / 图片生成 / 骨骼动画 / 地图地块全都跟着走;图生视频走 MiniMax,也可以改走本机 / 远端 ComfyUI(comfyVideo 开关)。",
616
779
  " ⚠️ 用户可以在「设置 → 游戏素材大师 → 功能管理」里隐藏某些功能模块。被隐藏的模块**工具面一律拒绝**(界面也看不到),",
617
780
  " 调用会直接报错并说明去哪里打开;不要试图绕过。hiddenModules 本身只能由用户在设置界面里改,工具面不允许写。",
618
781
  "八方向图:listProjects() / createProject({name}) / getProject({projectId}) / deleteProject({projectId}) / renameProject({projectId,name}) /",
@@ -637,6 +800,8 @@ const CALL_DESCRIPTION = [
637
800
  " saveSequenceJob({jobId,name?,mode?,prompt?,suffix?,settings?,keying?,approved?,step?}) / uploadSequenceRef({jobId,kind:firstFrame|lastFrame|referenceImage|referenceVideo,name,data}) /",
638
801
  " removeSequenceRef({jobId,kind,file?}) / runSequenceVideo({jobId}) / pollSequenceVideo({jobId}) / clearSequenceVideo({jobId}) /",
639
802
  " runSequenceFrames({jobId,count?}) / keySequenceFrames({jobId}) / composeSequence({jobId})",
803
+ " ★ getImageJob / getSequenceJob 都回一个 `dir`(**本机绝对目录**):把生成结果交给别的模块时用得上——",
804
+ " 图片生成的作品绝对路径 = `dir + \"/\" + items[i].file`(形如 out/img-00.png);序列帧抽好的帧看 `frames.files`,绝对路径 = `dir + \"/\" + file`。",
640
805
  "骨骼动画生成:listRigJobs() / createRigJob({name}) / getRigJob({jobId}) / deleteRigJob({jobId}) /",
641
806
  " saveRigJob({jobId,name?,sheetPrompt?,suffix?,resetSheetPrompt?,settings?,approved?,stage?parts|layout|rig|atlas,part?}) /",
642
807
  " uploadRigSource({jobId,name,data:角色整图}) / uploadRigPart({jobId,name:部件名,data:部件PNG}) / removeRigPart({jobId,name}) /",
@@ -664,8 +829,15 @@ const CALL_DESCRIPTION = [
664
829
  " ★ 几何交给代码、内容交给 AI:参考图由本机渲染,AI 只填菱形内部;生成后本地量一次、仿射对齐回标准菱形。",
665
830
  "地图编辑器(模块六,**全本地、零计费**;导入自己的素材图,四步:素材图 → 自动连接 → 环绕画布 → 导出 PNG/存档):",
666
831
  " listMapProjects() / createMapProject({name,grid?,cols?,rows?}) / getMapProject({projectId,lang?}) / saveMapProject({projectId,name}) / deleteMapProject({projectId}) /",
667
- " importMapTileset({projectId,name,data:素材图base64,cell?,shape?,animRows?})【新增素材:属性这一下就定死,之后只能删掉重来;cell/shape/animRows 留空 = 自动识别】/ importSampleTileset({projectId})【内置素材:本机现算、零成本,4 张自动连接图 + 1 张道具图;属性不可改、可删、可一键恢复】/",
668
- " saveMapTileset({projectId,tilesetId,name?,cell?,shape?,animRows?})【形态由尺寸自动识别,改形态/删素材会让图块序号平移,宿主按「素材 id + 图块 id」自动重新映射每格】/ removeMapTileset({projectId,tilesetId}) /",
832
+ " importMapTileset({projectId,name,data:素材图base64,cell?,shape?,animRows?,fps?,clarity?,scale?})【新增素材:属性这一下就定死,之后只能删掉重来;cell/shape/animRows 留空 = 自动识别;fps = 这个素材自己的动画播放速度(0.5~30 帧/秒,留空 = 跟「设置 → 动画速度」那条全局速度走);clarity = 把大图缩到格子的方式(smooth 面积平均,默认 / sharp 最近邻 / crisp 平均+锐化);scale = 素材图每格几倍(默认 1,AI 那条路是 4)】/ importSampleTileset({projectId})【内置素材:本机现算、零成本,4 张自动连接图 + 1 张道具图;属性不可改、可删、可一键恢复】/",
833
+ " composeMapAsset({projectId,name?,files:[本机绝对路径…],shape?,cell?,animRows?,stampCols?,stampRows?})【把 AI 生成的那几张图按**事先定好的素材形态**整理成一张待确认的素材图,落在项目 `ai/` 下;返回 {file,shape,cell,width,height,frameCount,variants,animRows,scale,notes,stamp?}。四种形态的输入约定:`plain`(普通,默认)每张 = 一帧(一格内容)→ 裁到网格后竖排成一列(多张 = 翻页图);`corner16`(整格)**只能 1 张** = **一块**无缝墙砖 → 宿主从这一块砖拼出 16 种接法(断口由代码加收口);`a2quad`(拼块)每张 = **一个变体的一块**无缝材质 → 拼成 N 列 × 5 行;`stamp`(整图,多格印花)**每张 = 一帧的整张画** + 必须给 `stampCols`/`stampRows`(占几格,2~8)→ 宿主按占格切成 N×M 格、并烘出 4 个旋转,地图上一次印一整张(区域 / 通行性在导入时由用户点选)。**不要自己先拼多格排布**:模型画的多格各自独立,拼到地图上每一处交界都有缝(这条是实测返工过的)。**这一步只整理、不进素材列表** —— 返回的 openUrl 会让地图编辑器弹出「新增素材」并按这个形态预填好,用户点「确定」才真的导入。cell 留空 = 用地图项目的网格】/",
834
+ " ★ 「AI 生成素材」固定流程(地图编辑器素材窗口那颗按钮会自动开一个新对话并发来需求):提示词里参数已齐、形态多半也定了、审核模式已定,**不要再问、不要停下等确认**。",
835
+ " ① 先定这块素材怎么用:成片铺开、边缘要自动接上(草地 / 水面 / 沙地 / 岩浆 / 雪地)→ `a2quad`(拼块);要连成一条、拐角要对上(墙 / 路 / 栅栏 / 桥 / 管道)→ `corner16`(整格);一块一块单独摆、不跟邻居接(树 / 箱子 / 道具 / 装饰)→ `plain`(普通)。",
836
+ " 整格 / 拼块都只画**一块无缝砖**(不要画多格排布,也不要在砖里画边框 / 收口),怎么拼由宿主做。",
837
+ " ② 按这个形态规划生图(提示词里会写清每种形态该画几行几列、每块画什么)。",
838
+ " ③ 生成:帧数 1 = 图片生成 count:1;帧数 > 1 + 生图模型 = 图片生成 count:N;帧数 > 1 + 视频模型 = 先图片生成 count:1 当首帧 → 序列帧 upload(firstFrame) → runSequenceVideo → runSequenceFrames count:N。",
839
+ " ④ `composeMapAsset({projectId,name,files,shape:'<上面那个形态>'})` 整理(**必须把形态传进去**,宿主按它规整几何),最后把它返回的 openUrl 原样贴成 Markdown 链接。",
840
+ " recomposeMapTileset({projectId,tilesetId,files,clarity?})【★原地重烘一张素材:用同一份源图按**现在**的规则重新合成(整格给 1 张、普通/拼块按帧序给 N 张),保留素材 id 与图块序号 —— 地图上已经画好的格子一个都不用重画。整格/拼块的 16 块是烘进素材图的(收口、竖段换向、转角斜接都在里面),规则一改就只能靠这条重烘;删掉重导会把它画过的格子清空】/\n saveMapTileset({projectId,tilesetId,name?,cell?,shape?,animRows?,fps?})【形态由尺寸自动识别,改形态/删素材会让图块序号平移,宿主按「素材 id + 图块 id」自动重新映射每格;fps 是**表现层**属性(0.5~30 帧/秒,null = 回到跟全局),改它不动几何、不动序号,随时能改 —— 一张地图上不同素材可以各走各的速度】/ removeMapTileset({projectId,tilesetId}) /",
669
841
  " saveMapDoc({projectId,name?,cols?,rows?,layers?,addLayer?,removeLayerId?,moveLayer?,clearLayerId?,wrap?})【地图只有一张:改尺寸/图层/环绕都走它】/",
670
842
  " applyMapOps({projectId,ops,stroke?,have?})【★ agent 也能画:ops = [{kind:'paint',layerId,cells:[{r,c,tile}]}, {kind:'fill',layerId,r,c,tile}, {kind:'rect',layerId,r0,c0,r1,c1,tile,filled}, {kind:'replace',layerId,from,to}];tile 取 getMapProject 的 view.tilesets[].palette[].index(1 起,0 = 空)。have = 界面已有的 chunk key,宿主只回真正失效的 dropKeys】/",
671
843
  " mapUndo({projectId,have?}) / mapRedo({projectId,have?})【宿主持撤销栈,界面不用管】/ mapPlan({projectId,view:{x,y,width,height},have?,layerIds?})【绘制计划:每项 = {l 层, r,c 格号, t 图块序号, x,y 目标像素, a 不透明度, cycle? 动画帧序},界面画布与导出 PNG 执行同一份】/",
@@ -676,6 +848,24 @@ const CALL_DESCRIPTION = [
676
848
  " ★ 地图四周**环绕**:视口范围可以越出边界,宿主会把这些格子映射回图内;一张地图就一个 `map.json`,没有多地图。",
677
849
  " 生成的几何报告看 game_material_review 返回的 variants[].geomMode —— measured 是量测成功,template 是回退模板几何。",
678
850
  " 出现 template 多半是模型不对:必须用 Seedream 5.0 系列;4.0 会把 2:1 等距菱形画成近正方形(实测比例 1.058)。",
851
+ "音乐生成编辑(模块七;直接生成走谱乐 AI、按积分计费;谱曲模式本地免费):getMusicGuide({lang?})【直接生成指南】/ getMusicScoreGuide({lang?})【谱曲模式 scoremill 指南】/ listMusicJobs() / createMusicJob({name?,source?,settings?,reviewMode?,workflow:generate|compose}) / getMusicJob({jobId,lang?}) / saveMusicJob({jobId,name?,source?,settings?,reviewMode?}) / deleteMusicJob({jobId}) /",
852
+ " saveMusicScorePlan({jobId,plan})【保存谱曲方案,免费;plan 含 summary/style/mood/key/tempo/timeSignature/structure/instrumentation/sunoTags/sunoPrompt/negativeTags 等】/",
853
+ " runMusicScore({jobId,title?,plan?,script,basedOn?,label?})【★本地免费:script 是 scoremill Python,必须 s.save('score.mid');宿主跑 Python、解析 MIDI、渲染试听,返回 openUrl】/",
854
+ " submitMusicScoreToSuno({jobId,scoreId?,confirm:true,model?,params?,regenerate?,copyrightAudio?,audioWeight?})【★计费:先把这一版试听音频上传给 Suno 作为参考(标准上传免费),再走 cover;**不上传 MIDI 原文件**;Suno 判定版权时需 copyrightAudio:true 走付费版权通道;已有歌曲必须 regenerate:true】/",
855
+ " setMusicApproved({jobId,stage?,songId?,versionId?,scoreId?,approved}) / revealMusicJob({jobId}) /",
856
+ " runMusicGeneration({jobId,engine,mode,model?,params?,regenerate?})【★计费:engine=suno|mureka|minimax|aceStep;mode 见指南;params 用 camelCase 或 API 的 snake_case 都收】/",
857
+ " cancelMusicGeneration({jobId})【只停本地轮询,已提交的仍会完成并计费】/ refreshMusicJob({jobId})【补查/补下载/恢复工具轮询】/",
858
+ " getMusicWav({jobId,songId}) / getMusicLrc({jobId,songIds?}) / listMusicHistory({page?,size?,filters?}) / listMusicStemInstruments() /",
859
+ " runMusicTool({jobId,kind,params?})【kind=stems|pro-stems|midi|sheet-music|style-analysis|convert;工具接口只接受公开 http(s) URL】/",
860
+ " musicPeaks({jobId,songId?,versionId?,scoreId?,buckets?}) / renderMusicEdit({jobId,songId?,versionId?,ops,label?,preview?,force?})【本地 ffmpeg,免费;ops={start,end,gainDb,fadeIn,fadeOut,normalize,lufs,truePeak,format,bitrate,channels,sampleRate}】/",
861
+ " saveMusicVersion({jobId,versionId,label?}) / deleteMusicVersion({jobId,versionId}) / exportMusic({jobId,songId?,versionId?,scoreId?,format?,name?,zip?})【导出到 out/,返回可下载 URL;给 scoreId 时导出乐谱包 MIDI+试听+方案+compose.py】",
862
+ " ★ 直接生成:先 getMusicGuide;用户给完整歌词时以歌词为权威文本;Suno 每次提交返回 2 首;已有歌曲后再生成必须 regenerate:true;生成后用 game_material_wait,再做后期或让用户点 openUrl 回界面。",
863
+ " ★ 谱曲模式:先 saveMusicScorePlan(方案用用户语言输出给用户看;manual 停下等确认)→ runMusicScore(本地免费)→ 贴 openUrl 让用户试听 → 有意见就 runMusicScore 出新版本(basedOn)→ 只有用户明确要求才 submitMusicScoreToSuno(计费;先上传试听音频再 cover,不上传 MIDI 原文件)。",
864
+ "音效生成(模块八;火山引擎 Seed-Audio,每次生成真实计费):listSfxJobs() / createSfxJob({name?,prompt,settings?:{format?,sampleRate?,speechRate?,loudnessRate?,pitchRate?,watermark?},reviewMode?}) / getSfxJob({jobId}) / saveSfxJob({jobId,name?,prompt?,settings?,reviewMode?}) / deleteSfxJob({jobId}) /",
865
+ " uploadSfxRef({jobId,kind:image|audio,name?,data})【参考图 1 张 / 参考音频 ≤3 条,两者互斥,单文件 ≤10MB】/ removeSfxRef({jobId,kind,file?}) /",
866
+ " runSfxGeneration({jobId})【★计费:同步接口,宿主包成后台任务;一次一条 take,失败不自动重试】/ cancelSfxGeneration({jobId})【只停本地请求,远端可能仍会完成并计费】/",
867
+ " setSfxApproved({jobId,stage?:generate|export,approved}) / revealSfxJob({jobId}) / exportSfx({jobId,takeId?,zip?})【导出到 out/;zip 打包全部 take】/",
868
+ " ★ 音效提示词当导演脚本写:声源 + 环境 + 强度/节奏 + 时长;单次输出上限 120 秒(没有 duration 参数)。参考音频在提示词里用 @音频1…@音频3;参考图与参考音频不能混用。失败重试会再计费,先问用户。",
679
869
  "说明:key 是方向英文字面量(front/back/downLeft/downRight/upLeft/upRight/left/right);data 是原始文件字节的 base64(不带 data: 前缀);",
680
870
  "生成类方法立刻返回 {started:true},接着用 game_material_wait 等它跑完,再用 game_material_review 拿验收包。",
681
871
  "调用结果里若带 openUrl,请把它作为 Markdown 链接贴给用户,用户点击即切换到插件对应页面。"
@@ -753,9 +943,11 @@ export function registerStudioTools(host, gateway) {
753
943
  throw new Error(`${method} 调用失败:${error instanceof Error ? error.message : String(error)}`);
754
944
  }
755
945
  const result = { method, ok: true, value: value ?? null };
756
- const intent = intentFromCall(method, payload ?? {});
757
- if (intent !== undefined)
758
- Object.assign(result, openInfo(intent, "点开可以看到这一步的实际产物并打「通过」"));
946
+ const intent = intentFromCall(method, payload ?? {}, value);
947
+ if (intent !== undefined) {
948
+ const hint = method === "composeMapAsset" ? "点开回到地图编辑器:「新增素材」已经打开并预填好这张图,确认一下就能用" : "点开可以看到这一步的实际产物并打「通过」";
949
+ Object.assign(result, openInfo(intent, hint));
950
+ }
759
951
  return result;
760
952
  }
761
953
  });
@@ -781,13 +973,15 @@ export function registerStudioTools(host, gateway) {
781
973
  if (id === "") {
782
974
  // 只列可见模块的清单:隐藏的模块连「有哪些项目」都不给模型看一眼。
783
975
  await assertModuleVisible(moduleOf(args?.module));
784
- const [projects, images, sequences, rigs, tiles, maps] = await Promise.all([
976
+ const [projects, images, sequences, rigs, tiles, maps, music, sfx] = await Promise.all([
785
977
  hidden.has("sprite") ? [] : listProjects(),
786
978
  hidden.has("image") ? [] : listImageJobs(),
787
979
  hidden.has("sequence") ? [] : listSequenceJobs(),
788
980
  hidden.has("rig") ? [] : listRigJobs(),
789
981
  hidden.has("tile") ? [] : listTileProjects(),
790
- hidden.has("map") ? [] : listMapProjects()
982
+ hidden.has("map") ? [] : listMapProjects(),
983
+ hidden.has("music") ? [] : listMusicJobs(),
984
+ hidden.has("sfx") ? [] : listSfxJobs()
791
985
  ]);
792
986
  const links = {};
793
987
  for (const key of MODULES)
@@ -802,8 +996,10 @@ export function registerStudioTools(host, gateway) {
802
996
  rigJobs: rigs,
803
997
  tileProjects: tiles,
804
998
  mapProjects: maps,
999
+ musicJobs: music,
1000
+ sfxJobs: sfx,
805
1001
  links,
806
- hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export,地图编辑器是 assets(素材)→ rules(自动连接)→ paint(地图)→ export(导出),全本地不花钱。"
1002
+ hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export,地图编辑器是 assets(素材)→ rules(自动连接)→ paint(地图)→ export(导出),全本地不花钱;音乐是 generate(生成)→ edit(编辑)→ export(导出),生成按谱乐 AI 积分计费;音效是 generate(生成,火山引擎 Seed-Audio)→ export(导出),每次生成真实计费。"
807
1003
  };
808
1004
  }
809
1005
  // ⚠️ 这里**不能**再按 module 短路:`status({module:'tile', id})` 也走到这里,
@@ -865,7 +1061,7 @@ export function registerStudioTools(host, gateway) {
865
1061
  "参数 `path` 是文件的绝对路径或相对当前工作目录的路径,宿主自己读盘,**不要把 base64 贴进来**。",
866
1062
  "kind 取值:sprite=source(源设定图)| video(**本地自选视频**,要用 `key` 指定槽位:turn=转圈视频,或 front/back/downLeft/downRight/upLeft/upRight/left/right 之一);",
867
1063
  "image=ref(参考图,最多 10 张)| item(直接加一张图,只做抠像用);",
868
- "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名);map=tileset(图集原图)。",
1064
+ "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名);map=tileset(图集原图);sfx=referenceImage(参考图)| referenceAudio(参考音频)。",
869
1065
  "限制:图片 ≤30MB,视频 ≤40MB(平台请求体上限 64MB;界面上那条本地上传路更宽),类型按文件头嗅探。"
870
1066
  ].join("\n"),
871
1067
  parameters: {
@@ -874,7 +1070,7 @@ export function registerStudioTools(host, gateway) {
874
1070
  properties: {
875
1071
  module: { type: "string", enum: [...MODULES], description: "目标所属模块。" },
876
1072
  id: { type: "string", description: "项目 id(p…)或任务 id(i… / s…)。" },
877
- kind: { type: "string", enum: ["source", "video", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part", "tileset"], description: "上传到哪个槽位。" },
1073
+ kind: { type: "string", enum: ["source", "video", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part", "tileset", "referenceAudio"], description: "上传到哪个槽位。" },
878
1074
  key: { type: "string", description: "仅 sprite + kind=video 用:槽位 `turn`(转圈视频)或某个方向 key。" },
879
1075
  path: { type: "string", description: "本机文件路径。" },
880
1076
  name: { type: "string", description: "可选:展示用的文件名。" }
@@ -986,7 +1182,7 @@ export function registerStudioTools(host, gateway) {
986
1182
  id: { type: "string", description: "项目 id(p…)/ 图片任务 id(i…)/ 序列帧任务 id(s…)。" },
987
1183
  stage: {
988
1184
  type: "string",
989
- enum: ["images", "videos", "frames", "sheet", "generate", "review", "map", "export", "parts", "layout", "rig", "atlas", ...MAP_STAGES],
1185
+ enum: ["images", "videos", "frames", "sheet", "generate", "review", "map", "export", "parts", "layout", "rig", "atlas", ...MAP_STAGES, ...MUSIC_STAGES, ...SFX_STAGES],
990
1186
  description: "八方向图 / 地图地块 / 地图编辑器 / 骨骼动画专用:只看某一个阶段。"
991
1187
  },
992
1188
  direction: { type: "string", description: "八方向图专用:只看某一个方位(front/back/…)。" },
@@ -1104,6 +1300,45 @@ export function registerStudioTools(host, gateway) {
1104
1300
  : "几何都正常。可以继续验收、拼图(runTileMap)或导出(runTileExport)。"
1105
1301
  };
1106
1302
  }
1303
+ else if (module === "music") {
1304
+ const musicStages = snapshot.stages;
1305
+ const stageKeys = Object.keys(musicStages ?? {});
1306
+ if (stage !== undefined && !stageKeys.includes(stage)) {
1307
+ throw new Error(`未知阶段:${stage}(可选:${stageKeys.join(" / ")})`);
1308
+ }
1309
+ packet.stages = stageKeys
1310
+ .filter((key) => stage === undefined || key === stage)
1311
+ .map((key) => ({ stage: key, ...musicStages[key] }));
1312
+ packet.source = snapshot.source;
1313
+ packet.settings = snapshot.settings;
1314
+ packet.workflow = snapshot.workflow;
1315
+ packet.scorePlan = snapshot.scorePlan;
1316
+ packet.compositions = snapshot.compositions;
1317
+ packet.currentScoreId = snapshot.currentScoreId;
1318
+ packet.songs = snapshot.songs;
1319
+ packet.versions = snapshot.versions;
1320
+ packet.tools = snapshot.tools;
1321
+ packet.exports = snapshot.exports;
1322
+ packet.songsReady = snapshot.songsReady;
1323
+ packet.nextActions = musicNextActions(snapshot, stage);
1324
+ }
1325
+ else if (module === "sfx") {
1326
+ const sfxStages = snapshot.stages;
1327
+ const stageKeys = Object.keys(sfxStages ?? {});
1328
+ if (stage !== undefined && !stageKeys.includes(stage)) {
1329
+ throw new Error(`未知阶段:${stage}(可选:${stageKeys.join(" / ")})`);
1330
+ }
1331
+ packet.stages = stageKeys
1332
+ .filter((key) => stage === undefined || key === stage)
1333
+ .map((key) => ({ stage: key, ...sfxStages[key] }));
1334
+ packet.prompt = snapshot.prompt;
1335
+ packet.settings = snapshot.settings;
1336
+ packet.refs = snapshot.refs;
1337
+ packet.takes = snapshot.takes;
1338
+ packet.exports = snapshot.exports;
1339
+ packet.blocker = snapshot.blocker;
1340
+ packet.nextActions = sfxNextActions(snapshot);
1341
+ }
1107
1342
  else {
1108
1343
  // 骨骼动画(模块四)
1109
1344
  const stages = snapshot.stages.filter((entry) => stage === undefined || entry.stage === stage);
@@ -1126,7 +1361,9 @@ export function registerStudioTools(host, gateway) {
1126
1361
  "图片任务:module=image,id=任务 id,index 可只对某一张生效(省略即全任务)。",
1127
1362
  "序列帧:module=sequence,id=任务 id,step=video|frames|sheet(省略即全部三步)。",
1128
1363
  "骨骼动画:module=rig,id=任务 id,stage=parts|layout|rig|atlas(省略即四个阶段全打);stage=parts 时可再带 part 只对某个部件生效。",
1129
- "地图编辑器:module=map,id=项目 id,stage=assets|rules|paint|export(省略即四个阶段全打)。这条链路全本地,打勾只是记录「这步看过了」。"
1364
+ "地图编辑器:module=map,id=项目 id,stage=assets|rules|paint|export(省略即四个阶段全打)。这条链路全本地,打勾只是记录「这步看过了」。",
1365
+ "音乐:module=music,id=任务 id,stage=compose|generate|edit|export;也可以带 songId / versionId / scoreId 只对某一首/某一版/某一版谱曲打勾。",
1366
+ "音效:module=sfx,id=任务 id,stage=generate|export(省略即两个阶段全打)。"
1130
1367
  ].join("\n"),
1131
1368
  parameters: {
1132
1369
  type: "object",
@@ -1134,7 +1371,10 @@ export function registerStudioTools(host, gateway) {
1134
1371
  properties: {
1135
1372
  module: { type: "string", enum: [...MODULES], description: "目标所属模块;可省略,按 id 前缀判断。" },
1136
1373
  id: { type: "string", description: "项目 / 任务 id。" },
1137
- stage: { type: "string", enum: ["images", "videos", "frames", "sheet", ...MAP_STAGES], description: "八方向图 / 地图编辑器:阶段。" },
1374
+ stage: { type: "string", enum: ["images", "videos", "frames", "sheet", ...MAP_STAGES, ...MUSIC_STAGES, ...SFX_STAGES], description: "八方向图 / 地图编辑器 / 音乐 / 音效:阶段。" },
1375
+ songId: { type: "string", description: "音乐:只对某一首歌生效。" },
1376
+ versionId: { type: "string", description: "音乐:只对某个版本生效。" },
1377
+ scoreId: { type: "string", description: "音乐:只对某一版谱曲(MIDI)生效。" },
1138
1378
  key: { type: "string", description: "八方向图:只对某个方位生效(front/back/…)。" },
1139
1379
  index: { type: "integer", description: "图片任务:只对某一张生效。" },
1140
1380
  step: { type: "string", enum: ["video", "frames", "sheet"], description: "序列帧:只对某一步生效。" },
@@ -1202,6 +1442,27 @@ export function registerStudioTools(host, gateway) {
1202
1442
  await gateway.saveSequenceJob(step === undefined ? { jobId: id, approved } : { jobId: id, approved, step });
1203
1443
  return { module, id, step: step ?? null, approved, ...openInfo({ module: "sequence", jobId: id }, "点开看验收结果") };
1204
1444
  }
1445
+ if (module === "music") {
1446
+ const stage = asString(args?.stage) || undefined;
1447
+ if (stage !== undefined && !MUSIC_STAGES.includes(stage)) {
1448
+ throw new Error(`未知阶段:${stage}(可选:${MUSIC_STAGES.join(" / ")})`);
1449
+ }
1450
+ const songId = asString(args?.songId) || undefined;
1451
+ const versionId = asString(args?.versionId) || undefined;
1452
+ const scoreId = asString(args?.scoreId) || undefined;
1453
+ await gateway.setMusicApproved(stage === undefined && songId === undefined && versionId === undefined && scoreId === undefined
1454
+ ? { jobId: id, approved }
1455
+ : { jobId: id, approved, ...(stage === undefined ? {} : { stage }), ...(songId === undefined ? {} : { songId }), ...(versionId === undefined ? {} : { versionId }), ...(scoreId === undefined ? {} : { scoreId }) });
1456
+ return { module, id, stage: stage ?? null, songId: songId ?? null, versionId: versionId ?? null, scoreId: scoreId ?? null, approved, ...openInfo({ module: "music", jobId: id, stage, ...(scoreId === undefined ? {} : { scoreId }) }, "点开看验收结果") };
1457
+ }
1458
+ if (module === "sfx") {
1459
+ const stage = asString(args?.stage) || undefined;
1460
+ if (stage !== undefined && !SFX_STAGES.includes(stage)) {
1461
+ throw new Error(`未知阶段:${stage}(可选:${SFX_STAGES.join(" / ")})`);
1462
+ }
1463
+ await gateway.setSfxApproved({ jobId: id, approved, ...(stage === undefined ? {} : { stage }) });
1464
+ return { module, id, stage: stage ?? null, approved, ...openInfo({ module: "sfx", jobId: id, stage }, "点开看验收结果") };
1465
+ }
1205
1466
  const rigJob = await readRigJob(id);
1206
1467
  if (rigJob === undefined)
1207
1468
  throw new Error(`找不到骨骼动画任务:${id}`);
@@ -1226,7 +1487,7 @@ export function registerStudioTools(host, gateway) {
1226
1487
  }
1227
1488
  const PROMPT_SECTION = [
1228
1489
  "## 游戏素材大师(game-material-master)",
1229
- "本机已挂载「游戏素材大师」插件:八方向图生成 / 图片生成 / 序列帧生成 / 骨骼动画生成四个模块,界面在侧栏「游戏素材大师」面板。",
1490
+ "本机已挂载「游戏素材大师」插件:八方向图生成 / 图片生成 / 序列帧生成 / 骨骼动画生成 / 45°地图地块 / 地图编辑器 / 音乐生成编辑 / 音效生成八个模块,界面在侧栏「游戏素材大师」面板。",
1230
1491
  "工具:`game_material_intake`(固定流程第 0 步)、`game_material_call`(万能通道,插件全部方法)、`game_material_upload`(按路径上传素材)、",
1231
1492
  "`game_material_reviewMode`、`game_material_status`、`game_material_wait`、`game_material_review`、`game_material_approve`。",
1232
1493
  "一律走这些工具,不要用 bash/shell 直接改 `<DSH_HOME>/game-material-master/` 下的 JSON——那会绕过宿主的复用与校验。",
@@ -1240,6 +1501,18 @@ const PROMPT_SECTION = [
1240
1501
  "序列帧是 video → frames → sheet;骨骼动画是 parts → layout → rig → atlas。每次提交类调用之后**立刻** `game_material_wait`。",
1241
1502
  "骨骼动画只有第 ① 步(runRigSheet)花钱,②③④ 都是本地计算,重跑不额外计费;装配失败时用 runRigLayout({jobId, names:[…]}) 只重跑那几个部件。",
1242
1503
  "",
1504
+ "### 「AI 生成素材」自动任务(地图编辑器素材窗口发起)",
1505
+ "用户在地图编辑器的「素材」卡里点「AI 生成素材」时,插件会**自动开一个新对话**,把拼好的需求作为第一句话发过来:",
1506
+ "目标地图项目 id、素材名字、动画帧数、动画生成方式、素材主题、画法要求都在那段话里 —— **不要再调用 intake 追问、不要停下来等确认**,直接做完。",
1507
+ "**第一件事是定这块素材怎么用**(普通 / 整格 / 拼块;那段话里没指定时才由你判断):",
1508
+ " · `a2quad` 拼块 —— 成片铺开、边缘要自动接上:草地 / 水面 / 沙地 / 岩浆 / 雪地。每个变体只画**一块**无缝材质(四边能接上自己),5 种形状与边缘收口由宿主从这一块砖拼出来。",
1509
+ " · `corner16` 整格 —— 要连成一条、拐角要对上:墙 / 路 / 栅栏 / 桥 / 管道。只画**一块**无缝墙砖(整张图就是这一块,不要分格),16 种接法与断口收口由宿主从这一块砖拼出来。",
1510
+ " · `plain` 普通 —— 一块一块单独摆、不跟邻居接:树 / 箱子 / 道具 / 装饰。每张 = 一格内容。",
1511
+ "流程:帧数 1 或「生图模型」→ 图片生成 count:N(N = 帧数;拼块时 N = 变体数);「视频模型」→ 先图片生成 count:1 当首帧,再序列帧 upload(firstFrame) → runSequenceVideo → runSequenceFrames count:N。",
1512
+ "最后 `composeMapAsset({projectId,name,files:[绝对路径…],shape:'<上面那个形态>'})` 整理成一张素材图(宿主按形态从这一块砖拼出全部格子;**会留 4 倍分辨率**,等用户在「新增素材」里选清晰度再缩到格子大小 —— 所以回链会带 `scale`;路径用 `getImageJob.dir` / `getSequenceJob.dir` 拼),",
1513
+ "把它返回的 `openUrl` 原样贴成 Markdown 链接 —— 用户点开就回到地图编辑器,素材窗口与「新增素材」都开好了、图与「这块素材怎么用」也预选好了,他点「确定」才真的导入。",
1514
+ "审核模式按那段话里写的(通常是 auto);生成真实计费,失败只重跑失败的那一步。",
1515
+ "",
1243
1516
  "### 八方向图的第①步有两种生成方式(默认「转圈截帧」)",
1244
1517
  "`getProject` 返回的 `imageMode` 决定这一步怎么做,产物都是 `images/<方向>.png`,第②③④步不变:",
1245
1518
  " · `turn`(默认)**转圈截帧**:`runTurnVideo({projectId})` 生成一段「角色原地匀速转一整圈」的绿幕视频(★一次 MiniMax 计费),",
@@ -1306,7 +1579,31 @@ const PROMPT_SECTION = [
1306
1579
  " · 工具面**同样不可用**——`game_material_call` / `status` / `intake` / `upload` / `wait` / `review` / `approve` 都会明确报错。",
1307
1580
  "`game_material_status`(不带 id)返回的 `hiddenModules` 是当前被隐藏的模块 key 列表。",
1308
1581
  "遇到这类报错时**不要重试、也不要绕过**(例如直接改配置文件):告诉用户这个功能被隐藏了,请他在设置里打开。",
1309
- "`hiddenModules` 也不能通过 `game_material_call({method:\"saveConfig\"})` 修改——工具面会拒绝。"
1582
+ "`hiddenModules` 也不能通过 `game_material_call({method:\"saveConfig\"})` 修改——工具面会拒绝。",
1583
+ "",
1584
+ "### 音乐生成编辑(模块七,谱乐 AI)",
1585
+ "用户要写歌/做音乐时:先 `game_material_intake({module:'music'})` 问清「灵感还是完整歌词 / 用途与风格 / 要不要后期」,并问审核模式;",
1586
+ "然后 `createMusicJob` → `runMusicGeneration` → `game_material_wait`。**提交前先 `getMusicGuide`**(内置创作指南:风格提示词结构、歌词 QC、引擎/模型选择、生成设置、游戏循环与响度目标)。",
1587
+ "一次提交按谱乐 AI 积分计费:Suno 返回 2 首;已有歌曲后再生成必须 `regenerate:true`;不要为确认状态重复提交;失败重试也要先问用户。",
1588
+ "生成后用 `renderMusicEdit` 做裁剪/音量/淡入淡出/loudnorm(本地 ffmpeg、免费),用 `exportMusic` 导出;最后把工具返回的 `openUrl` 原样贴成 Markdown 链接,用户点开回到音乐编辑界面。",
1589
+ "用户给完整歌词时歌词是权威文本:不要重写,只修断句/结构标签/发音并说明改动。工具类接口(分轨/MIDI/乐谱/风格分析/转码)只接受公开 http(s) URL,编辑后的本地版本不能直接传。",
1590
+ "manual 模式:生成后先贴链接并停下等用户说「通过」;auto 模式:自己核对后继续,但失败/再生成仍要找用户确认。",
1591
+ "",
1592
+ "### 谱曲模式(模块七 · 本地 MIDI,谱曲免费)",
1593
+ "用户想「先谱曲 / 先出 MIDI / 要能改的曲子 / 先听听再决定要不要 AI 唱」时,用谱曲模式:",
1594
+ "`createMusicJob({workflow:'compose', source:{kind:'prompt', prompt, note, instrumental}, reviewMode})`。",
1595
+ "流程:`getMusicScoreGuide` 读 scoremill 指南 → 分析用户想法 → **用用户的语言把方案(曲风/调性/BPM/段落表/配器/主题/力度弧)输出给用户看** → `saveMusicScorePlan` → manual 模式停下等确认 → 写 `compose.py`(scoremill)→ `runMusicScore({jobId,title,plan,script})`(本地免费,宿主跑 Python + 渲染试听)→ 把 `openUrl` 贴给用户试听 → 有修改意见就再 `runMusicScore`(`basedOn` 指上一版,每版都保留)。",
1596
+ "只有用户**明确要求**「用 Suno 生成正式版 / 交给 Suno」时才调 `submitMusicScoreToSuno({jobId,scoreId,confirm:true})`:★真实计费;插件会先把这一版的**试听音频**上传给 Suno 作为参考(标准上传免费),再走 **cover** 生成。Suno 不接受 MIDI 原文件,但接受音频,所以「MIDI → 渲染音频 → 上传 cover」才是正确链路;结果不会逐音一致。若 Suno 判定版权,会返回 needsCopyrightConsent,用户确认后传 `copyrightAudio:true` 走付费版权通道。已有歌曲时必须 `regenerate:true`,并先问用户。",
1597
+ "谱曲脚本只做记谱:必须 `s.save('score.mid')`;不要自己渲染音频、不要联网。报错按 scoremill 的小节号只改那一处,最多重试 3 次。",
1598
+ "谱曲依赖本机 Python 3 + scoremill;缺了会在 `getConfig().musicScoreStatus` / `testMusicScore` 里说明。谱曲不需要谱乐 AI Key,交 Suno 才需要。",
1599
+ "",
1600
+ "### 音效生成(模块八,火山引擎 Seed-Audio)",
1601
+ "用户要音效 / 环境音 / UI 声 / 生物吼叫 / 角色配音时:先 `game_material_intake({module:'sfx'})` 问清「要什么声音 / 要不要参考」与审核模式。",
1602
+ "流程:`createSfxJob({name,prompt,settings:{format,sampleRate,speechRate?,loudnessRate?,pitchRate?,watermark?},reviewMode})` →(可选)`game_material_upload({module:'sfx', id, kind:'referenceImage'|'referenceAudio', path})` → `runSfxGeneration({jobId})`(★每次真实计费)→ `game_material_wait({module:'sfx', id})` → `game_material_review` → 把 `openUrl` 原样贴成 Markdown 链接。",
1603
+ "提示词要写成**导演脚本**:声源 + 环境 + 强度/节奏 + 时长(例如「暴雨中的金属撞击,短促有力,约 1 秒,带一点尾音」)。单次输出上限 120 秒;没有 duration 参数。",
1604
+ "参考:参考图最多 1 张;参考音频最多 3 条(每条 ≤30 秒 / ≤10MB),提示词里用 `@音频1…@音频3` 引用;**参考图与参考音频不能同时用**。",
1605
+ "一次生成 = 一条 take,永不覆盖;再生成一条会再计费。失败不自动重试,重试前先问用户。manual 模式生成后先贴链接并停下等用户说「通过」;auto 模式自己核对后继续。",
1606
+ "`seed-audio-1.0` 需要在火山引擎语音控制台开通;Key 是语音控制台的 API Key(`X-Api-Key`),不是火山方舟的 `ARK_API_KEY`。"
1310
1607
  ].join("\n");
1311
1608
  function sleep(ms, signal) {
1312
1609
  return new Promise((resolve, reject) => {
@@ -1406,7 +1703,7 @@ function intakeFor(module, id, told, config, target) {
1406
1703
  known.当前网格 = target.grid;
1407
1704
  if (target?.reviewMode)
1408
1705
  known.审核模式 = target.reviewMode;
1409
- ask("tileset", "素材从哪来?把素材图 PNG 的**本机绝对路径**给我(可以多张),或者你自己在界面「素材」里上传;也可以先用内置素材试手。", "这个模块是「导入派」:不生成素材,只把已有素材图切成可用地块。", "用 game_material_upload({module:'map', id, kind:'tileset', path}),或 game_material_call 的 importMapTileset({projectId, name, data}) 传 base64,或 importSampleTileset({projectId}) 装内置素材。");
1706
+ ask("tileset", "素材从哪来?把素材图 PNG 的**本机绝对路径**给我(可以多张),或者你自己在界面「素材」里上传;也可以先用内置素材试手。", "这个模块是「导入派」:不生成素材,只把已有素材图切成可用地块。界面「素材」那张卡里还有一颗「AI 生成素材」:它会**自动开一个新对话**把生成需求发过来(帧数 1 = 一张静态素材;帧数 > 1 = 先生成再整理成会动的素材),做完用 composeMapAsset 整理并回一条带 dialog=add 的链接。", "用 game_material_upload({module:'map', id, kind:'tileset', path}),或 game_material_call 的 importMapTileset({projectId, name, data}) 传 base64,或 importSampleTileset({projectId}) 装内置素材;需要新素材时先定「这块素材怎么用」(自动判断:成片铺开→拼块、连成一条→整格、单独摆→普通),按它规划生图,再 composeMapAsset({projectId, name, files, shape}) 按形态规整。");
1410
1707
  ask("mapSize", "地图多大?(默认 32×32;改尺寸用 saveMapDoc 的 cols / rows)要分几层?(默认两层:图层 1 / 图层 2)", "尺寸与图层决定画布和最终 PNG 的像素大小;地图四周默认**环绕**。", "用 saveMapDoc({projectId, cols, rows, addLayer:{name}, wrap})。");
1411
1708
  ask("generate", "先一键铺一层再手改,还是直接手画?(一键生成:随机铺满 / 迷宫 / 大陆;也可以让 agent 直接拿坐标系画)", "一键生成是本地计算、不花钱,同一个种子结果完全一样,随时能撤销。", "用 runMapGenerate({projectId, kind:'random'|'maze'|'continent', tiles?, seed?, layerId?}),或 applyMapOps({projectId, ops}) 直接画。");
1412
1709
  }
@@ -1430,6 +1727,72 @@ function intakeFor(module, id, told, config, target) {
1430
1727
  ask("items", "要做哪几类地块?(默认给 9 类地形 + 4 个装饰 + 1 栋建筑,可以直接用,也可以增删改)", "地块清单决定画面里有什么,也决定要花多少次调用。", "用 saveTileProject({projectId, items:[…]}) 整份写回;每项含 key/label/kind/family/content/mode/variantCount。");
1431
1728
  ask("mapLayout", "地图要多大?(默认 14×14)要不要指定某几格用别的类别、或者撒装饰?", "布局是本地计算,改多少次都不花钱。", "用 runTileMap({projectId, rows, cols, seed, fill, decorDensity});手动指定格子用 saveTileMapCells。");
1432
1729
  }
1730
+ if (module === "music") {
1731
+ // ⚠️ 不再因为缺谱乐 Key 直接阻塞:谱曲模式全程本地免费,不需要 Key。
1732
+ // 只把它写成 known,等用户选择「直接生成 / 交 Suno」时再要求配 Key。
1733
+ if (config?.musicBlocker !== null && config?.musicBlocker !== undefined) {
1734
+ known.直接生成需要Key = `${config.musicBlocker}(谱曲模式不需要 Key;最后交 Suno 才需要)`;
1735
+ }
1736
+ const scoreStatus = config?.musicScoreStatus;
1737
+ known.平台 = "谱乐 AI(YourMusic)Open API;当前只支持它";
1738
+ known.BaseURL = config?.musicBaseUrl ?? "https://api.yourmusic.fun";
1739
+ known.默认模型 = config?.musicModel ?? "chirp-v6";
1740
+ known.引擎与模式 = (config?.musicEngines ?? [])
1741
+ .map((engine) => `${engine.label}:${(engine.modes ?? []).map((mode) => mode.id).join(" / ")}`)
1742
+ .join(";");
1743
+ known.两种做法 = "直接生成(谱乐 AI 出音频,按积分计费)/ 谱曲模式(本机 scoremill 写 MIDI,免费;先试听、可反复改,满意后再可选交 Suno)";
1744
+ known.计费 = "直接生成与交 Suno 按谱乐 AI 积分计费;谱曲、试听、导出全部本地免费。Suno 一次返回 2 首;已有歌曲后再生成必须显式 regenerate:true。";
1745
+ known.四个阶段 = "compose(谱曲 / 试听)→ generate(交 Suno 生成)→ edit(裁剪 / 音量 / 淡入淡出 / 标准化)→ export(导出)";
1746
+ known.本地编辑免费 = "裁剪 / 音量 / 淡入淡出 / loudnorm 全在本机 ffmpeg 完成;只有平台生成与部分工具接口(WAV、分轨、MIDI、乐谱、风格分析、转码)会计费。";
1747
+ known.工具接口 = "stems 分轨 / pro-stems 高级分轨 / midi / sheet-music / style-analysis / convert;这些接口只接受公开可访问的 http(s) URL(生成歌曲的 audio_url 满足,本地编辑版本不满足)。";
1748
+ known.谱曲模式 = "对话里先分析想法、用用户语言输出方案(曲风/调性/BPM/段落表/配器),保存方案后用 scoremill 写 MIDI;宿主跑 Python 并把 MIDI 渲染成可试听的音频。每次修改都是新版本,旧版保留。";
1749
+ known.谱曲依赖 = scoreStatus === undefined || scoreStatus === null
1750
+ ? "尚未探测(getConfig().musicScoreStatus / testMusicScore 可查)"
1751
+ : `Python ${scoreStatus.python?.ok ? scoreStatus.python.version ?? "OK" : "缺失"} · scoremill ${scoreStatus.scoremill?.ok ? scoreStatus.scoremill.version ?? "OK" : "缺失"} · 试听 ${scoreStatus.renderer === "fluidsynth" ? "FluidSynth + SoundFont" : "内置简易音源"}${scoreStatus.blocker ? ` · 阻塞:${scoreStatus.blocker}` : ""}`;
1752
+ known.Suno交接 = "谱乐 AI 的 Suno **不接受 MIDI 原文件,但接受音频**:插件先把这一版 MIDI 渲染成试听音频,上传到 `/v1/suno/audio/upload` 拿参考 id,再走 cover 生成。标准上传免费;版权音频通道要用户确认并扣积分。结果不会逐音一致。";
1753
+ if (target?.workflow)
1754
+ known.工作流 = target.workflow === "compose" ? "谱曲模式(本地 MIDI)" : "直接生成(谱乐 AI)";
1755
+ if (target?.source)
1756
+ known.用户输入 = target.source.kind === "lyrics" ? "完整歌词" : "灵感提示词";
1757
+ if (target?.source?.prompt)
1758
+ known.提示词原文 = String(target.source.prompt).slice(0, 200);
1759
+ if (target?.source?.lyrics)
1760
+ known.歌词原文 = `${String(target.source.lyrics).slice(0, 200)}…(共 ${String(target.source.lyrics).length} 字)`;
1761
+ if (target?.reviewMode)
1762
+ known.审核模式 = target.reviewMode;
1763
+ const hasMusicText = target?.source !== undefined && ((typeof target.source.prompt === "string" && target.source.prompt.trim() !== "") || (typeof target.source.lyrics === "string" && target.source.lyrics.trim() !== "") || (typeof target.source.note === "string" && target.source.note.trim() !== ""));
1764
+ if (!hasMusicText) {
1765
+ ask("musicSource", "要做一首什么?给我一段灵感提示词,或者一整首歌词(二选一即可)。", "这是创作的起点;有歌词时会以歌词为权威文本,只有灵感时由 agent 写歌词/扩写。", "用 game_material_call({method:'createMusicJob', payload:{name, source:{kind:'prompt'|'lyrics', prompt, lyrics, title?, tags?, instrumental?}, workflow:'generate'|'compose'}}) 建任务。");
1766
+ }
1767
+ ask("musicWorkflow", "要直接生成,还是先谱曲(本地 MIDI)?直接生成 = 谱乐 AI 出成品音频、按积分计费;谱曲模式 = 先分析和规划、用 scoremill 写 MIDI 让你试听,可以反复改,满意后再可选交给 Suno。", "两条路的计费、可控性和修改方式完全不同:谱曲模式免费、可逐音改;直接生成更快但不可逐音控制。", "建任务时传 createMusicJob({workflow:'generate'|'compose', ...});谱曲模式后续用 saveMusicScorePlan + runMusicScore。");
1768
+ ask("musicStyle", "想要什么风格 / 情绪 / 编制?有没有「不要」的元素(例如不要电吉他、不要合唱)?", "会变成风格标签与 negative_tags;谱曲模式下还会决定配器与段落写法。", "直接生成用 saveMusicJob({jobId, source:{tags, ...}, settings:{negativeTags}});谱曲模式写进 plan.style / plan.mood / plan.instrumentation。");
1769
+ ask("musicUse", "这首歌在游戏里怎么用:主题曲 / 战斗 / 菜单 / 环境床 / 循环 / 短 stinger?要不要人声、大概多长?", "用途决定时长、结构、能不能循环,比堆风格词更重要。", "直接生成把结论写进 source.note,并用 settings.duration / instrumental 表达;谱曲模式写进 plan.structure / plan.lengthBars / plan.instrumental。");
1770
+ ask("musicCompose", "如果走谱曲模式:有偏好的调性 / BPM / 拍号 / 主题动机吗?要不要循环?想用什么乐器(例如古筝、弦乐、铜管、太鼓)?", "这些会直接变成方案与 scoremill 的声部/通道;不确定就让 agent 按用途拟一版方案给你确认。", "agent 先输出方案,再用 saveMusicScorePlan({jobId, plan}) 保存;谱曲用 runMusicScore({jobId, title, plan, script})。");
1771
+ ask("musicEngine", "(仅直接生成 / 交 Suno)引擎有偏好吗?(Suno / Mureka / MiniMax / ACE-Step;默认 Suno chirp-v6,纯音乐或需要固定 BPM 时 ACE-Step 更稳)", "不同引擎的模式、参数与计费方式不同;谱曲模式的本地部分不需要选引擎。", "直接生成:runMusicGeneration({jobId, engine, mode, params});交 Suno:submitMusicScoreToSuno({jobId, scoreId, confirm:true, model?})。");
1772
+ ask("musicReview", "(仅直接生成)生成后要不要做后期处理?(裁剪掉头尾 / 调音量 / 淡入淡出 / 标准化到 -14 LUFS;默认不处理,保留原曲)", "后期是本地免费的,但会多出一些版本;谱曲模式的试听已经是本地渲染。", "renderMusicEdit({jobId, songId, ops:{start,end,gainDb,fadeIn,fadeOut,normalize}}) → game_material_wait。");
1773
+ }
1774
+ if (module === "sfx") {
1775
+ if (config?.sfxBlocker !== null && config?.sfxBlocker !== undefined) {
1776
+ blockers.push(config.sfxBlocker);
1777
+ }
1778
+ known.平台 = "火山引擎豆包语音 · 生成式音频(seed-audio-1.0)";
1779
+ known.BaseURL = config?.sfxBaseUrl ?? "https://openspeech.bytedance.com";
1780
+ known.默认模型 = config?.sfxModel ?? "seed-audio-1.0";
1781
+ known.单次上限 = "120 秒;没有 duration 参数,时长要写进提示词";
1782
+ known.计费 = "每次生成一条 take 都真实计费(按 original_duration);失败重试会再计费,先问用户。";
1783
+ known.参考规则 = "参考图最多 1 张;参考音频最多 3 条(每条 ≤30 秒 / ≤10MB);两者不能同时使用;提示词里用 @音频1…@音频3 引用。";
1784
+ known.两个阶段 = "generate(生成)→ export(导出);v1 不做本地剪辑。";
1785
+ if (target?.prompt)
1786
+ known.提示词原文 = String(target.prompt).slice(0, 200);
1787
+ if (target?.settings)
1788
+ known.输出参数 = `${target.settings.format ?? "?"} / ${target.settings.sampleRate ?? "?"}Hz`;
1789
+ if (target?.reviewMode)
1790
+ known.审核模式 = target.reviewMode;
1791
+ if (!hasPrompt) {
1792
+ ask("sfxPrompt", "要什么声音?写清声源、环境、强度/节奏与大致时长,例如「暴雨中的金属撞击,短促有力,约 1 秒,带一点尾音」。", "生成式音频把提示词当导演脚本;写得越具体越稳。单次上限 120 秒。", "用 game_material_call({method:'createSfxJob', payload:{name, prompt, settings:{format,sampleRate}, reviewMode}}) 建任务,再 runSfxGeneration({jobId})(★计费)。");
1793
+ }
1794
+ ask("sfxRefs", "要不要参考图或参考音频?(可选;参考图与参考音频不能同时用。参考音频最多 3 条、每条 ≤30 秒。)", "参考图适合「按形象生成声线」,参考音频适合「按这个音色/风格生成」;不用参考也可以。", "用 game_material_upload({module:'sfx', id, kind:'referenceImage'|'referenceAudio', path}),或 uploadSfxRef({jobId, kind, name, data})。");
1795
+ }
1433
1796
  if (id === "") {
1434
1797
  questions.push({
1435
1798
  key: "target",
@@ -1443,9 +1806,13 @@ function intakeFor(module, id, told, config, target) {
1443
1806
  ? "新建一个地图地块项目,还是在已有项目上继续?"
1444
1807
  : module === "map"
1445
1808
  ? "新建一个地图项目,还是在已有项目上继续?"
1446
- : "新建一个骨骼动画任务,还是在已有任务上继续?",
1809
+ : module === "music"
1810
+ ? "新建一个音乐任务,还是在已有任务上继续?"
1811
+ : module === "sfx"
1812
+ ? "新建一个音效任务,还是在已有任务上继续?"
1813
+ : "新建一个骨骼动画任务,还是在已有任务上继续?",
1447
1814
  why: "后面的参数都挂在项目 / 任务上。",
1448
- how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject'|'createMapProject', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1815
+ how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject'|'createMapProject'|'createMusicJob'|'createSfxJob', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1449
1816
  });
1450
1817
  }
1451
1818
  if (module === "sprite") {
@@ -1519,6 +1886,8 @@ function intakeFor(module, id, told, config, target) {
1519
1886
  // ── 上传:宿主自己读盘,模型只给路径 ────────────────────────────────────
1520
1887
  const IMAGE_MAX_BYTES = 30 * 1024 * 1024;
1521
1888
  const VIDEO_MAX_BYTES = 40 * 1024 * 1024;
1889
+ /** 音效参考(图 / 音频)平台上限是 10MB。 */
1890
+ const SFX_REF_MAX_BYTES = 10 * 1024 * 1024;
1522
1891
  /** 各模块允许的 kind,避免把「源图」传到「参考视频」这类错位。 */
1523
1892
  const UPLOAD_KINDS = {
1524
1893
  sprite: ["source", "video"],
@@ -1530,7 +1899,12 @@ const UPLOAD_KINDS = {
1530
1899
  // 「上传」这条路给出明确的报错信息(见 uploadFromPath)。
1531
1900
  tile: [],
1532
1901
  // 地图编辑器就是**导入素材**起家的:这里上传的就是 tileset 图集原图。
1533
- map: ["tileset"]
1902
+ map: ["tileset"],
1903
+ // 音乐模块 v1 不导入本地音频:只编辑本任务生成/下载的歌曲。留空数组让
1904
+ // 上传这条路给出明确报错,而不是掉进 sequence 分支做别的事。
1905
+ music: [],
1906
+ // 音效模块:参考图 / 参考音频(两者互斥,上限 10MB)。
1907
+ sfx: ["referenceImage", "referenceAudio"]
1534
1908
  };
1535
1909
  /** sprite 的本地视频槽位:`turn`(转圈)或八个方向之一。 */
1536
1910
  const SPRITE_VIDEO_SLOTS = ["turn", "front", "back", "downLeft", "downRight", "upLeft", "upRight", "left", "right"];
@@ -1554,14 +1928,16 @@ async function uploadFromPath(gateway, module, id, kind, path, name, key) {
1554
1928
  // 上限与嗅探都跟着它走:落到图片那条路上会被图片嗅探当场拒掉,而且 30MB 的上限
1555
1929
  // 会让一段正常的手机视频莫名其妙传不进来。
1556
1930
  const isVideo = kind === "referenceVideo" || kind === "video";
1557
- const limit = isVideo ? VIDEO_MAX_BYTES : IMAGE_MAX_BYTES;
1931
+ // 音效的参考音频不是图片:不能走 sniffImage,上限也是平台规定的 10MB。
1932
+ const isAudio = kind === "referenceAudio";
1933
+ const limit = isVideo ? VIDEO_MAX_BYTES : isAudio ? SFX_REF_MAX_BYTES : IMAGE_MAX_BYTES;
1558
1934
  if (info.size > limit) {
1559
1935
  throw new Error(`文件 ${(info.size / 1024 / 1024).toFixed(1)}MB 超过上限 ${(limit / 1024 / 1024).toFixed(0)}MB:${absolute}`);
1560
1936
  }
1561
1937
  const bytes = await readFile(absolute);
1562
1938
  const base64 = bytes.toString("base64");
1563
1939
  const fileName = name ?? basename(absolute);
1564
- if (!isVideo && sniffImage(base64) === undefined) {
1940
+ if (!isVideo && !isAudio && sniffImage(base64) === undefined) {
1565
1941
  throw new Error(`无法识别的图片格式(支持 PNG / JPEG / WebP / GIF / BMP):${absolute}`);
1566
1942
  }
1567
1943
  const call = gateway;
@@ -1610,6 +1986,17 @@ async function uploadFromPath(gateway, module, id, kind, path, name, key) {
1610
1986
  // 明确报错,而不是掉进 sequence 分支里做一件风马牛不相及的事。
1611
1987
  throw new Error("地图地块模块不需要上传素材:地块由「代码渲染的菱形模板 + 提示词」生成。要改画风请用 saveTileProject({style})");
1612
1988
  }
1989
+ else if (module === "music") {
1990
+ throw new Error("音乐模块 v1 不导入本地音频:只用 runMusicGeneration 生成的歌曲;要编辑本地文件请等后续版本。");
1991
+ }
1992
+ else if (module === "sfx") {
1993
+ await call.uploadSfxRef({
1994
+ jobId: id,
1995
+ kind: kind === "referenceAudio" ? "audio" : "image",
1996
+ name: fileName,
1997
+ data: base64
1998
+ });
1999
+ }
1613
2000
  else {
1614
2001
  await call.uploadSequenceRef({ jobId: id, kind, name: fileName, data: base64 });
1615
2002
  }
@@ -1763,6 +2150,136 @@ function renderMapSummary(value) {
1763
2150
  lines.push(` ⚠ ${warning}`);
1764
2151
  return lines;
1765
2152
  }
2153
+ /** 音乐任务的验收/状态摘要:歌曲、版本、工具与导出都直接给可点的 URL。 */
2154
+ function renderMusicSummary(value) {
2155
+ const lines = [];
2156
+ const stageLabels = { compose: "谱曲", generate: "生成", edit: "编辑", export: "导出" };
2157
+ if (Array.isArray(value.stages)) {
2158
+ lines.push(` 阶段:${value.stages
2159
+ .map((stage) => `${stageLabels[stage.stage] ?? stage.stage}:${stage.status ?? "idle"}${stage.approved ? " · 已通过" : ""}${stage.error ? ` · ${stage.error}` : ""}`)
2160
+ .join(" ")}`);
2161
+ }
2162
+ else if (value.stages !== null && value.stages !== undefined) {
2163
+ lines.push(` 阶段:${Object.entries(value.stages)
2164
+ .map(([key, stage]) => `${stageLabels[key] ?? key}:${stage?.status ?? "idle"}${stage?.approved ? " · 已通过" : ""}${stage?.error ? ` · ${stage.error}` : ""}`)
2165
+ .join(" ")}`);
2166
+ }
2167
+ if (value.source !== undefined && value.source !== null) {
2168
+ const kind = value.source.kind === "lyrics" ? "完整歌词" : "灵感提示词";
2169
+ lines.push(` 输入:${kind}${value.source.title ? ` · 标题「${value.source.title}」` : ""}${value.source.instrumental ? " · 纯音乐" : ""}`);
2170
+ if (value.source.note)
2171
+ lines.push(` 补充要求:${String(value.source.note).slice(0, 200)}`);
2172
+ if (value.source.adaptedPrompt)
2173
+ lines.push(` AI 扩写提示词:${String(value.source.adaptedPrompt).slice(0, 240)}`);
2174
+ if (value.source.adaptedTags)
2175
+ lines.push(` 风格标签:${String(value.source.adaptedTags).slice(0, 240)}`);
2176
+ }
2177
+ if (value.workflow === "compose") {
2178
+ lines.push(" 工作流:谱曲模式(本地 MIDI;谱曲/试听免费,交 Suno 才计费)");
2179
+ }
2180
+ if (value.settings !== undefined && value.settings !== null) {
2181
+ lines.push(` 引擎:${value.settings.engine ?? "?"} · 模式:${value.settings.mode ?? "?"} · 模型:${value.settings.model ?? "?"}`);
2182
+ }
2183
+ if (value.scorePlan !== undefined && value.scorePlan !== null) {
2184
+ const plan = value.scorePlan;
2185
+ const head = [plan.style, plan.mood, plan.key, plan.tempo ? `${plan.tempo} BPM` : "", plan.timeSignature].filter(Boolean).join(" · ");
2186
+ lines.push(` 谱曲方案:${head || "(已保存)"}`);
2187
+ if (Array.isArray(plan.structure) && plan.structure.length > 0) {
2188
+ lines.push(` 段落:${plan.structure.map((entry) => `${entry.name}${entry.bars ? ` ${entry.bars}小节` : ""}${entry.energy ? ` ${entry.energy}` : ""}`).join(" → ")}`);
2189
+ }
2190
+ if (plan.summary)
2191
+ lines.push(` ${String(plan.summary).slice(0, 400)}`);
2192
+ }
2193
+ for (const composition of value.compositions ?? []) {
2194
+ lines.push(` 谱曲「${composition.label}」:${composition.status}${composition.approved ? " · 已通过" : ""} · ${composition.midi?.bars ?? "?"} 小节 / ${Number(composition.midi?.duration ?? 0).toFixed(1)}s${composition.audioRenderer ? ` · ${composition.audioRenderer}` : ""}${composition.audioError ? ` · 试听失败:${composition.audioError}` : ""}`);
2195
+ if (typeof composition.midiUrl === "string")
2196
+ lines.push(` MIDI:${composition.midiUrl}`);
2197
+ if (typeof composition.audioUrl === "string")
2198
+ lines.push(` 试听:${composition.audioUrl}`);
2199
+ }
2200
+ if (typeof value.songsReady === "number" && typeof value.songsTotal === "number") {
2201
+ lines.push(` 歌曲:${value.songsReady}/${value.songsTotal} 首就绪`);
2202
+ }
2203
+ for (const song of value.songs ?? []) {
2204
+ lines.push(` - ${song.title ?? song.id}:${song.status}${song.approved ? " · 已通过" : ""}${song.duration ? ` · ${Number(song.duration).toFixed(1)}s` : ""}${song.downloadError ? ` · 下载失败:${song.downloadError}` : ""}${song.error ? ` · ${song.error}` : ""}`);
2205
+ if (typeof song.url === "string")
2206
+ lines.push(` ${song.url}`);
2207
+ if (typeof song.wavUrl === "string")
2208
+ lines.push(` WAV:${song.wavUrl}`);
2209
+ if (typeof song.lrcUrl === "string")
2210
+ lines.push(` 滚动歌词:${song.lrcUrl}`);
2211
+ }
2212
+ for (const version of value.versions ?? []) {
2213
+ lines.push(` 版本「${version.label}」:${version.status}${version.preview ? " · 试听" : ""}${version.error ? ` · ${version.error}` : ""} · ${version.format}${version.duration ? ` · ${Number(version.duration).toFixed(1)}s` : ""}`);
2214
+ if (typeof version.url === "string")
2215
+ lines.push(` ${version.url}`);
2216
+ }
2217
+ for (const tool of value.tools ?? []) {
2218
+ lines.push(` 工具 ${tool.kind}:${tool.status}${tool.error ? ` · ${tool.error}` : ""}`);
2219
+ for (const file of tool.files ?? []) {
2220
+ lines.push(` ${file.name}${typeof file.url === "string" ? `:${file.url}` : `:${file.file}`}`);
2221
+ }
2222
+ if (tool.result !== undefined && tool.kind === "style-analysis") {
2223
+ const result = tool.result;
2224
+ lines.push(` 风格:${(result.genres ?? []).join(" / ")};标签:${(result.tags ?? []).join(" / ")}`);
2225
+ if (result.description)
2226
+ lines.push(` ${String(result.description).slice(0, 240)}`);
2227
+ }
2228
+ }
2229
+ for (const entry of value.exports ?? []) {
2230
+ lines.push(` 导出:${entry.file}`);
2231
+ if (typeof entry.downloadUrl === "string")
2232
+ lines.push(` ${entry.downloadUrl}`);
2233
+ }
2234
+ if (typeof value.blocker === "string" && value.blocker !== "") {
2235
+ lines.push(value.workflow === "compose" ? ` ⚠ 交 Suno 需要:${value.blocker}` : ` ⚠ ${value.blocker}`);
2236
+ }
2237
+ return lines;
2238
+ }
2239
+ /** 音效任务的摘要:阶段 / 提示词 / 参考 / takes / 导出。 */
2240
+ function renderSfxSummary(value) {
2241
+ const lines = [];
2242
+ const stageLabels = { generate: "生成", export: "导出" };
2243
+ if (Array.isArray(value.stages)) {
2244
+ lines.push(` 阶段:${value.stages
2245
+ .map((stage) => `${stageLabels[stage.stage] ?? stage.stage}:${stage.status ?? "idle"}${stage.approved ? " · 已通过" : ""}${stage.error ? ` · ${stage.error}` : ""}`)
2246
+ .join(" ")}`);
2247
+ }
2248
+ else if (value.stages !== null && value.stages !== undefined) {
2249
+ lines.push(` 阶段:${Object.entries(value.stages)
2250
+ .map(([key, stage]) => `${stageLabels[key] ?? key}:${stage?.status ?? "idle"}${stage?.approved ? " · 已通过" : ""}${stage?.error ? ` · ${stage.error}` : ""}`)
2251
+ .join(" ")}`);
2252
+ }
2253
+ if (typeof value.prompt === "string" && value.prompt !== "")
2254
+ lines.push(` 提示词:${value.prompt.slice(0, 300)}`);
2255
+ if (value.settings !== undefined && value.settings !== null) {
2256
+ lines.push(` 输出:${value.settings.format ?? "?"} / ${value.settings.sampleRate ?? "?"}Hz`);
2257
+ }
2258
+ const refs = value.refs ?? {};
2259
+ if (refs.image !== undefined && refs.image !== null) {
2260
+ lines.push(` 参考图:${refs.image.name ?? refs.image.file}${typeof refs.image.url === "string" ? ` · ${refs.image.url}` : ""}`);
2261
+ }
2262
+ if (Array.isArray(refs.audios) && refs.audios.length > 0) {
2263
+ lines.push(` 参考音频(${refs.audios.length} 条):${refs.audios.map((entry) => entry.name ?? entry.file).join(" / ")}`);
2264
+ }
2265
+ if (typeof value.error === "string" && value.error !== "")
2266
+ lines.push(` ⚠ 上次失败:${value.error}`);
2267
+ if (typeof value.blocker === "string" && value.blocker !== "")
2268
+ lines.push(` ⚠ ${value.blocker}`);
2269
+ for (const take of value.takes ?? []) {
2270
+ lines.push(` take ${take.id}:${take.format}${take.duration ? ` · ${Number(take.duration).toFixed(2)}s` : ""}${take.originalDuration ? `(计费 ${Number(take.originalDuration).toFixed(2)}s)` : ""} · ${take.bytes} 字节`);
2271
+ if (typeof take.prompt === "string" && take.prompt !== "")
2272
+ lines.push(` 提示词:${take.prompt.slice(0, 200)}`);
2273
+ if (typeof take.url === "string")
2274
+ lines.push(` ${take.url}`);
2275
+ }
2276
+ for (const entry of value.exports ?? []) {
2277
+ lines.push(` 导出:${entry.file}`);
2278
+ if (typeof entry.downloadUrl === "string")
2279
+ lines.push(` ${entry.downloadUrl}`);
2280
+ }
2281
+ return lines;
2282
+ }
1766
2283
  function renderStatus(value) {
1767
2284
  if (Array.isArray(value.projects)) {
1768
2285
  const lines = [
@@ -1772,6 +2289,10 @@ function renderStatus(value) {
1772
2289
  ...value.imageJobs.map((j) => ` - ${j.id} ${j.name} — ${j.ready}/${j.total} 张(抠像 ${j.keyed})`),
1773
2290
  `序列帧任务(${value.sequenceJobs.length}):`,
1774
2291
  ...value.sequenceJobs.map((j) => ` - ${j.id} ${j.name} — 视频${j.videoReady ? "✓" : "✗"} 帧${j.frameReady ? "✓" : "✗"} 条图${j.sheetReady ? "✓" : "✗"}`),
2292
+ `音乐任务(${(value.musicJobs ?? []).length}):`,
2293
+ ...(value.musicJobs ?? []).map((j) => ` - ${j.id} ${j.name} — ${j.workflow === "compose" ? `谱曲 ${j.compositions ?? 0} 版 · ` : ""}${j.songsReady}/${j.songsTotal} 首 · ${j.versions} 个版本${j.busy ? " · ⏳" : ""}`),
2294
+ `音效任务(${(value.sfxJobs ?? []).length}):`,
2295
+ ...(value.sfxJobs ?? []).map((j) => ` - ${j.id} ${j.name} — ${j.takes ?? 0} 条${j.latestDuration === null || j.latestDuration === undefined ? "" : ` · 最新 ${Number(j.latestDuration).toFixed(2)}s`}${j.busy ? " · ⏳" : ""}`),
1775
2296
  ...(Array.isArray(value.hiddenModules) && value.hiddenModules.length > 0
1776
2297
  ? [`已隐藏的功能(工具面同样不可调用):${value.hiddenModules.map((key) => MODULE_LABELS[key] ?? key).join("、")}`]
1777
2298
  : []),
@@ -1784,7 +2305,11 @@ function renderStatus(value) {
1784
2305
  if (value.qa !== null && value.qa !== undefined) {
1785
2306
  lines.push(` ${renderRigQa(value.qa)}`);
1786
2307
  }
1787
- if (Array.isArray(value.stages)) {
2308
+ if (value.module === "music")
2309
+ lines.push(...renderMusicSummary(value));
2310
+ if (value.module === "sfx")
2311
+ lines.push(...renderSfxSummary(value));
2312
+ if (value.module !== "music" && value.module !== "sfx" && Array.isArray(value.stages)) {
1788
2313
  for (const stage of value.stages) {
1789
2314
  lines.push(` ${renderStageLine(stage)}`);
1790
2315
  // 骨骼动画:阶段名之后直接把产物 URL 贴上,否则用户点不到东西。
@@ -1862,7 +2387,11 @@ function renderReview(value) {
1862
2387
  // 单独走一段,免得掉进下面按 cells / items 迭代的通用分支。
1863
2388
  if (value.module === "map")
1864
2389
  lines.push(...renderMapSummary(value));
1865
- if (Array.isArray(value.stages)) {
2390
+ if (value.module === "music")
2391
+ lines.push(...renderMusicSummary(value));
2392
+ if (value.module === "sfx")
2393
+ lines.push(...renderSfxSummary(value));
2394
+ if (value.module !== "music" && value.module !== "sfx" && Array.isArray(value.stages)) {
1866
2395
  for (const stage of value.stages) {
1867
2396
  lines.push(`${stage.title}${stage.stale ? " · 需重做" : ""}`);
1868
2397
  // 骨骼动画的阶段**没有 cells**(产物是每阶段固定的几个 URL),
@@ -2063,6 +2592,61 @@ function rigNextActions(snapshot, stage) {
2063
2592
  actions.push("四个阶段都已就绪:可以 game_material_approve 打通过,或把 openUrl 贴给用户验收动画预览");
2064
2593
  return actions;
2065
2594
  }
2595
+ function musicNextActions(snapshot, stage) {
2596
+ const actions = [];
2597
+ const songs = Array.isArray(snapshot.songs) ? snapshot.songs : [];
2598
+ const ready = songs.filter((song) => song.status === "succeeded");
2599
+ const failed = songs.filter((song) => song.status === "failed");
2600
+ const pending = songs.filter((song) => song.status === "pending" || song.status === "processing");
2601
+ const versions = Array.isArray(snapshot.versions) ? snapshot.versions : [];
2602
+ const compositions = Array.isArray(snapshot.compositions) ? snapshot.compositions : [];
2603
+ if (snapshot.blocker) {
2604
+ actions.push(snapshot.workflow === "compose" ? `谱曲/试听不需要 Key;只有交 Suno 才需要:${snapshot.blocker}` : snapshot.blocker);
2605
+ }
2606
+ if (snapshot.workflow === "compose") {
2607
+ if (snapshot.scorePlan === undefined || snapshot.scorePlan === null) {
2608
+ actions.push("先分析用户的想法并保存谱曲方案:saveMusicScorePlan({jobId, plan});manual 模式要停下等用户确认。");
2609
+ }
2610
+ else if (compositions.length === 0) {
2611
+ actions.push("方案已保存:写 compose.py(scoremill),再 runMusicScore({jobId, title, plan, script});宿主会跑 Python 并渲染试听。");
2612
+ }
2613
+ else {
2614
+ actions.push("谱曲已就绪:把 openUrl 贴给用户试听;用户提修改意见就用 runMusicScore 出新版本(basedOn 指上一版),不要覆盖旧版。");
2615
+ actions.push("用户明确要求 Suno 正式版时:submitMusicScoreToSuno({jobId, scoreId, confirm:true})(★计费;先把试听音频上传为参考,再走 cover;版权音频需 copyrightAudio:true)。");
2616
+ }
2617
+ if (compositions.some((entry) => entry.audioError)) {
2618
+ actions.push("有版本没有试听音频:装 FluidSynth + SoundFont 可重新渲染,或让用户直接下载 MIDI。");
2619
+ }
2620
+ }
2621
+ if (snapshot.workflow !== "compose" && songs.length === 0) {
2622
+ actions.push("还没有提交生成:先 getMusicGuide 读创作指南,再用 runMusicGeneration({jobId, engine, mode, params}) 提交(★计费),随后 game_material_wait。");
2623
+ }
2624
+ else if (songs.length === 0) {
2625
+ // 谱曲模式还没交 Suno:不提示 runMusicGeneration,避免误触发计费。
2626
+ }
2627
+ else if (pending.length > 0) {
2628
+ actions.push(`还有 ${pending.length} 首在跑:game_material_wait({module:'music', id, timeoutSeconds:900});超时用 refreshMusicJob 继续查,不要重复提交。`);
2629
+ }
2630
+ else if (ready.length === 0) {
2631
+ actions.push("全部失败:先看每首歌的 error,再决定是否调整提示词/参数;重试会再计费,先问用户。");
2632
+ }
2633
+ else {
2634
+ actions.push("歌曲已就绪:把 openUrl 贴给用户,回界面试听;要处理就用 renderMusicEdit(本地免费),要导出用 exportMusic。");
2635
+ }
2636
+ if (ready.length > 0) {
2637
+ actions.push("后期处理:renderMusicEdit({jobId, songId, ops:{start,end,gainDb,fadeIn,fadeOut,normalize,format}}) → game_material_wait;结果在 versions 里,原曲不动。");
2638
+ actions.push("导出:exportMusic({jobId, versionId?|songId?, format?, zip?});多产物会自动打 zip。");
2639
+ }
2640
+ if (failed.length > 0)
2641
+ actions.push(`${failed.length} 首失败:失败重试会再计费,先向用户确认。`);
2642
+ if (versions.some((version) => version.status === "rendering"))
2643
+ actions.push("有版本正在渲染:game_material_wait 等它完成。");
2644
+ if (stage === "edit" && ready.length === 0 && songs.length === 0)
2645
+ actions.push("先完成生成,再来编辑。");
2646
+ if (actions.length === 0)
2647
+ actions.push("任务已就绪:可以继续生成、编辑或导出。");
2648
+ return actions;
2649
+ }
2066
2650
  function sequenceNextActions(snapshot) {
2067
2651
  const byStep = Object.fromEntries(snapshot.steps.map((entry) => [entry.step, entry]));
2068
2652
  const actions = [];