@taptap/maker 0.0.24 → 0.0.25-beta.2

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/dist/maker.js CHANGED
@@ -29287,12 +29287,21 @@ function createMakerAgentsPolicyBody() {
29287
29287
  "- `edit_image` for modifying existing project images.",
29288
29288
  "- `create_video_task` for game video assets or referenced image/video generation.",
29289
29289
  "- `query_video_task` for refreshing video task status and fetching completed videos.",
29290
- "- `text_to_music` for game music or audio assets.",
29291
- "- `create_3d_model_task` for game 3D model assets.",
29292
- "- `query_3d_model_task` for polling 3D model tasks.",
29293
- "- For 3D characters that need skeletons, animation, or FBX output, ask whether to use",
29294
- " `rig=true`. Use it only for biped humanoid characters in A-pose or A-pose-compatible",
29295
- " front-view inputs; otherwise keep static model generation.",
29290
+ "- `text_to_music` for game music.",
29291
+ "- `text_to_sound_effect` for one sound effect.",
29292
+ "- `batch_sound_effects` for multiple sound effects.",
29293
+ "- `text_to_dialogue` for final character dialogue.",
29294
+ "- `text_to_dialogue` automatically converts local project audio to data URLs and reuses confirmed local voice mappings.",
29295
+ "- After `audition_voices_for_character` returns previews, show them to the user and wait",
29296
+ " for the user to choose. Do not select or confirm a voice automatically.",
29297
+ "- Call `confirm_character_voice` only after the user explicitly chooses one preview.",
29298
+ "- Generated sound effects and dialogue are saved in the project.",
29299
+ "- Voice audition previews are not saved to the project.",
29300
+ "- Local MCP does not transcode generated audio to OGG.",
29301
+ "- `create_3d_asset` for the complete 3D lifecycle: start, query, explicit review continuation,",
29302
+ " option inspection, and post-processing.",
29303
+ "- Never automatically continue a 3D review step. Show returned previews and wait for explicit",
29304
+ ' user approval before calling `create_3d_asset` with `action="continue"`.',
29296
29305
  "",
29297
29306
  "Follow each Maker tool schema for supported local path, remote URL, and data URL inputs.",
29298
29307
  "If the user references attached/local media, inspect the attachment or workspace file path",
@@ -29307,8 +29316,8 @@ function createMakerAgentsPolicyBody() {
29307
29316
  "Generated Maker proxy assets should stay in the Maker project asset workflow under",
29308
29317
  "`assets/image`, `assets/video`, `assets/audio`, or `assets/model`, with remote mappings",
29309
29318
  "preserved for later edits and builds.",
29310
- "3D model results save the original GLB/FBX, the MDL zip, extracted MDL assets, and rendered",
29311
- "preview images when those URLs are returned."
29319
+ "`create_3d_asset` local runtime `model_files` copy/extract instructions are materialized into",
29320
+ "`assets/model`. Use `local_delivery` for the usable local model path and preserve the remote result."
29312
29321
  ].join("\n");
29313
29322
  }
