"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NewSessionHandler = void 0;
const common_1 = require("@nestjs/common");
const new_session_args_dto_1 = require("./dto/new-session.args.dto");
const class_transformer_1 = require("class-transformer");
const class_validator_1 = require("class-validator");
const utils_1 = require("../../utils");
let NewSessionHandler = class NewSessionHandler {
    constructor() {
        this.toolName = 'new_session';
    }
    getMetadata() {
        return {
            name: this.toolName,
            description: this.getDefinition(),
            arguments: [
                {
                    name: 'handover_string',
                    type: 'string',
                    description: 'A clear instruction or prompt for the new session to execute.',
                    required: true,
                },
            ],
        };
    }
    generateExample(toolCall) {
        return (0, utils_1.generateToolCallJson)(toolCall);
    }
    getDefinition() {
        const example = this.generateExample({
            tool_name: this.toolName,
            handover_string: 'The component has been created. Now, create a new set of unit tests for the component located at `src/components/NewComponent.tsx`. Ensure all props are tested.',
        });
        const definition = `
::<${this.toolName}>
  Used to break down a complex task into a smaller, separate task. It halts the current plan and creates a new session with the provided instructions.

  Parameters:
  - "handover_string": (string) A clear instruction or prompt for the new session to execute.

  <example>
    Explanation: After completing a large refactor, this creates a follow-up task to add documentation.
:${example}
  </example>
::</${this.toolName}>
`;
        return definition.trim();
    }
    async execute(args) {
        const validatedArgs = (0, class_transformer_1.plainToClass)(new_session_args_dto_1.NewSessionArgsDto, args);
        const errors = await (0, class_validator_1.validate)(validatedArgs);
        if (errors.length > 0) {
            const errorMessages = errors
                .map((err) => Object.values(err.constraints || {}).join(', '))
                .join('; ');
            return {
                status: 'FAILURE',
                summary: `Invalid arguments for ${this.toolName}.`,
                error_message: errorMessages,
                persisted_args: args,
                execution_log: { output: '', error_message: errorMessages },
            };
        }
        return {
            status: 'SUCCESS',
            summary: `Session handover prepared: ${validatedArgs.handover_string}`,
            persisted_args: validatedArgs,
            execution_log: { output: 'New session prepared.', error_message: '' },
        };
    }
};
exports.NewSessionHandler = NewSessionHandler;
exports.NewSessionHandler = NewSessionHandler = __decorate([
    (0, common_1.Injectable)()
], NewSessionHandler);
//# sourceMappingURL=new-session.handler.js.map