@aleph-alpha/chat-kit 1.0.0 → 1.2.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-744ZHsQU.js → CkInput.vue_vue_type_script_setup_true_lang-CRymGkQs.js} +24 -69
- package/dist/components/base/CkHistoryItem/CkHistoryItem.vue.d.ts +3 -4
- package/dist/components/base/CkHistoryItem/CkHistoryItem.vue.d.ts.map +1 -1
- package/dist/components/base/CkHistoryItem/types.d.ts +3 -2
- package/dist/components/base/CkHistoryItem/types.d.ts.map +1 -1
- package/dist/components/base/CkPromptStopButton/CkPromptStopButton.vue.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/composables/index.d.ts +2 -0
- package/dist/composables/index.d.ts.map +1 -1
- package/dist/composables/index.js +3 -2
- package/dist/composables/useConversationSessions.d.ts +29 -0
- package/dist/composables/useConversationSessions.d.ts.map +1 -0
- package/dist/handlers/index.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -6
- package/dist/purify.es-md74IFlY.js +1081 -0
- package/dist/{useChatKitLabels-Dvi2FmjE.js → useChatKitLabels-BmWmMyqX.js} +75 -1152
- package/dist/{useConversations-Ca242D2P.js → useConversationSessions-ulFhtpQr.js} +50 -2
- package/dist/{useMessageHandler-uLHNac39.js → useMessageHandler-BmBdu2EW.js} +4 -1
- package/package.json +5 -5
- package/src/components/base/CkAgentMessage/CkAgentMessage.spec.ts +91 -0
- package/src/components/base/CkAgentMessage/CkAgentMessage.stories.ts +215 -0
- package/src/components/base/CkAgentMessage/CkAgentMessage.vue +25 -0
- package/src/components/base/CkAgentMessage/index.ts +2 -0
- package/src/components/base/CkAgentMessage/types.ts +11 -0
- package/src/components/base/CkConversationLayout/CkConversationLayout.spec.ts +129 -0
- package/src/components/base/CkConversationLayout/CkConversationLayout.stories.ts +251 -0
- package/src/components/base/CkConversationLayout/CkConversationLayout.vue +206 -0
- package/src/components/base/CkConversationLayout/index.ts +2 -0
- package/src/components/base/CkConversationLayout/types.ts +18 -0
- package/src/components/base/CkCopyMessageActionButton/CkCopyMessageActionButton.spec.ts +89 -0
- package/src/components/base/CkCopyMessageActionButton/CkCopyMessageActionButton.stories.ts +70 -0
- package/src/components/base/CkCopyMessageActionButton/CkCopyMessageActionButton.vue +110 -0
- package/src/components/base/CkCopyMessageActionButton/index.ts +2 -0
- package/src/components/base/CkCopyMessageActionButton/types.ts +43 -0
- package/src/components/base/CkHistoryItem/CkHistoryItem.spec.ts +42 -0
- package/src/components/base/CkHistoryItem/CkHistoryItem.stories.ts +230 -0
- package/src/components/base/CkHistoryItem/CkHistoryItem.vue +285 -0
- package/src/components/base/CkHistoryItem/activeIndicator.ts +15 -0
- package/src/components/base/CkHistoryItem/index.ts +2 -0
- package/src/components/base/CkHistoryItem/types.ts +111 -0
- package/src/components/base/CkHistoryWrapper/CkHistoryWrapper.spec.ts +26 -0
- package/src/components/base/CkHistoryWrapper/CkHistoryWrapper.stories.ts +149 -0
- package/src/components/base/CkHistoryWrapper/CkHistoryWrapper.vue +36 -0
- package/src/components/base/CkHistoryWrapper/index.ts +2 -0
- package/src/components/base/CkHistoryWrapper/types.ts +16 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.spec.ts +348 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.stories.ts +382 -0
- package/src/components/base/CkMarkdownRenderer/CkMarkdownRenderer.vue +89 -0
- package/src/components/base/CkMarkdownRenderer/defaultMarkdownClasses.ts +19 -0
- package/src/components/base/CkMarkdownRenderer/index.ts +5 -0
- package/src/components/base/CkMarkdownRenderer/types.ts +53 -0
- package/src/components/base/CkMessageActionButton/CkMessageActionButton.spec.ts +40 -0
- package/src/components/base/CkMessageActionButton/CkMessageActionButton.stories.ts +56 -0
- package/src/components/base/CkMessageActionButton/CkMessageActionButton.vue +23 -0
- package/src/components/base/CkMessageActionButton/index.ts +2 -0
- package/src/components/base/CkMessageActionButton/types.ts +21 -0
- package/src/components/base/CkPromptActionButton/CkPromptActionButton.spec.ts +52 -0
- package/src/components/base/CkPromptActionButton/CkPromptActionButton.stories.ts +126 -0
- package/src/components/base/CkPromptActionButton/CkPromptActionButton.vue +25 -0
- package/src/components/base/CkPromptActionButton/index.ts +2 -0
- package/src/components/base/CkPromptActionButton/types.ts +32 -0
- package/src/components/base/CkPromptInput/CkPromptInput.spec.ts +181 -0
- package/src/components/base/CkPromptInput/CkPromptInput.stories.ts +224 -0
- package/src/components/base/CkPromptInput/CkPromptInput.vue +104 -0
- package/src/components/base/CkPromptInput/index.ts +2 -0
- package/src/components/base/CkPromptInput/types.ts +39 -0
- package/src/components/base/CkPromptInputDisclaimer/CkPromptInputDisclaimer.spec.ts +40 -0
- package/src/components/base/CkPromptInputDisclaimer/CkPromptInputDisclaimer.stories.ts +103 -0
- package/src/components/base/CkPromptInputDisclaimer/CkPromptInputDisclaimer.vue +16 -0
- package/src/components/base/CkPromptInputDisclaimer/index.ts +2 -0
- package/src/components/base/CkPromptInputDisclaimer/types.ts +17 -0
- package/src/components/base/CkPromptStopButton/CkPromptStopButton.spec.ts +64 -0
- package/src/components/base/CkPromptStopButton/CkPromptStopButton.stories.ts +81 -0
- package/src/components/base/CkPromptStopButton/CkPromptStopButton.vue +27 -0
- package/src/components/base/CkPromptStopButton/index.ts +2 -0
- package/src/components/base/CkPromptStopButton/types.ts +28 -0
- package/src/components/base/CkUserMessage/CkUserMessage.spec.ts +20 -0
- package/src/components/base/CkUserMessage/CkUserMessage.stories.ts +112 -0
- package/src/components/base/CkUserMessage/CkUserMessage.vue +19 -0
- package/src/components/base/CkUserMessage/index.ts +2 -0
- package/src/components/base/CkUserMessage/types.ts +14 -0
- package/src/components/base/icons/CkSendIcon.vue +22 -0
- package/src/components/base/icons/CkStopIcon.vue +18 -0
- package/src/components/base/icons/index.ts +2 -0
- package/src/components/base/index.ts +21 -0
- package/src/components/composed/CkConversation/CkConversation.spec.ts +439 -0
- package/src/components/composed/CkConversation/CkConversation.stories.ts +642 -0
- package/src/components/composed/CkConversation/CkConversation.vue +146 -0
- package/src/components/composed/CkConversation/index.ts +2 -0
- package/src/components/composed/CkConversation/types.ts +37 -0
- package/src/components/composed/CkHistory/CkHistory.spec.ts +327 -0
- package/src/components/composed/CkHistory/CkHistory.stories.ts +373 -0
- package/src/components/composed/CkHistory/CkHistory.vue +126 -0
- package/src/components/composed/CkHistory/index.ts +2 -0
- package/src/components/composed/CkHistory/types.ts +72 -0
- package/src/components/composed/CkInput/CkInput.spec.ts +191 -0
- package/src/components/composed/CkInput/CkInput.stories.ts +438 -0
- package/src/components/composed/CkInput/CkInput.vue +104 -0
- package/src/components/composed/CkInput/index.ts +2 -0
- package/src/components/composed/CkInput/types.ts +60 -0
- package/src/components/composed/index.ts +5 -0
- package/src/components/index.ts +34 -0
- package/src/composables/index.ts +15 -0
- package/src/composables/types.ts +36 -0
- package/src/composables/useChat.ts +18 -0
- package/src/composables/useConversationSessions.spec.ts +86 -0
- package/src/composables/useConversationSessions.ts +85 -0
- package/src/composables/useConversations.spec.ts +557 -0
- package/src/composables/useConversations.ts +321 -0
- package/src/handlers/index.ts +9 -0
- package/src/handlers/useChatKitLabels.spec.ts +290 -0
- package/src/handlers/useChatKitLabels.ts +96 -0
- package/src/handlers/useMarkdownParser.spec.ts +112 -0
- package/src/handlers/useMarkdownParser.ts +47 -0
- package/src/handlers/useMessageHandler.spec.ts +535 -0
- package/src/handlers/useMessageHandler.ts +138 -0
- package/src/helpers/conversationTree.spec.ts +423 -0
- package/src/helpers/conversationTree.ts +117 -0
- package/src/helpers/generateId.ts +5 -0
- package/src/helpers/index.ts +4 -0
- package/src/helpers/secondsToDate.ts +7 -0
- package/src/helpers/toError.ts +8 -0
- package/src/index.ts +86 -0
- package/src/services/ChatService.ts +60 -0
- package/src/services/MockChatService.ts +47 -0
- package/src/services/index.ts +12 -0
- package/src/services/types.ts +92 -0
- package/src/test-setup.ts +12 -0
- package/src/test-utils/createTextPlugin.ts +9 -0
- package/src/types.ts +47 -0
- package/dist/generateId-BHf0W4Rq.js +0 -6
package/src/index.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Services
|
|
2
|
+
export {
|
|
3
|
+
ChatService,
|
|
4
|
+
type IChatService,
|
|
5
|
+
type ChatConfig,
|
|
6
|
+
type ChatMessage,
|
|
7
|
+
type ChatResponse,
|
|
8
|
+
type ConversationSummary,
|
|
9
|
+
type HttpClient,
|
|
10
|
+
type RawConversation,
|
|
11
|
+
type RawConversationList,
|
|
12
|
+
type StreamEvent,
|
|
13
|
+
} from './services';
|
|
14
|
+
|
|
15
|
+
// Handlers
|
|
16
|
+
export {
|
|
17
|
+
useMessageHandler,
|
|
18
|
+
useMarkdownParser,
|
|
19
|
+
provideChatKitLabels,
|
|
20
|
+
useChatKitLabels,
|
|
21
|
+
defaultChatKitLabels,
|
|
22
|
+
CHAT_KIT_LABELS,
|
|
23
|
+
} from './handlers';
|
|
24
|
+
export type { ChatKitLabels } from './handlers';
|
|
25
|
+
|
|
26
|
+
// Composables
|
|
27
|
+
export {
|
|
28
|
+
useChat,
|
|
29
|
+
useConversationSessions,
|
|
30
|
+
useConversations,
|
|
31
|
+
} from './composables';
|
|
32
|
+
export type {
|
|
33
|
+
ChatActions,
|
|
34
|
+
ChatState,
|
|
35
|
+
ConversationSession,
|
|
36
|
+
CreateConversationInput,
|
|
37
|
+
MessageHandler,
|
|
38
|
+
MutationOptions,
|
|
39
|
+
UseChatReturn,
|
|
40
|
+
UseConversationSessionsReturn,
|
|
41
|
+
UseConversationsOptions,
|
|
42
|
+
UseConversationsReturn,
|
|
43
|
+
} from './composables';
|
|
44
|
+
|
|
45
|
+
// Components
|
|
46
|
+
export {
|
|
47
|
+
CkAgentMessage,
|
|
48
|
+
CkConversation,
|
|
49
|
+
CkConversationLayout,
|
|
50
|
+
CkCopyMessageActionButton,
|
|
51
|
+
CkHistory,
|
|
52
|
+
CkHistoryItem,
|
|
53
|
+
CkHistoryWrapper,
|
|
54
|
+
CkInput,
|
|
55
|
+
CkMarkdownRenderer,
|
|
56
|
+
CkMessageActionButton,
|
|
57
|
+
CkPromptActionButton,
|
|
58
|
+
CkPromptStopButton,
|
|
59
|
+
CkPromptInput,
|
|
60
|
+
CkPromptInputDisclaimer,
|
|
61
|
+
CkSendIcon,
|
|
62
|
+
CkStopIcon,
|
|
63
|
+
CkUserMessage,
|
|
64
|
+
} from './components';
|
|
65
|
+
export type {
|
|
66
|
+
CkConversationLayoutProps,
|
|
67
|
+
CkConversationProps,
|
|
68
|
+
CkHistoryEmits,
|
|
69
|
+
CkHistoryItemEmits,
|
|
70
|
+
CkHistoryItemProps,
|
|
71
|
+
CkHistoryProps,
|
|
72
|
+
CkHistoryWrapperProps,
|
|
73
|
+
CkMarkdownElementClasses,
|
|
74
|
+
CkMarkdownRendererProps,
|
|
75
|
+
CkUserMessageProps,
|
|
76
|
+
} from './components';
|
|
77
|
+
|
|
78
|
+
// Shared Types
|
|
79
|
+
export type {
|
|
80
|
+
BaseMessage,
|
|
81
|
+
Conversation,
|
|
82
|
+
ConversationTree,
|
|
83
|
+
MessageRole,
|
|
84
|
+
MessageStatus,
|
|
85
|
+
TreeMessage,
|
|
86
|
+
} from './types';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ChatConfig,
|
|
3
|
+
ChatMessage,
|
|
4
|
+
ChatResponse,
|
|
5
|
+
StreamEvent,
|
|
6
|
+
} from './types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Interface for chat service implementations
|
|
10
|
+
*
|
|
11
|
+
* This is a skeleton interface that defines the contract for chat services.
|
|
12
|
+
* Implementations should provide concrete implementations of these methods.
|
|
13
|
+
*/
|
|
14
|
+
export interface IChatService {
|
|
15
|
+
/**
|
|
16
|
+
* Send a message and receive a response
|
|
17
|
+
* @param message - The message to send
|
|
18
|
+
* @returns Promise resolving to the chat response
|
|
19
|
+
*/
|
|
20
|
+
sendMessage(message: ChatMessage): Promise<ChatResponse>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get chat history
|
|
24
|
+
* @param limit - Maximum number of messages to retrieve
|
|
25
|
+
* @returns Promise resolving to an array of messages
|
|
26
|
+
*/
|
|
27
|
+
getHistory(limit?: number): Promise<ChatMessage[]>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Stream a message response
|
|
31
|
+
* @param message - The message to send
|
|
32
|
+
* @param onEvent - Callback for stream events
|
|
33
|
+
* @returns Promise that resolves when streaming is complete
|
|
34
|
+
*/
|
|
35
|
+
streamMessage(
|
|
36
|
+
message: ChatMessage,
|
|
37
|
+
onEvent: (event: StreamEvent) => void,
|
|
38
|
+
): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Abstract base class for chat service implementations
|
|
43
|
+
*
|
|
44
|
+
* This is a skeleton abstract class that can be extended to create
|
|
45
|
+
* concrete chat service implementations.
|
|
46
|
+
*/
|
|
47
|
+
export abstract class ChatService implements IChatService {
|
|
48
|
+
protected config: ChatConfig;
|
|
49
|
+
|
|
50
|
+
constructor(config?: ChatConfig) {
|
|
51
|
+
this.config = config || {};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
abstract sendMessage(message: ChatMessage): Promise<ChatResponse>;
|
|
55
|
+
abstract getHistory(limit?: number): Promise<ChatMessage[]>;
|
|
56
|
+
abstract streamMessage(
|
|
57
|
+
message: ChatMessage,
|
|
58
|
+
onEvent: (event: StreamEvent) => void,
|
|
59
|
+
): Promise<void>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { BaseMessage } from '../types';
|
|
2
|
+
import { ChatService, type IChatService } from './ChatService';
|
|
3
|
+
import type { ChatMessage, ChatResponse, StreamEvent } from './types';
|
|
4
|
+
|
|
5
|
+
export class MockChatService extends ChatService implements IChatService {
|
|
6
|
+
constructor() {
|
|
7
|
+
super({});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async sendMessage(message: ChatMessage): Promise<ChatResponse> {
|
|
11
|
+
const replyText = `Mock reply: ${message.content}`;
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
message: this.createBaseMessage({
|
|
15
|
+
role: 'assistant',
|
|
16
|
+
content: replyText,
|
|
17
|
+
}),
|
|
18
|
+
metadata: { mock: true },
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async getHistory(): Promise<ChatMessage[]> {
|
|
23
|
+
return [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async streamMessage(
|
|
27
|
+
message: ChatMessage,
|
|
28
|
+
onEvent: (event: StreamEvent) => void,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
const response = await this.sendMessage(message);
|
|
31
|
+
onEvent({ type: 'chunk', data: response.message.content });
|
|
32
|
+
onEvent({ type: 'done' });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private createBaseMessage(input: {
|
|
36
|
+
role: BaseMessage['role'];
|
|
37
|
+
content: string;
|
|
38
|
+
}): BaseMessage {
|
|
39
|
+
return {
|
|
40
|
+
id: crypto.randomUUID(),
|
|
41
|
+
role: input.role,
|
|
42
|
+
content: input.content,
|
|
43
|
+
createdAt: new Date(),
|
|
44
|
+
status: 'completed',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { ChatService, type IChatService } from './ChatService';
|
|
2
|
+
export { MockChatService } from './MockChatService';
|
|
3
|
+
export type {
|
|
4
|
+
ChatConfig,
|
|
5
|
+
ChatMessage,
|
|
6
|
+
ChatResponse,
|
|
7
|
+
ConversationSummary,
|
|
8
|
+
HttpClient,
|
|
9
|
+
RawConversation,
|
|
10
|
+
RawConversationList,
|
|
11
|
+
StreamEvent,
|
|
12
|
+
} from './types';
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { BaseMessage, MessageRole } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Minimal HTTP transport contract that chat-kit composables depend on.
|
|
5
|
+
*
|
|
6
|
+
* The app injects an implementation (typically a thin wrapper around
|
|
7
|
+
* `fetch`, `ofetch`, or `axios`). The app owns the base URL, auth headers,
|
|
8
|
+
* retries, and error shape normalisation. chat-kit only calls these methods
|
|
9
|
+
* with the path it was given and assumes the response is JSON.
|
|
10
|
+
*/
|
|
11
|
+
export interface HttpClient {
|
|
12
|
+
get<T>(
|
|
13
|
+
path: string,
|
|
14
|
+
options?: { params?: Record<string, unknown> },
|
|
15
|
+
): Promise<T>;
|
|
16
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
17
|
+
delete(path: string): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* One past conversation, in the shape chat-kit consumers work with.
|
|
22
|
+
*
|
|
23
|
+
* This is the shape consumers work with. The raw server response is mapped
|
|
24
|
+
* into this internally by `useConversations`.
|
|
25
|
+
*/
|
|
26
|
+
export interface ConversationSummary {
|
|
27
|
+
id: string;
|
|
28
|
+
title: string;
|
|
29
|
+
createdAt: Date;
|
|
30
|
+
updatedAt: Date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Raw server response for a single conversation, in the OpenAI-style API
|
|
35
|
+
* shape. Consumers should not need to use this directly; `useConversations`
|
|
36
|
+
* maps it to `ConversationSummary`.
|
|
37
|
+
*/
|
|
38
|
+
export interface RawConversation {
|
|
39
|
+
id: string;
|
|
40
|
+
object?: string;
|
|
41
|
+
metadata?: { title?: string; [key: string]: unknown } | null;
|
|
42
|
+
created_at: number;
|
|
43
|
+
updated_at: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Raw server response for a list of conversations, in the OpenAI-style API
|
|
48
|
+
* shape.
|
|
49
|
+
*/
|
|
50
|
+
export interface RawConversationList {
|
|
51
|
+
object?: string;
|
|
52
|
+
data: RawConversation[];
|
|
53
|
+
has_more: boolean;
|
|
54
|
+
first_id?: string | null;
|
|
55
|
+
last_id?: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Chat message sent to the service
|
|
60
|
+
*/
|
|
61
|
+
export interface ChatMessage {
|
|
62
|
+
id: string;
|
|
63
|
+
role: MessageRole;
|
|
64
|
+
content: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Response from the chat service
|
|
69
|
+
*/
|
|
70
|
+
export interface ChatResponse {
|
|
71
|
+
message: BaseMessage;
|
|
72
|
+
metadata?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Stream event emitted during message streaming
|
|
77
|
+
*/
|
|
78
|
+
export interface StreamEvent {
|
|
79
|
+
type: 'chunk' | 'done' | 'error';
|
|
80
|
+
data?: string;
|
|
81
|
+
error?: Error;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Configuration for the chat service
|
|
86
|
+
*/
|
|
87
|
+
export interface ChatConfig {
|
|
88
|
+
apiEndpoint?: string;
|
|
89
|
+
timeout?: number;
|
|
90
|
+
retries?: number;
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global test setup for JSDOM environment.
|
|
3
|
+
* Polyfills browser APIs not available in JSDOM.
|
|
4
|
+
*/
|
|
5
|
+
import '@testing-library/jest-dom/vitest';
|
|
6
|
+
|
|
7
|
+
// ResizeObserver is not available in JSDOM
|
|
8
|
+
global.ResizeObserver = class ResizeObserver {
|
|
9
|
+
observe(): void {}
|
|
10
|
+
unobserve(): void {}
|
|
11
|
+
disconnect(): void {}
|
|
12
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function createTextPlugin(transform: (text: string) => string) {
|
|
2
|
+
return () => (tree: any) => {
|
|
3
|
+
const visit = (node: any) => {
|
|
4
|
+
if (node.type === 'text') node.value = transform(node.value);
|
|
5
|
+
if (node.children) node.children.forEach(visit);
|
|
6
|
+
};
|
|
7
|
+
visit(tree);
|
|
8
|
+
};
|
|
9
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types used across the chat-kit package layers
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export type MessageRole = 'user' | 'assistant' | 'system';
|
|
6
|
+
|
|
7
|
+
export type MessageStatus = 'started' | 'sending' | 'completed' | 'error';
|
|
8
|
+
|
|
9
|
+
export interface BaseMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
role: MessageRole;
|
|
12
|
+
content: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
status: MessageStatus;
|
|
15
|
+
siblingIds?: string[];
|
|
16
|
+
siblingIndex?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface TreeMessage {
|
|
20
|
+
id: string;
|
|
21
|
+
parentId: string | null;
|
|
22
|
+
childrenIds: string[];
|
|
23
|
+
activeChildIndex: number;
|
|
24
|
+
role: MessageRole;
|
|
25
|
+
content: string;
|
|
26
|
+
status: MessageStatus;
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ConversationTree {
|
|
31
|
+
nodes: Record<string, TreeMessage>;
|
|
32
|
+
rootId: string | null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* High-level conversation record consumed by `CkHistory`.
|
|
37
|
+
*
|
|
38
|
+
* `createdAt` and `updatedAt` are expected to be **Unix seconds**.
|
|
39
|
+
* `title` is optional; `CkHistory` falls back to a localised "Untitled"
|
|
40
|
+
* label when it is missing or blank.
|
|
41
|
+
*/
|
|
42
|
+
export interface Conversation {
|
|
43
|
+
id: string;
|
|
44
|
+
title?: string;
|
|
45
|
+
createdAt: number;
|
|
46
|
+
updatedAt: number;
|
|
47
|
+
}
|