"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toolDiscoverFieldsOutputSchema = exports.discoverFieldsResultSchema = exports.discoverFieldsResultUnionSchema = exports.discoverFieldsInputSchema = exports.DISCOVER_FIELDS_DESCRIPTION = void 0;
const zod_1 = require("zod");
exports.DISCOVER_FIELDS_DESCRIPTION = `Tool: discoverFields

Purpose:
Run the data-discovery subagent. Given the latest user query, returns a structured handoff describing which explore and which fields to use to answer it.

Use this tool as the FIRST step whenever the user asks a data question (counts, totals, breakdowns, trends, "what is", "show me", "how many"). Do NOT call this when the user is only asking about existing dashboards/charts (use findContent) or follow-up clarifications about a chart you already produced.

You will receive one of three statuses:
- "resolved" — proceed with generateVisualization (or generateDashboard) using the returned explore + fields.
- "ambiguous" — surface the suggestedQuestion to the user; do NOT call generateVisualization.
- "no_match" — explain back to the user that no data source covers the request.

Re-call this tool if the user pivots mid-thread to a different data topic and you need fields from a different explore.
`;
exports.discoverFieldsInputSchema = zod_1.z.object({
    userQuery: zod_1.z
        .string()
        .describe('The latest user question or instruction the agent is responding to. Pass the full message — the subagent uses it to disambiguate explores and rank fields.'),
    agentInstruction: zod_1.z
        .string()
        .nullable()
        .describe("The agent's configured `instruction` field if present, otherwise null. Provides domain-specific guidance for explore/field selection."),
});
const discoverFieldsExploreSummarySchema = zod_1.z.object({
    name: zod_1.z.string(),
    label: zod_1.z.string(),
    baseTable: zod_1.z.string(),
    joinedTables: zod_1.z.array(zod_1.z.string()),
});
const discoverFieldsFieldSummarySchema = zod_1.z.object({
    fieldId: zod_1.z
        .string()
        .describe('The fieldId to use in generateVisualization payloads.'),
    name: zod_1.z.string(),
    label: zod_1.z.string(),
    table: zod_1.z.string(),
    fieldType: zod_1.z.enum(['dimension', 'metric']),
    fieldValueType: zod_1.z
        .string()
        .describe('The value type (e.g. number, string, date, timestamp, boolean).'),
    fieldFilterType: zod_1.z.string(),
    caseSensitiveFilters: zod_1.z
        .enum(['true', 'false', 'not_applicable'])
        .describe('Use "true" or "false" only when the exact selected findFields result explicitly includes caseSensitiveFilters with that value; otherwise use "not_applicable".'),
    isFromJoinedTable: zod_1.z.boolean(),
    description: zod_1.z
        .string()
        .nullable()
        .describe('Short description, only include when needed to distinguish similar fields.'),
});
const discoverFieldsCandidateSchema = zod_1.z.object({
    exploreName: zod_1.z.string(),
    exploreLabel: zod_1.z.string(),
    reason: zod_1.z
        .string()
        .describe('Why this explore is a plausible candidate for the query.'),
});
exports.discoverFieldsResultUnionSchema = zod_1.z.discriminatedUnion('status', [
    zod_1.z.object({
        status: zod_1.z.literal('resolved'),
        explore: discoverFieldsExploreSummarySchema,
        fields: zod_1.z
            .array(discoverFieldsFieldSummarySchema)
            .describe('Filtered list of fields relevant to the user query — typically 5–20 entries. Not the full explore.'),
        rationale: zod_1.z
            .string()
            .nullable()
            .describe('Brief justification for the explore + field selection.'),
    }),
    zod_1.z.object({
        status: zod_1.z.literal('ambiguous'),
        candidates: zod_1.z
            .array(discoverFieldsCandidateSchema)
            .min(2)
            .describe('Plausible explores the parent should ask the user to disambiguate between.'),
        suggestedQuestion: zod_1.z
            .string()
            .describe("A clarification question the parent can echo to the user (e.g. 'Did you mean revenue from the orders explore or the payments explore?')."),
    }),
    zod_1.z.object({
        status: zod_1.z.literal('no_match'),
        reason: zod_1.z
            .string()
            .describe('Why no explore covers the user query — used by the parent to explain back to the user.'),
    }),
]);
exports.discoverFieldsResultSchema = zod_1.z.object({
    handoff: exports.discoverFieldsResultUnionSchema,
});
exports.toolDiscoverFieldsOutputSchema = zod_1.z.union([
    zod_1.z.object({
        result: zod_1.z.literal(''),
        metadata: zod_1.z.object({
            status: zod_1.z.literal('streaming'),
            streamingMessage: zod_1.z.unknown(),
        }),
    }),
    zod_1.z.object({
        result: zod_1.z.string(),
        metadata: zod_1.z.object({
            status: zod_1.z.literal('success'),
            discovery: exports.discoverFieldsResultUnionSchema,
            streamingMessage: zod_1.z.unknown().optional(),
        }),
    }),
    zod_1.z.object({
        result: zod_1.z.string(),
        metadata: zod_1.z.object({
            status: zod_1.z.literal('error'),
        }),
    }),
]);
//# sourceMappingURL=toolDiscoverFieldsArgs.js.map