@epam/ai-dial-chat-hooks 1.4.0-dev.83 → 1.4.0-dev.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/catalog/create-publish-api.d.ts +7 -1
  2. package/catalog/create-publish-api.d.ts.map +1 -1
  3. package/catalog/create-publish-api.js +5 -0
  4. package/catalog/resource-save-adapter.d.ts +7 -2
  5. package/catalog/resource-save-adapter.d.ts.map +1 -1
  6. package/catalog/resource-save-adapters.d.ts +32 -7
  7. package/catalog/resource-save-adapters.d.ts.map +1 -1
  8. package/catalog/resource-save-adapters.js +47 -41
  9. package/catalog/resource-save.d.ts +17 -9
  10. package/catalog/resource-save.d.ts.map +1 -1
  11. package/catalog/resource-save.js +34 -25
  12. package/catalog/save-destination-root.d.ts +12 -0
  13. package/catalog/save-destination-root.d.ts.map +1 -0
  14. package/catalog/save-destination-root.js +6 -0
  15. package/catalog/usePublishFolders/usePublishFolders.d.ts +8 -2
  16. package/catalog/usePublishFolders/usePublishFolders.d.ts.map +1 -1
  17. package/catalog/usePublishFolders/usePublishFolders.js +29 -29
  18. package/catalog/useResourceSavePanel/useResourceSavePanel.d.ts +7 -3
  19. package/catalog/useResourceSavePanel/useResourceSavePanel.d.ts.map +1 -1
  20. package/catalog/useResourceSavePanel/useResourceSavePanel.js +107 -97
  21. package/catalog.js +9 -8
  22. package/entry-points/usage-limits.d.ts +1 -0
  23. package/entry-points/usage-limits.d.ts.map +1 -1
  24. package/entry-points/utils.d.ts +3 -0
  25. package/entry-points/utils.d.ts.map +1 -1
  26. package/index.d.ts +4 -0
  27. package/index.d.ts.map +1 -1
  28. package/index.js +191 -187
  29. package/org-units/models.d.ts +3 -1
  30. package/org-units/models.d.ts.map +1 -1
  31. package/org-units/org-unit-guards.d.ts +64 -0
  32. package/org-units/org-unit-guards.d.ts.map +1 -0
  33. package/org-units/org-unit-guards.js +28 -0
  34. package/org-units/useFolderGuards/useFolderGuards.d.ts +31 -0
  35. package/org-units/useFolderGuards/useFolderGuards.d.ts.map +1 -0
  36. package/org-units/useFolderGuards/useFolderGuards.js +50 -0
  37. package/org-units/useOrgUnits/useOrgUnits.d.ts +18 -3
  38. package/org-units/useOrgUnits/useOrgUnits.d.ts.map +1 -1
  39. package/org-units/useOrgUnits/useOrgUnits.js +43 -23
  40. package/package.json +18 -18
  41. package/skill/useSkillEditorSubmit.d.ts +4 -1
  42. package/skill/useSkillEditorSubmit.d.ts.map +1 -1
  43. package/skill/useSkillEditorSubmit.js +125 -121
  44. package/usage/map-usage-data-to-dashboard.d.ts +22 -1
  45. package/usage/map-usage-data-to-dashboard.d.ts.map +1 -1
  46. package/usage/map-usage-data-to-dashboard.js +33 -2
  47. package/usage/spending-limits-mode.d.ts +37 -0
  48. package/usage/spending-limits-mode.d.ts.map +1 -0
  49. package/usage/spending-limits-mode.js +15 -0
  50. package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts +6 -2
  51. package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts.map +1 -1
  52. package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts +4 -1
  53. package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts.map +1 -1
  54. package/usage/useUsageLimitBanner/useUsageLimitBanner.js +55 -47
  55. package/usage-limits.js +6 -5
  56. package/usage.js +3 -3
  57. 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 { useCallback as u, useRef as d, useState as f } from "react";
