@n8n/chat 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.cjs +51 -0
  3. package/.np-config.json +5 -0
  4. package/.storybook/main.ts +27 -0
  5. package/.storybook/preview.scss +4 -0
  6. package/.storybook/preview.ts +16 -0
  7. package/.vscode/extensions.json +3 -0
  8. package/README.md +4 -21
  9. package/env.d.ts +1 -0
  10. package/index.html +13 -0
  11. package/package.json +2 -69
  12. package/resources/workflow.json +293 -0
  13. package/scripts/pack.js +11 -0
  14. package/scripts/postbuild.js +16 -0
  15. package/{App.vue → src/App.vue} +2 -2
  16. package/src/__stories__/App.stories.ts +43 -0
  17. package/src/__tests__/index.spec.ts +223 -0
  18. package/src/__tests__/utils/create.ts +16 -0
  19. package/src/__tests__/utils/fetch.ts +18 -0
  20. package/src/__tests__/utils/selectors.ts +53 -0
  21. package/src/api/generic.ts +64 -0
  22. package/src/api/message.ts +31 -0
  23. package/src/components/Button.vue +41 -0
  24. package/{components → src/components}/Chat.vue +15 -19
  25. package/src/components/ChatWindow.vue +125 -0
  26. package/src/components/GetStarted.vue +24 -0
  27. package/{components → src/components}/GetStartedFooter.vue +4 -4
  28. package/{components → src/components}/Input.vue +40 -35
  29. package/src/components/Layout.vue +82 -0
  30. package/src/components/Message.vue +97 -0
  31. package/src/components/MessageTyping.vue +109 -0
  32. package/{components → src/components}/MessagesList.vue +8 -8
  33. package/{components → src/components}/PoweredBy.vue +7 -6
  34. package/src/composables/useChat.ts +7 -0
  35. package/src/composables/useI18n.ts +16 -0
  36. package/src/composables/useOptions.ts +11 -0
  37. package/src/constants/defaults.ts +25 -0
  38. package/{constants/localStorage.mjs → src/constants/localStorage.ts} +1 -1
  39. package/src/constants/symbols.ts +8 -0
  40. package/src/event-buses/chatEventBus.ts +3 -0
  41. package/src/index.ts +42 -0
  42. package/src/main.scss +40 -0
  43. package/src/plugins/chat.ts +101 -0
  44. package/src/types/chat.ts +12 -0
  45. package/src/types/messages.ts +6 -0
  46. package/src/types/options.ts +23 -0
  47. package/src/types/webhook.ts +17 -0
  48. package/src/utils/event-bus.ts +51 -0
  49. package/src/utils/mount.ts +16 -0
  50. package/tsconfig.json +27 -0
  51. package/vite.config.ts +51 -0
  52. package/vitest.config.ts +20 -0
  53. package/__stories__/App.stories.d.ts +0 -16
  54. package/__stories__/App.stories.js +0 -38
  55. package/__stories__/App.stories.mjs +0 -32
  56. package/__tests__/index.spec.d.ts +0 -1
  57. package/__tests__/index.spec.js +0 -146
  58. package/__tests__/index.spec.mjs +0 -172
  59. package/__tests__/setup.js +0 -3
  60. package/__tests__/setup.mjs +0 -1
  61. package/__tests__/utils/create.d.ts +0 -5
  62. package/__tests__/utils/create.js +0 -16
  63. package/__tests__/utils/create.mjs +0 -10
  64. package/__tests__/utils/fetch.d.ts +0 -3
  65. package/__tests__/utils/fetch.js +0 -20
  66. package/__tests__/utils/fetch.mjs +0 -9
  67. package/__tests__/utils/index.js +0 -38
  68. package/__tests__/utils/index.mjs +0 -3
  69. package/__tests__/utils/selectors.d.ts +0 -12
  70. package/__tests__/utils/selectors.js +0 -58
  71. package/__tests__/utils/selectors.mjs +0 -41
  72. package/api/generic.d.ts +0 -6
  73. package/api/generic.js +0 -68
  74. package/api/generic.mjs +0 -54
  75. package/api/index.js +0 -27
  76. package/api/index.mjs +0 -2
  77. package/api/message.d.ts +0 -3
  78. package/api/message.js +0 -33
  79. package/api/message.mjs +0 -30
  80. package/chat.bundle.es.js +0 -10760
  81. package/chat.bundle.umd.js +0 -18
  82. package/components/Button.vue +0 -34
  83. package/components/ChatWindow.vue +0 -104
  84. package/components/GetStarted.vue +0 -24
  85. package/components/Layout.vue +0 -66
  86. package/components/Message.vue +0 -94
  87. package/components/MessageTyping.vue +0 -101
  88. package/components/index.js +0 -76
  89. package/components/index.mjs +0 -10
  90. package/composables/index.js +0 -38
  91. package/composables/index.mjs +0 -3
  92. package/composables/useChat.d.ts +0 -1
  93. package/composables/useChat.js +0 -11
  94. package/composables/useChat.mjs +0 -5
  95. package/composables/useI18n.d.ts +0 -4
  96. package/composables/useI18n.js +0 -23
  97. package/composables/useI18n.mjs +0 -12
  98. package/composables/useOptions.d.ts +0 -3
  99. package/composables/useOptions.js +0 -14
  100. package/composables/useOptions.mjs +0 -8
  101. package/constants/defaults.d.ts +0 -3
  102. package/constants/defaults.js +0 -32
  103. package/constants/defaults.mjs +0 -26
  104. package/constants/index.js +0 -38
  105. package/constants/index.mjs +0 -3
  106. package/constants/localStorage.d.ts +0 -2
  107. package/constants/localStorage.js +0 -8
  108. package/constants/symbols.d.ts +0 -3
  109. package/constants/symbols.js +0 -8
  110. package/constants/symbols.mjs +0 -2
  111. package/css/index.css +0 -31
  112. package/event-buses/chatEventBus.d.ts +0 -1
  113. package/event-buses/chatEventBus.js +0 -8
  114. package/event-buses/chatEventBus.mjs +0 -2
  115. package/event-buses/index.js +0 -16
  116. package/event-buses/index.mjs +0 -1
  117. package/index.d.ts +0 -3
  118. package/index.js +0 -43
  119. package/index.mjs +0 -36
  120. package/main.css +0 -151
  121. package/plugins/chat.d.ts +0 -3
  122. package/plugins/chat.js +0 -85
  123. package/plugins/chat.mjs +0 -83
  124. package/plugins/index.js +0 -16
  125. package/plugins/index.mjs +0 -1
  126. package/style.css +0 -1
  127. package/types/App.vue.d.ts +0 -8
  128. package/types/__stories__/App.stories.d.ts +0 -17
  129. package/types/__tests__/index.spec.d.ts +0 -1
  130. package/types/__tests__/setup.d.ts +0 -0
  131. package/types/__tests__/utils/create.d.ts +0 -5
  132. package/types/__tests__/utils/fetch.d.ts +0 -4
  133. package/types/__tests__/utils/index.d.ts +0 -3
  134. package/types/__tests__/utils/selectors.d.ts +0 -12
  135. package/types/api/generic.d.ts +0 -6
  136. package/types/api/index.d.ts +0 -2
  137. package/types/api/message.d.ts +0 -3
  138. package/types/chat.d.ts +0 -11
  139. package/types/chat.js +0 -1
  140. package/types/chat.mjs +0 -0
  141. package/types/components/Button.vue.d.ts +0 -9
  142. package/types/components/Chat.vue.d.ts +0 -2
  143. package/types/components/ChatWindow.vue.d.ts +0 -2
  144. package/types/components/GetStarted.vue.d.ts +0 -2
  145. package/types/components/GetStartedFooter.vue.d.ts +0 -2
  146. package/types/components/Input.vue.d.ts +0 -2
  147. package/types/components/Layout.vue.d.ts +0 -11
  148. package/types/components/Message.vue.d.ts +0 -21
  149. package/types/components/MessageTyping.vue.d.ts +0 -15
  150. package/types/components/MessagesList.vue.d.ts +0 -14
  151. package/types/components/PoweredBy.vue.d.ts +0 -2
  152. package/types/components/index.d.ts +0 -10
  153. package/types/composables/index.d.ts +0 -3
  154. package/types/composables/useChat.d.ts +0 -2
  155. package/types/composables/useI18n.d.ts +0 -4
  156. package/types/composables/useOptions.d.ts +0 -4
  157. package/types/constants/defaults.d.ts +0 -3
  158. package/types/constants/index.d.ts +0 -3
  159. package/types/constants/localStorage.d.ts +0 -2
  160. package/types/constants/symbols.d.ts +0 -4
  161. package/types/event-buses/chatEventBus.d.ts +0 -1
  162. package/types/event-buses/index.d.ts +0 -1
  163. package/types/index.js +0 -49
  164. package/types/index.mjs +0 -4
  165. package/types/messages.d.ts +0 -6
  166. package/types/messages.js +0 -1
  167. package/types/messages.mjs +0 -0
  168. package/types/options.d.ts +0 -25
  169. package/types/options.js +0 -1
  170. package/types/options.mjs +0 -0
  171. package/types/plugins/chat.d.ts +0 -3
  172. package/types/plugins/index.d.ts +0 -1
  173. package/types/src/App.vue.d.ts +0 -8
  174. package/types/src/__stories__/App.stories.d.ts +0 -17
  175. package/types/src/__tests__/index.spec.d.ts +0 -1
  176. package/types/src/__tests__/setup.d.ts +0 -0
  177. package/types/src/__tests__/utils/create.d.ts +0 -5
  178. package/types/src/__tests__/utils/fetch.d.ts +0 -4
  179. package/types/src/__tests__/utils/index.d.ts +0 -3
  180. package/types/src/__tests__/utils/selectors.d.ts +0 -12
  181. package/types/src/api/generic.d.ts +0 -6
  182. package/types/src/api/index.d.ts +0 -2
  183. package/types/src/api/message.d.ts +0 -3
  184. package/types/src/components/Button.vue.d.ts +0 -9
  185. package/types/src/components/Chat.vue.d.ts +0 -2
  186. package/types/src/components/ChatWindow.vue.d.ts +0 -2
  187. package/types/src/components/GetStarted.vue.d.ts +0 -2
  188. package/types/src/components/GetStartedFooter.vue.d.ts +0 -2
  189. package/types/src/components/Input.vue.d.ts +0 -2
  190. package/types/src/components/Layout.vue.d.ts +0 -11
  191. package/types/src/components/Message.vue.d.ts +0 -21
  192. package/types/src/components/MessageTyping.vue.d.ts +0 -15
  193. package/types/src/components/MessagesList.vue.d.ts +0 -14
  194. package/types/src/components/PoweredBy.vue.d.ts +0 -2
  195. package/types/src/components/index.d.ts +0 -10
  196. package/types/src/composables/index.d.ts +0 -3
  197. package/types/src/composables/useChat.d.ts +0 -2
  198. package/types/src/composables/useI18n.d.ts +0 -4
  199. package/types/src/composables/useOptions.d.ts +0 -4
  200. package/types/src/constants/defaults.d.ts +0 -3
  201. package/types/src/constants/index.d.ts +0 -3
  202. package/types/src/constants/localStorage.d.ts +0 -2
  203. package/types/src/constants/symbols.d.ts +0 -4
  204. package/types/src/event-buses/chatEventBus.d.ts +0 -1
  205. package/types/src/event-buses/index.d.ts +0 -1
  206. package/types/src/index.d.ts +0 -2
  207. package/types/src/plugins/chat.d.ts +0 -3
  208. package/types/src/plugins/index.d.ts +0 -1
  209. package/types/src/types/chat.d.ts +0 -11
  210. package/types/src/types/index.d.ts +0 -4
  211. package/types/src/types/messages.d.ts +0 -6
  212. package/types/src/types/options.d.ts +0 -25
  213. package/types/src/types/webhook.d.ts +0 -15
  214. package/types/src/utils/event-bus.d.ts +0 -8
  215. package/types/src/utils/mount.d.ts +0 -1
  216. package/types/types/chat.d.ts +0 -11
  217. package/types/types/index.d.ts +0 -4
  218. package/types/types/messages.d.ts +0 -6
  219. package/types/types/options.d.ts +0 -25
  220. package/types/types/webhook.d.ts +0 -15
  221. package/types/utils/event-bus.d.ts +0 -8
  222. package/types/utils/index.d.ts +0 -2
  223. package/types/utils/mount.d.ts +0 -1
  224. package/types/webhook.d.ts +0 -15
  225. package/types/webhook.js +0 -1
  226. package/types/webhook.mjs +0 -0
  227. package/utils/event-bus.d.ts +0 -8
  228. package/utils/event-bus.js +0 -38
  229. package/utils/event-bus.mjs +0 -32
  230. package/utils/index.d.ts +0 -2
  231. package/utils/index.js +0 -27
  232. package/utils/index.mjs +0 -2
  233. package/utils/mount.d.ts +0 -1
  234. package/utils/mount.js +0 -19
  235. package/utils/mount.mjs +0 -13
  236. /package/{favicon.ico → public/favicon.ico} +0 -0
  237. /package/{__tests__/setup.d.ts → src/__tests__/setup.ts} +0 -0
  238. /package/{__tests__/utils/index.d.ts → src/__tests__/utils/index.ts} +0 -0
  239. /package/{api/index.d.ts → src/api/index.ts} +0 -0
  240. /package/{components/index.d.ts → src/components/index.ts} +0 -0
  241. /package/{composables/index.d.ts → src/composables/index.ts} +0 -0
  242. /package/{constants/index.d.ts → src/constants/index.ts} +0 -0
  243. /package/{event-buses/index.d.ts → src/event-buses/index.ts} +0 -0
  244. /package/{plugins/index.d.ts → src/plugins/index.ts} +0 -0
  245. /package/{shims.d.ts → src/shims.d.ts} +0 -0
  246. /package/{types/index.d.ts → src/types/index.ts} +0 -0
  247. /package/{types/src/utils/index.d.ts → src/utils/index.ts} +0 -0
