export const DEFAULT_REMOTE_AGENT_HOST = "127.0.0.1";
export const DEFAULT_REMOTE_AGENT_PORT = 4790;
export const REMOTE_AGENT_CHANNEL_NAME = "remote-agent";
function isJsonValue(value) {
    if (value === null ||
        typeof value === "string" ||
        typeof value === "boolean" ||
        (typeof value === "number" && Number.isFinite(value))) {
        return true;
    }
    if (Array.isArray(value)) {
        return value.every(isJsonValue);
    }
    if (typeof value === "object") {
        return Object.values(value).every(isJsonValue);
    }
    return false;
}
export function encodeRemoteAgentFrame(frame) {
    return `${JSON.stringify(frame)}\n`;
}
export function remoteAgentErrorResponse(id, error) {
    return {
        type: "remote_res",
        id,
        ok: false,
        error: { message: error instanceof Error ? error.message : String(error) },
    };
}
export function isRemoteAgentRequestFrame(value) {
    if (!value || typeof value !== "object")
        return false;
    const frame = value;
    if (typeof frame.id !== "string")
        return false;
    if (frame.type === "remote_attach") {
        return (typeof frame.sessionName === "string" &&
            frame.sessionName.length > 0 &&
            (frame.profile === undefined || typeof frame.profile === "string"));
    }
    if (frame.type === "remote_input") {
        if (!frame.input || typeof frame.input !== "object")
            return false;
        const input = frame.input;
        if (input.type === "message")
            return typeof input.text === "string";
        if (input.type === "execution") {
            return typeof input.action === "string" && (input.params === undefined || isJsonValue(input.params));
        }
    }
    if (frame.type === "remote_capabilities") {
        return true;
    }
    return false;
}