5
- import { NotificationVariant as p } from "@epam/ai-dial-ui-kit";
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 m = (e, t, n) => JSON.stringify({
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
- }), h = {}, g = ({ bucket: g, isEditMode: _, files: v, filesContentRef: y, contentRevisions: b = h, frontmatterRef: x, loadedPathRef: S, etagRef: C, returnUrl: w, getCreateReturnUrl: T, refetchSkills: E, client: D, messages: O, onNavigate: k, onNotify: A, onSaveRequest: j }) => {
12
- let [M, N] = f({}), [P, F] = f(), [I, L] = f(!1), [R, z] = f(), [B, V] = f("idle"), H = d(null), U = d(null), W = u(async (n) => {
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
- N({ name: O.nameConflict });
16
+ I({ name: j.nameConflict });
16
17
  return;
17
18
  case 412:
18
- N({ name: O.nameConflict });
19
+ I({ name: j.nameConflict });
19
20
  return;
20
21
  case 413:
21
- F(O.archiveTooLarge);
22
+ R(j.archiveTooLarge);
22
23
  return;
23
24
  case 503:
24
- F(O.serviceUnavailable), L(!0);
25
+ R(j.serviceUnavailable), B(!0);
25
26
  return;
26
27
  case 400: {
27
28
  let { message: t } = await e(n);
28
- F(t ?? O.pathInvalid);
29
+ R(t ?? j.pathInvalid);
29
30
  return;
30
31
  }
31
32
  default: {
32
33
  let { traceId: t } = await e(n);
33
- F(O.saveError), A({
34
- variant: p.Error,
35
- message: O.saveError,
34
+ R(j.saveError), N({
35
+ variant: h.Error,
36
+ message: j.saveError,
36
37
  requestId: t
37
38
  });
38
39
  }
39
40
  }
40
- }, [O, A]), G = u(async (e) => {
41
+ }, [j, N]), J = d(async (e) => {
41
42
  let t = s(e.name);
42
43
  if (!t || !o(t)) {
43
- N({ name: O.nameInvalid });
44
+ I({ name: j.nameInvalid });
44
45
  return;
45
46
  }
46
- let n = m(e, v, b), a = H.current, c = a != null && a.fingerprint === n, l = t, u, d, f;
47
- c ? {skillManifest: u, filePaths: d, files: f} = a : (u = i(x.current, t, e.description, e.instructions), {filePaths: d, files: f} = r(v, y.current)), V("submitting"), H.current = {
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: g,
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 D.createSkill(g, l, u, d, f), await E(), V("success"), A({
57
- variant: p.Success,
58
- title: O.saveSuccessTitle,
59
- message: O.createSuccess(t)
60
- }), k(T?.(l) ?? w);
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
- V("failure"), await W(e);
63
+ W("failure"), await q(e);
63
64
  }
64
65
  }, [
65
- g,
66
66
  v,
67
- y,
68
67
  b,
69
68
  x,
70
- O,
71
- D,
72
- A,
69
+ S,
70
+ C,
71
+ j,
73
72
  k,
74
- w,
75
- T,
73
+ N,
74
+ M,
76
75
  E,
77
- W
78
- ]), K = u(async (e) => {
79
- let n = S.current, a = C.current;
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
- F(O.saveError);
82
+ R(j.saveError);
82
83
  return;
83
84
  }
84
- let o = i(x.current, e.name, e.description, e.instructions), { filePaths: s, files: c } = r(v, y.current);
85
- V("submitting");
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
- C.current = (await D.updateSkill(g, n, o, s, c, a)).etag ?? a, await E(), V("success"), A({
88
- variant: p.Success,
89
- title: O.updateSuccessTitle,
90
- message: O.updateSuccess(e.name)
91
- }), k(w);
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 (V("failure"), t(e) === 412) {
94
- z({ message: O.conflictMessage });
94
+ if (W("failure"), t(e) === 412) {
95
+ H({ message: j.conflictMessage });
95
96
  return;
96
97
  }
97
- await W(e);
98
+ await q(e);
98
99
  }
99
100
  }, [
100
- g,
101
101
  v,
102
- y,
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
- W
113
- ]), q = u(async (n, r) => {
112
+ O,
113
+ q
114
+ ]), X = d(async (n, r) => {
114
115
  let i = t(n);
115
- if (i === 412 && r) return z({ message: O.conflictMessage }), new l(O.conflictMessage);
116
- if (i === 409 || i === 412) return new l(O.nameConflict);
117
- if (i === 413) return new l(O.archiveTooLarge);
118
- if (i === 503) return new l(O.serviceUnavailable);
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 ?? O.pathInvalid);
122
+ return new l(t ?? j.pathInvalid);
122
123
  }
123
- return new l(O.saveError);
124
- }, [O]), J = u((e) => {
125
- let t = g, { filePaths: n, files: a } = r(v, y.current);
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
- N({ name: O.nameInvalid });
130
+ I({ name: j.nameInvalid });
130
131
  return;
131
132
  }
132
- let c = i(x.current, r, e.description, e.instructions);
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 D.createSkill(t, i, c, n, a);
140
+ await k.createSkill(t, i, c, n, a);
140
141
  } catch (e) {
141
- throw await q(e, !1);
142
+ throw await X(e, !1);
142
143
  }
