"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolFindExploresOutputSchema = exports.findExploresResultSchema = exports.findExploresRelevantVerifiedAnswerSchema = exports.findExploresRequiredFilterSchema = exports.findExploresRankingMetadataSchema = exports.toolFindExploresArgsSchemaTransformed = exports.toolFindExploresArgsSchemaV3 = exports.toolFindExploresArgsSchemaV2 = exports.toolFindExploresArgsSchemaV1 = exports.TOOL_FIND_EXPLORES_DESCRIPTION = void 0;
const zod_1 = require("zod");
const outputMetadata_1 = require("../outputMetadata");
const toolSchemaBuilder_1 = require("../toolSchemaBuilder");
exports.TOOL_FIND_EXPLORES_DESCRIPTION = `Tool: findExplores

Purpose:
Returns explores matching the query with their joined tables, required filters, AI hints and descriptions, plus the top 50 matching fields across ALL explores. Search matches explore and field name, label, and description. A follow-up query runs against a single explore, so this tool is meant to identify the explore whose fields can answer the user's question.
IMPORTANT: Each explore may include fields from multiple joined tables. Check the "joinedTables" elements to see which tables are included in the explore.

Parameters:
- searchQuery: Keyword terms for finding relevant explores

Output:
- Matching explores with searchRank scores
- Top matching fields with their explore names and searchRank scores
- Required filters set on matching explores, including default values
`;
exports.toolFindExploresArgsSchemaV1 = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    exploreName: zod_1.z
        .string()
        .nullable()
        .describe('Name of the explore that you have access to'),
})
    .withPagination()
    .build();
exports.toolFindExploresArgsSchemaV2 = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    exploreName: zod_1.z
        .string()
        .describe('Name of the explore that you have access to'),
})
    .build();
exports.toolFindExploresArgsSchemaV3 = (0, toolSchemaBuilder_1.createToolSchema)()
    .extend({
    // TODO: check if we need to add exploreName back in for backward compatibility
    searchQuery: zod_1.z
        .string()
        .describe("set of high-signal keyword terms for query. Search uses PostgreSQL websearch_to_tsquery after joining whitespace-separated terms with OR. It searches explore and field name, label, and description. Prefer metric/entity/dimension nouns that capture the user's analytical intent."),
})
    .build();
exports.toolFindExploresArgsSchemaTransformed = exports.toolFindExploresArgsSchemaV3;
exports.findExploresRankingMetadataSchema = zod_1.z.object({
    searchQuery: zod_1.z.string(),
    exploreSearchResults: zod_1.z
        .array(zod_1.z.object({
        name: zod_1.z.string(),
        label: zod_1.z.string(),
        searchRank: zod_1.z.number().nullable().optional(),
        joinedTables: zod_1.z.array(zod_1.z.string()).nullable().optional(),
        requiredFilters: zod_1.z
            .array(zod_1.z.object({
            fieldId: zod_1.z.string(),
            fieldRef: zod_1.z.string(),
            tableName: zod_1.z.string(),
            operator: zod_1.z.string(),
            values: zod_1.z.array(zod_1.z.unknown()).optional(),
            settings: zod_1.z.unknown().optional(),
            required: zod_1.z.boolean(),
        }))
            .optional(),
    }))
        .optional(),
    topMatchingFields: zod_1.z
        .array(zod_1.z.object({
        name: zod_1.z.string(),
        label: zod_1.z.string(),
        tableName: zod_1.z.string(),
        fieldType: zod_1.z.string(),
        searchRank: zod_1.z.number().nullable().optional(),
        chartUsage: zod_1.z.number().nullable().optional(),
        verifiedChartUsage: zod_1.z.number().nullable().optional(),
    }))
        .optional(),
});
exports.findExploresRequiredFilterSchema = zod_1.z.object({
    fieldId: zod_1.z.string(),
    fieldRef: zod_1.z.string(),
    tableName: zod_1.z.string(),
    operator: zod_1.z.string(),
    values: zod_1.z.array(zod_1.z.unknown()).optional(),
    settings: zod_1.z.unknown().optional(),
    required: zod_1.z.boolean(),
});
exports.findExploresRelevantVerifiedAnswerSchema = zod_1.z.object({
    artifactVersionUuid: zod_1.z.string(),
    chartConfig: zod_1.z.record(zod_1.z.unknown()),
    artifactType: zod_1.z.enum(['chart', 'dashboard']),
    verifiedQuestion: zod_1.z.string().nullable(),
    title: zod_1.z.string().nullable(),
    description: zod_1.z.string().nullable(),
    similarity: zod_1.z.number(),
});
exports.findExploresResultSchema = zod_1.z.object({
    searchQuery: zod_1.z.string(),
    description: zod_1.z.string(),
    searchResults: zod_1.z.object({
        count: zod_1.z.number(),
        note: zod_1.z.string(),
        results: zod_1.z.array(zod_1.z.object({
            name: zod_1.z.string(),
            label: zod_1.z.string(),
            searchRank: zod_1.z.number().nullable(),
            description: zod_1.z.string().nullable(),
            aiHints: zod_1.z.array(zod_1.z.string()),
            joinedTables: zod_1.z.object({
                count: zod_1.z.number(),
                note: zod_1.z.string().nullable(),
                tables: zod_1.z.array(zod_1.z.string()),
            }),
            requiredFilters: zod_1.z.array(exports.findExploresRequiredFilterSchema),
        })),
    }),
    topMatchingFields: zod_1.z.object({
        count: zod_1.z.number(),
        note: zod_1.z.string(),
        fields: zod_1.z.array(zod_1.z.object({
            name: zod_1.z.string(),
            label: zod_1.z.string(),
            exploreName: zod_1.z.string(),
            fieldType: zod_1.z.string(),
            searchRank: zod_1.z.number().nullable(),
            usageInCharts: zod_1.z.number(),
            usageInVerifiedCharts: zod_1.z.number(),
        })),
    }),
    relevantVerifiedAnswers: zod_1.z
        .array(exports.findExploresRelevantVerifiedAnswerSchema)
        .optional(),
});
exports.toolFindExploresOutputSchema = zod_1.z.object({
    result: zod_1.z.string(),
    metadata: outputMetadata_1.baseOutputMetadataSchema.extend({
        ranking: exports.findExploresRankingMetadataSchema.optional(),
    }),
});
//# sourceMappingURL=toolFindExploresArgs.js.map