- 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
38 lines
894 B
TypeScript
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);
|
|
} |