mulmocast 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/README.md +129 -15
  2. package/assets/font/NotoSansJP-Regular.ttf +0 -0
  3. package/assets/html/chart.html +38 -0
  4. package/assets/html/mermaid.html +51 -0
  5. package/assets/templates/business.json +57 -14
  6. package/assets/templates/children_book.json +1 -3
  7. package/assets/templates/coding.json +140 -0
  8. package/lib/actions/audio.d.ts +2 -2
  9. package/lib/actions/audio.js +88 -101
  10. package/lib/actions/images.d.ts +1 -1
  11. package/lib/actions/images.js +50 -88
  12. package/lib/actions/index.d.ts +5 -0
  13. package/lib/actions/index.js +5 -0
  14. package/lib/actions/movie.d.ts +9 -1
  15. package/lib/actions/movie.js +124 -65
  16. package/lib/actions/pdf.d.ts +2 -0
  17. package/lib/actions/pdf.js +211 -0
  18. package/lib/actions/pdf2.d.ts +2 -0
  19. package/lib/actions/pdf2.js +203 -0
  20. package/lib/actions/translate.d.ts +1 -1
  21. package/lib/actions/translate.js +38 -61
  22. package/lib/agents/add_bgm_agent.d.ts +1 -1
  23. package/lib/agents/add_bgm_agent.js +10 -14
  24. package/lib/agents/anthropic_agent.d.ts +23 -0
  25. package/lib/agents/anthropic_agent.js +162 -0
  26. package/lib/agents/combine_audio_files_agent.d.ts +1 -1
  27. package/lib/agents/combine_audio_files_agent.js +33 -32
  28. package/lib/agents/image_google_agent.d.ts +1 -1
  29. package/lib/agents/image_google_agent.js +8 -11
  30. package/lib/agents/image_openai_agent.js +7 -14
  31. package/lib/agents/index.d.ts +8 -8
  32. package/lib/agents/index.js +13 -30
  33. package/lib/agents/mulmo_prompts_agent.d.ts +1 -1
  34. package/lib/agents/mulmo_prompts_agent.js +7 -11
  35. package/lib/agents/nested_agent.d.ts +9 -0
  36. package/lib/agents/nested_agent.js +138 -0
  37. package/lib/agents/prompts_data.js +1 -4
  38. package/lib/agents/tts_nijivoice_agent.d.ts +1 -1
  39. package/lib/agents/tts_nijivoice_agent.js +8 -12
  40. package/lib/agents/tts_openai_agent.js +9 -16
  41. package/lib/agents/validate_mulmo_script_agent.d.ts +1 -1
  42. package/lib/agents/validate_mulmo_script_agent.js +6 -10
  43. package/lib/cli/args.d.ts +5 -2
  44. package/lib/cli/args.js +52 -35
  45. package/lib/cli/cli.d.ts +14 -0
  46. package/lib/cli/cli.js +74 -57
  47. package/lib/cli/common.js +1 -5
  48. package/lib/cli/tool-args.d.ts +4 -1
  49. package/lib/cli/tool-args.js +29 -18
  50. package/lib/cli/tool-cli.js +34 -51
  51. package/lib/methods/index.d.ts +4 -3
  52. package/lib/methods/index.js +4 -19
  53. package/lib/methods/mulmo_media_source.d.ts +4 -0
  54. package/lib/methods/mulmo_media_source.js +21 -0
  55. package/lib/methods/mulmo_script.d.ts +6 -5
  56. package/lib/methods/mulmo_script.js +29 -16
  57. package/lib/methods/mulmo_script_template.d.ts +1 -1
  58. package/lib/methods/mulmo_script_template.js +4 -10
  59. package/lib/methods/mulmo_studio_context.d.ts +1 -1
  60. package/lib/methods/mulmo_studio_context.js +3 -9
  61. package/lib/tools/create_mulmo_script_from_url.d.ts +3 -0
  62. package/lib/tools/create_mulmo_script_from_url.js +152 -0
  63. package/lib/tools/create_mulmo_script_interactively.d.ts +3 -0
  64. package/lib/tools/create_mulmo_script_interactively.js +258 -0
  65. package/lib/tools/dump_prompt.js +5 -8
  66. package/lib/tools/prompt.js +9 -11
  67. package/lib/tools/seed_from_url2.d.ts +3 -0
  68. package/lib/tools/seed_from_url2.js +154 -0
  69. package/lib/types/index.d.ts +2 -1
  70. package/lib/types/index.js +2 -17
  71. package/lib/types/schema.d.ts +3624 -2798
  72. package/lib/types/schema.js +172 -123
  73. package/lib/types/type.d.ts +34 -3
  74. package/lib/types/type.js +1 -2
  75. package/lib/utils/const.d.ts +4 -1
  76. package/lib/utils/const.js +6 -6
  77. package/lib/utils/file.d.ts +22 -4
  78. package/lib/utils/file.js +100 -79
  79. package/lib/utils/filters.d.ts +1 -0
  80. package/lib/utils/filters.js +47 -26
  81. package/lib/utils/image_plugins/chart.d.ts +3 -0
  82. package/lib/utils/image_plugins/chart.js +18 -0
  83. package/lib/utils/image_plugins/image.d.ts +2 -0
  84. package/lib/utils/image_plugins/image.js +3 -0
  85. package/lib/utils/image_plugins/index.d.ts +7 -0
  86. package/lib/utils/image_plugins/index.js +7 -0
  87. package/lib/utils/image_plugins/markdown.d.ts +3 -0
  88. package/lib/utils/image_plugins/markdown.js +11 -0
  89. package/lib/utils/image_plugins/mermaid.d.ts +3 -0
  90. package/lib/utils/image_plugins/mermaid.js +21 -0
  91. package/lib/utils/image_plugins/movie.d.ts +2 -0
  92. package/lib/utils/image_plugins/movie.js +3 -0
  93. package/lib/utils/image_plugins/source.d.ts +4 -0
  94. package/lib/utils/image_plugins/source.js +15 -0
  95. package/lib/utils/image_plugins/text_slide.d.ts +3 -0
  96. package/lib/utils/image_plugins/text_slide.js +12 -0
  97. package/lib/utils/image_plugins/type_guards.d.ts +6 -0
  98. package/lib/utils/image_plugins/type_guards.js +21 -0
  99. package/lib/utils/image_preprocess.d.ts +14 -0
  100. package/lib/utils/image_preprocess.js +52 -0
  101. package/lib/utils/inquirer.d.ts +2 -0
  102. package/lib/utils/inquirer.js +33 -0
  103. package/lib/utils/markdown.d.ts +3 -1
  104. package/lib/utils/markdown.js +20 -19
  105. package/lib/utils/pdf.d.ts +8 -0
  106. package/lib/utils/pdf.js +75 -0
  107. package/lib/utils/plugins.d.ts +5 -0
  108. package/lib/utils/plugins.js +11 -0
  109. package/lib/utils/preprocess.d.ts +70 -123
  110. package/lib/utils/preprocess.js +37 -43
  111. package/lib/utils/string.js +4 -10
  112. package/lib/utils/text_hash.js +2 -39
  113. package/lib/utils/utils.d.ts +12 -0
  114. package/lib/utils/utils.js +34 -0
  115. package/package.json +23 -8
