/** * Base Agent - Durable Object for AI Agents * DO NOT MODIFY THIS FILE - You may break the agent functionality * * This is the Durable Object class for AI agents built on Cloudflare's Agents SDK. * It extends AIChatAgent which provides: * - WebSocket connection handling * - Message persistence (SQLite) * - Streaming response resumption * - State management * * LLM calls go through runwork's AI proxy, which: * - Handles API keys securely (no keys in vibe-app) * - Provides analytics, caching, and rate limiting via AI Gateway * - Supports multiple providers (OpenAI, Anthropic, etc.) * * Agent definitions are loaded from the APP_AGENTS registry based on * the agent name stored in the DO's storage. */ import { AIChatAgent } from 'agents/ai-chat-agent'; import { type StreamTextOnFinishCallback, type ToolSet } from 'ai'; import { type Env } from './core-utils'; import { type AgentDefinition, type AgentRuntimeStatus } from './core-agent'; /** * BaseAgent - The Durable Object for all agents * * This class extends AIChatAgent directly, which means: * - The class itself IS the Durable Object (not wrapped in another DO) * - AIChatAgent handles WebSocket connections, message persistence, and streaming * - We implement onChatMessage() to process incoming messages using the AI SDK * * Agent instances are identified by DO ID format: "{agentName}:{sessionId}" */ export declare class BaseAgent extends AIChatAgent { private definition; private integrationClient; private agentName; /** * Called when the agent starts (on first request or after hibernation) * Load the agent definition from storage */ onStart(): Promise; /** * Set the agent name and load its definition * Called when initializing a new agent instance */ setAgentName(name: string): Promise; /** * Handle incoming chat messages using AI SDK * This is the main entry point called by AIChatAgent when a message arrives */ onChatMessage(onFinish: StreamTextOnFinishCallback): Promise; /** * Build tools from agent definition using AI SDK tool() helper */ private buildTools; /** * Build tools for accessing integrations using AI SDK tool() helper * Uses shared definitions from core-agent.ts, wraps with executors * @param integrations - List of integration IDs to build tools for */ private buildIntegrationTools; /** * Build tools for accessing entities using AI SDK tool() helper * Uses entity classes directly with EntityContext */ /** * One tool per endpoint the agent is allowed to call on another app. * * Routed through `callAppEndpoint`, so it works in preview and production * alike: a production app cannot HTTP-fetch a sibling's public URL. */ private buildAppEndpointTools; private buildEntityTools; /** * Build tools for running complex tasks via a sandboxed AI sub-agent */ private buildCodeExecutionTools; /** * Get integration client (lazy-loaded) */ private getIntegrationClient; /** * Get tool execution context */ private getToolContext; /** * Get the agent's name */ getAgentName(): string | null; /** * Get the agent's definition */ getDefinition(): AgentDefinition | null; /** * Get runtime status - actual availability of tools and integrations * This checks real connectivity, not just declared capabilities */ getStatus(): Promise; }