import { KeyValueClient } from '@agentuity/keyvalue';
import { getCatalystUrl } from "../../../catalyst.js";
import * as tui from "../../../tui.js";
export function createStorageAdapter(ctx, explicitOrgId) {
    const orgId = explicitOrgId ??
        ctx.project?.orgId ??
        ctx.options.orgId ??
        (process.env.AGENTUITY_CLOUD_ORG_ID || ctx.config?.preferences?.orgId);
    if (!orgId) {
        tui.fatal('Organization ID is required. Either run from a project directory or use --org-id flag.');
    }
    const baseUrl = getCatalystUrl(ctx.region, ctx.config?.overrides);
    return new KeyValueClient({
        apiKey: ctx.auth.apiKey,
        orgId,
        url: baseUrl,
        logger: ctx.logger,
    });
}
//# sourceMappingURL=util.js.map