"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueryWorkspacePlanRunsToolDefinition = exports.queryWorkspacePlanRunsResponseSchema = exports.queryWorkspacePlanRunsParamsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var constants_js_1 = require("../shared/constants.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
var GetPlanRunInfoDefinition_js_1 = require("./GetPlanRunInfoDefinition.js");
/**
 * QueryWorkspacePlanRunsDefinition - Tool definition for listing plan runs in a workspace.
 * Filters (workspace, time range, environment, application) are supplied by the server from
 * the session context and are not passed as tool arguments.
 */
exports.queryWorkspacePlanRunsParamsSchema = zod_1.z.object({
    limit: zod_1.z.number().optional().meta({
        description: 'Maximum plan runs to return after matching filters (newest first). Ignored when fetch_all is true. Default: 500, max: 10000 when set.',
    }),
    fetch_all: zod_1.z.boolean().optional().meta({
        description: 'When true, return all matching plan runs in the session window (newest first), up to server safety limits on Core API paging. Ignores limit. Use for full workspace listings; large windows may return very large payloads.',
    }),
    filter_status: zod_1.z.enum(['all', 'passed', 'failed']).optional().meta({
        description: 'Filter by plan run status. Default: all',
    }),
});
var workspacePlanRunSummarySchema = GetPlanRunInfoDefinition_js_1.planRunSummarySchema.extend({
    applicationId: zod_1.z.string().optional().meta({ description: 'Application ID this run targeted' }),
    environmentId: zod_1.z.string().optional().meta({ description: 'Environment ID this run used' }),
});
exports.queryWorkspacePlanRunsResponseSchema = zod_1.z.object({
    planRuns: zod_1.z.array(workspacePlanRunSummarySchema).meta({
        description: 'Plan runs in the workspace for the fixed time range and filters (newest first)',
    }),
    total_matching: zod_1.z.number().meta({
        description: 'Total plan runs matching filters counted on pages scanned. Exact global total when total_matching_count_incomplete is false; a lower bound when pagination stopped early while more API pages remained.',
    }),
    total_matching_count_incomplete: zod_1.z.boolean().optional().meta({
        description: 'True when pagination stopped after collecting enough rows for the limit while the Core API still had more pages (cursor). total_matching is then a lower bound; more matching runs may exist on later pages.',
    }),
    returned_count: zod_1.z.number().meta({ description: 'Number of plan runs in planRuns' }),
    truncated: zod_1.z.boolean().meta({
        description: 'True if returned_count is less than the full matching set: either total_matching exceeds returned_count, or total_matching_count_incomplete is true (limit hit before scanning all API pages).',
    }),
    stopped_early: zod_1.z.boolean().meta({
        description: 'True if the scan stopped before the API reported no more pages (safety cap on API pages). More matching runs may exist.',
    }),
    appliedFilters: zod_1.z
        .object({
        workspaceId: zod_1.z.string(),
        startTime: zod_1.z.string(),
        endTime: zod_1.z.string(),
        environmentId: zod_1.z.string().optional(),
        applicationId: zod_1.z.string().optional(),
    })
        .meta({
        description: 'Filters applied to this query (from session context). Shown so the agent knows what scope the data has.',
    }),
});
exports.QueryWorkspacePlanRunsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.QueryWorkspacePlanRuns,
    description: "Paginated plan-run **rows** (session scope auto-applied). Not for a minimal opening \u2014 when **`initial_workspace_summary`** exists, put that prefetch into **".concat(constants_js_1.EVIDENCE_FILENAME, "** first (minimal snapshot tables), then **").concat(agentToolNames_js_1.AgentToolNames.SendResponse, "** with `filename: \"").concat(constants_js_1.EVIDENCE_FILENAME, "\"`; otherwise **").concat(agentToolNames_js_1.AgentToolNames.GetWorkspacePlanRunsOverview, "** first.\n\nFor tables, **filter_status**, many **plan_run_id**s. Newest-first; `limit` ~100\u2013300; avoid `fetch_all`. See `stopped_early`, `total_matching_count_incomplete`."),
    argumentsSchema: exports.queryWorkspacePlanRunsParamsSchema,
    responseSchema: exports.queryWorkspacePlanRunsResponseSchema,
});
//# sourceMappingURL=QueryWorkspacePlanRunsDefinition.js.map