@n8n/chat 0.6.0 → 0.6.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.
Files changed (205) hide show
  1. package/{src/App.vue → App.vue} +2 -2
  2. package/README.md +27 -4
  3. package/__stories__/App.stories.d.ts +16 -0
  4. package/__stories__/App.stories.js +38 -0
  5. package/__stories__/App.stories.mjs +32 -0
  6. package/__tests__/index.spec.d.ts +1 -0
  7. package/__tests__/index.spec.js +146 -0
  8. package/__tests__/index.spec.mjs +172 -0
  9. package/__tests__/setup.js +3 -0
  10. package/__tests__/setup.mjs +1 -0
  11. package/__tests__/utils/create.d.ts +5 -0
  12. package/__tests__/utils/create.js +16 -0
  13. package/__tests__/utils/create.mjs +10 -0
  14. package/__tests__/utils/fetch.d.ts +3 -0
  15. package/__tests__/utils/fetch.js +20 -0
  16. package/__tests__/utils/fetch.mjs +9 -0
  17. package/__tests__/utils/index.js +38 -0
  18. package/__tests__/utils/index.mjs +3 -0
  19. package/__tests__/utils/selectors.d.ts +12 -0
  20. package/__tests__/utils/selectors.js +58 -0
  21. package/__tests__/utils/selectors.mjs +41 -0
  22. package/api/generic.d.ts +6 -0
  23. package/api/generic.js +68 -0
  24. package/api/generic.mjs +54 -0
  25. package/api/index.js +27 -0
  26. package/api/index.mjs +2 -0
  27. package/api/message.d.ts +3 -0
  28. package/api/message.js +33 -0
  29. package/api/message.mjs +30 -0
  30. package/chat.bundle.es.js +10753 -0
  31. package/chat.bundle.umd.js +18 -0
  32. package/chat.es.js +6864 -0
  33. package/chat.umd.js +18 -0
  34. package/components/Button.vue +34 -0
  35. package/{src/components → components}/Chat.vue +19 -15
  36. package/components/ChatWindow.vue +104 -0
  37. package/components/GetStarted.vue +24 -0
  38. package/{src/components → components}/GetStartedFooter.vue +4 -4
  39. package/{src/components → components}/Input.vue +35 -40
  40. package/components/Layout.vue +66 -0
  41. package/components/Message.vue +94 -0
  42. package/components/MessageTyping.vue +101 -0
  43. package/{src/components → components}/MessagesList.vue +8 -8
  44. package/{src/components → components}/PoweredBy.vue +6 -7
  45. package/components/index.js +76 -0
  46. package/components/index.mjs +10 -0
  47. package/composables/index.js +38 -0
  48. package/composables/index.mjs +3 -0
  49. package/composables/useChat.d.ts +1 -0
  50. package/composables/useChat.js +11 -0
  51. package/composables/useChat.mjs +5 -0
  52. package/composables/useI18n.d.ts +4 -0
  53. package/composables/useI18n.js +23 -0
  54. package/composables/useI18n.mjs +12 -0
  55. package/composables/useOptions.d.ts +3 -0
  56. package/composables/useOptions.js +14 -0
  57. package/composables/useOptions.mjs +8 -0
  58. package/constants/defaults.d.ts +3 -0
  59. package/constants/defaults.js +32 -0
  60. package/constants/defaults.mjs +26 -0
  61. package/constants/index.js +38 -0
  62. package/constants/index.mjs +3 -0
  63. package/constants/localStorage.d.ts +2 -0
  64. package/constants/localStorage.js +8 -0
  65. package/{src/constants/localStorage.ts → constants/localStorage.mjs} +1 -1
  66. package/constants/symbols.d.ts +3 -0
  67. package/constants/symbols.js +8 -0
  68. package/constants/symbols.mjs +2 -0
  69. package/css/index.css +31 -0
  70. package/event-buses/chatEventBus.d.ts +1 -0
  71. package/event-buses/chatEventBus.js +8 -0
  72. package/event-buses/chatEventBus.mjs +2 -0
  73. package/event-buses/index.js +16 -0
  74. package/event-buses/index.mjs +1 -0
  75. package/index.d.ts +3 -0
  76. package/index.js +43 -0
  77. package/index.mjs +36 -0
  78. package/main.css +151 -0
  79. package/package.json +41 -5
  80. package/plugins/chat.d.ts +3 -0
  81. package/plugins/chat.js +85 -0
  82. package/plugins/chat.mjs +83 -0
  83. package/plugins/index.js +16 -0
  84. package/plugins/index.mjs +1 -0
  85. package/style.css +1 -0
  86. package/types/App.vue.d.ts +8 -0
  87. package/types/__stories__/App.stories.d.ts +17 -0
  88. package/types/__tests__/index.spec.d.ts +1 -0
  89. package/types/__tests__/setup.d.ts +0 -0
  90. package/types/__tests__/utils/create.d.ts +5 -0
  91. package/types/__tests__/utils/fetch.d.ts +4 -0
  92. package/types/__tests__/utils/index.d.ts +3 -0
  93. package/types/__tests__/utils/selectors.d.ts +12 -0
  94. package/types/api/generic.d.ts +6 -0
  95. package/types/api/index.d.ts +2 -0
  96. package/types/api/message.d.ts +3 -0
  97. package/types/chat.d.ts +11 -0
  98. package/types/chat.js +1 -0
  99. package/types/chat.mjs +0 -0
  100. package/types/components/Button.vue.d.ts +9 -0
  101. package/types/components/Chat.vue.d.ts +2 -0
  102. package/types/components/ChatWindow.vue.d.ts +2 -0
  103. package/types/components/GetStarted.vue.d.ts +2 -0
  104. package/types/components/GetStartedFooter.vue.d.ts +2 -0
  105. package/types/components/Input.vue.d.ts +2 -0
  106. package/types/components/Layout.vue.d.ts +11 -0
  107. package/types/components/Message.vue.d.ts +21 -0
  108. package/types/components/MessageTyping.vue.d.ts +15 -0
  109. package/types/components/MessagesList.vue.d.ts +14 -0
  110. package/types/components/PoweredBy.vue.d.ts +2 -0
  111. package/types/components/index.d.ts +10 -0
  112. package/types/composables/index.d.ts +3 -0
  113. package/types/composables/useChat.d.ts +2 -0
  114. package/types/composables/useI18n.d.ts +4 -0
  115. package/types/composables/useOptions.d.ts +4 -0
  116. package/types/constants/defaults.d.ts +3 -0
  117. package/types/constants/index.d.ts +3 -0
  118. package/types/constants/localStorage.d.ts +2 -0
  119. package/types/constants/symbols.d.ts +4 -0
  120. package/types/event-buses/chatEventBus.d.ts +1 -0
  121. package/types/event-buses/index.d.ts +1 -0
  122. package/types/index.js +49 -0
  123. package/types/index.mjs +4 -0
  124. package/types/messages.d.ts +6 -0
  125. package/types/messages.js +1 -0
  126. package/types/messages.mjs +0 -0
  127. package/types/options.d.ts +25 -0
  128. package/types/options.js +1 -0
  129. package/types/options.mjs +0 -0
  130. package/types/plugins/chat.d.ts +3 -0
  131. package/types/plugins/index.d.ts +1 -0
  132. package/types/types/chat.d.ts +11 -0
  133. package/types/types/index.d.ts +4 -0
  134. package/types/types/messages.d.ts +6 -0
  135. package/types/types/options.d.ts +25 -0
  136. package/types/types/webhook.d.ts +15 -0
  137. package/types/utils/event-bus.d.ts +8 -0
  138. package/types/utils/mount.d.ts +1 -0
  139. package/types/webhook.d.ts +15 -0
  140. package/types/webhook.js +1 -0
  141. package/types/webhook.mjs +0 -0
  142. package/utils/event-bus.d.ts +8 -0
  143. package/utils/event-bus.js +38 -0
  144. package/utils/event-bus.mjs +32 -0
  145. package/utils/index.d.ts +2 -0
  146. package/utils/index.js +27 -0
  147. package/utils/index.mjs +2 -0
  148. package/utils/mount.d.ts +1 -0
  149. package/utils/mount.js +19 -0
  150. package/utils/mount.mjs +13 -0
  151. package/.eslintignore +0 -2
  152. package/.eslintrc.cjs +0 -51
  153. package/.np-config.json +0 -5
  154. package/.storybook/main.ts +0 -27
  155. package/.storybook/preview.scss +0 -4
  156. package/.storybook/preview.ts +0 -16
  157. package/.vscode/extensions.json +0 -3
  158. package/env.d.ts +0 -1
  159. package/index.html +0 -13
  160. package/resources/workflow.json +0 -293
  161. package/scripts/pack.js +0 -11
  162. package/scripts/postbuild.js +0 -16
  163. package/src/__stories__/App.stories.ts +0 -43
  164. package/src/__tests__/index.spec.ts +0 -223
  165. package/src/__tests__/utils/create.ts +0 -16
  166. package/src/__tests__/utils/fetch.ts +0 -18
  167. package/src/__tests__/utils/selectors.ts +0 -53
  168. package/src/api/generic.ts +0 -64
  169. package/src/api/message.ts +0 -31
  170. package/src/components/Button.vue +0 -41
  171. package/src/components/ChatWindow.vue +0 -125
  172. package/src/components/GetStarted.vue +0 -24
  173. package/src/components/Layout.vue +0 -82
  174. package/src/components/Message.vue +0 -97
  175. package/src/components/MessageTyping.vue +0 -109
  176. package/src/composables/useChat.ts +0 -7
  177. package/src/composables/useI18n.ts +0 -16
  178. package/src/composables/useOptions.ts +0 -11
  179. package/src/constants/defaults.ts +0 -25
  180. package/src/constants/symbols.ts +0 -8
  181. package/src/event-buses/chatEventBus.ts +0 -3
  182. package/src/index.ts +0 -42
  183. package/src/main.scss +0 -40
  184. package/src/plugins/chat.ts +0 -101
  185. package/src/types/chat.ts +0 -12
  186. package/src/types/messages.ts +0 -6
  187. package/src/types/options.ts +0 -23
  188. package/src/types/webhook.ts +0 -17
  189. package/src/utils/event-bus.ts +0 -51
  190. package/src/utils/mount.ts +0 -16
  191. package/tsconfig.json +0 -27
  192. package/vite.config.ts +0 -51
  193. package/vitest.config.ts +0 -20
  194. /package/{src/__tests__/setup.ts → __tests__/setup.d.ts} +0 -0
  195. /package/{src/__tests__/utils/index.ts → __tests__/utils/index.d.ts} +0 -0
  196. /package/{src/api/index.ts → api/index.d.ts} +0 -0
  197. /package/{src/components/index.ts → components/index.d.ts} +0 -0
  198. /package/{src/composables/index.ts → composables/index.d.ts} +0 -0
  199. /package/{src/constants/index.ts → constants/index.d.ts} +0 -0
  200. /package/{src/event-buses/index.ts → event-buses/index.d.ts} +0 -0
  201. /package/{public/favicon.ico → favicon.ico} +0 -0
  202. /package/{src/plugins/index.ts → plugins/index.d.ts} +0 -0
  203. /package/{src/shims.d.ts → shims.d.ts} +0 -0
  204. /package/{src/types/index.ts → types/index.d.ts} +0 -0
  205. /package/{src/utils/index.ts → types/utils/index.d.ts} +0 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ChatPlugin = void 0;
