@epam/ai-dial-chat-hooks 1.4.0-dev.84 → 1.4.0-dev.90
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/catalog/create-publish-api.d.ts +7 -1
- package/catalog/create-publish-api.d.ts.map +1 -1
- package/catalog/create-publish-api.js +5 -0
- package/catalog/resource-save-adapter.d.ts +7 -2
- package/catalog/resource-save-adapter.d.ts.map +1 -1
- package/catalog/resource-save-adapters.d.ts +32 -7
- package/catalog/resource-save-adapters.d.ts.map +1 -1
- package/catalog/resource-save-adapters.js +47 -41
- package/catalog/resource-save.d.ts +17 -9
- package/catalog/resource-save.d.ts.map +1 -1
- package/catalog/resource-save.js +34 -25
- package/catalog/save-destination-root.d.ts +12 -0
- package/catalog/save-destination-root.d.ts.map +1 -0
- package/catalog/save-destination-root.js +6 -0
- package/catalog/usePublishFolders/usePublishFolders.d.ts +8 -2
- package/catalog/usePublishFolders/usePublishFolders.d.ts.map +1 -1
- package/catalog/usePublishFolders/usePublishFolders.js +29 -29
- package/catalog/useResourceSavePanel/useResourceSavePanel.d.ts +7 -3
- package/catalog/useResourceSavePanel/useResourceSavePanel.d.ts.map +1 -1
- package/catalog/useResourceSavePanel/useResourceSavePanel.js +107 -97
- package/catalog.js +9 -8
- package/entry-points/usage-limits.d.ts +1 -0
- package/entry-points/usage-limits.d.ts.map +1 -1
- package/entry-points/utils.d.ts +3 -0
- package/entry-points/utils.d.ts.map +1 -1
- package/index.d.ts +4 -0
- package/index.d.ts.map +1 -1
- package/index.js +191 -187
- package/org-units/models.d.ts +3 -1
- package/org-units/models.d.ts.map +1 -1
- package/org-units/org-unit-guards.d.ts +64 -0
- package/org-units/org-unit-guards.d.ts.map +1 -0
- package/org-units/org-unit-guards.js +28 -0
- package/org-units/useFolderGuards/useFolderGuards.d.ts +31 -0
- package/org-units/useFolderGuards/useFolderGuards.d.ts.map +1 -0
- package/org-units/useFolderGuards/useFolderGuards.js +50 -0
- package/org-units/useOrgUnits/useOrgUnits.d.ts +18 -3
- package/org-units/useOrgUnits/useOrgUnits.d.ts.map +1 -1
- package/org-units/useOrgUnits/useOrgUnits.js +43 -23
- package/package.json +18 -18
- package/skill/useSkillEditorSubmit.d.ts +4 -1
- package/skill/useSkillEditorSubmit.d.ts.map +1 -1
- package/skill/useSkillEditorSubmit.js +125 -121
- package/usage/map-usage-data-to-dashboard.d.ts +22 -1
- package/usage/map-usage-data-to-dashboard.d.ts.map +1 -1
- package/usage/map-usage-data-to-dashboard.js +33 -2
- package/usage/spending-limits-mode.d.ts +37 -0
- package/usage/spending-limits-mode.d.ts.map +1 -0
- package/usage/spending-limits-mode.js +15 -0
- package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts +6 -2
- package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts.map +1 -1
- package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts +4 -1
- package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts.map +1 -1
- package/usage/useUsageLimitBanner/useUsageLimitBanner.js +55 -47
- package/usage-limits.js +6 -5
- package/usage.js +3 -3
- package/utils.js +19 -16
|
@@ -1,236 +1,240 @@
|
|
|
1
1
|
import { getApiErrorDetails as e, getApiErrorStatus as t } from "../api-error/api-error.js";
|
|
2
2
|
import { SKILL_TEXT_FIELD_MAX_LENGTHS as n, buildSkillFilesPayload as r, buildSkillManifestForSubmit as i, getSkillFieldLengthViolations as a, isValidSkillRelativePath as o, normalizeSkillName as s, startsWithFrontmatterBlock as c } from "./skill.js";
|
|
3
3
|
import { ResourceSaveError as l } from "../catalog/resource-save-adapter.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { createOrgUnitWriter as u } from "../catalog/resource-save-adapters.js";
|
|
5
|
+
import { useCallback as d, useMemo as f, useRef as p, useState as m } from "react";
|
|
6
|
+
import { NotificationVariant as h } from "@epam/ai-dial-ui-kit";
|
|
6
7
|
//#region src/skill/useSkillEditorSubmit.ts
|
|
7
|
-
var
|
|
8
|
+
var g = (e, t, n) => JSON.stringify({
|
|
8
9
|
values: e,
|
|
9
10
|
files: [...t].sort((e, t) => e.path.localeCompare(t.path)),
|
|
10
11
|
contentRevisions: Object.entries(n).sort(([e], [t]) => e.localeCompare(t))
|
|
11
|
-
}),
|
|
12
|
-
let [
|
|
12
|
+
}), _ = {}, v = ({ bucket: v, isEditMode: y, files: b, filesContentRef: x, contentRevisions: S = _, frontmatterRef: C, loadedPathRef: w, etagRef: T, returnUrl: E, getCreateReturnUrl: D, refetchSkills: O, client: k, publishClient: A, messages: j, onNavigate: M, onNotify: N, onSaveRequest: P }) => {
|
|
13
|
+
let [F, I] = m({}), [L, R] = m(), [z, B] = m(!1), [V, H] = m(), [U, W] = m("idle"), G = p(null), K = p(null), q = d(async (n) => {
|
|
13
14
|
switch (t(n)) {
|
|
14
15
|
case 409:
|
|
15
|
-
|
|
16
|
+
I({ name: j.nameConflict });
|
|
16
17
|
return;
|
|
17
18
|
case 412:
|
|
18
|
-
|
|
19
|
+
I({ name: j.nameConflict });
|
|
19
20
|
return;
|
|
20
21
|
case 413:
|
|
21
|
-
|
|
22
|
+
R(j.archiveTooLarge);
|
|
22
23
|
return;
|
|
23
24
|
case 503:
|
|
24
|
-
|
|
25
|
+
R(j.serviceUnavailable), B(!0);
|
|
25
26
|
return;
|
|
26
27
|
case 400: {
|
|
27
28
|
let { message: t } = await e(n);
|
|
28
|
-
|
|
29
|
+
R(t ?? j.pathInvalid);
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
31
32
|
default: {
|
|
32
33
|
let { traceId: t } = await e(n);
|
|
33
|
-
|
|
34
|
-
variant:
|
|
35
|
-
message:
|
|
34
|
+
R(j.saveError), N({
|
|
35
|
+
variant: h.Error,
|
|
36
|
+
message: j.saveError,
|
|
36
37
|
requestId: t
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
}, [
|
|
41
|
+
}, [j, N]), J = d(async (e) => {
|
|
41
42
|
let t = s(e.name);
|
|
42
43
|
if (!t || !o(t)) {
|
|
43
|
-
|
|
44
|
+
I({ name: j.nameInvalid });
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
|
-
let n =
|
|
47
|
-
c ? {skillManifest: u, filePaths: d, files: f} = a : (u = i(
|
|
47
|
+
let n = g(e, b, S), a = G.current, c = a != null && a.fingerprint === n, l = t, u, d, f;
|
|
48
|
+
c ? {skillManifest: u, filePaths: d, files: f} = a : (u = i(C.current, t, e.description, e.instructions), {filePaths: d, files: f} = r(b, x.current)), W("submitting"), G.current = {
|
|
48
49
|
fingerprint: n,
|
|
49
|
-
bucket:
|
|
50
|
+
bucket: v,
|
|
50
51
|
path: l,
|
|
51
52
|
skillManifest: u,
|
|
52
53
|
filePaths: d,
|
|
53
54
|
files: f
|
|
54
55
|
};
|
|
55
56
|
try {
|
|
56
|
-
await
|
|
57
|
-
variant:
|
|
58
|
-
title:
|
|
59
|
-
message:
|
|
60
|
-
}),
|
|
57
|
+
await k.createSkill(v, l, u, d, f), await O(), W("success"), N({
|
|
58
|
+
variant: h.Success,
|
|
59
|
+
title: j.saveSuccessTitle,
|
|
60
|
+
message: j.createSuccess(t)
|
|
61
|
+
}), M(D?.(l) ?? E);
|
|
61
62
|
} catch (e) {
|
|
62
|
-
|
|
63
|
+
W("failure"), await q(e);
|
|
63
64
|
}
|
|
64
65
|
}, [
|
|
65
|
-
g,
|
|
66
66
|
v,
|
|
67
|
-
y,
|
|
68
67
|
b,
|
|
69
68
|
x,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
S,
|
|
70
|
+
C,
|
|
71
|
+
j,
|
|
73
72
|
k,
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
N,
|
|
74
|
+
M,
|
|
76
75
|
E,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
D,
|
|
77
|
+
O,
|
|
78
|
+
q
|
|
79
|
+
]), Y = d(async (e) => {
|
|
80
|
+
let n = w.current, a = T.current;
|
|
80
81
|
if (!n || !a) {
|
|
81
|
-
|
|
82
|
+
R(j.saveError);
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
|
-
let o = i(
|
|
85
|
-
|
|
85
|
+
let o = i(C.current, e.name, e.description, e.instructions), { filePaths: s, files: c } = r(b, x.current);
|
|
86
|
+
W("submitting");
|
|
86
87
|
try {
|
|
87
|
-
|
|
88
|
-
variant:
|
|
89
|
-
title:
|
|
90
|
-
message:
|
|
91
|
-
}),
|
|
88
|
+
T.current = (await k.updateSkill(v, n, o, s, c, a)).etag ?? a, await O(), W("success"), N({
|
|
89
|
+
variant: h.Success,
|
|
90
|
+
title: j.updateSuccessTitle,
|
|
91
|
+
message: j.updateSuccess(e.name)
|
|
92
|
+
}), M(E);
|
|
92
93
|
} catch (e) {
|
|
93
|
-
if (
|
|
94
|
-
|
|
94
|
+
if (W("failure"), t(e) === 412) {
|
|
95
|
+
H({ message: j.conflictMessage });
|
|
95
96
|
return;
|
|
96
97
|
}
|
|
97
|
-
await
|
|
98
|
+
await q(e);
|
|
98
99
|
}
|
|
99
100
|
}, [
|
|
100
|
-
g,
|
|
101
101
|
v,
|
|
102
|
-
|
|
102
|
+
b,
|
|
103
103
|
x,
|
|
104
|
-
S,
|
|
105
104
|
C,
|
|
106
|
-
O,
|
|
107
|
-
D,
|
|
108
|
-
A,
|
|
109
|
-
k,
|
|
110
105
|
w,
|
|
106
|
+
T,
|
|
107
|
+
j,
|
|
108
|
+
k,
|
|
109
|
+
N,
|
|
110
|
+
M,
|
|
111
111
|
E,
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
O,
|
|
113
|
+
q
|
|
114
|
+
]), X = d(async (n, r) => {
|
|
114
115
|
let i = t(n);
|
|
115
|
-
if (i === 412 && r) return
|
|
116
|
-
if (i === 409 || i === 412) return new l(
|
|
117
|
-
if (i === 413) return new l(
|
|
118
|
-
if (i === 503) return new l(
|
|
116
|
+
if (i === 412 && r) return H({ message: j.conflictMessage }), new l(j.conflictMessage);
|
|
117
|
+
if (i === 409 || i === 412) return new l(j.nameConflict);
|
|
118
|
+
if (i === 413) return new l(j.archiveTooLarge);
|
|
119
|
+
if (i === 503) return new l(j.serviceUnavailable);
|
|
119
120
|
if (i === 400) {
|
|
120
121
|
let { message: t } = await e(n);
|
|
121
|
-
return new l(t ??
|
|
122
|
+
return new l(t ?? j.pathInvalid);
|
|
122
123
|
}
|
|
123
|
-
return new l(
|
|
124
|
-
}, [
|
|
125
|
-
let t =
|
|
126
|
-
if (!
|
|
124
|
+
return new l(j.saveError);
|
|
125
|
+
}, [j]), Z = f(() => u(A, "skill"), [A]), Q = d((e) => {
|
|
126
|
+
let t = v, { filePaths: n, files: a } = r(b, x.current);
|
|
127
|
+
if (!y) {
|
|
127
128
|
let r = s(e.name);
|
|
128
129
|
if (!r || !o(r)) {
|
|
129
|
-
|
|
130
|
+
I({ name: j.nameInvalid });
|
|
130
131
|
return;
|
|
131
132
|
}
|
|
132
|
-
let c = i(
|
|
133
|
+
let c = i(C.current, r, e.description, e.instructions);
|
|
133
134
|
return {
|
|
134
135
|
publishEntityType: "skill",
|
|
135
136
|
isVersioned: !1,
|
|
136
137
|
createIn: async (e) => {
|
|
137
138
|
let i = [...e, r].join("/");
|
|
138
139
|
try {
|
|
139
|
-
await
|
|
140
|
+
await k.createSkill(t, i, c, n, a);
|
|
140
141
|
} catch (e) {
|
|
141
|
-
throw await
|
|
142
|
+
throw await X(e, !1);
|
|
142
143
|
}
|
|
143
|
-
return await
|
|
144
|
-
}
|
|
144
|
+
return await O().catch(() => void 0), { id: `skills/${t}/${i}` };
|
|
145
|
+
},
|
|
146
|
+
...Z
|
|
145
147
|
};
|
|
146
148
|
}
|
|
147
|
-
let c =
|
|
149
|
+
let c = w.current, u = T.current;
|
|
148
150
|
if (!c || !u) {
|
|
149
|
-
|
|
151
|
+
R(j.saveError);
|
|
150
152
|
return;
|
|
151
153
|
}
|
|
152
|
-
let d = i(
|
|
154
|
+
let d = i(C.current, e.name, e.description, e.instructions);
|
|
153
155
|
return {
|
|
154
156
|
publishEntityType: "skill",
|
|
155
157
|
isVersioned: !1,
|
|
156
158
|
saveInPlace: async () => {
|
|
157
159
|
try {
|
|
158
|
-
|
|
160
|
+
T.current = (await k.updateSkill(t, c, d, n, a, T.current ?? u)).etag ?? u;
|
|
159
161
|
} catch (e) {
|
|
160
|
-
throw await
|
|
162
|
+
throw await X(e, !0);
|
|
161
163
|
}
|
|
162
|
-
return await
|
|
164
|
+
return await O().catch(() => void 0), { id: `skills/${t}/${c}` };
|
|
163
165
|
},
|
|
164
166
|
move: async (e, t) => {
|
|
165
|
-
if (!
|
|
167
|
+
if (!k.moveSkill) throw new l(j.saveError);
|
|
166
168
|
try {
|
|
167
|
-
return await
|
|
169
|
+
return await k.moveSkill(c, t.join("/"));
|
|
168
170
|
} catch (e) {
|
|
169
|
-
throw await
|
|
171
|
+
throw await X(e, !1);
|
|
170
172
|
}
|
|
171
|
-
}
|
|
173
|
+
},
|
|
174
|
+
...Z
|
|
172
175
|
};
|
|
173
176
|
}, [
|
|
174
|
-
g,
|
|
175
|
-
D,
|
|
176
|
-
C,
|
|
177
177
|
v,
|
|
178
|
-
|
|
178
|
+
k,
|
|
179
|
+
Z,
|
|
180
|
+
T,
|
|
181
|
+
b,
|
|
179
182
|
x,
|
|
180
|
-
|
|
181
|
-
|
|
183
|
+
C,
|
|
184
|
+
y,
|
|
185
|
+
w,
|
|
186
|
+
j,
|
|
182
187
|
O,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
]), Y = u((e) => {
|
|
188
|
+
X
|
|
189
|
+
]), ee = d((e) => {
|
|
186
190
|
let t = c(e.instructions), r = a(e);
|
|
187
|
-
|
|
191
|
+
I((e) => {
|
|
188
192
|
let i = { ...e };
|
|
189
193
|
for (let e of Object.keys(n)) {
|
|
190
|
-
let t =
|
|
194
|
+
let t = j.tooLong(n[e]);
|
|
191
195
|
r[e] ? i[e] = t : i[e] === t && delete i[e];
|
|
192
196
|
}
|
|
193
197
|
if (!r.instructions) {
|
|
194
|
-
let e = i.instructions ===
|
|
195
|
-
t && !e ? i.instructions =
|
|
198
|
+
let e = i.instructions === j.instructionsFrontmatter;
|
|
199
|
+
t && !e ? i.instructions = j.instructionsFrontmatter : !t && e && delete i.instructions;
|
|
196
200
|
}
|
|
197
201
|
return Object.keys(i).length === Object.keys(e).length && Object.keys(i).every((t) => i[t] === e[t]) ? e : i;
|
|
198
202
|
});
|
|
199
|
-
}, [
|
|
200
|
-
if (
|
|
203
|
+
}, [j]), $ = d(async (e) => {
|
|
204
|
+
if (U === "submitting" || !v) return;
|
|
201
205
|
let t = {};
|
|
202
|
-
e.name.trim() || (t.name =
|
|
206
|
+
e.name.trim() || (t.name = j.required), e.description.trim() || (t.description = j.required), e.instructions.trim() ? c(e.instructions) && (t.instructions = j.instructionsFrontmatter) : t.instructions = j.required;
|
|
203
207
|
let r = a(e);
|
|
204
|
-
for (let e of Object.keys(r)) t[e] ??=
|
|
205
|
-
if (Object.keys(t).length > 0)
|
|
206
|
-
else if (
|
|
207
|
-
let t =
|
|
208
|
-
t &&
|
|
209
|
-
} else
|
|
208
|
+
for (let e of Object.keys(r)) t[e] ??= j.tooLong(n[e]);
|
|
209
|
+
if (Object.keys(t).length > 0) I(t);
|
|
210
|
+
else if (I({}), R(void 0), B(!1), H(void 0), K.current = e, P) {
|
|
211
|
+
let t = Q(e);
|
|
212
|
+
t && P(t, e);
|
|
213
|
+
} else y ? await Y(e) : await J(e);
|
|
210
214
|
}, [
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
O,
|
|
214
|
-
_,
|
|
215
|
+
U,
|
|
216
|
+
v,
|
|
215
217
|
j,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
218
|
+
y,
|
|
219
|
+
P,
|
|
220
|
+
Q,
|
|
221
|
+
Y,
|
|
222
|
+
J
|
|
219
223
|
]);
|
|
220
224
|
return {
|
|
221
|
-
phase:
|
|
222
|
-
errors:
|
|
223
|
-
submitError:
|
|
224
|
-
isSubmitErrorRetryable:
|
|
225
|
-
retrySubmit:
|
|
226
|
-
let e =
|
|
227
|
-
e != null &&
|
|
228
|
-
}, [
|
|
229
|
-
conflict:
|
|
230
|
-
clearConflict: () =>
|
|
231
|
-
handleSubmit:
|
|
232
|
-
handleValuesChange:
|
|
225
|
+
phase: U,
|
|
226
|
+
errors: F,
|
|
227
|
+
submitError: L,
|
|
228
|
+
isSubmitErrorRetryable: z,
|
|
229
|
+
retrySubmit: d(() => {
|
|
230
|
+
let e = K.current;
|
|
231
|
+
e != null && $(e);
|
|
232
|
+
}, [$]),
|
|
233
|
+
conflict: V,
|
|
234
|
+
clearConflict: () => H(void 0),
|
|
235
|
+
handleSubmit: $,
|
|
236
|
+
handleValuesChange: ee
|
|
233
237
|
};
|
|
234
238
|
};
|
|
235
239
|
//#endregion
|
|
236
|
-
export {
|
|
240
|
+
export { v as useSkillEditorSubmit };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserLimitStatsResponseDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
-
import { UsageLimitCardData } from '@epam/ai-dial-usage-dashboard';
|
|
2
|
+
import { SpendingBudgetData, UsageLimitCardData } from '@epam/ai-dial-usage-dashboard';
|
|
3
3
|
import { ResetTimeDisplay } from './usage-reset-time';
|
|
4
4
|
/** A translate function compatible with i18next's `TFunction`. */
|
|
5
5
|
type Translate = (key: string, options?: Record<string, unknown>) => string;
|
|
@@ -35,5 +35,26 @@ export declare const USAGE_DATA_I18N_KEYS: {
|
|
|
35
35
|
* `formatResetTime`, and is absent when that callback returns `undefined`.
|
|
36
36
|
*/
|
|
37
37
|
export declare const mapUsageDataToDashboard: (usage: UserLimitStatsResponseDto | undefined, t: Translate, formatResetTime: FormatResetTime) => UsageLimitCardData[];
|
|
38
|
+
/**
|
|
39
|
+
* i18n key strings that the consuming app's translation bundle must define for
|
|
40
|
+
* `mapBudgetsToDashboard`, beyond the Today and This month keys of
|
|
41
|
+
* `USAGE_DATA_I18N_KEYS`. The values are the default key paths used by AI DIAL Chat.
|
|
42
|
+
*/
|
|
43
|
+
export declare const BUDGET_DATA_I18N_KEYS: {
|
|
44
|
+
/** Coverage line of a budget that covers every model (e.g. `'All models'`). */
|
|
45
|
+
readonly allModels: "usage.budgets.allModels";
|
|
46
|
+
/** Coverage line of a budget that lists its models. Receives `{ models: string }`. */
|
|
47
|
+
readonly coveredModels: "usage.budgets.coveredModels";
|
|
48
|
+
};
|
|
49
|
+
/** Resolves a deployment id to its display name, or `undefined` when the host does not know it. */
|
|
50
|
+
export type ResolveModelName = (deploymentId: string) => string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Maps the budgets charged for the caller's model calls — the `budgets`
|
|
53
|
+
* entries whose `costObject` equals the response's `costObject` — into
|
|
54
|
+
* `SpendingBudgetsSection`'s `budgets` prop, in response order, each with a
|
|
55
|
+
* Today card and a This month card. Returns `[]` when the response carries no
|
|
56
|
+
* `costObject` or no `budgets`.
|
|
57
|
+
*/
|
|
58
|
+
export declare const mapBudgetsToDashboard: (usage: Pick<UserLimitStatsResponseDto, "budgets" | "costObject"> | undefined, t: Translate, formatResetTime: FormatResetTime, resolveModelName: ResolveModelName) => SpendingBudgetData[];
|
|
38
59
|
export {};
|
|
39
60
|
//# sourceMappingURL=map-usage-data-to-dashboard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-usage-data-to-dashboard.d.ts","sourceRoot":"","sources":["../../src/usage/map-usage-data-to-dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"map-usage-data-to-dashboard.d.ts","sourceRoot":"","sources":["../../src/usage/map-usage-data-to-dashboard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EACV,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,kEAAkE;AAClE,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAC;AAE5E,yGAAyG;AACzG,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,MAAM,GAAG,SAAS,KACzB,gBAAgB,GAAG,SAAS,CAAC;AAElC;;;;GAIG;AACH,eAAO,MAAM,oBAAoB;IAC/B,2DAA2D;;IAE3D,kEAAkE;;IAElE,gEAAgE;;IAEhE,mEAAmE;;IAEnE,kEAAkE;;IAElE,oEAAoE;;IAEpE,sEAAsE;;IAEtE,sHAAsH;;CAE9G,CAAC;AA8FX;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,OAAO,yBAAyB,GAAG,SAAS,EAC5C,GAAG,SAAS,EACZ,iBAAiB,eAAe,KAC/B,kBAAkB,EAoCpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;IAChC,+EAA+E;;IAE/E,sFAAsF;;CAE9E,CAAC;AAEX,mGAAmG;AACnG,MAAM,MAAM,gBAAgB,GAAG,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAuB5E;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAChC,OAAO,IAAI,CAAC,yBAAyB,EAAE,SAAS,GAAG,YAAY,CAAC,GAAG,SAAS,EAC5E,GAAG,SAAS,EACZ,iBAAiB,eAAe,EAChC,kBAAkB,gBAAgB,KACjC,kBAAkB,EAmDpB,CAAC"}
|
|
@@ -61,6 +61,37 @@ var n = {
|
|
|
61
61
|
titleKey: n.thisMonthTitle,
|
|
62
62
|
periodDescriptionKey: n.thisMonthPeriodDescription
|
|
63
63
|
}
|
|
64
|
-
].flatMap(({ stats: e, titleKey: n, periodDescriptionKey: i }) => a(e) ? [c(e, t(n), t(i), t, r(e.resetsAt))] : [])
|
|
64
|
+
].flatMap(({ stats: e, titleKey: n, periodDescriptionKey: i }) => a(e) ? [c(e, t(n), t(i), t, r(e.resetsAt))] : []), u = {
|
|
65
|
+
allModels: "usage.budgets.allModels",
|
|
66
|
+
coveredModels: "usage.budgets.coveredModels"
|
|
67
|
+
}, d = "*", f = (e) => e.displayName?.trim() ? e.displayName : e.policy, p = (e, t, n) => {
|
|
68
|
+
if (e === d) return t(u.allModels);
|
|
69
|
+
if (!Array.isArray(e) || e.length === 0) return;
|
|
70
|
+
let r = e.map((e) => n(e) ?? e).join(", ");
|
|
71
|
+
return t(u.coveredModels, { models: r });
|
|
72
|
+
}, m = (e, t, r, i) => {
|
|
73
|
+
let o = e?.costObject;
|
|
74
|
+
if (!o || !Array.isArray(e?.budgets)) return [];
|
|
75
|
+
let s = /* @__PURE__ */ new Map();
|
|
76
|
+
return e.budgets.filter((e) => e.costObject === o).map((e) => {
|
|
77
|
+
let l = s.get(e.policy) ?? 0;
|
|
78
|
+
s.set(e.policy, l + 1);
|
|
79
|
+
let u = p(e.object, t, i), d = [{
|
|
80
|
+
stats: e.day,
|
|
81
|
+
titleKey: n.todayTitle,
|
|
82
|
+
periodDescriptionKey: n.todayPeriodDescription
|
|
83
|
+
}, {
|
|
84
|
+
stats: e.month,
|
|
85
|
+
titleKey: n.thisMonthTitle,
|
|
86
|
+
periodDescriptionKey: n.thisMonthPeriodDescription
|
|
87
|
+
}];
|
|
88
|
+
return {
|
|
89
|
+
id: `${o}\u0000${e.policy}\u0000${l}`,
|
|
90
|
+
title: f(e),
|
|
91
|
+
...u == null ? {} : { coverageLabel: u },
|
|
92
|
+
cards: d.flatMap(({ stats: e, titleKey: n, periodDescriptionKey: i }) => a(e) ? [c(e, t(n), t(i), t, r(e.resetsAt))] : [])
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
};
|
|
65
96
|
//#endregion
|
|
66
|
-
export { n as USAGE_DATA_I18N_KEYS, l as mapUsageDataToDashboard };
|
|
97
|
+
export { u as BUDGET_DATA_I18N_KEYS, n as USAGE_DATA_I18N_KEYS, m as mapBudgetsToDashboard, l as mapUsageDataToDashboard };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { BudgetStatsDto, LimitStatsDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
+
/** DIAL Core's `spendingLimits.mode`, as the host's operator declares it. */
|
|
3
|
+
export declare enum SpendingLimitsMode {
|
|
4
|
+
/** Budgets are not presented; the role cost limit is the account limit. */
|
|
5
|
+
Off = "off",
|
|
6
|
+
/** Budgets are presented as not yet enforced; the role cost limit still decides. */
|
|
7
|
+
Shadow = "shadow",
|
|
8
|
+
/** Budgets limit model calls; the role cost limit applies to application calls only. */
|
|
9
|
+
Enforce = "enforce"
|
|
10
|
+
}
|
|
11
|
+
/** The parts of a user usage or limits response that decide the effective mode. */
|
|
12
|
+
export interface SpendingLimitsEvidence {
|
|
13
|
+
/** The cost object whose budgets the caller's model calls are charged to. */
|
|
14
|
+
costObject?: string;
|
|
15
|
+
/** Every budget that applies to the caller. */
|
|
16
|
+
budgets?: BudgetStatsDto[];
|
|
17
|
+
}
|
|
18
|
+
/** The top-level role cost stats `omitAccountCostStats` removes. */
|
|
19
|
+
export interface AccountCostStats {
|
|
20
|
+
/** The role cost limit and spend for the current minute. */
|
|
21
|
+
minuteCostStats?: LimitStatsDto;
|
|
22
|
+
/** The role cost limit and spend for the current day. */
|
|
23
|
+
dayCostStats?: LimitStatsDto;
|
|
24
|
+
/** The role cost limit and spend for the current week. */
|
|
25
|
+
weekCostStats?: LimitStatsDto;
|
|
26
|
+
/** The role cost limit and spend for the current month. */
|
|
27
|
+
monthCostStats?: LimitStatsDto;
|
|
28
|
+
}
|
|
29
|
+
/** Returns `value` as a `SpendingLimitsMode`, or `SpendingLimitsMode.Off` when it is not one. */
|
|
30
|
+
export declare const parseSpendingLimitsMode: (value: unknown) => SpendingLimitsMode;
|
|
31
|
+
/** Returns `configured` when `usage` carries a `budgets` array and a non-empty `costObject`, otherwise `SpendingLimitsMode.Off`. */
|
|
32
|
+
export declare const resolveSpendingLimitsMode: (configured: SpendingLimitsMode, usage: SpendingLimitsEvidence | undefined) => SpendingLimitsMode;
|
|
33
|
+
/** Returns a copy of `usage` without the four top-level role cost stats; every other field is kept. */
|
|
34
|
+
export declare const omitAccountCostStats: <T extends AccountCostStats>(usage: T) => Omit<T, keyof AccountCostStats>;
|
|
35
|
+
/** Returns `usage` without its role cost stats when the effective mode is `Enforce`, and `usage` unchanged otherwise. */
|
|
36
|
+
export declare const withholdAccountCostInEnforce: <T extends AccountCostStats & SpendingLimitsEvidence>(usage: T | undefined, configured: SpendingLimitsMode) => T | undefined;
|
|
37
|
+
//# sourceMappingURL=spending-limits-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spending-limits-mode.d.ts","sourceRoot":"","sources":["../../src/usage/spending-limits-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACd,MAAM,+BAA+B,CAAC;AAEvC,6EAA6E;AAC7E,oBAAY,kBAAkB;IAC5B,2EAA2E;IAC3E,GAAG,QAAQ;IACX,oFAAoF;IACpF,MAAM,WAAW;IACjB,wFAAwF;IACxF,OAAO,YAAY;CACpB;AAED,mFAAmF;AACnF,MAAM,WAAW,sBAAsB;IACrC,6EAA6E;IAC7E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+CAA+C;IAC/C,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;CAC5B;AAED,oEAAoE;AACpE,MAAM,WAAW,gBAAgB;IAC/B,4DAA4D;IAC5D,eAAe,CAAC,EAAE,aAAa,CAAC;IAChC,yDAAyD;IACzD,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,0DAA0D;IAC1D,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,2DAA2D;IAC3D,cAAc,CAAC,EAAE,aAAa,CAAC;CAChC;AAaD,iGAAiG;AACjG,eAAO,MAAM,uBAAuB,GAAI,OAAO,OAAO,KAAG,kBAG7B,CAAC;AAE7B,oIAAoI;AACpI,eAAO,MAAM,yBAAyB,GACpC,YAAY,kBAAkB,EAC9B,OAAO,sBAAsB,GAAG,SAAS,KACxC,kBAcF,CAAC;AAEF,uGAAuG;AACvG,eAAO,MAAM,oBAAoB,GAAI,CAAC,SAAS,gBAAgB,EAC7D,OAAO,CAAC,KACP,IAAI,CAAC,CAAC,EAAE,MAAM,gBAAgB,CAMhC,CAAC;AAEF,yHAAyH;AACzH,eAAO,MAAM,4BAA4B,GACvC,CAAC,SAAS,gBAAgB,GAAG,sBAAsB,EAEnD,OAAO,CAAC,GAAG,SAAS,EACpB,YAAY,kBAAkB,KAC7B,CAAC,GAAG,SASN,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/usage/spending-limits-mode.ts
|
|
2
|
+
var e = /* @__PURE__ */ function(e) {
|
|
3
|
+
return e.Off = "off", e.Shadow = "shadow", e.Enforce = "enforce", e;
|
|
4
|
+
}({}), t = [
|
|
5
|
+
"minuteCostStats",
|
|
6
|
+
"dayCostStats",
|
|
7
|
+
"weekCostStats",
|
|
8
|
+
"monthCostStats"
|
|
9
|
+
], n = new Set(Object.values(e)), r = (e) => typeof e == "string" && n.has(e) ? e : "off", i = (e, t) => !Array.isArray(t?.budgets) || typeof t.costObject != "string" || t.costObject.trim() === "" ? "off" : e, a = (e) => {
|
|
10
|
+
let n = { ...e };
|
|
11
|
+
for (let e of t) delete n[e];
|
|
12
|
+
return n;
|
|
13
|
+
}, o = (e, t) => e == null || i(t, e) !== "enforce" ? e : a(e);
|
|
14
|
+
//#endregion
|
|
15
|
+
export { e as SpendingLimitsMode, a as omitAccountCostStats, r as parseSpendingLimitsMode, i as resolveSpendingLimitsMode, o as withholdAccountCostInEnforce };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { DeploymentLimitsResponseDto, UserLimitStatsResponseDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The caller's account-wide cost budget and spend, plus the spending-limit
|
|
4
|
+
* evidence (`costObject`, `budgets`) that decides the effective spending
|
|
5
|
+
* limits mode: the top level of a user-usage response.
|
|
6
|
+
*/
|
|
7
|
+
export type AccountUsage = Pick<UserLimitStatsResponseDto, 'dayCostStats' | 'weekCostStats' | 'monthCostStats' | 'costObject' | 'budgets'>;
|
|
4
8
|
/**
|
|
5
9
|
* What the usage dial and the usage banner are mapped from. Each field has a
|
|
6
10
|
* single scope, so a deployment's figures are never read as the account's or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeploymentUsageLimits.d.ts","sourceRoot":"","sources":["../../../src/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AAGvC
|
|
1
|
+
{"version":3,"file":"useDeploymentUsageLimits.d.ts","sourceRoot":"","sources":["../../../src/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AAGvC;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,yBAAyB,EACzB,cAAc,GAAG,eAAe,GAAG,gBAAgB,GAAG,YAAY,GAAG,SAAS,CAC/E,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,0GAA0G;IAC1G,UAAU,EAAE,2BAA2B,GAAG,SAAS,CAAC;IACpD,2EAA2E;IAC3E,OAAO,EAAE,YAAY,GAAG,SAAS,CAAC;CACnC;AAED,8DAA8D;AAC9D,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF,kBAAkB,EAAE,CAClB,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAC1C,kFAAkF;IAClF,eAAe,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9C;AAED,wDAAwD;AACxD,MAAM,WAAW,8BAA8B;IAC7C,0DAA0D;IAC1D,OAAO,EAAE,kBAAkB,CAAC;IAC5B,iEAAiE;IACjE,SAAS,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,CAAC;IAClB,4DAA4D;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,wBAAwB,GACnC,cAAc,MAAM,GAAG,SAAS,EAChC,KAAK,cAAc,KAClB,8BA6EF,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UsageLimitBannerViewProps } from '@epam/ai-dial-conversation-input';
|
|
2
|
+
import { SpendingLimitsMode } from '../spending-limits-mode';
|
|
2
3
|
import { TranslateFn } from '../usage-reset-time';
|
|
3
4
|
import { UsageLimitsApi } from '../useDeploymentUsageLimits/useDeploymentUsageLimits';
|
|
4
5
|
/**
|
|
@@ -39,6 +40,8 @@ export interface UseUsageLimitBannerOptions {
|
|
|
39
40
|
activeLocale: string;
|
|
40
41
|
/** Translate function compatible with i18next's `TFunction`. */
|
|
41
42
|
t: TranslateFn;
|
|
43
|
+
/** The host's configured spending limits mode; in an effective `Enforce`, the account cost is not reported. Defaults to `SpendingLimitsMode.Off`. */
|
|
44
|
+
spendingLimitsMode?: SpendingLimitsMode;
|
|
42
45
|
}
|
|
43
46
|
/** The part of `UsageLimitBannerViewProps` the hook decides. */
|
|
44
47
|
export type UsageLimitBannerState = Pick<UsageLimitBannerViewProps, 'severity' | 'limitText' | 'reset' | 'onClose' | 'closeAriaLabel'>;
|
|
@@ -54,5 +57,5 @@ export interface UseUsageLimitBannerResult {
|
|
|
54
57
|
* tracks tab-lifetime dismissal. Spread `banner` onto `UsageLimitBannerView`
|
|
55
58
|
* from `@epam/ai-dial-conversation-input`.
|
|
56
59
|
*/
|
|
57
|
-
export declare const useUsageLimitBanner: ({ deploymentId, isGenerationInProgress, getDeploymentUsage, getAccountUsage, warningThresholdPercent, activeLocale, t, }: UseUsageLimitBannerOptions) => UseUsageLimitBannerResult;
|
|
60
|
+
export declare const useUsageLimitBanner: ({ deploymentId, isGenerationInProgress, getDeploymentUsage, getAccountUsage, warningThresholdPercent, activeLocale, t, spendingLimitsMode, }: UseUsageLimitBannerOptions) => UseUsageLimitBannerResult;
|
|
58
61
|
//# sourceMappingURL=useUsageLimitBanner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUsageLimitBanner.d.ts","sourceRoot":"","sources":["../../../src/usage/useUsageLimitBanner/useUsageLimitBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"useUsageLimitBanner.d.ts","sourceRoot":"","sources":["../../../src/usage/useUsageLimitBanner/useUsageLimitBanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,kBAAkB,EAEnB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,KAAK,WAAW,EAAyB,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EACL,KAAK,cAAc,EAEpB,MAAM,sDAAsD,CAAC;AAI9D;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB;IACjC,0EAA0E;;IAE1E,2EAA2E;;IAE3E,4EAA4E;;IAE5E,0EAA0E;;IAE1E,2EAA2E;;IAE3E,4EAA4E;;IAE5E,2CAA2C;;CAEnC,CAAC;AAkBX,6CAA6C;AAC7C,MAAM,WAAW,0BAA0B;IACzC,+CAA+C;IAC/C,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,+FAA+F;IAC/F,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,oEAAoE;IACpE,kBAAkB,EAAE,cAAc,CAAC,oBAAoB,CAAC,CAAC;IACzD,oEAAoE;IACpE,eAAe,EAAE,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACnD,oFAAoF;IACpF,uBAAuB,EAAE,MAAM,CAAC;IAChC,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAC;IACrB,gEAAgE;IAChE,CAAC,EAAE,WAAW,CAAC;IACf,qJAAqJ;IACrJ,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED,gEAAgE;AAChE,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,yBAAyB,EACzB,UAAU,GAAG,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,gBAAgB,CAClE,CAAC;AAEF,mDAAmD;AACnD,MAAM,WAAW,yBAAyB;IACxC,wIAAwI;IACxI,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,8IASjC,0BAA0B,KAAG,yBAoF/B,CAAC"}
|