@n8n/chat 0.3.0 → 0.4.1
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/README.md +22 -5
- package/chat.bundle.es.js +10757 -0
- package/chat.bundle.umd.js +18 -0
- package/chat.es.js +6867 -0
- package/chat.umd.js +18 -0
- package/package.json +62 -2
- package/style.css +1 -0
- package/types/App.vue.d.ts +8 -0
- package/types/__stories__/App.stories.d.ts +17 -0
- package/types/__tests__/index.spec.d.ts +1 -0
- package/types/__tests__/setup.d.ts +0 -0
- package/types/__tests__/utils/create.d.ts +5 -0
- package/types/__tests__/utils/fetch.d.ts +4 -0
- package/types/__tests__/utils/selectors.d.ts +12 -0
- package/types/api/generic.d.ts +6 -0
- package/types/api/message.d.ts +3 -0
- package/types/components/Button.vue.d.ts +9 -0
- package/types/components/Chat.vue.d.ts +2 -0
- package/types/components/ChatWindow.vue.d.ts +2 -0
- package/types/components/GetStarted.vue.d.ts +2 -0
- package/types/components/GetStartedFooter.vue.d.ts +2 -0
- package/types/components/Input.vue.d.ts +2 -0
- package/types/components/Layout.vue.d.ts +11 -0
- package/types/components/Message.vue.d.ts +21 -0
- package/types/components/MessageTyping.vue.d.ts +15 -0
- package/types/components/MessagesList.vue.d.ts +14 -0
- package/types/components/PoweredBy.vue.d.ts +2 -0
- package/types/composables/useChat.d.ts +2 -0
- package/types/composables/useI18n.d.ts +4 -0
- package/types/composables/useOptions.d.ts +4 -0
- package/types/constants/defaults.d.ts +3 -0
- package/types/constants/localStorage.d.ts +2 -0
- package/types/constants/symbols.d.ts +4 -0
- package/types/event-buses/chatEventBus.d.ts +1 -0
- package/types/index.d.ts +2 -0
- package/types/plugins/chat.d.ts +3 -0
- package/types/types/chat.d.ts +11 -0
- package/types/types/messages.d.ts +6 -0
- package/types/types/options.d.ts +24 -0
- package/types/types/webhook.d.ts +15 -0
- package/types/utils/event-bus.d.ts +8 -0
- package/types/utils/mount.d.ts +1 -0
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -52
- package/.np-config.json +0 -5
- package/.storybook/main.ts +0 -27
- package/.storybook/preview.scss +0 -4
- package/.storybook/preview.ts +0 -16
- package/.vscode/extensions.json +0 -3
- package/env.d.ts +0 -1
- package/index.html +0 -13
- package/resources/workflow.json +0 -293
- package/scripts/pack.js +0 -11
- package/scripts/postbuild.js +0 -16
- package/src/App.vue +0 -23
- package/src/__stories__/App.stories.ts +0 -43
- package/src/__tests__/index.spec.ts +0 -223
- package/src/__tests__/setup.ts +0 -1
- package/src/__tests__/utils/create.ts +0 -16
- package/src/__tests__/utils/fetch.ts +0 -18
- package/src/__tests__/utils/selectors.ts +0 -53
- package/src/api/generic.ts +0 -64
- package/src/api/message.ts +0 -31
- package/src/components/Button.vue +0 -41
- package/src/components/Chat.vue +0 -48
- package/src/components/ChatWindow.vue +0 -125
- package/src/components/GetStarted.vue +0 -24
- package/src/components/GetStartedFooter.vue +0 -20
- package/src/components/Input.vue +0 -93
- package/src/components/Layout.vue +0 -82
- package/src/components/Message.vue +0 -97
- package/src/components/MessageTyping.vue +0 -109
- package/src/components/MessagesList.vue +0 -37
- package/src/components/PoweredBy.vue +0 -17
- package/src/composables/useChat.ts +0 -7
- package/src/composables/useI18n.ts +0 -16
- package/src/composables/useOptions.ts +0 -11
- package/src/constants/defaults.ts +0 -25
- package/src/constants/localStorage.ts +0 -2
- package/src/constants/symbols.ts +0 -8
- package/src/event-buses/chatEventBus.ts +0 -3
- package/src/index.ts +0 -42
- package/src/main.scss +0 -40
- package/src/plugins/chat.ts +0 -101
- package/src/shims.d.ts +0 -6
- package/src/types/chat.ts +0 -12
- package/src/types/messages.ts +0 -6
- package/src/types/options.ts +0 -23
- package/src/types/webhook.ts +0 -17
- package/src/utils/event-bus.ts +0 -51
- package/src/utils/mount.ts +0 -16
- package/tsconfig.json +0 -27
- package/vite.config.ts +0 -51
- package/vitest.config.ts +0 -20
- /package/{public/favicon.ico → favicon.ico} +0 -0
- /package/{src/__tests__/utils/index.ts → types/__tests__/utils/index.d.ts} +0 -0
- /package/{src/api/index.ts → types/api/index.d.ts} +0 -0
- /package/{src/components/index.ts → types/components/index.d.ts} +0 -0
- /package/{src/composables/index.ts → types/composables/index.d.ts} +0 -0
- /package/{src/constants/index.ts → types/constants/index.d.ts} +0 -0
- /package/{src/event-buses/index.ts → types/event-buses/index.d.ts} +0 -0
- /package/{src/plugins/index.ts → types/plugins/index.d.ts} +0 -0
- /package/{src/types/index.ts → types/types/index.d.ts} +0 -0
- /package/{src/utils/index.ts → types/utils/index.d.ts} +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import type { ChatMessage } from '@/types';
|
|
3
|
-
import { Message } from './index';
|
|
4
|
-
import type { PropType } from 'vue';
|
|
5
|
-
import { computed } from 'vue';
|
|
6
|
-
|
|
7
|
-
const props = defineProps({
|
|
8
|
-
animation: {
|
|
9
|
-
type: String as PropType<'bouncing' | 'scaling'>,
|
|
10
|
-
default: 'bouncing',
|
|
11
|
-
},
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const message: ChatMessage = {
|
|
15
|
-
id: 'typing',
|
|
16
|
-
text: '',
|
|
17
|
-
sender: 'bot',
|
|
18
|
-
createdAt: '',
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const classes = computed(() => {
|
|
22
|
-
return {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
24
|
-
'chat-message-typing': true,
|
|
25
|
-
[`chat-message-typing-animation-${props.animation}`]: true,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
</script>
|
|
29
|
-
<template>
|
|
30
|
-
<Message :class="classes" :message="message">
|
|
31
|
-
<div class="chat-message-typing-body">
|
|
32
|
-
<span class="chat-message-typing-circle"></span>
|
|
33
|
-
<span class="chat-message-typing-circle"></span>
|
|
34
|
-
<span class="chat-message-typing-circle"></span>
|
|
35
|
-
</div>
|
|
36
|
-
</Message>
|
|
37
|
-
</template>
|
|
38
|
-
<style lang="scss">
|
|
39
|
-
.chat-message-typing {
|
|
40
|
-
max-width: 80px;
|
|
41
|
-
|
|
42
|
-
&.chat-message-typing-animation-scaling .chat-message-typing-circle {
|
|
43
|
-
animation: chat-message-typing-animation-scaling 800ms ease-in-out infinite;
|
|
44
|
-
animation-delay: 3600ms;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
&.chat-message-typing-animation-bouncing .chat-message-typing-circle {
|
|
48
|
-
animation: chat-message-typing-animation-bouncing 800ms ease-in-out infinite;
|
|
49
|
-
animation-delay: 3600ms;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.chat-message-typing-body {
|
|
53
|
-
display: flex;
|
|
54
|
-
justify-content: center;
|
|
55
|
-
align-items: center;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.chat-message-typing-circle {
|
|
59
|
-
display: block;
|
|
60
|
-
height: 10px;
|
|
61
|
-
width: 10px;
|
|
62
|
-
border-radius: 50%;
|
|
63
|
-
background-color: var(--chat--color-typing);
|
|
64
|
-
margin: 3px;
|
|
65
|
-
|
|
66
|
-
&:nth-child(1) {
|
|
67
|
-
animation-delay: 0ms;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
&:nth-child(2) {
|
|
71
|
-
animation-delay: 333ms;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
&:nth-child(3) {
|
|
75
|
-
animation-delay: 666ms;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@keyframes chat-message-typing-animation-scaling {
|
|
81
|
-
0% {
|
|
82
|
-
transform: scale(1);
|
|
83
|
-
}
|
|
84
|
-
33% {
|
|
85
|
-
transform: scale(1);
|
|
86
|
-
}
|
|
87
|
-
50% {
|
|
88
|
-
transform: scale(1.4);
|
|
89
|
-
}
|
|
90
|
-
100% {
|
|
91
|
-
transform: scale(1);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
@keyframes chat-message-typing-animation-bouncing {
|
|
96
|
-
0% {
|
|
97
|
-
transform: translateY(0);
|
|
98
|
-
}
|
|
99
|
-
33% {
|
|
100
|
-
transform: translateY(0);
|
|
101
|
-
}
|
|
102
|
-
50% {
|
|
103
|
-
transform: translateY(-10px);
|
|
104
|
-
}
|
|
105
|
-
100% {
|
|
106
|
-
transform: translateY(0);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
</style>
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import type { PropType } from 'vue';
|
|
3
|
-
import Message from '@/components/Message.vue';
|
|
4
|
-
import type { ChatMessage } from '@/types';
|
|
5
|
-
import MessageTyping from '@/components/MessageTyping.vue';
|
|
6
|
-
import { useChat } from '@/composables';
|
|
7
|
-
|
|
8
|
-
defineProps({
|
|
9
|
-
messages: {
|
|
10
|
-
type: Array as PropType<ChatMessage[]>,
|
|
11
|
-
required: true,
|
|
12
|
-
},
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const chatStore = useChat();
|
|
16
|
-
|
|
17
|
-
const { initialMessages, waitingForResponse } = chatStore;
|
|
18
|
-
</script>
|
|
19
|
-
<template>
|
|
20
|
-
<div class="chat-messages-list">
|
|
21
|
-
<Message
|
|
22
|
-
v-for="initialMessage in initialMessages"
|
|
23
|
-
:key="initialMessage.id"
|
|
24
|
-
:message="initialMessage"
|
|
25
|
-
/>
|
|
26
|
-
<Message v-for="message in messages" :key="message.id" :message="message" />
|
|
27
|
-
<MessageTyping v-if="waitingForResponse" />
|
|
28
|
-
</div>
|
|
29
|
-
</template>
|
|
30
|
-
|
|
31
|
-
<style lang="scss">
|
|
32
|
-
.chat-messages-list {
|
|
33
|
-
margin-top: auto;
|
|
34
|
-
display: block;
|
|
35
|
-
padding: var(--chat--messages-list--padding, var(--chat--spacing));
|
|
36
|
-
}
|
|
37
|
-
</style>
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="chat-powered-by">
|
|
3
|
-
Powered by
|
|
4
|
-
<a href="https://n8n.io?utm_source=n8n-external&utm_medium=widget-powered-by">n8n</a>
|
|
5
|
-
</div>
|
|
6
|
-
</template>
|
|
7
|
-
|
|
8
|
-
<style lang="scss">
|
|
9
|
-
.chat-powered-by {
|
|
10
|
-
text-align: center;
|
|
11
|
-
|
|
12
|
-
a {
|
|
13
|
-
color: var(--chat--color-primary);
|
|
14
|
-
text-decoration: none;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
</style>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useOptions } from '@/composables/useOptions';
|
|
2
|
-
|
|
3
|
-
export function useI18n() {
|
|
4
|
-
const { options } = useOptions();
|
|
5
|
-
const language = options?.defaultLanguage ?? 'en';
|
|
6
|
-
|
|
7
|
-
function t(key: string): string {
|
|
8
|
-
return options?.i18n?.[language]?.[key] ?? key;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function te(key: string): boolean {
|
|
12
|
-
return !!options?.i18n?.[language]?.[key];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return { t, te };
|
|
16
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { ChatOptions } from '@/types';
|
|
2
|
-
|
|
3
|
-
export const defaultOptions: ChatOptions = {
|
|
4
|
-
webhookUrl: 'http://localhost:5678',
|
|
5
|
-
webhookConfig: {
|
|
6
|
-
method: 'POST',
|
|
7
|
-
headers: {},
|
|
8
|
-
},
|
|
9
|
-
target: '#n8n-chat',
|
|
10
|
-
mode: 'window',
|
|
11
|
-
defaultLanguage: 'en',
|
|
12
|
-
initialMessages: ['Hi there! 👋', 'My name is Nathan. How can I assist you today?'],
|
|
13
|
-
i18n: {
|
|
14
|
-
en: {
|
|
15
|
-
title: 'Hi there! 👋',
|
|
16
|
-
subtitle: "Start a chat. We're here to help you 24/7.",
|
|
17
|
-
footer: '',
|
|
18
|
-
getStarted: 'New Conversation',
|
|
19
|
-
inputPlaceholder: 'Type your question..',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
theme: {},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export const defaultMountingTarget = '#n8n-chat';
|
package/src/constants/symbols.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { InjectionKey } from 'vue';
|
|
2
|
-
import type { Chat, ChatOptions } from '@/types';
|
|
3
|
-
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
-
export const ChatSymbol = 'Chat' as unknown as InjectionKey<Chat>;
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
-
export const ChatOptionsSymbol = 'ChatOptions' as unknown as InjectionKey<ChatOptions>;
|
package/src/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import './main.scss';
|
|
2
|
-
|
|
3
|
-
import { createApp } from 'vue';
|
|
4
|
-
import App from './App.vue';
|
|
5
|
-
import type { ChatOptions } from '@/types';
|
|
6
|
-
import { defaultMountingTarget, defaultOptions } from '@/constants';
|
|
7
|
-
import { createDefaultMountingTarget } from '@/utils';
|
|
8
|
-
import { ChatPlugin } from '@/plugins';
|
|
9
|
-
|
|
10
|
-
export function createChat(options?: Partial<ChatOptions>) {
|
|
11
|
-
const resolvedOptions: ChatOptions = {
|
|
12
|
-
...defaultOptions,
|
|
13
|
-
...options,
|
|
14
|
-
webhookConfig: {
|
|
15
|
-
...defaultOptions.webhookConfig,
|
|
16
|
-
...options?.webhookConfig,
|
|
17
|
-
},
|
|
18
|
-
i18n: {
|
|
19
|
-
...defaultOptions.i18n,
|
|
20
|
-
...options?.i18n,
|
|
21
|
-
en: {
|
|
22
|
-
...defaultOptions.i18n?.en,
|
|
23
|
-
...options?.i18n?.en,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
theme: {
|
|
27
|
-
...defaultOptions.theme,
|
|
28
|
-
...options?.theme,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const mountingTarget = resolvedOptions.target ?? defaultMountingTarget;
|
|
33
|
-
if (typeof mountingTarget === 'string') {
|
|
34
|
-
createDefaultMountingTarget(mountingTarget);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
38
|
-
const app = createApp(App);
|
|
39
|
-
app.use(ChatPlugin, resolvedOptions);
|
|
40
|
-
app.mount(mountingTarget);
|
|
41
|
-
return app;
|
|
42
|
-
}
|
package/src/main.scss
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
.n8n-chat {
|
|
2
|
-
@import 'highlight.js/styles/github';
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
:root {
|
|
6
|
-
--chat--color-primary: #e74266;
|
|
7
|
-
--chat--color-primary-shade-50: #db4061;
|
|
8
|
-
--chat--color-primary-shade-100: #cf3c5c;
|
|
9
|
-
--chat--color-secondary: #20b69e;
|
|
10
|
-
--chat--color-secondary-shade-50: #1ca08a;
|
|
11
|
-
--chat--color-white: #ffffff;
|
|
12
|
-
--chat--color-light: #f2f4f8;
|
|
13
|
-
--chat--color-light-shade-50: #e6e9f1;
|
|
14
|
-
--chat--color-light-shade-100: #c2c5cc;
|
|
15
|
-
--chat--color-medium: #d2d4d9;
|
|
16
|
-
--chat--color-dark: #101330;
|
|
17
|
-
--chat--color-disabled: #777980;
|
|
18
|
-
--chat--color-typing: #404040;
|
|
19
|
-
|
|
20
|
-
--chat--spacing: 1rem;
|
|
21
|
-
--chat--border-radius: 0.25rem;
|
|
22
|
-
--chat--transition-duration: 0.15s;
|
|
23
|
-
|
|
24
|
-
--chat--window--width: 400px;
|
|
25
|
-
--chat--window--height: 600px;
|
|
26
|
-
|
|
27
|
-
--chat--textarea--height: 50px;
|
|
28
|
-
|
|
29
|
-
--chat--message--bot--background: var(--chat--color-white);
|
|
30
|
-
--chat--message--bot--color: var(--chat--color-dark);
|
|
31
|
-
--chat--message--user--background: var(--chat--color-secondary);
|
|
32
|
-
--chat--message--user--color: var(--chat--color-white);
|
|
33
|
-
--chat--message--pre--background: rgba(0, 0, 0, 0.05);
|
|
34
|
-
|
|
35
|
-
--chat--toggle--background: var(--chat--color-primary);
|
|
36
|
-
--chat--toggle--hover--background: var(--chat--color-primary-shade-50);
|
|
37
|
-
--chat--toggle--active--background: var(--chat--color-primary-shade-100);
|
|
38
|
-
--chat--toggle--color: var(--chat--color-white);
|
|
39
|
-
--chat--toggle--size: 64px;
|
|
40
|
-
}
|
package/src/plugins/chat.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vue';
|
|
2
|
-
import { computed, nextTick, ref } from 'vue';
|
|
3
|
-
import type { ChatMessage, ChatOptions } from '@/types';
|
|
4
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
-
import { chatEventBus } from '@/event-buses';
|
|
6
|
-
import * as api from '@/api';
|
|
7
|
-
import { ChatOptionsSymbol, ChatSymbol, localStorageSessionIdKey } from '@/constants';
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
-
export const ChatPlugin: Plugin<ChatOptions> = {
|
|
11
|
-
install(app, options) {
|
|
12
|
-
app.provide(ChatOptionsSymbol, options);
|
|
13
|
-
|
|
14
|
-
const messages = ref<ChatMessage[]>([]);
|
|
15
|
-
const currentSessionId = ref<string | null>(null);
|
|
16
|
-
const waitingForResponse = ref(false);
|
|
17
|
-
|
|
18
|
-
const initialMessages = computed<ChatMessage[]>(() =>
|
|
19
|
-
(options.initialMessages ?? []).map((text) => ({
|
|
20
|
-
id: uuidv4(),
|
|
21
|
-
text,
|
|
22
|
-
sender: 'bot',
|
|
23
|
-
createdAt: new Date().toISOString(),
|
|
24
|
-
})),
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
async function sendMessage(text: string) {
|
|
28
|
-
const sentMessage: ChatMessage = {
|
|
29
|
-
id: uuidv4(),
|
|
30
|
-
text,
|
|
31
|
-
sender: 'user',
|
|
32
|
-
createdAt: new Date().toISOString(),
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
messages.value.push(sentMessage);
|
|
36
|
-
waitingForResponse.value = true;
|
|
37
|
-
|
|
38
|
-
void nextTick(() => {
|
|
39
|
-
chatEventBus.emit('scrollToBottom');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const sendMessageResponse = await api.sendMessage(
|
|
43
|
-
text,
|
|
44
|
-
currentSessionId.value as string,
|
|
45
|
-
options,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const receivedMessage: ChatMessage = {
|
|
49
|
-
id: uuidv4(),
|
|
50
|
-
text: sendMessageResponse.output,
|
|
51
|
-
sender: 'bot',
|
|
52
|
-
createdAt: new Date().toISOString(),
|
|
53
|
-
};
|
|
54
|
-
messages.value.push(receivedMessage);
|
|
55
|
-
|
|
56
|
-
waitingForResponse.value = false;
|
|
57
|
-
|
|
58
|
-
void nextTick(() => {
|
|
59
|
-
chatEventBus.emit('scrollToBottom');
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async function loadPreviousSession() {
|
|
64
|
-
const sessionId = localStorage.getItem(localStorageSessionIdKey) ?? uuidv4();
|
|
65
|
-
const previousMessagesResponse = await api.loadPreviousSession(sessionId, options);
|
|
66
|
-
const timestamp = new Date().toISOString();
|
|
67
|
-
|
|
68
|
-
messages.value = (previousMessagesResponse?.data || []).map((message, index) => ({
|
|
69
|
-
id: `${index}`,
|
|
70
|
-
text: message.kwargs.content,
|
|
71
|
-
sender: message.id.includes('HumanMessage') ? 'user' : 'bot',
|
|
72
|
-
createdAt: timestamp,
|
|
73
|
-
}));
|
|
74
|
-
|
|
75
|
-
if (messages.value.length) {
|
|
76
|
-
currentSessionId.value = sessionId;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return sessionId;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async function startNewSession() {
|
|
83
|
-
currentSessionId.value = uuidv4();
|
|
84
|
-
|
|
85
|
-
localStorage.setItem(localStorageSessionIdKey, currentSessionId.value);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const chatStore = {
|
|
89
|
-
initialMessages,
|
|
90
|
-
messages,
|
|
91
|
-
currentSessionId,
|
|
92
|
-
waitingForResponse,
|
|
93
|
-
loadPreviousSession,
|
|
94
|
-
startNewSession,
|
|
95
|
-
sendMessage,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
app.provide(ChatSymbol, chatStore);
|
|
99
|
-
app.config.globalProperties.$chat = chatStore;
|
|
100
|
-
},
|
|
101
|
-
};
|
package/src/shims.d.ts
DELETED
package/src/types/chat.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ChatMessage } from '@/types/messages';
|
|
2
|
-
import type { Ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
export interface Chat {
|
|
5
|
-
initialMessages: Ref<ChatMessage[]>;
|
|
6
|
-
messages: Ref<ChatMessage[]>;
|
|
7
|
-
currentSessionId: Ref<string | null>;
|
|
8
|
-
waitingForResponse: Ref<boolean>;
|
|
9
|
-
loadPreviousSession: () => Promise<string>;
|
|
10
|
-
startNewSession: () => Promise<void>;
|
|
11
|
-
sendMessage: (text: string) => Promise<void>;
|
|
12
|
-
}
|
package/src/types/messages.ts
DELETED
package/src/types/options.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export interface ChatOptions {
|
|
2
|
-
webhookUrl: string;
|
|
3
|
-
webhookConfig?: {
|
|
4
|
-
method?: 'GET' | 'POST';
|
|
5
|
-
headers?: Record<string, string>;
|
|
6
|
-
};
|
|
7
|
-
target?: string | Element;
|
|
8
|
-
mode?: 'window' | 'fullscreen';
|
|
9
|
-
defaultLanguage?: 'en';
|
|
10
|
-
initialMessages?: string[];
|
|
11
|
-
i18n: Record<
|
|
12
|
-
string,
|
|
13
|
-
{
|
|
14
|
-
title: string;
|
|
15
|
-
subtitle: string;
|
|
16
|
-
footer: string;
|
|
17
|
-
getStarted: string;
|
|
18
|
-
inputPlaceholder: string;
|
|
19
|
-
[message: string]: string;
|
|
20
|
-
}
|
|
21
|
-
>;
|
|
22
|
-
theme?: {};
|
|
23
|
-
}
|
package/src/types/webhook.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface LoadPreviousSessionResponseItem {
|
|
2
|
-
id: string[];
|
|
3
|
-
kwargs: {
|
|
4
|
-
content: string;
|
|
5
|
-
additional_kwargs: Record<string, unknown>;
|
|
6
|
-
};
|
|
7
|
-
lc: number;
|
|
8
|
-
type: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface LoadPreviousSessionResponse {
|
|
12
|
-
data: LoadPreviousSessionResponseItem[];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface SendMessageResponse {
|
|
16
|
-
output: string;
|
|
17
|
-
}
|
package/src/utils/event-bus.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
2
|
-
export type CallbackFn = Function;
|
|
3
|
-
export type UnregisterFn = () => void;
|
|
4
|
-
|
|
5
|
-
export interface EventBus {
|
|
6
|
-
on: (eventName: string, fn: CallbackFn) => UnregisterFn;
|
|
7
|
-
off: (eventName: string, fn: CallbackFn) => void;
|
|
8
|
-
emit: <T = Event>(eventName: string, event?: T) => void;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function createEventBus(): EventBus {
|
|
12
|
-
const handlers = new Map<string, CallbackFn[]>();
|
|
13
|
-
|
|
14
|
-
function off(eventName: string, fn: CallbackFn) {
|
|
15
|
-
const eventFns = handlers.get(eventName);
|
|
16
|
-
|
|
17
|
-
if (eventFns) {
|
|
18
|
-
eventFns.splice(eventFns.indexOf(fn) >>> 0, 1);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function on(eventName: string, fn: CallbackFn): UnregisterFn {
|
|
23
|
-
let eventFns = handlers.get(eventName);
|
|
24
|
-
|
|
25
|
-
if (!eventFns) {
|
|
26
|
-
eventFns = [fn];
|
|
27
|
-
} else {
|
|
28
|
-
eventFns.push(fn);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
handlers.set(eventName, eventFns);
|
|
32
|
-
|
|
33
|
-
return () => off(eventName, fn);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function emit<T = Event>(eventName: string, event?: T) {
|
|
37
|
-
const eventFns = handlers.get(eventName);
|
|
38
|
-
|
|
39
|
-
if (eventFns) {
|
|
40
|
-
eventFns.slice().forEach(async (handler) => {
|
|
41
|
-
await handler(event);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return {
|
|
47
|
-
on,
|
|
48
|
-
off,
|
|
49
|
-
emit,
|
|
50
|
-
};
|
|
51
|
-
}
|
package/src/utils/mount.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function createDefaultMountingTarget(mountingTarget: string) {
|
|
2
|
-
const mountingTargetNode = document.querySelector(mountingTarget);
|
|
3
|
-
if (!mountingTargetNode) {
|
|
4
|
-
const generatedMountingTargetNode = document.createElement('div');
|
|
5
|
-
|
|
6
|
-
if (mountingTarget.startsWith('#')) {
|
|
7
|
-
generatedMountingTargetNode.id = mountingTarget.replace('#', '');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (mountingTarget.startsWith('.')) {
|
|
11
|
-
generatedMountingTargetNode.classList.add(mountingTarget.replace('.', ''));
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
document.body.appendChild(generatedMountingTargetNode);
|
|
15
|
-
}
|
|
16
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"rootDir": ".",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"target": "esnext",
|
|
7
|
-
"module": "esnext",
|
|
8
|
-
"allowJs": true,
|
|
9
|
-
"importHelpers": true,
|
|
10
|
-
"incremental": false,
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"baseUrl": ".",
|
|
14
|
-
"types": ["vitest/globals", "unplugin-icons/types/vue"],
|
|
15
|
-
"paths": {
|
|
16
|
-
"@/*": ["src/*"],
|
|
17
|
-
"n8n-design-system/*": ["../design-system/src/*"]
|
|
18
|
-
},
|
|
19
|
-
"lib": ["esnext", "dom", "dom.iterable", "scripthost"],
|
|
20
|
-
// TODO: remove all options below this line
|
|
21
|
-
"noUnusedLocals": false,
|
|
22
|
-
"useUnknownInCatchVariables": false
|
|
23
|
-
},
|
|
24
|
-
"include": ["src/**/*.ts", "src/**/*.vue", "**/*.d.ts"]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
package/vite.config.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath, URL } from 'node:url';
|
|
2
|
-
|
|
3
|
-
import { defineConfig } from 'vite';
|
|
4
|
-
import { resolve } from 'path';
|
|
5
|
-
import vue from '@vitejs/plugin-vue';
|
|
6
|
-
import icons from 'unplugin-icons/vite';
|
|
7
|
-
import dts from 'vite-plugin-dts';
|
|
8
|
-
|
|
9
|
-
const includeVue = process.env.INCLUDE_VUE === 'true';
|
|
10
|
-
|
|
11
|
-
// https://vitejs.dev/config/
|
|
12
|
-
export default defineConfig({
|
|
13
|
-
plugins: [
|
|
14
|
-
vue(),
|
|
15
|
-
icons({
|
|
16
|
-
compiler: 'vue3',
|
|
17
|
-
}),
|
|
18
|
-
dts(),
|
|
19
|
-
],
|
|
20
|
-
resolve: {
|
|
21
|
-
alias: {
|
|
22
|
-
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
define: {
|
|
26
|
-
'process.env.NODE_ENV': process.env.NODE_ENV ? `"${process.env.NODE_ENV}"` : '"development"',
|
|
27
|
-
},
|
|
28
|
-
build: {
|
|
29
|
-
emptyOutDir: !includeVue,
|
|
30
|
-
lib: {
|
|
31
|
-
entry: resolve(__dirname, 'src', 'index.ts'),
|
|
32
|
-
name: 'N8nChat',
|
|
33
|
-
fileName: (format) => (includeVue ? `chat.bundle.${format}.js` : `chat.${format}.js`),
|
|
34
|
-
},
|
|
35
|
-
rollupOptions: {
|
|
36
|
-
// make sure to externalize deps that shouldn't be bundled
|
|
37
|
-
// into your library
|
|
38
|
-
external: includeVue ? [] : ['vue'],
|
|
39
|
-
output: {
|
|
40
|
-
exports: 'named',
|
|
41
|
-
// Provide global variables to use in the UMD build
|
|
42
|
-
// for externalized deps
|
|
43
|
-
globals: includeVue
|
|
44
|
-
? {}
|
|
45
|
-
: {
|
|
46
|
-
vue: 'Vue',
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
});
|
package/vitest.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
-
import { mergeConfig, defineConfig } from 'vite';
|
|
3
|
-
import { configDefaults } from 'vitest/config';
|
|
4
|
-
import viteConfig from './vite.config';
|
|
5
|
-
|
|
6
|
-
export default mergeConfig(
|
|
7
|
-
viteConfig,
|
|
8
|
-
defineConfig({
|
|
9
|
-
test: {
|
|
10
|
-
globals: true,
|
|
11
|
-
environment: 'jsdom',
|
|
12
|
-
exclude: [...configDefaults.exclude, 'e2e/*'],
|
|
13
|
-
root: fileURLToPath(new URL('./', import.meta.url)),
|
|
14
|
-
setupFiles: ['./src/__tests__/setup.ts'],
|
|
15
|
-
transformMode: {
|
|
16
|
-
web: [/\.[jt]sx$/],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
}),
|
|
20
|
-
);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|