29314
29323
  function hashPolicyBody(body) {
@@ -32346,8 +32355,18 @@ function formatMakerSkillStatus(_options = {}) {
32346
32355
  "- Prefer Maker MCP proxy tools over native AI image/video/audio tools for bound Maker projects.",
32347
32356
  "- If Maker proxy tools are missing, explain the session/configuration issue and available alternatives.",
32348
32357
  "- Use generate_image, batch_generate_images, edit_image for game image assets.",
32349
- "- Use create_video_task, query_video_task, and text_to_music for game video/audio assets.",
32350
- "- Use create_3d_model_task and query_3d_model_task for game 3D model assets.",
32358
+ "- Use create_video_task and query_video_task for game video assets.",
32359
+ "- Use text_to_music for game music.",
32360
+ "- Use text_to_sound_effect for one sound effect.",
32361
+ "- Use batch_sound_effects for multiple sound effects.",
32362
+ "- Use text_to_dialogue for final character dialogue.",
32363
+ "- text_to_dialogue automatically converts local project audio to data URLs and reuses confirmed local voice mappings.",
32364
+ "- After audition_voices_for_character returns previews, wait for the user to choose.",
32365
+ "- Call confirm_character_voice only after the user explicitly chooses a preview.",
32366
+ "- Generated sound effects and dialogue are saved in the project.",
32367
+ "- Voice audition previews are not saved to the project.",
32368
+ "- Local MCP does not transcode generated audio to OGG.",
32369
+ "- Use create_3d_asset with start/query/continue/post_process for game 3D model assets.",
32351
32370
  "- For any ad-related request, call get_ad_config first to get ad activation status and ad config.",
32352
32371
  "- Do not infer ad readiness from local SDK docs, .maker-mcp/config.json, or runtime callbacks.",
32353
32372
  "- If .project/project.json is missing, build once with maker_build_current_directory, then call get_ad_config again.",
@@ -32357,8 +32376,8 @@ function formatMakerSkillStatus(_options = {}) {
32357
32376
  "- Generated assets are saved under assets/image, assets/video, assets/audio, or assets/model with remote mappings.",
32358
32377
  "- Follow each tool schema for supported local path, remote URL, and data URL inputs.",
32359
32378
  "- Local proxy may convert resolvable local reference media to data URLs before forwarding.",
32360
- "- Generated 3D outputs save original GLB/FBX and MDL zip under assets/model.",
32361
- "- MDL zip contents are extracted into assets/Meshes, assets/Materials, assets/Textures, and assets/Prefabs.",
32379
+ "- create_3d_asset local runtime model_files copy/extract instructions are materialized under assets/model.",
32380
+ "- Use local_delivery for the usable local model path and preview_assets for local review images.",
32362
32381
  "Maker initialization next_step: execute `taptap-maker init`.",
32363
32382
  "Load these documents when the current AI client supports reading local guide files."
32364
32383
  ].join("\n");
@@ -33467,6 +33486,7 @@ function sameStringSet(left, right) {
33467
33486
  // src/maker/server/proxyAssets.ts
33468
33487
  import fs15 from "node:fs";
33469
33488
  import path16 from "node:path";
33489
+ import { randomUUID } from "node:crypto";
33470
33490
  var IMAGE_ASSET_DIRS = ["assets/image"];
33471
33491
  var VIDEO_ASSET_DIRS = ["assets/video"];
33472
33492
  var AUDIO_ASSET_DIRS = ["assets/audio"];
@@ -33476,7 +33496,12 @@ var IMAGE_REFERENCE_MAX_BYTES = 10 * 1024 * 1024;
33476
33496
  var VIDEO_TASK_IMAGE_REFERENCE_MAX_BYTES = 30 * 1024 * 1024;
33477
33497
  var VIDEO_REFERENCE_MAX_BYTES = 50 * 1024 * 1024;
33478
33498
  var AUDIO_REFERENCE_MAX_BYTES = 15 * 1024 * 1024;
33499
+ var AUDIO_DIALOGUE_REFERENCE_MAX_BYTES = 20 * 1024 * 1024;
33500
+ var AUDIO_DIALOGUE_INPUT_TOTAL_MAX_BYTES = 28 * 1024 * 1024;
33501
+ var AUDIO_CONFIRM_MAX_BYTES = 1 * 1024 * 1024;
33502
+ var VOICE_CONFIRMATION_NEXT_STEP_HINT = "Call text_to_dialogue with character_name and text. The confirmed voice mapping is reused automatically; omit reference_audio unless the user requests a one-time override.";
33479
33503
  var DEBUG_FEEDBACK_PATH_HINT = "Use local_dir/local_log_paths/local_screenshot_paths when they are returned. If only local_candidate_* is present, it is a possible project-relative location and must not be treated as a downloaded local file.";
33504
+ var CREATE_3D_ASSET_PROXY_TOOL_NAME = "create_3d_asset";
33480
33505
  var DATA_URL_MIME_BY_EXTENSION = {
33481
33506
  image: {
33482
33507
  ".gif": "image/gif",
@@ -33490,10 +33515,20 @@ var DATA_URL_MIME_BY_EXTENSION = {
33490
33515
  ".mp4": "video/mp4"
33491
33516
  },
33492
33517
  audio: {
33518
+ ".aac": "audio/aac",
33519
+ ".m4a": "audio/mp4",
33493
33520
  ".mp3": "audio/mpeg",
33521
+ ".ogg": "audio/ogg",
33494
33522
  ".wav": "audio/wav"
33495
33523
  }
33496
33524
  };
33525
+ var AUDIO_MIME_BY_EXTENSION = {
33526
+ ".aac": "audio/aac",
33527
+ ".m4a": "audio/mp4",
33528
+ ".mp3": "audio/mpeg",
33529
+ ".ogg": "audio/ogg",
33530
+ ".wav": "audio/wav"
33531
+ };
33497
33532
  var RemoteProxyToolResultError = class extends Error {
33498
33533
  constructor(toolName, result) {
33499
33534
  super(
@@ -33509,6 +33544,9 @@ var RemoteProxyToolResultError = class extends Error {
33509
33544
  }
33510
33545
  };
33511
33546
  function prepareRemoteProxyToolArgs(options) {
33547
+ if (options.toolName === "audition_voices_for_character") {
33548
+ return validateVoiceAuditionArgs(options.args);
33549
+ }
33512
33550
  if (options.toolName === "edit_image") {
33513
33551
  return rewriteEditImageAssetArgs(options.targetDir, options.args);
33514
33552
  }
@@ -33521,11 +33559,24 @@ function prepareRemoteProxyToolArgs(options) {
33521
33559
  if (options.toolName === "create_video_task") {
33522
33560
  return rewriteVideoReferenceAssetArgs(options.targetDir, options.args);
33523
33561
  }
33524
- if (options.toolName === "create_3d_model_task") {
33525
- return rewrite3dModelAssetArgs(options.targetDir, options.args);
33562
+ if (options.toolName === CREATE_3D_ASSET_PROXY_TOOL_NAME) {
33563
+ return rewriteCreate3dAssetArgs(options.targetDir, options.args);
33564
+ }
33565
+ if (options.toolName === "text_to_dialogue") {
33566
+ return rewriteTextToDialogueArgs(options.targetDir, options.args);
33526
33567
  }
33527
33568
  return options.args;
33528
33569
  }
33570
+ function validateVoiceAuditionArgs(args) {
33571
+ const voiceProfile = args.voice_profile;
33572
+ const gender = isRecord(voiceProfile) ? voiceProfile.gender : void 0;
33573
+ if (gender !== "male" && gender !== "female") {
33574
+ throw new Error(
33575
+ "voice_profile.gender is required for character voice audition and must be male or female. Extract it from character_description or the character settings before retrying."
33576
+ );
33577
+ }
33578
+ return args;
33579
+ }
33529
33580
  async function materializeRemoteProxyToolAssets(options) {
33530
33581
  if (isRemoteProxyToolErrorResult(options.result)) {
33531
33582
  throw new RemoteProxyToolResultError(options.toolName, options.result);
@@ -33586,8 +33637,12 @@ function shouldMaterializeRemoteProxyTool(toolName) {
33586
33637
  "create_video_task",
33587
33638
  "query_video_task",
33588
33639
  "text_to_music",
33589
- "create_3d_model_task",
33590
- "query_3d_model_task",
33640
+ "text_to_sound_effect",
33641
+ "batch_sound_effects",
33642
+ "text_to_dialogue",
33643
+ "audition_voices_for_character",
33644
+ "confirm_character_voice",
33645
+ CREATE_3D_ASSET_PROXY_TOOL_NAME,
33591
33646
  "get_debug_feedbacks"
33592
33647
  ].includes(toolName);
33593
33648
  }
@@ -33634,8 +33689,14 @@ async function materializeParsedProxyResult(options) {
33634
33689
  if (options.toolName === "text_to_music") {
33635
33690
  return await materializeMusicResult(options);
33636
33691
  }
33637
- if (options.toolName === "create_3d_model_task" || options.toolName === "query_3d_model_task") {
33638
- return await materialize3dModelResult(options, options.toolName);
33692
+ if (options.toolName === "text_to_sound_effect" || options.toolName === "batch_sound_effects" || options.toolName === "text_to_dialogue") {
33693
+ return await materializeAudioFilesResult(options, options.toolName);
33694
+ }
33695
+ if (options.toolName === "confirm_character_voice") {
33696
+ return await materializeVoiceConfirmationResult(options);
33697
+ }
33698
+ if (options.toolName === CREATE_3D_ASSET_PROXY_TOOL_NAME) {
33699
+ return await materializeCreate3dAssetResult(options);
33639
33700
  }
33640
33701
  if (options.toolName === "get_debug_feedbacks") {
33641
33702
  return await materializeDebugFeedbackResult(options);
@@ -34007,214 +34068,719 @@ async function materializeMusicResult(options) {
34007
34068
  })
34008
34069
  } : options.payload;
34009
34070
  }
34010
- async function materialize3dModelResult(options, toolName) {
34011
- if (options.payload.phase === 1) {
34012
- return await materialize3dPreviewResult(options);
34071
+ async function materializeAudioFilesResult(options, toolName) {
34072
+ if (!Array.isArray(options.payload.audio_files)) return options.payload;
34073
+ const audioFiles = [];
34074
+ for (const rawItem of options.payload.audio_files) {
34075
+ if (!isRecord(rawItem)) {
34076
+ audioFiles.push(rawItem);
34077
+ continue;
34078
+ }
34079
+ const item = { ...rawItem };
34080
+ const audioUrl = stringField2(item.audioUrl);
34081
+ const kind = stringField2(item.kind);
34082
+ const expectedKind = toolName === "text_to_dialogue" ? "dialogue" : "sound_effect";
34083
+ const expectedDirectory = expectedKind === "dialogue" ? "assets/audio/voice" : "assets/audio/sfx";
34084
+ const targetDirectory = stringField2(item.targetDirectory);
34085
+ const suggestedFileName = stringField2(item.suggestedFileName);
34086
+ const validationError = validateAudioAssetContract({
34087
+ audioUrl,
34088
+ kind,
34089
+ expectedKind,
34090
+ targetDirectory,
34091
+ expectedDirectory,
34092
+ suggestedFileName,
34093
+ format: stringField2(item.format),
34094
+ mimeType: stringField2(item.mimeType)
34095
+ });
34096
+ if (validationError) {
34097
+ audioFiles.push({
34098
+ ...item,
34099
+ ...audioUrl ? { audioUrl } : {},
34100
+ download: { success: false, error: validationError }
34101
+ });
34102
+ continue;
34103
+ }
34104
+ const extension = audioExtensionForItem(item, suggestedFileName);
34105
+ const materialized = await materializeAudioAsset({
34106
+ targetDir: options.targetDir,
34107
+ targetDirectory: expectedDirectory,
34108
+ fileName: suggestedFileName,
34109
+ url: audioUrl,
34110
+ extension,
34111
+ now: options.now,
34112
+ fetchImpl: options.fetchImpl
34113
+ });
34114
+ audioFiles.push(
34115
+ materialized ? persistMaterializedAsset({
34116
+ targetDir: options.targetDir,
34117
+ toolName,
34118
+ payload: item,
34119
+ materialized,
34120
+ cdnUrl: audioUrl,
34121
+ now: options.now,
34122
+ extraRegistryFields: { assetKind: "audio", kind }
34123
+ }) : item
34124
+ );
34013
34125
  }
34014
- return await materialize3dFinalResult(options, toolName);
34126
+ return { ...options.payload, audio_files: audioFiles };
34015
34127
  }
34016
- async function materialize3dPreviewResult(options) {
34017
- if (!isRecord(options.payload.preview_urls)) {
34018
- return options.payload;
34128
+ function validateAudioAssetContract(options) {
34129
+ var _a3, _b;
34130
+ if (!options.audioUrl || !/^https?:\/\//i.test(options.audioUrl)) {
34131
+ return "audioUrl must be an HTTP(S) URL.";
34019
34132
  }
34020
- let changed = false;
34133
+ if (options.kind !== options.expectedKind) {
34134
+ return `audio_files item kind must be ${options.expectedKind} for this tool.`;
34135
+ }
34136
+ if (options.targetDirectory !== options.expectedDirectory) {
34137
+ return `targetDirectory must be ${options.expectedDirectory}.`;
34138
+ }
34139
+ const fileName = options.suggestedFileName;
34140
+ if (!fileName || fileName === "." || fileName === ".." || fileName.includes("/") || fileName.includes("\\") || fileName.includes("\0")) {
34141
+ return "suggestedFileName must be a safe basename.";
34142
+ }
34143
+ if (path16.basename(fileName) !== fileName || fileName.endsWith(".") || fileName.endsWith(" ")) {
34144
+ return "suggestedFileName must be a safe basename.";
34145
+ }
34146
+ const format = (_a3 = options.format) == null ? void 0 : _a3.toLowerCase();
34147
+ const mimeType = (_b = options.mimeType) == null ? void 0 : _b.toLowerCase();
34148
+ const extension = path16.extname(fileName).toLowerCase();
34149
+ const contract = {
34150
+ mp3: { mimeType: "audio/mpeg", extension: ".mp3" },
34151
+ wav: { mimeType: "audio/wav", extension: ".wav" },
34152
+ pcm: { mimeType: "audio/l16", extension: ".pcm" },
34153
+ ogg_opus: { mimeType: "audio/ogg", extension: ".ogg" }
34154
+ }[format || ""];
34155
+ if (!contract) {
34156
+ return "audio output format is unsupported; format must be one of mp3, wav, pcm, or ogg_opus.";
34157
+ }
34158
+ if (mimeType !== contract.mimeType || extension !== contract.extension) {
34159
+ return `audio output contract mismatch: format ${format} requires mime ${contract.mimeType} and extension ${contract.extension}.`;
34160
+ }
34161
+ return void 0;
34162
+ }
34163
+ function audioExtensionForItem(item, fileName) {
34164
+ var _a3;
34165
+ const format = (_a3 = stringField2(item.format)) == null ? void 0 : _a3.toLowerCase();
34166
+ const byFormat = {
34167
+ mp3: "mp3",
34168
+ wav: "wav",
34169
+ pcm: "pcm",
34170
+ ogg_opus: "ogg",
34171
+ ogg: "ogg",
34172
+ m4a: "m4a",
34173
+ aac: "aac"
34174
+ };
34175
+ return byFormat[format || ""] || path16.extname(fileName).slice(1).toLowerCase() || "mp3";
34176
+ }
34177
+ async function materializeAudioAsset(options) {
34178
+ const relativeDir = options.targetDirectory;
34179
+ const directory = path16.join(options.targetDir, ...relativeDir.split("/"));
34180
+ try {
34181
+ fs15.mkdirSync(directory, { recursive: true });
34182
+ assertProjectDirectory(options.targetDir, directory);
34183
+ } catch (error2) {
34184
+ return {
34185
+ download: {
34186
+ success: false,
34187
+ error: `Audio target directory is outside the project: ${error2 instanceof Error ? error2.message : String(error2)}`
34188
+ }
34189
+ };
34190
+ }
34191
+ const baseName = path16.basename(options.fileName, path16.extname(options.fileName));
34192
+ let absolutePath;
34193
+ let relativePath;
34194
+ for (let index = 1; index <= 9999; index += 1) {
34195
+ const suffix = index === 1 ? "" : `_${index}`;
34196
+ const candidateName = `${baseName}${suffix}.${options.extension}`;
34197
+ const candidate = path16.join(directory, candidateName);
34198
+ if (!fs15.existsSync(candidate)) {
34199
+ absolutePath = candidate;
34200
+ relativePath = path16.posix.join(relativeDir, candidateName);
34201
+ break;
34202
+ }
34203
+ }
34204
+ if (!absolutePath || !relativePath) {
34205
+ return { download: { success: false, error: "Unable to allocate a unique audio asset path." } };
34206
+ }
34207
+ try {
34208
+ const response = await options.fetchImpl(options.url);
34209
+ if (!response.ok) {
34210
+ return {
34211
+ download: { success: false, error: `Asset download failed: HTTP ${response.status}` }
34212
+ };
34213
+ }
34214
+ const bytes = Buffer.from(await response.arrayBuffer());
34215
+ if (bytes.length === 0) {
34216
+ return { download: { success: false, error: "Asset download failed: empty response." } };
34217
+ }
34218
+ fs15.writeFileSync(absolutePath, bytes, { flag: "wx" });
34219
+ return { localPath: relativePath, absolutePath, download: { success: true } };
34220
+ } catch (error2) {
34221
+ return {
34222
+ download: {
34223
+ success: false,
34224
+ error: `Asset download failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34225
+ }
34226
+ };
34227
+ }
34228
+ }
34229
+ async function materializeVoiceConfirmationResult(options) {
34230
+ if (options.payload.success !== true || !isRecord(options.payload.mapping)) {
34231
+ return withoutVoiceConfirmationNextStepHint(options.payload);
34232
+ }
34233
+ const payload = withoutVoiceConfirmationNextStepHint(options.payload);
34234
+ const successfulPayload = withVoiceConfirmationNextStepHint(options.payload);
34235
+ const mapping = payload.mapping;
34236
+ const provider = stringField2(mapping.provider);
34237
+ const characterName = stringField2(mapping.characterName) || stringField2(payload.characterName);
34238
+ if (!characterName || provider === "elevenlabs") {
34239
+ if (provider !== "elevenlabs" || !characterName) return payload;
34240
+ try {
34241
+ mergeVoiceMappingFile({
34242
+ targetDir: options.targetDir,
34243
+ provider: "elevenlabs",
34244
+ characterName,
34245
+ mapping,
34246
+ now: options.now
34247
+ });
34248
+ return successfulPayload;
34249
+ } catch (error2) {
34250
+ const message = `ElevenLabs voice mapping persistence failed: ${error2 instanceof Error ? error2.message : String(error2)}`;
34251
+ return {
34252
+ ...payload,
34253
+ localPersistenceError: message,
34254
+ mappingPersistenceError: message
34255
+ };
34256
+ }
34257
+ }
34258
+ if (provider !== "doubao" || !isRecord(payload.referenceAudio)) {
34259
+ return payload;
34260
+ }
34261
+ const referenceAudio = payload.referenceAudio;
34262
+ const audioUrl = stringField2(referenceAudio.audioUrl);
34263
+ const targetPath = stringField2(referenceAudio.targetPath);
34264
+ const pathError = validateDoubaoReferenceTarget(targetPath);
34265
+ if (!audioUrl || pathError) {
34266
+ return {
34267
+ ...payload,
34268
+ referenceAudio: {
34269
+ ...referenceAudio,
34270
+ download: { success: false, error: pathError || "referenceAudio.audioUrl is required." }
34271
+ }
34272
+ };
34273
+ }
34274
+ let bytes;
34275
+ try {
34276
+ const response = await options.fetchImpl(audioUrl);
34277
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
34278
+ bytes = Buffer.from(await response.arrayBuffer());
34279
+ } catch (error2) {
34280
+ return {
34281
+ ...payload,
34282
+ referenceAudio: {
34283
+ ...referenceAudio,
34284
+ download: {
34285
+ success: false,
34286
+ error: `Reference audio download failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34287
+ }
34288
+ }
34289
+ };
34290
+ }
34291
+ if (bytes.length === 0 || bytes.length > AUDIO_CONFIRM_MAX_BYTES || !isStructurallyValidMp3(bytes)) {
34292
+ return {
34293
+ ...payload,
34294
+ referenceAudio: {
34295
+ ...referenceAudio,
34296
+ download: {
34297
+ success: false,
34298
+ error: "Reference audio must be a non-empty valid MP3 no larger than 1 MiB."
34299
+ }
34300
+ }
34301
+ };
34302
+ }
34303
+ try {
34304
+ mergeVoiceMappingFile({
34305
+ targetDir: options.targetDir,
34306
+ provider: "doubao",
34307
+ characterName,
34308
+ mapping,
34309
+ now: options.now,
34310
+ referenceAudio: { targetPath, bytes }
34311
+ });
34312
+ return {
34313
+ ...successfulPayload,
34314
+ referenceAudio: {
34315
+ ...referenceAudio,
34316
+ localPath: targetPath,
34317
+ absolutePath: path16.join(options.targetDir, ...targetPath.split("/")),
34318
+ download: { success: true }
34319
+ }
34320
+ };
34321
+ } catch (error2) {
34322
+ return {
34323
+ ...payload,
34324
+ referenceAudio: {
34325
+ ...referenceAudio,
34326
+ download: {
34327
+ success: false,
34328
+ error: `Voice mapping transaction failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34329
+ }
34330
+ }
34331
+ };
34332
+ }
34333
+ }
34334
+ function withVoiceConfirmationNextStepHint(payload) {
34335
+ return typeof payload.next_step_hint === "string" && payload.next_step_hint.trim() ? payload : { ...payload, next_step_hint: VOICE_CONFIRMATION_NEXT_STEP_HINT };
34336
+ }
34337
+ function withoutVoiceConfirmationNextStepHint(payload) {
34338
+ if (!Object.prototype.hasOwnProperty.call(payload, "next_step_hint")) return payload;
34339
+ const nextPayload = { ...payload };
34340
+ delete nextPayload.next_step_hint;
34341
+ return nextPayload;
34342
+ }
34343
+ function validateDoubaoReferenceTarget(targetPath) {
34344
+ if (!targetPath) return "referenceAudio.targetPath is required.";
34345
+ if (!/^assets\/audio\/voice-reference\/[^/]+\.mp3$/.test(targetPath)) {
34346
+ return "referenceAudio.targetPath must be assets/audio/voice-reference/<basename>.mp3.";
34347
+ }
34348
+ const base = path16.posix.basename(targetPath, ".mp3");
34349
+ if (!base || base === "." || base === ".." || base.includes("\\") || base.includes("\0")) {
34350
+ return "referenceAudio.targetPath contains an unsafe basename.";
34351
+ }
34352
+ return void 0;
34353
+ }
34354
+ function isStructurallyValidMp3(bytes) {
34355
+ const firstOffset = mp3AudioOffset(bytes);
34356
+ if (firstOffset === void 0) return false;
34357
+ const first = parseMp3Frame(bytes, firstOffset);
34358
+ if (!first) return false;
34359
+ const second = parseMp3Frame(bytes, firstOffset + first.length);
34360
+ return Boolean(
34361
+ second && second.version === first.version && second.sampleRate === first.sampleRate
34362
+ );
34363
+ }
34364
+ function mp3AudioOffset(bytes) {
34365
+ if (bytes.subarray(0, 3).toString("ascii") !== "ID3") return 0;
34366
+ if (bytes.length < 10 || bytes[3] < 2 || bytes[3] > 4) return void 0;
34367
+ const sizeBytes = bytes.subarray(6, 10);
34368
+ if (sizeBytes.some((value) => (value & 128) !== 0)) return void 0;
34369
+ const size = sizeBytes[0] << 21 | sizeBytes[1] << 14 | sizeBytes[2] << 7 | sizeBytes[3];
34370
+ const offset = 10 + size + (bytes[3] === 4 && (bytes[5] & 16) !== 0 ? 10 : 0);
34371
+ return offset <= bytes.length ? offset : void 0;
34372
+ }
34373
+ function parseMp3Frame(bytes, offset) {
34374
+ if (offset + 4 > bytes.length || bytes[offset] !== 255 || (bytes[offset + 1] & 224) !== 224) {
34375
+ return void 0;
34376
+ }
34377
+ const versionBits = bytes[offset + 1] >> 3 & 3;
34378
+ const version2 = versionBits === 3 ? 1 : versionBits === 2 ? 2 : versionBits === 0 ? 2.5 : void 0;
34379
+ if (!version2 || (bytes[offset + 1] >> 1 & 3) !== 1) return void 0;
34380
+ const bitrateIndex = bytes[offset + 2] >> 4 & 15;
34381
+ const rateIndex = bytes[offset + 2] >> 2 & 3;
34382
+ if (bitrateIndex === 0 || bitrateIndex === 15 || rateIndex === 3) return void 0;
34383
+ const mpeg1Rates = [0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320];
34384
+ const mpeg2Rates = [0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160];
34385
+ const bitrate = (version2 === 1 ? mpeg1Rates : mpeg2Rates)[bitrateIndex];
34386
+ const baseSampleRate = [44100, 48e3, 32e3][rateIndex];
34387
+ const sampleRate = version2 === 1 ? baseSampleRate : version2 === 2 ? baseSampleRate / 2 : baseSampleRate / 4;
34388
+ const padding = bytes[offset + 2] >> 1 & 1;
34389
+ const length = Math.floor((version2 === 1 ? 144 : 72) * bitrate * 1e3 / sampleRate) + padding;
34390
+ return length > 4 && offset + length <= bytes.length ? { length, version: version2, sampleRate } : void 0;
34391
+ }
34392
+ function mergeVoiceMappingFile(options) {
34393
+ const configPath = path16.join(
34394
+ options.targetDir,
34395
+ ".project",
34396
+ options.provider === "doubao" ? "audio-voice-mapping.json" : "elevenlabs-voice-mapping.json"
34397
+ );
34398
+ const referencePath = options.referenceAudio ? path16.join(options.targetDir, ...options.referenceAudio.targetPath.split("/")) : void 0;
34399
+ const configDirectory = path16.dirname(configPath);
34400
+ const referenceDirectory = referencePath ? path16.dirname(referencePath) : void 0;
34401
+ fs15.mkdirSync(configDirectory, { recursive: true });
34402
+ assertProjectDirectory(options.targetDir, configDirectory);
34403
+ assertFileIsNotSymlink(configPath);
34404
+ if (referenceDirectory) {
34405
+ fs15.mkdirSync(referenceDirectory, { recursive: true });
34406
+ assertProjectDirectory(options.targetDir, referenceDirectory);
34407
+ assertFileIsNotSymlink(referencePath);
34408
+ }
34409
+ const oldConfig = snapshotFile(configPath);
34410
+ const oldReference = referencePath ? snapshotFile(referencePath) : void 0;
34411
+ const existing = readJsonFile2(configPath);
34412
+ const characters = isRecord(existing == null ? void 0 : existing.characters) ? { ...existing.characters } : {};
34413
+ const oldCharacter = isRecord(characters[options.characterName]) ? characters[options.characterName] : {};
34414
+ const createdAt = stringField2(oldCharacter.created_at) || options.now.toISOString();
34415
+ const character = {
34416
+ ...oldCharacter,
34417
+ ...Object.fromEntries(
34418
+ Object.entries(options.mapping).filter(([key]) => key !== "characterName")
34419
+ ),
34420
+ provider: options.provider,
34421
+ language: stringField2(options.mapping.language) || stringField2(oldCharacter.language) || stringField2(existing == null ? void 0 : existing.default_language) || "cmn",
34422
+ stability: typeof options.mapping.stability === "number" ? options.mapping.stability : typeof oldCharacter.stability === "number" ? oldCharacter.stability : typeof (existing == null ? void 0 : existing.default_stability) === "number" ? existing.default_stability : 0.5,
34423
+ created_at: createdAt,
34424
+ last_used: options.now.toISOString()
34425
+ };
34426
+ characters[options.characterName] = character;
34427
+ const nextConfig = {
34428
+ ...existing,
34429
+ version: options.provider === "doubao" ? 4 : "1.0",
34430
+ provider: options.provider,
34431
+ characters
34432
+ };
34433
+ if (options.provider === "doubao") {
34434
+ nextConfig.default_language = stringField2(existing == null ? void 0 : existing.default_language) || "cmn";
34435
+ nextConfig.default_stability = typeof (existing == null ? void 0 : existing.default_stability) === "number" ? existing.default_stability : 0.5;
34436
+ nextConfig.special_voices = isRecord(existing == null ? void 0 : existing.special_voices) ? existing.special_voices : {};
34437
+ } else {
34438
+ delete nextConfig.default_language;
34439
+ delete nextConfig.default_stability;
34440
+ delete nextConfig.special_voices;
34441
+ }
34442
+ const configBytes = Buffer.from(`${JSON.stringify(nextConfig, null, 2)}
34443
+ `, "utf8");
34444
+ const transactionId = randomUUID();
34445
+ const configTemp = `${configPath}.${transactionId}.tmp`;
34446
+ const referenceTemp = referencePath ? `${referencePath}.${transactionId}.tmp` : void 0;
34447
+ try {
34448
+ if (referenceTemp && options.referenceAudio) {
34449
+ fs15.writeFileSync(referenceTemp, options.referenceAudio.bytes, { flag: "wx" });
34450
+ fs15.renameSync(referenceTemp, referencePath);
34451
+ }
34452
+ fs15.writeFileSync(configTemp, configBytes, { flag: "wx" });
34453
+ fs15.renameSync(configTemp, configPath);
34454
+ } catch (error2) {
34455
+ try {
34456
+ if (fs15.existsSync(configTemp)) fs15.rmSync(configTemp, { force: true });
34457
+ if (referenceTemp && fs15.existsSync(referenceTemp)) fs15.rmSync(referenceTemp, { force: true });
34458
+ restoreFile(configPath, oldConfig);
34459
+ if (referencePath) restoreFile(referencePath, oldReference);
34460
+ } catch {
34461
+ }
34462
+ throw error2;
34463
+ }
34464
+ }
34465
+ function snapshotFile(filePath) {
34466
+ try {
34467
+ assertFileIsNotSymlink(filePath);
34468
+ return { exists: true, bytes: fs15.readFileSync(filePath) };
34469
+ } catch {
34470
+ if (isSymlink(filePath)) {
34471
+ throw new Error(`refusing to read symlinked file: ${filePath}`);
34472
+ }
34473
+ return { exists: false };
34474
+ }
34475
+ }
34476
+ function restoreFile(filePath, snapshot) {
34477
+ assertFileIsNotSymlink(filePath);
34478
+ if (snapshot.exists && snapshot.bytes) {
34479
+ fs15.mkdirSync(path16.dirname(filePath), { recursive: true });
34480
+ fs15.writeFileSync(filePath, snapshot.bytes);
34481
+ } else {
34482
+ fs15.rmSync(filePath, { force: true });
34483
+ }
34484
+ }
34485
+ function readJsonFile2(filePath) {
34486
+ assertFileIsNotSymlink(filePath);
34487
+ try {
34488
+ const parsed = JSON.parse(fs15.readFileSync(filePath, "utf8"));
34489
+ return isRecord(parsed) ? parsed : void 0;
34490
+ } catch {
34491
+ return void 0;
34492
+ }
34493
+ }
34494
+ async function materializeCreate3dAssetResult(options) {
34495
+ var _a3;
34496
+ const payload = isRecord(options.payload.preview) ? await materializeCreate3dAssetPreviewResult(options) : options.payload;
34497
+ const modelFile = Array.isArray(payload.model_files) ? payload.model_files.find(isRecord) : void 0;
34498
+ if (!modelFile) {
34499
+ return payload;
34500
+ }
34501
+ const assetId = stringField2(modelFile.assetId) || stringField2(payload.asset_id) || stringField2(payload.task_id) || "3d_asset";
34502
+ const remoteUrl = stringField2(modelFile.modelUrl);
34503
+ const format = (_a3 = stringField2(modelFile.format)) == null ? void 0 : _a3.toLowerCase();
34504
+ const materialization = stringField2(modelFile.materialization);
34505
+ if (!remoteUrl || !format || !materialization) {
34506
+ return {
34507
+ ...payload,
34508
+ local_delivery: create3dAssetDeliveryFailure(
34509
+ assetId,
34510
+ remoteUrl,
34511
+ format,
34512
+ materialization,
34513
+ "Invalid create_3d_asset model_files entry."
34514
+ )
34515
+ };
34516
+ }
34517
+ const existing = findExistingCreate3dAssetDelivery({
34518
+ targetDir: options.targetDir,
34519
+ assetId,
34520
+ remoteUrl
34521
+ });
34522
+ if (existing) {
34523
+ return {
34524
+ ...payload,
34525
+ local_delivery: create3dAssetLocalDelivery({
34526
+ assetId,
34527
+ remoteUrl,
34528
+ format,
34529
+ materialization,
34530
+ materialized: existing,
34531
+ reused: true
34532
+ })
34533
+ };
34534
+ }
34535
+ const materialized = await materializeCreate3dAssetModelFile({
34536
+ ...options,
34537
+ assetId,
34538
+ modelFile,
34539
+ remoteUrl,
34540
+ format,
34541
+ materialization
34542
+ });
34543
+ if ("localPath" in materialized) {
34544
+ upsertGeneratedAssetRecord(options.targetDir, materialized.localPath, {
34545
+ tool: CREATE_3D_ASSET_PROXY_TOOL_NAME,
34546
+ name: assetId,
34547
+ assetKind: "model",
34548
+ assetId,
34549
+ taskId: stringField2(payload.task_id),
34550
+ cdnUrl: remoteUrl,
34551
+ previewUrl: remoteUrl,
34552
+ localPath: materialized.localPath,
34553
+ absolutePath: materialized.absolutePath,
34554
+ createdAt: options.now.toISOString(),
34555
+ modelCdnUrl: remoteUrl
34556
+ });
34557
+ }
34558
+ return {
34559
+ ...payload,
34560
+ local_delivery: create3dAssetLocalDelivery({
34561
+ assetId,
34562
+ remoteUrl,
34563
+ format,
34564
+ materialization,
34565
+ materialized,
34566
+ reused: false
34567
+ })
34568
+ };
34569
+ }
34570
+ async function materializeCreate3dAssetPreviewResult(options) {
34571
+ const preview = options.payload.preview;
34572
+ const assetId = stringField2(options.payload.asset_id) || "3d_asset";
34021
34573
  const previewAssets = {};
34022
- const taskId = get3dTaskId(options.payload);
34023
- const mode = stringField2(options.payload.mode);
34024
34574
  for (const view of THREE_D_MODEL_VIEWS) {
34025
- const url2 = stringField2(options.payload.preview_urls[view]);
34575
+ const url2 = stringField2(preview[view]);
34026
34576
  const materialized = await materializeAsset({
34027
34577
  targetDir: options.targetDir,
34028
34578
  url: url2,
34029
- baseName: `${taskId || "3d_model"}_${view}`,
34030
- relativeDir: "assets/image",
34579
+ baseName: `${assetId}_${view}`,
34580
+ relativeDir: IMAGE_ASSET_DIRS[0],
34031
34581
  extension: extensionFromUrl(url2) || "png",
34032
34582
  now: options.now,
34033
34583
  fetchImpl: options.fetchImpl
34034
34584
  });
34035
- if (!materialized) {
34036
- continue;
34037
- }
34038
- changed = true;
34585
+ if (!materialized) continue;
34039
34586
  previewAssets[view] = { ...materialized, cdnUrl: url2 };
34040
34587
  if ("localPath" in materialized && url2) {
34041
34588
  upsertGeneratedAssetRecord(options.targetDir, materialized.localPath, {
34042
- tool: "create_3d_model_task",
34043
- name: `${taskId || "3d_model"}_${view}`,
34589
+ tool: CREATE_3D_ASSET_PROXY_TOOL_NAME,
34590
+ name: `${assetId}_${view}`,
34591
+ assetId,
34044
34592
  cdnUrl: url2,
34045
34593
  previewUrl: url2,
34046
34594
  localPath: materialized.localPath,
34047
34595
  absolutePath: materialized.absolutePath,
34048
34596
  createdAt: options.now.toISOString(),
34049
- taskId,
34050
- mode,
34051
- phase: 1,
34052
34597
  view
34053
34598
  });
34054
34599
  }
34055
34600
  }
34056
- return {
34057
- ...options.payload,
34058
- ...changed ? { preview_assets: previewAssets } : {},
34059
- ...create3dPreviewReviewGuidance()
34060
- };
34061
- }
34062
- function create3dPreviewReviewGuidance() {
34063
- return {
34064
- workflow_state: "awaiting_user_review",
34065
- user_review_required: true,
34066
- next_action: "Show the four-view previews to the user and ask whether they approve them or want changes.",
34067
- approval_next_step: "If the user approves, continue the original 3D model generation flow by calling create_3d_model_task again with the approved four-view images.",
34068
- revision_next_step: "If the user requests changes, call create_3d_model_task again with the requested changes to regenerate the four-view previews before model generation.",
34069
- agent_instruction: "Do not stop after phase 1. The 3D model is not complete until the user approves the four-view previews and final model generation finishes."
34070
- };
34601
+ return Object.keys(previewAssets).length > 0 ? { ...options.payload, preview_assets: previewAssets } : options.payload;
34071
34602
  }
34072
- async function materialize3dFinalResult(options, toolName) {
34073
- if (options.payload.status !== "success") {
34074
- return options.payload;
34603
+ async function materializeCreate3dAssetModelFile(options) {
34604
+ var _a3;
34605
+ const targetDirectory = stringField2(options.modelFile.targetDirectory);
34606
+ const suggestedFileName = stringField2(options.modelFile.suggestedFileName);
34607
+ const targetAbsolutePath = targetDirectory ? resolveProjectRelativePath(options.targetDir, targetDirectory) : void 0;
34608
+ const modelAssetRoot = path16.resolve(options.targetDir, MODEL_ASSET_DIRS[0]);
34609
+ if (!targetDirectory || !targetAbsolutePath || !isKnownAssetPath(targetDirectory, MODEL_ASSET_DIRS) || !isPathWithinDirectory(modelAssetRoot, targetAbsolutePath) || !suggestedFileName || path16.posix.basename(suggestedFileName) !== suggestedFileName || suggestedFileName.includes("\\")) {
34610
+ return {
34611
+ download: { success: false, error: "Invalid create_3d_asset local target path." }
34612
+ };
34075
34613
  }
34076
- let changed = false;
34077
- const nextPayload = { ...options.payload };
34078
- const taskId = get3dTaskId(options.payload);
34079
- const modelCdnUrl = stringField2(options.payload.model_cdn_url);
34080
- const renderedImageUrl = stringField2(options.payload.rendered_image_url);
34081
- const mdlConversionError = stringField2(options.payload.mdl_conversion_error);
34082
- const modelMaterialized = await materializeAsset({
34083
- targetDir: options.targetDir,
34084
- url: modelCdnUrl,
34085
- baseName: taskId || "3d_model",
34086
- relativeDir: MODEL_ASSET_DIRS[0],
34087
- extension: extensionFromUrl(modelCdnUrl) || "glb",
34088
- now: options.now,
34089
- fetchImpl: options.fetchImpl
34090
- });
34091
- if (modelMaterialized) {
34092
- changed = true;
34093
- nextPayload.modelDownload = modelMaterialized.download;
34094
- if ("localPath" in modelMaterialized) {
34095
- nextPayload.modelLocalPath = modelMaterialized.localPath;
34096
- nextPayload.modelAbsolutePath = modelMaterialized.absolutePath;
34097
- if (modelCdnUrl) {
34098
- upsertGeneratedAssetRecord(options.targetDir, modelMaterialized.localPath, {
34099
- tool: toolName,
34100
- name: taskId,
34101
- assetKind: "model",
34102
- cdnUrl: modelCdnUrl,
34103
- previewUrl: renderedImageUrl || modelCdnUrl,
34104
- localPath: modelMaterialized.localPath,
34105
- absolutePath: modelMaterialized.absolutePath,
34106
- createdAt: options.now.toISOString(),
34107
- taskId,
34108
- modelCdnUrl,
34109
- renderedImageUrl,
34110
- mdlConversionError
34111
- });
34614
+ if (options.materialization === "copy") {
34615
+ return await materializeAssetAtPath({
34616
+ url: options.remoteUrl,
34617
+ relativePath: path16.posix.join(targetDirectory, suggestedFileName),
34618
+ targetDir: options.targetDir,
34619
+ fetchImpl: options.fetchImpl
34620
+ });
34621
+ }
34622
+ if (options.materialization !== "extract") {
34623
+ return {
34624
+ download: {
34625
+ success: false,
34626
+ error: `Unsupported create_3d_asset materialization: ${options.materialization}`
34112
34627
  }
34113
- }
34628
+ };
34114
34629
  }
34115
- const mdlUrl = stringField2(options.payload.mdl_cdn_url);
34116
- const mdlMaterialized = await materializeAsset({
34630
+ const archive = await materializeAsset({
34117
34631
  targetDir: options.targetDir,
34118
- url: mdlUrl,
34119
- baseName: taskId || "3d_model",
34120
- relativeDir: MODEL_ASSET_DIRS[0],
34121
- extension: extensionFromUrl(mdlUrl) || "zip",
34632
+ url: options.remoteUrl,
34633
+ baseName: options.assetId,
34634
+ relativeDir: ".maker/assets/downloads",
34635
+ extension: path16.extname(suggestedFileName).replace(/^\./, "") || "zip",
34122
34636
  now: options.now,
34123
34637
  fetchImpl: options.fetchImpl
34124
34638
  });
34125
- if (mdlMaterialized) {
34126
- changed = true;
34127
- nextPayload.mdlDownload = mdlMaterialized.download;
34128
- if ("localPath" in mdlMaterialized) {
34129
- nextPayload.mdlLocalPath = mdlMaterialized.localPath;
34130
- nextPayload.mdlAbsolutePath = mdlMaterialized.absolutePath;
34131
- let mdlExtractError;
34132
- try {
34133
- extractZip(
34134
- mdlMaterialized.absolutePath,
34135
- path16.join(options.targetDir, "assets"),
34136
- "3D model asset"
34137
- );
34138
- nextPayload.mdlExtracted = true;
34139
- nextPayload.mdlExtractedTo = "assets";
34140
- } catch (error2) {
34141
- mdlExtractError = `3D model asset extraction failed: ${error2 instanceof Error ? error2.message : String(error2)}`;
34142
- nextPayload.mdlExtracted = false;
34143
- nextPayload.mdlExtractError = mdlExtractError;
34144
- }
34145
- if (mdlUrl) {
34146
- upsertGeneratedAssetRecord(options.targetDir, mdlMaterialized.localPath, {
34147
- tool: toolName,
34148
- name: taskId,
34149
- assetKind: "mdl_zip",
34150
- cdnUrl: mdlUrl,
34151
- previewUrl: renderedImageUrl || mdlUrl,
34152
- localPath: mdlMaterialized.localPath,
34153
- absolutePath: mdlMaterialized.absolutePath,
34154
- createdAt: options.now.toISOString(),
34155
- taskId,
34156
- modelCdnUrl,
34157
- renderedImageUrl,
34158
- mdlConversionError,
34159
- mdlExtractError
34160
- });
34639
+ if (!archive || !("localPath" in archive)) {
34640
+ return archive ?? {
34641
+ download: { success: false, error: "Missing create_3d_asset model archive." }
34642
+ };
34643
+ }
34644
+ try {
34645
+ fs15.mkdirSync(targetAbsolutePath, { recursive: true });
34646
+ extractZip(archive.absolutePath, targetAbsolutePath, "3D model asset");
34647
+ const entrypointExtension = ((_a3 = stringField2(options.modelFile.entrypointExtension)) == null ? void 0 : _a3.toLowerCase()) || ".mdl";
34648
+ const entrypoint = findFileByExtension(targetAbsolutePath, entrypointExtension);
34649
+ if (!entrypoint) {
34650
+ throw new Error(`3D model archive contains no ${entrypointExtension} entrypoint.`);
34651
+ }
34652
+ const localPath = path16.relative(options.targetDir, entrypoint).split(path16.sep).join("/");
34653
+ return {
34654
+ localPath,
34655
+ absolutePath: entrypoint,
34656
+ download: archive.download
34657
+ };
34658
+ } catch (error2) {
34659
+ return {
34660
+ download: {
34661
+ success: false,
34662
+ error: `3D model asset extraction failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34663
+ }
34664
+ };
34665
+ } finally {
34666
+ fs15.rmSync(archive.absolutePath, { force: true });
34667
+ }
34668
+ }
34669
+ async function materializeAssetAtPath(options) {
34670
+ const absolutePath = resolveProjectRelativePath(options.targetDir, options.relativePath);
34671
+ if (!absolutePath) {
34672
+ return { download: { success: false, error: "Asset target path escapes the project." } };
34673
+ }
34674
+ try {
34675
+ const response = await options.fetchImpl(options.url);
34676
+ if (!response.ok) {
34677
+ return {
34678
+ download: { success: false, error: `Asset download failed: HTTP ${response.status}` }
34679
+ };
34680
+ }
34681
+ fs15.mkdirSync(path16.dirname(absolutePath), { recursive: true });
34682
+ fs15.writeFileSync(absolutePath, Buffer.from(await response.arrayBuffer()));
34683
+ return { localPath: options.relativePath, absolutePath, download: { success: true } };
34684
+ } catch (error2) {
34685
+ return {
34686
+ download: {
34687
+ success: false,
34688
+ error: `Asset download failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34161
34689
  }
34690
+ };
34691
+ }
34692
+ }
34693
+ function findFileByExtension(directory, extension) {
34694
+ const entries = fs15.readdirSync(directory, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name));
34695
+ for (const entry of entries) {
34696
+ const absolutePath = path16.join(directory, entry.name);
34697
+ if (entry.isDirectory()) {
34698
+ const nested = findFileByExtension(absolutePath, extension);
34699
+ if (nested) return nested;
34700
+ } else if (entry.isFile() && entry.name.toLowerCase().endsWith(extension)) {
34701
+ return absolutePath;
34162
34702
  }
34163
34703
  }
34164
- const renderedImageMaterialized = await materializeAsset({
34165
- targetDir: options.targetDir,
34166
- url: renderedImageUrl,
34167
- baseName: `${taskId || "3d_model"}_render`,
34168
- relativeDir: "assets/image",
34169
- extension: extensionFromUrl(renderedImageUrl) || "png",
34170
- now: options.now,
34171
- fetchImpl: options.fetchImpl
34704
+ return void 0;
34705
+ }
34706
+ function findExistingCreate3dAssetDelivery(options) {
34707
+ const registry2 = readGeneratedAssetRegistry(options.targetDir);
34708
+ const match = Object.entries(registry2).find(([, record3]) => {
34709
+ return record3.tool === CREATE_3D_ASSET_PROXY_TOOL_NAME && record3.assetId === options.assetId && record3.cdnUrl === options.remoteUrl && typeof record3.absolutePath === "string" && fs15.existsSync(record3.absolutePath);
34172
34710
  });
34173
- if (renderedImageMaterialized) {
34174
- changed = true;
34175
- nextPayload.renderedImageDownload = renderedImageMaterialized.download;
34176
- if ("localPath" in renderedImageMaterialized) {
34177
- nextPayload.renderedImageLocalPath = renderedImageMaterialized.localPath;
34178
- nextPayload.renderedImageAbsolutePath = renderedImageMaterialized.absolutePath;
34179
- if (renderedImageUrl) {
34180
- upsertGeneratedAssetRecord(options.targetDir, renderedImageMaterialized.localPath, {
34181
- tool: toolName,
34182
- name: `${taskId || "3d_model"}_render`,
34183
- assetKind: "render",
34184
- cdnUrl: renderedImageUrl,
34185
- previewUrl: renderedImageUrl,
34186
- localPath: renderedImageMaterialized.localPath,
34187
- absolutePath: renderedImageMaterialized.absolutePath,
34188
- createdAt: options.now.toISOString(),
34189
- taskId,
34190
- modelCdnUrl,
34191
- renderedImageUrl,
34192
- mdlConversionError
34193
- });
34711
+ if (!match) {
34712
+ return void 0;
34713
+ }
34714
+ const [localPath, record2] = match;
34715
+ return {
34716
+ localPath,
34717
+ absolutePath: record2.absolutePath,
34718
+ download: { success: true }
34719
+ };
34720
+ }
34721
+ function create3dAssetLocalDelivery(options) {
34722
+ if (!("localPath" in options.materialized)) {
34723
+ return {
34724
+ status: "failed",
34725
+ asset_id: options.assetId,
34726
+ model: {
34727
+ remote_url: options.remoteUrl,
34728
+ format: options.format,
34729
+ materialization: options.materialization,
34730
+ download: options.materialized.download
34194
34731
  }
34195
- }
34732
+ };
34196
34733
  }
34197
- return changed ? nextPayload : options.payload;
34734
+ return {
34735
+ status: "success",
34736
+ asset_id: options.assetId,
34737
+ model: {
34738
+ remote_url: options.remoteUrl,
34739
+ local_path: options.materialized.localPath,
34740
+ absolute_path: options.materialized.absolutePath,
34741
+ format: options.format,
34742
+ materialization: options.materialization,
34743
+ reused: options.reused,
34744
+ download: options.materialized.download
34745
+ }
34746
+ };
34198
34747
  }
34199
- function get3dTaskId(payload) {
34200
- return stringField2(payload.task_id) || stringField2(payload.taskId);
34748
+ function create3dAssetDeliveryFailure(assetId, remoteUrl, format, materialization, error2) {
34749
+ return {
34750
+ status: "failed",
34751
+ asset_id: assetId,
34752
+ model: {
34753
+ remote_url: remoteUrl,
34754
+ format,
34755
+ materialization,
34756
+ download: { success: false, error: error2 }
34757
+ }
34758
+ };
34201
34759
  }
34202
34760
  function persistMaterializedAsset(options) {
34203
34761
  const nextPayload = { ...options.payload, ...options.materialized };
34204
34762
  if (!("localPath" in options.materialized) || !options.cdnUrl) {
34205
34763
  return nextPayload;
34206
34764
  }
34207
- upsertGeneratedAssetRecord(options.targetDir, options.materialized.localPath, {
34208
- tool: options.toolName,
34209
- name: stringField2(options.payload.name) || stringField2(options.payload.title),
34210
- prompt: stringField2(options.payload.prompt),
34211
- cdnUrl: options.cdnUrl,
34212
- previewUrl: options.cdnUrl,
34213
- localPath: options.materialized.localPath,
34214
- absolutePath: options.materialized.absolutePath,
34215
- createdAt: options.now.toISOString(),
34216
- ...options.extraRegistryFields
34217
- });
34765
+ try {
34766
+ upsertGeneratedAssetRecord(options.targetDir, options.materialized.localPath, {
34767
+ tool: options.toolName,
34768
+ name: stringField2(options.payload.name) || stringField2(options.payload.title),
34769
+ prompt: stringField2(options.payload.prompt),
34770
+ cdnUrl: options.cdnUrl,
34771
+ previewUrl: options.cdnUrl,
34772
+ localPath: options.materialized.localPath,
34773
+ absolutePath: options.materialized.absolutePath,
34774
+ createdAt: options.now.toISOString(),
34775
+ ...options.extraRegistryFields
34776
+ });
34777
+ } catch (error2) {
34778
+ return {
34779
+ ...nextPayload,
34780
+ registryError: `Generated asset registry persistence failed: ${error2 instanceof Error ? error2.message : String(error2)}`,
34781
+ localPersistenceError: `Generated asset registry persistence failed: ${error2 instanceof Error ? error2.message : String(error2)}`
34782
+ };
34783
+ }
34218
34784
  return nextPayload;
34219
34785
  }
34220
34786
  async function materializeAsset(options) {
@@ -34338,50 +34904,236 @@ function rewriteVideoReferenceAssetArgs(targetDir, args) {
34338
34904
  })
34339
34905
  };
34340
34906
  }
34341
- function rewrite3dModelAssetArgs(targetDir, args) {
34907
+ function rewriteCreate3dAssetArgs(targetDir, args) {
34908
+ if (!isRecord(args.payload) || !isRecord(args.payload.images)) {
34909
+ return args;
34910
+ }
34342
34911
  const registry2 = readGeneratedAssetRegistry(targetDir);
34343
34912
  const imageOptions = {
34344
34913
  assetDirs: IMAGE_ASSET_DIRS,
34345
34914
  mediaKind: "image",
34346
34915
  maxBytes: IMAGE_REFERENCE_MAX_BYTES
34347
34916
  };
34917
+ const images = args.payload.images;
34348
34918
  return {
34349
34919
  ...args,
34350
- image: rewriteGeneratedAssetReference(targetDir, args.image, registry2, imageOptions),
34351
- front_image: rewriteGeneratedAssetReference(
34352
- targetDir,
34353
- args.front_image,
34354
- registry2,
34355
- imageOptions
34356
- ),
34357
- left_image: rewriteGeneratedAssetReference(targetDir, args.left_image, registry2, imageOptions),
34358
- back_image: rewriteGeneratedAssetReference(targetDir, args.back_image, registry2, imageOptions),
34359
- right_image: rewriteGeneratedAssetReference(
34360
- targetDir,
34361
- args.right_image,
34362
- registry2,
34363
- imageOptions
34364
- ),
34365
- confirmed_image_paths: rewrite3dConfirmedImagePaths(
34366
- targetDir,
34367
- args.confirmed_image_paths,
34368
- registry2,
34369
- imageOptions
34370
- )
34920
+ payload: {
34921
+ ...args.payload,
34922
+ images: {
34923
+ ...images,
34924
+ front: rewriteGeneratedAssetReference(targetDir, images.front, registry2, imageOptions),
34925
+ left: rewriteGeneratedAssetReference(targetDir, images.left, registry2, imageOptions),
34926
+ back: rewriteGeneratedAssetReference(targetDir, images.back, registry2, imageOptions),
34927
+ right: rewriteGeneratedAssetReference(targetDir, images.right, registry2, imageOptions)
34928
+ }
34929
+ }
34371
34930
  };
34372
34931
  }
34373
- function rewrite3dConfirmedImagePaths(targetDir, value, registry2, options) {
34374
- if (!isRecord(value)) {
34375
- return value;
34932
+ function rewriteTextToDialogueArgs(targetDir, args) {
34933
+ if (!Array.isArray(args.inputs)) {
34934
+ return args;
34376
34935
  }
34936
+ const registry2 = readGeneratedAssetRegistry(targetDir);
34937
+ const localElevenLabsMapping = readLocalElevenLabsVoiceMapping(targetDir);
34938
+ const localDoubaoMapping = args.inputs.some(
34939
+ (value) => isRecord(value) && normalizeOptionalDialogueReference(value.reference_audio) === void 0 && normalizeOptionalDialogueReference(value.reference_audio_path) === void 0
34940
+ ) ? readLocalDoubaoVoiceMapping(targetDir) : void 0;
34941
+ let referenceAudioInputBytes = 0;
34377
34942
  return {
34378
- ...value,
34379
- front: rewriteGeneratedAssetReference(targetDir, value.front, registry2, options),
34380
- left: rewriteGeneratedAssetReference(targetDir, value.left, registry2, options),
34381
- back: rewriteGeneratedAssetReference(targetDir, value.back, registry2, options),
34382
- right: rewriteGeneratedAssetReference(targetDir, value.right, registry2, options)
34943
+ ...args,
34944
+ inputs: args.inputs.map((value, index) => {
34945
+ if (!isRecord(value)) {
34946
+ return value;
34947
+ }
34948
+ let canonicalReference = normalizeOptionalDialogueReference(value.reference_audio);
34949
+ const legacyReference = normalizeOptionalDialogueReference(value.reference_audio_path);
34950
+ if (canonicalReference !== void 0 && legacyReference !== void 0) {
34951
+ throw new Error(
34952
+ `inputs[${index}].reference_audio and reference_audio_path are mutually exclusive.`
34953
+ );
34954
+ }
34955
+ const normalizedValue = { ...value };
34956
+ delete normalizedValue.reference_audio;
34957
+ delete normalizedValue.reference_audio_path;
34958
+ delete normalizedValue._local_voice_id;
34959
+ const localVoiceId = resolveLocalElevenLabsVoiceId(
34960
+ value.character_name,
34961
+ localElevenLabsMapping
34962
+ );
34963
+ if (localVoiceId) {
34964
+ normalizedValue._local_voice_id = localVoiceId;
34965
+ }
34966
+ if (canonicalReference === void 0 && legacyReference === void 0) {
34967
+ canonicalReference = resolveLocalDoubaoMappingReference({
34968
+ targetDir,
34969
+ characterName: value.character_name,
34970
+ mapping: localDoubaoMapping,
34971
+ registry: registry2,
34972
+ index
34973
+ });
34974
+ }
34975
+ if (canonicalReference === void 0) canonicalReference = legacyReference;
34976
+ if (canonicalReference === void 0) return normalizedValue;
34977
+ const referenceAudio = normalizeDialogueReference(
34978
+ targetDir,
34979
+ canonicalReference,
34980
+ registry2,
34981
+ index
34982
+ );
34983
+ referenceAudioInputBytes += Buffer.byteLength(referenceAudio, "utf8");
34984
+ if (referenceAudioInputBytes > AUDIO_DIALOGUE_INPUT_TOTAL_MAX_BYTES) {
34985
+ throw new Error(
34986
+ `reference_audio input total must not exceed ${AUDIO_DIALOGUE_INPUT_TOTAL_MAX_BYTES / 1024 / 1024} MiB.`
34987
+ );
34988
+ }
34989
+ return {
34990
+ ...normalizedValue,
34991
+ reference_audio: referenceAudio
34992
+ };
34993
+ })
34383
34994
  };
34384
34995
  }
34996
+ async function prepareRemoteProxyToolArgsAsync(options) {
34997
+ return prepareRemoteProxyToolArgs(options);
34998
+ }
34999
+ function readLocalDoubaoVoiceMapping(targetDir) {
35000
+ const mappingPath = path16.join(targetDir, ".project", "audio-voice-mapping.json");
35001
+ if (!fs15.existsSync(mappingPath)) return void 0;
35002
+ assertProjectDirectory(targetDir, path16.dirname(mappingPath));
35003
+ const mapping = readJsonFile2(mappingPath);
35004
+ return (mapping == null ? void 0 : mapping.provider) === "doubao" ? mapping : void 0;
35005
+ }
35006
+ function readLocalElevenLabsVoiceMapping(targetDir) {
35007
+ const mappingPath = path16.join(targetDir, ".project", "elevenlabs-voice-mapping.json");
35008
+ if (!fs15.existsSync(mappingPath)) return void 0;
35009
+ assertProjectDirectory(targetDir, path16.dirname(mappingPath));
35010
+ const mapping = readJsonFile2(mappingPath);
35011
+ return (mapping == null ? void 0 : mapping.provider) === "elevenlabs" ? mapping : void 0;
35012
+ }
35013
+ function resolveLocalElevenLabsVoiceId(characterName, mapping) {
35014
+ if (typeof characterName !== "string" || !mapping) return void 0;
35015
+ const characters = mapping.characters;
35016
+ if (!isRecord(characters)) return void 0;
35017
+ const character = characters[characterName];
35018
+ if (!isRecord(character) || character.provider !== "elevenlabs") return void 0;
35019
+ return stringField2(character.voice_id);
35020
+ }
35021
+ function resolveLocalDoubaoMappingReference(options) {
35022
+ if (typeof options.characterName !== "string" || !options.mapping) return void 0;
35023
+ const characters = options.mapping.characters;
35024
+ if (!isRecord(characters)) return void 0;
35025
+ const character = characters[options.characterName];
35026
+ if (!isRecord(character) || character.provider !== "doubao") return void 0;
35027
+ const referencePath = stringField2(character.reference_audio_path);
35028
+ if (!referencePath) return void 0;
35029
+ try {
35030
+ const reference = normalizeDialogueReference(
35031
+ options.targetDir,
35032
+ referencePath,
35033
+ options.registry,
35034
+ options.index
35035
+ );
35036
+ return reference.toLowerCase().startsWith("data:") ? reference : void 0;
35037
+ } catch (error2) {
35038
+ const reason = error2 instanceof Error ? error2.message : String(error2);
35039
+ throw new Error(
35040
+ `Local Doubao voice mapping for character "${options.characterName}" references unavailable audio "${referencePath}". Re-run confirm_character_voice to restore it. ${reason}`
35041
+ );
35042
+ }
35043
+ }
35044
+ function normalizeOptionalDialogueReference(value) {
35045
+ if (value === void 0 || value === null) return void 0;
35046
+ if (typeof value === "string") {
35047
+ const normalized = value.trim();
35048
+ if (normalized === "" || /^data:audio\/[^,]*,\s*$/i.test(normalized)) return void 0;
35049
+ }
35050
+ return value;
35051
+ }
35052
+ function normalizeDialogueReference(targetDir, value, registry2, index) {
35053
+ if (typeof value !== "string" || !value.trim()) {
35054
+ throw new Error(`inputs[${index}].reference_audio must be a non-empty string.`);
35055
+ }
35056
+ const trimmed = value.trim();
35057
+ if (trimmed.toLowerCase().startsWith("data:")) {
35058
+ validateAudioDataUrl(trimmed);
35059
+ return trimmed;
35060
+ }
35061
+ if (/^https?:\/\//i.test(trimmed)) {
35062
+ return trimmed;
35063
+ }
35064
+ const projectReference = normalizeDialogueProjectReference(targetDir, trimmed, registry2, index);
35065
+ return localDialogueAudioReferenceToDataUrl({
35066
+ targetDir,
35067
+ value: projectReference,
35068
+ localPath: projectReference
35069
+ });
35070
+ }
35071
+ function localDialogueAudioReferenceToDataUrl(options) {
35072
+ const absolutePath = resolveLocalAssetAbsolutePath(options.targetDir, options);
35073
+ if (!absolutePath) {
35074
+ throw new Error(`local reference audio file was not found: ${options.value}`);
35075
+ }
35076
+ const projectRoot = fs15.realpathSync(path16.resolve(options.targetDir));
35077
+ const realFile = fs15.realpathSync(absolutePath);
35078
+ const relative = path16.relative(projectRoot, realFile);
35079
+ if (relative === ".." || relative.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative)) {
35080
+ throw new Error("local dialogue reference resolves outside the project target directory");
35081
+ }
35082
+ const stat = fs15.statSync(realFile);
35083
+ if (!stat.isFile()) {
35084
+ throw new Error(`local reference audio path is not a file: ${options.value}`);
35085
+ }
35086
+ if (stat.size > AUDIO_DIALOGUE_REFERENCE_MAX_BYTES) {
35087
+ throw new Error("local reference audio file must be no larger than 20 MiB.");
35088
+ }
35089
+ const mime = dataUrlMimeForPath(realFile, "audio");
35090
+ if (!mime) {
35091
+ throw new Error("local reference audio format is unsupported.");
35092
+ }
35093
+ return `data:${mime};base64,${fs15.readFileSync(realFile).toString("base64")}`;
35094
+ }
35095
+ function normalizeDialogueProjectReference(targetDir, value, registry2, index) {
35096
+ if (typeof value !== "string" || !value.trim()) {
35097
+ throw new Error(`inputs[${index}].reference_audio must be a non-empty project audio path.`);
35098
+ }
35099
+ let normalized = value.trim().replace(/^workspace\//, "");
35100
+ if (path16.isAbsolute(normalized)) {
35101
+ const relative = path16.relative(path16.resolve(targetDir), path16.resolve(normalized));
35102
+ if (relative === ".." || relative.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative)) {
35103
+ throw new Error(`inputs[${index}].reference_audio must stay inside project assets/audio.`);
35104
+ }
35105
+ normalized = relative.split(path16.sep).join("/");
35106
+ }
35107
+ const localPath = resolveLocalAssetReference(targetDir, normalized, registry2, AUDIO_ASSET_DIRS);
35108
+ if (localPath) {
35109
+ normalized = localPath;
35110
+ }
35111
+ const segments = normalized.split("/");
35112
+ const extension = path16.extname(normalized).toLowerCase();
35113
+ if (segments.some((segment) => segment === "" || segment === "." || segment === "..") || !isKnownAssetPath(normalized, AUDIO_ASSET_DIRS) || !AUDIO_MIME_BY_EXTENSION[extension]) {
35114
+ throw new Error(`inputs[${index}].reference_audio must be an audio path under assets/audio.`);
35115
+ }
35116
+ return normalized;
35117
+ }
35118
+ function validateAudioDataUrl(value) {
35119
+ const match = /^data:([a-z0-9.+-]+\/[a-z0-9.+-]+)((?:;[a-z0-9.+-]+=[^;,]*)*);base64,([\s\S]+)$/i.exec(value);
35120
+ if (!match || !Object.values(AUDIO_MIME_BY_EXTENSION).includes(match[1].toLowerCase())) {
35121
+ throw new Error("reference_audio must be a valid audio data URL, not bare base64.");
35122
+ }
35123
+ const cleaned = match[3].replace(/\s/g, "");
35124
+ if (cleaned.length === 0 || cleaned.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(cleaned)) {
35125
+ throw new Error("reference_audio must be a valid audio data URL, not bare base64.");
35126
+ }
35127
+ const padding = cleaned.endsWith("==") ? 2 : cleaned.endsWith("=") ? 1 : 0;
35128
+ const estimatedBytes = cleaned.length / 4 * 3 - padding;
35129
+ if (estimatedBytes > AUDIO_DIALOGUE_REFERENCE_MAX_BYTES) {
35130
+ throw new Error("reference_audio data URL must be no larger than 20 MiB.");
35131
+ }
35132
+ const bytes = Buffer.from(cleaned, "base64");
35133
+ if (bytes.length === 0 || bytes.length > AUDIO_DIALOGUE_REFERENCE_MAX_BYTES) {
35134
+ throw new Error("reference_audio data URL must be no larger than 20 MiB.");
35135
+ }
35136
+ }
34385
35137
  function rewriteUrlObjectArray(targetDir, value, registry2, options) {
34386
35138
  if (!Array.isArray(value)) {
34387
35139
  return value;
@@ -34546,19 +35298,35 @@ function resolveProjectRelativePath(targetDir, value) {
34546
35298
  }
34547
35299
  return void 0;
34548
35300
  }
35301
+ function assertProjectDirectory(targetDir, directory) {
35302
+ const projectRoot = fs15.realpathSync(path16.resolve(targetDir));
35303
+ const realDirectory = fs15.realpathSync(directory);
35304
+ const relative = path16.relative(projectRoot, realDirectory);
35305
+ if (relative === ".." || relative.startsWith(`..${path16.sep}`) || path16.isAbsolute(relative)) {
35306
+ throw new Error("resolved directory escapes the project target directory");
35307
+ }
35308
+ }
35309
+ function isPathWithinDirectory(rootDir, candidatePath) {
35310
+ const relativePath = path16.relative(path16.resolve(rootDir), path16.resolve(candidatePath));
35311
+ return relativePath === "" || relativePath !== ".." && !relativePath.startsWith(`..${path16.sep}`) && !path16.isAbsolute(relativePath);
35312
+ }
34549
35313
  function dataUrlMimeForPath(filePath, mediaKind) {
34550
35314
  return DATA_URL_MIME_BY_EXTENSION[mediaKind][path16.extname(filePath).toLowerCase()];
34551
35315
  }
34552
35316
  function upsertGeneratedAssetRecord(targetDir, localPath, record2) {
35317
+ const registryPath = getGeneratedAssetRegistryPath(targetDir);
35318
+ const registryDirectory = path16.dirname(registryPath);
35319
+ fs15.mkdirSync(registryDirectory, { recursive: true });
35320
+ assertProjectDirectory(targetDir, registryDirectory);
35321
+ assertFileIsNotSymlink(registryPath);
34553
35322
  const registry2 = readGeneratedAssetRegistry(targetDir);
34554
35323
  registry2[localPath] = record2;
34555
- const registryPath = getGeneratedAssetRegistryPath(targetDir);
34556
- fs15.mkdirSync(path16.dirname(registryPath), { recursive: true });
34557
35324
  fs15.writeFileSync(registryPath, `${JSON.stringify(registry2, null, 2)}
34558
35325
  `, "utf8");
34559
35326
  }
34560
35327
  function readGeneratedAssetRegistry(targetDir) {
34561
35328
  const registryPath = getGeneratedAssetRegistryPath(targetDir);
35329
+ assertFileIsNotSymlink(registryPath);
34562
35330
  if (!fs15.existsSync(registryPath)) {
34563
35331
  return {};
34564
35332
  }
@@ -34572,6 +35340,18 @@ function readGeneratedAssetRegistry(targetDir) {
34572
35340
  function getGeneratedAssetRegistryPath(targetDir) {
34573
35341
  return path16.join(targetDir, ".maker", "assets", "generated-assets.json");
34574
35342
  }
35343
+ function isSymlink(filePath) {
35344
+ try {
35345
+ return fs15.lstatSync(filePath).isSymbolicLink();
35346
+ } catch {
35347
+ return false;
35348
+ }
35349
+ }
35350
+ function assertFileIsNotSymlink(filePath) {
35351
+ if (isSymlink(filePath)) {
35352
+ throw new Error(`refusing to access symlinked file: ${filePath}`);
35353
+ }
35354
+ }
34575
35355
  function normalizeAssetRegistryKey(targetDir, value) {
34576
35356
  if (/^https?:\/\//i.test(value) || value.startsWith("data:")) {
34577
35357
  return void 0;
@@ -34767,7 +35547,7 @@ function applyDefaults(config2) {
34767
35547
  }
34768
35548
 
34769
35549
  // src/maker/server/mcp.ts
34770
- var VERSION = true ? "0.0.24" : "dev";
35550
+ var VERSION = true ? "0.0.25-beta.2" : "dev";
34771
35551
  var DEFAULT_BUILD_TIMEOUT_MS = 10 * 60 * 1e3;
34772
35552
  var DEFAULT_PROXY_RETRY_ATTEMPTS = 5;
34773
35553
  var DEFAULT_PROXY_RETRY_DELAY_MS = 30 * 1e3;
@@ -34782,8 +35562,12 @@ var MAKER_REMOTE_PROXY_EXPOSED_TOOL_NAMES = [
34782
35562
  "create_video_task",
34783
35563
  "query_video_task",
34784
35564
  "text_to_music",
34785
- "create_3d_model_task",
34786
- "query_3d_model_task",
35565
+ "text_to_sound_effect",
35566
+ "batch_sound_effects",
35567
+ "text_to_dialogue",
35568
+ "audition_voices_for_character",
35569
+ "confirm_character_voice",
35570
+ CREATE_3D_ASSET_PROXY_TOOL_NAME,
34787
35571
  "generate_test_qrcode",
34788
35572
  "get_ad_config",
34789
35573
  "get_debug_feedbacks"
@@ -34969,18 +35753,21 @@ function decorateRemoteProxyToolDefinition(tool) {
34969
35753
  const guidance = remoteProxyToolGuidance(tool.name);
34970
35754
  return {
34971
35755
  ...tool,
34972
- inputSchema: decorateRemoteProxyToolInputSchema(tool.inputSchema),
35756
+ inputSchema: decorateRemoteProxyToolInputSchema(tool.inputSchema, tool.name),
34973
35757
  description: [tool.description, guidance].filter(Boolean).join("\n\n")
34974
35758
  };
34975
35759
  }
34976
- function decorateRemoteProxyToolInputSchema(inputSchema) {
35760
+ function decorateRemoteProxyToolInputSchema(inputSchema, toolName) {
34977
35761
  const schema = isPlainRecord(inputSchema) ? inputSchema : {};
34978
35762
  const properties = isPlainRecord(schema.properties) ? schema.properties : {};
35763
+ const decoratedProperties = toolName === "text_to_dialogue" ? decorateTextToDialogueInputProperties(properties) : toolName === "audition_voices_for_character" ? decorateVoiceAuditionInputProperties(properties) : properties;
35764
+ const required2 = Array.isArray(schema.required) ? schema.required : [];
34979
35765
  return {
34980
35766
  ...schema,
34981
35767
  type: schema.type || "object",
35768
+ ...toolName === "audition_voices_for_character" ? { required: [.../* @__PURE__ */ new Set([...required2, "voice_profile"])] } : {},
34982
35769
  properties: {
34983
- ...properties,
35770
+ ...decoratedProperties,
34984
35771
  target_dir: {
34985
35772
  type: "string",
34986
35773
  description: "Optional local Maker project directory. This is a local Maker MCP private parameter used to resolve the current project for asset materialization and reference rewriting; it is not forwarded to the remote Maker tool."
@@ -34988,6 +35775,76 @@ function decorateRemoteProxyToolInputSchema(inputSchema) {
34988
35775
  }
34989
35776
  };
34990
35777
  }
35778
+ function decorateVoiceAuditionInputProperties(properties) {
35779
+ const remoteVoiceProfile = properties.voice_profile;
35780
+ const voiceProfile = isPlainRecord(remoteVoiceProfile) ? remoteVoiceProfile : {};
35781
+ const profileProperties = isPlainRecord(voiceProfile.properties) ? voiceProfile.properties : {};
35782
+ const profileRequired = Array.isArray(voiceProfile.required) ? voiceProfile.required : [];
35783
+ const remoteGender = profileProperties.gender;
35784
+ return {
35785
+ ...properties,
35786
+ voice_profile: {
35787
+ ...voiceProfile,
35788
+ type: voiceProfile.type || "object",
35789
+ description: [
35790
+ voiceProfile.description,
35791
+ "Required for character voice audition. Extract gender from character_description or the character settings instead of relying on a default."
35792
+ ].filter(Boolean).join(" "),
35793
+ properties: {
35794
+ ...profileProperties,
35795
+ gender: {
35796
+ ...isPlainRecord(remoteGender) ? remoteGender : {},
35797
+ type: "string",
35798
+ enum: ["male", "female"],
35799
+ description: "Required structured character gender. Extract male or female from character_description or the character settings."
35800
+ }
35801
+ },
35802
+ required: [.../* @__PURE__ */ new Set([...profileRequired, "gender"])]
35803
+ }
35804
+ };
35805
+ }
35806
+ function decorateTextToDialogueInputProperties(properties) {
35807
+ const inputs = properties.inputs;
35808
+ if (!isPlainRecord(inputs) || !isPlainRecord(inputs.items)) {
35809
+ return properties;
35810
+ }
35811
+ const itemProperties = inputs.items.properties;
35812
+ if (!isPlainRecord(itemProperties)) {
35813
+ return properties;
35814
+ }
35815
+ const referenceAudio = itemProperties.reference_audio;
35816
+ const referenceAudioPath = itemProperties.reference_audio_path;
35817
+ return {
35818
+ ...properties,
35819
+ inputs: {
35820
+ ...inputs,
35821
+ items: {
35822
+ ...inputs.items,
35823
+ properties: {
35824
+ ...itemProperties,
35825
+ ...isPlainRecord(referenceAudio) ? {
35826
+ reference_audio: {
35827
+ ...referenceAudio,
35828
+ description: [
35829
+ referenceAudio.description,
35830
+ "Use a local project audio path under assets/audio/, an HTTP(S) URL, or an audio data URL here. Local project audio must exist in the current project and is converted to a data URL automatically. Do not pass bare base64."
35831
+ ].filter(Boolean).join(" ")
35832
+ }
35833
+ } : {},
35834
+ ...isPlainRecord(referenceAudioPath) ? {
35835
+ reference_audio_path: {
35836
+ ...referenceAudioPath,
35837
+ description: [
35838
+ referenceAudioPath.description,
35839
+ "This legacy local project audio path must exist under assets/audio/ or workspace/assets/audio/. The local proxy converts it to the canonical reference_audio data URL; it is not a project-external filesystem path."
35840
+ ].filter(Boolean).join(" ")
35841
+ }
35842
+ } : {}
35843
+ }
35844
+ }
35845
+ }
35846
+ };
35847
+ }
34991
35848
  function isPlainRecord(value) {
34992
35849
  return typeof value === "object" && value !== null && !Array.isArray(value);
34993
35850
  }
@@ -35025,6 +35882,35 @@ function remoteProxyToolGuidance(toolName) {
35025
35882
  "**Maker asset workflow hint:** Prefer this Maker MCP proxy tool for Maker music generation so generated audio can be materialized into the project and recorded for later Maker references.",
35026
35883
  failurePolicy
35027
35884
  ].join(" ");
35885
+ case "text_to_sound_effect":
35886
+ case "batch_sound_effects":
35887
+ return [
35888
+ "**Maker asset workflow hint:** Prefer this Maker MCP proxy tool for game sound effects. Successful audio is materialized in its original format under assets/audio/sfx and recorded for later Maker references.",
35889
+ failurePolicy
35890
+ ].join(" ");
35891
+ case "text_to_dialogue":
35892
+ return [
35893
+ "**Maker voice workflow hint:** For normal dialogue, pass only character_name and text after voice confirmation; the local proxy automatically reuses a confirmed local Doubao reference. reference_audio is an optional per-call override and accepts a local project audio path under assets/audio/, an HTTP(S) URL, or an audio data URL. Project audio must exist locally and is converted to a data URL automatically. reference_audio and reference_audio_path are mutually exclusive; reference_audio is canonical and reference_audio_path is the legacy local-path field. Successful dialogue audio is materialized under assets/audio/voice.",
35894
+ failurePolicy
35895
+ ].join(" ");
35896
+ case "audition_voices_for_character":
35897
+ return [
35898
+ "**Maker voice workflow hint:** Use this Maker MCP proxy tool to create temporary preview voices for one character. voice_profile.gender is required: extract male or female from character_description or the character settings and pass it explicitly. Show every returned preview URL to the user and wait for their choice before calling confirm_character_voice. Preview candidates are not saved as game assets.",
35899
+ failurePolicy
35900
+ ].join(" ");
35901
+ case "confirm_character_voice":
35902
+ return [
35903
+ "**Maker voice workflow hint:** Call this Maker MCP proxy tool only after audition_voices_for_character and after the user selects a candidate or accepts the recommendation. Confirmation persists the provider-specific voice mapping for later text_to_dialogue calls.",
35904
+ failurePolicy
35905
+ ].join(" ");
35906
+ case CREATE_3D_ASSET_PROXY_TOOL_NAME:
35907
+ return [
35908
+ "**Maker asset workflow hint:** Use this tool for the complete Maker 3D asset lifecycle: start, query, continue after explicit user review, inspect options, and post-process completed assets.",
35909
+ "Local image paths in payload.images are forwarded as data URLs when they resolve inside the Maker project. Unknown server response fields are preserved. In local runtime query results, model_files copy/extract instructions are materialized into assets/model and local_delivery reports the usable local model path.",
35910
+ "Review preview URLs are materialized into assets/image and returned in preview_assets when possible.",
35911
+ 'Do not automatically approve review steps; show the returned previews to the user and wait for explicit confirmation before action="continue".',
35912
+ failurePolicy
35913
+ ].join(" ");
35028
35914
  case "get_ad_config":
35029
35915
  return [
35030
35916
  "**Maker hint:** Trigger this tool for any ad-related request (广告, 激励视频, 播放广告, ad ID, ad placement, ShowRewardVideoAd, ad status, or ad config). Call it first to get the current Maker project ad activation status and ad config; do not infer ad readiness from local SDK docs, .maker-mcp/config.json, or runtime callbacks. If .project/project.json is missing, build the project once with maker_build_current_directory to initialize it, then call this tool again. If this tool says app_id or developer_id is missing, call generate_test_qrcode once to generate test QR code metadata, then call this tool again.",
@@ -35085,7 +35971,7 @@ async function callRemoteProxyTool(options) {
35085
35971
  targetDir: options.targetDir,
35086
35972
  exposedTools: MAKER_REMOTE_PROXY_EXPOSED_TOOL_NAMES
35087
35973
  });
35088
- const finalArgs = prepareRemoteProxyToolArgs({
35974
+ const finalArgs = await prepareRemoteProxyToolArgsAsync({
35089
35975
  toolName: options.name,
35090
35976
  targetDir: proxy.projectRoot,
35091
35977
  args: options.args
@@ -37017,19 +37903,37 @@ function formatToolException(toolName, error2) {
37017
37903
  ].join("\n");
37018
37904
  }
37019
37905
  if (error2 instanceof RemoteProxyToolResultError) {
37906
+ const displayResult = flattenNestedMcpErrorPrefixes(error2.result);
37907
+ const remoteMessage = extractRemoteProxyErrorMessage(displayResult);
37020
37908
  return [
37021
37909
  "✗ Maker MCP proxy tool failed",
37022
37910
  "",
37023
37911
  `- tool: ${toolName}`,
37024
37912
  "- reason: remote_proxy_tool_result_error",
37025
37913
  `- error_name: ${error2.name}`,
37026
- `- message: ${firstLine(error2.message)}`,
37914
+ `- message: ${remoteMessage ?? firstLine(error2.message)}`,
37027
37915
  "",
37028
- formatRemoteProxyToolResult(error2.result),
37916
+ formatRemoteProxyToolResult(displayResult),
37029
37917
  "",
37030
37918
  "next_action: 远端 proxy tool 已返回失败结果;请把 remote_result 原样反馈给开发者,方便排查 server 返回内容。"
37031
37919
  ].join("\n");
37032
37920
  }
37921
+ if (isExposedRemoteProxyTool(toolName)) {
37922
+ return [
37923
+ "✗ Maker MCP proxy tool failed",
37924
+ "",
37925
+ `- tool: ${toolName}`,
37926
+ "- reason: remote_proxy_tool_call_error",
37927
+ `- error_name: ${error2 instanceof Error ? error2.name : typeof error2}`,
37928
+ `- message: ${stripNestedMcpErrorPrefixes(message)}`,
37929
+ ...formatUnknownExceptionDetailLines(error2),
37930
+ "",
37931
+ "debug:",
37932
+ stack ? indent2(stack) : indent2(message),
37933
+ "",
37934
+ "next_action: 请根据上面的简化 message 判断失败原因;参数或能力不支持时不要重复调用,并保留 error_details/debug 反馈给开发者。"
37935
+ ].join("\n");
37936
+ }
37033
37937
  return [
37034
37938
  "✗ Maker MCP tool failed",
37035
37939
  "",
@@ -37044,6 +37948,68 @@ function formatToolException(toolName, error2) {
37044
37948
  "next_action: 请把上面的完整错误反馈给开发者;如果本地已有 commit 但 push 未完成,不要重复 commit,直接重试 maker_build_current_directory。"
37045
37949
  ].join("\n");
37046
37950
  }
37951
+ function stripNestedMcpErrorPrefixes(message) {
37952
+ const prefix = /^MCP error -?\d+:\s*/i;
37953
+ let concise = message.trim();
37954
+ while (prefix.test(concise)) {
37955
+ concise = concise.replace(prefix, "");
37956
+ }
37957
+ return concise || message;
37958
+ }
37959
+ function flattenNestedMcpErrorPrefixes(value) {
37960
+ if (typeof value === "string") {
37961
+ return stripNestedMcpErrorPrefixes(value);
37962
+ }
37963
+ if (Array.isArray(value)) {
37964
+ return value.map((item) => flattenNestedMcpErrorPrefixes(item));
37965
+ }
37966
+ if (isPlainRecord(value)) {
37967
+ return Object.fromEntries(
37968
+ Object.entries(value).map(([key, nestedValue]) => [
37969
+ key,
37970
+ flattenNestedMcpErrorPrefixes(nestedValue)
37971
+ ])
37972
+ );
37973
+ }
37974
+ return value;
37975
+ }
37976
+ function extractRemoteProxyErrorMessage(result) {
37977
+ if (!isPlainRecord(result) || !Array.isArray(result.content)) {
37978
+ return void 0;
37979
+ }
37980
+ for (const item of result.content) {
37981
+ if (!isPlainRecord(item) || typeof item.text !== "string") {
37982
+ continue;
37983
+ }
37984
+ const text = item.text.trim();
37985
+ if (!text) {
37986
+ continue;
37987
+ }
37988
+ try {
37989
+ const parsed = JSON.parse(text);
37990
+ const structuredMessage = extractStructuredErrorMessage(parsed);
37991
+ if (structuredMessage) {
37992
+ return firstLine(structuredMessage);
37993
+ }
37994
+ return void 0;
37995
+ } catch {
37996
+ return firstLine(text);
37997
+ }
37998
+ }
37999
+ return void 0;
38000
+ }
38001
+ function extractStructuredErrorMessage(value) {
38002
+ if (!isPlainRecord(value)) {
38003
+ return void 0;
38004
+ }
38005
+ for (const key of ["message", "error", "detail"]) {
38006
+ const candidate = value[key];
38007
+ if (typeof candidate === "string" && candidate.trim()) {
38008
+ return stripNestedMcpErrorPrefixes(candidate);
38009
+ }
38010
+ }
38011
+ return void 0;
38012
+ }
37047
38013
  function firstLine(value) {
37048
38014
  return value.split("\n")[0] || value;
37049
38015
  }
@@ -37245,7 +38211,7 @@ function formatError2(error2) {
37245
38211
  }
37246
38212
 
37247
38213
  // src/maker/cli/commands.ts
37248
- var VERSION2 = true ? "0.0.24" : "dev";
38214
+ var VERSION2 = true ? "0.0.25-beta.2" : "dev";
37249
38215
  var DEFAULT_MCP_NAME = "taptap-maker";
37250
38216
  var MAKER_NPM_PACKAGE = "@taptap/maker";
37251
38217
  var TWO_PART_COMMANDS = /* @__PURE__ */ new Set(["pat", "mcp", "dev-kit", "logs", "python", "lua-lsp", "agents"]);