agent-ecosystem/src/shared/utils/inboxNoise.ts
iliya 70fdc2537a feat: enhance inbox message handling and UI components
- Introduced functions to identify and filter out internal coordination noise from inbox messages, improving notification relevance.
- Updated TeamProvisioningService to automatically mark noise messages as read, reducing clutter for team leads.
- Enhanced TeamDetailView and MessagesFilterPopover to allow users to toggle visibility of noise messages in the UI.
- Refactored various components to improve the handling of task attachments and message serialization, ensuring better user experience.
- Improved error handling and state management in session detail fetching, allowing for real-time updates without UI disruptions.
2026-03-05 17:27:09 +02:00

38 lines
1.1 KiB
TypeScript

/**
* Inbox "noise" messages are structured JSON objects that represent internal coordination
* signals (idle/shutdown/etc.). They should not trigger user-facing notifications or
* automatic lead relays.
*/
export const INBOX_NOISE_TYPES = [
'idle_notification',
'shutdown_approved',
'teammate_terminated',
'shutdown_request',
] as const;
const INBOX_NOISE_SET = new Set<string>(INBOX_NOISE_TYPES);
export function parseInboxJson(text: string): Record<string, unknown> | null {
const trimmed = text.trim();
if (!trimmed.startsWith('{')) return null;
try {
const parsed = JSON.parse(trimmed) as unknown;
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
return parsed as Record<string, unknown>;
}
} catch {
// not JSON
}
return null;
}
export function getInboxJsonType(text: string): string | null {
const parsed = parseInboxJson(text);
if (!parsed) return null;
return typeof parsed.type === 'string' ? parsed.type : null;
}
export function isInboxNoiseMessage(text: string): boolean {
const type = getInboxJsonType(text);
return !!type && INBOX_NOISE_SET.has(type);
}