// Force strict mode and setup for ESM
"use strict";
import "./chunk-QQOPXQYM.js";
import "./chunk-TWPJO254.js";
import "./chunk-H6XPXXMH.js";
import "./chunk-5M6IDOMF.js";
import "./chunk-UPUG4GXM.js";
import "./chunk-64LQLPL7.js";
import "./chunk-2LQTH543.js";
import "./chunk-KRXPRVGL.js";
import "./chunk-GNCIZTNJ.js";
import "./chunk-CVHIL5IG.js";
import "./chunk-IRH27ZC2.js";
import "./chunk-QHWCP53L.js";
import "./chunk-PONHVBRT.js";
import "./chunk-T26EAKDL.js";
import "./chunk-6PVPNMXU.js";
import "./chunk-CPBF7KYF.js";
import "./chunk-6QIGFD5W.js";
import "./chunk-XWWKIXVD.js";
import "./chunk-75GFAX4R.js";
import "./chunk-OKF7JF3R.js";
import {
  isSubagentLikeExecutionContext
} from "./chunk-JSD33JG6.js";
import "./chunk-S6LOFUVP.js";
import "./chunk-JCW2R7WC.js";
import "./chunk-2DN4J57Y.js";
import "./chunk-ZPJWUGCS.js";
import "./chunk-2LKVPASC.js";
import "./chunk-NAVJD2PQ.js";
import "./chunk-LW3RFMG7.js";
import "./chunk-W4MIWP6M.js";
import "./chunk-DGEIYUC3.js";
import "./chunk-MPHPFVKK.js";
import "./chunk-GLNBDYUX.js";
import "./chunk-DJ2GSRLV.js";
import "./chunk-6D2RWQMA.js";
import "./chunk-75MIQ3LV.js";
import "./chunk-2J3OJGTL.js";
import "./chunk-P3QQPMQA.js";
import "./chunk-RPLGZJV2.js";
import "./chunk-GLCZKT5V.js";
import "./chunk-DZLYR4U3.js";
import "./chunk-NKHOVMWF.js";
import "./chunk-VGC4I5JJ.js";
import "./chunk-SGFT55XI.js";
import "./chunk-Y4IHBGBP.js";
import {
  BaseDeclarativeTool,
  BaseToolInvocation,
  ToolDisplayNames,
  ToolNames
} from "./chunk-Y6AXW2OG.js";
import "./chunk-2M3XQKPR.js";
import "./chunk-46UV252V.js";
import "./chunk-ZBVS26BY.js";
import "./chunk-WZRWHXFE.js";
import "./chunk-A3NDJ5SB.js";
import "./chunk-7XATOOE7.js";
import "./chunk-BGTQCTQW.js";
import "./chunk-W4RQUHY3.js";
import "./chunk-S7W2GKIO.js";
import "./chunk-UHUSJ6X7.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
 */
