@fre4x/gemini 1.0.50 → 1.0.51

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 (2) hide show
  1. package/dist/index.js +86 -53
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -67583,6 +67583,10 @@ var ANALYZE_MEDIA_TOOL = {
67583
67583
  type: "string",
67584
67584
  default: DEFAULT_TEXT_MODEL,
67585
67585
  description: "Gemini model to use for analysis."
67586
+ },
67587
+ output_dir: {
67588
+ type: "string",
67589
+ description: "Optional directory to save the analysis result as a .txt file."
67586
67590
  }
67587
67591
  },
67588
67592
  required: ["media_source"]
@@ -67772,14 +67776,15 @@ async function analyzeMedia(rawArgs) {
67772
67776
  prompt: z3.string().min(1).default("Describe this media."),
67773
67777
  media_source: z3.string().min(1),
67774
67778
  mime_type: z3.string().optional(),
67775
- model: z3.string().optional().default(DEFAULT_TEXT_MODEL)
67779
+ model: z3.string().optional().default(DEFAULT_TEXT_MODEL),
67780
+ output_dir: z3.string().optional()
67776
67781
  }).strict(),
67777
67782
  rawArgs
67778
67783
  );
67779
67784
  if (!parsed.success) {
67780
67785
  return parsed.error;
67781
67786
  }
67782
- const { prompt, media_source, mime_type, model } = parsed.data;
67787
+ const { prompt, media_source, mime_type, model, output_dir } = parsed.data;
67783
67788
  let media;
67784
67789
  try {
67785
67790
  media = await resolveMediaSource(media_source, mime_type);
@@ -67789,34 +67794,46 @@ async function analyzeMedia(rawArgs) {
67789
67794
  error48 instanceof Error ? error48.message : String(error48)
67790
67795
  );
67791
67796
  }
67797
+ let responseText;
67792
67798
  if (IS_MOCK) {
67793
- return textResult(
67794
- `[Mock] Analyzed media (${media.mimeType})
67799
+ responseText = `[Mock] Analyzed media (${media.mimeType})
67795
67800
  Source: ${media.label}
67796
67801
  Prompt: "${prompt}"
67797
67802
  Model: ${model}
67798
67803
 
67799
- Mock response \u2014 no API call made.`
67804
+ Mock response \u2014 no API call made.`;
67805
+ } else {
67806
+ const response = await getAi().models.generateContent({
67807
+ model,
67808
+ contents: [
67809
+ {
67810
+ role: "user",
67811
+ parts: [
67812
+ { text: prompt },
67813
+ {
67814
+ inlineData: {
67815
+ data: media.data,
67816
+ mimeType: media.mimeType
67817
+ }
67818
+ }
67819
+ ]
67820
+ }
67821
+ ]
67822
+ });
67823
+ responseText = response.text || "No analysis generated.";
67824
+ }
67825
+ if (output_dir) {
67826
+ const fname = `analysis-${Date.now()}.txt`;
67827
+ const fpath = path2.join(output_dir, fname);
67828
+ await fs3.mkdir(output_dir, { recursive: true });
67829
+ await fs3.writeFile(fpath, responseText);
67830
+ return textResult(
67831
+ `${responseText}
67832
+
67833
+ \u2705 Analysis result saved to: ${fpath}`
67800
67834
  );
67801
67835
  }
67802
- const response = await getAi().models.generateContent({
67803
- model,
67804
- contents: [
67805
- {
67806
- role: "user",
67807
- parts: [
67808
- { text: prompt },
67809
- {
67810
- inlineData: {
67811
- data: media.data,
67812
- mimeType: media.mimeType
67813
- }
67814
- }
67815
- ]
67816
- }
67817
- ]
67818
- });
67819
- return textResult(response.text || "No analysis generated.");
67836
+ return textResult(responseText);
67820
67837
  }
