import browser from 'webextension-polyfill';
export type AgentId = string;
export declare enum PorterContext {
    ContentScript = "contentscript",
    Extension = "extension",
    Popup = "popup",
    Sidepanel = "sidepanel",
    Devtools = "devtools",
    Options = "options",
    Unknown = "unknown"
}
export declare enum ConnectionType {
    NewTab = "new-tab",
    NewFrame = "new-frame",
    Refresh = "refresh",
    NewExtensionContext = "new-extension-context"
}
export interface AgentInfo {
    id: AgentId;
    location: BrowserLocation;
    createdAt: number;
    lastActiveAt: number;
}
export type Agent = {
    port?: browser.Runtime.Port;
    info: AgentInfo;
};
export type BrowserLocation = {
    context: PorterContext;
    tabId: number;
    frameId: number;
};
export type MessageTarget = BrowserLocation | PorterContext | string | number;
export type Unsubscribe = () => void;
export type Message<K extends keyof MessageAction> = {
    action: K;
    target?: MessageTarget;
    payload?: MessageAction[K];
};
export type MessageAction = {
    [key: string]: any;
};
export type Listener<T extends keyof PorterEvent> = (arg: PorterEvent[T]) => void;
export type MessageListener = {
    config: MessageConfig;
    listener: Listener<'onMessage'>;
};
export type MessageConfig = {
    [K in keyof MessageAction]: (message: Message<K>, info?: AgentInfo) => void;
};
export interface PorterEvent {
    onConnect: AgentInfo;
    onDisconnect: AgentInfo;
    onMessagesSet: AgentInfo;
    onMessage: AgentInfo & {
        message: Message<any>;
    };
}
export declare enum PorterErrorType {
    CONNECTION_FAILED = "connection-failed",
    CONNECTION_TIMEOUT = "connection-timeout",
    INVALID_TARGET = "invalid-target",
    MESSAGE_FAILED = "message-failed",
    INVALID_CONTEXT = "invalid-context",
    INVALID_PORT = "invalid-port"
}
export declare class PorterError extends Error {
    type: PorterErrorType;
    details?: any | undefined;
    constructor(type: PorterErrorType, message: string, details?: any | undefined);
}