@@ -1,46 +1,11 @@
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.translate = void 0;
37
- require("dotenv/config");
38
- const graphai_1 = require("graphai");
39
- const agents = __importStar(require("@graphai/vanilla"));
40
- const openai_agent_1 = require("@graphai/openai_agent");
41
- const vanilla_node_agents_1 = require("@graphai/vanilla_node_agents");
42
- const string_1 = require("../utils/string");
43
- const file_1 = require("../utils/file");
1
+ import "dotenv/config";
2
+ import { GraphAI, assert } from "graphai";
3
+ import * as agents from "@graphai/vanilla";
4
+ import { openAIAgent } from "@graphai/openai_agent";
5
+ import { fileWriteAgent } from "@graphai/vanilla_node_agents";
6
+ import { recursiveSplitJa, replacementsJa, replacePairsJa } from "../utils/string.js";
7
+ import { getOutputStudioFilePath, mkdir, writingMessage } from "../utils/file.js";
8
+ const { default: __, ...vanillaAgents } = agents;
44
9
  const translateGraph = {
45
10
  version: 0.5,
46
11
  nodes: {
@@ -67,7 +32,8 @@ const translateGraph = {
67
32
  agent: "mapAgent",
68
33
  inputs: {
69
34
  targetLangs: ":targetLangs",
70
- rows: ":studio.beats",
35
+ studio: ":studio",
36
+ rows: ":studio.script.beats",
71
37
  lang: ":lang",
72
38
  },
73
39
  params: {
@@ -77,12 +43,23 @@ const translateGraph = {
77
43
  graph: {
78
44
  version: 0.5,
79
45
  nodes: {
46
+ studioBeat: {
47
+ agent: (namedInputs) => {
48
+ return namedInputs.rows[namedInputs.index];
49
+ },
50
+ inputs: {
51
+ index: ":__mapIndex",
52
+ rows: ":studio.beats",
53
+ },
54
+ },
80
55
  preprocessBeats: {
81
56
  agent: "mapAgent",
82
57
  inputs: {
83
58
  beat: ":beat",
59
+ studioBeat: ":studioBeat",
84
60
  rows: ":targetLangs",
85
61
  lang: ":lang.text",
62
+ studio: ":studio",
86
63
  },
87
64
  params: {
88
65
  compositeResult: true,
@@ -95,6 +72,7 @@ const translateGraph = {
95
72
  inputs: {
96
73
  targetLang: ":targetLang",
97
74
  beat: ":beat",
75
+ studioBeat: ":studioBeat",
98
76
  lang: ":lang",
99
77
  system: "Please translate the given text into the language specified in language (in locale format, like en, ja, fr, ch).",
100
78
  prompt: ["## Original Language", ":lang", "", "## Language", ":targetLang", "", "## Target", ":beat.text"],
@@ -118,7 +96,7 @@ const translateGraph = {
118
96
  if (targetLang === "ja") {
119
97
  return {
120
98
  ...localizedText,
121
- texts: (0, string_1.recursiveSplitJa)(localizedText.text),
99
+ texts: recursiveSplitJa(localizedText.text),
122
100
  };
123
101
  }
124
102
  // not split
@@ -143,7 +121,7 @@ const translateGraph = {
143
121
  if (targetLang === "ja") {
144
122
  return {
145
123
  ...localizedText,
146
- ttsTexts: localizedText?.texts?.map((text) => (0, string_1.replacePairsJa)(text, string_1.replacementsJa)),
124
+ ttsTexts: localizedText?.texts?.map((text) => replacePairsJa(text, replacementsJa)),
147
125
  };
148
126
  }
149
127
  return {
@@ -173,7 +151,7 @@ const translateGraph = {
173
151
  isResult: true,
174
152
  agent: "mergeObjectAgent",
175
153
  inputs: {
176
- items: [":beat", { multiLingualTexts: ":mergeLocalizedText" }],
154
+ items: [":studioBeat", { multiLingualTexts: ":mergeLocalizedText" }],
177
155
  },
178
156
  },
179
157
  },
@@ -191,14 +169,14 @@ const translateGraph = {
191
169
  };
192
170
  const localizedTextCacheAgentFilter = async (context, next) => {
193
171
  const { namedInputs } = context;
194
- const { targetLang, beat, lang } = namedInputs;
172
+ const { targetLang, beat, lang, studioBeat } = namedInputs;
195
173
  // The original text is unchanged and the target language text is present
196
- if (beat.multiLingualTexts &&
197
- beat.multiLingualTexts[lang] &&
198
- beat.multiLingualTexts[lang].text === beat.text &&
199
- beat.multiLingualTexts[targetLang] &&
200
- beat.multiLingualTexts[targetLang].text) {
201
- return { text: beat.multiLingualTexts[targetLang].text };
174
+ if (studioBeat.multiLingualTexts &&
175
+ studioBeat.multiLingualTexts[lang] &&
176
+ studioBeat.multiLingualTexts[lang].text === beat.text &&
177
+ studioBeat.multiLingualTexts[targetLang] &&
178
+ studioBeat.multiLingualTexts[targetLang].text) {
179
+ return { text: studioBeat.multiLingualTexts[targetLang].text };
202
180
  }
203
181
  // same language
204
182
  if (targetLang === lang) {
@@ -215,22 +193,21 @@ const agentFilters = [
215
193
  ];
216
194
  const defaultLang = "en";
217
195
  const targetLangs = ["ja", "en"];
218
- const translate = async (context) => {
196
+ export const translate = async (context) => {
219
197
  const { studio, fileDirs } = context;
220
198
  const { outDirPath } = fileDirs;
221
- const outputStudioFilePath = (0, file_1.getOutputStudioFilePath)(outDirPath, studio.filename);
222
- (0, file_1.mkdir)(outDirPath);
223
- (0, graphai_1.assert)(!!process.env.OPENAI_API_KEY, "The OPENAI_API_KEY environment variable is missing or empty");
224
- const graph = new graphai_1.GraphAI(translateGraph, { ...agents, fileWriteAgent: vanilla_node_agents_1.fileWriteAgent, openAIAgent: openai_agent_1.openAIAgent }, { agentFilters });
199
+ const outputStudioFilePath = getOutputStudioFilePath(outDirPath, studio.filename);
200
+ mkdir(outDirPath);
201
+ assert(!!process.env.OPENAI_API_KEY, "The OPENAI_API_KEY environment variable is missing or empty");
202
+ const graph = new GraphAI(translateGraph, { ...vanillaAgents, fileWriteAgent, openAIAgent }, { agentFilters });
225
203
  graph.injectValue("studio", studio);
226
204
  graph.injectValue("defaultLang", defaultLang);
227
205
  graph.injectValue("targetLangs", targetLangs);
228
206
  graph.injectValue("outDirPath", outDirPath);
229
207
  graph.injectValue("outputStudioFilePath", outputStudioFilePath);
230
208
  await graph.run();
231
- (0, file_1.writingMessage)(outputStudioFilePath);
209
+ writingMessage(outputStudioFilePath);
232
210
  // const results = await graph.run();
233
211
  // const mulmoDataResult = results.mergeResult;
234
212
  // console.log(JSON.stringify(mulmoDataResult, null, 2));
235
213
  };
236
- exports.translate = translate;
@@ -1,3 +1,3 @@
1
- import { AgentFunctionInfo } from "graphai";
1
+ import type { AgentFunctionInfo } from "graphai";
2
2
  declare const addBGMAgentInfo: AgentFunctionInfo;
3
3
  export default addBGMAgentInfo;
@@ -1,24 +1,20 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
7
- const methods_1 = require("../methods");
1
+ import { GraphAILogger } from "graphai";
2
+ import ffmpeg from "fluent-ffmpeg";
3
+ import { MulmoScriptMethods } from "../methods/index.js";
8
4
  const addBGMAgent = async ({ namedInputs, params, }) => {
9
5
  const { voiceFile, outputFile, script } = namedInputs;
10
6
  const { musicFile } = params;
11
7
  const promise = new Promise((resolve, reject) => {
12
- fluent_ffmpeg_1.default.ffprobe(voiceFile, (err, metadata) => {
8
+ ffmpeg.ffprobe(voiceFile, (err, metadata) => {
13
9
  if (err) {
14
- console.error("Error getting metadata: " + err.message);
10
+ GraphAILogger.info("Error getting metadata: " + err.message);
15
11
  reject(err);
16
12
  }
17
13
  const speechDuration = metadata.format.duration;
18
- const padding = methods_1.MulmoScriptMethods.getPadding(script);
14
+ const padding = MulmoScriptMethods.getPadding(script);
19
15
  const totalDuration = (padding * 2) / 1000 + Math.round(speechDuration ?? 0);
20
- console.log("totalDucation:", speechDuration, totalDuration);
21
- const command = (0, fluent_ffmpeg_1.default)();
16
+ GraphAILogger.log("totalDucation:", speechDuration, totalDuration);
17
+ const command = ffmpeg();
22
18
  command
23
19
  .input(musicFile)
24
20
  .input(voiceFile)
@@ -35,7 +31,7 @@ const addBGMAgent = async ({ namedInputs, params, }) => {
35
31
  `[trimmed]afade=t=out:st=${totalDuration - padding / 1000}:d=${padding}`,
36
32
  ])
37
33
  .on("error", (err) => {
38
- console.error("Error: " + err.message);
34
+ GraphAILogger.info("Error: " + err.message);
39
35
  reject(err);
40
36
  })
41
37
  .on("end", () => {
@@ -58,4 +54,4 @@ const addBGMAgentInfo = {
58
54
  repository: "https://github.com/snakajima/ai-podcaster",
59
55
  license: "MIT",
60
56
  };
61
- exports.default = addBGMAgentInfo;
57
+ export default addBGMAgentInfo;
@@ -0,0 +1,23 @@
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;
@@ -0,0 +1,162 @@
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,3 +1,3 @@
1
- import { AgentFunctionInfo } from "graphai";
1
+ import type { AgentFunctionInfo } from "graphai";
2
2
  declare const combineAudioFilesAgentInfo: AgentFunctionInfo;
3
3
  export default combineAudioFilesAgentInfo;
@@ -1,44 +1,45 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fluent_ffmpeg_1 = __importDefault(require("fluent-ffmpeg"));
7
- const file_1 = require("../utils/file");
8
- const methods_1 = require("../methods");
1
+ import { GraphAILogger } from "graphai";
2
+ import ffmpeg from "fluent-ffmpeg";
3
+ import { silentPath, silentLastPath } from "../utils/file.js";
9
4
  const combineAudioFilesAgent = async ({ namedInputs }) => {
10
- const { context, combinedFileName, scratchpadDirPath } = namedInputs;
11
- const command = (0, fluent_ffmpeg_1.default)();
12
- context.studio.beats.forEach((mulmoBeat, index) => {
13
- const audioPath = mulmoBeat.audio?.type === "audio" &&
14
- ((mulmoBeat.audio?.source.kind === "path" && methods_1.MulmoStudioContextMethods.resolveAssetPath(context, mulmoBeat.audio.source.path)) ||
15
- (mulmoBeat.audio?.source.kind === "url" && mulmoBeat.audio.source.url));
16
- const filePath = audioPath || (0, file_1.getScratchpadFilePath)(scratchpadDirPath, mulmoBeat.audioFile ?? "");
17
- const isLast = index === context.studio.beats.length - 2;
18
- command.input(filePath);
19
- command.input(isLast ? file_1.silentLastPath : file_1.silentPath);
20
- // Measure and log the timestamp of each section
21
- fluent_ffmpeg_1.default.ffprobe(filePath, (err, metadata) => {
22
- if (err) {
23
- console.error("Error while getting metadata:", err);
24
- }
25
- else {
26
- context.studio.beats[index]["duration"] = metadata.format.duration + (isLast ? 0.8 : 0.3);
27
- }
5
+ const { context, combinedFileName, audioDirPath } = namedInputs;
6
+ const command = ffmpeg();
7
+ const getDuration = (filePath, isLastGap) => {
8
+ return new Promise((resolve, reject) => {
9
+ ffmpeg.ffprobe(filePath, (err, metadata) => {
10
+ if (err) {
11
+ GraphAILogger.info("Error while getting metadata:", err);
12
+ reject(err);
13
+ }
14
+ else {
15
+ // TODO: Remove hard-coded 0.8 and 0.3
16
+ resolve(metadata.format.duration + (isLastGap ? 0.8 : 0.3));
17
+ }
18
+ });
28
19
  });
29
- });
30
- const promise = new Promise((resolve, reject) => {
20
+ };
21
+ await Promise.all(context.studio.beats.map(async (studioBeat, index) => {
22
+ const isLastGap = index === context.studio.beats.length - 2;
23
+ if (studioBeat.audioFile) {
24
+ command.input(studioBeat.audioFile);
25
+ command.input(isLastGap ? silentLastPath : silentPath);
26
+ studioBeat.duration = await getDuration(studioBeat.audioFile, isLastGap);
27
+ }
28
+ else {
29
+ GraphAILogger.error("Missing studioBeat.audioFile:", index);
30
+ }
31
+ }));
32
+ await new Promise((resolve, reject) => {
31
33
  command
32
34
  .on("end", () => {
33
35
  resolve(0);
34
36
  })
35
37
  .on("error", (err) => {
36
- console.error("Error while combining MP3 files:", err);
38
+ GraphAILogger.info("Error while combining MP3 files:", err);
37
39
  reject(err);
38
40
  })
39
- .mergeToFile(combinedFileName, scratchpadDirPath);
41
+ .mergeToFile(combinedFileName, audioDirPath);
40
42
  });
41
- await promise;
42
43
  return {
43
44
  studio: context.studio,
44
45
  };
@@ -54,4 +55,4 @@ const combineAudioFilesAgentInfo = {
54
55
  repository: "https://github.com/snakajima/ai-podcaster",
55
56
  license: "MIT",
56
57
  };
57
- exports.default = combineAudioFilesAgentInfo;
58
+ export default combineAudioFilesAgentInfo;
@@ -1,4 +1,4 @@
1
- import { AgentFunction, AgentFunctionInfo } from "graphai";
1
+ import type { AgentFunction, AgentFunctionInfo } from "graphai";
2
2
  export type ImageGoogleConfig = {
3
3
  projectId?: string;
4
4
  token?: string;
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageGoogleAgent = void 0;
1
+ import { GraphAILogger } from "graphai";
4
2
  async function generateImage(projectId, model, token, prompt, aspectRatio) {
5
3
  const GOOGLE_IMAGEN_ENDPOINT = `https://us-central1-aiplatform.googleapis.com/v1/projects/${projectId}/locations/us-central1/publishers/google/models/${model}:predict`;
6
4
  try {
@@ -43,16 +41,16 @@ async function generateImage(projectId, model, token, prompt, aspectRatio) {
43
41
  }
44
42
  else {
45
43
  // console.log(response);
46
- console.log("No predictions returned from the API.", responseData, prompt);
44
+ GraphAILogger.info("No predictions returned from the API.", responseData, prompt);
47
45
  return undefined;
48
46
  }
49
47
  }
50
48
  catch (error) {
51
- console.error("Error generating image:", error);
49
+ GraphAILogger.info("Error generating image:", error);
52
50
  throw error;
53
51
  }
54
52
  }
55
- const imageGoogleAgent = async ({ namedInputs, params, config, }) => {
53
+ export const imageGoogleAgent = async ({ namedInputs, params, config, }) => {
56
54
  const { prompt } = namedInputs;
57
55
  const aspectRatio = params.aspectRatio ?? "16:9";
58
56
  const model = params.model ?? "imagen-3.0-fast-generate-001";
@@ -67,15 +65,14 @@ const imageGoogleAgent = async ({ namedInputs, params, config, }) => {
67
65
  throw new Error("ERROR: geneateImage returned undefined");
68
66
  }
69
67
  catch (error) {
70
- console.error("Failed to generate image:", error);
68
+ GraphAILogger.info("Failed to generate image:", error);
71
69
  throw error;
72
70
  }
73
71
  };
74
- exports.imageGoogleAgent = imageGoogleAgent;
75
72
  const imageGoogleAgentInfo = {
76
73
  name: "imageGoogleAgent",
77
- agent: exports.imageGoogleAgent,
78
- mock: exports.imageGoogleAgent,
74
+ agent: imageGoogleAgent,
75
+ mock: imageGoogleAgent,
79
76
  samples: [],
80
77
  description: "Google Image agent",
81
78
  category: ["image"],
@@ -85,4 +82,4 @@ const imageGoogleAgentInfo = {
85
82
  license: "MIT",
86
83
  environmentVariables: [],
87
84
  };
88
- exports.default = imageGoogleAgentInfo;
85
+ export default imageGoogleAgentInfo;
@@ -1,20 +1,14 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.imageOpenaiAgent = void 0;
7
- const openai_1 = __importDefault(require("openai"));
1
+ import OpenAI from "openai";
8
2
  // https://platform.openai.com/docs/guides/image-generation
9
- const imageOpenaiAgent = async ({ namedInputs, params }) => {
3
+ export const imageOpenaiAgent = async ({ namedInputs, params }) => {
10
4
  const { prompt } = namedInputs;
11
5
  const { apiKey, model, size, moderation } = params;
12
- const openai = new openai_1.default({ apiKey });
6
+ const openai = new OpenAI({ apiKey });
13
7
  const imageOptions = {
14
8
  model: model ?? "dall-e-3",
15
9
  prompt,
16
10
  n: 1,
17
- size: size || "1792x1024",
11
+ size: size || model === "gpt-image-1" ? "1536x1024" : "1792x1024",
18
12
  };
19
13
  if (model === "gpt-image-1") {
20
14
  imageOptions.moderation = moderation || "auto";
@@ -42,11 +36,10 @@ const imageOpenaiAgent = async ({ namedInputs, params }) => {
42
36
  // 3. Convert the ArrayBuffer to a Node.js Buffer and return it along with url
43
37
  return { buffer: Buffer.from(arrayBuffer) };
44
38
  };
45
- exports.imageOpenaiAgent = imageOpenaiAgent;
46
39
  const imageOpenaiAgentInfo = {
47
40
  name: "imageOpenaiAgent",
48
- agent: exports.imageOpenaiAgent,
49
- mock: exports.imageOpenaiAgent,
41
+ agent: imageOpenaiAgent,
42
+ mock: imageOpenaiAgent,
50
43
  samples: [],
51
44
  description: "OpenAI Image agent",
52
45
  category: ["image"],
@@ -56,4 +49,4 @@ const imageOpenaiAgentInfo = {
56
49
  license: "MIT",
57
50
  environmentVariables: ["OPENAI_API_KEY"],
58
51
  };
59
- exports.default = imageOpenaiAgentInfo;
52
+ export default imageOpenaiAgentInfo;
@@ -1,11 +1,11 @@
1
- import addBGMAgent from "./add_bgm_agent";
2
- import combineAudioFilesAgent from "./combine_audio_files_agent";
3
- import imageGoogleAgent from "./image_google_agent";
4
- import imageOpenaiAgent from "./image_openai_agent";
5
- import mulmoPromptsAgent from "./mulmo_prompts_agent";
6
- import ttsNijivoiceAgent from "./tts_nijivoice_agent";
7
- import ttsOpenaiAgent from "./tts_openai_agent";
8
- import validateMulmoScriptAgent from "./validate_mulmo_script_agent";
1
+ import addBGMAgent from "./add_bgm_agent.js";
2
+ import combineAudioFilesAgent from "./combine_audio_files_agent.js";
3
+ import imageGoogleAgent from "./image_google_agent.js";
4
+ import imageOpenaiAgent from "./image_openai_agent.js";
5
+ import mulmoPromptsAgent from "./mulmo_prompts_agent.js";
6
+ import ttsNijivoiceAgent from "./tts_nijivoice_agent.js";
7
+ import ttsOpenaiAgent from "./tts_openai_agent.js";
8
+ import validateMulmoScriptAgent from "./validate_mulmo_script_agent.js";
9
9
  import { browserlessAgent } from "@graphai/browserless_agent";
10
10
  import { textInputAgent } from "@graphai/input_agents";
11
11
  import { openAIAgent } from "@graphai/openai_agent";