import { WorkflowService } from '@agentuity/core';
import { createServerFetchAdapter } from '@agentuity/server';
import { getCatalystUrl } from "../../../catalyst.js";
import { defaultProfileName, getDefaultRegion } from "../../../config.js";
import * as tui from "../../../tui.js";
export async function createWorkflowAdapter(ctx) {
    const orgId = ctx.options.orgId ?? (process.env.AGENTUITY_CLOUD_ORG_ID || ctx.config?.preferences?.orgId);
    if (!orgId) {
        tui.fatal('Organization ID is required. Use --org-id flag or set AGENTUITY_CLOUD_ORG_ID.');
    }
    const adapter = createServerFetchAdapter({ headers: { Authorization: `Bearer ${ctx.auth.apiKey}`, 'x-agentuity-orgid': orgId } }, ctx.logger);
    const region = await getDefaultRegion(ctx.config?.name ?? defaultProfileName, ctx.config);
    const baseUrl = getCatalystUrl(region, ctx.config?.overrides);
    return new WorkflowService(baseUrl, adapter);
}
//# sourceMappingURL=util.js.map