feat(FN-3332): add droid runtime plugin with event bridge and process manag
The merge delivers a new `fusion-plugin-droid-runtime` plugin providing a full MCP server and runtime adapter for droid-based agents, with event bridging, process management, tool mapping, and a prompt builder. It also adds agent delegation and org hierarchy tools to the pi extension, while fixing a Fusion-Task-Id: FN-3332
This commit is contained in:
37
plugins/fusion-plugin-droid-runtime/src/stream-parser.ts
Normal file
37
plugins/fusion-plugin-droid-runtime/src/stream-parser.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import type { NdjsonMessage } from "./types.js";
|
||||
|
||||
/**
|
||||
* Parse a single NDJSON line from Droid CLI stdout into a typed message.
|
||||
*
|
||||
* This function is deliberately resilient -- it never throws. Debug noise,
|
||||
* empty lines, and malformed JSON all return null so the streaming pipeline
|
||||
* can safely skip them and continue processing.
|
||||
*/
|
||||
export function parseLine(line: string): NdjsonMessage | null {
|
||||
const trimmed = line.trim();
|
||||
|
||||
// Skip empty lines
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Skip non-JSON lines (debug output like "[SandboxDebug] ...")
|
||||
if (!trimmed.startsWith("{")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
let parsed: unknown;
|
||||
try {
|
||||
parsed = JSON.parse(trimmed);
|
||||
} catch {
|
||||
console.error("Failed to parse NDJSON line:", trimmed);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Validate that the parsed result is a non-null object (not array, not primitive)
|
||||
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return parsed as NdjsonMessage;
|
||||
}
|
||||
Reference in New Issue
Block a user