import type { AdvertisingCostBatch, PageContext } from '@/types/advertisingCost'; import type { ExtensionFeatureManifest } from '@/features/runtime/types'; export type ExtensionMessage = | { type: 'GET_PAGE_CONTEXT' } | { type: 'PARSE_ADVERTISING_COST' } | { type: 'TOGGLE_FLOATING_PANEL' } | { type: 'SET_FLOATING_PANEL'; payload: { visible: boolean } } | { type: 'GET_FLOATING_PANEL_STATE' } | { type: 'MOUNT_FEATURE'; payload: { featureId: string; code: string } } | { type: 'UNMOUNT_FEATURE' } | { type: 'GET_ACTIVE_FEATURE' } | { type: 'PING' }; export type ExtensionResponse = | { ok: true; data: PageContext } | { ok: true; data: AdvertisingCostBatch } | { ok: true; data: { pong: true } } | { ok: true; data: { visible: boolean } } | { ok: true; data: { featureId: string | null } } | { ok: true; data: ExtensionFeatureManifest } | { ok: false; code: string; message: string }; const MESSAGE_TYPES = new Set([ 'GET_PAGE_CONTEXT', 'PARSE_ADVERTISING_COST', 'TOGGLE_FLOATING_PANEL', 'SET_FLOATING_PANEL', 'GET_FLOATING_PANEL_STATE', 'MOUNT_FEATURE', 'UNMOUNT_FEATURE', 'GET_ACTIVE_FEATURE', 'PING', ]); export function isExtensionMessage(value: unknown): value is ExtensionMessage { if (!value || typeof value !== 'object') return false; const type = (value as { type?: unknown }).type; return typeof type === 'string' && MESSAGE_TYPES.has(type); }