import z from "zod";
import { FALLBACK_STRATEGIES } from "@superblocksteam/library-shared/types";
/**
 * Feature flag definitions for AI service.
 *
 * To add a new flag, simply add a property here with key and schema:
 * ```
 * myNewFlag: {
 *   key: 'ai.my-new-flag',
 *   schema: z.number()
 * }
 * ```
 *
 * Then access it type-safely: `flags.myNewFlag`
 */
const FLAG_DEFINITIONS = {
    metadataCacheMaxTotalSizeMB: {
        key: "ai.metadata-cache-size-mb",
        schema: z.number(),
    },
    metadataCacheMaxSingleFileSizeMB: {
        key: "ai.metadata-file-size-mb",
        schema: z.number(),
    },
    unifiedProviderEnabled: {
        key: "superblocks.ai.provider.unified",
        schema: z.boolean(),
    },
    safetyGuidancePrompt: {
        key: "ai.prompt.safety-guidance",
        schema: z.string().nonempty(),
    },
    safetyClassificationEnabled: {
        key: "superblocks.ai.safety-classification.enabled",
        schema: z.boolean(),
    },
    secretRedactionLevel: {
        key: "superblocks.ai.secret-redaction.level",
        schema: z.enum(["full", "initial-prompt", "off"]),
    },
    fallbackStrategy: {
        key: "ai.fallback.strategy",
        schema: z.enum(FALLBACK_STRATEGIES),
    },
    parameterizedApisEnabled: {
        key: "clark.parameterized-apis.v2.enabled",
        schema: z.boolean(),
    },
    webToolsEnabled: {
        key: "superblocks.ai.web-tools.enabled",
        schema: z.boolean(),
    },
    superblocksDocsMcpEnabled: {
        key: "superblocks.ai.docs-mcp.enabled",
        schema: z.boolean(),
    },
    enableClarkAiReadAccessPermission: {
        key: "ui.clark-ai.read-access-permission",
        schema: z.boolean(),
    },
    thirdPartyImportEnabled: {
        key: "ui.third-party-import.enabled",
        schema: z.boolean(),
    },
    apiRunLogsEnabled: {
        key: "ai.get-logs.api-runs.enabled",
        schema: z.boolean(),
    },
    useSystemSkills: {
        key: "clark.use_system_skills",
        schema: z.boolean(),
    },
    sessionRecordingEnabled: {
        key: "clark.session-recording.enabled",
        schema: z.boolean(),
    },
    sessionManagementEnabled: {
        key: "clark.session-management.enabled",
        schema: z.boolean(),
    },
    promptUsageAlarmThreshold: {
        key: "superblocks.ai.prompt.usage-alarm-threshold",
        schema: z.number().nonnegative().finite(),
        defaultValue: 10,
    },
    /** Derived from application templateName in CLI (not LD). See isSdkApiTemplate(). */
    sdkApiEnabled: {
        key: "clark.sdk-api.enabled",
        schema: z.boolean(),
    },
    aiFileUploadEnabled: {
        key: "ai.file-upload.enabled",
        schema: z.boolean(),
    },
    clarkAttachmentDownloadEnabled: {
        key: "ai.clark-attachment-download.enabled",
        schema: z.boolean(),
    },
    appKnowledgeEnabled: {
        key: "ai.app-knowledge.enabled",
        schema: z.boolean(),
    },
    nativeGitEnabled: {
        key: "superblocks.native-git.enabled",
        schema: z.boolean(),
    },
    nativeGitRawEnabled: {
        key: "superblocks.native-git-raw.enabled",
        schema: z.boolean(),
    },
    enableDeletingLockfiles: {
        key: "ai.clark-delete-package-lock.enabled",
        schema: z.boolean(),
    },
    suggestWhatsNext: {
        key: "ai.suggest-whats-next",
        schema: z.boolean(),
    },
    integrationSetupEnabled: {
        key: "clark.integration-setup.enabled",
        schema: z.boolean(),
    },
};
export const AiServiceFeatureFlags = {
    /**
     * Create a new feature flags instance with the given flag values.
     */
    create(flags = {}) {
        return new Proxy({}, {
            get(_target, prop) {
                if (typeof prop !== "string" || !(prop in FLAG_DEFINITIONS)) {
                    return undefined;
                }
                const def = FLAG_DEFINITIONS[prop];
                const raw = flags[def.key];
                const defaultValue = "defaultValue" in def ? def.defaultValue : undefined;
                if (raw === undefined) {
                    return defaultValue;
                }
                const result = def.schema.safeParse(raw);
                return result.success ? result.data : defaultValue;
            },
        });
    },
};
//# sourceMappingURL=features.js.map