import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { EVIDENCE_FILENAME } from '../shared/constants.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
import { planRunSummarySchema } from './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.
 */
export const queryWorkspacePlanRunsParamsSchema = z.object({
    limit: 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: 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: z.enum(['all', 'passed', 'failed']).optional().meta({
        description: 'Filter by plan run status. Default: all',
    }),
});
const workspacePlanRunSummarySchema = planRunSummarySchema.extend({
    applicationId: z.string().optional().meta({ description: 'Application ID this run targeted' }),
    environmentId: z.string().optional().meta({ description: 'Environment ID this run used' }),
});
export const queryWorkspacePlanRunsResponseSchema = z.object({
    planRuns: z.array(workspacePlanRunSummarySchema).meta({
        description: 'Plan runs in the workspace for the fixed time range and filters (newest first)',
    }),
    total_matching: 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: 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: z.number().meta({ description: 'Number of plan runs in planRuns' }),
    truncated: 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: 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: z
        .object({
        workspaceId: z.string(),
        startTime: z.string(),
        endTime: z.string(),
        environmentId: z.string().optional(),
        applicationId: z.string().optional(),
    })
        .meta({
        description: 'Filters applied to this query (from session context). Shown so the agent knows what scope the data has.',
    }),
});
export const QueryWorkspacePlanRunsToolDefinition = defineTool({
    name: AgentToolNames.QueryWorkspacePlanRuns,
    description: `Paginated plan-run **rows** (session scope auto-applied). Not for a minimal opening — when **\`initial_workspace_summary\`** exists, put that prefetch into **${EVIDENCE_FILENAME}** first (minimal snapshot tables), then **${AgentToolNames.SendResponse}** with \`filename: "${EVIDENCE_FILENAME}"\`; otherwise **${AgentToolNames.GetWorkspacePlanRunsOverview}** first.

For tables, **filter_status**, many **plan_run_id**s. Newest-first; \`limit\` ~100–300; avoid \`fetch_all\`. See \`stopped_early\`, \`total_matching_count_incomplete\`.`,
    argumentsSchema: queryWorkspacePlanRunsParamsSchema,
    responseSchema: queryWorkspacePlanRunsResponseSchema,
});
//# sourceMappingURL=QueryWorkspacePlanRunsDefinition.js.map