@epam/ai-dial-chat-hooks 1.2.0-dev.141 → 1.2.0-dev.143

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.
@@ -1,14 +1,86 @@
1
+ import { formatCost as e } from "@epam/ai-dial-chat-shared";
2
+ import { CatalogLimitStatus as t } from "@epam/ai-dial-catalog";
1
3
  //#region src/catalog/map-deployment-limits-to-input.ts
2
- var e = (e) => {
3
- let t = e?.monthTokenStats;
4
- if (t == null || !Number.isFinite(t.total) || !Number.isFinite(t.used) || t.total <= 0 || t.total >= 2 ** 53 - 1) return;
5
- let n = Math.max(0, t.used);
4
+ var n = [
5
+ {
6
+ key: "dayTokenStats",
7
+ labelField: "periodDay"
8
+ },
9
+ {
10
+ key: "weekTokenStats",
11
+ labelField: "periodWeek"
12
+ },
13
+ {
14
+ key: "monthTokenStats",
15
+ labelField: "periodMonth"
16
+ }
17
+ ], r = [
18
+ {
19
+ key: "dayCostStats",
20
+ labelField: "periodDay"
21
+ },
22
+ {
23
+ key: "weekCostStats",
24
+ labelField: "periodWeek"
25
+ },
26
+ {
27
+ key: "monthCostStats",
28
+ labelField: "periodMonth"
29
+ }
30
+ ], i = 2 ** 53 - 1, a = .75, o = [1e6, 1e3], s = new Intl.NumberFormat(void 0, {
31
+ notation: "compact",
32
+ maximumFractionDigits: 1
33
+ }), c = new Intl.NumberFormat(void 0, { maximumFractionDigits: 2 }), l = (e) => {
34
+ let t = o.find((t) => Math.abs(e) >= t);
35
+ return t == null ? e : Math.trunc(e / t * 10) / 10 * t;
36
+ }, u = (e) => e != null && Number.isFinite(e.total) && Number.isFinite(e.used) && e.total > 0, d = (e) => e >= i, f = (e, t) => {
37
+ let n = t?.(e.resetsAt);
38
+ return n ? {
39
+ resetLabel: n.label,
40
+ resetIsoValue: n.isoValue,
41
+ resetAriaLabel: n.ariaLabel
42
+ } : {};
43
+ }, p = (e, t, n, r, i) => {
44
+ let a = Math.max(0, e.used), o = e.total, s = r.format(a), c = r.format(o);
6
45
  return {
7
- used: n,
8
- total: t.total,
9
- remaining: Math.max(0, t.total - n),
10
- usedPercent: Math.min(100, Math.round(n / t.total * 100))
46
+ label: t,
47
+ used: a,
48
+ total: o,
49
+ ...f(e, i),
50
+ usedLabel: s,
51
+ totalLabel: c,
52
+ valueLabel: n.formatValueLabel(s, c),
53
+ ariaLabel: n.formatProgressAriaLabel({
54
+ label: t,
55
+ used: r.formatFull(a),
56
+ total: r.formatFull(o)
57
+ })
11
58
  };
59
+ }, m = (e) => d(e.total) ? 0 : Math.max(e.used, 0) / e.total, h = (e) => m(e) >= a, g = (e) => e.reduce((e, n) => {
60
+ let r = m(n);
61
+ return r >= 1 ? t.LimitReached : r >= a && e !== t.LimitReached ? t.RunningLow : e;
62
+ }, void 0), _ = (e, t, n, r, i, a, o) => {
63
+ let s = t.flatMap((t) => {
64
+ let n = e[t.key];
65
+ return !u(n) || !h(n) ? [] : (o.push(n), [p(n, r[t.labelField], r, i, a)]);
66
+ });
67
+ return s.length > 0 ? {
68
+ label: n,
69
+ rows: s
70
+ } : void 0;
71
+ }, v = (t, i, a) => {
72
+ if (t == null) return;
73
+ let o = [], u = [_(t, n, i.tokenGroup, i, {
74
+ format: (e) => s.format(l(e)),
75
+ formatFull: (e) => c.format(e)
76
+ }, a, o), _(t, r, i.costGroup, i, {
77
+ format: e,
78
+ formatFull: e
79
+ }, a, o)].filter((e) => e != null);
80
+ return u.length > 0 ? {
81
+ groups: u,
82
+ status: g(o)
83
+ } : void 0;
12
84
  };
13
85
  //#endregion
14
- export { e as mapDeploymentLimitsToInput };
86
+ export { v as mapDeploymentLimitsToInput };
package/catalog.d.ts CHANGED
@@ -247,6 +247,28 @@ export declare enum CatalogPrimaryActionType {
247
247
  */
248
248
  export declare type CatalogPublishEntityType = 'model' | 'toolset' | 'application' | 'prompt' | 'skill';
249
249
 
250
+ /** Labels and formatter callbacks for the conversation-input limits mapping utility. */
251
+ export declare interface ConversationInputLimitsLabels {
252
+ /** Heading of the group listing the selected deployment's token limits. */
253
+ tokenGroup: string;
254
+ /** Heading of the group listing the caller's cost budget, which spans every deployment. */
255
+ costGroup: string;
256
+ /** Label for the current-UTC-day row, used by both groups. */
257
+ periodDay: string;
258
+ /** Label for the current-UTC-week row, used by both groups. */
259
+ periodWeek: string;
260
+ /** Label for the current-UTC-month row, used by both groups. */
261
+ periodMonth: string;
262
+ /** Formats the combined used/total display value for a capped row. */
263
+ formatValueLabel: (used: string, total: string) => string;
264
+ /** Formats the ARIA label for a capped progress row. */
265
+ formatProgressAriaLabel: (params: {
266
+ label: string;
267
+ used: string;
268
+ total: string;
269
+ }) => string;
270
+ }
271
+
250
272
  /**
251
273
  * Wraps the generated `PublishApi` in the positional-argument surface the
252
274
  * catalog and conversation publish flows call, so each host app re-exports one
@@ -369,6 +391,9 @@ export declare const filterHiddenOwnedItems: (items: readonly CatalogItem[], hid
369
391
  */
370
392
  export declare const findDeploymentByIdOrReference: (deployments: DeploymentItemDto[], idOrReference: string | null | undefined) => DeploymentItemDto | undefined;
371
393
 
394
+ /** Formats a raw `resetsAt` into display strings, or returns `undefined` when it cannot be formatted. */
395
+ declare type FormatResetTime = (resetsAt: string | undefined) => ResetTimeDisplay | undefined;
396
+
372
397
  /**
373
398
  * The publish folder a public catalog entity id sits in: the segments between
374
399
  * the `public` bucket and the entity name, decoded to the plain text the
@@ -406,8 +431,8 @@ export declare const mapDeploymentDetailsDtoToEntityDetails: (dto: DeploymentDet
406
431
  /** Maps a deployment limits DTO to display-ready catalog limits, or `undefined` when no qualifying stats exist. */
407
432
  export declare const mapDeploymentLimitsDtoToCatalogLimits: (dto: DeploymentLimitsResponseDto | undefined, labels: DeploymentLimitsLabels) => CatalogItemLimits | undefined;
408
433
 
409
- /** Maps the monthly deployment token limit to a display-ready value. */
410
- export declare const mapDeploymentLimitsToInput: (dto: DeploymentLimitsResponseDto | undefined) => MonthlyUsageLimit | undefined;
434
+ /** Maps a deployment's day, week, and month token limits and the caller's cost budget to display-ready rows, or `undefined` when none qualify. */
435
+ export declare const mapDeploymentLimitsToInput: (dto: DeploymentLimitsResponseDto | undefined, labels: ConversationInputLimitsLabels, formatResetTime?: FormatResetTime) => CatalogItemLimits | undefined;
411
436
 
412
437
  /** Maps a deployment listing row into the catalog UI's `CatalogItem` shape. */
413
438
  export declare const mapDeploymentToCatalogItem: (deployment: DeploymentItemDto, { favoriteIds, entityDetails, folderLabels, editableSchemaIds, isCustomAppsEditable, activeLocale, primaryLocale, resolveIconUrl, }: MapDeploymentToCatalogItemOptions) => CatalogItem;
@@ -589,18 +614,6 @@ export declare interface ModelSpecification {
589
614
  createdAt?: number;
590
615
  }
591
616
 
592
- /** Normalized monthly token usage consumed by the conversation input control. */
593
- export declare interface MonthlyUsageLimit {
594
- /** Normalized used-token count. */
595
- used: number;
596
- /** Configured monthly token limit. */
597
- total: number;
598
- /** Remaining monthly tokens, clamped to zero. */
599
- remaining: number;
600
- /** Monthly utilization percentage, clamped to 0–100. */
601
- usedPercent: number;
602
- }
603
-
604
617
  /** A skill resource URL split into the bucket and the path within it. */
605
618
  export declare interface ParsedSkillResourceUrl {
606
619
  /** DIAL Core bucket name. */
@@ -693,6 +706,23 @@ export declare const readSkillManifest: (response: Response) => Promise<string |
693
706
  */
694
707
  export declare const reconcileFilterTopics: (persistedTopics: ReadonlySet<string>, items: readonly CatalogItem[]) => Set<string>;
695
708
 
709
+ /**
710
+ * One reset time, already parsed and formatted by the host. Declared
711
+ * structurally here so this library never imports an application type; the
712
+ * host passes a value that satisfies this shape (e.g. `apps/chat`'s own
713
+ * `ResetTimeDisplay`).
714
+ */
715
+ declare interface ResetTimeDisplay {
716
+ /** Exclusive end of the period as an epoch ms value, for the host's boundary scheduling. */
717
+ resetsAtMs: number;
718
+ /** Machine-readable instant for a `<time dateTime>` attribute. */
719
+ isoValue: string;
720
+ /** Visible reset line. */
721
+ label: string;
722
+ /** Accessible expansion of the reset line. */
723
+ ariaLabel: string;
724
+ }
725
+
696
726
  /**
697
727
  * Resolves the primary action for a catalog item.
698
728
  *
package/index.d.ts CHANGED
@@ -819,6 +819,28 @@ export declare interface ConversationGenerationLifecycle {
819
819
  completeGeneration: (path: string, generationId: string) => void;
820
820
  }
821
821
 
822
+ /** Labels and formatter callbacks for the conversation-input limits mapping utility. */
823
+ export declare interface ConversationInputLimitsLabels {
824
+ /** Heading of the group listing the selected deployment's token limits. */
825
+ tokenGroup: string;
826
+ /** Heading of the group listing the caller's cost budget, which spans every deployment. */
827
+ costGroup: string;
828
+ /** Label for the current-UTC-day row, used by both groups. */
829
+ periodDay: string;
830
+ /** Label for the current-UTC-week row, used by both groups. */
831
+ periodWeek: string;
832
+ /** Label for the current-UTC-month row, used by both groups. */
833
+ periodMonth: string;
834
+ /** Formats the combined used/total display value for a capped row. */
835
+ formatValueLabel: (used: string, total: string) => string;
836
+ /** Formats the ARIA label for a capped progress row. */
837
+ formatProgressAriaLabel: (params: {
838
+ label: string;
839
+ used: string;
840
+ total: string;
841
+ }) => string;
842
+ }
843
+
822
844
  /** Stable reverse-lookup maps returned by `useConversationLookupMaps`. */
823
845
  export declare interface ConversationLookupMaps {
824
846
  /** Returns the raw context id for a panel-space conversation id, or `undefined` when not found. */
@@ -2153,8 +2175,8 @@ export declare const mapDeploymentDetailsDtoToEntityDetails: (dto: DeploymentDet
2153
2175
  /** Maps a deployment limits DTO to display-ready catalog limits, or `undefined` when no qualifying stats exist. */
2154
2176
  export declare const mapDeploymentLimitsDtoToCatalogLimits: (dto: DeploymentLimitsResponseDto | undefined, labels: DeploymentLimitsLabels) => CatalogItemLimits | undefined;
2155
2177
 
2156
- /** Maps the monthly deployment token limit to a display-ready value. */
2157
- export declare const mapDeploymentLimitsToInput: (dto: DeploymentLimitsResponseDto | undefined) => MonthlyUsageLimit | undefined;
2178
+ /** Maps a deployment's day, week, and month token limits and the caller's cost budget to display-ready rows, or `undefined` when none qualify. */
2179
+ export declare const mapDeploymentLimitsToInput: (dto: DeploymentLimitsResponseDto | undefined, labels: ConversationInputLimitsLabels, formatResetTime?: FormatResetTime) => CatalogItemLimits | undefined;
2158
2180
 
2159
2181
  /** Maps a deployment listing row into the catalog UI's `CatalogItem` shape. */
2160
2182
  export declare const mapDeploymentToCatalogItem: (deployment: DeploymentItemDto, { favoriteIds, entityDetails, folderLabels, editableSchemaIds, isCustomAppsEditable, activeLocale, primaryLocale, resolveIconUrl, }: MapDeploymentToCatalogItemOptions) => CatalogItem;
@@ -2601,18 +2623,6 @@ export declare interface ModelSpecification {
2601
2623
  createdAt?: number;
2602
2624
  }
2603
2625
 
2604
- /** Normalized monthly token usage consumed by the conversation input control. */
2605
- export declare interface MonthlyUsageLimit {
2606
- /** Normalized used-token count. */
2607
- used: number;
2608
- /** Configured monthly token limit. */
2609
- total: number;
2610
- /** Remaining monthly tokens, clamped to zero. */
2611
- remaining: number;
2612
- /** Monthly utilization percentage, clamped to 0–100. */
2613
- usedPercent: number;
2614
- }
2615
-
2616
2626
  /** Returns a skill relative path's final segment (its display name in the file tree). */
2617
2627
  export declare const nameFromPath: (path: string) => string;
2618
2628
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@epam/ai-dial-chat-hooks",
3
3
  "description": "Framework-level React hooks extracted from AI DIAL Chat for building custom chat interfaces",
4
- "version": "1.2.0-dev.141",
4
+ "version": "1.2.0-dev.143",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "main": "./index.js",
@@ -111,7 +111,7 @@
111
111
  }
112
112
  },
113
113
  "dependencies": {
114
- "@epam/ai-dial-chat-api-client": "1.2.0-dev.141",
114
+ "@epam/ai-dial-chat-api-client": "1.2.0-dev.143",
115
115
  "dompurify": "3.4.15",
116
116
  "fflate": "^0.8.3",
117
117
  "lru-cache": "^10.4.3",
@@ -120,22 +120,22 @@
120
120
  },
121
121
  "peerDependencies": {
122
122
  "react": "^19.2.8",
123
- "@epam/ai-dial-attachment-canvas": "1.2.0-dev.141",
124
- "@epam/ai-dial-attachment-input": "1.2.0-dev.141",
125
- "@epam/ai-dial-builder-form": "1.2.0-dev.141",
126
- "@epam/ai-dial-catalog": "1.2.0-dev.141",
127
- "@epam/ai-dial-chat-overlay": "1.2.0-dev.141",
128
- "@epam/ai-dial-chat-shared": "1.2.0-dev.141",
129
- "@epam/ai-dial-mcp-apps": "1.2.0-dev.141",
130
- "@epam/ai-dial-publish-panel": "1.2.0-dev.141",
131
- "@epam/ai-dial-quotations": "1.2.0-dev.141",
123
+ "@epam/ai-dial-attachment-canvas": "1.2.0-dev.143",
124
+ "@epam/ai-dial-attachment-input": "1.2.0-dev.143",
125
+ "@epam/ai-dial-builder-form": "1.2.0-dev.143",
126
+ "@epam/ai-dial-catalog": "1.2.0-dev.143",
127
+ "@epam/ai-dial-chat-overlay": "1.2.0-dev.143",
128
+ "@epam/ai-dial-chat-shared": "1.2.0-dev.143",
129
+ "@epam/ai-dial-mcp-apps": "1.2.0-dev.143",
130
+ "@epam/ai-dial-publish-panel": "1.2.0-dev.143",
131
+ "@epam/ai-dial-quotations": "1.2.0-dev.143",
132
132
  "@epam/ai-dial-react-file-manager": "^0.3.0-dev.4",
133
- "@epam/ai-dial-scheduled-tasks": "1.2.0-dev.141",
134
- "@epam/ai-dial-share": "1.2.0-dev.141",
135
- "@epam/ai-dial-skill-editor": "1.2.0-dev.141",
136
- "@epam/ai-dial-source-panel": "1.2.0-dev.141",
133
+ "@epam/ai-dial-scheduled-tasks": "1.2.0-dev.143",
134
+ "@epam/ai-dial-share": "1.2.0-dev.143",
135
+ "@epam/ai-dial-skill-editor": "1.2.0-dev.143",
136
+ "@epam/ai-dial-source-panel": "1.2.0-dev.143",
137
137
  "@epam/ai-dial-ui-kit": "^0.15.0-dev.18",
138
- "@epam/ai-dial-usage-dashboard": "1.2.0-dev.141",
138
+ "@epam/ai-dial-usage-dashboard": "1.2.0-dev.143",
139
139
  "@modelcontextprotocol/sdk": "^1.29.0",
140
140
  "@epam/pdf-highlighter-kit": "^0.0.19",
141
141
  "@mcp-ui/client": "^7.1.1"