mulmocast-preprocessor 0.1.1 → 0.1.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/lib/cli/commands/summarize.d.ts +1 -0
- package/lib/cli/commands/summarize.js +36 -2
- package/lib/cli/index.js +9 -3
- package/lib/core/summarize/prompts.d.ts +1 -1
- package/lib/core/summarize/prompts.js +26 -2
- package/lib/types/summarize.d.ts +1 -0
- package/lib/types/summarize.js +2 -0
- package/package.json +1 -1
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import { GraphAILogger } from "graphai";
|
|
3
3
|
import { summarizeScript } from "../../core/summarize/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Check if input is a URL
|
|
6
|
+
*/
|
|
7
|
+
const isUrl = (input) => {
|
|
8
|
+
return input.startsWith("http://") || input.startsWith("https://");
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Fetch JSON from URL with timeout
|
|
12
|
+
*/
|
|
13
|
+
const fetchJson = async (url) => {
|
|
14
|
+
const controller = new AbortController();
|
|
15
|
+
const timeout_ms = 30000;
|
|
16
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout_ms);
|
|
17
|
+
try {
|
|
18
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
throw new Error(`HTTP error: ${response.status} ${response.statusText}`);
|
|
21
|
+
}
|
|
22
|
+
return (await response.json());
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
clearTimeout(timeoutId);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Load script from file path or URL
|
|
30
|
+
*/
|
|
31
|
+
const loadScript = async (input) => {
|
|
32
|
+
if (isUrl(input)) {
|
|
33
|
+
return fetchJson(input);
|
|
34
|
+
}
|
|
35
|
+
const content = readFileSync(input, "utf-8");
|
|
36
|
+
return JSON.parse(content);
|
|
37
|
+
};
|
|
4
38
|
/**
|
|
5
39
|
* Summarize command handler - outputs summary to stdout
|
|
6
40
|
*/
|
|
7
41
|
export const summarizeCommand = async (scriptPath, options) => {
|
|
8
42
|
try {
|
|
9
|
-
const
|
|
10
|
-
const script = JSON.parse(content);
|
|
43
|
+
const script = await loadScript(scriptPath);
|
|
11
44
|
const result = await summarizeScript(script, {
|
|
12
45
|
provider: options.provider ?? "openai",
|
|
13
46
|
model: options.model,
|
|
14
47
|
format: options.format ?? "text",
|
|
48
|
+
lang: options.lang,
|
|
15
49
|
targetLengthChars: options.targetLength,
|
|
16
50
|
systemPrompt: options.systemPrompt,
|
|
17
51
|
verbose: options.verbose ?? false,
|
package/lib/cli/index.js
CHANGED
|
@@ -49,7 +49,7 @@ yargs(hideBin(process.argv))
|
|
|
49
49
|
})
|
|
50
50
|
.command("summarize <script>", "Generate a summary of the script content", (builder) => builder
|
|
51
51
|
.positional("script", {
|
|
52
|
-
describe: "Path to MulmoScript JSON file",
|
|
52
|
+
describe: "Path or URL to MulmoScript JSON file",
|
|
53
53
|
type: "string",
|
|
54
54
|
demandOption: true,
|
|
55
55
|
})
|
|
@@ -68,6 +68,11 @@ yargs(hideBin(process.argv))
|
|
|
68
68
|
describe: "Output format (text, markdown)",
|
|
69
69
|
type: "string",
|
|
70
70
|
default: "text",
|
|
71
|
+
})
|
|
72
|
+
.option("lang", {
|
|
73
|
+
alias: "l",
|
|
74
|
+
describe: "Output language (e.g., ja, en, zh)",
|
|
75
|
+
type: "string",
|
|
71
76
|
})
|
|
72
77
|
.option("target-length", {
|
|
73
78
|
describe: "Target summary length in characters",
|
|
@@ -97,6 +102,7 @@ yargs(hideBin(process.argv))
|
|
|
97
102
|
provider: argv.provider,
|
|
98
103
|
model: argv.model,
|
|
99
104
|
format: argv.format,
|
|
105
|
+
lang: argv.lang,
|
|
100
106
|
targetLength: argv.targetLength,
|
|
101
107
|
systemPrompt: argv.systemPrompt,
|
|
102
108
|
verbose: argv.verbose,
|
|
@@ -112,8 +118,8 @@ yargs(hideBin(process.argv))
|
|
|
112
118
|
.example("$0 profiles script.json", "List all available profiles")
|
|
113
119
|
.example("$0 summarize script.json", "Generate text summary with OpenAI")
|
|
114
120
|
.example("$0 summarize script.json --format markdown", "Generate markdown summary")
|
|
115
|
-
.example("$0 summarize script.json
|
|
116
|
-
.example("$0 summarize script.json
|
|
121
|
+
.example("$0 summarize script.json -l ja", "Output summary in Japanese")
|
|
122
|
+
.example("$0 summarize https://example.com/script.json", "Summarize from URL")
|
|
117
123
|
.help()
|
|
118
124
|
.alias("h", "help")
|
|
119
125
|
.version()
|
|
@@ -13,6 +13,6 @@ export declare const DEFAULT_SYSTEM_PROMPT_MARKDOWN = "You are creating a summar
|
|
|
13
13
|
*/
|
|
14
14
|
export declare const buildUserPrompt: (script: ExtendedScript, options: SummarizeOptions) => string;
|
|
15
15
|
/**
|
|
16
|
-
* Get system prompt based on format
|
|
16
|
+
* Get system prompt based on format and language
|
|
17
17
|
*/
|
|
18
18
|
export declare const getSystemPrompt: (options: SummarizeOptions) => string;
|
|
@@ -53,11 +53,35 @@ export const buildUserPrompt = (script, options) => {
|
|
|
53
53
|
return parts.join("\n");
|
|
54
54
|
};
|
|
55
55
|
/**
|
|
56
|
-
* Get
|
|
56
|
+
* Get language name from code
|
|
57
|
+
*/
|
|
58
|
+
const getLanguageName = (langCode) => {
|
|
59
|
+
const langMap = {
|
|
60
|
+
ja: "Japanese",
|
|
61
|
+
en: "English",
|
|
62
|
+
zh: "Chinese",
|
|
63
|
+
ko: "Korean",
|
|
64
|
+
fr: "French",
|
|
65
|
+
de: "German",
|
|
66
|
+
es: "Spanish",
|
|
67
|
+
it: "Italian",
|
|
68
|
+
pt: "Portuguese",
|
|
69
|
+
ru: "Russian",
|
|
70
|
+
};
|
|
71
|
+
return langMap[langCode] || langCode;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Get system prompt based on format and language
|
|
57
75
|
*/
|
|
58
76
|
export const getSystemPrompt = (options) => {
|
|
59
77
|
if (options.systemPrompt) {
|
|
60
78
|
return options.systemPrompt;
|
|
61
79
|
}
|
|
62
|
-
|
|
80
|
+
const basePrompt = options.format === "markdown" ? DEFAULT_SYSTEM_PROMPT_MARKDOWN : DEFAULT_SYSTEM_PROMPT_TEXT;
|
|
81
|
+
// Add language instruction if specified
|
|
82
|
+
if (options.lang) {
|
|
83
|
+
const langName = getLanguageName(options.lang);
|
|
84
|
+
return `${basePrompt}\n- IMPORTANT: Write the output in ${langName}`;
|
|
85
|
+
}
|
|
86
|
+
return basePrompt;
|
|
63
87
|
};
|
package/lib/types/summarize.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare const summarizeOptionsSchema: z.ZodObject<{
|
|
|
34
34
|
text: "text";
|
|
35
35
|
markdown: "markdown";
|
|
36
36
|
}>>;
|
|
37
|
+
lang: z.ZodOptional<z.ZodString>;
|
|
37
38
|
targetLengthChars: z.ZodOptional<z.ZodNumber>;
|
|
38
39
|
systemPrompt: z.ZodOptional<z.ZodString>;
|
|
39
40
|
verbose: z.ZodDefault<z.ZodBoolean>;
|
package/lib/types/summarize.js
CHANGED
|
@@ -18,6 +18,8 @@ export const summarizeOptionsSchema = z.object({
|
|
|
18
18
|
maxTokens: z.number().positive().optional(),
|
|
19
19
|
// Output format
|
|
20
20
|
format: summarizeFormatSchema.default("text"),
|
|
21
|
+
// Output language (e.g., "ja", "en", "fr")
|
|
22
|
+
lang: z.string().optional(),
|
|
21
23
|
// Target length (optional)
|
|
22
24
|
targetLengthChars: z.number().positive().optional(),
|
|
23
25
|
// Custom prompt
|