// Force strict mode and setup for ESM
"use strict";
import "./chunk-33JSFFSK.js";
import "./chunk-5P5XGNYH.js";
import "./chunk-SKAZWEV5.js";
import "./chunk-K5PGHDBN.js";
import "./chunk-3B26UVCX.js";
import "./chunk-W7EEOR7D.js";
import "./chunk-42XGFRJS.js";
import "./chunk-X2XNQQJI.js";
import "./chunk-VZ7HY3YU.js";
import "./chunk-2MPVVENX.js";
import "./chunk-ZTQ26VBE.js";
import "./chunk-FV7425LN.js";
import "./chunk-MLZQVCF3.js";
import "./chunk-LQ7TMOCE.js";
import "./chunk-E5A7LHNN.js";
import {
  isSubagentLikeExecutionContext
} from "./chunk-5MBO76SL.js";
import "./chunk-GO6LNQXT.js";
import "./chunk-NQKLOAVJ.js";
import "./chunk-WMPVYQ4P.js";
import "./chunk-TLWA7TPR.js";
import "./chunk-QYNNN7BK.js";
import "./chunk-G2DUQQCZ.js";
import "./chunk-E6US47KI.js";
import "./chunk-UWCTAVOD.js";
import "./chunk-OFEVLU4C.js";
import "./chunk-OMX7CUOE.js";
import "./chunk-OACJLMLD.js";
import "./chunk-SUAKHHK7.js";
import "./chunk-FEJ2FZ3U.js";
import {
  BaseDeclarativeTool,
  BaseToolInvocation,
  ToolDisplayNames,
  ToolNames
} from "./chunk-X3YGAX7V.js";
import "./chunk-IJRL2S3D.js";
import "./chunk-AHNJGLFV.js";
import "./chunk-22IFUCVR.js";
import "./chunk-7LTB54MK.js";
import "./chunk-SIUQ3YYX.js";
import "./chunk-HW4N45EE.js";
import "./chunk-CCGOFQV3.js";
import "./chunk-IRJWHZWU.js";
import "./chunk-SYCJMSIJ.js";
import "./chunk-55ZMG67I.js";
import "./chunk-H6BD2ELD.js";
import "./chunk-5IFG2VC4.js";
import "./chunk-64WXLC72.js";
import "./chunk-H6EMK6QK.js";
import "./chunk-22MNNNXE.js";
import "./chunk-ZERZSAZL.js";
import "./chunk-QN5NZ3UQ.js";
import "./chunk-BR4QREVK.js";
import "./chunk-Z2Z3GUXZ.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/core/src/tools/team-plan-approval.ts
init_esbuild_shims();
var TeamPlanApprovalInvocation = class extends BaseToolInvocation {
  constructor(config, params) {
    super(params);
    this.config = config;
  }
  static {
    __name(this, "TeamPlanApprovalInvocation");
  }
  getDescription() {
    return `${this.params.action} teammate plan ${this.params.request_id}`;
  }
  async getDefaultPermission() {
    return "allow";
  }
  async execute(_signal) {
    if (isSubagentLikeExecutionContext()) {
      const msg = "Only the team leader can approve teammate plans.";
      return {
        llmContent: msg,
        returnDisplay: msg,
        error: { message: msg }
      };
    }
    const manager = this.config.getTeamManager();
    if (!manager) {
      const msg = "No active team. Create a team first.";
      return {
        llmContent: msg,
        returnDisplay: msg,
        error: { message: msg }
      };
    }
    try {
      if (this.params.action === "approve") {
        const targetMode = this.getApprovalTargetMode();
        if (targetMode === "plan" /* PLAN */) {
          const msg3 = "Cannot approve teammate plan while the leader is still in plan mode. Exit the leader plan mode first; the request remains pending.";
          return {
            llmContent: msg3,
            returnDisplay: msg3,
            error: { message: msg3 }
          };
        }
        manager.resolvePlanApprovalRequest(this.params.request_id, {
          action: "approve",
          targetMode,
          message: this.params.message
        });
        const msg2 = `Teammate plan request "${this.params.request_id}" approved.`;
        return { llmContent: msg2, returnDisplay: msg2 };
      }
      manager.resolvePlanApprovalRequest(this.params.request_id, {
        action: "reject",
        message: this.params.message
      });
      const msg = `Teammate plan request "${this.params.request_id}" rejected.`;
      return { llmContent: msg, returnDisplay: msg };
    } catch (error) {
      const message = error instanceof Error ? error.message : String(error);
      return {
        llmContent: `Failed to resolve teammate plan approval: ${message}`,
        returnDisplay: `Plan approval failed: ${message}`,
        error: { message }
      };
    }
  }
  getApprovalTargetMode() {
    const current = this.config.getApprovalMode();
    if (current === "auto" /* AUTO */) {
      return "default" /* DEFAULT */;
    }
    if (!this.config.isTrustedFolder() && (current === "auto-edit" /* AUTO_EDIT */ || current === "yolo" /* YOLO */)) {
      return "default" /* DEFAULT */;
    }
    return current;
  }
};
var TeamPlanApprovalTool = class _TeamPlanApprovalTool extends BaseDeclarativeTool {
  constructor(config) {
    super(
      _TeamPlanApprovalTool.Name,
      ToolDisplayNames.TEAM_PLAN_APPROVAL,
      "Approve or reject a plan submitted by a plan-required teammate. Only the team leader can use this tool.",
      "think" /* Think */,
      {
        type: "object",
        properties: {
          request_id: {
            type: "string",
            description: "The request id from the team plan approval request."
          },
          action: {
            type: "string",
            enum: ["approve", "reject"],
            description: "Approve or reject the teammate plan."
          },
          message: {
            type: "string",
            description: "Optional feedback for the teammate, especially when rejecting."
          }
        },
        required: ["request_id", "action"],
        additionalProperties: false
      }
    );
    this.config = config;
  }
  static {
    __name(this, "TeamPlanApprovalTool");
  }
  static Name = ToolNames.TEAM_PLAN_APPROVAL;
  validateToolParams(params) {
    if (!params.request_id || typeof params.request_id !== "string" || params.request_id.trim() === "") {
      return 'Parameter "request_id" must be a non-empty string.';
    }
    if (params.action !== "approve" && params.action !== "reject") {
      return 'Parameter "action" must be "approve" or "reject".';
    }
    if (params.message !== void 0 && typeof params.message !== "string") {
      return 'Parameter "message" must be a string when set.';
    }
    return null;
  }
  createInvocation(params) {
    return new TeamPlanApprovalInvocation(this.config, params);
  }
};
export {
  TeamPlanApprovalTool
};
/**
 * @license
 * Copyright 2025 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
