mulmocast-preprocessor 0.5.0 → 0.5.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/package.json +3 -3
- package/lib/actions/index.d.ts +0 -1
- package/lib/actions/index.js +0 -3
- package/lib/core/filter.d.ts +0 -14
- package/lib/core/filter.js +0 -30
- package/lib/core/llm/index.d.ts +0 -45
- package/lib/core/llm/index.js +0 -144
- package/lib/core/process.d.ts +0 -7
- package/lib/core/process.js +0 -12
- package/lib/core/profiles.d.ts +0 -5
- package/lib/core/profiles.js +0 -38
- package/lib/core/query/index.d.ts +0 -8
- package/lib/core/query/index.js +0 -33
- package/lib/core/query/prompts.d.ts +0 -14
- package/lib/core/query/prompts.js +0 -59
- package/lib/core/summarize/index.d.ts +0 -8
- package/lib/core/summarize/index.js +0 -33
- package/lib/core/summarize/prompts.d.ts +0 -18
- package/lib/core/summarize/prompts.js +0 -70
- package/lib/core/summarize/provider.d.ts +0 -14
- package/lib/core/summarize/provider.js +0 -43
- package/lib/core/variant.d.ts +0 -6
- package/lib/core/variant.js +0 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mulmocast-preprocessor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Preprocessor for MulmoScript",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@graphai/openai_agent": "^2.0.9",
|
|
41
41
|
"@graphai/vanilla": "^2.0.12",
|
|
42
42
|
"@mulmocast/extended-types": "^0.3.0",
|
|
43
|
-
"@mulmocast/types": "^2.1.
|
|
44
|
-
"dotenv": "^17.
|
|
43
|
+
"@mulmocast/types": "^2.1.38",
|
|
44
|
+
"dotenv": "^17.3.1",
|
|
45
45
|
"graphai": "^2.0.16",
|
|
46
46
|
"yargs": "^18.0.0",
|
|
47
47
|
"zod": "^4.3.6"
|
package/lib/actions/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const preprocessorVersion = "0.0.1";
|
package/lib/actions/index.js
DELETED
package/lib/core/filter.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { MulmoScript } from "mulmocast";
|
|
2
|
-
import type { ExtendedScript } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Filter beats by section (preserves meta for chaining)
|
|
5
|
-
*/
|
|
6
|
-
export declare const filterBySection: (script: ExtendedScript, section: string) => ExtendedScript;
|
|
7
|
-
/**
|
|
8
|
-
* Filter beats by tags (preserves meta for chaining)
|
|
9
|
-
*/
|
|
10
|
-
export declare const filterByTags: (script: ExtendedScript, tags: string[]) => ExtendedScript;
|
|
11
|
-
/**
|
|
12
|
-
* Strip variants and meta fields, converting to standard MulmoScript
|
|
13
|
-
*/
|
|
14
|
-
export declare const stripExtendedFields: (script: ExtendedScript) => MulmoScript;
|
package/lib/core/filter.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const stripBeatExtendedFields = (beat) => {
|
|
2
|
-
const { variants: __variants, meta: __meta, ...baseBeat } = beat;
|
|
3
|
-
return baseBeat;
|
|
4
|
-
};
|
|
5
|
-
const filterBeatsToMulmoScript = (script, predicate) => {
|
|
6
|
-
const { outputProfiles: __outputProfiles, ...baseScript } = script;
|
|
7
|
-
return {
|
|
8
|
-
...baseScript,
|
|
9
|
-
beats: script.beats.filter(predicate).map(stripBeatExtendedFields),
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
const filterBeatsPreservingMeta = (script, predicate) => ({
|
|
13
|
-
...script,
|
|
14
|
-
beats: script.beats.filter(predicate),
|
|
15
|
-
});
|
|
16
|
-
/**
|
|
17
|
-
* Filter beats by section (preserves meta for chaining)
|
|
18
|
-
*/
|
|
19
|
-
export const filterBySection = (script, section) => filterBeatsPreservingMeta(script, (beat) => beat.meta?.section === section);
|
|
20
|
-
/**
|
|
21
|
-
* Filter beats by tags (preserves meta for chaining)
|
|
22
|
-
*/
|
|
23
|
-
export const filterByTags = (script, tags) => {
|
|
24
|
-
const tagSet = new Set(tags);
|
|
25
|
-
return filterBeatsPreservingMeta(script, (beat) => (beat.meta?.tags ?? []).some((tag) => tagSet.has(tag)));
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Strip variants and meta fields, converting to standard MulmoScript
|
|
29
|
-
*/
|
|
30
|
-
export const stripExtendedFields = (script) => filterBeatsToMulmoScript(script, () => true);
|
package/lib/core/llm/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { ExtendedScript } from "../../types/index.js";
|
|
2
|
-
import type { LLMProvider } from "../../types/summarize.js";
|
|
3
|
-
/**
|
|
4
|
-
* Base options for LLM operations
|
|
5
|
-
*/
|
|
6
|
-
export interface BaseLLMOptions {
|
|
7
|
-
provider: LLMProvider;
|
|
8
|
-
model?: string;
|
|
9
|
-
temperature?: number;
|
|
10
|
-
maxTokens?: number;
|
|
11
|
-
lang?: string;
|
|
12
|
-
systemPrompt?: string;
|
|
13
|
-
verbose?: boolean;
|
|
14
|
-
section?: string;
|
|
15
|
-
tags?: string[];
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Provider configuration
|
|
19
|
-
*/
|
|
20
|
-
export interface ProviderConfig {
|
|
21
|
-
agentName: string;
|
|
22
|
-
defaultModel: string;
|
|
23
|
-
keyName: string;
|
|
24
|
-
maxTokens?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Get provider configuration
|
|
28
|
-
*/
|
|
29
|
-
export declare const getProviderConfig: (provider: LLMProvider) => ProviderConfig;
|
|
30
|
-
/**
|
|
31
|
-
* Get API key for provider
|
|
32
|
-
*/
|
|
33
|
-
export declare const getProviderApiKey: (provider: LLMProvider) => string | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Filter script based on options (section, tags)
|
|
36
|
-
*/
|
|
37
|
-
export declare const filterScript: (script: ExtendedScript, options: BaseLLMOptions) => ExtendedScript;
|
|
38
|
-
/**
|
|
39
|
-
* Get language name from code
|
|
40
|
-
*/
|
|
41
|
-
export declare const getLanguageName: (langCode: string) => string;
|
|
42
|
-
/**
|
|
43
|
-
* Execute LLM call with GraphAI
|
|
44
|
-
*/
|
|
45
|
-
export declare const executeLLM: (systemPrompt: string, userPrompt: string, options: BaseLLMOptions, verboseMessage?: string) => Promise<string>;
|
package/lib/core/llm/index.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import dotenv from "dotenv";
|
|
2
|
-
import { GraphAI, GraphAILogger } from "graphai";
|
|
3
|
-
import * as vanillaAgents from "@graphai/vanilla";
|
|
4
|
-
import { openAIAgent } from "@graphai/openai_agent";
|
|
5
|
-
import { anthropicAgent } from "@graphai/anthropic_agent";
|
|
6
|
-
import { groqAgent } from "@graphai/groq_agent";
|
|
7
|
-
import { geminiAgent } from "@graphai/gemini_agent";
|
|
8
|
-
import { filterBySection, filterByTags } from "../filter.js";
|
|
9
|
-
dotenv.config({ quiet: true });
|
|
10
|
-
const agents = vanillaAgents.default ?? vanillaAgents;
|
|
11
|
-
const provider2Agent = {
|
|
12
|
-
openai: {
|
|
13
|
-
agentName: "openAIAgent",
|
|
14
|
-
defaultModel: "gpt-4o-mini",
|
|
15
|
-
keyName: "OPENAI_API_KEY",
|
|
16
|
-
maxTokens: 4096,
|
|
17
|
-
},
|
|
18
|
-
anthropic: {
|
|
19
|
-
agentName: "anthropicAgent",
|
|
20
|
-
defaultModel: "claude-sonnet-4-20250514",
|
|
21
|
-
keyName: "ANTHROPIC_API_KEY",
|
|
22
|
-
maxTokens: 4096,
|
|
23
|
-
},
|
|
24
|
-
groq: {
|
|
25
|
-
agentName: "groqAgent",
|
|
26
|
-
defaultModel: "llama-3.1-8b-instant",
|
|
27
|
-
keyName: "GROQ_API_KEY",
|
|
28
|
-
maxTokens: 4096,
|
|
29
|
-
},
|
|
30
|
-
gemini: {
|
|
31
|
-
agentName: "geminiAgent",
|
|
32
|
-
defaultModel: "gemini-2.0-flash",
|
|
33
|
-
keyName: "GEMINI_API_KEY",
|
|
34
|
-
maxTokens: 4096,
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Get provider configuration
|
|
39
|
-
*/
|
|
40
|
-
export const getProviderConfig = (provider) => {
|
|
41
|
-
return provider2Agent[provider];
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Get API key for provider
|
|
45
|
-
*/
|
|
46
|
-
export const getProviderApiKey = (provider) => {
|
|
47
|
-
const config = provider2Agent[provider];
|
|
48
|
-
return process.env[config.keyName];
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Create GraphAI graph for LLM call
|
|
52
|
-
*/
|
|
53
|
-
const createLLMGraph = (agentName) => ({
|
|
54
|
-
version: 0.5,
|
|
55
|
-
nodes: {
|
|
56
|
-
systemPrompt: {},
|
|
57
|
-
userPrompt: {},
|
|
58
|
-
model: {},
|
|
59
|
-
temperature: {},
|
|
60
|
-
maxTokens: {},
|
|
61
|
-
llmCall: {
|
|
62
|
-
agent: agentName,
|
|
63
|
-
inputs: {
|
|
64
|
-
system: ":systemPrompt",
|
|
65
|
-
prompt: ":userPrompt",
|
|
66
|
-
model: ":model",
|
|
67
|
-
temperature: ":temperature",
|
|
68
|
-
max_tokens: ":maxTokens",
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
result: {
|
|
72
|
-
isResult: true,
|
|
73
|
-
agent: "copyAgent",
|
|
74
|
-
inputs: {
|
|
75
|
-
text: ":llmCall.text",
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
/**
|
|
81
|
-
* Filter script based on options (section, tags)
|
|
82
|
-
*/
|
|
83
|
-
export const filterScript = (script, options) => {
|
|
84
|
-
const afterSection = options.section ? filterBySection(script, options.section) : script;
|
|
85
|
-
const afterTags = options.tags && options.tags.length > 0 ? filterByTags(afterSection, options.tags) : afterSection;
|
|
86
|
-
return afterTags;
|
|
87
|
-
};
|
|
88
|
-
/**
|
|
89
|
-
* Get language name from code
|
|
90
|
-
*/
|
|
91
|
-
export const getLanguageName = (langCode) => {
|
|
92
|
-
const langMap = {
|
|
93
|
-
ja: "Japanese",
|
|
94
|
-
en: "English",
|
|
95
|
-
zh: "Chinese",
|
|
96
|
-
ko: "Korean",
|
|
97
|
-
fr: "French",
|
|
98
|
-
de: "German",
|
|
99
|
-
es: "Spanish",
|
|
100
|
-
it: "Italian",
|
|
101
|
-
pt: "Portuguese",
|
|
102
|
-
ru: "Russian",
|
|
103
|
-
};
|
|
104
|
-
return langMap[langCode] || langCode;
|
|
105
|
-
};
|
|
106
|
-
/**
|
|
107
|
-
* Execute LLM call with GraphAI
|
|
108
|
-
*/
|
|
109
|
-
export const executeLLM = async (systemPrompt, userPrompt, options, verboseMessage) => {
|
|
110
|
-
const providerConfig = getProviderConfig(options.provider);
|
|
111
|
-
const apiKey = getProviderApiKey(options.provider);
|
|
112
|
-
if (!apiKey) {
|
|
113
|
-
throw new Error(`API key not found for provider "${options.provider}". Please set the ${providerConfig.keyName} environment variable.`);
|
|
114
|
-
}
|
|
115
|
-
// Build GraphAI config
|
|
116
|
-
const config = {
|
|
117
|
-
openAIAgent: { apiKey: process.env.OPENAI_API_KEY },
|
|
118
|
-
anthropicAgent: { apiKey: process.env.ANTHROPIC_API_KEY },
|
|
119
|
-
groqAgent: { apiKey: process.env.GROQ_API_KEY },
|
|
120
|
-
geminiAgent: { apiKey: process.env.GEMINI_API_KEY },
|
|
121
|
-
};
|
|
122
|
-
// Create GraphAI instance
|
|
123
|
-
const graph = new GraphAI(createLLMGraph(providerConfig.agentName), {
|
|
124
|
-
...agents,
|
|
125
|
-
openAIAgent,
|
|
126
|
-
anthropicAgent,
|
|
127
|
-
groqAgent,
|
|
128
|
-
geminiAgent,
|
|
129
|
-
}, { config });
|
|
130
|
-
if (options.verbose && verboseMessage) {
|
|
131
|
-
GraphAILogger.info(verboseMessage);
|
|
132
|
-
}
|
|
133
|
-
// Inject values
|
|
134
|
-
graph.injectValue("systemPrompt", systemPrompt);
|
|
135
|
-
graph.injectValue("userPrompt", userPrompt);
|
|
136
|
-
graph.injectValue("model", options.model ?? providerConfig.defaultModel);
|
|
137
|
-
graph.injectValue("temperature", options.temperature ?? 0.7);
|
|
138
|
-
graph.injectValue("maxTokens", options.maxTokens ?? providerConfig.maxTokens ?? 2048);
|
|
139
|
-
// Run graph
|
|
140
|
-
const graphResult = await graph.run();
|
|
141
|
-
// Extract text from result node
|
|
142
|
-
const resultNode = graphResult.result;
|
|
143
|
-
return resultNode?.text || "";
|
|
144
|
-
};
|
package/lib/core/process.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { MulmoScript } from "mulmocast";
|
|
2
|
-
import type { ExtendedScript, ProcessOptions } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Main processing function
|
|
5
|
-
* Applies filters first (while meta exists), then profile
|
|
6
|
-
*/
|
|
7
|
-
export declare const processScript: (script: ExtendedScript, options?: ProcessOptions) => MulmoScript;
|
package/lib/core/process.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { applyProfile } from "./variant.js";
|
|
2
|
-
import { filterBySection, filterByTags, stripExtendedFields } from "./filter.js";
|
|
3
|
-
/**
|
|
4
|
-
* Main processing function
|
|
5
|
-
* Applies filters first (while meta exists), then profile
|
|
6
|
-
*/
|
|
7
|
-
export const processScript = (script, options = {}) => {
|
|
8
|
-
const afterSection = options.section ? filterBySection(script, options.section) : script;
|
|
9
|
-
const afterTags = options.tags && options.tags.length > 0 ? filterByTags(afterSection, options.tags) : afterSection;
|
|
10
|
-
const afterProfile = options.profile && options.profile !== "default" ? applyProfile(afterTags, options.profile) : stripExtendedFields(afterTags);
|
|
11
|
-
return afterProfile;
|
|
12
|
-
};
|
package/lib/core/profiles.d.ts
DELETED
package/lib/core/profiles.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get list of available profiles from script
|
|
3
|
-
*/
|
|
4
|
-
export const listProfiles = (script) => {
|
|
5
|
-
const profileNames = new Set(["default"]);
|
|
6
|
-
script.beats
|
|
7
|
-
.filter((beat) => beat.variants)
|
|
8
|
-
.flatMap((beat) => Object.keys(beat.variants))
|
|
9
|
-
.forEach((name) => profileNames.add(name));
|
|
10
|
-
const buildProfileInfo = (profileName) => {
|
|
11
|
-
const outputProfile = script.outputProfiles?.[profileName];
|
|
12
|
-
const { beatCount, skippedCount } = profileName === "default"
|
|
13
|
-
? { beatCount: script.beats.length, skippedCount: 0 }
|
|
14
|
-
: script.beats.reduce((acc, beat) => {
|
|
15
|
-
const isSkipped = beat.variants?.[profileName]?.skip === true;
|
|
16
|
-
return {
|
|
17
|
-
beatCount: acc.beatCount + (isSkipped ? 0 : 1),
|
|
18
|
-
skippedCount: acc.skippedCount + (isSkipped ? 1 : 0),
|
|
19
|
-
};
|
|
20
|
-
}, { beatCount: 0, skippedCount: 0 });
|
|
21
|
-
return {
|
|
22
|
-
name: profileName,
|
|
23
|
-
displayName: outputProfile?.name,
|
|
24
|
-
description: outputProfile?.description,
|
|
25
|
-
beatCount,
|
|
26
|
-
skippedCount,
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
return Array.from(profileNames)
|
|
30
|
-
.map(buildProfileInfo)
|
|
31
|
-
.sort((a, b) => {
|
|
32
|
-
if (a.name === "default")
|
|
33
|
-
return -1;
|
|
34
|
-
if (b.name === "default")
|
|
35
|
-
return 1;
|
|
36
|
-
return a.name.localeCompare(b.name);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ExtendedScript } from "../../types/index.js";
|
|
2
|
-
import type { QueryOptions, QueryResult } from "../../types/query.js";
|
|
3
|
-
/**
|
|
4
|
-
* Main query function - answers a question based on script content
|
|
5
|
-
*/
|
|
6
|
-
export declare const queryScript: (script: ExtendedScript, question: string, options?: Partial<QueryOptions>) => Promise<QueryResult>;
|
|
7
|
-
export type { QueryOptions, QueryResult } from "../../types/query.js";
|
|
8
|
-
export { queryOptionsSchema } from "../../types/query.js";
|
package/lib/core/query/index.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { queryOptionsSchema } from "../../types/query.js";
|
|
2
|
-
import { executeLLM, filterScript } from "../llm/index.js";
|
|
3
|
-
import { buildUserPrompt, getSystemPrompt } from "./prompts.js";
|
|
4
|
-
/**
|
|
5
|
-
* Main query function - answers a question based on script content
|
|
6
|
-
*/
|
|
7
|
-
export const queryScript = async (script, question, options = {}) => {
|
|
8
|
-
// Validate and apply defaults
|
|
9
|
-
const validatedOptions = queryOptionsSchema.parse(options);
|
|
10
|
-
// Filter script if section/tags specified
|
|
11
|
-
const filteredScript = filterScript(script, validatedOptions);
|
|
12
|
-
const scriptTitle = script.title || "Untitled";
|
|
13
|
-
if (filteredScript.beats.length === 0) {
|
|
14
|
-
return {
|
|
15
|
-
answer: "No content available to answer the question.",
|
|
16
|
-
question,
|
|
17
|
-
scriptTitle,
|
|
18
|
-
beatCount: 0,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// Build prompts
|
|
22
|
-
const systemPrompt = getSystemPrompt(validatedOptions);
|
|
23
|
-
const userPrompt = buildUserPrompt(filteredScript, question);
|
|
24
|
-
// Execute LLM
|
|
25
|
-
const answer = await executeLLM(systemPrompt, userPrompt, validatedOptions, `Querying script "${script.title}" with ${validatedOptions.provider}... Beats: ${filteredScript.beats.length}, Question: ${question}`);
|
|
26
|
-
return {
|
|
27
|
-
answer,
|
|
28
|
-
question,
|
|
29
|
-
scriptTitle,
|
|
30
|
-
beatCount: filteredScript.beats.length,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export { queryOptionsSchema } from "../../types/query.js";
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { QueryOptions } from "../../types/query.js";
|
|
2
|
-
import type { ExtendedScript } from "../../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Default system prompt for query
|
|
5
|
-
*/
|
|
6
|
-
export declare const DEFAULT_SYSTEM_PROMPT = "You are answering questions based on the content provided.\n- Answer based ONLY on the information in the provided content\n- If the answer cannot be found in the content, say so clearly\n- Be concise and direct in your answers\n- Do not make up information that is not in the content";
|
|
7
|
-
/**
|
|
8
|
-
* Get system prompt based on options
|
|
9
|
-
*/
|
|
10
|
-
export declare const getSystemPrompt: (options: QueryOptions) => string;
|
|
11
|
-
/**
|
|
12
|
-
* Build user prompt from script and question
|
|
13
|
-
*/
|
|
14
|
-
export declare const buildUserPrompt: (script: ExtendedScript, question: string) => string;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { getLanguageName } from "../llm/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Default system prompt for query
|
|
4
|
-
*/
|
|
5
|
-
export const DEFAULT_SYSTEM_PROMPT = `You are answering questions based on the content provided.
|
|
6
|
-
- Answer based ONLY on the information in the provided content
|
|
7
|
-
- If the answer cannot be found in the content, say so clearly
|
|
8
|
-
- Be concise and direct in your answers
|
|
9
|
-
- Do not make up information that is not in the content`;
|
|
10
|
-
/**
|
|
11
|
-
* Get system prompt based on options
|
|
12
|
-
*/
|
|
13
|
-
export const getSystemPrompt = (options) => {
|
|
14
|
-
if (options.systemPrompt) {
|
|
15
|
-
return options.systemPrompt;
|
|
16
|
-
}
|
|
17
|
-
const basePrompt = DEFAULT_SYSTEM_PROMPT;
|
|
18
|
-
// Add language instruction if specified
|
|
19
|
-
if (options.lang) {
|
|
20
|
-
const langName = getLanguageName(options.lang);
|
|
21
|
-
return `${basePrompt}\n- IMPORTANT: Write the answer in ${langName}`;
|
|
22
|
-
}
|
|
23
|
-
return basePrompt;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Build user prompt from script and question
|
|
27
|
-
*/
|
|
28
|
-
export const buildUserPrompt = (script, question) => {
|
|
29
|
-
const parts = [];
|
|
30
|
-
// Add script metadata
|
|
31
|
-
parts.push(`# Script: ${script.title}`);
|
|
32
|
-
parts.push(`Language: ${script.lang}`);
|
|
33
|
-
parts.push("");
|
|
34
|
-
// Collect all text from beats
|
|
35
|
-
const sections = new Map();
|
|
36
|
-
script.beats.forEach((beat, index) => {
|
|
37
|
-
const text = beat.text || "";
|
|
38
|
-
if (!text.trim())
|
|
39
|
-
return;
|
|
40
|
-
const section = beat.meta?.section || "main";
|
|
41
|
-
if (!sections.has(section)) {
|
|
42
|
-
sections.set(section, []);
|
|
43
|
-
}
|
|
44
|
-
sections.get(section).push(`[${index}] ${text}`);
|
|
45
|
-
});
|
|
46
|
-
// Output by section
|
|
47
|
-
sections.forEach((texts, section) => {
|
|
48
|
-
parts.push(`## Section: ${section}`);
|
|
49
|
-
texts.forEach((t) => parts.push(t));
|
|
50
|
-
parts.push("");
|
|
51
|
-
});
|
|
52
|
-
parts.push("");
|
|
53
|
-
parts.push("---");
|
|
54
|
-
parts.push("");
|
|
55
|
-
parts.push(`Question: ${question}`);
|
|
56
|
-
parts.push("");
|
|
57
|
-
parts.push("Answer:");
|
|
58
|
-
return parts.join("\n");
|
|
59
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ExtendedScript } from "../../types/index.js";
|
|
2
|
-
import type { SummarizeOptions, SummarizeResult } from "../../types/summarize.js";
|
|
3
|
-
/**
|
|
4
|
-
* Main summarize function - generates a summary of the entire script
|
|
5
|
-
*/
|
|
6
|
-
export declare const summarizeScript: (script: ExtendedScript, options?: Partial<SummarizeOptions>) => Promise<SummarizeResult>;
|
|
7
|
-
export type { SummarizeOptions, SummarizeResult, LLMProvider, SummarizeFormat } from "../../types/summarize.js";
|
|
8
|
-
export { summarizeOptionsSchema, llmProviderSchema, summarizeFormatSchema } from "../../types/summarize.js";
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { summarizeOptionsSchema } from "../../types/summarize.js";
|
|
2
|
-
import { executeLLM, filterScript } from "../llm/index.js";
|
|
3
|
-
import { buildUserPrompt, getSystemPrompt } from "./prompts.js";
|
|
4
|
-
/**
|
|
5
|
-
* Main summarize function - generates a summary of the entire script
|
|
6
|
-
*/
|
|
7
|
-
export const summarizeScript = async (script, options = {}) => {
|
|
8
|
-
// Validate and apply defaults
|
|
9
|
-
const validatedOptions = summarizeOptionsSchema.parse(options);
|
|
10
|
-
// Filter script if section/tags specified
|
|
11
|
-
const filteredScript = filterScript(script, validatedOptions);
|
|
12
|
-
const scriptTitle = script.title || "Untitled";
|
|
13
|
-
if (filteredScript.beats.length === 0) {
|
|
14
|
-
return {
|
|
15
|
-
summary: "No content to summarize.",
|
|
16
|
-
format: validatedOptions.format,
|
|
17
|
-
scriptTitle,
|
|
18
|
-
beatCount: 0,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
// Build prompts
|
|
22
|
-
const systemPrompt = getSystemPrompt(validatedOptions);
|
|
23
|
-
const userPrompt = buildUserPrompt(filteredScript, validatedOptions);
|
|
24
|
-
// Execute LLM
|
|
25
|
-
const summary = await executeLLM(systemPrompt, userPrompt, validatedOptions, `Summarizing script "${script.title}" with ${validatedOptions.provider}... Beats: ${filteredScript.beats.length}, Format: ${validatedOptions.format}`);
|
|
26
|
-
return {
|
|
27
|
-
summary,
|
|
28
|
-
format: validatedOptions.format,
|
|
29
|
-
scriptTitle,
|
|
30
|
-
beatCount: filteredScript.beats.length,
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
export { summarizeOptionsSchema, llmProviderSchema, summarizeFormatSchema } from "../../types/summarize.js";
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SummarizeOptions } from "../../types/summarize.js";
|
|
2
|
-
import type { ExtendedScript } from "../../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Default system prompt for text summary
|
|
5
|
-
*/
|
|
6
|
-
export declare const DEFAULT_SYSTEM_PROMPT_TEXT = "You are creating a summary based on the content provided.\n- Extract and explain the actual information and knowledge from the content\n- Do NOT describe what the presentation/script is about (avoid phrases like \"this presentation explains...\" or \"the script describes...\")\n- Write as if you are directly explaining the topic to the reader\n- Be concise and informative\n- Output plain text only";
|
|
7
|
-
/**
|
|
8
|
-
* Default system prompt for markdown summary
|
|
9
|
-
*/
|
|
10
|
-
export declare const DEFAULT_SYSTEM_PROMPT_MARKDOWN = "You are creating a summary based on the content provided.\n- Extract and explain the actual information and knowledge from the content\n- Do NOT describe what the presentation/script is about (avoid phrases like \"this presentation explains...\" or \"the script describes...\")\n- Write as if you are directly explaining the topic to the reader\n- Use markdown formatting (headers, bullet points, etc.)\n- Include a title, key points, and conclusion\n- Output well-formatted markdown";
|
|
11
|
-
/**
|
|
12
|
-
* Build user prompt from entire script
|
|
13
|
-
*/
|
|
14
|
-
export declare const buildUserPrompt: (script: ExtendedScript, options: SummarizeOptions) => string;
|
|
15
|
-
/**
|
|
16
|
-
* Get system prompt based on format and language
|
|
17
|
-
*/
|
|
18
|
-
export declare const getSystemPrompt: (options: SummarizeOptions) => string;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { getLanguageName } from "../llm/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* Default system prompt for text summary
|
|
4
|
-
*/
|
|
5
|
-
export const DEFAULT_SYSTEM_PROMPT_TEXT = `You are creating a summary based on the content provided.
|
|
6
|
-
- Extract and explain the actual information and knowledge from the content
|
|
7
|
-
- Do NOT describe what the presentation/script is about (avoid phrases like "this presentation explains..." or "the script describes...")
|
|
8
|
-
- Write as if you are directly explaining the topic to the reader
|
|
9
|
-
- Be concise and informative
|
|
10
|
-
- Output plain text only`;
|
|
11
|
-
/**
|
|
12
|
-
* Default system prompt for markdown summary
|
|
13
|
-
*/
|
|
14
|
-
export const DEFAULT_SYSTEM_PROMPT_MARKDOWN = `You are creating a summary based on the content provided.
|
|
15
|
-
- Extract and explain the actual information and knowledge from the content
|
|
16
|
-
- Do NOT describe what the presentation/script is about (avoid phrases like "this presentation explains..." or "the script describes...")
|
|
17
|
-
- Write as if you are directly explaining the topic to the reader
|
|
18
|
-
- Use markdown formatting (headers, bullet points, etc.)
|
|
19
|
-
- Include a title, key points, and conclusion
|
|
20
|
-
- Output well-formatted markdown`;
|
|
21
|
-
/**
|
|
22
|
-
* Build user prompt from entire script
|
|
23
|
-
*/
|
|
24
|
-
export const buildUserPrompt = (script, options) => {
|
|
25
|
-
const parts = [];
|
|
26
|
-
// Add script metadata
|
|
27
|
-
parts.push(`# Script: ${script.title}`);
|
|
28
|
-
parts.push(`Language: ${script.lang}`);
|
|
29
|
-
parts.push("");
|
|
30
|
-
// Collect all text from beats
|
|
31
|
-
const sections = new Map();
|
|
32
|
-
script.beats.forEach((beat, index) => {
|
|
33
|
-
const text = beat.text || "";
|
|
34
|
-
if (!text.trim())
|
|
35
|
-
return;
|
|
36
|
-
const section = beat.meta?.section || "main";
|
|
37
|
-
if (!sections.has(section)) {
|
|
38
|
-
sections.set(section, []);
|
|
39
|
-
}
|
|
40
|
-
sections.get(section).push(`[${index}] ${text}`);
|
|
41
|
-
});
|
|
42
|
-
// Output by section
|
|
43
|
-
sections.forEach((texts, section) => {
|
|
44
|
-
parts.push(`## Section: ${section}`);
|
|
45
|
-
texts.forEach((t) => parts.push(t));
|
|
46
|
-
parts.push("");
|
|
47
|
-
});
|
|
48
|
-
// Add target length if specified
|
|
49
|
-
if (options.targetLengthChars) {
|
|
50
|
-
parts.push(`Target summary length: approximately ${options.targetLengthChars} characters`);
|
|
51
|
-
}
|
|
52
|
-
parts.push("");
|
|
53
|
-
parts.push("Based on the above content, explain the topic directly to the reader:");
|
|
54
|
-
return parts.join("\n");
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Get system prompt based on format and language
|
|
58
|
-
*/
|
|
59
|
-
export const getSystemPrompt = (options) => {
|
|
60
|
-
if (options.systemPrompt) {
|
|
61
|
-
return options.systemPrompt;
|
|
62
|
-
}
|
|
63
|
-
const basePrompt = options.format === "markdown" ? DEFAULT_SYSTEM_PROMPT_MARKDOWN : DEFAULT_SYSTEM_PROMPT_TEXT;
|
|
64
|
-
// Add language instruction if specified
|
|
65
|
-
if (options.lang) {
|
|
66
|
-
const langName = getLanguageName(options.lang);
|
|
67
|
-
return `${basePrompt}\n- IMPORTANT: Write the output in ${langName}`;
|
|
68
|
-
}
|
|
69
|
-
return basePrompt;
|
|
70
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ProviderConfig, LLMProvider } from "../../types/summarize.js";
|
|
2
|
-
/**
|
|
3
|
-
* Provider to LLM agent configuration mapping
|
|
4
|
-
* Following mulmocast-cli provider2agent pattern
|
|
5
|
-
*/
|
|
6
|
-
export declare const provider2SummarizeAgent: Record<LLMProvider, ProviderConfig>;
|
|
7
|
-
/**
|
|
8
|
-
* Get provider config by provider name
|
|
9
|
-
*/
|
|
10
|
-
export declare const getProviderConfig: (provider: LLMProvider) => ProviderConfig;
|
|
11
|
-
/**
|
|
12
|
-
* Get API key from environment for provider
|
|
13
|
-
*/
|
|
14
|
-
export declare const getProviderApiKey: (provider: LLMProvider) => string | undefined;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provider to LLM agent configuration mapping
|
|
3
|
-
* Following mulmocast-cli provider2agent pattern
|
|
4
|
-
*/
|
|
5
|
-
export const provider2SummarizeAgent = {
|
|
6
|
-
openai: {
|
|
7
|
-
agentName: "openAIAgent",
|
|
8
|
-
defaultModel: "gpt-4o-mini",
|
|
9
|
-
keyName: "OPENAI_API_KEY",
|
|
10
|
-
maxTokens: 8192,
|
|
11
|
-
},
|
|
12
|
-
anthropic: {
|
|
13
|
-
agentName: "anthropicAgent",
|
|
14
|
-
defaultModel: "claude-sonnet-4-20250514",
|
|
15
|
-
keyName: "ANTHROPIC_API_KEY",
|
|
16
|
-
maxTokens: 8192,
|
|
17
|
-
},
|
|
18
|
-
groq: {
|
|
19
|
-
agentName: "groqAgent",
|
|
20
|
-
defaultModel: "llama-3.1-8b-instant",
|
|
21
|
-
keyName: "GROQ_API_KEY",
|
|
22
|
-
maxTokens: 4096,
|
|
23
|
-
},
|
|
24
|
-
gemini: {
|
|
25
|
-
agentName: "geminiAgent",
|
|
26
|
-
defaultModel: "gemini-2.0-flash",
|
|
27
|
-
keyName: "GEMINI_API_KEY",
|
|
28
|
-
maxTokens: 8192,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Get provider config by provider name
|
|
33
|
-
*/
|
|
34
|
-
export const getProviderConfig = (provider) => {
|
|
35
|
-
return provider2SummarizeAgent[provider];
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Get API key from environment for provider
|
|
39
|
-
*/
|
|
40
|
-
export const getProviderApiKey = (provider) => {
|
|
41
|
-
const config = provider2SummarizeAgent[provider];
|
|
42
|
-
return process.env[config.keyName];
|
|
43
|
-
};
|
package/lib/core/variant.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { MulmoScript } from "mulmocast";
|
|
2
|
-
import type { ExtendedScript } from "../types/index.js";
|
|
3
|
-
/**
|
|
4
|
-
* Apply profile to script and return standard MulmoScript
|
|
5
|
-
*/
|
|
6
|
-
export declare const applyProfile: (script: ExtendedScript, profileName: string) => MulmoScript;
|
package/lib/core/variant.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Apply profile variant to a single beat
|
|
3
|
-
* @returns Processed beat, or null if skip is set
|
|
4
|
-
*/
|
|
5
|
-
const applyVariantToBeat = (beat, profileName) => {
|
|
6
|
-
const variant = beat.variants?.[profileName];
|
|
7
|
-
if (variant?.skip) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
const { variants: __variants, meta: __meta, ...baseBeat } = beat;
|
|
11
|
-
if (!variant) {
|
|
12
|
-
return baseBeat;
|
|
13
|
-
}
|
|
14
|
-
const { skip: __skip, ...overrides } = variant;
|
|
15
|
-
return { ...baseBeat, ...overrides };
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Apply profile to script and return standard MulmoScript
|
|
19
|
-
*/
|
|
20
|
-
export const applyProfile = (script, profileName) => {
|
|
21
|
-
const { outputProfiles: __outputProfiles, ...baseScript } = script;
|
|
22
|
-
return {
|
|
23
|
-
...baseScript,
|
|
24
|
-
beats: script.beats.map((beat) => applyVariantToBeat(beat, profileName)).filter((beat) => beat !== null),
|
|
25
|
-
};
|
|
26
|
-
};
|