@chenzy-design/core 0.2.1 → 0.4.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/ai-chat-dialogue.d.ts +300 -0
- package/dist/ai-chat-dialogue.d.ts.map +1 -0
- package/dist/ai-chat-dialogue.js +699 -0
- package/dist/ai-chat-dialogue.js.map +1 -0
- package/dist/ai-chat-dialogue.test.d.ts +2 -0
- package/dist/ai-chat-dialogue.test.d.ts.map +1 -0
- package/dist/ai-chat-dialogue.test.js +338 -0
- package/dist/ai-chat-dialogue.test.js.map +1 -0
- package/dist/ai-chat-input.d.ts +191 -0
- package/dist/ai-chat-input.d.ts.map +1 -0
- package/dist/ai-chat-input.js +274 -0
- package/dist/ai-chat-input.js.map +1 -0
- package/dist/ai-chat-input.test.d.ts +2 -0
- package/dist/ai-chat-input.test.d.ts.map +1 -0
- package/dist/ai-chat-input.test.js +339 -0
- package/dist/ai-chat-input.test.js.map +1 -0
- package/dist/audio-player.d.ts +154 -0
- package/dist/audio-player.d.ts.map +1 -0
- package/dist/audio-player.js +254 -0
- package/dist/audio-player.js.map +1 -0
- package/dist/audio-player.test.d.ts +2 -0
- package/dist/audio-player.test.d.ts.map +1 -0
- package/dist/audio-player.test.js +275 -0
- package/dist/audio-player.test.js.map +1 -0
- package/dist/back-top.d.ts +4 -1
- package/dist/back-top.d.ts.map +1 -1
- package/dist/back-top.js +5 -2
- package/dist/back-top.js.map +1 -1
- package/dist/back-top.test.js +3 -2
- package/dist/back-top.test.js.map +1 -1
- package/dist/calendar.d.ts +132 -44
- package/dist/calendar.d.ts.map +1 -1
- package/dist/calendar.js +413 -70
- package/dist/calendar.js.map +1 -1
- package/dist/calendar.test.js +160 -76
- package/dist/calendar.test.js.map +1 -1
- package/dist/chat.d.ts +172 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +210 -0
- package/dist/chat.js.map +1 -0
- package/dist/chat.test.d.ts +2 -0
- package/dist/chat.test.d.ts.map +1 -0
- package/dist/chat.test.js +181 -0
- package/dist/chat.test.js.map +1 -0
- package/dist/code-highlight.d.ts +30 -0
- package/dist/code-highlight.d.ts.map +1 -0
- package/dist/code-highlight.js +37 -0
- package/dist/code-highlight.js.map +1 -0
- package/dist/code-highlight.test.d.ts +2 -0
- package/dist/code-highlight.test.d.ts.map +1 -0
- package/dist/code-highlight.test.js +36 -0
- package/dist/code-highlight.test.js.map +1 -0
- package/dist/collapsible.d.ts +41 -0
- package/dist/collapsible.d.ts.map +1 -0
- package/dist/collapsible.js +33 -0
- package/dist/collapsible.js.map +1 -0
- package/dist/collapsible.test.d.ts +2 -0
- package/dist/collapsible.test.d.ts.map +1 -0
- package/dist/collapsible.test.js +57 -0
- package/dist/collapsible.test.js.map +1 -0
- package/dist/color-value.d.ts +60 -0
- package/dist/color-value.d.ts.map +1 -0
- package/dist/color-value.js +165 -0
- package/dist/color-value.js.map +1 -0
- package/dist/color-value.test.d.ts +2 -0
- package/dist/color-value.test.d.ts.map +1 -0
- package/dist/color-value.test.js +104 -0
- package/dist/color-value.test.js.map +1 -0
- package/dist/config-provider.d.ts +76 -37
- package/dist/config-provider.d.ts.map +1 -1
- package/dist/config-provider.js +107 -32
- package/dist/config-provider.js.map +1 -1
- package/dist/config-provider.test.js +123 -60
- package/dist/config-provider.test.js.map +1 -1
- package/dist/cropper.d.ts +164 -0
- package/dist/cropper.d.ts.map +1 -0
- package/dist/cropper.js +841 -0
- package/dist/cropper.js.map +1 -0
- package/dist/cropper.test.d.ts +2 -0
- package/dist/cropper.test.d.ts.map +1 -0
- package/dist/cropper.test.js +259 -0
- package/dist/cropper.test.js.map +1 -0
- package/dist/drag-move.d.ts +119 -0
- package/dist/drag-move.d.ts.map +1 -0
- package/dist/drag-move.js +237 -0
- package/dist/drag-move.js.map +1 -0
- package/dist/drag-move.test.d.ts +2 -0
- package/dist/drag-move.test.d.ts.map +1 -0
- package/dist/drag-move.test.js +304 -0
- package/dist/drag-move.test.js.map +1 -0
- package/dist/editable.d.ts +24 -4
- package/dist/editable.d.ts.map +1 -1
- package/dist/editable.js +18 -0
- package/dist/editable.js.map +1 -1
- package/dist/editable.test.js +55 -2
- package/dist/editable.test.js.map +1 -1
- package/dist/ellipsis.d.ts +13 -0
- package/dist/ellipsis.d.ts.map +1 -1
- package/dist/ellipsis.js +36 -0
- package/dist/ellipsis.js.map +1 -1
- package/dist/ellipsis.test.js +37 -1
- package/dist/ellipsis.test.js.map +1 -1
- package/dist/form-path.d.ts +19 -0
- package/dist/form-path.d.ts.map +1 -0
- package/dist/form-path.js +97 -0
- package/dist/form-path.js.map +1 -0
- package/dist/form-path.test.d.ts +2 -0
- package/dist/form-path.test.d.ts.map +1 -0
- package/dist/form-path.test.js +57 -0
- package/dist/form-path.test.js.map +1 -0
- package/dist/form-validate.d.ts +13 -0
- package/dist/form-validate.d.ts.map +1 -0
- package/dist/form-validate.js +204 -0
- package/dist/form-validate.js.map +1 -0
- package/dist/form.d.ts +91 -18
- package/dist/form.d.ts.map +1 -1
- package/dist/form.js +170 -115
- package/dist/form.js.map +1 -1
- package/dist/form.test.js +349 -76
- package/dist/form.test.js.map +1 -1
- package/dist/highlight.d.ts +42 -32
- package/dist/highlight.d.ts.map +1 -1
- package/dist/highlight.js +67 -41
- package/dist/highlight.js.map +1 -1
- package/dist/highlight.test.js +73 -32
- package/dist/highlight.test.js.map +1 -1
- package/dist/hotkeys.d.ts +151 -0
- package/dist/hotkeys.d.ts.map +1 -0
- package/dist/hotkeys.js +188 -0
- package/dist/hotkeys.js.map +1 -0
- package/dist/hotkeys.test.d.ts +2 -0
- package/dist/hotkeys.test.d.ts.map +1 -0
- package/dist/hotkeys.test.js +170 -0
- package/dist/hotkeys.test.js.map +1 -0
- package/dist/index.d.ts +33 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -13
- package/dist/index.js.map +1 -1
- package/dist/input.d.ts +34 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +54 -0
- package/dist/input.js.map +1 -0
- package/dist/input.test.d.ts +2 -0
- package/dist/input.test.d.ts.map +1 -0
- package/dist/input.test.js +56 -0
- package/dist/input.test.js.map +1 -0
- package/dist/markdown-render.d.ts +49 -0
- package/dist/markdown-render.d.ts.map +1 -0
- package/dist/markdown-render.js +61 -0
- package/dist/markdown-render.js.map +1 -0
- package/dist/markdown-render.test.d.ts +2 -0
- package/dist/markdown-render.test.d.ts.map +1 -0
- package/dist/markdown-render.test.js +106 -0
- package/dist/markdown-render.test.js.map +1 -0
- package/dist/notification.d.ts +40 -31
- package/dist/notification.d.ts.map +1 -1
- package/dist/notification.js +86 -70
- package/dist/notification.js.map +1 -1
- package/dist/notification.test.js +62 -39
- package/dist/notification.test.js.map +1 -1
- package/dist/numeral.d.ts +32 -0
- package/dist/numeral.d.ts.map +1 -0
- package/dist/numeral.js +67 -0
- package/dist/numeral.js.map +1 -0
- package/dist/numeral.test.d.ts +2 -0
- package/dist/numeral.test.d.ts.map +1 -0
- package/dist/numeral.test.js +59 -0
- package/dist/numeral.test.js.map +1 -0
- package/dist/overflow-list.d.ts +9 -40
- package/dist/overflow-list.d.ts.map +1 -1
- package/dist/overflow-list.js +9 -70
- package/dist/overflow-list.js.map +1 -1
- package/dist/overflow-list.test.js +1 -122
- package/dist/overflow-list.test.js.map +1 -1
- package/dist/pagination.d.ts +17 -0
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +48 -0
- package/dist/pagination.js.map +1 -1
- package/dist/pagination.test.js +40 -1
- package/dist/pagination.test.js.map +1 -1
- package/dist/pincode.d.ts +79 -0
- package/dist/pincode.d.ts.map +1 -0
- package/dist/pincode.js +119 -0
- package/dist/pincode.js.map +1 -0
- package/dist/pincode.test.d.ts +2 -0
- package/dist/pincode.test.d.ts.map +1 -0
- package/dist/pincode.test.js +151 -0
- package/dist/pincode.test.js.map +1 -0
- package/dist/progress.d.ts +32 -30
- package/dist/progress.d.ts.map +1 -1
- package/dist/progress.js +257 -64
- package/dist/progress.js.map +1 -1
- package/dist/progress.test.js +50 -47
- package/dist/progress.test.js.map +1 -1
- package/dist/resizable.d.ts +200 -0
- package/dist/resizable.d.ts.map +1 -0
- package/dist/resizable.js +329 -0
- package/dist/resizable.js.map +1 -0
- package/dist/resizable.test.d.ts +2 -0
- package/dist/resizable.test.d.ts.map +1 -0
- package/dist/resizable.test.js +302 -0
- package/dist/resizable.test.js.map +1 -0
- package/dist/scroll-list.d.ts +69 -62
- package/dist/scroll-list.d.ts.map +1 -1
- package/dist/scroll-list.js +103 -144
- package/dist/scroll-list.js.map +1 -1
- package/dist/scroll-list.test.js +100 -110
- package/dist/scroll-list.test.js.map +1 -1
- package/dist/sidebar.d.ts +46 -0
- package/dist/sidebar.d.ts.map +1 -0
- package/dist/sidebar.js +65 -0
- package/dist/sidebar.js.map +1 -0
- package/dist/sidebar.test.d.ts +2 -0
- package/dist/sidebar.test.d.ts.map +1 -0
- package/dist/sidebar.test.js +88 -0
- package/dist/sidebar.test.js.map +1 -0
- package/dist/spin.d.ts +5 -5
- package/dist/spin.d.ts.map +1 -1
- package/dist/spin.js +13 -39
- package/dist/spin.js.map +1 -1
- package/dist/spin.test.js +2 -26
- package/dist/spin.test.js.map +1 -1
- package/dist/toast.d.ts +33 -30
- package/dist/toast.d.ts.map +1 -1
- package/dist/toast.js +77 -72
- package/dist/toast.js.map +1 -1
- package/dist/toast.test.js +63 -37
- package/dist/toast.test.js.map +1 -1
- package/dist/tree.d.ts +22 -5
- package/dist/tree.d.ts.map +1 -1
- package/dist/tree.js +61 -9
- package/dist/tree.js.map +1 -1
- package/dist/tree.test.js +72 -1
- package/dist/tree.test.js.map +1 -1
- package/dist/user-guide.d.ts +73 -0
- package/dist/user-guide.d.ts.map +1 -0
- package/dist/user-guide.js +95 -0
- package/dist/user-guide.js.map +1 -0
- package/dist/user-guide.test.d.ts +2 -0
- package/dist/user-guide.test.d.ts.map +1 -0
- package/dist/user-guide.test.js +109 -0
- package/dist/user-guide.test.js.map +1 -0
- package/dist/video-player.d.ts +196 -0
- package/dist/video-player.d.ts.map +1 -0
- package/dist/video-player.js +461 -0
- package/dist/video-player.js.map +1 -0
- package/dist/video-player.test.d.ts +2 -0
- package/dist/video-player.test.d.ts.map +1 -0
- package/dist/video-player.test.js +435 -0
- package/dist/video-player.test.js.map +1 -0
- package/package.json +17 -1
- package/dist/banner.d.ts +0 -19
- package/dist/banner.d.ts.map +0 -1
- package/dist/banner.js +0 -20
- package/dist/banner.js.map +0 -1
- package/dist/banner.test.d.ts +0 -2
- package/dist/banner.test.d.ts.map +0 -1
- package/dist/banner.test.js +0 -29
- package/dist/banner.test.js.map +0 -1
- package/dist/breakpoints.d.ts +0 -30
- package/dist/breakpoints.d.ts.map +0 -1
- package/dist/breakpoints.js +0 -45
- package/dist/breakpoints.js.map +0 -1
- package/dist/breakpoints.test.d.ts +0 -2
- package/dist/breakpoints.test.d.ts.map +0 -1
- package/dist/breakpoints.test.js +0 -46
- package/dist/breakpoints.test.js.map +0 -1
- package/dist/lottie-icon.d.ts +0 -88
- package/dist/lottie-icon.d.ts.map +0 -1
- package/dist/lottie-icon.js +0 -84
- package/dist/lottie-icon.js.map +0 -1
- package/dist/lottie-icon.test.d.ts +0 -2
- package/dist/lottie-icon.test.d.ts.map +0 -1
- package/dist/lottie-icon.test.js +0 -88
- package/dist/lottie-icon.test.js.map +0 -1
- package/dist/sider.d.ts +0 -26
- package/dist/sider.d.ts.map +0 -1
- package/dist/sider.js +0 -55
- package/dist/sider.js.map +0 -1
- package/dist/sider.test.d.ts +0 -2
- package/dist/sider.test.d.ts.map +0 -1
- package/dist/sider.test.js +0 -29
- package/dist/sider.test.js.map +0 -1
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判定一次 Enter 键是否应触发发送(而非换行)。
|
|
3
|
+
* - sendHotKey='enter':裸 Enter 发送,Shift+Enter 换行。
|
|
4
|
+
* - sendHotKey='shift+enter':Shift+Enter 发送,裸 Enter 换行。
|
|
5
|
+
* IME 组字中(composing)永不发送,交由渲染层前置拦截。
|
|
6
|
+
*/
|
|
7
|
+
export function isSendHotKey(key, shiftKey, sendHotKey) {
|
|
8
|
+
if (key !== 'Enter')
|
|
9
|
+
return false;
|
|
10
|
+
return sendHotKey === 'enter' ? !shiftKey : shiftKey;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 解析当前是否可发送。
|
|
14
|
+
* - 显式传入 canSend(受控)时直接返回它。
|
|
15
|
+
* - 否则:富文本非空 或 有附件 即可发送。
|
|
16
|
+
*/
|
|
17
|
+
export function resolveCanSend(params) {
|
|
18
|
+
const { canSend, isEmpty, attachments } = params;
|
|
19
|
+
if (canSend !== undefined)
|
|
20
|
+
return canSend;
|
|
21
|
+
const validRichText = !isEmpty;
|
|
22
|
+
const validAttachment = Array.isArray(attachments) && attachments.length > 0;
|
|
23
|
+
return validRichText || validAttachment;
|
|
24
|
+
}
|
|
25
|
+
/** 组装 onMessageSend 载荷。空字段省略,保持载荷精简。 */
|
|
26
|
+
export function buildMessageContent(params) {
|
|
27
|
+
const { inputContents, attachments, references, setup } = params;
|
|
28
|
+
const msg = {};
|
|
29
|
+
if (inputContents && inputContents.length > 0)
|
|
30
|
+
msg.inputContents = inputContents;
|
|
31
|
+
if (attachments && attachments.length > 0)
|
|
32
|
+
msg.attachments = attachments;
|
|
33
|
+
if (references && references.length > 0)
|
|
34
|
+
msg.references = references;
|
|
35
|
+
if (setup && Object.keys(setup).length > 0)
|
|
36
|
+
msg.setup = setup;
|
|
37
|
+
return msg;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 把 tiptap 文档 JSON 归一为 AIChatInputContent[](阶段 1)。
|
|
41
|
+
* 阶段 1 只有段落文本:每个顶层块产出一段 `{ type:'text', text }`,空段丢弃。
|
|
42
|
+
* transformer(Map<nodeType, fn>)可覆盖特定节点的转换(对齐 Semi transformer)。
|
|
43
|
+
* 阶段 2+ 的 input-slot/select-slot 节点在此扩展。
|
|
44
|
+
*/
|
|
45
|
+
export function transformDocToContents(json, transformer) {
|
|
46
|
+
const doc = json;
|
|
47
|
+
if (!doc || !Array.isArray(doc.content))
|
|
48
|
+
return [];
|
|
49
|
+
const out = [];
|
|
50
|
+
for (const block of doc.content) {
|
|
51
|
+
const t = block?.type ?? '';
|
|
52
|
+
const override = transformer?.get(t);
|
|
53
|
+
if (override) {
|
|
54
|
+
out.push(override(block));
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const text = extractText(block);
|
|
58
|
+
if (text.length > 0)
|
|
59
|
+
out.push({ type: 'text', text });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** 零宽字符(对齐 Semi ZERO_WIDTH_CHAR):inputSlot 空态占位锚点,归一时剔除。 */
|
|
64
|
+
export const AI_CHAT_INPUT_ZERO_WIDTH = '';
|
|
65
|
+
/**
|
|
66
|
+
* 递归抽取一个块内的纯文本(含 hardBreak → 换行)。内联自定义 slot 节点归一:
|
|
67
|
+
* - selectSlot:取 attrs.value(用户选中的选项值)。
|
|
68
|
+
* - skillSlot:取 attrs.label ?? attrs.value(技能显示文本)。
|
|
69
|
+
* - inputSlot:取可编辑内容文本(剔零宽字符);为空回退 attrs.placeholder。
|
|
70
|
+
* 对齐 Semi transformSelectSlot / transformSkillSlot / transformInputSlot,使 slot 内容开箱进 content。
|
|
71
|
+
*/
|
|
72
|
+
function extractText(node) {
|
|
73
|
+
const n = node;
|
|
74
|
+
if (!n)
|
|
75
|
+
return '';
|
|
76
|
+
if (n.type === 'text') {
|
|
77
|
+
const t = n.text ?? '';
|
|
78
|
+
return t === AI_CHAT_INPUT_ZERO_WIDTH ? '' : t;
|
|
79
|
+
}
|
|
80
|
+
if (n.type === 'hardBreak')
|
|
81
|
+
return '\n';
|
|
82
|
+
if (n.type === 'selectSlot') {
|
|
83
|
+
const v = n.attrs?.value;
|
|
84
|
+
return typeof v === 'string' ? v : '';
|
|
85
|
+
}
|
|
86
|
+
if (n.type === 'skillSlot') {
|
|
87
|
+
const label = n.attrs?.label ?? n.attrs?.value;
|
|
88
|
+
return typeof label === 'string' ? label : '';
|
|
89
|
+
}
|
|
90
|
+
if (n.type === 'inputSlot') {
|
|
91
|
+
const inner = Array.isArray(n.content) ? n.content.map(extractText).join('') : '';
|
|
92
|
+
if (inner.length > 0)
|
|
93
|
+
return inner;
|
|
94
|
+
const ph = n.attrs?.placeholder;
|
|
95
|
+
return typeof ph === 'string' ? ph : '';
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(n.content))
|
|
98
|
+
return n.content.map(extractText).join('');
|
|
99
|
+
return '';
|
|
100
|
+
}
|
|
101
|
+
/** 取建议项的显示文本(string 直接返回,对象取 content)。 */
|
|
102
|
+
export function suggestionContent(suggestion) {
|
|
103
|
+
return typeof suggestion === 'string' ? suggestion : (suggestion?.content ?? '');
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 建议面板键盘导航:从 current 沿 dir(-1=上 / +1=下)环绕移动,返回新 activeIndex。
|
|
107
|
+
* - len<=0 返回 -1(无项)。
|
|
108
|
+
* - current<0(未选中)时:向下从 0 开始、向上从末项开始。
|
|
109
|
+
*/
|
|
110
|
+
export function nextSuggestionIndex(current, len, dir) {
|
|
111
|
+
if (len <= 0)
|
|
112
|
+
return -1;
|
|
113
|
+
if (current < 0)
|
|
114
|
+
return dir === 1 ? 0 : len - 1;
|
|
115
|
+
return (current + dir + len) % len;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 取引用项的显示文本:type='text' 用 content,否则用 name(缺省回退到 id)。
|
|
119
|
+
*/
|
|
120
|
+
export function referenceLabel(ref) {
|
|
121
|
+
if (ref.type === 'text')
|
|
122
|
+
return ref.content ?? '';
|
|
123
|
+
return ref.name ?? ref.id;
|
|
124
|
+
}
|
|
125
|
+
/** 该引用是否应按图片渲染(type='image' 或 url 以常见图片扩展名结尾)。 */
|
|
126
|
+
export function isImageReference(ref) {
|
|
127
|
+
if (ref.type === 'image')
|
|
128
|
+
return true;
|
|
129
|
+
const url = ref.url ?? '';
|
|
130
|
+
return /\.(png|jpe?g|gif|bmp|webp|svg)(\?|#|$)/i.test(url);
|
|
131
|
+
}
|
|
132
|
+
/** 取技能项的显示文本(label 优先,回退 value,再回退空串)。 */
|
|
133
|
+
export function skillLabel(skill) {
|
|
134
|
+
return skill.label ?? skill.value ?? '';
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 生成 skillSlot 节点的 HTML(供 editor.setContent 插入)。对齐 Semi getSkillSlotString:
|
|
138
|
+
* `<skill-slot data-label data-value data-template>`。属性值做 HTML 转义防注入。
|
|
139
|
+
*/
|
|
140
|
+
export function getSkillSlotHTML(skill) {
|
|
141
|
+
const attrs = [];
|
|
142
|
+
if (skill.label)
|
|
143
|
+
attrs.push(`data-label="${escapeAttr(skill.label)}"`);
|
|
144
|
+
if (skill.value)
|
|
145
|
+
attrs.push(`data-value="${escapeAttr(skill.value)}"`);
|
|
146
|
+
if (typeof skill.hasTemplate === 'boolean')
|
|
147
|
+
attrs.push(`data-template="${skill.hasTemplate}"`);
|
|
148
|
+
return `<skill-slot ${attrs.join(' ')}></skill-slot>`;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 生成 selectSlot 节点的 HTML(供 editor.setContent 插入,通常用于 renderTemplate 模版填空)。
|
|
152
|
+
* 对齐 Semi selectSlot:`<select-slot options='["a","b"]' value="a">`。options 为 JSON 字符串。
|
|
153
|
+
* @param options 可选项(string[])
|
|
154
|
+
* @param value 默认选中值(缺省空)
|
|
155
|
+
*/
|
|
156
|
+
export function getSelectSlotHTML(options, value = '') {
|
|
157
|
+
const optionsJson = escapeAttr(JSON.stringify(options));
|
|
158
|
+
const attrs = [`options="${optionsJson}"`];
|
|
159
|
+
if (value)
|
|
160
|
+
attrs.push(`value="${escapeAttr(value)}"`);
|
|
161
|
+
return `<select-slot ${attrs.join(' ')}></select-slot>`;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 生成 inputSlot 节点的 HTML(供 editor.setContent 插入,用于 renderTemplate 模版填空的可编辑空格)。
|
|
165
|
+
* 对齐 Semi inputSlot:`<input-slot placeholder="...">` 内含零宽字符作为空态光标锚点。
|
|
166
|
+
* @param placeholder 空态占位提示
|
|
167
|
+
* @param value 初始内容(缺省仅零宽锚点)
|
|
168
|
+
*/
|
|
169
|
+
export function getInputSlotHTML(placeholder = '', value = '') {
|
|
170
|
+
const ph = placeholder ? ` placeholder="${escapeAttr(placeholder)}"` : '';
|
|
171
|
+
const inner = value ? escapeHTML(value) : AI_CHAT_INPUT_ZERO_WIDTH;
|
|
172
|
+
return `<input-slot${ph}>${inner}</input-slot>`;
|
|
173
|
+
}
|
|
174
|
+
/** HTML 文本内容转义(元素内容上下文)。 */
|
|
175
|
+
function escapeHTML(value) {
|
|
176
|
+
return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
177
|
+
}
|
|
178
|
+
/** HTML 属性值转义(双引号上下文)。 */
|
|
179
|
+
function escapeAttr(value) {
|
|
180
|
+
return value
|
|
181
|
+
.replace(/&/g, '&')
|
|
182
|
+
.replace(/"/g, '"')
|
|
183
|
+
.replace(/</g, '<')
|
|
184
|
+
.replace(/>/g, '>');
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 是否应触发技能面板:编辑区为空、按下的键等于 skillHotKey、且有技能项。
|
|
188
|
+
* 对齐 Semi:`oldValue === '' && e.key === skillHotKey && skills.length`。
|
|
189
|
+
*/
|
|
190
|
+
export function shouldOpenSkillPanel(params) {
|
|
191
|
+
const { key, skillHotKey, isEmpty, skillCount } = params;
|
|
192
|
+
return isEmpty && key === skillHotKey && skillCount > 0;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 配置区状态计算(纯函数,框架无关)。渲染层持有 value($state),
|
|
196
|
+
* 用这些函数算下一个 value —— 对齐 Semi Configure 的 onChange(obj)/onRemove(field)。
|
|
197
|
+
*/
|
|
198
|
+
/** 合并一个字段补丁到 value,返回新对象(不可变)。 */
|
|
199
|
+
export function setConfigureField(value, patch) {
|
|
200
|
+
return { ...value, ...patch };
|
|
201
|
+
}
|
|
202
|
+
/** 从 value 移除一个字段,返回新对象(不可变;对齐 Semi onRemove)。 */
|
|
203
|
+
export function removeConfigureField(value, field) {
|
|
204
|
+
const next = {};
|
|
205
|
+
for (const key of Object.keys(value)) {
|
|
206
|
+
if (key !== field)
|
|
207
|
+
next[key] = value[key];
|
|
208
|
+
}
|
|
209
|
+
return next;
|
|
210
|
+
}
|
|
211
|
+
// ————————————————————————————————————————————————————————————————
|
|
212
|
+
// 阶段 5 · Adapter 桥(AIChatInput → AIChatDialogue / OpenAI API)
|
|
213
|
+
// ————————————————————————————————————————————————————————————————
|
|
214
|
+
/**
|
|
215
|
+
* 附件是否应按图片处理。Attachment.type 是 'file'|'directory'(非 mime),故按
|
|
216
|
+
* name/url 的图片扩展名判定。
|
|
217
|
+
*/
|
|
218
|
+
function isImageAttachment(att) {
|
|
219
|
+
const s = `${att.url ?? ''} ${att.name ?? ''}`;
|
|
220
|
+
return /\.(png|jpe?g|gif|bmp|webp|svg)(\?|#|\s|$)/i.test(s);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* messageToChatInput —— 把 AIChatInput 的 onMessageSend 载荷转成一条 AIDialogueMessage(user 角色),
|
|
224
|
+
* 供直接 push 进 AIChatDialogue 的 chats 展示。对齐 OpenAI Response 输入消息形态:
|
|
225
|
+
* content 为单个 InputMessage 块,其 content 数组含 input_text / input_image / input_file。
|
|
226
|
+
*
|
|
227
|
+
* @param message AIChatInput onMessageSend 载荷
|
|
228
|
+
* @param opts.id 消息 id(AIChatDialogue 需唯一 id;调用方应提供,缺省 '')
|
|
229
|
+
* @param opts.model 可选模型标记
|
|
230
|
+
*/
|
|
231
|
+
export function messageToChatInput(message, opts = {}) {
|
|
232
|
+
const parts = [];
|
|
233
|
+
for (const c of message.inputContents ?? []) {
|
|
234
|
+
const text = typeof c.text === 'string' ? c.text : '';
|
|
235
|
+
if (text.length > 0)
|
|
236
|
+
parts.push({ type: 'input_text', text });
|
|
237
|
+
}
|
|
238
|
+
for (const att of message.attachments ?? []) {
|
|
239
|
+
if (isImageAttachment(att)) {
|
|
240
|
+
parts.push({ type: 'input_image', image_url: att.url, file_id: att.uid });
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
parts.push({ type: 'input_file', filename: att.name, file_url: att.url, file_id: att.uid });
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const inputMessage = { type: 'message', role: 'user', content: parts };
|
|
247
|
+
const msg = { id: opts.id ?? '', role: 'user', content: [inputMessage] };
|
|
248
|
+
if (opts.model !== undefined)
|
|
249
|
+
msg.model = opts.model;
|
|
250
|
+
return msg;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* chatInputToChatCompletion —— 把 onMessageSend 载荷转成 OpenAI ChatCompletion 请求的 user message,
|
|
254
|
+
* content 为多模态 parts(text / image_url / file)。供直接放进 messages 数组喂 API。
|
|
255
|
+
* 纯文本可由调用方按需扁平化;这里统一产出 parts 数组,保真多模态。
|
|
256
|
+
*/
|
|
257
|
+
export function chatInputToChatCompletion(message) {
|
|
258
|
+
const content = [];
|
|
259
|
+
for (const c of message.inputContents ?? []) {
|
|
260
|
+
const text = typeof c.text === 'string' ? c.text : '';
|
|
261
|
+
if (text.length > 0)
|
|
262
|
+
content.push({ type: 'text', text });
|
|
263
|
+
}
|
|
264
|
+
for (const att of message.attachments ?? []) {
|
|
265
|
+
if (isImageAttachment(att)) {
|
|
266
|
+
content.push({ type: 'image_url', image_url: { url: att.url } });
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
content.push({ type: 'file', file: { filename: att.name, file_data: att.url } });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return { role: 'user', content };
|
|
273
|
+
}
|
|
274
|
+
//# sourceMappingURL=ai-chat-input.js.map
|
|
@@ -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QACnF,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-chat-input.test.d.ts","sourceRoot":"","sources":["../src/ai-chat-input.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { isSendHotKey, resolveCanSend, buildMessageContent, transformDocToContents, suggestionContent, nextSuggestionIndex, referenceLabel, isImageReference, skillLabel, getSkillSlotHTML, getSelectSlotHTML, getInputSlotHTML, AI_CHAT_INPUT_ZERO_WIDTH as ZW, shouldOpenSkillPanel, setConfigureField, removeConfigureField, messageToChatInput, chatInputToChatCompletion, } from './ai-chat-input.js';
|
|
3
|
+
describe('ai-chat-input · isSendHotKey', () => {
|
|
4
|
+
it("sendHotKey='enter':裸 Enter 发送、Shift+Enter 换行", () => {
|
|
5
|
+
expect(isSendHotKey('Enter', false, 'enter')).toBe(true);
|
|
6
|
+
expect(isSendHotKey('Enter', true, 'enter')).toBe(false);
|
|
7
|
+
});
|
|
8
|
+
it("sendHotKey='shift+enter':Shift+Enter 发送、裸 Enter 换行", () => {
|
|
9
|
+
expect(isSendHotKey('Enter', true, 'shift+enter')).toBe(true);
|
|
10
|
+
expect(isSendHotKey('Enter', false, 'shift+enter')).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
it('非 Enter 键永不发送', () => {
|
|
13
|
+
expect(isSendHotKey('a', false, 'enter')).toBe(false);
|
|
14
|
+
expect(isSendHotKey('ArrowDown', true, 'shift+enter')).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('ai-chat-input · resolveCanSend', () => {
|
|
18
|
+
it('显式 canSend 优先(受控)', () => {
|
|
19
|
+
expect(resolveCanSend({ canSend: true, isEmpty: true })).toBe(true);
|
|
20
|
+
expect(resolveCanSend({ canSend: false, isEmpty: false, attachments: [{ uid: '1' }] })).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
it('非受控:富文本非空即可发送', () => {
|
|
23
|
+
expect(resolveCanSend({ isEmpty: false })).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
it('非受控:空文本但有附件即可发送', () => {
|
|
26
|
+
expect(resolveCanSend({ isEmpty: true, attachments: [{ uid: '1' }] })).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it('非受控:空文本且无附件不可发送', () => {
|
|
29
|
+
expect(resolveCanSend({ isEmpty: true, attachments: [] })).toBe(false);
|
|
30
|
+
expect(resolveCanSend({ isEmpty: true })).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('ai-chat-input · buildMessageContent', () => {
|
|
34
|
+
it('省略空字段,只带非空内容', () => {
|
|
35
|
+
const msg = buildMessageContent({ inputContents: [{ type: 'text', text: 'hi' }] });
|
|
36
|
+
expect(msg).toEqual({ inputContents: [{ type: 'text', text: 'hi' }] });
|
|
37
|
+
expect(msg.attachments).toBeUndefined();
|
|
38
|
+
expect(msg.references).toBeUndefined();
|
|
39
|
+
expect(msg.setup).toBeUndefined();
|
|
40
|
+
});
|
|
41
|
+
it('全字段均带上', () => {
|
|
42
|
+
const msg = buildMessageContent({
|
|
43
|
+
inputContents: [{ type: 'text', text: 'hi' }],
|
|
44
|
+
attachments: [{ uid: '1', name: 'a.png' }],
|
|
45
|
+
references: [{ type: 'file', id: 'r1' }],
|
|
46
|
+
setup: { model: 'gpt-5' },
|
|
47
|
+
});
|
|
48
|
+
expect(msg.inputContents).toHaveLength(1);
|
|
49
|
+
expect(msg.attachments).toHaveLength(1);
|
|
50
|
+
expect(msg.references).toHaveLength(1);
|
|
51
|
+
expect(msg.setup).toEqual({ model: 'gpt-5' });
|
|
52
|
+
});
|
|
53
|
+
it('空数组与空对象视作无内容而省略', () => {
|
|
54
|
+
expect(buildMessageContent({ inputContents: [], attachments: [], setup: {} })).toEqual({});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('ai-chat-input · transformDocToContents', () => {
|
|
58
|
+
it('段落文本 → text content,空段丢弃', () => {
|
|
59
|
+
const doc = {
|
|
60
|
+
type: 'doc',
|
|
61
|
+
content: [
|
|
62
|
+
{ type: 'paragraph', content: [{ type: 'text', text: '你好' }] },
|
|
63
|
+
{ type: 'paragraph' }, // 空段
|
|
64
|
+
{ type: 'paragraph', content: [{ type: 'text', text: 'world' }] },
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
expect(transformDocToContents(doc)).toEqual([
|
|
68
|
+
{ type: 'text', text: '你好' },
|
|
69
|
+
{ type: 'text', text: 'world' },
|
|
70
|
+
]);
|
|
71
|
+
});
|
|
72
|
+
it('hardBreak → 换行;嵌套 marks 文本连接', () => {
|
|
73
|
+
const doc = {
|
|
74
|
+
type: 'doc',
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: 'paragraph',
|
|
78
|
+
content: [{ type: 'text', text: 'a' }, { type: 'hardBreak' }, { type: 'text', text: 'b' }],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
expect(transformDocToContents(doc)).toEqual([{ type: 'text', text: 'a\nb' }]);
|
|
83
|
+
});
|
|
84
|
+
it('transformer 覆盖特定节点转换', () => {
|
|
85
|
+
const doc = {
|
|
86
|
+
type: 'doc',
|
|
87
|
+
content: [{ type: 'inputSlot', attrs: { value: 'x' } }],
|
|
88
|
+
};
|
|
89
|
+
const transformer = new Map([
|
|
90
|
+
['inputSlot', (n) => ({ type: 'slot', raw: n })],
|
|
91
|
+
]);
|
|
92
|
+
expect(transformDocToContents(doc, transformer)).toEqual([
|
|
93
|
+
{ type: 'slot', raw: { type: 'inputSlot', attrs: { value: 'x' } } },
|
|
94
|
+
]);
|
|
95
|
+
});
|
|
96
|
+
it('非法/空 JSON → 空数组', () => {
|
|
97
|
+
expect(transformDocToContents(undefined)).toEqual([]);
|
|
98
|
+
expect(transformDocToContents({})).toEqual([]);
|
|
99
|
+
expect(transformDocToContents({ content: null })).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
describe('ai-chat-input · suggestionContent', () => {
|
|
103
|
+
it('string 直接返回', () => {
|
|
104
|
+
expect(suggestionContent('帮我写代码')).toBe('帮我写代码');
|
|
105
|
+
});
|
|
106
|
+
it('对象取 content', () => {
|
|
107
|
+
expect(suggestionContent({ content: '翻译', lang: 'en' })).toBe('翻译');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
describe('ai-chat-input · nextSuggestionIndex', () => {
|
|
111
|
+
it('len<=0 返回 -1', () => {
|
|
112
|
+
expect(nextSuggestionIndex(0, 0, 1)).toBe(-1);
|
|
113
|
+
expect(nextSuggestionIndex(2, -1, -1)).toBe(-1);
|
|
114
|
+
});
|
|
115
|
+
it('未选中(current<0):向下从 0、向上从末项', () => {
|
|
116
|
+
expect(nextSuggestionIndex(-1, 3, 1)).toBe(0);
|
|
117
|
+
expect(nextSuggestionIndex(-1, 3, -1)).toBe(2);
|
|
118
|
+
});
|
|
119
|
+
it('向下环绕', () => {
|
|
120
|
+
expect(nextSuggestionIndex(0, 3, 1)).toBe(1);
|
|
121
|
+
expect(nextSuggestionIndex(2, 3, 1)).toBe(0);
|
|
122
|
+
});
|
|
123
|
+
it('向上环绕', () => {
|
|
124
|
+
expect(nextSuggestionIndex(1, 3, -1)).toBe(0);
|
|
125
|
+
expect(nextSuggestionIndex(0, 3, -1)).toBe(2);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
describe('ai-chat-input · referenceLabel', () => {
|
|
129
|
+
it("type='text' 用 content", () => {
|
|
130
|
+
expect(referenceLabel({ type: 'text', id: '1', content: '引用文本' })).toBe('引用文本');
|
|
131
|
+
});
|
|
132
|
+
it('非文本用 name,缺省回退 id', () => {
|
|
133
|
+
expect(referenceLabel({ type: 'file', id: '1', name: 'a.pdf' })).toBe('a.pdf');
|
|
134
|
+
expect(referenceLabel({ type: 'file', id: 'fallback-id' })).toBe('fallback-id');
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
describe('ai-chat-input · isImageReference', () => {
|
|
138
|
+
it("type='image' 判图", () => {
|
|
139
|
+
expect(isImageReference({ type: 'image', id: '1' })).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
it('url 图片扩展名判图(含 query/hash)', () => {
|
|
142
|
+
expect(isImageReference({ type: 'file', id: '1', url: 'a.png' })).toBe(true);
|
|
143
|
+
expect(isImageReference({ type: 'file', id: '1', url: 'https://x/y.JPG?v=2' })).toBe(true);
|
|
144
|
+
expect(isImageReference({ type: 'file', id: '1', url: 'doc.pdf' })).toBe(false);
|
|
145
|
+
expect(isImageReference({ type: 'file', id: '1' })).toBe(false);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
describe('ai-chat-input · skillLabel', () => {
|
|
149
|
+
it('label 优先,回退 value,再回退空串', () => {
|
|
150
|
+
expect(skillLabel({ label: '总结', value: 'summarize' })).toBe('总结');
|
|
151
|
+
expect(skillLabel({ value: 'summarize' })).toBe('summarize');
|
|
152
|
+
expect(skillLabel({})).toBe('');
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe('ai-chat-input · getSkillSlotHTML', () => {
|
|
156
|
+
it('生成 skill-slot 节点 HTML,带 data 属性', () => {
|
|
157
|
+
const html = getSkillSlotHTML({ label: '总结', value: 'sum', hasTemplate: true });
|
|
158
|
+
expect(html).toBe('<skill-slot data-label="总结" data-value="sum" data-template="true"></skill-slot>');
|
|
159
|
+
});
|
|
160
|
+
it('省略未提供的属性', () => {
|
|
161
|
+
expect(getSkillSlotHTML({ label: '仅标签' })).toBe('<skill-slot data-label="仅标签"></skill-slot>');
|
|
162
|
+
});
|
|
163
|
+
it('转义属性值防注入', () => {
|
|
164
|
+
const html = getSkillSlotHTML({ label: '"><img>&' });
|
|
165
|
+
expect(html).toContain('data-label=""><img>&"');
|
|
166
|
+
expect(html).not.toContain('<img>');
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
describe('ai-chat-input · shouldOpenSkillPanel', () => {
|
|
170
|
+
it('空编辑区 + 命中 skillHotKey + 有技能 → true', () => {
|
|
171
|
+
expect(shouldOpenSkillPanel({ key: '/', skillHotKey: '/', isEmpty: true, skillCount: 2 })).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
it('非空编辑区不触发', () => {
|
|
174
|
+
expect(shouldOpenSkillPanel({ key: '/', skillHotKey: '/', isEmpty: false, skillCount: 2 })).toBe(false);
|
|
175
|
+
});
|
|
176
|
+
it('键不匹配不触发', () => {
|
|
177
|
+
expect(shouldOpenSkillPanel({ key: 'a', skillHotKey: '/', isEmpty: true, skillCount: 2 })).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
it('无技能不触发', () => {
|
|
180
|
+
expect(shouldOpenSkillPanel({ key: '/', skillHotKey: '/', isEmpty: true, skillCount: 0 })).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
describe('ai-chat-input · setConfigureField', () => {
|
|
184
|
+
it('合并字段补丁,不可变', () => {
|
|
185
|
+
const v = { model: 'gpt-5' };
|
|
186
|
+
const next = setConfigureField(v, { web: true });
|
|
187
|
+
expect(next).toEqual({ model: 'gpt-5', web: true });
|
|
188
|
+
expect(v).toEqual({ model: 'gpt-5' }); // 原对象不变
|
|
189
|
+
});
|
|
190
|
+
it('同字段覆盖', () => {
|
|
191
|
+
expect(setConfigureField({ model: 'a' }, { model: 'b' })).toEqual({ model: 'b' });
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
describe('ai-chat-input · removeConfigureField', () => {
|
|
195
|
+
it('移除字段,不可变', () => {
|
|
196
|
+
const v = { model: 'gpt-5', web: true };
|
|
197
|
+
const next = removeConfigureField(v, 'web');
|
|
198
|
+
expect(next).toEqual({ model: 'gpt-5' });
|
|
199
|
+
expect(v).toEqual({ model: 'gpt-5', web: true });
|
|
200
|
+
});
|
|
201
|
+
it('移除不存在的字段无副作用', () => {
|
|
202
|
+
expect(removeConfigureField({ a: 1 }, 'b')).toEqual({ a: 1 });
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('ai-chat-input · messageToChatInput', () => {
|
|
206
|
+
it('inputContents → input_text,附件按类型 → input_image/input_file', () => {
|
|
207
|
+
const msg = messageToChatInput({
|
|
208
|
+
inputContents: [{ type: 'text', text: '你好' }],
|
|
209
|
+
attachments: [
|
|
210
|
+
{ uid: '1', name: 'a.png', url: 'https://x/a.png' },
|
|
211
|
+
{ uid: '2', name: 'doc.pdf', url: 'https://x/doc.pdf' },
|
|
212
|
+
],
|
|
213
|
+
}, { id: 'm1', model: 'gpt-5' });
|
|
214
|
+
expect(msg.role).toBe('user');
|
|
215
|
+
expect(msg.id).toBe('m1');
|
|
216
|
+
expect(msg.model).toBe('gpt-5');
|
|
217
|
+
const inner = msg.content[0].content;
|
|
218
|
+
expect(inner).toEqual([
|
|
219
|
+
{ type: 'input_text', text: '你好' },
|
|
220
|
+
{ type: 'input_image', image_url: 'https://x/a.png', file_id: '1' },
|
|
221
|
+
{ type: 'input_file', filename: 'doc.pdf', file_url: 'https://x/doc.pdf', file_id: '2' },
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
it('缺 id 默认空串;空文本段丢弃', () => {
|
|
225
|
+
const msg = messageToChatInput({ inputContents: [{ type: 'text', text: '' }] });
|
|
226
|
+
expect(msg.id).toBe('');
|
|
227
|
+
const inner = msg.content[0].content;
|
|
228
|
+
expect(inner).toEqual([]);
|
|
229
|
+
});
|
|
230
|
+
it('按 url 图片扩展名判图(attachment.type 是 file/directory 非 mime)', () => {
|
|
231
|
+
const msg = messageToChatInput({ attachments: [{ uid: '1', url: 'https://x/pic.webp' }] });
|
|
232
|
+
const inner = msg.content[0].content;
|
|
233
|
+
expect(inner[0].type).toBe('input_image');
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
describe('ai-chat-input · chatInputToChatCompletion', () => {
|
|
237
|
+
it('转成 OpenAI user message 多模态 parts', () => {
|
|
238
|
+
const m = chatInputToChatCompletion({
|
|
239
|
+
inputContents: [{ type: 'text', text: 'hi' }],
|
|
240
|
+
attachments: [{ uid: '1', name: 'a.jpg', url: 'https://x/a.jpg' }],
|
|
241
|
+
});
|
|
242
|
+
expect(m.role).toBe('user');
|
|
243
|
+
expect(m.content).toEqual([
|
|
244
|
+
{ type: 'text', text: 'hi' },
|
|
245
|
+
{ type: 'image_url', image_url: { url: 'https://x/a.jpg' } },
|
|
246
|
+
]);
|
|
247
|
+
});
|
|
248
|
+
it('非图附件 → file part', () => {
|
|
249
|
+
const m = chatInputToChatCompletion({
|
|
250
|
+
attachments: [{ uid: '1', name: 'r.pdf', url: 'https://x/r.pdf' }],
|
|
251
|
+
});
|
|
252
|
+
expect(m.content).toEqual([
|
|
253
|
+
{ type: 'file', file: { filename: 'r.pdf', file_data: 'https://x/r.pdf' } },
|
|
254
|
+
]);
|
|
255
|
+
});
|
|
256
|
+
it('空载荷 → 空 content', () => {
|
|
257
|
+
expect(chatInputToChatCompletion({}).content).toEqual([]);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
describe('ai-chat-input · getSelectSlotHTML', () => {
|
|
261
|
+
it('生成 select-slot 节点 HTML,options 为转义 JSON', () => {
|
|
262
|
+
const html = getSelectSlotHTML(['北京', '上海'], '北京');
|
|
263
|
+
expect(html).toContain('<select-slot ');
|
|
264
|
+
expect(html).toContain('value="北京"');
|
|
265
|
+
// options 是 JSON 且引号被转义
|
|
266
|
+
expect(html).toContain('options="["北京","上海"]"');
|
|
267
|
+
});
|
|
268
|
+
it('无默认值时省略 value', () => {
|
|
269
|
+
const html = getSelectSlotHTML(['a']);
|
|
270
|
+
expect(html).not.toContain('value=');
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
describe('ai-chat-input · transformDocToContents · 内联 slot 归一', () => {
|
|
274
|
+
it('selectSlot 取 attrs.value,skillSlot 取 label', () => {
|
|
275
|
+
const doc = {
|
|
276
|
+
type: 'doc',
|
|
277
|
+
content: [
|
|
278
|
+
{
|
|
279
|
+
type: 'paragraph',
|
|
280
|
+
content: [
|
|
281
|
+
{ type: 'text', text: '去 ' },
|
|
282
|
+
{ type: 'selectSlot', attrs: { value: '上海' } },
|
|
283
|
+
{ type: 'text', text: ' 出差,用 ' },
|
|
284
|
+
{ type: 'skillSlot', attrs: { label: '总结', value: 'sum' } },
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
};
|
|
289
|
+
expect(transformDocToContents(doc)).toEqual([{ type: 'text', text: '去 上海 出差,用 总结' }]);
|
|
290
|
+
});
|
|
291
|
+
it('skillSlot 无 label 回退 value', () => {
|
|
292
|
+
const doc = {
|
|
293
|
+
type: 'doc',
|
|
294
|
+
content: [{ type: 'paragraph', content: [{ type: 'skillSlot', attrs: { value: 'sk' } }] }],
|
|
295
|
+
};
|
|
296
|
+
expect(transformDocToContents(doc)).toEqual([{ type: 'text', text: 'sk' }]);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
describe('ai-chat-input · getInputSlotHTML', () => {
|
|
300
|
+
it('生成 input-slot 节点,带 placeholder + 零宽锚点', () => {
|
|
301
|
+
const html = getInputSlotHTML('填城市');
|
|
302
|
+
expect(html).toBe(`<input-slot placeholder="填城市">${ZW}</input-slot>`);
|
|
303
|
+
});
|
|
304
|
+
it('有 value 时用转义内容', () => {
|
|
305
|
+
expect(getInputSlotHTML('', '<b>x</b>')).toBe('<input-slot><b>x</b></input-slot>');
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
describe('ai-chat-input · transformDocToContents · inputSlot 归一', () => {
|
|
309
|
+
it('inputSlot 有内容取内容,剔零宽字符', () => {
|
|
310
|
+
const doc = {
|
|
311
|
+
type: 'doc',
|
|
312
|
+
content: [
|
|
313
|
+
{
|
|
314
|
+
type: 'paragraph',
|
|
315
|
+
content: [
|
|
316
|
+
{ type: 'text', text: '去 ' },
|
|
317
|
+
{ type: 'inputSlot', attrs: { placeholder: '城市' }, content: [{ type: 'text', text: '北京' }] },
|
|
318
|
+
],
|
|
319
|
+
},
|
|
320
|
+
],
|
|
321
|
+
};
|
|
322
|
+
expect(transformDocToContents(doc)).toEqual([{ type: 'text', text: '去 北京' }]);
|
|
323
|
+
});
|
|
324
|
+
it('inputSlot 空(仅零宽)回退 placeholder', () => {
|
|
325
|
+
const doc = {
|
|
326
|
+
type: 'doc',
|
|
327
|
+
content: [
|
|
328
|
+
{
|
|
329
|
+
type: 'paragraph',
|
|
330
|
+
content: [
|
|
331
|
+
{ type: 'inputSlot', attrs: { placeholder: '请输入城市' }, content: [{ type: 'text', text: ZW }] },
|
|
332
|
+
],
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
};
|
|
336
|
+
expect(transformDocToContents(doc)).toEqual([{ type: 'text', text: '请输入城市' }]);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
//# sourceMappingURL=ai-chat-input.test.js.map
|