mulmocast 1.2.53 → 1.2.55

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.
@@ -256,6 +256,7 @@ export const generateBeatAudio = async (index, context, args) => {
256
256
  await graph.run();
257
257
  }
258
258
  catch (error) {
259
+ // CAUSE
259
260
  GraphAILogger.error(error);
260
261
  throw error;
261
262
  }
@@ -8,7 +8,7 @@ import { splitText } from "../utils/string.js";
8
8
  import { settings2GraphAIConfig, beatId, multiLingualObjectToArray } from "../utils/utils.js";
9
9
  import { getMultiLingual } from "../utils/context.js";
10
10
  import { currentMulmoScriptVersion } from "../utils/const.js";
11
- import { translateApiKeyMissingError } from "../utils/error_cause.js";
11
+ import { translateApiKeyMissingError, hasCause, agentGenerationError, translateAction, multiLingualFileTarget } from "../utils/error_cause.js";
12
12
  import { getOutputMultilingualFilePath, mkdir, writingMessage, hashSHA256 } from "../utils/file.js";
13
13
  import { translateSystemPrompt, translatePrompts } from "../utils/prompt.js";
14
14
  import { MulmoStudioContextMethods } from "../methods/mulmo_studio_context.js";
@@ -266,7 +266,12 @@ export const translateBeat = async (index, context, targetLangs, args) => {
266
266
  }
267
267
  catch (error) {
268
268
  GraphAILogger.log(error);
269
- throw error;
269
+ if (hasCause(error) && error.cause) {
270
+ throw error;
271
+ }
272
+ throw new Error("Failed to translate", {
273
+ cause: agentGenerationError("translateBeat", translateAction, multiLingualFileTarget),
274
+ });
270
275
  }
271
276
  };
272
277
  export const translate = async (context, args) => {
@@ -298,7 +303,12 @@ export const translate = async (context, args) => {
298
303
  }
299
304
  catch (error) {
300
305
  MulmoStudioContextMethods.setSessionState(context, "multiLingual", false, false);
301
- throw error;
306
+ if (hasCause(error) && error.cause) {
307
+ throw error;
308
+ }
309
+ throw new Error("Failed to translate", {
310
+ cause: agentGenerationError("translateBeat", translateAction, multiLingualFileTarget),
311
+ });
302
312
  }
303
313
  return context;
304
314
  };
