text stringlengths 0 59.1k |
|---|
import * as fs from "fs/promises"; |
import * as path from "path"; |
export const screenshotTool = createTool({ |
name: "take_screenshot", |
description: "Take a screenshot of the current page or a specific element", |
parameters: z.object({ |
url: z.string().url().optional().describe("URL to navigate to (optional if already on a page)"), |
fullPage: z.boolean().optional().default(false).describe("Whether to capture the full page"), |
selector: z.string().optional().describe("CSS selector for specific element to capture"), |
filename: z.string().optional().describe("Custom filename for the screenshot"), |
}), |
execute: async ({ url, fullPage, selector, filename }, context) => { |
const stagehand = await sessionManager.ensureStagehand(); |
const page = stagehand.page; |
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", |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.