@abpjs/ui 0.2.0-next.4 → 0.2.0-next.41

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/dist/ai.d.ts CHANGED
@@ -522,7 +522,7 @@ declare const limitRow: (l: AiLimit) => LimitRow;
522
522
  * changed ones are set. A person's and a group's limits are left alone.
523
523
  */
524
524
  declare function saveLimits(request: HostRequest, scopeId: string | null | undefined, before: readonly AiLimit[], rows: readonly LimitRow[]): Promise<void>;
525
- /** "Cost per day: 5", "Tokens per reply: 2,000". */
525
+ /** "Cost per day: 5", "Tokens per reply: 2,000", and a person's default: "Cost per day for each person: 1". */
526
526
  declare function useLimitText(): (l: AiLimit) => string;
527
527
  /**
528
528
  * Limits on a scope or the site: cost, tokens or requests per minute, day or month, and tokens per reply. With `onSave`
package/dist/ai.js CHANGED
@@ -18,7 +18,7 @@ import { Button as Button2, CheckboxField, DataTable, FormDialog, HostSlot, Inli
18
18
  import { useState } from "react";
19
19
  import { HStack, Input, Stack, Text } from "@chakra-ui/react";
20
20
  import { Trash2 } from "lucide-react";
21
- import { Button, Field, IconButton, InlineAlert, SelectField, useFormatters } from "@abpjs/ui";
21
+ import { AddButton, Button, Field, IconButton, InlineAlert, SelectField, useFormatters } from "@abpjs/ui";
22
22
 
23
23
  // src/areas/ai/texts.ts
24
24
  import { createAreaTexts } from "@abpjs/ui";
@@ -118,6 +118,8 @@ var ar_default = {
118
118
  "periods.month": "\u0634\u0647\u0631",
119
119
  limitText: "{kind} \u0644\u0643\u0644 {period}: {amount}",
120
120
  limitCallTokens: "\u0627\u0644\u0631\u0645\u0648\u0632 \u0644\u0643\u0644 \u0631\u062F: {amount}",
121
+ limitEachPerson: "{kind} \u0644\u0643\u0644 {period} \u0644\u0643\u0644 \u0634\u062E\u0635: {amount}",
122
+ limitsOfTheirOwn: "{count, plural, zero {\u0644\u0627 \u062D\u0633\u0627\u0628\u0627\u062A \u0623\u0648 \u0645\u062C\u0645\u0648\u0639\u0627\u062A \u0644\u0647\u0627 \u062D\u062F\u0648\u062F \u062E\u0627\u0635\u0629.} one {\u0644\u062D\u0633\u0627\u0628 \u0623\u0648 \u0645\u062C\u0645\u0648\u0639\u0629 \u0648\u0627\u062D\u062F\u0629 \u062D\u062F\u0651 \u062E\u0627\u0635.} two {\u0644\u062D\u0633\u0627\u0628\u064A\u0646 \u0623\u0648 \u0645\u062C\u0645\u0648\u0639\u062A\u064A\u0646 \u062D\u062F\u0648\u062F \u062E\u0627\u0635\u0629.} few {\u0644\u0640# \u062D\u0633\u0627\u0628\u0627\u062A \u0648\u0645\u062C\u0645\u0648\u0639\u0627\u062A \u062D\u062F\u0648\u062F \u062E\u0627\u0635\u0629.} many {\u0644\u0640# \u062D\u0633\u0627\u0628\u064B\u0627 \u0648\u0645\u062C\u0645\u0648\u0639\u0629 \u062D\u062F\u0648\u062F \u062E\u0627\u0635\u0629.} other {\u0644\u0640# \u062D\u0633\u0627\u0628 \u0648\u0645\u062C\u0645\u0648\u0639\u0629 \u062D\u062F\u0648\u062F \u062E\u0627\u0635\u0629.}}",
121
123
  usageTitle: "\u0627\u0644\u0627\u0633\u062A\u062E\u062F\u0627\u0645",
122
124
  usageTotal: "\u0627\u0644\u0643\u0644\u0641\u0629 \u0627\u0644\u0625\u062C\u0645\u0627\u0644\u064A\u0629: {cost}",
123
125
  by: "\u0627\u0644\u062A\u062C\u0645\u064A\u0639 \u062D\u0633\u0628",
@@ -276,6 +278,8 @@ var en_default = {
276
278
  "periods.month": "month",
277
279
  limitText: "{kind} per {period}: {amount}",
278
280
  limitCallTokens: "Tokens per reply: {amount}",
281
+ limitEachPerson: "{kind} per {period} for each person: {amount}",
282
+ limitsOfTheirOwn: "{count, plural, one {One account or group has a limit of its own.} other {# accounts and groups have limits of their own.}}",
279
283
  usageTitle: "Usage",
280
284
  usageTotal: "Total cost: {cost}",
281
285
  by: "Sum by",
@@ -370,9 +374,12 @@ function useLimitText() {
370
374
  const fmt = useFormatters();
371
375
  return (l) => {
372
376
  const r = limitRow(l);
373
- return r.kind === "call-tokens" ? t("limitCallTokens", { amount: fmt.number(num(l.amount)) }) : t("limitText", { kind: t(`kinds.${r.kind}`), period: t(`periods.${r.period}`), amount: fmt.number(num(l.amount), { maximumFractionDigits: 6 }) });
377
+ if (r.kind === "call-tokens") return t("limitCallTokens", { amount: fmt.number(num(l.amount)) });
378
+ const values = { kind: t(`kinds.${r.kind}`), period: t(`periods.${r.period}`), amount: fmt.number(num(l.amount), { maximumFractionDigits: 6 }) };
379
+ return t(l.kind === "person" ? "limitEachPerson" : "limitText", values);
374
380
  };
375
381
  }
382
+ var namedLimit = (l) => !!l.accountId || !!l.groupId || l.kind === "account" || l.kind === "group";
376
383
  function LimitsEditor({ limits, onSave, onChange, busy, error }) {
377
384
  const t = useAiTexts();
378
385
  const [draft, setDraftRows] = useState(null);
@@ -403,11 +410,11 @@ function LimitsEditor({ limits, onSave, onChange, busy, error }) {
403
410
  ) }),
404
411
  /* @__PURE__ */ jsx(Field, { label: i === 0 ? t("limitPeriod") : void 0, flex: "1", children: r.kind === "call-tokens" ? /* @__PURE__ */ jsx(Text, { textStyle: "sm", color: "fg.muted", py: "2", children: t("perReply") }) : /* @__PURE__ */ jsx(SelectField, { value: r.period, options: periods, "aria-label": t("limitPeriod"), onChange: (e) => set(i, { period: e.target.value }) }) }),
