import type { Attachment, Message, SessionInfo } from "../types.js"; function isAttachment(value: unknown): value is Attachment { if (typeof value !== "object" || value === null) return false; const attachment = value as Record; if (attachment.type !== "file" && attachment.type !== "snippet" && attachment.type !== "context") return false; if (typeof attachment.name !== "string" || typeof attachment.content !== "string") return false; return attachment.language === undefined || typeof attachment.language === "string"; } function isMessageSource(value: unknown): value is NonNullable { if (typeof value !== "object" || value === null || Array.isArray(value)) return false; const source = value as Record; return typeof source.subagentRunId === "string" && (source.subagentAgent === undefined || typeof source.subagentAgent === "string") && (source.subagentIndex === undefined || typeof source.subagentIndex === "number"); } export function isMessage(value: unknown): value is Message { if (typeof value !== "object" || value === null) return false; const message = value as Record; if (typeof message.id !== "string" || typeof message.timestamp !== "number") return false; if (message.replyTo !== undefined && typeof message.replyTo !== "string") return false; if (message.expectsReply !== undefined && typeof message.expectsReply !== "boolean") return false; if (message.replyError !== undefined && typeof message.replyError !== "string") return false; if (message.source !== undefined && !isMessageSource(message.source)) return false; if (typeof message.content !== "object" || message.content === null) return false; const content = message.content as Record; if (typeof content.text !== "string") return false; return content.attachments === undefined || (Array.isArray(content.attachments) && content.attachments.every(isAttachment)); } export function isSessionInfo(value: unknown): value is SessionInfo { if (typeof value !== "object" || value === null) return false; const session = value as Record; if ( typeof session.id !== "string" || typeof session.cwd !== "string" || typeof session.model !== "string" || typeof session.pid !== "number" || typeof session.startedAt !== "number" || typeof session.lastActivity !== "number" ) return false; if (session.name !== undefined && typeof session.name !== "string") return false; if (session.group !== undefined && typeof session.group !== "string") return false; return session.status === undefined || typeof session.status === "string"; }