@aleph-alpha/chat-kit 0.2.0 → 0.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/{ChatInput.vue_vue_type_script_setup_true_lang-DaXHxshB.js → ChatInput.vue_vue_type_script_setup_true_lang-BCa2ePSm.js} +2 -1
- package/dist/components/composed/ChatConversation/index.d.ts +1 -0
- package/dist/components/composed/ChatConversation/index.d.ts.map +1 -1
- package/dist/components/composed/index.d.ts +1 -1
- package/dist/components/composed/index.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -2
- package/dist/handlers/conversationTree.d.ts +16 -0
- package/dist/handlers/conversationTree.d.ts.map +1 -0
- package/dist/handlers/index.js +1 -1
- package/dist/handlers/useMessageHandler.d.ts +22 -11
- package/dist/handlers/useMessageHandler.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/types.d.ts +16 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/useMessageHandler-Day_sdpQ.js +193 -0
- package/package.json +2 -2
- package/dist/useMessageHandler-Db-ywEa6.js +0 -82
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/ChatConversation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/ChatConversation/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ChatConversation } from './ChatConversation';
|
|
1
|
+
export { ChatConversation, defaultAgentMarkdownClasses } from './ChatConversation';
|
|
2
2
|
export type { ChatConversationProps } from './ChatConversation';
|
|
3
3
|
export { ChatInput } from './ChatInput';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/composed/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/composed/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACnF,YAAY,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AgentMessage, ChatConversationLayout, MarkdownRenderer, PromptActionButton, PromptInput, PromptInputDisclaimer, UserMessage, } from './base';
|
|
2
2
|
export type { ChatConversationLayoutProps, MarkdownElementClasses, MarkdownRendererProps, UserMessageProps, } from './base';
|
|
3
|
-
export { ChatConversation, ChatInput } from './composed';
|
|
3
|
+
export { ChatConversation, ChatInput, defaultAgentMarkdownClasses } from './composed';
|
|
4
4
|
export type { ChatConversationProps } from './composed';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,WAAW,GACZ,MAAM,QAAQ,CAAC;AAChB,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,WAAW,GACZ,MAAM,QAAQ,CAAC;AAChB,YAAY,EACV,2BAA2B,EAC3B,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AACtF,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A, _, a, b, c, d, e, f, g } from "../ChatInput.vue_vue_type_script_setup_true_lang-
|
|
1
|
+
import { A, _, a, b, c, d, e, f, g, h } from "../ChatInput.vue_vue_type_script_setup_true_lang-BCa2ePSm.js";
|
|
2
2
|
export {
|
|
3
3
|
A as AgentMessage,
|
|
4
4
|
_ as ChatConversation,
|
|
@@ -8,5 +8,6 @@ export {
|
|
|
8
8
|
d as PromptActionButton,
|
|
9
9
|
e as PromptInput,
|
|
10
10
|
f as PromptInputDisclaimer,
|
|
11
|
-
g as UserMessage
|
|
11
|
+
g as UserMessage,
|
|
12
|
+
h as defaultAgentMarkdownClasses
|
|
12
13
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BaseMessage, ConversationTree, TreeMessage } from '../types';
|
|
2
|
+
export declare function createEmptyTree(): ConversationTree;
|
|
3
|
+
/**
|
|
4
|
+
* Walks from rootId following activeChildIndex at each node.
|
|
5
|
+
* Enriches each node with sibling metadata for the UI.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getLinearPath(tree: ConversationTree): BaseMessage[];
|
|
8
|
+
export declare function addNode(tree: ConversationTree, node: TreeMessage): void;
|
|
9
|
+
export declare function updateNode(tree: ConversationTree, id: string, updates: Partial<Pick<TreeMessage, 'content' | 'status' | 'role'>>): void;
|
|
10
|
+
export declare function updateNodeId(tree: ConversationTree, oldId: string, newId: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Navigate to a different branch by updating the parent's activeChildIndex
|
|
13
|
+
* to point at the target sibling.
|
|
14
|
+
*/
|
|
15
|
+
export declare function navigate(tree: ConversationTree, targetId: string): void;
|
|
16
|
+
//# sourceMappingURL=conversationTree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversationTree.d.ts","sourceRoot":"","sources":["../../src/handlers/conversationTree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE3E,wBAAgB,eAAe,IAAI,gBAAgB,CAElD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,gBAAgB,GAAG,WAAW,EAAE,CAkCnE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAYvE;AAED,wBAAgB,UAAU,CACxB,IAAI,EAAE,gBAAgB,EACtB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,CAAC,CAAC,GACjE,IAAI,CAON;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAsBvF;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAWvE"}
|
package/dist/handlers/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseMessage, MessageRole, MessageStatus } from '../types';
|
|
2
|
-
import { Ref } from 'vue';
|
|
1
|
+
import type { BaseMessage, ConversationTree, MessageRole, MessageStatus, TreeMessage } from '../types';
|
|
2
|
+
import { type Ref } from 'vue';
|
|
3
3
|
export declare const useMessageHandler: () => {
|
|
4
4
|
messages: Ref<BaseMessage[]>;
|
|
5
5
|
currentUserMessage: Readonly<Ref<string, string>>;
|
|
@@ -10,19 +10,30 @@ export declare const useMessageHandler: () => {
|
|
|
10
10
|
status: MessageStatus;
|
|
11
11
|
}) => void;
|
|
12
12
|
setCurrentUserMessage: (text: string) => void;
|
|
13
|
-
getMessageById: (id: string) =>
|
|
14
|
-
id: string;
|
|
15
|
-
role: MessageRole;
|
|
16
|
-
content: string;
|
|
17
|
-
createdAt: Date;
|
|
18
|
-
status: MessageStatus;
|
|
19
|
-
} | undefined;
|
|
13
|
+
getMessageById: (id: string) => BaseMessage | undefined;
|
|
20
14
|
clearCurrentUserMessage: () => void;
|
|
21
15
|
commitUserMessage: () => BaseMessage;
|
|
22
|
-
setMessages: (list: BaseMessage[]) => void;
|
|
23
|
-
removeMessage: (id: string) => void;
|
|
24
16
|
getLastUserMessage: () => BaseMessage | undefined;
|
|
25
17
|
updateMessageId: (oldId: string, newId: string) => void;
|
|
26
18
|
clearMessages: () => void;
|
|
19
|
+
currentLeafId: import("vue").ComputedRef<string | null>;
|
|
20
|
+
tree: {
|
|
21
|
+
readonly nodes: {
|
|
22
|
+
readonly [x: string]: {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
readonly parentId: string | null;
|
|
25
|
+
readonly childrenIds: readonly string[];
|
|
26
|
+
readonly activeChildIndex: number;
|
|
27
|
+
readonly role: MessageRole;
|
|
28
|
+
readonly content: string;
|
|
29
|
+
readonly status: MessageStatus;
|
|
30
|
+
readonly createdAt: Date;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
readonly rootId: string | null;
|
|
34
|
+
};
|
|
35
|
+
setTree: (incoming: ConversationTree) => void;
|
|
36
|
+
addNode: (node: TreeMessage) => void;
|
|
37
|
+
navigate: (targetId: string) => void;
|
|
27
38
|
};
|
|
28
39
|
//# sourceMappingURL=useMessageHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessageHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/useMessageHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useMessageHandler.d.ts","sourceRoot":"","sources":["../../src/handlers/useMessageHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,EACZ,MAAM,UAAU,CAAC;AAClB,OAAO,EAAqC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAUlE,eAAO,MAAM,iBAAiB;cAkHJ,GAAG,CAAC,WAAW,EAAE,CAAC;;6BAnEV;QAC9B,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,WAAW,CAAC;QAClB,MAAM,EAAE,aAAa,CAAC;KACvB;kCAzCoC,MAAM;yBAiEf,MAAM,KAAG,WAAW,GAAG,SAAS;;6BAzD9B,WAAW;8BAqEV,WAAW,GAAG,SAAS;6BAItB,MAAM,SAAS,MAAM;;;;;;;;;;;;;;;;;;wBAQ1B,gBAAgB;oBAKpB,WAAW;yBAIN,MAAM;CAsBnC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { useChat, useMarkdownParser } from './composables';
|
|
|
3
3
|
export { provideChatKitLabels, useChatKitLabels, defaultChatKitLabels, CHAT_KIT_LABELS, } from './composables';
|
|
4
4
|
export type { ChatKitLabels, ChatActions, ChatState, UseChatReturn } from './composables';
|
|
5
5
|
export { useMessageHandler } from './handlers';
|
|
6
|
-
export { AgentMessage, ChatConversation, ChatConversationLayout, ChatInput, MarkdownRenderer, PromptActionButton, PromptInput, PromptInputDisclaimer, UserMessage, } from './components';
|
|
6
|
+
export { AgentMessage, ChatConversation, ChatConversationLayout, ChatInput, MarkdownRenderer, PromptActionButton, PromptInput, PromptInputDisclaimer, UserMessage, defaultAgentMarkdownClasses, } from './components';
|
|
7
7
|
export type { ChatConversationLayoutProps, ChatConversationProps, MarkdownElementClasses, MarkdownRendererProps, UserMessageProps, } from './components';
|
|
8
|
-
export type { BaseMessage, MessageRole, MessageStatus } from './types';
|
|
8
|
+
export type { BaseMessage, ConversationTree, MessageRole, MessageStatus, TreeMessage, } from './types';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,sBAAsB,EACtB,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,qBAAqB,EACrB,WAAW,EACX,2BAA2B,GAC5B,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { C } from "./ChatService-LogwJNxh.js";
|
|
2
2
|
import { u } from "./useChat-CtN_iBTc.js";
|
|
3
3
|
import { C as C2, d, p, u as u2, a } from "./useChatKitLabels-xZXcnxZZ.js";
|
|
4
|
-
import { u as u3 } from "./useMessageHandler-
|
|
5
|
-
import { A, _, a as a2, b, c, d as d2, e, f, g } from "./ChatInput.vue_vue_type_script_setup_true_lang-
|
|
4
|
+
import { u as u3 } from "./useMessageHandler-Day_sdpQ.js";
|
|
5
|
+
import { A, _, a as a2, b, c, d as d2, e, f, g, h } from "./ChatInput.vue_vue_type_script_setup_true_lang-BCa2ePSm.js";
|
|
6
6
|
export {
|
|
7
7
|
A as AgentMessage,
|
|
8
8
|
C2 as CHAT_KIT_LABELS,
|
|
@@ -15,6 +15,7 @@ export {
|
|
|
15
15
|
e as PromptInput,
|
|
16
16
|
f as PromptInputDisclaimer,
|
|
17
17
|
g as UserMessage,
|
|
18
|
+
h as defaultAgentMarkdownClasses,
|
|
18
19
|
d as defaultChatKitLabels,
|
|
19
20
|
p as provideChatKitLabels,
|
|
20
21
|
u as useChat,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared types used across the chat-kit package layers
|
|
3
3
|
*/
|
|
4
|
-
/**
|
|
5
|
-
* Role of a message in a chat conversation
|
|
6
|
-
*/
|
|
7
4
|
export type MessageRole = 'user' | 'assistant' | 'system';
|
|
8
|
-
/**
|
|
9
|
-
* Status of a message
|
|
10
|
-
*/
|
|
11
5
|
export type MessageStatus = 'started' | 'sending' | 'completed' | 'error';
|
|
12
|
-
/**
|
|
13
|
-
* Base message structure
|
|
14
|
-
*/
|
|
15
6
|
export interface BaseMessage {
|
|
16
7
|
id: string;
|
|
17
8
|
role: MessageRole;
|
|
18
9
|
content: string;
|
|
19
10
|
createdAt: Date;
|
|
20
11
|
status: MessageStatus;
|
|
12
|
+
siblingIds?: string[];
|
|
13
|
+
siblingIndex?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface TreeMessage {
|
|
16
|
+
id: string;
|
|
17
|
+
parentId: string | null;
|
|
18
|
+
childrenIds: string[];
|
|
19
|
+
activeChildIndex: number;
|
|
20
|
+
role: MessageRole;
|
|
21
|
+
content: string;
|
|
22
|
+
status: MessageStatus;
|
|
23
|
+
createdAt: Date;
|
|
24
|
+
}
|
|
25
|
+
export interface ConversationTree {
|
|
26
|
+
nodes: Record<string, TreeMessage>;
|
|
27
|
+
rootId: string | null;
|
|
21
28
|
}
|
|
22
29
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;AAE1E,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACnC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { reactive, ref, computed, readonly } from "vue";
|
|
2
|
+
function generateId() {
|
|
3
|
+
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : String(Date.now());
|
|
4
|
+
}
|
|
5
|
+
function createEmptyTree() {
|
|
6
|
+
return { nodes: {}, rootId: null };
|
|
7
|
+
}
|
|
8
|
+
function getLinearPath(tree) {
|
|
9
|
+
const { nodes, rootId } = tree;
|
|
10
|
+
if (!rootId || !nodes[rootId]) return [];
|
|
11
|
+
const path = [];
|
|
12
|
+
let current = rootId;
|
|
13
|
+
while (current !== null) {
|
|
14
|
+
const node = nodes[current];
|
|
15
|
+
if (!node) break;
|
|
16
|
+
const base = {
|
|
17
|
+
id: node.id,
|
|
18
|
+
role: node.role,
|
|
19
|
+
content: node.content,
|
|
20
|
+
createdAt: node.createdAt,
|
|
21
|
+
status: node.status
|
|
22
|
+
};
|
|
23
|
+
if (node.parentId !== null) {
|
|
24
|
+
const parent = nodes[node.parentId];
|
|
25
|
+
if (parent && parent.childrenIds.length > 1) {
|
|
26
|
+
base.siblingIds = [...parent.childrenIds];
|
|
27
|
+
base.siblingIndex = parent.childrenIds.indexOf(node.id);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
path.push(base);
|
|
31
|
+
if (node.childrenIds.length === 0) break;
|
|
32
|
+
current = node.childrenIds[node.activeChildIndex];
|
|
33
|
+
}
|
|
34
|
+
return path;
|
|
35
|
+
}
|
|
36
|
+
function addNode(tree, node) {
|
|
37
|
+
tree.nodes[node.id] = node;
|
|
38
|
+
if (node.parentId !== null) {
|
|
39
|
+
const parent = tree.nodes[node.parentId];
|
|
40
|
+
if (parent && !parent.childrenIds.includes(node.id)) {
|
|
41
|
+
parent.childrenIds.push(node.id);
|
|
42
|
+
parent.activeChildIndex = parent.childrenIds.length - 1;
|
|
43
|
+
}
|
|
44
|
+
} else if (tree.rootId === null) {
|
|
45
|
+
tree.rootId = node.id;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function updateNode(tree, id, updates) {
|
|
49
|
+
const node = tree.nodes[id];
|
|
50
|
+
if (!node) return;
|
|
51
|
+
if (updates.content !== void 0) node.content = updates.content;
|
|
52
|
+
if (updates.status !== void 0) node.status = updates.status;
|
|
53
|
+
if (updates.role !== void 0) node.role = updates.role;
|
|
54
|
+
}
|
|
55
|
+
function updateNodeId(tree, oldId, newId) {
|
|
56
|
+
const node = tree.nodes[oldId];
|
|
57
|
+
if (!node) return;
|
|
58
|
+
delete tree.nodes[oldId];
|
|
59
|
+
node.id = newId;
|
|
60
|
+
tree.nodes[newId] = node;
|
|
61
|
+
if (node.parentId !== null) {
|
|
62
|
+
const parent = tree.nodes[node.parentId];
|
|
63
|
+
if (parent) {
|
|
64
|
+
const idx = parent.childrenIds.indexOf(oldId);
|
|
65
|
+
if (idx !== -1) parent.childrenIds[idx] = newId;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const childId of node.childrenIds) {
|
|
69
|
+
const child = tree.nodes[childId];
|
|
70
|
+
if (child) child.parentId = newId;
|
|
71
|
+
}
|
|
72
|
+
if (tree.rootId === oldId) tree.rootId = newId;
|
|
73
|
+
}
|
|
74
|
+
function navigate(tree, targetId) {
|
|
75
|
+
const node = tree.nodes[targetId];
|
|
76
|
+
if (!node || node.parentId === null) return;
|
|
77
|
+
const parent = tree.nodes[node.parentId];
|
|
78
|
+
if (!parent) return;
|
|
79
|
+
const idx = parent.childrenIds.indexOf(targetId);
|
|
80
|
+
if (idx === -1) return;
|
|
81
|
+
parent.activeChildIndex = idx;
|
|
82
|
+
}
|
|
83
|
+
const useMessageHandler = () => {
|
|
84
|
+
const tree = reactive(createEmptyTree());
|
|
85
|
+
const currentUserMessage = ref("");
|
|
86
|
+
const messages = computed(() => getLinearPath(tree));
|
|
87
|
+
const currentLeafId = computed(() => {
|
|
88
|
+
const list = messages.value;
|
|
89
|
+
return list.length > 0 ? list[list.length - 1].id : null;
|
|
90
|
+
});
|
|
91
|
+
function setCurrentUserMessage(text) {
|
|
92
|
+
currentUserMessage.value = text;
|
|
93
|
+
}
|
|
94
|
+
function clearCurrentUserMessage() {
|
|
95
|
+
currentUserMessage.value = "";
|
|
96
|
+
}
|
|
97
|
+
function commitUserMessage() {
|
|
98
|
+
const id = generateId();
|
|
99
|
+
const text = currentUserMessage.value.trim();
|
|
100
|
+
if (!text) throw new Error("No message");
|
|
101
|
+
const node = {
|
|
102
|
+
id,
|
|
103
|
+
parentId: currentLeafId.value,
|
|
104
|
+
childrenIds: [],
|
|
105
|
+
activeChildIndex: 0,
|
|
106
|
+
role: "user",
|
|
107
|
+
content: text,
|
|
108
|
+
status: "completed",
|
|
109
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
110
|
+
};
|
|
111
|
+
addNode(tree, node);
|
|
112
|
+
clearCurrentUserMessage();
|
|
113
|
+
return {
|
|
114
|
+
id: node.id,
|
|
115
|
+
role: node.role,
|
|
116
|
+
content: node.content,
|
|
117
|
+
createdAt: node.createdAt,
|
|
118
|
+
status: node.status
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function updateMessage(message) {
|
|
122
|
+
const existing = tree.nodes[message.id];
|
|
123
|
+
if (existing) {
|
|
124
|
+
updateNode(tree, message.id, {
|
|
125
|
+
content: message.content,
|
|
126
|
+
role: message.role,
|
|
127
|
+
status: message.status
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
const node = {
|
|
131
|
+
id: message.id,
|
|
132
|
+
parentId: currentLeafId.value,
|
|
133
|
+
childrenIds: [],
|
|
134
|
+
activeChildIndex: 0,
|
|
135
|
+
role: message.role,
|
|
136
|
+
content: message.content,
|
|
137
|
+
status: message.status,
|
|
138
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
139
|
+
};
|
|
140
|
+
addNode(tree, node);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function getMessageById(id) {
|
|
144
|
+
const node = tree.nodes[id];
|
|
145
|
+
if (!node) return void 0;
|
|
146
|
+
return {
|
|
147
|
+
id: node.id,
|
|
148
|
+
role: node.role,
|
|
149
|
+
content: node.content,
|
|
150
|
+
createdAt: node.createdAt,
|
|
151
|
+
status: node.status
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function getLastUserMessage() {
|
|
155
|
+
return messages.value.findLast((m) => m.role === "user");
|
|
156
|
+
}
|
|
157
|
+
function updateMessageId(oldId, newId) {
|
|
158
|
+
updateNodeId(tree, oldId, newId);
|
|
159
|
+
}
|
|
160
|
+
function clearMessages() {
|
|
161
|
+
Object.assign(tree, createEmptyTree());
|
|
162
|
+
}
|
|
163
|
+
function setTree(incoming) {
|
|
164
|
+
tree.nodes = incoming.nodes;
|
|
165
|
+
tree.rootId = incoming.rootId;
|
|
166
|
+
}
|
|
167
|
+
function addNode$1(node) {
|
|
168
|
+
addNode(tree, node);
|
|
169
|
+
}
|
|
170
|
+
function navigate$1(targetId) {
|
|
171
|
+
navigate(tree, targetId);
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
messages,
|
|
175
|
+
currentUserMessage: readonly(currentUserMessage),
|
|
176
|
+
updateMessage,
|
|
177
|
+
setCurrentUserMessage,
|
|
178
|
+
getMessageById,
|
|
179
|
+
clearCurrentUserMessage,
|
|
180
|
+
commitUserMessage,
|
|
181
|
+
getLastUserMessage,
|
|
182
|
+
updateMessageId,
|
|
183
|
+
clearMessages,
|
|
184
|
+
currentLeafId,
|
|
185
|
+
tree: readonly(tree),
|
|
186
|
+
setTree,
|
|
187
|
+
addNode: addNode$1,
|
|
188
|
+
navigate: navigate$1
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
export {
|
|
192
|
+
useMessageHandler as u
|
|
193
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/chat-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Chat kit package for building chat interfaces with Vue",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"remark-parse": "^11.0.0",
|
|
64
64
|
"remark-rehype": "^11.1.2",
|
|
65
65
|
"unified": "^11.0.5",
|
|
66
|
-
"@aleph-alpha/ui-library": "1.
|
|
66
|
+
"@aleph-alpha/ui-library": "1.20.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@storybook/addon-a11y": "10.2.17",
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { ref, readonly } from "vue";
|
|
2
|
-
function generateId() {
|
|
3
|
-
return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : String(Date.now());
|
|
4
|
-
}
|
|
5
|
-
function createMessage(input) {
|
|
6
|
-
return {
|
|
7
|
-
id: input.id,
|
|
8
|
-
role: input.role,
|
|
9
|
-
content: input.content,
|
|
10
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
11
|
-
status: input.status
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
const useMessageHandler = () => {
|
|
15
|
-
const messages = ref([]);
|
|
16
|
-
const currentUserMessage = ref("");
|
|
17
|
-
function setCurrentUserMessage(text) {
|
|
18
|
-
currentUserMessage.value = text;
|
|
19
|
-
}
|
|
20
|
-
function clearCurrentUserMessage() {
|
|
21
|
-
currentUserMessage.value = "";
|
|
22
|
-
}
|
|
23
|
-
function commitUserMessage() {
|
|
24
|
-
const id = generateId();
|
|
25
|
-
const text = currentUserMessage.value.trim();
|
|
26
|
-
if (!text) throw new Error("No message");
|
|
27
|
-
const msg = createMessage({ id, role: "user", content: text, status: "completed" });
|
|
28
|
-
messages.value.push(msg);
|
|
29
|
-
clearCurrentUserMessage();
|
|
30
|
-
return msg;
|
|
31
|
-
}
|
|
32
|
-
function updateMessage(message) {
|
|
33
|
-
const messageIndexToUpdate = messages.value.findIndex((m) => m.id === message.id);
|
|
34
|
-
const messageToUpdate = messages.value[messageIndexToUpdate];
|
|
35
|
-
if (!messageToUpdate) {
|
|
36
|
-
messages.value.push(createMessage(message));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (messageIndexToUpdate !== messages.value.length - 1) {
|
|
40
|
-
messages.value = messages.value.slice(0, messageIndexToUpdate + 1);
|
|
41
|
-
}
|
|
42
|
-
messageToUpdate.content = message.content;
|
|
43
|
-
messageToUpdate.role = message.role;
|
|
44
|
-
messageToUpdate.status = message.status;
|
|
45
|
-
}
|
|
46
|
-
function getMessageById(id) {
|
|
47
|
-
return messages.value.find((m) => m.id === id);
|
|
48
|
-
}
|
|
49
|
-
function setMessages(list) {
|
|
50
|
-
messages.value = list;
|
|
51
|
-
}
|
|
52
|
-
function removeMessage(id) {
|
|
53
|
-
messages.value = messages.value.filter((m) => m.id !== id);
|
|
54
|
-
}
|
|
55
|
-
function getLastUserMessage() {
|
|
56
|
-
return [...messages.value].reverse().find((m) => m.role === "user");
|
|
57
|
-
}
|
|
58
|
-
function updateMessageId(oldId, newId) {
|
|
59
|
-
const msg = messages.value.find((m) => m.id === oldId);
|
|
60
|
-
if (msg) msg.id = newId;
|
|
61
|
-
}
|
|
62
|
-
function clearMessages() {
|
|
63
|
-
messages.value = [];
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
messages: readonly(messages),
|
|
67
|
-
currentUserMessage: readonly(currentUserMessage),
|
|
68
|
-
updateMessage,
|
|
69
|
-
setCurrentUserMessage,
|
|
70
|
-
getMessageById,
|
|
71
|
-
clearCurrentUserMessage,
|
|
72
|
-
commitUserMessage,
|
|
73
|
-
setMessages,
|
|
74
|
-
removeMessage,
|
|
75
|
-
getLastUserMessage,
|
|
76
|
-
updateMessageId,
|
|
77
|
-
clearMessages
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
export {
|
|
81
|
-
useMessageHandler as u
|
|
82
|
-
};
|