@abpjs/ui 0.1.0 → 0.2.0-next.10

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.js ADDED
@@ -0,0 +1,1440 @@
1
+ "use client";
2
+
3
+ // src/areas/ai/pages.tsx
4
+ import { Stack as Stack9 } from "@chakra-ui/react";
5
+ import { PageHeader } from "@abpjs/ui";
6
+
7
+ // src/areas/ai/AiAdmin.tsx
8
+ import { useMemo as useMemo4 } from "react";
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
+
12
+ // src/areas/ai/AccessPanel.tsx
13
+ import { useCallback, useEffect, useMemo, useRef, useState as useState2 } from "react";
14
+ import { Stack as Stack2, Text as Text2 } from "@chakra-ui/react";
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
+
17
+ // src/areas/ai/LimitsEditor.tsx
18
+ import { useState } from "react";
19
+ import { HStack, Input, Stack, Text } from "@chakra-ui/react";
20
+ import { Trash2 } from "lucide-react";
21
+ import { Button, Field, IconButton, InlineAlert, SelectField, useFormatters } from "@abpjs/ui";
22
+
23
+ // src/areas/ai/texts.ts
24
+ import { createAreaTexts } from "@abpjs/ui";
25
+
26
+ // src/areas/ai/texts/ar.json
27
+ var ar_default = {
28
+ pageTitle: "\u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A",
29
+ pageSubtitle: "\u0627\u0644\u0646\u0645\u0627\u0630\u062C \u0627\u0644\u062A\u064A \u064A\u0645\u0643\u0646 \u0644{product} \u0627\u0633\u062A\u062F\u0639\u0627\u0624\u0647\u0627\u060C \u0648\u0627\u0644\u0623\u0633\u0645\u0627\u0621 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631\u0629 \u0627\u0644\u062A\u064A \u062A\u0633\u062A\u062E\u062F\u0645\u0647\u0627 \u0627\u0644\u0645\u0647\u0627\u0631\u0627\u062A \u0648\u0627\u0644\u062E\u0637\u0648\u0627\u062A\u060C \u0648\u0645\u0627 \u064A\u0645\u0643\u0646 \u0644\u0643\u0644 \u0645\u0634\u0631\u0648\u0639 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647\u060C \u0648\u0627\u0644\u062D\u062F\u0648\u062F\u060C \u0648\u0643\u0644\u0641\u0629 \u0630\u0644\u0643 \u0643\u0644\u0647. \u0627\u0644\u0645\u0632\u0648\u0651\u062F\u0648\u0646 \u0627\u062A\u0635\u0627\u0644\u0627\u062A.",
30
+ "tabs.models": "\u0627\u0644\u0646\u0645\u0627\u0630\u062C",
31
+ "tabs.aliases": "\u0627\u0644\u0623\u0633\u0645\u0627\u0621 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631\u0629",
32
+ "tabs.access": "\u0627\u0644\u0645\u0634\u0627\u0631\u064A\u0639",
33
+ "tabs.limits": "\u0627\u0644\u062D\u062F\u0648\u062F",
34
+ "tabs.usage": "\u0627\u0644\u0627\u0633\u062A\u062E\u062F\u0627\u0645",
35
+ "tabs.try": "\u062A\u062C\u0631\u0628\u0629",
36
+ "tabs.exports": "\u0627\u0644\u062A\u0635\u062F\u064A\u0631",
37
+ modelsTitle: "\u0627\u0644\u0646\u0645\u0627\u0630\u062C",
38
+ modelsHint: "\u0646\u0645\u0627\u0630\u062C \u0643\u0644 \u0627\u062A\u0635\u0627\u0644 \u0628\u0645\u0632\u0648\u0651\u062F\u060C \u062A\u064F\u0643\u062A\u0634\u0641 \u0628\u0633\u0624\u0627\u0644\u0647. \u064A\u0628\u0642\u0649 \u0627\u0644\u0646\u0645\u0648\u0630\u062C \u0645\u062A\u0648\u0642\u0641\u064B\u0627 \u062D\u062A\u0649 \u062A\u0634\u063A\u0651\u0644\u0647\u061B \u0648\u062D\u062F\u0651\u062F \u0623\u0633\u0639\u0627\u0631\u0647 \u0644\u062A\u0643\u0648\u0646 \u0627\u0644\u062D\u062F\u0648\u062F \u0628\u0627\u0644\u0645\u0627\u0644.",
39
+ noProviders: "\u0644\u0627 \u064A\u0648\u062C\u062F \u0645\u0632\u0648\u0651\u062F \u0646\u0645\u0627\u0630\u062C \u0645\u062A\u0635\u0644 \u0628\u0639\u062F. \u0623\u0636\u0641 \u0627\u062A\u0635\u0627\u0644 Anthropic \u0623\u0648 \u0627\u062A\u0635\u0627\u0644\u064B\u0627 \u0645\u062A\u0648\u0627\u0641\u0642\u064B\u0627 \u0645\u0639 OpenAI \u0645\u0646 \u0627\u0644\u0625\u062F\u0627\u0631\u0629 \u203A \u0627\u0644\u0627\u062A\u0635\u0627\u0644\u0627\u062A.",
40
+ connection: "\u0627\u0644\u0627\u062A\u0635\u0627\u0644",
41
+ findModels: "\u0627\u0643\u062A\u0634\u0627\u0641 \u0646\u0645\u0627\u0630\u062C\u0647",
42
+ found: "\u064A\u0642\u062F\u0651\u0645 {name} {count, plural, zero {\u0644\u0627 \u0646\u0645\u0627\u0630\u062C} one {\u0646\u0645\u0648\u0630\u062C\u064B\u0627 \u0648\u0627\u062D\u062F\u064B\u0627} two {\u0646\u0645\u0648\u0630\u062C\u064A\u0646} few {# \u0646\u0645\u0627\u0630\u062C} many {# \u0646\u0645\u0648\u0630\u062C\u064B\u0627} other {# \u0646\u0645\u0648\u0630\u062C}}.",
43
+ noModels: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0646\u0645\u0627\u0630\u062C \u0628\u0639\u062F.",
44
+ noModelsFind: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0646\u0645\u0627\u0630\u062C \u0628\u0639\u062F. \u0627\u0643\u062A\u0634\u0641 \u0646\u0645\u0627\u0630\u062C \u0627\u062A\u0635\u0627\u0644 \u0644\u0644\u0628\u062F\u0621.",
45
+ model: "\u0627\u0644\u0646\u0645\u0648\u0630\u062C",
46
+ can: "\u0645\u0627 \u064A\u0633\u062A\u0637\u064A\u0639\u0647",
47
+ tools: "\u0627\u0644\u0623\u062F\u0648\u0627\u062A",
48
+ images: "\u0627\u0644\u0635\u0648\u0631",
49
+ structured: "\u0625\u062C\u0627\u0628\u0627\u062A \u0645\u0646\u0638\u0651\u0645\u0629",
50
+ toolsLong: "\u064A\u0633\u062A\u062F\u0639\u064A \u0627\u0644\u0623\u062F\u0648\u0627\u062A",
51
+ imagesLong: "\u064A\u0642\u0631\u0623 \u0627\u0644\u0635\u0648\u0631",
52
+ structuredLong: "\u064A\u062C\u064A\u0628 \u0628\u0635\u064A\u063A\u0629 JSON \u0645\u062D\u062F\u062F\u0629",
53
+ prices: "\u0627\u0644\u0623\u0633\u0639\u0627\u0631",
54
+ price: "{input} \u0644\u0644\u0625\u062F\u062E\u0627\u0644\u060C {output} \u0644\u0644\u0625\u062E\u0631\u0627\u062C\u060C \u0644\u0643\u0644 \u0645\u0644\u064A\u0648\u0646 \u0631\u0645\u0632",
55
+ noPrice: "\u0628\u0644\u0627 \u0633\u0639\u0631: \u062A\u064F\u062D\u062A\u0633\u0628 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A\u0647 \u0645\u062C\u0627\u0646\u064A\u0629",
56
+ priceSetAt: "\u062D\u064F\u062F\u0651\u062F \u0641\u064A {at}",
57
+ state: "\u0627\u0644\u062D\u0627\u0644\u0629",
58
+ on: "\u064A\u0639\u0645\u0644",
59
+ off: "\u0645\u062A\u0648\u0642\u0641",
60
+ edit: "\u062A\u0639\u062F\u064A\u0644",
61
+ editModel: "\u0627\u0644\u0646\u0645\u0648\u0630\u062C {name}",
62
+ modelOn: "\u064A\u0639\u0645\u0644: \u064A\u0645\u0643\u0646 \u0644\u0644\u0623\u0633\u0645\u0627\u0621 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631\u0629 \u0627\u0644\u0625\u0634\u0627\u0631\u0629 \u0625\u0644\u064A\u0647 \u0648\u064A\u0645\u0643\u0646 \u0645\u0646\u062D\u0647 \u0644\u0644\u0645\u0634\u0627\u0631\u064A\u0639",
63
+ name: "\u0627\u0644\u0627\u0633\u0645",
64
+ nameHint: "\u0645\u0627 \u064A\u0631\u0627\u0647 \u0627\u0644\u0646\u0627\u0633\u061B \u0645\u0639\u0631\u0651\u0641\u0647 \u0645\u0627 \u0644\u0645 \u062A\u064F\u0639\u0650\u062F \u062A\u0633\u0645\u064A\u062A\u0647.",
65
+ context: "\u062D\u062C\u0645 \u0627\u0644\u0633\u064A\u0627\u0642 (\u0628\u0627\u0644\u0631\u0645\u0648\u0632)",
66
+ optional: "(\u0627\u062E\u062A\u064A\u0627\u0631\u064A)",
67
+ inputPrice: "\u0633\u0639\u0631 \u0627\u0644\u0625\u062F\u062E\u0627\u0644",
68
+ outputPrice: "\u0633\u0639\u0631 \u0627\u0644\u0625\u062E\u0631\u0627\u062C",
69
+ perMillion: "\u0644\u0643\u0644 \u0645\u0644\u064A\u0648\u0646 \u0631\u0645\u0632\u060C \u0628\u0639\u0645\u0644\u0629 \u0627\u0644\u0645\u0648\u0642\u0639.",
70
+ save: "\u062D\u0641\u0638",
71
+ saved: "\u062A\u0645 \u0627\u0644\u062D\u0641\u0638.",
72
+ aliasesTitle: "\u0627\u0644\u0623\u0633\u0645\u0627\u0621 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631\u0629",
73
+ aliasesHint: "\u0645\u0627 \u062A\u0634\u064A\u0631 \u0625\u0644\u064A\u0647 \u0627\u0644\u0645\u0647\u0627\u0631\u0627\u062A \u0648\u062E\u0637\u0648\u0627\u062A \u0633\u064A\u0631 \u0627\u0644\u0639\u0645\u0644\u060C \u0645\u062B\u0644 fast \u0623\u0648 smart. \u062A\u0648\u062C\u064A\u0647 \u0627\u0644\u0627\u0633\u0645 \u0625\u0644\u0649 \u0646\u0645\u0648\u0630\u062C \u0622\u062E\u0631 \u064A\u063A\u064A\u0651\u0631 \u0643\u0644 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0627\u062A\u0647 \u062F\u0641\u0639\u0629 \u0648\u0627\u062D\u062F\u0629.",
74
+ aliasesProjectHint: "\u062A\u0623\u062A\u064A \u0623\u0633\u0645\u0627\u0621 \u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u0623\u0648\u0644\u064B\u0627\u060C \u0648\u062A\u0643\u0645\u0644 \u0623\u0633\u0645\u0627\u0621 \u0627\u0644\u0645\u0648\u0642\u0639 \u0627\u0644\u0628\u0627\u0642\u064A. \u064A\u0634\u064A\u0631 \u0643\u0644 \u0645\u0646\u0647\u0627 \u0625\u0644\u0649 \u0646\u0645\u0648\u0630\u062C \u064A\u0645\u0643\u0646 \u0644\u0644\u0645\u0634\u0631\u0648\u0639 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647.",
75
+ alias: "\u0627\u0644\u0627\u0633\u0645 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631",
76
+ pickModel: "\u0627\u062E\u062A\u0631 \u0646\u0645\u0648\u0630\u062C\u064B\u0627\u2026",
77
+ removeAlias: "\u0625\u0632\u0627\u0644\u0629 \u0627\u0644\u0627\u0633\u0645 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631 {name}",
78
+ noAliases: "\u0644\u0627 \u0623\u0633\u0645\u0627\u0621 \u0645\u0633\u062A\u0639\u0627\u0631\u0629 \u062E\u0627\u0635\u0629 \u0628\u0647.",
79
+ addAlias: "\u0625\u0636\u0627\u0641\u0629 \u0627\u0633\u0645 \u0645\u0633\u062A\u0639\u0627\u0631",
80
+ noUsable: "\u0644\u0627 \u064A\u0648\u062C\u062F \u0646\u0645\u0648\u0630\u062C \u064A\u0639\u0645\u0644 \u0648\u0645\u0641\u062A\u0648\u062D \u0647\u0646\u0627 \u0628\u0639\u062F.",
81
+ fromSite: "\u0645\u0646 \u0627\u0644\u0645\u0648\u0642\u0639",
82
+ notOpenHere: "\u063A\u064A\u0631 \u0645\u0641\u062A\u0648\u062D \u0644\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639\u060C \u0641\u0644\u0627 \u064A\u062C\u064A\u0628 \u0647\u0646\u0627",
83
+ accessTitle: "\u0645\u0627 \u064A\u0645\u0643\u0646 \u0644\u0643\u0644 \u0645\u0634\u0631\u0648\u0639 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647",
84
+ accessHint: "\u0644\u0627 \u064A\u0633\u062A\u062E\u062F\u0645 \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u0623\u064A \u0646\u0645\u0648\u0630\u062C \u062D\u062A\u0649 \u062A\u0641\u062A\u062D \u0644\u0647 \u0628\u0639\u0636\u0647\u0627. \u0648\u064A\u0645\u0643\u0646\u0643 \u0623\u064A\u0636\u064B\u0627 \u0627\u0644\u0633\u0645\u0627\u062D \u0644\u0645\u0633\u0624\u0648\u0644\u064A\u0647 \u0628\u0625\u0636\u0627\u0641\u0629 \u0627\u062A\u0635\u0627\u0644\u0627\u062A \u062E\u0627\u0635\u0629 \u0628\u0647\u060C \u0648\u0645\u0646\u062D\u0647 \u062D\u062F\u0648\u062F\u064B\u0627 \u0636\u0645\u0646 \u062D\u062F\u0648\u062F \u0627\u0644\u0645\u0648\u0642\u0639.",
85
+ findProject: "\u0627\u0644\u0628\u062D\u062B \u0639\u0646 \u0645\u0634\u0631\u0648\u0639",
86
+ noProjects: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u0634\u0627\u0631\u064A\u0639.",
87
+ project: "\u0627\u0644\u0645\u0634\u0631\u0648\u0639",
88
+ opened: "\u0627\u0644\u0646\u0645\u0627\u0630\u062C",
89
+ allModels: "\u0643\u0644 \u0646\u0645\u0648\u0630\u062C \u064A\u0639\u0645\u0644",
90
+ someModels: "{count, plural, zero {\u0644\u0627 \u0646\u0645\u0627\u0630\u062C} one {\u0646\u0645\u0648\u0630\u062C \u0648\u0627\u062D\u062F} two {\u0646\u0645\u0648\u0630\u062C\u0627\u0646} few {# \u0646\u0645\u0627\u0630\u062C} many {# \u0646\u0645\u0648\u0630\u062C\u064B\u0627} other {# \u0646\u0645\u0648\u0630\u062C}}",
91
+ noModelsOpen: "\u0644\u0627 \u0634\u064A\u0621",
92
+ ownConnections: "\u0627\u062A\u0635\u0627\u0644\u0627\u062A \u062E\u0627\u0635\u0629",
93
+ allowed: "\u0645\u0633\u0645\u0648\u062D",
94
+ notAllowed: "\u063A\u064A\u0631 \u0645\u0633\u0645\u0648\u062D",
95
+ accessFor: "\u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A \u0644\u0640 {name}",
96
+ accessDialogHint: "\u0645\u0627 \u064A\u0645\u0643\u0646 \u0644\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647\u060C \u0648\u062D\u062F\u0648\u062F\u0647. \u064A\u0631\u0627\u0647\u0627 \u0645\u0633\u0624\u0648\u0644\u0648\u0647 \u0641\u064A \u0635\u0641\u062D\u0629 \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A \u0644\u0644\u0645\u0634\u0631\u0648\u0639.",
97
+ openAll: "\u0643\u0644 \u0646\u0645\u0648\u0630\u062C \u064A\u0639\u0645\u0644\u060C \u0627\u0644\u0622\u0646 \u0648\u0644\u0627\u062D\u0642\u064B\u0627",
98
+ openSome: "\u0647\u0630\u0647 \u0627\u0644\u0646\u0645\u0627\u0630\u062C",
99
+ noModelsOn: "\u0644\u0627 \u064A\u0648\u062C\u062F \u0646\u0645\u0648\u0630\u062C \u064A\u0639\u0645\u0644 \u0628\u0639\u062F.",
100
+ allowOwn: "\u064A\u0645\u0643\u0646 \u0644\u0645\u0633\u0624\u0648\u0644\u064A\u0647 \u0625\u0636\u0627\u0641\u0629 \u0627\u062A\u0635\u0627\u0644\u0627\u062A \u0646\u0645\u0627\u0630\u062C \u062E\u0627\u0635\u0629 \u0628\u0647",
101
+ projectLimits: "\u062D\u062F\u0648\u062F \u0627\u0644\u0645\u0634\u0631\u0648\u0639",
102
+ projectLimitsHint: "\u062A\u0646\u0637\u0628\u0642 \u0636\u0645\u0646 \u062D\u062F\u0648\u062F \u0627\u0644\u0645\u0648\u0642\u0639: \u064A\u062C\u0628 \u0623\u0646 \u064A\u062A\u0633\u0639 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621 \u0644\u0644\u0627\u062B\u0646\u064A\u0646.",
103
+ siteLimitsTitle: "\u062D\u062F\u0648\u062F \u0627\u0644\u0645\u0648\u0642\u0639",
104
+ siteLimitsHint: "\u062A\u0646\u0637\u0628\u0642 \u0639\u0644\u0649 \u0643\u0644 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u060C \u0628\u0645\u0627 \u0641\u064A \u0630\u0644\u0643 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u0634\u0627\u0631\u064A\u0639. \u064A\u062D\u062C\u0632 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621 \u0645\u0627 \u0642\u062F \u064A\u0646\u0641\u0642\u0647 \u0642\u0628\u0644 \u062A\u0634\u063A\u064A\u0644\u0647\u060C \u0641\u0644\u0627 \u062A\u062A\u062C\u0627\u0648\u0632 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A \u0627\u0644\u0645\u062A\u0632\u0627\u0645\u0646\u0629 \u0627\u0644\u062D\u062F \u0645\u0639\u064B\u0627.",
105
+ limitKind: "\u0627\u0644\u062D\u062F",
106
+ limitPeriod: "\u0644\u0643\u0644",
107
+ limitAmount: "\u0627\u0644\u0645\u0642\u062F\u0627\u0631",
108
+ perReply: "\u0643\u0644 \u0631\u062F",
109
+ removeLimit: "\u0625\u0632\u0627\u0644\u0629 \u0647\u0630\u0627 \u0627\u0644\u062D\u062F",
110
+ noLimits: "\u0644\u0627 \u062D\u062F\u0648\u062F.",
111
+ addLimit: "\u0625\u0636\u0627\u0641\u0629 \u062D\u062F",
112
+ "kinds.cost": "\u0627\u0644\u0643\u0644\u0641\u0629",
113
+ "kinds.tokens": "\u0627\u0644\u0631\u0645\u0648\u0632",
114
+ "kinds.requests": "\u0627\u0644\u0637\u0644\u0628\u0627\u062A",
115
+ "kinds.call-tokens": "\u0627\u0644\u0631\u0645\u0648\u0632 \u0644\u0643\u0644 \u0631\u062F",
116
+ "periods.minute": "\u062F\u0642\u064A\u0642\u0629",
117
+ "periods.day": "\u064A\u0648\u0645",
118
+ "periods.month": "\u0634\u0647\u0631",
119
+ limitText: "{kind} \u0644\u0643\u0644 {period}: {amount}",
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.}}",
123
+ usageTitle: "\u0627\u0644\u0627\u0633\u062A\u062E\u062F\u0627\u0645",
124
+ usageTotal: "\u0627\u0644\u0643\u0644\u0641\u0629 \u0627\u0644\u0625\u062C\u0645\u0627\u0644\u064A\u0629: {cost}",
125
+ by: "\u0627\u0644\u062A\u062C\u0645\u064A\u0639 \u062D\u0633\u0628",
126
+ "byOptions.project": "\u0627\u0644\u0645\u0634\u0631\u0648\u0639",
127
+ "byOptions.model": "\u0627\u0644\u0646\u0645\u0648\u0630\u062C",
128
+ "byOptions.purpose": "\u0627\u0644\u063A\u0631\u0636",
129
+ "byOptions.account": "\u0627\u0644\u0634\u062E\u0635",
130
+ month: "\u0627\u0644\u0634\u0647\u0631",
131
+ noUsage: "\u0644\u0627 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A \u0641\u064A \u0647\u0630\u0627 \u0627\u0644\u0634\u0647\u0631.",
132
+ siteCalls: "\u0627\u0644\u0645\u0648\u0642\u0639 (\u0628\u0644\u0627 \u0645\u0634\u0631\u0648\u0639)",
133
+ calls: "\u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A",
134
+ tokensIn: "\u0631\u0645\u0648\u0632 \u0627\u0644\u0625\u062F\u062E\u0627\u0644",
135
+ tokensOut: "\u0631\u0645\u0648\u0632 \u0627\u0644\u0625\u062E\u0631\u0627\u062C",
136
+ cost: "\u0627\u0644\u0643\u0644\u0641\u0629",
137
+ refused: "\u0645\u0631\u0641\u0648\u0636\u0629",
138
+ failed: "\u0641\u0627\u0634\u0644\u0629",
139
+ recentTitle: "\u0623\u062D\u062F\u062B \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A",
140
+ at: "\u0627\u0644\u0648\u0642\u062A",
141
+ who: "\u0645\u0646",
142
+ purpose: "\u0627\u0644\u063A\u0631\u0636",
143
+ tokens: "\u0627\u0644\u0631\u0645\u0648\u0632 \u0625\u062F\u062E\u0627\u0644 / \u0625\u062E\u0631\u0627\u062C",
144
+ outcome: "\u0627\u0644\u0646\u062A\u064A\u062C\u0629",
145
+ "outcomes.ok": "\u0623\u064F\u062C\u064A\u0628",
146
+ "outcomes.refused": "\u0631\u064F\u0641\u0636",
147
+ "outcomes.failed": "\u0641\u0634\u0644",
148
+ "outcomes.reserved": "\u0642\u064A\u062F \u0627\u0644\u062A\u0634\u063A\u064A\u0644",
149
+ tryTitle: "\u062A\u062C\u0631\u0628\u0629 \u0627\u0633\u0645 \u0645\u0633\u062A\u0639\u0627\u0631",
150
+ tryHint: "\u0627\u0633\u062A\u062F\u0639\u0627\u0621 \u0642\u0635\u064A\u0631 \u0628\u0627\u0633\u0645\u0643\u060C \u0639\u0628\u0631 \u0627\u0644\u0635\u0644\u0627\u062D\u064A\u0627\u062A \u0648\u0627\u0644\u062D\u062F\u0648\u062F \u0646\u0641\u0633\u0647\u0627 \u0644\u0623\u064A \u0627\u0633\u062A\u062F\u0639\u0627\u0621. \u0648\u064A\u064F\u0633\u062C\u064E\u0651\u0644 \u0641\u064A \u0627\u0644\u0633\u062C\u0644.",
151
+ prompt: "\u0627\u0644\u0637\u0644\u0628",
152
+ run: "\u0627\u0633\u0623\u0644",
153
+ answered: "{model} \xB7 {input} \u0631\u0645\u0632 \u0625\u062F\u062E\u0627\u0644\u060C {output} \u0625\u062E\u0631\u0627\u062C \xB7 \u0627\u0644\u0643\u0644\u0641\u0629 {cost}",
154
+ projectSubtitle: "\u0627\u0644\u0646\u0645\u0627\u0630\u062C \u0627\u0644\u062A\u064A \u064A\u0645\u0643\u0646 \u0644\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u0627\u0633\u062A\u062E\u062F\u0627\u0645\u0647\u0627\u060C \u0648\u0623\u0633\u0645\u0627\u0624\u0647 \u0627\u0644\u0645\u0633\u062A\u0639\u0627\u0631\u0629\u060C \u0648\u062D\u062F\u0648\u062F\u0647\u060C \u0648\u0643\u0644\u0641\u0629 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A\u0647.",
155
+ projectAccessTitle: "\u0645\u0627 \u064A\u0633\u0645\u062D \u0628\u0647 \u0627\u0644\u0645\u0648\u0642\u0639",
156
+ projectAccessHint: "\u064A\u0641\u062A\u062D \u0645\u0633\u0624\u0648\u0644 \u0627\u0644\u0645\u0648\u0642\u0639 \u0627\u0644\u0646\u0645\u0627\u0630\u062C \u0644\u0644\u0645\u0634\u0631\u0648\u0639 \u0648\u064A\u062D\u062F\u062F \u062D\u062F\u0648\u062F\u0647.",
157
+ ownAllowed: "\u064A\u0645\u0643\u0646 \u0644\u0645\u0633\u0624\u0648\u0644\u064A\u0647 \u0625\u0636\u0627\u0641\u0629 \u0627\u062A\u0635\u0627\u0644\u0627\u062A \u0646\u0645\u0627\u0630\u062C \u062E\u0627\u0635\u0629 \u0628\u0647 (\u0625\u0639\u062F\u0627\u062F\u0627\u062A \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u203A \u0627\u0644\u0627\u062A\u0635\u0627\u0644\u0627\u062A).",
158
+ ownNotAllowed: "\u0644\u0627 \u064A\u0645\u0643\u0646\u0647 \u0627\u0633\u062A\u062E\u062F\u0627\u0645 \u0627\u062A\u0635\u0627\u0644\u0627\u062A \u0646\u0645\u0627\u0630\u062C \u062E\u0627\u0635\u0629 \u0628\u0647.",
159
+ projectModelsTitle: "\u0627\u0644\u0646\u0645\u0627\u0630\u062C \u0627\u0644\u0645\u062A\u0627\u062D\u0629 \u0644\u0647",
160
+ projectModelsHint: "\u0646\u0645\u0627\u0630\u062C \u0627\u0644\u0645\u0648\u0642\u0639 \u0627\u0644\u0645\u0641\u062A\u0648\u062D\u0629 \u0644\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639.",
161
+ projectModelsOwnHint: "\u0646\u0645\u0627\u0630\u062C \u0627\u0644\u0645\u0648\u0642\u0639 \u0627\u0644\u0645\u0641\u062A\u0648\u062D\u0629 \u0644\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639\u060C \u0648\u0646\u0645\u0627\u0630\u062C \u0627\u062A\u0635\u0627\u0644\u0627\u062A\u0647 \u0627\u0644\u062E\u0627\u0635\u0629 \u0627\u0644\u062A\u064A \u062A\u0634\u063A\u0651\u0644\u0647\u0627 \u0648\u062A\u0633\u0639\u0651\u0631\u0647\u0627 \u0647\u0646\u0627.",
162
+ projectLimitsReadHint: "\u064A\u062D\u062F\u062F\u0647\u0627 \u0645\u0633\u0624\u0648\u0644\u0648 \u0627\u0644\u0645\u0648\u0642\u0639. \u064A\u062C\u0628 \u0623\u0646 \u064A\u062A\u0633\u0639 \u0627\u0644\u0627\u0633\u062A\u062F\u0639\u0627\u0621 \u0644\u062D\u062F\u0648\u062F \u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639 \u0648\u062D\u062F\u0648\u062F \u0627\u0644\u0645\u0648\u0642\u0639.",
163
+ thisProject: "\u0647\u0630\u0627 \u0627\u0644\u0645\u0634\u0631\u0648\u0639",
164
+ theSite: "\u0627\u0644\u0645\u0648\u0642\u0639",
165
+ allowOwnSkills: "\u064A\u0645\u0643\u0646 \u0644\u0645\u0633\u0624\u0648\u0644\u064A\u0647 \u0627\u0633\u062A\u062E\u062F\u0627\u0645 \u0645\u0633\u062A\u0648\u062F\u0639 \u0645\u0647\u0627\u0631\u0627\u062A \u062E\u0627\u0635 \u0628\u0647\u0645",
166
+ ownSkills: "\u0645\u0647\u0627\u0631\u0627\u062A \u062E\u0627\u0635\u0629",
167
+ exportsTitle: "\u062A\u0635\u062F\u064A\u0631 \u0644\u0644\u062F\u0639\u0645",
168
+ exportsHint: "\u0627\u0633\u062A\u062F\u0639\u0627\u0621\u0627\u062A \u0627\u0644\u0630\u0643\u0627\u0621 \u0627\u0644\u0627\u0635\u0637\u0646\u0627\u0639\u064A \u0641\u064A \u0645\u062F\u0629 \u0645\u0627\u060C \u0644\u0625\u0631\u0633\u0627\u0644\u0647\u0627 \u0625\u0644\u0649 \u0627\u0644\u062F\u0639\u0645 \u062D\u064A\u0646 \u062A\u062E\u0637\u0626 \u0627\u0644\u0625\u062C\u0627\u0628\u0627\u062A: \u0633\u0637\u0631 \u0644\u0643\u0644 \u0627\u0633\u062A\u062F\u0639\u0627\u0621\u060C \u0645\u0639 \u0637\u0644\u0628\u0647 \u0648\u0631\u062F\u0651\u0647 \u062D\u064A\u062B \u064A\u062D\u062A\u0641\u0638 \u0628\u0647\u0645\u0627 \u0647\u0630\u0627 \u0627\u0644\u0645\u0648\u0642\u0639. \u0633\u062A\u064F\u0633\u0623\u0644 \u0639\u0646 \u0643\u0644\u0645\u0629 \u0645\u0631\u0648\u0631\u0643\u060C \u0648\u064A\u064F\u0633\u062C\u064E\u0651\u0644 \u0630\u0644\u0643 \u0641\u064A \u0633\u062C\u0644 \u0627\u0644\u0623\u0645\u0627\u0646\u060C \u0648\u064A\u064F\u062D\u0630\u0641 \u0643\u0644 \u062A\u0635\u062F\u064A\u0631 \u0628\u0639\u062F \u0623\u0633\u0628\u0648\u0639.",
169
+ exportFrom: "\u0645\u0646",
170
+ exportTo: "\u0625\u0644\u0649",
171
+ exportCreate: "\u062A\u0635\u062F\u064A\u0631",
172
+ exportPeriodHint: "\u064A\u063A\u0637\u064A \u0627\u0644\u062A\u0635\u062F\u064A\u0631 \u0645\u0646 \u064A\u0648\u0645 \u0625\u0644\u0649 31 \u064A\u0648\u0645\u064B\u0627.",
173
+ noExports: "\u0644\u0627 \u064A\u0648\u062C\u062F \u062A\u0635\u062F\u064A\u0631 \u0645\u062D\u0641\u0648\u0638.",
174
+ exportPeriod: "\u0627\u0644\u0645\u062F\u0629",
175
+ exportPrompts: "{count, plural, =0 {\u0628\u0644\u0627 \u0637\u0644\u0628\u0627\u062A} one {# \u0645\u0639 \u0637\u0644\u0628\u0647} other {# \u0645\u0639 \u0637\u0644\u0628\u0627\u062A\u0647\u0627}}",
176
+ exportTruncated: "\u062A\u0648\u0642\u0651\u0641 \u0639\u0646\u062F \u0623\u0642\u0635\u0649 \u0645\u0627 \u064A\u062A\u0651\u0633\u0639 \u0644\u0647 \u0627\u0644\u062A\u0635\u062F\u064A\u0631",
177
+ exportMade: "\u0623\u064F\u0646\u0634\u0626",
178
+ exportExpires: "\u064A\u064F\u062D\u0630\u0641",
179
+ exportDownload: "\u062A\u0646\u0632\u064A\u0644",
180
+ exportDelete: "\u062D\u0630\u0641",
181
+ exportDeleteTitle: "\u0623\u062A\u062D\u0630\u0641 \u0647\u0630\u0627 \u0627\u0644\u062A\u0635\u062F\u064A\u0631\u061F",
182
+ 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.",
183
+ callThrough: "\u0639\u0628\u0631 {name}"
184
+ };
185
+
186
+ // src/areas/ai/texts/en.json
187
+ var en_default = {
188
+ pageTitle: "AI",
189
+ pageSubtitle: "The models {product} may call, the aliases skills and steps name, what each project may use, limits, and what it all costs. Providers are connections.",
190
+ "tabs.models": "Models",
191
+ "tabs.aliases": "Aliases",
192
+ "tabs.access": "Projects",
193
+ "tabs.limits": "Limits",
194
+ "tabs.usage": "Usage",
195
+ "tabs.try": "Try",
196
+ "tabs.exports": "Exports",
197
+ modelsTitle: "Models",
198
+ modelsHint: "Each provider connection's models, found by asking it. A model is off until you turn it on; give it prices so limits can be in money.",
199
+ noProviders: "No model provider is connected yet. Add an Anthropic or OpenAI-compatible connection under Administration \u203A Connections.",
200
+ connection: "Connection",
201
+ findModels: "Find its models",
202
+ found: "{name} offers {count, plural, one {# model} other {# models}}.",
203
+ noModels: "No models yet.",
204
+ noModelsFind: "No models yet. Find a connection's models to start.",
205
+ model: "Model",
206
+ can: "What it can do",
207
+ tools: "Tools",
208
+ images: "Images",
209
+ structured: "Structured answers",
210
+ toolsLong: "Calls tools",
211
+ imagesLong: "Reads images",
212
+ structuredLong: "Answers in a given JSON shape",
213
+ prices: "Prices",
214
+ price: "{input} in, {output} out, per million tokens",
215
+ noPrice: "No price: its calls count as free",
216
+ priceSetAt: "Set {at}",
217
+ state: "State",
218
+ on: "On",
219
+ off: "Off",
220
+ edit: "Edit",
221
+ editModel: "Model {name}",
222
+ modelOn: "On: aliases may name it and projects may be given it",
223
+ name: "Name",
224
+ nameHint: "What people see; its id unless you rename it.",
225
+ context: "Context size (tokens)",
226
+ optional: "(optional)",
227
+ inputPrice: "Input price",
228
+ outputPrice: "Output price",
229
+ perMillion: "Per million tokens, in the site's currency.",
230
+ save: "Save",
231
+ saved: "Saved.",
232
+ aliasesTitle: "Aliases",
233
+ aliasesHint: "What skills and workflow steps name, such as fast or smart. Pointing an alias at another model changes every use at once.",
234
+ aliasesProjectHint: "This project's own aliases come first; the site's fill in the rest. Each names a model the project may use.",
235
+ alias: "Alias",
236
+ pickModel: "Choose a model\u2026",
237
+ removeAlias: "Remove alias {name}",
238
+ noAliases: "No aliases of its own.",
239
+ addAlias: "Add an alias",
240
+ noUsable: "No model is on and open here yet.",
241
+ fromSite: "From the site",
242
+ notOpenHere: "not open to this project, so it doesn't answer here",
243
+ accessTitle: "What each project may use",
244
+ accessHint: "A project uses no model until you open some to it. You can also let its admins add connections of their own, and give it limits inside the site's.",
245
+ findProject: "Find a project",
246
+ noProjects: "No projects.",
247
+ project: "Project",
248
+ opened: "Models",
249
+ allModels: "Every model that's on",
250
+ someModels: "{count, plural, one {# model} other {# models}}",
251
+ noModelsOpen: "None",
252
+ ownConnections: "Own connections",
253
+ allowed: "Allowed",
254
+ notAllowed: "Not allowed",
255
+ accessFor: "AI for {name}",
256
+ accessDialogHint: "What this project may use, and its limits. Its admins see these on the project's AI page.",
257
+ openAll: "Every model that's on, now and later",
258
+ openSome: "These models",
259
+ noModelsOn: "No model is on yet.",
260
+ allowOwn: "Its admins may add model connections of their own",
261
+ projectLimits: "The project's limits",
262
+ projectLimitsHint: "They apply inside the site's: a call has to fit both.",
263
+ siteLimitsTitle: "The site's limits",
264
+ siteLimitsHint: "They apply to every call, a project's included. A call reserves what it may spend before it runs, so calls at once can't go over together.",
265
+ limitKind: "Limit",
266
+ limitPeriod: "Per",
267
+ limitAmount: "Amount",
268
+ perReply: "Each reply",
269
+ removeLimit: "Remove this limit",
270
+ noLimits: "No limits.",
271
+ addLimit: "Add a limit",
272
+ "kinds.cost": "Cost",
273
+ "kinds.tokens": "Tokens",
274
+ "kinds.requests": "Requests",
275
+ "kinds.call-tokens": "Tokens per reply",
276
+ "periods.minute": "minute",
277
+ "periods.day": "day",
278
+ "periods.month": "month",
279
+ limitText: "{kind} per {period}: {amount}",
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.}}",
283
+ usageTitle: "Usage",
284
+ usageTotal: "Total cost: {cost}",
285
+ by: "Sum by",
286
+ "byOptions.project": "Project",
287
+ "byOptions.model": "Model",
288
+ "byOptions.purpose": "Purpose",
289
+ "byOptions.account": "Person",
290
+ month: "Month",
291
+ noUsage: "No calls in this month.",
292
+ siteCalls: "The site (no project)",
293
+ calls: "Calls",
294
+ tokensIn: "Tokens in",
295
+ tokensOut: "Tokens out",
296
+ cost: "Cost",
297
+ refused: "Refused",
298
+ failed: "Failed",
299
+ recentTitle: "Latest calls",
300
+ at: "When",
301
+ who: "Who",
302
+ purpose: "Purpose",
303
+ tokens: "Tokens in / out",
304
+ outcome: "Outcome",
305
+ "outcomes.ok": "Answered",
306
+ "outcomes.refused": "Refused",
307
+ "outcomes.failed": "Failed",
308
+ "outcomes.reserved": "Running",
309
+ tryTitle: "Try an alias",
310
+ tryHint: "A short call as you, through the same access and limits as any call. It's on the ledger.",
311
+ prompt: "Prompt",
312
+ run: "Ask",
313
+ answered: "{model} \xB7 {input} tokens in, {output} out \xB7 cost {cost}",
314
+ projectSubtitle: "The models this project may use, its aliases, its limits and what its calls cost.",
315
+ projectAccessTitle: "What the site allows",
316
+ projectAccessHint: "A site admin opens models to the project and sets its limits.",
317
+ ownAllowed: "Its admins may add model connections of their own (Project settings \u203A Connections).",
318
+ ownNotAllowed: "It may not use model connections of its own.",
319
+ projectModelsTitle: "Models it may use",
320
+ projectModelsHint: "The site's models opened to this project.",
321
+ projectModelsOwnHint: "The site's models opened to this project, and its own connections' models, which you turn on and price here.",
322
+ projectLimitsReadHint: "Set by site admins. A call has to fit this project's limits and the site's.",
323
+ thisProject: "This project",
324
+ theSite: "The site",
325
+ allowOwnSkills: "Its admins may use a skills repository of their own",
326
+ ownSkills: "Own skills",
327
+ exportsTitle: "Exports for support",
328
+ exportsHint: "A period's AI calls, to send to support when answers go wrong: one line each, with its prompt and reply where this site keeps them. You'll be asked for your password, it's in the security log, and each export is deleted after a week.",
329
+ exportFrom: "From",
330
+ exportTo: "To",
331
+ exportCreate: "Export",
332
+ exportPeriodHint: "An export covers 1 to 31 days.",
333
+ noExports: "No exports kept.",
334
+ exportPeriod: "Period",
335
+ exportPrompts: "{count, plural, =0 {no prompts} one {# with its prompt} other {# with their prompts}}",
336
+ exportTruncated: "Stopped at the most one export holds",
337
+ exportMade: "Made",
338
+ exportExpires: "Deleted",
339
+ exportDownload: "Download",
340
+ exportDelete: "Delete",
341
+ exportDeleteTitle: "Delete this export?",
342
+ exportDeleteHint: "Its file goes now, before its week is up.",
343
+ callThrough: "through {name}"
344
+ };
345
+
346
+ // src/areas/ai/texts.ts
347
+ var useAiTexts = createAreaTexts("ai", { en: en_default, ar: ar_default });
348
+
349
+ // src/areas/ai/types.ts
350
+ var num = (value) => value == null || value === "" ? 0 : typeof value === "number" ? value : Number(value);
351
+ var scopeQuery = (scopeId, joiner = "?") => scopeId ? `${joiner}scopeId=${encodeURIComponent(scopeId)}` : "";
352
+
353
+ // src/areas/ai/LimitsEditor.tsx
354
+ import { jsx, jsxs } from "react/jsx-runtime";
355
+ var LIMIT_KINDS = ["cost", "tokens", "requests", "call-tokens"];
356
+ var LIMIT_PERIODS = ["minute", "day", "month"];
357
+ var editableLimit = (l) => (l.kind === "total" || l.kind === "call-tokens") && !l.accountId && !l.groupId;
358
+ var limitRow = (l) => l.kind === "call-tokens" ? { kind: "call-tokens", period: "", amount: String(num(l.amount)) } : { kind: l.measure ?? "cost", period: l.period || "day", amount: String(num(l.amount)) };
359
+ var limitInput = (r) => r.kind === "call-tokens" ? { kind: "call-tokens", period: "", measure: "tokens", amount: Number(r.amount || 0) } : { kind: "total", period: r.period || "day", measure: r.kind, amount: Number(r.amount || 0) };
360
+ async function saveLimits(request, scopeId, before, rows) {
361
+ const same = (a, b) => a.kind === b.kind && a.period === b.period && Number(a.amount || 0) === Number(b.amount || 0);
362
+ const left = [...rows];
363
+ const gone = [];
364
+ for (const l of before.filter(editableLimit)) {
365
+ const i = left.findIndex((r) => same(r, limitRow(l)));
366
+ if (i >= 0) left.splice(i, 1);
367
+ else gone.push(l);
368
+ }
369
+ for (const l of gone) await request(`/limits/${encodeURIComponent(l.id)}`, { method: "DELETE" });
370
+ for (const r of left) await request(`/limits${scopeQuery(scopeId)}`, { method: "POST", body: limitInput(r) });
371
+ }
372
+ function useLimitText() {
373
+ const t = useAiTexts();
374
+ const fmt = useFormatters();
375
+ return (l) => {
376
+ const r = limitRow(l);
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);
380
+ };
381
+ }
382
+ var namedLimit = (l) => !!l.accountId || !!l.groupId || l.kind === "account" || l.kind === "group";
383
+ function LimitsEditor({ limits, onSave, onChange, busy, error }) {
384
+ const t = useAiTexts();
385
+ const [draft, setDraftRows] = useState(null);
386
+ const rows = draft ?? limits.filter(editableLimit).map(limitRow);
387
+ const kinds = LIMIT_KINDS.map((k) => ({ value: k, label: t(`kinds.${k}`) }));
388
+ const periods = LIMIT_PERIODS.map((p) => ({ value: p, label: t(`periods.${p}`) }));
389
+ const setDraft = (next) => {
390
+ setDraftRows(next);
391
+ onChange?.(next);
392
+ };
393
+ const set = (i, change) => setDraft(rows.map((x, j) => j === i ? { ...x, ...change } : x));
394
+ async function save() {
395
+ if (!onSave) return;
396
+ await onSave(rows);
397
+ setDraftRows(null);
398
+ }
399
+ return /* @__PURE__ */ jsxs(Stack, { gap: "3", "data-testid": "ai-limits", children: [
400
+ /* @__PURE__ */ jsx(InlineAlert, { tone: "danger", children: error }),
401
+ rows.map((r, i) => /* @__PURE__ */ jsxs(HStack, { gap: "2", alignItems: "end", children: [
402
+ /* @__PURE__ */ jsx(Field, { label: i === 0 ? t("limitKind") : void 0, flex: "2", children: /* @__PURE__ */ jsx(
403
+ SelectField,
404
+ {
405
+ value: r.kind,
406
+ options: kinds,
407
+ "aria-label": t("limitKind"),
408
+ onChange: (e) => set(i, { kind: e.target.value, period: e.target.value === "call-tokens" ? "" : r.period || "day" })
409
+ }
410
+ ) }),
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 }) }) }),
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 }) }) }),
413
+ /* @__PURE__ */ jsx(IconButton, { "aria-label": t("removeLimit"), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx(Trash2, {}) })
414
+ ] }, i)),
415
+ rows.length === 0 && /* @__PURE__ */ jsx(Text, { textStyle: "sm", color: "fg.muted", children: t("noLimits") }),
416
+ /* @__PURE__ */ jsxs(HStack, { children: [
417
+ /* @__PURE__ */ jsx(Button, { size: "sm", variant: "secondary", onClick: () => setDraft([...rows, { kind: "cost", period: "day", amount: "" }]), children: t("addLimit") }),
418
+ onSave && /* @__PURE__ */ jsx(Button, { size: "sm", loading: busy, disabled: draft === null, onClick: () => void save(), children: t("save") })
419
+ ] })
420
+ ] });
421
+ }
422
+
423
+ // src/areas/ai/models.ts
424
+ var modelKey = (connectionId, model) => `${connectionId}:${model ?? ""}`;
425
+ function modelRows(connections) {
426
+ return connections.flatMap(
427
+ (c) => c.models.map((model) => {
428
+ const settings = c.modelSettings?.[model] ?? {};
429
+ const price = c.modelPrices?.[model];
430
+ const input = price ? num(price.input) : num(c.inputPrice);
431
+ const output = price ? num(price.output) : num(c.outputPrice);
432
+ const priced = input !== 0 || output !== 0;
433
+ return {
434
+ key: modelKey(c.id, model),
435
+ connectionId: c.id,
436
+ connection: c.name,
437
+ scopeId: c.scopeId ?? null,
438
+ modelId: model,
439
+ name: settings.name || model,
440
+ enabled: settings.enabled ?? true,
441
+ tools: settings.tools ?? true,
442
+ images: settings.images ?? false,
443
+ structuredOutput: settings.structuredOutput ?? c.structuredOutput,
444
+ contextTokens: settings.contextTokens == null ? null : num(settings.contextTokens),
445
+ inputPrice: priced ? input : null,
446
+ outputPrice: priced ? output : null,
447
+ priceSetAt: settings.priceSetAt ?? null
448
+ };
449
+ })
450
+ );
451
+ }
452
+ function scopeModelRows(view) {
453
+ return view.models.map((m) => {
454
+ const s = m.settings ?? {};
455
+ const input = num(m.price?.input);
456
+ const output = num(m.price?.output);
457
+ const priced = input !== 0 || output !== 0;
458
+ return {
459
+ key: modelKey(m.connectionId, m.model),
460
+ connectionId: m.connectionId,
461
+ connection: m.connection,
462
+ scopeId: m.setOnScopeId ?? null,
463
+ modelId: m.model,
464
+ name: s.name || m.model,
465
+ enabled: s.enabled ?? true,
466
+ tools: s.tools ?? true,
467
+ images: s.images ?? false,
468
+ structuredOutput: s.structuredOutput ?? false,
469
+ contextTokens: s.contextTokens == null ? null : num(s.contextTokens),
470
+ inputPrice: priced ? input : null,
471
+ outputPrice: priced ? output : null,
472
+ priceSetAt: s.priceSetAt ?? null,
473
+ own: m.own
474
+ };
475
+ });
476
+ }
477
+ function withModel(c, model, settings, price) {
478
+ const modelPrices = { ...c.modelPrices ?? {} };
479
+ if (price) modelPrices[model] = { ...modelPrices[model], input: price.input, output: price.output };
480
+ else delete modelPrices[model];
481
+ return {
482
+ name: c.name,
483
+ provider: c.provider,
484
+ models: c.models,
485
+ dataClasses: c.dataClasses,
486
+ modelSettings: { ...c.modelSettings ?? {}, [model]: settings },
487
+ endpoint: c.endpoint,
488
+ labels: c.labels,
489
+ settings: c.settings,
490
+ inputPrice: c.inputPrice,
491
+ outputPrice: c.outputPrice,
492
+ modelPrices,
493
+ structuredOutput: c.structuredOutput,
494
+ enabled: c.enabled,
495
+ cacheWritePrice: c.cacheWritePrice,
496
+ cacheReadPrice: c.cacheReadPrice
497
+ };
498
+ }
499
+
500
+ // src/areas/ai/AccessPanel.tsx
501
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
502
+ function useAllScopes() {
503
+ const host = useHost();
504
+ const [scopes, setScopes] = useState2(void 0);
505
+ const [error, setError] = useState2(null);
506
+ useEffect(() => {
507
+ let alive = true;
508
+ if (!host.scopes) {
509
+ setScopes([]);
510
+ return;
511
+ }
512
+ host.scopes.search("").then((found) => alive && setScopes(found), (e) => alive && setError(e instanceof Error ? e.message : String(e)));
513
+ return () => {
514
+ alive = false;
515
+ };
516
+ }, [host]);
517
+ return { scopes, error };
518
+ }
519
+ function AccessPanel({ models }) {
520
+ const t = useAiTexts();
521
+ const list = useApiQuery("ai", "/scopes/access");
522
+ const { scopes, error: scopesError } = useAllScopes();
523
+ const extraCell = Boolean(useOptionalHost()?.slots?.["ai.access.cell"]);
524
+ const [search, setSearch] = useState2("");
525
+ const [editing, setEditing] = useState2(null);
526
+ const unnamed = useMemo(() => (list.data ?? []).map((a) => a.scopeId).filter((id) => !(scopes ?? []).some((s) => s.id === id)), [list.data, scopes]);
527
+ const names = useNames("scopes", unnamed);
528
+ const rows = useMemo(() => {
529
+ if (!list.data || !scopes) return void 0;
530
+ const access = new Map(list.data.map((a) => [a.scopeId, a]));
531
+ const listed = scopes.map((s) => ({ scopeId: s.id, name: s.name, code: s.code, access: access.get(s.id) }));
532
+ const more = unnamed.map((id) => ({ scopeId: id, name: names[id] ?? id, access: access.get(id) }));
533
+ return [...listed, ...more];
534
+ }, [list.data, scopes, unnamed, names]);
535
+ const { counts, refresh } = useLimitCounts(useMemo(() => (rows ?? []).map((r) => r.scopeId), [rows]));
536
+ const fmt = useFormatters2();
537
+ const needle = search.trim().toLowerCase();
538
+ const shown = rows?.filter((p) => !needle || `${p.name} ${p.code ?? ""}`.toLowerCase().includes(needle));
539
+ const opened = (a) => a?.allSiteModels ? t("allModels") : a?.siteModels.length ? t("someModels", { count: a.siteModels.length }) : t("noModelsOpen");
540
+ return /* @__PURE__ */ jsxs2(
541
+ Panel,
542
+ {
543
+ title: t("accessTitle"),
544
+ description: t("accessHint"),
545
+ flush: true,
546
+ "data-testid": "ai-access",
547
+ actions: /* @__PURE__ */ jsx2(SearchInput, { size: "sm", value: search, onChange: (e) => setSearch(e.target.value), placeholder: t("findProject"), "aria-label": t("findProject") }),
548
+ children: [
549
+ /* @__PURE__ */ jsx2(InlineAlert2, { tone: "danger", children: list.error ?? scopesError }),
550
+ /* @__PURE__ */ jsx2(
551
+ DataTable,
552
+ {
553
+ "aria-label": t("accessTitle"),
554
+ rows: shown,
555
+ loading: list.loading || scopes === void 0,
556
+ getRowId: (p) => p.scopeId,
557
+ empty: t("noProjects"),
558
+ columns: [
559
+ {
560
+ id: "project",
561
+ header: t("project"),
562
+ cell: (p) => /* @__PURE__ */ jsxs2(Stack2, { gap: "0", children: [
563
+ /* @__PURE__ */ jsx2(Text2, { fontWeight: "medium", children: p.name }),
564
+ p.code && /* @__PURE__ */ jsx2(Text2, { textStyle: "caption", color: "fg.muted", dir: "ltr", children: p.code })
565
+ ] })
566
+ },
567
+ {
568
+ id: "models",
569
+ header: t("opened"),
570
+ cell: (p) => /* @__PURE__ */ jsx2(StatusPill, { tone: p.access?.allSiteModels || p.access?.siteModels.length ? "success" : "neutral", children: opened(p.access) })
571
+ },
572
+ { id: "own", header: t("ownConnections"), cell: (p) => p.access?.mayConnect ? t("allowed") : t("notAllowed") },
573
+ ...extraCell ? [{ id: "host", header: t("ownSkills"), cell: (p) => /* @__PURE__ */ jsx2(HostSlot, { name: "ai.access.cell", context: { scopeId: p.scopeId } }) }] : [],
574
+ { id: "limits", header: t("tabs.limits"), numeric: true, cell: (p) => counts[p.scopeId] === void 0 ? "" : fmt.number(counts[p.scopeId]) },
575
+ { 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") }) }
576
+ ]
577
+ }
578
+ ),
579
+ editing && /* @__PURE__ */ jsx2(AccessEditor, { scope: editing, models, onClose: () => setEditing(null), onSaved: async () => {
580
+ refresh(editing.scopeId);
581
+ setEditing(null);
582
+ await list.reload();
583
+ } })
584
+ ]
585
+ }
586
+ );
587
+ }
588
+ function useLimitCounts(scopeIds) {
589
+ const request = useAreaRequest("ai");
590
+ const asked = useRef(/* @__PURE__ */ new Set());
591
+ const [counts, setCounts] = useState2({});
592
+ const [round, setRound] = useState2(0);
593
+ const key = scopeIds.join(",");
594
+ useEffect(() => {
595
+ const wanted = (key ? key.split(",") : []).filter((id) => !asked.current.has(id));
596
+ wanted.forEach((id) => asked.current.add(id));
597
+ void (async () => {
598
+ for (let i = 0; i < wanted.length; i += 4) {
599
+ const found = await Promise.all(wanted.slice(i, i + 4).map(async (id) => {
600
+ try {
601
+ return [id, (await request(`/limits${scopeQuery(id)}`)).length];
602
+ } catch {
603
+ asked.current.delete(id);
604
+ return null;
605
+ }
606
+ }));
607
+ setCounts((c) => ({ ...c, ...Object.fromEntries(found.filter((f) => f !== null)) }));
608
+ }
609
+ })();
610
+ }, [key, request, round]);
611
+ const refresh = useCallback((scopeId) => {
612
+ asked.current.delete(scopeId);
613
+ setRound((r) => r + 1);
614
+ }, []);
615
+ return { counts, refresh };
616
+ }
617
+ function AccessEditor({ scope, models, onClose, onSaved }) {
618
+ const t = useAiTexts();
619
+ const request = useAreaRequest("ai");
620
+ const action = useApiAction();
621
+ const slots = useSlotSaves();
622
+ const limits = useApiQuery("ai", `/limits${scopeQuery(scope.scopeId)}`);
623
+ const usable = models.filter((m) => m.enabled);
624
+ const [all, setAll] = useState2(scope.access?.allSiteModels ?? false);
625
+ const [picked, setPicked] = useState2((scope.access?.siteModels ?? []).map((m) => modelKey(m.connectionId, m.model)));
626
+ const [own, setOwn] = useState2(scope.access?.mayConnect ?? false);
627
+ const [nextLimits, setNextLimits] = useState2(null);
628
+ async function save() {
629
+ const done = await action.run(async () => {
630
+ const body = {
631
+ allSiteModels: all,
632
+ siteModels: all ? [] : usable.filter((m) => picked.includes(m.key)).map((m) => ({ connectionId: m.connectionId, model: m.modelId })),
633
+ mayConnect: own
634
+ };
635
+ await request(`/scopes/${encodeURIComponent(scope.scopeId)}/access`, { method: "PUT", body });
636
+ if (nextLimits && limits.data) await saveLimits(request, scope.scopeId, limits.data, nextLimits);
637
+ await slots.run();
638
+ return true;
639
+ });
640
+ if (done) {
641
+ notify.success(t("saved"));
642
+ await onSaved();
643
+ }
644
+ }
645
+ return /* @__PURE__ */ jsxs2(
646
+ FormDialog,
647
+ {
648
+ open: true,
649
+ onOpenChange: (open) => !open && onClose(),
650
+ title: t("accessFor", { name: scope.name }),
651
+ description: t("accessDialogHint"),
652
+ submitLabel: t("save"),
653
+ onSubmit: save,
654
+ busy: action.busy,
655
+ error: action.error,
656
+ size: "lg",
657
+ children: [
658
+ /* @__PURE__ */ jsx2(SwitchField, { label: t("openAll"), checked: all, onCheckedChange: setAll }),
659
+ !all && /* @__PURE__ */ jsxs2(Stack2, { gap: "1.5", role: "group", "aria-labelledby": "ai-access-models", children: [
660
+ /* @__PURE__ */ jsx2(Text2, { id: "ai-access-models", textStyle: "sm", fontWeight: "medium", children: t("openSome") }),
661
+ usable.map((m) => /* @__PURE__ */ jsx2(
662
+ CheckboxField,
663
+ {
664
+ label: `${m.name} \xB7 ${m.connection}`,
665
+ checked: picked.includes(m.key),
666
+ onCheckedChange: (c) => setPicked(c ? [...picked, m.key] : picked.filter((x) => x !== m.key))
667
+ },
668
+ m.key
669
+ )),
670
+ usable.length === 0 && /* @__PURE__ */ jsx2(Text2, { textStyle: "sm", color: "fg.muted", children: t("noModelsOn") })
671
+ ] }),
672
+ /* @__PURE__ */ jsx2(SwitchField, { label: t("allowOwn"), checked: own, onCheckedChange: setOwn }),
673
+ /* @__PURE__ */ jsx2(HostSlot, { name: "ai.access.editor", context: { scopeId: scope.scopeId, register: slots.register } }),
674
+ /* @__PURE__ */ jsxs2(Stack2, { gap: "2", children: [
675
+ /* @__PURE__ */ jsx2(Text2, { textStyle: "sm", fontWeight: "medium", children: t("projectLimits") }),
676
+ /* @__PURE__ */ jsx2(Text2, { textStyle: "sm", color: "fg.muted", children: t("projectLimitsHint") }),
677
+ limits.data && /* @__PURE__ */ jsx2(LimitsEditor, { limits: limits.data, onChange: setNextLimits, error: limits.error })
678
+ ] })
679
+ ]
680
+ }
681
+ );
682
+ }
683
+
684
+ // src/areas/ai/AliasesPanel.tsx
685
+ import { useMemo as useMemo2, useState as useState3 } from "react";
686
+ import { HStack as HStack2, Input as Input2, Stack as Stack3, Text as Text3 } from "@chakra-ui/react";
687
+ import { Trash2 as Trash22 } from "lucide-react";
688
+ 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";
689
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
690
+ var target = (key) => {
691
+ const at = key.indexOf(":");
692
+ const model = key.slice(at + 1);
693
+ return { connectionId: key.slice(0, at), model: model || null };
694
+ };
695
+ function AliasesPanel({ scopeId, aliases, inherited, models, onSaved }) {
696
+ const t = useAiTexts();
697
+ const request = useAreaRequest2("ai");
698
+ const action = useApiAction2();
699
+ const own = useMemo2(
700
+ () => (aliases ?? []).map((a) => ({ name: a.name, key: a.targets[0] ? modelKey(a.targets[0].connectionId, a.targets[0].model) : "", rest: a.targets.slice(1) })),
701
+ [aliases]
702
+ );
703
+ const [draft, setDraft] = useState3(null);
704
+ const rows = draft ?? own;
705
+ const usable = models.filter((m) => m.enabled);
706
+ const label = (key) => usable.find((m) => m.key === key) ?? models.find((m) => m.key === key);
707
+ const options = [{ value: "", label: t("pickModel") }, ...usable.map((m) => ({ value: m.key, label: `${m.name} \xB7 ${m.connection}` }))];
708
+ const shownInherited = (inherited ?? []).filter((a) => !rows.some((r) => r.name.trim().toLowerCase() === a.name));
709
+ async function save() {
710
+ const next = rows.map((r) => ({ ...r, name: r.name.trim().toLowerCase() }));
711
+ const done = await action.run(async () => {
712
+ for (const a of own) {
713
+ if (!next.some((r) => r.name === a.name)) await request(`/aliases/${encodeURIComponent(a.name)}${scopeQuery(scopeId)}`, { method: "DELETE" });
714
+ }
715
+ for (const r of next) {
716
+ const before = own.find((a) => a.name === r.name);
717
+ if (before && before.key === r.key) continue;
718
+ await request(`/aliases/${encodeURIComponent(r.name)}${scopeQuery(scopeId)}`, { method: "PUT", body: [target(r.key), ...r.rest] });
719
+ }
720
+ return true;
721
+ });
722
+ if (done) {
723
+ notify2.success(t("saved"));
724
+ setDraft(null);
725
+ await onSaved();
726
+ }
727
+ }
728
+ return /* @__PURE__ */ jsx3(
729
+ Panel2,
730
+ {
731
+ title: t("aliasesTitle"),
732
+ description: scopeId ? t("aliasesProjectHint") : t("aliasesHint"),
733
+ "data-testid": "ai-aliases",
734
+ actions: /* @__PURE__ */ jsx3(Button3, { size: "sm", onClick: () => void save(), loading: action.busy, disabled: draft === null, children: t("save") }),
735
+ children: /* @__PURE__ */ jsxs3(Stack3, { gap: "3", children: [
736
+ /* @__PURE__ */ jsx3(InlineAlert3, { tone: "danger", children: action.error }),
737
+ rows.map((r, i) => /* @__PURE__ */ jsxs3(HStack2, { gap: "2", alignItems: "end", children: [
738
+ /* @__PURE__ */ jsx3(Field2, { label: i === 0 ? t("alias") : void 0, flex: "1", children: /* @__PURE__ */ jsx3(
739
+ Input2,
740
+ {
741
+ value: r.name,
742
+ dir: "ltr",
743
+ maxLength: 40,
744
+ placeholder: "fast",
745
+ "aria-label": t("alias"),
746
+ onChange: (e) => setDraft(rows.map((x, j) => j === i ? { ...x, name: e.target.value } : x))
747
+ }
748
+ ) }),
749
+ /* @__PURE__ */ jsx3(Field2, { label: i === 0 ? t("model") : void 0, flex: "2", children: /* @__PURE__ */ jsx3(
750
+ SelectField2,
751
+ {
752
+ value: r.key,
753
+ options,
754
+ "aria-label": t("model"),
755
+ onChange: (e) => setDraft(rows.map((x, j) => j === i ? { ...x, key: e.target.value } : x))
756
+ }
757
+ ) }),
758
+ /* @__PURE__ */ jsx3(IconButton2, { "aria-label": t("removeAlias", { name: r.name || "\u2026" }), size: "sm", onClick: () => setDraft(rows.filter((_, j) => j !== i)), children: /* @__PURE__ */ jsx3(Trash22, {}) })
759
+ ] }, i)),
760
+ rows.length === 0 && /* @__PURE__ */ jsx3(Text3, { textStyle: "sm", color: "fg.muted", children: t("noAliases") }),
761
+ /* @__PURE__ */ jsxs3(HStack2, { children: [
762
+ /* @__PURE__ */ jsx3(Button3, { size: "sm", variant: "secondary", onClick: () => setDraft([...rows, { name: "", key: usable[0]?.key ?? "", rest: [] }]), disabled: usable.length === 0, children: t("addAlias") }),
763
+ usable.length === 0 && /* @__PURE__ */ jsx3(Text3, { textStyle: "sm", color: "fg.muted", children: t("noUsable") })
764
+ ] }),
765
+ shownInherited.length > 0 && /* @__PURE__ */ jsxs3(Stack3, { gap: "1", children: [
766
+ /* @__PURE__ */ jsx3(Text3, { textStyle: "sm", fontWeight: "medium", children: t("fromSite") }),
767
+ shownInherited.map((a) => {
768
+ const first = a.targets[0] ? modelKey(a.targets[0].connectionId, a.targets[0].model) : "";
769
+ const m = label(first);
770
+ return /* @__PURE__ */ jsxs3(Text3, { textStyle: "sm", children: [
771
+ /* @__PURE__ */ jsx3(Text3, { as: "span", fontFamily: "mono", dir: "ltr", children: a.name }),
772
+ " \u2192 ",
773
+ m?.name ?? a.targets[0]?.model ?? "",
774
+ !usable.some((u) => u.key === first) && /* @__PURE__ */ jsxs3(Text3, { as: "span", color: "fg.muted", children: [
775
+ " (",
776
+ t("notOpenHere"),
777
+ ")"
778
+ ] })
779
+ ] }, a.name);
780
+ })
781
+ ] })
782
+ ] })
783
+ }
784
+ );
785
+ }
786
+
787
+ // src/areas/ai/ExportsPanel.tsx
788
+ import { useState as useState4 } from "react";
789
+ import { HStack as HStack3, Input as Input3, Stack as Stack4, Text as Text4 } from "@chakra-ui/react";
790
+ import { Button as Button4, DataTable as DataTable2, Field as Field3, InlineAlert as InlineAlert4, Panel as Panel3, errorText, useApiAction as useApiAction3, useApiDownload, useApiQuery as useApiQuery2, useAreaRequest as useAreaRequest3, useConfirm, useFormatters as useFormatters3 } from "@abpjs/ui";
791
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
792
+ var day = (d) => d.toISOString().slice(0, 10);
793
+ function ExportsPanel({ scopeId }) {
794
+ const t = useAiTexts();
795
+ const fmt = useFormatters3();
796
+ const confirm = useConfirm();
797
+ const request = useAreaRequest3("ai");
798
+ const downloadFile = useApiDownload("ai");
799
+ const exports = useApiQuery2("ai", "/exports");
800
+ const action = useApiAction3();
801
+ const today = /* @__PURE__ */ new Date();
802
+ const [from, setFrom] = useState4(day(new Date(today.getTime() - 864e5)));
803
+ const [to, setTo] = useState4(day(today));
804
+ const [fetching, setFetching] = useState4(null);
805
+ const [error, setError] = useState4(null);
806
+ const days = (Date.parse(to) - Date.parse(from)) / 864e5 + 1;
807
+ const valid = Number.isFinite(days) && days >= 1 && days <= 31;
808
+ async function create(e) {
809
+ e.preventDefault();
810
+ if (!valid) return;
811
+ const end = new Date(Date.parse(to) + 864e5).toISOString();
812
+ const made = await action.run(() => request("/exports", { method: "POST", body: { from: `${from}T00:00:00Z`, to: end, scopeId: scopeId ?? null } }));
813
+ if (made) await exports.reload();
814
+ }
815
+ async function download(x) {
816
+ setFetching(x.id);
817
+ setError(null);
818
+ try {
819
+ await downloadFile(`/exports/${encodeURIComponent(x.id)}/file`, { method: "POST" }, `ai-calls-${day(new Date(x.from))}.jsonl.gz`);
820
+ } catch (err) {
821
+ setError(errorText(err));
822
+ } finally {
823
+ setFetching(null);
824
+ }
825
+ }
826
+ async function remove(x) {
827
+ if (!await confirm({ title: t("exportDeleteTitle"), description: t("exportDeleteHint"), confirmLabel: t("exportDelete"), danger: true })) return;
828
+ const done = await action.run(async () => {
829
+ await request(`/exports/${encodeURIComponent(x.id)}`, { method: "DELETE" });
830
+ return true;
831
+ });
832
+ if (done) await exports.reload();
833
+ }
834
+ const period = (x) => `${fmt.dateTime(x.from, { dateStyle: "medium", timeZone: "UTC" })} \u2013 ${fmt.dateTime(new Date(Date.parse(x.to) - 1).toISOString(), { dateStyle: "medium", timeZone: "UTC" })}`;
835
+ return /* @__PURE__ */ jsxs4(Panel3, { title: t("exportsTitle"), description: t("exportsHint"), flush: true, "data-testid": "ai-exports", children: [
836
+ /* @__PURE__ */ jsxs4(Stack4, { gap: "4", px: "5", py: "4", borderBottomWidth: "1px", children: [
837
+ /* @__PURE__ */ jsx4("form", { onSubmit: create, children: /* @__PURE__ */ jsxs4(HStack3, { gap: "3", align: "end", flexWrap: "wrap", children: [
838
+ /* @__PURE__ */ jsx4(Field3, { label: t("exportFrom"), w: "11rem", children: /* @__PURE__ */ jsx4(Input3, { type: "date", value: from, max: to, onChange: (e) => setFrom(e.target.value) }) }),
839
+ /* @__PURE__ */ jsx4(Field3, { label: t("exportTo"), w: "11rem", children: /* @__PURE__ */ jsx4(Input3, { type: "date", value: to, min: from, max: day(today), onChange: (e) => setTo(e.target.value) }) }),
840
+ /* @__PURE__ */ jsx4(Button4, { type: "submit", disabled: !valid, loading: action.busy, children: t("exportCreate") })
841
+ ] }) }),
842
+ !valid && /* @__PURE__ */ jsx4(Text4, { textStyle: "sm", color: "fg.muted", children: t("exportPeriodHint") }),
843
+ (action.error || error) && /* @__PURE__ */ jsx4(InlineAlert4, { tone: "danger", children: action.error ?? error })
844
+ ] }),
845
+ /* @__PURE__ */ jsx4(
846
+ DataTable2,
847
+ {
848
+ "aria-label": t("exportsTitle"),
849
+ rows: exports.data,
850
+ loading: exports.loading,
851
+ error: exports.error,
852
+ getRowId: (x) => x.id,
853
+ empty: t("noExports"),
854
+ columns: [
855
+ { id: "period", header: t("exportPeriod"), cell: (x) => /* @__PURE__ */ jsx4(Text4, { children: period(x) }) },
856
+ {
857
+ id: "calls",
858
+ header: t("calls"),
859
+ numeric: true,
860
+ cell: (x) => /* @__PURE__ */ jsxs4(Stack4, { gap: "0", align: "end", children: [
861
+ /* @__PURE__ */ jsx4(Text4, { children: fmt.number(num(x.calls)) }),
862
+ /* @__PURE__ */ jsx4(Text4, { textStyle: "caption", color: "fg.muted", children: t("exportPrompts", { count: num(x.prompts) }) }),
863
+ x.truncated && /* @__PURE__ */ jsx4(Text4, { textStyle: "caption", color: "fg.warning", children: t("exportTruncated") })
864
+ ] })
865
+ },
866
+ { id: "made", header: t("exportMade"), nowrap: true, cell: (x) => fmt.dateTime(x.at, { dateStyle: "short", timeStyle: "short" }) },
867
+ { id: "expires", header: t("exportExpires"), nowrap: true, cell: (x) => fmt.dateTime(x.expiresAt, { dateStyle: "short", timeStyle: "short" }) },
868
+ {
869
+ id: "actions",
870
+ header: "",
871
+ cell: (x) => /* @__PURE__ */ jsxs4(HStack3, { gap: "2", justify: "end", children: [
872
+ /* @__PURE__ */ jsx4(Button4, { size: "sm", variant: "secondary", loading: fetching === x.id, onClick: () => download(x), children: t("exportDownload") }),
873
+ /* @__PURE__ */ jsx4(Button4, { size: "sm", variant: "ghost", onClick: () => remove(x), children: t("exportDelete") })
874
+ ] })
875
+ }
876
+ ]
877
+ }
878
+ )
879
+ ] });
880
+ }
881
+
882
+ // src/areas/ai/ModelsPanel.tsx
883
+ import { useState as useState5 } from "react";
884
+ import { HStack as HStack4, Input as Input4, Stack as Stack5, Text as Text5 } from "@chakra-ui/react";
885
+ import { Button as Button5, CheckboxField as CheckboxField2, DataTable as DataTable3, Field as Field4, FormDialog as FormDialog2, HostSlot as HostSlot2, notify as notify3, Panel as Panel4, SelectField as SelectField3, StatusPill as StatusPill2, SwitchField as SwitchField2, errorText as errorText2, useApiAction as useApiAction4, useAreaRequest as useAreaRequest4, useFormatters as useFormatters4, useOptionalHost as useOptionalHost2 } from "@abpjs/ui";
886
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
887
+ function ModelsPanel({ scopeId, connections, rows, loading, hostKeeps, onChanged, title, description }) {
888
+ const t = useAiTexts();
889
+ const fmt = useFormatters4();
890
+ const request = useAreaRequest4("ai");
891
+ const [editing, setEditing] = useState5(null);
892
+ const [finding, setFinding] = useState5(null);
893
+ const [picked, setPicked] = useState5(null);
894
+ const list = connections ?? [];
895
+ const shown = rows ?? (connections ? modelRows(connections) : void 0);
896
+ const source = list.find((c) => c.id === picked) ?? list[0];
897
+ const own = (m) => list.some((c) => c.id === m.connectionId);
898
+ const host = useOptionalHost2();
899
+ const hostSaysCan = hostKeeps && Boolean(host?.slots?.["ai.models.can"]);
900
+ async function discover(c) {
901
+ setFinding(c.id);
902
+ try {
903
+ const found = await request(`/connections/${encodeURIComponent(c.id)}/discover`, { method: "POST" });
904
+ notify3.success(t("found", { count: found.models.length, name: c.name }));
905
+ await onChanged();
906
+ } catch (e) {
907
+ notify3.error(errorText2(e));
908
+ } finally {
909
+ setFinding(null);
910
+ }
911
+ }
912
+ const price = (m) => m.inputPrice == null && m.outputPrice == null ? t("noPrice") : t("price", { input: fmt.number(m.inputPrice ?? 0, { maximumFractionDigits: 4 }), output: fmt.number(m.outputPrice ?? 0, { maximumFractionDigits: 4 }) });
913
+ return /* @__PURE__ */ jsxs5(
914
+ Panel4,
915
+ {
916
+ title,
917
+ description,
918
+ flush: true,
919
+ "data-testid": "ai-models",
920
+ actions: hostKeeps ? /* @__PURE__ */ jsx5(HostSlot2, { name: "ai.models.actions", context: { scopeId, onChanged } }) : list.length > 0 && /* @__PURE__ */ jsxs5(HStack4, { gap: "2", children: [
921
+ /* @__PURE__ */ jsx5(
922
+ SelectField3,
923
+ {
924
+ size: "sm",
925
+ width: "auto",
926
+ value: source?.id ?? "",
927
+ "aria-label": t("connection"),
928
+ options: list.map((c) => ({ value: c.id, label: c.name })),
929
+ onChange: (e) => setPicked(e.target.value)
930
+ }
931
+ ),
932
+ /* @__PURE__ */ jsx5(Button5, { size: "sm", variant: "secondary", loading: finding !== null, disabled: !source, onClick: () => source && void discover(source), children: t("findModels") })
933
+ ] }),
934
+ children: [
935
+ /* @__PURE__ */ jsx5(
936
+ DataTable3,
937
+ {
938
+ "aria-label": title,
939
+ rows: shown,
940
+ loading,
941
+ getRowId: (m) => m.key,
942
+ empty: list.length ? t("noModelsFind") : t("noModels"),
943
+ columns: [
944
+ {
945
+ id: "model",
946
+ header: t("model"),
947
+ cell: (m) => /* @__PURE__ */ jsxs5(Stack5, { gap: "0.5", children: [
948
+ /* @__PURE__ */ jsx5(Text5, { fontWeight: "medium", children: m.name }),
949
+ /* @__PURE__ */ jsxs5(Text5, { textStyle: "caption", color: "fg.muted", children: [
950
+ /* @__PURE__ */ jsx5(Text5, { as: "span", fontFamily: "mono", dir: "ltr", children: m.modelId }),
951
+ " \xB7 ",
952
+ m.connection
953
+ ] })
954
+ ] })
955
+ },
956
+ {
957
+ id: "can",
958
+ header: t("can"),
959
+ 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: [
960
+ m.tools && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("tools") }),
961
+ m.images && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("images") }),
962
+ m.structuredOutput && /* @__PURE__ */ jsx5(StatusPill2, { tone: "neutral", dot: false, children: t("structured") })
963
+ ] })
964
+ },
965
+ {
966
+ id: "price",
967
+ header: t("prices"),
968
+ cell: (m) => /* @__PURE__ */ jsxs5(Stack5, { gap: "0.5", children: [
969
+ /* @__PURE__ */ jsx5(Text5, { textStyle: "sm", children: price(m) }),
970
+ m.priceSetAt && /* @__PURE__ */ jsx5(Text5, { textStyle: "caption", color: "fg.muted", children: t("priceSetAt", { at: fmt.dateTime(m.priceSetAt, { dateStyle: "medium" }) }) })
971
+ ] })
972
+ },
973
+ { id: "on", header: t("state"), nowrap: true, cell: (m) => /* @__PURE__ */ jsx5(StatusPill2, { tone: m.enabled ? "success" : "neutral", children: m.enabled ? t("on") : t("off") }) },
974
+ {
975
+ id: "edit",
976
+ header: /* @__PURE__ */ jsx5(Text5, { srOnly: true, children: t("edit") }),
977
+ align: "end",
978
+ cell: (m) => !own(m) ? null : hostKeeps ? /* @__PURE__ */ jsx5(HostSlot2, { name: "ai.models.edit", context: { connectionId: m.connectionId, modelId: m.modelId, scopeId, onSaved: onChanged } }) : /* @__PURE__ */ jsx5(Button5, { size: "sm", variant: "ghost", onClick: () => setEditing(m), children: t("edit") })
979
+ }
980
+ ]
981
+ }
982
+ ),
983
+ editing && /* @__PURE__ */ jsx5(
984
+ ModelEditor,
985
+ {
986
+ connection: list.find((c) => c.id === editing.connectionId),
987
+ model: editing,
988
+ onClose: () => setEditing(null),
989
+ onSaved: async () => {
990
+ setEditing(null);
991
+ await onChanged();
992
+ }
993
+ }
994
+ )
995
+ ]
996
+ }
997
+ );
998
+ }
999
+ function ModelEditor({ connection, model, onClose, onSaved }) {
1000
+ const t = useAiTexts();
1001
+ const request = useAreaRequest4("ai");
1002
+ const action = useApiAction4();
1003
+ const [name, setName] = useState5(model.name === model.modelId ? "" : model.name);
1004
+ const [enabled, setEnabled] = useState5(model.enabled);
1005
+ const [tools, setTools] = useState5(model.tools);
1006
+ const [images, setImages] = useState5(model.images);
1007
+ const [structured, setStructured] = useState5(model.structuredOutput);
1008
+ const [context, setContext] = useState5(model.contextTokens == null ? "" : String(model.contextTokens));
1009
+ const [input, setInput] = useState5(model.inputPrice == null ? "" : String(model.inputPrice));
1010
+ const [output, setOutput] = useState5(model.outputPrice == null ? "" : String(model.outputPrice));
1011
+ const number = (v) => v.trim() === "" ? null : Number(v);
1012
+ async function save() {
1013
+ const settings = {
1014
+ ...connection.modelSettings?.[model.modelId],
1015
+ name: name.trim() || null,
1016
+ enabled,
1017
+ tools,
1018
+ images,
1019
+ structuredOutput: structured,
1020
+ contextTokens: number(context)
1021
+ };
1022
+ const price = input.trim() === "" && output.trim() === "" ? null : { input: number(input) ?? 0, output: number(output) ?? 0 };
1023
+ const body = withModel(connection, model.modelId, settings, price);
1024
+ if (await action.run(() => request(`/connections/${encodeURIComponent(connection.id)}`, { method: "PUT", body })) !== void 0) await onSaved();
1025
+ }
1026
+ return /* @__PURE__ */ jsxs5(
1027
+ FormDialog2,
1028
+ {
1029
+ open: true,
1030
+ onOpenChange: (open) => !open && onClose(),
1031
+ title: t("editModel", { name: model.modelId }),
1032
+ submitLabel: t("save"),
1033
+ onSubmit: save,
1034
+ busy: action.busy,
1035
+ error: action.error,
1036
+ children: [
1037
+ /* @__PURE__ */ jsx5(SwitchField2, { label: t("modelOn"), checked: enabled, onCheckedChange: setEnabled }),
1038
+ /* @__PURE__ */ jsx5(Field4, { label: t("name"), helperText: t("nameHint"), children: /* @__PURE__ */ jsx5(Input4, { value: name, maxLength: 200, onChange: (e) => setName(e.target.value) }) }),
1039
+ /* @__PURE__ */ jsxs5(Stack5, { gap: "1.5", role: "group", "aria-labelledby": "ai-model-can", children: [
1040
+ /* @__PURE__ */ jsx5(Text5, { id: "ai-model-can", textStyle: "sm", fontWeight: "medium", children: t("can") }),
1041
+ /* @__PURE__ */ jsx5(CheckboxField2, { label: t("toolsLong"), checked: tools, onCheckedChange: setTools }),
1042
+ /* @__PURE__ */ jsx5(CheckboxField2, { label: t("imagesLong"), checked: images, onCheckedChange: setImages }),
1043
+ /* @__PURE__ */ jsx5(CheckboxField2, { label: t("structuredLong"), checked: structured, onCheckedChange: setStructured })
1044
+ ] }),
1045
+ /* @__PURE__ */ jsx5(Field4, { label: t("context"), optionalText: t("optional"), children: /* @__PURE__ */ jsx5(Input4, { type: "number", min: 1, value: context, dir: "ltr", onChange: (e) => setContext(e.target.value) }) }),
1046
+ /* @__PURE__ */ jsxs5(HStack4, { gap: "3", alignItems: "start", children: [
1047
+ /* @__PURE__ */ jsx5(Field4, { label: t("inputPrice"), helperText: t("perMillion"), children: /* @__PURE__ */ jsx5(Input4, { type: "number", min: 0, step: "any", value: input, dir: "ltr", onChange: (e) => setInput(e.target.value) }) }),
1048
+ /* @__PURE__ */ jsx5(Field4, { label: t("outputPrice"), helperText: t("perMillion"), children: /* @__PURE__ */ jsx5(Input4, { type: "number", min: 0, step: "any", value: output, dir: "ltr", onChange: (e) => setOutput(e.target.value) }) })
1049
+ ] })
1050
+ ]
1051
+ }
1052
+ );
1053
+ }
1054
+
1055
+ // src/areas/ai/TryPanel.tsx
1056
+ import { useId, useState as useState6 } from "react";
1057
+ import { HStack as HStack5, Input as Input5, Stack as Stack6, Text as Text6, Textarea } from "@chakra-ui/react";
1058
+ 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";
1059
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1060
+ function TryPanel({ scopeId, aliases }) {
1061
+ const t = useAiTexts();
1062
+ const fmt = useFormatters5();
1063
+ const request = useAreaRequest5("ai");
1064
+ const action = useApiAction5();
1065
+ const [alias, setAlias] = useState6(aliases[0] ?? "");
1066
+ const [prompt, setPrompt] = useState6("");
1067
+ const [result, setResult] = useState6(null);
1068
+ const listId = useId();
1069
+ async function run() {
1070
+ setResult(null);
1071
+ const body = { alias: alias.trim(), prompt, scopeId: scopeId ?? null };
1072
+ const answer = await action.run(() => request("/try", { method: "POST", body }));
1073
+ if (answer) setResult(answer);
1074
+ }
1075
+ return /* @__PURE__ */ jsx6(Panel5, { title: t("tryTitle"), description: t("tryHint"), "data-testid": "ai-try", children: /* @__PURE__ */ jsxs6(Stack6, { gap: "field", children: [
1076
+ /* @__PURE__ */ jsxs6(Field5, { label: t("alias"), children: [
1077
+ /* @__PURE__ */ jsx6(Input5, { value: alias, dir: "ltr", list: listId, onChange: (e) => setAlias(e.target.value) }),
1078
+ /* @__PURE__ */ jsx6("datalist", { id: listId, children: aliases.map((a) => /* @__PURE__ */ jsx6("option", { value: a }, a)) })
1079
+ ] }),
1080
+ /* @__PURE__ */ jsx6(Field5, { label: t("prompt"), children: /* @__PURE__ */ jsx6(Textarea, { value: prompt, rows: 3, onChange: (e) => setPrompt(e.target.value) }) }),
1081
+ /* @__PURE__ */ jsx6(HStack5, { children: /* @__PURE__ */ jsx6(Button6, { onClick: () => void run(), loading: action.busy, disabled: !alias.trim() || !prompt.trim(), children: t("run") }) }),
1082
+ /* @__PURE__ */ jsx6(InlineAlert5, { tone: "danger", children: action.error }),
1083
+ result && /* @__PURE__ */ jsxs6(Stack6, { gap: "1", "data-testid": "ai-try-answer", children: [
1084
+ /* @__PURE__ */ jsx6(Text6, { whiteSpace: "pre-wrap", dir: "auto", children: result.text }),
1085
+ /* @__PURE__ */ jsx6(Text6, { textStyle: "caption", color: "fg.muted", children: t("answered", {
1086
+ model: result.model,
1087
+ input: fmt.number(num(result.usage.inputTokens)),
1088
+ output: fmt.number(num(result.usage.outputTokens)),
1089
+ cost: fmt.number(num(result.usage.cost), { maximumFractionDigits: 6 })
1090
+ }) })
1091
+ ] })
1092
+ ] }) });
1093
+ }
1094
+
1095
+ // src/areas/ai/UsagePanel.tsx
1096
+ import { useMemo as useMemo3, useState as useState8 } from "react";
1097
+ import { HStack as HStack6, Stack as Stack7, Text as Text7 } from "@chakra-ui/react";
1098
+ import { DataTable as DataTable4, EMPTY_VALUE, Panel as Panel6, SelectField as SelectField4, StatusPill as StatusPill3, useFormatters as useFormatters6, useNames as useNames2 } from "@abpjs/ui";
1099
+
1100
+ // src/areas/ai/usePostQuery.ts
1101
+ import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState7 } from "react";
1102
+ import { errorText as errorText3, useAreaRequest as useAreaRequest6 } from "@abpjs/ui";
1103
+ function usePostQuery(path, body) {
1104
+ const request = useAreaRequest6("ai");
1105
+ const key = JSON.stringify(body);
1106
+ const [data, setData] = useState7(void 0);
1107
+ const [error, setError] = useState7(null);
1108
+ const [loading, setLoading] = useState7(true);
1109
+ const seq = useRef2(0);
1110
+ const reload = useCallback2(async () => {
1111
+ const id = ++seq.current;
1112
+ setLoading(true);
1113
+ try {
1114
+ const answer = await request(path, { method: "POST", body: JSON.parse(key) });
1115
+ if (id === seq.current) {
1116
+ setData(answer);
1117
+ setError(null);
1118
+ }
1119
+ } catch (e) {
1120
+ if (id === seq.current) setError(errorText3(e));
1121
+ } finally {
1122
+ if (id === seq.current) setLoading(false);
1123
+ }
1124
+ }, [request, path, key]);
1125
+ useEffect2(() => {
1126
+ void reload();
1127
+ }, [reload]);
1128
+ return { data, error, loading, reload };
1129
+ }
1130
+
1131
+ // src/areas/ai/UsagePanel.tsx
1132
+ import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1133
+ var USAGE_BY = { project: "scope", model: "model", purpose: "purpose", account: "account" };
1134
+ var outcomeOf = (state) => state === "done" ? "ok" : state;
1135
+ var OUTCOME_TONES = { ok: "success", refused: "warning", failed: "danger", reserved: "info" };
1136
+ function monthRange(offset) {
1137
+ const now = /* @__PURE__ */ new Date();
1138
+ const from = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - offset, 1));
1139
+ const to = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - offset + 1, 1));
1140
+ return { from: from.toISOString(), to: to.toISOString() };
1141
+ }
1142
+ function UsagePanel({ scopeId, by: byOptions }) {
1143
+ const t = useAiTexts();
1144
+ const fmt = useFormatters6();
1145
+ const [by, setBy] = useState8(byOptions[0]);
1146
+ const [month, setMonth] = useState8(0);
1147
+ const { from, to } = monthRange(month);
1148
+ const usage = usePostQuery("/usage", { from, to, scopeId: scopeId ?? null, groupBy: USAGE_BY[by] });
1149
+ const recent = usePostQuery("/usage/recent", { from, to, scopeId: scopeId ?? null, count: 50 });
1150
+ const rows = usage.data?.rows;
1151
+ const people = useNames2("people", useMemo3(() => [
1152
+ ...by === "account" ? (rows ?? []).filter((r) => !r.title && r.key).map((r) => r.key) : [],
1153
+ ...(recent.data ?? []).flatMap((c) => [
1154
+ ...c.accountId && !c.accountName ? [c.accountId] : [],
1155
+ ...c.onBehalfOf && !c.onBehalfOfName ? [c.onBehalfOf] : []
1156
+ ])
1157
+ ], [by, rows, recent.data]));
1158
+ const nameOf = (id, name) => name || (id ? people[id] : void 0) || id || EMPTY_VALUE;
1159
+ const scopes = useNames2("scopes", useMemo3(() => by === "project" ? (rows ?? []).filter((r) => !r.title && r.key).map((r) => r.key) : [], [by, rows]));
1160
+ 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" }) }));
1161
+ const total = (rows ?? []).reduce((sum, r) => sum + num(r.cost), 0);
1162
+ const money = (v) => fmt.number(num(v), { maximumFractionDigits: 6 });
1163
+ const label = (key, title) => key === "" && by === "project" ? t("siteCalls") : title || (by === "account" ? people[key] : by === "project" ? scopes[key] : void 0) || key;
1164
+ return /* @__PURE__ */ jsxs7(Stack7, { gap: "section", children: [
1165
+ /* @__PURE__ */ jsx7(
1166
+ Panel6,
1167
+ {
1168
+ title: t("usageTitle"),
1169
+ description: t("usageTotal", { cost: money(total) }),
1170
+ flush: true,
1171
+ "data-testid": "ai-usage",
1172
+ actions: /* @__PURE__ */ jsxs7(HStack6, { gap: "2", children: [
1173
+ /* @__PURE__ */ jsx7(
1174
+ SelectField4,
1175
+ {
1176
+ size: "sm",
1177
+ width: "auto",
1178
+ value: by,
1179
+ "aria-label": t("by"),
1180
+ options: byOptions.map((b) => ({ value: b, label: t(`byOptions.${b}`) })),
1181
+ onChange: (e) => setBy(e.target.value)
1182
+ }
1183
+ ),
1184
+ /* @__PURE__ */ jsx7(SelectField4, { size: "sm", width: "auto", value: String(month), "aria-label": t("month"), options: months, onChange: (e) => setMonth(Number(e.target.value)) })
1185
+ ] }),
1186
+ children: /* @__PURE__ */ jsx7(
1187
+ DataTable4,
1188
+ {
1189
+ "aria-label": t("usageTitle"),
1190
+ rows,
1191
+ loading: usage.loading,
1192
+ error: usage.error,
1193
+ getRowId: (r) => r.key,
1194
+ empty: t("noUsage"),
1195
+ columns: [
1196
+ { id: "label", header: t(`byOptions.${by}`), cell: (r) => /* @__PURE__ */ jsx7(Text7, { dir: "auto", children: label(r.key, r.title) }) },
1197
+ { id: "calls", header: t("calls"), numeric: true, cell: (r) => fmt.number(num(r.calls)) },
1198
+ { id: "in", header: t("tokensIn"), numeric: true, cell: (r) => fmt.number(num(r.inputTokens)) },
1199
+ { id: "out", header: t("tokensOut"), numeric: true, cell: (r) => fmt.number(num(r.outputTokens)) },
1200
+ { id: "cost", header: t("cost"), numeric: true, cell: (r) => money(r.cost) },
1201
+ { id: "refused", header: t("refused"), numeric: true, cell: (r) => fmt.number(num(r.refused)) },
1202
+ { id: "failed", header: t("failed"), numeric: true, cell: (r) => fmt.number(num(r.failed)) }
1203
+ ]
1204
+ }
1205
+ )
1206
+ }
1207
+ ),
1208
+ /* @__PURE__ */ jsx7(Panel6, { title: t("recentTitle"), flush: true, "data-testid": "ai-recent", children: /* @__PURE__ */ jsx7(
1209
+ DataTable4,
1210
+ {
1211
+ "aria-label": t("recentTitle"),
1212
+ rows: recent.data,
1213
+ loading: recent.loading,
1214
+ error: recent.error,
1215
+ getRowId: (u) => u.id,
1216
+ empty: t("noUsage"),
1217
+ columns: [
1218
+ { id: "at", header: t("at"), nowrap: true, cell: (u) => fmt.dateTime(u.at, { dateStyle: "short", timeStyle: "medium" }) },
1219
+ {
1220
+ id: "who",
1221
+ header: t("who"),
1222
+ // An agent's call is the person's it acted for, the agent beside it.
1223
+ cell: (u) => /* @__PURE__ */ jsxs7(Stack7, { gap: "0", children: [
1224
+ /* @__PURE__ */ jsx7(Text7, { children: u.onBehalfOf ? nameOf(u.onBehalfOf, u.onBehalfOfName) : nameOf(u.accountId, u.accountName) }),
1225
+ u.onBehalfOf && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", children: t("callThrough", { name: nameOf(u.accountId, u.accountName) }) }),
1226
+ u.scope && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", dir: "ltr", children: u.scope })
1227
+ ] })
1228
+ },
1229
+ { id: "purpose", header: t("purpose"), cell: (u) => /* @__PURE__ */ jsx7(Text7, { fontFamily: "mono", textStyle: "sm", dir: "ltr", children: u.purpose || EMPTY_VALUE }) },
1230
+ { id: "model", header: t("model"), cell: (u) => /* @__PURE__ */ jsx7(Text7, { fontFamily: "mono", textStyle: "sm", dir: "ltr", children: u.model }) },
1231
+ { id: "tokens", header: t("tokens"), numeric: true, cell: (u) => `${fmt.number(num(u.inputTokens))} / ${fmt.number(num(u.outputTokens))}` },
1232
+ { id: "cost", header: t("cost"), numeric: true, cell: (u) => money(u.cost) },
1233
+ {
1234
+ id: "outcome",
1235
+ header: t("outcome"),
1236
+ cell: (u) => /* @__PURE__ */ jsxs7(Stack7, { gap: "0.5", children: [
1237
+ /* @__PURE__ */ jsx7(StatusPill3, { tone: OUTCOME_TONES[outcomeOf(u.state)] ?? "neutral", children: t(`outcomes.${outcomeOf(u.state)}`) }),
1238
+ u.error && /* @__PURE__ */ jsx7(Text7, { textStyle: "caption", color: "fg.muted", lineClamp: 2, title: u.error, children: u.error })
1239
+ ] })
1240
+ }
1241
+ ]
1242
+ }
1243
+ ) })
1244
+ ] });
1245
+ }
1246
+
1247
+ // src/areas/ai/AiAdmin.tsx
1248
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
1249
+ function useHostKeepsConnections(told, scopeId) {
1250
+ const can = useCan();
1251
+ return told ?? !can("ai.connections.edit", scopeId);
1252
+ }
1253
+ function AiAdmin() {
1254
+ const t = useAiTexts();
1255
+ const request = useAreaRequest7("ai");
1256
+ const site = useApiQuery3("ai", "/site");
1257
+ const connections = useApiQuery3("ai", "/connections");
1258
+ const aliases = useApiQuery3("ai", "/aliases");
1259
+ const limits = useApiQuery3("ai", "/limits");
1260
+ const saving = useApiAction6();
1261
+ const hostKeeps = useHostKeepsConnections(site.data?.connectionsKeptByHost);
1262
+ const models = useMemo4(() => modelRows(connections.data ?? []), [connections.data]);
1263
+ async function saveSiteLimits(rows) {
1264
+ if (await saving.run(() => saveLimits(request, null, limits.data ?? [], rows).then(() => true)) !== void 0) {
1265
+ notify4.success(t("saved"));
1266
+ await limits.reload();
1267
+ }
1268
+ }
1269
+ return /* @__PURE__ */ jsxs8(Tabs.Root, { defaultValue: "models", variant: "line", lazyMount: true, children: [
1270
+ /* @__PURE__ */ jsxs8(Tabs.List, { mb: "section", overflowX: "auto", overflowY: "hidden", children: [
1271
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "models", children: t("tabs.models") }),
1272
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "aliases", children: t("tabs.aliases") }),
1273
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "access", children: t("tabs.access") }),
1274
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "limits", children: t("tabs.limits") }),
1275
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "usage", children: t("tabs.usage") }),
1276
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "try", children: t("tabs.try") }),
1277
+ /* @__PURE__ */ jsx8(Tabs.Trigger, { value: "exports", children: t("tabs.exports") })
1278
+ ] }),
1279
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "models", children: /* @__PURE__ */ jsxs8(Stack8, { gap: "section", children: [
1280
+ /* @__PURE__ */ jsx8(InlineAlert6, { tone: "danger", children: connections.error }),
1281
+ connections.data && connections.data.length === 0 && /* @__PURE__ */ jsx8(InlineAlert6, { tone: "info", children: t("noProviders") }),
1282
+ /* @__PURE__ */ jsx8(
1283
+ ModelsPanel,
1284
+ {
1285
+ connections: connections.data,
1286
+ loading: connections.loading,
1287
+ hostKeeps,
1288
+ onChanged: () => Promise.all([connections.reload(), aliases.reload()]).then(() => void 0),
1289
+ title: t("modelsTitle"),
1290
+ description: t("modelsHint")
1291
+ }
1292
+ )
1293
+ ] }) }),
1294
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "aliases", children: /* @__PURE__ */ jsx8(AliasesPanel, { aliases: aliases.data, models, onSaved: aliases.reload }) }),
1295
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "access", children: /* @__PURE__ */ jsx8(AccessPanel, { models }) }),
1296
+ /* @__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 }) }) }),
1297
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "usage", children: /* @__PURE__ */ jsx8(UsagePanel, { by: ["project", "model", "purpose", "account"] }) }),
1298
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "try", children: /* @__PURE__ */ jsx8(TryPanel, { aliases: (aliases.data ?? []).map((a) => a.name) }) }),
1299
+ /* @__PURE__ */ jsx8(Tabs.Content, { value: "exports", children: /* @__PURE__ */ jsx8(ExportsPanel, {}) })
1300
+ ] });
1301
+ }
1302
+
1303
+ // src/areas/ai/pages.tsx
1304
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
1305
+ function AiAdminPage() {
1306
+ const t = useAiTexts();
1307
+ return /* @__PURE__ */ jsxs9(Stack9, { gap: "section", children: [
1308
+ /* @__PURE__ */ jsx9(PageHeader, { title: t("pageTitle"), description: t("pageSubtitle") }),
1309
+ /* @__PURE__ */ jsx9(AiAdmin, {})
1310
+ ] });
1311
+ }
1312
+ function aiPages(options) {
1313
+ return [
1314
+ {
1315
+ id: "ai.admin",
1316
+ section: options.section,
1317
+ weight: options.weight ?? 100,
1318
+ title: options.title ?? "AI models and usage",
1319
+ href: options.href,
1320
+ about: options.about,
1321
+ plugin: "ai",
1322
+ visible: options.visible,
1323
+ component: AiAdminPage
1324
+ }
1325
+ ];
1326
+ }
1327
+
1328
+ // src/areas/ai/AiScopeScreen.tsx
1329
+ import { useMemo as useMemo5 } from "react";
1330
+ import { Stack as Stack10, Text as Text8 } from "@chakra-ui/react";
1331
+ import { InlineAlert as InlineAlert7, Loading, Panel as Panel8, StatusPill as StatusPill4, TextBone, TextSlot, useApiQuery as useApiQuery4, useNames as useNames3 } from "@abpjs/ui";
1332
+ import { Fragment, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
1333
+ function AiScopeScreen({ scopeId, header }) {
1334
+ const t = useAiTexts();
1335
+ const limitText = useLimitText();
1336
+ const id = encodeURIComponent(scopeId);
1337
+ const view = useApiQuery4("ai", `/scopes/${id}/view`);
1338
+ const access = useApiQuery4("ai", `/scopes/${id}/access`);
1339
+ const v = view.data;
1340
+ const own = useApiQuery4("ai", v?.mayConnect ? `/connections${scopeQuery(scopeId)}` : null);
1341
+ const aliases = useApiQuery4("ai", `/aliases${scopeQuery(scopeId)}`);
1342
+ const limits = useApiQuery4("ai", `/limits${scopeQuery(scopeId)}`);
1343
+ const hostKeeps = useHostKeepsConnections(v?.connectionsKeptByHost, scopeId);
1344
+ const rows = useMemo5(() => v ? scopeModelRows(v) : void 0, [v]);
1345
+ const a = access.data;
1346
+ const above = useMemo5(() => {
1347
+ const groups = [];
1348
+ for (const l of v?.limitsFromAbove ?? []) {
1349
+ const at = l.scopeId ?? null;
1350
+ const group = groups.find((g) => g.scopeId === at);
1351
+ if (group) group.limits.push(l);
1352
+ else groups.push({ scopeId: at, limits: [l] });
1353
+ }
1354
+ return groups;
1355
+ }, [v]);
1356
+ const scopeNames = useNames3("scopes", useMemo5(() => above.flatMap((g) => g.scopeId ? [g.scopeId] : []), [above]));
1357
+ const aliasNames = useMemo5(() => [...new Set([...aliases.data ?? [], ...v?.aliasesFromAbove ?? []].map((x) => x.name))], [aliases.data, v]);
1358
+ if (view.error && !v || access.error && !a) {
1359
+ return /* @__PURE__ */ jsxs10(Stack10, { gap: "section", children: [
1360
+ header,
1361
+ /* @__PURE__ */ jsx10(InlineAlert7, { tone: "danger", children: view.error ?? access.error })
1362
+ ] });
1363
+ }
1364
+ const opened = a && (a.allSiteModels ? t("allModels") : a.siteModels.length ? t("someModels", { count: a.siteModels.length }) : t("noModelsOpen"));
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
+ };
1375
+ return /* @__PURE__ */ jsx10(Loading, { when: !v || !a, children: /* @__PURE__ */ jsxs10(Stack10, { gap: "section", children: [
1376
+ header,
1377
+ /* @__PURE__ */ jsx10(Panel8, { title: t("projectAccessTitle"), description: t("projectAccessHint"), "data-testid": "ai-project-access", children: /* @__PURE__ */ jsxs10(Stack10, { gap: "2", children: [
1378
+ /* @__PURE__ */ jsx10(Text8, { children: /* @__PURE__ */ jsx10(StatusPill4, { tone: a?.allSiteModels || a?.siteModels.length ? "success" : "neutral", children: opened }) }),
1379
+ /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", children: /* @__PURE__ */ jsx10(TextSlot, { width: 44, children: v && (v.mayConnect ? t("ownAllowed") : t("ownNotAllowed")) }) })
1380
+ ] }) }),
1381
+ /* @__PURE__ */ jsx10(
1382
+ ModelsPanel,
1383
+ {
1384
+ scopeId,
1385
+ connections: v?.mayConnect ? own.data ?? [] : [],
1386
+ rows,
1387
+ loading: view.loading,
1388
+ hostKeeps,
1389
+ onChanged: () => Promise.all([view.reload(), own.reload(), aliases.reload()]).then(() => void 0),
1390
+ title: t("projectModelsTitle"),
1391
+ description: v?.mayConnect ? t("projectModelsOwnHint") : t("projectModelsHint")
1392
+ }
1393
+ ),
1394
+ /* @__PURE__ */ jsx10(AliasesPanel, { scopeId, aliases: aliases.data, inherited: v?.aliasesFromAbove, models: rows ?? [], onSaved: aliases.reload }),
1395
+ /* @__PURE__ */ jsx10(Panel8, { title: t("tabs.limits"), description: t("projectLimitsReadHint"), "data-testid": "ai-project-limits", children: /* @__PURE__ */ jsxs10(Stack10, { gap: "3", children: [
1396
+ /* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
1397
+ /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: t("thisProject") }),
1398
+ lines(limits.data)
1399
+ ] }),
1400
+ !v || !above.some((g) => g.scopeId === null) ? /* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
1401
+ /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: t("theSite") }),
1402
+ lines(v ? [] : void 0)
1403
+ ] }) : null,
1404
+ above.map((g) => /* @__PURE__ */ jsxs10(Stack10, { gap: "1", children: [
1405
+ /* @__PURE__ */ jsx10(Text8, { textStyle: "sm", fontWeight: "medium", children: g.scopeId ? scopeNames[g.scopeId] ?? g.scopeId : t("theSite") }),
1406
+ lines(g.limits)
1407
+ ] }, g.scopeId ?? "site"))
1408
+ ] }) }),
1409
+ /* @__PURE__ */ jsx10(UsagePanel, { scopeId, by: ["model", "purpose", "account"] }),
1410
+ /* @__PURE__ */ jsx10(TryPanel, { scopeId, aliases: aliasNames }, aliases.data && v ? "loaded" : "loading")
1411
+ ] }) });
1412
+ }
1413
+ export {
1414
+ AccessPanel,
1415
+ AiAdmin,
1416
+ AiAdminPage,
1417
+ AiScopeScreen,
1418
+ AliasesPanel,
1419
+ ExportsPanel,
1420
+ LIMIT_KINDS,
1421
+ LIMIT_PERIODS,
1422
+ LimitsEditor,
1423
+ ModelsPanel,
1424
+ TryPanel,
1425
+ USAGE_BY,
1426
+ UsagePanel,
1427
+ aiPages,
1428
+ editableLimit,
1429
+ limitRow,
1430
+ modelKey,
1431
+ modelRows,
1432
+ num,
1433
+ saveLimits,
1434
+ scopeModelRows,
1435
+ useAiTexts,
1436
+ useHostKeepsConnections,
1437
+ useLimitText,
1438
+ withModel
1439
+ };
1440
+ //# sourceMappingURL=ai.js.map