@aleph-alpha/chat-kit 0.2.0 → 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/{ChatInput.vue_vue_type_script_setup_true_lang-DaXHxshB.js → ChatInput.vue_vue_type_script_setup_true_lang-Cca7le4i.js} +23 -23
- package/dist/components/base/MarkdownRenderer/MarkdownRenderer.vue.d.ts.map +1 -1
- package/dist/components/base/MarkdownRenderer/defaultMarkdownClasses.d.ts +3 -0
- package/dist/components/base/MarkdownRenderer/defaultMarkdownClasses.d.ts.map +1 -0
- package/dist/components/composed/ChatConversation/ChatConversation.vue.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- 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 +6 -12
- package/dist/handlers/useMessageHandler.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/types.d.ts +16 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/useMessageHandler-DQrXlsoz.js +184 -0
- package/package.json +2 -2
- package/dist/components/composed/ChatConversation/defaultAgentMarkdownClasses.d.ts +0 -3
- package/dist/components/composed/ChatConversation/defaultAgentMarkdownClasses.d.ts.map +0 -1
- package/dist/useMessageHandler-Db-ywEa6.js +0 -82
|
@@ -213,6 +213,23 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
|
|
|
213
213
|
};
|
|
214
214
|
}
|
|
215
215
|
});
|
|
216
|
+
const defaultMarkdownClasses = {
|
|
217
|
+
p: "my-1 leading-7",
|
|
218
|
+
a: "underline underline-offset-4",
|
|
219
|
+
h1: "mt-4 mb-2 text-2xl font-bold",
|
|
220
|
+
h2: "mt-3 mb-2 text-xl font-semibold",
|
|
221
|
+
h3: "mt-3 mb-1 text-lg font-semibold",
|
|
222
|
+
ul: "my-1 ml-6 list-disc",
|
|
223
|
+
ol: "my-1 ml-6 list-decimal",
|
|
224
|
+
li: "my-0.5",
|
|
225
|
+
pre: "my-2 overflow-x-auto rounded-lg p-4",
|
|
226
|
+
code: "rounded px-1.5 py-0.5",
|
|
227
|
+
blockquote: "my-2 border-l-2 pl-4 italic",
|
|
228
|
+
table: "my-2 w-full border-collapse",
|
|
229
|
+
th: "border p-2 text-left font-semibold",
|
|
230
|
+
td: "border p-2",
|
|
231
|
+
hr: "my-4"
|
|
232
|
+
};
|
|
216
233
|
function domToVNode(node, slots, classes) {
|
|
217
234
|
if (node.nodeType === Node.TEXT_NODE) return node.textContent;
|
|
218
235
|
if (node.nodeType !== Node.ELEMENT_NODE) return null;
|
|
@@ -253,8 +270,12 @@ const _sfc_main$7 = defineComponent({
|
|
|
253
270
|
const doc = new DOMParser().parseFromString(raw, "text/html");
|
|
254
271
|
return Array.from(doc.body.childNodes);
|
|
255
272
|
});
|
|
273
|
+
const mergedClasses = computed(() => ({
|
|
274
|
+
...defaultMarkdownClasses,
|
|
275
|
+
...props.classes
|
|
276
|
+
}));
|
|
256
277
|
return () => {
|
|
257
|
-
const elementClasses =
|
|
278
|
+
const elementClasses = mergedClasses.value;
|
|
258
279
|
const children = parsedNodes.value.map((node) => domToVNode(node, slots, elementClasses)).filter((c) => c != null);
|
|
259
280
|
return h("div", { class: "markdown-renderer" }, children);
|
|
260
281
|
};
|
|
@@ -420,23 +441,6 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
|
420
441
|
};
|
|
421
442
|
}
|
|
422
443
|
});
|
|
423
|
-
const defaultAgentMarkdownClasses = {
|
|
424
|
-
p: "my-1 leading-7",
|
|
425
|
-
a: "underline underline-offset-4",
|
|
426
|
-
h1: "mt-4 mb-2 text-2xl font-bold",
|
|
427
|
-
h2: "mt-3 mb-2 text-xl font-semibold",
|
|
428
|
-
h3: "mt-3 mb-1 text-lg font-semibold",
|
|
429
|
-
ul: "my-1 ml-6 list-disc",
|
|
430
|
-
ol: "my-1 ml-6 list-decimal",
|
|
431
|
-
li: "my-0.5",
|
|
432
|
-
pre: "my-2 overflow-x-auto rounded-lg p-4",
|
|
433
|
-
code: "rounded px-1.5 py-0.5",
|
|
434
|
-
blockquote: "my-2 border-l-2 pl-4 italic",
|
|
435
|
-
table: "my-2 w-full border-collapse",
|
|
436
|
-
th: "border p-2 text-left font-semibold",
|
|
437
|
-
td: "border p-2",
|
|
438
|
-
hr: "my-4"
|
|
439
|
-
};
|
|
440
444
|
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
441
445
|
__name: "ChatConversation",
|
|
442
446
|
props: {
|
|
@@ -448,10 +452,6 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
448
452
|
},
|
|
449
453
|
setup(__props) {
|
|
450
454
|
const props = __props;
|
|
451
|
-
const mergedMarkdownClasses = computed(() => ({
|
|
452
|
-
...defaultAgentMarkdownClasses,
|
|
453
|
-
...props.agentMarkdownClasses
|
|
454
|
-
}));
|
|
455
455
|
const slots = useSlots();
|
|
456
456
|
const labels = useChatKitLabels();
|
|
457
457
|
const hasIcon = computed(
|
|
@@ -485,7 +485,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
|
485
485
|
renderSlot(_ctx.$slots, "agent-message-content", { message }, () => [
|
|
486
486
|
createVNode(_sfc_main$7, {
|
|
487
487
|
content: message.content,
|
|
488
|
-
classes:
|
|
488
|
+
classes: __props.agentMarkdownClasses
|
|
489
489
|
}, createSlots({ _: 2 }, [
|
|
490
490
|
_ctx.$slots["agent-message-code-block"] ? {
|
|
491
491
|
name: "code-block",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/base/MarkdownRenderer/MarkdownRenderer.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/base/MarkdownRenderer/MarkdownRenderer.vue"],"names":[],"mappings":"AAiFE,OAAO,EAAwC,KAAK,QAAQ,EAAc,KAAK,KAAK,EAAE,MAAM,KAAK,CAAC;AAClG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;wBAyCjC,OAAO,YAAY;AAAxC,wBAAyC;AAQ3C,QAAA,MAAM,YAAY;;;;;;cAIe,QAAQ,CAAC,sBAAsB,CAAC;;;;cACjC,QAAQ,CAAC,aAAa,CAAC;;;;;;;;;;;cADtB,QAAQ,CAAC,sBAAsB,CAAC;;;;cACjC,QAAQ,CAAC,aAAa,CAAC;;;;;;4EA0BnD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultMarkdownClasses.d.ts","sourceRoot":"","sources":["../../../../src/components/base/MarkdownRenderer/defaultMarkdownClasses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,sBAAsB,EAAE,sBAgBpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatConversation.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/ChatConversation/ChatConversation.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChatConversation.vue.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/ChatConversation/ChatConversation.vue"],"names":[],"mappings":"AAuHE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAWrD,KAAK,WAAW,GAAG;IACjB,gDAAgD;IAChD,cAAc,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAC1D,yDAAyD;IACzD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,iDAAiD;IACjD,eAAe,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAC3D,oCAAoC;IACpC,oBAAoB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,8EAA8E;IAC9E,4BAA4B,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,uCAAuC;IACvC,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,qCAAqC;IACrC,uBAAuB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IACnE,mDAAmD;IACnD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,WAAW,CAAA;KAAE,KAAK,IAAI,CAAC;IAClE,qEAAqE;IACrE,0BAA0B,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CACjF,CAAC;AAwQJ,QAAA,MAAM,UAAU;;;;6EAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AAWzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -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,8 +1,9 @@
|
|
|
1
|
-
import type { BaseMessage, MessageRole, MessageStatus } from '../types';
|
|
2
|
-
import { Ref } from 'vue';
|
|
1
|
+
import type { BaseMessage, ConversationTree, MessageRole, MessageStatus } 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>>;
|
|
6
|
+
currentLeafId: import("vue").ComputedRef<string | null>;
|
|
6
7
|
updateMessage: (message: {
|
|
7
8
|
id: string;
|
|
8
9
|
content: string;
|
|
@@ -10,19 +11,12 @@ export declare const useMessageHandler: () => {
|
|
|
10
11
|
status: MessageStatus;
|
|
11
12
|
}) => void;
|
|
12
13
|
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;
|
|
14
|
+
getMessageById: (id: string) => BaseMessage | undefined;
|
|
20
15
|
clearCurrentUserMessage: () => void;
|
|
21
16
|
commitUserMessage: () => BaseMessage;
|
|
22
|
-
setMessages: (list: BaseMessage[]) => void;
|
|
23
|
-
removeMessage: (id: string) => void;
|
|
24
|
-
getLastUserMessage: () => BaseMessage | undefined;
|
|
25
17
|
updateMessageId: (oldId: string, newId: string) => void;
|
|
26
18
|
clearMessages: () => void;
|
|
19
|
+
setTree: (incoming: ConversationTree) => void;
|
|
20
|
+
navigate: (targetId: string) => void;
|
|
27
21
|
};
|
|
28
22
|
//# 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,EAEd,MAAM,UAAU,CAAC;AAClB,OAAO,EAAqC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAUlE,eAAO,MAAM,iBAAiB;cA0GJ,GAAG,CAAC,WAAW,EAAE,CAAC;;;6BA3DV;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;6BAqET,MAAM,SAAS,MAAM;;wBAQ1B,gBAAgB;yBAKf,MAAM;CAkBnC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ export type { ChatKitLabels, ChatActions, ChatState, UseChatReturn } from './com
|
|
|
5
5
|
export { useMessageHandler } from './handlers';
|
|
6
6
|
export { AgentMessage, ChatConversation, ChatConversationLayout, ChatInput, MarkdownRenderer, PromptActionButton, PromptInput, PromptInputDisclaimer, UserMessage, } 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,GACZ,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,2BAA2B,EAC3B,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,YAAY,
|
|
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,GACZ,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-DQrXlsoz.js";
|
|
5
|
+
import { A, _, a as a2, b, c, d as d2, e, f, g } from "./ChatInput.vue_vue_type_script_setup_true_lang-Cca7le4i.js";
|
|
6
6
|
export {
|
|
7
7
|
A as AgentMessage,
|
|
8
8
|
C2 as CHAT_KIT_LABELS,
|
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,184 @@
|
|
|
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 updateMessageId(oldId, newId) {
|
|
155
|
+
updateNodeId(tree, oldId, newId);
|
|
156
|
+
}
|
|
157
|
+
function clearMessages() {
|
|
158
|
+
Object.assign(tree, createEmptyTree());
|
|
159
|
+
}
|
|
160
|
+
function setTree(incoming) {
|
|
161
|
+
tree.nodes = incoming.nodes;
|
|
162
|
+
tree.rootId = incoming.rootId;
|
|
163
|
+
}
|
|
164
|
+
function navigate$1(targetId) {
|
|
165
|
+
navigate(tree, targetId);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
messages,
|
|
169
|
+
currentUserMessage: readonly(currentUserMessage),
|
|
170
|
+
currentLeafId,
|
|
171
|
+
updateMessage,
|
|
172
|
+
setCurrentUserMessage,
|
|
173
|
+
getMessageById,
|
|
174
|
+
clearCurrentUserMessage,
|
|
175
|
+
commitUserMessage,
|
|
176
|
+
updateMessageId,
|
|
177
|
+
clearMessages,
|
|
178
|
+
setTree,
|
|
179
|
+
navigate: navigate$1
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
export {
|
|
183
|
+
useMessageHandler as u
|
|
184
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aleph-alpha/chat-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultAgentMarkdownClasses.d.ts","sourceRoot":"","sources":["../../../../src/components/composed/ChatConversation/defaultAgentMarkdownClasses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAE1E,eAAO,MAAM,2BAA2B,EAAE,sBAgBzC,CAAC"}
|
|
@@ -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
|
-
};
|