@abpjs/ui 0.2.0-next.2 → 0.2.0-next.4
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.
- package/CHANGELOG.md +28 -0
- package/dist/ai.d.ts +112 -22
- package/dist/ai.js +230 -111
- package/dist/ai.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +77 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/ai.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
// src/areas/ai/pages.tsx
|
|
4
|
-
import { Stack as
|
|
4
|
+
import { Stack as Stack9 } from "@chakra-ui/react";
|
|
5
5
|
import { PageHeader } from "@abpjs/ui";
|
|
6
6
|
|
|
7
7
|
// src/areas/ai/AiAdmin.tsx
|
|
8
8
|
import { useMemo as useMemo4 } from "react";
|
|
9
|
-
import { Stack as
|
|
10
|
-
import {
|
|
9
|
+
import { Stack as Stack8, Tabs } from "@chakra-ui/react";
|
|
10
|
+
import { InlineAlert as InlineAlert6, notify as notify4, Panel as Panel7, useApiAction as useApiAction6, useApiQuery as useApiQuery3, useAreaRequest as useAreaRequest7, useCan } from "@abpjs/ui";
|
|
11
11
|
|
|
12
12
|
// src/areas/ai/AccessPanel.tsx
|
|
13
|
-
import { useEffect, useMemo, useState as useState2 } from "react";
|
|
13
|
+
import { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "react";
|
|
14
14
|
import { Stack as Stack2, Text as Text2 } from "@chakra-ui/react";
|
|
15
15
|
import { Button as Button2, CheckboxField, DataTable, FormDialog, HostSlot, InlineAlert as InlineAlert2, notify, Panel, SearchInput, StatusPill, SwitchField, useApiAction, useApiQuery, useAreaRequest, useFormatters as useFormatters2, useHost, useNames, useOptionalHost, useSlotSaves } from "@abpjs/ui";
|
|
16
16
|
|
|
@@ -177,7 +177,8 @@ var ar_default = {
|
|
|
177
177
|
exportDownload: "\u062A\u0646\u0632\u064A\u0644",
|
|
178
178
|
exportDelete: "\u062D\u0630\u0641",
|
|
179
179
|
exportDeleteTitle: "\u0623\u062A\u062D\u0630\u0641 \u0647\u0630\u0627 \u0627\u0644\u062A\u0635\u062F\u064A\u0631\u061F",
|
|
180
|
-
exportDeleteHint: "\u064A\u064F\u062D\u0630\u0641 \u0645\u0644\u0641\u0647 \u0627\u0644\u0622\u0646\u060C \u0642\u0628\u0644 \u0627\u0646\u0642\u0636\u0627\u0621 \u0623\u0633\u0628\u0648\u0639\u0647."
|
|
180
|
+
exportDeleteHint: "\u064A\u064F\u062D\u0630\u0641 \u0645\u0644\u0641\u0647 \u0627\u0644\u0622\u0646\u060C \u0642\u0628\u0644 \u0627\u0646\u0642\u0636\u0627\u0621 \u0623\u0633\u0628\u0648\u0639\u0647.",
|
|
181
|
+
callThrough: "\u0639\u0628\u0631 {name}"
|
|
181
182
|
};
|
|
182
183
|
|
|
183
184
|
// src/areas/ai/texts/en.json
|
|
@@ -334,7 +335,8 @@ var en_default = {
|
|
|
334
335
|
exportDownload: "Download",
|
|
335
336
|
exportDelete: "Delete",
|
|
336
337
|
exportDeleteTitle: "Delete this export?",
|
|
337
|
-
exportDeleteHint: "Its file goes now, before its week is up."
|
|
338
|
+
exportDeleteHint: "Its file goes now, before its week is up.",
|
|
339
|
+
callThrough: "through {name}"
|
|
338
340
|
};
|
|
339
341
|
|
|
340
342
|
// src/areas/ai/texts.ts
|
|
@@ -440,6 +442,31 @@ function modelRows(connections) {
|
|
|
440
442
|
})
|
|
441
443
|
);
|
|
442
444
|
}
|
|
445
|
+
function scopeModelRows(view) {
|
|
446
|
+
return view.models.map((m) => {
|
|
447
|
+
const s = m.settings ?? {};
|
|
448
|
+
const input = num(m.price?.input);
|
|
449
|
+
const output = num(m.price?.output);
|
|
450
|
+
const priced = input !== 0 || output !== 0;
|
|
451
|
+
return {
|
|
452
|
+
key: modelKey(m.connectionId, m.model),
|
|
453
|
+
connectionId: m.connectionId,
|
|
454
|
+
connection: m.connection,
|
|
455
|
+
scopeId: m.setOnScopeId ?? null,
|
|
456
|
+
modelId: m.model,
|
|
457
|
+
name: s.name || m.model,
|
|
458
|
+
enabled: s.enabled ?? true,
|
|
459
|
+
tools: s.tools ?? true,
|
|
460
|
+
images: s.images ?? false,
|
|
461
|
+
structuredOutput: s.structuredOutput ?? false,
|
|
462
|
+
contextTokens: s.contextTokens == null ? null : num(s.contextTokens),
|
|
463
|
+
inputPrice: priced ? input : null,
|
|
464
|
+
outputPrice: priced ? output : null,
|
|
465
|
+
priceSetAt: s.priceSetAt ?? null,
|
|
466
|
+
own: m.own
|
|
467
|
+
};
|
|
468
|
+
});
|
|
469
|
+
}
|
|
443
470
|
function withModel(c, model, settings, price) {
|
|
444
471
|
const modelPrices = { ...c.modelPrices ?? {} };
|
|
445
472
|
if (price) modelPrices[model] = { ...modelPrices[model], input: price.input, output: price.output };
|
|
@@ -464,7 +491,7 @@ function withModel(c, model, settings, price) {
|
|
|
464
491
|
}
|
|
465
492
|
|
|
466
493
|
// src/areas/ai/AccessPanel.tsx
|
|
467
|
-
import {
|
|
494
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
468
495
|
function useAllScopes() {
|
|
469
496
|
const host = useHost();
|
|
470
497
|
const [scopes, setScopes] = useState2(void 0);
|
|
@@ -498,6 +525,8 @@ function AccessPanel({ models }) {
|
|
|
498
525
|
const more = unnamed.map((id) => ({ scopeId: id, name: names[id] ?? id, access: access.get(id) }));
|
|
499
526
|
return [...listed, ...more];
|
|
500
527
|
}, [list.data, scopes, unnamed, names]);
|
|
528
|
+
const { counts, refresh } = useLimitCounts(useMemo(() => (rows ?? []).map((r) => r.scopeId), [rows]));
|
|
529
|
+
const fmt = useFormatters2();
|
|
501
530
|
const needle = search.trim().toLowerCase();
|
|
502
531
|
const shown = rows?.filter((p) => !needle || `${p.name} ${p.code ?? ""}`.toLowerCase().includes(needle));
|
|
503
532
|
const opened = (a) => a?.allSiteModels ? t("allModels") : a?.siteModels.length ? t("someModels", { count: a.siteModels.length }) : t("noModelsOpen");
|
|
@@ -535,12 +564,13 @@ function AccessPanel({ models }) {
|
|
|
535
564
|
},
|
|
536
565
|
{ id: "own", header: t("ownConnections"), cell: (p) => p.access?.mayConnect ? t("allowed") : t("notAllowed") },
|
|
537
566
|
...extraCell ? [{ id: "host", header: t("ownSkills"), cell: (p) => /* @__PURE__ */ jsx2(HostSlot, { name: "ai.access.cell", context: { scopeId: p.scopeId } }) }] : [],
|
|
538
|
-
{ id: "limits", header: t("tabs.limits"), numeric: true, cell: (p) =>
|
|
567
|
+
{ id: "limits", header: t("tabs.limits"), numeric: true, cell: (p) => counts[p.scopeId] === void 0 ? "" : fmt.number(counts[p.scopeId]) },
|
|
539
568
|
{ id: "edit", header: /* @__PURE__ */ jsx2(Text2, { srOnly: true, children: t("edit") }), align: "end", cell: (p) => /* @__PURE__ */ jsx2(Button2, { size: "sm", variant: "ghost", onClick: () => setEditing(p), children: t("edit") }) }
|
|
540
569
|
]
|
|
541
570
|
}
|
|
542
571
|
),
|
|
543
572
|
editing && /* @__PURE__ */ jsx2(AccessEditor, { scope: editing, models, onClose: () => setEditing(null), onSaved: async () => {
|
|
573
|
+
refresh(editing.scopeId);
|
|
544
574
|
setEditing(null);
|
|
545
575
|
await list.reload();
|
|
546
576
|
} })
|
|
@@ -548,10 +578,34 @@ function AccessPanel({ models }) {
|
|
|
548
578
|
}
|
|
549
579
|
);
|
|
550
580
|
}
|
|
551
|
-
function
|
|
552
|
-
const
|
|
553
|
-
const
|
|
554
|
-
|
|
581
|
+
function useLimitCounts(scopeIds) {
|
|
582
|
+
const request = useAreaRequest("ai");
|
|
583
|
+
const asked = useRef(/* @__PURE__ */ new Set());
|
|
584
|
+
const [counts, setCounts] = useState2({});
|
|
585
|
+
const [round, setRound] = useState2(0);
|
|
586
|
+
const key = scopeIds.join(",");
|
|
587
|
+
useEffect(() => {
|
|
588
|
+
const wanted = (key ? key.split(",") : []).filter((id) => !asked.current.has(id));
|
|
589
|
+
wanted.forEach((id) => asked.current.add(id));
|
|
590
|
+
void (async () => {
|
|
591
|
+
for (let i = 0; i < wanted.length; i += 4) {
|
|
592
|
+
const found = await Promise.all(wanted.slice(i, i + 4).map(async (id) => {
|
|
593
|
+
try {
|
|
594
|
+
return [id, (await request(`/limits${scopeQuery(id)}`)).length];
|
|
595
|
+
} catch {
|
|
596
|
+
asked.current.delete(id);
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
}));
|
|
600
|
+
setCounts((c) => ({ ...c, ...Object.fromEntries(found.filter((f) => f !== null)) }));
|
|
601
|
+
}
|
|
602
|
+
})();
|
|
603
|
+
}, [key, request, round]);
|
|
604
|
+
const refresh = useCallback((scopeId) => {
|
|
605
|
+
asked.current.delete(scopeId);
|
|
606
|
+
setRound((r) => r + 1);
|
|
607
|
+
}, []);
|
|
608
|
+
return { counts, refresh };
|
|
555
609
|
}
|
|
556
610
|
function AccessEditor({ scope, models, onClose, onSaved }) {
|
|
557
611
|
const t = useAiTexts();
|
|
@@ -895,7 +949,7 @@ function ModelsPanel({ scopeId, connections, rows, loading, hostKeeps, onChanged
|
|
|
895
949
|
{
|
|
896
950
|
id: "can",
|
|
897
951
|
header: t("can"),
|
|
898
|
-
cell: (m) => hostSaysCan ? /* @__PURE__ */ jsx5(HostSlot2, { name: "ai.models.can", context: { connectionId: m.connectionId, modelId: m.modelId } }) : /* @__PURE__ */ jsxs5(HStack4, { gap: "1", flexWrap: "wrap", children: [
|
|
952
|
+
cell: (m) => hostSaysCan ? /* @__PURE__ */ jsx5(HostSlot2, { name: "ai.models.can", context: { connectionId: m.connectionId, modelId: m.modelId, scopeId } }) : /* @__PURE__ */ jsxs5(HStack4, { gap: "1", flexWrap: "wrap", children: [
|
|
899
953
|
m.tools && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("tools") }),
|
|
900
954
|
m.images && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("images") }),
|
|
901
955
|
m.structuredOutput && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("structured") })
|
|
@@ -991,22 +1045,62 @@ function ModelEditor({ connection, model, onClose, onSaved }) {
|
|
|
991
1045
|
);
|
|
992
1046
|
}
|
|
993
1047
|
|
|
1048
|
+
// src/areas/ai/TryPanel.tsx
|
|
1049
|
+
import { useId, useState as useState6 } from "react";
|
|
1050
|
+
import { HStack as HStack5, Input as Input5, Stack as Stack6, Text as Text6, Textarea } from "@chakra-ui/react";
|
|
1051
|
+
import { Button as Button6, Field as Field5, InlineAlert as InlineAlert5, Panel as Panel5, useApiAction as useApiAction5, useAreaRequest as useAreaRequest5, useFormatters as useFormatters5 } from "@abpjs/ui";
|
|
1052
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1053
|
+
function TryPanel({ scopeId, aliases }) {
|
|
1054
|
+
const t = useAiTexts();
|
|
1055
|
+
const fmt = useFormatters5();
|
|
1056
|
+
const request = useAreaRequest5("ai");
|
|
1057
|
+
const action = useApiAction5();
|
|
1058
|
+
const [alias, setAlias] = useState6(aliases[0] ?? "");
|
|
1059
|
+
const [prompt, setPrompt] = useState6("");
|
|
1060
|
+
const [result, setResult] = useState6(null);
|
|
1061
|
+
const listId = useId();
|
|
1062
|
+
async function run() {
|
|
1063
|
+
setResult(null);
|
|
1064
|
+
const body = { alias: alias.trim(), prompt, scopeId: scopeId ?? null };
|
|
1065
|
+
const answer = await action.run(() => request("/try", { method: "POST", body }));
|
|
1066
|
+
if (answer) setResult(answer);
|
|
1067
|
+
}
|
|
1068
|
+
return /* @__PURE__ */ jsx6(Panel5, { title: t("tryTitle"), description: t("tryHint"), "data-testid": "ai-try", children: /* @__PURE__ */ jsxs6(Stack6, { gap: "field", children: [
|
|
1069
|
+
/* @__PURE__ */ jsxs6(Field5, { label: t("alias"), children: [
|
|
1070
|
+
/* @__PURE__ */ jsx6(Input5, { value: alias, dir: "ltr", list: listId, onChange: (e) => setAlias(e.target.value) }),
|
|
1071
|
+
/* @__PURE__ */ jsx6("datalist", { id: listId, children: aliases.map((a) => /* @__PURE__ */ jsx6("option", { value: a }, a)) })
|
|
1072
|
+
] }),
|
|
1073
|
+
/* @__PURE__ */ jsx6(Field5, { label: t("prompt"), children: /* @__PURE__ */ jsx6(Textarea, { value: prompt, rows: 3, onChange: (e) => setPrompt(e.target.value) }) }),
|
|
1074
|
+
/* @__PURE__ */ jsx6(HStack5, { children: /* @__PURE__ */ jsx6(Button6, { onClick: () => void run(), loading: action.busy, disabled: !alias.trim() || !prompt.trim(), children: t("run") }) }),
|
|
1075
|
+
/* @__PURE__ */ jsx6(InlineAlert5, { tone: "danger", children: action.error }),
|
|
1076
|
+
result && /* @__PURE__ */ jsxs6(Stack6, { gap: "1", "data-testid": "ai-try-answer", children: [
|
|
1077
|
+
/* @__PURE__ */ jsx6(Text6, { whiteSpace: "pre-wrap", dir: "auto", children: result.text }),
|
|
1078
|
+
/* @__PURE__ */ jsx6(Text6, { textStyle: "caption", color: "fg.muted", children: t("answered", {
|
|
1079
|
+
model: result.model,
|
|
1080
|
+
input: fmt.number(num(result.usage.inputTokens)),
|
|
1081
|
+
output: fmt.number(num(result.usage.outputTokens)),
|
|
1082
|
+
cost: fmt.number(num(result.usage.cost), { maximumFractionDigits: 6 })
|
|
1083
|
+
}) })
|
|
1084
|
+
] })
|
|
1085
|
+
] }) });
|
|
1086
|
+
}
|
|
1087
|
+
|
|
994
1088
|
// src/areas/ai/UsagePanel.tsx
|
|
995
|
-
import { useMemo as useMemo3, useState as
|
|
996
|
-
import { HStack as
|
|
997
|
-
import { DataTable as DataTable4, EMPTY_VALUE, Panel as
|
|
1089
|
+
import { useMemo as useMemo3, useState as useState8 } from "react";
|
|
1090
|
+
import { HStack as HStack6, Stack as Stack7, Text as Text7 } from "@chakra-ui/react";
|
|
1091
|
+
import { DataTable as DataTable4, EMPTY_VALUE, Panel as Panel6, SelectField as SelectField4, StatusPill as StatusPill3, useFormatters as useFormatters6, useNames as useNames2 } from "@abpjs/ui";
|
|
998
1092
|
|
|
999
1093
|
// src/areas/ai/usePostQuery.ts
|
|
1000
|
-
import { useCallback, useEffect as useEffect2, useRef, useState as
|
|
1001
|
-
import { errorText as errorText3, useAreaRequest as
|
|
1094
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState7 } from "react";
|
|
1095
|
+
import { errorText as errorText3, useAreaRequest as useAreaRequest6 } from "@abpjs/ui";
|
|
1002
1096
|
function usePostQuery(path, body) {
|
|
1003
|
-
const request =
|
|
1097
|
+
const request = useAreaRequest6("ai");
|
|
1004
1098
|
const key = JSON.stringify(body);
|
|
1005
|
-
const [data, setData] =
|
|
1006
|
-
const [error, setError] =
|
|
1007
|
-
const [loading, setLoading] =
|
|
1008
|
-
const seq =
|
|
1009
|
-
const reload =
|
|
1099
|
+
const [data, setData] = useState7(void 0);
|
|
1100
|
+
const [error, setError] = useState7(null);
|
|
1101
|
+
const [loading, setLoading] = useState7(true);
|
|
1102
|
+
const seq = useRef2(0);
|
|
1103
|
+
const reload = useCallback2(async () => {
|
|
1010
1104
|
const id = ++seq.current;
|
|
1011
1105
|
setLoading(true);
|
|
1012
1106
|
try {
|
|
@@ -1028,7 +1122,7 @@ function usePostQuery(path, body) {
|
|
|
1028
1122
|
}
|
|
1029
1123
|
|
|
1030
1124
|
// src/areas/ai/UsagePanel.tsx
|
|
1031
|
-
import { jsx as
|
|
1125
|
+
import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1032
1126
|
var USAGE_BY = { project: "scope", model: "model", purpose: "purpose", account: "account" };
|
|
1033
1127
|
var outcomeOf = (state) => state === "done" ? "ok" : state;
|
|
1034
1128
|
var OUTCOME_TONES = { ok: "success", refused: "warning", failed: "danger", reserved: "info" };
|
|
@@ -1040,32 +1134,36 @@ function monthRange(offset) {
|
|
|
1040
1134
|
}
|
|
1041
1135
|
function UsagePanel({ scopeId, by: byOptions }) {
|
|
1042
1136
|
const t = useAiTexts();
|
|
1043
|
-
const fmt =
|
|
1044
|
-
const [by, setBy] =
|
|
1045
|
-
const [month, setMonth] =
|
|
1137
|
+
const fmt = useFormatters6();
|
|
1138
|
+
const [by, setBy] = useState8(byOptions[0]);
|
|
1139
|
+
const [month, setMonth] = useState8(0);
|
|
1046
1140
|
const { from, to } = monthRange(month);
|
|
1047
1141
|
const usage = usePostQuery("/usage", { from, to, scopeId: scopeId ?? null, groupBy: USAGE_BY[by] });
|
|
1048
1142
|
const recent = usePostQuery("/usage/recent", { from, to, scopeId: scopeId ?? null, count: 50 });
|
|
1049
1143
|
const rows = usage.data?.rows;
|
|
1050
1144
|
const people = useNames2("people", useMemo3(() => [
|
|
1051
1145
|
...by === "account" ? (rows ?? []).filter((r) => !r.title && r.key).map((r) => r.key) : [],
|
|
1052
|
-
...(recent.data ?? []).flatMap((c) =>
|
|
1146
|
+
...(recent.data ?? []).flatMap((c) => [
|
|
1147
|
+
...c.accountId && !c.accountName ? [c.accountId] : [],
|
|
1148
|
+
...c.onBehalfOf && !c.onBehalfOfName ? [c.onBehalfOf] : []
|
|
1149
|
+
])
|
|
1053
1150
|
], [by, rows, recent.data]));
|
|
1151
|
+
const nameOf = (id, name) => name || (id ? people[id] : void 0) || id || EMPTY_VALUE;
|
|
1054
1152
|
const scopes = useNames2("scopes", useMemo3(() => by === "project" ? (rows ?? []).filter((r) => !r.title && r.key).map((r) => r.key) : [], [by, rows]));
|
|
1055
1153
|
const months = [0, 1, 2, 3, 4, 5].map((m) => ({ value: String(m), label: fmt.dateTime(monthRange(m).from, { year: "numeric", month: "long", timeZone: "UTC" }) }));
|
|
1056
1154
|
const total = (rows ?? []).reduce((sum, r) => sum + num(r.cost), 0);
|
|
1057
1155
|
const money = (v) => fmt.number(num(v), { maximumFractionDigits: 6 });
|
|
1058
1156
|
const label = (key, title) => key === "" && by === "project" ? t("siteCalls") : title || (by === "account" ? people[key] : by === "project" ? scopes[key] : void 0) || key;
|
|
1059
|
-
return /* @__PURE__ */
|
|
1060
|
-
/* @__PURE__ */
|
|
1061
|
-
|
|
1157
|
+
return /* @__PURE__ */ jsxs7(Stack7, { gap: "section", children: [
|
|
1158
|
+
/* @__PURE__ */ jsx7(
|
|
1159
|
+
Panel6,
|
|
1062
1160
|
{
|
|
1063
1161
|
title: t("usageTitle"),
|
|
1064
1162
|
description: t("usageTotal", { cost: money(total) }),
|
|
1065
1163
|
flush: true,
|
|
1066
1164
|
"data-testid": "ai-usage",
|
|
1067
|
-
actions: /* @__PURE__ */
|
|
1068
|
-
/* @__PURE__ */
|
|
1165
|
+
actions: /* @__PURE__ */ jsxs7(HStack6, { gap: "2", children: [
|
|
1166
|
+
/* @__PURE__ */ jsx7(
|
|
1069
1167
|
SelectField4,
|
|
1070
1168
|
{
|
|
1071
1169
|
size: "sm",
|
|
@@ -1076,9 +1174,9 @@ function UsagePanel({ scopeId, by: byOptions }) {
|
|
|
1076
1174
|
onChange: (e) => setBy(e.target.value)
|
|
1077
1175
|
}
|
|
1078
1176
|
),
|
|
1079
|
-
/* @__PURE__ */
|
|
1177
|
+
/* @__PURE__ */ jsx7(SelectField4, { size: "sm", width: "auto", value: String(month), "aria-label": t("month"), options: months, onChange: (e) => setMonth(Number(e.target.value)) })
|
|
1080
1178
|
] }),
|
|
1081
|
-
children: /* @__PURE__ */
|
|
1179
|
+
children: /* @__PURE__ */ jsx7(
|
|
1082
1180
|
DataTable4,
|
|
1083
1181
|
{
|
|
1084
1182
|
"aria-label": t("usageTitle"),
|
|
@@ -1088,7 +1186,7 @@ function UsagePanel({ scopeId, by: byOptions }) {
|
|
|
1088
1186
|
getRowId: (r) => r.key,
|
|
1089
1187
|
empty: t("noUsage"),
|
|
1090
1188
|
columns: [
|
|
1091
|
-
{ id: "label", header: t(`byOptions.${by}`), cell: (r) => /* @__PURE__ */
|
|
1189
|
+
{ id: "label", header: t(`byOptions.${by}`), cell: (r) => /* @__PURE__ */ jsx7(Text7, { dir: "auto", children: label(r.key, r.title) }) },
|
|
1092
1190
|
{ id: "calls", header: t("calls"), numeric: true, cell: (r) => fmt.number(num(r.calls)) },
|
|
1093
1191
|
{ id: "in", header: t("tokensIn"), numeric: true, cell: (r) => fmt.number(num(r.inputTokens)) },
|
|
1094
1192
|
{ id: "out", header: t("tokensOut"), numeric: true, cell: (r) => fmt.number(num(r.outputTokens)) },
|
|
@@ -1100,7 +1198,7 @@ function UsagePanel({ scopeId, by: byOptions }) {
|
|
|
1100
1198
|
)
|
|
1101
1199
|
}
|
|
1102
1200
|
),
|
|
1103
|
-
/* @__PURE__ */
|
|
1201
|
+
/* @__PURE__ */ jsx7(Panel6, { title: t("recentTitle"), flush: true, "data-testid": "ai-recent", children: /* @__PURE__ */ jsx7(
|
|
1104
1202
|
DataTable4,
|
|
1105
1203
|
{
|
|
1106
1204
|
"aria-label": t("recentTitle"),
|
|
@@ -1114,21 +1212,23 @@ function UsagePanel({ scopeId, by: byOptions }) {
|
|
|
1114
1212
|
{
|
|
1115
1213
|
id: "who",
|
|
1116
1214
|
header: t("who"),
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1215
|
+
// An agent's call is the person's it acted for, the agent beside it.
|
|
1216
|
+
cell: (u) => /* @__PURE__ */ jsxs7(Stack7, { gap: "0", children: [
|
|
1217
|
+
/* @__PURE__ */ jsx7(Text7, { children: u.onBehalfOf ? nameOf(u.onBehalfOf, u.onBehalfOfName) : nameOf(u.accountId, u.accountName) }),
|
|
1218
|
+
u.onBehalfOf && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", children: t("callThrough", { name: nameOf(u.accountId, u.accountName) }) }),
|
|
1219
|
+
u.scope && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", dir: "ltr", children: u.scope })
|
|
1120
1220
|
] })
|
|
1121
1221
|
},
|
|
1122
|
-
{ id: "purpose", header: t("purpose"), cell: (u) => /* @__PURE__ */
|
|
1123
|
-
{ id: "model", header: t("model"), cell: (u) => /* @__PURE__ */
|
|
1222
|
+
{ id: "purpose", header: t("purpose"), cell: (u) => /* @__PURE__ */ jsx7(Text7, { fontFamily: "mono", textStyle: "sm", dir: "ltr", children: u.purpose || EMPTY_VALUE }) },
|
|
1223
|
+
{ id: "model", header: t("model"), cell: (u) => /* @__PURE__ */ jsx7(Text7, { fontFamily: "mono", textStyle: "sm", dir: "ltr", children: u.model }) },
|
|
1124
1224
|
{ id: "tokens", header: t("tokens"), numeric: true, cell: (u) => `${fmt.number(num(u.inputTokens))} / ${fmt.number(num(u.outputTokens))}` },
|
|
1125
1225
|
{ id: "cost", header: t("cost"), numeric: true, cell: (u) => money(u.cost) },
|
|
1126
1226
|
{
|
|
1127
1227
|
id: "outcome",
|
|
1128
1228
|
header: t("outcome"),
|
|
1129
|
-
cell: (u) => /* @__PURE__ */
|
|
1130
|
-
/* @__PURE__ */
|
|
1131
|
-
u.error && /* @__PURE__ */
|
|
1229
|
+
cell: (u) => /* @__PURE__ */ jsxs7(Stack7, { gap: "0.5", children: [
|
|
1230
|
+
/* @__PURE__ */ jsx7(StatusPill3, { tone: OUTCOME_TONES[outcomeOf(u.state)] ?? "neutral", children: t(`outcomes.${outcomeOf(u.state)}`) }),
|
|
1231
|
+
u.error && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", lineClamp: 2, title: u.error, children: u.error })
|
|
1132
1232
|
] })
|
|
1133
1233
|
}
|
|
1134
1234
|
]
|
|
@@ -1138,22 +1238,20 @@ function UsagePanel({ scopeId, by: byOptions }) {
|
|
|
1138
1238
|
}
|
|
1139
1239
|
|
|
1140
1240
|
// src/areas/ai/AiAdmin.tsx
|
|
1141
|
-
import { jsx as
|
|
1142
|
-
function useHostKeepsConnections(
|
|
1241
|
+
import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1242
|
+
function useHostKeepsConnections(told, scopeId) {
|
|
1143
1243
|
const can = useCan();
|
|
1144
|
-
const told = site?.connectionsKeptByHost;
|
|
1145
1244
|
return told ?? !can("ai.connections.edit", scopeId);
|
|
1146
1245
|
}
|
|
1147
1246
|
function AiAdmin() {
|
|
1148
1247
|
const t = useAiTexts();
|
|
1149
|
-
const request =
|
|
1248
|
+
const request = useAreaRequest7("ai");
|
|
1150
1249
|
const site = useApiQuery3("ai", "/site");
|
|
1151
1250
|
const connections = useApiQuery3("ai", "/connections");
|
|
1152
1251
|
const aliases = useApiQuery3("ai", "/aliases");
|
|
1153
1252
|
const limits = useApiQuery3("ai", "/limits");
|
|
1154
|
-
const saving =
|
|
1155
|
-
const hostKeeps = useHostKeepsConnections(site.data);
|
|
1156
|
-
const tryHere = Boolean(useOptionalHost3()?.slots?.["ai.try"]);
|
|
1253
|
+
const saving = useApiAction6();
|
|
1254
|
+
const hostKeeps = useHostKeepsConnections(site.data?.connectionsKeptByHost);
|
|
1157
1255
|
const models = useMemo4(() => modelRows(connections.data ?? []), [connections.data]);
|
|
1158
1256
|
async function saveSiteLimits(rows) {
|
|
1159
1257
|
if (await saving.run(() => saveLimits(request, null, limits.data ?? [], rows).then(() => true)) !== void 0) {
|
|
@@ -1161,20 +1259,20 @@ function AiAdmin() {
|
|
|
1161
1259
|
await limits.reload();
|
|
1162
1260
|
}
|
|
1163
1261
|
}
|
|
1164
|
-
return /* @__PURE__ */
|
|
1165
|
-
/* @__PURE__ */
|
|
1166
|
-
/* @__PURE__ */
|
|
1167
|
-
/* @__PURE__ */
|
|
1168
|
-
/* @__PURE__ */
|
|
1169
|
-
/* @__PURE__ */
|
|
1170
|
-
/* @__PURE__ */
|
|
1171
|
-
|
|
1172
|
-
/* @__PURE__ */
|
|
1262
|
+
return /* @__PURE__ */ jsxs8(Tabs.Root, { defaultValue: "models", variant: "line", lazyMount: true, children: [
|
|
1263
|
+
/* @__PURE__ */ jsxs8(Tabs.List, { mb: "section", overflowX: "auto", overflowY: "hidden", children: [
|
|
1264
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "models", children: t("tabs.models") }),
|
|
1265
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "aliases", children: t("tabs.aliases") }),
|
|
1266
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "access", children: t("tabs.access") }),
|
|
1267
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "limits", children: t("tabs.limits") }),
|
|
1268
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "usage", children: t("tabs.usage") }),
|
|
1269
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "try", children: t("tabs.try") }),
|
|
1270
|
+
/* @__PURE__ */ jsx8(Tabs.Trigger, { value: "exports", children: t("tabs.exports") })
|
|
1173
1271
|
] }),
|
|
1174
|
-
/* @__PURE__ */
|
|
1175
|
-
/* @__PURE__ */
|
|
1176
|
-
connections.data && connections.data.length === 0 && /* @__PURE__ */
|
|
1177
|
-
/* @__PURE__ */
|
|
1272
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "models", children: /* @__PURE__ */ jsxs8(Stack8, { gap: "section", children: [
|
|
1273
|
+
/* @__PURE__ */ jsx8(InlineAlert6, { tone: "danger", children: connections.error }),
|
|
1274
|
+
connections.data && connections.data.length === 0 && /* @__PURE__ */ jsx8(InlineAlert6, { tone: "info", children: t("noProviders") }),
|
|
1275
|
+
/* @__PURE__ */ jsx8(
|
|
1178
1276
|
ModelsPanel,
|
|
1179
1277
|
{
|
|
1180
1278
|
connections: connections.data,
|
|
@@ -1186,22 +1284,22 @@ function AiAdmin() {
|
|
|
1186
1284
|
}
|
|
1187
1285
|
)
|
|
1188
1286
|
] }) }),
|
|
1189
|
-
/* @__PURE__ */
|
|
1190
|
-
/* @__PURE__ */
|
|
1191
|
-
/* @__PURE__ */
|
|
1192
|
-
/* @__PURE__ */
|
|
1193
|
-
|
|
1194
|
-
/* @__PURE__ */
|
|
1287
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "aliases", children: /* @__PURE__ */ jsx8(AliasesPanel, { aliases: aliases.data, models, onSaved: aliases.reload }) }),
|
|
1288
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "access", children: /* @__PURE__ */ jsx8(AccessPanel, { models }) }),
|
|
1289
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "limits", children: /* @__PURE__ */ jsx8(Panel7, { title: t("siteLimitsTitle"), description: t("siteLimitsHint"), children: limits.data && /* @__PURE__ */ jsx8(LimitsEditor, { limits: limits.data, onSave: saveSiteLimits, busy: saving.busy, error: saving.error ?? limits.error }) }) }),
|
|
1290
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "usage", children: /* @__PURE__ */ jsx8(UsagePanel, { by: ["project", "model", "purpose", "account"] }) }),
|
|
1291
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "try", children: /* @__PURE__ */ jsx8(TryPanel, { aliases: (aliases.data ?? []).map((a) => a.name) }) }),
|
|
1292
|
+
/* @__PURE__ */ jsx8(Tabs.Content, { value: "exports", children: /* @__PURE__ */ jsx8(ExportsPanel, {}) })
|
|
1195
1293
|
] });
|
|
1196
1294
|
}
|
|
1197
1295
|
|
|
1198
1296
|
// src/areas/ai/pages.tsx
|
|
1199
|
-
import { jsx as
|
|
1297
|
+
import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1200
1298
|
function AiAdminPage() {
|
|
1201
1299
|
const t = useAiTexts();
|
|
1202
|
-
return /* @__PURE__ */
|
|
1203
|
-
/* @__PURE__ */
|
|
1204
|
-
/* @__PURE__ */
|
|
1300
|
+
return /* @__PURE__ */ jsxs9(Stack9, { gap: "section", children: [
|
|
1301
|
+
/* @__PURE__ */ jsx9(PageHeader, { title: t("pageTitle"), description: t("pageSubtitle") }),
|
|
1302
|
+
/* @__PURE__ */ jsx9(AiAdmin, {})
|
|
1205
1303
|
] });
|
|
1206
1304
|
}
|
|
1207
1305
|
function aiPages(options) {
|
|
@@ -1222,59 +1320,78 @@ function aiPages(options) {
|
|
|
1222
1320
|
|
|
1223
1321
|
// src/areas/ai/AiScopeScreen.tsx
|
|
1224
1322
|
import { useMemo as useMemo5 } from "react";
|
|
1225
|
-
import { Stack as
|
|
1226
|
-
import {
|
|
1227
|
-
import { jsx as
|
|
1228
|
-
function AiScopeScreen({ scopeId }) {
|
|
1323
|
+
import { Stack as Stack10, Text as Text8 } from "@chakra-ui/react";
|
|
1324
|
+
import { InlineAlert as InlineAlert7, Loading, Panel as Panel8, StatusPill as StatusPill4, TextBone, TextSlot, useApiQuery as useApiQuery4, useNames as useNames3 } from "@abpjs/ui";
|
|
1325
|
+
import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1326
|
+
function AiScopeScreen({ scopeId, header }) {
|
|
1229
1327
|
const t = useAiTexts();
|
|
1230
1328
|
const limitText = useLimitText();
|
|
1231
|
-
const
|
|
1232
|
-
const
|
|
1233
|
-
const
|
|
1329
|
+
const id = encodeURIComponent(scopeId);
|
|
1330
|
+
const view = useApiQuery4("ai", `/scopes/${id}/view`);
|
|
1331
|
+
const access = useApiQuery4("ai", `/scopes/${id}/access`);
|
|
1332
|
+
const v = view.data;
|
|
1333
|
+
const own = useApiQuery4("ai", v?.mayConnect ? `/connections${scopeQuery(scopeId)}` : null);
|
|
1234
1334
|
const aliases = useApiQuery4("ai", `/aliases${scopeQuery(scopeId)}`);
|
|
1235
1335
|
const limits = useApiQuery4("ai", `/limits${scopeQuery(scopeId)}`);
|
|
1236
|
-
const
|
|
1237
|
-
const
|
|
1336
|
+
const hostKeeps = useHostKeepsConnections(v?.connectionsKeptByHost, scopeId);
|
|
1337
|
+
const rows = useMemo5(() => v ? scopeModelRows(v) : void 0, [v]);
|
|
1238
1338
|
const a = access.data;
|
|
1239
|
-
const
|
|
1240
|
-
const
|
|
1241
|
-
const
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1339
|
+
const above = useMemo5(() => {
|
|
1340
|
+
const groups = [];
|
|
1341
|
+
for (const l of v?.limitsFromAbove ?? []) {
|
|
1342
|
+
const at = l.scopeId ?? null;
|
|
1343
|
+
const group = groups.find((g) => g.scopeId === at);
|
|
1344
|
+
if (group) group.limits.push(l);
|
|
1345
|
+
else groups.push({ scopeId: at, limits: [l] });
|
|
1346
|
+
}
|
|
1347
|
+
return groups;
|
|
1348
|
+
}, [v]);
|
|
1349
|
+
const scopeNames = useNames3("scopes", useMemo5(() => above.flatMap((g) => g.scopeId ? [g.scopeId] : []), [above]));
|
|
1350
|
+
const aliasNames = useMemo5(() => [...new Set([...aliases.data ?? [], ...v?.aliasesFromAbove ?? []].map((x) => x.name))], [aliases.data, v]);
|
|
1351
|
+
if (view.error && !v || access.error && !a) {
|
|
1352
|
+
return /* @__PURE__ */ jsxs10(Stack10, { gap: "section", children: [
|
|
1353
|
+
header,
|
|
1354
|
+
/* @__PURE__ */ jsx10(InlineAlert7, { tone: "danger", children: view.error ?? access.error })
|
|
1355
|
+
] });
|
|
1356
|
+
}
|
|
1245
1357
|
const opened = a && (a.allSiteModels ? t("allModels") : a.siteModels.length ? t("someModels", { count: a.siteModels.length }) : t("noModelsOpen"));
|
|
1246
|
-
const lines = (list) => !list ? /* @__PURE__ */
|
|
1247
|
-
return /* @__PURE__ */
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
/* @__PURE__ */
|
|
1358
|
+
const lines = (list) => !list ? /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: /* @__PURE__ */ jsx10(TextBone, { width: 24 }) }) : list.length ? list.map((l) => /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: limitText(l) }, l.id)) : /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", color: "fg.muted", children: t("noLimits") });
|
|
1359
|
+
return /* @__PURE__ */ jsx10(Loading, { when: !v || !a, children: /* @__PURE__ */ jsxs10(Stack10, { gap: "section", children: [
|
|
1360
|
+
header,
|
|
1361
|
+
/* @__PURE__ */ jsx10(Panel8, { title: t("projectAccessTitle"), description: t("projectAccessHint"), "data-testid": "ai-project-access", children: /* @__PURE__ */ jsxs10(Stack10, { gap: "2", children: [
|
|
1362
|
+
/* @__PURE__ */ jsx10(Text8, { children: /* @__PURE__ */ jsx10(StatusPill4, { tone: a?.allSiteModels || a?.siteModels.length ? "success" : "neutral", children: opened }) }),
|
|
1363
|
+
/* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: /* @__PURE__ */ jsx10(TextSlot, { width: 44, children: v && (v.mayConnect ? t("ownAllowed") : t("ownNotAllowed")) }) })
|
|
1251
1364
|
] }) }),
|
|
1252
|
-
/* @__PURE__ */
|
|
1365
|
+
/* @__PURE__ */ jsx10(
|
|
1253
1366
|
ModelsPanel,
|
|
1254
1367
|
{
|
|
1255
1368
|
scopeId,
|
|
1256
|
-
connections:
|
|
1369
|
+
connections: v?.mayConnect ? own.data ?? [] : [],
|
|
1257
1370
|
rows,
|
|
1258
|
-
loading:
|
|
1371
|
+
loading: view.loading,
|
|
1259
1372
|
hostKeeps,
|
|
1260
|
-
onChanged: () => Promise.all([own.reload(), aliases.reload()]).then(() => void 0),
|
|
1373
|
+
onChanged: () => Promise.all([view.reload(), own.reload(), aliases.reload()]).then(() => void 0),
|
|
1261
1374
|
title: t("projectModelsTitle"),
|
|
1262
|
-
description:
|
|
1375
|
+
description: v?.mayConnect ? t("projectModelsOwnHint") : t("projectModelsHint")
|
|
1263
1376
|
}
|
|
1264
1377
|
),
|
|
1265
|
-
/* @__PURE__ */
|
|
1266
|
-
/* @__PURE__ */
|
|
1267
|
-
/* @__PURE__ */
|
|
1268
|
-
/* @__PURE__ */
|
|
1378
|
+
/* @__PURE__ */ jsx10(AliasesPanel, { scopeId, aliases: aliases.data, inherited: v?.aliasesFromAbove, models: rows ?? [], onSaved: aliases.reload }),
|
|
1379
|
+
/* @__PURE__ */ jsx10(Panel8, { title: t("tabs.limits"), description: t("projectLimitsReadHint"), "data-testid": "ai-project-limits", children: /* @__PURE__ */ jsxs10(Stack10, { gap: "3", children: [
|
|
1380
|
+
/* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
|
|
1381
|
+
/* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: t("thisProject") }),
|
|
1269
1382
|
lines(limits.data)
|
|
1270
1383
|
] }),
|
|
1271
|
-
!
|
|
1272
|
-
/* @__PURE__ */
|
|
1273
|
-
lines(
|
|
1274
|
-
] })
|
|
1384
|
+
!v || !above.some((g) => g.scopeId === null) ? /* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
|
|
1385
|
+
/* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: t("theSite") }),
|
|
1386
|
+
lines(v ? [] : void 0)
|
|
1387
|
+
] }) : null,
|
|
1388
|
+
above.map((g) => /* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
|
|
1389
|
+
/* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: g.scopeId ? scopeNames[g.scopeId] ?? g.scopeId : t("theSite") }),
|
|
1390
|
+
lines(g.limits)
|
|
1391
|
+
] }, g.scopeId ?? "site"))
|
|
1275
1392
|
] }) }),
|
|
1276
|
-
/* @__PURE__ */
|
|
1277
|
-
/* @__PURE__ */
|
|
1393
|
+
/* @__PURE__ */ jsx10(UsagePanel, { scopeId, by: ["model", "purpose", "account"] }),
|
|
1394
|
+
/* @__PURE__ */ jsx10(TryPanel, { scopeId, aliases: aliasNames }, aliases.data && v ? "loaded" : "loading")
|
|
1278
1395
|
] }) });
|
|
1279
1396
|
}
|
|
1280
1397
|
export {
|
|
@@ -1288,6 +1405,7 @@ export {
|
|
|
1288
1405
|
LIMIT_PERIODS,
|
|
1289
1406
|
LimitsEditor,
|
|
1290
1407
|
ModelsPanel,
|
|
1408
|
+
TryPanel,
|
|
1291
1409
|
USAGE_BY,
|
|
1292
1410
|
UsagePanel,
|
|
1293
1411
|
aiPages,
|
|
@@ -1297,6 +1415,7 @@ export {
|
|
|
1297
1415
|
modelRows,
|
|
1298
1416
|
num,
|
|
1299
1417
|
saveLimits,
|
|
1418
|
+
scopeModelRows,
|
|
1300
1419
|
useAiTexts,
|
|
1301
1420
|
useHostKeepsConnections,
|
|
1302
1421
|
useLimitText,
|