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.
- package/README.md +129 -15
- package/assets/font/NotoSansJP-Regular.ttf +0 -0
- package/assets/html/chart.html +38 -0
- package/assets/html/mermaid.html +51 -0
- package/assets/templates/business.json +57 -14
- package/assets/templates/children_book.json +1 -3
- package/assets/templates/coding.json +140 -0
- package/lib/actions/audio.d.ts +2 -2
- package/lib/actions/audio.js +88 -101
- package/lib/actions/images.d.ts +1 -1
- package/lib/actions/images.js +50 -88
- package/lib/actions/index.d.ts +5 -0
- package/lib/actions/index.js +5 -0
- package/lib/actions/movie.d.ts +9 -1
- package/lib/actions/movie.js +124 -65
- package/lib/actions/pdf.d.ts +2 -0
- package/lib/actions/pdf.js +211 -0
- package/lib/actions/pdf2.d.ts +2 -0
- package/lib/actions/pdf2.js +203 -0
- package/lib/actions/translate.d.ts +1 -1
- package/lib/actions/translate.js +38 -61
- package/lib/agents/add_bgm_agent.d.ts +1 -1
- package/lib/agents/add_bgm_agent.js +10 -14
- package/lib/agents/anthropic_agent.d.ts +23 -0
- package/lib/agents/anthropic_agent.js +162 -0
- package/lib/agents/combine_audio_files_agent.d.ts +1 -1
- package/lib/agents/combine_audio_files_agent.js +33 -32
- package/lib/agents/image_google_agent.d.ts +1 -1
- package/lib/agents/image_google_agent.js +8 -11
- package/lib/agents/image_openai_agent.js +7 -14
- package/lib/agents/index.d.ts +8 -8
- package/lib/agents/index.js +13 -30
- package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
- package/lib/agents/mulmo_prompts_agent.js +7 -11
- package/lib/agents/nested_agent.d.ts +9 -0
- package/lib/agents/nested_agent.js +138 -0
- package/lib/agents/prompts_data.js +1 -4
- package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
- package/lib/agents/tts_nijivoice_agent.js +8 -12
- package/lib/agents/tts_openai_agent.js +9 -16
- package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
- package/lib/agents/validate_mulmo_script_agent.js +6 -10
- package/lib/cli/args.d.ts +5 -2
- package/lib/cli/args.js +52 -35
- package/lib/cli/cli.d.ts +14 -0
- package/lib/cli/cli.js +74 -57
- package/lib/cli/common.js +1 -5
- package/lib/cli/tool-args.d.ts +4 -1
- package/lib/cli/tool-args.js +29 -18
- package/lib/cli/tool-cli.js +34 -51
- package/lib/methods/index.d.ts +4 -3
- package/lib/methods/index.js +4 -19
- package/lib/methods/mulmo_media_source.d.ts +4 -0
- package/lib/methods/mulmo_media_source.js +21 -0
- package/lib/methods/mulmo_script.d.ts +6 -5
- package/lib/methods/mulmo_script.js +29 -16
- package/lib/methods/mulmo_script_template.d.ts +1 -1
- package/lib/methods/mulmo_script_template.js +4 -10
- package/lib/methods/mulmo_studio_context.d.ts +1 -1
- package/lib/methods/mulmo_studio_context.js +3 -9
- package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
- package/lib/tools/create_mulmo_script_from_url.js +152 -0
- package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
- package/lib/tools/create_mulmo_script_interactively.js +258 -0
- package/lib/tools/dump_prompt.js +5 -8
- package/lib/tools/prompt.js +9 -11
- package/lib/tools/seed_from_url2.d.ts +3 -0
- package/lib/tools/seed_from_url2.js +154 -0
- package/lib/types/index.d.ts +2 -1
- package/lib/types/index.js +2 -17
- package/lib/types/schema.d.ts +3624 -2798
- package/lib/types/schema.js +172 -123
- package/lib/types/type.d.ts +34 -3
- package/lib/types/type.js +1 -2
- package/lib/utils/const.d.ts +4 -1
- package/lib/utils/const.js +6 -6
- package/lib/utils/file.d.ts +22 -4
- package/lib/utils/file.js +100 -79
- package/lib/utils/filters.d.ts +1 -0
- package/lib/utils/filters.js +47 -26
- package/lib/utils/image_plugins/chart.d.ts +3 -0
- package/lib/utils/image_plugins/chart.js +18 -0
- package/lib/utils/image_plugins/image.d.ts +2 -0
- package/lib/utils/image_plugins/image.js +3 -0
- package/lib/utils/image_plugins/index.d.ts +7 -0
- package/lib/utils/image_plugins/index.js +7 -0
- package/lib/utils/image_plugins/markdown.d.ts +3 -0
- package/lib/utils/image_plugins/markdown.js +11 -0
- package/lib/utils/image_plugins/mermaid.d.ts +3 -0
- package/lib/utils/image_plugins/mermaid.js +21 -0
- package/lib/utils/image_plugins/movie.d.ts +2 -0
- package/lib/utils/image_plugins/movie.js +3 -0
- package/lib/utils/image_plugins/source.d.ts +4 -0
- package/lib/utils/image_plugins/source.js +15 -0
- package/lib/utils/image_plugins/text_slide.d.ts +3 -0
- package/lib/utils/image_plugins/text_slide.js +12 -0
- package/lib/utils/image_plugins/type_guards.d.ts +6 -0
- package/lib/utils/image_plugins/type_guards.js +21 -0
- package/lib/utils/image_preprocess.d.ts +14 -0
- package/lib/utils/image_preprocess.js +52 -0
- package/lib/utils/inquirer.d.ts +2 -0
- package/lib/utils/inquirer.js +33 -0
- package/lib/utils/markdown.d.ts +3 -1
- package/lib/utils/markdown.js +20 -19
- package/lib/utils/pdf.d.ts +8 -0
- package/lib/utils/pdf.js +75 -0
- package/lib/utils/plugins.d.ts +5 -0
- package/lib/utils/plugins.js +11 -0
- package/lib/utils/preprocess.d.ts +70 -123
- package/lib/utils/preprocess.js +37 -43
- package/lib/utils/string.js +4 -10
- package/lib/utils/text_hash.js +2 -39
- package/lib/utils/utils.d.ts +12 -0
- package/lib/utils/utils.js +34 -0
- package/package.json +23 -8
package/lib/cli/cli.js
CHANGED
|
@@ -1,78 +1,95 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
|
74
|
+
await translate(context);
|
|
65
75
|
}
|
|
66
76
|
if (action === "audio") {
|
|
67
|
-
await
|
|
77
|
+
await audio(context);
|
|
68
78
|
}
|
|
69
79
|
if (action === "images") {
|
|
70
|
-
await
|
|
80
|
+
await images(context);
|
|
71
81
|
}
|
|
72
82
|
if (action === "movie") {
|
|
73
|
-
await
|
|
74
|
-
await
|
|
75
|
-
await
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
package/lib/cli/tool-args.d.ts
CHANGED
|
@@ -6,7 +6,10 @@ export declare const args: {
|
|
|
6
6
|
u: string[] | never[];
|
|
7
7
|
i: boolean | undefined;
|
|
8
8
|
t: string | undefined;
|
|
9
|
-
|
|
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
|
};
|
package/lib/cli/tool-args.js
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
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("
|
|
38
|
-
alias: "
|
|
39
|
-
description: "
|
|
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();
|
package/lib/cli/tool-cli.js
CHANGED
|
@@ -1,78 +1,61 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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,
|
|
33
|
-
let { t: template } =
|
|
34
|
-
const
|
|
35
|
-
const
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
47
|
+
context.urls = await getUrlsIfNeeded(urls);
|
|
48
|
+
await createMulmoScriptFromUrl(context);
|
|
66
49
|
}
|
|
67
50
|
}
|
|
68
51
|
else if (action === "prompt") {
|
|
69
|
-
await
|
|
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
|
-
|
|
59
|
+
GraphAILogger.info("An unexpected error occurred:", error);
|
|
77
60
|
process.exit(1);
|
|
78
61
|
});
|
package/lib/methods/index.d.ts
CHANGED
|
@@ -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";
|
package/lib/methods/index.js
CHANGED
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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,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
|
|
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):
|
|
5
|
+
getCanvasSize(script: MulmoScript): MulmoCanvasDimension;
|
|
5
6
|
getAspectRatio(script: MulmoScript): string;
|
|
6
|
-
getSpeechProvider(script: MulmoScript):
|
|
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
|
-
|
|
10
|
+
getImageAgentInfo(script: MulmoScript): Text2ImageAgentInfo;
|
|
11
|
+
getImageType(_: MulmoScript, beat: MulmoBeat): BeatMediaType;
|
|
11
12
|
};
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.MulmoScriptMethods = void 0;
|
|
1
|
+
import "dotenv/config";
|
|
2
|
+
import { text2ImageProviderSchema, text2SpeechProviderSchema, mulmoCanvasDimensionSchema } from "../types/schema.js";
|
|
4
3
|
const defaultTextSlideStyles = [
|
|
5
|
-
|
|
6
|
-
"
|
|
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 {
|
|
10
|
+
"pre { background: #eeeecc; font-size: 16px; padding:4px }",
|
|
9
11
|
"p { margin-left: 40px }",
|
|
10
|
-
"table { font-size:
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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,19 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 = (
|
|
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,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
|
4
|
+
return path.resolve(context.fileDirs.mulmoFileDirPath, relativePath);
|
|
11
5
|
},
|
|
12
6
|
};
|