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
@@ -1,88 +1,67 @@
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]; } };
1
+ import "dotenv/config";
2
+ import { GraphAI } from "graphai";
3
+ import * as agents from "@graphai/vanilla";
4
+ import ttsNijivoiceAgent from "../agents/tts_nijivoice_agent.js";
5
+ import addBGMAgent from "../agents/add_bgm_agent.js";
6
+ import combineAudioFilesAgent from "../agents/combine_audio_files_agent.js";
7
+ import ttsOpenaiAgent from "../agents/tts_openai_agent.js";
8
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
9
+ import { MulmoScriptMethods } from "../methods/index.js";
10
+ import { fileCacheAgentFilter } from "../utils/filters.js";
11
+ import { getAudioArtifactFilePath, getAudioSegmentDirPath, getAudioCombinedFilePath, getOutputStudioFilePath, defaultBGMPath, mkdir, writingMessage, getAudioSegmentFilePath, resolveMediaSource, } from "../utils/file.js";
12
+ import { text2hash } from "../utils/utils.js";
13
+ const { default: __, ...vanillaAgents } = agents;
14
+ // const rion_takanashi_voice = "b9277ce3-ba1c-4f6f-9a65-c05ca102ded0"; // たかなし りおん
15
+ // const ben_carter_voice = "bc06c63f-fef6-43b6-92f7-67f919bd5dae"; // ベン・カーター
16
+ const provider_to_agent = {
17
+ nijivoice: "ttsNijivoiceAgent",
18
+ openai: "ttsOpenaiAgent",
19
+ };
20
+ const getAudioPath = (context, beat, audioFile, audioDirPath) => {
21
+ if (beat.audio?.type === "audio") {
22
+ const path = resolveMediaSource(beat.audio.source, context);
23
+ if (path) {
24
+ return path;
25
+ }
26
+ throw new Error("Invalid audio source");
7
27
  }
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;
28
+ return getAudioSegmentFilePath(audioDirPath, context.studio.filename, audioFile);
29
+ };
30
+ const preprocessor = (namedInputs) => {
31
+ const { beat, index, context, audioDirPath } = namedInputs;
32
+ const studioBeat = context.studio.beats[index];
33
+ const voiceId = context.studio.script.speechParams.speakers[beat.speaker].voiceId;
34
+ const speechOptions = MulmoScriptMethods.getSpeechOptions(context.studio.script, beat);
35
+ const hash_string = `${beat.text}${voiceId}${speechOptions?.instruction ?? ""}${speechOptions?.speed ?? 1.0}`;
36
+ const audioFile = `${context.studio.filename}_${index}_${text2hash(hash_string)}`;
37
+ const audioPath = getAudioPath(context, beat, audioFile, audioDirPath);
38
+ studioBeat.audioFile = audioPath;
39
+ return {
40
+ ttsAgent: provider_to_agent[context.studio.script.speechParams.provider],
41
+ studioBeat,
42
+ voiceId,
43
+ speechOptions,
44
+ audioPath,
33
45
  };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
46
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.audio = void 0;
40
- require("dotenv/config");
41
- const graphai_1 = require("graphai");
42
- const agents = __importStar(require("@graphai/vanilla"));
43
- const tts_nijivoice_agent_1 = __importDefault(require("../agents/tts_nijivoice_agent"));
44
- const add_bgm_agent_1 = __importDefault(require("../agents/add_bgm_agent"));
45
- const combine_audio_files_agent_1 = __importDefault(require("../agents/combine_audio_files_agent"));
46
- const tts_openai_agent_1 = __importDefault(require("../agents/tts_openai_agent"));
47
- const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
48
- const methods_1 = require("../methods");
49
- const filters_1 = require("../utils/filters");
50
- const file_1 = require("../utils/file");
51
- // const rion_takanashi_voice = "b9277ce3-ba1c-4f6f-9a65-c05ca102ded0"; // たかなし りおん
52
- // const ben_carter_voice = "bc06c63f-fef6-43b6-92f7-67f919bd5dae"; // ベン・カーター
53
47
  const graph_tts = {
54
48
  nodes: {
55
49
  preprocessor: {
56
- agent: (namedInputs) => {
57
- const { beat, script, speakers } = namedInputs;
58
- return {
59
- voiceId: speakers[beat.speaker].voiceId,
60
- speechOptions: methods_1.MulmoScriptMethods.getSpeechOptions(script, beat),
61
- };
62
- },
50
+ agent: preprocessor,
63
51
  inputs: {
64
52
  beat: ":beat",
65
- script: ":script",
66
- speakers: ":script.speechParams.speakers",
67
- },
68
- },
69
- ttsAgent: {
70
- agent: (namedInputs) => {
71
- if (namedInputs.provider === "nijivoice") {
72
- return "ttsNijivoiceAgent";
73
- }
74
- return "ttsOpenaiAgent";
75
- },
76
- inputs: {
77
- provider: ":script.speechParams.provider",
53
+ index: ":__mapIndex",
54
+ context: ":context",
55
+ audioDirPath: ":audioDirPath",
78
56
  },
79
57
  },
80
58
  tts: {
81
59
  unless: ":beat.audio",
82
- agent: ":ttsAgent",
60
+ agent: ":preprocessor.ttsAgent",
83
61
  inputs: {
84
62
  text: ":beat.text",
85
- file: "${:scratchpadDirPath}/${:beat.audioFile}.mp3", // TODO
63
+ file: ":preprocessor.audioPath",
64
+ force: ":context.force",
86
65
  },
87
66
  params: {
88
67
  voice: ":preprocessor.voiceId",
@@ -97,13 +76,20 @@ const graph_data = {
97
76
  concurrency: 8,
98
77
  nodes: {
99
78
  context: {},
100
- outputBGMFilePath: {},
101
- outputAudioFilePath: {},
79
+ audioArtifactFilePath: {},
80
+ audioCombinedFilePath: {},
102
81
  outputStudioFilePath: {},
103
- scratchpadDirPath: {},
82
+ audioDirPath: {},
83
+ audioSegmentDirPath: {},
104
84
  map: {
105
85
  agent: "mapAgent",
106
- inputs: { rows: ":context.studio.beats", script: ":context.studio.script", scratchpadDirPath: ":scratchpadDirPath" },
86
+ inputs: {
87
+ rows: ":context.studio.script.beats",
88
+ studio: ":context.studio",
89
+ audioDirPath: ":audioDirPath",
90
+ audioSegmentDirPath: ":audioSegmentDirPath",
91
+ context: ":context",
92
+ },
107
93
  params: {
108
94
  rowKey: "beat",
109
95
  },
@@ -114,8 +100,8 @@ const graph_data = {
114
100
  inputs: {
115
101
  map: ":map",
116
102
  context: ":context",
117
- combinedFileName: ":outputAudioFilePath",
118
- scratchpadDirPath: ":scratchpadDirPath",
103
+ combinedFileName: ":audioCombinedFilePath",
104
+ audioDirPath: ":audioDirPath",
119
105
  },
120
106
  isResult: true,
121
107
  },
@@ -129,12 +115,12 @@ const graph_data = {
129
115
  addBGM: {
130
116
  agent: "addBGMAgent",
131
117
  params: {
132
- musicFile: process.env.PATH_BGM ?? file_1.defaultBGMPath,
118
+ musicFile: process.env.PATH_BGM ?? defaultBGMPath,
133
119
  },
134
120
  inputs: {
135
121
  wait: ":combineFiles",
136
- voiceFile: ":outputAudioFilePath",
137
- outputFile: ":outputBGMFilePath",
122
+ voiceFile: ":audioCombinedFilePath",
123
+ outputFile: ":audioArtifactFilePath",
138
124
  script: ":context.studio.script",
139
125
  },
140
126
  isResult: true,
@@ -154,33 +140,34 @@ const graph_data = {
154
140
  const agentFilters = [
155
141
  {
156
142
  name: "fileCacheAgentFilter",
157
- agent: filters_1.fileCacheAgentFilter,
143
+ agent: fileCacheAgentFilter,
158
144
  nodeIds: ["tts"],
159
145
  },
160
146
  ];
161
- const audio = async (context, concurrency) => {
147
+ export const audio = async (context) => {
162
148
  const { studio, fileDirs } = context;
163
- const { outDirPath, scratchpadDirPath } = fileDirs;
164
- const outputBGMFilePath = (0, file_1.getOutputBGMFilePath)(outDirPath, studio.filename);
165
- const outputAudioFilePath = (0, file_1.getOutputAudioFilePath)(outDirPath, studio.filename);
166
- const outputStudioFilePath = (0, file_1.getOutputStudioFilePath)(outDirPath, studio.filename);
167
- (0, file_1.mkdir)(outDirPath);
168
- (0, file_1.mkdir)(scratchpadDirPath);
169
- graph_data.concurrency = concurrency;
170
- const graph = new graphai_1.GraphAI(graph_data, {
171
- ...agents,
172
- fileWriteAgent: vanilla_node_agents_1.fileWriteAgent,
173
- ttsOpenaiAgent: tts_openai_agent_1.default,
174
- ttsNijivoiceAgent: tts_nijivoice_agent_1.default,
175
- addBGMAgent: add_bgm_agent_1.default,
176
- combineAudioFilesAgent: combine_audio_files_agent_1.default,
149
+ const { outDirPath, audioDirPath } = fileDirs;
150
+ const audioArtifactFilePath = getAudioArtifactFilePath(outDirPath, studio.filename);
151
+ const audioSegmentDirPath = getAudioSegmentDirPath(audioDirPath, studio.filename);
152
+ const audioCombinedFilePath = getAudioCombinedFilePath(audioDirPath, studio.filename);
153
+ const outputStudioFilePath = getOutputStudioFilePath(outDirPath, studio.filename);
154
+ mkdir(outDirPath);
155
+ mkdir(audioSegmentDirPath);
156
+ graph_data.concurrency = MulmoScriptMethods.getSpeechProvider(studio.script) === "nijivoice" ? 1 : 8;
157
+ const graph = new GraphAI(graph_data, {
158
+ ...vanillaAgents,
159
+ fileWriteAgent,
160
+ ttsOpenaiAgent,
161
+ ttsNijivoiceAgent,
162
+ addBGMAgent,
163
+ combineAudioFilesAgent,
177
164
  }, { agentFilters });
178
165
  graph.injectValue("context", context);
179
- graph.injectValue("outputBGMFilePath", outputBGMFilePath);
180
- graph.injectValue("outputAudioFilePath", outputAudioFilePath);
166
+ graph.injectValue("audioArtifactFilePath", audioArtifactFilePath);
167
+ graph.injectValue("audioCombinedFilePath", audioCombinedFilePath);
181
168
  graph.injectValue("outputStudioFilePath", outputStudioFilePath);
182
- graph.injectValue("scratchpadDirPath", scratchpadDirPath);
169
+ graph.injectValue("audioSegmentDirPath", audioSegmentDirPath);
170
+ graph.injectValue("audioDirPath", audioDirPath);
183
171
  await graph.run();
184
- (0, file_1.writingMessage)(outputAudioFilePath);
172
+ writingMessage(audioCombinedFilePath);
185
173
  };
186
- exports.audio = audio;
@@ -1,2 +1,2 @@
1
- import { MulmoStudioContext } from "../types";
1
+ import { MulmoStudioContext } from "../types/index.js";
2
2
  export declare const images: (context: MulmoStudioContext) => Promise<void>;
@@ -1,83 +1,42 @@
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;
1
+ import dotenv from "dotenv";
2
+ import { GraphAI, GraphAILogger } from "graphai";
3
+ import * as agents from "@graphai/vanilla";
4
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
5
+ import { getOutputStudioFilePath, mkdir } from "../utils/file.js";
6
+ import { fileCacheAgentFilter } from "../utils/filters.js";
7
+ import imageGoogleAgent from "../agents/image_google_agent.js";
8
+ import imageOpenaiAgent from "../agents/image_openai_agent.js";
9
+ import { MulmoScriptMethods } from "../methods/index.js";
10
+ import { imagePlugins } from "../utils/image_plugins/index.js";
11
+ const { default: __, ...vanillaAgents } = agents;
12
+ dotenv.config();
13
+ // const openai = new OpenAI();
14
+ import { GoogleAuth } from "google-auth-library";
15
+ const htmlStyle = (script, beat) => {
16
+ return {
17
+ canvasSize: MulmoScriptMethods.getCanvasSize(script),
18
+ textSlideStyle: MulmoScriptMethods.getTextSlideStyle(script, beat),
33
19
  };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
20
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.images = void 0;
40
- const dotenv_1 = __importDefault(require("dotenv"));
41
- const graphai_1 = require("graphai");
42
- const agents = __importStar(require("@graphai/vanilla"));
43
- const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
44
- const file_1 = require("../utils/file");
45
- const filters_1 = require("../utils/filters");
46
- const markdown_1 = require("../utils/markdown");
47
- const image_google_agent_1 = __importDefault(require("../agents/image_google_agent"));
48
- const image_openai_agent_1 = __importDefault(require("../agents/image_openai_agent"));
49
- const methods_1 = require("../methods");
50
- dotenv_1.default.config();
51
- // const openai = new OpenAI();
52
- const google_auth_library_1 = require("google-auth-library");
53
- const preprocess_agent = async (namedInputs) => {
54
- const { context, beat, index, suffix, imageDirPath } = namedInputs;
55
- const imageParams = { ...context.studio.script.imageParams, ...beat.imageParams };
56
- const prompt = (beat.imagePrompt || beat.text) + "\n" + (imageParams.style || "");
21
+ const imagePreprocessAgent = async (namedInputs) => {
22
+ const { context, beat, index, suffix, imageDirPath, imageAgentInfo } = namedInputs;
23
+ const imageParams = { ...imageAgentInfo.imageParams, ...beat.imageParams };
57
24
  const imagePath = `${imageDirPath}/${context.studio.filename}/${index}${suffix}.png`;
58
- const aspectRatio = methods_1.MulmoScriptMethods.getAspectRatio(context.studio.script);
25
+ const returnValue = {
26
+ aspectRatio: MulmoScriptMethods.getAspectRatio(context.studio.script),
27
+ imageParams,
28
+ };
59
29
  if (beat.image) {
60
- if (beat.image.type === "textSlide") {
61
- const slide = beat.image.slide;
62
- const markdown = `# ${slide.title}` + slide.bullets.map((text) => `- ${text}`).join("\n");
63
- await (0, markdown_1.convertMarkdownToImage)(markdown, methods_1.MulmoScriptMethods.getTextSlideStyle(context.studio.script, beat), imagePath);
64
- }
65
- else if (beat.image.type === "markdown") {
66
- const markdown = Array.isArray(beat.image.markdown) ? beat.image.markdown.join("\n") : beat.image.markdown;
67
- await (0, markdown_1.convertMarkdownToImage)(markdown, methods_1.MulmoScriptMethods.getTextSlideStyle(context.studio.script, beat), imagePath);
68
- }
69
- else if (beat.image.type === "image") {
70
- if (beat.image.source.kind === "url") {
71
- // undefined prompt indicates "no need to generate image"
72
- return { path: beat.image.source.url, prompt: undefined, imageParams, aspectRatio };
73
- }
74
- else if (beat.image.source.kind === "path") {
75
- const path = methods_1.MulmoStudioContextMethods.resolveAssetPath(context, beat.image.source.path);
76
- return { path, prompt: undefined, imageParams, aspectRatio };
77
- }
30
+ const plugin = imagePlugins.find((plugin) => plugin.imageType === beat?.image?.type);
31
+ if (plugin) {
32
+ const processorParams = { beat, context, imagePath, ...htmlStyle(context.studio.script, beat) };
33
+ const path = await plugin.process(processorParams);
34
+ // undefined prompt indicates that image generation is not needed
35
+ return { path, ...returnValue };
78
36
  }
79
37
  }
80
- return { path: imagePath, prompt, imageParams, aspectRatio };
38
+ const prompt = (beat.imagePrompt || beat.text) + "\n" + (imageParams.style || "");
39
+ return { path: imagePath, prompt, ...returnValue };
81
40
  };
82
41
  const graph_data = {
83
42
  version: 0.5,
@@ -85,11 +44,11 @@ const graph_data = {
85
44
  nodes: {
86
45
  context: {},
87
46
  imageDirPath: {},
88
- text2imageAgent: {},
47
+ imageAgentInfo: {},
89
48
  outputStudioFilePath: {},
90
49
  map: {
91
50
  agent: "mapAgent",
92
- inputs: { rows: ":context.studio.beats", context: ":context", text2imageAgent: ":text2imageAgent", imageDirPath: ":imageDirPath" },
51
+ inputs: { rows: ":context.studio.script.beats", context: ":context", imageAgentInfo: ":imageAgentInfo", imageDirPath: ":imageDirPath" },
93
52
  isResult: true,
94
53
  params: {
95
54
  rowKey: "beat",
@@ -98,18 +57,19 @@ const graph_data = {
98
57
  graph: {
99
58
  nodes: {
100
59
  preprocessor: {
101
- agent: preprocess_agent,
60
+ agent: imagePreprocessAgent,
102
61
  inputs: {
103
62
  context: ":context",
104
63
  beat: ":beat",
105
64
  index: ":__mapIndex",
106
65
  suffix: "p",
107
66
  imageDirPath: ":imageDirPath",
67
+ imageAgentInfo: ":imageAgentInfo",
108
68
  },
109
69
  },
110
70
  imageGenerator: {
111
71
  if: ":preprocessor.prompt",
112
- agent: ":text2imageAgent",
72
+ agent: ":imageAgentInfo.agent",
113
73
  params: {
114
74
  model: ":preprocessor.imageParams.model",
115
75
  size: ":preprocessor.imageParams.size",
@@ -120,6 +80,7 @@ const graph_data = {
120
80
  prompt: ":preprocessor.prompt",
121
81
  file: ":preprocessor.path", // only for fileCacheAgentFilter
122
82
  text: ":preprocessor.prompt", // only for fileCacheAgentFilter
83
+ force: ":context.force",
123
84
  },
124
85
  defaultValue: {},
125
86
  },
@@ -164,30 +125,31 @@ const graph_data = {
164
125
  },
165
126
  };
166
127
  const googleAuth = async () => {
167
- const auth = new google_auth_library_1.GoogleAuth({
128
+ const auth = new GoogleAuth({
168
129
  scopes: ["https://www.googleapis.com/auth/cloud-platform"],
169
130
  });
170
131
  const client = await auth.getClient();
171
132
  const accessToken = await client.getAccessToken();
172
133
  return accessToken.token;
173
134
  };
174
- const images = async (context) => {
135
+ export const images = async (context) => {
175
136
  const { studio, fileDirs } = context;
176
137
  const { outDirPath, imageDirPath } = fileDirs;
177
- (0, file_1.mkdir)(`${imageDirPath}/${studio.filename}`);
138
+ mkdir(`${imageDirPath}/${studio.filename}`);
178
139
  const agentFilters = [
179
140
  {
180
141
  name: "fileCacheAgentFilter",
181
- agent: filters_1.fileCacheAgentFilter,
142
+ agent: fileCacheAgentFilter,
182
143
  nodeIds: ["imageGenerator"],
183
144
  },
184
145
  ];
185
146
  const options = {
186
147
  agentFilters,
187
148
  };
149
+ const imageAgentInfo = MulmoScriptMethods.getImageAgentInfo(studio.script);
188
150
  // We need to get google's auth token only if the google is the text2image provider.
189
- if (methods_1.MulmoScriptMethods.getImageProvider(studio.script) === "google") {
190
- console.log("google was specified as text2image engine");
151
+ if (imageAgentInfo.provider === "google") {
152
+ GraphAILogger.log("google was specified as text2image engine");
191
153
  const token = await googleAuth();
192
154
  options.config = {
193
155
  imageGoogleAgent: {
@@ -196,16 +158,16 @@ const images = async (context) => {
196
158
  },
197
159
  };
198
160
  }
161
+ GraphAILogger.info(`text2image: provider=${imageAgentInfo.provider} model=${imageAgentInfo.imageParams.model}`);
199
162
  const injections = {
200
163
  context,
201
- text2imageAgent: methods_1.MulmoScriptMethods.getText2imageAgent(studio.script),
202
- outputStudioFilePath: (0, file_1.getOutputStudioFilePath)(outDirPath, studio.filename),
164
+ imageAgentInfo,
165
+ outputStudioFilePath: getOutputStudioFilePath(outDirPath, studio.filename),
203
166
  imageDirPath,
204
167
  };
205
- const graph = new graphai_1.GraphAI(graph_data, { ...agents, imageGoogleAgent: image_google_agent_1.default, imageOpenaiAgent: image_openai_agent_1.default, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent }, options);
168
+ const graph = new GraphAI(graph_data, { ...vanillaAgents, imageGoogleAgent, imageOpenaiAgent, fileWriteAgent }, options);
206
169
  Object.keys(injections).forEach((key) => {
207
170
  graph.injectValue(key, injections[key]);
208
171
  });
209
172
  await graph.run();
210
173
  };
211
- exports.images = images;
@@ -0,0 +1,5 @@
1
+ export * from "./audio.js";
2
+ export * from "./images.js";
3
+ export * from "./movie.js";
4
+ export * from "./pdf.js";
5
+ export * from "./translate.js";
@@ -0,0 +1,5 @@
1
+ export * from "./audio.js";
2
+ export * from "./images.js";
3
+ export * from "./movie.js";
4
+ export * from "./pdf.js";
5
+ export * from "./translate.js";
@@ -1,2 +1,10 @@
1
- import { MulmoStudioContext } from "../types";
1
+ import { MulmoStudioContext, MulmoCanvasDimension, BeatMediaType } from "../types/index.js";
2
+ export declare const getVideoPart: (inputIndex: number, mediaType: BeatMediaType, duration: number, canvasInfo: MulmoCanvasDimension) => {
3
+ videoId: string;
4
+ videoPart: string;
5
+ };
6
+ export declare const getAudioPart: (inputIndex: number, duration: number, delay: number) => {
7
+ audioId: string;
8
+ audioPart: string;
9
+ };
2
10
  export declare const movie: (context: MulmoStudioContext) => Promise<void>;