mulmocast 0.0.1 → 0.0.2

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 (79) hide show
  1. package/README.md +108 -12
  2. package/assets/html/chart.html +47 -0
  3. package/assets/html/mermaid.html +63 -0
  4. package/assets/templates/business.json +60 -6
  5. package/assets/templates/children_book.json +1 -3
  6. package/assets/templates/coding.json +103 -0
  7. package/lib/actions/audio.d.ts +1 -1
  8. package/lib/actions/audio.js +52 -81
  9. package/lib/actions/images.d.ts +1 -1
  10. package/lib/actions/images.js +48 -80
  11. package/lib/actions/movie.d.ts +1 -1
  12. package/lib/actions/movie.js +76 -76
  13. package/lib/actions/translate.d.ts +1 -1
  14. package/lib/actions/translate.js +16 -52
  15. package/lib/agents/add_bgm_agent.d.ts +1 -1
  16. package/lib/agents/add_bgm_agent.js +10 -14
  17. package/lib/agents/combine_audio_files_agent.d.ts +1 -1
  18. package/lib/agents/combine_audio_files_agent.js +40 -30
  19. package/lib/agents/image_google_agent.d.ts +1 -1
  20. package/lib/agents/image_google_agent.js +8 -11
  21. package/lib/agents/image_openai_agent.js +7 -14
  22. package/lib/agents/index.d.ts +8 -8
  23. package/lib/agents/index.js +13 -30
  24. package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
  25. package/lib/agents/mulmo_prompts_agent.js +7 -11
  26. package/lib/agents/prompts_data.js +1 -4
  27. package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
  28. package/lib/agents/tts_nijivoice_agent.js +8 -12
  29. package/lib/agents/tts_openai_agent.js +9 -16
  30. package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
  31. package/lib/agents/validate_mulmo_script_agent.js +6 -10
  32. package/lib/cli/args.d.ts +2 -1
  33. package/lib/cli/args.js +16 -14
  34. package/lib/cli/cli.js +64 -49
  35. package/lib/cli/common.js +1 -5
  36. package/lib/cli/tool-args.d.ts +2 -1
  37. package/lib/cli/tool-args.js +19 -18
  38. package/lib/cli/tool-cli.js +32 -51
  39. package/lib/methods/index.d.ts +3 -3
  40. package/lib/methods/index.js +3 -19
  41. package/lib/methods/mulmo_script.d.ts +10 -5
  42. package/lib/methods/mulmo_script.js +17 -11
  43. package/lib/methods/mulmo_script_template.d.ts +1 -1
  44. package/lib/methods/mulmo_script_template.js +4 -10
  45. package/lib/methods/mulmo_studio_context.d.ts +1 -1
  46. package/lib/methods/mulmo_studio_context.js +3 -9
  47. package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
  48. package/lib/tools/create_mulmo_script_from_url.js +152 -0
  49. package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
  50. package/lib/tools/create_mulmo_script_interactively.js +217 -0
  51. package/lib/tools/dump_prompt.js +5 -8
  52. package/lib/tools/prompt.js +9 -11
  53. package/lib/tools/seed_from_url2.d.ts +3 -0
  54. package/lib/tools/seed_from_url2.js +154 -0
  55. package/lib/types/index.d.ts +1 -1
  56. package/lib/types/index.js +1 -17
  57. package/lib/types/schema.d.ts +433 -71
  58. package/lib/types/schema.js +126 -111
  59. package/lib/types/type.d.ts +7 -3
  60. package/lib/types/type.js +1 -2
  61. package/lib/utils/const.d.ts +2 -1
  62. package/lib/utils/const.js +4 -6
  63. package/lib/utils/file.d.ts +19 -4
  64. package/lib/utils/file.js +78 -71
  65. package/lib/utils/filters.d.ts +1 -0
  66. package/lib/utils/filters.js +47 -26
  67. package/lib/utils/image_preprocess.d.ts +14 -0
  68. package/lib/utils/image_preprocess.js +52 -0
  69. package/lib/utils/inquirer.d.ts +2 -0
  70. package/lib/utils/inquirer.js +33 -0
  71. package/lib/utils/markdown.d.ts +3 -1
  72. package/lib/utils/markdown.js +17 -19
  73. package/lib/utils/plugins.d.ts +5 -0
  74. package/lib/utils/plugins.js +11 -0
  75. package/lib/utils/preprocess.d.ts +24 -7
  76. package/lib/utils/preprocess.js +8 -14
  77. package/lib/utils/string.js +4 -10
  78. package/lib/utils/text_hash.js +2 -39
  79. package/package.json +12 -6
