"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var async_toolset_exports = {};
__export(async_toolset_exports, {
  AsyncToolset: () => AsyncToolset
});
module.exports = __toCommonJS(async_toolset_exports);
var import_tool_executor = require("../voice/tool_executor.cjs");
var import_tool_context = require("./tool_context.cjs");
class AsyncToolset extends import_tool_context.Toolset {
  _executor = new import_tool_executor.ToolExecutor({ owningActivity: null });
  asyncToolOptionsOverride;
  constructor({ id, tools, toolHandling }) {
    super({ id, tools });
    this.asyncToolOptionsOverride = toolHandling == null ? void 0 : toolHandling.asyncOptions;
  }
  static create(options) {
    return new AsyncToolset(options);
  }
  _attachActivity({
    activity,
    session
  }) {
    var _a;
    this._executor.setOwningActivity(
      activity
    );
    if (this.asyncToolOptionsOverride) {
      this._executor.setToolOptions(this.asyncToolOptionsOverride);
      return;
    }
    const activityOptions = (_a = activity == null ? void 0 : activity.agent) == null ? void 0 : _a._asyncToolOptions;
    if (activityOptions) {
      this._executor.setToolOptions(activityOptions);
      return;
    }
    const sessionOptions = session._asyncToolOptions;
    if (sessionOptions) {
      this._executor.setToolOptions(sessionOptions);
    }
  }
  async aclose() {
    await super.aclose();
    await this._executor.drain();
    await this._executor.aclose();
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AsyncToolset
});
//# sourceMappingURL=async_toolset.cjs.map