core/apps/webapp/app/trigger/utils/cli-message-handler.ts
Harshith Mullapudi 038acea669
Feat: added integration connect and mcp oAuth (#20)
* Feat: added integration connect and mcp oAuth

* Feat: add mcp support to chat

* Fix: UI for integrations and logs

* Fix: ui

* Fix: proxy server

* Feat: enhance MCP tool integration and loading functionality

* Fix: added header

* Fix: Linear integration sync

---------

Co-authored-by: Manoj K <saimanoj58@gmail.com>
2025-07-17 12:41:32 +05:30

46 lines
1.1 KiB
TypeScript

import { type Message } from "@core/types";
/**
* Validates if a message has the correct structure
* @param message - Message to validate
* @returns True if valid, false otherwise
*/
export function isValidMessage(message: any): message is Message {
return (
typeof message === "object" &&
message !== null &&
typeof message.type === "string" &&
message.data !== undefined &&
["spec", "activity", "state", "identifier", "account"].includes(
message.type,
)
);
}
/**
* Extracts and validates messages from CLI output
* @param output - Raw CLI output string
* @returns Array of valid messages
*/
export function extractMessagesFromOutput(output: string): Message[] {
const messages: Message[] = [];
const lines = output.split("\n");
for (const line of lines) {
const trimmed = line.trim();
if (!trimmed) continue;
try {
const parsed = JSON.parse(trimmed);
if (isValidMessage(parsed)) {
messages.push(parsed);
}
} catch (error) {
// Line is not JSON, skip it
continue;
}
}
return messages;
}