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
@@ -0,0 +1,152 @@
1
+ import "dotenv/config";
2
+ import { GraphAI } from "graphai";
3
+ import { openAIAgent } from "@graphai/openai_agent";
4
+ import * as agents from "@graphai/vanilla";
5
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
6
+ import { browserlessAgent } from "@graphai/browserless_agent";
7
+ import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent.js";
8
+ import { readTemplatePrompt, mkdir, writingMessage } from "../utils/file.js";
9
+ import { browserlessCacheGenerator } from "../utils/filters.js";
10
+ import { urlsSchema } from "../types/schema.js";
11
+ import { cliLoadingPlugin } from "../utils/plugins.js";
12
+ const { default: __, ...vanillaAgents } = agents;
13
+ const graphData = {
14
+ version: 0.5,
15
+ // Execute sequentially because the free version of browserless API doesn't support concurrent execution.
16
+ concurrency: 1,
17
+ nodes: {
18
+ urls: {
19
+ value: [],
20
+ },
21
+ prompt: {
22
+ value: "",
23
+ },
24
+ outdir: {
25
+ value: "",
26
+ },
27
+ fileName: {
28
+ value: "",
29
+ },
30
+ // get the text content of the urls
31
+ fetchResults: {
32
+ agent: "mapAgent",
33
+ inputs: {
34
+ rows: ":urls",
35
+ },
36
+ params: {
37
+ compositeResult: true,
38
+ },
39
+ graph: {
40
+ nodes: {
41
+ fetcher: {
42
+ agent: "browserlessAgent",
43
+ inputs: {
44
+ url: ":row",
45
+ text_content: true,
46
+ },
47
+ },
48
+ copyAgent: {
49
+ agent: "copyAgent",
50
+ inputs: {
51
+ text: '{ url: "${:row}", text: "${:fetcher.text}" }',
52
+ },
53
+ params: {
54
+ namedKey: "text",
55
+ },
56
+ isResult: true,
57
+ },
58
+ },
59
+ },
60
+ },
61
+ // join the text content
62
+ sourceText: {
63
+ agent: "arrayJoinAgent",
64
+ inputs: {
65
+ array: ":fetchResults.copyAgent",
66
+ },
67
+ params: {
68
+ separator: ",",
69
+ },
70
+ },
71
+ // generate the mulmo script
72
+ mulmoScript: {
73
+ agent: "nestedAgent",
74
+ inputs: {
75
+ sourceText: ":sourceText",
76
+ prompt: ":prompt",
77
+ },
78
+ graph: {
79
+ loop: {
80
+ // If the script is not valid and the counter is less than 3, continue the loop
81
+ while: ":continue",
82
+ },
83
+ nodes: {
84
+ counter: {
85
+ value: 0,
86
+ update: ":counter.add(1)",
87
+ },
88
+ openAIAgent: {
89
+ agent: "openAIAgent",
90
+ inputs: {
91
+ model: "gpt-4o",
92
+ system: ":prompt",
93
+ prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
94
+ },
95
+ },
96
+ validateMulmoScriptAgent: {
97
+ agent: "validateMulmoScriptAgent",
98
+ inputs: {
99
+ text: ":openAIAgent.text.codeBlock()",
100
+ },
101
+ isResult: true,
102
+ },
103
+ continue: {
104
+ agent: ({ isValid, counter }) => {
105
+ return !isValid && counter < 3;
106
+ },
107
+ inputs: {
108
+ isValid: ":validateMulmoScriptAgent.isValid",
109
+ counter: ":counter",
110
+ },
111
+ },
112
+ },
113
+ },
114
+ },
115
+ writeJSON: {
116
+ if: ":mulmoScript.validateMulmoScriptAgent.isValid",
117
+ agent: "fileWriteAgent",
118
+ inputs: {
119
+ file: "${:outdir}/${:fileName}-${@now}.json",
120
+ text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
121
+ },
122
+ isResult: true,
123
+ },
124
+ },
125
+ };
126
+ export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath }) => {
127
+ mkdir(outDirPath);
128
+ mkdir(cacheDirPath);
129
+ const parsedUrls = urlsSchema.parse(urls);
130
+ const browserlessCache = browserlessCacheGenerator(cacheDirPath);
131
+ const agentFilters = [
132
+ {
133
+ name: "browserlessCache",
134
+ agent: browserlessCache,
135
+ nodeIds: ["fetcher"],
136
+ },
137
+ ];
138
+ const graph = new GraphAI(graphData, {
139
+ ...vanillaAgents,
140
+ openAIAgent,
141
+ browserlessAgent,
142
+ validateMulmoScriptAgent,
143
+ fileWriteAgent,
144
+ }, { agentFilters });
145
+ graph.injectValue("urls", parsedUrls);
146
+ graph.injectValue("prompt", readTemplatePrompt(templateName));
147
+ graph.injectValue("outdir", outDirPath);
148
+ graph.injectValue("fileName", filename);
149
+ graph.registerCallback(cliLoadingPlugin({ nodeId: "mulmoScript", message: "Generating script..." }));
150
+ const result = await graph.run();
151
+ writingMessage(result?.writeJSON?.path ?? "");
152
+ };
@@ -0,0 +1,3 @@
1
+ import "dotenv/config";
2
+ import { ScriptingParams } from "../types/index.js";
3
+ export declare const createMulmoScriptInteractively: ({ outDirPath, cacheDirPath, filename, templateName, urls, llm_agent, llm_model }: ScriptingParams) => Promise<void>;
@@ -0,0 +1,258 @@
1
+ import "dotenv/config";
2
+ import { GraphAILogger, GraphAI } from "graphai";
3
+ import { textInputAgent } from "@graphai/input_agents";
4
+ import { streamAgentFilterGenerator } from "@graphai/agent_filters";
5
+ import { openAIAgent } from "@graphai/openai_agent";
6
+ import { anthropicAgent } from "@graphai/anthropic_agent";
7
+ import { geminiAgent } from "@graphai/gemini_agent";
8
+ import { groqAgent } from "@graphai/groq_agent";
9
+ import * as agents from "@graphai/vanilla";
10
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
11
+ import { readTemplatePrompt, mkdir } from "../utils/file.js";
12
+ import { browserlessCacheGenerator } from "../utils/filters.js";
13
+ import { browserlessAgent } from "@graphai/browserless_agent";
14
+ import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent.js";
15
+ import { llmPair } from "../utils/utils.js";
16
+ // import { cliLoadingPlugin } from "../utils/plugins.js";
17
+ const { default: __, ...vanillaAgents } = agents;
18
+ const agentHeader = "\x1b[34m● \x1b[0m\x1b[1mAgent\x1b[0m:\x1b[0m";
19
+ const graphDataForScraping = {
20
+ version: 0.5,
21
+ nodes: {
22
+ urls: {
23
+ value: [],
24
+ },
25
+ fetchResults: {
26
+ agent: "mapAgent",
27
+ inputs: {
28
+ rows: ":urls",
29
+ },
30
+ params: {
31
+ compositeResult: true,
32
+ },
33
+ graph: {
34
+ nodes: {
35
+ fetcher: {
36
+ agent: "browserlessAgent",
37
+ inputs: {
38
+ url: ":row",
39
+ text_content: true,
40
+ },
41
+ },
42
+ copyAgent: {
43
+ agent: "copyAgent",
44
+ inputs: {
45
+ text: '{ url: "${:row}", text: "${:fetcher.text}" }',
46
+ },
47
+ params: {
48
+ namedKey: "text",
49
+ },
50
+ isResult: true,
51
+ },
52
+ },
53
+ },
54
+ },
55
+ sourceText: {
56
+ agent: "arrayJoinAgent",
57
+ inputs: {
58
+ array: ":fetchResults.copyAgent",
59
+ },
60
+ params: {
61
+ separator: ",",
62
+ },
63
+ isResult: true,
64
+ },
65
+ },
66
+ };
67
+ const graphData = {
68
+ version: 0.5,
69
+ loop: {
70
+ while: ":continue",
71
+ },
72
+ nodes: {
73
+ llmAgent: {
74
+ update: ":llmAgent",
75
+ },
76
+ llmModel: {
77
+ update: ":llmModel",
78
+ },
79
+ maxTokens: {
80
+ update: ":maxTokens",
81
+ },
82
+ fileName: {
83
+ update: ":fileName",
84
+ },
85
+ outdir: {
86
+ update: ":outdir",
87
+ },
88
+ messages: {
89
+ value: [],
90
+ update: ":reply.chatAgent.messages",
91
+ },
92
+ userInput: {
93
+ agent: "textInputAgent",
94
+ params: {
95
+ message: "You:",
96
+ required: true,
97
+ },
98
+ },
99
+ reply: {
100
+ agent: "nestedAgent",
101
+ inputs: {
102
+ messages: ":messages",
103
+ prompt: ":userInput.text",
104
+ llmAgent: ":llmAgent",
105
+ llmModel: ":llmModel",
106
+ maxTokens: ":maxTokens",
107
+ },
108
+ graph: {
109
+ loop: {
110
+ while: ":continue",
111
+ },
112
+ nodes: {
113
+ counter: {
114
+ value: 0,
115
+ update: ":counter.add(1)",
116
+ },
117
+ chatAgent: {
118
+ agent: ":llmAgent",
119
+ params: {
120
+ model: ":llmModel",
121
+ stream: true,
122
+ max_tokens: ":maxTokens",
123
+ },
124
+ inputs: {
125
+ messages: ":messages",
126
+ prompt: ":prompt",
127
+ },
128
+ isResult: true,
129
+ },
130
+ validateMulmoScriptAgent: {
131
+ agent: "validateMulmoScriptAgent",
132
+ inputs: {
133
+ text: ":chatAgent.text.codeBlock()",
134
+ },
135
+ },
136
+ continue: {
137
+ agent: ({ codeBlock, isValid, counter }) => {
138
+ if (counter >= 3) {
139
+ GraphAILogger.info("\n" + agentHeader + " \x1b[31mFailed to generate a valid script. Please try again.\n");
140
+ return false;
141
+ }
142
+ const result = !!codeBlock && !isValid;
143
+ if (result) {
144
+ GraphAILogger.info("\n" + agentHeader + " Generated script was broken. Retry generate a script.");
145
+ }
146
+ return result;
147
+ },
148
+ inputs: {
149
+ counter: ":counter",
150
+ codeBlock: ":chatAgent.text.codeBlock()",
151
+ isValid: ":validateMulmoScriptAgent.isValid",
152
+ },
153
+ },
154
+ },
155
+ },
156
+ },
157
+ json: {
158
+ agent: "copyAgent",
159
+ inputs: {
160
+ json: ":reply.chatAgent.text.codeBlock().jsonParse()",
161
+ text: ":reply.chatAgent.text.codeBlock()",
162
+ },
163
+ },
164
+ writeJSON: {
165
+ if: ":json.json",
166
+ agent: "fileWriteAgent",
167
+ inputs: {
168
+ file: "${:outdir}/${:fileName}-${@now}.json",
169
+ text: ":json.text",
170
+ },
171
+ },
172
+ writeLog: {
173
+ agent: "consoleAgent",
174
+ inputs: {
175
+ text: "\n\x1b[32m🎉 Script file generated successfully! Type /bye to exit.\x1b[0m\nwriting: ${:writeJSON.path}",
176
+ waiting: ":writeJSON",
177
+ },
178
+ },
179
+ shouldResponse: {
180
+ agent: "compareAgent",
181
+ inputs: {
182
+ array: [[":json.json", "==", undefined], "&&", [":userInput.text", "!=", "/bye"]],
183
+ },
184
+ },
185
+ checkInput: {
186
+ agent: "compareAgent",
187
+ inputs: { array: [":userInput.text", "!=", "/bye"] },
188
+ },
189
+ continue: {
190
+ value: true,
191
+ update: ":checkInput.result",
192
+ },
193
+ },
194
+ };
195
+ const interactiveClarificationPrompt = `If there are any unclear points, be sure to ask the user questions and clarify them before generating the script.`;
196
+ const scrapeWebContent = async (urls, cacheDirPath) => {
197
+ mkdir(cacheDirPath);
198
+ GraphAILogger.info(`${agentHeader} Scraping ${urls.length} URLs...\n`);
199
+ const browserlessCache = browserlessCacheGenerator(cacheDirPath);
200
+ const agentFilters = [
201
+ {
202
+ name: "browserlessCache",
203
+ agent: browserlessCache,
204
+ nodeIds: ["fetcher"],
205
+ },
206
+ ];
207
+ const graph = new GraphAI(graphDataForScraping, { ...vanillaAgents, openAIAgent, textInputAgent, fileWriteAgent, browserlessAgent }, { agentFilters });
208
+ graph.injectValue("urls", urls);
209
+ const result = (await graph.run());
210
+ if (!result?.sourceText?.text) {
211
+ return "";
212
+ }
213
+ const prefixPrompt = "Here is the web content that can be used as reference material for the script:";
214
+ return `\n\n${prefixPrompt}\n${result?.sourceText.text}`;
215
+ };
216
+ export const createMulmoScriptInteractively = async ({ outDirPath, cacheDirPath, filename, templateName, urls, llm_agent, llm_model }) => {
217
+ mkdir(outDirPath);
218
+ // if urls is not empty, scrape web content and reference it in the prompt
219
+ const webContentPrompt = urls.length > 0 ? await scrapeWebContent(urls, cacheDirPath) : "";
220
+ const { agent, model, max_tokens } = llmPair(llm_agent, llm_model);
221
+ GraphAILogger.log({ agent, model, max_tokens });
222
+ const streamAgentFilter = streamAgentFilterGenerator((context, data) => {
223
+ process.stdout.write(String(data));
224
+ });
225
+ const agentFilters = [
226
+ {
227
+ name: "streamAgentFilter",
228
+ agent: streamAgentFilter,
229
+ nodeIds: ["chatAgent"],
230
+ },
231
+ ];
232
+ const graph = new GraphAI(graphData, { ...vanillaAgents, anthropicAgent, geminiAgent, groqAgent, openAIAgent, textInputAgent, fileWriteAgent, validateMulmoScriptAgent }, { agentFilters });
233
+ const prompt = readTemplatePrompt(templateName);
234
+ graph.injectValue("messages", [
235
+ {
236
+ role: "system",
237
+ content: `${prompt}\n\n${interactiveClarificationPrompt}${webContentPrompt}`,
238
+ },
239
+ ]);
240
+ graph.injectValue("outdir", outDirPath);
241
+ graph.injectValue("fileName", filename);
242
+ graph.injectValue("llmAgent", agent);
243
+ graph.injectValue("llmModel", model);
244
+ graph.injectValue("maxTokens", max_tokens);
245
+ graph.registerCallback(({ nodeId, state }) => {
246
+ if (nodeId === "chatAgent") {
247
+ if (state === "executing") {
248
+ process.stdout.write(String("\n" + agentHeader + " "));
249
+ }
250
+ if (state === "completed") {
251
+ process.stdout.write("\n\n");
252
+ }
253
+ }
254
+ });
255
+ // graph.registerCallback(cliLoadingPlugin({ nodeId: "reply", message: "Loading..." }));
256
+ GraphAILogger.info(`${agentHeader} Hi! What topic would you like me to generate about?\n`);
257
+ await graph.run();
258
+ };
@@ -1,9 +1,6 @@
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);
1
+ import { GraphAILogger } from "graphai";
2
+ import { readTemplatePrompt } from "../utils/file.js";
3
+ export const dumpPromptFromTemplate = async ({ templateName }) => {
4
+ const prompt = readTemplatePrompt(templateName);
5
+ GraphAILogger.info(prompt);
8
6
  };
