AgentSkillsCN

vercel-blob

为您的机器人添加 Vercel Blob 存储,用于持久化状态、对话记录与日志。该方案采用存储于 Vercel 对象存储中的 JSON 文件,特别适合那些需要在沙盒重启后仍能记忆状态的机器人。

SKILL.md
--- frontmatter
name: vercel-blob
description: Add Vercel Blob storage to your bot for persistent state, conversations, and logs. Uses JSON files stored in Vercel's object storage. Perfect for bots that need to remember state across sandbox restarts.
metadata:
  author: b-open-io
  version: "0.0.1"
  supports: [agent, bot]

Vercel Blob Storage

This skill adds Vercel Blob storage to your bot for persistent data across sandbox restarts.

Storage Strategy

Data is organized by bot name:

code
bots/{bot-name}/
├── state.json              # Bot state (counters, config, etc.)
├── config.json             # Bot configuration
├── conversations/
│   ├── {session-id}.json   # Individual conversation sessions
│   └── ...
└── logs/
    └── {YYYY-MM-DD}.json   # Daily log files

Setup

Run the setup script:

bash
./skills/vercel-blob/scripts/setup.sh

This creates a Vercel Blob store for your bot.

API Endpoints

Once added, your bot gets these endpoints:

State Management

  • GET /api/storage/state - Load current state
  • POST /api/storage/state - Save state

Conversations

  • GET /api/storage/conversations - List all conversations
  • GET /api/storage/conversations/:id - Load specific conversation
  • POST /api/storage/conversations/:id - Save conversation

Logs

  • POST /api/storage/log - Append log entry
  • GET /api/storage/logs - Get recent logs

Usage from Bot Code

typescript
// Save bot state
await fetch('/api/storage/state', {
  method: 'POST',
  body: JSON.stringify({ 
    lastRun: Date.now(),
    counter: 42,
    config: { theme: 'dark' }
  })
});

// Load state
const state = await fetch('/api/storage/state').then(r => r.json());

// Log activity
await fetch('/api/storage/log', {
  method: 'POST',
  body: JSON.stringify({
    level: 'info',
    message: 'Bot started',
    metadata: { version: '1.0.0' }
  })
});

// Save conversation
await fetch('/api/storage/conversations/session-123', {
  method: 'POST',
  body: JSON.stringify({
    messages: [
      { role: 'user', content: 'Hello!' },
      { role: 'bot', content: 'Hi there!' }
    ]
  })
});

Environment Variables

Add to .env.local:

code
BLOB_READ_WRITE_TOKEN=your_token_here

How It Works

  1. Bot starts → Automatically loads state from Blob
  2. During operation → State saved periodically + on changes
  3. Bot stops → Final state flush to Blob
  4. Next deployment → State restored from Blob

File Structure

  • state.json - Small, frequently updated (bot state)
  • conversations/*.json - Session-based (conversation history)
  • logs/*.json - Append-only (daily log files)

Limitations

  • Max file size: 500MB
  • No SQL queries (file-based only)
  • List operations can be slow with many files
  • Best for: State, logs, config, small conversation histories

Pricing