text
stringlengths
0
59.1k
## Expose Postgres as an agent tool
```ts
import { createTool, VoltOpsClient } from "@voltagent/core";
import { z } from "zod";
const voltops = new VoltOpsClient({
publicKey: process.env.VOLTAGENT_PUBLIC_KEY!,
secretKey: process.env.VOLTAGENT_SECRET_KEY!,
});
export const runPostgresQueryTool = createTool({
name: "runPostgresQuery",
description: "Run a parameterized SQL query against Postgres",
parameters: z.object({
query: z.string(),
parameters: z.array(z.any()).default([]),
}),
execute: async ({ query, parameters }) => {
const exec = await voltops.actions.postgres.executeQuery({
credential: { credentialId: process.env.POSTGRES_CREDENTIAL_ID! },
query,
parameters,
statementTimeoutMs: 20_000,
});
return {
actionId: exec.actionId,
rows: exec.responsePayload.rows,
metadata: exec.metadata,
};
},
});
```
Attach `runPostgresQuery` to any agent; the planner will call it when SQL is needed. VoltOps records the request/response so you can replay or debug failures in **Volt → Actions → Runs**.
## Testing payloads in the console
Open **Volt Console → Actions → Add Action → Postgres**. Pick your credential and use the **Payload & Test** editor. A sample payload is prefilled to list public tables:
```json
{
"query": "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name LIMIT 20;",
"parameters": []
}
```
Click **Run Test** to execute against your database; successful runs return rows plus a copy-ready SDK snippet.
## Troubleshooting
- **“unsupported startup parameter: statement_timeout”** – Volt sets `statement_timeout` after connecting (not as a startup param). If your server blocks `SET statement_timeout`, remove that field or lower the value.
- **SSL / self-signed certs** – set `ssl: true` and `ssl.rejectUnauthorized: false` if your instance uses self-signed certificates.
- **Long-running queries** – use `statementTimeoutMs` to avoid hanging agents; `connectionTimeoutMs` controls how long we wait to establish the socket.
- **Always parameterize** – pass values via `parameters: []` (`$1`, `$2`, …) instead of string concatenation to avoid SQL injection and to match the Postgres action schema.
<|endoftext|>
# source: VoltAgent__voltagent/website/actions-triggers-docs/actions/google-drive.md type: docs
# Google Drive Actions
VoltOps ships managed Google Drive actions so agents can list, download, upload, move, copy, delete,
and share files without manually signing requests or refreshing OAuth tokens.
## Prerequisites
1. Google Drive API enabled plus OAuth2 credentials (Volt managed app or your own). Provide
`accessToken` + `refreshToken` + client ID/secret, or pass a valid short-lived `accessToken`.
2. A Volt project with API keys (`pk_…`, `sk_…`).
3. Google Drive credential inside Volt: **Settings → Integrations → Add Credential → Google Drive**,
paste your OAuth values, and copy the returned `cred_xxx`.
4. (Recommended) Environment variables:
```bash
GOOGLE_DRIVE_CREDENTIAL_ID=cred_xxx
```
## Available actions
- `drive.listFiles` – list files/folders with search (`q`), ordering, pagination, and `includeTrashed`.
- `drive.getFileMetadata` – fetch metadata for a specific file.
- `drive.downloadFile` – download file content (base64 + content type).
- `drive.uploadFile` – upload binary or base64 content; supports parent folders.
- `drive.createFolder` – create a folder.
- `drive.moveFile` – move to a new parent (optionally remove previous parents).
- `drive.copyFile` – duplicate a file into another folder and/or name.
- `drive.deleteFile` – delete or move to trash depending on Drive settings.
- `drive.shareFilePublic` – create a public link (anyone with link can view).
## Running Google Drive actions from code
```ts
import { VoltOpsClient } from "@voltagent/core";
const voltops = new VoltOpsClient({
publicKey: process.env.VOLTAGENT_PUBLIC_KEY!,
secretKey: process.env.VOLTAGENT_SECRET_KEY!,
});