mulmocast 0.0.1
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 +74 -0
- package/assets/audio/silent300.mp3 +0 -0
- package/assets/audio/silent800.mp3 +0 -0
- package/assets/music/StarsBeyondEx.mp3 +0 -0
- package/assets/templates/business.json +89 -0
- package/assets/templates/children_book.json +135 -0
- package/assets/templates/podcast_standard.json +5 -0
- package/assets/templates/sensei_and_taro.json +123 -0
- package/lib/actions/audio.d.ts +3 -0
- package/lib/actions/audio.js +186 -0
- package/lib/actions/images.d.ts +2 -0
- package/lib/actions/images.js +211 -0
- package/lib/actions/movie.d.ts +2 -0
- package/lib/actions/movie.js +81 -0
- package/lib/actions/translate.d.ts +3 -0
- package/lib/actions/translate.js +236 -0
- package/lib/agents/add_bgm_agent.d.ts +3 -0
- package/lib/agents/add_bgm_agent.js +61 -0
- package/lib/agents/combine_audio_files_agent.d.ts +3 -0
- package/lib/agents/combine_audio_files_agent.js +57 -0
- package/lib/agents/image_google_agent.d.ts +15 -0
- package/lib/agents/image_google_agent.js +88 -0
- package/lib/agents/image_openai_agent.d.ts +15 -0
- package/lib/agents/image_openai_agent.js +59 -0
- package/lib/agents/index.d.ts +13 -0
- package/lib/agents/index.js +31 -0
- package/lib/agents/mulmo_prompts_agent.d.ts +7 -0
- package/lib/agents/mulmo_prompts_agent.js +41 -0
- package/lib/agents/prompts_data.d.ts +15 -0
- package/lib/agents/prompts_data.js +19 -0
- package/lib/agents/tts_nijivoice_agent.d.ts +4 -0
- package/lib/agents/tts_nijivoice_agent.js +68 -0
- package/lib/agents/tts_openai_agent.d.ts +4 -0
- package/lib/agents/tts_openai_agent.js +50 -0
- package/lib/agents/validate_mulmo_script_agent.d.ts +17 -0
- package/lib/agents/validate_mulmo_script_agent.js +38 -0
- package/lib/cli/args.d.ts +10 -0
- package/lib/cli/args.js +38 -0
- package/lib/cli/cli.d.ts +2 -0
- package/lib/cli/cli.js +78 -0
- package/lib/cli/common.d.ts +8 -0
- package/lib/cli/common.js +26 -0
- package/lib/cli/tool-args.d.ts +12 -0
- package/lib/cli/tool-args.js +53 -0
- package/lib/cli/tool-cli.d.ts +2 -0
- package/lib/cli/tool-cli.js +78 -0
- package/lib/methods/index.d.ts +3 -0
- package/lib/methods/index.js +19 -0
- package/lib/methods/mulmo_script.d.ts +11 -0
- package/lib/methods/mulmo_script.js +45 -0
- package/lib/methods/mulmo_script_template.d.ts +4 -0
- package/lib/methods/mulmo_script_template.js +22 -0
- package/lib/methods/mulmo_studio_context.d.ts +4 -0
- package/lib/methods/mulmo_studio_context.js +12 -0
- package/lib/tools/dump_prompt.d.ts +3 -0
- package/lib/tools/dump_prompt.js +9 -0
- package/lib/tools/prompt.d.ts +1 -0
- package/lib/tools/prompt.js +20 -0
- package/lib/tools/seed.d.ts +3 -0
- package/lib/tools/seed.js +201 -0
- package/lib/tools/seed_from_url.d.ts +3 -0
- package/lib/tools/seed_from_url.js +178 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +17 -0
- package/lib/types/schema.d.ts +5817 -0
- package/lib/types/schema.js +207 -0
- package/lib/types/type.d.ts +33 -0
- package/lib/types/type.js +2 -0
- package/lib/utils/const.d.ts +3 -0
- package/lib/utils/const.js +6 -0
- package/lib/utils/file.d.ts +28 -0
- package/lib/utils/file.js +112 -0
- package/lib/utils/filters.d.ts +3 -0
- package/lib/utils/filters.js +32 -0
- package/lib/utils/markdown.d.ts +1 -0
- package/lib/utils/markdown.js +27 -0
- package/lib/utils/preprocess.d.ts +247 -0
- package/lib/utils/preprocess.js +53 -0
- package/lib/utils/string.d.ts +9 -0
- package/lib/utils/string.js +60 -0
- package/lib/utils/text_hash.d.ts +1 -0
- package/lib/utils/text_hash.js +41 -0
- package/package.json +77 -0
package/lib/cli/cli.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
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 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 };
|
|
30
|
+
};
|
|
31
|
+
const main = async () => {
|
|
32
|
+
const files = getFileObject();
|
|
33
|
+
const { mulmoFilePath } = files;
|
|
34
|
+
if (args_1.args.v) {
|
|
35
|
+
console.log(files);
|
|
36
|
+
}
|
|
37
|
+
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;
|
|
45
|
+
}
|
|
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);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error(`Error: invalid MulmoScript Schema: ${mulmoFilePath} \n ${error}`);
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
const context = {
|
|
60
|
+
studio,
|
|
61
|
+
fileDirs: files,
|
|
62
|
+
};
|
|
63
|
+
if (action === "translate") {
|
|
64
|
+
await (0, translate_1.translate)(context);
|
|
65
|
+
}
|
|
66
|
+
if (action === "audio") {
|
|
67
|
+
await (0, audio_1.audio)(context, methods_1.MulmoScriptMethods.getSpeechProvider(studio.script) === "nijivoice" ? 1 : 8);
|
|
68
|
+
}
|
|
69
|
+
if (action === "images") {
|
|
70
|
+
await (0, images_1.images)(context);
|
|
71
|
+
}
|
|
72
|
+
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);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
main();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commonOptions = void 0;
|
|
4
|
+
const commonOptions = (yargs) => {
|
|
5
|
+
return yargs
|
|
6
|
+
.option("v", {
|
|
7
|
+
alias: "verbose",
|
|
8
|
+
describe: "verbose log",
|
|
9
|
+
demandOption: true,
|
|
10
|
+
default: false,
|
|
11
|
+
type: "boolean",
|
|
12
|
+
})
|
|
13
|
+
.option("o", {
|
|
14
|
+
alias: "outdir",
|
|
15
|
+
description: "output dir",
|
|
16
|
+
demandOption: false,
|
|
17
|
+
type: "string",
|
|
18
|
+
})
|
|
19
|
+
.option("b", {
|
|
20
|
+
alias: "basedir",
|
|
21
|
+
description: "base dir",
|
|
22
|
+
demandOption: false,
|
|
23
|
+
type: "string",
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
exports.commonOptions = commonOptions;
|
|
@@ -0,0 +1,53 @@
|
|
|
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")
|
|
16
|
+
.option("u", {
|
|
17
|
+
alias: "url",
|
|
18
|
+
description: "URLs to reference (required when not in interactive mode)",
|
|
19
|
+
demandOption: false,
|
|
20
|
+
default: [],
|
|
21
|
+
type: "array",
|
|
22
|
+
string: true,
|
|
23
|
+
})
|
|
24
|
+
.option("i", {
|
|
25
|
+
alias: "interactive",
|
|
26
|
+
description: "Generate script in interactive mode with user prompts",
|
|
27
|
+
demandOption: false,
|
|
28
|
+
type: "boolean",
|
|
29
|
+
})
|
|
30
|
+
.option("t", {
|
|
31
|
+
alias: "template",
|
|
32
|
+
description: "Template name to use",
|
|
33
|
+
demandOption: false,
|
|
34
|
+
choices: availableTemplateNames,
|
|
35
|
+
type: "string",
|
|
36
|
+
})
|
|
37
|
+
.option("f", {
|
|
38
|
+
alias: "filename",
|
|
39
|
+
description: "output filename",
|
|
40
|
+
demandOption: false,
|
|
41
|
+
default: "script",
|
|
42
|
+
type: "string",
|
|
43
|
+
})
|
|
44
|
+
.command("$0 <action>", "Run mulmocast tool", (yargs) => {
|
|
45
|
+
return yargs.positional("action", {
|
|
46
|
+
describe: "action to perform",
|
|
47
|
+
choices: ["scripting", "prompt"],
|
|
48
|
+
type: "string",
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
.strict()
|
|
52
|
+
.help()
|
|
53
|
+
.parseSync();
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
};
|
|
31
|
+
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);
|
|
36
|
+
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);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
graphai_1.GraphAILogger.setLevelEnabled("error", false);
|
|
47
|
+
graphai_1.GraphAILogger.setLevelEnabled("log", false);
|
|
48
|
+
graphai_1.GraphAILogger.setLevelEnabled("warn", false);
|
|
49
|
+
}
|
|
50
|
+
// If template is not specified, show the selection prompt
|
|
51
|
+
if (!template) {
|
|
52
|
+
template = await selectTemplate();
|
|
53
|
+
if (verbose) {
|
|
54
|
+
console.log("Selected template:", template);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (action === "scripting") {
|
|
58
|
+
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 });
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
throw new Error("urls is required when not in interactive mode");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else if (action === "prompt") {
|
|
69
|
+
await (0, dump_prompt_1.dumpPromptFromTemplate)({ templateName: template });
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
throw new Error(`Unknown or unsupported action: ${action}`);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
main().catch((error) => {
|
|
76
|
+
console.error("An unexpected error occurred:", error);
|
|
77
|
+
process.exit(1);
|
|
78
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
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);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MulmoDimension, MulmoScript, MulmoBeat, SpeechOptions } from "../types";
|
|
2
|
+
export declare const MulmoScriptMethods: {
|
|
3
|
+
getPadding(script: MulmoScript): number;
|
|
4
|
+
getCanvasSize(script: MulmoScript): MulmoDimension;
|
|
5
|
+
getAspectRatio(script: MulmoScript): string;
|
|
6
|
+
getSpeechProvider(script: MulmoScript): string;
|
|
7
|
+
getImageProvider(script: MulmoScript): string;
|
|
8
|
+
getTextSlideStyle(script: MulmoScript, beat: MulmoBeat): string;
|
|
9
|
+
getSpeechOptions(script: MulmoScript, beat: MulmoBeat): SpeechOptions | undefined;
|
|
10
|
+
getText2imageAgent(script: MulmoScript): string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulmoScriptMethods = void 0;
|
|
4
|
+
const defaultTextSlideStyles = [
|
|
5
|
+
"body { margin: 40px; margin-top: 60px; color:#333; font-size: 48px }",
|
|
6
|
+
"h1 { font-size: 60px; text-align: center }",
|
|
7
|
+
"ul { margin-left: 40px } ",
|
|
8
|
+
"pre { margin-left: 40px; font-size: 32px }",
|
|
9
|
+
"p { margin-left: 40px }",
|
|
10
|
+
"table { font-size: 40px; margin: auto; border: 1px solid gray; border-collapse: collapse }",
|
|
11
|
+
"th { border-bottom: 1px solid gray }",
|
|
12
|
+
"td, th { padding: 8px }",
|
|
13
|
+
"tr:nth-child(even) { background-color: #eee }",
|
|
14
|
+
];
|
|
15
|
+
exports.MulmoScriptMethods = {
|
|
16
|
+
getPadding(script) {
|
|
17
|
+
return script.videoParams?.padding ?? 1000; // msec
|
|
18
|
+
},
|
|
19
|
+
getCanvasSize(script) {
|
|
20
|
+
return script.canvasSize ?? { width: 1280, height: 720 };
|
|
21
|
+
},
|
|
22
|
+
getAspectRatio(script) {
|
|
23
|
+
// Google's text2image specific parameter
|
|
24
|
+
const size = this.getCanvasSize(script);
|
|
25
|
+
return size.width > size.height ? "16:9" : "9:16";
|
|
26
|
+
},
|
|
27
|
+
getSpeechProvider(script) {
|
|
28
|
+
return script.speechParams?.provider ?? "openai";
|
|
29
|
+
},
|
|
30
|
+
getImageProvider(script) {
|
|
31
|
+
return script.imageParams?.provider ?? "openai";
|
|
32
|
+
},
|
|
33
|
+
getTextSlideStyle(script, beat) {
|
|
34
|
+
const styles = script.textSlideParams?.cssStyles ?? defaultTextSlideStyles;
|
|
35
|
+
// NOTES: Taking advantage of CSS override rule (you can redefine it to override)
|
|
36
|
+
const extraStyles = beat.textSlideParams?.cssStyles ?? [];
|
|
37
|
+
return [...styles, ...extraStyles].join("\n");
|
|
38
|
+
},
|
|
39
|
+
getSpeechOptions(script, beat) {
|
|
40
|
+
return { ...script.speechParams.speakers[beat.speaker].speechOptions, ...beat.speechOptions };
|
|
41
|
+
},
|
|
42
|
+
getText2imageAgent(script) {
|
|
43
|
+
return this.getImageProvider(script) === "google" ? "imageGoogleAgent" : "imageOpenaiAgent";
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 = {
|
|
10
|
+
getSystemPrompt(template) {
|
|
11
|
+
// script is provided, use it as a script template
|
|
12
|
+
if (template.script) {
|
|
13
|
+
return `${template.systemPrompt}\n\`\`\`JSON\n${JSON.stringify(template.script)}\n\`\`\``;
|
|
14
|
+
}
|
|
15
|
+
// script is not provided, use the default schema
|
|
16
|
+
const defaultSchema = (0, zod_to_json_schema_1.default)(schema_1.mulmoScriptSchema, {
|
|
17
|
+
strictUnions: true,
|
|
18
|
+
});
|
|
19
|
+
const specificOutputPrompt = `The output should follow the JSON schema specified below. Please provide your response as valid JSON within \`\`\`json code blocks for clarity.`;
|
|
20
|
+
return `${template.systemPrompt}\n\n${specificOutputPrompt}\n\n\`\`\`JSON\n${JSON.stringify(defaultSchema)}\n\`\`\``;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
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 = {
|
|
9
|
+
resolveAssetPath(context, relativePath) {
|
|
10
|
+
return path_1.default.resolve(context.fileDirs.mulmoFileDirPath, relativePath);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dumpPromptFromTemplate = void 0;
|
|
4
|
+
const file_1 = require("../utils/file");
|
|
5
|
+
const dumpPromptFromTemplate = async ({ templateName }) => {
|
|
6
|
+
const prompt = (0, file_1.readTemplatePrompt)(templateName);
|
|
7
|
+
console.log(prompt);
|
|
8
|
+
};
|
|
9
|
+
exports.dumpPromptFromTemplate = dumpPromptFromTemplate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const main = async () => {
|
|
9
|
+
const basePath = path_1.default.resolve(__dirname + "/../../prompts/");
|
|
10
|
+
const ret = {};
|
|
11
|
+
fs_1.default.readdirSync(basePath).map((file) => {
|
|
12
|
+
const key = file.split(".")[0];
|
|
13
|
+
const content = fs_1.default.readFileSync(path_1.default.resolve(basePath) + "/" + file, "utf-8");
|
|
14
|
+
ret[key] = content;
|
|
15
|
+
});
|
|
16
|
+
const code = ["// This file is auto-generated by src/tools/prompt.ts and Do not be edited manually.", `export const prompts = ${JSON.stringify(ret)};`].join("\n");
|
|
17
|
+
fs_1.default.writeFileSync(path_1.default.resolve(__dirname + "/../../src/agents/prompts_data.ts"), code, "utf8");
|
|
18
|
+
// console.log(hoge);
|
|
19
|
+
};
|
|
20
|
+
main();
|
|
@@ -0,0 +1,201 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createMulmoScriptWithInteractive = void 0;
|
|
37
|
+
require("dotenv/config");
|
|
38
|
+
const graphai_1 = require("graphai");
|
|
39
|
+
const input_agents_1 = require("@graphai/input_agents");
|
|
40
|
+
const openai_agent_1 = require("@graphai/openai_agent");
|
|
41
|
+
const vanilla = __importStar(require("@graphai/vanilla"));
|
|
42
|
+
const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
|
|
43
|
+
const file_1 = require("../utils/file");
|
|
44
|
+
const browserless_agent_1 = require("@graphai/browserless_agent");
|
|
45
|
+
const agentHeader = "\x1b[34m● \x1b[0m\x1b[1mAgent\x1b[0m:\x1b[0m";
|
|
46
|
+
const graphDataForScraping = {
|
|
47
|
+
version: 0.5,
|
|
48
|
+
nodes: {
|
|
49
|
+
urls: {
|
|
50
|
+
value: [],
|
|
51
|
+
},
|
|
52
|
+
fetchResults: {
|
|
53
|
+
agent: "mapAgent",
|
|
54
|
+
inputs: {
|
|
55
|
+
rows: ":urls",
|
|
56
|
+
},
|
|
57
|
+
params: {
|
|
58
|
+
compositeResult: true,
|
|
59
|
+
},
|
|
60
|
+
graph: {
|
|
61
|
+
nodes: {
|
|
62
|
+
fetcher: {
|
|
63
|
+
agent: "browserlessAgent",
|
|
64
|
+
inputs: {
|
|
65
|
+
url: ":row",
|
|
66
|
+
text_content: true,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
copyAgent: {
|
|
70
|
+
agent: "copyAgent",
|
|
71
|
+
inputs: {
|
|
72
|
+
text: '{ url: "${:row}", text: "${:fetcher.text}" }',
|
|
73
|
+
},
|
|
74
|
+
params: {
|
|
75
|
+
namedKey: "text",
|
|
76
|
+
},
|
|
77
|
+
isResult: true,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
sourceText: {
|
|
83
|
+
agent: "arrayJoinAgent",
|
|
84
|
+
inputs: {
|
|
85
|
+
array: ":fetchResults.copyAgent",
|
|
86
|
+
},
|
|
87
|
+
params: {
|
|
88
|
+
separator: ",",
|
|
89
|
+
},
|
|
90
|
+
isResult: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
const graphData = {
|
|
95
|
+
version: 0.5,
|
|
96
|
+
loop: {
|
|
97
|
+
while: ":continue",
|
|
98
|
+
},
|
|
99
|
+
nodes: {
|
|
100
|
+
fileName: {
|
|
101
|
+
update: ":fileName",
|
|
102
|
+
},
|
|
103
|
+
outdir: {
|
|
104
|
+
update: ":outdir",
|
|
105
|
+
},
|
|
106
|
+
messages: {
|
|
107
|
+
value: [],
|
|
108
|
+
update: ":llm.messages",
|
|
109
|
+
},
|
|
110
|
+
userInput: {
|
|
111
|
+
agent: "textInputAgent",
|
|
112
|
+
params: {
|
|
113
|
+
message: "You:",
|
|
114
|
+
required: true,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
llm: {
|
|
118
|
+
agent: "openAIAgent",
|
|
119
|
+
params: {
|
|
120
|
+
model: "gpt-4o",
|
|
121
|
+
},
|
|
122
|
+
inputs: {
|
|
123
|
+
messages: ":messages",
|
|
124
|
+
prompt: ":userInput.text",
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
json: {
|
|
128
|
+
agent: "copyAgent",
|
|
129
|
+
inputs: {
|
|
130
|
+
json: ":llm.text.codeBlock().jsonParse()",
|
|
131
|
+
text: ":llm.text.codeBlock()",
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
writeJSON: {
|
|
135
|
+
if: ":json.json",
|
|
136
|
+
agent: "fileWriteAgent",
|
|
137
|
+
inputs: {
|
|
138
|
+
file: "${:outdir}/${:fileName}-${@now}.json",
|
|
139
|
+
text: ":json.text",
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
writeLog: {
|
|
143
|
+
agent: "consoleAgent",
|
|
144
|
+
inputs: {
|
|
145
|
+
text: "\n\x1b[32m🎉 Script file generated successfully! Type /bye to exit.\x1b[0m\nwriting: ${:writeJSON.path}",
|
|
146
|
+
waiting: ":writeJSON",
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
shouldResponse: {
|
|
150
|
+
agent: "compareAgent",
|
|
151
|
+
inputs: {
|
|
152
|
+
array: [[":json.json", "==", undefined], "&&", [":userInput.text", "!=", "/bye"]],
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
agentResponse: {
|
|
156
|
+
if: ":shouldResponse.result",
|
|
157
|
+
agent: "consoleAgent",
|
|
158
|
+
inputs: {
|
|
159
|
+
text: "\n" + agentHeader + " ${:llm.text}\n",
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
checkInput: {
|
|
163
|
+
agent: "compareAgent",
|
|
164
|
+
inputs: { array: [":userInput.text", "!=", "/bye"] },
|
|
165
|
+
},
|
|
166
|
+
continue: {
|
|
167
|
+
value: true,
|
|
168
|
+
update: ":checkInput.result",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const interactiveClarificationPrompt = `If there are any unclear points, be sure to ask the user questions and clarify them before generating the script.`;
|
|
173
|
+
const scrapeWebContent = async (urls) => {
|
|
174
|
+
console.log(`${agentHeader} Scraping ${urls.length} URLs...\n`);
|
|
175
|
+
const graph = new graphai_1.GraphAI(graphDataForScraping, { ...vanilla, openAIAgent: openai_agent_1.openAIAgent, textInputAgent: input_agents_1.textInputAgent, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent, browserlessAgent: browserless_agent_1.browserlessAgent });
|
|
176
|
+
graph.injectValue("urls", urls);
|
|
177
|
+
const result = (await graph.run());
|
|
178
|
+
if (!result?.sourceText?.text) {
|
|
179
|
+
return "";
|
|
180
|
+
}
|
|
181
|
+
const prefixPrompt = "Here is the web content that can be used as reference material for the script:";
|
|
182
|
+
return `\n\n${prefixPrompt}\n${result?.sourceText.text}`;
|
|
183
|
+
};
|
|
184
|
+
const createMulmoScriptWithInteractive = async ({ outDirPath, filename, templateName, urls }) => {
|
|
185
|
+
(0, file_1.mkdir)(outDirPath);
|
|
186
|
+
// if urls is not empty, scrape web content and reference it in the prompt
|
|
187
|
+
const webContentPrompt = urls.length > 0 ? await scrapeWebContent(urls) : "";
|
|
188
|
+
const graph = new graphai_1.GraphAI(graphData, { ...vanilla, openAIAgent: openai_agent_1.openAIAgent, textInputAgent: input_agents_1.textInputAgent, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent });
|
|
189
|
+
const prompt = (0, file_1.readTemplatePrompt)(templateName);
|
|
190
|
+
graph.injectValue("messages", [
|
|
191
|
+
{
|
|
192
|
+
role: "system",
|
|
193
|
+
content: `${prompt}\n\n${interactiveClarificationPrompt}${webContentPrompt}`,
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
graph.injectValue("outdir", outDirPath);
|
|
197
|
+
graph.injectValue("fileName", filename);
|
|
198
|
+
console.log(`${agentHeader} Hi! What topic would you like me to generate about?\n`);
|
|
199
|
+
await graph.run();
|
|
200
|
+
};
|
|
201
|
+
exports.createMulmoScriptWithInteractive = createMulmoScriptWithInteractive;
|