"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../_vendor/@legendapp/state/index.cjs");
const concurrencyStore$ = index.observable({
  // 当前活跃的会话数量
  currentActiveSessions: 0,
  // 最大并发消息数（默认 3）
  maxConcurrentMessages: 3
});
const concurrencyComputed$ = index.observable({
  // 是否可以发送新消息（未达到并发上限）
  canSendNewMessage: () => {
    const current = concurrencyStore$.currentActiveSessions.get();
    const max = concurrencyStore$.maxConcurrentMessages.get();
    return current < max;
  },
  // 获取完整的并发状态信息
  concurrencyStatus: () => {
    const current = concurrencyStore$.currentActiveSessions.get();
    const max = concurrencyStore$.maxConcurrentMessages.get();
    return {
      current,
      // 当前活跃数
      max,
      // 最大并发数
      available: max - current
      // 可用槽位
    };
  }
});
const concurrencyActions = {
  // 增加活跃会话数（不超过最大值）
  incrementActiveSessions: () => {
    const current = concurrencyStore$.currentActiveSessions.peek();
    const max = concurrencyStore$.maxConcurrentMessages.peek();
    concurrencyStore$.currentActiveSessions.set(Math.min(current + 1, max));
  },
  // 减少活跃会话数（不低于 0）
  decrementActiveSessions: () => {
    const current = concurrencyStore$.currentActiveSessions.peek();
    concurrencyStore$.currentActiveSessions.set(Math.max(0, current - 1));
  },
  // 设置最大并发消息数
  // ❌ 未使用
  setMaxConcurrentMessages: (max) => {
    const validMax = Math.max(1, max);
    concurrencyStore$.maxConcurrentMessages.set(validMax);
  },
  // 获取并发状态（同步方法）
  // ❌ 未使用
  getConcurrencyStatus: () => {
    const current = concurrencyStore$.currentActiveSessions.peek();
    const max = concurrencyStore$.maxConcurrentMessages.peek();
    return {
      current,
      max,
      available: max - current
    };
  }
};
exports.concurrencyActions = concurrencyActions;
exports.concurrencyComputed$ = concurrencyComputed$;
exports.concurrencyStore$ = concurrencyStore$;
//# sourceMappingURL=concurrency-store.cjs.map
