import { ToolExecutor } from "../voice/tool_executor.js";
import { Toolset } from "./tool_context.js";
class AsyncToolset extends Toolset {
  _executor = new 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();
  }
}
export {
  AsyncToolset
};
//# sourceMappingURL=async_toolset.js.map