@@ -1,89 +1,100 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.urlsSchema = exports.mulmoScriptTemplateSchema = exports.mulmoStudioSchema = exports.mulmoStudioBeatSchema = exports.mulmoScriptSchema = exports.mulmoSpeechParamsSchema = exports.mulmoCastCreditSchema = exports.mulmoDimensionSchema = exports.mulmoBeatSchema = exports.videoParamsSchema = exports.textSlideParamsSchema = exports.mulmoImageParamsSchema = exports.mulmoAudioAssetSchema = exports.mulmoMediaSchema = exports.speakerDictionarySchema = exports.speechOptionsSchema = exports.multiLingualTextsSchema = exports.localizedTextSchema = exports.langSchema = void 0;
4
- const zod_1 = require("zod");
5
- exports.langSchema = zod_1.z.string();
6
- const URLStringSchema = zod_1.z.string().url();
7
- exports.localizedTextSchema = zod_1.z
8
- .object({
9
- text: zod_1.z.string(),
10
- lang: zod_1.z.string(),
1
+ import { z } from "zod";
2
+ export const langSchema = z.string();
3
+ const URLStringSchema = z.string().url();
4
+ export const localizedTextSchema = z
5
+ .object({
6
+ text: z.string(),
7
+ lang: z.string(),
11
8
  // caption: z.string(),
12
- texts: zod_1.z.array(zod_1.z.string()).optional(),
13
- ttsTexts: zod_1.z.array(zod_1.z.string()).optional(),
14
- duration: zod_1.z.number().optional(), // generated // video duration time(ms)
9
+ texts: z.array(z.string()).optional(),
10
+ ttsTexts: z.array(z.string()).optional(),
11
+ duration: z.number().optional(), // generated // video duration time(ms)
15
12
  // filename: z.string().optional(), // generated //
16
13
  })
17
14
  .strict();
18
- exports.multiLingualTextsSchema = zod_1.z.record(exports.langSchema, exports.localizedTextSchema);
19
- exports.speechOptionsSchema = zod_1.z
15
+ export const multiLingualTextsSchema = z.record(langSchema, localizedTextSchema);
16
+ export const speechOptionsSchema = z
20
17
  .object({
21
- speed: zod_1.z.number().optional(), // default: 1.0
22
- instruction: zod_1.z.string().optional(),
18
+ speed: z.number().optional(), // default: 1.0
19
+ instruction: z.string().optional(),
23
20
  })
24
21
  .strict();
25
- const speakerIdSchema = zod_1.z.string();
26
- const speakerDataSchema = zod_1.z
22
+ const speakerIdSchema = z.string();
23
+ const speakerDataSchema = z
27
24
  .object({
28
- displayName: zod_1.z.record(exports.langSchema, zod_1.z.string()),
29
- voiceId: zod_1.z.string(),
30
- speechOptions: exports.speechOptionsSchema.optional(),
25
+ displayName: z.record(langSchema, z.string()),
26
+ voiceId: z.string(),
27
+ speechOptions: speechOptionsSchema.optional(),
31
28
  })
32
29
  .strict();
33
- exports.speakerDictionarySchema = zod_1.z.record(speakerIdSchema, speakerDataSchema);
34
- const mediaSourceSchema = zod_1.z.discriminatedUnion("kind", [
35
- zod_1.z.object({ kind: zod_1.z.literal("url"), url: URLStringSchema }).strict(), // https://example.com/foo.pdf
36
- zod_1.z.object({ kind: zod_1.z.literal("data"), data: zod_1.z.string() }).strict(), // base64
37
- zod_1.z.object({ kind: zod_1.z.literal("path"), path: zod_1.z.string() }).strict(), // foo.pdf
30
+ export const speakerDictionarySchema = z.record(speakerIdSchema, speakerDataSchema);
31
+ const mediaSourceSchema = z.discriminatedUnion("kind", [
32
+ z.object({ kind: z.literal("url"), url: URLStringSchema }).strict(), // https://example.com/foo.pdf
33
+ z.object({ kind: z.literal("data"), data: z.string() }).strict(), // base64
34
+ z.object({ kind: z.literal("path"), path: z.string() }).strict(), // foo.pdf
38
35
  ]);
39
36
  // String is easier for AI, string array is easier for human
40
- const stringOrStringArray = zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]);
41
- const MulmoMarkdownMediaSchema = zod_1.z
37
+ const stringOrStringArray = z.union([z.string(), z.array(z.string())]);
38
+ const MulmoMarkdownMediaSchema = z
42
39
  .object({
43
- type: zod_1.z.literal("markdown"),
40
+ type: z.literal("markdown"),
44
41
  markdown: stringOrStringArray,
45
42
  })
46
43
  .strict();
47
- const MulmoWebMediaSchema = zod_1.z
44
+ const MulmoWebMediaSchema = z
48
45
  .object({
49
- type: zod_1.z.literal("web"),
46
+ type: z.literal("web"),
50
47
  url: URLStringSchema,
51
48
  })
52
49
  .strict();
53
- const MulmoPdfMediaSchema = zod_1.z
50
+ const MulmoPdfMediaSchema = z
54
51
  .object({
55
- type: zod_1.z.literal("pdf"),
52
+ type: z.literal("pdf"),
56
53
  source: mediaSourceSchema,
57
54
  })
58
55
  .strict();
59
- const MulmoImageMediaSchema = zod_1.z
56
+ const MulmoImageMediaSchema = z
60
57
  .object({
61
- type: zod_1.z.literal("image"),
58
+ type: z.literal("image"),
62
59
  source: mediaSourceSchema,
63
60
  })
64
61
  .strict();
65
- const MulmoSvgMediaSchema = zod_1.z
62
+ const MulmoSvgMediaSchema = z
66
63
  .object({
67
- type: zod_1.z.literal("svg"),
64
+ type: z.literal("svg"),
68
65
  source: mediaSourceSchema,
69
66
  })
70
67
  .strict();
71
- const MulmoMovieMediaSchema = zod_1.z
68
+ const MulmoMovieMediaSchema = z
72
69
  .object({
73
- type: zod_1.z.literal("movie"),
70
+ type: z.literal("movie"),
74
71
  source: mediaSourceSchema,
75
72
  })
76
73
  .strict();
77
- const MulmoTextSlideMediaSchema = zod_1.z
74
+ const MulmoTextSlideMediaSchema = z
78
75
  .object({
79
- type: zod_1.z.literal("textSlide"),
80
- slide: zod_1.z.object({
81
- title: zod_1.z.string(),
82
- bullets: zod_1.z.array(zod_1.z.string()),
76
+ type: z.literal("textSlide"),
77
+ slide: z.object({
78
+ title: z.string(),
79
+ bullets: z.array(z.string()),
83
80
  }),
84
81
  })
85
82
  .strict();
86
- exports.mulmoMediaSchema = zod_1.z.union([
83
+ const MulmoChartMediaSchema = z
84
+ .object({
85
+ type: z.literal("chart"),
86
+ title: z.string(),
87
+ chartData: z.record(z.any()),
88
+ })
89
+ .strict();
90
+ const MulmoMermaidMediaSchema = z
91
+ .object({
92
+ type: z.literal("mermaid"),
93
+ title: z.string().describe("The title of the diagram"),
94
+ code: z.string().describe("The code of the mermaid diagram"),
95
+ })
96
+ .strict();
97
+ export const mulmoImageAssetSchema = z.union([
87
98
  MulmoMarkdownMediaSchema,
88
99
  MulmoWebMediaSchema,
89
100
  MulmoPdfMediaSchema,
@@ -91,117 +102,121 @@ exports.mulmoMediaSchema = zod_1.z.union([
91
102
  MulmoSvgMediaSchema,
92
103
  MulmoMovieMediaSchema,
93
104
  MulmoTextSlideMediaSchema,
105
+ MulmoChartMediaSchema,
106
+ MulmoMermaidMediaSchema,
94
107
  ]);
95
- const MulmoAudioMediaSchema = zod_1.z
108
+ const MulmoAudioMediaSchema = z
96
109
  .object({
97
- type: zod_1.z.literal("audio"),
110
+ type: z.literal("audio"),
98
111
  source: mediaSourceSchema,
99
112
  })
100
113
  .strict();
101
- const MulmoMidiMediaSchema = zod_1.z
114
+ const MulmoMidiMediaSchema = z
102
115
  .object({
103
- type: zod_1.z.literal("midi"),
104
- source: zod_1.z.string(), // TODO: define it later
116
+ type: z.literal("midi"),
117
+ source: z.string(), // TODO: define it later
105
118
  })
106
119
  .strict();
107
- exports.mulmoAudioAssetSchema = zod_1.z.union([MulmoAudioMediaSchema, MulmoMidiMediaSchema]);
108
- exports.mulmoImageParamsSchema = zod_1.z
120
+ export const mulmoAudioAssetSchema = z.union([MulmoAudioMediaSchema, MulmoMidiMediaSchema]);
121
+ export const mulmoImageParamsSchema = z
109
122
  .object({
110
- model: zod_1.z.string().optional(), // default: provider specific
111
- size: zod_1.z.string().optional(), // default: provider specific
112
- style: zod_1.z.string().optional(), // optional image style
113
- moderation: zod_1.z.string().optional(), // optional image style
123
+ model: z.string().optional(), // default: provider specific
124
+ size: z.string().optional(), // default: provider specific
125
+ style: z.string().optional(), // optional image style
126
+ moderation: z.string().optional(), // optional image style
114
127
  })
115
128
  .strict();
116
- exports.textSlideParamsSchema = zod_1.z
129
+ export const textSlideParamsSchema = z
117
130
  .object({
118
- cssStyles: zod_1.z.array(zod_1.z.string()),
131
+ cssStyles: z.array(z.string()),
119
132
  })
120
133
  .strict();
121
- exports.videoParamsSchema = zod_1.z
134
+ export const videoParamsSchema = z
122
135
  .object({
123
- padding: zod_1.z.number().optional(), // msec
136
+ padding: z.number().optional(), // msec
124
137
  })
125
138
  .strict();
126
- exports.mulmoBeatSchema = zod_1.z
139
+ export const mulmoBeatSchema = z
127
140
  .object({
128
141
  speaker: speakerIdSchema,
129
- text: zod_1.z.string(),
130
- image: exports.mulmoMediaSchema.optional(),
131
- audio: exports.mulmoAudioAssetSchema.optional(),
132
- imageParams: exports.mulmoImageParamsSchema.optional(), // beat specific parameters
133
- speechOptions: exports.speechOptionsSchema.optional(),
134
- textSlideParams: exports.textSlideParamsSchema.optional(),
135
- imagePrompt: zod_1.z.string().optional(), // specified or inserted by preprocessor
142
+ text: z.string(),
143
+ image: mulmoImageAssetSchema.optional(),
144
+ audio: mulmoAudioAssetSchema.optional(),
145
+ imageParams: mulmoImageParamsSchema.optional(), // beat specific parameters
146
+ speechOptions: speechOptionsSchema.optional(),
147
+ textSlideParams: textSlideParamsSchema.optional(),
148
+ imagePrompt: z.string().optional(), // specified or inserted by preprocessor
136
149
  })
137
150
  .strict();
138
- exports.mulmoDimensionSchema = zod_1.z
151
+ export const mulmoCanvasDimensionSchema = z
139
152
  .object({
140
- width: zod_1.z.number(),
141
- height: zod_1.z.number(),
153
+ width: z.number(),
154
+ height: z.number(),
142
155
  })
143
- .strict();
156
+ .default({ width: 1280, height: 720 });
144
157
  // export const voiceMapSchema = z.record(speakerIdSchema, z.string())
145
- exports.mulmoCastCreditSchema = zod_1.z
158
+ export const mulmoCastCreditSchema = z
146
159
  .object({
147
- version: zod_1.z.literal("1.0"),
148
- credit: zod_1.z.literal("closing").optional(),
160
+ version: z.literal("1.0"),
161
+ credit: z.literal("closing").optional(),
149
162
  })
150
163
  .strict();
151
- exports.mulmoSpeechParamsSchema = zod_1.z
164
+ export const text2SpeechProviderSchema = z.union([z.literal("openai"), z.literal("nijivoice")]).default("openai");
165
+ export const mulmoSpeechParamsSchema = z
152
166
  .object({
153
- provider: zod_1.z.string().optional(),
154
- speakers: exports.speakerDictionarySchema,
167
+ provider: text2SpeechProviderSchema, // has default value
168
+ speakers: speakerDictionarySchema,
155
169
  })
156
170
  .strict();
157
- exports.mulmoScriptSchema = zod_1.z
171
+ export const text2ImageProviderSchema = z.union([z.literal("openai"), z.literal("google")]).default("openai");
172
+ export const mulmoScriptSchema = z
158
173
  .object({
159
174
  // global settings
160
- $mulmocast: exports.mulmoCastCreditSchema,
161
- title: zod_1.z.string(),
162
- description: zod_1.z.string().optional(),
163
- reference: zod_1.z.string().optional(),
164
- lang: exports.langSchema.optional(), // default "en"
165
- canvasSize: exports.mulmoDimensionSchema.optional(),
166
- beats: zod_1.z.array(exports.mulmoBeatSchema),
167
- speechParams: exports.mulmoSpeechParamsSchema,
168
- imageParams: exports.mulmoImageParamsSchema
175
+ $mulmocast: mulmoCastCreditSchema,
176
+ title: z.string(),
177
+ description: z.string().optional(),
178
+ reference: z.string().optional(),
179
+ lang: langSchema.optional(), // default "en"
180
+ canvasSize: mulmoCanvasDimensionSchema, // has default value
181
+ beats: z.array(mulmoBeatSchema),
182
+ speechParams: mulmoSpeechParamsSchema,
183
+ imageParams: mulmoImageParamsSchema
169
184
  .extend({
170
- provider: zod_1.z.string().optional(),
185
+ provider: text2ImageProviderSchema, // has default value
171
186
  })
172
187
  .optional(),
173
188
  // for textSlides
174
- textSlideParams: exports.textSlideParamsSchema.optional(),
175
- videoParams: exports.videoParamsSchema.optional(),
189
+ textSlideParams: textSlideParamsSchema.optional(),
190
+ videoParams: videoParamsSchema.optional(),
176
191
  // images: ImageInfo[] // generated
177
- imagePath: zod_1.z.string().optional(), // for keynote images movie ??
178
- omitCaptions: zod_1.z.boolean().optional(), // default is false
192
+ imagePath: z.string().optional(), // for keynote images movie ??
193
+ omitCaptions: z.boolean().optional(), // default is false
179
194
  // for debugging
180
- __test_invalid__: zod_1.z.boolean().optional(),
195
+ __test_invalid__: z.boolean().optional(),
181
196
  })
182
197
  .strict();
183
- exports.mulmoStudioBeatSchema = exports.mulmoBeatSchema
198
+ export const mulmoStudioBeatSchema = mulmoBeatSchema
184
199
  .extend({
185
- multiLingualTexts: exports.multiLingualTextsSchema.optional(),
186
- hash: zod_1.z.string().optional(),
187
- duration: zod_1.z.number().optional(),
188
- audioFile: zod_1.z.string().optional(),
189
- imageFile: zod_1.z.string().optional(), // path to the image
200
+ multiLingualTexts: multiLingualTextsSchema.optional(),
201
+ hash: z.string().optional(),
202
+ duration: z.number().optional(),
203
+ audioFile: z.string().optional(),
204
+ imageFile: z.string().optional(), // path to the image
190
205
  })
191
206
  .strict();
192
- exports.mulmoStudioSchema = zod_1.z
207
+ export const mulmoStudioSchema = z
193
208
  .object({
194
- script: exports.mulmoScriptSchema,
195
- filename: zod_1.z.string(),
196
- beats: zod_1.z.array(exports.mulmoStudioBeatSchema),
209
+ script: mulmoScriptSchema,
210
+ filename: z.string(),
211
+ beats: z.array(mulmoStudioBeatSchema),
197
212
  })
198
213
  .strict();
199
- exports.mulmoScriptTemplateSchema = zod_1.z
214
+ export const mulmoScriptTemplateSchema = z
200
215
  .object({
201
- title: zod_1.z.string(),
202
- description: zod_1.z.string(),
203
- systemPrompt: zod_1.z.string(),
204
- script: exports.mulmoScriptSchema.optional(),
216
+ title: z.string(),
217
+ description: z.string(),
218
+ systemPrompt: z.string(),
219
+ script: mulmoScriptSchema.optional(),
205
220
  })
206
221
  .strict();
207
- exports.urlsSchema = zod_1.z.array(zod_1.z.string().url({ message: "Invalid URL format" }));
222
+ export const urlsSchema = z.array(z.string().url({ message: "Invalid URL format" }));
@@ -1,4 +1,4 @@
1
- import { langSchema, localizedTextSchema, mulmoBeatSchema, mulmoScriptSchema, mulmoStudioSchema, mulmoStudioBeatSchema, speakerDictionarySchema, mulmoImageParamsSchema, mulmoSpeechParamsSchema, textSlideParamsSchema, speechOptionsSchema, mulmoDimensionSchema, mulmoScriptTemplateSchema } from "./schema";
1
+ import { langSchema, localizedTextSchema, mulmoBeatSchema, mulmoScriptSchema, mulmoStudioSchema, mulmoStudioBeatSchema, speakerDictionarySchema, mulmoImageParamsSchema, mulmoSpeechParamsSchema, textSlideParamsSchema, speechOptionsSchema, mulmoCanvasDimensionSchema, mulmoScriptTemplateSchema, text2ImageProviderSchema, text2SpeechProviderSchema } from "./schema.js";
2
2
  import { z } from "zod";
3
3
  export type LANG = z.infer<typeof langSchema>;
4
4
  export type MulmoBeat = z.infer<typeof mulmoBeatSchema>;
@@ -7,9 +7,11 @@ export type MulmoSpeechParams = z.infer<typeof mulmoSpeechParamsSchema>;
7
7
  export type SpeechOptions = z.infer<typeof speechOptionsSchema>;
8
8
  export type MulmoImageParams = z.infer<typeof mulmoImageParamsSchema>;
9
9
  export type TextSlideParams = z.infer<typeof textSlideParamsSchema>;
10
+ export type Text2ImageProvider = z.infer<typeof text2ImageProviderSchema>;
11
+ export type Text2SpeechProvider = z.infer<typeof text2SpeechProviderSchema>;
10
12
  export type LocalizedText = z.infer<typeof localizedTextSchema>;
11
13
  export type MulmoScript = z.infer<typeof mulmoScriptSchema>;
12
- export type MulmoDimension = z.infer<typeof mulmoDimensionSchema>;
14
+ export type MulmoCanvasDimension = z.infer<typeof mulmoCanvasDimensionSchema>;
13
15
  export type MulmoStudioBeat = z.infer<typeof mulmoStudioBeatSchema>;
14
16
  export type MulmoStudio = z.infer<typeof mulmoStudioSchema>;
15
17
  export type MulmoScriptTemplate = z.infer<typeof mulmoScriptTemplateSchema>;
@@ -19,15 +21,17 @@ export type FileDirs = {
19
21
  baseDirPath: string;
20
22
  outDirPath: string;
21
23
  imageDirPath: string;
22
- scratchpadDirPath: string;
24
+ audioDirPath: string;
23
25
  };
24
26
  export type MulmoStudioContext = {
25
27
  fileDirs: FileDirs;
26
28
  studio: MulmoStudio;
29
+ force: boolean;
27
30
  };
28
31
  export type ScriptingParams = {
29
32
  urls: string[];
30
33
  outDirPath: string;
34
+ cacheDirPath: string;
31
35
  templateName: string;
32
36
  filename: string;
33
37
  };
package/lib/types/type.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,3 +1,4 @@
1
1
  export declare const outDirName = "output";
2
- export declare const scratchpadDirName = "scratchpad";
2
+ export declare const audioDirName = "audio";
3
3
  export declare const imageDirName = "images";
4
+ export declare const cacheDirName = "cache";
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageDirName = exports.scratchpadDirName = exports.outDirName = void 0;
4
- exports.outDirName = "output";
5
- exports.scratchpadDirName = "scratchpad";
6
- exports.imageDirName = "images";
1
+ export const outDirName = "output";
2
+ export const audioDirName = "audio";
3
+ export const imageDirName = "images";
4
+ export const cacheDirName = "cache";
@@ -1,4 +1,4 @@
1
- import { MulmoScript, MulmoScriptTemplate } from "../types";
1
+ import { MulmoScript, MulmoScriptTemplate } from "../types/index.js";
2
2
  export declare function readMulmoScriptFile<T = MulmoScript>(path: string, errorMessage: string): {
3
3
  mulmoData: T;
4
4
  mulmoDataPath: string;
@@ -9,16 +9,31 @@ export declare function readMulmoScriptFile<T = MulmoScript>(path: string): {
9
9
  mulmoDataPath: string;
10
10
  fileName: string;
11
11
  } | null;
12
+ export declare const fetchMulmoScriptFile: (url: string) => Promise<{
13
+ result: boolean;
14
+ status: number;
15
+ script?: undefined;
16
+ } | {
17
+ result: boolean;
18
+ script: any;
19
+ status?: undefined;
20
+ } | {
21
+ result: boolean;
22
+ status: string;
23
+ script?: undefined;
24
+ }>;
12
25
  export declare const getOutputStudioFilePath: (outDirPath: string, fileName: string) => string;
13
- export declare const getOutputBGMFilePath: (outDirPath: string, fileName: string) => string;
26
+ export declare const getAudioSegmentDirPath: (audioDirPath: string, studioFileName: string) => string;
27
+ export declare const getAudioSegmentFilePath: (audioDirPath: string, studioFileName: string, fileName: string) => string;
28
+ export declare const getAudioCombinedFilePath: (audioDirPath: string, fileName: string) => string;
29
+ export declare const getAudioArtifactFilePath: (outDirPath: string, fileName: string) => string;
14
30
  export declare const getOutputVideoFilePath: (outDirPath: string, fileName: string) => string;
15
- export declare const getOutputAudioFilePath: (outDirPath: string, fileName: string) => string;
16
- export declare const getScratchpadFilePath: (scratchpadDirName: string, fileName: string) => string;
17
31
  export declare const getTemplateFilePath: (templateName: string) => string;
18
32
  export declare const mkdir: (dirPath: string) => void;
19
33
  export declare const silentPath: string;
20
34
  export declare const silentLastPath: string;
21
35
  export declare const defaultBGMPath: string;
36
+ export declare const getHTMLFile: (filename: string) => string;
22
37
  export declare const getBaseDirPath: (basedir?: string) => string;
23
38
  export declare const getFullPath: (baseDirPath: string | undefined, file: string) => string;
24
39
  export declare const readTemplatePrompt: (templateName: string) => string;
package/lib/utils/file.js CHANGED
@@ -1,112 +1,119 @@
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.writingMessage = exports.getAvailableTemplates = exports.readTemplatePrompt = exports.getFullPath = exports.getBaseDirPath = exports.defaultBGMPath = exports.silentLastPath = exports.silentPath = exports.mkdir = exports.getTemplateFilePath = exports.getScratchpadFilePath = exports.getOutputAudioFilePath = exports.getOutputVideoFilePath = exports.getOutputBGMFilePath = exports.getOutputStudioFilePath = void 0;
7
- exports.readMulmoScriptFile = readMulmoScriptFile;
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- const graphai_1 = require("graphai");
11
- const mulmo_script_template_1 = require("../methods/mulmo_script_template");
12
- const schema_1 = require("../types/schema");
13
- function readMulmoScriptFile(arg2, errorMessage) {
14
- const scriptPath = path_1.default.resolve(arg2);
15
- if (!fs_1.default.existsSync(scriptPath)) {
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { fileURLToPath } from "url";
4
+ import { GraphAILogger } from "graphai";
5
+ import { MulmoScriptTemplateMethods } from "../methods/mulmo_script_template.js";
6
+ import { mulmoScriptTemplateSchema } from "../types/schema.js";
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ export function readMulmoScriptFile(arg2, errorMessage) {
10
+ const scriptPath = path.resolve(arg2);
11
+ if (!fs.existsSync(scriptPath)) {
16
12
  if (errorMessage) {
17
- console.error(errorMessage);
13
+ GraphAILogger.info(errorMessage);
18
14
  process.exit(1);
19
15
  }
20
16
  return null;
21
17
  }
22
- const scriptData = fs_1.default.readFileSync(scriptPath, "utf-8");
18
+ const scriptData = fs.readFileSync(scriptPath, "utf-8");
23
19
  const script = JSON.parse(scriptData);
24
- const parsedPath = path_1.default.parse(scriptPath);
20
+ const parsedPath = path.parse(scriptPath);
25
21
  return {
26
22
  mulmoData: script,
27
23
  mulmoDataPath: scriptPath,
28
24
  fileName: parsedPath.name,
29
25
  };
30
26
  }
31
- const getOutputStudioFilePath = (outDirPath, fileName) => {
32
- return path_1.default.resolve(outDirPath, fileName + "_studio.json");
27
+ export const fetchMulmoScriptFile = async (url) => {
28
+ try {
29
+ const res = await fetch(url);
30
+ if (!res.ok) {
31
+ return { result: false, status: res.status };
32
+ }
33
+ const script = await res.json();
34
+ return {
35
+ result: true,
36
+ script,
37
+ };
38
+ }
39
+ catch {
40
+ return { result: false, status: "unknown" };
41
+ }
42
+ };
43
+ export const getOutputStudioFilePath = (outDirPath, fileName) => {
44
+ return path.resolve(outDirPath, fileName + "_studio.json");
33
45
  };
34
- exports.getOutputStudioFilePath = getOutputStudioFilePath;
35
- const getOutputBGMFilePath = (outDirPath, fileName) => {
36
- return path_1.default.resolve(outDirPath, fileName + "_bgm.mp3");
46
+ export const getAudioSegmentDirPath = (audioDirPath, studioFileName) => {
47
+ return path.resolve(audioDirPath, studioFileName);
37
48
  };
38
- exports.getOutputBGMFilePath = getOutputBGMFilePath;
39
- const getOutputVideoFilePath = (outDirPath, fileName) => {
40
- return path_1.default.resolve(outDirPath, fileName + ".mp4");
49
+ export const getAudioSegmentFilePath = (audioDirPath, studioFileName, fileName) => {
50
+ return path.resolve(getAudioSegmentDirPath(audioDirPath, studioFileName), fileName + ".mp3");
41
51
  };
42
- exports.getOutputVideoFilePath = getOutputVideoFilePath;
43
- const getOutputAudioFilePath = (outDirPath, fileName) => {
44
- return path_1.default.resolve(outDirPath, fileName + ".mp3");
52
+ export const getAudioCombinedFilePath = (audioDirPath, fileName) => {
53
+ return path.resolve(audioDirPath, fileName, fileName + ".mp3");
45
54
  };
46
- exports.getOutputAudioFilePath = getOutputAudioFilePath;
47
- const getScratchpadFilePath = (scratchpadDirName, fileName) => {
48
- return path_1.default.resolve(scratchpadDirName, fileName + ".mp3");
55
+ export const getAudioArtifactFilePath = (outDirPath, fileName) => {
56
+ return path.resolve(outDirPath, fileName + ".mp3");
49
57
  };
50
- exports.getScratchpadFilePath = getScratchpadFilePath;
51
- const getTemplateFilePath = (templateName) => {
52
- return path_1.default.resolve(__dirname, "../../assets/templates/" + templateName + ".json");
58
+ export const getOutputVideoFilePath = (outDirPath, fileName) => {
59
+ return path.resolve(outDirPath, fileName + ".mp4");
53
60
  };
54
- exports.getTemplateFilePath = getTemplateFilePath;
55
- const mkdir = (dirPath) => {
56
- if (!fs_1.default.existsSync(dirPath)) {
57
- console.info("mkdir: " + dirPath);
58
- fs_1.default.mkdirSync(dirPath, { recursive: true });
61
+ export const getTemplateFilePath = (templateName) => {
62
+ return path.resolve(__dirname, "../../assets/templates/" + templateName + ".json");
63
+ };
64
+ export const mkdir = (dirPath) => {
65
+ if (!fs.existsSync(dirPath)) {
66
+ GraphAILogger.info("mkdir: " + dirPath);
67
+ fs.mkdirSync(dirPath, { recursive: true });
59
68
  }
60
69
  };
61
- exports.mkdir = mkdir;
62
- exports.silentPath = path_1.default.resolve(__dirname, "../../assets/audio/silent300.mp3");
63
- exports.silentLastPath = path_1.default.resolve(__dirname, "../../assets/audio/silent800.mp3");
64
- exports.defaultBGMPath = path_1.default.resolve(__dirname, "../../assets/music/StarsBeyondEx.mp3");
70
+ export const silentPath = path.resolve(__dirname, "../../assets/audio/silent300.mp3");
71
+ export const silentLastPath = path.resolve(__dirname, "../../assets/audio/silent800.mp3");
72
+ export const defaultBGMPath = path.resolve(__dirname, "../../assets/music/StarsBeyondEx.mp3");
73
+ export const getHTMLFile = (filename) => {
74
+ const htmlPath = path.resolve(__dirname, `../../assets/html/${filename}.html`);
75
+ return fs.readFileSync(htmlPath, "utf-8");
76
+ };
65
77
  // for cli
66
- const getBaseDirPath = (basedir) => {
78
+ export const getBaseDirPath = (basedir) => {
67
79
  if (!basedir) {
68
80
  return process.cwd();
69
81
  }
70
- if (path_1.default.isAbsolute(basedir)) {
71
- return path_1.default.normalize(basedir);
82
+ if (path.isAbsolute(basedir)) {
83
+ return path.normalize(basedir);
72
84
  }
73
- return path_1.default.resolve(process.cwd(), basedir);
85
+ return path.resolve(process.cwd(), basedir);
74
86
  };
75
- exports.getBaseDirPath = getBaseDirPath;
76
- const getFullPath = (baseDirPath, file) => {
77
- if (path_1.default.isAbsolute(file)) {
78
- return path_1.default.normalize(file);
87
+ export const getFullPath = (baseDirPath, file) => {
88
+ if (path.isAbsolute(file)) {
89
+ return path.normalize(file);
79
90
  }
80
91
  if (baseDirPath) {
81
- return path_1.default.resolve(baseDirPath, file);
92
+ return path.resolve(baseDirPath, file);
82
93
  }
83
- return path_1.default.resolve(file);
94
+ return path.resolve(file);
84
95
  };
85
- exports.getFullPath = getFullPath;
86
- const readTemplatePrompt = (templateName) => {
87
- const templatePath = (0, exports.getTemplateFilePath)(templateName);
88
- const scriptData = fs_1.default.readFileSync(templatePath, "utf-8");
89
- const template = schema_1.mulmoScriptTemplateSchema.parse(JSON.parse(scriptData));
90
- const prompt = mulmo_script_template_1.MulmoScriptTemplateMethods.getSystemPrompt(template);
96
+ export const readTemplatePrompt = (templateName) => {
97
+ const templatePath = getTemplateFilePath(templateName);
98
+ const scriptData = fs.readFileSync(templatePath, "utf-8");
99
+ const template = mulmoScriptTemplateSchema.parse(JSON.parse(scriptData));
100
+ const prompt = MulmoScriptTemplateMethods.getSystemPrompt(template);
91
101
  return prompt;
92
102
  };
93
- exports.readTemplatePrompt = readTemplatePrompt;
94
- const getAvailableTemplates = () => {
95
- const templatesDir = path_1.default.resolve(__dirname, "../../assets/templates");
96
- if (!fs_1.default.existsSync(templatesDir)) {
103
+ export const getAvailableTemplates = () => {
104
+ const templatesDir = path.resolve(__dirname, "../../assets/templates");
105
+ if (!fs.existsSync(templatesDir)) {
97
106
  return [];
98
107
  }
99
- const files = fs_1.default.readdirSync(templatesDir);
108
+ const files = fs.readdirSync(templatesDir);
100
109
  return files.map((file) => {
101
- const template = JSON.parse(fs_1.default.readFileSync(path_1.default.resolve(templatesDir, file), "utf-8"));
110
+ const template = JSON.parse(fs.readFileSync(path.resolve(templatesDir, file), "utf-8"));
102
111
  return {
103
- ...schema_1.mulmoScriptTemplateSchema.parse(template),
112
+ ...mulmoScriptTemplateSchema.parse(template),
104
113
  filename: file.replace(/\.json$/, ""),
105
114
  };
106
115
  });
107
116
  };
108
- exports.getAvailableTemplates = getAvailableTemplates;
109
- const writingMessage = (filePath) => {
110
- graphai_1.GraphAILogger.info(`writing: ${filePath}`);
117
+ export const writingMessage = (filePath) => {
118
+ GraphAILogger.info(`writing: ${filePath}`);
111
119
  };
112
- exports.writingMessage = writingMessage;
@@ -1,3 +1,4 @@
1
1
  import "dotenv/config";
2
2
  import type { AgentFilterFunction } from "graphai";
3
3
  export declare const fileCacheAgentFilter: AgentFilterFunction;
4
+ export declare const browserlessCacheGenerator: (cacheDir: string) => AgentFilterFunction;