@kine-design/ai-chat 0.0.1-beta.4 → 0.0.1-beta.6
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/.vlaude/last-session-id +1 -1
- package/components/KChatInput.tsx +5 -3
- package/components/KPhaseIndicator.tsx +15 -9
- package/composables/useChatHistory.ts +3 -1
- package/dist/ai-chat.js +19 -13
- package/dist/components/KChatInput.d.ts +2 -2
- package/package.json +3 -2
- package/vite.config.build.ts +1 -0
package/.vlaude/last-session-id
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4c9b1c27-b707-4b0b-98d7-fde5d511ce47
|
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { defineComponent, ref } from 'vue';
|
|
11
|
+
import { useLocale } from '@kine-design/core';
|
|
11
12
|
import './chat-input.css';
|
|
12
13
|
|
|
13
14
|
export const KChatInput = defineComponent({
|
|
14
15
|
name: 'KChatInput',
|
|
15
16
|
props: {
|
|
16
|
-
placeholder: { type: String, default:
|
|
17
|
+
placeholder: { type: String, default: undefined },
|
|
17
18
|
disabled: { type: Boolean, default: false },
|
|
18
19
|
},
|
|
19
20
|
emits: ['send'],
|
|
20
21
|
setup(props, { emit }) {
|
|
22
|
+
const t = useLocale();
|
|
21
23
|
const text = ref('');
|
|
22
24
|
|
|
23
25
|
function handleSend() {
|
|
@@ -41,7 +43,7 @@ export const KChatInput = defineComponent({
|
|
|
41
43
|
value={text.value}
|
|
42
44
|
onInput={(e: Event) => { text.value = (e.target as HTMLTextAreaElement).value; }}
|
|
43
45
|
onKeydown={handleKeydown}
|
|
44
|
-
placeholder={props.placeholder}
|
|
46
|
+
placeholder={props.placeholder ?? t.value.aiChat.inputPlaceholder}
|
|
45
47
|
disabled={props.disabled}
|
|
46
48
|
rows={1}
|
|
47
49
|
/>
|
|
@@ -50,7 +52,7 @@ export const KChatInput = defineComponent({
|
|
|
50
52
|
onClick={handleSend}
|
|
51
53
|
disabled={props.disabled || !text.value.trim()}
|
|
52
54
|
>
|
|
53
|
-
|
|
55
|
+
{t.value.aiChat.send}
|
|
54
56
|
</button>
|
|
55
57
|
</div>
|
|
56
58
|
);
|
|
@@ -9,24 +9,30 @@
|
|
|
9
9
|
|
|
10
10
|
import { defineComponent, computed, type PropType } from 'vue';
|
|
11
11
|
import { KLoading } from 'kine-ui';
|
|
12
|
+
import { useLocale } from '@kine-design/core';
|
|
12
13
|
import type { ChatPhase } from '../composables/types';
|
|
13
14
|
import './phase-indicator.css';
|
|
14
15
|
|
|
15
|
-
const PHASE_LABELS: Record<ChatPhase, string> = {
|
|
16
|
-
idle: '',
|
|
17
|
-
aggregating: '正在输入…',
|
|
18
|
-
thinking: '思考中…',
|
|
19
|
-
streaming: '回复中…',
|
|
20
|
-
sending: '发送中…',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
16
|
export const KPhaseIndicator = defineComponent({
|
|
24
17
|
name: 'KPhaseIndicator',
|
|
25
18
|
props: {
|
|
26
19
|
phase: { type: String as PropType<ChatPhase>, required: true },
|
|
27
20
|
},
|
|
28
21
|
setup(props) {
|
|
29
|
-
const
|
|
22
|
+
const t = useLocale();
|
|
23
|
+
|
|
24
|
+
// 阶段文案映射:依赖 locale,必须在 setup 内现取以保持响应式
|
|
25
|
+
const label = computed(() => {
|
|
26
|
+
const c = t.value.aiChat;
|
|
27
|
+
const map: Record<ChatPhase, string> = {
|
|
28
|
+
idle: '',
|
|
29
|
+
aggregating: c.phaseTyping,
|
|
30
|
+
thinking: c.phaseThinking,
|
|
31
|
+
streaming: c.phaseReplying,
|
|
32
|
+
sending: c.phaseSending,
|
|
33
|
+
};
|
|
34
|
+
return map[props.phase];
|
|
35
|
+
});
|
|
30
36
|
const visible = computed(() => props.phase !== 'idle');
|
|
31
37
|
|
|
32
38
|
return () => visible.value
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { ref, watch } from 'vue';
|
|
11
|
+
import { getActiveLocaleMessages } from '@kine-design/core';
|
|
11
12
|
import type { Conversation, UseChatHistoryOptions, UseChatHistoryReturn } from './types';
|
|
12
13
|
|
|
13
14
|
function generateId(): string {
|
|
@@ -43,10 +44,11 @@ export function useChatHistory(options: UseChatHistoryOptions = {}): UseChatHist
|
|
|
43
44
|
watch(conversations, persist, { deep: true });
|
|
44
45
|
|
|
45
46
|
function create(title?: string): Conversation {
|
|
47
|
+
const t = getActiveLocaleMessages();
|
|
46
48
|
const now = Date.now();
|
|
47
49
|
const conversation: Conversation = {
|
|
48
50
|
id: generateId(),
|
|
49
|
-
title: title ??
|
|
51
|
+
title: title ?? t.aiChat.defaultTitle(conversations.value.length + 1),
|
|
50
52
|
clusters: [],
|
|
51
53
|
createdAt: now,
|
|
52
54
|
updatedAt: now,
|
package/dist/ai-chat.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { computed,
|
|
1
|
+
import { computed, createVNode, defineComponent, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
|
2
|
+
import { getActiveLocaleMessages, useLocale } from "@kine-design/core";
|
|
2
3
|
import { io } from "socket.io-client";
|
|
3
4
|
import { KLoading } from "kine-ui";
|
|
4
5
|
//#region composables/useChat.ts
|
|
@@ -141,10 +142,11 @@ function useChatHistory(options = {}) {
|
|
|
141
142
|
load();
|
|
142
143
|
watch(conversations, persist, { deep: true });
|
|
143
144
|
function create(title) {
|
|
145
|
+
const t = getActiveLocaleMessages();
|
|
144
146
|
const now = Date.now();
|
|
145
147
|
const conversation = {
|
|
146
148
|
id: generateId(),
|
|
147
|
-
title: title ??
|
|
149
|
+
title: title ?? t.aiChat.defaultTitle(conversations.value.length + 1),
|
|
148
150
|
clusters: [],
|
|
149
151
|
createdAt: now,
|
|
150
152
|
updatedAt: now
|
|
@@ -375,13 +377,6 @@ var KMessageCluster = /* @__PURE__ */ defineComponent({
|
|
|
375
377
|
*
|
|
376
378
|
* 江湖的业务千篇一律,复杂的代码好几百行。
|
|
377
379
|
*/
|
|
378
|
-
var PHASE_LABELS = {
|
|
379
|
-
idle: "",
|
|
380
|
-
aggregating: "正在输入…",
|
|
381
|
-
thinking: "思考中…",
|
|
382
|
-
streaming: "回复中…",
|
|
383
|
-
sending: "发送中…"
|
|
384
|
-
};
|
|
385
380
|
var KPhaseIndicator = /* @__PURE__ */ defineComponent({
|
|
386
381
|
name: "KPhaseIndicator",
|
|
387
382
|
props: { phase: {
|
|
@@ -389,7 +384,17 @@ var KPhaseIndicator = /* @__PURE__ */ defineComponent({
|
|
|
389
384
|
required: true
|
|
390
385
|
} },
|
|
391
386
|
setup(props) {
|
|
392
|
-
const
|
|
387
|
+
const t = useLocale();
|
|
388
|
+
const label = computed(() => {
|
|
389
|
+
const c = t.value.aiChat;
|
|
390
|
+
return {
|
|
391
|
+
idle: "",
|
|
392
|
+
aggregating: c.phaseTyping,
|
|
393
|
+
thinking: c.phaseThinking,
|
|
394
|
+
streaming: c.phaseReplying,
|
|
395
|
+
sending: c.phaseSending
|
|
396
|
+
}[props.phase];
|
|
397
|
+
});
|
|
393
398
|
const visible = computed(() => props.phase !== "idle");
|
|
394
399
|
return () => visible.value ? createVNode("div", { "class": ["k-phase-indicator", `k-phase-indicator--${props.phase}`] }, [createVNode(KLoading, { "size": "small" }, null), createVNode("span", null, [label.value])]) : null;
|
|
395
400
|
}
|
|
@@ -455,7 +460,7 @@ var KChatInput = /* @__PURE__ */ defineComponent({
|
|
|
455
460
|
props: {
|
|
456
461
|
placeholder: {
|
|
457
462
|
type: String,
|
|
458
|
-
default:
|
|
463
|
+
default: void 0
|
|
459
464
|
},
|
|
460
465
|
disabled: {
|
|
461
466
|
type: Boolean,
|
|
@@ -464,6 +469,7 @@ var KChatInput = /* @__PURE__ */ defineComponent({
|
|
|
464
469
|
},
|
|
465
470
|
emits: ["send"],
|
|
466
471
|
setup(props, { emit }) {
|
|
472
|
+
const t = useLocale();
|
|
467
473
|
const text = ref("");
|
|
468
474
|
function handleSend() {
|
|
469
475
|
const trimmed = text.value.trim();
|
|
@@ -484,14 +490,14 @@ var KChatInput = /* @__PURE__ */ defineComponent({
|
|
|
484
490
|
text.value = e.target.value;
|
|
485
491
|
},
|
|
486
492
|
"onKeydown": handleKeydown,
|
|
487
|
-
"placeholder": props.placeholder,
|
|
493
|
+
"placeholder": props.placeholder ?? t.value.aiChat.inputPlaceholder,
|
|
488
494
|
"disabled": props.disabled,
|
|
489
495
|
"rows": 1
|
|
490
496
|
}, null), createVNode("button", {
|
|
491
497
|
"class": "k-chat-input__send",
|
|
492
498
|
"onClick": handleSend,
|
|
493
499
|
"disabled": props.disabled || !text.value.trim()
|
|
494
|
-
}, [
|
|
500
|
+
}, [t.value.aiChat.send])]);
|
|
495
501
|
}
|
|
496
502
|
});
|
|
497
503
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const KChatInput: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
2
2
|
placeholder: {
|
|
3
3
|
type: StringConstructor;
|
|
4
|
-
default:
|
|
4
|
+
default: undefined;
|
|
5
5
|
};
|
|
6
6
|
disabled: {
|
|
7
7
|
type: BooleanConstructor;
|
|
@@ -10,7 +10,7 @@ export declare const KChatInput: import('vue').DefineComponent<import('vue').Ext
|
|
|
10
10
|
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, "send"[], "send", import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
11
11
|
placeholder: {
|
|
12
12
|
type: StringConstructor;
|
|
13
|
-
default:
|
|
13
|
+
default: undefined;
|
|
14
14
|
};
|
|
15
15
|
disabled: {
|
|
16
16
|
type: BooleanConstructor;
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kine-design/ai-chat",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/ai-chat.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"socket.io-client": "^4.8.3",
|
|
9
9
|
"vue": "^3.5.30",
|
|
10
|
-
"kine-ui": "^0.0.1-beta.
|
|
10
|
+
"kine-ui": "^0.0.1-beta.23",
|
|
11
|
+
"@kine-design/core": "0.0.1-beta.12"
|
|
11
12
|
},
|
|
12
13
|
"publishConfig": {
|
|
13
14
|
"access": "public",
|