405
412
  /* @__PURE__ */ jsx(Field, { label: i === 0 ? t("limitAmount") : void 0, flex: "1", children: /* @__PURE__ */ jsx(Input, { type: "number", min: 0, step: "any", value: r.amount, dir: "ltr", "aria-label": t("limitAmount"), onChange: (e) => set(i, { amount: e.target.value }) }) }),
406
- /* @__PURE__ */ jsx(IconButton, { "aria-label": t("removeLimit"), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx(Trash2, {}) })
413
+ /* @__PURE__ */ jsx(IconButton, { remove: true, "aria-label": t("removeLimit"), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx(Trash2, {}) })
407
414
  ] }, i)),
408
415
  rows.length === 0 && /* @__PURE__ */ jsx(Text, { textStyle: "sm", color: "fg.muted", children: t("noLimits") }),
409
416
  /* @__PURE__ */ jsxs(HStack, { children: [
410
- /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", onClick: () => setDraft([...rows, { kind: "cost", period: "day", amount: "" }]), children: t("addLimit") }),
417
+ /* @__PURE__ */ jsx(AddButton, { onClick: () => setDraft([...rows, { kind: "cost", period: "day", amount: "" }]), children: t("addLimit") }),
411
418
  onSave && /* @__PURE__ */ jsx(Button, { size: "sm", loading: busy, disabled: draft === null, onClick: () => void save(), children: t("save") })
412
419
  ] })
413
420
  ] });
