@yuku123/z-team-component 0.2.140 → 0.2.141

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/{AdminModuleContent-DDB35gOh.js → AdminModuleContent-FFU5MUjw.js} +10526 -10697
  2. package/dist/{ChangeLogView-AKOZ6Ski.js → ChangeLogView-C5v5uT8L.js} +1 -1
  3. package/dist/{ComponentDoc-SiXXhka1.js → ComponentDoc-DnZq0_Rk.js} +1318 -1313
  4. package/dist/{InvitationManagementPage-CRbABOKe.js → InvitationManagementPage-dEBNe9_s.js} +1 -1
  5. package/dist/{OnboardingPage-BNJopRYO.js → OnboardingPage-BW8WhBg5.js} +2 -2
  6. package/dist/ScheduledTasks-BaZ0_klE.js +12024 -0
  7. package/dist/SystemShell-I7vWo1XG.js +858 -0
  8. package/dist/{admin-logs-B3IxooG2.js → admin-logs-BDPC3Q_Y.js} +5 -5
  9. package/dist/{api-DmBlT5MH.js → api-BJ5jPWNm.js} +1 -1
  10. package/dist/{api-DW8nsucC.js → api-U9U4zzq_.js} +1 -1
  11. package/dist/createWorkspaceWsHandler-B6TdD0Oz.js +11757 -0
  12. package/dist/{index-DCAO83Wb.js → index-BGZV4U3S.js} +1325 -1187
  13. package/dist/{index-Hv2KDG7i.js → index-BPEfgkzE.js} +3 -3
  14. package/dist/{index-VmRWH4U5.js → index-BXaJSMd0.js} +9 -9
  15. package/dist/{index-C1nr0UeB.js → index-Bfw6OE5L.js} +19 -20
  16. package/dist/index-BlDMnzJF.js +18 -0
  17. package/dist/{index-BBLRGBWu.js → index-BmlFIrWx.js} +1 -1
  18. package/dist/{index-C7DSDopw.js → index-BwhK44Dc.js} +26 -27
  19. package/dist/{index-l9KH8r7F.js → index-CP5raaOW.js} +780 -792
  20. package/dist/{index-CvHMXrAD.js → index-CPpqideA.js} +1 -1
  21. package/dist/{index-C24QsGsG.js → index-CToJEufJ.js} +1 -1
  22. package/dist/{index-CJ7dJejJ.js → index-CVgvlDAT.js} +17 -17
  23. package/dist/{index-BSqUODiN.js → index-CmzTSdmD.js} +30 -31
  24. package/dist/{index-BV64kKse.js → index-CsNtBWH-.js} +2 -2
  25. package/dist/index-DIv1OJ_2.js +1840 -0
  26. package/dist/{index-Du95tdVf.js → index-DKUg7Evq.js} +28 -29
  27. package/dist/{index-DULYXalY.js → index-DSXVCDf7.js} +9 -9
  28. package/dist/{index-CXjen4Gx.js → index-Dd5RE_0a.js} +342 -389
  29. package/dist/index-DuZrrpXt.js +1298 -0
  30. package/dist/{index-D-G4mbxH.js → index-Gn0zdd5m.js} +2 -2
  31. package/dist/index-WWGxF0UX.js +136 -0
  32. package/dist/{index-DHrMSEVJ.js → index-XTNGZnrF.js} +1 -1
  33. package/dist/{index-D7thpI99.js → index-XgaiU13i.js} +1 -1
  34. package/dist/{index-DjbLq5lI.js → index-d6RIzlsj.js} +2 -2
  35. package/dist/{index-DDOfdrn4.js → index-kjli87DO.js} +3895 -3964
  36. package/dist/{index-D440bEgm.js → index-mDjl3m2W.js} +198 -192
  37. package/dist/{index-CEoS_jEa.js → index-skl-gjj4.js} +6 -6
  38. package/dist/index.js +1 -1
  39. package/dist/instance-D_EP8AQm.js +116 -0
  40. package/dist/{menuPermission-DxknHmt8.js → menuPermission-Bhnols4v.js} +3 -3
  41. package/dist/pages.js +1 -1
  42. package/dist/{send-default-agent-team-message-DYytBtLc.js → send-default-agent-team-message-0RB1pYex.js} +1 -1
  43. package/dist/{training-CKYPSkUP.js → training-B1eRX8g1.js} +1 -1
  44. package/dist/{webide-JAalC_Wr.js → webide-C4ThGZzY.js} +1161 -1317
  45. package/dist/z-team-component.css +1 -1
  46. package/package.json +4 -4
  47. package/dist/ScheduledTasks-Cn_CEZ-B.js +0 -12006
  48. package/dist/SystemShell-B8Tyluzu.js +0 -893
  49. package/dist/SystemWorkbench.module-DpLM0zgA.js +0 -36
  50. package/dist/createWorkspaceWsHandler-5MHgQGfJ.js +0 -12902
  51. package/dist/index-BT4oQJby.js +0 -228
  52. package/dist/index-DrDFy5jN.js +0 -139
  53. package/dist/index-DvslXAjT.js +0 -1323
  54. package/dist/index-NIu3OKHi.js +0 -1868
  55. package/dist/instance-B4SrJ-BY.js +0 -186
  56. package/dist/sso-user-DN6kSAc0.js +0 -43
