@fre4x/gemini 1.0.25 → 1.0.26
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/dist/index.js +74 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -55417,7 +55417,7 @@ var LIST_MODELS_TOOL = {
|
|
|
55417
55417
|
};
|
|
55418
55418
|
var GENERATE_IMAGE_TOOL = {
|
|
55419
55419
|
name: "generate_image",
|
|
55420
|
-
description: "Generate an image using Imagen and
|
|
55420
|
+
description: "Generate an image using Imagen, return as base64 and optionally save to disk",
|
|
55421
55421
|
inputSchema: {
|
|
55422
55422
|
type: "object",
|
|
55423
55423
|
properties: {
|
|
@@ -55431,6 +55431,10 @@ var GENERATE_IMAGE_TOOL = {
|
|
|
55431
55431
|
type: "string",
|
|
55432
55432
|
description: "Imagen model (default: imagen-3.0-generate-002)",
|
|
55433
55433
|
default: "imagen-3.0-generate-002"
|
|
55434
|
+
},
|
|
55435
|
+
output_dir: {
|
|
55436
|
+
type: "string",
|
|
55437
|
+
description: "Directory to save image file (e.g. /tmp or ./output). Omit to skip saving."
|
|
55434
55438
|
}
|
|
55435
55439
|
},
|
|
55436
55440
|
required: ["prompt"]
|
|
@@ -55454,13 +55458,17 @@ var GENERATE_VIDEO_TOOL = {
|
|
|
55454
55458
|
};
|
|
55455
55459
|
var GET_VIDEO_STATUS_TOOL = {
|
|
55456
55460
|
name: "get_video_status",
|
|
55457
|
-
description: "Poll
|
|
55461
|
+
description: "Poll status of async video generation. Returns done=true and video URLs when complete. Optionally downloads and saves to disk.",
|
|
55458
55462
|
inputSchema: {
|
|
55459
55463
|
type: "object",
|
|
55460
55464
|
properties: {
|
|
55461
55465
|
operation_name: {
|
|
55462
55466
|
type: "string",
|
|
55463
55467
|
description: "Operation name returned by generate_video"
|
|
55468
|
+
},
|
|
55469
|
+
output_dir: {
|
|
55470
|
+
type: "string",
|
|
55471
|
+
description: "Directory to save video file when done (e.g. /tmp or ./output). Omit to skip saving."
|
|
55464
55472
|
}
|
|
55465
55473
|
},
|
|
55466
55474
|
required: ["operation_name"]
|
|
@@ -55575,15 +55583,25 @@ Mock response \u2014 no API call made.` }] };
|
|
|
55575
55583
|
return { content: [{ type: "text", text: lines.join("\n").trim() || "No models found." }] };
|
|
55576
55584
|
}
|
|
55577
55585
|
if (name === "generate_image") {
|
|
55578
|
-
const { prompt, aspect_ratio = "1:1", model = "imagen-3.0-generate-002" } = z2.object({
|
|
55586
|
+
const { prompt, aspect_ratio = "1:1", model = "imagen-3.0-generate-002", output_dir } = z2.object({
|
|
55579
55587
|
prompt: z2.string(),
|
|
55580
55588
|
aspect_ratio: z2.string().optional(),
|
|
55581
|
-
model: z2.string().optional()
|
|
55589
|
+
model: z2.string().optional(),
|
|
55590
|
+
output_dir: z2.string().optional()
|
|
55582
55591
|
}).parse(args);
|
|
55583
55592
|
if (IS_MOCK) {
|
|
55584
|
-
|
|
55585
|
-
|
|
55586
|
-
|
|
55593
|
+
const mockBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
55594
|
+
const content2 = [
|
|
55595
|
+
{ type: "image", data: mockBase64, mimeType: "image/png" }
|
|
55596
|
+
];
|
|
55597
|
+
if (output_dir) {
|
|
55598
|
+
const fname = `image-${Date.now()}.png`;
|
|
55599
|
+
const fpath = `${output_dir.replace(/\/$/, "")}/${fname}`;
|
|
55600
|
+
await fs.mkdir(output_dir, { recursive: true });
|
|
55601
|
+
await fs.writeFile(fpath, Buffer.from(mockBase64, "base64"));
|
|
55602
|
+
content2.push({ type: "text", text: `[Mock] Saved to: ${fpath}` });
|
|
55603
|
+
}
|
|
55604
|
+
return { content: content2 };
|
|
55587
55605
|
}
|
|
55588
55606
|
const response = await ai.models.generateImages({
|
|
55589
55607
|
model,
|
|
@@ -55606,7 +55624,22 @@ Check Imagen access at https://ai.google.dev/` }],
|
|
|
55606
55624
|
isError: true
|
|
55607
55625
|
};
|
|
55608
55626
|
}
|
|
55609
|
-
|
|
55627
|
+
const savedPaths = [];
|
|
55628
|
+
if (output_dir) {
|
|
55629
|
+
await fs.mkdir(output_dir, { recursive: true });
|
|
55630
|
+
for (const img of images) {
|
|
55631
|
+
const fname = `image-${Date.now()}-${savedPaths.length + 1}.png`;
|
|
55632
|
+
const fpath = `${output_dir.replace(/\/$/, "")}/${fname}`;
|
|
55633
|
+
await fs.writeFile(fpath, Buffer.from(img.data, "base64"));
|
|
55634
|
+
savedPaths.push(fpath);
|
|
55635
|
+
}
|
|
55636
|
+
}
|
|
55637
|
+
const content = [...images];
|
|
55638
|
+
if (savedPaths.length > 0) {
|
|
55639
|
+
content.push({ type: "text", text: `Saved to:
|
|
55640
|
+
${savedPaths.join("\n")}` });
|
|
55641
|
+
}
|
|
55642
|
+
return { content };
|
|
55610
55643
|
}
|
|
55611
55644
|
if (name === "generate_video") {
|
|
55612
55645
|
const { prompt, model = "veo-2.0-generate-001" } = z2.object({ prompt: z2.string(), model: z2.string().optional() }).parse(args);
|
|
@@ -55630,11 +55663,17 @@ Poll every ~30 seconds until done=true.` }]
|
|
|
55630
55663
|
};
|
|
55631
55664
|
}
|
|
55632
55665
|
if (name === "get_video_status") {
|
|
55633
|
-
const { operation_name } = z2.object({ operation_name: z2.string() }).parse(args);
|
|
55666
|
+
const { operation_name, output_dir } = z2.object({ operation_name: z2.string(), output_dir: z2.string().optional() }).parse(args);
|
|
55634
55667
|
if (IS_MOCK) {
|
|
55635
|
-
|
|
55636
|
-
|
|
55637
|
-
|
|
55668
|
+
const lines2 = [`[Mock] Operation: ${operation_name}`, "done: true", "Video URL: https://example.com/mock-video.mp4"];
|
|
55669
|
+
if (output_dir) {
|
|
55670
|
+
const fname = `video-${Date.now()}.mp4`;
|
|
55671
|
+
const fpath = `${output_dir.replace(/\/$/, "")}/${fname}`;
|
|
55672
|
+
await fs.mkdir(output_dir, { recursive: true });
|
|
55673
|
+
await fs.writeFile(fpath, "[mock video data]");
|
|
55674
|
+
lines2.push(`Saved to: ${fpath}`);
|
|
55675
|
+
}
|
|
55676
|
+
return { content: [{ type: "text", text: lines2.join("\n") }] };
|
|
55638
55677
|
}
|
|
55639
55678
|
const resp = await fetch(
|
|
55640
55679
|
`https://generativelanguage.googleapis.com/v1beta/${operation_name}?key=${API_KEY}`
|
|
@@ -55651,16 +55690,31 @@ Video URL: https://example.com/mock-video.mp4` }] };
|
|
|
55651
55690
|
};
|
|
55652
55691
|
}
|
|
55653
55692
|
const videos = (op.response?.generatedVideos ?? []).map((v) => v.video?.uri ?? "").filter(Boolean);
|
|
55654
|
-
|
|
55655
|
-
content: [{
|
|
55656
|
-
|
|
55657
|
-
|
|
55693
|
+
if (videos.length === 0) {
|
|
55694
|
+
return { content: [{ type: "text", text: `Complete but no video URLs found:
|
|
55695
|
+
${JSON.stringify(op.response, null, 2)}` }] };
|
|
55696
|
+
}
|
|
55697
|
+
const savedPaths = [];
|
|
55698
|
+
if (output_dir) {
|
|
55699
|
+
await fs.mkdir(output_dir, { recursive: true });
|
|
55700
|
+
for (const url2 of videos) {
|
|
55701
|
+
const fname = `video-${Date.now()}-${savedPaths.length + 1}.mp4`;
|
|
55702
|
+
const fpath = `${output_dir.replace(/\/$/, "")}/${fname}`;
|
|
55703
|
+
const videoResp = await fetch(url2);
|
|
55704
|
+
if (!videoResp.ok) throw new Error(`Failed to download video: ${videoResp.status}`);
|
|
55705
|
+
const buf = await videoResp.arrayBuffer();
|
|
55706
|
+
await fs.writeFile(fpath, Buffer.from(buf));
|
|
55707
|
+
savedPaths.push(fpath);
|
|
55708
|
+
}
|
|
55709
|
+
}
|
|
55710
|
+
const lines = [`Video generation complete!
|
|
55658
55711
|
|
|
55659
55712
|
Download URLs:
|
|
55660
|
-
${videos.join("\n")}`
|
|
55661
|
-
|
|
55662
|
-
|
|
55663
|
-
|
|
55713
|
+
${videos.join("\n")}`];
|
|
55714
|
+
if (savedPaths.length > 0) lines.push(`
|
|
55715
|
+
Saved to:
|
|
55716
|
+
${savedPaths.join("\n")}`);
|
|
55717
|
+
return { content: [{ type: "text", text: lines.join("") }] };
|
|
55664
55718
|
}
|
|
55665
55719
|
throw new Error(`Tool not found: ${name}`);
|
|
55666
55720
|
} catch (error48) {
|