@@ -1,172 +0,0 @@
1
- import { fireEvent, waitFor } from "@testing-library/vue";
2
- import {
3
- createFetchResponse,
4
- createGetLatestMessagesResponse,
5
- createSendMessageResponse,
6
- getChatInputSendButton,
7
- getChatInputTextarea,
8
- getChatMessage,
9
- getChatMessageByText,
10
- getChatMessages,
11
- getChatMessageTyping,
12
- getChatWindowToggle,
13
- getChatWindowWrapper,
14
- getChatWrapper,
15
- getGetStartedButton,
16
- getMountingTarget
17
- } from "@n8n/chat/__tests__/utils";
18
- import { createChat } from "@n8n/chat/index";
19
- describe("createChat()", () => {
20
- let app;
21
- afterEach(() => {
22
- vi.clearAllMocks();
23
- app.unmount();
24
- });
25
- describe("mode", () => {
26
- it("should create fullscreen chat app with default options", () => {
27
- const fetchSpy = vi.spyOn(window, "fetch");
28
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse()));
29
- app = createChat({
30
- mode: "fullscreen"
31
- });
32
- expect(getMountingTarget()).toBeVisible();
33
- expect(getChatWrapper()).toBeVisible();
34
- expect(getChatWindowWrapper()).not.toBeInTheDocument();
35
- });
36
- it("should create window chat app with default options", () => {
37
- const fetchSpy = vi.spyOn(window, "fetch");
38
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse()));
39
- app = createChat({
40
- mode: "window"
41
- });
42
- expect(getMountingTarget()).toBeDefined();
43
- expect(getChatWindowWrapper()).toBeVisible();
44
- expect(getChatWrapper()).not.toBeVisible();
45
- });
46
- it("should open window chat app using toggle button", async () => {
47
- const fetchSpy = vi.spyOn(window, "fetch");
48
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse()));
49
- app = createChat();
50
- expect(getMountingTarget()).toBeVisible();
51
- expect(getChatWindowWrapper()).toBeVisible();
52
- const trigger = getChatWindowToggle();
53
- await fireEvent.click(trigger);
54
- expect(getChatWrapper()).toBeVisible();
55
- });
56
- });
57
- describe("loadPreviousMessages", () => {
58
- it("should load previous messages on mount", async () => {
59
- const fetchSpy = vi.spyOn(global, "fetch");
60
- fetchSpy.mockImplementation(createFetchResponse(createGetLatestMessagesResponse()));
61
- app = createChat({
62
- mode: "fullscreen",
63
- showWelcomeScreen: true
64
- });
65
- const getStartedButton = getGetStartedButton();
66
- await fireEvent.click(getStartedButton);
67
- expect(fetchSpy.mock.calls[0][1]).toEqual(
68
- expect.objectContaining({
69
- method: "POST",
70
- headers: {
71
- "Content-Type": "application/json"
72
- },
73
- body: expect.stringContaining('"action":"loadPreviousSession"'),
74
- mode: "cors",
75
- cache: "no-cache"
76
- })
77
- );
78
- });
79
- });
80
- describe("initialMessages", () => {
81
- it.each(["fullscreen", "window"])(
82
- "should show initial default messages in %s mode",
83
- async (mode) => {
84
- const fetchSpy = vi.spyOn(window, "fetch");
85
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse()));
86
- const initialMessages = ["Hello tester!", "How are you?"];
87
- app = createChat({
88
- mode,
89
- initialMessages
90
- });
91
- if (mode === "window") {
92
- const trigger = getChatWindowToggle();
93
- await fireEvent.click(trigger);
94
- }
95
- expect(getChatMessages().length).toBe(initialMessages.length);
96
- expect(getChatMessageByText(initialMessages[0])).toBeInTheDocument();
97
- expect(getChatMessageByText(initialMessages[1])).toBeInTheDocument();
98
- }
99
- );
100
- });
101
- describe("sendMessage", () => {
102
- it.each(["window", "fullscreen"])(
103
- "should send a message and render a text message in %s mode",
104
- async (mode) => {
105
- const input = "Hello User World!";
106
- const output = "Hello Bot World!";
107
- const fetchSpy = vi.spyOn(window, "fetch");
108
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse)).mockImplementationOnce(createFetchResponse(createSendMessageResponse(output)));
109
- app = createChat({
110
- mode
111
- });
112
- if (mode === "window") {
113
- const trigger = getChatWindowToggle();
114
- await fireEvent.click(trigger);
115
- }
116
- expect(getChatMessageTyping()).not.toBeInTheDocument();
117
- expect(getChatMessages().length).toBe(2);
118
- await waitFor(() => expect(getChatInputTextarea()).toBeInTheDocument());
119
- const textarea = getChatInputTextarea();
120
- const sendButton = getChatInputSendButton();
121
- await fireEvent.update(textarea, input);
122
- expect(sendButton).not.toBeDisabled();
123
- await fireEvent.click(sendButton);
124
- expect(fetchSpy.mock.calls[1][1]).toEqual(
125
- expect.objectContaining({
126
- method: "POST",
127
- headers: {
128
- "Content-Type": "application/json"
129
- },
130
- body: expect.stringMatching(/"action":"sendMessage"/),
131
- mode: "cors",
132
- cache: "no-cache"
133
- })
134
- );
135
- expect(fetchSpy.mock.calls[1][1]?.body).toContain(`"${input}"`);
136
- expect(getChatMessages().length).toBe(3);
137
- expect(getChatMessageByText(input)).toBeInTheDocument();
138
- expect(getChatMessageTyping()).toBeVisible();
139
- await waitFor(() => expect(getChatMessageTyping()).not.toBeInTheDocument());
140
- expect(getChatMessageByText(output)).toBeInTheDocument();
141
- }
142
- );
143
- it.each(["fullscreen", "window"])(
144
- "should send a message and render a code markdown message in %s mode",
145
- async (mode) => {
146
- const input = "Teach me javascript!";
147
- const output = '# Code\n```js\nconsole.log("Hello World!");\n```';
148
- const fetchSpy = vi.spyOn(window, "fetch");
149
- fetchSpy.mockImplementationOnce(createFetchResponse(createGetLatestMessagesResponse)).mockImplementationOnce(createFetchResponse(createSendMessageResponse(output)));
150
- app = createChat({
151
- mode
152
- });
153
- if (mode === "window") {
154
- const trigger = getChatWindowToggle();
155
- await fireEvent.click(trigger);
156
- }
157
- await waitFor(() => expect(getChatInputTextarea()).toBeInTheDocument());
158
- const textarea = getChatInputTextarea();
159
- const sendButton = getChatInputSendButton();
160
- await fireEvent.update(textarea, input);
161
- await fireEvent.click(sendButton);
162
- expect(getChatMessageByText(input)).toBeInTheDocument();
163
- expect(getChatMessages().length).toBe(3);
164
- await waitFor(() => expect(getChatMessageTyping()).not.toBeInTheDocument());
165
- const lastMessage = getChatMessage(-1);
166
- expect(lastMessage).toBeInTheDocument();
167
- expect(lastMessage.querySelector("h1")).toHaveTextContent("Code");
168
- expect(lastMessage.querySelector("code")).toHaveTextContent('console.log("Hello World!");');
169
- }
170
- );
171
- });
172
- });
@@ -1,3 +0,0 @@
1
- "use strict";
2
-
3
- require("@testing-library/jest-dom");
@@ -1 +0,0 @@
1
- import "@testing-library/jest-dom";
@@ -1,5 +0,0 @@
1
- import { createChat } from '@n8n/chat/index';
2
- export declare function createTestChat(options?: Parameters<typeof createChat>[0]): {
3
- unmount: () => void;
4
- container: Element;
5
- };
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createTestChat = createTestChat;
7
- var _index = require("@n8n/chat/index");
8
- function createTestChat(options = {}) {
9
- const app = (0, _index.createChat)(options);
10
- const container = app._container;
11
- const unmount = () => app.unmount();
12
- return {
13
- unmount,
14
- container
15
- };
16
- }
@@ -1,10 +0,0 @@
1
- import { createChat } from "@n8n/chat/index";
2
- export function createTestChat(options = {}) {
3
- const app = createChat(options);
4
- const container = app._container;
5
- const unmount = () => app.unmount();
6
- return {
7
- unmount,
8
- container
9
- };
10
- }
@@ -1,3 +0,0 @@
1
- export declare function createFetchResponse<T>(data: T): () => Promise<Response>;
2
- export declare const createGetLatestMessagesResponse: (data?: LoadPreviousSessionResponse) => LoadPreviousSessionResponse;
3
- export declare const createSendMessageResponse: (output: SendMessageResponse) => SendMessageResponse;
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createFetchResponse = createFetchResponse;
7
- exports.createSendMessageResponse = exports.createGetLatestMessagesResponse = void 0;
8
- function createFetchResponse(data) {
9
- return async () => ({
10
- json: async () => new Promise(resolve => resolve(data))
11
- });
12
- }
13
- const createGetLatestMessagesResponse = (data = []) => ({
14
- data
15
- });
16
- exports.createGetLatestMessagesResponse = createGetLatestMessagesResponse;
17
- const createSendMessageResponse = output => ({
18
- output
19
- });
20
- exports.createSendMessageResponse = createSendMessageResponse;
@@ -1,9 +0,0 @@
1
- export function createFetchResponse(data) {
2
- return async () => ({
3
- json: async () => new Promise((resolve) => resolve(data))
4
- });
5
- }
6
- export const createGetLatestMessagesResponse = (data = []) => ({ data });
7
- export const createSendMessageResponse = (output) => ({
8
- output
9
- });
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _create = require("./create");
7
- Object.keys(_create).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _create[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _create[key];
14
- }
15
- });
16
- });
17
- var _fetch = require("./fetch");
18
- Object.keys(_fetch).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _fetch[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _fetch[key];
25
- }
26
- });
27
- });
28
- var _selectors = require("./selectors");
29
- Object.keys(_selectors).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _selectors[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _selectors[key];
36
- }
37
- });
38
- });
@@ -1,3 +0,0 @@
1
- export * from "./create.mjs";
2
- export * from "./fetch.mjs";
3
- export * from "./selectors.mjs";
@@ -1,12 +0,0 @@
1
- export declare function getMountingTarget(target?: any): any;
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;
@@ -1,58 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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
- }
package/api/generic.d.ts DELETED
@@ -1,6 +0,0 @@
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 DELETED
@@ -1,68 +0,0 @@
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
- }
package/api/generic.mjs DELETED
@@ -1,54 +0,0 @@
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 DELETED
@@ -1,27 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export * from "./generic.mjs";
2
- export * from "./message.mjs";
package/api/message.d.ts DELETED
@@ -1,3 +0,0 @@
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 DELETED
@@ -1,33 +0,0 @@
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
- }
package/api/message.mjs DELETED
@@ -1,30 +0,0 @@
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
- }