// Force strict mode and setup for ESM
"use strict";
import {
  BaseDeclarativeTool,
  BaseToolInvocation,
  ToolDisplayNames,
  ToolNames
} from "./chunk-G763GDO6.js";
import "./chunk-R5PDRHEF.js";
import "./chunk-WFVXF3OM.js";
import {
  init_esbuild_shims
} from "./chunk-A4BMJM77.js";
import {
  __name
} from "./chunk-J2S4EL5Y.js";

// packages/core/src/tools/send-message.ts
init_esbuild_shims();
var SendMessageInvocation = class extends BaseToolInvocation {
  constructor(config, params) {
    super(params);
    this.config = config;
  }
  static {
    __name(this, "SendMessageInvocation");
  }
  getDescription() {
    return `Send message to task ${this.params.task_id}`;
  }
  /**
   * Send-message routes free-form text into a running background task,
   * which will then execute it as a new instruction with full tool
   * access. Treat it as a privileged sink — the L4 default must not be
   * 'allow', because that would let the scheduler auto-approve in
   * AUTO mode (where 'allow' short-circuits the classifier). 'ask' lets
   * AUTO route through the classifier so the destination task and
   * message text can be inspected.
   */
  async getDefaultPermission() {
    return "ask";
  }
  async execute(_signal) {
    const registry = this.config.getBackgroundTaskRegistry();
    const entry = registry.get(this.params.task_id);
    if (!entry) {
      return {
        llmContent: `Error: No background task found with ID "${this.params.task_id}".`,
        returnDisplay: "Task not found.",
        error: {
          message: `Task not found: ${this.params.task_id}`,
          type: "send_message_not_found" /* SEND_MESSAGE_NOT_FOUND */
        }
      };
    }
    if (entry.status === "paused") {
      const resumed = await this.config.resumeBackgroundAgent(
        this.params.task_id,
        this.params.message
      );
      if (!resumed) {
        return {
          llmContent: `Error: Background task "${this.params.task_id}" could not be resumed.`,
          returnDisplay: "Task could not be resumed.",
          error: {
            message: `Task could not be resumed: ${this.params.task_id}`,
            type: "send_message_not_running" /* SEND_MESSAGE_NOT_RUNNING */
          }
        };
      }
      return {
        llmContent: `Background task "${this.params.task_id}" resumed with your message as the first continuation instruction.`,
        returnDisplay: `Resumed ${entry.description}`
      };
    }
    if (entry.status !== "running") {
      return {
        llmContent: `Error: Background task "${this.params.task_id}" is not running (status: ${entry.status}). Cannot send messages to stopped tasks.`,
        returnDisplay: `Task not running (${entry.status}).`,
        error: {
          message: `Task is ${entry.status}: ${this.params.task_id}`,
          type: "send_message_not_running" /* SEND_MESSAGE_NOT_RUNNING */
        }
      };
    }
    registry.queueMessage(this.params.task_id, this.params.message);
    return {
      llmContent: `Message queued for delivery to background task "${this.params.task_id}". The task will receive it at the next tool-round boundary.`,
      returnDisplay: `Message queued for ${entry.description}`
    };
  }
};
var SendMessageTool = class _SendMessageTool extends BaseDeclarativeTool {
  constructor(config) {
    super(
      _SendMessageTool.Name,
      ToolDisplayNames.SEND_MESSAGE,
      "Send a text message to a background task. Running tasks receive it at the next tool-round boundary. Paused recovered tasks are resumed first and use the message as their first continuation instruction.",
      "other" /* Other */,
      {
        type: "object",
        properties: {
          task_id: {
            type: "string",
            description: "The ID of the background task (from the launch response or a recovered paused task)."
          },
          message: {
            type: "string",
            description: "The text message to send to the task."
          }
        },
        required: ["task_id", "message"],
        additionalProperties: false
      },
      true,
      // isOutputMarkdown
      false,
      // canUpdateOutput
      true,
      // shouldDefer — sending messages to tasks is infrequent
      false,
      // alwaysLoad
      "send message task communicate notify"
    );
    this.config = config;
  }
  static {
    __name(this, "SendMessageTool");
  }
  static Name = ToolNames.SEND_MESSAGE;
  createInvocation(params) {
    return new SendMessageInvocation(this.config, params);
  }
  /**
   * Forward both fields verbatim to the classifier — `task_id` identifies
   * the privileged sink and the `message` itself is the new instruction
   * the background task will execute, so the classifier needs the full
   * text to evaluate the action's safety.
   */
  toAutoClassifierInput(params) {
    return { task_id: params.task_id, message: params.message };
  }
};
export {
  SendMessageTool
};
/**
 * @license
 * Copyright 2025 Qwen
 * SPDX-License-Identifier: Apache-2.0
 */
