@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,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getChatInput = getChatInput;
7
+ exports.getChatInputSendButton = getChatInputSendButton;
8
+ exports.getChatInputTextarea = getChatInputTextarea;
9
+ exports.getChatMessage = getChatMessage;
10
+ exports.getChatMessageByText = getChatMessageByText;
11
+ exports.getChatMessageTyping = getChatMessageTyping;
12
+ exports.getChatMessages = getChatMessages;
13
+ exports.getChatWindowToggle = getChatWindowToggle;
14
+ exports.getChatWindowWrapper = getChatWindowWrapper;
15
+ exports.getChatWrapper = getChatWrapper;
16
+ exports.getGetStartedButton = getGetStartedButton;
17
+ exports.getMountingTarget = getMountingTarget;
18
+ var _vue = require("@testing-library/vue");
19
+ var _constants = require("@n8n/chat/constants");
20
+ function getMountingTarget(target = _constants.defaultMountingTarget) {
21
+ return document.querySelector(target);
22
+ }
23
+ function getChatWindowWrapper() {
24
+ return document.querySelector(".chat-window-wrapper");
25
+ }
26
+ function getChatWindowToggle() {
27
+ return document.querySelector(".chat-window-toggle");
28
+ }
29
+ function getChatWrapper() {
30
+ return document.querySelector(".chat-wrapper");
31
+ }
32
+ function getChatMessages() {
33
+ return document.querySelectorAll(".chat-message:not(.chat-message-typing)");
34
+ }
35
+ function getChatMessage(index) {
36
+ const messages = getChatMessages();
37
+ return index < 0 ? messages[messages.length + index] : messages[index];
38
+ }
39
+ function getChatMessageByText(text) {
40
+ return _vue.screen.queryByText(text, {
41
+ selector: ".chat-message:not(.chat-message-typing) .chat-message-markdown p"
42
+ });
43
+ }
44
+ function getChatMessageTyping() {
45
+ return document.querySelector(".chat-message-typing");
46
+ }
47
+ function getGetStartedButton() {
48
+ return document.querySelector(".chat-get-started .chat-button");
49
+ }
50
+ function getChatInput() {
51
+ return document.querySelector(".chat-input");
52
+ }
53
+ function getChatInputTextarea() {
54
+ return document.querySelector(".chat-input textarea");
55
+ }
56
+ function getChatInputSendButton() {
57
+ return document.querySelector(".chat-input .chat-input-send-button");
58
+ }
@@ -0,0 +1,41 @@
1
+ import { screen } from "@testing-library/vue";
2
+ import { defaultMountingTarget } from "@n8n/chat/constants";
3
+ export function getMountingTarget(target = defaultMountingTarget) {
4
+ return document.querySelector(target);
5
+ }
6
+ export function getChatWindowWrapper() {
7
+ return document.querySelector(".chat-window-wrapper");
8
+ }
9
+ export function getChatWindowToggle() {
10
+ return document.querySelector(".chat-window-toggle");
11
+ }
12
+ export function getChatWrapper() {
13
+ return document.querySelector(".chat-wrapper");
14
+ }
15
+ export function getChatMessages() {
16
+ return document.querySelectorAll(".chat-message:not(.chat-message-typing)");
17
+ }
18
+ export function getChatMessage(index) {
19
+ const messages = getChatMessages();
20
+ return index < 0 ? messages[messages.length + index] : messages[index];
21
+ }
22
+ export function getChatMessageByText(text) {
23
+ return screen.queryByText(text, {
24
+ selector: ".chat-message:not(.chat-message-typing) .chat-message-markdown p"
25
+ });
26
+ }
27
+ export function getChatMessageTyping() {
28
+ return document.querySelector(".chat-message-typing");
29
+ }
30
+ export function getGetStartedButton() {
31
+ return document.querySelector(".chat-get-started .chat-button");
32
+ }
33
+ export function getChatInput() {
34
+ return document.querySelector(".chat-input");
35
+ }
36
+ export function getChatInputTextarea() {
37
+ return document.querySelector(".chat-input textarea");
38
+ }
39
+ export function getChatInputSendButton() {
40
+ return document.querySelector(".chat-input .chat-input-send-button");
41
+ }
@@ -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>;
package/api/generic.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.authenticatedFetch = authenticatedFetch;
7
+ exports.del = del;
8
+ exports.get = get;
9
+ exports.patch = patch;
10
+ exports.post = post;
11
+ exports.put = put;
12
+ async function getAccessToken() {
13
+ return "";
14
+ }
15
+ async function authenticatedFetch(...args) {
16
+ const accessToken = await getAccessToken();
17
+ const response = await fetch(args[0], {
18
+ ...args[1],
19
+ mode: "cors",
20
+ cache: "no-cache",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...(accessToken ? {
24
+ authorization: `Bearer ${accessToken}`
25
+ } : {}),
26
+ ...args[1]?.headers
27
+ }
28
+ });
29
+ return await response.json();
30
+ }
31
+ async function get(url, query = {}, options = {}) {
32
+ let resolvedUrl = url;
33
+ if (Object.keys(query).length > 0) {
34
+ resolvedUrl = `${resolvedUrl}?${new URLSearchParams(query).toString()}`;
35
+ }
36
+ return authenticatedFetch(resolvedUrl, {
37
+ ...options,
38
+ method: "GET"
39
+ });
40
+ }
41
+ async function post(url, body = {}, options = {}) {
42
+ return authenticatedFetch(url, {
43
+ ...options,
44
+ method: "POST",
45
+ body: JSON.stringify(body)
46
+ });
47
+ }
48
+ async function put(url, body = {}, options = {}) {
49
+ return authenticatedFetch(url, {
50
+ ...options,
51
+ method: "PUT",
52
+ body: JSON.stringify(body)
53
+ });
54
+ }
55
+ async function patch(url, body = {}, options = {}) {
56
+ return authenticatedFetch(url, {
57
+ ...options,
58
+ method: "PATCH",
59
+ body: JSON.stringify(body)
60
+ });
61
+ }
62
+ async function del(url, body = {}, options = {}) {
63
+ return authenticatedFetch(url, {
64
+ ...options,
65
+ method: "DELETE",
66
+ body: JSON.stringify(body)
67
+ });
68
+ }
@@ -0,0 +1,54 @@
1
+ async function getAccessToken() {
2
+ return "";
3
+ }
4
+ export async function authenticatedFetch(...args) {
5
+ const accessToken = await getAccessToken();
6
+ const response = await fetch(args[0], {
7
+ ...args[1],
8
+ mode: "cors",
9
+ cache: "no-cache",
10
+ headers: {
11
+ "Content-Type": "application/json",
12
+ ...accessToken ? { authorization: `Bearer ${accessToken}` } : {},
13
+ ...args[1]?.headers
14
+ }
15
+ });
16
+ return await response.json();
17
+ }
18
+ export async function get(url, query = {}, options = {}) {
19
+ let resolvedUrl = url;
20
+ if (Object.keys(query).length > 0) {
21
+ resolvedUrl = `${resolvedUrl}?${new URLSearchParams(
22
+ query
23
+ ).toString()}`;
24
+ }
25
+ return authenticatedFetch(resolvedUrl, { ...options, method: "GET" });
26
+ }
27
+ export async function post(url, body = {}, options = {}) {
28
+ return authenticatedFetch(url, {
29
+ ...options,
30
+ method: "POST",
31
+ body: JSON.stringify(body)
32
+ });
33
+ }
34
+ export async function put(url, body = {}, options = {}) {
35
+ return authenticatedFetch(url, {
36
+ ...options,
37
+ method: "PUT",
38
+ body: JSON.stringify(body)
39
+ });
40
+ }
41
+ export async function patch(url, body = {}, options = {}) {
42
+ return authenticatedFetch(url, {
43
+ ...options,
44
+ method: "PATCH",
45
+ body: JSON.stringify(body)
46
+ });
47
+ }
48
+ export async function del(url, body = {}, options = {}) {
49
+ return authenticatedFetch(url, {
50
+ ...options,
51
+ method: "DELETE",
52
+ body: JSON.stringify(body)
53
+ });
54
+ }
package/api/index.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _generic = require("./generic");
7
+ Object.keys(_generic).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _generic[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _generic[key];
14
+ }
15
+ });
16
+ });
17
+ var _message = require("./message");
18
+ Object.keys(_message).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _message[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _message[key];
25
+ }
26
+ });
27
+ });
package/api/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./generic.mjs";
2
+ export * from "./message.mjs";
@@ -0,0 +1,3 @@
1
+ import type { ChatOptions } from '@n8n/chat/types';
2
+ export declare function loadPreviousSession(sessionId: string, options: ChatOptions): Promise<any>;
3
+ export declare function sendMessage(message: string, sessionId: string, options: ChatOptions): Promise<any>;
package/api/message.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadPreviousSession = loadPreviousSession;
7
+ exports.sendMessage = sendMessage;
8
+ var _generic = require("@n8n/chat/api/generic");
9
+ async function loadPreviousSession(sessionId, options) {
10
+ const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
11
+ return method(`${options.webhookUrl}`, {
12
+ action: "loadPreviousSession",
13
+ [options.chatSessionKey]: sessionId,
14
+ ...(options.metadata ? {
15
+ metadata: options.metadata
16
+ } : {})
17
+ }, {
18
+ headers: options.webhookConfig?.headers
19
+ });
20
+ }
21
+ async function sendMessage(message, sessionId, options) {
22
+ const method = options.webhookConfig?.method === "POST" ? _generic.post : _generic.get;
23
+ return method(`${options.webhookUrl}`, {
24
+ action: "sendMessage",
25
+ [options.chatSessionKey]: sessionId,
26
+ [options.chatInputKey]: message,
27
+ ...(options.metadata ? {
28
+ metadata: options.metadata
29
+ } : {})
30
+ }, {
31
+ headers: options.webhookConfig?.headers
32
+ });
33
+ }
@@ -0,0 +1,30 @@
1
+ import { get, post } from "@n8n/chat/api/generic";
2
+ export async function loadPreviousSession(sessionId, options) {
3
+ const method = options.webhookConfig?.method === "POST" ? post : get;
4
+ return method(
5
+ `${options.webhookUrl}`,
6
+ {
7
+ action: "loadPreviousSession",
8
+ [options.chatSessionKey]: sessionId,
9
+ ...options.metadata ? { metadata: options.metadata } : {}
10
+ },
11
+ {
12
+ headers: options.webhookConfig?.headers
13
+ }
14
+ );
15
+ }
16
+ export async function sendMessage(message, sessionId, options) {
17
+ const method = options.webhookConfig?.method === "POST" ? post : get;
18
+ return method(
19
+ `${options.webhookUrl}`,
20
+ {
21
+ action: "sendMessage",
22
+ [options.chatSessionKey]: sessionId,
23
+ [options.chatInputKey]: message,
24
+ ...options.metadata ? { metadata: options.metadata } : {}
25
+ },
26
+ {
27
+ headers: options.webhookConfig?.headers
28
+ }
29
+ );
30
+ }