Files
extension/packages/ai/src/utils/stream.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

25 lines
569 B
TypeScript

import { createParser, ParsedEvent } from 'eventsource-parser';
export interface StreamPart {
type: 'text' | 'function_call' | 'tool_calls' | 'data' | 'error' | 'done';
value: any;
}
/**
* Parses a stream part from a server-sent event
*/
export function parseStreamPart(data: string): StreamPart | null {
try {
const parsed = JSON.parse(data);
return parsed;
} catch {
return null;
}
}
/**
* Creates an event source parser
*/
export function createEventSourceParser(onParse: (event: ParsedEvent) => void) {
return createParser(onParse);
}