@aleph-alpha/chat-kit 0.1.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.
Files changed (55) hide show
  1. package/dist/{ChatInput.vue_vue_type_script_setup_true_lang-DVCUwptr.js → ChatInput.vue_vue_type_script_setup_true_lang-BCa2ePSm.js} +160 -34
  2. package/dist/components/base/ChatConversationLayout/ChatConversationLayout.vue.d.ts +1 -0
  3. package/dist/components/base/ChatConversationLayout/ChatConversationLayout.vue.d.ts.map +1 -1
  4. package/dist/components/base/MarkdownRenderer/MarkdownRenderer.stories.d.ts +13 -0
  5. package/dist/components/base/MarkdownRenderer/MarkdownRenderer.stories.d.ts.map +1 -0
  6. package/dist/components/base/MarkdownRenderer/MarkdownRenderer.vue.d.ts +38 -0
  7. package/dist/components/base/MarkdownRenderer/MarkdownRenderer.vue.d.ts.map +1 -0
  8. package/dist/components/base/MarkdownRenderer/index.d.ts +3 -0
  9. package/dist/components/base/MarkdownRenderer/index.d.ts.map +1 -0
  10. package/dist/components/base/MarkdownRenderer/types.d.ts +36 -0
  11. package/dist/components/base/MarkdownRenderer/types.d.ts.map +1 -0
  12. package/dist/components/base/PromptActionButton/PromptActionButton.vue.d.ts +1 -1
  13. package/dist/components/base/PromptActionButton/PromptActionButton.vue.d.ts.map +1 -1
  14. package/dist/components/base/UserMessage/UserMessage.vue.d.ts.map +1 -1
  15. package/dist/components/base/index.d.ts +2 -0
  16. package/dist/components/base/index.d.ts.map +1 -1
  17. package/dist/components/composed/ChatConversation/ChatConversation.stories.d.ts +2 -0
  18. package/dist/components/composed/ChatConversation/ChatConversation.stories.d.ts.map +1 -1
  19. package/dist/components/composed/ChatConversation/ChatConversation.vue.d.ts +10 -0
  20. package/dist/components/composed/ChatConversation/ChatConversation.vue.d.ts.map +1 -1
  21. package/dist/components/composed/ChatConversation/defaultAgentMarkdownClasses.d.ts +3 -0
  22. package/dist/components/composed/ChatConversation/defaultAgentMarkdownClasses.d.ts.map +1 -0
  23. package/dist/components/composed/ChatConversation/index.d.ts +1 -0
  24. package/dist/components/composed/ChatConversation/index.d.ts.map +1 -1
  25. package/dist/components/composed/ChatConversation/types.d.ts +5 -0
  26. package/dist/components/composed/ChatConversation/types.d.ts.map +1 -1
  27. package/dist/components/composed/index.d.ts +1 -1
  28. package/dist/components/composed/index.d.ts.map +1 -1
  29. package/dist/components/index.d.ts +3 -3
  30. package/dist/components/index.d.ts.map +1 -1
  31. package/dist/components/index.js +7 -5
  32. package/dist/composables/index.d.ts +1 -0
  33. package/dist/composables/index.d.ts.map +1 -1
  34. package/dist/composables/index.js +3 -2
  35. package/dist/composables/useChatKitLabels.d.ts +20 -8
  36. package/dist/composables/useChatKitLabels.d.ts.map +1 -1
  37. package/dist/composables/useMarkdownParser.d.ts +6 -0
  38. package/dist/composables/useMarkdownParser.d.ts.map +1 -0
  39. package/dist/handlers/conversationTree.d.ts +16 -0
  40. package/dist/handlers/conversationTree.d.ts.map +1 -0
  41. package/dist/handlers/index.js +1 -1
  42. package/dist/handlers/useMessageHandler.d.ts +23 -11
  43. package/dist/handlers/useMessageHandler.d.ts.map +1 -1
  44. package/dist/index.d.ts +4 -4
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +11 -8
  47. package/dist/test-utils/createTextPlugin.d.ts +2 -0
  48. package/dist/test-utils/createTextPlugin.d.ts.map +1 -0
  49. package/dist/types.d.ts +16 -9
  50. package/dist/types.d.ts.map +1 -1
  51. package/dist/useChatKitLabels-xZXcnxZZ.js +13740 -0
  52. package/dist/useMessageHandler-Day_sdpQ.js +193 -0
  53. package/package.json +19 -9
  54. package/dist/useChatKitLabels-Bi0szl2l.js +0 -18
  55. package/dist/useMessageHandler-BdcOcw0w.js +0 -73