@@ -0,0 +1 @@
1
+ export declare function resolveAssetFile(relFromPkgRoot: string, npmRoot?: string): string;
@@ -0,0 +1,22 @@
1
+ import { createRequire } from "node:module";
2
+ import { fileURLToPath } from "node:url";
3
+ import path from "node:path";
4
+ import fs from "node:fs";
5
+ const require = createRequire(import.meta.url);
6
+ export function resolveAssetFile(relFromPkgRoot, npmRoot) {
7
+ const rel = relFromPkgRoot.replace(/^\.\//, "");
8
+ try {
9
+ return require.resolve(`mulmocast/${rel}`);
10
+ }
11
+ catch {
12
+ if (npmRoot) {
13
+ const maybe = path.resolve(npmRoot, relFromPkgRoot);
14
+ if (fs.existsSync(maybe)) {
15
+ return maybe;
16
+ }
17
+ }
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+ return path.join(__dirname, relFromPkgRoot);
21
+ }
22
+ }
@@ -62,6 +62,7 @@ export declare const translateAction = "translate";
62
62
  export declare const audioFileTarget = "audioFile";
63
63
  export declare const imageFileTarget = "imageFile";
64
64
  export declare const movieFileTarget = "movieFile";
65
+ export declare const multiLingualFileTarget = "multiLingualFile";
65
66
  export declare const videoSourceTarget = "videoSource";
66
67
  export declare const audioSourceTarget = "audioSource";
67
68
  export declare const codeTextTarget = "codeText";
@@ -65,6 +65,7 @@ export const translateAction = "translate";
65
65
  export const audioFileTarget = "audioFile";
66
66
  export const imageFileTarget = "imageFile";
67
67
  export const movieFileTarget = "movieFile";
68
+ export const multiLingualFileTarget = "multiLingualFile";
68
69
  export const videoSourceTarget = "videoSource";
69
70
  export const audioSourceTarget = "audioSource";
70
71
  export const codeTextTarget = "codeText";
package/lib/utils/file.js CHANGED
@@ -7,6 +7,7 @@ import { GraphAILogger } from "graphai";
7
7
  import { MulmoStudioContextMethods } from "../methods/index.js";
8
8
  import { mulmoPromptTemplateSchema } from "../types/schema.js";
9
9
  import { getMulmoScriptTemplateSystemPrompt } from "./prompt.js";
10
+ import { resolveAssetFile } from "./asset_import.js";
10
11
  const promptTemplateDirName = "./assets/templates";
11
12
  const scriptTemplateDirName = "./scripts/templates";
12
13
  const __filename = fileURLToPath(import.meta.url);
@@ -120,7 +121,7 @@ export const getOutputPdfFilePath = (outDirPath, fileName, pdfMode, lang) => {
120
121
  return path.resolve(outDirPath, `${fileName}_${pdfMode}.pdf`);
121
122
  };
122
123
  export const getPromptTemplateFilePath = (promptTemplateName) => {
123
- return path.resolve(npmRoot, promptTemplateDirName, promptTemplateName + ".json");
124
+ return resolveAssetFile(path.join(promptTemplateDirName, promptTemplateName + ".json"), npmRoot);
124
125
  };
125
126
  export const mkdir = (dirPath) => {
126
127
  if (!fs.existsSync(dirPath)) {
@@ -134,14 +135,14 @@ export const resolveAssetPath = (context, relativePath) => {
134
135
  };
135
136
  // export const silentPath = path.resolve(npmRoot, "./assets/audio/silent300.mp3");
136
137
  // export const silentLastPath = path.resolve(npmRoot, "./assets/audio/silent800.mp3");
137
- export const silent60secPath = () => path.resolve(npmRoot, "./assets/audio/silent60sec.mp3");
138
+ export const silent60secPath = () => resolveAssetFile("./assets/audio/silent60sec.mp3", npmRoot);
138
139
  export const defaultBGMPath = () => "https://github.com/receptron/mulmocast-media/raw/refs/heads/main/bgms/story002.mp3";
139
- export const mulmoCreditPath = () => path.resolve(npmRoot, "./assets/images/mulmocast_credit.png");
140
- export const blankImagePath = () => path.resolve(npmRoot, "./assets/images/blank.png");
141
- export const blankVerticalImagePath = () => path.resolve(npmRoot, "./assets/images/blank_v.png");
142
- export const blankSquareImagePath = () => path.resolve(npmRoot, "./assets/images/blank_sq.png");
140
+ export const mulmoCreditPath = () => resolveAssetFile("./assets/images/mulmocast_credit.png", npmRoot);
141
+ export const blankImagePath = () => resolveAssetFile("./assets/images/blank.png", npmRoot);
142
+ export const blankVerticalImagePath = () => resolveAssetFile("./assets/images/blank_v.png", npmRoot);
143
+ export const blankSquareImagePath = () => resolveAssetFile("./assets/images/blank_sq.png", npmRoot);
143
144
  export const getHTMLFile = (filename) => {
144
- const htmlPath = path.resolve(npmRoot, `./assets/html/${filename}.html`);
145
+ const htmlPath = resolveAssetFile(`./assets/html/${filename}.html`, npmRoot);
145
146
  return fs.readFileSync(htmlPath, "utf-8");
146
147
  };
147
148
  // for cli
@@ -165,7 +166,7 @@ export const getFullPath = (baseDirPath, file) => {
165
166
  };
166
167
  // script and prompt template
167
168
  export const readScriptTemplateFile = (scriptTemplateFileName) => {
168
- const scriptTemplatePath = path.resolve(npmRoot, scriptTemplateDirName, scriptTemplateFileName);
169
+ const scriptTemplatePath = resolveAssetFile(path.join(scriptTemplateDirName, scriptTemplateFileName), npmRoot);
169
170
  const scriptTemplateData = fs.readFileSync(scriptTemplatePath, "utf-8");
170
171
  // NOTE: We don't want to schema parse the script here to eliminate default values.
171
172
  return JSON.parse(scriptTemplateData);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mulmocast",
3
- "version": "1.2.53",
3
+ "version": "1.2.55",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "lib/index.node.js",
@@ -15,7 +15,9 @@
15
15
  },
16
16
  "./data": {
17
17
  "default": "./lib/data/index.js"
18
- }
18
+ },
19
+ "./assets/*": "./assets/*",
20
+ "./scripts/*": "./scripts/*"
19
21
  },
20
22
  "bin": {
21
23
  "mulmo": "lib/cli/bin.js",