"use strict";
/**
 * 用户相关工具函数
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAliWorkNo = void 0;
exports.getAgentUserIdForRequest = getAgentUserIdForRequest;
exports.getAgentUserIdForStorageKey = getAgentUserIdForStorageKey;
const cn_ai_filter_1 = require("../../cn-ai-filter");
/**
 * 获取当前用户的 workId（`__PAGE_INFO__`，与助理接口里 `getOperator` 来源不同）
 */
const getAliWorkNo = () => {
    var _a, _b;
    return ((_b = (_a = window.__PAGE_INFO__) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.aliWorkNo) || '';
};
exports.getAliWorkNo = getAliWorkNo;
/**
 * 用于助理接口请求体的用户 id：`props.userId` → `getAliWorkNo()` → `getOperator()`；都无时为空串。
 */
function getAgentUserIdForRequest(userId) {
    var _a;
    const fromProp = userId === null || userId === void 0 ? void 0 : userId.trim();
    if (fromProp)
        return fromProp;
    const fromPageInfo = (0, exports.getAliWorkNo)().trim();
    if (fromPageInfo)
        return fromPageInfo;
    return ((_a = (0, cn_ai_filter_1.getOperator)()) === null || _a === void 0 ? void 0 : _a.trim()) || '';
}
/**
 * 用于助理显隐 localStorage key 的用户段，与 {@link getAgentUserIdForRequest} 同序。
 * 三者皆无时返回 `null`（不读写 localStorage，仅内存态）。
 */
function getAgentUserIdForStorageKey(userId) {
    const resolved = getAgentUserIdForRequest(userId);
    return resolved || null;
}