@@ -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.1.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",
@@ -54,10 +54,16 @@
54
54
  "peerDependencies": {
55
55
  "@aleph-alpha/ui-library": "*",
56
56
  "pinia": "^3.0.0",
57
- "vue": "^3.5.25"
57
+ "vue": "^3.5.27"
58
58
  },
59
59
  "dependencies": {
60
- "@aleph-alpha/ui-library": "1.16.0"
60
+ "dompurify": "^3.3.2",
61
+ "rehype-stringify": "^10.0.1",
62
+ "remark-gfm": "^4.0.1",
63
+ "remark-parse": "^11.0.0",
64
+ "remark-rehype": "^11.1.2",
65
+ "unified": "^11.0.5",
66
+ "@aleph-alpha/ui-library": "1.20.0"
61
67
  },
62
68
  "devDependencies": {
63
69
  "@storybook/addon-a11y": "10.2.17",
@@ -65,20 +71,24 @@
65
71
  "@storybook/vue3-vite": "10.2.17",
66
72
  "@testing-library/jest-dom": "6.9.1",
67
73
  "@testing-library/vue": "8.1.0",
74
+ "@types/dompurify": "^3.2.0",
68
75
  "@types/node": "^25.1.0",
69
- "@unocss/reset": "66.6.0",
76
+ "@unocss/preset-wind4": "^66.6.2",
77
+ "@unocss/reset": "^66.6.2",
70
78
  "@vitejs/plugin-vue": "^6.0.3",
71
79
  "@vue/test-utils": "^2.4.6",
72
80
  "jsdom": "^25.0.1",
73
- "storybook": "10.2.17",
81
+ "storybook": "^10.2.17",
74
82
  "pinia": "^3.0.3",
75
83
  "typescript": "^5.9.3",
76
- "unocss": "66.6.0",
84
+ "unocss": "^66.6.2",
85
+ "unocss-preset-animations": "^1.3.0",
86
+ "unocss-preset-shadcn": "^1.0.1",
77
87
  "vite": "7.3.1",
78
- "vitest": "^4.0.18",
79
- "vue": "^3.5.25",
88
+ "vitest": "4.0.15",
89
+ "vue": "^3.5.27",
80
90
  "vue-tsc": "^3.2.4",
81
- "@aleph-alpha/config-css": "0.21.0"
91
+ "@aleph-alpha/config-css": "0.21.2"
82
92
  },
83
93
  "scripts": {
84
94
  "build": "vite build && vue-tsc --project tsconfig.build.json --declaration --emitDeclarationOnly --outDir dist",
@@ -1,18 +0,0 @@
1
- import { provide, inject } from "vue";
2
- const defaultChatKitLabels = {
3
- agentAvatarAlt: "Agent avatar",
4
- inputPlaceholder: "Type a message..."
5
- };
6
- const CHAT_KIT_LABELS = /* @__PURE__ */ Symbol("chat-kit-labels");
7
- function provideChatKitLabels(labels) {
8
- provide(CHAT_KIT_LABELS, { ...defaultChatKitLabels, ...labels });
9
- }
10
- function useChatKitLabels() {
11
- return inject(CHAT_KIT_LABELS, defaultChatKitLabels);
12
- }
13
- export {
14
- CHAT_KIT_LABELS as C,
15
- defaultChatKitLabels as d,
16
- provideChatKitLabels as p,
17
- useChatKitLabels as u
18
- };
@@ -1,73 +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 messageToUpdate = messages.value.find((m) => m.id === message.id);
34
- if (messageToUpdate) {
35
- messageToUpdate.content = message.content;
36
- messageToUpdate.role = message.role;
37
- messageToUpdate.status = message.status;
38
- } else {
39
- messages.value.push(createMessage(message));
40
- }
41
- }
42
- function getMessageById(id) {
43
- return messages.value.find((m) => m.id === id);
44
- }
45
- function setMessages(list) {
46
- messages.value = list;
47
- }
48
- function removeMessage(id) {
49
- messages.value = messages.value.filter((m) => m.id !== id);
50
- }
51
- function getLastUserMessage() {
52
- return [...messages.value].reverse().find((m) => m.role === "user");
53
- }
54
- function clearMessages() {
55
- messages.value = [];
56
- }
57
- return {
58
- messages: readonly(messages),
59
- currentUserMessage: readonly(currentUserMessage),
60
- updateMessage,
61
- setCurrentUserMessage,
62
- getMessageById,
63
- clearCurrentUserMessage,
64
- commitUserMessage,
65
- setMessages,
66
- removeMessage,
67
- getLastUserMessage,
68
- clearMessages
69
- };
70
- };
71
- export {
72
- useMessageHandler as u
73
- };