9
- exports.dumpPromptFromTemplate = dumpPromptFromTemplate;
@@ -1,20 +1,18 @@
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"));
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ const __filename = fileURLToPath(import.meta.url);
5
+ const __dirname = path.dirname(__filename);
8
6
  const main = async () => {
9
- const basePath = path_1.default.resolve(__dirname + "/../../prompts/");
7
+ const basePath = path.resolve(__dirname, "../../prompts/");
10
8
  const ret = {};
11
- fs_1.default.readdirSync(basePath).map((file) => {
9
+ fs.readdirSync(basePath).map((file) => {
12
10
  const key = file.split(".")[0];
13
- const content = fs_1.default.readFileSync(path_1.default.resolve(basePath) + "/" + file, "utf-8");
11
+ const content = fs.readFileSync(path.resolve(basePath, file), "utf-8");
14
12
  ret[key] = content;
15
13
  });
16
14
  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");
15
+ fs.writeFileSync(path.resolve(__dirname, "../../src/agents/prompts_data.ts"), code, "utf8");
18
16
  // console.log(hoge);
19
17
  };
20
18
  main();
@@ -0,0 +1,3 @@
1
+ import "dotenv/config";
2
+ import { ScriptingParams } from "../types";
3
+ export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename, cacheDirPath }: ScriptingParams) => Promise<void>;
@@ -0,0 +1,154 @@
1
+ import "dotenv/config";
2
+ import { GraphAI } from "graphai";
3
+ import { openAIAgent } from "@graphai/openai_agent";
4
+ import * as vanilla from "@graphai/vanilla";
5
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
6
+ import { browserlessAgent } from "@graphai/browserless_agent";
7
+ import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent";
8
+ import { readTemplatePrompt, mkdir, writingMessage } from "../utils/file";
9
+ import { browserlessCacheGenerator } from "../utils/filters";
10
+ import { urlsSchema } from "../types/schema";
11
+ import { cliLoadingPlugin } from "../utils/plugins";
12
+ const graphData = {
13
+ version: 0.5,
14
+ // Execute sequentially because the free version of browserless API doesn't support concurrent execution.
15
+ concurrency: 1,
16
+ nodes: {
17
+ urls: {
18
+ value: [],
19
+ },
20
+ prompt: {
21
+ value: "",
22
+ },
23
+ outdir: {
24
+ value: "",
25
+ },
26
+ fileName: {
27
+ value: "",
28
+ },
29
+ fetchGraph: {
30
+ value: {
31
+ nodes: {
32
+ fetcher: {
33
+ agent: "browserlessAgent",
34
+ inputs: {
35
+ url: ":row",
36
+ text_content: true,
37
+ },
38
+ },
39
+ copyAgent: {
40
+ agent: "copyAgent",
41
+ inputs: {
42
+ text: '{ url: "${:row}", text: "${:fetcher.text}" }',
43
+ },
44
+ params: {
45
+ namedKey: "text",
46
+ },
47
+ isResult: true,
48
+ },
49
+ },
50
+ },
51
+ },
52
+ // get the text content of the urls
53
+ fetchResults: {
54
+ agent: "mapAgent",
55
+ inputs: {
56
+ rows: ":urls",
57
+ },
58
+ params: {
59
+ compositeResult: true,
60
+ },
61
+ graph: ":fetchGraph",
62
+ },
63
+ // join the text content
64
+ sourceText: {
65
+ agent: "arrayJoinAgent",
66
+ inputs: {
67
+ array: ":fetchResults.copyAgent",
68
+ },
69
+ params: {
70
+ separator: ",",
71
+ },
72
+ },
73
+ // generate the mulmo script
74
+ mulmoScript: {
75
+ agent: "nestedAgent",
76
+ inputs: {
77
+ sourceText: ":sourceText",
78
+ prompt: ":prompt",
79
+ },
80
+ graph: {
81
+ loop: {
82
+ // If the script is not valid and the counter is less than 3, continue the loop
83
+ while: ":continue",
84
+ },
85
+ nodes: {
86
+ counter: {
87
+ value: 0,
88
+ update: ":counter.add(1)",
89
+ },
90
+ openAIAgent: {
91
+ agent: "openAIAgent",
92
+ inputs: {
93
+ model: "gpt-4o",
94
+ system: ":prompt",
95
+ prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
96
+ },
97
+ },
98
+ validateMulmoScriptAgent: {
99
+ agent: "validateMulmoScriptAgent",
100
+ inputs: {
101
+ text: ":openAIAgent.text.codeBlock()",
102
+ },
103
+ isResult: true,
104
+ },
105
+ continue: {
106
+ agent: ({ isValid, counter }) => {
107
+ return !isValid && counter < 3;
108
+ },
109
+ inputs: {
110
+ isValid: ":validateMulmoScriptAgent.isValid",
111
+ counter: ":counter",
112
+ },
113
+ },
114
+ },
115
+ },
116
+ },
117
+ writeJSON: {
118
+ if: ":mulmoScript.validateMulmoScriptAgent.isValid",
119
+ agent: "fileWriteAgent",
120
+ inputs: {
121
+ file: "${:outdir}/${:fileName}-${@now}.json",
122
+ text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
123
+ },
124
+ isResult: true,
125
+ },
126
+ },
127
+ };
128
+ export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath }) => {
129
+ mkdir(outDirPath);
130
+ mkdir(cacheDirPath);
131
+ const parsedUrls = urlsSchema.parse(urls);
132
+ const browserlessCache = browserlessCacheGenerator(cacheDirPath);
133
+ const agentFilters = [
134
+ {
135
+ name: "browserlessCache",
136
+ agent: browserlessCache,
137
+ nodeIds: ["fetcher"],
138
+ },
139
+ ];
140
+ const graph = new GraphAI(graphData, {
141
+ ...vanilla,
142
+ openAIAgent,
143
+ browserlessAgent,
144
+ validateMulmoScriptAgent,
145
+ fileWriteAgent,
146
+ }, { agentFilters });
147
+ graph.injectValue("urls", parsedUrls);
148
+ graph.injectValue("prompt", readTemplatePrompt(templateName));
149
+ graph.injectValue("outdir", outDirPath);
150
+ graph.injectValue("fileName", filename);
151
+ graph.registerCallback(cliLoadingPlugin({ nodeId: "mulmoScript", message: "Generating script..." }));
152
+ const result = await graph.run();
153
+ writingMessage(result?.writeJSON?.path ?? "");
154
+ };
@@ -1 +1,2 @@
1
- export * from "./type";
1
+ export * from "./type.js";
2
+ export * from "./schema.js";
@@ -1,17 +1,2 @@
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("./type"), exports);
1
+ export * from "./type.js";
2
+ export * from "./schema.js";