export { KeyValueStorageService, KV_MIN_TTL_SECONDS, KV_MAX_TTL_SECONDS, KV_DEFAULT_TTL_SECONDS, DataResultFoundSchema, DataResultNotFoundSchema, DataResultSchema, KeyValueStorageSetParamsSchema, CreateNamespaceParamsSchema, GetAllStatsParamsSchema, KeyValueStatsSchema, KeyValueStatsPaginatedSchema, KeyValueItemWithMetadataSchema, KVSortFieldSchema, } from '@agentuity/core/keyvalue';
import { KeyValueStorageService, } from '@agentuity/core/keyvalue';
import { createServerFetchAdapter, buildClientHeaders } from '@agentuity/adapter';
import { createMinimalLogger } from '@agentuity/core';
import { getEnv } from '@agentuity/core';
import { getServiceUrls } from '@agentuity/core/config';
import { z } from 'zod';
const isLogger = (val) => typeof val === 'object' &&
    val !== null &&
    ['info', 'warn', 'error', 'debug', 'trace'].every((m) => typeof val[m] === 'function');
export const KeyValueClientOptionsSchema = z.object({
    apiKey: z.string().optional().describe('API key for authentication'),
    url: z.string().optional().describe('Base URL for the KV API'),
    orgId: z.string().optional().describe('Organization ID for multi-tenant operations'),
    logger: z.custom(isLogger).optional().describe('Custom logger instance'),
});
export class KeyValueClient {
    #service;
    constructor(options = {}) {
        const validatedOptions = KeyValueClientOptionsSchema.parse(options);
        const apiKey = validatedOptions.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
        const region = getEnv('AGENTUITY_REGION') ?? 'usc';
        const serviceUrls = getServiceUrls(region);
        const url = validatedOptions.url || getEnv('AGENTUITY_KEYVALUE_URL') || serviceUrls.keyvalue;
        const logger = validatedOptions.logger ?? createMinimalLogger();
        const headers = buildClientHeaders({
            apiKey,
            orgId: validatedOptions.orgId,
        });
        const adapter = createServerFetchAdapter({ headers }, logger);
        this.#service = new KeyValueStorageService(url, adapter);
    }
    async get(name, key) {
        return this.#service.get(name, key);
    }
    async set(name, key, value, params) {
        return this.#service.set(name, key, value, params);
    }
    async delete(name, key) {
        return this.#service.delete(name, key);
    }
    async getStats(name) {
        return this.#service.getStats(name);
    }
    async getAllStats(params) {
        return this.#service.getAllStats(params);
    }
    async getNamespaces() {
        return this.#service.getNamespaces();
    }
    async search(name, keyword) {
        return this.#service.search(name, keyword);
    }
    async getKeys(name) {
        return this.#service.getKeys(name);
    }
    async deleteNamespace(name) {
        return this.#service.deleteNamespace(name);
    }
    async createNamespace(name, params) {
        return this.#service.createNamespace(name, params);
    }
}
//# sourceMappingURL=index.js.map