// Force strict mode and setup for ESM
"use strict";
import "./chunk-UQDFEU47.js";
import "./chunk-GOFAQQZA.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-VA5NLVPT.js";
import "./chunk-I7JDGNG6.js";
import "./chunk-A6SX5TAH.js";
import "./chunk-33FNCQSY.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-XUMAD5IT.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-MOHAWIAW.js";
import "./chunk-X6QNZOTC.js";
import "./chunk-O6GEWCJA.js";
import "./chunk-T26EAKDL.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-MISUEWB4.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-A5YZ3FA2.js";
import "./chunk-YAVY33G4.js";
import "./chunk-2UISUFHQ.js";
import "./chunk-HFVW54NL.js";
import {
  isSubagentLikeExecutionContext
} from "./chunk-TZTBZ25J.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-SRY26X4H.js";
import "./chunk-K623ENWT.js";
import "./chunk-AQ37AY7B.js";
import "./chunk-432XCUHF.js";
import "./chunk-XC656O42.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-QYPT3QUD.js";
import "./chunk-QMBEW7EW.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-EIMKVOSF.js";
import "./chunk-RPYYTL7E.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-6O5DVH27.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-2DNKEBXY.js";
import "./chunk-4K3RV3OA.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-E4WHKETF.js";
import "./chunk-UEJESCS7.js";
import {
  BaseDeclarativeTool,
  BaseToolInvocation,
  ToolDisplayNames,
  ToolNames
} from "./chunk-CFDR3GNL.js";
import "./chunk-H35Q5CEG.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-BFHXDAR7.js";
import "./chunk-TYERNYH4.js";
import "./chunk-UH7Z7Y45.js";
import "./chunk-O2ZYHG33.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-G7XXKQYS.js";
import "./chunk-3RXUYQJI.js";
import "./chunk-VOQXFAY5.js";
import "./chunk-75DOP5OR.js";
import "./chunk-DMTGGOSA.js";
import "./chunk-YQ3U5MUC.js";
import "./chunk-AMDSOFFV.js";
import "./chunk-QUGAUQGJ.js";
import {
  init_esbuild_shims
} from "./chunk-5O2XNYP6.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
 */
