@aleph-alpha/chat-kit 3.1.3 → 3.3.0
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/dist/{CkInput.vue_vue_type_script_setup_true_lang-LPrW7CSQ.js → CkInput.vue_vue_type_script_setup_true_lang-BAcBFs6I.js} +302 -71
- package/dist/adapters/responses-api.d.ts.map +1 -1
- package/dist/adapters/responses-api.js +63 -37
- package/dist/chat-kit.css +6 -0
- package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts +7 -0
- package/dist/components/base/CkAgentMessage/CkAgentMessage.stories.d.ts.map +1 -1
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts +47 -0
- package/dist/components/base/CkCitation/CkCitation.stories.d.ts.map +1 -0
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts +15 -0
- package/dist/components/base/CkCitation/CkCitation.vue.d.ts.map +1 -0
- package/dist/components/base/CkCitation/index.d.ts +3 -0
- package/dist/components/base/CkCitation/index.d.ts.map +1 -0
- package/dist/components/base/CkCitation/types.d.ts +79 -0
- package/dist/components/base/CkCitation/types.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts +51 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.stories.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts +13 -0
- package/dist/components/base/CkCitationCard/CkCitationCard.vue.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/index.d.ts +3 -0
- package/dist/components/base/CkCitationCard/index.d.ts.map +1 -0
- package/dist/components/base/CkCitationCard/types.d.ts +51 -0
- package/dist/components/base/CkCitationCard/types.d.ts.map +1 -0
- package/dist/components/base/CkDropZoneOverlay/CkDropZoneOverlay.vue.d.ts +1 -1
- package/dist/components/base/CkFeedbackDialog/CkFeedbackDialog.vue.d.ts +2 -2
- package/dist/components/base/CkFileItemsList/CkFileItemsList.vue.d.ts +1 -1
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts +15 -0
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts +16 -2
- package/dist/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/index.d.ts +1 -1
- package/dist/components/base/CkMarkdownRenderer/index.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/types.d.ts +25 -0
- package/dist/components/base/CkMarkdownRenderer/types.d.ts.map +1 -1
- package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts +17 -0
- package/dist/components/base/CkMarkdownRenderer/useCitationRendering.d.ts.map +1 -0
- package/dist/components/base/CkPromptSendButton/CkPromptSendButton.vue.d.ts +1 -1
- package/dist/components/base/index.d.ts +5 -1
- package/dist/components/base/index.d.ts.map +1 -1
- package/dist/components/composed/CkInput/CkInput.vue.d.ts +1 -1
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +25 -23
- package/dist/composables/fileUpload/types.d.ts +3 -0
- package/dist/composables/fileUpload/types.d.ts.map +1 -1
- package/dist/composables/fileUpload/useFileUpload.d.ts.map +1 -1
- package/dist/composables/fileUpload/useFileUploadWrapper.d.ts.map +1 -1
- package/dist/composables/index.js +1 -1
- package/dist/handlers/index.d.ts +3 -0
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/index.js +4 -1
- package/dist/handlers/useChatKitLabels.d.ts +11 -0
- package/dist/handlers/useChatKitLabels.d.ts.map +1 -1
- package/dist/handlers/useMarkdownParser.d.ts.map +1 -1
- package/dist/helpers/unified/remarkCitations.d.ts +17 -0
- package/dist/helpers/unified/remarkCitations.d.ts.map +1 -0
- package/dist/helpers/unified/remarkNormalizeMath.d.ts +24 -0
- package/dist/helpers/unified/remarkNormalizeMath.d.ts.map +1 -0
- package/dist/{index-DVxCNAs3.js → index-C6njJ8EB.js} +96 -49
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -26
- package/dist/{useChatKitLabels-Ctz1dHpx.js → useChatKitLabels-BM2I7-9o.js} +126 -3
- package/package.json +6 -3
- package/src/adapters/responses-api.spec.ts +156 -0
- package/src/adapters/responses-api.ts +125 -58
- package/src/components/base/CkAgentMessage/CkAgentMessage.stories.ts +112 -0
- package/src/components/base/CkCitation/CkCitation.spec.ts +79 -0
- package/src/components/base/CkCitation/CkCitation.stories.ts +136 -0
- package/src/components/base/CkCitation/CkCitation.vue +145 -0
- package/src/components/base/CkCitation/index.ts +2 -0
- package/src/components/base/CkCitation/types.ts +80 -0
- package/src/components/base/CkCitationCard/CkCitationCard.spec.ts +77 -0
- package/src/components/base/CkCitationCard/CkCitationCard.stories.ts +144 -0
- package/src/components/base/CkCitationCard/CkCitationCard.vue +76 -0
- package/src/components/base/CkCitationCard/index.ts +2 -0
- package/src/components/base/CkCitationCard/types.ts +51 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.spec.ts +124 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.ts +118 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue +70 -28
- package/src/components/base/CkMarkdownRenderer/index.ts +1 -0
- package/src/components/base/CkMarkdownRenderer/types.ts +26 -0
- package/src/components/base/CkMarkdownRenderer/useCitationRendering.spec.ts +94 -0
- package/src/components/base/CkMarkdownRenderer/useCitationRendering.ts +52 -0
- package/src/components/base/index.ts +12 -0
- package/src/components/index.ts +8 -0
- package/src/composables/fileUpload/types.ts +6 -0
- package/src/composables/fileUpload/useFileUpload.spec.ts +2 -61
- package/src/composables/fileUpload/useFileUpload.ts +9 -10
- package/src/composables/fileUpload/useFileUploadWrapper.spec.ts +241 -10
- package/src/composables/fileUpload/useFileUploadWrapper.ts +126 -53
- package/src/handlers/index.ts +6 -0
- package/src/handlers/useChatKitLabels.ts +13 -0
- package/src/handlers/useMarkdownParser.spec.ts +34 -0
- package/src/handlers/useMarkdownParser.ts +15 -3
- package/src/helpers/unified/remarkCitations.spec.ts +112 -0
- package/src/helpers/unified/remarkCitations.ts +55 -0
- package/src/helpers/unified/remarkNormalizeMath.spec.ts +84 -0
- package/src/helpers/unified/remarkNormalizeMath.ts +134 -0
- package/src/index.ts +8 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Plugin } from 'unified';
|
|
2
|
+
|
|
3
|
+
const PLACEHOLDER_PREFIX = '\uE000PH_';
|
|
4
|
+
const PLACEHOLDER_SUFFIX = '\uE000';
|
|
5
|
+
const PLACEHOLDER_RE = /\uE000PH_(\d+)\uE000/g;
|
|
6
|
+
|
|
7
|
+
const FENCE_START_RE = /^[ \t]{0,3}(`{3,}|~{3,})/;
|
|
8
|
+
const INLINE_CODE_RE = /`[^`\n]+`/g;
|
|
9
|
+
|
|
10
|
+
const LATEX_BLOCK_RE = /\\\[([\s\S]+?)\\\]/g;
|
|
11
|
+
const LATEX_INLINE_RE = /\\\(([^\n]+?)\\\)/g;
|
|
12
|
+
const SINGLE_LINE_DOUBLE_DOLLAR_RE = /\$\$([^\n$]+?)\$\$/g;
|
|
13
|
+
|
|
14
|
+
type Stash = (value: string) => string;
|
|
15
|
+
|
|
16
|
+
function isClosingFence(
|
|
17
|
+
line: string,
|
|
18
|
+
fenceChar: string,
|
|
19
|
+
minLen: number,
|
|
20
|
+
): boolean {
|
|
21
|
+
let i = 0;
|
|
22
|
+
let indent = 0;
|
|
23
|
+
while (
|
|
24
|
+
i < line.length &&
|
|
25
|
+
(line[i] === ' ' || line[i] === '\t') &&
|
|
26
|
+
indent < 4
|
|
27
|
+
) {
|
|
28
|
+
indent++;
|
|
29
|
+
i++;
|
|
30
|
+
}
|
|
31
|
+
if (indent >= 4) return false;
|
|
32
|
+
let runLen = 0;
|
|
33
|
+
while (i < line.length && line[i] === fenceChar) {
|
|
34
|
+
runLen++;
|
|
35
|
+
i++;
|
|
36
|
+
}
|
|
37
|
+
if (runLen < minLen) return false;
|
|
38
|
+
while (i < line.length) {
|
|
39
|
+
if (line[i] !== ' ' && line[i] !== '\t') return false;
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Walk the source line-by-line and stash fenced code blocks (```/~~~) so
|
|
47
|
+
* their contents are not rewritten by subsequent math regexes. A line-based
|
|
48
|
+
* scanner avoids the catastrophic-backtracking risk of a single regex over the
|
|
49
|
+
* whole document.
|
|
50
|
+
*/
|
|
51
|
+
function protectFencedCode(input: string, stash: Stash): string {
|
|
52
|
+
const lines = input.split('\n');
|
|
53
|
+
const out: string[] = [];
|
|
54
|
+
let i = 0;
|
|
55
|
+
while (i < lines.length) {
|
|
56
|
+
const match = FENCE_START_RE.exec(lines[i]);
|
|
57
|
+
if (match) {
|
|
58
|
+
const fence = match[1];
|
|
59
|
+
const fenceChar = fence[0];
|
|
60
|
+
const minLen = fence.length;
|
|
61
|
+
const block: string[] = [lines[i]];
|
|
62
|
+
i++;
|
|
63
|
+
while (i < lines.length) {
|
|
64
|
+
const current = lines[i];
|
|
65
|
+
block.push(current);
|
|
66
|
+
i++;
|
|
67
|
+
if (isClosingFence(current, fenceChar, minLen)) break;
|
|
68
|
+
}
|
|
69
|
+
out.push(stash(block.join('\n')));
|
|
70
|
+
} else {
|
|
71
|
+
out.push(lines[i]);
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return out.join('\n');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Normalize math delimiters in a markdown source string so they survive
|
|
80
|
+
* `remark-math`'s CommonMark-style parsing:
|
|
81
|
+
*
|
|
82
|
+
* - LaTeX-style block delimiters `\[ ... \]` become a fenced `$$ ... $$` block.
|
|
83
|
+
* - LaTeX-style inline delimiters `\( ... \)` become inline `$ ... $`.
|
|
84
|
+
* - Single-line `$$ ... $$` (which `remark-math` treats as inline math)
|
|
85
|
+
* is promoted to a proper block math fence on its own lines.
|
|
86
|
+
*
|
|
87
|
+
* Content inside fenced (``` / ~~~) or inline (`) code spans is preserved
|
|
88
|
+
* verbatim and is not subject to any of these rewrites.
|
|
89
|
+
*/
|
|
90
|
+
export function normalizeMathDelimiters(input: string): string {
|
|
91
|
+
if (!input) return input;
|
|
92
|
+
|
|
93
|
+
const placeholders: string[] = [];
|
|
94
|
+
const stash: Stash = (value) => {
|
|
95
|
+
const id = placeholders.length;
|
|
96
|
+
placeholders.push(value);
|
|
97
|
+
return `${PLACEHOLDER_PREFIX}${id}${PLACEHOLDER_SUFFIX}`;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
let s = protectFencedCode(input, stash);
|
|
101
|
+
s = s.replace(INLINE_CODE_RE, stash);
|
|
102
|
+
|
|
103
|
+
s = s.replace(
|
|
104
|
+
LATEX_BLOCK_RE,
|
|
105
|
+
(_m, body: string) => `\n\n$$\n${body.trim()}\n$$\n\n`,
|
|
106
|
+
);
|
|
107
|
+
s = s.replace(LATEX_INLINE_RE, (_m, body: string) => `$${body.trim()}$`);
|
|
108
|
+
s = s.replace(
|
|
109
|
+
SINGLE_LINE_DOUBLE_DOLLAR_RE,
|
|
110
|
+
(_m, body: string) => `\n\n$$\n${body.trim()}\n$$\n\n`,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
s = s.replace(PLACEHOLDER_RE, (_m, id: string) => placeholders[Number(id)]);
|
|
114
|
+
return s;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type ParserLike = (document: string, file: unknown) => unknown;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Unified plugin that wraps `this.parser` so the markdown source is run
|
|
121
|
+
* through {@link normalizeMathDelimiters} before parsing.
|
|
122
|
+
*
|
|
123
|
+
* Register this plugin *after* `remark-parse`, otherwise `this.parser` is not
|
|
124
|
+
* yet defined when the plugin is invoked at freeze time and the wrap is a
|
|
125
|
+
* no-op.
|
|
126
|
+
*/
|
|
127
|
+
export const remarkNormalizeMath: Plugin<[]> = function () {
|
|
128
|
+
const processor = this as unknown as { parser?: ParserLike };
|
|
129
|
+
const originalParser = processor.parser;
|
|
130
|
+
if (typeof originalParser !== 'function') return;
|
|
131
|
+
|
|
132
|
+
processor.parser = (document, file) =>
|
|
133
|
+
originalParser(normalizeMathDelimiters(document), file);
|
|
134
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -63,6 +63,8 @@ export type {
|
|
|
63
63
|
// Components
|
|
64
64
|
export {
|
|
65
65
|
CkAgentMessage,
|
|
66
|
+
CkCitation,
|
|
67
|
+
CkCitationCard,
|
|
66
68
|
CkConversation,
|
|
67
69
|
CkConversationLayout,
|
|
68
70
|
CkCopyMessageActionButton,
|
|
@@ -87,6 +89,11 @@ export {
|
|
|
87
89
|
CkUserMessage,
|
|
88
90
|
} from './components';
|
|
89
91
|
export type {
|
|
92
|
+
CkCitationProps,
|
|
93
|
+
CkCitationEmits,
|
|
94
|
+
CkCitationSource,
|
|
95
|
+
CkCitationCardProps,
|
|
96
|
+
CkCitationCardEmits,
|
|
90
97
|
CkConversationLayoutProps,
|
|
91
98
|
CkConversationProps,
|
|
92
99
|
CkDropZoneOverlayProps,
|
|
@@ -110,6 +117,7 @@ export type {
|
|
|
110
117
|
CkHistoryWrapperProps,
|
|
111
118
|
CkMarkdownElementClasses,
|
|
112
119
|
CkMarkdownRendererProps,
|
|
120
|
+
CkMarkdownRendererEmits,
|
|
113
121
|
CkModelOption,
|
|
114
122
|
CkModelSelectorProps,
|
|
115
123
|
CkModelSelectorEmits,
|