@epam/ai-dial-chat-hooks 1.3.0-dev.147 → 1.3.0-dev.152
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/map-deployment-limits-to-input.d.ts +4 -3
- package/catalog/map-deployment-limits-to-input.d.ts.map +1 -1
- package/catalog/map-deployment-limits-to-input.js +3 -4
- package/conversation/conversation-transfer/attachment-refs.d.ts +10 -2
- package/conversation/conversation-transfer/attachment-refs.d.ts.map +1 -1
- package/conversation/conversation-transfer/attachment-refs.js +31 -9
- package/conversation/conversation-transfer/export-conversation.d.ts +5 -1
- package/conversation/conversation-transfer/export-conversation.d.ts.map +1 -1
- package/conversation/conversation-transfer/export-conversation.js +19 -18
- package/conversation/conversation-transfer/import-conversation.d.ts +11 -6
- package/conversation/conversation-transfer/import-conversation.d.ts.map +1 -1
- package/conversation/conversation-transfer/import-conversation.js +63 -66
- package/conversation/create-chat-stream-api.d.ts +3 -2
- package/conversation/create-chat-stream-api.d.ts.map +1 -1
- package/conversation/create-chat-stream-api.js +1 -1
- package/conversation/useConversationExport/useConversationExport.js +52 -52
- package/package.json +16 -16
- package/usage/usage-banner-source.d.ts +6 -5
- package/usage/usage-banner-source.d.ts.map +1 -1
- package/usage/usage-banner-source.js +36 -12
- package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts +42 -18
- package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.d.ts.map +1 -1
- package/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.js +23 -28
- package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts +10 -8
- package/usage/useUsageLimitBanner/useUsageLimitBanner.d.ts.map +1 -1
- package/usage/useUsageLimitBanner/useUsageLimitBanner.js +28 -25
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CatalogItemLimits, UsageLimitProgressRow } from '@epam/ai-dial-catalog';
|
|
2
|
-
import {
|
|
2
|
+
import { LimitStatsDto } from '@epam/ai-dial-chat-api-client';
|
|
3
3
|
import { FormatResetTime } from '../usage/map-usage-data-to-dashboard';
|
|
4
|
+
import { UsageLimitsSources } from '../usage/useDeploymentUsageLimits/useDeploymentUsageLimits';
|
|
4
5
|
/** Labels and formatter callbacks for the conversation-input limits mapping utility. */
|
|
5
6
|
export interface ConversationInputLimitsLabels {
|
|
6
7
|
/** Heading of the group listing the selected deployment's token limits. */
|
|
@@ -23,6 +24,6 @@ export interface ConversationInputLimitsLabels {
|
|
|
23
24
|
}) => string;
|
|
24
25
|
}
|
|
25
26
|
export declare const buildResetFields: (stats: LimitStatsDto, formatResetTime: FormatResetTime | undefined) => Pick<UsageLimitProgressRow, "resetLabel" | "resetIsoValue" | "resetAriaLabel">;
|
|
26
|
-
/** Maps
|
|
27
|
-
export declare const mapDeploymentLimitsToInput: (
|
|
27
|
+
/** Maps the deployment's day, week, and month token limits (from `sources.deployment`) and the account cost budget (from `sources.account`) to display-ready rows, or `undefined` when none qualify. */
|
|
28
|
+
export declare const mapDeploymentLimitsToInput: (sources: UsageLimitsSources, labels: ConversationInputLimitsLabels, formatResetTime?: FormatResetTime) => CatalogItemLimits | undefined;
|
|
28
29
|
//# sourceMappingURL=map-deployment-limits-to-input.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"map-deployment-limits-to-input.d.ts","sourceRoot":"","sources":["../../src/catalog/map-deployment-limits-to-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EAEtB,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"map-deployment-limits-to-input.d.ts","sourceRoot":"","sources":["../../src/catalog/map-deployment-limits-to-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EAEtB,KAAK,qBAAqB,EAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAEV,aAAa,EACd,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4DAA4D,CAAC;AAErG,wFAAwF;AACxF,MAAM,WAAW,6BAA6B;IAC5C,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,kFAAkF;IAClF,SAAS,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAC;IACpB,sEAAsE;IACtE,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC1D,wDAAwD;IACxD,uBAAuB,EAAE,CAAC,MAAM,EAAE;QAChC,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,KAAK,MAAM,CAAC;CACd;AAgGD,eAAO,MAAM,gBAAgB,GAC3B,OAAO,aAAa,EACpB,iBAAiB,eAAe,GAAG,SAAS,KAC3C,IAAI,CACL,qBAAqB,EACrB,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAYlD,CAAC;AA4GF,wMAAwM;AACxM,eAAO,MAAM,0BAA0B,GACrC,SAAS,kBAAkB,EAC3B,QAAQ,6BAA6B,EACrC,kBAAkB,eAAe,KAChC,iBAAiB,GAAG,SAqCtB,CAAC"}
|
|
@@ -61,7 +61,7 @@ var n = [
|
|
|
61
61
|
return r >= 1 ? t.LimitReached : r >= a && e !== t.LimitReached ? t.RunningLow : e;
|
|
62
62
|
}, void 0), _ = (e, t, n, r, i, a, o) => {
|
|
63
63
|
let s = t.flatMap((t) => {
|
|
64
|
-
let n = e[t.key];
|
|
64
|
+
let n = e?.[t.key];
|
|
65
65
|
return !u(n) || !h(n) ? [] : (o.push(n), [p(n, r[t.labelField], r, i, a)]);
|
|
66
66
|
});
|
|
67
67
|
return s.length > 0 ? {
|
|
@@ -69,11 +69,10 @@ var n = [
|
|
|
69
69
|
rows: s
|
|
70
70
|
} : void 0;
|
|
71
71
|
}, v = (t, i, a) => {
|
|
72
|
-
|
|
73
|
-
let o = [], u = [_(t, n, i.tokenGroup, i, {
|
|
72
|
+
let o = [], u = [_(t.deployment, n, i.tokenGroup, i, {
|
|
74
73
|
format: (e) => s.format(l(e)),
|
|
75
74
|
formatFull: (e) => c.format(e)
|
|
76
|
-
}, a, o), _(t, r, i.costGroup, i, {
|
|
75
|
+
}, a, o), _(t.account, r, i.costGroup, i, {
|
|
77
76
|
format: e,
|
|
78
77
|
formatFull: e
|
|
79
78
|
}, a, o)].filter((e) => e != null);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Conversation } from '@epam/ai-dial-chat-shared';
|
|
1
|
+
import { Annotation, Conversation } from '@epam/ai-dial-chat-shared';
|
|
2
2
|
/**
|
|
3
3
|
* The reference fields shared by every attachment shape a conversation can
|
|
4
4
|
* carry — `MessageAttachment` on a message or a stage, and
|
|
@@ -27,13 +27,21 @@ export declare const splitFileIdAnchor: (url: string) => {
|
|
|
27
27
|
fileId: string;
|
|
28
28
|
anchor: string;
|
|
29
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Applies `mapAnnotation` to every readable entry of the citation pool,
|
|
32
|
+
* keeping unreadable entries and every other `customViewState` key as they
|
|
33
|
+
* are. Returns `conversation` itself when no entry changed, so a caller can
|
|
34
|
+
* tell by identity that the pool needed no work.
|
|
35
|
+
*/
|
|
36
|
+
export declare const mapAnnotationPool: (conversation: Conversation, mapAnnotation: (annotation: Annotation) => Annotation) => Conversation;
|
|
30
37
|
/** A unique DIAL file reference found in a conversation's messages. */
|
|
31
38
|
export interface AttachmentRef {
|
|
32
39
|
fileId: string;
|
|
33
40
|
}
|
|
34
41
|
/**
|
|
35
42
|
* Collects unique attachment references across all messages — message
|
|
36
|
-
* attachments, stage attachments, and citation source documents —
|
|
43
|
+
* attachments, stage attachments, and citation source documents — and the
|
|
44
|
+
* conversation-level citation pool, with any
|
|
37
45
|
* `#…` anchor stripped. The same file can be referenced more than once (by a
|
|
38
46
|
* later turn, by a stage and the message it belongs to, or by several
|
|
39
47
|
* citations), so dedupe by file id and process it only once.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachment-refs.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/attachment-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"attachment-refs.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/attachment-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAK1E;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,sFAAsF;IACtF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAeD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,MAAM,KACV;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CASlC,CAAC;AAqBF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,cAAc,YAAY,EAC1B,eAAe,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,KACpD,YAgBF,CAAC;AAEF,uEAAuE;AACvE,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;CAChB;AAgDD;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAChC,cAAc,YAAY,KACzB,aAAa,EAef,CAAC"}
|
|
@@ -10,7 +10,25 @@ var e = (e) => e.startsWith("files/"), t = /^#[\w.=%-]*$/, n = (e) => {
|
|
|
10
10
|
fileId: e.slice(0, n),
|
|
11
11
|
anchor: t.test(r) ? r : ""
|
|
12
12
|
};
|
|
13
|
-
}, r = (e,
|
|
13
|
+
}, r = (e) => typeof e == "object" && !!e, i = (e) => {
|
|
14
|
+
let t = e.customViewState?.annotations;
|
|
15
|
+
return Array.isArray(t) ? t.filter(r) : [];
|
|
16
|
+
}, a = (e, t) => {
|
|
17
|
+
let n = e.customViewState, i = n?.annotations;
|
|
18
|
+
if (!Array.isArray(i)) return e;
|
|
19
|
+
let a = !1, o = i.map((e) => {
|
|
20
|
+
if (!r(e)) return e;
|
|
21
|
+
let n = t(e);
|
|
22
|
+
return n !== e && (a = !0), n;
|
|
23
|
+
});
|
|
24
|
+
return a ? {
|
|
25
|
+
...e,
|
|
26
|
+
customViewState: {
|
|
27
|
+
...n,
|
|
28
|
+
annotations: o
|
|
29
|
+
}
|
|
30
|
+
} : e;
|
|
31
|
+
}, o = (e, t) => {
|
|
14
32
|
for (let n of e.messages) {
|
|
15
33
|
let e = n.custom_content;
|
|
16
34
|
if (e) {
|
|
@@ -22,15 +40,19 @@ var e = (e) => e.startsWith("files/"), t = /^#[\w.=%-]*$/, n = (e) => {
|
|
|
22
40
|
}
|
|
23
41
|
}
|
|
24
42
|
}
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
for (let n of i(e)) {
|
|
44
|
+
let e = n.body?.source?.attachment;
|
|
45
|
+
e && t(e);
|
|
46
|
+
}
|
|
47
|
+
}, s = (t) => {
|
|
48
|
+
let r = /* @__PURE__ */ new Set(), i = (t) => {
|
|
27
49
|
if (t == null) return;
|
|
28
|
-
let { fileId:
|
|
29
|
-
e(
|
|
50
|
+
let { fileId: i } = n(t);
|
|
51
|
+
e(i) && r.add(i);
|
|
30
52
|
};
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
}), Array.from(
|
|
53
|
+
return o(t, (e) => {
|
|
54
|
+
i(e.url), i(e.reference_url);
|
|
55
|
+
}), Array.from(r, (e) => ({ fileId: e }));
|
|
34
56
|
};
|
|
35
57
|
//#endregion
|
|
36
|
-
export {
|
|
58
|
+
export { s as collectAttachmentRefs, a as mapAnnotationPool, n as splitFileIdAnchor };
|
|
@@ -2,7 +2,11 @@ import { Conversation, ExportFolder, ExportFormat } from '@epam/ai-dial-chat-sha
|
|
|
2
2
|
import { ExportFileNameKind } from './types';
|
|
3
3
|
/** Placeholder app name used in every export file name — this branch has no app display-name config yet. */
|
|
4
4
|
export declare const EXPORT_APP_NAME = "ai_dial";
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Returns the conversation with every message-, stage- and citation-level
|
|
7
|
+
* attachment reference removed, including the source documents of the
|
|
8
|
+
* conversation-level citation pool.
|
|
9
|
+
*/
|
|
6
10
|
export declare const stripConversationAttachments: (conversation: Conversation) => Conversation;
|
|
7
11
|
export declare const buildExportEnvelope: (conversations: Conversation[], folders?: ExportFolder[]) => ExportFormat;
|
|
8
12
|
export declare const serializeExportEnvelope: (envelope: ExportFormat) => Blob;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export-conversation.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/export-conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EACZ,YAAY,EACZ,YAAY,EAGb,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"export-conversation.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/export-conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EACZ,YAAY,EACZ,YAAY,EAGb,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAE7C,4GAA4G;AAC5G,eAAO,MAAM,eAAe,YAAY,CAAC;AA8CzC;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,GACvC,cAAc,YAAY,KACzB,YAOA,CAAC;AAEJ,eAAO,MAAM,mBAAmB,GAC9B,eAAe,YAAY,EAAE,EAC7B,UAAS,YAAY,EAAO,KAC3B,YAID,CAAC;AAEH,eAAO,MAAM,uBAAuB,GAAI,UAAU,YAAY,KAAG,IACY,CAAC;AAQ9E,eAAO,MAAM,mBAAmB,GAC9B,MAAM,kBAAkB,EACxB,SAAS,MAAM,EACf,OAAM,IAAiB,KACtB,MACyE,CAAC"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { mapAnnotationPool as e } from "./attachment-refs.js";
|
|
2
|
+
import { formatDateYMD as t } from "./date.js";
|
|
3
|
+
import { ExportFileNameKind as n } from "./types.js";
|
|
3
4
|
//#region src/conversation/conversation-transfer/export-conversation.ts
|
|
4
|
-
var
|
|
5
|
+
var r = "ai_dial", i = (e) => e.map(({ attachments: e, ...t }) => t), a = (e) => {
|
|
5
6
|
if (e.body?.source == null) return e;
|
|
6
7
|
let { source: t, ...n } = e.body;
|
|
7
8
|
return {
|
|
8
9
|
...e,
|
|
9
10
|
body: n
|
|
10
11
|
};
|
|
11
|
-
}
|
|
12
|
+
}, o = (e) => e.map(a), s = (e) => {
|
|
12
13
|
let t = e.custom_content;
|
|
13
14
|
if (!t) return e;
|
|
14
|
-
let { attachments: n, stages:
|
|
15
|
-
if (n == null &&
|
|
15
|
+
let { attachments: n, stages: r, annotations: a, ...s } = t;
|
|
16
|
+
if (n == null && r == null && a == null) return e;
|
|
16
17
|
let c = {
|
|
17
18
|
...s,
|
|
18
|
-
...
|
|
19
|
-
...
|
|
19
|
+
...r ? { stages: i(r) } : {},
|
|
20
|
+
...a ? { annotations: o(a) } : {}
|
|
20
21
|
};
|
|
21
22
|
if (Object.keys(c).length > 0) return {
|
|
22
23
|
...e,
|
|
@@ -24,17 +25,17 @@ var n = "ai_dial", r = (e) => e.map(({ attachments: e, ...t }) => t), i = (e) =>
|
|
|
24
25
|
};
|
|
25
26
|
let { custom_content: l, ...u } = e;
|
|
26
27
|
return u;
|
|
27
|
-
},
|
|
28
|
-
...
|
|
29
|
-
messages:
|
|
30
|
-
}),
|
|
28
|
+
}, c = (t) => e({
|
|
29
|
+
...t,
|
|
30
|
+
messages: t.messages.map(s)
|
|
31
|
+
}, a), l = (e, t = []) => ({
|
|
31
32
|
version: 5,
|
|
32
33
|
history: e,
|
|
33
34
|
folders: t
|
|
34
|
-
}),
|
|
35
|
-
[
|
|
36
|
-
[
|
|
37
|
-
[
|
|
38
|
-
},
|
|
35
|
+
}), u = (e) => new Blob([JSON.stringify(e, null, 2)], { type: "application/json" }), d = {
|
|
36
|
+
[n.SingleConversation]: "json",
|
|
37
|
+
[n.SingleConversationWithAttachments]: "dial",
|
|
38
|
+
[n.AllConversationsHistory]: "json"
|
|
39
|
+
}, f = (e, n, r = /* @__PURE__ */ new Date()) => `${t(r)}_${n}_${e}.${d[e]}`;
|
|
39
40
|
//#endregion
|
|
40
|
-
export {
|
|
41
|
+
export { r as EXPORT_APP_NAME, l as buildExportEnvelope, f as buildExportFileName, u as serializeExportEnvelope, c as stripConversationAttachments };
|
|
@@ -52,12 +52,13 @@ export interface RewrittenAttachmentTarget {
|
|
|
52
52
|
title?: string;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* Rewrites every attachment reference a
|
|
56
|
-
* `custom_content.attachments`, the attachments of each
|
|
57
|
-
* the source document of each citation
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
55
|
+
* Rewrites every attachment reference a conversation carries — each
|
|
56
|
+
* message's own `custom_content.attachments`, the attachments of each
|
|
57
|
+
* execution stage, the source document of each citation, and the source
|
|
58
|
+
* document of each entry in the conversation-level citation pool — from an
|
|
59
|
+
* old file id to its new uploaded location, and its `title` when the target
|
|
60
|
+
* carries a renamed one. References not present in `targetMap` are left
|
|
61
|
+
* untouched (immutable — returns a new conversation).
|
|
61
62
|
*/
|
|
62
63
|
export declare const rewriteAttachmentUrls: (conversation: Conversation, targetMap: Map<string, RewrittenAttachmentTarget>) => Conversation;
|
|
63
64
|
/**
|
|
@@ -72,6 +73,10 @@ export declare const rewriteAttachmentUrls: (conversation: Conversation, targetM
|
|
|
72
73
|
* user shared with the importing user is dropped too: nothing here can tell
|
|
73
74
|
* it apart from one they never had access to.
|
|
74
75
|
*
|
|
76
|
+
* The conversation-level citation pool is covered as well: a message
|
|
77
|
+
* citation stripped of its source would otherwise resolve its `<cit>` from
|
|
78
|
+
* the pool's copy, which still names the foreign file.
|
|
79
|
+
*
|
|
75
80
|
* Returns the conversation (unchanged when nothing was foreign) and the name
|
|
76
81
|
* of every dropped file, for the skipped-attachment warning.
|
|
77
82
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-conversation.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/import-conversation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAGb,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"import-conversation.d.ts","sourceRoot":"","sources":["../../../src/conversation/conversation-transfer/import-conversation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,YAAY,EAEZ,YAAY,EAGb,MAAM,2BAA2B,CAAC;AAOnC,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,qBAAqB,CAAC;AAG7B,oFAAoF;AACpF,qBAAa,4BAA6B,SAAQ,KAAK;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAOD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,MAAM,MAAM,KAAG,YA2BlD,CAAC;AAgGF,MAAM,WAAW,qBAAqB;IACpC,wGAAwG;IACxG,YAAY,EAAE,YAAY,CAAC;IAC3B,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;CACjB;AAgBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,cAAc,YAAY,EAC1B,QAAQ,MAAM,KACb,qBAmDF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,cAAc,YAAY,KACzB,MAAM,GAAG,SAMX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,EAAE,KAAG,MACV,CAAC;AAE9C,qGAAqG;AACrG,MAAM,WAAW,yBAAyB;IACxC,0EAA0E;IAC1E,GAAG,EAAE,MAAM,CAAC;IACZ,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA8HD;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,cAAc,YAAY,EAC1B,WAAW,GAAG,CAAC,MAAM,EAAE,yBAAyB,CAAC,KAChD,YAIA,CAAC;AA4EJ;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,yBAAyB,GACpC,cAAc,YAAY,EAC1B,QAAQ,MAAM,KACb;IAAE,YAAY,EAAE,YAAY,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CA+DtD,CAAC;AAMF,0GAA0G;AAC1G,MAAM,WAAW,uBAAuB;IACtC,yGAAyG;IACzG,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,EAAE,UAAU,CAAC;IAClB,+FAA+F;IAC/F,gBAAgB,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,SAAS,EAAE,mBAAmB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,cAAc,YAAY,EAC1B,iBAAiB,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,EACxC,WAAW,mBAAmB,KAC7B;IAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CA2B3D,CAAC"}
|
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import { collectAttachmentRefs as e,
|
|
2
|
-
import { resolveDialFileBucketAndPath as
|
|
3
|
-
import { PUBLIC_BUCKET as
|
|
1
|
+
import { collectAttachmentRefs as e, mapAnnotationPool as t, splitFileIdAnchor as n } from "./attachment-refs.js";
|
|
2
|
+
import { resolveDialFileBucketAndPath as r } from "./dial-file-resolve.js";
|
|
3
|
+
import { PUBLIC_BUCKET as i, generateUUID as a, sanitizeConversationName as o, stripTrailingDots as s, truncateToUtf8Bytes as c } from "@epam/ai-dial-chat-shared";
|
|
4
4
|
//#region src/conversation/conversation-transfer/import-conversation.ts
|
|
5
|
-
var
|
|
5
|
+
var l = class extends Error {
|
|
6
6
|
constructor(e) {
|
|
7
7
|
super(e), this.name = "UnsupportedImportFormatError";
|
|
8
8
|
}
|
|
9
|
-
},
|
|
9
|
+
}, u = (e) => typeof e == "object" && !!e, d = 5, f = (e) => {
|
|
10
10
|
let t;
|
|
11
11
|
try {
|
|
12
12
|
t = JSON.parse(e);
|
|
13
13
|
} catch {
|
|
14
|
-
throw new
|
|
14
|
+
throw new l("Import file is not valid JSON");
|
|
15
15
|
}
|
|
16
|
-
if (!
|
|
16
|
+
if (!u(t) || t.version !== d || !Array.isArray(t.history)) throw new l("Import file is not a supported export format");
|
|
17
17
|
let n = Array.isArray(t.folders) ? t.folders : [];
|
|
18
18
|
return {
|
|
19
|
-
version:
|
|
19
|
+
version: d,
|
|
20
20
|
history: t.history,
|
|
21
21
|
folders: n
|
|
22
22
|
};
|
|
23
|
-
},
|
|
24
|
-
let t = e.replace(/\r\n|\r/g, "\n").split("\n").map((e) =>
|
|
25
|
-
return
|
|
26
|
-
},
|
|
27
|
-
let r = e.split(
|
|
28
|
-
if (r.length < 2) return [e,
|
|
29
|
-
let
|
|
23
|
+
}, p = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, m = "__", h = 255, g = "applications", _ = /[-+]/, v = /^\d+$/, y = (e) => e ? e.split(_)[0].split(".").every((e) => v.test(e)) : !1, b = (e) => {
|
|
24
|
+
let t = e.replace(/\r\n|\r/g, "\n").split("\n").map((e) => o(e).trim()).filter(Boolean)[0] ?? "";
|
|
25
|
+
return s(c(t, h)).trimEnd();
|
|
26
|
+
}, x = (e, t, n) => {
|
|
27
|
+
let r = e.split(m);
|
|
28
|
+
if (r.length < 2) return [e, a()].join(m);
|
|
29
|
+
let i = n && y(r[1]) ? r.slice(0, 2) : r.slice(0, 1), o = i.length > 1 ? p.test(r[r.length - 1]) : r.length >= 3, s = r.slice(i.length, o ? -1 : void 0).join(m);
|
|
30
30
|
return [
|
|
31
|
-
...
|
|
31
|
+
...i,
|
|
32
32
|
t || s,
|
|
33
|
-
|
|
34
|
-
].join(
|
|
35
|
-
},
|
|
36
|
-
let n =
|
|
33
|
+
a()
|
|
34
|
+
].join(m);
|
|
35
|
+
}, S = "conversations/", C = (e) => e.startsWith(S) ? e.slice(14) : e, w = (e, t) => {
|
|
36
|
+
let n = C(e.id), r = n.split("/"), i = C(e.folderId), a = r[0], o = i.startsWith(`${a}/`) ? i.slice(a.length + 1).split("/").filter(Boolean) : [], s = r.slice(1).slice(o.length), c = s.slice(0, -1), l = s.at(-1) ?? r.at(-1) ?? n, u = [...o, ...c], d = b(e.name), f = x(l, d, u[0] === g), p = [...u, f].join("/"), m = o.length ? `${t}/${o.join("/")}` : t;
|
|
37
37
|
return {
|
|
38
38
|
conversation: {
|
|
39
39
|
...e,
|
|
@@ -43,18 +43,18 @@ var c = class extends Error {
|
|
|
43
43
|
},
|
|
44
44
|
subPath: p
|
|
45
45
|
};
|
|
46
|
-
},
|
|
47
|
-
let t =
|
|
46
|
+
}, T = (e) => {
|
|
47
|
+
let t = C(e.folderId).split("/").filter(Boolean).slice(1);
|
|
48
48
|
return t.length ? t.join(" / ") : void 0;
|
|
49
|
-
},
|
|
49
|
+
}, E = (e) => e.map((e) => `"${e}"`).join(", "), D = (e, t) => {
|
|
50
50
|
if (!e) return;
|
|
51
|
-
let { fileId: r, anchor: i } =
|
|
51
|
+
let { fileId: r, anchor: i } = n(e), a = t.get(r);
|
|
52
52
|
if (a != null) return {
|
|
53
53
|
...a,
|
|
54
54
|
url: `${a.url}${i}`
|
|
55
55
|
};
|
|
56
|
-
},
|
|
57
|
-
let n =
|
|
56
|
+
}, O = (e, t) => {
|
|
57
|
+
let n = D(e.url, t), r = D(e.reference_url, t);
|
|
58
58
|
if (n == null && r == null) return;
|
|
59
59
|
let i = n?.title ?? r?.title;
|
|
60
60
|
return {
|
|
@@ -62,19 +62,19 @@ var c = class extends Error {
|
|
|
62
62
|
...r == null ? {} : { reference_url: r.url },
|
|
63
63
|
...i == null ? {} : { title: i }
|
|
64
64
|
};
|
|
65
|
-
},
|
|
65
|
+
}, k = (e, t) => e.map((e) => e.attachments?.length ? {
|
|
66
66
|
...e,
|
|
67
67
|
attachments: e.attachments.map((e) => {
|
|
68
|
-
let n =
|
|
68
|
+
let n = O(e, t);
|
|
69
69
|
return n ? {
|
|
70
70
|
...e,
|
|
71
71
|
...n
|
|
72
72
|
} : e;
|
|
73
73
|
})
|
|
74
|
-
} : e),
|
|
74
|
+
} : e), A = (e, t) => {
|
|
75
75
|
let n = e.body?.source;
|
|
76
76
|
if (n?.attachment == null) return e;
|
|
77
|
-
let r =
|
|
77
|
+
let r = O(n.attachment, t);
|
|
78
78
|
return r == null ? e : {
|
|
79
79
|
...e,
|
|
80
80
|
body: {
|
|
@@ -88,7 +88,7 @@ var c = class extends Error {
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
|
-
}
|
|
91
|
+
}, j = (e, t) => e.map((e) => A(e, t)), M = (e, t) => ({
|
|
92
92
|
...e,
|
|
93
93
|
messages: e.messages.map((e) => {
|
|
94
94
|
let n = e.custom_content;
|
|
@@ -99,31 +99,31 @@ var c = class extends Error {
|
|
|
99
99
|
custom_content: {
|
|
100
100
|
...n,
|
|
101
101
|
...r?.length ? { attachments: r.map((e) => {
|
|
102
|
-
let n =
|
|
102
|
+
let n = O(e, t);
|
|
103
103
|
return n ? {
|
|
104
104
|
...e,
|
|
105
105
|
...n
|
|
106
106
|
} : e;
|
|
107
107
|
}) } : {},
|
|
108
|
-
...i?.length ? { stages:
|
|
109
|
-
...a?.length ? { annotations:
|
|
108
|
+
...i?.length ? { stages: k(i, t) } : {},
|
|
109
|
+
...a?.length ? { annotations: j(a, t) } : {}
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
})
|
|
113
|
-
}),
|
|
113
|
+
}), N = (e, n) => t(M(e, n), (e) => A(e, n)), P = (e, t) => {
|
|
114
114
|
if (!e) return;
|
|
115
|
-
let a = n(
|
|
116
|
-
if (a && a.bucket !==
|
|
117
|
-
},
|
|
118
|
-
let r =
|
|
115
|
+
let a = r(n(e).fileId);
|
|
116
|
+
if (a && a.bucket !== t && a.bucket !== i) return a.path.split("/").pop() || a.path;
|
|
117
|
+
}, F = (e, t, n) => e.flatMap((e) => {
|
|
118
|
+
let r = P(e.url, t);
|
|
119
119
|
if (r != null) return n.push(r), [];
|
|
120
|
-
let i =
|
|
120
|
+
let i = P(e.reference_url, t);
|
|
121
121
|
if (i == null) return [e];
|
|
122
122
|
n.push(i);
|
|
123
123
|
let { reference_url: a, reference_type: o, ...s } = e;
|
|
124
124
|
return s.url == null && s.data == null ? [] : [s];
|
|
125
|
-
}),
|
|
126
|
-
let r = e.body, i =
|
|
125
|
+
}), I = (e, t, n) => {
|
|
126
|
+
let r = e.body, i = P(r?.source?.attachment?.url, t);
|
|
127
127
|
if (r == null || i == null) return e;
|
|
128
128
|
n.push(i);
|
|
129
129
|
let { source: a, ...o } = r;
|
|
@@ -131,43 +131,40 @@ var c = class extends Error {
|
|
|
131
131
|
...e,
|
|
132
132
|
body: o
|
|
133
133
|
};
|
|
134
|
-
}
|
|
135
|
-
let
|
|
136
|
-
let
|
|
137
|
-
if (!
|
|
138
|
-
let { attachments: i, stages: a, annotations: o } =
|
|
134
|
+
}, L = (e, t, n) => e.map((e) => I(e, t, n)), R = (e, n) => {
|
|
135
|
+
let r = [], i = e.messages.map((e) => {
|
|
136
|
+
let t = e.custom_content;
|
|
137
|
+
if (!t) return e;
|
|
138
|
+
let { attachments: i, stages: a, annotations: o } = t;
|
|
139
139
|
return !i?.length && !a?.length && !o?.length ? e : {
|
|
140
140
|
...e,
|
|
141
141
|
custom_content: {
|
|
142
|
-
...
|
|
143
|
-
...i?.length ? { attachments:
|
|
142
|
+
...t,
|
|
143
|
+
...i?.length ? { attachments: F(i, n, r) } : {},
|
|
144
144
|
...a?.length ? { stages: a.map((e) => e.attachments?.length ? {
|
|
145
145
|
...e,
|
|
146
|
-
attachments:
|
|
146
|
+
attachments: F(e.attachments, n, r)
|
|
147
147
|
} : e) } : {},
|
|
148
|
-
...o?.length ? { annotations:
|
|
148
|
+
...o?.length ? { annotations: L(o, n, r) } : {}
|
|
149
149
|
}
|
|
150
150
|
};
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
droppedNames:
|
|
158
|
-
} : {
|
|
159
|
-
conversation: e,
|
|
160
|
-
droppedNames: n
|
|
151
|
+
}), a = r.length ? {
|
|
152
|
+
...e,
|
|
153
|
+
messages: i
|
|
154
|
+
} : e;
|
|
155
|
+
return {
|
|
156
|
+
conversation: t(a, (e) => I(e, n, r)),
|
|
157
|
+
droppedNames: r
|
|
161
158
|
};
|
|
162
|
-
},
|
|
159
|
+
}, z = (e) => e.split("/").pop() || e, B = (t, n, i) => {
|
|
163
160
|
let a = [], o = [];
|
|
164
161
|
for (let s of e(t)) {
|
|
165
|
-
let e =
|
|
162
|
+
let e = r(s.fileId);
|
|
166
163
|
if (!e) {
|
|
167
|
-
o.push(
|
|
164
|
+
o.push(z(s.fileId));
|
|
168
165
|
continue;
|
|
169
166
|
}
|
|
170
|
-
let t = e.path.split("/").pop() ?? e.path, c =
|
|
167
|
+
let t = e.path.split("/").pop() ?? e.path, c = n.get(e.path);
|
|
171
168
|
c ? a.push({
|
|
172
169
|
fileId: s.fileId,
|
|
173
170
|
bytes: c,
|
|
@@ -181,4 +178,4 @@ var c = class extends Error {
|
|
|
181
178
|
};
|
|
182
179
|
};
|
|
183
180
|
//#endregion
|
|
184
|
-
export {
|
|
181
|
+
export { l as UnsupportedImportFormatError, R as dropForeignAttachmentRefs, E as formatQuotedNameList, T as getFolderBreadcrumb, f as parseImportEnvelope, B as planAttachmentUploads, w as rebaseConversationId, N as rewriteAttachmentUrls };
|
|
@@ -27,8 +27,9 @@ export declare class GenerationConflictError extends Error {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Reported through `onError` when DIAL Core itself signals a failure with an
|
|
30
|
-
* in-band `{ error: { message } }` SSE chunk. Its `message`
|
|
31
|
-
* intended for the user
|
|
30
|
+
* in-band `{ error: { message, display_message? } }` SSE chunk. Its `message`
|
|
31
|
+
* is upstream text intended for the user — the chunk's `display_message` when
|
|
32
|
+
* present, else its `message` — unlike a transport failure (failed `fetch`, non-OK
|
|
32
33
|
* status, broken stream), whose message is technical detail. A custom
|
|
33
34
|
* transport raises this for any user-facing upstream error text.
|
|
34
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-chat-stream-api.d.ts","sourceRoot":"","sources":["../../src/conversation/create-chat-stream-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAOnC,mFAAmF;AACnF,eAAO,MAAM,4CAA4C,0IACgF,CAAC;AAE1I,yFAAyF;AACzF,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,QAAQ,CAAC,IAAI,8BAA8B;IAElD,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;gBACS,MAAM,CAAC,EAAE,MAAM;CAK5B;AAED,sFAAsF;AACtF,eAAO,MAAM,mCAAmC,iIACgF,CAAC;AAEjI;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,GAAE,MAA4C;CAIlE;AAED
|
|
1
|
+
{"version":3,"file":"create-chat-stream-api.d.ts","sourceRoot":"","sources":["../../src/conversation/create-chat-stream-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACZ,MAAM,2BAA2B,CAAC;AAOnC,mFAAmF;AACnF,eAAO,MAAM,4CAA4C,0IACgF,CAAC;AAE1I,yFAAyF;AACzF,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,QAAQ,CAAC,IAAI,8BAA8B;IAElD,iFAAiF;IACjF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;gBACS,MAAM,CAAC,EAAE,MAAM;CAK5B;AAED,sFAAsF;AACtF,eAAO,MAAM,mCAAmC,iIACgF,CAAC;AAEjI;;;;;;GAMG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,GAAE,MAA4C;CAIlE;AAED;;;;;;;GAOG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;GAOG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;gBACnC,KAAK,CAAC,EAAE,OAAO;CAI5B;AAED,kEAAkE;AAClE,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,MAAM,EAAE,MAAM;CAK3B;AAMD,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAErD,qFAAqF;AACrF,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;IACtC,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,0FAA0F;AAC1F,MAAM,WAAW,uBAAuB;IACtC,yEAAyE;IACzE,YAAY,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IAClC,2DAA2D;IAC3D,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC7C,iFAAiF;IACjF,mBAAmB,EAAE,MAAM,CAAC;IAC5B,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACvC,wFAAwF;IACxF,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AA8GD,wFAAwF;AACxF,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,CAChB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,2BAA2B,EACpC,aAAa,CAAC,EAAE,oBAAoB,EACpC,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,yBAAyB,EAChC,YAAY,CAAC,EAAE,MAAM,EACrB,eAAe,CAAC,EAAE,MAAM,KACrB,IAAI,CAAC;IACV,cAAc,EAAE,CAAC,GAAG,EAAE;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AAED;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,MAAM,uBAAuB,KAC5B,aAoKF,CAAC"}
|
|
@@ -48,7 +48,7 @@ var e = { "Content-Type": "application/json" }, t = 409, n = "The response could
|
|
|
48
48
|
if (a !== "[DONE]") try {
|
|
49
49
|
let e = JSON.parse(a);
|
|
50
50
|
if (e.error) {
|
|
51
|
-
n(e.error.type === r.type ? new r(f(e.error)) : new o(e.error.message));
|
|
51
|
+
n(e.error.type === r.type ? new r(f(e.error)) : new o(e.error.display_message ?? e.error.message));
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
t(e);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { collectAttachmentRefs as e } from "../conversation-transfer/attachment-refs.js";
|
|
2
|
+
import { ConversationExportMode as t, ConversationTransferWarningCode as n, ExportFileNameKind as r } from "../conversation-transfer/types.js";
|
|
3
|
+
import { EXPORT_APP_NAME as i, buildExportEnvelope as a, buildExportFileName as o, serializeExportEnvelope as s, stripConversationAttachments as c } from "../conversation-transfer/export-conversation.js";
|
|
4
4
|
import { resolveDialFileBucketAndPath as l } from "../conversation-transfer/dial-file-resolve.js";
|
|
5
5
|
import { runWithConcurrency as u } from "../conversation-transfer/async.js";
|
|
6
6
|
import { ConversationTransferKind as d, ConversationTransferPhase as f, buildTransferProgress as p } from "../conversation-transfer/progress.js";
|
|
@@ -29,7 +29,7 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
29
29
|
if (n.aborted || !D(e) || r >= T) throw e;
|
|
30
30
|
await k(O(e, r), n);
|
|
31
31
|
}
|
|
32
|
-
}, j = (e) => !e.sharedWithMe && !e.publishedWithMe, M = (e) => e instanceof RangeError, N = (
|
|
32
|
+
}, j = (e) => !e.sharedWithMe && !e.publishedWithMe, M = (e) => e instanceof RangeError, N = (e) => e === t.WithoutAttachments ? d.ExportSingle : d.ExportSingleWithAttachments, P = ({ conversationsApi: x, filesApi: w, normalizeConversationPath: T, classifyTransferError: E = () => ({}), resolveErrorTraceId: D = async () => void 0, maxArchiveBytes: O = C, onSuccess: k, onWarning: P, onError: F }) => {
|
|
33
33
|
let I = m(), L = b(async (e, t, n) => {
|
|
34
34
|
let r = !1, i = !1, a = 0, o = () => {
|
|
35
35
|
a += 1, n(a, e.length);
|
|
@@ -61,44 +61,44 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
61
61
|
anySkipped: !t.aborted && !i && r,
|
|
62
62
|
isUnauthorized: !t.aborted && i
|
|
63
63
|
};
|
|
64
|
-
}, [E, w]), R = b(async (
|
|
64
|
+
}, [E, w]), R = b(async (r, i, o, l, u, d) => {
|
|
65
65
|
let m = N(l), _;
|
|
66
66
|
try {
|
|
67
|
-
_ = await A(x, T(
|
|
67
|
+
_ = await A(x, T(i), d);
|
|
68
68
|
} catch (e) {
|
|
69
69
|
if (d.aborted) return;
|
|
70
70
|
if (E(e).isUnauthorized) F?.({
|
|
71
|
-
jobId:
|
|
71
|
+
jobId: r,
|
|
72
72
|
code: g.Unauthorized
|
|
73
|
-
}), I.failJob(
|
|
73
|
+
}), I.failJob(r, g.Unauthorized);
|
|
74
74
|
else {
|
|
75
75
|
let t = await D(e);
|
|
76
76
|
F?.({
|
|
77
|
-
jobId:
|
|
77
|
+
jobId: r,
|
|
78
78
|
code: g.Unknown,
|
|
79
|
-
titles: [
|
|
79
|
+
titles: [o],
|
|
80
80
|
traceId: t
|
|
81
|
-
}), I.failJob(
|
|
81
|
+
}), I.failJob(r, g.Unknown);
|
|
82
82
|
}
|
|
83
83
|
console.error("Failed to fetch conversation for export", e);
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
if (!d.aborted) {
|
|
87
|
-
I.setJobProgress(
|
|
87
|
+
I.setJobProgress(r, p({
|
|
88
88
|
kind: m,
|
|
89
89
|
phase: f.Prepare
|
|
90
90
|
}));
|
|
91
91
|
try {
|
|
92
|
-
if (l ===
|
|
93
|
-
let e =
|
|
92
|
+
if (l === t.WithoutAttachments) {
|
|
93
|
+
let e = a([c(_)], []), t = s(e);
|
|
94
94
|
y(t, u), k?.({
|
|
95
|
-
jobId:
|
|
96
|
-
titles: [
|
|
97
|
-
}), I.succeedJob(
|
|
95
|
+
jobId: r,
|
|
96
|
+
titles: [o]
|
|
97
|
+
}), I.succeedJob(r);
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
|
-
let
|
|
101
|
-
I.setJobProgress(
|
|
100
|
+
let i = e(_), { entries: b, anySkipped: x, isUnauthorized: S } = await L(i, d, (e, t) => {
|
|
101
|
+
I.setJobProgress(r, p({
|
|
102
102
|
kind: m,
|
|
103
103
|
phase: f.Transfer,
|
|
104
104
|
completed: e,
|
|
@@ -112,43 +112,43 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
112
112
|
if (d.aborted) return;
|
|
113
113
|
if (S) {
|
|
114
114
|
F?.({
|
|
115
|
-
jobId:
|
|
115
|
+
jobId: r,
|
|
116
116
|
code: g.Unauthorized
|
|
117
|
-
}), I.failJob(
|
|
117
|
+
}), I.failJob(r, g.Unauthorized);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
120
|
-
I.setJobProgress(
|
|
120
|
+
I.setJobProgress(r, p({
|
|
121
121
|
kind: m,
|
|
122
122
|
phase: f.Transfer,
|
|
123
|
-
completed:
|
|
124
|
-
total:
|
|
123
|
+
completed: i.length,
|
|
124
|
+
total: i.length
|
|
125
125
|
}));
|
|
126
126
|
let C = b.reduce((e, t) => e + t.data.byteLength, 0);
|
|
127
127
|
if (C > O) {
|
|
128
128
|
F?.({
|
|
129
|
-
jobId:
|
|
129
|
+
jobId: r,
|
|
130
130
|
code: g.FileTooLarge,
|
|
131
|
-
titles: [
|
|
132
|
-
}), I.failJob(
|
|
131
|
+
titles: [o]
|
|
132
|
+
}), I.failJob(r, g.FileTooLarge), console.error(`Refused to build an export archive of ${C} bytes: over the ${O}-byte limit`);
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
let w =
|
|
135
|
+
let w = a([_], []), { blob: T, skippedPaths: E } = h(w, b), D = x || E.length > 0;
|
|
136
136
|
D && P?.({
|
|
137
|
-
jobId:
|
|
138
|
-
code:
|
|
137
|
+
jobId: r,
|
|
138
|
+
code: n.AttachmentSkipped
|
|
139
139
|
}), y(T, u), k?.({
|
|
140
|
-
jobId:
|
|
141
|
-
titles: [
|
|
142
|
-
}), D ? I.warnJob(
|
|
140
|
+
jobId: r,
|
|
141
|
+
titles: [o]
|
|
142
|
+
}), D ? I.warnJob(r, n.AttachmentSkipped) : I.succeedJob(r);
|
|
143
143
|
} catch (e) {
|
|
144
144
|
if (d.aborted) return;
|
|
145
|
-
let t = M(e) ? g.FileTooLarge : g.Unknown,
|
|
145
|
+
let t = M(e) ? g.FileTooLarge : g.Unknown, n = await D(e);
|
|
146
146
|
F?.({
|
|
147
|
-
jobId:
|
|
147
|
+
jobId: r,
|
|
148
148
|
code: t,
|
|
149
|
-
titles: [
|
|
150
|
-
traceId:
|
|
151
|
-
}), I.failJob(
|
|
149
|
+
titles: [o],
|
|
150
|
+
traceId: n
|
|
151
|
+
}), I.failJob(r, t), console.error("Failed to build conversation export archive", e);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
}, [
|
|
@@ -162,19 +162,19 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
162
162
|
P,
|
|
163
163
|
I,
|
|
164
164
|
D
|
|
165
|
-
]), z = b((
|
|
166
|
-
let s = a
|
|
165
|
+
]), z = b((e, n, a) => {
|
|
166
|
+
let s = o(a === t.WithoutAttachments ? r.SingleConversation : r.SingleConversationWithAttachments, i), c = I.addJob({
|
|
167
167
|
kind: _.Single,
|
|
168
|
-
title:
|
|
168
|
+
title: n
|
|
169
169
|
}, s);
|
|
170
|
-
return I.startJob(c, (
|
|
170
|
+
return I.startJob(c, (t) => R(c, e, n, a, s, t));
|
|
171
171
|
}, [I, R]), B = b(async (e, t, n) => {
|
|
172
|
-
let r = d.ExportAll,
|
|
172
|
+
let r = d.ExportAll, i = [], o;
|
|
173
173
|
do {
|
|
174
174
|
if (n.aborted) return;
|
|
175
175
|
let t;
|
|
176
176
|
try {
|
|
177
|
-
t = await x.listConversations({ nextToken:
|
|
177
|
+
t = await x.listConversations({ nextToken: o }, { signal: n });
|
|
178
178
|
} catch (t) {
|
|
179
179
|
if (n.aborted) return;
|
|
180
180
|
if (E(t).isUnauthorized) F?.({
|
|
@@ -192,17 +192,17 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
192
192
|
console.error("Failed to list conversations for export", t);
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
|
-
|
|
195
|
+
i.push(...t.items.filter(j).map((e) => ({
|
|
196
196
|
id: e.id,
|
|
197
197
|
title: e.title
|
|
198
|
-
}))),
|
|
199
|
-
} while (
|
|
198
|
+
}))), o = t.nextToken;
|
|
199
|
+
} while (o);
|
|
200
200
|
I.setJobProgress(e, p({
|
|
201
201
|
kind: r,
|
|
202
202
|
phase: f.Prepare
|
|
203
203
|
}));
|
|
204
204
|
let l = [];
|
|
205
|
-
for (let t of
|
|
205
|
+
for (let t of i) {
|
|
206
206
|
if (n.aborted) return;
|
|
207
207
|
try {
|
|
208
208
|
let e = await A(x, T(t.id), n);
|
|
@@ -239,16 +239,16 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
239
239
|
kind: r,
|
|
240
240
|
phase: f.Transfer,
|
|
241
241
|
completed: l.length,
|
|
242
|
-
total:
|
|
242
|
+
total: i.length
|
|
243
243
|
}, {
|
|
244
244
|
completed: l.length,
|
|
245
|
-
total:
|
|
245
|
+
total: i.length,
|
|
246
246
|
kind: v.Conversation
|
|
247
247
|
}));
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
if (!n.aborted) try {
|
|
251
|
-
let n =
|
|
251
|
+
let n = a(l.map(c), []), r = s(n);
|
|
252
252
|
y(r, t), k?.({ jobId: e }), I.succeedJob(e);
|
|
253
253
|
} catch (t) {
|
|
254
254
|
let n = M(t) ? g.FileTooLarge : g.Unknown, r = await D(t);
|
|
@@ -267,7 +267,7 @@ var S = 5, C = 536870912, w = 429, T = 5, E = 2e3, D = (e) => e instanceof x &&
|
|
|
267
267
|
I,
|
|
268
268
|
D
|
|
269
269
|
]), V = b(() => {
|
|
270
|
-
let e =
|
|
270
|
+
let e = o(r.AllConversationsHistory, i), t = I.addJob({ kind: _.All }, e);
|
|
271
271
|
return I.startJob(t, (n) => B(t, e, n));
|
|
272
272
|
}, [I, B]);
|
|
273
273
|
return {
|
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.3.0-dev.
|
|
4
|
+
"version": "1.3.0-dev.152",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.js",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
}
|
|
122
122
|
},
|
|
123
123
|
"dependencies": {
|
|
124
|
-
"@epam/ai-dial-chat-api-client": "1.3.0-dev.
|
|
124
|
+
"@epam/ai-dial-chat-api-client": "1.3.0-dev.152",
|
|
125
125
|
"dompurify": "3.4.16",
|
|
126
126
|
"fflate": "^0.8.3",
|
|
127
127
|
"lru-cache": "^10.4.3",
|
|
@@ -130,22 +130,22 @@
|
|
|
130
130
|
},
|
|
131
131
|
"peerDependencies": {
|
|
132
132
|
"react": "^19.2.8",
|
|
133
|
-
"@epam/ai-dial-attachment-canvas": "1.3.0-dev.
|
|
134
|
-
"@epam/ai-dial-attachment-input": "1.3.0-dev.
|
|
135
|
-
"@epam/ai-dial-catalog": "1.3.0-dev.
|
|
136
|
-
"@epam/ai-dial-chat-overlay": "1.3.0-dev.
|
|
137
|
-
"@epam/ai-dial-chat-shared": "1.3.0-dev.
|
|
138
|
-
"@epam/ai-dial-conversation-input": "1.3.0-dev.
|
|
139
|
-
"@epam/ai-dial-mcp-apps": "1.3.0-dev.
|
|
140
|
-
"@epam/ai-dial-publish-panel": "1.3.0-dev.
|
|
141
|
-
"@epam/ai-dial-quotations": "1.3.0-dev.
|
|
133
|
+
"@epam/ai-dial-attachment-canvas": "1.3.0-dev.152",
|
|
134
|
+
"@epam/ai-dial-attachment-input": "1.3.0-dev.152",
|
|
135
|
+
"@epam/ai-dial-catalog": "1.3.0-dev.152",
|
|
136
|
+
"@epam/ai-dial-chat-overlay": "1.3.0-dev.152",
|
|
137
|
+
"@epam/ai-dial-chat-shared": "1.3.0-dev.152",
|
|
138
|
+
"@epam/ai-dial-conversation-input": "1.3.0-dev.152",
|
|
139
|
+
"@epam/ai-dial-mcp-apps": "1.3.0-dev.152",
|
|
140
|
+
"@epam/ai-dial-publish-panel": "1.3.0-dev.152",
|
|
141
|
+
"@epam/ai-dial-quotations": "1.3.0-dev.152",
|
|
142
142
|
"@epam/ai-dial-react-file-manager": "^0.4.0-dev.11",
|
|
143
|
-
"@epam/ai-dial-scheduled-tasks": "1.3.0-dev.
|
|
144
|
-
"@epam/ai-dial-share": "1.3.0-dev.
|
|
145
|
-
"@epam/ai-dial-skill-editor": "1.3.0-dev.
|
|
146
|
-
"@epam/ai-dial-source-panel": "1.3.0-dev.
|
|
143
|
+
"@epam/ai-dial-scheduled-tasks": "1.3.0-dev.152",
|
|
144
|
+
"@epam/ai-dial-share": "1.3.0-dev.152",
|
|
145
|
+
"@epam/ai-dial-skill-editor": "1.3.0-dev.152",
|
|
146
|
+
"@epam/ai-dial-source-panel": "1.3.0-dev.152",
|
|
147
147
|
"@epam/ai-dial-ui-kit": "^0.16.0-dev.22",
|
|
148
|
-
"@epam/ai-dial-usage-dashboard": "1.3.0-dev.
|
|
148
|
+
"@epam/ai-dial-usage-dashboard": "1.3.0-dev.152",
|
|
149
149
|
"@modelcontextprotocol/sdk": "^1.32.1",
|
|
150
150
|
"@epam/pdf-highlighter-kit": "^0.0.19",
|
|
151
151
|
"@mcp-ui/client": "^7.1.1"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DeploymentLimitsResponseDto } from '@epam/ai-dial-chat-api-client';
|
|
2
1
|
import { UsageLimitBannerSeverity } from '@epam/ai-dial-conversation-input';
|
|
3
2
|
import { UsagePeriod } from './usage-period';
|
|
3
|
+
import { UsageLimitsSources } from './useDeploymentUsageLimits/useDeploymentUsageLimits';
|
|
4
4
|
/** The day/week/month usage stat the composer banner reports on, and how close it is to its limit. */
|
|
5
5
|
export interface UsageBannerSource {
|
|
6
6
|
/** Calendar period of the stat. */
|
|
@@ -15,9 +15,10 @@ export interface UsageBannerSource {
|
|
|
15
15
|
/** `true` when `total` is a real cap: finite, positive, and below DIAL Core's unlimited sentinel. */
|
|
16
16
|
export declare const isCappedStat: (total: number) => boolean;
|
|
17
17
|
/**
|
|
18
|
-
* Returns the capped day/week/month token
|
|
19
|
-
* used/total ratio, classified
|
|
20
|
-
* no stat is capped or the
|
|
18
|
+
* Returns the capped day/week/month token stat of `sources.deployment` or cost
|
|
19
|
+
* stat of `sources.account` with the highest used/total ratio, classified
|
|
20
|
+
* against `thresholdPercent`, or `undefined` when no stat is capped or the
|
|
21
|
+
* worst one is below the threshold.
|
|
21
22
|
*/
|
|
22
|
-
export declare const selectUsageBannerSource: (
|
|
23
|
+
export declare const selectUsageBannerSource: (sources: UsageLimitsSources, thresholdPercent: number) => UsageBannerSource | undefined;
|
|
23
24
|
//# sourceMappingURL=usage-banner-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage-banner-source.d.ts","sourceRoot":"","sources":["../../src/usage/usage-banner-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usage-banner-source.d.ts","sourceRoot":"","sources":["../../src/usage/usage-banner-source.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qDAAqD,CAAC;AAE9F,sGAAsG;AACtG,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,uDAAuD;IACvD,QAAQ,EAAE,wBAAwB,CAAC;IACnC,wEAAwE;IACxE,WAAW,EAAE,MAAM,CAAC;IACpB,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;CAC9B;AAQD,qGAAqG;AACrG,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,KAAG,OAC4B,CAAC;AAsC1E;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,SAAS,kBAAkB,EAC3B,kBAAkB,MAAM,KACvB,iBAAiB,GAAG,SAsCtB,CAAC"}
|
|
@@ -2,22 +2,46 @@ import { UsagePeriod as e } from "./usage-period.js";
|
|
|
2
2
|
import { UsageLimitBannerSeverity as t } from "@epam/ai-dial-conversation-input";
|
|
3
3
|
//#region src/usage/usage-banner-source.ts
|
|
4
4
|
var n = 2 ** 53 - 1, r = (e) => Number.isFinite(e) && e > 0 && e < n, i = [
|
|
5
|
-
[
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
[
|
|
5
|
+
[
|
|
6
|
+
"deployment",
|
|
7
|
+
"monthTokenStats",
|
|
8
|
+
e.Month
|
|
9
|
+
],
|
|
10
|
+
[
|
|
11
|
+
"account",
|
|
12
|
+
"monthCostStats",
|
|
13
|
+
e.Month
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"deployment",
|
|
17
|
+
"weekTokenStats",
|
|
18
|
+
e.Week
|
|
19
|
+
],
|
|
20
|
+
[
|
|
21
|
+
"account",
|
|
22
|
+
"weekCostStats",
|
|
23
|
+
e.Week
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
"deployment",
|
|
27
|
+
"dayTokenStats",
|
|
28
|
+
e.Day
|
|
29
|
+
],
|
|
30
|
+
[
|
|
31
|
+
"account",
|
|
32
|
+
"dayCostStats",
|
|
33
|
+
e.Day
|
|
34
|
+
]
|
|
11
35
|
], a = (e, n) => {
|
|
12
36
|
let a;
|
|
13
|
-
for (let [t, n] of i) {
|
|
14
|
-
let i = e
|
|
37
|
+
for (let [t, n, o] of i) {
|
|
38
|
+
let i = e[t]?.[n];
|
|
15
39
|
if (i == null || !r(i.total)) continue;
|
|
16
|
-
let
|
|
17
|
-
(a == null ||
|
|
40
|
+
let s = Math.max(i.used, 0) / i.total;
|
|
41
|
+
(a == null || s > a.ratio) && (a = {
|
|
18
42
|
stat: i,
|
|
19
|
-
period:
|
|
20
|
-
ratio:
|
|
43
|
+
period: o,
|
|
44
|
+
ratio: s
|
|
21
45
|
});
|
|
22
46
|
}
|
|
23
47
|
if (a == null) return;
|
|
@@ -1,32 +1,56 @@
|
|
|
1
|
-
import { DeploymentLimitsResponseDto } from '@epam/ai-dial-chat-api-client';
|
|
2
|
-
/**
|
|
3
|
-
export type
|
|
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'>;
|
|
4
|
+
/**
|
|
5
|
+
* What the usage dial and the usage banner are mapped from. Each field has a
|
|
6
|
+
* single scope, so a deployment's figures are never read as the account's or
|
|
7
|
+
* the other way round.
|
|
8
|
+
*/
|
|
9
|
+
export interface UsageLimitsSources {
|
|
10
|
+
/** The selected deployment's own stats (its deployment-usage response). Only its token stats are read. */
|
|
11
|
+
deployment: DeploymentLimitsResponseDto | undefined;
|
|
12
|
+
/** The caller's account budget and spend. Only its cost stats are read. */
|
|
13
|
+
account: AccountUsage | undefined;
|
|
14
|
+
}
|
|
15
|
+
/** Host-configured calls that fetch the two usage sources. */
|
|
16
|
+
export interface UsageLimitsApi {
|
|
17
|
+
/** Fetches one deployment's own usage, every stat scoped to that deployment. */
|
|
18
|
+
getDeploymentUsage: (deploymentId: string) => Promise<DeploymentLimitsResponseDto>;
|
|
19
|
+
/** Fetches the caller's account usage; only its top-level cost stats are read. */
|
|
20
|
+
getAccountUsage: () => Promise<AccountUsage>;
|
|
21
|
+
}
|
|
4
22
|
/** Return shape of {@link useDeploymentUsageLimits}. */
|
|
5
23
|
export interface UseDeploymentUsageLimitsResult {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
/** `true`
|
|
24
|
+
/** The last successfully fetched value of each source. */
|
|
25
|
+
sources: UsageLimitsSources;
|
|
26
|
+
/** `true` until both calls of the current fetch have settled. */
|
|
9
27
|
isLoading: boolean;
|
|
10
|
-
/** `true` after the most recent fetch rejected. */
|
|
28
|
+
/** `true` after either call of the most recent fetch rejected. */
|
|
11
29
|
hasError: boolean;
|
|
12
|
-
/** Re-fetches
|
|
30
|
+
/** Re-fetches both sources when no request is in flight. */
|
|
13
31
|
refresh: () => void;
|
|
14
32
|
}
|
|
15
33
|
/**
|
|
16
|
-
* Fetches the selected deployment's usage
|
|
17
|
-
* `
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
34
|
+
* Fetches the selected deployment's own usage and the caller's account usage
|
|
35
|
+
* through the provided `api`. The hook accepts the calls as a parameter so the
|
|
36
|
+
* caller supplies an already-configured API client; the hook never constructs
|
|
37
|
+
* or imports one itself. The identity of `api` is not a re-fetch trigger; only
|
|
38
|
+
* `deploymentId` and `refresh()` are.
|
|
39
|
+
*
|
|
40
|
+
* Two sources rather than one deployment-limits response: there, the cost
|
|
41
|
+
* stats add an application's aggregated callee cost to the account spend that
|
|
42
|
+
* already contains it, so an agent's spend would be counted twice.
|
|
21
43
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
44
|
+
* Both calls share one monotonic request ID, so a slower response for a
|
|
45
|
+
* previous deployment never replaces the current value. Each source keeps its
|
|
46
|
+
* last known value when its own call fails, so the open popover can surface a
|
|
47
|
+
* non-blocking error while the other source still renders. The account source
|
|
48
|
+
* survives a deployment change, since it does not depend on the selection.
|
|
25
49
|
*
|
|
26
|
-
* The raw
|
|
50
|
+
* The raw responses are returned rather than a mapped display model: mapping
|
|
27
51
|
* needs the caller's translated labels and locale-bound reset formatter, and
|
|
28
52
|
* holding the mapped value in state here would leave it stale after a language
|
|
29
53
|
* change until the next fetch.
|
|
30
54
|
*/
|
|
31
|
-
export declare const useDeploymentUsageLimits: (deploymentId: string | undefined,
|
|
55
|
+
export declare const useDeploymentUsageLimits: (deploymentId: string | undefined, api: UsageLimitsApi) => UseDeploymentUsageLimitsResult;
|
|
32
56
|
//# sourceMappingURL=useDeploymentUsageLimits.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeploymentUsageLimits.d.ts","sourceRoot":"","sources":["../../../src/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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,39 +1,34 @@
|
|
|
1
|
-
import { useCallback as e, useEffect as t,
|
|
1
|
+
import { useCallback as e, useEffect as t, useMemo as n, useRef as r, useState as i } from "react";
|
|
2
2
|
//#region src/usage/useDeploymentUsageLimits/useDeploymentUsageLimits.ts
|
|
3
|
-
var
|
|
4
|
-
let [
|
|
5
|
-
|
|
6
|
-
let
|
|
7
|
-
|
|
3
|
+
var a = (a, o) => {
|
|
4
|
+
let [s, c] = i(), [l, u] = i(), [d, f] = i(!1), [p, m] = i(!1), [h, g] = i(0), _ = r(0), v = r(!1), y = r(void 0), b = r(o);
|
|
5
|
+
b.current = o;
|
|
6
|
+
let x = e(() => {
|
|
7
|
+
v.current || g((e) => e + 1);
|
|
8
8
|
}, []);
|
|
9
9
|
return t(() => {
|
|
10
|
-
let e =
|
|
11
|
-
if (
|
|
12
|
-
|
|
10
|
+
let e = y.current !== a;
|
|
11
|
+
if (y.current = a, !a) {
|
|
12
|
+
_.current += 1, c(void 0), f(!1), m(!1), v.current = !1;
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
e &&
|
|
16
|
-
let t = ++
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (n || t !== m.current) return;
|
|
21
|
-
s(e);
|
|
22
|
-
} catch {
|
|
23
|
-
if (n || t !== m.current) return;
|
|
24
|
-
d(!0);
|
|
25
|
-
} finally {
|
|
26
|
-
!n && t === m.current && (l(!1), h.current = !1);
|
|
27
|
-
}
|
|
15
|
+
e && c(void 0);
|
|
16
|
+
let t = ++_.current, n = !1, r = () => !n && t === _.current;
|
|
17
|
+
return f(!0), m(!1), v.current = !0, (async () => {
|
|
18
|
+
let [e, t] = await Promise.allSettled([b.current.getDeploymentUsage(a), b.current.getAccountUsage()]);
|
|
19
|
+
r() && (e.status === "fulfilled" && c(e.value), t.status === "fulfilled" && u(t.value), m(e.status === "rejected" || t.status === "rejected"), f(!1), v.current = !1);
|
|
28
20
|
})(), () => {
|
|
29
21
|
n = !0;
|
|
30
22
|
};
|
|
31
|
-
}, [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
}, [a, h]), {
|
|
24
|
+
sources: n(() => ({
|
|
25
|
+
deployment: s,
|
|
26
|
+
account: l
|
|
27
|
+
}), [s, l]),
|
|
28
|
+
isLoading: d,
|
|
29
|
+
hasError: p,
|
|
30
|
+
refresh: x
|
|
36
31
|
};
|
|
37
32
|
};
|
|
38
33
|
//#endregion
|
|
39
|
-
export {
|
|
34
|
+
export { a as useDeploymentUsageLimits };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UsageLimitBannerViewProps } from '@epam/ai-dial-conversation-input';
|
|
2
2
|
import { TranslateFn } from '../usage-reset-time';
|
|
3
|
-
import {
|
|
3
|
+
import { UsageLimitsApi } from '../useDeploymentUsageLimits/useDeploymentUsageLimits';
|
|
4
4
|
/**
|
|
5
5
|
* i18n key strings the consuming app's translation bundle must define for
|
|
6
6
|
* `useUsageLimitBanner` to produce translated strings, in addition to
|
|
@@ -29,8 +29,10 @@ export interface UseUsageLimitBannerOptions {
|
|
|
29
29
|
deploymentId: string | undefined;
|
|
30
30
|
/** Whether the selected deployment is currently generating a response. Defaults to `false`. */
|
|
31
31
|
isGenerationInProgress?: boolean;
|
|
32
|
-
/** Host-configured call that fetches one deployment's
|
|
33
|
-
|
|
32
|
+
/** Host-configured call that fetches one deployment's own usage. */
|
|
33
|
+
getDeploymentUsage: UsageLimitsApi['getDeploymentUsage'];
|
|
34
|
+
/** Host-configured call that fetches the caller's account usage. */
|
|
35
|
+
getAccountUsage: UsageLimitsApi['getAccountUsage'];
|
|
34
36
|
/** Used percentage at or above which a not-yet-exhausted limit raises a warning. */
|
|
35
37
|
warningThresholdPercent: number;
|
|
36
38
|
/** Active UI locale, used to format the reset time. */
|
|
@@ -47,10 +49,10 @@ export interface UseUsageLimitBannerResult {
|
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Everything the composer usage banner needs except its rendering: fetches the
|
|
50
|
-
* selected deployment's
|
|
51
|
-
* the limit worth reporting, formats its sentences, and
|
|
52
|
-
* dismissal. Spread `banner` onto `UsageLimitBannerView`
|
|
53
|
-
* `@epam/ai-dial-conversation-input`.
|
|
52
|
+
* selected deployment's own usage and the account usage, refreshes both after
|
|
53
|
+
* each generation, picks the limit worth reporting, formats its sentences, and
|
|
54
|
+
* tracks tab-lifetime dismissal. Spread `banner` onto `UsageLimitBannerView`
|
|
55
|
+
* from `@epam/ai-dial-conversation-input`.
|
|
54
56
|
*/
|
|
55
|
-
export declare const useUsageLimitBanner: ({ deploymentId, isGenerationInProgress,
|
|
57
|
+
export declare const useUsageLimitBanner: ({ deploymentId, isGenerationInProgress, getDeploymentUsage, getAccountUsage, warningThresholdPercent, activeLocale, t, }: UseUsageLimitBannerOptions) => UseUsageLimitBannerResult;
|
|
56
58
|
//# 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,
|
|
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"}
|
|
@@ -26,41 +26,44 @@ var l = {
|
|
|
26
26
|
[e.Week]: l.reachedWeek,
|
|
27
27
|
[e.Month]: l.reachedMonth
|
|
28
28
|
}
|
|
29
|
-
}, d = ({ deploymentId: e, isGenerationInProgress: c = !1,
|
|
30
|
-
let
|
|
29
|
+
}, d = ({ deploymentId: e, isGenerationInProgress: c = !1, getDeploymentUsage: d, getAccountUsage: f, warningThresholdPercent: p, activeLocale: m, t: h }) => {
|
|
30
|
+
let g = s(() => ({
|
|
31
|
+
getDeploymentUsage: d,
|
|
32
|
+
getAccountUsage: f
|
|
33
|
+
}), [d, f]), { sources: _, isLoading: v, refresh: y } = r(e, g), { isDismissed: b, dismiss: x } = a();
|
|
31
34
|
i({
|
|
32
35
|
isGenerationInProgress: c,
|
|
33
|
-
isLoading:
|
|
34
|
-
refresh:
|
|
36
|
+
isLoading: v,
|
|
37
|
+
refresh: y
|
|
35
38
|
});
|
|
36
|
-
let
|
|
37
|
-
if (
|
|
38
|
-
dismissalKey: `${e}:${
|
|
39
|
-
limitText:
|
|
40
|
-
reset: n(
|
|
39
|
+
let S = s(() => t(_, p), [_, p]), C = s(() => {
|
|
40
|
+
if (S != null && e) return {
|
|
41
|
+
dismissalKey: `${e}:${S.period}:${S.severity}`,
|
|
42
|
+
limitText: h(u[S.severity][S.period], { percent: S.usedPercent }),
|
|
43
|
+
reset: n(S.resetsAt, S.period, m, h)
|
|
41
44
|
};
|
|
42
45
|
}, [
|
|
43
|
-
|
|
46
|
+
S,
|
|
44
47
|
e,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
]),
|
|
48
|
-
|
|
49
|
-
}, [
|
|
48
|
+
m,
|
|
49
|
+
h
|
|
50
|
+
]), w = C?.dismissalKey, T = o(() => {
|
|
51
|
+
w != null && x(w);
|
|
52
|
+
}, [x, w]), E = h(l.closeLabel);
|
|
50
53
|
return { banner: s(() => {
|
|
51
|
-
if (!(
|
|
52
|
-
severity:
|
|
53
|
-
limitText:
|
|
54
|
-
reset:
|
|
55
|
-
onClose:
|
|
56
|
-
closeAriaLabel:
|
|
54
|
+
if (!(S == null || C == null || b(C.dismissalKey))) return {
|
|
55
|
+
severity: S.severity,
|
|
56
|
+
limitText: C.limitText,
|
|
57
|
+
reset: C.reset,
|
|
58
|
+
onClose: T,
|
|
59
|
+
closeAriaLabel: E
|
|
57
60
|
};
|
|
58
61
|
}, [
|
|
59
|
-
|
|
60
|
-
x,
|
|
61
|
-
v,
|
|
62
|
+
S,
|
|
62
63
|
C,
|
|
63
|
-
|
|
64
|
+
b,
|
|
65
|
+
T,
|
|
66
|
+
E
|
|
64
67
|
]) };
|
|
65
68
|
};
|
|
66
69
|
//#endregion
|