text
stringlengths
0
59.1k
if (url) {
await page.goto(url, { waitUntil: "networkidle" });
}
const outputDir = path.join(process.cwd(), "output", "screenshots");
await fs.mkdir(outputDir, { recursive: true });
const timestamp = Date.now();
const finalFilename = filename || `screenshot_${timestamp}.png`;
const filepath = path.join(outputDir, finalFilename);
let screenshot: Buffer;
if (selector) {
const element = await page.$(selector);
if (!element) {
throw new Error(`Element with selector "${selector}" not found`);
}
screenshot = await element.screenshot();
} else {
screenshot = await page.screenshot({ fullPage });
}
await fs.writeFile(filepath, screenshot);
// Persist filepath for downstream tools
context?.context.set("screenshotPath", filepath);
context?.context.set("screenshotFilename", finalFilename);
return {
success: true,
filepath,
filename: finalFilename,
url: page.url(),
fullPage,
selector,
};
},
});
```
</details>
Features:
- Full page or viewport screenshots
- Element-specific captures via CSS selectors
- Automatic output directory saving
- Context sharing with other tools
- Reference images for Gemini generation
### Google Gemini Image Generation Tool
Orchestrates image generation pipeline:
<details>
<summary>Show instagram-ad-gemini.tool.ts</summary>
```typescript
import { Agent, createTool } from "@voltagent/core";
import { z } from "zod";
import { google } from "@ai-sdk/google";
import sharp from "sharp";
import * as fs from "fs/promises";
import * as path from "path";
const creativeBriefAgent = new Agent({
name: "GeminiCreativeBrief",
purpose: "Transform product information into rich Instagram creative direction",
instructions:
"You take raw product inputs and return an inspiring creative direction for an Instagram ad.",
model: google("gemini-2.0-flash-exp"),
});
const imageGenerationAgent = new Agent({
name: "GeminiImageGenerator",
purpose: "Generate high-converting Instagram visuals",
instructions:
"You receive fully prepared prompts and return the best possible Instagram-ready visual output.",
model: google("gemini-2.5-flash-image-preview"),
});
export const generateInstagramAdGeminiTool = createTool({
name: "generate_instagram_ad_gemini",
description:
"Generate a square Instagram ad image using Google Gemini with optional landing page reference",
parameters: z.object({
productName: z.string().describe("The product or brand name"),
tagline: z.string().describe("The main tagline or value proposition"),
adConcept: z.string().describe("Creative concept for the ad"),
style: z.string().optional().default("modern and professional").describe("Visual style"),
targetAudience: z.string().optional().describe("Target audience description"),
}),
execute: async ({ productName, tagline, adConcept, style, targetAudience }, context) => {
const outputDir = path.join(process.cwd(), "output", "ads", "instagram");
await fs.mkdir(outputDir, { recursive: true });
// First, generate creative brief
const { text: adDescription } = await creativeBriefAgent.generateText(