mulmocast 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +129 -15
  2. package/assets/font/NotoSansJP-Regular.ttf +0 -0
  3. package/assets/html/chart.html +38 -0
  4. package/assets/html/mermaid.html +51 -0
  5. package/assets/templates/business.json +57 -14
  6. package/assets/templates/children_book.json +1 -3
  7. package/assets/templates/coding.json +140 -0
  8. package/lib/actions/audio.d.ts +2 -2
  9. package/lib/actions/audio.js +88 -101
  10. package/lib/actions/images.d.ts +1 -1
  11. package/lib/actions/images.js +50 -88
  12. package/lib/actions/index.d.ts +5 -0
  13. package/lib/actions/index.js +5 -0
  14. package/lib/actions/movie.d.ts +9 -1
  15. package/lib/actions/movie.js +124 -65
  16. package/lib/actions/pdf.d.ts +2 -0
  17. package/lib/actions/pdf.js +211 -0
  18. package/lib/actions/pdf2.d.ts +2 -0
  19. package/lib/actions/pdf2.js +203 -0
  20. package/lib/actions/translate.d.ts +1 -1
  21. package/lib/actions/translate.js +38 -61
  22. package/lib/agents/add_bgm_agent.d.ts +1 -1
  23. package/lib/agents/add_bgm_agent.js +10 -14
  24. package/lib/agents/anthropic_agent.d.ts +23 -0
  25. package/lib/agents/anthropic_agent.js +162 -0
  26. package/lib/agents/combine_audio_files_agent.d.ts +1 -1
  27. package/lib/agents/combine_audio_files_agent.js +33 -32
  28. package/lib/agents/image_google_agent.d.ts +1 -1
  29. package/lib/agents/image_google_agent.js +8 -11
  30. package/lib/agents/image_openai_agent.js +7 -14
  31. package/lib/agents/index.d.ts +8 -8
  32. package/lib/agents/index.js +13 -30
  33. package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
  34. package/lib/agents/mulmo_prompts_agent.js +7 -11
  35. package/lib/agents/nested_agent.d.ts +9 -0
  36. package/lib/agents/nested_agent.js +138 -0
  37. package/lib/agents/prompts_data.js +1 -4
  38. package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
  39. package/lib/agents/tts_nijivoice_agent.js +8 -12
  40. package/lib/agents/tts_openai_agent.js +9 -16
  41. package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
  42. package/lib/agents/validate_mulmo_script_agent.js +6 -10
  43. package/lib/cli/args.d.ts +5 -2
  44. package/lib/cli/args.js +52 -35
  45. package/lib/cli/cli.d.ts +14 -0
  46. package/lib/cli/cli.js +74 -57
  47. package/lib/cli/common.js +1 -5
  48. package/lib/cli/tool-args.d.ts +4 -1
  49. package/lib/cli/tool-args.js +29 -18
  50. package/lib/cli/tool-cli.js +34 -51
  51. package/lib/methods/index.d.ts +4 -3
  52. package/lib/methods/index.js +4 -19
  53. package/lib/methods/mulmo_media_source.d.ts +4 -0
  54. package/lib/methods/mulmo_media_source.js +21 -0
  55. package/lib/methods/mulmo_script.d.ts +6 -5
  56. package/lib/methods/mulmo_script.js +29 -16
  57. package/lib/methods/mulmo_script_template.d.ts +1 -1
  58. package/lib/methods/mulmo_script_template.js +4 -10
  59. package/lib/methods/mulmo_studio_context.d.ts +1 -1
  60. package/lib/methods/mulmo_studio_context.js +3 -9
  61. package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
  62. package/lib/tools/create_mulmo_script_from_url.js +152 -0
  63. package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
  64. package/lib/tools/create_mulmo_script_interactively.js +258 -0
  65. package/lib/tools/dump_prompt.js +5 -8
  66. package/lib/tools/prompt.js +9 -11
  67. package/lib/tools/seed_from_url2.d.ts +3 -0
  68. package/lib/tools/seed_from_url2.js +154 -0
  69. package/lib/types/index.d.ts +2 -1
  70. package/lib/types/index.js +2 -17
  71. package/lib/types/schema.d.ts +3624 -2798
  72. package/lib/types/schema.js +172 -123
  73. package/lib/types/type.d.ts +34 -3
  74. package/lib/types/type.js +1 -2
  75. package/lib/utils/const.d.ts +4 -1
  76. package/lib/utils/const.js +6 -6
  77. package/lib/utils/file.d.ts +22 -4
  78. package/lib/utils/file.js +100 -79
  79. package/lib/utils/filters.d.ts +1 -0
  80. package/lib/utils/filters.js +47 -26
  81. package/lib/utils/image_plugins/chart.d.ts +3 -0
  82. package/lib/utils/image_plugins/chart.js +18 -0
  83. package/lib/utils/image_plugins/image.d.ts +2 -0
  84. package/lib/utils/image_plugins/image.js +3 -0
  85. package/lib/utils/image_plugins/index.d.ts +7 -0
  86. package/lib/utils/image_plugins/index.js +7 -0
  87. package/lib/utils/image_plugins/markdown.d.ts +3 -0
  88. package/lib/utils/image_plugins/markdown.js +11 -0
  89. package/lib/utils/image_plugins/mermaid.d.ts +3 -0
  90. package/lib/utils/image_plugins/mermaid.js +21 -0
  91. package/lib/utils/image_plugins/movie.d.ts +2 -0
  92. package/lib/utils/image_plugins/movie.js +3 -0
  93. package/lib/utils/image_plugins/source.d.ts +4 -0
  94. package/lib/utils/image_plugins/source.js +15 -0
  95. package/lib/utils/image_plugins/text_slide.d.ts +3 -0
  96. package/lib/utils/image_plugins/text_slide.js +12 -0
  97. package/lib/utils/image_plugins/type_guards.d.ts +6 -0
  98. package/lib/utils/image_plugins/type_guards.js +21 -0
  99. package/lib/utils/image_preprocess.d.ts +14 -0
  100. package/lib/utils/image_preprocess.js +52 -0
  101. package/lib/utils/inquirer.d.ts +2 -0
  102. package/lib/utils/inquirer.js +33 -0
  103. package/lib/utils/markdown.d.ts +3 -1
  104. package/lib/utils/markdown.js +20 -19
  105. package/lib/utils/pdf.d.ts +8 -0
  106. package/lib/utils/pdf.js +75 -0
  107. package/lib/utils/plugins.d.ts +5 -0
  108. package/lib/utils/plugins.js +11 -0
  109. package/lib/utils/preprocess.d.ts +70 -123
  110. package/lib/utils/preprocess.js +37 -43
  111. package/lib/utils/string.js +4 -10
  112. package/lib/utils/text_hash.js +2 -39
  113. package/lib/utils/utils.d.ts +12 -0
  114. package/lib/utils/utils.js +34 -0
  115. package/package.json +23 -8
