@fre4x/gemini 1.0.50 → 1.0.52
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 +135 -73
- 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,54 @@ 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
|
-
|
|
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
|
|
67800
|
-
|
|
67801
|
-
|
|
67802
|
-
|
|
67803
|
-
|
|
67804
|
-
|
|
67805
|
-
|
|
67806
|
-
|
|
67807
|
-
|
|
67808
|
-
|
|
67809
|
-
|
|
67810
|
-
|
|
67811
|
-
|
|
67812
|
-
|
|
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
|
+
}
|
|
67813
67818
|
}
|
|
67814
|
-
|
|
67815
|
-
|
|
67816
|
-
|
|
67817
|
-
|
|
67818
|
-
|
|
67819
|
-
|
|
67819
|
+
]
|
|
67820
|
+
}
|
|
67821
|
+
]
|
|
67822
|
+
});
|
|
67823
|
+
responseText = response.text || "No analysis generated.";
|
|
67824
|
+
}
|
|
67825
|
+
if (output_dir) {
|
|
67826
|
+
try {
|
|
67827
|
+
const fname = `analysis-${Date.now()}.txt`;
|
|
67828
|
+
const fpath = path2.join(output_dir, fname);
|
|
67829
|
+
await fs3.mkdir(output_dir, { recursive: true });
|
|
67830
|
+
await fs3.writeFile(fpath, responseText);
|
|
67831
|
+
return textResult(
|
|
67832
|
+
`${responseText}
|
|
67833
|
+
|
|
67834
|
+
\u2705 Analysis result saved to: ${fpath}`
|
|
67835
|
+
);
|
|
67836
|
+
} catch (error48) {
|
|
67837
|
+
return textResult(
|
|
67838
|
+
`${responseText}
|
|
67839
|
+
|
|
67840
|
+
\u26A0\uFE0F Failed to save analysis result: ${error48.message}`
|
|
67841
|
+
);
|
|
67842
|
+
}
|
|
67843
|
+
}
|
|
67844
|
+
return textResult(responseText);
|
|
67820
67845
|
}
|
|
67821
67846
|
async function listModels(rawArgs) {
|
|
67822
67847
|
const parsed = parseArgs(
|
|
@@ -67901,14 +67926,21 @@ async function generateImage(rawArgs) {
|
|
|
67901
67926
|
{ type: "image", data: mockBase64, mimeType: "image/png" }
|
|
67902
67927
|
];
|
|
67903
67928
|
if (output_dir) {
|
|
67904
|
-
|
|
67905
|
-
|
|
67906
|
-
|
|
67907
|
-
|
|
67908
|
-
|
|
67909
|
-
|
|
67910
|
-
|
|
67911
|
-
|
|
67929
|
+
try {
|
|
67930
|
+
const fname = `image-${Date.now()}.png`;
|
|
67931
|
+
const fpath = path2.join(output_dir, fname);
|
|
67932
|
+
await fs3.mkdir(output_dir, { recursive: true });
|
|
67933
|
+
await fs3.writeFile(fpath, Buffer.from(mockBase64, "base64"));
|
|
67934
|
+
content2.push({
|
|
67935
|
+
type: "text",
|
|
67936
|
+
text: `[Mock] Saved to: ${fpath}`
|
|
67937
|
+
});
|
|
67938
|
+
} catch (error48) {
|
|
67939
|
+
content2.push({
|
|
67940
|
+
type: "text",
|
|
67941
|
+
text: `\u26A0\uFE0F [Mock] Failed to save image: ${error48.message}`
|
|
67942
|
+
});
|
|
67943
|
+
}
|
|
67912
67944
|
}
|
|
67913
67945
|
return { content: content2 };
|
|
67914
67946
|
}
|
|
@@ -67939,24 +67971,31 @@ Check Imagen access at https://ai.google.dev/`
|
|
|
67939
67971
|
};
|
|
67940
67972
|
}
|
|
67941
67973
|
const savedPaths = [];
|
|
67974
|
+
let saveErrorText = "";
|
|
67942
67975
|
if (output_dir) {
|
|
67943
|
-
|
|
67944
|
-
|
|
67945
|
-
|
|
67946
|
-
|
|
67947
|
-
|
|
67948
|
-
|
|
67949
|
-
|
|
67950
|
-
|
|
67951
|
-
|
|
67952
|
-
|
|
67976
|
+
try {
|
|
67977
|
+
await fs3.mkdir(output_dir, { recursive: true });
|
|
67978
|
+
const paths = await Promise.all(
|
|
67979
|
+
images.map(async (img, index) => {
|
|
67980
|
+
const fname = `image-${Date.now()}-${index + 1}.png`;
|
|
67981
|
+
const fpath = path2.join(output_dir, fname);
|
|
67982
|
+
await fs3.writeFile(fpath, Buffer.from(img.data, "base64"));
|
|
67983
|
+
return fpath;
|
|
67984
|
+
})
|
|
67985
|
+
);
|
|
67986
|
+
savedPaths.push(...paths);
|
|
67987
|
+
} catch (error48) {
|
|
67988
|
+
saveErrorText = `
|
|
67989
|
+
|
|
67990
|
+
\u26A0\uFE0F Failed to save images: ${error48.message}`;
|
|
67991
|
+
}
|
|
67953
67992
|
}
|
|
67954
67993
|
const content = [
|
|
67955
67994
|
{
|
|
67956
67995
|
type: "text",
|
|
67957
67996
|
text: `\u2705 Image generated successfully (${images.length} image${images.length > 1 ? "s" : ""}, prompt: "${prompt}").${savedPaths.length > 0 ? `
|
|
67958
67997
|
Saved to:
|
|
67959
|
-
${savedPaths.join("\n")}` : ""}`
|
|
67998
|
+
${savedPaths.join("\n")}` : ""}${saveErrorText}`
|
|
67960
67999
|
},
|
|
67961
68000
|
...images
|
|
67962
68001
|
];
|
|
@@ -68022,24 +68061,21 @@ async function getVideoStatus(rawArgs) {
|
|
|
68022
68061
|
return parsed.error;
|
|
68023
68062
|
}
|
|
68024
68063
|
const { operation_name, output_dir } = parsed.data;
|
|
68064
|
+
let op;
|
|
68025
68065
|
if (IS_MOCK) {
|
|
68026
|
-
|
|
68027
|
-
|
|
68028
|
-
|
|
68029
|
-
|
|
68030
|
-
|
|
68031
|
-
|
|
68032
|
-
|
|
68033
|
-
|
|
68034
|
-
|
|
68035
|
-
|
|
68036
|
-
|
|
68037
|
-
}
|
|
68038
|
-
return textResult(lines2.join("\n"));
|
|
68066
|
+
op = {
|
|
68067
|
+
done: true,
|
|
68068
|
+
response: {
|
|
68069
|
+
generatedVideos: [
|
|
68070
|
+
{ video: { uri: "https://example.com/mock-video.mp4" } }
|
|
68071
|
+
]
|
|
68072
|
+
}
|
|
68073
|
+
};
|
|
68074
|
+
} else {
|
|
68075
|
+
op = await getAi().operations.getVideosOperation({
|
|
68076
|
+
operation: createVideoOperation(operation_name)
|
|
68077
|
+
});
|
|
68039
68078
|
}
|
|
68040
|
-
const op = await getAi().operations.getVideosOperation({
|
|
68041
|
-
operation: createVideoOperation(operation_name)
|
|
68042
|
-
});
|
|
68043
68079
|
if (!op.done) {
|
|
68044
68080
|
return textResult(
|
|
68045
68081
|
`Operation ${operation_name} is still in progress. Check back in ~30 seconds.`
|
|
@@ -68064,25 +68100,43 @@ ${JSON.stringify(op.response, null, 2)}`
|
|
|
68064
68100
|
);
|
|
68065
68101
|
}
|
|
68066
68102
|
const savedPaths = [];
|
|
68067
|
-
|
|
68068
|
-
|
|
68069
|
-
|
|
68070
|
-
|
|
68071
|
-
|
|
68072
|
-
|
|
68103
|
+
const videoContents = [];
|
|
68104
|
+
await Promise.all(
|
|
68105
|
+
videos.map(async (url2, index) => {
|
|
68106
|
+
let buffer;
|
|
68107
|
+
if (IS_MOCK) {
|
|
68108
|
+
buffer = Buffer.from("[mock video data]");
|
|
68109
|
+
} else {
|
|
68073
68110
|
const videoResp = await fetch(withApiKey(url2));
|
|
68074
68111
|
if (!videoResp.ok) {
|
|
68075
68112
|
throw new Error(
|
|
68076
68113
|
`Failed to download video: ${videoResp.status}`
|
|
68077
68114
|
);
|
|
68078
68115
|
}
|
|
68079
|
-
const
|
|
68080
|
-
|
|
68081
|
-
|
|
68082
|
-
|
|
68083
|
-
|
|
68084
|
-
|
|
68085
|
-
|
|
68116
|
+
const arrayBuffer = await videoResp.arrayBuffer();
|
|
68117
|
+
buffer = Buffer.from(arrayBuffer);
|
|
68118
|
+
}
|
|
68119
|
+
videoContents.push({
|
|
68120
|
+
type: "resource",
|
|
68121
|
+
resource: {
|
|
68122
|
+
uri: url2,
|
|
68123
|
+
mimeType: "video/mp4",
|
|
68124
|
+
blob: buffer.toString("base64")
|
|
68125
|
+
}
|
|
68126
|
+
});
|
|
68127
|
+
if (output_dir) {
|
|
68128
|
+
try {
|
|
68129
|
+
const fname = `video-${Date.now()}-${index + 1}.mp4`;
|
|
68130
|
+
const fpath = path2.join(output_dir, fname);
|
|
68131
|
+
await fs3.mkdir(output_dir, { recursive: true });
|
|
68132
|
+
await fs3.writeFile(fpath, buffer);
|
|
68133
|
+
savedPaths.push(fpath);
|
|
68134
|
+
} catch (error48) {
|
|
68135
|
+
console.error(`Failed to save video: ${error48.message}`);
|
|
68136
|
+
}
|
|
68137
|
+
}
|
|
68138
|
+
})
|
|
68139
|
+
);
|
|
68086
68140
|
const lines = [
|
|
68087
68141
|
`Video generation complete!
|
|
68088
68142
|
|
|
@@ -68093,8 +68147,16 @@ ${videos.join("\n")}`
|
|
|
68093
68147
|
lines.push(`
|
|
68094
68148
|
Saved to:
|
|
68095
68149
|
${savedPaths.join("\n")}`);
|
|
68150
|
+
} else if (output_dir) {
|
|
68151
|
+
lines.push(`
|
|
68152
|
+
\u26A0\uFE0F Failed to save videos to disk.`);
|
|
68096
68153
|
}
|
|
68097
|
-
return
|
|
68154
|
+
return {
|
|
68155
|
+
content: [
|
|
68156
|
+
{ type: "text", text: lines.join("") },
|
|
68157
|
+
...videoContents
|
|
68158
|
+
]
|
|
68159
|
+
};
|
|
68098
68160
|
}
|
|
68099
68161
|
async function handleToolCall(name, args) {
|
|
68100
68162
|
try {
|