"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecuteEditStepsToolDefinition = exports.executeEditStepsResponseSchema = exports.executeEditStepsArgumentsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
// One edit operation. A flat object (not a discriminated union) so the
// emitted JSON Schema stays oneOf/anyOf-free for Gemini compatibility;
// step_id is required on every op, so the schema can enforce it directly
// without an op-conditional refinement.
var editOperationSchema = zod_1.z.object({
    op: zod_1.z.enum(['replace', 'insert_after', 'insert_before']).meta({
        description: '"replace": overwrite the step identified by step_id with `step`. ' +
            '"insert_after": insert `step` as a sibling immediately after the step identified by step_id. ' +
            '"insert_before": insert `step` as a sibling immediately before the step identified by step_id (use this for front-of-list / before-first-step insertion).',
    }),
    step_id: zod_1.z.string().meta({
        description: 'Stable canonical step id of the anchor step. Required for every op — replace overwrites this step; insert_after/insert_before place `step` as a sibling on the indicated side. Read ids from the test execution state; ids survive list mutations, so they are safe across edits and rebases. Inserting into an empty container is not supported here — record or move steps in instead.',
    }),
    step: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).meta({
        description: 'The step in json_steps form: a single-key object keyed by the step type, e.g. {"Click": {...}}. Element finds cannot be hand-authored here. Any op (replace, insert_after, insert_before) may carry a find ONLY if it reuses one already captured this session — copy an existing step\'s find via get_step_json so its selector uuid matches a capture, then use it as-is. On "replace", omit the find entirely to keep the original step\'s recorded find untouched (the common path for changing only the entered text or assertion value); include a reused find only to re-point the step at a different already-captured element. A find with no uuid, or with a uuid the session never captured, is rejected. To target a new element, re-record it with the recording tools — they capture the trained descriptor that cannot be written by hand.',
    }),
});
exports.executeEditStepsArgumentsSchema = zod_1.z.object({
    edits: zod_1.z.array(editOperationSchema).min(1).meta({
        description: 'Batch of edit operations applied together. Op step_ids reference the steps as they are now (before this batch); the batch either applies fully or fails as a whole.',
    }),
});
exports.executeEditStepsResponseSchema = zod_1.z.object({
    success: zod_1.z.boolean(),
    message: zod_1.z.string().optional(),
});
exports.ExecuteEditStepsToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: 'execute_edit_steps',
    description: 'Edits the content of existing steps and inserts hand-authored steps, without re-recording in the browser. Use this to fix an element find/selector, change entered text, or adjust an assertion on a step that is already in the test. Capture brand-new page interactions with the recording tools (execute_click, execute_enter_text, ...) instead.\n\n' +
        'Each edit is "replace" (overwrite a step by step_id), "insert_after" (sibling immediately after an anchor step_id), or "insert_before" (sibling immediately before an anchor step_id — use this for front-of-list insertion). Every op requires step_id; there is no positional or cursor-relative fallback. Provide the new step in json_steps form, keyed by step type. This tool edits step CONTENT (entered text, assertion values, descriptions, variable/wait config) — it does NOT hand-author element finds. A find may ride along on any op, but only if it reuses one already captured this session; an invented find is rejected. On "replace", omit the find to keep the original step\'s recorded find untouched. To target a new element, record it with the recording tools instead. The whole batch is validated and applied atomically: if any op or the resulting test is invalid, nothing changes.\n\n' +
        'Steps are addressed by step_id (from get_test_context) and may live anywhere — at the root or nested inside a step group; ids stay stable across edits and rebases. Steps inside a referenced flow are NOT editable here — edit the flow itself. This tool only mutates the working state — it does NOT replay the edited or inserted steps in the browser. Use execute_play_steps over the affected range to re-verify behavior after editing. WARNING: inserting steps shifts the positional indices used by other tools, so call get_test_context to refresh before any later index-based tool.',
    argumentsSchema: exports.executeEditStepsArgumentsSchema,
    responseSchema: exports.executeEditStepsResponseSchema,
});
//# sourceMappingURL=ExecuteEditStepsDefinition.js.map