Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647import type { HistoryEntry, Session } from '../api';
export type AgentBubbleRole = 'subagent' | 'agent';
type MailUserBlock = { mail?: { senderId: string | null; kind: NonNullable<HistoryEntry['mail']>['kind']; } | null; turnType?: HistoryEntry['turn_type'];};
const EXTERNAL_MAIL = new Set(['webhook', 'event_tool', 'event_turn']);
/** * Classifies a `user` block for chat bubble placement and tinting: null for * the person or non-agent triggers, `'subagent'` for a descendant of this * session, or `'agent'` for a sibling, parent, or other agent. */export function agentBubbleRole( block: MailUserBlock, sessionId: string, knownSessions: ReadonlyMap<string, Session>,): AgentBubbleRole | null { const mail = block.mail; if (mail && EXTERNAL_MAIL.has(mail.kind)) return null; if (!mail && block.turnType !== 'agent') return null;
if (mail?.kind === 'result' || mail?.kind === 'unreviewed') return 'subagent';
const senderId = mail?.senderId; if (!senderId) return 'agent'; const sender = knownSessions.get(senderId); if (!sender) return 'agent';
const seen = new Set<string>([sender.id]); let parentId = sender.parent_id; while (parentId) { if (parentId === sessionId) return 'subagent'; if (seen.has(parentId)) break; seen.add(parentId); parentId = knownSessions.get(parentId)?.parent_id ?? null; }
return 'agent';}