"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.agents = void 0;
const tslib_1 = require("tslib");
const logger_1 = require("@refloat/logger");
const api_client_1 = require("../api/api-client");
const config_1 = require("../config");
const schema_1 = require("../generated/schema");
const version_1 = (0, tslib_1.__importDefault)(require("../generated/version"));
const abort_context_1 = require("../utils/abort-context");
const config_agent_1 = require("./config-agent");
const build_agent_1 = require("./build-agent");
const logger = logger_1.Logger.create('agents');
async function agents() {
    const config = config_1.Configuration.get();
    const api = new api_client_1.APIClient(config.api);
    const ctx = new abort_context_1.AbortContext();
    logger.info('registering', {
        platform: config.platform,
        name: config.name,
        version: version_1.default,
    });
    const { agent } = await api.register(config);
    logger.info('registered', {
        id: agent.id,
        org: agent.org.slug,
        tags: agent.tags,
    });
    await Promise.all([
        (0, build_agent_1.runAgent)(ctx, api),
        Promise.resolve().then(async () => {
            if (config.platform === schema_1.AgentPlatform.Linux ||
                config.platform === schema_1.AgentPlatform.macOS) {
                await (0, config_agent_1.configAgent)(ctx, api);
            }
        }),
    ]);
}
exports.agents = agents;
//# sourceMappingURL=agents.js.map