7
+ var _vue = require("vue");
8
+ var _uuid = require("uuid");
9
+ var _eventBuses = require("@n8n/chat/event-buses");
10
+ var api = _interopRequireWildcard(require("@n8n/chat/api"));
11
+ var _constants = require("@n8n/chat/constants");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ const ChatPlugin = exports.ChatPlugin = {
15
+ install(app, options) {
16
+ app.provide(_constants.ChatOptionsSymbol, options);
17
+ const messages = (0, _vue.ref)([]);
18
+ const currentSessionId = (0, _vue.ref)(null);
19
+ const waitingForResponse = (0, _vue.ref)(false);
20
+ const initialMessages = (0, _vue.computed)(() => (options.initialMessages ?? []).map(text => ({
21
+ id: (0, _uuid.v4)(),
22
+ text,
23
+ sender: "bot",
24
+ createdAt: /* @__PURE__ */new Date().toISOString()
25
+ })));
26
+ async function sendMessage(text) {
27
+ const sentMessage = {
28
+ id: (0, _uuid.v4)(),
29
+ text,
30
+ sender: "user",
31
+ createdAt: /* @__PURE__ */new Date().toISOString()
32
+ };
33
+ messages.value.push(sentMessage);
34
+ waitingForResponse.value = true;
35
+ void (0, _vue.nextTick)(() => {
36
+ _eventBuses.chatEventBus.emit("scrollToBottom");
37
+ });
38
+ const sendMessageResponse = await api.sendMessage(text, currentSessionId.value, options);
39
+ const receivedMessage = {
40
+ id: (0, _uuid.v4)(),
41
+ text: sendMessageResponse.output,
42
+ sender: "bot",
43
+ createdAt: /* @__PURE__ */new Date().toISOString()
44
+ };
45
+ messages.value.push(receivedMessage);
46
+ waitingForResponse.value = false;
47
+ void (0, _vue.nextTick)(() => {
48
+ _eventBuses.chatEventBus.emit("scrollToBottom");
49
+ });
50
+ }
51
+ async function loadPreviousSession() {
52
+ if (!options.loadPreviousSession) {
53
+ return;
54
+ }
55
+ const sessionId = localStorage.getItem(_constants.localStorageSessionIdKey) ?? (0, _uuid.v4)();
56
+ const previousMessagesResponse = await api.loadPreviousSession(sessionId, options);
57
+ const timestamp = /* @__PURE__ */new Date().toISOString();
58
+ messages.value = (previousMessagesResponse?.data || []).map((message, index) => ({
59
+ id: `${index}`,
60
+ text: message.kwargs.content,
61
+ sender: message.id.includes("HumanMessage") ? "user" : "bot",
62
+ createdAt: timestamp
63
+ }));
64
+ if (messages.value.length) {
65
+ currentSessionId.value = sessionId;
66
+ }
67
+ return sessionId;
68
+ }
69
+ async function startNewSession() {
70
+ currentSessionId.value = (0, _uuid.v4)();
71
+ localStorage.setItem(_constants.localStorageSessionIdKey, currentSessionId.value);
72
+ }
73
+ const chatStore = {
74
+ initialMessages,
75
+ messages,
76
+ currentSessionId,
77
+ waitingForResponse,
78
+ loadPreviousSession,
79
+ startNewSession,
80
+ sendMessage
81
+ };
82
+ app.provide(_constants.ChatSymbol, chatStore);
83
+ app.config.globalProperties.$chat = chatStore;
84
+ }
85
+ };
@@ -0,0 +1,83 @@
1
+ import { computed, nextTick, ref } from "vue";
2
+ import { v4 as uuidv4 } from "uuid";
3
+ import { chatEventBus } from "@n8n/chat/event-buses";
4
+ import * as api from "@n8n/chat/api";
5
+ import { ChatOptionsSymbol, ChatSymbol, localStorageSessionIdKey } from "@n8n/chat/constants";
6
+ export const ChatPlugin = {
7
+ install(app, options) {
8
+ app.provide(ChatOptionsSymbol, options);
9
+ const messages = ref([]);
10
+ const currentSessionId = ref(null);
11
+ const waitingForResponse = ref(false);
12
+ const initialMessages = computed(
13
+ () => (options.initialMessages ?? []).map((text) => ({
14
+ id: uuidv4(),
15
+ text,
16
+ sender: "bot",
17
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
18
+ }))
19
+ );
20
+ async function sendMessage(text) {
21
+ const sentMessage = {
22
+ id: uuidv4(),
23
+ text,
24
+ sender: "user",
25
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
26
+ };
27
+ messages.value.push(sentMessage);
28
+ waitingForResponse.value = true;
29
+ void nextTick(() => {
30
+ chatEventBus.emit("scrollToBottom");
31
+ });
32
+ const sendMessageResponse = await api.sendMessage(
33
+ text,
34
+ currentSessionId.value,
35
+ options
36
+ );
37
+ const receivedMessage = {
38
+ id: uuidv4(),
39
+ text: sendMessageResponse.output,
40
+ sender: "bot",
41
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
42
+ };
43
+ messages.value.push(receivedMessage);
44
+ waitingForResponse.value = false;
45
+ void nextTick(() => {
46
+ chatEventBus.emit("scrollToBottom");
47
+ });
48
+ }
49
+ async function loadPreviousSession() {
50
+ if (!options.loadPreviousSession) {
51
+ return;
52
+ }
53
+ const sessionId = localStorage.getItem(localStorageSessionIdKey) ?? uuidv4();
54
+ const previousMessagesResponse = await api.loadPreviousSession(sessionId, options);
55
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
56
+ messages.value = (previousMessagesResponse?.data || []).map((message, index) => ({
57
+ id: `${index}`,
58
+ text: message.kwargs.content,
59
+ sender: message.id.includes("HumanMessage") ? "user" : "bot",
60
+ createdAt: timestamp
61
+ }));
62
+ if (messages.value.length) {
63
+ currentSessionId.value = sessionId;
64
+ }
65
+ return sessionId;
66
+ }
67
+ async function startNewSession() {
68
+ currentSessionId.value = uuidv4();
69
+ localStorage.setItem(localStorageSessionIdKey, currentSessionId.value);
70
+ }
71
+ const chatStore = {
72
+ initialMessages,
73
+ messages,
74
+ currentSessionId,
75
+ waitingForResponse,
76
+ loadPreviousSession,
77
+ startNewSession,
78
+ sendMessage
79
+ };
80
+ app.provide(ChatSymbol, chatStore);
81
+ app.config.globalProperties.$chat = chatStore;
82
+ }
83
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _chat = require("./chat");
7
+ Object.keys(_chat).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _chat[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _chat[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1 @@
1
+ export * from "./chat.mjs";
package/style.css ADDED
@@ -0,0 +1 @@
1
+ .n8n-chat pre code.hljs{display:block;overflow-x:auto;padding:1em}.n8n-chat code.hljs{padding:3px 5px}.n8n-chat .hljs{color:#24292e;background:#ffffff}.n8n-chat .hljs-doctag,.n8n-chat .hljs-keyword,.n8n-chat .hljs-meta .hljs-keyword,.n8n-chat .hljs-template-tag,.n8n-chat .hljs-template-variable,.n8n-chat .hljs-type,.n8n-chat .hljs-variable.language_{color:#d73a49}.n8n-chat .hljs-title,.n8n-chat .hljs-title.class_,.n8n-chat .hljs-title.class_.inherited__,.n8n-chat .hljs-title.function_{color:#6f42c1}.n8n-chat .hljs-attr,.n8n-chat .hljs-attribute,.n8n-chat .hljs-literal,.n8n-chat .hljs-meta,.n8n-chat .hljs-number,.n8n-chat .hljs-operator,.n8n-chat .hljs-variable,.n8n-chat .hljs-selector-attr,.n8n-chat .hljs-selector-class,.n8n-chat .hljs-selector-id{color:#005cc5}.n8n-chat .hljs-regexp,.n8n-chat .hljs-string,.n8n-chat .hljs-meta .hljs-string{color:#032f62}.n8n-chat .hljs-built_in,.n8n-chat .hljs-symbol{color:#e36209}.n8n-chat .hljs-comment,.n8n-chat .hljs-code,.n8n-chat .hljs-formula{color:#6a737d}.n8n-chat .hljs-name,.n8n-chat .hljs-quote,.n8n-chat .hljs-selector-tag,.n8n-chat .hljs-selector-pseudo{color:#22863a}.n8n-chat .hljs-subst{color:#24292e}.n8n-chat .hljs-section{color:#005cc5;font-weight:700}.n8n-chat .hljs-bullet{color:#735c0f}.n8n-chat .hljs-emphasis{color:#24292e;font-style:italic}.n8n-chat .hljs-strong{color:#24292e;font-weight:700}.n8n-chat .hljs-addition{color:#22863a;background-color:#f0fff4}.n8n-chat .hljs-deletion{color:#b31d28;background-color:#ffeef0}:root{--chat--color-primary: #e74266;--chat--color-primary-shade-50: #db4061;--chat--color-primary-shade-100: #cf3c5c;--chat--color-secondary: #20b69e;--chat--color-secondary-shade-50: #1ca08a;--chat--color-white: #ffffff;--chat--color-light: #f2f4f8;--chat--color-light-shade-50: #e6e9f1;--chat--color-light-shade-100: #c2c5cc;--chat--color-medium: #d2d4d9;--chat--color-dark: #101330;--chat--color-disabled: #777980;--chat--color-typing: #404040;--chat--spacing: 1rem;--chat--border-radius: .25rem;--chat--transition-duration: .15s;--chat--window--width: 400px;--chat--window--height: 600px;--chat--textarea--height: 50px;--chat--message--bot--background: var(--chat--color-white);--chat--message--bot--color: var(--chat--color-dark);--chat--message--user--background: var(--chat--color-secondary);--chat--message--user--color: var(--chat--color-white);--chat--message--pre--background: rgba(0, 0, 0, .05);--chat--toggle--background: var(--chat--color-primary);--chat--toggle--hover--background: var(--chat--color-primary-shade-50);--chat--toggle--active--background: var(--chat--color-primary-shade-100);--chat--toggle--color: var(--chat--color-white);--chat--toggle--size: 64px}.chat-button{display:inline-flex;text-align:center;vertical-align:middle;-webkit-user-select:none;user-select:none;color:var(--chat--button--color, var(--chat--color-light));background-color:var(--chat--button--background, var(--chat--color-primary));border:1px solid transparent;padding:var(--chat--button--padding, calc(var(--chat--spacing) * 1 / 2) var(--chat--spacing));font-size:1rem;line-height:1.5;border-radius:var(--chat--button--border-radius, var(--chat--border-radius));transition:color var(--chat--transition-duration) ease-in-out,background-color var(--chat--transition-duration) ease-in-out,border-color var(--chat--transition-duration) ease-in-out,box-shadow var(--chat--transition-duration) ease-in-out;cursor:pointer}.chat-button:hover{color:var(--chat--button--hover--color, var(--chat--color-light));background-color:var(--chat--button--hover--background, var(--chat--color-primary-shade-50));text-decoration:none}.chat-button:focus{outline:0;box-shadow:0 0 0 .2rem #007bff40}.chat-button:disabled{opacity:.65}.chat-layout{width:100%;height:100%;display:flex;overflow-y:auto;flex-direction:column;font-family:var(--chat--font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif)}.chat-layout .chat-header{padding:var(--chat--header--padding, var(--chat--spacing));background:var(--chat--header--background, var(--chat--color-dark));color:var(--chat--header--color, var(--chat--color-light))}.chat-layout .chat-body{background:var(--chat--body--background, var(--chat--color-light));flex:1;display:flex;flex-direction:column;overflow-y:auto;position:relative;min-height:100px}.chat-layout .chat-footer{border-top:1px solid var(--chat--color-light-shade-100);background:var(--chat--footer--background, var(--chat--color-light));color:var(--chat--footer--color, var(--chat--color-dark))}.chat-get-started{padding-top:var(--chat--spacing);padding-bottom:var(--chat--spacing);display:flex;justify-content:center;align-items:center;height:100%}.chat-powered-by{text-align:center}.chat-powered-by a{color:var(--chat--color-primary);text-decoration:none}.chat-get-started-footer{padding:var(--chat--spacing)}.chat-message{display:block;max-width:80%;padding:var(--chat--message--padding, var(--chat--spacing));border-radius:var(--chat--message--border-radius, var(--chat--border-radius))}.chat-message+.chat-message{margin-top:var(--chat--message--margin-bottom, calc(var(--chat--spacing) * .5))}.chat-message.chat-message-from-bot{background-color:var(--chat--message--bot--background);color:var(--chat--message--bot--color);border-bottom-left-radius:0}.chat-message.chat-message-from-user{background-color:var(--chat--message--user--background);color:var(--chat--message--user--color);margin-left:auto;border-bottom-right-radius:0}.chat-message>.chat-message-markdown{display:block;box-sizing:border-box}.chat-message>.chat-message-markdown>*:first-child{margin-top:0}.chat-message>.chat-message-markdown>*:last-child{margin-bottom:0}.chat-message>.chat-message-markdown pre{font-family:inherit;font-size:inherit;margin:0;white-space:pre-wrap;box-sizing:border-box;padding:var(--chat--spacing);background:var(--chat--message--pre--background);border-radius:var(--chat--border-radius)}.chat-message-typing{max-width:80px}.chat-message-typing.chat-message-typing-animation-scaling .chat-message-typing-circle{animation:chat-message-typing-animation-scaling .8s ease-in-out infinite;animation-delay:3.6s}.chat-message-typing.chat-message-typing-animation-bouncing .chat-message-typing-circle{animation:chat-message-typing-animation-bouncing .8s ease-in-out infinite;animation-delay:3.6s}.chat-message-typing .chat-message-typing-body{display:flex;justify-content:center;align-items:center}.chat-message-typing .chat-message-typing-circle{display:block;height:10px;width:10px;border-radius:50%;background-color:var(--chat--color-typing);margin:3px}.chat-message-typing .chat-message-typing-circle:nth-child(1){animation-delay:0ms}.chat-message-typing .chat-message-typing-circle:nth-child(2){animation-delay:333ms}.chat-message-typing .chat-message-typing-circle:nth-child(3){animation-delay:666ms}@keyframes chat-message-typing-animation-scaling{0%{transform:scale(1)}33%{transform:scale(1)}50%{transform:scale(1.4)}to{transform:scale(1)}}@keyframes chat-message-typing-animation-bouncing{0%{transform:translateY(0)}33%{transform:translateY(0)}50%{transform:translateY(-10px)}to{transform:translateY(0)}}.chat-messages-list{margin-top:auto;display:block;padding:var(--chat--messages-list--padding, var(--chat--spacing))}.chat-input{display:flex;justify-content:center;align-items:center;width:100%}.chat-input textarea{font-family:inherit;font-size:inherit;width:100%;border:0;padding:var(--chat--spacing);max-height:var(--chat--textarea--height);resize:none}.chat-input .chat-input-send-button{height:var(--chat--textarea--height);width:var(--chat--textarea--height);background:white;cursor:pointer;color:var(--chat--color-secondary);border:0;font-size:24px;display:inline-flex;align-items:center;justify-content:center;transition:color var(--chat--transition-duration) ease}.chat-input .chat-input-send-button:hover,.chat-input .chat-input-send-button:focus{color:var(--chat--color-secondary-shade-50)}.chat-input .chat-input-send-button[disabled]{cursor:default;color:var(--chat--color-disabled)}.chat-window-wrapper{position:fixed;display:flex;flex-direction:column;bottom:var(--chat--window--bottom, var(--chat--spacing));right:var(--chat--window--right, var(--chat--spacing));z-index:var(--chat--window--z-index, 9999);max-width:calc(100% - var(--chat--window--right, var(--chat--spacing)) * 2);max-height:calc(100% - var(--chat--window--bottom, var(--chat--spacing)) * 2)}.chat-window-wrapper .chat-window{display:flex;width:var(--chat--window--width);height:var(--chat--window--height);max-width:100%;max-height:100%;border:var(--chat--window--border, 1px solid var(--chat--color-light-shade-100));border-radius:var(--chat--window--border-radius, var(--chat--border-radius));margin-bottom:var(--chat--window--margin-bottom, var(--chat--spacing));overflow:hidden;transform-origin:bottom right}.chat-window-wrapper .chat-window .chat-layout{width:auto;height:auto;flex:1}.chat-window-wrapper .chat-window-toggle{flex:0 0 auto;background:var(--chat--toggle--background);color:var(--chat--toggle--color);cursor:pointer;width:var(--chat--toggle--width, var(--chat--toggle--size));height:var(--chat--toggle--height, var(--chat--toggle--size));border-radius:var(--chat--toggle--border-radius, 50%);display:inline-flex;align-items:center;justify-content:center;margin-left:auto;transition:transform var(--chat--transition-duration) ease,background var(--chat--transition-duration) ease}.chat-window-wrapper .chat-window-toggle:hover,.chat-window-wrapper .chat-window-toggle:focus{transform:scale(1.05);background:var(--chat--toggle--hover--background)}.chat-window-wrapper .chat-window-toggle:active{transform:scale(.95);background:var(--chat--toggle--active--background)}.chat-window-transition-enter-active,.chat-window-transition-leave-active{transition:transform var(--chat--transition-duration) ease,opacity var(--chat--transition-duration) ease}.chat-window-transition-enter-from,.chat-window-transition-leave-to{transform:scale(0);opacity:0}.chat-window-toggle-transition-enter-active,.chat-window-toggle-transition-leave-active{transition:opacity var(--chat--transition-duration) ease}.chat-window-toggle-transition-enter-from,.chat-window-toggle-transition-leave-to{opacity:0}
@@ -0,0 +1,8 @@
1
+ declare const _default: import("vue").DefineComponent<Readonly<import("vue").ComponentPropsOptions<{
2
+ [x: string]: unknown;
3
+ }>>, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, readonly string[] | Readonly<import("vue").ExtractPropTypes<Readonly<import("vue").ComponentObjectPropsOptions<{
4
+ [x: string]: unknown;
5
+ }>>>>, {
6
+ readonly [x: number]: string;
7
+ } | {}, {}>;
8
+ export default _default;
@@ -0,0 +1,17 @@
1
+ import type { StoryObj } from '@storybook/vue3';
2
+ import type { ChatOptions } from '../types';
3
+ declare const meta: {
4
+ title: string;
5
+ render: (args: Partial<ChatOptions>) => {
6
+ setup(): {};
7
+ template: string;
8
+ };
9
+ parameters: {
10
+ layout: string;
11
+ };
12
+ tags: string[];
13
+ };
14
+ export default meta;
15
+ type Story = StoryObj<typeof meta>;
16
+ export declare const Fullscreen: Story;
17
+ export declare const Windowed: Story;
@@ -0,0 +1 @@
1
+ export {};
File without changes
@@ -0,0 +1,5 @@
1
+ import { createChat } from '../../index';
2
+ export declare function createTestChat(options?: Parameters<typeof createChat>[0]): {
3
+ unmount: () => void;
4
+ container: Element;
5
+ };
@@ -0,0 +1,4 @@
1
+ import type { LoadPreviousSessionResponse, SendMessageResponse } from '../../types';
2
+ export declare function createFetchResponse<T>(data: T): () => Promise<Response>;
3
+ export declare const createGetLatestMessagesResponse: (data?: LoadPreviousSessionResponse['data']) => LoadPreviousSessionResponse;
4
+ export declare const createSendMessageResponse: (output: SendMessageResponse['output']) => SendMessageResponse;
@@ -0,0 +1,3 @@
1
+ export * from './create';
2
+ export * from './fetch';
3
+ export * from './selectors';
@@ -0,0 +1,12 @@
1
+ export declare function getMountingTarget(target?: string): Element | null;
2
+ export declare function getChatWindowWrapper(): Element | null;
3
+ export declare function getChatWindowToggle(): Element | null;
4
+ export declare function getChatWrapper(): Element | null;
5
+ export declare function getChatMessages(): NodeListOf<Element>;
6
+ export declare function getChatMessage(index: number): Element;
7
+ export declare function getChatMessageByText(text: string): HTMLElement | null;
8
+ export declare function getChatMessageTyping(): Element | null;
9
+ export declare function getGetStartedButton(): Element | null;
10
+ export declare function getChatInput(): Element | null;
11
+ export declare function getChatInputTextarea(): Element | null;
12
+ export declare function getChatInputSendButton(): Element | null;
@@ -0,0 +1,6 @@
1
+ export declare function authenticatedFetch<T>(...args: Parameters<typeof fetch>): Promise<T>;
2
+ export declare function get<T>(url: string, query?: object, options?: RequestInit): Promise<T>;
3
+ export declare function post<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
4
+ export declare function put<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
5
+ export declare function patch<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
6
+ export declare function del<T>(url: string, body?: object, options?: RequestInit): Promise<T>;
@@ -0,0 +1,2 @@
1
+ export * from './generic';
2
+ export * from './message';
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions, LoadPreviousSessionResponse, SendMessageResponse } from '../types';
2
+ export declare function loadPreviousSession(sessionId: string, options: ChatOptions): Promise<LoadPreviousSessionResponse>;
3
+ export declare function sendMessage(message: string, sessionId: string, options: ChatOptions): Promise<SendMessageResponse>;
@@ -0,0 +1,11 @@
1
+ import type { ChatMessage } from '@n8n/chat/types/messages';
2
+ import type { Ref } from 'vue';
3
+ export interface Chat {
4
+ initialMessages: Ref<ChatMessage[]>;
5
+ messages: Ref<ChatMessage[]>;
6
+ currentSessionId: Ref<string | null>;
7
+ waitingForResponse: Ref<boolean>;
8
+ loadPreviousSession: () => Promise<string | undefined>;
9
+ startNewSession: () => Promise<void>;
10
+ sendMessage: (text: string) => Promise<void>;
11
+ }
package/types/chat.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/types/chat.mjs ADDED
File without changes
@@ -0,0 +1,9 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
2
+ default?(_: {}): any;
3
+ }>;
4
+ export default _default;
5
+ type __VLS_WithTemplateSlots<T, S> = T & {
6
+ new (): {
7
+ $slots: S;
8
+ };
9
+ };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,11 @@
1
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>, {
2
+ header?(_: {}): any;
3
+ default?(_: {}): any;
4
+ footer?(_: {}): any;
5
+ }>;
6
+ export default _default;
7
+ type __VLS_WithTemplateSlots<T, S> = T & {
8
+ new (): {
9
+ $slots: S;
10
+ };
11
+ };
@@ -0,0 +1,21 @@
1
+ import type { ChatMessage } from '../types';
2
+ import type { PropType } from 'vue';
3
+ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{
4
+ message: {
5
+ type: PropType<ChatMessage>;
6
+ required: true;
7
+ };
8
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
9
+ message: {
10
+ type: PropType<ChatMessage>;
11
+ required: true;
12
+ };
13
+ }>>, {}, {}>, {
14
+ default?(_: {}): any;
15
+ }>;
16
+ export default _default;
17
+ type __VLS_WithTemplateSlots<T, S> = T & {
18
+ new (): {
19
+ $slots: S;
20
+ };
21
+ };
@@ -0,0 +1,15 @@
1
+ import type { PropType } from 'vue';
2
+ declare const _default: import("vue").DefineComponent<{
3
+ animation: {
4
+ type: PropType<"bouncing" | "scaling">;
5
+ default: string;
6
+ };
7
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
8
+ animation: {
9
+ type: PropType<"bouncing" | "scaling">;
10
+ default: string;
11
+ };
12
+ }>>, {
13
+ animation: "bouncing" | "scaling";
14
+ }, {}>;
15
+ export default _default;
@@ -0,0 +1,14 @@
1
+ import type { PropType } from 'vue';
2
+ import type { ChatMessage } from '../types';
3
+ declare const _default: import("vue").DefineComponent<{
4
+ messages: {
5
+ type: PropType<ChatMessage[]>;
6
+ required: true;
7
+ };
8
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
9
+ messages: {
10
+ type: PropType<ChatMessage[]>;
11
+ required: true;
12
+ };
13
+ }>>, {}, {}>;
14
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{}>>, {}, {}>;
2
+ export default _default;
@@ -0,0 +1,10 @@
1
+ export { default as Button } from './Button.vue';
2
+ export { default as Chat } from './Chat.vue';
3
+ export { default as ChatWindow } from './ChatWindow.vue';
4
+ export { default as GetStarted } from './GetStarted.vue';
5
+ export { default as GetStartedFooter } from './GetStartedFooter.vue';
6
+ export { default as Input } from './Input.vue';
7
+ export { default as Layout } from './Layout.vue';
8
+ export { default as Message } from './Message.vue';
9
+ export { default as MessagesList } from './MessagesList.vue';
10
+ export { default as PoweredBy } from './PoweredBy.vue';
@@ -0,0 +1,3 @@
1
+ export * from './useChat';
2
+ export * from './useI18n';
3
+ export * from './useOptions';
@@ -0,0 +1,2 @@
1
+ import type { Chat } from '../types';
2
+ export declare function useChat(): Chat;
@@ -0,0 +1,4 @@
1
+ export declare function useI18n(): {
2
+ t: (key: string) => string;
3
+ te: (key: string) => boolean;
4
+ };
@@ -0,0 +1,4 @@
1
+ import type { ChatOptions } from '../types';
2
+ export declare function useOptions(): {
3
+ options: ChatOptions;
4
+ };
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions } from '../types';
2
+ export declare const defaultOptions: ChatOptions;
3
+ export declare const defaultMountingTarget = "#n8n-chat";
@@ -0,0 +1,3 @@
1
+ export * from './defaults';
2
+ export * from './localStorage';
3
+ export * from './symbols';
@@ -0,0 +1,2 @@
1
+ export declare const localStorageNamespace = "n8n-chat";
2
+ export declare const localStorageSessionIdKey = "n8n-chat/sessionId";
@@ -0,0 +1,4 @@
1
+ import type { InjectionKey } from 'vue';
2
+ import type { Chat, ChatOptions } from '../types';
3
+ export declare const ChatSymbol: InjectionKey<Chat>;
4
+ export declare const ChatOptionsSymbol: InjectionKey<ChatOptions>;
@@ -0,0 +1 @@
1
+ export declare const chatEventBus: import('../utils').EventBus;
@@ -0,0 +1 @@
1
+ export * from './chatEventBus';
package/types/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _chat = require("./chat");
7
+ Object.keys(_chat).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _chat[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _chat[key];
14
+ }
15
+ });
16
+ });
17
+ var _messages = require("./messages");
18
+ Object.keys(_messages).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _messages[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _messages[key];
25
+ }
26
+ });
27
+ });
28
+ var _options = require("./options");
29
+ Object.keys(_options).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _options[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _options[key];
36
+ }
37
+ });
38
+ });
39
+ var _webhook = require("./webhook");
40
+ Object.keys(_webhook).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _webhook[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _webhook[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,4 @@
1
+ export * from "./chat.mjs";
2
+ export * from "./messages.mjs";
3
+ export * from "./options.mjs";
4
+ export * from "./webhook.mjs";
@@ -0,0 +1,6 @@
1
+ export interface ChatMessage {
2
+ id: string;
3
+ text: string;
4
+ createdAt: string;
5
+ sender: 'user' | 'bot';
6
+ }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,25 @@
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
+ showWelcomeScreen?: boolean;
10
+ loadPreviousSession?: boolean;
11
+ chatInputKey?: string;
12
+ chatSessionKey?: string;
13
+ defaultLanguage?: 'en';
14
+ initialMessages?: string[];
15
+ metadata?: Record<string, unknown>;
16
+ i18n: Record<string, {
17
+ title: string;
18
+ subtitle: string;
19
+ footer: string;
20
+ getStarted: string;
21
+ inputPlaceholder: string;
22
+ [message: string]: string;
23
+ }>;
24
+ theme?: {};
25
+ }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'vue';
2
+ import type { ChatOptions } from '../types';
3
+ export declare const ChatPlugin: Plugin<ChatOptions>;
@@ -0,0 +1 @@
1
+ export * from './chat';
@@ -0,0 +1,11 @@
1
+ import type { ChatMessage } from '../types/messages';
2
+ import type { Ref } from 'vue';
3
+ export interface Chat {
4
+ initialMessages: Ref<ChatMessage[]>;
5
+ messages: Ref<ChatMessage[]>;
6
+ currentSessionId: Ref<string | null>;
7
+ waitingForResponse: Ref<boolean>;
8
+ loadPreviousSession: () => Promise<string | undefined>;
9
+ startNewSession: () => Promise<void>;
10
+ sendMessage: (text: string) => Promise<void>;
11
+ }
@@ -0,0 +1,4 @@
1
+ export * from './chat';
2
+ export * from './messages';
3
+ export * from './options';
4
+ export * from './webhook';
@@ -0,0 +1,6 @@
1
+ export interface ChatMessage {
2
+ id: string;
3
+ text: string;
4
+ createdAt: string;
5
+ sender: 'user' | 'bot';
6
+ }