@@ -1,1868 +0,0 @@
1
- import { jsxs as s, jsx as e } from "react/jsx-runtime";
2
- import { CopyOutlined as ie, ReloadOutlined as we, PlusOutlined as Ee, StopOutlined as Ye, DeleteOutlined as Xe, ClearOutlined as Ze, CloseOutlined as et, SendOutlined as tt, RobotOutlined as _e, DownOutlined as at, RightOutlined as nt, CloudServerOutlined as Pe, MessageOutlined as st, BarChartOutlined as ot, KeyOutlined as be, NodeIndexOutlined as rt, ApiOutlined as lt, ToolOutlined as ct, FundOutlined as it } from "@ant-design/icons";
3
- import { useState as C, useEffect as V, useCallback as H, useRef as ge, useMemo as Me, Suspense as dt, lazy as mt } from "react";
4
- import { Table as ce, Tooltip as oe, Tabs as $e, Input as Ce, Button as L, Modal as ye, Drawer as Oe, Spin as se, Statistic as K, message as F, Tag as Z, Select as ut, Checkbox as ht } from "antd";
5
- import { u as Ue } from "./ComponentDoc-SiXXhka1.js";
6
- import { M as pt } from "./index-C24QsGsG.js";
7
- import { s as z } from "./SystemWorkbench.module-DpLM0zgA.js";
8
- import { AgentAppList as kt, AgentInstanceManager as gt, McpPage as yt } from "@yuku123/z-agent-component";
9
- import { Catalog as ft } from "@yuku123/z-skill-component";
10
- const ue = "ft_gateway_default_ak", Le = "system-default", ee = "", Ne = "";
11
- function te(t = {}) {
12
- const n = { Accept: "application/json", ...t };
13
- try {
14
- const o = localStorage.getItem("token");
15
- o && (n.Authorization = `Bearer ${o}`);
16
- } catch {
17
- }
18
- return n;
19
- }
20
- function _t(t) {
21
- return {
22
- modelName: String(t.modelName ?? t.model_name ?? t.service ?? ""),
23
- service: String(t.service ?? t.modelName ?? ""),
24
- endpoint: String(t.endpoint ?? ""),
25
- modelProvider: t.modelProvider ?? t.model_provider ?? null,
26
- apiType: String(t.apiType ?? t.api_type ?? "OpenAPI")
27
- };
28
- }
29
- async function Te() {
30
- let t;
31
- try {
32
- t = await fetch(`${ee}/api/scenario-instances/0/models`, {
33
- credentials: "include",
34
- headers: te({
35
- Accept: "application/json",
36
- "project-env": window.ENV_TYPE ?? "local"
37
- })
38
- });
39
- } catch {
40
- throw new Error("模型列表不可达:模型配置接口请求失败");
41
- }
42
- if (!t.ok)
43
- throw new Error(`模型列表获取失败(HTTP ${t.status})`);
44
- let n;
45
- try {
46
- n = await t.json();
47
- } catch {
48
- throw new Error("模型列表返回格式异常(非 JSON)");
49
- }
50
- const o = n != null && n.success ? n.data : (n == null ? void 0 : n.data) ?? n;
51
- if (!Array.isArray(o))
52
- throw new Error("模型列表返回格式异常(非数组)");
53
- return o.map(_t);
54
- }
55
- async function Ct(t, n, o, i) {
56
- var S, N, g;
57
- const c = await fetch(`${Ne}/v1/chat/completions`, {
58
- method: "POST",
59
- headers: {
60
- "Content-Type": "application/json",
61
- Authorization: `Bearer ${t}`,
62
- Accept: "text/event-stream"
63
- },
64
- body: JSON.stringify({
65
- model: n,
66
- messages: o,
67
- stream: !0
68
- }),
69
- signal: i.signal
70
- });
71
- if (!c.ok || !c.body) {
72
- const m = await c.text().catch(() => "");
73
- if (/<!doctype html/i.test(m.slice(0, 200)))
74
- throw new Error("模型网关未接入(/v1/chat/completions 落到主壳 SPA,无网关响应)");
75
- let k = `HTTP ${c.status}`;
76
- try {
77
- const p = JSON.parse(m);
78
- k = ((S = p == null ? void 0 : p.error) == null ? void 0 : S.message) ?? k;
79
- } catch {
80
- m && (k = m);
81
- }
82
- throw new Error(k);
83
- }
84
- const w = c.body.getReader(), B = new TextDecoder();
85
- let A = "", f;
86
- try {
87
- for (; ; ) {
88
- const { done: m, value: k } = await w.read();
89
- if (m) break;
90
- A += B.decode(k, { stream: !0 });
91
- const p = A.split(`
92
-
93
- `);
94
- A = p.pop() ?? "";
95
- for (const d of p) {
96
- let _ = "";
97
- for (const h of d.split(`
98
- `))
99
- h.startsWith("data:") && (_ += h.slice(5).trim());
100
- if (!_ || _ === "[DONE]") {
101
- if (_ === "[DONE]") {
102
- i.onDone(f);
103
- return;
104
- }
105
- continue;
106
- }
107
- try {
108
- const h = JSON.parse(_), P = h == null ? void 0 : h.choices;
109
- if (h != null && h.usage) {
110
- const M = {
111
- promptTokens: h.usage.prompt_tokens ?? 0,
112
- completionTokens: h.usage.completion_tokens ?? 0,
113
- totalTokens: h.usage.total_tokens ?? 0
114
- };
115
- (!f || M.totalTokens > 0) && (f = M);
116
- }
117
- if (Array.isArray(P) && P.length > 0) {
118
- const M = (N = P[0]) == null ? void 0 : N.delta;
119
- M != null && M.content && i.onDelta(M.content);
120
- continue;
121
- }
122
- i.onDone(f);
123
- return;
124
- } catch {
125
- }
126
- }
127
- }
128
- i.onDone(f);
129
- } catch (m) {
130
- if ((g = i.signal) != null && g.aborted) return;
131
- throw i.onError(m instanceof Error ? m : new Error(String(m))), m;
132
- }
133
- }
134
- async function re(t, n) {
135
- const o = await t.text();
136
- if (!t.ok)
137
- throw new Error(`${n}失败 HTTP ${t.status}${o ? `: ${o.slice(0, 120)}` : ""}`);
138
- if (/<!doctype html/i.test(o.slice(0, 200)))
139
- throw new Error("AK 接口落到主壳 SPA(无后端响应)");
140
- try {
141
- return JSON.parse(o);
142
- } catch {
143
- throw new Error(`${n}返回非 JSON:${o.slice(0, 120)}`);
144
- }
145
- }
146
- function Nt(t) {
147
- const n = t.status === 1;
148
- return {
149
- id: Number(t.id),
150
- akPrefix: t.access_key ?? "",
151
- userId: t.owner_user_id ?? "",
152
- userName: t.owner_user_name ?? "",
153
- description: t.description || t.ak_name || "",
154
- status: n ? "active" : "disabled",
155
- active: n,
156
- isDeleted: t.is_deleted ?? 0,
157
- totalRequests: 0,
158
- totalTokens: Number(t.total_tokens ?? 0),
159
- tokenQuota: 0,
160
- rateLimitRpm: 0,
161
- defaultModel: null,
162
- lastUsedAt: t.last_used_time ?? null,
163
- createTime: (t.created_time ?? "").replace("T", " ").slice(0, 19),
164
- updateTime: (t.updated_time ?? "").replace("T", " ").slice(0, 19),
165
- secret: t.secret_key
166
- };
167
- }
168
- async function ze(t, n, o) {
169
- const i = await fetch(`${ee}/api/ak/create`, {
170
- method: "POST",
171
- headers: te({ Accept: "application/json", "Content-Type": "application/json" }),
172
- credentials: "include",
173
- body: JSON.stringify({
174
- akName: o || `AK-${n || t}`,
175
- description: o,
176
- akType: "PERSONAL",
177
- ownerUserId: t,
178
- ownerUserName: n
179
- })
180
- }), c = await re(i, "创建 AK"), w = (c == null ? void 0 : c.data) ?? {}, B = w.accessKey ?? "", A = w.secretKey ?? "";
181
- return B && A && Ae(B, A), { apiKey: A, akPrefix: B, message: "AK 已创建,secretKey 仅创建时可见" };
182
- }
183
- async function he(t) {
184
- const n = await fetch(
185
- `${ee}/api/ak/list`,
186
- { headers: te({ Accept: "application/json" }), credentials: "include" }
187
- ), o = await re(n, "获取 AK 列表"), i = Array.isArray(o == null ? void 0 : o.data) ? o.data : [];
188
- return (t ? i.filter((w) => (w.owner_user_id == null || w.owner_user_id === "" ? Le : String(w.owner_user_id)) === String(t)) : i).filter((w) => (w.is_deleted ?? 0) === 0).map(Nt);
189
- }
190
- async function vt(t) {
191
- const n = await fetch(`${ee}/api/ak/delete?id=${encodeURIComponent(String(t))}`, {
192
- method: "POST",
193
- headers: te({ Accept: "application/json" }),
194
- credentials: "include"
195
- });
196
- await re(n, "吊销 AK");
197
- }
198
- async function wt(t, n) {
199
- const o = await fetch(
200
- `${ee}/api/ak/toggle?id=${encodeURIComponent(String(t))}&status=${n ? 1 : 0}`,
201
- {
202
- method: "POST",
203
- headers: te({ Accept: "application/json" }),
204
- credentials: "include"
205
- }
206
- );
207
- await re(o, n ? "启用 AK" : "停用 AK");
208
- }
209
- async function Re(t) {
210
- var m, k;
211
- const n = await fetch(
212
- `${ee}/api/admin/llm-call-monitor/stats?hours=168`,
213
- { headers: te({ Accept: "application/json" }), credentials: "include" }
214
- ), o = await re(n, "获取调用统计"), c = ((o == null ? void 0 : o.data) ?? {}).summary ?? {};
215
- let w = [];
216
- try {
217
- const p = await fetch(
218
- `${ee}/api/admin/llm-call-monitor/recent?page=1&size=20`,
219
- { headers: te({ Accept: "application/json" }), credentials: "include" }
220
- ), d = await re(p, "获取调用明细");
221
- w = (Array.isArray((m = d == null ? void 0 : d.data) == null ? void 0 : m.records) ? d.data.records : []).map((h, P) => {
222
- const M = Number(h.promptTokens ?? 0), q = Number(h.completionTokens ?? 0);
223
- return {
224
- id: Number(h.id ?? P),
225
- apiKeyId: t,
226
- protocol: "chat/completions",
227
- model: String(h.model ?? ""),
228
- stream: Number(h.stream ?? 0),
229
- promptTokens: M,
230
- completionTokens: q,
231
- totalTokens: Number(h.totalTokens ?? M + q),
232
- latencyMs: Number(h.durationMs ?? 0),
233
- statusCode: h.success === !1 || h.success === 0 ? 500 : 200,
234
- errorMsg: h.errorType ?? null,
235
- createTime: String(h.createTime ?? "").replace("T", " ").slice(0, 19)
236
- };
237
- });
238
- } catch {
239
- }
240
- const B = {}, A = {};
241
- for (const p of w) {
242
- const d = B[k = p.model] || (B[k] = [0, 0, 0]);
243
- d[0] += 1, d[1] += p.promptTokens, d[2] += p.completionTokens;
244
- const _ = (p.createTime || "").slice(0, 10);
245
- if (_) {
246
- const h = A[_] || (A[_] = [0, 0, 0]);
247
- h[0] += 1, h[1] += p.promptTokens, h[2] += p.completionTokens;
248
- }
249
- }
250
- const f = Number(c.totalTokens ?? 0), S = w.reduce((p, d) => p + d.totalTokens, 0), N = w.reduce((p, d) => p + d.promptTokens, 0), g = w.reduce((p, d) => p + d.completionTokens, 0);
251
- return {
252
- totalRequests: Number(c.totalCount ?? 0),
253
- // 汇总口径优先用后端整窗合计(后端 selectStats 才有 token 合计),
254
- // 明细只有最近一页 ⇒ 只在汇总缺失时用明细兜底。
255
- totalPromptTokens: Number(c.totalPromptTokens ?? 0) || N,
256
- totalCompletionTokens: Number(c.totalCompletionTokens ?? 0) || g,
257
- totalTokens: f || S,
258
- avgLatencyMs: Number(c.avgDurationMs ?? 0),
259
- errorCount: Number(c.failCount ?? 0),
260
- daily: A,
261
- models: B,
262
- recent: w
263
- };
264
- }
265
- function Tt() {
266
- return typeof window < "u" ? `${window.location.origin}${Ne}` : Ne;
267
- }
268
- async function Se(t) {
269
- const n = await fetch(`${ee}${t}`, {
270
- headers: te({ Accept: "application/json" }),
271
- credentials: "include"
272
- });
273
- if (!(n.headers.get("content-type") || "").includes("json"))
274
- throw new Error("网关控制面未启用(该路径返回的是前端页面,不是接口)");
275
- if (!n.ok)
276
- throw new Error(`网关控制面请求失败(HTTP ${n.status})`);
277
- return n.json();
278
- }
279
- async function De() {
280
- return Se("/z-llm/admin/overview");
281
- }
282
- async function St() {
283
- return Se("/z-llm/admin/health");
284
- }
285
- async function Ge() {
286
- const t = await Se("/z-llm/admin/usage");
287
- return (Array.isArray(t == null ? void 0 : t.byTenant) ? t.byTenant : []).map((o) => ({
288
- tenantCode: String(o.tenantCode ?? o.keyId ?? ""),
289
- requests: Number(o.requests ?? o.count ?? 0),
290
- promptTokens: Number(o.promptTokens ?? 0),
291
- completionTokens: Number(o.completionTokens ?? 0),
292
- cost: Number(o.cost ?? 0)
293
- }));
294
- }
295
- const ve = "ft_gateway_ak_cache";
296
- function Ae(t, n) {
297
- try {
298
- const o = JSON.parse(localStorage.getItem(ve) || "{}");
299
- o[t] = n, localStorage.setItem(ve, JSON.stringify(o));
300
- } catch {
301
- }
302
- }
303
- function At(t) {
304
- try {
305
- return JSON.parse(localStorage.getItem(ve) || "{}")[t] || null;
306
- } catch {
307
- return null;
308
- }
309
- }
310
- async function xt() {
311
- try {
312
- const i = localStorage.getItem(ue);
313
- if (i) return i;
314
- } catch {
315
- }
316
- const n = (await he("").catch(() => [])).find((i) => i.active && i.secret);
317
- if (n != null && n.secret) {
318
- try {
319
- localStorage.setItem(ue, n.secret);
320
- } catch {
321
- }
322
- return n.akPrefix && Ae(n.akPrefix, n.secret), n.secret;
323
- }
324
- const o = await ze(
325
- "system-default",
326
- "系统默认",
327
- "智能工作台默认AK(自动创建)"
328
- );
329
- if (!o.apiKey)
330
- throw new Error("AK 创建成功但未返回 secretKey");
331
- try {
332
- localStorage.setItem(ue, o.apiKey);
333
- } catch {
334
- }
335
- return o.apiKey;
336
- }
337
- function He() {
338
- try {
339
- localStorage.removeItem(ue);
340
- } catch {
341
- }
342
- }
343
- const Bt = "_container_1ctyd_7", It = "_panelArea_1ctyd_16", Pt = "_modelGrid_1ctyd_45", bt = "_modelCard_1ctyd_51", Kt = "_modelCardSelected_1ctyd_80", Et = "_modelCardHeader_1ctyd_85", Mt = "_modelIconWrap_1ctyd_92", $t = "_modelCardInfo_1ctyd_105", Ot = "_modelName_1ctyd_110", Ut = "_modelTags_1ctyd_119", Lt = "_modelEndpoint_1ctyd_135", zt = "_modelCardFooter_1ctyd_144", Rt = "_modelCheckbox_1ctyd_152", Dt = "_modelActionBar_1ctyd_159", Gt = "_modelSelectionCount_1ctyd_173", Ht = "_chatContainer_1ctyd_182", jt = "_chatHeader_1ctyd_189", Ft = "_chatPanels_1ctyd_204", qt = "_chatPanel_1ctyd_204", Jt = "_chatPanelHeader_1ctyd_231", Wt = "_chatPanelClose_1ctyd_241", Qt = "_chatPanelBody_1ctyd_253", Vt = "_chatMsgUser_1ctyd_262", Yt = "_chatMsgAI_1ctyd_274", Xt = "_chatMsgError_1ctyd_287", Zt = "_chatStreamingCursor_1ctyd_297", ea = "_chatUsageBar_1ctyd_316", ta = "_chatThinkBlock_1ctyd_326", aa = "_chatInputBar_1ctyd_375", na = "_chatInput_1ctyd_375", sa = "_addPanelBtn_1ctyd_388", oa = "_akContainer_1ctyd_417", ra = "_akIntegrationPanel_1ctyd_423", la = "_akIntegrationTitle_1ctyd_430", ca = "_akIntegrationGrid_1ctyd_437", ia = "_akCodeBlock_1ctyd_443", da = "_akCodeLabel_1ctyd_455", ma = "_akCard_1ctyd_462", ua = "_akCardRow_1ctyd_480", ha = "_akTitle_1ctyd_487", pa = "_akPrefixSmall_1ctyd_497", ka = "_akStatus_1ctyd_503", ga = "_akStatusActive_1ctyd_509", ya = "_akStatusRevoked_1ctyd_515", fa = "_akCardActions_1ctyd_521", _a = "_akCardRow2_1ctyd_528", Ca = "_akMiniBar_1ctyd_534", Na = "_akMiniBarFill_1ctyd_543", va = "_akUsageText_1ctyd_550", wa = "_akMetaText_1ctyd_557", Ta = "_akEmpty_1ctyd_563", Sa = "_akBaseUrlRow_1ctyd_571", Aa = "_akBaseUrlItem_1ctyd_577", xa = "_akBaseUrlLabel_1ctyd_587", Ba = "_akBaseUrlValue_1ctyd_593", Ia = "_akCopyIcon_1ctyd_603", Pa = "_usageDrawerContent_1ctyd_617", ba = "_usageStatsGrid_1ctyd_623", Ka = "_usageSection_1ctyd_629", Ea = "_usageSectionTitle_1ctyd_633", Ma = "_usageBarChart_1ctyd_643", $a = "_usageBarCol_1ctyd_652", Oa = "_usageBar_1ctyd_643", Ua = "_usageBarLabel_1ctyd_675", La = "_modelBreakdown_1ctyd_683", za = "_modelBreakdownRow_1ctyd_689", Ra = "_modelBreakdownName_1ctyd_695", Da = "_modelBreakdownBar_1ctyd_705", Ga = "_modelBreakdownFill_1ctyd_713", Ha = "_modelBreakdownCount_1ctyd_720", ja = "_usageEmpty_1ctyd_727", a = {
344
- container: Bt,
345
- panelArea: It,
346
- modelGrid: Pt,
347
- modelCard: bt,
348
- modelCardSelected: Kt,
349
- modelCardHeader: Et,
350
- modelIconWrap: Mt,
351
- modelCardInfo: $t,
352
- modelName: Ot,
353
- modelTags: Ut,
354
- modelEndpoint: Lt,
355
- modelCardFooter: zt,
356
- modelCheckbox: Rt,
357
- modelActionBar: Dt,
358
- modelSelectionCount: Gt,
359
- chatContainer: Ht,
360
- chatHeader: jt,
361
- chatPanels: Ft,
362
- chatPanel: qt,
363
- chatPanelHeader: Jt,
364
- chatPanelClose: Wt,
365
- chatPanelBody: Qt,
366
- chatMsgUser: Vt,
367
- chatMsgAI: Yt,
368
- chatMsgError: Xt,
369
- chatStreamingCursor: Zt,
370
- chatUsageBar: ea,
371
- chatThinkBlock: ta,
372
- chatInputBar: aa,
373
- chatInput: na,
374
- addPanelBtn: sa,
375
- akContainer: oa,
376
- akIntegrationPanel: ra,
377
- akIntegrationTitle: la,
378
- akIntegrationGrid: ca,
379
- akCodeBlock: ia,
380
- akCodeLabel: da,
381
- akCard: ma,
382
- akCardRow: ua,
383
- akTitle: ha,
384
- akPrefixSmall: pa,
385
- akStatus: ka,
386
- akStatusActive: ga,
387
- akStatusRevoked: ya,
388
- akCardActions: fa,
389
- akCardRow2: _a,
390
- akMiniBar: Ca,
391
- akMiniBarFill: Na,
392
- akUsageText: va,
393
- akMetaText: wa,
394
- akEmpty: Ta,
395
- akBaseUrlRow: Sa,
396
- akBaseUrlItem: Aa,
397
- akBaseUrlLabel: xa,
398
- akBaseUrlValue: Ba,
399
- akCopyIcon: Ia,
400
- usageDrawerContent: Pa,
401
- usageStatsGrid: ba,
402
- usageSection: Ka,
403
- usageSectionTitle: Ea,
404
- usageBarChart: Ma,
405
- usageBarCol: $a,
406
- usageBar: Oa,
407
- usageBarLabel: Ua,
408
- modelBreakdown: La,
409
- modelBreakdownRow: za,
410
- modelBreakdownName: Ra,
411
- modelBreakdownBar: Da,
412
- modelBreakdownFill: Ga,
413
- modelBreakdownCount: Ha,
414
- usageEmpty: ja
415
- };
416
- function de(t) {
417
- return t >= 1e6 ? `${(t / 1e6).toFixed(1)}M` : t >= 1e3 ? `${(t / 1e3).toFixed(1)}K` : `${t}`;
418
- }
419
- function Fa(t, n) {
420
- return `# OpenAI 兼容
421
- curl -X POST ${t}/v1/chat/completions \\
422
- -H "Content-Type: application/json" \\
423
- -H "Authorization: Bearer ft-xxx" \\
424
- -d '{
425
- "model": "${n}",
426
- "messages": [{"role":"user","content":"你好"}],
427
- "stream": true
428
- }'`;
429
- }
430
- function qa(t, n) {
431
- return `# Anthropic 兼容
432
- curl -X POST ${t}/v1/messages \\
433
- -H "Content-Type: application/json" \\
434
- -H "x-api-key: ft-xxx" \\
435
- -d '{
436
- "model": "${n}",
437
- "messages": [{"role":"user","content":"你好"}]
438
- }'`;
439
- }
440
- function Ja() {
441
- const [t, n] = C("personal"), [o, i] = C([]), [c, w] = C([]), [B, A] = C(!0), [f, S] = C(!1), [N, g] = C(!1), [m, k] = C(""), [p, d] = C({ open: !1 }), [_, h] = C(null), [P, M] = C(null), [q, ae] = C(!1), [Y, u] = C(null), [$, R] = C([]), [r, y] = C(""), x = Ue((l) => l.currentUser), b = String((x == null ? void 0 : x.id) ?? ""), O = (x == null ? void 0 : x.username) ?? "", [E, J] = C(""), X = Tt(), [D, j] = C("<model-name>");
442
- V(() => {
443
- let l = !1;
444
- return Te().then((v) => {
445
- !l && v.length > 0 && j(v[0].modelName);
446
- }).catch(() => {
447
- }), () => {
448
- l = !0;
449
- };
450
- }, []), V(() => {
451
- let l = !1;
452
- return Promise.all([De(), Ge()]).then(([v, Q]) => {
453
- l || (u(v), R(Q), y(""));
454
- }).catch((v) => {
455
- l || (u(null), R([]), y(v instanceof Error ? v.message : "网关台账不可用"));
456
- }), () => {
457
- l = !0;
458
- };
459
- }, []);
460
- const W = H(async () => {
461
- A(!0);
462
- try {
463
- const l = b ? await he(b).catch(() => []) : [], [v] = await Promise.all([
464
- he("system-default").catch(() => [])
465
- ]);
466
- i(v), w(l);
467
- } finally {
468
- A(!1);
469
- }
470
- }, [b]);
471
- V(() => {
472
- W();
473
- }, [W]);
474
- const pe = () => {
475
- k(""), g(!0);
476
- }, xe = async () => {
477
- if (!m.trim()) {
478
- F.warning("请输入 AK 名称");
479
- return;
480
- }
481
- if (!b) {
482
- F.warning("登录态不可用,无法生成 AK");
483
- return;
484
- }
485
- S(!0);
486
- try {
487
- const l = await ze(b, O, m.trim());
488
- Ae(l.akPrefix, l.apiKey), g(!1), d({
489
- open: !0,
490
- apiKey: l.apiKey,
491
- akPrefix: l.akPrefix
492
- }), W();
493
- } catch (l) {
494
- F.error(l instanceof Error ? l.message : "创建 AK 失败");
495
- } finally {
496
- S(!1);
497
- }
498
- }, je = (l) => {
499
- ye.confirm({
500
- title: "确认吊销此 AK?",
501
- content: "吊销后此 AK 将立即失效,无法恢复。",
502
- okText: "确认吊销",
503
- okType: "danger",
504
- cancelText: "取消",
505
- onOk: async () => {
506
- try {
507
- await vt(l), F.success("AK 已吊销"), W(), He();
508
- } catch (v) {
509
- F.error(v instanceof Error ? v.message : "吊销失败");
510
- }
511
- }
512
- });
513
- }, Be = async (l) => {
514
- try {
515
- await wt(l.id, !l.active), F.success(l.active ? "AK 已停用" : "AK 已启用"), W();
516
- } catch (v) {
517
- F.error(v instanceof Error ? v.message : "操作失败");
518
- }
519
- }, le = (l) => {
520
- navigator.clipboard.writeText(l).then(() => F.success("已复制到剪贴板")).catch(() => F.warning("复制失败,请手动复制"));
521
- }, Fe = (l) => {
522
- const v = At(l.akPrefix);
523
- v ? le(v) : (le(l.akPrefix), F.info("完整 AK 未在本地缓存(可能在本设备外创建),已复制前缀"));
524
- }, qe = async (l) => {
525
- h(l), ae(!0), M(null);
526
- try {
527
- const v = await Re(l.id);
528
- M(v);
529
- } catch (v) {
530
- F.error(v instanceof Error ? v.message : "获取用量失败");
531
- } finally {
532
- ae(!1);
533
- }
534
- }, Je = () => {
535
- h(null), M(null);
536
- }, We = (l) => {
537
- const v = Object.entries(l);
538
- if (v.length === 0)
539
- return /* @__PURE__ */ e("span", { className: a.usageEmpty, children: "暂无数据" });
540
- const Q = Math.max(...v.map(([, U]) => U[1] + U[2]), 1);
541
- return /* @__PURE__ */ e("div", { className: a.usageBarChart, children: v.map(([U, G]) => {
542
- const T = G[1] + G[2], ke = T / Q * 100;
543
- return /* @__PURE__ */ s("div", { className: a.usageBarCol, children: [
544
- /* @__PURE__ */ e(oe, { title: `${U}: ${G[0]}次 / ${T} tokens`, children: /* @__PURE__ */ e(
545
- "div",
546
- {
547
- className: a.usageBar,
548
- style: { height: `${Math.max(ke, 2)}%` }
549
- }
550
- ) }),
551
- /* @__PURE__ */ e("span", { className: a.usageBarLabel, children: U })
552
- ] }, U);
553
- }) });
554
- }, Qe = (l) => {
555
- const v = Object.entries(l);
556
- if (v.length === 0)
557
- return /* @__PURE__ */ e("span", { className: a.usageEmpty, children: "暂无数据" });
558
- const Q = Math.max(...v.map(([, U]) => U[0]), 1);
559
- return /* @__PURE__ */ e("div", { className: a.modelBreakdown, children: v.sort((U, G) => G[1][0] - U[1][0]).map(([U, G]) => /* @__PURE__ */ s("div", { className: a.modelBreakdownRow, children: [
560
- /* @__PURE__ */ e("span", { className: a.modelBreakdownName, children: U }),
561
- /* @__PURE__ */ e("div", { className: a.modelBreakdownBar, children: /* @__PURE__ */ e(
562
- "div",
563
- {
564
- className: a.modelBreakdownFill,
565
- style: { width: `${G[0] / Q * 100}%` }
566
- }
567
- ) }),
568
- /* @__PURE__ */ s("span", { className: a.modelBreakdownCount, children: [
569
- G[0],
570
- "次 / ",
571
- G[1] + (G[2] || 0),
572
- "tokens"
573
- ] })
574
- ] }, U)) });
575
- }, Ve = [
576
- {
577
- title: "时间",
578
- dataIndex: "createTime",
579
- key: "createTime",
580
- width: 160,
581
- render: (l) => l ? new Date(l).toLocaleString("zh-CN") : "-"
582
- },
583
- { title: "模型", dataIndex: "model", key: "model", width: 140 },
584
- {
585
- title: "协议",
586
- dataIndex: "protocol",
587
- key: "protocol",
588
- width: 90,
589
- render: (l) => /* @__PURE__ */ e(Z, { children: l })
590
- },
591
- {
592
- title: "输入",
593
- dataIndex: "promptTokens",
594
- key: "promptTokens",
595
- width: 70
596
- },
597
- {
598
- title: "输出",
599
- dataIndex: "completionTokens",
600
- key: "completionTokens",
601
- width: 70
602
- },
603
- {
604
- title: "总Token",
605
- dataIndex: "totalTokens",
606
- key: "totalTokens",
607
- width: 80
608
- },
609
- {
610
- title: "耗时",
611
- dataIndex: "latencyMs",
612
- key: "latencyMs",
613
- width: 70,
614
- render: (l) => l ? `${l}ms` : "-"
615
- },
616
- {
617
- title: "状态",
618
- dataIndex: "statusCode",
619
- key: "statusCode",
620
- width: 60,
621
- render: (l) => l ? /* @__PURE__ */ e(Z, { color: l < 400 ? "green" : "red", children: l }) : "-"
622
- }
623
- ], Ie = (l, v) => {
624
- const Q = Array.isArray(l) ? l : [], U = E.trim().toLowerCase(), G = U ? Q.filter(
625
- (T) => `${T.description || ""} ${T.akPrefix || ""} ${T.defaultModel || ""}`.toLowerCase().includes(U)
626
- ) : Q;
627
- return B ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 40 }, children: /* @__PURE__ */ e(se, { tip: "加载中..." }) }) : Q.length === 0 ? /* @__PURE__ */ e("div", { className: a.akEmpty, children: v ? "暂无应用 AK" : "暂无个人 AK,点击上方按钮生成" }) : G.length === 0 ? /* @__PURE__ */ e("div", { className: a.akEmpty, children: "无匹配 AK" }) : /* @__PURE__ */ e("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: G.map((T) => /* @__PURE__ */ s(
628
- "div",
629
- {
630
- className: a.akCard,
631
- onClick: () => qe(T),
632
- children: [
633
- /* @__PURE__ */ s("div", { className: a.akCardRow, children: [
634
- /* @__PURE__ */ e("span", { className: a.akTitle, children: T.description || T.akPrefix.replace("...", "**") }),
635
- /* @__PURE__ */ e("code", { className: a.akPrefixSmall, children: T.akPrefix.replace("...", "**") }),
636
- /* @__PURE__ */ e(
637
- "span",
638
- {
639
- className: `${a.akStatus} ${T.active ? a.akStatusActive : a.akStatusRevoked}`,
640
- children: T.active ? "活跃" : "已吊销"
641
- }
642
- ),
643
- T.defaultModel && /* @__PURE__ */ s(Z, { style: { fontSize: 11 }, children: [
644
- "默认: ",
645
- T.defaultModel
646
- ] }),
647
- /* @__PURE__ */ s(
648
- "div",
649
- {
650
- className: a.akCardActions,
651
- onClick: (ke) => ke.stopPropagation(),
652
- children: [
653
- /* @__PURE__ */ e(oe, { title: "复制完整 AK", children: /* @__PURE__ */ e(
654
- L,
655
- {
656
- size: "small",
657
- icon: /* @__PURE__ */ e(ie, {}),
658
- onClick: () => Fe(T),
659
- children: "复制"
660
- }
661
- ) }),
662
- !v && T.active && /* @__PURE__ */ e(
663
- L,
664
- {
665
- size: "small",
666
- icon: /* @__PURE__ */ e(Ye, {}),
667
- onClick: () => void Be(T),
668
- children: "停用"
669
- }
670
- ),
671
- !v && !T.active && /* @__PURE__ */ e(
672
- L,
673
- {
674
- size: "small",
675
- type: "primary",
676
- ghost: !0,
677
- onClick: () => void Be(T),
678
- children: "启用"
679
- }
680
- ),
681
- !v && T.active && /* @__PURE__ */ e(
682
- L,
683
- {
684
- size: "small",
685
- danger: !0,
686
- icon: /* @__PURE__ */ e(Xe, {}),
687
- onClick: () => je(T.id),
688
- children: "吊销"
689
- }
690
- )
691
- ]
692
- }
693
- )
694
- ] }),
695
- /* @__PURE__ */ s("div", { className: a.akCardRow2, children: [
696
- T.tokenQuota > 0 && /* @__PURE__ */ e("div", { className: a.akMiniBar, children: /* @__PURE__ */ e(
697
- "div",
698
- {
699
- className: a.akMiniBarFill,
700
- style: {
701
- width: `${Math.min(
702
- (T.totalTokens || 0) / T.tokenQuota * 100,
703
- 100
704
- )}%`
705
- }
706
- }
707
- ) }),
708
- /* @__PURE__ */ s("span", { className: a.akUsageText, children: [
709
- de(T.totalTokens || 0),
710
- T.tokenQuota > 0 ? ` / ${de(T.tokenQuota)}` : " tokens"
711
- ] }),
712
- /* @__PURE__ */ e("span", { className: a.akMetaText, children: T.lastUsedAt ? `最近使用 ${T.lastUsedAt}` : "尚未使用" }),
713
- /* @__PURE__ */ e("span", { className: a.akMetaText, children: new Date(T.createTime).toLocaleDateString("zh-CN") })
714
- ] })
715
- ]
716
- },
717
- T.id
718
- )) });
719
- };
720
- return /* @__PURE__ */ s("div", { className: a.akContainer, children: [
721
- (Y || $.length > 0 || r) && /* @__PURE__ */ s("div", { className: a.akIntegrationPanel, children: [
722
- /* @__PURE__ */ s("h4", { className: a.akIntegrationTitle, children: [
723
- "网关台账",
724
- Y && /* @__PURE__ */ e("span", { style: { fontWeight: 400, fontSize: 12, marginLeft: 8, opacity: 0.7 }, children: Y.vendors.map((l) => `${l.vendor} ${l.credentials} 凭据/${l.models} 模型`).join(" · ") })
725
- ] }),
726
- r ? /* @__PURE__ */ e("div", { style: { fontSize: 12, opacity: 0.65 }, children: r }) : $.length === 0 ? /* @__PURE__ */ e("div", { style: { fontSize: 12, opacity: 0.65 }, children: "暂无租户用量(仅绑定 tenantCode 并发生过调用的 AK 才会入账)" }) : /* @__PURE__ */ e(
727
- ce,
728
- {
729
- size: "small",
730
- rowKey: "tenantCode",
731
- pagination: !1,
732
- dataSource: $,
733
- columns: [
734
- { title: "租户", dataIndex: "tenantCode", key: "tenantCode" },
735
- { title: "请求数", dataIndex: "requests", key: "requests", width: 90 },
736
- {
737
- title: "Prompt",
738
- dataIndex: "promptTokens",
739
- key: "promptTokens",
740
- width: 100,
741
- render: (l) => de(l)
742
- },
743
- {
744
- title: "Completion",
745
- dataIndex: "completionTokens",
746
- key: "completionTokens",
747
- width: 110,
748
- render: (l) => de(l)
749
- },
750
- {
751
- title: "成本",
752
- dataIndex: "cost",
753
- key: "cost",
754
- width: 90,
755
- render: (l) => l ? l.toFixed(4) : "-"
756
- }
757
- ]
758
- }
759
- )
760
- ] }),
761
- /* @__PURE__ */ s("div", { className: a.akIntegrationPanel, children: [
762
- /* @__PURE__ */ e("h4", { className: a.akIntegrationTitle, children: "协议接入地址" }),
763
- /* @__PURE__ */ s("div", { className: a.akBaseUrlRow, children: [
764
- /* @__PURE__ */ s("div", { className: a.akBaseUrlItem, children: [
765
- /* @__PURE__ */ e("span", { className: a.akBaseUrlLabel, children: "OpenAI 兼容" }),
766
- /* @__PURE__ */ e("code", { className: a.akBaseUrlValue, children: X }),
767
- /* @__PURE__ */ e(oe, { title: "复制 Base URL", children: /* @__PURE__ */ e(
768
- ie,
769
- {
770
- className: a.akCopyIcon,
771
- onClick: () => le(X)
772
- }
773
- ) })
774
- ] }),
775
- /* @__PURE__ */ s("div", { className: a.akBaseUrlItem, children: [
776
- /* @__PURE__ */ e("span", { className: a.akBaseUrlLabel, children: "Anthropic 兼容" }),
777
- /* @__PURE__ */ e("code", { className: a.akBaseUrlValue, children: X }),
778
- /* @__PURE__ */ e(oe, { title: "复制 Base URL", children: /* @__PURE__ */ e(
779
- ie,
780
- {
781
- className: a.akCopyIcon,
782
- onClick: () => le(X)
783
- }
784
- ) })
785
- ] })
786
- ] }),
787
- /* @__PURE__ */ s("div", { className: a.akIntegrationGrid, children: [
788
- /* @__PURE__ */ s("div", { children: [
789
- /* @__PURE__ */ e("p", { className: a.akCodeLabel, children: "OpenAI 兼容 — curl 示例" }),
790
- /* @__PURE__ */ e("pre", { className: a.akCodeBlock, children: Fa(X, D) })
791
- ] }),
792
- /* @__PURE__ */ s("div", { children: [
793
- /* @__PURE__ */ e("p", { className: a.akCodeLabel, children: "Anthropic 兼容 — curl 示例" }),
794
- /* @__PURE__ */ e("pre", { className: a.akCodeBlock, children: qa(X, D) })
795
- ] })
796
- ] })
797
- ] }),
798
- /* @__PURE__ */ s("div", { children: [
799
- /* @__PURE__ */ s(
800
- "div",
801
- {
802
- style: {
803
- display: "flex",
804
- justifyContent: "space-between",
805
- alignItems: "center",
806
- marginBottom: 12
807
- },
808
- children: [
809
- /* @__PURE__ */ e(
810
- $e,
811
- {
812
- activeKey: t,
813
- onChange: (l) => n(l),
814
- items: [
815
- { key: "app", label: "应用 AK" },
816
- { key: "personal", label: "个人 AK" }
817
- ],
818
- style: { flex: 1 }
819
- }
820
- ),
821
- /* @__PURE__ */ s("div", { style: { display: "flex", gap: 8 }, children: [
822
- /* @__PURE__ */ e(
823
- Ce.Search,
824
- {
825
- allowClear: !0,
826
- placeholder: "按名称 / 前缀过滤",
827
- style: { width: 200 },
828
- onChange: (l) => J(l.target.value)
829
- }
830
- ),
831
- /* @__PURE__ */ e(L, { icon: /* @__PURE__ */ e(we, {}), onClick: W, size: "small", children: "刷新" }),
832
- t === "personal" && /* @__PURE__ */ e(
833
- L,
834
- {
835
- type: "primary",
836
- icon: /* @__PURE__ */ e(Ee, {}),
837
- onClick: pe,
838
- loading: f,
839
- children: "生成 AK"
840
- }
841
- )
842
- ] })
843
- ]
844
- }
845
- ),
846
- t === "app" ? Ie(o, !0) : Ie(c, !1)
847
- ] }),
848
- /* @__PURE__ */ s(
849
- ye,
850
- {
851
- open: N,
852
- title: "生成新 AK",
853
- onCancel: () => g(!1),
854
- onOk: xe,
855
- okText: "确认生成",
856
- cancelText: "取消",
857
- confirmLoading: f,
858
- children: [
859
- /* @__PURE__ */ e(
860
- "div",
861
- {
862
- style: {
863
- marginBottom: 8,
864
- color: "var(--text-secondary)",
865
- fontSize: 13
866
- },
867
- children: "请输入 AK 名称(用于标识此密钥的用途)"
868
- }
869
- ),
870
- /* @__PURE__ */ e(
871
- Ce,
872
- {
873
- placeholder: "例如:测试用 AK、生产网关 AK",
874
- value: m,
875
- onChange: (l) => k(l.target.value),
876
- onPressEnter: xe,
877
- maxLength: 50,
878
- autoFocus: !0
879
- }
880
- )
881
- ]
882
- }
883
- ),
884
- /* @__PURE__ */ s(
885
- ye,
886
- {
887
- open: p.open,
888
- title: "AK 创建成功",
889
- onCancel: () => d({ open: !1 }),
890
- footer: [
891
- /* @__PURE__ */ e(
892
- L,
893
- {
894
- icon: /* @__PURE__ */ e(ie, {}),
895
- onClick: () => p.apiKey && le(p.apiKey),
896
- children: "复制 AK"
897
- },
898
- "copy"
899
- ),
900
- /* @__PURE__ */ e(
901
- L,
902
- {
903
- type: "primary",
904
- onClick: () => d({ open: !1 }),
905
- children: "我已保存"
906
- },
907
- "close"
908
- )
909
- ],
910
- children: [
911
- /* @__PURE__ */ e("div", { style: { marginBottom: 8, color: "#faad14", fontSize: 14 }, children: "请立即保存此 AK,关闭后将无法再次查看完整密钥。" }),
912
- /* @__PURE__ */ e(
913
- "div",
914
- {
915
- style: {
916
- background: "var(--bg-tertiary, #f6f8fa)",
917
- padding: "12px 14px",
918
- borderRadius: 8,
919
- fontFamily: "SF Mono, Fira Code, monospace",
920
- fontSize: 13,
921
- wordBreak: "break-all",
922
- userSelect: "all"
923
- },
924
- children: p.apiKey
925
- }
926
- ),
927
- /* @__PURE__ */ s("div", { style: { marginTop: 8, fontSize: 12, color: "var(--text-muted)" }, children: [
928
- "前缀: ",
929
- p.akPrefix
930
- ] })
931
- ]
932
- }
933
- ),
934
- /* @__PURE__ */ e(
935
- Oe,
936
- {
937
- title: _ ? /* @__PURE__ */ s("span", { children: [
938
- "AK 详情 — ",
939
- /* @__PURE__ */ e("code", { children: _.akPrefix })
940
- ] }) : "AK 详情",
941
- open: !!_,
942
- onClose: Je,
943
- size: "large",
944
- children: q ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 60 }, children: /* @__PURE__ */ e(se, { tip: "加载用量数据..." }) }) : P ? /* @__PURE__ */ s("div", { className: a.usageDrawerContent, children: [
945
- /* @__PURE__ */ e("div", { style: { fontSize: 12, color: "#8c8c8c", marginBottom: 12 }, children: "以下为网关全局调用统计(近 7 天窗口), 监控侧不按 AK 留存;该 AK 自身的累计消耗见下方「本 AK 累计 Token」。" }),
946
- /* @__PURE__ */ s("div", { className: a.usageStatsGrid, children: [
947
- /* @__PURE__ */ e(K, { title: "总请求数", value: P.totalRequests }),
948
- /* @__PURE__ */ e(K, { title: "总 Token", value: P.totalTokens }),
949
- /* @__PURE__ */ e(
950
- K,
951
- {
952
- title: "输入 Token",
953
- value: P.totalPromptTokens
954
- }
955
- ),
956
- /* @__PURE__ */ e(
957
- K,
958
- {
959
- title: "输出 Token",
960
- value: P.totalCompletionTokens
961
- }
962
- ),
963
- /* @__PURE__ */ e(
964
- K,
965
- {
966
- title: "平均耗时",
967
- value: P.avgLatencyMs,
968
- suffix: "ms"
969
- }
970
- ),
971
- /* @__PURE__ */ e(
972
- K,
973
- {
974
- title: "错误数",
975
- value: P.errorCount,
976
- styles: {
977
- content: {
978
- color: P.errorCount > 0 ? "#ff4d4f" : void 0
979
- }
980
- }
981
- }
982
- ),
983
- /* @__PURE__ */ e(
984
- K,
985
- {
986
- title: "本 AK 累计 Token",
987
- value: (_ == null ? void 0 : _.totalTokens) ?? 0
988
- }
989
- )
990
- ] }),
991
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
992
- /* @__PURE__ */ e("h4", { className: a.usageSectionTitle, children: "每日调用曲线(按最近调用明细聚合)" }),
993
- We(P.daily)
994
- ] }),
995
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
996
- /* @__PURE__ */ e("h4", { className: a.usageSectionTitle, children: "模型用量分布" }),
997
- Qe(P.models)
998
- ] }),
999
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
1000
- /* @__PURE__ */ e("h4", { className: a.usageSectionTitle, children: "最近调用记录" }),
1001
- /* @__PURE__ */ e(
1002
- ce,
1003
- {
1004
- columns: Ve,
1005
- dataSource: P.recent,
1006
- rowKey: "id",
1007
- size: "small",
1008
- pagination: {
1009
- pageSize: 10,
1010
- size: "small",
1011
- showSizeChanger: !0,
1012
- pageSizeOptions: ["10", "20", "50", "100"],
1013
- showTotal: (l) => `共 ${l} 条`
1014
- },
1015
- scroll: { x: 760 }
1016
- }
1017
- )
1018
- ] })
1019
- ] }) : /* @__PURE__ */ e("div", { className: a.usageEmpty, children: "暂无用量数据" })
1020
- }
1021
- )
1022
- ] });
1023
- }
1024
- function Wa(t) {
1025
- const n = [];
1026
- if (!t) return n;
1027
- const o = /<(think|thinking|reasoning)>([\s\S]*?)<\/\1>/gi;
1028
- let i = 0, c;
1029
- for (; (c = o.exec(t)) !== null; )
1030
- c.index > i && n.push({ type: "text", text: t.slice(i, c.index) }), n.push({ type: "think", text: c[2] }), i = c.index + c[0].length;
1031
- return i < t.length && n.push({ type: "text", text: t.slice(i) }), n;
1032
- }
1033
- const me = 4;
1034
- let Qa = 0;
1035
- function Va({ initialModels: t }) {
1036
- const [n, o] = C([]), [i, c] = C([]), [w, B] = C(!0), [A, f] = C(null), [S, N] = C(""), [g, m] = C(!1), k = ge(""), p = ge(/* @__PURE__ */ new Map()), d = ge(/* @__PURE__ */ new Map());
1037
- V(() => {
1038
- (async () => {
1039
- try {
1040
- const r = await Te();
1041
- c(r), B(!1);
1042
- const y = t.length > 0 ? t : r.slice(0, 1).map((x) => x.modelName);
1043
- o(y.slice(0, me).map((x) => fe(x)));
1044
- } catch (r) {
1045
- B(!1), f(r instanceof Error ? r.message : "模型列表加载失败");
1046
- }
1047
- })();
1048
- }, []), V(() => {
1049
- if (t.length > 0 && i.length > 0) {
1050
- const r = t.slice(0, me).map((y) => fe(y));
1051
- o(r);
1052
- }
1053
- }, [t.join(",")]);
1054
- const _ = H((r) => {
1055
- const y = d.current.get(r);
1056
- y && (y.scrollTop = y.scrollHeight);
1057
- }, []), h = H(
1058
- (r, y) => {
1059
- o((x) => x.map((b) => b.id === r ? y(b) : b));
1060
- },
1061
- []
1062
- ), P = H(async () => {
1063
- if (k.current) return k.current;
1064
- const r = await xt();
1065
- return k.current = r, r;
1066
- }, []), M = H(async () => {
1067
- const r = S.trim();
1068
- if (!r || g) return;
1069
- let y;
1070
- try {
1071
- y = await P();
1072
- } catch {
1073
- return;
1074
- }
1075
- N(""), m(!0);
1076
- const x = n.map((E) => ({
1077
- ...E,
1078
- messages: [
1079
- ...E.messages,
1080
- { role: "user", content: r },
1081
- { role: "assistant", content: "" }
1082
- ],
1083
- streamingContent: "",
1084
- isStreaming: !0,
1085
- error: null,
1086
- usage: null
1087
- }));
1088
- o(x);
1089
- const b = x;
1090
- b.forEach((E) => {
1091
- const J = new AbortController();
1092
- p.current.set(E.id, J);
1093
- const X = E.messages.slice(0, -1);
1094
- Ct(y, E.model, X, {
1095
- onDelta: (D) => {
1096
- h(E.id, (j) => ({
1097
- ...j,
1098
- streamingContent: j.streamingContent + D,
1099
- messages: j.messages.map(
1100
- (W, pe) => pe === j.messages.length - 1 ? { ...W, content: j.streamingContent + D } : W
1101
- )
1102
- })), _(E.id);
1103
- },
1104
- onDone: (D) => {
1105
- h(E.id, (j) => ({
1106
- ...j,
1107
- isStreaming: !1,
1108
- usage: D ? {
1109
- promptTokens: D.promptTokens,
1110
- completionTokens: D.completionTokens,
1111
- totalTokens: D.totalTokens
1112
- } : null
1113
- })), p.current.delete(E.id);
1114
- },
1115
- onError: (D) => {
1116
- (D.message.includes("401") || D.message.includes("API key")) && (He(), k.current = ""), h(E.id, (j) => ({
1117
- ...j,
1118
- isStreaming: !1,
1119
- error: D.message
1120
- })), p.current.delete(E.id);
1121
- },
1122
- signal: J.signal
1123
- }).catch(() => {
1124
- });
1125
- });
1126
- const O = setInterval(() => {
1127
- b.every(
1128
- (J) => !p.current.has(J.id)
1129
- ) && (clearInterval(O), m(!1));
1130
- }, 200);
1131
- setTimeout(() => {
1132
- clearInterval(O), m(!1);
1133
- }, 300 * 1e3);
1134
- }, [S, g, n, P, h, _]), q = H(() => {
1135
- p.current.forEach((r) => r.abort()), p.current.clear(), o((r) => r.map((y) => ({ ...y, isStreaming: !1 }))), m(!1);
1136
- }, []), ae = H(() => {
1137
- var y;
1138
- if (n.length >= me) return;
1139
- const r = (y = i.find((x) => !n.some((b) => b.model === x.modelName))) == null ? void 0 : y.modelName;
1140
- r && o((x) => [...x, fe(r)]);
1141
- }, [n, i]), Y = H(() => {
1142
- p.current.forEach((r) => r.abort()), p.current.clear(), o(
1143
- (r) => r.map((y) => ({
1144
- ...y,
1145
- messages: [],
1146
- streamingContent: "",
1147
- isStreaming: !1,
1148
- error: null,
1149
- usage: null
1150
- }))
1151
- ), m(!1);
1152
- }, [g, n]), u = H((r) => {
1153
- const y = p.current.get(r);
1154
- y && y.abort(), p.current.delete(r), o((x) => x.filter((b) => b.id !== r));
1155
- }, []), $ = H(
1156
- (r, y) => {
1157
- h(r, (x) => ({ ...x, model: y }));
1158
- },
1159
- [h]
1160
- ), R = i.map((r) => ({
1161
- label: r.modelName,
1162
- value: r.modelName
1163
- }));
1164
- return w ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 60 }, children: /* @__PURE__ */ e(se, { tip: "加载模型列表..." }) }) : A ? /* @__PURE__ */ e("div", { className: a.chatContainer, children: /* @__PURE__ */ s("div", { className: a.akEmpty, children: [
1165
- "模型列表加载失败:",
1166
- A
1167
- ] }) }) : /* @__PURE__ */ s("div", { className: a.chatContainer, children: [
1168
- /* @__PURE__ */ s("div", { className: a.chatHeader, children: [
1169
- n.length > 1 && /* @__PURE__ */ s(Z, { color: "blue", style: { fontSize: 12 }, children: [
1170
- n.length,
1171
- " 个模型对比"
1172
- ] }),
1173
- /* @__PURE__ */ e(
1174
- L,
1175
- {
1176
- size: "small",
1177
- icon: /* @__PURE__ */ e(Ze, {}),
1178
- onClick: Y,
1179
- disabled: g || n.every((r) => r.messages.length === 0),
1180
- children: "清空重新来"
1181
- }
1182
- )
1183
- ] }),
1184
- /* @__PURE__ */ s("div", { className: a.chatPanels, children: [
1185
- n.map((r) => /* @__PURE__ */ s("div", { className: a.chatPanel, children: [
1186
- /* @__PURE__ */ s("div", { className: a.chatPanelHeader, children: [
1187
- /* @__PURE__ */ e(
1188
- ut,
1189
- {
1190
- size: "small",
1191
- value: r.model,
1192
- onChange: (y) => $(r.id, y),
1193
- options: R,
1194
- style: { minWidth: 140, flex: 1 },
1195
- showSearch: !0,
1196
- optionFilterProp: "label"
1197
- }
1198
- ),
1199
- n.length > 1 && /* @__PURE__ */ e(
1200
- "span",
1201
- {
1202
- className: a.chatPanelClose,
1203
- onClick: () => u(r.id),
1204
- children: /* @__PURE__ */ e(et, {})
1205
- }
1206
- )
1207
- ] }),
1208
- /* @__PURE__ */ s(
1209
- "div",
1210
- {
1211
- className: a.chatPanelBody,
1212
- ref: (y) => {
1213
- d.current.set(r.id, y);
1214
- },
1215
- children: [
1216
- r.messages.map((y, x) => /* @__PURE__ */ s(
1217
- "div",
1218
- {
1219
- className: y.role === "user" ? a.chatMsgUser : a.chatMsgAI,
1220
- children: [
1221
- y.role === "assistant" ? Wa(y.content).map(
1222
- (b, O) => b.type === "think" ? /* @__PURE__ */ s(
1223
- "details",
1224
- {
1225
- className: a.chatThinkBlock,
1226
- children: [
1227
- /* @__PURE__ */ e("summary", { children: "思考过程" }),
1228
- /* @__PURE__ */ e("pre", { children: b.text })
1229
- ]
1230
- },
1231
- O
1232
- ) : /* @__PURE__ */ e("span", { style: { whiteSpace: "pre-wrap" }, children: b.text }, O)
1233
- ) : /* @__PURE__ */ e("span", { style: { whiteSpace: "pre-wrap" }, children: y.content }),
1234
- r.isStreaming && x === r.messages.length - 1 && y.role === "assistant" && /* @__PURE__ */ e("span", { className: a.chatStreamingCursor })
1235
- ]
1236
- },
1237
- x
1238
- )),
1239
- r.error && /* @__PURE__ */ e("div", { className: a.chatMsgError, children: r.error }),
1240
- r.usage && /* @__PURE__ */ s("div", { className: a.chatUsageBar, children: [
1241
- /* @__PURE__ */ s("span", { children: [
1242
- "输入: ",
1243
- r.usage.promptTokens
1244
- ] }),
1245
- /* @__PURE__ */ s("span", { children: [
1246
- "输出: ",
1247
- r.usage.completionTokens
1248
- ] })
1249
- ] })
1250
- ]
1251
- }
1252
- )
1253
- ] }, r.id)),
1254
- n.length < me && /* @__PURE__ */ e(oe, { title: "添加面板", children: /* @__PURE__ */ e("div", { className: a.addPanelBtn, onClick: ae, children: /* @__PURE__ */ e(Ee, {}) }) })
1255
- ] }),
1256
- /* @__PURE__ */ s("div", { className: a.chatInputBar, children: [
1257
- /* @__PURE__ */ e(
1258
- Ce.TextArea,
1259
- {
1260
- className: a.chatInput,
1261
- value: S,
1262
- onChange: (r) => N(r.target.value),
1263
- placeholder: "输入消息,所有面板将同时收到并流式输出...",
1264
- autoSize: { minRows: 1, maxRows: 4 },
1265
- onPressEnter: (r) => {
1266
- r.shiftKey || (r.preventDefault(), M());
1267
- },
1268
- disabled: g
1269
- }
1270
- ),
1271
- g ? /* @__PURE__ */ e(L, { danger: !0, onClick: q, children: "停止" }) : /* @__PURE__ */ s(L, { type: "primary", onClick: M, disabled: !S.trim(), children: [
1272
- /* @__PURE__ */ e(tt, {}),
1273
- " 发送"
1274
- ] })
1275
- ] })
1276
- ] });
1277
- }
1278
- function fe(t) {
1279
- return {
1280
- id: ++Qa,
1281
- model: t,
1282
- messages: [],
1283
- streamingContent: "",
1284
- isStreaming: !1,
1285
- error: null,
1286
- usage: null
1287
- };
1288
- }
1289
- function Ya({ onStartChat: t }) {
1290
- const [n, o] = C([]), [i, c] = C(!0), [w, B] = C(null), [A, f] = C(/* @__PURE__ */ new Set()), S = () => {
1291
- c(!0), B(null), Te().then((d) => {
1292
- o(d), c(!1);
1293
- }).catch((d) => {
1294
- o([]), B(d instanceof Error ? d.message : "加载失败"), c(!1);
1295
- });
1296
- };
1297
- V(() => {
1298
- S();
1299
- }, []);
1300
- const N = (d) => {
1301
- f((_) => {
1302
- const h = new Set(_);
1303
- return h.has(d) ? h.delete(d) : h.add(d), h;
1304
- });
1305
- }, g = Array.from(A), m = (d) => {
1306
- t([d]);
1307
- }, k = () => {
1308
- g.length > 0 && t(g);
1309
- }, p = (d) => {
1310
- if (!d) return "default";
1311
- const _ = d.toLowerCase();
1312
- return _.includes("aliyun") || _.includes("ali") ? "blue" : _.includes("zhipu") || _.includes("glm") ? "purple" : _.includes("moonshot") || _.includes("kimi") ? "cyan" : _.includes("minimax") ? "orange" : "default";
1313
- };
1314
- return i ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 60 }, children: /* @__PURE__ */ e(se, { tip: "加载模型列表..." }) }) : w ? /* @__PURE__ */ e("div", { children: /* @__PURE__ */ s("div", { className: a.akEmpty, children: [
1315
- "模型列表加载失败:",
1316
- w,
1317
- /* @__PURE__ */ e("div", { style: { marginTop: 16 }, children: /* @__PURE__ */ e(L, { type: "primary", onClick: S, children: "重试" }) })
1318
- ] }) }) : /* @__PURE__ */ s("div", { children: [
1319
- n.length === 0 && /* @__PURE__ */ e("div", { className: a.akEmpty, children: "后端暂无启用模型(z_team_model_config 中 enable=1 的行),请先在数据库或网关配置中启用" }),
1320
- /* @__PURE__ */ e("div", { className: a.modelGrid, children: n.map((d) => {
1321
- const _ = A.has(d.modelName);
1322
- return /* @__PURE__ */ s(
1323
- "div",
1324
- {
1325
- className: `${a.modelCard} ${_ ? a.modelCardSelected : ""}`,
1326
- onClick: () => N(d.modelName),
1327
- children: [
1328
- /* @__PURE__ */ e(
1329
- ht,
1330
- {
1331
- className: a.modelCheckbox,
1332
- checked: _,
1333
- onChange: (h) => {
1334
- h.stopPropagation(), N(d.modelName);
1335
- }
1336
- }
1337
- ),
1338
- /* @__PURE__ */ s("div", { className: a.modelCardHeader, children: [
1339
- /* @__PURE__ */ e("div", { className: a.modelIconWrap, children: /* @__PURE__ */ e(_e, {}) }),
1340
- /* @__PURE__ */ s("div", { className: a.modelCardInfo, children: [
1341
- /* @__PURE__ */ e("h4", { className: a.modelName, children: d.modelName }),
1342
- /* @__PURE__ */ s("div", { className: a.modelTags, children: [
1343
- d.modelProvider && /* @__PURE__ */ e(
1344
- Z,
1345
- {
1346
- color: p(d.modelProvider),
1347
- style: { fontSize: 11, margin: 0 },
1348
- children: d.modelProvider
1349
- }
1350
- ),
1351
- /* @__PURE__ */ e(Z, { style: { fontSize: 11, margin: 0 }, children: d.apiType })
1352
- ] })
1353
- ] })
1354
- ] }),
1355
- /* @__PURE__ */ e("p", { className: a.modelEndpoint, children: d.endpoint }),
1356
- /* @__PURE__ */ e("div", { className: a.modelCardFooter, children: /* @__PURE__ */ e(
1357
- L,
1358
- {
1359
- type: "link",
1360
- size: "small",
1361
- onClick: (h) => {
1362
- h.stopPropagation(), m(d.modelName);
1363
- },
1364
- children: "发起对话"
1365
- }
1366
- ) })
1367
- ]
1368
- },
1369
- d.modelName
1370
- );
1371
- }) }),
1372
- g.length > 0 && /* @__PURE__ */ s("div", { className: a.modelActionBar, children: [
1373
- /* @__PURE__ */ s("span", { className: a.modelSelectionCount, children: [
1374
- "已选择 ",
1375
- g.length,
1376
- " 个模型"
1377
- ] }),
1378
- /* @__PURE__ */ e(
1379
- L,
1380
- {
1381
- type: "primary",
1382
- onClick: k,
1383
- disabled: g.length === 0,
1384
- children: "批量对比"
1385
- }
1386
- )
1387
- ] })
1388
- ] });
1389
- }
1390
- const Xa = "_container_15pgq_5", Za = "_page_15pgq_10", en = "_kpiGrid_15pgq_16", tn = "_kpiCard_15pgq_22", an = "_sectionCard_15pgq_29", nn = "_sectionHead_15pgq_36", sn = "_sectionHint_15pgq_42", on = "_akList_15pgq_47", rn = "_errorState_15pgq_54", ln = "_errorTitle_15pgq_66", cn = "_errorDetail_15pgq_72", I = {
1391
- container: Xa,
1392
- page: Za,
1393
- kpiGrid: en,
1394
- kpiCard: tn,
1395
- sectionCard: an,
1396
- sectionHead: nn,
1397
- sectionHint: sn,
1398
- akList: on,
1399
- errorState: rn,
1400
- errorTitle: ln,
1401
- errorDetail: cn
1402
- }, dn = mt(
1403
- () => import("@yuku123/z-agent-component").then((t) => ({ default: t.AgentDashboard }))
1404
- );
1405
- function ne(t) {
1406
- return t >= 1e6 ? `${(t / 1e6).toFixed(2)}M` : t >= 1e3 ? `${(t / 1e3).toFixed(1)}K` : String(t ?? 0);
1407
- }
1408
- function mn({ daily: t }) {
1409
- const n = Object.entries(t);
1410
- if (n.length === 0) return /* @__PURE__ */ e("span", { className: a.usageEmpty, children: "暂无数据" });
1411
- const o = Math.max(...n.map(([, i]) => i[1] + i[2]), 1);
1412
- return /* @__PURE__ */ e("div", { className: a.usageBarChart, children: n.map(([i, c]) => {
1413
- const w = c[1] + c[2];
1414
- return /* @__PURE__ */ s("div", { className: a.usageBarCol, children: [
1415
- /* @__PURE__ */ e(oe, { title: `${i}: ${c[0]}次 / ${w} tokens`, children: /* @__PURE__ */ e(
1416
- "div",
1417
- {
1418
- className: a.usageBar,
1419
- style: { height: `${Math.max(w / o * 100, 2)}%` }
1420
- }
1421
- ) }),
1422
- /* @__PURE__ */ e("span", { className: a.usageBarLabel, children: i })
1423
- ] }, i);
1424
- }) });
1425
- }
1426
- function Ke({ models: t }) {
1427
- const n = Object.entries(t);
1428
- if (n.length === 0) return /* @__PURE__ */ e("span", { className: a.usageEmpty, children: "暂无数据" });
1429
- const o = Math.max(...n.map(([, i]) => i[0]), 1);
1430
- return /* @__PURE__ */ e("div", { className: a.modelBreakdown, children: n.sort((i, c) => c[1][0] - i[1][0]).map(([i, c]) => /* @__PURE__ */ s("div", { className: a.modelBreakdownRow, children: [
1431
- /* @__PURE__ */ e("span", { className: a.modelBreakdownName, children: i }),
1432
- /* @__PURE__ */ e("div", { className: a.modelBreakdownBar, children: /* @__PURE__ */ e(
1433
- "div",
1434
- {
1435
- className: a.modelBreakdownFill,
1436
- style: { width: `${c[0] / o * 100}%` }
1437
- }
1438
- ) }),
1439
- /* @__PURE__ */ s("span", { className: a.modelBreakdownCount, children: [
1440
- c[0],
1441
- "次 / ",
1442
- ne(c[1] + (c[2] || 0)),
1443
- "tokens"
1444
- ] })
1445
- ] }, i)) });
1446
- }
1447
- const un = [
1448
- {
1449
- title: "时间",
1450
- dataIndex: "createTime",
1451
- key: "createTime",
1452
- width: 160,
1453
- render: (t) => t ? new Date(t).toLocaleString("zh-CN") : "-"
1454
- },
1455
- { title: "模型", dataIndex: "model", key: "model", width: 150 },
1456
- { title: "协议", dataIndex: "protocol", key: "protocol", width: 90, render: (t) => /* @__PURE__ */ e(Z, { children: t }) },
1457
- { title: "输入", dataIndex: "promptTokens", key: "promptTokens", width: 70 },
1458
- { title: "输出", dataIndex: "completionTokens", key: "completionTokens", width: 70 },
1459
- { title: "总Token", dataIndex: "totalTokens", key: "totalTokens", width: 80 },
1460
- { title: "耗时", dataIndex: "latencyMs", key: "latencyMs", width: 70, render: (t) => t ? `${t}ms` : "-" },
1461
- {
1462
- title: "状态",
1463
- dataIndex: "statusCode",
1464
- key: "statusCode",
1465
- width: 60,
1466
- render: (t) => t ? /* @__PURE__ */ e(Z, { color: t < 400 ? "green" : "red", children: t }) : "-"
1467
- }
1468
- ];
1469
- function hn(t) {
1470
- var n;
1471
- return ((n = t == null ? void 0 : t.stats) == null ? void 0 : n.recent) ?? [];
1472
- }
1473
- function pn() {
1474
- var g;
1475
- const [t, n] = C(!0), [o, i] = C(null), [c, w] = C(null), [B, A] = C([]), [f, S] = C(null), N = H(async () => {
1476
- n(!0), i(null);
1477
- const m = await Promise.allSettled([
1478
- De(),
1479
- Ge(),
1480
- St()
1481
- ]), [k, p, d] = m;
1482
- k.status === "fulfilled" && w(k.value), p.status === "fulfilled" && A(p.value), d.status === "fulfilled" && S(d.value), m.every((_) => _.status === "rejected") && i(
1483
- k.status === "rejected" && k.reason instanceof Error ? k.reason.message : "网关控制面加载失败"
1484
- ), n(!1);
1485
- }, []);
1486
- return V(() => {
1487
- N();
1488
- }, [N]), t ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 60 }, children: /* @__PURE__ */ e(se, { tip: "加载网关控制面..." }) }) : o && !c ? /* @__PURE__ */ s("div", { className: I.errorState, children: [
1489
- /* @__PURE__ */ e("div", { className: I.errorTitle, children: "网关控制面不可用" }),
1490
- /* @__PURE__ */ e("div", { className: I.errorDetail, children: o }),
1491
- /* @__PURE__ */ e(L, { icon: /* @__PURE__ */ e(we, {}), onClick: () => void N(), type: "primary", children: "重试" })
1492
- ] }) : /* @__PURE__ */ s("div", { className: I.page, children: [
1493
- /* @__PURE__ */ s("div", { className: I.kpiGrid, children: [
1494
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(
1495
- K,
1496
- {
1497
- title: "网关状态",
1498
- value: f ? "在线" : "未知",
1499
- valueStyle: f ? { color: "#52c41a" } : { color: "#faad14" }
1500
- }
1501
- ) }),
1502
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(K, { title: "上游厂商", value: ((g = c == null ? void 0 : c.vendors) == null ? void 0 : g.length) ?? 0 }) }),
1503
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(
1504
- K,
1505
- {
1506
- title: "上游模型总数",
1507
- value: ((c == null ? void 0 : c.vendors) ?? []).reduce((m, k) => m + (k.models ?? 0), 0)
1508
- }
1509
- ) }),
1510
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(K, { title: "网关 AK 数", value: (c == null ? void 0 : c.activeApiKeys) ?? "—" }) })
1511
- ] }),
1512
- /* @__PURE__ */ e(
1513
- ce,
1514
- {
1515
- size: "small",
1516
- style: { marginTop: 16 },
1517
- rowKey: "vendor",
1518
- pagination: !1,
1519
- columns: [
1520
- { title: "上游厂商", dataIndex: "vendor", key: "vendor" },
1521
- { title: "凭据数", dataIndex: "credentials", key: "credentials", width: 100 },
1522
- { title: "可用模型数", dataIndex: "models", key: "models", width: 110 }
1523
- ],
1524
- dataSource: (c == null ? void 0 : c.vendors) ?? [],
1525
- locale: { emptyText: "网关控制面未返回厂商数据" }
1526
- }
1527
- ),
1528
- /* @__PURE__ */ s("div", { className: a.usageSection, style: { marginTop: 16 }, children: [
1529
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "租户用量台账(网关 UsageLedger,按租户维度)" }),
1530
- /* @__PURE__ */ e(
1531
- ce,
1532
- {
1533
- size: "small",
1534
- rowKey: "tenantCode",
1535
- columns: [
1536
- { title: "租户", dataIndex: "tenantCode", key: "tenantCode" },
1537
- { title: "请求数", dataIndex: "requests", key: "requests", width: 100 },
1538
- { title: "Prompt Tokens", dataIndex: "promptTokens", key: "promptTokens", width: 130, render: (m) => ne(m) },
1539
- { title: "Completion Tokens", dataIndex: "completionTokens", key: "completionTokens", width: 160, render: (m) => ne(m) },
1540
- { title: "成本", dataIndex: "cost", key: "cost", width: 100 }
1541
- ],
1542
- dataSource: B,
1543
- locale: { emptyText: "暂无租户用量(还没有绑定租户的 key 发生过调用)" },
1544
- pagination: {
1545
- pageSize: 10,
1546
- showSizeChanger: !0,
1547
- pageSizeOptions: ["10", "20", "50"],
1548
- showTotal: (m) => `共 ${m} 条`
1549
- }
1550
- }
1551
- )
1552
- ] })
1553
- ] });
1554
- }
1555
- function kn() {
1556
- var _, h, P, M, q, ae, Y;
1557
- const [t, n] = C(!0), [o, i] = C(null), [c, w] = C([]), [B, A] = C(null), [f, S] = C(null), N = String(Ue((u) => {
1558
- var $;
1559
- return (($ = u.currentUser) == null ? void 0 : $.id) ?? "";
1560
- })), g = Array.from(
1561
- new Set([N, Le].filter((u) => u !== ""))
1562
- ), m = H(async () => {
1563
- n(!0), i(null);
1564
- try {
1565
- const u = await Promise.allSettled(
1566
- g.map((O) => he(O))
1567
- ), $ = [], R = /* @__PURE__ */ new Set();
1568
- let r = 0;
1569
- for (const O of u)
1570
- if (O.status === "fulfilled")
1571
- for (const E of O.value) {
1572
- const J = String(E.id ?? E.akPrefix ?? "");
1573
- R.has(J) || (R.add(J), $.push(E));
1574
- }
1575
- else r += 1;
1576
- if (r === u.length)
1577
- throw new Error("网关不可达:无法获取 AK 列表");
1578
- $.sort((O, E) => (O.id ?? 0) - (E.id ?? 0));
1579
- let y = null, x = null;
1580
- try {
1581
- y = await Re(0);
1582
- } catch (O) {
1583
- x = O instanceof Error ? O.message : "获取用量失败";
1584
- }
1585
- A(y);
1586
- const b = $.map((O) => ({
1587
- key: O,
1588
- stats: y,
1589
- statsError: x
1590
- }));
1591
- w(b);
1592
- } catch (u) {
1593
- i(u instanceof Error ? u.message : "加载失败");
1594
- } finally {
1595
- n(!1);
1596
- }
1597
- }, [g.join(",")]);
1598
- V(() => {
1599
- m();
1600
- }, [m]);
1601
- const k = Me(() => {
1602
- const u = B, $ = {};
1603
- for (const [R, r] of Object.entries((u == null ? void 0 : u.models) ?? {}))
1604
- $[R] = [r[0] ?? 0, r[1] ?? 0, r[2] ?? 0];
1605
- return {
1606
- requests: (u == null ? void 0 : u.totalRequests) ?? 0,
1607
- tokens: (u == null ? void 0 : u.totalTokens) ?? 0,
1608
- avgLatency: (u == null ? void 0 : u.avgLatencyMs) ?? 0,
1609
- errors: (u == null ? void 0 : u.errorCount) ?? 0,
1610
- models: $
1611
- };
1612
- }, [B]), p = c.reduce((u, $) => u + ($.key.tokenQuota || 0), 0), d = () => t ? /* @__PURE__ */ e("div", { style: { textAlign: "center", padding: 60 }, children: /* @__PURE__ */ e(se, { tip: "加载监控数据..." }) }) : o ? /* @__PURE__ */ s("div", { className: I.errorState, children: [
1613
- /* @__PURE__ */ e("div", { className: I.errorTitle, children: "模型监控数据加载失败" }),
1614
- /* @__PURE__ */ e("div", { className: I.errorDetail, children: o }),
1615
- /* @__PURE__ */ e(L, { icon: /* @__PURE__ */ e(we, {}), onClick: m, type: "primary", children: "重试" })
1616
- ] }) : /* @__PURE__ */ s("div", { className: I.page, children: [
1617
- /* @__PURE__ */ s("div", { className: I.kpiGrid, children: [
1618
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(K, { title: "总请求(近7天)", value: k.requests }) }),
1619
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(K, { title: "总 Tokens", value: ne(k.tokens) }) }),
1620
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(K, { title: "平均延迟", value: k.avgLatency, suffix: "ms" }) }),
1621
- /* @__PURE__ */ e("div", { className: I.kpiCard, children: /* @__PURE__ */ e(
1622
- K,
1623
- {
1624
- title: "错误数",
1625
- value: k.errors,
1626
- valueStyle: k.errors > 0 ? { color: "#ff4d4f" } : void 0
1627
- }
1628
- ) })
1629
- ] }),
1630
- /* @__PURE__ */ s("div", { className: I.sectionCard, children: [
1631
- /* @__PURE__ */ s("div", { className: I.sectionHead, children: [
1632
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "AK 用量" }),
1633
- p > 0 && /* @__PURE__ */ s("span", { className: I.sectionHint, children: [
1634
- "合计额度 ",
1635
- ne(p),
1636
- " tokens"
1637
- ] })
1638
- ] }),
1639
- c.length === 0 ? /* @__PURE__ */ e("div", { className: a.akEmpty, children: "网关下暂无 AK" }) : /* @__PURE__ */ e("div", { className: I.akList, children: c.map((u) => {
1640
- const $ = u.key.totalTokens ?? 0, R = u.key.tokenQuota || 0, r = R > 0 ? Math.min($ / R * 100, 100) : 0;
1641
- return /* @__PURE__ */ s(
1642
- "div",
1643
- {
1644
- className: a.akCard,
1645
- onClick: () => S(u),
1646
- children: [
1647
- /* @__PURE__ */ s("div", { className: a.akCardRow, children: [
1648
- /* @__PURE__ */ e("span", { className: a.akTitle, children: u.key.description || u.key.userName || `AK #${u.key.id}` }),
1649
- /* @__PURE__ */ e("span", { className: a.akPrefixSmall, children: u.key.akPrefix }),
1650
- /* @__PURE__ */ e(
1651
- "span",
1652
- {
1653
- className: `${a.akStatus} ${u.key.active ? a.akStatusActive : a.akStatusRevoked}`,
1654
- children: u.key.active ? "启用" : "吊销"
1655
- }
1656
- ),
1657
- /* @__PURE__ */ e("span", { className: a.akMetaText, children: u.key.userId === "system-default" ? "系统对话" : u.key.userId })
1658
- ] }),
1659
- /* @__PURE__ */ s("div", { className: a.akCardRow2, children: [
1660
- /* @__PURE__ */ e("div", { className: a.akMiniBar, children: /* @__PURE__ */ e(
1661
- "div",
1662
- {
1663
- className: a.akMiniBarFill,
1664
- style: { width: `${r}%` }
1665
- }
1666
- ) }),
1667
- /* @__PURE__ */ s("span", { className: a.akUsageText, children: [
1668
- ne($),
1669
- R > 0 ? ` / ${ne(R)}` : "",
1670
- " tokens"
1671
- ] }),
1672
- /* @__PURE__ */ e("span", { className: a.akMetaText, children: u.statsError ? u.statsError : u.key.lastUsedAt ? `最近使用 ${u.key.lastUsedAt}` : "尚未使用" })
1673
- ] })
1674
- ]
1675
- },
1676
- u.key.id
1677
- );
1678
- }) })
1679
- ] }),
1680
- /* @__PURE__ */ s("div", { className: I.sectionCard, children: [
1681
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "模型用量分布(网关全局)" }),
1682
- /* @__PURE__ */ e(Ke, { models: k.models })
1683
- ] })
1684
- ] });
1685
- return /* @__PURE__ */ s("div", { className: I.container, children: [
1686
- /* @__PURE__ */ e(
1687
- $e,
1688
- {
1689
- defaultActiveKey: "usage",
1690
- items: [
1691
- { key: "usage", label: "模型用量", children: d() },
1692
- {
1693
- key: "sessions",
1694
- label: "会话统计",
1695
- children: /* @__PURE__ */ e(dt, { fallback: /* @__PURE__ */ e(se, { tip: "加载会话统计..." }), children: /* @__PURE__ */ e(dn, {}) })
1696
- },
1697
- { key: "gateway", label: "网关控制面", children: /* @__PURE__ */ e(pn, {}) }
1698
- ]
1699
- }
1700
- ),
1701
- /* @__PURE__ */ e(
1702
- Oe,
1703
- {
1704
- title: f ? `AK 用量 — ${f.key.description || f.key.akPrefix}` : "",
1705
- width: 860,
1706
- open: !!f,
1707
- onClose: () => S(null),
1708
- destroyOnHidden: !0,
1709
- children: f && /* @__PURE__ */ s("div", { className: a.usageDrawerContent, children: [
1710
- /* @__PURE__ */ e("div", { style: { fontSize: 12, color: "#8c8c8c", marginBottom: 12 }, children: "调用监控是网关全局维度(不按 AK 留存),以下统计覆盖全部 AK; 该 AK 自身的累计消耗见「本 AK 累计 Token」。" }),
1711
- /* @__PURE__ */ s("div", { className: a.usageStatsGrid, children: [
1712
- /* @__PURE__ */ e(K, { title: "总请求", value: ((_ = f.stats) == null ? void 0 : _.totalRequests) ?? 0 }),
1713
- /* @__PURE__ */ e(K, { title: "总 Tokens", value: ((h = f.stats) == null ? void 0 : h.totalTokens) ?? 0 }),
1714
- /* @__PURE__ */ e(K, { title: "平均延迟", value: ((P = f.stats) == null ? void 0 : P.avgLatencyMs) ?? 0, suffix: "ms" }),
1715
- /* @__PURE__ */ e(K, { title: "输入 Tokens", value: ((M = f.stats) == null ? void 0 : M.totalPromptTokens) ?? 0 }),
1716
- /* @__PURE__ */ e(K, { title: "输出 Tokens", value: ((q = f.stats) == null ? void 0 : q.totalCompletionTokens) ?? 0 }),
1717
- /* @__PURE__ */ e(
1718
- K,
1719
- {
1720
- title: "本 AK 累计 Token",
1721
- value: f.key.totalTokens ?? 0
1722
- }
1723
- ),
1724
- /* @__PURE__ */ e(
1725
- K,
1726
- {
1727
- title: "错误数",
1728
- value: ((ae = f.stats) == null ? void 0 : ae.errorCount) ?? 0,
1729
- valueStyle: (((Y = f.stats) == null ? void 0 : Y.errorCount) ?? 0) > 0 ? { color: "#ff4d4f" } : void 0
1730
- }
1731
- )
1732
- ] }),
1733
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
1734
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "每日用量(按最近调用明细聚合)" }),
1735
- f.stats ? /* @__PURE__ */ e(mn, { daily: f.stats.daily ?? {} }) : /* @__PURE__ */ e("span", { className: a.usageEmpty, children: f.statsError ?? "暂无数据" })
1736
- ] }),
1737
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
1738
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "模型用量分布(按最近调用明细聚合)" }),
1739
- f.stats ? /* @__PURE__ */ e(Ke, { models: f.stats.models ?? {} }) : /* @__PURE__ */ e("span", { className: a.usageEmpty, children: f.statsError ?? "暂无数据" })
1740
- ] }),
1741
- /* @__PURE__ */ s("div", { className: a.usageSection, children: [
1742
- /* @__PURE__ */ e("span", { className: a.usageSectionTitle, children: "最近调用" }),
1743
- /* @__PURE__ */ e(
1744
- ce,
1745
- {
1746
- size: "small",
1747
- columns: un,
1748
- dataSource: hn(f),
1749
- rowKey: "id",
1750
- pagination: {
1751
- pageSize: 8,
1752
- showSizeChanger: !0,
1753
- pageSizeOptions: ["8", "20", "50", "100"],
1754
- showTotal: (u) => `共 ${u} 条`
1755
- }
1756
- }
1757
- )
1758
- ] })
1759
- ] })
1760
- }
1761
- )
1762
- ] });
1763
- }
1764
- const gn = [
1765
- {
1766
- title: "模型",
1767
- icon: /* @__PURE__ */ e(Pe, {}),
1768
- items: [
1769
- { key: "model-management", label: "模型管理", icon: /* @__PURE__ */ e(Pe, {}) },
1770
- { key: "model-chat", label: "模型对话", icon: /* @__PURE__ */ e(st, {}) },
1771
- { key: "model-monitor", label: "模型监控", icon: /* @__PURE__ */ e(ot, {}) }
1772
- ]
1773
- },
1774
- {
1775
- title: "接入",
1776
- icon: /* @__PURE__ */ e(be, {}),
1777
- items: [
1778
- { key: "ak-management", label: "AK 管理", icon: /* @__PURE__ */ e(be, {}) }
1779
- ]
1780
- },
1781
- {
1782
- title: "智能体",
1783
- icon: /* @__PURE__ */ e(_e, {}),
1784
- items: [
1785
- { key: "agent-app", label: "Agent 应用", icon: /* @__PURE__ */ e(_e, {}) },
1786
- { key: "agent-instance", label: "Agent 实例", icon: /* @__PURE__ */ e(rt, {}) },
1787
- { key: "mcp-service", label: "MCP 服务", icon: /* @__PURE__ */ e(lt, {}) },
1788
- { key: "skill-market", label: "技能市场", icon: /* @__PURE__ */ e(ct, {}) },
1789
- { key: "agent-msg-monitor", label: "消息监控", icon: /* @__PURE__ */ e(it, {}) }
1790
- ]
1791
- }
1792
- ];
1793
- function An() {
1794
- const [t, n] = C("model-management"), [o, i] = C([]), [c, w] = C(/* @__PURE__ */ new Set()), B = (N) => {
1795
- i(N), n("model-chat");
1796
- }, A = Me(() => gn, []);
1797
- V(() => {
1798
- t && A.forEach((N) => {
1799
- N.items.some((g) => g.key === t) && w(
1800
- (g) => g.has(N.title) ? g : new Set(g).add(N.title)
1801
- );
1802
- });
1803
- }, [t, A]);
1804
- const f = (N) => {
1805
- w((g) => {
1806
- const m = new Set(g);
1807
- return m.has(N) ? m.delete(N) : m.add(N), m;
1808
- });
1809
- }, S = (N, g, m = !1) => /* @__PURE__ */ e(
1810
- "div",
1811
- {
1812
- style: {
1813
- display: t === N ? m ? "flex" : "block" : "none",
1814
- height: "100%",
1815
- ...m ? { flexDirection: "column" } : {}
1816
- },
1817
- children: g
1818
- }
1819
- );
1820
- return /* @__PURE__ */ s("div", { className: a.container, children: [
1821
- /* @__PURE__ */ e("aside", { className: z.sidebar, children: /* @__PURE__ */ e("nav", { className: z.menuList, children: A.map((N) => {
1822
- const g = c.has(N.title), m = N.items.findIndex((k) => k.key === t);
1823
- return /* @__PURE__ */ s("div", { className: z.menuGroup, children: [
1824
- /* @__PURE__ */ s(
1825
- "div",
1826
- {
1827
- className: `${z.menuGroupHeader} ${g ? z.menuGroupHeaderOpen : ""} ${m >= 0 ? z.menuGroupHeaderActive : ""}`,
1828
- onClick: () => f(N.title),
1829
- children: [
1830
- /* @__PURE__ */ e("span", { className: z.menuGroupIcon, children: N.icon }),
1831
- /* @__PURE__ */ e("span", { className: z.menuGroupLabel, children: N.title }),
1832
- /* @__PURE__ */ e("span", { className: z.menuGroupArrow, children: g ? /* @__PURE__ */ e(at, {}) : /* @__PURE__ */ e(nt, {}) })
1833
- ]
1834
- }
1835
- ),
1836
- g && /* @__PURE__ */ e("ul", { className: z.menuSubList, children: N.items.map((k, p) => {
1837
- const d = m >= 0 && p <= m;
1838
- return /* @__PURE__ */ e(
1839
- "li",
1840
- {
1841
- className: `${z.menuSubItem} ${d ? z.menuItemOnPath : ""} ${t === k.key ? z.menuSubItemActive : ""}`,
1842
- onClick: () => n(k.key),
1843
- children: /* @__PURE__ */ s("div", { className: z.menuSubItemPill, children: [
1844
- /* @__PURE__ */ e("span", { className: z.menuSubItemIcon, children: k.icon }),
1845
- /* @__PURE__ */ e("span", { children: k.label })
1846
- ] })
1847
- },
1848
- k.key
1849
- );
1850
- }) })
1851
- ] }, N.title);
1852
- }) }) }),
1853
- /* @__PURE__ */ s("main", { className: a.panelArea, children: [
1854
- S("model-management", /* @__PURE__ */ e(Ya, { onStartChat: B })),
1855
- S("model-chat", /* @__PURE__ */ e(Va, { initialModels: o }), !0),
1856
- S("ak-management", /* @__PURE__ */ e(Ja, {})),
1857
- S("agent-app", /* @__PURE__ */ e(kt, {})),
1858
- S("agent-instance", /* @__PURE__ */ e(gt, {})),
1859
- S("mcp-service", /* @__PURE__ */ e(yt, {})),
1860
- S("skill-market", /* @__PURE__ */ e(ft, {})),
1861
- S("agent-msg-monitor", /* @__PURE__ */ e(pt, {})),
1862
- S("model-monitor", /* @__PURE__ */ e(kn, {}))
1863
- ] })
1864
- ] });
1865
- }
1866
- export {
1867
- An as default
1868
- };