mulmocast 0.0.3 → 0.0.4

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/cli.d.ts CHANGED
@@ -14,3 +14,4 @@ export declare const getFileObject: (_args: {
14
14
  outputStudioFilePath: string;
15
15
  fileName: string;
16
16
  };
17
+ export declare const main: () => Promise<void>;
package/lib/cli/cli.js CHANGED
@@ -2,12 +2,11 @@
2
2
  import "dotenv/config";
3
3
  import fs from "fs";
4
4
  import path from "path";
5
- import { fileURLToPath } from "url";
6
5
  import { GraphAILogger } from "graphai";
7
6
  import { getArgs } from "./args.js";
8
7
  import { createOrUpdateStudioData } from "../utils/preprocess.js";
9
8
  import { outDirName, imageDirName, audioDirName } from "../utils/const.js";
10
- import { translate, audio, images, movie, pdf } from "../../src/actions/index.js";
9
+ import { translate, audio, images, movie, pdf } from "../actions/index.js";
11
10
  import { getBaseDirPath, getFullPath, readMulmoScriptFile, fetchMulmoScriptFile, getOutputStudioFilePath } from "../utils/file.js";
12
11
  import { isHttp } from "../utils/utils.js";
13
12
  export const getFileObject = (_args) => {
@@ -39,7 +38,7 @@ const fetchScript = async (isHttpPath, mulmoFilePath, fileOrUrl) => {
39
38
  }
40
39
  return readMulmoScriptFile(mulmoFilePath, "ERROR: File does not exist " + mulmoFilePath).mulmoData;
41
40
  };
42
- const main = async () => {
41
+ export const main = async () => {
43
42
  const args = getArgs();
44
43
  const files = getFileObject(args);
45
44
  const { mulmoFilePath, isHttpPath, fileOrUrl, fileName, outputStudioFilePath } = files;
@@ -89,7 +88,3 @@ const main = async () => {
89
88
  await pdf(context, pdf_mode, pdf_size);
90
89
  }
91
90
  };
92
- const __filename = fileURLToPath(import.meta.url);
93
- if (process.argv[1] === __filename) {
94
- main();
95
- }
@@ -0,0 +1 @@
1
+ export {};
package/lib/cli/run.js ADDED
@@ -0,0 +1,2 @@
1
+ import { main } from "./cli.js";
2
+ main();
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mulmocast",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "lib/cli/cli.js",
6
+ "main": "lib/cli/run.js",
7
7
  "bin": {
8
- "mulmo": "lib/cli/cli.js",
8
+ "mulmo": "lib/cli/run.js",
9
9
  "mulmo-tool": "lib/cli/tool-cli.js"
10
10
  },
11
11
  "files": [
@@ -23,18 +23,18 @@
23
23
  "test": "tests"
24
24
  },
25
25
  "scripts": {
26
- "audio": "npx tsx ./src/cli/cli.ts audio",
27
- "translate": "npx tsx ./src/cli/cli.ts translate",
28
- "movie": "npx tsx ./src/cli/cli.ts movie",
29
- "images": "npx tsx ./src/cli/cli.ts images",
30
- "preprocess": "npx tsx ./src/cli/cli.ts preprocess",
26
+ "audio": "npx tsx ./src/cli/run.ts audio",
27
+ "translate": "npx tsx ./src/cli/run.ts translate",
28
+ "movie": "npx tsx ./src/cli/run.ts movie",
29
+ "images": "npx tsx ./src/cli/run.ts images",
30
+ "preprocess": "npx tsx ./src/cli/run.ts preprocess",
31
31
  "test": "rm -f scratchpad/test*.* && npx tsx ./src/audio.ts scripts/test/test.json && npx tsx ./src/images.ts scripts/test/test.json && npx tsx ./src/movie.ts scripts/test/test.json",
32
32
  "ci_test": "tsx --test ./test/*/test_*.ts",
33
33
  "lint": "eslint src test",
34
34
  "build": "tsc",
35
35
  "build_test": "tsc && git checkout -- lib/*",
36
36
  "prompt": "npx tsx ./src/tools/prompt.ts",
37
- "cli": "npx tsx ./src/cli/cli.ts",
37
+ "cli": "npx tsx ./src/cli/run.ts",
38
38
  "scripting": "npx tsx ./src/cli/tool-cli.ts scripting",
39
39
  "dump_prompt": "npx tsx ./src/cli/tool-cli.ts prompt",
40
40
  "latest": "yarn upgrade-interactive --latest",
@@ -1,2 +0,0 @@
1
- import { MulmoStudioContext, PDFMode, PDFSize } from "../types/index.js";
2
- export declare const pdf: (context: MulmoStudioContext, pdfMode: PDFMode, pdfSize: PDFSize) => Promise<void>;
@@ -1,203 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { rgb, PDFDocument } from "pdf-lib";
4
- import { chunkArray, isHttp } from "../utils/utils.js";
5
- import { getOutputPdfFilePath, writingMessage } from "../utils/file.js";
6
- import { MulmoScriptMethods } from "../methods/index.js";
7
- const imagesPerPage = 4;
8
- const offset = 10;
9
- const handoutImageRatio = 0.5;
10
- const readImage = async (imagePath, pdfDoc) => {
11
- const imageBytes = await (async () => {
12
- if (isHttp(imagePath)) {
13
- const res = await fetch(imagePath);
14
- const arrayBuffer = await res.arrayBuffer();
15
- return Buffer.from(arrayBuffer);
16
- }
17
- return fs.readFileSync(imagePath);
18
- })();
19
- const ext = path.extname(imagePath).toLowerCase();
20
- return ext === ".jpg" || ext === ".jpeg" ? await pdfDoc.embedJpg(imageBytes) : await pdfDoc.embedPng(imageBytes);
21
- };
22
- const pdfSlide = async (pageWidth, pageHeight, imagePaths, pdfDoc) => {
23
- const cellRatio = pageHeight / pageWidth;
24
- for (const imagePath of imagePaths) {
25
- const image = await readImage(imagePath, pdfDoc);
26
- const { width: origWidth, height: origHeight } = image.scale(1);
27
- const originalRatio = origHeight / origWidth;
28
- const fitWidth = originalRatio / cellRatio < 1;
29
- const { drawWidth, drawHeight } = drawSize(fitWidth, pageWidth, pageHeight, origWidth, origHeight);
30
- const page = pdfDoc.addPage([pageWidth, pageHeight]);
31
- page.drawImage(image, {
32
- x: 0,
33
- y: 0,
34
- width: drawWidth,
35
- height: drawHeight,
36
- });
37
- }
38
- };
39
- const pdfTalk = async (pageWidth, pageHeight, imagePaths, texts, pdfDoc) => {
40
- const imageRatio = 0.7;
41
- const textMargin = 20;
42
- const textY = textMargin + (pageHeight * (1 - imageRatio)) / 2;
43
- const targetWidth = pageWidth - offset;
44
- const targetHeight = pageHeight * imageRatio - offset;
45
- const cellRatio = targetHeight / targetWidth;
46
- for (const [index, imagePath] of imagePaths.entries()) {
47
- const text = texts[index];
48
- const image = await readImage(imagePath, pdfDoc);
49
- const { width: origWidth, height: origHeight } = image.scale(1);
50
- const originalRatio = origHeight / origWidth;
51
- const fitWidth = originalRatio / cellRatio < 1;
52
- const { drawWidth, drawHeight } = drawSize(fitWidth, targetWidth, targetHeight, origWidth, origHeight);
53
- const x = (pageWidth - drawWidth) / 2;
54
- const y = pageHeight - drawHeight - offset;
55
- const page = pdfDoc.addPage([pageWidth, pageHeight]);
56
- const pos = {
57
- x,
58
- y,
59
- width: drawWidth,
60
- height: drawHeight,
61
- };
62
- page.drawImage(image, pos);
63
- page.drawRectangle({
64
- ...pos,
65
- borderColor: rgb(0, 0, 0),
66
- borderWidth: 1,
67
- });
68
- page.drawText(text, {
69
- x: textMargin,
70
- y: textY,
71
- size: 24,
72
- color: rgb(0, 0, 0),
73
- maxWidth: pageWidth - 2 * textMargin,
74
- });
75
- }
76
- };
77
- const drawSize = (fitWidth, expectWidth, expectHeight, origWidth, origHeight) => {
78
- if (fitWidth) {
79
- const drawWidth = expectWidth;
80
- const scale = drawWidth / origWidth;
81
- const drawHeight = origHeight * scale;
82
- return {
83
- drawWidth,
84
- drawHeight,
85
- };
86
- }
87
- const drawHeight = expectHeight;
88
- const scale = drawHeight / origHeight;
89
- const drawWidth = origWidth * scale;
90
- return {
91
- drawWidth,
92
- drawHeight,
93
- };
94
- };
95
- const pdfHandout = async (pageWidth, pageHeight, imagePaths, texts, pdfDoc, isLandscapeImage) => {
96
- const cellRatio = (pageHeight / imagesPerPage - offset) / (pageWidth * handoutImageRatio - offset);
97
- let i = 0;
98
- for (const chunkPaths of chunkArray(imagePaths, imagesPerPage)) {
99
- const page = pdfDoc.addPage([pageWidth, pageHeight]);
100
- for (let i = 0; i < chunkPaths.length; i++) {
101
- const imagePath = chunkPaths[i];
102
- const image = await readImage(imagePath, pdfDoc);
103
- const { width: origWidth, height: origHeight } = image.scale(1);
104
- const originalRatio = origHeight / origWidth;
105
- const fitWidth = originalRatio / cellRatio < 1;
106
- // console.log({handoutImageRatio, cellRatio, ratio, imageHeight, origHeight});
107
- const pos = (() => {
108
- if (isLandscapeImage) {
109
- const cellHeight = pageHeight / imagesPerPage - offset;
110
- const { drawWidth, drawHeight } = drawSize(fitWidth, (pageWidth - offset) * handoutImageRatio, cellHeight - offset, origWidth, origHeight);
111
- const x = offset;
112
- const y = pageHeight - (i + 1) * cellHeight + (cellHeight - drawHeight) * handoutImageRatio;
113
- return {
114
- x,
115
- y,
116
- width: drawWidth,
117
- height: drawHeight,
118
- };
119
- }
120
- else {
121
- const cellWidth = pageWidth / imagesPerPage;
122
- const { drawWidth, drawHeight } = drawSize(fitWidth, cellWidth - offset, (pageHeight - offset) * handoutImageRatio, origWidth, origHeight);
123
- const x = pageWidth - (imagesPerPage - i) * cellWidth + (cellWidth - drawWidth) * handoutImageRatio;
124
- const y = pageHeight - drawHeight - offset;
125
- return {
126
- x,
127
- y,
128
- width: drawWidth,
129
- height: drawHeight,
130
- };
131
- }
132
- })();
133
- page.drawRectangle({
134
- ...pos,
135
- borderColor: rgb(0, 0, 0),
136
- borderWidth: 1,
137
- });
138
- page.drawImage(image, pos);
139
- const text = texts[i];
140
- const textMargin = 20;
141
- if (isLandscapeImage) {
142
- const textX = pos.x + pos.width + textMargin; // 画像の右端より少し右
143
- const textY = pos.y + pos.height - 12; // 画像の上に揃える or 必要に応じて調整
144
- page.drawText(text, {
145
- x: textX,
146
- y: textY,
147
- size: 12,
148
- color: rgb(0, 0, 0),
149
- maxWidth: pageWidth - textX - textMargin,
150
- });
151
- }
152
- else {
153
- const textY = pos.y - textMargin - 12;
154
- page.drawText(text, {
155
- x: pos.x,
156
- y: textY,
157
- size: 12,
158
- color: rgb(0, 0, 0),
159
- maxWidth: pos.width,
160
- });
161
- }
162
- i++;
163
- }
164
- }
165
- };
166
- const outputSize = (pdfSize, isLandscapeImage, isRotate) => {
167
- // console.log(pdfSize);
168
- if (pdfSize === "a4") {
169
- if (isLandscapeImage !== isRotate) {
170
- return { width: 841.89, height: 595.28 };
171
- }
172
- return { width: 595.28, height: 841.89 };
173
- }
174
- // letter
175
- if (isLandscapeImage !== isRotate) {
176
- return { width: 792, height: 612 };
177
- }
178
- return { width: 612, height: 792 };
179
- };
180
- export const pdf = async (context, pdfMode, pdfSize) => {
181
- const { studio, fileDirs } = context;
182
- const { outDirPath } = fileDirs;
183
- const { width: imageWidth, height: imageHeight } = MulmoScriptMethods.getCanvasSize(studio.script);
184
- const isLandscapeImage = imageWidth > imageHeight;
185
- const isRotate = pdfMode === "handout";
186
- const { width: pageWidth, height: pageHeight } = outputSize(pdfSize, isLandscapeImage, isRotate);
187
- const imagePaths = studio.beats.map((beat) => beat.imageFile);
188
- const texts = studio.script.beats.map((beat) => beat.text);
189
- const outputPdfPath = getOutputPdfFilePath(outDirPath, studio.filename, pdfMode);
190
- const pdfDoc = await PDFDocument.create();
191
- if (pdfMode === "handout") {
192
- await pdfHandout(pageWidth, pageHeight, imagePaths, texts, pdfDoc, isLandscapeImage);
193
- }
194
- if (pdfMode === "slide") {
195
- await pdfSlide(pageWidth, pageHeight, imagePaths, pdfDoc);
196
- }
197
- if (pdfMode === "talk") {
198
- await pdfTalk(pageWidth, pageHeight, imagePaths, texts, pdfDoc);
199
- }
200
- const pdfBytes = await pdfDoc.save();
201
- fs.writeFileSync(outputPdfPath, pdfBytes);
202
- writingMessage(outputPdfPath);
203
- };
@@ -1,23 +0,0 @@
1
- import Anthropic from "@anthropic-ai/sdk";
2
- import { AgentFunction, AgentFunctionInfo } from "graphai";
3
- import { GraphAILLMInputBase } from "@graphai/llm_utils";
4
- import type { GraphAIText, GraphAITool, GraphAIToolCalls, GraphAIMessage, GraphAIMessages } from "@graphai/agent_utils";
5
- type AnthropicInputs = {
6
- verbose?: boolean;
7
- model?: string;
8
- temperature?: number;
9
- max_tokens?: number;
10
- tools?: any[];
11
- tool_choice?: any;
12
- messages?: Array<Anthropic.MessageParam>;
13
- } & GraphAILLMInputBase;
14
- type AnthropicConfig = {
15
- apiKey?: string;
16
- stream?: boolean;
17
- forWeb?: boolean;
18
- };
19
- type AnthropicParams = AnthropicInputs & AnthropicConfig;
20
- type AnthropicResult = Partial<GraphAIText & GraphAITool & GraphAIToolCalls & GraphAIMessage<string | Anthropic.ContentBlockParam[]> & GraphAIMessages<string | Anthropic.ContentBlockParam[]>>;
21
- export declare const anthropicAgent: AgentFunction<AnthropicParams, AnthropicResult, AnthropicInputs, AnthropicConfig>;
22
- declare const anthropicAgentInfo: AgentFunctionInfo;
23
- export default anthropicAgentInfo;
@@ -1,162 +0,0 @@
1
- import Anthropic from "@anthropic-ai/sdk";
2
- import { getMergeValue } from "@graphai/llm_utils";
3
- const convToolCall = (tool_call) => {
4
- const { id, name, input } = tool_call;
5
- return { id, name, arguments: input };
6
- };
7
- // https://docs.anthropic.com/ja/api/messages
8
- const convertOpenAIChatCompletion = (response, messages) => {
9
- // SDK bug https://github.com/anthropics/anthropic-sdk-typescript/issues/432
10
- const text = response.content[0].text;
11
- const functionResponses = response.content.filter((content) => content.type === "tool_use") ?? [];
12
- const tool_calls = functionResponses.map(convToolCall);
13
- const tool = tool_calls[0] ? tool_calls[0] : undefined;
14
- const message = { role: response.role, content: text };
15
- messages.push(message);
16
- return { ...response, choices: [{ message }], text, tool, tool_calls, message, messages };
17
- };
18
- export const anthropicAgent = async ({ params, namedInputs, filterParams, config, }) => {
19
- const { verbose, system, temperature, tools, tool_choice, max_tokens, prompt, messages } = { ...params, ...namedInputs };
20
- const { apiKey, stream, forWeb, model } = {
21
- ...params,
22
- ...(config || {}),
23
- };
24
- console.log({ stream });
25
- const userPrompt = getMergeValue(namedInputs, params, "mergeablePrompts", prompt);
26
- const systemPrompt = getMergeValue(namedInputs, params, "mergeableSystem", system);
27
- const messagesCopy = messages ? messages.map((m) => m) : [];
28
- if (userPrompt) {
29
- messagesCopy.push({
30
- role: "user",
31
- content: userPrompt,
32
- });
33
- }
34
- if (verbose) {
35
- console.log(messagesCopy);
36
- }
37
- const anthropic_tools = tools && tools.length > 0
38
- ? tools.map((tool) => {
39
- const { function: func } = tool;
40
- const { name, description, parameters } = func;
41
- return {
42
- name,
43
- description,
44
- input_schema: parameters,
45
- };
46
- })
47
- : undefined;
48
- const anthropic = new Anthropic({ apiKey, dangerouslyAllowBrowser: !!forWeb });
49
- const chatParams = {
50
- model: model ?? "claude-3-5-sonnet-latest",
51
- messages: messagesCopy,
52
- tools: anthropic_tools,
53
- tool_choice,
54
- system: systemPrompt,
55
- temperature: temperature ?? 0.7,
56
- max_tokens: max_tokens ?? 1024,
57
- };
58
- if (!stream) {
59
- const messageResponse = await anthropic.messages.create(chatParams);
60
- return convertOpenAIChatCompletion(messageResponse, messagesCopy);
61
- }
62
- try {
63
- console.log("###");
64
- const chatStream = await anthropic.messages.create({
65
- ...chatParams,
66
- stream: true,
67
- });
68
- console.log("###2");
69
- const contents = [];
70
- const partials = [];
71
- let streamResponse = null;
72
- console.log("###3");
73
- for await (const messageStreamEvent of chatStream) {
74
- console.log("AA");
75
- if (messageStreamEvent.type === "message_start") {
76
- streamResponse = messageStreamEvent.message;
77
- }
78
- if (messageStreamEvent.type === "content_block_start") {
79
- if (streamResponse) {
80
- streamResponse.content.push(messageStreamEvent.content_block);
81
- }
82
- partials.push("");
83
- }
84
- if (messageStreamEvent.type === "content_block_delta") {
85
- const { index, delta } = messageStreamEvent;
86
- if (delta.type === "input_json_delta") {
87
- partials[index] = partials[index] + delta.partial_json;
88
- }
89
- if (delta.type === "text_delta") {
90
- partials[index] = partials[index] + delta.text;
91
- }
92
- }
93
- if (messageStreamEvent.type === "content_block_delta" && messageStreamEvent.delta.type === "text_delta") {
94
- const token = messageStreamEvent.delta.text;
95
- contents.push(token);
96
- if (filterParams && filterParams.streamTokenCallback && token) {
97
- filterParams.streamTokenCallback(token);
98
- }
99
- }
100
- }
101
- if (streamResponse === null) {
102
- throw new Error("Anthoropic no response");
103
- }
104
- partials.forEach((partial, index) => {
105
- if (streamResponse.content[index].type === "text") {
106
- streamResponse.content[index].text = partial;
107
- }
108
- if (streamResponse.content[index].type === "tool_use") {
109
- streamResponse.content[index].input = JSON.parse(partial);
110
- }
111
- });
112
- return convertOpenAIChatCompletion(streamResponse, messagesCopy);
113
- /*
114
-
115
- const content = contents.join("");
116
- const message = { role: "assistant" as const, content: content };
117
- messagesCopy.push(message);
118
- return { choices: [{ message }], text: content, message, messages: messagesCopy };
119
- */
120
- }
121
- catch (e) {
122
- console.log(e);
123
- throw new Error("ant Error");
124
- }
125
- };
126
- const anthropicAgentInfo = {
127
- name: "anthropicAgent",
128
- agent: anthropicAgent,
129
- mock: anthropicAgent,
130
- inputs: {
131
- type: "object",
132
- properties: {
133
- model: { type: "string" },
134
- system: { type: "string" },
135
- max_tokens: { type: "number" },
136
- temperature: { type: "number" },
137
- prompt: {
138
- type: "string",
139
- description: "query string",
140
- },
141
- messages: {
142
- anyOf: [{ type: "string" }, { type: "integer" }, { type: "object" }, { type: "array" }],
143
- description: "chat messages",
144
- },
145
- },
146
- },
147
- output: {
148
- type: "object",
149
- },
150
- samples: [],
151
- description: "Anthropic Agent",
152
- category: ["llm"],
153
- author: "Receptron team",
154
- repository: "https://github.com/receptron/graphai",
155
- source: "https://github.com/receptron/graphai/blob/main/llm_agents/anthropic_agent/src/anthropic_agent.ts",
156
- package: "@graphai/anthropic_agent",
157
- license: "MIT",
158
- stream: true,
159
- environmentVariables: ["ANTHROPIC_API_KEY"],
160
- npms: ["@anthropic-ai/sdk"],
161
- };
162
- export default anthropicAgentInfo;
@@ -1,9 +0,0 @@
1
- import type { AgentFunction, AgentFunctionInfo, AgentFunctionContext, GraphData, ResultData, DefaultResultData } from "graphai";
2
- import type { GraphAISupressError, GraphAIOnError } from "@graphai/agent_utils";
3
- type NestedAgentGeneratorOption = {
4
- resultNodeId: string;
5
- };
6
- export declare const nestedAgentGenerator: (graphData: GraphData, options?: NestedAgentGeneratorOption) => (context: AgentFunctionContext) => Promise<ResultData<DefaultResultData> | GraphAIOnError>;
7
- export declare const nestedAgent: AgentFunction<Partial<GraphAISupressError> & NestedAgentGeneratorOption>;
8
- declare const nestedAgentInfo: AgentFunctionInfo;
9
- export default nestedAgentInfo;
@@ -1,138 +0,0 @@
1
- import { GraphAI, assert, graphDataLatestVersion } from "graphai";
2
- export const nestedAgentGenerator = (graphData, options) => {
3
- return async (context) => {
4
- const { namedInputs, log, debugInfo, params, forNestedGraph } = context;
5
- assert(!!forNestedGraph, "Please update graphai to 0.5.19 or higher");
6
- const { agents, graphOptions, onLogCallback, callbacks } = forNestedGraph;
7
- const { taskManager } = graphOptions;
8
- const supressError = params.supressError ?? false;
9
- if (taskManager) {
10
- const status = taskManager.getStatus(false);
11
- assert(status.concurrency > status.running, `nestedAgent: Concurrency is too low: ${status.concurrency}`);
12
- }
13
- assert(!!graphData, "nestedAgent: graph is required");
14
- const { nodes } = graphData;
15
- const newNodes = Object.keys(nodes).reduce((tmp, key) => {
16
- const node = nodes[key];
17
- if ("agent" in node) {
18
- tmp[key] = node;
19
- }
20
- else {
21
- const { value, update, isResult, console } = node;
22
- tmp[key] = { value, update, isResult, console };
23
- }
24
- return tmp;
25
- }, {});
26
- const nestedGraphData = { ...graphData, nodes: newNodes, version: graphDataLatestVersion }; // deep enough copy
27
- const nodeIds = Object.keys(namedInputs);
28
- if (nodeIds.length > 0) {
29
- nodeIds.forEach((nodeId) => {
30
- if (nestedGraphData.nodes[nodeId] === undefined) {
31
- // If the input node does not exist, automatically create a static node
32
- nestedGraphData.nodes[nodeId] = { value: namedInputs[nodeId] };
33
- }
34
- else {
35
- // Otherwise, inject the proper data here (instead of calling injectTo method later)
36
- if (namedInputs[nodeId] !== undefined) {
37
- nestedGraphData.nodes[nodeId]["value"] = namedInputs[nodeId];
38
- }
39
- }
40
- });
41
- }
42
- try {
43
- if (nestedGraphData.version === undefined && debugInfo.version) {
44
- nestedGraphData.version = debugInfo.version;
45
- }
46
- const graphAI = new GraphAI(nestedGraphData, agents || {}, graphOptions);
47
- // for backward compatibility. Remove 'if' later
48
- if (onLogCallback) {
49
- graphAI.onLogCallback = onLogCallback;
50
- }
51
- if (callbacks) {
52
- graphAI.callbacks = callbacks;
53
- }
54
- debugInfo.subGraphs.set(graphAI.graphId, graphAI);
55
- const results = await graphAI.run(false);
56
- debugInfo.subGraphs.delete(graphAI.graphId);
57
- log?.push(...graphAI.transactionLogs());
58
- console.log("FFF");
59
- if (options && options.resultNodeId) {
60
- return results[options.resultNodeId];
61
- }
62
- return results;
63
- }
64
- catch (error) {
65
- console.log("FFF2");
66
- if (error instanceof Error && supressError) {
67
- console.log("FFF3");
68
- return {
69
- onError: {
70
- message: error.message,
71
- error,
72
- },
73
- };
74
- }
75
- console.log("FFF4", error);
76
- throw error;
77
- }
78
- };
79
- };
80
- export const nestedAgent = async (context) => {
81
- const { forNestedGraph, params } = context;
82
- const { graphData } = forNestedGraph ?? { graphData: { nodes: {} } };
83
- assert(!!graphData, "No GraphData");
84
- return await nestedAgentGenerator(graphData, params)(context);
85
- };
86
- const nestedAgentInfo = {
87
- name: "nestedAgent",
88
- agent: nestedAgent,
89
- mock: nestedAgent,
90
- samples: [
91
- {
92
- inputs: {
93
- message: "hello",
94
- },
95
- params: {},
96
- result: {
97
- test: ["hello"],
98
- },
99
- graph: {
100
- nodes: {
101
- test: {
102
- agent: "copyAgent",
103
- params: { namedKey: "messages" },
104
- inputs: { messages: [":message"] },
105
- isResult: true,
106
- },
107
- },
108
- },
109
- },
110
- {
111
- inputs: {
112
- message: "hello",
113
- },
114
- params: {
115
- resultNodeId: "test",
116
- },
117
- result: ["hello"],
118
- graph: {
119
- nodes: {
120
- test: {
121
- agent: "copyAgent",
122
- params: { namedKey: "messages" },
123
- inputs: { messages: [":message"] },
124
- isResult: true,
125
- },
126
- },
127
- },
128
- },
129
- ],
130
- description: "nested Agent",
131
- category: ["graph"],
132
- author: "Receptron team",
133
- repository: "https://github.com/receptron/graphai",
134
- source: "https://github.com/receptron/graphai/blob/main/agents/vanilla_agents/src/graph_agents/nested_agent.ts",
135
- package: "@graphai/vanilla",
136
- license: "MIT",
137
- };
138
- export default nestedAgentInfo;
@@ -1,3 +0,0 @@
1
- import "dotenv/config";
2
- import { ScriptingParams } from "../types";
3
- export declare const createMulmoScriptWithInteractive: ({ outDirPath, filename, templateName, urls }: ScriptingParams) => Promise<void>;
package/lib/tools/seed.js DELETED
@@ -1,201 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createMulmoScriptWithInteractive = void 0;
37
- require("dotenv/config");
38
- const graphai_1 = require("graphai");
39
- const input_agents_1 = require("@graphai/input_agents");
40
- const openai_agent_1 = require("@graphai/openai_agent");
41
- const vanilla = __importStar(require("@graphai/vanilla"));
42
- const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
43
- const file_1 = require("../utils/file");
44
- const browserless_agent_1 = require("@graphai/browserless_agent");
45
- const agentHeader = "\x1b[34m● \x1b[0m\x1b[1mAgent\x1b[0m:\x1b[0m";
46
- const graphDataForScraping = {
47
- version: 0.5,
48
- nodes: {
49
- urls: {
50
- value: [],
51
- },
52
- fetchResults: {
53
- agent: "mapAgent",
54
- inputs: {
55
- rows: ":urls",
56
- },
57
- params: {
58
- compositeResult: true,
59
- },
60
- graph: {
61
- nodes: {
62
- fetcher: {
63
- agent: "browserlessAgent",
64
- inputs: {
65
- url: ":row",
66
- text_content: true,
67
- },
68
- },
69
- copyAgent: {
70
- agent: "copyAgent",
71
- inputs: {
72
- text: '{ url: "${:row}", text: "${:fetcher.text}" }',
73
- },
74
- params: {
75
- namedKey: "text",
76
- },
77
- isResult: true,
78
- },
79
- },
80
- },
81
- },
82
- sourceText: {
83
- agent: "arrayJoinAgent",
84
- inputs: {
85
- array: ":fetchResults.copyAgent",
86
- },
87
- params: {
88
- separator: ",",
89
- },
90
- isResult: true,
91
- },
92
- },
93
- };
94
- const graphData = {
95
- version: 0.5,
96
- loop: {
97
- while: ":continue",
98
- },
99
- nodes: {
100
- fileName: {
101
- update: ":fileName",
102
- },
103
- outdir: {
104
- update: ":outdir",
105
- },
106
- messages: {
107
- value: [],
108
- update: ":llm.messages",
109
- },
110
- userInput: {
111
- agent: "textInputAgent",
112
- params: {
113
- message: "You:",
114
- required: true,
115
- },
116
- },
117
- llm: {
118
- agent: "openAIAgent",
119
- params: {
120
- model: "gpt-4o",
121
- },
122
- inputs: {
123
- messages: ":messages",
124
- prompt: ":userInput.text",
125
- },
126
- },
127
- json: {
128
- agent: "copyAgent",
129
- inputs: {
130
- json: ":llm.text.codeBlock().jsonParse()",
131
- text: ":llm.text.codeBlock()",
132
- },
133
- },
134
- writeJSON: {
135
- if: ":json.json",
136
- agent: "fileWriteAgent",
137
- inputs: {
138
- file: "${:outdir}/${:fileName}-${@now}.json",
139
- text: ":json.text",
140
- },
141
- },
142
- writeLog: {
143
- agent: "consoleAgent",
144
- inputs: {
145
- text: "\n\x1b[32m🎉 Script file generated successfully! Type /bye to exit.\x1b[0m\nwriting: ${:writeJSON.path}",
146
- waiting: ":writeJSON",
147
- },
148
- },
149
- shouldResponse: {
150
- agent: "compareAgent",
151
- inputs: {
152
- array: [[":json.json", "==", undefined], "&&", [":userInput.text", "!=", "/bye"]],
153
- },
154
- },
155
- agentResponse: {
156
- if: ":shouldResponse.result",
157
- agent: "consoleAgent",
158
- inputs: {
159
- text: "\n" + agentHeader + " ${:llm.text}\n",
160
- },
161
- },
162
- checkInput: {
163
- agent: "compareAgent",
164
- inputs: { array: [":userInput.text", "!=", "/bye"] },
165
- },
166
- continue: {
167
- value: true,
168
- update: ":checkInput.result",
169
- },
170
- },
171
- };
172
- const interactiveClarificationPrompt = `If there are any unclear points, be sure to ask the user questions and clarify them before generating the script.`;
173
- const scrapeWebContent = async (urls) => {
174
- console.log(`${agentHeader} Scraping ${urls.length} URLs...\n`);
175
- const graph = new graphai_1.GraphAI(graphDataForScraping, { ...vanilla, openAIAgent: openai_agent_1.openAIAgent, textInputAgent: input_agents_1.textInputAgent, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent, browserlessAgent: browserless_agent_1.browserlessAgent });
176
- graph.injectValue("urls", urls);
177
- const result = (await graph.run());
178
- if (!result?.sourceText?.text) {
179
- return "";
180
- }
181
- const prefixPrompt = "Here is the web content that can be used as reference material for the script:";
182
- return `\n\n${prefixPrompt}\n${result?.sourceText.text}`;
183
- };
184
- const createMulmoScriptWithInteractive = async ({ outDirPath, filename, templateName, urls }) => {
185
- (0, file_1.mkdir)(outDirPath);
186
- // if urls is not empty, scrape web content and reference it in the prompt
187
- const webContentPrompt = urls.length > 0 ? await scrapeWebContent(urls) : "";
188
- const graph = new graphai_1.GraphAI(graphData, { ...vanilla, openAIAgent: openai_agent_1.openAIAgent, textInputAgent: input_agents_1.textInputAgent, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent });
189
- const prompt = (0, file_1.readTemplatePrompt)(templateName);
190
- graph.injectValue("messages", [
191
- {
192
- role: "system",
193
- content: `${prompt}\n\n${interactiveClarificationPrompt}${webContentPrompt}`,
194
- },
195
- ]);
196
- graph.injectValue("outdir", outDirPath);
197
- graph.injectValue("fileName", filename);
198
- console.log(`${agentHeader} Hi! What topic would you like me to generate about?\n`);
199
- await graph.run();
200
- };
201
- exports.createMulmoScriptWithInteractive = createMulmoScriptWithInteractive;
@@ -1,3 +0,0 @@
1
- import "dotenv/config";
2
- import { ScriptingParams } from "../types";
3
- export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename }: ScriptingParams) => Promise<void>;
@@ -1,178 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.createMulmoScriptFromUrl = void 0;
40
- require("dotenv/config");
41
- const graphai_1 = require("graphai");
42
- const openai_agent_1 = require("@graphai/openai_agent");
43
- const vanilla = __importStar(require("@graphai/vanilla"));
44
- const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
45
- const browserless_agent_1 = require("@graphai/browserless_agent");
46
- const validate_mulmo_script_agent_1 = __importDefault(require("../agents/validate_mulmo_script_agent"));
47
- const file_1 = require("../utils/file");
48
- const schema_1 = require("../types/schema");
49
- const graphData = {
50
- version: 0.5,
51
- // Execute sequentially because the free version of browserless API doesn't support concurrent execution.
52
- concurrency: 1,
53
- nodes: {
54
- urls: {
55
- value: [],
56
- },
57
- prompt: {
58
- value: "",
59
- },
60
- outdir: {
61
- value: "",
62
- },
63
- fileName: {
64
- value: "",
65
- },
66
- // get the text content of the urls
67
- fetchResults: {
68
- agent: "mapAgent",
69
- inputs: {
70
- rows: ":urls",
71
- },
72
- params: {
73
- compositeResult: true,
74
- },
75
- graph: {
76
- nodes: {
77
- fetcher: {
78
- agent: "browserlessAgent",
79
- inputs: {
80
- url: ":row",
81
- text_content: true,
82
- },
83
- },
84
- copyAgent: {
85
- agent: "copyAgent",
86
- inputs: {
87
- text: '{ url: "${:row}", text: "${:fetcher.text}" }',
88
- },
89
- params: {
90
- namedKey: "text",
91
- },
92
- isResult: true,
93
- },
94
- },
95
- },
96
- },
97
- // join the text content
98
- sourceText: {
99
- agent: "arrayJoinAgent",
100
- inputs: {
101
- array: ":fetchResults.copyAgent",
102
- },
103
- params: {
104
- separator: ",",
105
- },
106
- },
107
- // generate the mulmo script
108
- mulmoScript: {
109
- agent: "nestedAgent",
110
- inputs: {
111
- sourceText: ":sourceText",
112
- prompt: ":prompt",
113
- },
114
- graph: {
115
- loop: {
116
- // If the script is not valid and the counter is less than 3, continue the loop
117
- while: ":continue",
118
- },
119
- nodes: {
120
- counter: {
121
- value: 0,
122
- update: ":counter.add(1)",
123
- },
124
- openAIAgent: {
125
- agent: "openAIAgent",
126
- inputs: {
127
- model: "gpt-4o",
128
- system: ":prompt",
129
- prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
130
- },
131
- },
132
- validateMulmoScriptAgent: {
133
- agent: "validateMulmoScriptAgent",
134
- inputs: {
135
- text: ":openAIAgent.text.codeBlock()",
136
- },
137
- isResult: true,
138
- },
139
- continue: {
140
- agent: ({ isValid, counter }) => {
141
- return !isValid && counter < 3;
142
- },
143
- inputs: {
144
- isValid: ":validateMulmoScriptAgent.isValid",
145
- counter: ":counter",
146
- },
147
- },
148
- },
149
- },
150
- },
151
- writeJSON: {
152
- if: ":mulmoScript.validateMulmoScriptAgent.isValid",
153
- agent: "fileWriteAgent",
154
- inputs: {
155
- file: "${:outdir}/${:fileName}-${@now}.json",
156
- text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
157
- },
158
- isResult: true,
159
- },
160
- },
161
- };
162
- const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename }) => {
163
- (0, file_1.mkdir)(outDirPath);
164
- const parsedUrls = schema_1.urlsSchema.parse(urls);
165
- const graph = new graphai_1.GraphAI(graphData, {
166
- ...vanilla,
167
- openAIAgent: openai_agent_1.openAIAgent,
168
- browserlessAgent: browserless_agent_1.browserlessAgent,
169
- validateMulmoScriptAgent: validate_mulmo_script_agent_1.default,
170
- fileWriteAgent: vanilla_node_agents_1.fileWriteAgent,
171
- });
172
- graph.injectValue("urls", parsedUrls);
173
- graph.injectValue("prompt", (0, file_1.readTemplatePrompt)(templateName));
174
- graph.injectValue("outdir", outDirPath);
175
- graph.injectValue("fileName", filename);
176
- await graph.run();
177
- };
178
- exports.createMulmoScriptFromUrl = createMulmoScriptFromUrl;
@@ -1,3 +0,0 @@
1
- import "dotenv/config";
2
- import { ScriptingParams } from "../types";
3
- export declare const createMulmoScriptFromUrl: ({ urls, templateName, outDirPath, filename, cacheDirPath }: ScriptingParams) => Promise<void>;
@@ -1,154 +0,0 @@
1
- import "dotenv/config";
2
- import { GraphAI } from "graphai";
3
- import { openAIAgent } from "@graphai/openai_agent";
4
- import * as vanilla from "@graphai/vanilla";
5
- import { fileWriteAgent } from "@graphai/vanilla_node_agents";
6
- import { browserlessAgent } from "@graphai/browserless_agent";
7
- import validateMulmoScriptAgent from "../agents/validate_mulmo_script_agent";
8
- import { readTemplatePrompt, mkdir, writingMessage } from "../utils/file";
9
- import { browserlessCacheGenerator } from "../utils/filters";
10
- import { urlsSchema } from "../types/schema";
11
- import { cliLoadingPlugin } from "../utils/plugins";
12
- const graphData = {
13
- version: 0.5,
14
- // Execute sequentially because the free version of browserless API doesn't support concurrent execution.
15
- concurrency: 1,
16
- nodes: {
17
- urls: {
18
- value: [],
19
- },
20
- prompt: {
21
- value: "",
22
- },
23
- outdir: {
24
- value: "",
25
- },
26
- fileName: {
27
- value: "",
28
- },
29
- fetchGraph: {
30
- value: {
31
- nodes: {
32
- fetcher: {
33
- agent: "browserlessAgent",
34
- inputs: {
35
- url: ":row",
36
- text_content: true,
37
- },
38
- },
39
- copyAgent: {
40
- agent: "copyAgent",
41
- inputs: {
42
- text: '{ url: "${:row}", text: "${:fetcher.text}" }',
43
- },
44
- params: {
45
- namedKey: "text",
46
- },
47
- isResult: true,
48
- },
49
- },
50
- },
51
- },
52
- // get the text content of the urls
53
- fetchResults: {
54
- agent: "mapAgent",
55
- inputs: {
56
- rows: ":urls",
57
- },
58
- params: {
59
- compositeResult: true,
60
- },
61
- graph: ":fetchGraph",
62
- },
63
- // join the text content
64
- sourceText: {
65
- agent: "arrayJoinAgent",
66
- inputs: {
67
- array: ":fetchResults.copyAgent",
68
- },
69
- params: {
70
- separator: ",",
71
- },
72
- },
73
- // generate the mulmo script
74
- mulmoScript: {
75
- agent: "nestedAgent",
76
- inputs: {
77
- sourceText: ":sourceText",
78
- prompt: ":prompt",
79
- },
80
- graph: {
81
- loop: {
82
- // If the script is not valid and the counter is less than 3, continue the loop
83
- while: ":continue",
84
- },
85
- nodes: {
86
- counter: {
87
- value: 0,
88
- update: ":counter.add(1)",
89
- },
90
- openAIAgent: {
91
- agent: "openAIAgent",
92
- inputs: {
93
- model: "gpt-4o",
94
- system: ":prompt",
95
- prompt: "Please create a script using the information from the following URLs as reference: ${:sourceText.text}",
96
- },
97
- },
98
- validateMulmoScriptAgent: {
99
- agent: "validateMulmoScriptAgent",
100
- inputs: {
101
- text: ":openAIAgent.text.codeBlock()",
102
- },
103
- isResult: true,
104
- },
105
- continue: {
106
- agent: ({ isValid, counter }) => {
107
- return !isValid && counter < 3;
108
- },
109
- inputs: {
110
- isValid: ":validateMulmoScriptAgent.isValid",
111
- counter: ":counter",
112
- },
113
- },
114
- },
115
- },
116
- },
117
- writeJSON: {
118
- if: ":mulmoScript.validateMulmoScriptAgent.isValid",
119
- agent: "fileWriteAgent",
120
- inputs: {
121
- file: "${:outdir}/${:fileName}-${@now}.json",
122
- text: ":mulmoScript.validateMulmoScriptAgent.data.toJSON()",
123
- },
124
- isResult: true,
125
- },
126
- },
127
- };
128
- export const createMulmoScriptFromUrl = async ({ urls, templateName, outDirPath, filename, cacheDirPath }) => {
129
- mkdir(outDirPath);
130
- mkdir(cacheDirPath);
131
- const parsedUrls = urlsSchema.parse(urls);
132
- const browserlessCache = browserlessCacheGenerator(cacheDirPath);
133
- const agentFilters = [
134
- {
135
- name: "browserlessCache",
136
- agent: browserlessCache,
137
- nodeIds: ["fetcher"],
138
- },
139
- ];
140
- const graph = new GraphAI(graphData, {
141
- ...vanilla,
142
- openAIAgent,
143
- browserlessAgent,
144
- validateMulmoScriptAgent,
145
- fileWriteAgent,
146
- }, { agentFilters });
147
- graph.injectValue("urls", parsedUrls);
148
- graph.injectValue("prompt", readTemplatePrompt(templateName));
149
- graph.injectValue("outdir", outDirPath);
150
- graph.injectValue("fileName", filename);
151
- graph.registerCallback(cliLoadingPlugin({ nodeId: "mulmoScript", message: "Generating script..." }));
152
- const result = await graph.run();
153
- writingMessage(result?.writeJSON?.path ?? "");
154
- };
@@ -1,14 +0,0 @@
1
- import { MulmoStudioBeat, MulmoStudioContext, MulmoCanvasDimension } from "../types/index.js";
2
- type ImageProcessorParams = {
3
- beat: MulmoStudioBeat;
4
- context: MulmoStudioContext;
5
- imagePath: string;
6
- textSlideStyle: string;
7
- canvasSize: MulmoCanvasDimension;
8
- };
9
- export declare const processTextSlide: (params: ImageProcessorParams) => Promise<void>;
10
- export declare const processMarkdown: (params: ImageProcessorParams) => Promise<void>;
11
- export declare const processImage: (params: ImageProcessorParams) => string | undefined;
12
- export declare const processChart: (params: ImageProcessorParams) => Promise<void>;
13
- export declare const processMermaid: (params: ImageProcessorParams) => Promise<void>;
14
- export {};
@@ -1,52 +0,0 @@
1
- import { MulmoStudioContextMethods } from "../methods/index.js";
2
- import { getHTMLFile } from "./file.js";
3
- import { renderMarkdownToImage, renderHTMLToImage, interpolate } from "./markdown.js";
4
- export const processTextSlide = async (params) => {
5
- const { beat, imagePath, textSlideStyle, canvasSize } = params;
6
- if (!beat.image || beat.image.type !== "textSlide")
7
- return;
8
- const slide = beat.image.slide;
9
- const markdown = `# ${slide.title}\n` + slide.bullets.map((text) => `- ${text}`).join("\n");
10
- await renderMarkdownToImage(markdown, textSlideStyle, imagePath, canvasSize.width, canvasSize.height);
11
- };
12
- export const processMarkdown = async (params) => {
13
- const { beat, imagePath, textSlideStyle, canvasSize } = params;
14
- if (!beat.image || beat.image.type !== "markdown")
15
- return;
16
- const markdown = Array.isArray(beat.image.markdown) ? beat.image.markdown.join("\n") : beat.image.markdown;
17
- await renderMarkdownToImage(markdown, textSlideStyle, imagePath, canvasSize.width, canvasSize.height);
18
- };
19
- export const processImage = (params) => {
20
- const { beat, context } = params;
21
- if (!beat.image || beat.image.type !== "image")
22
- return;
23
- if (beat.image.source.kind === "url") {
24
- return beat.image.source.url;
25
- }
26
- else if (beat.image.source.kind === "path") {
27
- return MulmoStudioContextMethods.resolveAssetPath(context, beat.image.source.path);
28
- }
29
- };
30
- export const processChart = async (params) => {
31
- const { beat, imagePath, canvasSize } = params;
32
- if (!beat.image || beat.image.type !== "chart")
33
- return;
34
- const template = getHTMLFile("chart");
35
- const htmlData = interpolate(template, {
36
- title: beat.image.title,
37
- width: Math.round(canvasSize.width * 0.625).toString(),
38
- chart_data: JSON.stringify(beat.image.chartData),
39
- });
40
- await renderHTMLToImage(htmlData, imagePath, canvasSize.width, canvasSize.height);
41
- };
42
- export const processMermaid = async (params) => {
43
- const { beat, imagePath, canvasSize } = params;
44
- if (!beat.image || beat.image.type !== "mermaid")
45
- return;
46
- const template = getHTMLFile("mermaid");
47
- const htmlData = interpolate(template, {
48
- title: beat.image.title,
49
- diagram_code: beat.image.code,
50
- });
51
- await renderHTMLToImage(htmlData, imagePath, canvasSize.width, canvasSize.height);
52
- };
@@ -1 +0,0 @@
1
- export declare const text2hash: (input: string) => string;
@@ -1,4 +0,0 @@
1
- import * as crypto from "crypto";
2
- export const text2hash = (input) => {
3
- return crypto.createHash("sha256").update(input).digest("hex");
4
- };