@epam/ai-dial-chat-shared 1.1.0-dev.99 → 1.1.0-rc.1
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/components/CopyButton/CopyButton.js +33 -0
- package/components/DeploymentIcon/DeploymentIcon.js +62 -0
- package/components/DeploymentIcon/DeploymentIcon.module.scss.js +3 -0
- package/components/EntityHeader/EntityHeader.js +48 -0
- package/components/EntityTypeLabel/EntityTypeLabel.js +10 -0
- package/components/FeaturedChip/FeaturedChip.js +18 -0
- package/components/InitialsAvatar/InitialsAvatar.js +29 -0
- package/components/InitialsAvatar/InitialsAvatar.module.scss.js +6 -0
- package/components/ItemHeader/ItemHeader.js +35 -0
- package/components/ItemHeader/ItemHeader.module.scss.js +6 -0
- package/components/MarkdownRenderer/CodeBlock/CodeBlock.js +104 -0
- package/components/MarkdownRenderer/CodeBlock/CodeBlock.module.scss.js +10 -0
- package/components/MarkdownRenderer/CodeBlock/syntax-theme.js +69 -0
- package/components/MarkdownRenderer/MDMessageViewer.js +22 -0
- package/components/MarkdownRenderer/MarkdownRenderer.js +280 -0
- package/components/MarkdownRenderer/MarkdownRenderer.module.scss.js +11 -0
- package/components/MarkdownRenderer/Math/MarkdownMathBlock.js +24 -0
- package/components/MarkdownRenderer/Math/MarkdownMathBlock.module.scss.js +6 -0
- package/components/MarkdownRenderer/Table/MarkdownTable.js +77 -0
- package/components/MarkdownRenderer/Table/MarkdownTable.module.scss.js +15 -0
- package/components/MarkdownRenderer/Table/TableHeader.js +30 -0
- package/components/MarkdownRenderer/Table/TableHeader.module.scss.js +3 -0
- package/components/MarkdownRenderer/Table/table-serialization.js +6 -0
- package/components/MarkdownRenderer/Table/useMarkdownTableActions/useMarkdownTableActions.js +66 -0
- package/components/MarkdownRenderer/TaskCheckbox/MarkdownTaskCheckbox.js +12 -0
- package/components/MarkdownRenderer/markdown-class-names.js +23 -0
- package/components/MarkdownWithPlaceholders/MarkdownWithPlaceholders.js +18 -0
- package/components/PanelEmptyState/PanelEmptyState.js +17 -0
- package/components/PanelEmptyState/PanelEmptyState.module.scss.js +3 -0
- package/components/ResourceSummary/ResourceSummary.js +34 -0
- package/components/ResourceSummary/ResourceSummary.module.scss.js +6 -0
- package/constants/breakpoint.js +4 -0
- package/constants/dial.js +4 -0
- package/constants/entity-colors.js +17 -0
- package/constants/icon.js +13 -0
- package/constants/markdown-editor.js +4 -0
- package/constants/mime-types.js +99 -0
- package/constants/resizable-fields.js +4 -0
- package/constants/select-list.js +4 -0
- package/constants/tag-input.js +4 -0
- package/file-manager/DialFileManagerShell/DialFileManagerShell.js +299 -0
- package/file-manager/FileManagerAttachModal/FileManagerAttachModal.js +108 -0
- package/file-manager/OperationLoaderModal/OperationLoaderModal.js +36 -0
- package/file-manager/UploadProgressModal/UploadProgressModal.js +56 -0
- package/file-manager/file-manager-variant.js +8 -0
- package/file-manager/path.js +7 -0
- package/file-manager/upload-batch.js +6 -0
- package/file-manager/useGridEditingScroll/useGridEditingScroll.js +45 -0
- package/file-manager.d.ts +491 -0
- package/file-manager.js +3 -0
- package/hooks/useAvailableHeightCap.js +36 -0
- package/hooks/useCodeCopy.js +20 -0
- package/hooks/useCollapsedText.js +38 -0
- package/hooks/useHorizontalOverflow.js +25 -0
- package/hooks/useIsMobile.js +13 -0
- package/hooks/useStreamedMarkdownContent.js +32 -0
- package/index.css +1 -1
- package/index.d.ts +2505 -43
- package/index.js +64 -49151
- package/markdown.d.ts +401 -0
- package/markdown.js +11 -0
- package/models/chat.js +14 -0
- package/models/conversation-classification.js +6 -0
- package/models/conversation-transfer.js +14 -0
- package/models/deployment-features.js +6 -0
- package/package.json +43 -12
- package/types/attachment.js +8 -0
- package/types/code-editor.js +6 -0
- package/types/entity-type.js +6 -0
- package/types/mime-type.js +8 -0
- package/utils/annotation.js +120 -0
- package/utils/avatar-color.js +37 -0
- package/utils/build-css-vars.js +8 -0
- package/utils/copy-to-clipboard.js +69 -0
- package/utils/file-download.js +79 -0
- package/utils/format-file-size.js +4 -0
- package/utils/format-last-used.js +20 -0
- package/utils/format-price.js +18 -0
- package/utils/generate-uuid.js +7 -0
- package/utils/initials.js +7 -0
- package/utils/is-audio-transcription-supported.js +5 -0
- package/utils/latex.js +79 -0
- package/utils/merge-class.js +8 -0
- package/utils/message-attachment-to-display.js +31 -0
- package/utils/message.js +5 -0
- package/utils/mime-type.js +73 -0
- package/utils/prompt-variables.js +58 -0
- package/utils/string-utils.js +14 -0
- package/components/CopyButton/CopyButton.d.ts +0 -15
- package/components/CopyButton/CopyButton.d.ts.map +0 -1
- package/components/DeploymentIcon/DeploymentIcon.d.ts +0 -36
- package/components/DeploymentIcon/DeploymentIcon.d.ts.map +0 -1
- package/components/InitialsAvatar/InitialsAvatar.d.ts +0 -13
- package/components/InitialsAvatar/InitialsAvatar.d.ts.map +0 -1
- package/components/MarkdownRenderer/CodeBlock/CodeBlock.d.ts +0 -47
- package/components/MarkdownRenderer/CodeBlock/CodeBlock.d.ts.map +0 -1
- package/components/MarkdownRenderer/CodeBlock/syntax-theme.d.ts +0 -7
- package/components/MarkdownRenderer/CodeBlock/syntax-theme.d.ts.map +0 -1
- package/components/MarkdownRenderer/MDMessageViewer.d.ts +0 -31
- package/components/MarkdownRenderer/MDMessageViewer.d.ts.map +0 -1
- package/components/MarkdownRenderer/MarkdownRenderer.d.ts +0 -105
- package/components/MarkdownRenderer/MarkdownRenderer.d.ts.map +0 -1
- package/components/MarkdownRenderer/Table/MarkdownTable.d.ts +0 -31
- package/components/MarkdownRenderer/Table/MarkdownTable.d.ts.map +0 -1
- package/components/MarkdownRenderer/TaskCheckbox/MarkdownTaskCheckbox.d.ts +0 -9
- package/components/MarkdownRenderer/TaskCheckbox/MarkdownTaskCheckbox.d.ts.map +0 -1
- package/components/MarkdownRenderer/markdown-class-names.d.ts +0 -4
- package/components/MarkdownRenderer/markdown-class-names.d.ts.map +0 -1
- package/components/PanelEmptyState/PanelEmptyState.d.ts +0 -20
- package/components/PanelEmptyState/PanelEmptyState.d.ts.map +0 -1
- package/constants/dial.d.ts +0 -3
- package/constants/dial.d.ts.map +0 -1
- package/constants/icon.d.ts +0 -14
- package/constants/icon.d.ts.map +0 -1
- package/constants/mime-types.d.ts +0 -7
- package/constants/mime-types.d.ts.map +0 -1
- package/hooks/useCodeCopy.d.ts +0 -6
- package/hooks/useCodeCopy.d.ts.map +0 -1
- package/hooks/useCollapsedText.d.ts +0 -27
- package/hooks/useCollapsedText.d.ts.map +0 -1
- package/hooks/useIsMobile.d.ts +0 -3
- package/hooks/useIsMobile.d.ts.map +0 -1
- package/hooks/useStreamedMarkdownContent.d.ts +0 -3
- package/hooks/useStreamedMarkdownContent.d.ts.map +0 -1
- package/hooks/useTableScroll.d.ts +0 -17
- package/hooks/useTableScroll.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/models/annotation.d.ts +0 -78
- package/models/annotation.d.ts.map +0 -1
- package/models/auth.d.ts +0 -26
- package/models/auth.d.ts.map +0 -1
- package/models/chat.d.ts +0 -276
- package/models/chat.d.ts.map +0 -1
- package/models/custom-visualizer.d.ts +0 -61
- package/models/custom-visualizer.d.ts.map +0 -1
- package/models/deployment-configuration.d.ts +0 -55
- package/models/deployment-configuration.d.ts.map +0 -1
- package/models/deployment-features.d.ts +0 -17
- package/models/deployment-features.d.ts.map +0 -1
- package/models/deployment.d.ts +0 -31
- package/models/deployment.d.ts.map +0 -1
- package/models/dial-model.d.ts +0 -19
- package/models/dial-model.d.ts.map +0 -1
- package/models/import-export.d.ts +0 -23
- package/models/import-export.d.ts.map +0 -1
- package/models/theme.d.ts +0 -36
- package/models/theme.d.ts.map +0 -1
- package/models/tool-menu-item.d.ts +0 -13
- package/models/tool-menu-item.d.ts.map +0 -1
- package/types/attachment.d.ts +0 -23
- package/types/attachment.d.ts.map +0 -1
- package/types/code-editor.d.ts +0 -8
- package/types/code-editor.d.ts.map +0 -1
- package/types/mime-type.d.ts +0 -53
- package/types/mime-type.d.ts.map +0 -1
- package/utils/avatar-color.d.ts +0 -10
- package/utils/avatar-color.d.ts.map +0 -1
- package/utils/build-css-vars.d.ts +0 -4
- package/utils/build-css-vars.d.ts.map +0 -1
- package/utils/copy-to-clipboard.d.ts +0 -3
- package/utils/copy-to-clipboard.d.ts.map +0 -1
- package/utils/file-download.d.ts +0 -9
- package/utils/file-download.d.ts.map +0 -1
- package/utils/format-file-size.d.ts +0 -3
- package/utils/format-file-size.d.ts.map +0 -1
- package/utils/format-last-used.d.ts +0 -3
- package/utils/format-last-used.d.ts.map +0 -1
- package/utils/initials.d.ts +0 -3
- package/utils/initials.d.ts.map +0 -1
- package/utils/is-audio-transcription-supported.d.ts +0 -3
- package/utils/is-audio-transcription-supported.d.ts.map +0 -1
- package/utils/latex.d.ts +0 -11
- package/utils/latex.d.ts.map +0 -1
- package/utils/merge-class.d.ts +0 -4
- package/utils/merge-class.d.ts.map +0 -1
- package/utils/message-attachment-to-display.d.ts +0 -22
- package/utils/message-attachment-to-display.d.ts.map +0 -1
- package/utils/message.d.ts +0 -4
- package/utils/message.d.ts.map +0 -1
- package/utils/string-utils.d.ts +0 -5
- package/utils/string-utils.d.ts.map +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { MIMEType as e } from "../types/mime-type.js";
|
|
2
|
+
import { inferMimeTypeFromPath as t } from "./mime-type.js";
|
|
3
|
+
//#region src/utils/annotation.ts
|
|
4
|
+
var n = {
|
|
5
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
6
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
7
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
8
|
+
}, r = (e) => {
|
|
9
|
+
let r = t(e);
|
|
10
|
+
if (r != null) return r;
|
|
11
|
+
let i = e.split(/[?#]/)[0], a = i.lastIndexOf(".");
|
|
12
|
+
if (a !== -1) return n[i.slice(a + 1).toLowerCase()];
|
|
13
|
+
}, i = (e) => typeof e == "object" && !!e && !Array.isArray(e) && "type" in e && typeof e.type == "string", a = (e) => Array.isArray(e) ? e.filter(i) : i(e) ? e : void 0, o = (e) => typeof e == "number" ? e : null, s = (e) => {
|
|
14
|
+
if (typeof e != "object" || !e) return null;
|
|
15
|
+
let t = e;
|
|
16
|
+
if (t.type !== "pdf_region") return null;
|
|
17
|
+
let n = t.bbox;
|
|
18
|
+
if (typeof n != "object" || !n) return null;
|
|
19
|
+
let r = n, i = o(r.left), a = o(r.top), s = o(r.width), c = o(r.height);
|
|
20
|
+
return i === null || a === null || s === null || c === null ? null : {
|
|
21
|
+
type: "pdf_bbox",
|
|
22
|
+
page: o(t.page) ?? 1,
|
|
23
|
+
x1: i,
|
|
24
|
+
y1: a,
|
|
25
|
+
x2: i + s,
|
|
26
|
+
y2: a + c
|
|
27
|
+
};
|
|
28
|
+
}, c = (t, n) => {
|
|
29
|
+
let r = t.target;
|
|
30
|
+
if (typeof r != "object" || !r) return null;
|
|
31
|
+
let i = r, a = i.source;
|
|
32
|
+
if (typeof a != "object" || !a) return null;
|
|
33
|
+
let c = o(a.attachment_index);
|
|
34
|
+
if (c === null) return null;
|
|
35
|
+
let l = n.find((e) => e.index === c);
|
|
36
|
+
if (l?.url == null) return null;
|
|
37
|
+
let u = s(i.selector);
|
|
38
|
+
if (u === null) return null;
|
|
39
|
+
let d = t.body, f = typeof d == "object" && d ? d : {}, p = typeof f.title == "string" ? f.title : void 0, m = typeof f.quote == "string" ? f.quote : void 0;
|
|
40
|
+
return {
|
|
41
|
+
index: o(t.index) ?? void 0,
|
|
42
|
+
body: {
|
|
43
|
+
title: p,
|
|
44
|
+
quote: m,
|
|
45
|
+
source: {
|
|
46
|
+
type: "attachment",
|
|
47
|
+
attachment: {
|
|
48
|
+
type: l.type ?? e.PDF,
|
|
49
|
+
url: l.url,
|
|
50
|
+
title: l.title
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
selector: u
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}, l = (t) => {
|
|
57
|
+
let n = t.target;
|
|
58
|
+
if (typeof n != "object" || !n) return null;
|
|
59
|
+
let i = n.selector;
|
|
60
|
+
if (typeof i != "object" || !i) return null;
|
|
61
|
+
let s = i;
|
|
62
|
+
if (s.type !== "html_tag" || typeof s.tag != "string" || typeof s.id != "string") return null;
|
|
63
|
+
let c = {
|
|
64
|
+
type: "html_tag",
|
|
65
|
+
tag: s.tag,
|
|
66
|
+
id: s.id
|
|
67
|
+
}, l = t.body;
|
|
68
|
+
if (typeof l != "object" || !l) return null;
|
|
69
|
+
let u = l, d = u.source;
|
|
70
|
+
if (typeof d != "object" || !d) return null;
|
|
71
|
+
let f = d;
|
|
72
|
+
if (f.type !== "attachment") return null;
|
|
73
|
+
let p = f.url;
|
|
74
|
+
if (typeof p != "string") return null;
|
|
75
|
+
let m = typeof u.title == "string" ? u.title : void 0, h = typeof u.quote == "string" ? u.quote : void 0, g = a(u.selector);
|
|
76
|
+
return {
|
|
77
|
+
index: o(t.index) ?? void 0,
|
|
78
|
+
target: { selector: c },
|
|
79
|
+
body: {
|
|
80
|
+
title: m,
|
|
81
|
+
quote: h,
|
|
82
|
+
...g === void 0 ? {} : { selector: g },
|
|
83
|
+
source: {
|
|
84
|
+
type: "attachment",
|
|
85
|
+
attachment: {
|
|
86
|
+
type: r(p) ?? e.PDF,
|
|
87
|
+
url: p,
|
|
88
|
+
title: m
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}, u = (e) => {
|
|
94
|
+
if (e.target?.selector?.type !== "html_tag") return e;
|
|
95
|
+
let t = e.body?.source?.attachment;
|
|
96
|
+
if (t?.url == null) return e;
|
|
97
|
+
let n = r(t.url);
|
|
98
|
+
return n == null || n === t.type ? e : {
|
|
99
|
+
...e,
|
|
100
|
+
body: {
|
|
101
|
+
...e.body,
|
|
102
|
+
source: {
|
|
103
|
+
...e.body?.source,
|
|
104
|
+
type: "attachment",
|
|
105
|
+
attachment: {
|
|
106
|
+
...t,
|
|
107
|
+
type: n
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}, d = (e, t) => e.flatMap((e) => {
|
|
113
|
+
if (typeof e != "object" || !e) return [];
|
|
114
|
+
let n = e, r = l(n);
|
|
115
|
+
if (r) return [r];
|
|
116
|
+
let i = c(n, t);
|
|
117
|
+
return i ? [i] : [];
|
|
118
|
+
});
|
|
119
|
+
//#endregion
|
|
120
|
+
export { i as isAnnotationSelector, u as normalizePersistedHtmlTagAttachmentType, d as normalizeRawAnnotations };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/utils/avatar-color.ts
|
|
2
|
+
var e = [
|
|
3
|
+
{
|
|
4
|
+
background: "var(--bg-visual-green-1, #CDE8E5)",
|
|
5
|
+
foreground: "var(--text-visual-green-2, #0D6E72)"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
background: "var(--bg-visual-violet-2, #F1E9FF)",
|
|
9
|
+
foreground: "var(--text-visual-violet-1, #7C3AED)"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
background: "var(--bg-visual-brown, #FDE8D8)",
|
|
13
|
+
foreground: "var(--text-visual-brown-2, #B45309)"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
background: "var(--bg-visual-red, #FCE7F3)",
|
|
17
|
+
foreground: "var(--text-visual-red, #9D174D)"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
background: "var(--bg-visual-green-2, #D1F0DC)",
|
|
21
|
+
foreground: "var(--text-visual-green-3, #065F46)"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
background: "var(--bg-visual-blue, #D6EDF9)",
|
|
25
|
+
foreground: "var(--text-accent, #1D4ED8)"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
background: "var(--bg-visual-violet-1, #DDE3F9)",
|
|
29
|
+
foreground: "var(--text-visual-violet-2, #3730B7)"
|
|
30
|
+
}
|
|
31
|
+
], t = (t) => {
|
|
32
|
+
let n = 0;
|
|
33
|
+
for (let e = 0; e < t.length; e++) n += t.charCodeAt(e);
|
|
34
|
+
return e[n % e.length];
|
|
35
|
+
};
|
|
36
|
+
//#endregion
|
|
37
|
+
export { t as pickAvatarColor };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import e from "dompurify";
|
|
2
|
+
import t from "rehype-stringify";
|
|
3
|
+
import n from "remark-gfm";
|
|
4
|
+
import r from "remark-parse";
|
|
5
|
+
import i from "remark-rehype";
|
|
6
|
+
import { unified as a } from "unified";
|
|
7
|
+
//#region src/utils/copy-to-clipboard.ts
|
|
8
|
+
var o = {
|
|
9
|
+
table: "border-collapse:collapse;width:100%;margin:0 0 12px;font-size:14px;line-height:20px;background:#ffffff;color:#161b2d;border:1px solid #d1dbea",
|
|
10
|
+
th: "background:#fcfcfc;color:#57647a;border-bottom:1px solid #e0e6f0;padding:8px 12px;text-align:start;font-weight:600",
|
|
11
|
+
td: "border-top:1px solid #e0e6f0;padding:8px 12px;text-align:start",
|
|
12
|
+
h1: "font-size:20px;line-height:28px;font-weight:600;margin:0 0 12px",
|
|
13
|
+
h2: "font-size:18px;line-height:26px;font-weight:600;margin:16px 0 8px",
|
|
14
|
+
h3: "font-size:16px;line-height:24px;font-weight:600;margin:16px 0 8px",
|
|
15
|
+
p: "font-size:14px;line-height:24px;margin:0 0 12px",
|
|
16
|
+
ul: "font-size:14px;line-height:24px;margin:0 0 12px;padding-inline-start:24px",
|
|
17
|
+
ol: "font-size:14px;line-height:24px;margin:0 0 12px;padding-inline-start:24px",
|
|
18
|
+
blockquote: "border-inline-start:3px solid #d1dbea;margin:0 0 12px;padding:4px 0 4px 12px",
|
|
19
|
+
pre: "background:#f8fafc;border:1px solid #d1dbea;border-radius:8px;padding:12px;overflow:auto;font-size:14px;line-height:20px;color:#161b2d;margin:0 0 12px",
|
|
20
|
+
code: "font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:14px;background:#f3f5f9;color:#161b2d;padding:1px 4px;border-radius:4px",
|
|
21
|
+
a: "text-decoration:underline",
|
|
22
|
+
hr: "border:0;border-top:1px solid #d1dbea;margin:16px 0"
|
|
23
|
+
}, s = "background:#f5f7fa", c = {
|
|
24
|
+
left: "text-align:start",
|
|
25
|
+
center: "text-align:center",
|
|
26
|
+
right: "text-align:end"
|
|
27
|
+
}, l = (e) => {
|
|
28
|
+
let t = e.properties?.align;
|
|
29
|
+
return typeof t == "string" ? c[t] : void 0;
|
|
30
|
+
}, u = "font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:14px", d = (e, t) => {
|
|
31
|
+
e.properties ||= {};
|
|
32
|
+
let n = typeof e.properties.style == "string" ? e.properties.style : "";
|
|
33
|
+
e.properties.style = n ? `${n};${t}` : t;
|
|
34
|
+
}, f = (e, t = !1) => {
|
|
35
|
+
if (e.tagName === "code" && t) d(e, u);
|
|
36
|
+
else if (e.tagName) {
|
|
37
|
+
let t = o[e.tagName];
|
|
38
|
+
if (t && d(e, t), e.tagName === "th" || e.tagName === "td") {
|
|
39
|
+
let t = l(e);
|
|
40
|
+
t && d(e, t);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
let n = e.children ?? [];
|
|
44
|
+
e.tagName === "tbody" && n.filter((e) => e.tagName === "tr").forEach((e, t) => {
|
|
45
|
+
t % 2 == 1 && d(e, s);
|
|
46
|
+
}), n.forEach((n) => f(n, t || e.tagName === "pre"));
|
|
47
|
+
}, p = () => (e) => f(e), m = (o) => e.sanitize(a().use(r).use(n).use(i).use(p).use(t).processSync(o).toString()), h = (e) => {
|
|
48
|
+
if (typeof navigator > "u" || !navigator.clipboard?.write || typeof ClipboardItem > "u") return g(e);
|
|
49
|
+
let t;
|
|
50
|
+
try {
|
|
51
|
+
t = m(e);
|
|
52
|
+
} catch {
|
|
53
|
+
return g(e);
|
|
54
|
+
}
|
|
55
|
+
return navigator.clipboard.write([new ClipboardItem({
|
|
56
|
+
"text/html": new Blob([t], { type: "text/html" }),
|
|
57
|
+
"text/plain": new Blob([e], { type: "text/plain" })
|
|
58
|
+
})]).then(() => !0).catch(() => g(e));
|
|
59
|
+
}, g = (e) => typeof navigator < "u" && navigator.clipboard?.writeText ? navigator.clipboard.writeText(e).then(() => !0).catch(() => _(e)) : Promise.resolve(_(e)), _ = (e) => {
|
|
60
|
+
let t = document.createElement("textarea");
|
|
61
|
+
t.innerText = e, t.style.cssText = "position:fixed;top:0;left:0;width:1px;height:1px;padding:0;border:none;outline:none;box-shadow:none;background:transparent;opacity:0;", t.setAttribute("autocomplete", "off"), t.setAttribute("readonly", ""), document.body.appendChild(t);
|
|
62
|
+
try {
|
|
63
|
+
return t.focus({ preventScroll: !0 }), t.removeAttribute("readonly"), t.setSelectionRange(0, e.length), document.execCommand("copy");
|
|
64
|
+
} finally {
|
|
65
|
+
document.body.removeChild(t);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
//#endregion
|
|
69
|
+
export { h as copyMarkdownAsRichText, g as copyToClipboard, m as markdownToRichTextHtml };
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { stripUrlQueryAndFragment as e } from "./mime-type.js";
|
|
2
|
+
import { MIME_TYPE_EXT_MAP as t } from "../constants/mime-types.js";
|
|
3
|
+
//#region src/utils/file-download.ts
|
|
4
|
+
var n = /^[a-zA-Z0-9]{1,10}$/, r = (e) => {
|
|
5
|
+
let t = e.lastIndexOf(".");
|
|
6
|
+
if (t <= 0 || t >= e.length - 1) return;
|
|
7
|
+
let r = e.slice(t + 1);
|
|
8
|
+
return n.test(r) ? r : void 0;
|
|
9
|
+
}, i = (n, i, a) => {
|
|
10
|
+
if (r(n) != null) return n;
|
|
11
|
+
if (a != null) {
|
|
12
|
+
let e = t[a];
|
|
13
|
+
if (e != null) return `${n}.${e}`;
|
|
14
|
+
}
|
|
15
|
+
if (i != null) {
|
|
16
|
+
let t = r(e(i).split("/").pop() ?? "");
|
|
17
|
+
if (t != null) return `${n}.${t}`;
|
|
18
|
+
}
|
|
19
|
+
return n;
|
|
20
|
+
}, a = {
|
|
21
|
+
typescript: "ts",
|
|
22
|
+
ts: "ts",
|
|
23
|
+
tsx: "tsx",
|
|
24
|
+
javascript: "js",
|
|
25
|
+
js: "js",
|
|
26
|
+
jsx: "jsx",
|
|
27
|
+
python: "py",
|
|
28
|
+
py: "py",
|
|
29
|
+
java: "java",
|
|
30
|
+
csharp: "cs",
|
|
31
|
+
cs: "cs",
|
|
32
|
+
cpp: "cpp",
|
|
33
|
+
c: "c",
|
|
34
|
+
go: "go",
|
|
35
|
+
rust: "rs",
|
|
36
|
+
rs: "rs",
|
|
37
|
+
ruby: "rb",
|
|
38
|
+
rb: "rb",
|
|
39
|
+
php: "php",
|
|
40
|
+
html: "html",
|
|
41
|
+
css: "css",
|
|
42
|
+
scss: "scss",
|
|
43
|
+
json: "json",
|
|
44
|
+
yaml: "yaml",
|
|
45
|
+
yml: "yml",
|
|
46
|
+
markdown: "md",
|
|
47
|
+
md: "md",
|
|
48
|
+
sql: "sql",
|
|
49
|
+
bash: "sh",
|
|
50
|
+
sh: "sh",
|
|
51
|
+
shell: "sh",
|
|
52
|
+
xml: "xml",
|
|
53
|
+
kotlin: "kt",
|
|
54
|
+
swift: "swift",
|
|
55
|
+
dart: "dart",
|
|
56
|
+
plaintext: "txt",
|
|
57
|
+
text: "txt"
|
|
58
|
+
}, o = (e) => a[e.toLowerCase()] ?? "txt", s = 1e3, c = (e, t) => {
|
|
59
|
+
let n = document.createElement("a");
|
|
60
|
+
n.href = e, n.download = t, n.rel = "noopener", n.style.display = "none", document.body.appendChild(n), n.click(), setTimeout(() => n.remove(), s);
|
|
61
|
+
}, l = (e, t) => {
|
|
62
|
+
let n = URL.createObjectURL(e);
|
|
63
|
+
c(n, t), setTimeout(() => URL.revokeObjectURL(n), s);
|
|
64
|
+
}, u = (e) => {
|
|
65
|
+
try {
|
|
66
|
+
let t = atob(e), n = new Uint8Array(t.length);
|
|
67
|
+
for (let e = 0; e < t.length; e++) n[e] = t.charCodeAt(e);
|
|
68
|
+
return n;
|
|
69
|
+
} catch {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}, d = (e, t) => {
|
|
73
|
+
let n = u(e) ?? new TextEncoder().encode(e);
|
|
74
|
+
return new Blob([n.buffer], { type: t });
|
|
75
|
+
}, f = (e, t, n = "text/plain;charset=utf-8") => {
|
|
76
|
+
l(new Blob([e], { type: n }), t);
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
export { d as base64ToBlob, f as downloadTextFile, i as ensureDownloadFilename, o as getFileExtensionForLanguage, c as triggerAnchorDownload, l as triggerBlobDownload, u as tryBase64ToBytes };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/utils/format-file-size.ts
|
|
2
|
+
var e = 1024, t = e * 1024, n = t * 1024, r = (r) => r >= n ? `${(r / n).toFixed(r % n === 0 ? 0 : 1)} GB` : r >= t ? `${(r / t).toFixed(r % t === 0 ? 0 : 1)} MB` : r >= e ? `${(r / e).toFixed(r % e === 0 ? 0 : 1)} KB` : `${r} B`;
|
|
3
|
+
//#endregion
|
|
4
|
+
export { r as formatFileSize };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/utils/format-last-used.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
if (!e) return "";
|
|
4
|
+
let t = new Date(e);
|
|
5
|
+
if (isNaN(t.getTime())) return "";
|
|
6
|
+
let n = Date.now() - t.getTime(), r = Math.floor(n / 1e3);
|
|
7
|
+
if (r < 60) return "just now";
|
|
8
|
+
let i = Math.floor(r / 60);
|
|
9
|
+
if (i < 60) return `${i} min ago`;
|
|
10
|
+
let a = Math.floor(i / 60);
|
|
11
|
+
if (a < 24) return `${a} hour${a === 1 ? "" : "s"} ago`;
|
|
12
|
+
let o = Math.floor(a / 24);
|
|
13
|
+
if (o < 30) return `${o} day${o === 1 ? "" : "s"} ago`;
|
|
14
|
+
let s = Math.floor(o / 30);
|
|
15
|
+
if (s < 12) return `${s} month${s === 1 ? "" : "s"} ago`;
|
|
16
|
+
let c = Math.floor(s / 12);
|
|
17
|
+
return `${c} year${c === 1 ? "" : "s"} ago`;
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { e as formatLastUsed };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/format-price.ts
|
|
2
|
+
var e = "token", t = 1e6, n = "en-US", r = new Intl.NumberFormat(n, {
|
|
3
|
+
style: "currency",
|
|
4
|
+
currency: "USD",
|
|
5
|
+
minimumFractionDigits: 0,
|
|
6
|
+
maximumFractionDigits: 2
|
|
7
|
+
}), i = new Intl.NumberFormat(n, {
|
|
8
|
+
style: "currency",
|
|
9
|
+
currency: "USD",
|
|
10
|
+
minimumFractionDigits: 0,
|
|
11
|
+
maximumFractionDigits: 6
|
|
12
|
+
}), a = (e) => r.format(e), o = (e) => e !== 0 && Math.abs(e) < 1 ? i.format(e) : a(e), s = (n, r) => {
|
|
13
|
+
if (n == null) return;
|
|
14
|
+
let i = Number(n);
|
|
15
|
+
return n.trim() === "" || !Number.isFinite(i) ? n : r == null || r.toLowerCase() === e ? `${o(i * t)}/M tokens` : `${o(i)}/${r.replace(/_/g, " ")}`;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { a as formatCost, o as formatPrice, s as formatUnitPrice };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/generate-uuid.ts
|
|
2
|
+
var e = () => typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
3
|
+
let t = Math.random() * 16 | 0;
|
|
4
|
+
return (e === "x" ? t : t & 3 | 8).toString(16);
|
|
5
|
+
});
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as generateUUID };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/initials.ts
|
|
2
|
+
var e = (e) => e.match(/\p{L}/u)?.[0] ?? "", t = (t) => {
|
|
3
|
+
let n = t.trim().split(/\s+/).filter(Boolean);
|
|
4
|
+
return n.length === 0 ? "?" : n.length >= 2 ? (e(n[0]) + e(n[1])).toUpperCase() || "?" : n[0].replace(/[^\p{L}]/gu, "").slice(0, 2).toUpperCase() || "?";
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { t as extractInitials };
|
package/utils/latex.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//#region src/utils/latex.ts
|
|
2
|
+
var e = /\$\\ce\{/g, t = /\$\\pu\{/g, n = /\$\\\\ce\{[^}]*\}\$/g, r = /\$\\\\pu\{[^}]*\}\$/g, i = /\$\$([\s\S]*?)\$\$/g, a = /^[ \t]*\r?\n/, o = /\r?\n[ \t]*$/, s = /\d+(?:,\d{3})*(?:\.\d+)?(?:[KMBkmb])?/y, c = /\s|[^a-zA-Z\d]/y, l = /[\^_\\]/y, u = /(?:[<>]|\\(?:le|leq|ll|ge|geq|gg|ne|neq|approx|equiv|sim|simeq|cong|in|notin|subset|subseteq|supset|supseteq|to|rightarrow|leftarrow|mapsto|implies|iff)\b)/y, d = /\\[a-zA-Z]|[\^_]/, f = (i) => {
|
|
3
|
+
let a = i.replace(e, "$\\\\ce{");
|
|
4
|
+
return a = a.replace(t, "$\\\\pu{"), a = a.replace(n, (e) => `$${e}$`), a = a.replace(r, (e) => `$${e}$`), a;
|
|
5
|
+
}, p = (e) => {
|
|
6
|
+
let t = [], n = -1, r = -1;
|
|
7
|
+
for (let i = 0; i < e.length; i++) {
|
|
8
|
+
let a = e[i];
|
|
9
|
+
a === "`" && i + 2 < e.length && e[i + 1] === "`" && e[i + 2] === "`" ? r === -1 ? (r = i, i += 2) : (t.push([r, i + 2]), r = -1, i += 2) : a === "`" && r === -1 && (n === -1 ? n = i : (t.push([n, i]), n = -1));
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
}, m = (e, t) => {
|
|
13
|
+
let n = 0, r = t.length - 1;
|
|
14
|
+
for (; n <= r;) {
|
|
15
|
+
let i = Math.floor((n + r) / 2), [a, o] = t[i];
|
|
16
|
+
if (e >= a && e <= o) return !0;
|
|
17
|
+
e < a ? r = i - 1 : n = i + 1;
|
|
18
|
+
}
|
|
19
|
+
return !1;
|
|
20
|
+
}, h = (e, t, n) => (e.lastIndex = n, e.exec(t)), g = /\s/, _ = (e, t) => {
|
|
21
|
+
let n = t;
|
|
22
|
+
for (; n < e.length && g.test(e[n]);) n++;
|
|
23
|
+
return n;
|
|
24
|
+
}, v = (e) => {
|
|
25
|
+
if (!e.includes("$$")) return e;
|
|
26
|
+
let t = p(e), n = [], r = 0, s;
|
|
27
|
+
for (i.lastIndex = 0; (s = i.exec(e)) !== null;) {
|
|
28
|
+
let i = s.index, c = i + s[0].length, l = s[1];
|
|
29
|
+
if (!l.includes("\n") || m(i, t)) continue;
|
|
30
|
+
let u = e.lastIndexOf("\n", i - 1) + 1;
|
|
31
|
+
if (e.slice(u, i).trim() !== "") continue;
|
|
32
|
+
let d = l.replace(a, "").replace(o, ""), f = e.indexOf("\n", c), p = e.slice(c, f === -1 ? e.length : f);
|
|
33
|
+
n.push(e.slice(r, i)), n.push(`$$\n${d}\n$$${p.trim() === "" ? "" : "\n"}`), r = c;
|
|
34
|
+
}
|
|
35
|
+
return n.push(e.substring(r)), n.join("");
|
|
36
|
+
}, y = (e, t) => {
|
|
37
|
+
let n = h(s, e, t + 1);
|
|
38
|
+
return n ? t + 1 + n[0].length : -1;
|
|
39
|
+
}, b = (e, t) => t >= e.length ? !0 : !(!h(c, e, t) || h(l, e, t) || h(u, e, _(e, t))), x = (e, t) => {
|
|
40
|
+
let n = [];
|
|
41
|
+
for (let r = 0; r < e.length; r++) {
|
|
42
|
+
if (e[r] !== "$") continue;
|
|
43
|
+
let i = r;
|
|
44
|
+
for (; i + 1 < e.length && e[i + 1] === "$";) i++;
|
|
45
|
+
if (i > r) {
|
|
46
|
+
r = i;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
r > 0 && e[r - 1] === "\\" || m(r, t) || n.push(r);
|
|
50
|
+
}
|
|
51
|
+
return n;
|
|
52
|
+
}, S = (e, t, n, r) => {
|
|
53
|
+
if (n <= t + 1 || e[n - 1] === "`") return !1;
|
|
54
|
+
for (let i = t + 1; i < n; i++) if (e[i] === "\n" || e[i] === "$" && !(e[i - 1] === "\\" || r.has(i))) return !1;
|
|
55
|
+
return !0;
|
|
56
|
+
}, C = (e, t, n, r) => n !== void 0 && S(e, t, n, r) && d.test(e.slice(t + 1, n)), w = (e) => {
|
|
57
|
+
if (!e.includes("$")) return e;
|
|
58
|
+
let t = e;
|
|
59
|
+
(e.includes("\\ce{") || e.includes("\\pu{")) && (t = f(e)), t = v(t);
|
|
60
|
+
let n = p(t), r = x(t, n), i = /* @__PURE__ */ new Map(), a = -1;
|
|
61
|
+
for (let e = 0; e < r.length; e++) {
|
|
62
|
+
let n = r[e], o = y(t, n);
|
|
63
|
+
if (o !== -1 && b(t, o) && (a !== -1 || !C(t, n, r[e + 1], i))) {
|
|
64
|
+
i.set(n, "\\$"), a === -1 && r[e + 1] === o && (i.set(o, "\\$"), e++);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (a === -1) {
|
|
68
|
+
a = n;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
S(t, a, n, i) ? (i.set(a, "$$"), i.set(n, "$$"), a = -1) : a = n;
|
|
72
|
+
}
|
|
73
|
+
if (i.size === 0) return t;
|
|
74
|
+
let o = [], s = 0;
|
|
75
|
+
for (let e of [...i.keys()].sort((e, t) => e - t)) o.push(t.slice(s, e)), o.push(i.get(e)), s = e + 1;
|
|
76
|
+
return o.push(t.substring(s)), o.join("");
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
export { w as preprocessLaTeX };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RequestStatus as e } from "../models/chat.js";
|
|
2
|
+
import { AttachmentType as t } from "../types/attachment.js";
|
|
3
|
+
import { getAttachmentTypeFromMime as n, inferMimeTypeFromPath as r } from "./mime-type.js";
|
|
4
|
+
//#region src/utils/message-attachment-to-display.ts
|
|
5
|
+
var i = (e, t, n) => {
|
|
6
|
+
if (!(!e?.startsWith(n) || !t)) return `data:${e};base64,${t}`;
|
|
7
|
+
}, a = (a, o = {}) => {
|
|
8
|
+
let s = n(a.type), c = s === t.Image, l = s === t.Audio, u = a.url && a.reference_url && !a.reference_type, d = a.url ?? a.data ?? a.title, f = (a.url == null && a.reference_url != null ? a.reference_type ?? r(a.reference_url) : void 0) ?? a.type ?? "", p;
|
|
9
|
+
c && (a.url ? p = o.resolvePreviewUrl?.(a) ?? a.url : a.data && (p = i(a.type, a.data, "image/")));
|
|
10
|
+
let m;
|
|
11
|
+
return l && (a.url ? m = o.resolvePlayUrl?.(a) ?? a.url : a.data && (m = i(a.type, a.data, "audio/"))), {
|
|
12
|
+
id: d,
|
|
13
|
+
name: a.title,
|
|
14
|
+
contentType: f,
|
|
15
|
+
type: u ? t.Link : s,
|
|
16
|
+
status: e.Idle,
|
|
17
|
+
...a.url ? { url: a.url } : {},
|
|
18
|
+
...a.reference_url ? { referenceUrl: a.reference_url } : {},
|
|
19
|
+
...c && p ? { previewUrl: p } : {},
|
|
20
|
+
...l && m ? { playUrl: m } : {},
|
|
21
|
+
...!c && !l && a.data ? { data: a.data } : {}
|
|
22
|
+
};
|
|
23
|
+
}, o = (e, t = {}) => {
|
|
24
|
+
let n = /* @__PURE__ */ new Set();
|
|
25
|
+
return e?.reduce((e, r) => {
|
|
26
|
+
let i = a(r, t);
|
|
27
|
+
return n.has(i.id) || (n.add(i.id), e.push(i)), e;
|
|
28
|
+
}, []) ?? [];
|
|
29
|
+
};
|
|
30
|
+
//#endregion
|
|
31
|
+
export { a as messageAttachmentToDisplayAttachment, o as messageAttachmentsToDisplayAttachments };
|
package/utils/message.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AttachmentType as e } from "../types/attachment.js";
|
|
2
|
+
import { MIMEType as t } from "../types/mime-type.js";
|
|
3
|
+
//#region src/utils/mime-type.ts
|
|
4
|
+
var n = {
|
|
5
|
+
md: t.Markdown,
|
|
6
|
+
markdown: t.Markdown,
|
|
7
|
+
txt: t.Plain,
|
|
8
|
+
html: t.HTML,
|
|
9
|
+
htm: t.HTML,
|
|
10
|
+
xhtml: t.XHTML,
|
|
11
|
+
css: t.CSS,
|
|
12
|
+
scss: t.Plain,
|
|
13
|
+
sass: t.Plain,
|
|
14
|
+
less: t.Plain,
|
|
15
|
+
js: t.JavaScript,
|
|
16
|
+
mjs: t.JavaScript,
|
|
17
|
+
cjs: t.JavaScript,
|
|
18
|
+
jsx: t.JavaScript,
|
|
19
|
+
ts: t.TypeScript,
|
|
20
|
+
mts: t.TypeScript,
|
|
21
|
+
cts: t.TypeScript,
|
|
22
|
+
tsx: t.TypeScript,
|
|
23
|
+
csv: t.CSV,
|
|
24
|
+
tsv: t.Plain,
|
|
25
|
+
json: t.JSON,
|
|
26
|
+
jsonl: t.JSON,
|
|
27
|
+
ndjson: t.JSON,
|
|
28
|
+
xml: t.XML,
|
|
29
|
+
pdf: t.PDF,
|
|
30
|
+
zip: t.ZIP,
|
|
31
|
+
gz: t.GZIP,
|
|
32
|
+
gzip: t.GZIP,
|
|
33
|
+
yaml: t.Plain,
|
|
34
|
+
yml: t.Plain,
|
|
35
|
+
toml: t.Plain,
|
|
36
|
+
ini: t.Plain,
|
|
37
|
+
conf: t.Plain,
|
|
38
|
+
cfg: t.Plain,
|
|
39
|
+
py: t.Plain,
|
|
40
|
+
rb: t.Plain,
|
|
41
|
+
go: t.Plain,
|
|
42
|
+
rs: t.Plain,
|
|
43
|
+
java: t.Plain,
|
|
44
|
+
kt: t.Plain,
|
|
45
|
+
swift: t.Plain,
|
|
46
|
+
c: t.Plain,
|
|
47
|
+
h: t.Plain,
|
|
48
|
+
cpp: t.Plain,
|
|
49
|
+
cs: t.Plain,
|
|
50
|
+
sh: t.Plain,
|
|
51
|
+
bash: t.Plain,
|
|
52
|
+
zsh: t.Plain,
|
|
53
|
+
fish: t.Plain,
|
|
54
|
+
ps1: t.Plain,
|
|
55
|
+
log: t.Plain,
|
|
56
|
+
env: t.Plain,
|
|
57
|
+
sql: t.Plain,
|
|
58
|
+
jpg: t.JPEG,
|
|
59
|
+
jpeg: t.JPEG,
|
|
60
|
+
png: t.PNG,
|
|
61
|
+
gif: t.GIF,
|
|
62
|
+
webp: t.WebP,
|
|
63
|
+
bmp: t.BMP,
|
|
64
|
+
svg: t.SVG,
|
|
65
|
+
mp3: t.MP3,
|
|
66
|
+
wav: t.WAV,
|
|
67
|
+
ogg: t.OGG
|
|
68
|
+
}, r = (e) => e.split(/[?#]/)[0], i = (e) => {
|
|
69
|
+
let t = r(e), i = t.lastIndexOf(".");
|
|
70
|
+
if (i !== -1) return n[t.slice(i + 1).toLowerCase()];
|
|
71
|
+
}, a = (t) => t?.startsWith("image/") ? e.Image : t?.startsWith("audio/") ? e.Audio : e.File;
|
|
72
|
+
//#endregion
|
|
73
|
+
export { a as getAttachmentTypeFromMime, i as inferMimeTypeFromPath, r as stripUrlQueryAndFragment };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/utils/prompt-variables.ts
|
|
2
|
+
var e = /\{\{([^{}]+)\}\}/g, t = "cat-prompt-variable", n = new Set(["code", "pre"]), r = (n) => {
|
|
3
|
+
e.lastIndex = 0;
|
|
4
|
+
let r = [], i = 0, a = e.exec(n);
|
|
5
|
+
for (; a != null;) a.index > i && r.push({
|
|
6
|
+
type: "text",
|
|
7
|
+
value: n.slice(i, a.index)
|
|
8
|
+
}), r.push({
|
|
9
|
+
type: "element",
|
|
10
|
+
tagName: "span",
|
|
11
|
+
properties: { className: [t] },
|
|
12
|
+
children: [{
|
|
13
|
+
type: "text",
|
|
14
|
+
value: a[0]
|
|
15
|
+
}]
|
|
16
|
+
}), i = a.index + a[0].length, a = e.exec(n);
|
|
17
|
+
return r.length === 0 ? null : (i < n.length && r.push({
|
|
18
|
+
type: "text",
|
|
19
|
+
value: n.slice(i)
|
|
20
|
+
}), r);
|
|
21
|
+
}, i = (e) => {
|
|
22
|
+
if (e.children == null || e.tagName != null && n.has(e.tagName)) return;
|
|
23
|
+
let t = [];
|
|
24
|
+
for (let n of e.children) {
|
|
25
|
+
if (n.type === "text" && n.value != null) {
|
|
26
|
+
let e = r(n.value);
|
|
27
|
+
t.push(...e ?? [n]);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
i(n), t.push(n);
|
|
31
|
+
}
|
|
32
|
+
e.children = t;
|
|
33
|
+
}, a = () => (e) => {
|
|
34
|
+
i(e);
|
|
35
|
+
}, o = "|", s = (e) => {
|
|
36
|
+
let t = e.indexOf("|");
|
|
37
|
+
return t === -1 ? { name: e } : {
|
|
38
|
+
name: e.slice(0, t),
|
|
39
|
+
defaultValue: e.slice(t + 1)
|
|
40
|
+
};
|
|
41
|
+
}, c = (t) => {
|
|
42
|
+
e.lastIndex = 0;
|
|
43
|
+
let n = /* @__PURE__ */ new Map(), r = e.exec(t);
|
|
44
|
+
for (; r != null;) {
|
|
45
|
+
let i = s(r[1]);
|
|
46
|
+
n.has(i.name) || n.set(i.name, i), r = e.exec(t);
|
|
47
|
+
}
|
|
48
|
+
return Array.from(n.values());
|
|
49
|
+
}, l = (t, n) => t.replace(e, (e, t) => {
|
|
50
|
+
let { name: r, defaultValue: i } = s(t);
|
|
51
|
+
return n[r] ?? i ?? e;
|
|
52
|
+
}), u = (e) => {
|
|
53
|
+
let t = {};
|
|
54
|
+
for (let { name: n, defaultValue: r } of e) r != null && (t[n] = r);
|
|
55
|
+
return t;
|
|
56
|
+
};
|
|
57
|
+
//#endregion
|
|
58
|
+
export { o as PROMPT_PARAM_DEFAULT_SEPARATOR, e as PROMPT_PARAM_PATTERN, t as PROMPT_VARIABLE_CLASS_NAME, u as buildPromptParamDefaults, c as extractPromptParams, a as rehypePromptVariables, l as resolvePromptParams };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/string-utils.ts
|
|
2
|
+
var e = /[\t":;/\\,={}%&]/g, t = (t) => t.replace(e, ""), n = (e) => {
|
|
3
|
+
let t = e.length;
|
|
4
|
+
for (; t > 0 && e[t - 1] === ".";) --t;
|
|
5
|
+
return e.slice(0, t);
|
|
6
|
+
}, r = new TextEncoder(), i = new TextDecoder(), a = (e) => r.encode(e).length, o = (e, t) => {
|
|
7
|
+
let n = r.encode(e);
|
|
8
|
+
if (n.length <= t) return e;
|
|
9
|
+
let a = t;
|
|
10
|
+
for (; a > 0 && (n[a] & 192) == 128;) --a;
|
|
11
|
+
return i.decode(n.subarray(0, a));
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as PROHIBITED_CONVERSATION_NAME_CHARS_RE, a as getUtf8ByteLength, t as sanitizeConversationName, n as stripTrailingDots, o as truncateToUtf8Bytes };
|