/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import { formatUserReference } from '../../helpers/safeDisplay';
import {
Copy as ActionCopy,
Search as ActionSearch,
RotateCcw as ActionRotateCcw,
RefreshCw as ActionRefreshCw,
} from '@/components/common/icons/ActionIcons';
import React, { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import i18next from 'i18next';
import { Database, MessageSquareText, SlidersHorizontal } from 'lucide-react';
import {
Table,
Button,
Input,
Select,
Tag,
Tooltip,
DatePicker,
} from '@/components/ui';
import { copy, getQuotaPerUnit, showError, showSuccess } from '../../helpers';
import { API } from '../../helpers/api';
import { useOrgPromptRecords } from '../../hooks/org/useOrgData';
import OrgPanel from './components/OrgPanel';
import OrgStateBlock from './components/OrgStateBlock';
import { formatQuotaAsCNY } from './orgAuditFormat';
const emptyFilters = {
memberId: '',
modelName: '',
keyword: '',
startTimestamp: 0,
endTimestamp: 0,
};
const formatTokenCount = (value) =>
new Intl.NumberFormat(i18next.language).format(Number(value) || 0);
// 下钻明细:一条提示词记录 → 该次用户输入的全部接口调用行(首调 + agent 中间调用)。
// 数据来自平台消费日志(logs.prompt_group_key 索引等值查询),展开行时按需拉取。
const PromptCallDetails = ({ orgId, groupKey }) => {
const { t, i18n } = useTranslation();
const quotaPerUnit = getQuotaPerUnit();
const [calls, setCalls] = useState(null); // null = 加载中
const [error, setError] = useState('');
useEffect(() => {
let cancelled = false;
(async () => {
try {
const res = await API.get('/api/org/prompt-archive/records/calls', {
headers: { 'X-Org-Id': String(orgId) },
params: { group_key: groupKey },
});
if (cancelled) return;
if (res.data.success) {
setCalls(res.data.data?.items || []);
} else {
setError(res.data.message || t('查询失败'));
setCalls([]);
}
} catch (e) {
if (!cancelled) {
setError(e.message);
setCalls([]);
}
}
})();
return () => {
cancelled = true;
};
}, [orgId, groupKey, t]);
if (calls === null) {
return (