@@ -678,7 +685,7 @@ function AccessEditor({ scope, models, onClose, onSaved }) {
678
685
  import { useMemo as useMemo2, useState as useState3 } from "react";
679
686
  import { HStack as HStack2, Input as Input2, Stack as Stack3, Text as Text3 } from "@chakra-ui/react";
680
687
  import { Trash2 as Trash22 } from "lucide-react";
681
- import { Button as Button3, Field as Field2, IconButton as IconButton2, InlineAlert as InlineAlert3, notify as notify2, Panel as Panel2, SelectField as SelectField2, useApiAction as useApiAction2, useAreaRequest as useAreaRequest2 } from "@abpjs/ui";
688
+ import { AddButton as AddButton2, Button as Button3, Field as Field2, IconButton as IconButton2, InlineAlert as InlineAlert3, notify as notify2, Panel as Panel2, SelectField as SelectField2, useApiAction as useApiAction2, useAreaRequest as useAreaRequest2 } from "@abpjs/ui";
682
689
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
683
690
  var target = (key) => {
684
691
  const at = key.indexOf(":");
@@ -748,11 +755,11 @@ function AliasesPanel({ scopeId, aliases, inherited, models, onSaved }) {
748
755
  onChange: (e) => setDraft(rows.map((x, j) => j === i ? { ...x, key: e.target.value } : x))
749
756
  }
750
757
  ) }),
751
- /* @__PURE__ */ jsx3(IconButton2, { "aria-label": t("removeAlias", { name: r.name || "\u2026" }), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx3(Trash22, {}) })
758
+ /* @__PURE__ */ jsx3(IconButton2, { remove: true, "aria-label": t("removeAlias", { name: r.name || "\u2026" }), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx3(Trash22, {}) })
752
759
  ] }, i)),
753
760
  rows.length === 0 && /* @__PURE__ */ jsx3(Text3, { textStyle: "sm", color: "fg.muted", children: t("noAliases") }),
754
761
  /* @__PURE__ */ jsxs3(HStack2, { children: [
755
- /* @__PURE__ */ jsx3(Button3, { size: "sm", variant: "secondary", onClick: () => setDraft([...rows, { name: "", key: usable[0]?.key ?? "", rest: [] }]), disabled: usable.length === 0, children: t("addAlias") }),
762
+ /* @__PURE__ */ jsx3(AddButton2, { onClick: () => setDraft([...rows, { name: "", key: usable[0]?.key ?? "", rest: [] }]), disabled: usable.length === 0, children: t("addAlias") }),
756
763
  usable.length === 0 && /* @__PURE__ */ jsx3(Text3, { textStyle: "sm", color: "fg.muted", children: t("noUsable") })
757
764
  ] }),
758
765
  shownInherited.length > 0 && /* @__PURE__ */ jsxs3(Stack3, { gap: "1", children: [
@@ -1322,7 +1329,7 @@ function aiPages(options) {
1322
1329
  import { useMemo as useMemo5 } from "react";
1323
1330
  import { Stack as Stack10, Text as Text8 } from "@chakra-ui/react";
1324
1331
  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";
1332
+ import { Fragment, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
1326
1333
  function AiScopeScreen({ scopeId, header }) {
1327
1334
  const t = useAiTexts();
1328
1335
  const limitText = useLimitText();
@@ -1355,7 +1362,16 @@ function AiScopeScreen({ scopeId, header }) {
1355
1362
  ] });
1356
1363
  }
1357
1364
  const opened = a && (a.allSiteModels ? t("allModels") : a.siteModels.length ? t("someModels", { count: a.siteModels.length }) : t("noModelsOpen"));
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") });
1365
+ const lines = (list) => {
1366
+ if (!list) return /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: /* @__PURE__ */ jsx10(TextBone, { width: 24 }) });
1367
+ const own2 = list.filter((l) => !namedLimit(l));
1368
+ const named = new Set(list.filter(namedLimit).map((l) => l.accountId ?? l.groupId ?? l.id)).size;
1369
+ if (!own2.length && !named) return /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", color: "fg.muted", children: t("noLimits") });
1370
+ return /* @__PURE__ */ jsxs10(Fragment, { children: [
1371
+ own2.map((l) => /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: limitText(l) }, l.id)),
1372
+ named > 0 && /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", color: "fg.muted", children: t("limitsOfTheirOwn", { count: named }) })
1373
+ ] });
1374
+ };
1359
1375
  return /* @__PURE__ */ jsx10(Loading, { when: !v || !a, children: /* @__PURE__ */ jsxs10(Stack10, { gap: "section", children: [
1360
1376
  header,
1361
1377
  /* @__PURE__ */ jsx10(Panel8, { title: t("projectAccessTitle"), description: t("projectAccessHint"), "data-testid": "ai-project-access", children: /* @__PURE__ */ jsxs10(Stack10, { gap: "2", children: [