Skip to main content
Glama
StreamProcessor.ts1.21 kB
/** * StreamProcessor - Simplified stream processing for agent output * * Handles both cursor and claude output in JSON format. * Both agents now use --output-format json and return a single JSON response. */ export class StreamProcessor { private resultJson: unknown = null /** * Process a single line from the agent output stream. * Returns true when a valid JSON is detected, false otherwise. * * @param line - Raw line from stdout * @returns true if processing is complete, false to continue */ processLine(line: string): boolean { const trimmedLine = line.trim() // Empty lines are ignored if (!trimmedLine) { return false } // Try to parse as JSON try { const json = JSON.parse(trimmedLine) // Store the first valid JSON response if (!this.resultJson) { this.resultJson = json return true // Processing complete } return false // Ignore subsequent JSONs } catch { // Not valid JSON, ignore return false } } /** * Get the final result JSON. * @returns The stored result JSON or null if not yet available */ getResult(): unknown { return this.resultJson } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shinpr/sub-agents-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server