Files
extension/packages/ai/src/core/router.ts
T
Hanzo Dev 7f31475cc5 feat: major monorepo reorganization and AI package implementation
- Reorganized directory structure: pkg/ -> packages/, app/ -> apps/
- Added @hanzo/ai package with Vercel AI SDK patterns
- Implemented AgentKit concepts (agents, networks, state, routers)
- Added MCP (Model Context Protocol) integration
- Integrated telemetry with Hanzo Cloud observability
- Fixed all failing tests across all packages
- Updated Makefile with comprehensive commands for development and release
- Added support for Gemini, Codex, and Grok CLI tools
- Fixed import paths and build configuration for new structure
2025-07-20 02:44:59 -05:00

38 lines
894 B
TypeScript

/**
* Router implementation for agent networks
*/
import { Agent } from './agent';
import { Network } from './network';
import { State } from './state';
export interface RouterConfig {
handler: (context: RouterContext) => Agent | undefined | Promise<Agent | undefined>;
metadata?: Record<string, any>;
}
export interface RouterContext {
network: Network;
state: State;
messages: any[];
iteration: number;
history: any[];
}
export class Router {
private handler: RouterConfig['handler'];
readonly metadata: Record<string, any>;
constructor(config: RouterConfig) {
this.handler = config.handler;
this.metadata = config.metadata || {};
}
async route(context: RouterContext): Promise<Agent | undefined> {
return Promise.resolve(this.handler(context));
}
}
export function createRouter(config: RouterConfig): Router {
return new Router(config);
}