Environment-Aware Architecture
Core Architecture
Eko’s environment-aware architecture consists of three key layers:
- Universal Core
- Environment-Specific Tools
- Environment Bridge
1. Universal Core
The framework’s core layer provides environment-independent functionality:
- Workflow management and execution
- Tool Registration management
- LLM integration (Claude/OpenAI)
- Hook system
// Browser Extension / Node.js environmentsimport { Eko } from "@eko-ai/eko";const eko = new Eko({ apiKey: "your_api_key", // API key can be provided directly modelName: "claude-3-5-sonnet-20241022", // Optional});
// Web environmentimport { Eko } from "@eko-ai/eko";const eko = new Eko({ llm: "claude", // IMPORTANT: In web environments, use a server-side endpoint that handles authentication baseURL: "https://your-api-endpoint.com", defaultHeaders: { // Add any necessary authentication headers Authorization: `Bearer ${getAuthToken()}`, },});
2. Environment-Specific Tools
Each environment provides its own optimized set of tools:
Browser Extension Tools
import { tools } from "@eko-ai/eko/extension";
// Browser automation toolsconst { TabManagement, // Browser tab control OpenUrl, // URL navigation BrowserUse, // DOM interaction WebSearch, // Web search capabilities Screenshot, // Page capture ExtractContent, // Content extraction} = tools;
Web Tools
import { tools } from "@eko-ai/eko/web";
// Web-safe toolsconst { BrowserUse, // DOM interaction ElementClick, // Element interaction ExtractContent, // Content extraction Screenshot, // Page capture} = tools;
Node.js Tools
import { tools } from "@eko-ai/eko/nodejs";
// System-level toolsconst { FileRead, // File operations FileWrite, // File operations CommandExecute, // Shell command execution} = tools;
Learn more: Available Tools;
3. Environment Bridge
The bridge layer handles:
- Environment detection
- Tool registration and access control
- Resource management
- Security boundaries
Web Environment Security
When using Eko in a web environment, follow these security best practices:
-
Never expose API keys in client-side code
// ❌ WRONG - Never do this in web environmentsconst eko = new Eko({apiKey: "sk-...", // Never expose API keys in client code});// ✅ CORRECT - Use server-side authenticationconst eko = new Eko({llm: "claude",baseURL: "https://your-api-endpoint.com/v1",defaultHeaders: {Authorization: `Bearer ${getAuthToken()}`,},}); -
Implement server-side authentication
// Server-side endpoint example (Node.js/Express)app.post("/v1/messages", async (req, res) => {// Validate user authenticationconst userToken = req.headers.authorization;if (!(await validateUserToken(userToken))) {return res.status(401).json({ error: "Unauthorized" });}// Forward request to Claude with your API keyconst response = await fetch("https://api.anthropic.com/v1/messages", {method: "POST",headers: {"x-api-key": process.env.CLAUDE_API_KEY,"Content-Type": "application/json",},body: JSON.stringify(req.body),});const data = await response.json();res.json(data);}); -
Handle user authentication state
// Client-side authentication handlingasync function getAuthToken() {// Implement your authentication logicconst session = await getUserSession();return session?.token;}
Automatic Tool Registration
Each environment provides a loadTools()
helper for easy setup:
import { Eko } from "@eko-ai/eko";import { loadTools } from "@eko-ai/eko/extension"; // or /web or /nodejs
// Register all tools for current environmentEko.tools = loadTools();
Security and Access Control
Eko implements environment-appropriate security measures:
-
Browser Extension
- Respects extension permissions
- Manages tab and window access
- Handles cross-origin interactions
-
Web Environment
- Operates within browser sandbox
- Limited to web-safe APIs
- No direct system access
- Server-side API key management
- User authentication required
-
Node.js Environment
- Full system access based on Node permissions
- User-approved file operations
- Command execution safeguards
- Direct API key usage permitted
-
Fellou Browser Environment
- User-approved computer use
- Manages tab and window access
- Server-side API key management
Best Practices
-
Environment Detection
// Tools are automatically filtered based on environmentconst tools = loadTools(); -
Tool Registration
// Register specific toolseko.registerTool(new tools.TabManagement());// Or register all available toolsEko.tools = loadTools();Learn more: Custom Tools.
-
Error Handling
try {await eko.execute(workflow);} catch (error) {// Environment-specific error handlingconsole.error("Workflow execution failed:", error);}Learn more: Hook System.
Next Steps
- Learn about Tool System capabilities
- Explore Workflow Execution
- Understand the Hook System