export { dbQuery, QueryColumnSchema, QueryResultSchema, QueryResponseSchema, } from '@agentuity/core/db';
export { dbTables, generateCreateTableSQL, TableColumnSchema, TableSchemaSchema, TablesResponseSchema, } from '@agentuity/core/db';
export { dbLogs, DbQueryLogSchema, DbLogsAPIResponseSchema, DbLogsRequestSchema, DbLogsResponseSchema, } from '@agentuity/core/db';
export { dbLogStats, DbLogStatsAPIResponseSchema, DbLogStatsCommandBreakdownSchema, DbLogStatsQueryPatternSchema, DbLogStatsRequestSchema, DbLogStatsResponseSchema, DbLogStatsSummarySchema, DbLogStatsTimeSeriesPointSchema, } from '@agentuity/core/db';
export { DbInvalidArgumentError, DbResponseError } from '@agentuity/core/db';
import { APIClient } from '@agentuity/core/api';
import { createMinimalLogger } from '@agentuity/core';
import { getEnv } from '@agentuity/core';
import { getServiceUrls } from '@agentuity/core/config';
import { z } from 'zod';
import { dbQuery, dbTables, dbLogs, dbLogStats, } from '@agentuity/core/db';
export const DBClientOptionsSchema = z.object({
    apiKey: z.string().optional().describe('API key for authentication'),
    url: z.string().optional().describe('Base URL for the DB API'),
    database: z.string().describe('Database name'),
    orgId: z.string().describe('Organization ID'),
    region: z.string().optional().describe('Cloud region'),
    logger: z.custom().optional().describe('Custom logger instance'),
});
export class DBClient {
    #client;
    #database;
    #orgId;
    #region;
    constructor(options) {
        if (!options.database) {
            throw new Error('database is required for DBClient');
        }
        if (!options.orgId) {
            throw new Error('orgId is required for DBClient');
        }
        const apiKey = options.apiKey || getEnv('AGENTUITY_SDK_KEY') || getEnv('AGENTUITY_CLI_KEY');
        const region = options.region || (getEnv('AGENTUITY_REGION') ?? 'usc');
        const serviceUrls = getServiceUrls(region);
        const url = options.url || getEnv('AGENTUITY_DB_URL') || serviceUrls.catalyst;
        const logger = options.logger ?? createMinimalLogger();
        this.#client = new APIClient(url, logger, apiKey ?? '');
        this.#database = options.database;
        this.#orgId = options.orgId;
        this.#region = region;
    }
    async query(sql) {
        return dbQuery(this.#client, {
            database: this.#database,
            query: sql,
            orgId: this.#orgId,
            region: this.#region,
        });
    }
    async tables() {
        return dbTables(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
        });
    }
    async logs(params) {
        return dbLogs(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
            ...params,
        });
    }
    async stats(params) {
        return dbLogStats(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
            ...params,
        });
    }
}
//# sourceMappingURL=index.js.map