API for building agentic coding editors/platforms | NPM
- AI-powered code generation with streaming support
- Tool execution with automatic function calling
- Memory management for context-aware conversations
- Express.js integration for easy web server setup
- TypeScript support with full type definitions
npm install @cellular-ai/engineimport { engine, stream } from '@cellular-ai/engine';
// Create an engine instance
const engineInstance = engine({
dir: '/path/to/project',
fullContext: true,
sessionId: 'session-123',
apikey: 'your-api-key',
debug: false
});
// Stream AI responses
for await (const token of engineInstance.stream('Write a function to sort an array')) {
process.stdout.write(token);
}import express from 'express';
import { stream } from '@cellular-ai/engine';
const app = express();
app.post('/generate', async (req, res) => {
const { prompt, dir, context } = req.body;
const setHeaders = true;
// Create engine for specific request
const engineInstance = engine({
dir: dir,
fullContext: true,
sessionId: 'session-123',
apikey: 'your-api-key',
debug: false
});
// Stream agent response w/ tool calls for given prompt
await stream(res, engineInstance, prompt, setHeaders, context);
});
app.listen(3000, () => {
console.log('Server running on port 3000');
});The stream function returns data in standard SSE format:
- Content events:
data: {"type": "text", "content": "hello world", "timestamp": "..."} - Tool events:
event: tool_request data: {"type": "tool_request", "content": {...}, "timestamp": "..."}
Creates a new engine instance.
Parameters:
config(EngineConfig): Configuration object with the following properties:dir(string): Project directory pathfullContext(boolean, optional): Whether to dump entire codebase into context window. Default:falsemodel(string, optional): Model to use. Options:'pro','flash','mini'. Default:'flash'apikey(string, optional): Gemini API key. Can also be set viaGEMINI_API_KEYenvironment variable.sessionId(string, optional): Session identifier. Auto-generated if not provided.debug(boolean): Enable debug logging
Returns: EngineService instance
Express Integration to Streams AI responses seamlessly.
Parameters:
response(Response): Express.js response object.engine(EngineService): Engine instance.prompt(string): User prompt.setHeaders(boolean, optional): Whether to set required SSE headers automatically. Default:falsecontext(string, optional): Additional context.
Streams AI responses as an async generator. Ideal for ask type questions that do not require tool usage.
for await (const token of engineInstance.stream('Your prompt here')) {
console.log(token);
}Streams AI responses with tool execution events as an async generator. Ideal for project-wide agent queries.
for await (const event of engineInstance.streamWithToolEvents('Your prompt here')) {
if (event.type === 'text') {
console.log(event.data);
} else if (event.type === 'tool_request') {
console.log('Tool requested:', event.data);
}
}Returns available tools as function declarations.
const tools = await engineInstance.getTools();
console.log('Available tools:', tools.map(t => t.name));Executes a specific tool with parameters.
const result = await engineInstance.executeTool('read-file', { path: './example.js' });
console.log(result);Returns the current memory content.
const memory = engineInstance.getMemoryContent();
console.log('Memory content:', memory);GEMINI_API_KEY: Your Gemini API key (required)
import { engine } from '@cellular-ai/engine';
const engineInstance = engine({
dir: './my-project',
fullContext: true,
sessionId: 'code-gen-session',
debug: false
});
for await (const token of engineInstance.stream(
'Create a React component that displays a user profile'
)) {
process.stdout.write(token);
}import { engine } from '@cellular-ai/engine';
const engineInstance = engine({
dir: './my-project',
fullContext: true,
sessionId: 'code-gen-session',
debug: false
});
for await (const event of engineInstance.streamWithToolEvents(
'Create a React component that displays a user profile'
)) {
switch (event.type) {
case 'text':
process.stdout.write(event.data);
break;
case 'tool_request':
console.log('π οΈ Tool requested:', event.data.name);
break;
case 'tool_start':
console.log('π Tool started:', event.data.name);
break;
case 'tool_result':
console.log('β
Tool completed:', event.data.name);
break;
case 'tool_error':
console.log('β Tool failed:', event.data.name);
break;
}
}import { engine } from '@cellular-ai/engine';
const engineInstance = engine({
dir: './my-project',
debug: false
});
// Get available tools
const tools = await engineInstance.getTools();
console.log('Available tools:', tools.map(t => t.name));
// Execute a specific tool
const fileContent = await engineInstance.executeTool('read-file', {
path: './src/index.js'
});
console.log('File content:', fileContent);All code in this project is maintained under the Apache-2.0 License