package/lib/cli/cli.js CHANGED
@@ -1,78 +1,95 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ import "dotenv/config";
3
+ import fs from "fs";
4
+ import path from "path";
5
+ import { fileURLToPath } from "url";
6
+ import { GraphAILogger } from "graphai";
7
+ import { getArgs } from "./args.js";
8
+ import { createOrUpdateStudioData } from "../utils/preprocess.js";
9
+ import { outDirName, imageDirName, audioDirName } from "../utils/const.js";
10
+ import { translate, audio, images, movie, pdf } from "../../src/actions/index.js";
11
+ import { getBaseDirPath, getFullPath, readMulmoScriptFile, fetchMulmoScriptFile, getOutputStudioFilePath } from "../utils/file.js";
12
+ import { isHttp } from "../utils/utils.js";
13
+ export const getFileObject = (_args) => {
14
+ const { basedir, file, outdir, imagedir, audiodir } = _args;
15
+ const baseDirPath = getBaseDirPath(basedir);
16
+ const fileOrUrl = file ?? "";
17
+ const fileName = path.parse(fileOrUrl).name;
18
+ const isHttpPath = isHttp(fileOrUrl);
19
+ const mulmoFilePath = isHttpPath ? "" : getFullPath(baseDirPath, fileOrUrl);
20
+ const mulmoFileDirPath = path.dirname(isHttpPath ? baseDirPath : mulmoFilePath);
21
+ const outDirPath = getFullPath(baseDirPath, outdir ?? outDirName);
22
+ const imageDirPath = getFullPath(outDirPath, imagedir ?? imageDirName);
23
+ const audioDirPath = getFullPath(outDirPath, audiodir ?? audioDirName);
24
+ const outputStudioFilePath = getOutputStudioFilePath(outDirPath, fileName);
25
+ return { baseDirPath, mulmoFilePath, mulmoFileDirPath, outDirPath, imageDirPath, audioDirPath, isHttpPath, fileOrUrl, outputStudioFilePath, fileName };
5
26
  };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- require("dotenv/config");
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const graphai_1 = require("graphai");
11
- const args_1 = require("./args");
12
- const preprocess_1 = require("../utils/preprocess");
13
- const const_1 = require("../utils/const");
14
- const methods_1 = require("../methods");
15
- const translate_1 = require("../actions/translate");
16
- const images_1 = require("../actions/images");
17
- const audio_1 = require("../actions/audio");
18
- const movie_1 = require("../actions/movie");
19
- const file_1 = require("../utils/file");
20
- const schema_1 = require("../types/schema");
21
- const getFileObject = () => {
22
- const { basedir, file, outdir, imagedir, scratchpaddir } = args_1.args;
23
- const baseDirPath = (0, file_1.getBaseDirPath)(basedir);
24
- const mulmoFilePath = (0, file_1.getFullPath)(baseDirPath, file ?? "");
25
- const mulmoFileDirPath = path_1.default.dirname(mulmoFilePath);
26
- const outDirPath = (0, file_1.getFullPath)(baseDirPath, outdir ?? const_1.outDirName);
27
- const imageDirPath = (0, file_1.getFullPath)(baseDirPath, imagedir ?? const_1.imageDirName);
28
- const scratchpadDirPath = (0, file_1.getFullPath)(baseDirPath, scratchpaddir ?? const_1.scratchpadDirName);
29
- return { baseDirPath, mulmoFilePath, mulmoFileDirPath, outDirPath, imageDirPath, scratchpadDirPath };
27
+ const fetchScript = async (isHttpPath, mulmoFilePath, fileOrUrl) => {
28
+ if (isHttpPath) {
29
+ const res = await fetchMulmoScriptFile(fileOrUrl);
30
+ if (!res.result || !res.script) {
31
+ GraphAILogger.info(`ERROR: HTTP error! ${res.status} ${fileOrUrl}`);
32
+ process.exit(1);
33
+ }
34
+ return res.script;
35
+ }
36
+ if (!fs.existsSync(mulmoFilePath)) {
37
+ GraphAILogger.info(`ERROR: File not exists ${mulmoFilePath}`);
38
+ process.exit(1);
39
+ }
40
+ return readMulmoScriptFile(mulmoFilePath, "ERROR: File does not exist " + mulmoFilePath).mulmoData;
30
41
  };
31
42
  const main = async () => {
32
- const files = getFileObject();
33
- const { mulmoFilePath } = files;
34
- if (args_1.args.v) {
35
- console.log(files);
43
+ const args = getArgs();
44
+ const files = getFileObject(args);
45
+ const { mulmoFilePath, isHttpPath, fileOrUrl, fileName, outputStudioFilePath } = files;
46
+ if (args.v) {
47
+ GraphAILogger.info(files);
36
48
  }
37
49
  else {
38
- graphai_1.GraphAILogger.setLevelEnabled("error", false);
39
- graphai_1.GraphAILogger.setLevelEnabled("log", false);
40
- graphai_1.GraphAILogger.setLevelEnabled("warn", false);
41
- }
42
- if (!fs_1.default.existsSync(mulmoFilePath)) {
43
- console.error("File not exists");
44
- return -1;
50
+ GraphAILogger.setLevelEnabled("error", false);
51
+ GraphAILogger.setLevelEnabled("log", false);
52
+ GraphAILogger.setLevelEnabled("warn", false);
45
53
  }
46
- // TODO some option process
47
- const { action } = args_1.args;
48
- const studio = (0, preprocess_1.createOrUpdateStudioData)(mulmoFilePath, files);
49
- // validate mulmoStudioSchema. skip if __test_invalid__ is true
50
- try {
51
- if (!studio.script?.__test_invalid__) {
52
- schema_1.mulmoStudioSchema.parse(studio);
54
+ const { action, force, pdf_mode, pdf_size } = args;
55
+ const mulmoScript = await fetchScript(isHttpPath, mulmoFilePath, fileOrUrl);
56
+ // Create or update MulmoStudio file with MulmoScript
57
+ const currentStudio = readMulmoScriptFile(outputStudioFilePath);
58
+ const studio = (() => {
59
+ try {
60
+ // validate mulmoStudioSchema. skip if __test_invalid__ is true
61
+ return createOrUpdateStudioData(mulmoScript, currentStudio?.mulmoData, fileName);
53
62
  }
54
- }
55
- catch (error) {
56
- console.error(`Error: invalid MulmoScript Schema: ${mulmoFilePath} \n ${error}`);
57
- return -1;
58
- }
63
+ catch (error) {
64
+ GraphAILogger.info(`Error: invalid MulmoScript Schema: ${isHttpPath ? fileOrUrl : mulmoFilePath} \n ${error}`);
65
+ process.exit(1);
66
+ }
67
+ })();
59
68
  const context = {
60
69
  studio,
61
70
  fileDirs: files,
71
+ force: Boolean(force),
62
72
  };
63
73
  if (action === "translate") {
64
- await (0, translate_1.translate)(context);
74
+ await translate(context);
65
75
  }
66
76
  if (action === "audio") {
67
- await (0, audio_1.audio)(context, methods_1.MulmoScriptMethods.getSpeechProvider(studio.script) === "nijivoice" ? 1 : 8);
77
+ await audio(context);
68
78
  }
69
79
  if (action === "images") {
70
- await (0, images_1.images)(context);
80
+ await images(context);
71
81
  }
72
82
  if (action === "movie") {
73
- await (0, audio_1.audio)(context, methods_1.MulmoScriptMethods.getSpeechProvider(studio.script) === "nijivoice" ? 1 : 8);
74
- await (0, images_1.images)(context);
75
- await (0, movie_1.movie)(context);
83
+ await audio(context);
84
+ await images(context);
85
+ await movie(context);
86
+ }
87
+ if (action === "pdf") {
88
+ await images(context);
89
+ await pdf(context, pdf_mode, pdf_size);
76
90
  }
77
91
  };
78
- main();
92
+ const __filename = fileURLToPath(import.meta.url);
93
+ if (process.argv[1] === __filename) {
94
+ main();
95
+ }
package/lib/cli/common.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commonOptions = void 0;
4
- const commonOptions = (yargs) => {
1
+ export const commonOptions = (yargs) => {
5
2
  return yargs
6
3
  .option("v", {
7
4
  alias: "verbose",
@@ -23,4 +20,3 @@ const commonOptions = (yargs) => {
23
20
  type: "string",
24
21
  });
25
22
  };
26
- exports.commonOptions = commonOptions;
@@ -6,7 +6,10 @@ export declare const args: {
6
6
  u: string[] | never[];
7
7
  i: boolean | undefined;
8
8
  t: string | undefined;
9
- f: string;
9
+ c: string | undefined;
10
+ s: string;
11
+ llm_agent: string | undefined;
12
+ llm_model: string | undefined;
10
13
  _: (string | number)[];
11
14
  $0: string;
12
15
  };
@@ -1,18 +1,11 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.args = void 0;
7
- const yargs_1 = __importDefault(require("yargs"));
8
- const helpers_1 = require("yargs/helpers");
9
- const common_1 = require("./common");
10
- const graphai_1 = require("graphai");
11
- const file_1 = require("../utils/file");
12
- graphai_1.GraphAILogger.setLevelEnabled("error", false);
13
- const availableTemplateNames = (0, file_1.getAvailableTemplates)().map((template) => template.filename);
14
- exports.args = (0, common_1.commonOptions)((0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)))
15
- .scriptName("mulmocast-tool")
1
+ import yargs from "yargs";
2
+ import { hideBin } from "yargs/helpers";
3
+ import { commonOptions } from "./common.js";
4
+ import { getAvailableTemplates } from "../utils/file.js";
5
+ import { llmAgents } from "../utils/utils.js";
6
+ const availableTemplateNames = getAvailableTemplates().map((template) => template.filename);
7
+ export const args = commonOptions(yargs(hideBin(process.argv)))
8
+ .scriptName("mulmo-tool")
16
9
  .option("u", {
17
10
  alias: "url",
18
11
  description: "URLs to reference (required when not in interactive mode)",
@@ -34,12 +27,29 @@ exports.args = (0, common_1.commonOptions)((0, yargs_1.default)((0, helpers_1.hi
34
27
  choices: availableTemplateNames,
35
28
  type: "string",
36
29
  })
37
- .option("f", {
38
- alias: "filename",
39
- description: "output filename",
30
+ .option("c", {
31
+ alias: "cache",
32
+ description: "cache dir",
33
+ demandOption: false,
34
+ type: "string",
35
+ })
36
+ .option("s", {
37
+ alias: "script",
38
+ description: "script filename",
40
39
  demandOption: false,
41
40
  default: "script",
42
41
  type: "string",
42
+ })
43
+ .option("llm_agent", {
44
+ description: "llm agent",
45
+ demandOption: false,
46
+ choices: llmAgents,
47
+ type: "string",
48
+ })
49
+ .option("llm_model", {
50
+ description: "llm model",
51
+ demandOption: false,
52
+ type: "string",
43
53
  })
44
54
  .command("$0 <action>", "Run mulmocast tool", (yargs) => {
45
55
  return yargs.positional("action", {
@@ -50,4 +60,5 @@ exports.args = (0, common_1.commonOptions)((0, yargs_1.default)((0, helpers_1.hi
50
60
  })
51
61
  .strict()
52
62
  .help()
63
+ .alias("help", "h")
53
64
  .parseSync();
@@ -1,78 +1,61 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- require("dotenv/config");
8
- const graphai_1 = require("graphai");
9
- const inquirer_1 = __importDefault(require("inquirer"));
10
- const tool_args_1 = require("./tool-args");
11
- const const_1 = require("../utils/const");
12
- const seed_from_url_1 = require("../tools/seed_from_url");
13
- const file_1 = require("../utils/file");
14
- const seed_1 = require("../tools/seed");
15
- const dump_prompt_1 = require("../tools/dump_prompt");
16
- const selectTemplate = async () => {
17
- const availableTemplates = (0, file_1.getAvailableTemplates)();
18
- const answers = await inquirer_1.default.prompt([
19
- {
20
- type: "list",
21
- name: "templateName",
22
- message: "Select a template to use",
23
- choices: availableTemplates.map((t) => ({
24
- name: `${t.filename} - ${t.description}`,
25
- value: t.filename,
26
- })),
27
- },
28
- ]);
29
- return answers.templateName;
30
- };
2
+ import "dotenv/config";
3
+ import { GraphAILogger } from "graphai";
4
+ import { args } from "./tool-args.js";
5
+ import { outDirName, cacheDirName } from "../utils/const.js";
6
+ import { createMulmoScriptFromUrl } from "../tools/create_mulmo_script_from_url.js";
7
+ import { getBaseDirPath, getFullPath } from "../utils/file.js";
8
+ import { createMulmoScriptInteractively } from "../tools/create_mulmo_script_interactively.js";
9
+ import { dumpPromptFromTemplate } from "../tools/dump_prompt.js";
10
+ import { getUrlsIfNeeded, selectTemplate } from "../utils/inquirer.js";
31
11
  const main = async () => {
32
- const { o: outdir, u: urls, b: basedir, action, v: verbose, i: interactive, f: filename } = tool_args_1.args;
33
- let { t: template } = tool_args_1.args;
34
- const baseDirPath = (0, file_1.getBaseDirPath)(basedir);
35
- const outDirPath = (0, file_1.getFullPath)(baseDirPath, outdir ?? const_1.outDirName);
12
+ const { o: outdir, b: basedir, action, v: verbose, i: interactive, s: filename, cache } = args;
13
+ let { t: template } = args;
14
+ const { u: urls } = args;
15
+ const { llm_model, llm_agent } = args;
16
+ const baseDirPath = getBaseDirPath(basedir);
17
+ const outDirPath = getFullPath(baseDirPath, outdir ?? outDirName);
18
+ const cacheDirPath = getFullPath(outDirPath, cache ?? cacheDirName);
36
19
  if (verbose) {
37
- console.log("baseDirPath:", baseDirPath);
38
- console.log("outDirPath:", outDirPath);
39
- console.log("template:", template);
40
- console.log("urls:", urls);
41
- console.log("action:", action);
42
- console.log("interactive:", interactive);
43
- console.log("filename:", filename);
20
+ GraphAILogger.info("baseDirPath:", baseDirPath);
21
+ GraphAILogger.info("outDirPath:", outDirPath);
22
+ GraphAILogger.info("cacheDirPath:", cacheDirPath);
23
+ GraphAILogger.info("template:", template);
24
+ GraphAILogger.info("urls:", urls);
25
+ GraphAILogger.info("action:", action);
26
+ GraphAILogger.info("interactive:", interactive);
27
+ GraphAILogger.info("filename:", filename);
44
28
  }
45
29
  else {
46
- graphai_1.GraphAILogger.setLevelEnabled("error", false);
47
- graphai_1.GraphAILogger.setLevelEnabled("log", false);
48
- graphai_1.GraphAILogger.setLevelEnabled("warn", false);
30
+ GraphAILogger.setLevelEnabled("error", false);
31
+ GraphAILogger.setLevelEnabled("log", false);
32
+ GraphAILogger.setLevelEnabled("warn", false);
49
33
  }
50
34
  // If template is not specified, show the selection prompt
51
35
  if (!template) {
52
36
  template = await selectTemplate();
53
37
  if (verbose) {
54
- console.log("Selected template:", template);
38
+ GraphAILogger.info("Selected template:", template);
55
39
  }
56
40
  }
57
41
  if (action === "scripting") {
42
+ const context = { outDirPath, templateName: template, urls, filename, cacheDirPath, llm_model, llm_agent };
58
43
  if (interactive) {
59
- await (0, seed_1.createMulmoScriptWithInteractive)({ outDirPath, templateName: template, urls: urls, filename });
60
- }
61
- else if (urls.length > 0) {
62
- await (0, seed_from_url_1.createMulmoScriptFromUrl)({ urls, templateName: template, outDirPath, filename });
44
+ await createMulmoScriptInteractively(context);
63
45
  }
64
46
  else {
65
- throw new Error("urls is required when not in interactive mode");
47
+ context.urls = await getUrlsIfNeeded(urls);
48
+ await createMulmoScriptFromUrl(context);
66
49
  }
67
50
  }
68
51
  else if (action === "prompt") {
69
- await (0, dump_prompt_1.dumpPromptFromTemplate)({ templateName: template });
52
+ await dumpPromptFromTemplate({ templateName: template });
70
53
  }
71
54
  else {
72
55
  throw new Error(`Unknown or unsupported action: ${action}`);
73
56
  }
74
57
  };
75
58
  main().catch((error) => {
76
- console.error("An unexpected error occurred:", error);
59
+ GraphAILogger.info("An unexpected error occurred:", error);
77
60
  process.exit(1);
78
61
  });
@@ -1,3 +1,4 @@
1
- export * from "./mulmo_script";
2
- export * from "./mulmo_script_template";
3
- export * from "./mulmo_studio_context";
1
+ export * from "./mulmo_script.js";
2
+ export * from "./mulmo_script_template.js";
3
+ export * from "./mulmo_studio_context.js";
4
+ export * from "./mulmo_media_source.js";
@@ -1,19 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./mulmo_script"), exports);
18
- __exportStar(require("./mulmo_script_template"), exports);
19
- __exportStar(require("./mulmo_studio_context"), exports);
1
+ export * from "./mulmo_script.js";
2
+ export * from "./mulmo_script_template.js";
3
+ export * from "./mulmo_studio_context.js";
4
+ export * from "./mulmo_media_source.js";
@@ -0,0 +1,4 @@
1
+ import { MulmoMediaSource, MulmoStudioContext } from "../types/index.js";
2
+ export declare const MulmoMediaSourceMethods: {
3
+ getText(mediaSource: MulmoMediaSource, context: MulmoStudioContext): Promise<string | null>;
4
+ };
@@ -0,0 +1,21 @@
1
+ import fs from "fs";
2
+ import { getFullPath } from "../utils/file.js";
3
+ export const MulmoMediaSourceMethods = {
4
+ async getText(mediaSource, context) {
5
+ if (mediaSource.kind === "text") {
6
+ return mediaSource.text;
7
+ }
8
+ if (mediaSource.kind === "url") {
9
+ const res = await fetch(mediaSource.url);
10
+ if (!res.ok) {
11
+ throw new Error(`Failed to fetch media source: ${mediaSource.url}`);
12
+ }
13
+ return await res.text();
14
+ }
15
+ if (mediaSource.kind === "path") {
16
+ const path = getFullPath(context.fileDirs.mulmoFileDirPath, mediaSource.path);
17
+ return fs.readFileSync(path, "utf-8");
18
+ }
19
+ return null;
20
+ },
21
+ };
@@ -1,11 +1,12 @@
1
- import { MulmoDimension, MulmoScript, MulmoBeat, SpeechOptions } from "../types";
1
+ import "dotenv/config";
2
+ import { MulmoCanvasDimension, MulmoScript, MulmoBeat, SpeechOptions, Text2SpeechProvider, Text2ImageAgentInfo, BeatMediaType } from "../types/index.js";
2
3
  export declare const MulmoScriptMethods: {
3
4
  getPadding(script: MulmoScript): number;
4
- getCanvasSize(script: MulmoScript): MulmoDimension;
5
+ getCanvasSize(script: MulmoScript): MulmoCanvasDimension;
5
6
  getAspectRatio(script: MulmoScript): string;
6
- getSpeechProvider(script: MulmoScript): string;
7
- getImageProvider(script: MulmoScript): string;
7
+ getSpeechProvider(script: MulmoScript): Text2SpeechProvider;
8
8
  getTextSlideStyle(script: MulmoScript, beat: MulmoBeat): string;
9
9
  getSpeechOptions(script: MulmoScript, beat: MulmoBeat): SpeechOptions | undefined;
10
- getText2imageAgent(script: MulmoScript): string;
10
+ getImageAgentInfo(script: MulmoScript): Text2ImageAgentInfo;
11
+ getImageType(_: MulmoScript, beat: MulmoBeat): BeatMediaType;
11
12
  };
@@ -1,23 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MulmoScriptMethods = void 0;
1
+ import "dotenv/config";
2
+ import { text2ImageProviderSchema, text2SpeechProviderSchema, mulmoCanvasDimensionSchema } from "../types/schema.js";
4
3
  const defaultTextSlideStyles = [
5
- "body { margin: 40px; margin-top: 60px; color:#333; font-size: 48px }",
6
- "h1 { font-size: 60px; text-align: center }",
4
+ '*,*::before,*::after{box-sizing:border-box}body,h1,h2,h3,h4,p,figure,blockquote,dl,dd{margin:0}ul[role="list"],ol[role="list"]{list-style:none}html:focus-within{scroll-behavior:smooth}body{min-height:100vh;text-rendering:optimizeSpeed;line-height:1.5}a:not([class]){text-decoration-skip-ink:auto}img,picture{max-width:100%;display:block}input,button,textarea,select{font:inherit}@media(prefers-reduced-motion:reduce){html:focus-within{scroll-behavior:auto}*,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important;scroll-behavior:auto !important}}',
5
+ "body { margin: 60px; margin-top: 40px; color:#333; font-size: 30px; font-family: Arial, sans-serif; box-sizing: border-box; height: 100vh }",
6
+ "h1 { font-size: 56px; margin-bottom: 20px; text-align: center; }",
7
+ "h2 { font-size: 48px }",
8
+ "h3 { font-size: 36px }",
7
9
  "ul { margin-left: 40px } ",
8
- "pre { margin-left: 40px; font-size: 32px }",
10
+ "pre { background: #eeeecc; font-size: 16px; padding:4px }",
9
11
  "p { margin-left: 40px }",
10
- "table { font-size: 40px; margin: auto; border: 1px solid gray; border-collapse: collapse }",
12
+ "table { font-size: 36px; margin: auto; border: 1px solid gray; border-collapse: collapse }",
11
13
  "th { border-bottom: 1px solid gray }",
12
14
  "td, th { padding: 8px }",
13
15
  "tr:nth-child(even) { background-color: #eee }",
14
16
  ];
15
- exports.MulmoScriptMethods = {
17
+ export const MulmoScriptMethods = {
16
18
  getPadding(script) {
17
19
  return script.videoParams?.padding ?? 1000; // msec
18
20
  },
19
21
  getCanvasSize(script) {
20
- return script.canvasSize ?? { width: 1280, height: 720 };
22
+ return mulmoCanvasDimensionSchema.parse(script.canvasSize);
21
23
  },
22
24
  getAspectRatio(script) {
23
25
  // Google's text2image specific parameter
@@ -25,21 +27,32 @@ exports.MulmoScriptMethods = {
25
27
  return size.width > size.height ? "16:9" : "9:16";
26
28
  },
27
29
  getSpeechProvider(script) {
28
- return script.speechParams?.provider ?? "openai";
29
- },
30
- getImageProvider(script) {
31
- return script.imageParams?.provider ?? "openai";
30
+ return text2SpeechProviderSchema.parse(script.speechParams?.provider);
32
31
  },
33
32
  getTextSlideStyle(script, beat) {
34
33
  const styles = script.textSlideParams?.cssStyles ?? defaultTextSlideStyles;
35
34
  // NOTES: Taking advantage of CSS override rule (you can redefine it to override)
36
35
  const extraStyles = beat.textSlideParams?.cssStyles ?? [];
37
- return [...styles, ...extraStyles].join("\n");
36
+ // This code allows us to support both string and array of strings for cssStyles
37
+ return [...[styles], ...[extraStyles]].flat().join("\n");
38
38
  },
39
39
  getSpeechOptions(script, beat) {
40
40
  return { ...script.speechParams.speakers[beat.speaker].speechOptions, ...beat.speechOptions };
41
41
  },
42
- getText2imageAgent(script) {
43
- return this.getImageProvider(script) === "google" ? "imageGoogleAgent" : "imageOpenaiAgent";
42
+ getImageAgentInfo(script) {
43
+ // Notice that we copy imageParams from script and update
44
+ // provider and model appropriately.
45
+ const provider = text2ImageProviderSchema.parse(script.imageParams?.provider);
46
+ const defaultImageParams = {
47
+ model: provider === "openai" ? process.env.DEFAULT_OPENAI_IMAGE_MODEL : undefined,
48
+ };
49
+ return {
50
+ provider,
51
+ agent: provider === "google" ? "imageGoogleAgent" : "imageOpenaiAgent",
52
+ imageParams: { ...defaultImageParams, ...script.imageParams },
53
+ };
54
+ },
55
+ getImageType(_, beat) {
56
+ return beat.image?.type == "movie" ? "movie" : "image";
44
57
  },
45
58
  };
@@ -1,4 +1,4 @@
1
- import { MulmoScriptTemplate } from "../types";
1
+ import { MulmoScriptTemplate } from "../types/index.js";
2
2
  export declare const MulmoScriptTemplateMethods: {
3
3
  getSystemPrompt(template: MulmoScriptTemplate): string;
4
4
  };
@@ -1,19 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MulmoScriptTemplateMethods = void 0;
7
- const zod_to_json_schema_1 = __importDefault(require("zod-to-json-schema"));
8
- const schema_1 = require("../types/schema");
9
- exports.MulmoScriptTemplateMethods = {
1
+ import { zodToJsonSchema } from "zod-to-json-schema";
2
+ import { mulmoScriptSchema } from "../types/schema.js";
3
+ export const MulmoScriptTemplateMethods = {
10
4
  getSystemPrompt(template) {
11
5
  // script is provided, use it as a script template
12
6
  if (template.script) {
13
7
  return `${template.systemPrompt}\n\`\`\`JSON\n${JSON.stringify(template.script)}\n\`\`\``;
14
8
  }
15
9
  // script is not provided, use the default schema
16
- const defaultSchema = (0, zod_to_json_schema_1.default)(schema_1.mulmoScriptSchema, {
10
+ const defaultSchema = zodToJsonSchema(mulmoScriptSchema, {
17
11
  strictUnions: true,
18
12
  });
19
13
  const specificOutputPrompt = `The output should follow the JSON schema specified below. Please provide your response as valid JSON within \`\`\`json code blocks for clarity.`;
@@ -1,4 +1,4 @@
1
- import { MulmoStudioContext } from "../types";
1
+ import { MulmoStudioContext } from "../types/index.js";
2
2
  export declare const MulmoStudioContextMethods: {
3
3
  resolveAssetPath(context: MulmoStudioContext, relativePath: string): string;
4
4
  };
@@ -1,12 +1,6 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MulmoStudioContextMethods = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- exports.MulmoStudioContextMethods = {
1
+ import path from "path";
2
+ export const MulmoStudioContextMethods = {
9
3
  resolveAssetPath(context, relativePath) {
10
- return path_1.default.resolve(context.fileDirs.mulmoFileDirPath, relativePath);
4
+ return path.resolve(context.fileDirs.mulmoFileDirPath, relativePath);
11
5
  },
12
6
  };
@@ -0,0 +1,3 @@
1
+ import "dotenv/config";
2
+ import { ScriptingParams } from "../types/index.js";
3
+ export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename, cacheDirPath }: ScriptingParams) => Promise<void>;