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.
- package/README.md +108 -12
- package/assets/html/chart.html +47 -0
- package/assets/html/mermaid.html +63 -0
- package/assets/templates/business.json +60 -6
- package/assets/templates/children_book.json +1 -3
- package/assets/templates/coding.json +103 -0
- package/lib/actions/audio.d.ts +1 -1
- package/lib/actions/audio.js +52 -81
- package/lib/actions/images.d.ts +1 -1
- package/lib/actions/images.js +48 -80
- package/lib/actions/movie.d.ts +1 -1
- package/lib/actions/movie.js +76 -76
- package/lib/actions/translate.d.ts +1 -1
- package/lib/actions/translate.js +16 -52
- package/lib/agents/add_bgm_agent.d.ts +1 -1
- package/lib/agents/add_bgm_agent.js +10 -14
- package/lib/agents/combine_audio_files_agent.d.ts +1 -1
- package/lib/agents/combine_audio_files_agent.js +40 -30
- package/lib/agents/image_google_agent.d.ts +1 -1
- package/lib/agents/image_google_agent.js +8 -11
- package/lib/agents/image_openai_agent.js +7 -14
- package/lib/agents/index.d.ts +8 -8
- package/lib/agents/index.js +13 -30
- package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
- package/lib/agents/mulmo_prompts_agent.js +7 -11
- package/lib/agents/prompts_data.js +1 -4
- package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
- package/lib/agents/tts_nijivoice_agent.js +8 -12
- package/lib/agents/tts_openai_agent.js +9 -16
- package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
- package/lib/agents/validate_mulmo_script_agent.js +6 -10
- package/lib/cli/args.d.ts +2 -1
- package/lib/cli/args.js +16 -14
- package/lib/cli/cli.js +64 -49
- package/lib/cli/common.js +1 -5
- package/lib/cli/tool-args.d.ts +2 -1
- package/lib/cli/tool-args.js +19 -18
- package/lib/cli/tool-cli.js +32 -51
- package/lib/methods/index.d.ts +3 -3
- package/lib/methods/index.js +3 -19
- package/lib/methods/mulmo_script.d.ts +10 -5
- package/lib/methods/mulmo_script.js +17 -11
- package/lib/methods/mulmo_script_template.d.ts +1 -1
- package/lib/methods/mulmo_script_template.js +4 -10
- package/lib/methods/mulmo_studio_context.d.ts +1 -1
- package/lib/methods/mulmo_studio_context.js +3 -9
- package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
- package/lib/tools/create_mulmo_script_from_url.js +152 -0
- package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
- package/lib/tools/create_mulmo_script_interactively.js +217 -0
- package/lib/tools/dump_prompt.js +5 -8
- package/lib/tools/prompt.js +9 -11
- package/lib/tools/seed_from_url2.d.ts +3 -0
- package/lib/tools/seed_from_url2.js +154 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +1 -17
- package/lib/types/schema.d.ts +433 -71
- package/lib/types/schema.js +126 -111
- package/lib/types/type.d.ts +7 -3
- package/lib/types/type.js +1 -2
- package/lib/utils/const.d.ts +2 -1
- package/lib/utils/const.js +4 -6
- package/lib/utils/file.d.ts +19 -4
- package/lib/utils/file.js +78 -71
- package/lib/utils/filters.d.ts +1 -0
- package/lib/utils/filters.js +47 -26
- package/lib/utils/image_preprocess.d.ts +14 -0
- package/lib/utils/image_preprocess.js +52 -0
- package/lib/utils/inquirer.d.ts +2 -0
- package/lib/utils/inquirer.js +33 -0
- package/lib/utils/markdown.d.ts +3 -1
- package/lib/utils/markdown.js +17 -19
- package/lib/utils/plugins.d.ts +5 -0
- package/lib/utils/plugins.js +11 -0
- package/lib/utils/preprocess.d.ts +24 -7
- package/lib/utils/preprocess.js +8 -14
- package/lib/utils/string.js +4 -10
- package/lib/utils/text_hash.js +2 -39
- package/package.json +12 -6
package/lib/types/schema.js
CHANGED
|
@@ -1,89 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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:
|
|
13
|
-
ttsTexts:
|
|
14
|
-
duration:
|
|
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
|
-
|
|
19
|
-
|
|
15
|
+
export const multiLingualTextsSchema = z.record(langSchema, localizedTextSchema);
|
|
16
|
+
export const speechOptionsSchema = z
|
|
20
17
|
.object({
|
|
21
|
-
speed:
|
|
22
|
-
instruction:
|
|
18
|
+
speed: z.number().optional(), // default: 1.0
|
|
19
|
+
instruction: z.string().optional(),
|
|
23
20
|
})
|
|
24
21
|
.strict();
|
|
25
|
-
const speakerIdSchema =
|
|
26
|
-
const speakerDataSchema =
|
|
22
|
+
const speakerIdSchema = z.string();
|
|
23
|
+
const speakerDataSchema = z
|
|
27
24
|
.object({
|
|
28
|
-
displayName:
|
|
29
|
-
voiceId:
|
|
30
|
-
speechOptions:
|
|
25
|
+
displayName: z.record(langSchema, z.string()),
|
|
26
|
+
voiceId: z.string(),
|
|
27
|
+
speechOptions: speechOptionsSchema.optional(),
|
|
31
28
|
})
|
|
32
29
|
.strict();
|
|
33
|
-
|
|
34
|
-
const mediaSourceSchema =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 =
|
|
41
|
-
const MulmoMarkdownMediaSchema =
|
|
37
|
+
const stringOrStringArray = z.union([z.string(), z.array(z.string())]);
|
|
38
|
+
const MulmoMarkdownMediaSchema = z
|
|
42
39
|
.object({
|
|
43
|
-
type:
|
|
40
|
+
type: z.literal("markdown"),
|
|
44
41
|
markdown: stringOrStringArray,
|
|
45
42
|
})
|
|
46
43
|
.strict();
|
|
47
|
-
const MulmoWebMediaSchema =
|
|
44
|
+
const MulmoWebMediaSchema = z
|
|
48
45
|
.object({
|
|
49
|
-
type:
|
|
46
|
+
type: z.literal("web"),
|
|
50
47
|
url: URLStringSchema,
|
|
51
48
|
})
|
|
52
49
|
.strict();
|
|
53
|
-
const MulmoPdfMediaSchema =
|
|
50
|
+
const MulmoPdfMediaSchema = z
|
|
54
51
|
.object({
|
|
55
|
-
type:
|
|
52
|
+
type: z.literal("pdf"),
|
|
56
53
|
source: mediaSourceSchema,
|
|
57
54
|
})
|
|
58
55
|
.strict();
|
|
59
|
-
const MulmoImageMediaSchema =
|
|
56
|
+
const MulmoImageMediaSchema = z
|
|
60
57
|
.object({
|
|
61
|
-
type:
|
|
58
|
+
type: z.literal("image"),
|
|
62
59
|
source: mediaSourceSchema,
|
|
63
60
|
})
|
|
64
61
|
.strict();
|
|
65
|
-
const MulmoSvgMediaSchema =
|
|
62
|
+
const MulmoSvgMediaSchema = z
|
|
66
63
|
.object({
|
|
67
|
-
type:
|
|
64
|
+
type: z.literal("svg"),
|
|
68
65
|
source: mediaSourceSchema,
|
|
69
66
|
})
|
|
70
67
|
.strict();
|
|
71
|
-
const MulmoMovieMediaSchema =
|
|
68
|
+
const MulmoMovieMediaSchema = z
|
|
72
69
|
.object({
|
|
73
|
-
type:
|
|
70
|
+
type: z.literal("movie"),
|
|
74
71
|
source: mediaSourceSchema,
|
|
75
72
|
})
|
|
76
73
|
.strict();
|
|
77
|
-
const MulmoTextSlideMediaSchema =
|
|
74
|
+
const MulmoTextSlideMediaSchema = z
|
|
78
75
|
.object({
|
|
79
|
-
type:
|
|
80
|
-
slide:
|
|
81
|
-
title:
|
|
82
|
-
bullets:
|
|
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
|
-
|
|
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 =
|
|
108
|
+
const MulmoAudioMediaSchema = z
|
|
96
109
|
.object({
|
|
97
|
-
type:
|
|
110
|
+
type: z.literal("audio"),
|
|
98
111
|
source: mediaSourceSchema,
|
|
99
112
|
})
|
|
100
113
|
.strict();
|
|
101
|
-
const MulmoMidiMediaSchema =
|
|
114
|
+
const MulmoMidiMediaSchema = z
|
|
102
115
|
.object({
|
|
103
|
-
type:
|
|
104
|
-
source:
|
|
116
|
+
type: z.literal("midi"),
|
|
117
|
+
source: z.string(), // TODO: define it later
|
|
105
118
|
})
|
|
106
119
|
.strict();
|
|
107
|
-
|
|
108
|
-
|
|
120
|
+
export const mulmoAudioAssetSchema = z.union([MulmoAudioMediaSchema, MulmoMidiMediaSchema]);
|
|
121
|
+
export const mulmoImageParamsSchema = z
|
|
109
122
|
.object({
|
|
110
|
-
model:
|
|
111
|
-
size:
|
|
112
|
-
style:
|
|
113
|
-
moderation:
|
|
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
|
-
|
|
129
|
+
export const textSlideParamsSchema = z
|
|
117
130
|
.object({
|
|
118
|
-
cssStyles:
|
|
131
|
+
cssStyles: z.array(z.string()),
|
|
119
132
|
})
|
|
120
133
|
.strict();
|
|
121
|
-
|
|
134
|
+
export const videoParamsSchema = z
|
|
122
135
|
.object({
|
|
123
|
-
padding:
|
|
136
|
+
padding: z.number().optional(), // msec
|
|
124
137
|
})
|
|
125
138
|
.strict();
|
|
126
|
-
|
|
139
|
+
export const mulmoBeatSchema = z
|
|
127
140
|
.object({
|
|
128
141
|
speaker: speakerIdSchema,
|
|
129
|
-
text:
|
|
130
|
-
image:
|
|
131
|
-
audio:
|
|
132
|
-
imageParams:
|
|
133
|
-
speechOptions:
|
|
134
|
-
textSlideParams:
|
|
135
|
-
imagePrompt:
|
|
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
|
-
|
|
151
|
+
export const mulmoCanvasDimensionSchema = z
|
|
139
152
|
.object({
|
|
140
|
-
width:
|
|
141
|
-
height:
|
|
153
|
+
width: z.number(),
|
|
154
|
+
height: z.number(),
|
|
142
155
|
})
|
|
143
|
-
.
|
|
156
|
+
.default({ width: 1280, height: 720 });
|
|
144
157
|
// export const voiceMapSchema = z.record(speakerIdSchema, z.string())
|
|
145
|
-
|
|
158
|
+
export const mulmoCastCreditSchema = z
|
|
146
159
|
.object({
|
|
147
|
-
version:
|
|
148
|
-
credit:
|
|
160
|
+
version: z.literal("1.0"),
|
|
161
|
+
credit: z.literal("closing").optional(),
|
|
149
162
|
})
|
|
150
163
|
.strict();
|
|
151
|
-
|
|
164
|
+
export const text2SpeechProviderSchema = z.union([z.literal("openai"), z.literal("nijivoice")]).default("openai");
|
|
165
|
+
export const mulmoSpeechParamsSchema = z
|
|
152
166
|
.object({
|
|
153
|
-
provider:
|
|
154
|
-
speakers:
|
|
167
|
+
provider: text2SpeechProviderSchema, // has default value
|
|
168
|
+
speakers: speakerDictionarySchema,
|
|
155
169
|
})
|
|
156
170
|
.strict();
|
|
157
|
-
|
|
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:
|
|
161
|
-
title:
|
|
162
|
-
description:
|
|
163
|
-
reference:
|
|
164
|
-
lang:
|
|
165
|
-
canvasSize:
|
|
166
|
-
beats:
|
|
167
|
-
speechParams:
|
|
168
|
-
imageParams:
|
|
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:
|
|
185
|
+
provider: text2ImageProviderSchema, // has default value
|
|
171
186
|
})
|
|
172
187
|
.optional(),
|
|
173
188
|
// for textSlides
|
|
174
|
-
textSlideParams:
|
|
175
|
-
videoParams:
|
|
189
|
+
textSlideParams: textSlideParamsSchema.optional(),
|
|
190
|
+
videoParams: videoParamsSchema.optional(),
|
|
176
191
|
// images: ImageInfo[] // generated
|
|
177
|
-
imagePath:
|
|
178
|
-
omitCaptions:
|
|
192
|
+
imagePath: z.string().optional(), // for keynote images movie ??
|
|
193
|
+
omitCaptions: z.boolean().optional(), // default is false
|
|
179
194
|
// for debugging
|
|
180
|
-
__test_invalid__:
|
|
195
|
+
__test_invalid__: z.boolean().optional(),
|
|
181
196
|
})
|
|
182
197
|
.strict();
|
|
183
|
-
|
|
198
|
+
export const mulmoStudioBeatSchema = mulmoBeatSchema
|
|
184
199
|
.extend({
|
|
185
|
-
multiLingualTexts:
|
|
186
|
-
hash:
|
|
187
|
-
duration:
|
|
188
|
-
audioFile:
|
|
189
|
-
imageFile:
|
|
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
|
-
|
|
207
|
+
export const mulmoStudioSchema = z
|
|
193
208
|
.object({
|
|
194
|
-
script:
|
|
195
|
-
filename:
|
|
196
|
-
beats:
|
|
209
|
+
script: mulmoScriptSchema,
|
|
210
|
+
filename: z.string(),
|
|
211
|
+
beats: z.array(mulmoStudioBeatSchema),
|
|
197
212
|
})
|
|
198
213
|
.strict();
|
|
199
|
-
|
|
214
|
+
export const mulmoScriptTemplateSchema = z
|
|
200
215
|
.object({
|
|
201
|
-
title:
|
|
202
|
-
description:
|
|
203
|
-
systemPrompt:
|
|
204
|
-
script:
|
|
216
|
+
title: z.string(),
|
|
217
|
+
description: z.string(),
|
|
218
|
+
systemPrompt: z.string(),
|
|
219
|
+
script: mulmoScriptSchema.optional(),
|
|
205
220
|
})
|
|
206
221
|
.strict();
|
|
207
|
-
|
|
222
|
+
export const urlsSchema = z.array(z.string().url({ message: "Invalid URL format" }));
|
package/lib/types/type.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { langSchema, localizedTextSchema, mulmoBeatSchema, mulmoScriptSchema, mulmoStudioSchema, mulmoStudioBeatSchema, speakerDictionarySchema, mulmoImageParamsSchema, mulmoSpeechParamsSchema, textSlideParamsSchema, speechOptionsSchema,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/lib/utils/const.d.ts
CHANGED
package/lib/utils/const.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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";
|
package/lib/utils/file.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
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
|
-
|
|
13
|
+
GraphAILogger.info(errorMessage);
|
|
18
14
|
process.exit(1);
|
|
19
15
|
}
|
|
20
16
|
return null;
|
|
21
17
|
}
|
|
22
|
-
const scriptData =
|
|
18
|
+
const scriptData = fs.readFileSync(scriptPath, "utf-8");
|
|
23
19
|
const script = JSON.parse(scriptData);
|
|
24
|
-
const parsedPath =
|
|
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
|
|
32
|
-
|
|
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
|
-
|
|
35
|
-
|
|
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
|
-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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 (
|
|
71
|
-
return
|
|
82
|
+
if (path.isAbsolute(basedir)) {
|
|
83
|
+
return path.normalize(basedir);
|
|
72
84
|
}
|
|
73
|
-
return
|
|
85
|
+
return path.resolve(process.cwd(), basedir);
|
|
74
86
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
|
92
|
+
return path.resolve(baseDirPath, file);
|
|
82
93
|
}
|
|
83
|
-
return
|
|
94
|
+
return path.resolve(file);
|
|
84
95
|
};
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
89
|
-
const
|
|
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
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
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 =
|
|
108
|
+
const files = fs.readdirSync(templatesDir);
|
|
100
109
|
return files.map((file) => {
|
|
101
|
-
const template = JSON.parse(
|
|
110
|
+
const template = JSON.parse(fs.readFileSync(path.resolve(templatesDir, file), "utf-8"));
|
|
102
111
|
return {
|
|
103
|
-
...
|
|
112
|
+
...mulmoScriptTemplateSchema.parse(template),
|
|
104
113
|
filename: file.replace(/\.json$/, ""),
|
|
105
114
|
};
|
|
106
115
|
});
|
|
107
116
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
graphai_1.GraphAILogger.info(`writing: ${filePath}`);
|
|
117
|
+
export const writingMessage = (filePath) => {
|
|
118
|
+
GraphAILogger.info(`writing: ${filePath}`);
|
|
111
119
|
};
|
|
112
|
-
exports.writingMessage = writingMessage;
|
package/lib/utils/filters.d.ts
CHANGED