67821
67838
  async function listModels(rawArgs) {
67822
67839
  const parsed = parseArgs(
@@ -68022,24 +68039,21 @@ async function getVideoStatus(rawArgs) {
68022
68039
  return parsed.error;
68023
68040
  }
68024
68041
  const { operation_name, output_dir } = parsed.data;
68042
+ let op;
68025
68043
  if (IS_MOCK) {
68026
- const lines2 = [
68027
- `[Mock] Operation: ${operation_name}`,
68028
- "done: true",
68029
- "Video URL: https://example.com/mock-video.mp4"
68030
- ];
68031
- if (output_dir) {
68032
- const fname = `video-${Date.now()}.mp4`;
68033
- const fpath = path2.join(output_dir, fname);
68034
- await fs3.mkdir(output_dir, { recursive: true });
68035
- await fs3.writeFile(fpath, "[mock video data]");
68036
- lines2.push(`Saved to: ${fpath}`);
68037
- }
68038
- return textResult(lines2.join("\n"));
68044
+ op = {
68045
+ done: true,
68046
+ response: {
68047
+ generatedVideos: [
68048
+ { video: { uri: "https://example.com/mock-video.mp4" } }
68049
+ ]
68050
+ }
68051
+ };
68052
+ } else {
68053
+ op = await getAi().operations.getVideosOperation({
68054
+ operation: createVideoOperation(operation_name)
68055
+ });
68039
68056
  }
68040
- const op = await getAi().operations.getVideosOperation({
68041
- operation: createVideoOperation(operation_name)
68042
- });
68043
68057
  if (!op.done) {
68044
68058
  return textResult(
68045
68059
  `Operation ${operation_name} is still in progress. Check back in ~30 seconds.`
@@ -68064,25 +68078,39 @@ ${JSON.stringify(op.response, null, 2)}`
68064
68078
  );
68065
68079
  }
68066
68080
  const savedPaths = [];
68067
- if (output_dir) {
68068
- await fs3.mkdir(output_dir, { recursive: true });
68069
- const paths = await Promise.all(
68070
- videos.map(async (url2, index) => {
68071
- const fname = `video-${Date.now()}-${index + 1}.mp4`;
68072
- const fpath = path2.join(output_dir, fname);
68081
+ const videoContents = [];
68082
+ await Promise.all(
68083
+ videos.map(async (url2, index) => {
68084
+ let buffer;
68085
+ if (IS_MOCK) {
68086
+ buffer = Buffer.from("[mock video data]");
68087
+ } else {
68073
68088
  const videoResp = await fetch(withApiKey(url2));
68074
68089
  if (!videoResp.ok) {
68075
68090
  throw new Error(
68076
68091
  `Failed to download video: ${videoResp.status}`
68077
68092
  );
68078
68093
  }
68079
- const buf = await videoResp.arrayBuffer();
68080
- await fs3.writeFile(fpath, Buffer.from(buf));
68081
- return fpath;
68082
- })
68083
- );
68084
- savedPaths.push(...paths);
68085
- }
68094
+ const arrayBuffer = await videoResp.arrayBuffer();
68095
+ buffer = Buffer.from(arrayBuffer);
68096
+ }
68097
+ videoContents.push({
68098
+ type: "resource",
68099
+ resource: {
68100
+ uri: url2,
68101
+ mimeType: "video/mp4",
68102
+ blob: buffer.toString("base64")
68103
+ }
68104
+ });
68105
+ if (output_dir) {
68106
+ const fname = `video-${Date.now()}-${index + 1}.mp4`;
68107
+ const fpath = path2.join(output_dir, fname);
68108
+ await fs3.mkdir(output_dir, { recursive: true });
68109
+ await fs3.writeFile(fpath, buffer);
68110
+ savedPaths.push(fpath);
68111
+ }
68112
+ })
68113
+ );
68086
68114
  const lines = [
68087
68115
  `Video generation complete!
68088
68116
 
@@ -68094,7 +68122,12 @@ ${videos.join("\n")}`
68094
68122
  Saved to:
68095
68123
  ${savedPaths.join("\n")}`);
68096
68124
  }
68097
- return textResult(lines.join(""));
68125
+ return {
68126
+ content: [
68127
+ { type: "text", text: lines.join("") },
68128
+ ...videoContents
68129
+ ]
68130
+ };
68098
68131
  }
68099
68132
  async function handleToolCall(name, args) {
68100
68133
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fre4x/gemini",
3
- "version": "1.0.50",
3
+ "version": "1.0.51",
4
4
  "description": "A Gemini MCP server providing multimodal analysis and image/video generation.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",