143
- return await E().catch(() => void 0), { id: `skills/${t}/${i}` };
144
- }
144
+ return await O().catch(() => void 0), { id: `skills/${t}/${i}` };
145
+ },
146
+ ...Z
145
147
  };
146
148
  }
147
- let c = S.current, u = C.current;
149
+ let c = w.current, u = T.current;
148
150
  if (!c || !u) {
149
- F(O.saveError);
151
+ R(j.saveError);
150
152
  return;
151
153
  }
152
- let d = i(x.current, e.name, e.description, e.instructions);
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
- C.current = (await D.updateSkill(t, c, d, n, a, C.current ?? u)).etag ?? u;
160
+ T.current = (await k.updateSkill(t, c, d, n, a, T.current ?? u)).etag ?? u;
159
161
  } catch (e) {
160
- throw await q(e, !0);
162
+ throw await X(e, !0);
161
163
  }
162
- return await E().catch(() => void 0), { id: `skills/${t}/${c}` };
164
+ return await O().catch(() => void 0), { id: `skills/${t}/${c}` };
163
165
  },
164
166
  move: async (e, t) => {
165
- if (!D.moveSkill) throw new l(O.saveError);
167
+ if (!k.moveSkill) throw new l(j.saveError);
166
168
  try {
167
- return await D.moveSkill(c, t.join("/"));
169
+ return await k.moveSkill(c, t.join("/"));
168
170
  } catch (e) {
169
- throw await q(e, !1);
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
- y,
178
+ k,
179
+ Z,
180
+ T,
181
+ b,
179
182
  x,
180
- _,
181
- S,
183
+ C,
184
+ y,
185
+ w,
186
+ j,
182
187
  O,
183
- E,
184
- q
185
- ]), Y = u((e) => {
188
+ X
189
+ ]), ee = d((e) => {
186
190
  let t = c(e.instructions), r = a(e);
187
- N((e) => {
191
+ I((e) => {
188
192
  let i = { ...e };
189
193
  for (let e of Object.keys(n)) {
190
- let t = O.tooLong(n[e]);
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 === O.instructionsFrontmatter;
195
- t && !e ? i.instructions = O.instructionsFrontmatter : !t && e && delete 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
- }, [O]), X = u(async (e) => {
200
- if (B === "submitting" || !g) return;
203
+ }, [j]), $ = d(async (e) => {
204
+ if (U === "submitting" || !v) return;
201
205
  let t = {};
202
- e.name.trim() || (t.name = O.required), e.description.trim() || (t.description = O.required), e.instructions.trim() ? c(e.instructions) && (t.instructions = O.instructionsFrontmatter) : t.instructions = O.required;
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] ??= O.tooLong(n[e]);
205
- if (Object.keys(t).length > 0) N(t);
206
- else if (N({}), F(void 0), L(!1), z(void 0), U.current = e, j) {
207
- let t = J(e);
208
- t && j(t, e);
209
- } else _ ? await K(e) : await G(e);
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
- B,
212
- g,
213
- O,
214
- _,
215
+ U,
216
+ v,
215
217
  j,
216
- J,
217
- K,
218
- G
218
+ y,
219
+ P,
220
+ Q,
221
+ Y,
222
+ J
219
223
  ]);
220
224
  return {
221
- phase: B,
222
- errors: M,
223
- submitError: P,
224
- isSubmitErrorRetryable: I,
225
- retrySubmit: u(() => {
226
- let e = U.current;
227
- e != null && X(e);
228
- }, [X]),
229
- conflict: R,
230
- clearConflict: () => z(void 0),
231
- handleSubmit: X,
232
- handleValuesChange: Y
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 { g as useSkillEditorSubmit };
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,EAEV,yBAAyB,EAC1B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAExE,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"}
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
- /** The caller's account-wide cost budget and spend: the top level of a user-usage response. */
3
- export type AccountUsage = Pick<UserLimitStatsResponseDto, 'dayCostStats' | 'weekCostStats' | 'monthCostStats'>;
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,+FAA+F;AAC/F,MAAM,MAAM,YAAY,GAAG,IAAI,CAC7B,yBAAyB,EACzB,cAAc,GAAG,eAAe,GAAG,gBAAgB,CACpD,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
+ {"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;AAI1C,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;CAChB;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,0HAQjC,0BAA0B,KAAG,yBAqE/B,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"}