# Open Valstorm & Valstorm Cloud — AI Agent Developer Skill (`SKILL.md`) > Drop this file into `CLAUDE.md`, `.cursorrules`, or `~/.valstorm/skills/valstorm-dev/SKILL.md` so your AI coding agent immediately understands how to query, mutate, extend, and build on Valstorm. --- ## 1. Unified `PlatformContext` Mental Model (1:1 Parity) Valstorm exposes the exact same domain facades whether your code runs: 1. **Inside a Server Trigger, Custom Function, or FastAPI Route (`apps/open-api`)**: `platform.records`, `platform.query`, `platform.schemas`, `platform.vfs`, `platform.files`, `platform.tasks`, `platform.` 2. **In an External Script or Microservice via the Python SDK (`valstorm-client`)**: `client.records`, `client.query`, `client.schemas`, `client.vfs`, `client.files`, `client.apps`, `client.sandboxes` 3. **Inside the Go Worker (`apps/open-worker`)**: `platformCtx.ForOrg(orgID, userID).Records.Create/Update/Delete/Get/Query` ### Python SDK Quick Reference (`valstorm-client`) ```python from valstorm import AsyncValstormClient, ValstormClient, PatAuth, ServiceKeyAuth # Synchronous client client = ValstormClient( base_url="http://localhost:8010/v1", # or "https://api.valstorm.com/v1" auth=PatAuth("vst_pat_..."), ) # 1. Inspect an Object Schema before mutating contact_schema = client.schemas.get("contact") # 2. Execute Parameterized ANSI SQL with Valstorm Macros leads = client.query.sql( "SELECT id, name, status FROM lead WHERE owner = ME AND created_date = last_n_days:30 LIMIT 25" ) # 3. Create Records (Plain String Lookup IDs & Picklist String Labels!) created = client.records.create("ticket", [{ "name": "Configure Telnyx Webhook", "status": "Pending Assignment", # Picklist -> human-readable tag label "priority": "High", # Picklist -> human-readable tag label "type": "Feature Improvement", "owner": "user_qBulInDu18OcylWP", # Lookup -> plain Base62 string ID (NEVER a dict!) "description": "Full markdown details...", }]) # 4. Virtual File Service (VFS) Hybrid Vector + Full-Text Search vault_tree = client.vfs.tree() ``` --- ## 2. Mandatory Data Model Rules (Zero Exceptions) 1. **Relationship Lookups Store Plain String IDs Only:** - **NEVER** pass dictionary objects like `{"id": "user_123", "name": "Jared"}` to `lookup` or `lookup_list` fields. - Always store plain string Base62 IDs (`"owner": "user_123"`) and arrays of plain string IDs (`"contacts": ["con_123", "con_456"]`). 2. **Picklist Fields Store String Labels (Not Tag IDs):** - Fields with `format: "picklist"` (`status`, `priority`, `type`, `utm_source`) store the human-readable tag label (`"Active"`, `"High"`), **never** a `tag_...` ID. 3. **Custom Objects & Fields (`__c`):** - Creating a schema via `POST /v1/schema/object` compiles directly to PostgreSQL `CREATE TABLE`. - Adding a field via `POST /v1/schema/field` compiles to `ALTER TABLE ... ADD COLUMN` ($O(1)$ instant DDL). --- ## 3. Dual-Runtime Microservice Architecture (Cloud & COSS) | Service | Port | Runtime | Responsibilities & Direct Endpoints | | :--- | :--- | :--- | :--- | | **`open-api`** | `:8010` | Python 3.13 (FastAPI) | REST (`/v1/records/c/{obj}`, `/v1/query/sql`, `/v1/schema/*`, `/v1/vfs/*`), GraphQL (`/v1/graphql`), OAuth 2.1, and 19 Python plugin routers. | | **`open-worker`** | `:8080` | Go 1.23 (`pgx/v5`) | WebSocket Hub (`/v1/ws/{org}/{user}`, `/v1/ws/desktop/execute`), Fleet DDL Deployer (`/v1/deployment/rollout`), Sub-10ms AI Desktop Sync (`/v1/ai/chat/{chat_id}/desktop-sync`), Public Form/Webhook Ingress (`/v1/inbound/submit`), Booking (`/v1/booking/{slug}/availability`), and Telnyx/Twilio/SendGrid webhooks. | | **`open-worker-p1` / `p2`** | — | Python 3.13 | Standalone background queue consumers for `valstorm:queue:default` and `valstorm:queue:low`. | | **`open-agent-runtime`** | `:8660` | Python 3.13 | Multi-turn Cloud ReAct Agent Runtime (`POST /v1/runs`, `GET /v1/runs/{run_id}/events`). | | **`open-web-scraper`** | `:8661` | Python 3.14 | 3-Tier Waterfall Web Scraper (`POST /v1/scrape`, `/v1/crawl`, `/v1/feed/poll`, `/v1/diff`). | | **`open-video-worker`** | `:8089` | Python + FFmpeg | Video transcoding, thumbnails, and Deepgram/AI video metadata (`valstorm:queue:video`). | --- ## 4. Model Context Protocol (MCP) Server Tools (`valstorm-mcp-server`) Connect any MCP client to `https://mcp.valstorm.com/mcp` (Streamable HTTP) or run locally via `uv run --project apps/valstorm-mcp-server valstorm-mcp --transport stdio`: - **Records & SQL:** `schema_inspect`, `record_query_sql`, `record_get`, `record_create`, `record_update`, `record_delete`, `record_hydrate_batch` - **Knowledge Vaults (VFS):** `vfs_search` (`pgvector` + `tsvector` hybrid RRF), `vfs_ask`, `vfs_read_text`, `vfs_browse`, `vfs_move`, `vfs_prepare_upload`, `vfs_get_download_url`, `vfs_delete_file` --- ## 5. Creating or Extending an Open Valstorm Plugin (`/plugins`) Every plugin lives in `/plugins/valstorm-plugin-/` and is toggled via `VALSTORM_PLUGINS`: - **Python (`python/src/valstorm_plugin_/__init__.py`):** Exports `plugin = ValstormPlugin(name="...", routers=[...], worker_includes=[...], ai_tools=[...], prefixes={...}, context_class=...)` mounted at `platform.`. - **Go (`go/plugin.go`):** Calls `plugin.Register(&MyPlugin{})` in `init()`, binds high-speed routes on `ctx.HTTPMux`, registers `valstorm:queue:critical` task handlers via `ctx.RegisterTaskHandler(...)`, and mutates tenant Postgres directly via `ctx.Platform.ForOrg(orgID, userID)`.